Skip to content

Commit da3aeb7

Browse files
committed
✨ feat: added flush prop to accordion, fixed storybook jumpiness
1 parent 22dabb9 commit da3aeb7

11 files changed

+546
-368
lines changed

.storybook/preview-body.html

+4-1
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@
4545
.sbdocs-body-light .sbdocs-preview-contrast .docs-story {
4646
background-color: var(--phork-contrast-color, #0060ce);
4747
}
48-
</style>
4948

49+
.sbdocs .docs-story > div:first-child {
50+
margin: 0 !important;
51+
}
52+
</style>
5053
<link href="/favicon/apple-touch-icon.png" rel="apple-touch-icon" sizes="180x180" />
5154
<link href="/favicon/favicon-32x32.png" rel="icon" sizes="32x32" type="image/png" />
5255
<link href="/favicon/favicon-16x16.png" rel="icon" sizes="16x16" type="image/png" />

package.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,15 @@
181181
"@semantic-release/exec": "^5.0.0",
182182
"@semantic-release/git": "^9.0.0",
183183
"@semantic-release/npm": "^7.1.0",
184-
"@storybook/addon-a11y": "^6.5.16",
185-
"@storybook/addon-actions": "^6.5.16",
186-
"@storybook/addon-essentials": "^6.5.16",
187-
"@storybook/addon-jest": "^6.5.16",
188-
"@storybook/addon-links": "^6.5.16",
184+
"@storybook/addon-a11y": "^6.5.17-alpha",
185+
"@storybook/addon-actions": "^6.5.17-alpha",
186+
"@storybook/addon-essentials": "^6.5.17-alpha",
187+
"@storybook/addon-jest": "^6.5.17-alpha",
188+
"@storybook/addon-links": "^6.5.17-alpha",
189189
"@storybook/addon-postcss": "^2.0.0",
190-
"@storybook/addons": "^6.5.16",
191-
"@storybook/react": "^6.5.16",
192-
"@storybook/theming": "^6.5.16",
190+
"@storybook/addons": "^6.5.17-alpha",
191+
"@storybook/react": "^6.5.17-alpha",
192+
"@storybook/theming": "^6.5.17-alpha",
193193
"@testing-library/dom": "^10.4.0",
194194
"@testing-library/jest-dom": "^6.5.0",
195195
"@testing-library/react": "^16.0.1",

src/compositions/Accordion/Accordion.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export type AccordionProps = Pick<
2323
InteractiveGroupProviderProps,
2424
'maxSelect' | 'minSelect' | 'initialSelected' | 'onSelect'
2525
> &
26-
Pick<AccordionListProps, 'duration' | 'easing' | 'items' | 'orientation' | 'unstyled' | 'variant'> &
26+
Pick<AccordionListProps, 'duration' | 'easing' | 'flush' | 'items' | 'orientation' | 'unstyled' | 'variant'> &
2727
ThemeProps & {
2828
children?: AccordionRenderChildren;
2929
className?: string;
@@ -34,6 +34,7 @@ export type AccordionProps = Pick<
3434
| 'contrast'
3535
| 'duration'
3636
| 'easting'
37+
| 'flush'
3738
| 'items'
3839
| 'onBlur'
3940
| 'onFocus'
@@ -74,6 +75,7 @@ export function Accordion({
7475
contrast = false,
7576
duration,
7677
easing,
78+
flush = false,
7779
id,
7880
initialSelected,
7981
items,
@@ -135,6 +137,7 @@ export function Accordion({
135137
contrast={contrast}
136138
duration={duration}
137139
easing={easing}
140+
flush={flush}
138141
items={items}
139142
onBlur={handleBlur}
140143
onFocus={handleFocus}

src/compositions/Accordion/AccordionLabel.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { AccordionItemStateProps } from './types';
99
export type LocalAccordionLabelProps = AccordionItemStateProps & {
1010
children: React.ReactChild | React.ReactFragment;
1111
className?: string;
12+
flush?: boolean;
1213
iconOnly?: boolean;
1314
id: string;
1415
orientation?: Orientation;
@@ -31,6 +32,7 @@ export function AccordionLabel({
3132
children,
3233
className,
3334
disabled = false,
35+
flush = false,
3436
focused = false,
3537
iconOnly = false,
3638
id,
@@ -52,6 +54,7 @@ export function AccordionLabel({
5254
: cx(
5355
styles.accordionLabel,
5456
styles[`accordionLabel--${orientation}`],
57+
flush && styles['accordionLabel--flush'],
5558
iconOnly && styles['accordionLabel--icon'],
5659
selected && styles['is-selected'],
5760
disabled && styles['is-disabled'],

src/compositions/Accordion/AccordionList.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export type AccordionListProps = React.HTMLAttributes<HTMLDivElement> &
2020
ThemeProps & {
2121
className?: string;
2222
componentId: string;
23+
flush?: boolean;
2324
items: readonly AccordionItemType[];
2425
onBlur?: (e: React.FocusEvent<HTMLDivElement>) => void;
2526
onFocus?: (e: React.FocusEvent<HTMLDivElement>) => void;
@@ -43,6 +44,7 @@ export const AccordionList = React.forwardRef<HTMLDivElement, AccordionListProps
4344
contrast = false,
4445
duration,
4546
easing,
47+
flush,
4648
items,
4749
onBlur,
4850
onFocus,
@@ -126,7 +128,9 @@ export const AccordionList = React.forwardRef<HTMLDivElement, AccordionListProps
126128
>
127129
<AccordionLabel
128130
aria-controls={generateComponentId(id, 'panel')}
131+
aria-disabled={disabled}
129132
aria-expanded={!!stateProps.selected}
133+
flush={flush}
130134
iconOnly={iconOnly}
131135
id={generateComponentId(id)}
132136
onClick={(event: React.MouseEvent<HTMLDivElement, MouseEvent> | React.TouchEvent<HTMLDivElement>) =>

src/compositions/Accordion/stories/Accordion.stories.tsx

+68-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { ComponentStory, ComponentMeta } from '@storybook/react';
22
import React from 'react';
3-
import { Rhythm } from 'components/Rhythm/Rhythm';
3+
import { PhorkIcon } from 'icons/PhorkIcon';
4+
import { Flex } from 'components/Flex';
5+
import { Rhythm } from 'components/Rhythm';
6+
import { Typography } from 'components/Typography';
47
import { Accordion, AccordionProps } from '../Accordion';
58
import { items } from './helpers/items';
69
import AccordionDocumentation from './Accordion.docs.mdx';
@@ -9,6 +12,11 @@ export default {
912
title: 'Surfaces/Accordion',
1013
component: Accordion,
1114
argTypes: {
15+
flush: {
16+
table: {
17+
category: 'Appearance',
18+
},
19+
},
1220
orientation: {
1321
table: {
1422
category: 'Appearance',
@@ -128,6 +136,7 @@ const Template: ComponentStory<typeof Accordion> = args => <Accordion {...args}
128136

129137
const defaultArgs = {
130138
contrast: false,
139+
flush: false,
131140
items,
132141
orientation: 'vertical' as AccordionProps['orientation'],
133142
unstyled: false,
@@ -213,6 +222,64 @@ AllowUnselect.args = {
213222
minSelect: 0,
214223
};
215224

225+
export const IconsOnly = Template.bind({});
226+
IconsOnly.storyName = 'Icons only';
227+
IconsOnly.args = {
228+
...defaultArgs,
229+
items: [
230+
{
231+
id: 'first',
232+
iconOnly: true,
233+
label: <PhorkIcon scale="medium" />,
234+
content: (
235+
<Rhythm ml={2}>
236+
<Flex full alignItems="center">
237+
<Typography variants="no-wrap">First panel</Typography>
238+
</Flex>
239+
</Rhythm>
240+
),
241+
},
242+
{
243+
id: 'second',
244+
iconOnly: true,
245+
label: <PhorkIcon scale="medium" />,
246+
content: (
247+
<Rhythm ml={2}>
248+
<Flex full alignItems="center">
249+
<Typography variants="no-wrap">Second panel</Typography>
250+
</Flex>
251+
</Rhythm>
252+
),
253+
},
254+
{
255+
id: 'third',
256+
iconOnly: true,
257+
label: <PhorkIcon scale="medium" />,
258+
content: (
259+
<Rhythm ml={2}>
260+
<Flex full alignItems="center">
261+
<Typography variants="no-wrap">Third panel</Typography>
262+
</Flex>
263+
</Rhythm>
264+
),
265+
disabled: true,
266+
},
267+
{
268+
id: 'fourth',
269+
iconOnly: true,
270+
label: <PhorkIcon scale="medium" />,
271+
content: (
272+
<Rhythm ml={2}>
273+
<Flex full alignItems="center">
274+
<Typography variants="no-wrap">Fourth panel</Typography>
275+
</Flex>
276+
</Rhythm>
277+
),
278+
},
279+
],
280+
orientation: 'horizontal',
281+
};
282+
216283
export const ItemFunctions = Template.bind({});
217284
ItemFunctions.storyName = 'Item functions';
218285
ItemFunctions.args = {

src/compositions/Accordion/styles/AccordionLabel.module.css

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ button.accordionLabel {
1313
text-decoration: none;
1414
user-select: none;
1515

16+
&.accordionLabel--flush {
17+
padding: 0;
18+
}
19+
1620
&.is-selected {
1721
color: var(--accordion-label-selected-text-color);
1822
}
@@ -59,7 +63,7 @@ button.accordionLabel {
5963
justify-content: center;
6064
line-height: normal;
6165

62-
&.accordion--icon {
66+
&.accordionLabel--icon {
6367
min-width: 36px;
6468
padding: 10px;
6569
}

src/compositions/Accordion/styles/AccordionList.module.css

-2
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,11 @@
6161
}
6262

6363
.accordionItem--vertical {
64-
border-bottom: 1px solid var(--accordion-item-border-color);
6564
flex-direction: column;
6665
width: 100%;
6766
}
6867

6968
.accordionItem--horizontal {
70-
border-right: 1px solid var(--accordion-item-border-color);
7169
flex-direction: row;
7270
flex-wrap: nowrap;
7371
min-height: 100%;

src/stories/Icons.stories.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { PageTitle } from 'stories/helpers/PageTitle';
2424
<Flex wrap>
2525
<IconLooper icons={icons}>
2626
{(name, Icon) => (
27-
<Rhythm key={name} m={2} px={4} py={2}>
27+
<Rhythm key={name} m={2} px={3} py={2}>
2828
<Paper bordered color="primary" style={{ borderRadius: 3 }}>
2929
<Typography size="large" variants={['letter-spacing-comfy']} volume="quiet" weight="light">
3030
{name}
@@ -53,7 +53,7 @@ import { PageTitle } from 'stories/helpers/PageTitle';
5353
<Flex wrap>
5454
<IconLooper icons={internal}>
5555
{(name, Icon) => (
56-
<Rhythm key={name} m={2} px={4} py={2}>
56+
<Rhythm key={name} m={2} px={3} py={2}>
5757
<Paper bordered color="primary" style={{ borderRadius: 3 }}>
5858
<Typography size="large" variants={['letter-spacing-comfy']} volume="quiet" weight="light">
5959
{name}

0 commit comments

Comments
 (0)