Browse Source

style(ui): support right justify in dropdown

renovate/lint-staged-8.x
Tom Kirkpatrick 6 years ago
parent
commit
0375504f50
No known key found for this signature in database GPG Key ID: 72203A8EC5967EA8
  1. 13
      app/components/UI/Dropdown.js
  2. 1
      test/unit/components/UI/__snapshots__/Dropdown.spec.js.snap

13
app/components/UI/Dropdown.js

@ -14,7 +14,7 @@ const DropdownContainer = styled(Flex)({})
DropdownContainer.defaultProps = { DropdownContainer.defaultProps = {
flexDirection: 'column', flexDirection: 'column',
flexWrap: 'none', flexWrap: 'none',
display: 'relative' position: 'relative'
} }
/** /**
@ -36,14 +36,15 @@ DropdownButton.defaultProps = {
as: 'button', as: 'button',
m: 0, m: 0,
p: 0, p: 0,
textAlign: 'left' textAlign: 'left',
justify: 'left'
} }
/** /**
* Menu * Menu
*/ */
const MenuContainer = styled(Box)({ const MenuContainer = styled(Box)({
display: 'relative' position: 'relative'
}) })
const Menu = styled(Box)({ const Menu = styled(Box)({
@ -138,7 +139,7 @@ class Dropdown extends React.Component {
render() { render() {
const { isOpen } = this.state const { isOpen } = this.state
let { activeKey, items, theme, ...rest } = this.props let { activeKey, items, justify, theme, ...rest } = this.props
// coerce array of strings into array of objects. // coerce array of strings into array of objects.
items = items.map(item => { items = items.map(item => {
if (typeof item === 'string') { if (typeof item === 'string') {
@ -160,12 +161,12 @@ class Dropdown extends React.Component {
</DropdownButton> </DropdownButton>
{isOpen && ( {isOpen && (
<MenuContainer> <MenuContainer>
<Menu> <Menu css={justify === 'right' ? { right: 0 } : null}>
{items.map(item => { {items.map(item => {
return ( return (
<MenuItem key={item.key} onClick={() => this.onChange(item.key)}> <MenuItem key={item.key} onClick={() => this.onChange(item.key)}>
<Flex alignItems="center"> <Flex alignItems="center">
<Text width="18px"> <Text width="20px" textAlign="center">
{activeKey === item.key && ( {activeKey === item.key && (
<Check height="0.95em" color={theme.colors.superGreen} /> <Check height="0.95em" color={theme.colors.superGreen} />
)} )}

1
test/unit/components/UI/__snapshots__/Dropdown.spec.js.snap

@ -41,7 +41,6 @@ exports[`component.Dropdown should render correctly 1`] = `
<div <div
className="c0" className="c0"
display="relative"
onClick={[MockFunction]} onClick={[MockFunction]}
> >
<button <button

Loading…
Cancel
Save