-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ListItemExandIcon): added new list component for expanded icon v…
…iew (#1762)
- Loading branch information
1 parent
2d9c88e
commit b6516f4
Showing
19 changed files
with
288 additions
and
55 deletions.
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
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
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
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
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
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
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
7 changes: 7 additions & 0 deletions
7
src/components/useList/components/ListItemExpandIcon/ListItemExpandIcon.scss
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,7 @@ | ||
@use '../../../variables'; | ||
|
||
$block: '.#{variables.$ns}list-item-expand-icon'; | ||
|
||
#{$block} { | ||
flex-shrink: 0; | ||
} |
48 changes: 48 additions & 0 deletions
48
src/components/useList/components/ListItemExpandIcon/ListItemExpandIcon.tsx
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,48 @@ | ||
import React from 'react'; | ||
|
||
import type {ArrowToggleProps} from '../../../ArrowToggle'; | ||
import {ArrowToggle} from '../../../ArrowToggle'; | ||
import {colorText} from '../../../Text'; | ||
import {block} from '../../../utils/cn'; | ||
import type {ListItemExpandIconRenderProps} from '../../types'; | ||
|
||
import './ListItemExpandIcon.scss'; | ||
|
||
const b = block('list-item-expand-icon'); | ||
|
||
export interface ListItemExpandIconProps extends ListItemExpandIconRenderProps {} | ||
|
||
export const ListItemExpandIcon = ({ | ||
expanded, | ||
behavior = 'action', | ||
disabled, | ||
}: ListItemExpandIconProps) => { | ||
return ( | ||
<ArrowToggle | ||
direction={getIconDirection({behavior, expanded})} | ||
className={b(null, colorText({color: disabled ? 'hint' : undefined}))} | ||
size={16} | ||
/> | ||
); | ||
}; | ||
|
||
function getIconDirection({ | ||
behavior, | ||
expanded, | ||
}: Pick<ListItemExpandIconRenderProps, 'expanded' | 'behavior'>): ArrowToggleProps['direction'] { | ||
if (expanded && behavior === 'action') { | ||
return 'top'; | ||
} else if (expanded && behavior === 'state') { | ||
return 'bottom'; | ||
} else if (expanded && behavior === 'state-inverse') { | ||
return 'bottom'; | ||
} else if (behavior === 'action') { | ||
return 'bottom'; | ||
} else if (behavior === 'state') { | ||
return 'right'; | ||
} else if (behavior === 'state-inverse') { | ||
return 'left'; | ||
} | ||
|
||
return 'bottom'; | ||
} |
40 changes: 40 additions & 0 deletions
40
...mponents/useList/components/ListItemExpandIcon/__stories__/ListItemExpandIcon.stories.tsx
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,40 @@ | ||
import React from 'react'; | ||
|
||
import type {Meta, StoryObj} from '@storybook/react'; | ||
|
||
import {Button} from '../../../../Button'; | ||
import type {ListItemExpandIconProps} from '../ListItemExpandIcon'; | ||
import {ListItemExpandIcon} from '../ListItemExpandIcon'; | ||
|
||
const meta: Meta<typeof ListItemExpandIcon> = { | ||
title: 'Lab/useList/ListItemExpandIcon', | ||
component: ListItemExpandIcon, | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof ListItemExpandIcon>; | ||
|
||
const DefaultExample = (props: ListItemExpandIconProps) => { | ||
return <ListItemExpandIcon {...props} />; | ||
}; | ||
|
||
export const Default = { | ||
render: DefaultExample, | ||
} satisfies Story; | ||
|
||
const InsideButtonExample = (props: ListItemExpandIconProps) => { | ||
const [expanded, setExpanded] = React.useState(false); | ||
|
||
return ( | ||
<Button extraProps={{'aria-label': 'toggle-button'}} onClick={() => setExpanded((x) => !x)}> | ||
<Button.Icon> | ||
<ListItemExpandIcon {...props} expanded={expanded} /> | ||
</Button.Icon> | ||
</Button> | ||
); | ||
}; | ||
|
||
export const InsideButton = { | ||
render: InsideButtonExample, | ||
} satisfies Story; |
48 changes: 48 additions & 0 deletions
48
...ents/useList/components/ListItemExpandIcon/__stories__/list-item-expand-icon.md
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,48 @@ | ||
### ListItemExpandIcon | ||
|
||
Base group expand icon view | ||
|
||
#### Import | ||
|
||
```tsx | ||
import { | ||
type unstable_ListItemExpandIconProps as ListItemExpandIconProps, | ||
unstable_ListItemExpandIcon as ListItemExpandIcon, | ||
} from '@gravity-ui/uikit/unstable'; | ||
``` | ||
|
||
#### Base example: | ||
|
||
```jsx | ||
const DefaultExample = (props: ListItemExpandIconProps) => { | ||
return <ListItemExpandIcon {...props} />; | ||
}; | ||
``` | ||
|
||
<ListItemExpandIconDefault /> | ||
|
||
#### Render icon inside Button component: | ||
|
||
```jsx | ||
const InsideButtonExample = (props: ListItemExpandIconProps) => { | ||
const [expanded, setExpanded] = React.useState(false); | ||
|
||
return ( | ||
<Button onClick={() => setExpanded((x) => !x)}> | ||
<Button.Icon> | ||
<ListItemExpandIcon {...props} expanded={expanded} /> | ||
</Button.Icon> | ||
</Button> | ||
); | ||
}; | ||
``` | ||
|
||
<ListItemExpandIconInsideButton /> | ||
|
||
#### Props | ||
|
||
| Name | Description | Type | Default | | ||
| :------- | :---------------------------- | :-------------------------------: | :-----: | | ||
| expanded | icon state | `boolean` | | | ||
| disabled | disabled view type | `boolean` | | | ||
| behavior | The behavior of the component | `state`, `state-inverse`,`action` | | |
2 changes: 2 additions & 0 deletions
2
src/components/useList/components/ListItemExpandIcon/index.ts
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,2 @@ | ||
export {ListItemExpandIcon} from './ListItemExpandIcon'; | ||
export type {ListItemExpandIconProps} from './ListItemExpandIcon'; |
Oops, something went wrong.