Skip to content

Commit

Permalink
fix(ListItemI): use ArrowToggle inside
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaevAlexandr committed Sep 3, 2024
1 parent 66027e7 commit 775dbce
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,12 @@ export const WithGroupSelectionAndCustomIconStory = ({
: expandButtonLabel,
}}
>
<ListItemExpandIcon
expanded={itemProps.content.expanded}
usageRole="action"
/>
<Button.Icon>
<ListItemExpandIcon
expanded={itemProps.content.expanded}
kind="action"
/>
</Button.Icon>
</Button>
) : undefined,
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,12 @@ export const WithItemLinksAndActionsStory = (props: WithItemLinksAndActionsStory
: expandButtonLabel,
}}
>
<ListItemExpandIcon
expanded={itemProps.content.expanded}
usageRole="action-inverse"
/>
<Button.Icon>
<ListItemExpandIcon
expanded={itemProps.content.expanded}
kind="action"
/>
</Button.Icon>
</Button>
) : (
<Flex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,12 @@ export const WithGroupSelectionControlledStateAndCustomIconExample = ({
}));
}}
>
<ListItemExpandIcon
expanded={props.content.expanded}
usageRole="action"
/>
<Button.Icon>
<ListItemExpandIcon
expanded={props.content.expanded}
kind="action"
/>
</Button.Icon>
</Button>
) : undefined,
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,12 @@ export const WithItemLinksAndActionsExample = (storyProps: WithItemLinksAndActio
}));
}}
>
<ListItemExpandIcon
expanded={props.content.expanded}
usageRole="state"
/>
<Button.Icon>
<ListItemExpandIcon
expanded={props.content.expanded}
kind="state"
/>
</Button.Icon>
</Button>
) : (
<Flex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,7 @@ $block: '.#{variables.$ns}list-item-expand-icon';
#{$block} {
flex-shrink: 0;

transition: transform 0.1s ease;

&_disableTransition {
transition: none;
}

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

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

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

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

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

&_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
@@ -1,8 +1,7 @@
import React from 'react';

import {ChevronDown} from '@gravity-ui/icons';

import {Icon} from '../../../Icon';
import type {ArrowToggleProps} from '../../../ArrowToggle';
import {ArrowToggle} from '../../../ArrowToggle';
import {colorText} from '../../../Text';
import {block} from '../../../utils/cn';
import type {ListItemExpandIconRenderProps} from '../../types';
Expand All @@ -16,20 +15,35 @@ export interface ListItemExpandIconProps extends ListItemExpandIconRenderProps {
export const ListItemExpandIcon = ({
expanded,
disableTransition,
usageRole: usage = 'action',
kind = 'action',
disabled,
}: ListItemExpandIconProps) => {
return (
<Icon
className={b(
{expanded, disableTransition, usage},
colorText({color: disabled ? 'hint' : undefined}),
)}
data={ChevronDown}
<ArrowToggle
direction={getIconDirection({kind, expanded})}
className={b({disableTransition}, colorText({color: disabled ? 'hint' : undefined}))}
size={16}
/>
);
};

// For correct rendering inside `Button` component
ListItemExpandIcon.displayName = 'Icon';
function getIconDirection({
kind,
expanded,
}: Pick<ListItemExpandIconRenderProps, 'expanded' | 'kind'>): ArrowToggleProps['direction'] {
if (expanded && kind === 'action') {
return 'top';
} else if (expanded && kind === 'state') {
return 'bottom';
} else if (expanded && kind === 'state-inverse') {
return 'bottom';
} else if (kind === 'action') {
return 'bottom';
} else if (kind === 'state') {
return 'right';
} else if (kind === 'state-inverse') {
return 'left';
}

return 'bottom';
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ const InsideButtonExample = (props: ListItemExpandIconProps) => {

return (
<Button extraProps={{'aria-label': 'toggle-button'}} onClick={() => setExpanded((x) => !x)}>
<ListItemExpandIcon {...props} expanded={expanded} />
<Button.Icon>
<ListItemExpandIcon {...props} expanded={expanded} />
</Button.Icon>
</Button>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ const InsideButtonExample = (props: ListItemExpandIconProps) => {

return (
<Button onClick={() => setExpanded((x) => !x)}>
<ListItemExpandIcon {...props} expanded={expanded} />
<Button.Icon>
<ListItemExpandIcon {...props} expanded={expanded} />
</Button.Icon>
</Button>
);
};
Expand All @@ -39,9 +41,9 @@ const InsideButtonExample = (props: ListItemExpandIconProps) => {

#### 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` | |
| Name | Description | Type | Default |
| :---------------- | :---------------------------------------------- | :-------------------------------: | :-----: |
| expanded | icon state | `boolean` | |
| disableTransition | disable animation while `expanded` state change | `boolean` | |
| disabled | disabled view type | `boolean` | |
| kind | The type of behavior of the component | `state`, `state-inverse`,`action` | |
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ export const ListItemViewContent = ({
expanded,
selected,
title,
expandIconPosition = 'start',
expandIconPlacement = 'start',
renderExpandIcon: RenderExpandIcon = ListItemExpandIcon,
}: ListItemViewContentProps) => {
const expandIconNode = isGroup ? (
<RenderExpandIcon
usageRole={expandIconPosition === 'start' ? 'state' : 'action'}
kind={expandIconPlacement === 'start' ? 'state' : 'action'}
expanded={expanded}
disabled={disabled}
/>
Expand All @@ -83,7 +83,7 @@ export const ListItemViewContent = ({

{renderSafeIndentation(indentation)}

{expandIconPosition === 'start' && expandIconNode}
{expandIconPlacement === 'start' && expandIconNode}

{startSlot}

Expand All @@ -110,7 +110,7 @@ export const ListItemViewContent = ({
</Flex>

<Flex gap="2">
{expandIconPosition === 'end' && expandIconNode}
{expandIconPlacement === 'end' && expandIconNode}
{endSlot}
</Flex>
</Flex>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ const stories: ListItemViewProps[] = [
indentation: 1,
isGroup: true,
expanded: false,
expandIconPosition: 'end',
expandIconPlacement: 'end',
},
},
{
Expand All @@ -254,10 +254,12 @@ const stories: ListItemViewProps[] = [
title: 'Custom icon end',
isGroup: true,
expanded: false,
expandIconPosition: 'end',
expandIconPlacement: 'end',
renderExpandIcon: (props) => (
<Button view="flat" extraProps={{'aria-label': 'toggle-button'}}>
<ListItemExpandIcon {...props} />
<Button.Icon>
<ListItemExpandIcon {...props} />
</Button.Icon>
</Button>
),
},
Expand Down
7 changes: 4 additions & 3 deletions src/components/useList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ export interface ListItemExpandIconRenderProps {
* - 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;
kind: 'state' | 'state-inverse' | 'action';

disableTransition?: boolean;
expanded?: boolean;
disabled?: boolean;
}

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

0 comments on commit 775dbce

Please sign in to comment.