@saas-ui/forms 2.0.0-rc.31 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +81 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +59 -43
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -42
- package/dist/index.mjs.map +1 -1
- package/dist/yup/index.d.ts +2 -2
- package/dist/zod/index.d.ts +2 -2
- package/package.json +2 -2
- package/src/select/select-context.tsx +4 -0
- package/src/select/select.stories.tsx +79 -0
- package/src/select/select.tsx +46 -25
@@ -1,5 +1,6 @@
|
|
1
1
|
import {
|
2
2
|
HTMLChakraProps,
|
3
|
+
createStylesContext,
|
3
4
|
useControllableState,
|
4
5
|
useFormControl,
|
5
6
|
} from '@chakra-ui/react'
|
@@ -9,6 +10,9 @@ import { FieldOptions } from '../types'
|
|
9
10
|
import { mapOptions } from '../utils'
|
10
11
|
import { SelectOption } from './select'
|
11
12
|
|
13
|
+
export const [SelectStylesProvider, useSelectStyles] =
|
14
|
+
createStylesContext('SuiSelect')
|
15
|
+
|
12
16
|
export const [SelectProvider, useSelectContext] = createContext<
|
13
17
|
ReturnType<typeof useSelect>
|
14
18
|
>({
|
@@ -2,6 +2,7 @@ import {
|
|
2
2
|
Container,
|
3
3
|
Icon,
|
4
4
|
MenuItemOption,
|
5
|
+
Stack,
|
5
6
|
Tag,
|
6
7
|
Wrap,
|
7
8
|
WrapItem,
|
@@ -173,3 +174,81 @@ export const WithNativeSelect = {
|
|
173
174
|
<NativeSelect name="select" options={options} aria-label="Select" />
|
174
175
|
),
|
175
176
|
}
|
177
|
+
|
178
|
+
export const Sizes = {
|
179
|
+
render: () => (
|
180
|
+
<Stack>
|
181
|
+
<Select name="select" defaultValue="1" size="xs">
|
182
|
+
<SelectButton />
|
183
|
+
<SelectList>
|
184
|
+
<SelectOption value="">None</SelectOption>
|
185
|
+
<SelectOption value="1">Option 1</SelectOption>
|
186
|
+
<SelectOption value="2">Option 2</SelectOption>
|
187
|
+
</SelectList>
|
188
|
+
</Select>
|
189
|
+
<Select name="select" defaultValue="1" size="sm">
|
190
|
+
<SelectButton />
|
191
|
+
<SelectList>
|
192
|
+
<SelectOption value="">None</SelectOption>
|
193
|
+
<SelectOption value="1">Option 1</SelectOption>
|
194
|
+
<SelectOption value="2">Option 2</SelectOption>
|
195
|
+
</SelectList>
|
196
|
+
</Select>
|
197
|
+
<Select name="select" defaultValue="1" size="md">
|
198
|
+
<SelectButton />
|
199
|
+
<SelectList>
|
200
|
+
<SelectOption value="">None</SelectOption>
|
201
|
+
<SelectOption value="1">Option 1</SelectOption>
|
202
|
+
<SelectOption value="2">Option 2</SelectOption>
|
203
|
+
</SelectList>
|
204
|
+
</Select>
|
205
|
+
<Select name="select" defaultValue="1" size="lg">
|
206
|
+
<SelectButton />
|
207
|
+
<SelectList>
|
208
|
+
<SelectOption value="">None</SelectOption>
|
209
|
+
<SelectOption value="1">Option 1</SelectOption>
|
210
|
+
<SelectOption value="2">Option 2</SelectOption>
|
211
|
+
</SelectList>
|
212
|
+
</Select>
|
213
|
+
</Stack>
|
214
|
+
),
|
215
|
+
}
|
216
|
+
|
217
|
+
export const Variants = {
|
218
|
+
render: () => (
|
219
|
+
<Stack>
|
220
|
+
<Select name="select" defaultValue="1" variant="outline">
|
221
|
+
<SelectButton />
|
222
|
+
<SelectList>
|
223
|
+
<SelectOption value="">None</SelectOption>
|
224
|
+
<SelectOption value="1">Option 1</SelectOption>
|
225
|
+
<SelectOption value="2">Option 2</SelectOption>
|
226
|
+
</SelectList>
|
227
|
+
</Select>
|
228
|
+
<Select name="select" defaultValue="1" variant="flushed">
|
229
|
+
<SelectButton />
|
230
|
+
<SelectList>
|
231
|
+
<SelectOption value="">None</SelectOption>
|
232
|
+
<SelectOption value="1">Option 1</SelectOption>
|
233
|
+
<SelectOption value="2">Option 2</SelectOption>
|
234
|
+
</SelectList>
|
235
|
+
</Select>
|
236
|
+
<Select name="select" defaultValue="1" variant="filled">
|
237
|
+
<SelectButton />
|
238
|
+
<SelectList>
|
239
|
+
<SelectOption value="">None</SelectOption>
|
240
|
+
<SelectOption value="1">Option 1</SelectOption>
|
241
|
+
<SelectOption value="2">Option 2</SelectOption>
|
242
|
+
</SelectList>
|
243
|
+
</Select>
|
244
|
+
<Select name="select" defaultValue="1" variant="unstyled">
|
245
|
+
<SelectButton />
|
246
|
+
<SelectList>
|
247
|
+
<SelectOption value="">None</SelectOption>
|
248
|
+
<SelectOption value="1">Option 1</SelectOption>
|
249
|
+
<SelectOption value="2">Option 2</SelectOption>
|
250
|
+
</SelectList>
|
251
|
+
</Select>
|
252
|
+
</Stack>
|
253
|
+
),
|
254
|
+
}
|
package/src/select/select.tsx
CHANGED
@@ -5,7 +5,6 @@ import {
|
|
5
5
|
forwardRef,
|
6
6
|
Menu,
|
7
7
|
MenuProps,
|
8
|
-
MenuButton,
|
9
8
|
MenuList,
|
10
9
|
MenuListProps,
|
11
10
|
MenuItemOption,
|
@@ -14,9 +13,10 @@ import {
|
|
14
13
|
ButtonProps,
|
15
14
|
omitThemingProps,
|
16
15
|
useMultiStyleConfig,
|
17
|
-
SystemStyleObject,
|
18
16
|
MenuItemOptionProps,
|
19
17
|
useFormControlContext,
|
18
|
+
ThemingProps,
|
19
|
+
useMenuButton,
|
20
20
|
} from '@chakra-ui/react'
|
21
21
|
import { cx, dataAttr } from '@chakra-ui/utils'
|
22
22
|
import { ChevronDownIcon } from '@saas-ui/core'
|
@@ -26,8 +26,10 @@ import { FieldOption } from '../types'
|
|
26
26
|
import {
|
27
27
|
SelectOptions,
|
28
28
|
SelectProvider,
|
29
|
+
SelectStylesProvider,
|
29
30
|
useSelect,
|
30
31
|
useSelectContext,
|
32
|
+
useSelectStyles,
|
31
33
|
} from './select-context'
|
32
34
|
|
33
35
|
export interface SelectOption
|
@@ -35,10 +37,12 @@ export interface SelectOption
|
|
35
37
|
FieldOption {}
|
36
38
|
|
37
39
|
export interface SelectProps
|
38
|
-
extends Omit<MenuProps, 'children'>,
|
40
|
+
extends Omit<MenuProps, 'children' | 'variant' | 'size'>,
|
41
|
+
ThemingProps<'SuiSelect'>,
|
39
42
|
SelectOptions {}
|
40
43
|
|
41
|
-
export interface SelectButtonProps
|
44
|
+
export interface SelectButtonProps
|
45
|
+
extends Omit<ButtonProps, 'size' | 'variant'> {}
|
42
46
|
|
43
47
|
/**
|
44
48
|
* Button that opens the select menu and displays the selected value.
|
@@ -47,8 +51,6 @@ export interface SelectButtonProps extends ButtonProps {}
|
|
47
51
|
*/
|
48
52
|
export const SelectButton = forwardRef<SelectButtonProps, 'button'>(
|
49
53
|
(props, ref) => {
|
50
|
-
const styles = useMultiStyleConfig('SuiSelect', props)
|
51
|
-
|
52
54
|
const {
|
53
55
|
displayValue,
|
54
56
|
renderValue,
|
@@ -58,6 +60,8 @@ export const SelectButton = forwardRef<SelectButtonProps, 'button'>(
|
|
58
60
|
|
59
61
|
const context = useFormControlContext()
|
60
62
|
|
63
|
+
const styles = useSelectStyles()
|
64
|
+
|
61
65
|
const {
|
62
66
|
isInvalid,
|
63
67
|
isReadOnly,
|
@@ -92,16 +96,19 @@ export const SelectButton = forwardRef<SelectButtonProps, 'button'>(
|
|
92
96
|
_expanded: focusStyles,
|
93
97
|
_readOnly: readOnlyStyles,
|
94
98
|
_invalid: invalid,
|
99
|
+
minW: 0,
|
95
100
|
...styles.field,
|
96
101
|
h: 'auto',
|
97
102
|
}
|
98
103
|
|
104
|
+
const buttonProps = useMenuButton(rest, ref)
|
105
|
+
|
99
106
|
// Using a Button, so we can simply use leftIcon and rightIcon
|
100
107
|
return (
|
101
|
-
<
|
102
|
-
|
103
|
-
id={id || React.useId()}
|
108
|
+
<Button
|
109
|
+
{...buttonProps}
|
104
110
|
{...buttonStyles}
|
111
|
+
id={id || buttonProps.id}
|
105
112
|
{...rest}
|
106
113
|
onFocus={onFocus}
|
107
114
|
onBlur={onBlur}
|
@@ -111,10 +118,20 @@ export const SelectButton = forwardRef<SelectButtonProps, 'button'>(
|
|
111
118
|
data-focus={dataAttr(isFocused)}
|
112
119
|
data-required={dataAttr(isRequired)}
|
113
120
|
rightIcon={rightIcon}
|
114
|
-
ref={ref}
|
115
121
|
>
|
116
|
-
|
117
|
-
|
122
|
+
<chakra.span
|
123
|
+
__css={{
|
124
|
+
display: 'block',
|
125
|
+
pointerEvents: 'none',
|
126
|
+
flex: '1 1 auto',
|
127
|
+
minW: 0,
|
128
|
+
overflow: 'hidden',
|
129
|
+
textOverflow: 'ellipsis',
|
130
|
+
}}
|
131
|
+
>
|
132
|
+
{renderValue(displayValue) || placeholder}
|
133
|
+
</chakra.span>
|
134
|
+
</Button>
|
118
135
|
)
|
119
136
|
}
|
120
137
|
)
|
@@ -129,6 +146,8 @@ SelectButton.displayName = 'SelectButton'
|
|
129
146
|
export const Select = forwardRef<SelectProps, 'select'>((props, ref) => {
|
130
147
|
const { name, children, isDisabled, multiple, ...rest } = props
|
131
148
|
|
149
|
+
const styles = useMultiStyleConfig('SuiSelect', props)
|
150
|
+
|
132
151
|
const menuProps = omitThemingProps(rest)
|
133
152
|
|
134
153
|
const context = useSelect(props)
|
@@ -137,19 +156,21 @@ export const Select = forwardRef<SelectProps, 'select'>((props, ref) => {
|
|
137
156
|
|
138
157
|
return (
|
139
158
|
<SelectProvider value={context}>
|
140
|
-
<
|
141
|
-
<
|
142
|
-
{
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
159
|
+
<SelectStylesProvider value={styles}>
|
160
|
+
<Menu {...menuProps} closeOnSelect={!multiple}>
|
161
|
+
<chakra.div className={cx('sui-select')}>
|
162
|
+
{children}
|
163
|
+
<chakra.input
|
164
|
+
{...controlProps}
|
165
|
+
ref={ref}
|
166
|
+
name={name}
|
167
|
+
type="hidden"
|
168
|
+
value={value || ''}
|
169
|
+
className="saas-select__input"
|
170
|
+
/>
|
171
|
+
</chakra.div>
|
172
|
+
</Menu>
|
173
|
+
</SelectStylesProvider>
|
153
174
|
</SelectProvider>
|
154
175
|
)
|
155
176
|
})
|