import Radium from 'radium' import PropTypes from 'prop-types' import React, { Component } from 'react' import { Box, Icon } from '.' import { sizeInfo, colorInfo, fontInfo } from './style' import downArrowImage from './images/down-arrow.svg' import upArrowImage from './images/up-arrow.svg' import autobind from 'autobind-decorator' @Radium export class DropdownList extends Component { static propTypes = { data: PropTypes.array, render: PropTypes.func.isRequired, } constructor(props) { super(props) this.state = { open: false, } } @autobind handleClick(e) { this.setState({ open: !this.state.open }) } render() { const { data, render } = this.props const { open } = this.state const dropDownIconSize = 20 const dropdownIconMargin = 8 const dropdownBackground = 'white' const selectedItem = data ? data[0] : const border = { width: sizeInfo.listBorderWidth, color: colorInfo.listBorder } let dropdown = null if (open) { dropdown = ( ) } return (
{render(selectedItem)}
{dropdown}
) } } DropdownList.Item = Radium(class ListItem extends Component { static propTypes = { children: PropTypes.node, active: PropTypes.bool, onClick: PropTypes.func, } render() { const { children, active, onClick } = this.props return (
{children}
) } }) DropdownList.Icon = Radium(class ListIcon extends Component { static propTypes = { name: PropTypes.string, size: PropTypes.number, } render() { const { size, name } = this.props let source = Icon.svgs[name] || Icon.svgs['placeholder'] return ( ) } }) DropdownList.Text = Radium(class ListText extends Component { static propTypes = { children: PropTypes.node, } render() { const { children } = this.props return ( {children} ) } })