-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/accordion #60
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
768c204
add accordion
olahepelto f695ccb
started work on accordion
olahepelto d31c86a
work on accordion
olahepelto ef9b3a4
accordion
olahepelto dd7f43b
accordion
olahepelto efd5f5f
fix
olahepelto d40e15e
fix typo
olahepelto ca1934c
fix
olahepelto 6d85b89
fix
olahepelto 2d0802e
fix pr
olahepelto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React from 'react'; | ||
import { Meta, StoryFn } from '@storybook/react'; | ||
import { withDesign } from 'storybook-addon-designs'; | ||
import { Accordion, AccordionProps } from './Accordion'; | ||
|
||
// More on default export: https://storybook.js.org/docs/react/writing-stories/introduction#default-export | ||
export default { | ||
title: 'Components/Accordion', | ||
component: Accordion, | ||
// More on argTypes: https://storybook.js.org/docs/react/api/argtypes | ||
args: { | ||
title: <h3>Accordion Title</h3>, | ||
}, | ||
parameters: { | ||
design: [ | ||
{ | ||
name: 'light', | ||
type: 'figma', | ||
url: 'https://www.figma.com/file/qUvylGh5ubOWlpqlplVORt/IZ-Design-System---%F0%9F%9A%80-Live?type=design&node-id=3261%3A4322&mode=design&t=nkOlaGT8Xge4iBwT-1', | ||
}, | ||
{ | ||
name: 'dark', | ||
type: 'figma', | ||
url: 'https://www.figma.com/file/qUvylGh5ubOWlpqlplVORt/IZ-Design-System---%F0%9F%9A%80-Live?type=design&node-id=3407%3A10656&mode=design&t=nkOlaGT8Xge4iBwT-1', | ||
}, | ||
], | ||
}, | ||
decorators: [withDesign], | ||
} as Meta<typeof Accordion>; | ||
|
||
/* | ||
* Example Dialog story | ||
*/ | ||
const ExampleAccordion = ({ ...restProps }: AccordionProps) => { | ||
return ( | ||
<Accordion {...restProps}> | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod | ||
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim | ||
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea | ||
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate | ||
velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat | ||
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id | ||
est laborum. | ||
</Accordion> | ||
); | ||
}; | ||
|
||
// More on component templates: https://storybook.js.org/docs/react/writing-stories/introduction#using-args | ||
const Template: StoryFn<typeof Accordion> = (args) => ( | ||
<ExampleAccordion {...args}></ExampleAccordion> | ||
); | ||
|
||
/** | ||
* Default variant (not specified) | ||
*/ | ||
export const DefaultVariant = Template.bind({}); | ||
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,86 @@ | ||
import React, { useState } from 'react'; | ||
import styled from 'styled-components'; | ||
import { pxToRem, ComponentBaseProps } from '../../shared'; | ||
import { MdKeyboardArrowDown, MdKeyboardArrowUp } from 'react-icons/md'; | ||
|
||
/** | ||
* Dimensions of accordion component | ||
*/ | ||
const accordionDimensions = { | ||
accordionTitle: { | ||
paddingTop: 16, | ||
paddingRight: 16, | ||
paddingBottom: 16, | ||
paddingLeft: 24, | ||
}, | ||
accordionContent: { | ||
paddingTop: 0, | ||
paddingRight: 24, | ||
paddingBottom: 24, | ||
paddingLeft: 24, | ||
}, | ||
}; | ||
|
||
/** | ||
* Accordion component properties | ||
* Extends html div element attributes | ||
*/ | ||
export interface AccordionProps extends ComponentBaseProps<HTMLDivElement> { | ||
/** | ||
* Accordion title | ||
*/ | ||
title?: React.ReactNode; | ||
|
||
/** | ||
* Children | ||
*/ | ||
children: React.ReactNode; | ||
} | ||
|
||
const InternalAccordion = styled.div<AccordionProps>` | ||
background-color: ${(props) => props.theme.colors.grayScale.digitalBlack100}; | ||
`; | ||
|
||
const AccordionTitle = styled.div<AccordionProps>` | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: space-between; | ||
cursor: pointer; | ||
user-select: none; | ||
padding: ${pxToRem(accordionDimensions.accordionTitle.paddingTop)} | ||
${pxToRem(accordionDimensions.accordionTitle.paddingRight)} | ||
${pxToRem(accordionDimensions.accordionTitle.paddingBottom)} | ||
${pxToRem(accordionDimensions.accordionTitle.paddingLeft)}; | ||
`; | ||
const AccordionContent = styled.div<AccordionProps>` | ||
padding: ${pxToRem(accordionDimensions.accordionContent.paddingTop)} | ||
${pxToRem(accordionDimensions.accordionContent.paddingRight)} | ||
${pxToRem(accordionDimensions.accordionContent.paddingBottom)} | ||
${pxToRem(accordionDimensions.accordionContent.paddingLeft)}; | ||
`; | ||
const AccordionArrow = styled.div<AccordionProps>` | ||
olahepelto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
align-self: center; | ||
`; | ||
|
||
/** | ||
* Accordion component | ||
*/ | ||
export const Accordion = ({ | ||
children, | ||
title, | ||
...restProps | ||
}: AccordionProps) => { | ||
const [accordionIsOpen, setAccordionOpen] = useState(false); | ||
return ( | ||
<InternalAccordion {...restProps}> | ||
<AccordionTitle onClick={() => setAccordionOpen(!accordionIsOpen)}> | ||
{title} | ||
olahepelto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<AccordionArrow> | ||
{accordionIsOpen && <MdKeyboardArrowUp />} | ||
{!accordionIsOpen && <MdKeyboardArrowDown />} | ||
</AccordionArrow> | ||
</AccordionTitle> | ||
{accordionIsOpen && <AccordionContent>{children}</AccordionContent>} | ||
</InternalAccordion> | ||
); | ||
}; |
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 './Accordion'; |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './Accordion'; | ||
export * from './Box'; | ||
export * from './Button'; | ||
export * from './Card'; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jatkeeksi voisi tehdä storyn, jossa on useampi accordion kerralla näkyvissä.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lisätty