This repository has been archived by the owner on Jul 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(components): ✨ created collapsible / accordion component
- Loading branch information
Showing
5 changed files
with
203 additions
and
116 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
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
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,56 @@ | ||
import React from 'react'; | ||
import styled from '@emotion/styled'; | ||
import { useTheme } from 'emotion-theming'; | ||
import Collapsible from 'react-collapsible'; | ||
import { ChevronUp, ChevronDown } from 'react-feather'; | ||
import { renderToStaticMarkup } from 'react-dom/server'; | ||
import emoji from '../../utils/emoji'; | ||
|
||
const CollapsibleWrapper = styled.div` | ||
margin: 10px 0; | ||
& > div { | ||
box-shadow: 0 0 6px 0 ${(props) => props.theme.header.shadow}; | ||
border-radius: 4px; | ||
& > span { | ||
&.is-open { | ||
border-bottom: 1px solid ${(props) => props.theme.colors.border}; | ||
&:after { | ||
content: url('data:image/svg+xml; utf8, ${(props) => props.openImg}'); | ||
} | ||
} | ||
&:hover { | ||
border: 1px solid ${(props) => props.theme.colors.primary + 'cc'}; | ||
padding: 15px; | ||
} | ||
&:after { | ||
content: url('data:image/svg+xml; utf8, ${(props) => props.closedImg}'); | ||
float: right; | ||
} | ||
font-weight: 500; | ||
padding: 16px; | ||
cursor: pointer; | ||
display: block; | ||
width: 100%; | ||
} | ||
& > div > div { | ||
padding: 8px 16px; | ||
} | ||
} | ||
`; | ||
|
||
export default ({title, titleWhenOpen, expanded, children, ...props}) => { | ||
const theme = useTheme(); | ||
const color = encodeURIComponent(theme.colors.primary); // replace # to not follow uri as usual | ||
const closed = renderToStaticMarkup(<ChevronDown size={22} color={color}/>) | ||
const open = renderToStaticMarkup(<ChevronUp size={22} color={color}/>) | ||
const triggerWhenOpen = titleWhenOpen ? titleWhenOpen : title; | ||
return ( | ||
<CollapsibleWrapper theme={theme} openImg={open} closedImg={closed}> | ||
<Collapsible lazyRender={true} trigger={emoji.emojify(title)} triggerWhenOpen={emoji.emojify(triggerWhenOpen)} {...props}> | ||
{children} | ||
</Collapsible> | ||
</CollapsibleWrapper> | ||
) | ||
}; |
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
Oops, something went wrong.