diff --git a/.storybook/webpack.config.js b/.storybook/webpack.config.js index f9a39f44..cc490772 100644 --- a/.storybook/webpack.config.js +++ b/.storybook/webpack.config.js @@ -24,7 +24,7 @@ module.exports = ({ config }) => { }); config.module.rules.push({ - test: /\.(svg)$/, + test: /\.(svg|png|jpg)$/i, use: [ { loader: 'url-loader', diff --git a/src/inputs/Select/dai.png b/src/inputs/Select/dai.png new file mode 100644 index 00000000..06cff708 Binary files /dev/null and b/src/inputs/Select/dai.png differ diff --git a/src/inputs/Select/gnosis.png b/src/inputs/Select/gnosis.png new file mode 100644 index 00000000..13b3380e Binary files /dev/null and b/src/inputs/Select/gnosis.png differ diff --git a/src/inputs/Select/index.tsx b/src/inputs/Select/index.tsx index 1a3a6c02..a8cb2973 100644 --- a/src/inputs/Select/index.tsx +++ b/src/inputs/Select/index.tsx @@ -4,13 +4,15 @@ import FormControl from '@material-ui/core/FormControl'; import SelectMUI from '@material-ui/core/Select'; import styled from 'styled-components'; +import { Text } from '../../dataDisplay'; + const IconImg = styled.img` width: 20px; margin-right: 10px; `; const StyledSelect = styled(SelectMUI)` - background-color: #e8e7e6; + background-color: ${(props) => props.theme.colors.separator}; border-radius: 5px; height: 56px; width: 140px; @@ -22,18 +24,40 @@ const StyledSelect = styled(SelectMUI)` } .MuiSelect-selectMenu { - font-family: ${(p) => p.theme.fonts.fontFamily}; + font-family: ${(props) => props.theme.fonts.fontFamily}; + } + + &.MuiInput-underline:hover:not(.Mui-disabled):before { + border-bottom: 2px solid ${(props) => props.theme.colors.primary}; + } + &.MuiInput-underline:after { + border-bottom: 2px solid ${(props) => props.theme.colors.primary}; } `; +export type SelectItem = { + id: string; + label: string; + subLabel?: string; + iconUrl?: string; +}; + type Props = { - items: Array<{ id: string; label: string; iconUrl?: string }>; + items: Array; activeItemId: string; onItemClick: (id: string) => void; id?: string; + fallbackImage?: string; }; -function Select({ items, activeItemId, onItemClick, id, ...rest }: Props) { +function Select({ + items, + activeItemId, + onItemClick, + id, + fallbackImage, + ...rest +}: Props) { const [open, setOpen] = React.useState(false); const handleChange = (event: React.ChangeEvent<{ value: unknown }>) => { @@ -48,6 +72,15 @@ function Select({ items, activeItemId, onItemClick, id, ...rest }: Props) { setOpen(true); }; + const onFallbackImage: React.ReactEventHandler = (e) => { + if (!fallbackImage) { + return; + } + + (e.target as HTMLImageElement).onerror = null; + (e.target as HTMLImageElement).src = fallbackImage; + }; + return (
@@ -63,8 +96,23 @@ function Select({ items, activeItemId, onItemClick, id, ...rest }: Props) { {items.map((i) => { return ( - {i.iconUrl && } - {i.label} + {i.iconUrl && ( + + )} +
+ + {i.label} + + {i.subLabel && ( + + {i.subLabel} + + )} +
); })} diff --git a/src/inputs/Select/select.stories.tsx b/src/inputs/Select/select.stories.tsx index ae7f6492..bdcc6ace 100644 --- a/src/inputs/Select/select.stories.tsx +++ b/src/inputs/Select/select.stories.tsx @@ -1,21 +1,26 @@ import React, { useState } from 'react'; -import Select from './'; +import gnoIcon from './gnosis.png'; +import daiIcon from './dai.png'; +import tokenPlaceholder from './token-placeholder.svg'; +import Select, { SelectItem } from './'; export default { title: 'Inputs/Select', component: Select, parameters: { - componentSubtitle: 'Checkbox Input.' + componentSubtitle: 'Select Input.' } }; -const items = [ - { id: '1', label: 'ETH' }, - { id: '2', label: 'GNO' } -]; - export const select = () => { + const items: Array = [ + { id: '1', label: 'DAI', subLabel: 'stablecoin', iconUrl: daiIcon }, + { id: '2', label: 'GNO', iconUrl: gnoIcon }, + { id: '2', label: 'BrokenImage', iconUrl: 'https://broken-image.test' }, + { id: '3', label: 'without icon' } + ]; + const [activeItemId, setActiveItemId] = useState(''); return (