@podoba/react 0.0.42 → 0.0.43
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/package.json +3 -3
- package/src/components/combobox.tsx +25 -18
- package/src/components/date-field.tsx +26 -13
- package/src/components/date-picker.tsx +13 -5
- package/src/components/field-appearance.ts +44 -0
- package/src/components/input.tsx +19 -20
- package/src/components/multiselect.tsx +19 -7
- package/src/components/number-field.tsx +16 -9
- package/src/components/search-field.tsx +14 -7
- package/src/components/select.tsx +30 -17
- package/src/components/textarea.tsx +12 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@podoba/react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.43",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "podoba React components — React Aria Components + Tailwind primitives + layout, built with uic.",
|
|
6
6
|
"repository": {
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"typecheck": "tsc --build"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@podoba/tokens": "^0.0.
|
|
32
|
-
"@podoba/tailwind": "^0.0.
|
|
31
|
+
"@podoba/tokens": "^0.0.43",
|
|
32
|
+
"@podoba/tailwind": "^0.0.43",
|
|
33
33
|
"react-aria-components": "1.18.0",
|
|
34
34
|
"class-variance-authority": "0.7.1",
|
|
35
35
|
"clsx": "2.1.1",
|
|
@@ -17,14 +17,22 @@ import {
|
|
|
17
17
|
} from 'react-aria-components'
|
|
18
18
|
import { uic } from '../utils/uic'
|
|
19
19
|
import { useInFocusOverlay } from './focus-context'
|
|
20
|
-
import {
|
|
20
|
+
import {
|
|
21
|
+
fieldDescriptionClass,
|
|
22
|
+
fieldErrorClass,
|
|
23
|
+
fieldLabelClass,
|
|
24
|
+
fieldSizeClasses,
|
|
25
|
+
fieldStackClass,
|
|
26
|
+
outlinedFieldClasses,
|
|
27
|
+
type FieldSize,
|
|
28
|
+
} from './field-appearance'
|
|
21
29
|
|
|
22
30
|
/**
|
|
23
31
|
* ComboBox — a filterable single-select: a text input that narrows a listbox as
|
|
24
32
|
* you type. Built on React Aria Components `ComboBox` (typeahead, keyboard nav,
|
|
25
|
-
* ARIA all handled).
|
|
26
|
-
*
|
|
27
|
-
* options as `ComboBoxItem` children.
|
|
33
|
+
* ARIA all handled). The input uses the shared outlined skin and `size` scale,
|
|
34
|
+
* so it is the same box as an outlined `Input` or `Select`, and it shares
|
|
35
|
+
* `Select`'s cream dropdown. Pass options as `ComboBoxItem` children.
|
|
28
36
|
*/
|
|
29
37
|
const Chevron = () => (
|
|
30
38
|
<svg width="9.5" height="9.5" viewBox="0 0 12 12" fill="none" aria-hidden="true" className="text-fg">
|
|
@@ -32,17 +40,13 @@ const Chevron = () => (
|
|
|
32
40
|
</svg>
|
|
33
41
|
)
|
|
34
42
|
|
|
35
|
-
//
|
|
36
|
-
//
|
|
43
|
+
// The shared outlined skin, with room on the right for the toggle. Invalid is
|
|
44
|
+
// owned by the ComboBox root, so it comes through `group-data-invalid`.
|
|
37
45
|
const ComboBoxInput = uic(RACInput, {
|
|
38
46
|
displayName: 'ComboBoxInput',
|
|
39
|
-
baseClass:
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
'data-[hovered]:border-fg-subtle ' +
|
|
43
|
-
'data-[focused]:border-brand-green data-[focused]:ring-2 data-[focused]:ring-ring ' +
|
|
44
|
-
'group-data-[invalid]:border-danger group-data-[invalid]:ring-2 group-data-[invalid]:ring-danger ' +
|
|
45
|
-
'data-[disabled]:bg-surface-muted data-[disabled]:opacity-60',
|
|
47
|
+
baseClass: `w-full rounded-lg pl-4 pr-11 ${outlinedFieldClasses({ invalid: 'group' })}`,
|
|
48
|
+
variants: { fieldSize: fieldSizeClasses },
|
|
49
|
+
defaultVariants: { fieldSize: 'md' },
|
|
46
50
|
})
|
|
47
51
|
|
|
48
52
|
export const ComboBoxItem = uic(ListBoxItem, {
|
|
@@ -61,6 +65,8 @@ export type ComboBoxProps<T extends object> = RACComboBoxProps<T> & {
|
|
|
61
65
|
errorMessage?: string
|
|
62
66
|
/** Placeholder shown in the empty input. */
|
|
63
67
|
placeholder?: string
|
|
68
|
+
/** Input height, matching `Input`'s `size`. */
|
|
69
|
+
size?: FieldSize
|
|
64
70
|
children: ReactNode
|
|
65
71
|
}
|
|
66
72
|
|
|
@@ -69,6 +75,7 @@ export const ComboBox = <T extends object>({
|
|
|
69
75
|
description,
|
|
70
76
|
errorMessage,
|
|
71
77
|
placeholder,
|
|
78
|
+
size = 'md',
|
|
72
79
|
children,
|
|
73
80
|
selectedKey,
|
|
74
81
|
onSelectionChange,
|
|
@@ -86,8 +93,8 @@ export const ComboBox = <T extends object>({
|
|
|
86
93
|
// only fills its listbox while open, so compose Autocomplete + ListBox here).
|
|
87
94
|
if (inFocus) {
|
|
88
95
|
return (
|
|
89
|
-
<div className=
|
|
90
|
-
<span className=
|
|
96
|
+
<div className={fieldStackClass}>
|
|
97
|
+
<span className={fieldLabelClass}>{label}</span>
|
|
91
98
|
<Autocomplete filter={contains}>
|
|
92
99
|
<SearchField aria-label={typeof label === 'string' ? label : 'Search'}>
|
|
93
100
|
<RACInput
|
|
@@ -122,11 +129,11 @@ export const ComboBox = <T extends object>({
|
|
|
122
129
|
selectedKey={selectedKey}
|
|
123
130
|
onSelectionChange={onSelectionChange}
|
|
124
131
|
{...props}
|
|
125
|
-
className=
|
|
132
|
+
className={`group ${fieldStackClass}`}
|
|
126
133
|
>
|
|
127
|
-
<Label className=
|
|
134
|
+
<Label className={fieldLabelClass}>{label}</Label>
|
|
128
135
|
<div className="relative">
|
|
129
|
-
<ComboBoxInput placeholder={placeholder} />
|
|
136
|
+
<ComboBoxInput placeholder={placeholder} fieldSize={size} />
|
|
130
137
|
{/* RAC uses this Button to toggle the listbox open/closed. */}
|
|
131
138
|
<RACButton className="absolute inset-y-0 right-0 flex w-11 items-center justify-center rounded-r-lg outline-none data-[focus-visible]:ring-2 data-[focus-visible]:ring-ring">
|
|
132
139
|
<Chevron />
|
|
@@ -12,7 +12,15 @@ import {
|
|
|
12
12
|
type TimeFieldProps as RACTimeFieldProps,
|
|
13
13
|
type TimeValue,
|
|
14
14
|
} from 'react-aria-components'
|
|
15
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
fieldDescriptionClass,
|
|
17
|
+
fieldErrorClass,
|
|
18
|
+
fieldLabelClass,
|
|
19
|
+
fieldSizeClasses,
|
|
20
|
+
fieldStackClass,
|
|
21
|
+
outlinedFieldClasses,
|
|
22
|
+
type FieldSize,
|
|
23
|
+
} from './field-appearance'
|
|
16
24
|
|
|
17
25
|
/**
|
|
18
26
|
* DateField / TimeField — segmented, keyboard-first date and time entry (type or
|
|
@@ -28,21 +36,24 @@ export const segmentClass =
|
|
|
28
36
|
'data-[focused]:bg-brand-green data-[focused]:text-fg ' +
|
|
29
37
|
'data-[disabled]:opacity-50 data-[type=literal]:px-0 data-[type=literal]:text-fg-muted'
|
|
30
38
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
39
|
+
// The shared outlined box around the segments. Focus sits on a segment, so the
|
|
40
|
+
// wrapper shows it via focus-within; invalid lives on the field root.
|
|
41
|
+
export const dateInputClass = (size: FieldSize = 'md') =>
|
|
42
|
+
`flex w-full items-center gap-0.5 rounded-lg px-4 ${fieldSizeClasses[size]} ` +
|
|
43
|
+
outlinedFieldClasses({ focus: 'within', invalid: 'group' })
|
|
35
44
|
|
|
36
45
|
export type DateFieldProps<T extends DateValue> = RACDateFieldProps<T> & {
|
|
37
46
|
label: ReactNode
|
|
47
|
+
/** Field height, matching `Input`'s `size`. */
|
|
48
|
+
size?: FieldSize
|
|
38
49
|
description?: ReactNode
|
|
39
50
|
errorMessage?: string
|
|
40
51
|
}
|
|
41
52
|
|
|
42
|
-
export const DateField = <T extends DateValue>({ label, description, errorMessage, ...props }: DateFieldProps<T>) => (
|
|
43
|
-
<RACDateField {...props} className=
|
|
44
|
-
<Label className=
|
|
45
|
-
<DateInput className={dateInputClass}>{(segment) => <DateSegment segment={segment} className={segmentClass} />}</DateInput>
|
|
53
|
+
export const DateField = <T extends DateValue>({ label, description, errorMessage, size, ...props }: DateFieldProps<T>) => (
|
|
54
|
+
<RACDateField {...props} className={`group ${fieldStackClass}`}>
|
|
55
|
+
<Label className={fieldLabelClass}>{label}</Label>
|
|
56
|
+
<DateInput className={dateInputClass(size)}>{(segment) => <DateSegment segment={segment} className={segmentClass} />}</DateInput>
|
|
46
57
|
{description ? (
|
|
47
58
|
<Text slot="description" className={fieldDescriptionClass}>
|
|
48
59
|
{description}
|
|
@@ -54,14 +65,16 @@ export const DateField = <T extends DateValue>({ label, description, errorMessag
|
|
|
54
65
|
|
|
55
66
|
export type TimeFieldProps<T extends TimeValue> = RACTimeFieldProps<T> & {
|
|
56
67
|
label: ReactNode
|
|
68
|
+
/** Field height, matching `Input`'s `size`. */
|
|
69
|
+
size?: FieldSize
|
|
57
70
|
description?: ReactNode
|
|
58
71
|
errorMessage?: string
|
|
59
72
|
}
|
|
60
73
|
|
|
61
|
-
export const TimeField = <T extends TimeValue>({ label, description, errorMessage, ...props }: TimeFieldProps<T>) => (
|
|
62
|
-
<RACTimeField {...props} className=
|
|
63
|
-
<Label className=
|
|
64
|
-
<DateInput className={dateInputClass}>{(segment) => <DateSegment segment={segment} className={segmentClass} />}</DateInput>
|
|
74
|
+
export const TimeField = <T extends TimeValue>({ label, description, errorMessage, size, ...props }: TimeFieldProps<T>) => (
|
|
75
|
+
<RACTimeField {...props} className={`group ${fieldStackClass}`}>
|
|
76
|
+
<Label className={fieldLabelClass}>{label}</Label>
|
|
77
|
+
<DateInput className={dateInputClass(size)}>{(segment) => <DateSegment segment={segment} className={segmentClass} />}</DateInput>
|
|
65
78
|
{description ? (
|
|
66
79
|
<Text slot="description" className={fieldDescriptionClass}>
|
|
67
80
|
{description}
|
|
@@ -23,7 +23,13 @@ import {
|
|
|
23
23
|
import { clsx } from 'clsx'
|
|
24
24
|
import { dateInputClass, segmentClass } from './date-field'
|
|
25
25
|
import { useInFocusOverlay } from './focus-context'
|
|
26
|
-
import {
|
|
26
|
+
import {
|
|
27
|
+
fieldDescriptionClass,
|
|
28
|
+
fieldErrorClass,
|
|
29
|
+
fieldLabelClass,
|
|
30
|
+
fieldStackClass,
|
|
31
|
+
type FieldSize,
|
|
32
|
+
} from './field-appearance'
|
|
27
33
|
|
|
28
34
|
/**
|
|
29
35
|
* DatePicker — a `DateField` with a calendar popover. Built on React Aria
|
|
@@ -78,19 +84,21 @@ function CalendarBody() {
|
|
|
78
84
|
|
|
79
85
|
export type DatePickerProps<T extends DateValue> = RACDatePickerProps<T> & {
|
|
80
86
|
label: ReactNode
|
|
87
|
+
/** Field height, matching `Input`'s `size`. */
|
|
88
|
+
size?: FieldSize
|
|
81
89
|
description?: ReactNode
|
|
82
90
|
errorMessage?: string
|
|
83
91
|
}
|
|
84
92
|
|
|
85
|
-
export const DatePicker = <T extends DateValue>({ label, description, errorMessage, ...props }: DatePickerProps<T>) => {
|
|
93
|
+
export const DatePicker = <T extends DateValue>({ label, description, errorMessage, size, ...props }: DatePickerProps<T>) => {
|
|
86
94
|
// In a focus overlay, show the calendar inline (open) instead of a popover.
|
|
87
95
|
const inFocus = useInFocusOverlay()
|
|
88
96
|
return (
|
|
89
|
-
<RACDatePicker {...props} className=
|
|
90
|
-
<Label className=
|
|
97
|
+
<RACDatePicker {...props} className={`group ${fieldStackClass}`}>
|
|
98
|
+
<Label className={fieldLabelClass}>{label}</Label>
|
|
91
99
|
{/* In focus mode the field is bare + large and the calendar is borderless,
|
|
92
100
|
so field + calendar read as one seamless editor rather than boxes. */}
|
|
93
|
-
<Group className={inFocus ? 'flex w-full items-center' : `${dateInputClass} pr-2`}>
|
|
101
|
+
<Group className={inFocus ? 'flex w-full items-center' : `${dateInputClass(size)} pr-2`}>
|
|
94
102
|
<DateInput className={clsx('flex flex-1 items-center gap-0.5', inFocus && 'text-display font-medium')}>
|
|
95
103
|
{(segment) => <DateSegment segment={segment} className={segmentClass} />}
|
|
96
104
|
</DateInput>
|
|
@@ -22,3 +22,47 @@ export const fieldDescriptionClass = 'text-small text-fg-muted'
|
|
|
22
22
|
|
|
23
23
|
/** gs `.errorText`: 16px, line-height normal, error red (`danger`, 4.83:1 on white). */
|
|
24
24
|
export const fieldErrorClass = 'text-body leading-[normal] text-danger'
|
|
25
|
+
|
|
26
|
+
/** Field label, shared by every labelled form control (gs 17px/20px field label). */
|
|
27
|
+
export const fieldLabelClass = 'text-panel-heading font-medium text-fg'
|
|
28
|
+
|
|
29
|
+
/** Label, control, description and error stack. */
|
|
30
|
+
export const fieldStackClass = 'flex flex-col gap-3'
|
|
31
|
+
|
|
32
|
+
/** Outlined control heights. `md` is the default, so every outlined field in a
|
|
33
|
+
* form is the same 40px box unless the consumer opts into another size. */
|
|
34
|
+
export const FIELD_SIZES = ['sm', 'md', 'lg', 'tall'] as const
|
|
35
|
+
export type FieldSize = (typeof FIELD_SIZES)[number]
|
|
36
|
+
export const fieldSizeClasses: Record<FieldSize, string> = {
|
|
37
|
+
sm: 'h-8',
|
|
38
|
+
md: 'h-10',
|
|
39
|
+
lg: 'h-12',
|
|
40
|
+
tall: 'h-control-tall',
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// The outlined skin, split by where its state lives. Every class is spelled out
|
|
44
|
+
// in full so Tailwind's scanner sees it; don't build these from fragments.
|
|
45
|
+
const outlinedBase =
|
|
46
|
+
'border border-border bg-surface text-small text-fg ' +
|
|
47
|
+
'outline-none transition-colors duration-200 motion-reduce:transition-none placeholder:text-fg-muted ' +
|
|
48
|
+
'data-[hovered]:border-fg-subtle ' +
|
|
49
|
+
'data-[disabled]:bg-surface-muted data-[disabled]:opacity-60 data-[disabled]:pointer-events-none'
|
|
50
|
+
const outlinedFocus = {
|
|
51
|
+
// A focusable element (input, trigger button) marks itself focused.
|
|
52
|
+
self: 'data-[focused]:border-brand-green data-[focused]:ring-2 data-[focused]:ring-ring',
|
|
53
|
+
// A wrapper (Group, DateInput) marks focus on any child.
|
|
54
|
+
within: 'data-[focus-within]:border-brand-green data-[focus-within]:ring-2 data-[focus-within]:ring-ring',
|
|
55
|
+
}
|
|
56
|
+
const outlinedInvalid = {
|
|
57
|
+
self: 'data-[invalid]:border-danger data-[invalid]:ring-2 data-[invalid]:ring-danger',
|
|
58
|
+
// Invalid is owned by the field root (which carries `group`).
|
|
59
|
+
group: 'group-data-[invalid]:border-danger group-data-[invalid]:ring-2 group-data-[invalid]:ring-danger',
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Bordered white field skin, the default appearance of every form control.
|
|
63
|
+
* Pick where focus and invalid state are exposed for the element being styled. */
|
|
64
|
+
export const outlinedFieldClasses = ({
|
|
65
|
+
focus = 'self',
|
|
66
|
+
invalid = 'self',
|
|
67
|
+
}: { focus?: keyof typeof outlinedFocus; invalid?: keyof typeof outlinedInvalid } = {}) =>
|
|
68
|
+
`${outlinedBase} ${outlinedFocus[focus]} ${outlinedInvalid[invalid]}`
|
package/src/components/input.tsx
CHANGED
|
@@ -8,7 +8,17 @@ import {
|
|
|
8
8
|
type TextFieldProps,
|
|
9
9
|
} from 'react-aria-components'
|
|
10
10
|
import { uic } from '../utils/uic'
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
fieldDescriptionClass,
|
|
13
|
+
fieldErrorClass,
|
|
14
|
+
fieldLabelClass,
|
|
15
|
+
fieldSizeClasses,
|
|
16
|
+
fieldStackClass,
|
|
17
|
+
filledFieldClasses,
|
|
18
|
+
outlinedFieldClasses,
|
|
19
|
+
type FieldAppearance,
|
|
20
|
+
type FieldSize,
|
|
21
|
+
} from './field-appearance'
|
|
12
22
|
|
|
13
23
|
/**
|
|
14
24
|
* Input — labelled single-line text field.
|
|
@@ -26,29 +36,18 @@ const StyledInput = uic(RACInput, {
|
|
|
26
36
|
// surface-card — and in dark theme surface-card and surface are the SAME colour
|
|
27
37
|
// (#242423) — so a borderless cream field vanishes on both. Inverted: active =
|
|
28
38
|
// surface, disabled = the muted cream. border #eceae1 → border · hover #aba89c →
|
|
29
|
-
// fg-subtle · focus #75e7b8 → brand-green · error → danger.
|
|
30
|
-
//
|
|
31
|
-
//
|
|
39
|
+
// fg-subtle · focus #75e7b8 → brand-green · error → danger. That outlined skin
|
|
40
|
+
// lives in `outlinedFieldClasses` and every outlined control uses it, so they
|
|
41
|
+
// all render the same box; `fieldSize` adds the single-line height on top.
|
|
32
42
|
baseClass: 'w-full rounded-lg px-4',
|
|
33
43
|
variants: {
|
|
34
44
|
appearance: {
|
|
35
45
|
filled: filledFieldClasses,
|
|
36
|
-
outlined:
|
|
37
|
-
'outline-none transition-colors duration-200 placeholder:text-fg-muted ' +
|
|
38
|
-
'data-[hovered]:border-fg-subtle ' +
|
|
39
|
-
'data-[focused]:border-brand-green data-[focused]:ring-2 data-[focused]:ring-ring ' +
|
|
40
|
-
'data-[invalid]:border-danger data-[invalid]:ring-2 data-[invalid]:ring-danger ' +
|
|
41
|
-
'data-[disabled]:bg-surface-muted data-[disabled]:opacity-60 data-[disabled]:pointer-events-none',
|
|
46
|
+
outlined: outlinedFieldClasses(),
|
|
42
47
|
},
|
|
43
48
|
// `fieldSize` (not `size`) to avoid colliding with the native <input size>
|
|
44
49
|
// attribute, which RAC's Input inherits (a numeric prop).
|
|
45
|
-
fieldSize: {
|
|
46
|
-
sm: 'h-8',
|
|
47
|
-
md: 'h-10',
|
|
48
|
-
filled: 'h-10.5 py-3',
|
|
49
|
-
lg: 'h-12',
|
|
50
|
-
tall: 'h-control-tall',
|
|
51
|
-
},
|
|
50
|
+
fieldSize: { ...fieldSizeClasses, filled: 'h-10.5 py-3' },
|
|
52
51
|
},
|
|
53
52
|
defaultVariants: {
|
|
54
53
|
appearance: 'outlined',
|
|
@@ -66,7 +65,7 @@ export type InputProps = TextFieldProps & {
|
|
|
66
65
|
/** Error message; pass a string for a static error or rely on validation. */
|
|
67
66
|
errorMessage?: string
|
|
68
67
|
placeholder?: string
|
|
69
|
-
size?:
|
|
68
|
+
size?: FieldSize
|
|
70
69
|
/** Optional class for the TextField root. */
|
|
71
70
|
rootClassName?: string
|
|
72
71
|
/** Optional class for the inner native input (for product-specific composition). */
|
|
@@ -74,8 +73,8 @@ export type InputProps = TextFieldProps & {
|
|
|
74
73
|
}
|
|
75
74
|
|
|
76
75
|
export const Input = ({ label, description, errorMessage, placeholder, size, appearance = 'outlined', rootClassName, inputClassName, ...props }: InputProps) => (
|
|
77
|
-
<TextField {...props} className={
|
|
78
|
-
<Label className=
|
|
76
|
+
<TextField {...props} className={`${fieldStackClass} w-full ${rootClassName ?? ''}`}>
|
|
77
|
+
<Label className={fieldLabelClass}>{label}</Label>
|
|
79
78
|
<StyledInput className={inputClassName} placeholder={placeholder} appearance={appearance} fieldSize={size ?? (appearance === 'filled' ? 'filled' : undefined)} />
|
|
80
79
|
{description ? (
|
|
81
80
|
<Text slot="description" className={fieldDescriptionClass}>
|
|
@@ -14,7 +14,15 @@ import {
|
|
|
14
14
|
import { clsx } from 'clsx'
|
|
15
15
|
import { uic } from '../utils/uic'
|
|
16
16
|
import { useInFocusOverlay } from './focus-context'
|
|
17
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
fieldDescriptionClass,
|
|
19
|
+
fieldErrorClass,
|
|
20
|
+
fieldLabelClass,
|
|
21
|
+
fieldSizeClasses,
|
|
22
|
+
fieldStackClass,
|
|
23
|
+
outlinedFieldClasses,
|
|
24
|
+
type FieldSize,
|
|
25
|
+
} from './field-appearance'
|
|
18
26
|
|
|
19
27
|
/**
|
|
20
28
|
* MultiSelect — a dropdown that selects several options at once.
|
|
@@ -77,6 +85,8 @@ export type MultiSelectProps = {
|
|
|
77
85
|
searchable?: boolean
|
|
78
86
|
isDisabled?: boolean
|
|
79
87
|
isInvalid?: boolean
|
|
88
|
+
/** Trigger height, matching `Input`'s `size`. */
|
|
89
|
+
size?: FieldSize
|
|
80
90
|
className?: string
|
|
81
91
|
}
|
|
82
92
|
|
|
@@ -92,6 +102,7 @@ export const MultiSelect = ({
|
|
|
92
102
|
searchable,
|
|
93
103
|
isDisabled,
|
|
94
104
|
isInvalid,
|
|
105
|
+
size = 'md',
|
|
95
106
|
className,
|
|
96
107
|
}: MultiSelectProps) => {
|
|
97
108
|
const labelId = useId()
|
|
@@ -147,8 +158,10 @@ export const MultiSelect = ({
|
|
|
147
158
|
const err = isInvalid && errorMessage ? <span className={fieldErrorClass}>{errorMessage}</span> : null
|
|
148
159
|
|
|
149
160
|
return (
|
|
150
|
-
|
|
151
|
-
|
|
161
|
+
// `data-invalid` on the root drives the trigger's invalid border, as RAC does
|
|
162
|
+
// for the other fields.
|
|
163
|
+
<div className={clsx('group', fieldStackClass, className)} data-invalid={isInvalid || undefined}>
|
|
164
|
+
<span id={labelId} className={fieldLabelClass}>
|
|
152
165
|
{label}
|
|
153
166
|
</span>
|
|
154
167
|
{inFocus ? (
|
|
@@ -166,10 +179,9 @@ export const MultiSelect = ({
|
|
|
166
179
|
isDisabled={isDisabled}
|
|
167
180
|
onPress={() => setOpen(true)}
|
|
168
181
|
className={clsx(
|
|
169
|
-
'flex
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
isInvalid ? 'border-danger ring-2 ring-danger' : 'border-border',
|
|
182
|
+
'flex w-full items-center justify-between gap-2.5 rounded-lg px-4',
|
|
183
|
+
fieldSizeClasses[size],
|
|
184
|
+
outlinedFieldClasses({ invalid: 'group' }),
|
|
173
185
|
)}
|
|
174
186
|
>
|
|
175
187
|
<span className={clsx('truncate', chosen.length === 0 && 'text-fg-muted')}>{summary}</span>
|
|
@@ -9,7 +9,15 @@ import {
|
|
|
9
9
|
type NumberFieldProps as RACNumberFieldProps,
|
|
10
10
|
Text,
|
|
11
11
|
} from 'react-aria-components'
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
fieldDescriptionClass,
|
|
14
|
+
fieldErrorClass,
|
|
15
|
+
fieldLabelClass,
|
|
16
|
+
fieldSizeClasses,
|
|
17
|
+
fieldStackClass,
|
|
18
|
+
outlinedFieldClasses,
|
|
19
|
+
type FieldSize,
|
|
20
|
+
} from './field-appearance'
|
|
13
21
|
|
|
14
22
|
/**
|
|
15
23
|
* NumberField — numeric input with steppers, min/max and locale-aware formatting
|
|
@@ -26,18 +34,17 @@ export type NumberFieldProps = RACNumberFieldProps & {
|
|
|
26
34
|
description?: ReactNode
|
|
27
35
|
errorMessage?: string
|
|
28
36
|
placeholder?: string
|
|
37
|
+
/** Field height, matching `Input`'s `size`. */
|
|
38
|
+
size?: FieldSize
|
|
29
39
|
}
|
|
30
40
|
|
|
31
|
-
export const NumberField = ({ label, description, errorMessage, placeholder, ...props }: NumberFieldProps) => (
|
|
32
|
-
<RACNumberField {...props} className=
|
|
33
|
-
<Label className=
|
|
41
|
+
export const NumberField = ({ label, description, errorMessage, placeholder, size = 'md', ...props }: NumberFieldProps) => (
|
|
42
|
+
<RACNumberField {...props} className={`group ${fieldStackClass}`}>
|
|
43
|
+
<Label className={fieldLabelClass}>{label}</Label>
|
|
34
44
|
<Group
|
|
35
45
|
className={
|
|
36
|
-
|
|
37
|
-
'
|
|
38
|
-
'data-[focus-within]:border-brand-green data-[focus-within]:ring-2 data-[focus-within]:ring-ring ' +
|
|
39
|
-
'group-data-[invalid]:border-danger group-data-[invalid]:ring-2 group-data-[invalid]:ring-danger ' +
|
|
40
|
-
'data-[disabled]:bg-surface-muted data-[disabled]:opacity-60'
|
|
46
|
+
`flex w-full items-center overflow-hidden rounded-lg ${fieldSizeClasses[size]} ` +
|
|
47
|
+
outlinedFieldClasses({ focus: 'within', invalid: 'group' })
|
|
41
48
|
}
|
|
42
49
|
>
|
|
43
50
|
<RACButton slot="decrement" className={`${stepper} border-r border-border`}>
|
|
@@ -7,7 +7,14 @@ import {
|
|
|
7
7
|
type SearchFieldProps as RACSearchFieldProps,
|
|
8
8
|
Text,
|
|
9
9
|
} from 'react-aria-components'
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
fieldDescriptionClass,
|
|
12
|
+
fieldLabelClass,
|
|
13
|
+
fieldSizeClasses,
|
|
14
|
+
fieldStackClass,
|
|
15
|
+
outlinedFieldClasses,
|
|
16
|
+
type FieldSize,
|
|
17
|
+
} from './field-appearance'
|
|
11
18
|
|
|
12
19
|
/**
|
|
13
20
|
* SearchField — a text input for search, with a clear (✕) button that appears
|
|
@@ -35,19 +42,19 @@ export type SearchFieldProps = RACSearchFieldProps & {
|
|
|
35
42
|
label?: ReactNode
|
|
36
43
|
description?: ReactNode
|
|
37
44
|
placeholder?: string
|
|
45
|
+
/** Field height, matching `Input`'s `size`. */
|
|
46
|
+
size?: FieldSize
|
|
38
47
|
}
|
|
39
48
|
|
|
40
|
-
export const SearchField = ({ label, description, placeholder, ...props }: SearchFieldProps) => (
|
|
41
|
-
<RACSearchField {...props} className=
|
|
42
|
-
{label ? <Label className=
|
|
49
|
+
export const SearchField = ({ label, description, placeholder, size = 'md', ...props }: SearchFieldProps) => (
|
|
50
|
+
<RACSearchField {...props} className={`group ${fieldStackClass}`}>
|
|
51
|
+
{label ? <Label className={fieldLabelClass}>{label}</Label> : null}
|
|
43
52
|
<div className="relative flex items-center">
|
|
44
53
|
<SearchGlyph />
|
|
45
54
|
<RACInput
|
|
46
55
|
placeholder={placeholder}
|
|
47
56
|
className={
|
|
48
|
-
|
|
49
|
-
'placeholder:text-fg-muted data-[hovered]:border-fg-subtle ' +
|
|
50
|
-
'data-[focused]:border-brand-green data-[focused]:ring-2 data-[focused]:ring-ring ' +
|
|
57
|
+
`w-full rounded-lg pl-10 pr-10 ${fieldSizeClasses[size]} ${outlinedFieldClasses()} ` +
|
|
51
58
|
'[&::-webkit-search-cancel-button]:hidden'
|
|
52
59
|
}
|
|
53
60
|
/>
|
|
@@ -14,7 +14,16 @@ import {
|
|
|
14
14
|
} from 'react-aria-components'
|
|
15
15
|
import { uic } from '../utils/uic'
|
|
16
16
|
import { useInFocusOverlay } from './focus-context'
|
|
17
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
fieldDescriptionClass,
|
|
19
|
+
fieldErrorClass,
|
|
20
|
+
fieldLabelClass,
|
|
21
|
+
fieldSizeClasses,
|
|
22
|
+
fieldStackClass,
|
|
23
|
+
outlinedFieldClasses,
|
|
24
|
+
type FieldAppearance,
|
|
25
|
+
type FieldSize,
|
|
26
|
+
} from './field-appearance'
|
|
18
27
|
|
|
19
28
|
const SelectAppearanceContext = createContext<FieldAppearance>('outlined')
|
|
20
29
|
const filledPopoverStyle: CSSProperties & { '--select-popup-max-width': string } = {
|
|
@@ -27,31 +36,31 @@ const filledPopoverStyle: CSSProperties & { '--select-popup-max-width': string }
|
|
|
27
36
|
* RAC handles the listbox ARIA pattern, keyboard navigation, typeahead and
|
|
28
37
|
* focus management. Styling via `uic`. Pass options as `SelectItem` children.
|
|
29
38
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
39
|
+
* The outlined trigger uses the shared outlined skin and `size` scale, so it is
|
|
40
|
+
* the same box as an `Input` of the same size and a mixed form lines up. The
|
|
41
|
+
* filled trigger follows gs-platform's designer spec (Figma GraphicStandard 1.5,
|
|
42
|
+
* node 2115-4271, `Select.module.scss`). gs token map:
|
|
33
43
|
* hover border #aba89c → fg-subtle · text #0d0d0d → fg · placeholder → fg-muted ·
|
|
34
44
|
* 8px radius → rounded-lg · 6px item radius → rounded-md · error → danger.
|
|
35
45
|
*/
|
|
36
46
|
const SelectTrigger = uic(RACButton, {
|
|
37
47
|
displayName: 'SelectTrigger',
|
|
38
|
-
// Filled follows the Manager's borderless control
|
|
39
|
-
//
|
|
48
|
+
// Filled follows the Manager's borderless control. Outlined is the shared
|
|
49
|
+
// outlined skin; its height comes from `fieldSize`.
|
|
40
50
|
baseClass:
|
|
41
|
-
'flex w-full items-center justify-between gap-2.5 rounded-lg
|
|
51
|
+
'flex w-full items-center justify-between gap-2.5 rounded-lg text-small text-fg outline-none transition-colors',
|
|
42
52
|
variants: {
|
|
43
53
|
appearance: {
|
|
44
|
-
filled: 'min-h-control-tall border-0 bg-surface-card py-5 font-normal leading-4.5 duration-200 motion-reduce:transition-none ' +
|
|
54
|
+
filled: 'min-h-control-tall border-0 bg-surface-card px-5 py-5 font-normal leading-4.5 duration-200 motion-reduce:transition-none ' +
|
|
45
55
|
'data-[hovered]:bg-surface-muted group-data-[open]:bg-surface-card ' +
|
|
46
56
|
'data-[focus-visible]:outline-solid data-[focus-visible]:outline-2 data-[focus-visible]:outline-ring data-[focus-visible]:outline-offset-2 ' +
|
|
47
57
|
'group-data-[invalid]:ring-1 group-data-[invalid]:ring-danger ' +
|
|
48
58
|
'data-[disabled]:bg-surface-card data-[disabled]:opacity-50 data-[disabled]:cursor-not-allowed',
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
'data-[focus-visible]:ring-2 data-[focus-visible]:ring-ring ' +
|
|
52
|
-
'group-data-[invalid]:border-danger group-data-[invalid]:ring-2 group-data-[invalid]:ring-danger ' +
|
|
53
|
-
'data-[disabled]:bg-surface-muted data-[disabled]:opacity-60 data-[disabled]:pointer-events-none',
|
|
59
|
+
// Invalid lives on the Select root, not on the trigger button.
|
|
60
|
+
outlined: `px-4 ${outlinedFieldClasses({ invalid: 'group' })}`,
|
|
54
61
|
},
|
|
62
|
+
// Outlined only: filled keeps its fixed Manager height.
|
|
63
|
+
fieldSize: fieldSizeClasses,
|
|
55
64
|
},
|
|
56
65
|
defaultVariants: { appearance: 'outlined' },
|
|
57
66
|
})
|
|
@@ -104,6 +113,8 @@ const SelectPopover = uic(Popover, {
|
|
|
104
113
|
|
|
105
114
|
export type SelectProps<T extends object> = RACSelectProps<T> & {
|
|
106
115
|
appearance?: FieldAppearance
|
|
116
|
+
/** Outlined trigger height, matching `Input`'s `size`. Ignored when filled. */
|
|
117
|
+
size?: FieldSize
|
|
107
118
|
/** Keep the accessible label without reserving an empty label row. */
|
|
108
119
|
isLabelHidden?: boolean
|
|
109
120
|
/** Visible label (required for accessibility). */
|
|
@@ -132,6 +143,7 @@ export const Select = <T extends object>({
|
|
|
132
143
|
rootClassName,
|
|
133
144
|
triggerClassName,
|
|
134
145
|
appearance = 'outlined',
|
|
146
|
+
size = 'md',
|
|
135
147
|
isLabelHidden = false,
|
|
136
148
|
...props
|
|
137
149
|
}: SelectProps<T>) => {
|
|
@@ -151,8 +163,8 @@ export const Select = <T extends object>({
|
|
|
151
163
|
|
|
152
164
|
return (
|
|
153
165
|
<SelectAppearanceContext.Provider value={appearance}>
|
|
154
|
-
<RACSelect {...props} placeholder={placeholder} className={`group
|
|
155
|
-
<Label className={isLabelHidden ? 'sr-only' :
|
|
166
|
+
<RACSelect {...props} placeholder={placeholder} className={`group ${fieldStackClass} ${rootClassName ?? ''}`}>
|
|
167
|
+
<Label className={isLabelHidden ? 'sr-only' : fieldLabelClass}>{label}</Label>
|
|
156
168
|
{inFocus ? (
|
|
157
169
|
<>
|
|
158
170
|
{listbox}
|
|
@@ -161,8 +173,9 @@ export const Select = <T extends object>({
|
|
|
161
173
|
</>
|
|
162
174
|
) : (
|
|
163
175
|
<>
|
|
164
|
-
<SelectTrigger className={triggerClassName} appearance={appearance}>
|
|
165
|
-
|
|
176
|
+
<SelectTrigger className={triggerClassName} appearance={appearance} fieldSize={appearance === 'outlined' ? size : undefined}>
|
|
177
|
+
{/* One line: a long value must not wrap out of the fixed-height box. */}
|
|
178
|
+
<SelectValue className="min-w-0 truncate data-[placeholder]:text-fg-muted" />
|
|
166
179
|
{/* gs chevron: 9.5px caret, dark (neutral-400 → fg), non-interactive. */}
|
|
167
180
|
<svg
|
|
168
181
|
width="9.5"
|
|
@@ -8,7 +8,15 @@ import {
|
|
|
8
8
|
type TextFieldProps,
|
|
9
9
|
} from 'react-aria-components'
|
|
10
10
|
import { uic } from '../utils/uic'
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
fieldDescriptionClass,
|
|
13
|
+
fieldErrorClass,
|
|
14
|
+
fieldLabelClass,
|
|
15
|
+
fieldStackClass,
|
|
16
|
+
filledFieldClasses,
|
|
17
|
+
outlinedFieldClasses,
|
|
18
|
+
type FieldAppearance,
|
|
19
|
+
} from './field-appearance'
|
|
12
20
|
|
|
13
21
|
/**
|
|
14
22
|
* Textarea — labelled multi-line text field.
|
|
@@ -31,12 +39,7 @@ const StyledTextArea = uic(RACTextArea, {
|
|
|
31
39
|
variants: {
|
|
32
40
|
appearance: {
|
|
33
41
|
filled: filledFieldClasses,
|
|
34
|
-
outlined:
|
|
35
|
-
'outline-none transition-colors duration-200 placeholder:text-fg-muted ' +
|
|
36
|
-
'data-[hovered]:border-fg-subtle ' +
|
|
37
|
-
'data-[focused]:border-brand-green data-[focused]:ring-2 data-[focused]:ring-ring ' +
|
|
38
|
-
'data-[invalid]:border-danger data-[invalid]:ring-danger ' +
|
|
39
|
-
'data-[disabled]:bg-surface-muted data-[disabled]:opacity-60 data-[disabled]:pointer-events-none',
|
|
42
|
+
outlined: outlinedFieldClasses(),
|
|
40
43
|
},
|
|
41
44
|
},
|
|
42
45
|
defaultVariants: { appearance: 'outlined' },
|
|
@@ -60,8 +63,8 @@ export type TextareaProps = TextFieldProps & {
|
|
|
60
63
|
export const Textarea = ({ label, description, errorMessage, placeholder, rows, textAreaClassName, appearance = 'outlined', ...props }: TextareaProps) => (
|
|
61
64
|
// Label and gap match `Input` in both appearances (gs 17px/20px field label,
|
|
62
65
|
// 12px to the control), so a Title + Description pair reads as one form.
|
|
63
|
-
<TextField {...props} className=
|
|
64
|
-
<Label className=
|
|
66
|
+
<TextField {...props} className={`${fieldStackClass} w-full`}>
|
|
67
|
+
<Label className={fieldLabelClass}>{label}</Label>
|
|
65
68
|
<StyledTextArea className={textAreaClassName} placeholder={placeholder} rows={rows} appearance={appearance} />
|
|
66
69
|
{description ? (
|
|
67
70
|
<Text slot="description" className={fieldDescriptionClass}>
|