Skip to content

Commit 8ab3869

Browse files
committed
feat: more usable select
1 parent 8f4d041 commit 8ab3869

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

example/src/stories/Select.stories.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,35 @@ CustomRender.args = {
7070
</>
7171
),
7272
}
73+
74+
export const CustomTypes = Template.bind({})
75+
CustomTypes.args = {
76+
value: 'Select',
77+
items: [
78+
{
79+
value: 'kr',
80+
icon: 'https://flagicons.lipis.dev/flags/4x3/kr.svg',
81+
label: 'Korea',
82+
},
83+
{
84+
value: 'gb',
85+
icon: 'https://flagicons.lipis.dev/flags/4x3/gb.svg',
86+
label: 'United Kingdom',
87+
},
88+
{
89+
value: 'us',
90+
icon: 'https://flagicons.lipis.dev/flags/4x3/us.svg',
91+
label: 'United States',
92+
},
93+
{
94+
value: 'jp',
95+
icon: 'https://flagicons.lipis.dev/flags/4x3/jp.svg',
96+
label: 'Japan',
97+
},
98+
],
99+
render: (s: { value: string; icon: string; label: string }) => (
100+
<>
101+
<img src={s.icon} alt={s.label} style={{ height: '1em' }} /> {s.label}
102+
</>
103+
),
104+
}

src/components/Select.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import React, {
3232
useState
3333
} from 'react'
3434
import { IoChevronDown } from 'react-icons/io5'
35-
import { PC, PP, PR } from '../types/PolymorphicElementProps'
35+
import { PP, PR } from '../types/PolymorphicElementProps'
3636
import { cssClickable, cssDisablable } from '../utils/styles'
3737
import { ListItem, ListItemProps } from './$List'
3838
import { Centering } from './Centering'
@@ -87,7 +87,7 @@ const SelectInputAdornment = styled(Centering)`
8787

8888
type SelectItemNode = string | { value: string }
8989

90-
export interface SelectProps<T extends SelectItemNode = string> {
90+
export interface SelectProps<T extends SelectItemNode> {
9191
fullWidth?: boolean
9292
disableEllipsis?: boolean
9393
items?: T[]
@@ -97,7 +97,7 @@ export interface SelectProps<T extends SelectItemNode = string> {
9797
ListItemProps?: Partial<PP<'div', ListItemProps>>
9898
}
9999

100-
export const Select: PC<'button', SelectProps> = React.forwardRef(
100+
export const Select = React.forwardRef(
101101
<T extends ElementType, E extends SelectItemNode>(
102102
props: PP<T, SelectProps<E>>,
103103
ref?: PR<T>

0 commit comments

Comments
 (0)