Skip to content

Commit 884d10a

Browse files
tassoevanggazzo
authored andcommitted
feat: Accordion.Item pointer interactions and new variants (#77)
1 parent f8933ef commit 884d10a

8 files changed

+60
-21
lines changed

packages/fuselage/.storybook/jest-results.json

+1-1
Large diffs are not rendered by default.

packages/fuselage/src/components/Accordion/Item.js

+15-9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const Item = React.forwardRef(function Item({
1515
expanded,
1616
tabIndex = 0,
1717
title,
18+
noncollapsible = !title,
1819
onToggle,
1920
onToggleEnabled,
2021
...props
@@ -33,6 +34,8 @@ export const Item = React.forwardRef(function Item({
3334
return;
3435
}
3536

37+
event.currentTarget.blur();
38+
3639
if (onToggle) {
3740
return onToggle.call(event.currentTarget, event);
3841
}
@@ -65,24 +68,27 @@ export const Item = React.forwardRef(function Item({
6568
};
6669

6770
return <StyledAccordionItem theme={theme} {...props}>
68-
<Bar
71+
{title && <Bar
6972
aria-checked={expanded || internalExpanded ? 'true' : 'false'}
7073
className={classNames.bar}
7174
disabled={disabled}
7275
expanded={expanded || internalExpanded}
76+
noncollapsible={noncollapsible}
7377
ref={ref}
7478
role='switch'
75-
tabIndex={!disabled ? tabIndex : undefined}
79+
tabIndex={!disabled && !noncollapsible ? tabIndex : undefined}
7680
theme={theme}
77-
onClick={handleClick}
78-
onKeyDown={handleKeyDown}
81+
onClick={noncollapsible ? undefined : handleClick}
82+
onKeyDown={noncollapsible ? undefined : handleKeyDown}
7983
>
8084
<Title className={classNames.bar} theme={theme}>{title}</Title>
81-
{(disabled || onToggleEnabled)
85+
{!noncollapsible && <>
86+
{(disabled || onToggleEnabled)
8287
&& <ToggleSwitch checked={!disabled} onClick={handleToggleClick} onChange={onToggleEnabled} />}
83-
<Icon name={'arrow-down'} />
84-
</Bar>
85-
<Panel className={classNames.panel} expanded={expanded || internalExpanded} theme={theme}>
88+
<Icon name={'arrow-down'} />
89+
</>}
90+
</Bar>}
91+
<Panel className={classNames.panel} expanded={noncollapsible || expanded || internalExpanded} theme={theme}>
8692
{children}
8793
</Panel>
8894
</StyledAccordionItem>;
@@ -100,7 +106,7 @@ Item.propTypes = {
100106
disabled: PropTypes.bool,
101107
expanded: PropTypes.bool,
102108
tabIndex: PropTypes.number,
103-
title: PropTypes.string.isRequired,
109+
title: PropTypes.string,
104110
onToggle: PropTypes.func,
105111
onToggleEnabled: PropTypes.func,
106112
};

packages/fuselage/src/components/Accordion/Item.stories.mdx

+29
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { action } from '@storybook/addon-actions';
22
import { Meta, Preview, Props, Story } from '@storybook/addon-docs/blocks';
3+
import LinkTo from '@storybook/addon-links/react';
34

45
import { Accordion, Paragraph } from '../..';
56

@@ -33,6 +34,34 @@ A collapsible panel.
3334
</Story>
3435
</Preview>
3536

37+
## Noncollapsible
38+
39+
<Preview>
40+
<Story name='Noncollapsible'>
41+
<Accordion>
42+
<Accordion.Item title='Item' noncollapsible>
43+
<Paragraph>Content</Paragraph>
44+
</Accordion.Item>
45+
</Accordion>
46+
</Story>
47+
</Preview>
48+
49+
### Without title
50+
51+
When the `title` prop is omitted, its implied that
52+
the <LinkTo kind='Containers|Accordion/Accordion.Item' story='Default Story'>`Accordion.Item`</LinkTo>
53+
is <LinkTo kind='Containers|Accordion/Accordion.Item' story='Noncollapsible'>noncollapsible</LinkTo> too.
54+
55+
<Preview>
56+
<Story name='Without Title'>
57+
<Accordion>
58+
<Accordion.Item>
59+
<Paragraph>Content</Paragraph>
60+
</Accordion.Item>
61+
</Accordion>
62+
</Story>
63+
</Preview>
64+
3665
## With togglable state
3766

3867
### Enabled

packages/fuselage/src/components/Accordion/styles.js

+15-11
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const Bar = styled.div`
4040
4141
text-align: left;
4242
43-
${ ({ disabled }) => !disabled && css`
43+
${ ({ disabled, noncollapsible }) => !disabled && !noncollapsible && css`
4444
${ clickable }
4545
` }
4646
@@ -56,16 +56,20 @@ export const Bar = styled.div`
5656
` }
5757
}
5858
59-
&.hover,
60-
&:hover {
61-
background-color: ${ colors.dark100 };
62-
}
63-
64-
&.focus,
65-
&:focus {
66-
border-color: ${ colors.blue500 };
67-
box-shadow: 0 0 0 ${ toRem(6) } ${ colors.blue100 };
68-
}
59+
${ ({ disabled, noncollapsible }) => !disabled && !noncollapsible && css`
60+
&.focus,
61+
&:focus {
62+
border-color: ${ colors.blue500 };
63+
box-shadow: 0 0 0 ${ toRem(6) } ${ colors.blue100 };
64+
}
65+
66+
&.hover,
67+
&:hover {
68+
border-color: ${ colors.dark300 } transparent transparent;
69+
background-color: ${ colors.dark100 };
70+
box-shadow: none;
71+
}
72+
` }
6973
7074
${ ({ disabled, theme }) => disabled && css`
7175
color: ${ theme.textColors.disabled };

0 commit comments

Comments
 (0)