fix(SW-1509): add support for default selected key
fixed padding per list item
This commit is contained in:
@@ -22,6 +22,15 @@ export const Default: Story = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const DefaultSelected: Story = {
|
||||||
|
args: {
|
||||||
|
items: ['Foo', 'Bar', 'Baz'],
|
||||||
|
label: 'Select an item',
|
||||||
|
name: 'foo',
|
||||||
|
defaultSelectedKey: 'Foo',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
export const ObjectItem: Story = {
|
export const ObjectItem: Story = {
|
||||||
args: {
|
args: {
|
||||||
items: [
|
items: [
|
||||||
|
|||||||
@@ -88,22 +88,27 @@ export function Select({
|
|||||||
|
|
||||||
<Popover className={styles.popover} shouldFlip={false}>
|
<Popover className={styles.popover} shouldFlip={false}>
|
||||||
<ListBox className={styles.listBox}>
|
<ListBox className={styles.listBox}>
|
||||||
{items.map((item, idx) => (
|
{items.map((item) =>
|
||||||
<Typography variant="Body/Paragraph/mdRegular" key={idx}>
|
typeof item === 'object' ? (
|
||||||
{typeof item === 'object' ? (
|
<SelectItem
|
||||||
<SelectItem
|
key={item.label}
|
||||||
icon={item.icon || itemIcon}
|
id={item.label}
|
||||||
isDisabled={item.isDisabled}
|
icon={item.icon || itemIcon}
|
||||||
>
|
isDisabled={item.isDisabled}
|
||||||
{item.label}
|
>
|
||||||
</SelectItem>
|
{item.label}
|
||||||
) : (
|
</SelectItem>
|
||||||
<SelectItem icon={itemIcon} isDisabled={isDisabled}>
|
) : (
|
||||||
{item.toString()}
|
<SelectItem
|
||||||
</SelectItem>
|
key={item}
|
||||||
)}
|
id={item}
|
||||||
</Typography>
|
icon={itemIcon}
|
||||||
))}
|
isDisabled={isDisabled}
|
||||||
|
>
|
||||||
|
{item.toString()}
|
||||||
|
</SelectItem>
|
||||||
|
)
|
||||||
|
)}
|
||||||
</ListBox>
|
</ListBox>
|
||||||
</Popover>
|
</Popover>
|
||||||
</AriaSelect>
|
</AriaSelect>
|
||||||
|
|||||||
@@ -81,22 +81,27 @@ export function SelectFilter({
|
|||||||
offset={22}
|
offset={22}
|
||||||
>
|
>
|
||||||
<ListBox className={styles.listBox}>
|
<ListBox className={styles.listBox}>
|
||||||
{items.map((item, idx) => (
|
{items.map((item) =>
|
||||||
<Typography variant="Body/Paragraph/mdRegular" key={idx}>
|
typeof item === 'object' ? (
|
||||||
{typeof item === 'object' ? (
|
<SelectItem
|
||||||
<SelectItem
|
key={item.label}
|
||||||
icon={item.icon || itemIcon}
|
id={item.label}
|
||||||
isDisabled={item.isDisabled}
|
icon={item.icon || itemIcon}
|
||||||
>
|
isDisabled={item.isDisabled}
|
||||||
{item.label}
|
>
|
||||||
</SelectItem>
|
{item.label}
|
||||||
) : (
|
</SelectItem>
|
||||||
<SelectItem icon={itemIcon} isDisabled={isDisabled}>
|
) : (
|
||||||
{item.toString()}
|
<SelectItem
|
||||||
</SelectItem>
|
key={item}
|
||||||
)}
|
id={item}
|
||||||
</Typography>
|
icon={itemIcon}
|
||||||
))}
|
isDisabled={isDisabled}
|
||||||
|
>
|
||||||
|
{item.toString()}
|
||||||
|
</SelectItem>
|
||||||
|
)
|
||||||
|
)}
|
||||||
</ListBox>
|
</ListBox>
|
||||||
</Popover>
|
</Popover>
|
||||||
</ComboBox>
|
</ComboBox>
|
||||||
|
|||||||
@@ -4,12 +4,20 @@ import styles from './select.module.css'
|
|||||||
import { MaterialIcon } from '../Icons/MaterialIcon'
|
import { MaterialIcon } from '../Icons/MaterialIcon'
|
||||||
import { SelectItemProps } from './types'
|
import { SelectItemProps } from './types'
|
||||||
|
|
||||||
export function SelectItem({ children, icon, isDisabled }: SelectItemProps) {
|
export function SelectItem({
|
||||||
|
children,
|
||||||
|
icon,
|
||||||
|
isDisabled,
|
||||||
|
...props
|
||||||
|
}: SelectItemProps) {
|
||||||
|
const iconColor = isDisabled ? 'Icon/Interactive/Disabled' : 'Icon/Default'
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ListBoxItem
|
<ListBoxItem
|
||||||
className={styles.listBoxItem}
|
className={styles.listBoxItem}
|
||||||
textValue={children}
|
textValue={children}
|
||||||
isDisabled={isDisabled}
|
isDisabled={isDisabled}
|
||||||
|
{...props}
|
||||||
>
|
>
|
||||||
{({ isSelected }) => (
|
{({ isSelected }) => (
|
||||||
<>
|
<>
|
||||||
@@ -17,7 +25,7 @@ export function SelectItem({ children, icon, isDisabled }: SelectItemProps) {
|
|||||||
<MaterialIcon
|
<MaterialIcon
|
||||||
icon={icon}
|
icon={icon}
|
||||||
size={24}
|
size={24}
|
||||||
color={isDisabled ? 'Icon/Interactive/Disabled' : 'Icon/Default'}
|
color={iconColor}
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
|
|||||||
Reference in New Issue
Block a user