Browse Source

Better styling for unsearchable Select

master
meriadec 7 years ago
parent
commit
f69ff2d114
No known key found for this signature in database GPG Key ID: 1D2FC2305E2CB399
  1. 29
      src/components/base/Select/Triangles.js
  2. 18
      src/components/base/Select/index.js
  3. 1
      src/components/base/Select/stories.js

29
src/components/base/Select/Triangles.js

@ -0,0 +1,29 @@
// @flow
import React from 'react'
import styled from 'styled-components'
import Box from 'components/base/Box'
const UpTriangle = styled.div`
width: 0;
height: 0;
border-left: ${p => p.size}px solid transparent;
border-right: ${p => p.size}px solid transparent;
border-bottom: ${p => p.size}px solid ${p => p.theme.colors[p.color]};
`
const DownTriangle = styled.div`
width: 0;
height: 0;
border-left: ${p => p.size}px solid transparent;
border-right: ${p => p.size}px solid transparent;
border-top: ${p => p.size}px solid ${p => p.theme.colors[p.color]};
`
export default ({ size = 5, color = 'mouse' }: { size: number, color: string }) => (
<Box flow={1}>
<UpTriangle size={size} color={color} />
<DownTriangle size={size} color={color} />
</Box>
)

18
src/components/base/Select/index.js

@ -11,6 +11,8 @@ import Box from 'components/base/Box'
import Input from 'components/base/Input' import Input from 'components/base/Input'
import Search from 'components/base/Search' import Search from 'components/base/Search'
import Triangles from './Triangles'
type Props = { type Props = {
items: Array<Object>, items: Array<Object>,
itemToString: Function, itemToString: Function,
@ -34,8 +36,6 @@ const TriggerBtn = styled(Box).attrs({
width: 100%; width: 100%;
color: ${p => p.theme.colors.steel}; color: ${p => p.theme.colors.steel};
background: ${p => p.theme.colors.white}; background: ${p => p.theme.colors.white};
border-bottom-left-radius: ${p => (p.isOpen ? 0 : '')};
border-bottom-right-radius: ${p => (p.isOpen ? 0 : '')};
&:focus { &:focus {
outline: none; outline: none;
box-shadow: rgba(0, 0, 0, 0.05) 0 2px 2px; box-shadow: rgba(0, 0, 0, 0.05) 0 2px 2px;
@ -99,6 +99,7 @@ class Select extends PureComponent<Props> {
fuseOptions, fuseOptions,
highlight, highlight,
renderHighlight, renderHighlight,
renderSelected,
onChange, onChange,
} = this.props } = this.props
@ -113,19 +114,16 @@ class Select extends PureComponent<Props> {
isOpen, isOpen,
inputValue, inputValue,
openMenu, openMenu,
selectedItem,
...downshiftProps ...downshiftProps
}) => ( }) => (
<Container {...getRootProps({ refKey: 'innerRef' })}> <Container {...getRootProps({ refKey: 'innerRef' })}>
{searchable ? ( {searchable ? (
<Input <Input keepEvent {...getInputProps({ placeholder: 'Chess?' })} onClick={openMenu} />
keepEvent
{...getInputProps({ placeholder: 'Chess?' })}
isOpen={isOpen}
onClick={openMenu}
/>
) : ( ) : (
<TriggerBtn isOpen={isOpen} {...getButtonProps()} tabIndex={0}> <TriggerBtn {...getButtonProps()} tabIndex={0} horizontal align="center" flow={2}>
lablala <Box grow>{renderSelected(selectedItem)}</Box>
<Triangles />
</TriggerBtn> </TriggerBtn>
)} )}
{isOpen && {isOpen &&

1
src/components/base/Select/stories.js

@ -58,6 +58,7 @@ stories.add('basic', () => (
<Select <Select
items={itemsChessPlayers} items={itemsChessPlayers}
itemToString={item => (item ? item.name : '')} itemToString={item => (item ? item.name : '')}
renderSelected={item => (item ? item.name : 'Choose a chess player')}
onChange={onChange} onChange={onChange}
/> />
)} )}

Loading…
Cancel
Save