-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'styled-components' of https://github.com/cmpsr/composer …
…into styled-snackbar * 'styled-components' of https://github.com/cmpsr/composer: Styled Tooltip (#169) Styled Modal Improvements (#176) Styled Dropdown (#167) Styled Modal (#173)
- Loading branch information
Showing
24 changed files
with
888 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
packages/styled-components/src/components/Components.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export enum Shapes { | ||
Rounded = 'rounded', | ||
SemiRounded = 'semiRounded', | ||
Rectangle = 'rectangle' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 3 additions & 8 deletions
11
packages/styled-components/src/components/primitives/Button/Button.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
packages/styled-components/src/components/primitives/Dropdown/Dropdown.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import React from 'react'; | ||
import { Dropdown } from '.'; | ||
import { text } from '@storybook/addon-knobs'; | ||
import { LinkItem } from 'components/primitives/List/Items'; | ||
import { favorite as Favorite, Icon } from 'components/primitives/Icon'; | ||
import styled from 'styled-components'; | ||
|
||
export default { | ||
title: 'Primitives/Dropdown', | ||
component: Dropdown, | ||
}; | ||
|
||
export const Titles = () => ( | ||
<> | ||
<h1>Titles</h1> | ||
<Dropdown title="Title"> | ||
<LinkItem title="title" /> | ||
<LinkItem title="title" /> | ||
<LinkItem title="title" /> | ||
<LinkItem title="title" /> | ||
</Dropdown> | ||
</> | ||
); | ||
|
||
export const Icons = () => ( | ||
<> | ||
<h1>Icons</h1> | ||
<Dropdown title="Title"> | ||
<LinkItem title="title" icon={<Favorite type={Icon.Types.Filled} />} /> | ||
<LinkItem title="title" icon={<Favorite type={Icon.Types.Filled} />} /> | ||
<LinkItem title="title" icon={<Favorite type={Icon.Types.Filled} />} /> | ||
<LinkItem title="title" icon={<Favorite type={Icon.Types.Filled} />} /> | ||
</Dropdown> | ||
</> | ||
); | ||
|
||
const StyledFlex = styled.div` | ||
display: flex; | ||
`; | ||
export const Columns = () => ( | ||
<> | ||
<h1>Columns</h1> | ||
<Dropdown title="Title"> | ||
<StyledFlex> | ||
<div> | ||
{' '} | ||
<LinkItem | ||
title="title" | ||
icon={<Favorite type={Icon.Types.Filled} />} | ||
/> | ||
<LinkItem | ||
title="title" | ||
icon={<Favorite type={Icon.Types.Filled} />} | ||
/> | ||
<LinkItem | ||
title="title" | ||
icon={<Favorite type={Icon.Types.Filled} />} | ||
/> | ||
<LinkItem | ||
title="title" | ||
icon={<Favorite type={Icon.Types.Filled} />} | ||
/> | ||
</div> | ||
<div> | ||
{' '} | ||
<LinkItem | ||
title="title" | ||
icon={<Favorite type={Icon.Types.Filled} />} | ||
/> | ||
<LinkItem | ||
title="title" | ||
icon={<Favorite type={Icon.Types.Filled} />} | ||
/> | ||
<LinkItem | ||
title="title" | ||
icon={<Favorite type={Icon.Types.Filled} />} | ||
/> | ||
<LinkItem | ||
title="title" | ||
icon={<Favorite type={Icon.Types.Filled} />} | ||
/> | ||
</div> | ||
</StyledFlex> | ||
</Dropdown> | ||
</> | ||
); | ||
|
||
export const Playground = () => ( | ||
<> | ||
<h1>Playground</h1> | ||
<Dropdown title={text('Title', 'Title')}> | ||
{text('Content', 'Content')} | ||
</Dropdown> | ||
</> | ||
); |
23 changes: 23 additions & 0 deletions
23
packages/styled-components/src/components/primitives/Dropdown/Dropdown.styled.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import styled from 'styled-components'; | ||
import { Icon } from 'components/primitives/Icon'; | ||
import { List } from 'components/primitives/List'; | ||
|
||
export const StyledWrapper = styled.div` | ||
position: relative; | ||
`; | ||
|
||
export const StyledAnchor = styled.a` | ||
display: flex; | ||
align-items: middle; | ||
flex: 1 1 0%; | ||
`; | ||
|
||
export const StyledIcon = styled(Icon)` | ||
fill: currentColor; | ||
margin-left: 0.5rem; | ||
pointer-events: none; | ||
`; | ||
|
||
export const StyledList = styled(List)` | ||
min-width: 10rem; | ||
`; |
38 changes: 38 additions & 0 deletions
38
packages/styled-components/src/components/primitives/Dropdown/Dropdown.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from 'react'; | ||
import { render, fireEvent, screen } from '@testing-library/react'; | ||
import { Dropdown } from './Dropdown'; | ||
|
||
describe('Dropdown', () => { | ||
it('should render children when dropdown is open', () => { | ||
render( | ||
<Dropdown title="title"> | ||
<div>foo</div> | ||
</Dropdown> | ||
); | ||
const expandMore = screen.getByTestId('expandMore'); | ||
fireEvent.click(expandMore); | ||
screen.getByText('foo'); | ||
}); | ||
it('should render title', () => { | ||
render(<Dropdown title="foo" />); | ||
screen.getByText('foo'); | ||
}); | ||
it('should render ExpandMore icon', () => { | ||
render(<Dropdown title="title" />); | ||
screen.getByTestId('expandMore'); | ||
}); | ||
it('should render ExpandLess icon on click', () => { | ||
render(<Dropdown title="title" />); | ||
const expandMore = screen.getByTestId('expandMore'); | ||
fireEvent.click(expandMore); | ||
screen.getByTestId('expandLess'); | ||
}); | ||
it('should close menu when click outside', () => { | ||
render(<Dropdown title="title" />); | ||
const expandMore = screen.getByTestId('expandMore'); | ||
fireEvent.click(expandMore); | ||
screen.getByTestId('expandLess'); | ||
fireEvent.click(document); | ||
screen.getByTestId('expandMore'); | ||
}); | ||
}); |
58 changes: 58 additions & 0 deletions
58
packages/styled-components/src/components/primitives/Dropdown/Dropdown.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React, { useState, useEffect, useRef } from 'react'; | ||
import { Icon, Typography } from 'components/primitives'; | ||
import { | ||
expand_more as ExpandMore, | ||
expand_less as ExpandLess, | ||
} from 'components/primitives/Icon'; | ||
import { Props } from './Dropdown.types'; | ||
import { | ||
StyledWrapper, | ||
StyledAnchor, | ||
StyledIcon, | ||
StyledList, | ||
} from './Dropdown.styled'; | ||
|
||
export const Dropdown = ({ | ||
title, | ||
className, | ||
children, | ||
testId = 'dropdown', | ||
}: Props) => { | ||
const node = useRef(null); | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
useEffect(() => { | ||
const handleClose = (e) => { | ||
if (node.current && !node.current.contains(e.target)) { | ||
setIsOpen(false); | ||
} | ||
}; | ||
|
||
document.addEventListener('click', handleClose); | ||
return () => { | ||
document.removeEventListener('click', handleClose); | ||
}; | ||
}, [node]); | ||
|
||
return ( | ||
<StyledWrapper ref={node} data-testid={testId}> | ||
<StyledAnchor | ||
className={className} | ||
role="button" | ||
onClick={() => setIsOpen((isOpen) => !isOpen)} | ||
> | ||
<Typography tag={Typography.Tags.Span} type={Typography.Types.Body}> | ||
{title} | ||
</Typography> | ||
<StyledIcon testId={isOpen ? 'expandLess' : 'expandMore'}> | ||
{isOpen ? ( | ||
<ExpandLess type={Icon.Types.Filled} /> | ||
) : ( | ||
<ExpandMore type={Icon.Types.Filled} /> | ||
)} | ||
</StyledIcon> | ||
</StyledAnchor> | ||
{isOpen && <StyledList>{children}</StyledList>} | ||
</StyledWrapper> | ||
); | ||
}; |
8 changes: 8 additions & 0 deletions
8
packages/styled-components/src/components/primitives/Dropdown/Dropdown.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { ReactNode } from 'react'; | ||
|
||
export type Props = { | ||
title: string; | ||
className?: string; | ||
children?: ReactNode; | ||
testId?: string; | ||
}; |
1 change: 1 addition & 0 deletions
1
packages/styled-components/src/components/primitives/Dropdown/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './Dropdown'; |
Oops, something went wrong.