Skip to content

Commit

Permalink
feat(ListItemExpandIcon): aded usage types
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaevAlexandr committed Aug 22, 2024
1 parent 61b8335 commit d59a42c
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export const WithGroupSelectionAndCustomIconStory = ({
>
<ListItemExpandIcon
expanded={itemProps.content.expanded}
position="end"
usageRole="action"
/>
</Button>
) : undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ export const WithItemLinksAndActionsStory = (props: WithItemLinksAndActionsStory
: expandButtonLabel,
}}
>
<ListItemExpandIcon expanded={itemProps.content.expanded} />
<ListItemExpandIcon
expanded={itemProps.content.expanded}
usageRole="action-inverse"
/>
</Button>
) : (
<Flex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const WithGroupSelectionControlledStateAndCustomIconExample = ({
>
<ListItemExpandIcon
expanded={props.content.expanded}
position="end"
usageRole="action"
/>
</Button>
) : undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ export const WithItemLinksAndActionsExample = (storyProps: WithItemLinksAndActio
}));
}}
>
<ListItemExpandIcon expanded={props.content.expanded} />
<ListItemExpandIcon
expanded={props.content.expanded}
usageRole="state"
/>
</Button>
) : (
<Flex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,36 @@ $block: '.#{variables.$ns}list-item-expand-icon';
transition: none;
}

&_position_start {
&_usage_state {
transform: rotate(-90deg);

&#{$block}_expanded {
transform: rotate(0deg);
}
}
&_usage_state-inverse {
transform: rotate(90deg);

&#{$block}_expanded {
transform: rotate(0deg);
}
}

&_position_end {
transform: rotate(180deg);
&_usage_action {
transform: rotate(0deg);
transition: transform 0.2s ease;

&#{$block}_expanded {
transform: rotate(180deg);
}
}

&_expanded {
&_usage_action-inverse {
transform: rotate(0deg);
transition: transform 0.2s ease;

&#{$block}_expanded {
transform: rotate(-180deg);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ import './ListItemExpandIcon.scss';

const b = block('list-item-expand-icon');

export interface ListItemExpandIconProps extends Partial<ListItemExpandIconRenderProps> {}
export interface ListItemExpandIconProps extends ListItemExpandIconRenderProps {}

export const ListItemExpandIcon = ({
expanded,
disableTransition,
position = 'start',
usageRole: usage = 'action',
disabled,
}: ListItemExpandIconProps) => {
return (
<Icon
className={b(
{expanded, disableTransition, position},
{expanded, disableTransition, usage},
colorText({color: disabled ? 'hint' : undefined}),
)}
data={ChevronDown}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import React from 'react';
import type {Meta, StoryObj} from '@storybook/react';

import {Button} from '../../../../Button';
import {RadioButton} from '../../../../RadioButton';
import {Text} from '../../../../Text';
import {Flex} from '../../../../layout';
import type {ListItemExpandIconProps} from '../ListItemExpandIcon';
import {ListItemExpandIcon} from '../ListItemExpandIcon';

Expand All @@ -18,52 +15,21 @@ export default meta;

type Story = StoryObj<typeof ListItemExpandIcon>;

const DefaultExample = (props: ListItemExpandIconProps) => {
return <ListItemExpandIcon {...props} />;
};

export const Default = {
render: (args) => (
<Flex gap="5">
<Flex direction="column" gap="2">
<Text>Position: start</Text>
<Flex gap="2">
<ListItemExpandIcon {...args} expanded={true} />
<ListItemExpandIcon {...args} expanded={false} />
</Flex>
</Flex>
<Flex direction="column" gap="2">
<Text>Position: start</Text>
<Flex gap="2">
<ListItemExpandIcon {...args} expanded={true} position="end" />
<ListItemExpandIcon {...args} expanded={false} position="end" />
</Flex>
</Flex>
</Flex>
),
render: DefaultExample,
} satisfies Story;

const InsideButtonExample = (props: ListItemExpandIconProps) => {
const [expanded, setExpanded] = React.useState(false);
const [position, setPosition] = React.useState<'start' | 'end'>('start');

return (
<Flex direction="column" gap="3">
<Flex gap="3" alignItems="center">
<Text>Icon position: </Text>
<RadioButton
size="m"
value={position}
onUpdate={setPosition}
options={[
{value: 'start', content: 'Start'},
{value: 'end', content: 'End'},
]}
/>
</Flex>

<Text>Click on button to change state:</Text>

<Button onClick={() => setExpanded((x) => !x)}>
<ListItemExpandIcon {...props} expanded={expanded} position={position} />
</Button>
</Flex>
<Button extraProps={{'aria-label': 'toggle-button'}} onClick={() => setExpanded((x) => !x)}>
<ListItemExpandIcon {...props} expanded={expanded} />
</Button>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,57 +14,34 @@ import {
#### Base example:

```jsx
<Flex gap="5">
<Flex direction="column" gap="2">
<Text>Position: start</Text>
<Flex gap="2">
<ListItemExpandIcon expanded={true} />
<ListItemExpandIcon expanded={false} />
</Flex>
</Flex>
<Flex direction="column" gap="2">
<Text>Position: start</Text>
<Flex gap="2">
<ListItemExpandIcon expanded={true} position="end" />
<ListItemExpandIcon expanded={false} position="end" />
</Flex>
</Flex>
</Flex>
const DefaultExample = (props: ListItemExpandIconProps) => {
return <ListItemExpandIcon {...props} />;
};
```

<ListItemExpandIconDefault />

#### Render icon inside Button component:

```jsx

const InsideButtonExample = (props: ListItemExpandIconProps) => {
const [expanded, setExpanded] = React.useState(false);
const [position, setPosition] = React.useState<'start' | 'end'>('start');

return (
<Flex direction="column" gap="3">
<Flex gap="3" alignItems="center">
<Text>Icon position: </Text>
<RadioButton
size="m"
value={position}
onUpdate={setPosition}
options={[
{value: 'start', content: 'Start'},
{value: 'end', content: 'End'},
]}
/>
</Flex>

<Text>Click on button to change state:</Text>

<Button onClick={() => setExpanded((x) => !x)}>
<ListItemExpandIcon expanded={expanded} position={position} />
</Button>
</Flex>
<Button onClick={() => setExpanded((x) => !x)}>
<ListItemExpandIcon {...props} expanded={expanded} />
</Button>
);
};
```

<ListItemExpandIconInsideButton />

#### Props

| Name | Description | Type | Default |
| :---------------- | :---------------------------------------------- | :--------------------------------------------------: | :-----: |
| expanded | icon state | `boolean` | |
| disableTransition | disable animation while `expanded` state change | `boolean` | |
| disabled | disabled view type | `boolean` | |
| usageRole | The type of behavior of the component | `state`, `action`, `state-inverse`, `action-inverse` | |
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,9 @@ export const ListItemViewContent = ({
}: ListItemViewContentProps) => {
const expandIconNode = isGroup ? (
<RenderExpandIcon
position={expandIconPosition}
usageRole={expandIconPosition === 'start' ? 'state' : 'action'}
expanded={expanded}
disabled={disabled}
disableTransition={undefined}
/>
) : null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ const stories: ListItemViewProps[] = [
expanded: false,
expandIconPosition: 'end',
renderExpandIcon: (props) => (
<Button view="flat">
<Button view="flat" extraProps={{'aria-label': 'toggle-button'}}>
<ListItemExpandIcon {...props} />
</Button>
),
Expand Down
18 changes: 11 additions & 7 deletions src/components/useList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,17 @@ export type ItemState = {
indentation: number;
};

type ExpandIconPositionType = 'start' | 'end';

export interface ListItemExpandIconRenderProps {
position: ExpandIconPositionType;
expanded: boolean | undefined;
disableTransition: boolean | undefined;
disabled: boolean | undefined;
/**
* The type of behavior of the component
*
* - action - to indicate user actions. For example, for an icon inside a button;
* - state - to indicate the current state of the element;
*/
usageRole: 'state' | 'action' | 'state-inverse' | 'action-inverse';
expanded?: boolean;
disableTransition?: boolean;
disabled?: boolean;
}

export type ListItemViewContentType = {
Expand All @@ -65,7 +69,7 @@ export type ListItemViewContentType = {
/**
* @default - 'start'
*/
expandIconPosition?: ExpandIconPositionType;
expandIconPosition?: 'start' | 'end';
/**
* Will be applied if `isGroup` props is `true`
*/
Expand Down

0 comments on commit d59a42c

Please sign in to comment.