blob: 2cf44cae1f0973900360c4c615ae6f85c8bde556 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
import { colors } from '@0x/react-shared';
import * as _ from 'lodash';
import * as React from 'react';
import { Container } from './container';
export interface MultiSelectItemConfig {
value: string;
renderItemContent: (isSelected: boolean) => React.ReactNode;
onClick?: () => void;
}
export interface MultiSelectProps {
selectedValues?: string[];
items: MultiSelectItemConfig[];
backgroundColor?: string;
height?: string;
}
export class MultiSelect extends React.Component<MultiSelectProps> {
public static defaultProps = {
backgroundColor: colors.white,
};
public render(): React.ReactNode {
const { items, backgroundColor, selectedValues, height } = this.props;
return (
<Container
backgroundColor={backgroundColor}
borderRadius="4px"
width="100%"
height={height}
overflowY="scroll"
>
{_.map(items, item => (
<MultiSelectItem
key={item.value}
renderItemContent={item.renderItemContent}
backgroundColor={backgroundColor}
onClick={item.onClick}
isSelected={_.isUndefined(selectedValues) || _.includes(selectedValues, item.value)}
/>
))}
</Container>
);
}
}
export interface MultiSelectItemProps {
renderItemContent: (isSelected: boolean) => React.ReactNode;
isSelected?: boolean;
onClick?: () => void;
backgroundColor?: string;
}
export const MultiSelectItem: React.StatelessComponent<MultiSelectItemProps> = ({
renderItemContent,
isSelected,
onClick,
backgroundColor,
}) => (
<Container cursor="pointer" shouldDarkenOnHover={true} onClick={onClick} backgroundColor={backgroundColor}>
<Container borderBottom={`1px solid ${colors.lightestGrey}`} margin="0px 15px" padding="10px 0px">
{renderItemContent(isSelected)}
</Container>
</Container>
);
|