@tangible/ui 0.0.21 → 0.2.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/components/Button/Button.js +6 -8
- package/components/Button/types.d.ts +5 -7
- package/components/Chip/Chip.d.ts +28 -0
- package/components/Chip/Chip.js +19 -3
- package/components/Combobox/Combobox.d.ts +1 -1
- package/components/Combobox/Combobox.js +2 -2
- package/components/Combobox/types.d.ts +13 -0
- package/components/DatePicker/Calendar.d.ts +12 -0
- package/components/DatePicker/Calendar.js +145 -0
- package/components/DatePicker/DatePicker.d.ts +23 -0
- package/components/DatePicker/DatePicker.js +123 -0
- package/components/DatePicker/DateRangePicker.d.ts +16 -0
- package/components/DatePicker/DateRangePicker.js +114 -0
- package/components/DatePicker/date-utils.d.ts +51 -0
- package/components/DatePicker/date-utils.js +228 -0
- package/components/DatePicker/index.d.ts +8 -0
- package/components/DatePicker/index.js +6 -0
- package/components/DatePicker/presets.d.ts +3 -0
- package/components/DatePicker/presets.js +37 -0
- package/components/DatePicker/types.d.ts +138 -0
- package/components/DatePicker/types.js +39 -0
- package/components/IconButton/types.d.ts +2 -2
- package/components/MultiCombobox/MultiCombobox.d.ts +33 -0
- package/components/MultiCombobox/MultiCombobox.js +595 -0
- package/components/MultiCombobox/MultiComboboxContext.d.ts +8 -0
- package/components/MultiCombobox/MultiComboboxContext.js +36 -0
- package/components/MultiCombobox/index.d.ts +3 -0
- package/components/MultiCombobox/index.js +2 -0
- package/components/MultiCombobox/types.d.ts +244 -0
- package/components/MultiCombobox/types.js +7 -0
- package/components/MultiSelect/MultiSelect.js +22 -2
- package/components/Popover/Popover.js +16 -2
- package/components/SegmentedControl/types.d.ts +2 -2
- package/components/Select/Select.js +14 -0
- package/components/Slider/Slider.d.ts +2 -0
- package/components/Slider/Slider.js +29 -0
- package/components/Slider/index.d.ts +2 -0
- package/components/Slider/index.js +1 -0
- package/components/Slider/types.d.ts +39 -0
- package/components/Slider/types.js +1 -0
- package/components/index.d.ts +4 -0
- package/components/index.js +3 -0
- package/package.json +13 -1
- package/styles/all.css +1 -1
- package/styles/all.expanded.css +1181 -187
- package/styles/all.expanded.unlayered.css +1181 -187
- package/styles/all.unlayered.css +1 -1
- package/styles/components/_bundle.scss +6 -0
- package/styles/components/button.scss +59 -43
- package/styles/components/card.scss +1 -1
- package/styles/components/chip.scss +84 -10
- package/styles/components/combobox.scss +16 -2
- package/styles/components/date-picker.scss +400 -0
- package/styles/components/icon-button.scss +36 -30
- package/styles/components/input/index.scss +1 -2
- package/styles/components/multi-combobox.scss +457 -0
- package/styles/components/multi-select.scss +34 -18
- package/styles/components/notice.scss +15 -6
- package/styles/components/pager.scss +4 -2
- package/styles/components/popover.scss +6 -0
- package/styles/components/progress.scss +23 -6
- package/styles/components/segmented-control.scss +53 -15
- package/styles/components/select.scss +19 -3
- package/styles/components/slider.scss +184 -0
- package/styles/components/switch.scss +1 -1
- package/styles/core.css +1 -1
- package/styles/core.unlayered.css +1 -1
- package/styles/system/_control.scss +9 -8
- package/styles/system/_tokens.scss +16 -0
- package/tui-manifest.json +311 -14
- package/utils/portal.d.ts +0 -4
- package/utils/portal.js +38 -5
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
// =============================================================================
|
|
3
|
+
// Split Contexts for Performance
|
|
4
|
+
// =============================================================================
|
|
5
|
+
export const MultiComboboxActionsContext = createContext(null);
|
|
6
|
+
export const MultiComboboxStateContext = createContext(null);
|
|
7
|
+
export function useMultiComboboxActions() {
|
|
8
|
+
const context = useContext(MultiComboboxActionsContext);
|
|
9
|
+
if (!context) {
|
|
10
|
+
throw new Error('MultiCombobox components must be used within a MultiCombobox');
|
|
11
|
+
}
|
|
12
|
+
return context;
|
|
13
|
+
}
|
|
14
|
+
export function useMultiComboboxState() {
|
|
15
|
+
const context = useContext(MultiComboboxStateContext);
|
|
16
|
+
if (!context) {
|
|
17
|
+
throw new Error('MultiCombobox components must be used within a MultiCombobox');
|
|
18
|
+
}
|
|
19
|
+
return context;
|
|
20
|
+
}
|
|
21
|
+
export function useMultiComboboxContext() {
|
|
22
|
+
const actions = useMultiComboboxActions();
|
|
23
|
+
const state = useMultiComboboxState();
|
|
24
|
+
return { ...actions, ...state };
|
|
25
|
+
}
|
|
26
|
+
// =============================================================================
|
|
27
|
+
// Content Context (for Option registration)
|
|
28
|
+
// =============================================================================
|
|
29
|
+
export const MultiComboboxContentContext = createContext(null);
|
|
30
|
+
export function useMultiComboboxContentContext() {
|
|
31
|
+
const context = useContext(MultiComboboxContentContext);
|
|
32
|
+
if (!context) {
|
|
33
|
+
throw new Error('MultiCombobox.Option must be used within MultiCombobox.Content');
|
|
34
|
+
}
|
|
35
|
+
return context;
|
|
36
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { MultiCombobox, MultiComboboxContent, MultiComboboxOption, MultiComboboxGroup, MultiComboboxLabel, useMultiCombobox, } from './MultiCombobox';
|
|
2
|
+
export type { MultiComboboxProps, MultiComboboxContentProps, MultiComboboxOptionProps, MultiComboboxGroupProps, MultiComboboxLabelProps, MultiComboboxLabels, MultiComboboxValue, FilterMode as MultiComboboxFilterMode, RegisteredOption as MultiComboboxRegisteredOption, } from './types';
|
|
3
|
+
export { defaultMultiComboboxLabels } from './types';
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import type { FloatingContext, ReferenceType } from '@floating-ui/react';
|
|
2
|
+
import type { RefObject, CSSProperties, MutableRefObject } from 'react';
|
|
3
|
+
import type { SizeStandard } from '../../types/sizes';
|
|
4
|
+
import type { OptionValue } from '../../utils/value-key';
|
|
5
|
+
export type MultiComboboxLabels = {
|
|
6
|
+
/** Label for the clear-all button. */
|
|
7
|
+
clear?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Accessible label for a chip's remove button.
|
|
10
|
+
* @default (label) => `Remove ${label}`
|
|
11
|
+
*/
|
|
12
|
+
remove?: (label: string) => string;
|
|
13
|
+
/**
|
|
14
|
+
* Screen reader status announcement, fired on every selection change.
|
|
15
|
+
* When `max` is defined and `count >= max`, include a "maximum reached" note.
|
|
16
|
+
* @default (count, max) => count === 0 ? '0 items selected' : `${count} item${count === 1 ? '' : 's'} selected${max !== undefined && count >= max ? `. Maximum of ${max} reached` : ''}`
|
|
17
|
+
*/
|
|
18
|
+
status?: (count: number, max?: number) => string;
|
|
19
|
+
};
|
|
20
|
+
export declare const defaultMultiComboboxLabels: Required<MultiComboboxLabels>;
|
|
21
|
+
/**
|
|
22
|
+
* Controls when filtering should be active.
|
|
23
|
+
* - 'always': Consumer filters whenever inputValue changes (default)
|
|
24
|
+
* - 'when-searching': Query becomes empty when not actively searching,
|
|
25
|
+
* allowing consumers to show all options when browsing selections
|
|
26
|
+
*/
|
|
27
|
+
export type FilterMode = 'always' | 'when-searching';
|
|
28
|
+
/**
|
|
29
|
+
* Value type for MultiCombobox — arrays of strings or numbers.
|
|
30
|
+
*/
|
|
31
|
+
export type MultiComboboxValue = Array<string | number>;
|
|
32
|
+
export type MultiComboboxProps = {
|
|
33
|
+
/**
|
|
34
|
+
* Control size.
|
|
35
|
+
* @default 'md'
|
|
36
|
+
*/
|
|
37
|
+
size?: SizeStandard;
|
|
38
|
+
/**
|
|
39
|
+
* How selected chips behave when they exceed the control width.
|
|
40
|
+
* - 'trim' (default): the control stays a single line (fixed height); chips
|
|
41
|
+
* flow horizontally and clip toward the inline-start, keeping the typing
|
|
42
|
+
* area in view. Preserves row alignment in multi-column form layouts.
|
|
43
|
+
* - 'wrap': chips wrap onto new lines and the control grows vertically.
|
|
44
|
+
* Opt in for standalone or spacious placements.
|
|
45
|
+
* @default 'trim'
|
|
46
|
+
*/
|
|
47
|
+
overflow?: 'wrap' | 'trim';
|
|
48
|
+
/**
|
|
49
|
+
* Controlled selected values.
|
|
50
|
+
*/
|
|
51
|
+
value?: MultiComboboxValue;
|
|
52
|
+
/**
|
|
53
|
+
* Default values for uncontrolled usage.
|
|
54
|
+
*/
|
|
55
|
+
defaultValue?: MultiComboboxValue;
|
|
56
|
+
/**
|
|
57
|
+
* Callback when selection changes.
|
|
58
|
+
*/
|
|
59
|
+
onValueChange?: (value: MultiComboboxValue) => void;
|
|
60
|
+
/**
|
|
61
|
+
* Controlled input value for search/filter.
|
|
62
|
+
*/
|
|
63
|
+
inputValue?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Callback when input value changes (typing, clear).
|
|
66
|
+
*/
|
|
67
|
+
onInputChange?: (value: string) => void;
|
|
68
|
+
/**
|
|
69
|
+
* Controls filtering behavior.
|
|
70
|
+
* @default 'always'
|
|
71
|
+
*/
|
|
72
|
+
filterMode?: FilterMode;
|
|
73
|
+
/**
|
|
74
|
+
* Callback when the effective query changes.
|
|
75
|
+
*/
|
|
76
|
+
onQueryChange?: (query: string) => void;
|
|
77
|
+
/**
|
|
78
|
+
* Controlled open state.
|
|
79
|
+
*/
|
|
80
|
+
open?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Default open state for uncontrolled usage.
|
|
83
|
+
* @default false
|
|
84
|
+
*/
|
|
85
|
+
defaultOpen?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Callback when open state changes.
|
|
88
|
+
*/
|
|
89
|
+
onOpenChange?: (open: boolean) => void;
|
|
90
|
+
/**
|
|
91
|
+
* Whether the combobox is disabled.
|
|
92
|
+
* @default false
|
|
93
|
+
*/
|
|
94
|
+
disabled?: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Placeholder text for the input. Shown only when no values are selected.
|
|
97
|
+
*/
|
|
98
|
+
placeholder?: string;
|
|
99
|
+
/**
|
|
100
|
+
* Whether to open the listbox when the input receives focus.
|
|
101
|
+
* @default true
|
|
102
|
+
*/
|
|
103
|
+
openOnFocus?: boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Maximum number of selections allowed.
|
|
106
|
+
* When reached, unselected options become disabled.
|
|
107
|
+
*/
|
|
108
|
+
max?: number;
|
|
109
|
+
/**
|
|
110
|
+
* Callback when max selections is reached.
|
|
111
|
+
*/
|
|
112
|
+
onMaxReached?: () => void;
|
|
113
|
+
/**
|
|
114
|
+
* Accessible name for the combobox.
|
|
115
|
+
*/
|
|
116
|
+
'aria-label'?: string;
|
|
117
|
+
/**
|
|
118
|
+
* ID of element that labels this combobox.
|
|
119
|
+
*/
|
|
120
|
+
'aria-labelledby'?: string;
|
|
121
|
+
/**
|
|
122
|
+
* ID(s) of element(s) that describe this combobox (helper text, error).
|
|
123
|
+
* Forwarded to the input — Field.Control injects this.
|
|
124
|
+
*/
|
|
125
|
+
'aria-describedby'?: string;
|
|
126
|
+
/**
|
|
127
|
+
* Invalid state, forwarded to the input. Field.Control injects this.
|
|
128
|
+
*/
|
|
129
|
+
'aria-invalid'?: boolean | 'true' | 'false';
|
|
130
|
+
/**
|
|
131
|
+
* Required state, forwarded to the input. Field.Control injects this.
|
|
132
|
+
*/
|
|
133
|
+
'aria-required'?: boolean | 'true' | 'false';
|
|
134
|
+
/**
|
|
135
|
+
* Whether to show the clear-all button when values are present.
|
|
136
|
+
* @default true
|
|
137
|
+
*/
|
|
138
|
+
clearable?: boolean;
|
|
139
|
+
/**
|
|
140
|
+
* Class name applied directly to the `<input>` element.
|
|
141
|
+
* Use for utilities like `tui-input-reset` that must target the input itself.
|
|
142
|
+
*/
|
|
143
|
+
inputClassName?: string;
|
|
144
|
+
/**
|
|
145
|
+
* Override default English strings for i18n.
|
|
146
|
+
*/
|
|
147
|
+
labels?: MultiComboboxLabels;
|
|
148
|
+
children: React.ReactNode;
|
|
149
|
+
};
|
|
150
|
+
export type MultiComboboxContentProps = {
|
|
151
|
+
className?: string;
|
|
152
|
+
children: React.ReactNode;
|
|
153
|
+
};
|
|
154
|
+
export type MultiComboboxOptionProps = {
|
|
155
|
+
/**
|
|
156
|
+
* The value for this option. Required and must be unique.
|
|
157
|
+
* Can be string or number.
|
|
158
|
+
*/
|
|
159
|
+
value: OptionValue;
|
|
160
|
+
/**
|
|
161
|
+
* Whether this option is disabled.
|
|
162
|
+
* @default false
|
|
163
|
+
*/
|
|
164
|
+
disabled?: boolean;
|
|
165
|
+
/**
|
|
166
|
+
* Text value used for the chip label when selected.
|
|
167
|
+
* Required when children is not a string.
|
|
168
|
+
* If children is a string, defaults to that.
|
|
169
|
+
*/
|
|
170
|
+
textValue?: string;
|
|
171
|
+
className?: string;
|
|
172
|
+
children: React.ReactNode;
|
|
173
|
+
};
|
|
174
|
+
export type MultiComboboxGroupProps = {
|
|
175
|
+
className?: string;
|
|
176
|
+
children: React.ReactNode;
|
|
177
|
+
};
|
|
178
|
+
export type MultiComboboxLabelProps = {
|
|
179
|
+
className?: string;
|
|
180
|
+
children: React.ReactNode;
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* Registration record for an option.
|
|
184
|
+
*/
|
|
185
|
+
export type RegisteredOption = {
|
|
186
|
+
value: OptionValue;
|
|
187
|
+
ref: RefObject<HTMLElement | null>;
|
|
188
|
+
disabled: boolean;
|
|
189
|
+
textValue: string;
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* Stable context: config, IDs, refs, and stable callbacks.
|
|
193
|
+
*/
|
|
194
|
+
export type MultiComboboxActionsContextValue = {
|
|
195
|
+
disabled: boolean;
|
|
196
|
+
placeholder: string;
|
|
197
|
+
openOnFocus: boolean;
|
|
198
|
+
max: number | undefined;
|
|
199
|
+
inputId: string;
|
|
200
|
+
listboxId: string;
|
|
201
|
+
ariaLabel?: string;
|
|
202
|
+
ariaLabelledBy?: string;
|
|
203
|
+
setOpen: (open: boolean) => void;
|
|
204
|
+
setInputValue: (value: string) => void;
|
|
205
|
+
toggleOption: (value: OptionValue, textValue: string) => void;
|
|
206
|
+
registerOption: (option: RegisteredOption) => void;
|
|
207
|
+
unregisterOption: (value: OptionValue) => void;
|
|
208
|
+
refs: {
|
|
209
|
+
reference: React.RefObject<ReferenceType | null>;
|
|
210
|
+
floating: React.RefObject<HTMLElement | null>;
|
|
211
|
+
setReference: (node: ReferenceType | null) => void;
|
|
212
|
+
setFloating: (node: HTMLElement | null) => void;
|
|
213
|
+
};
|
|
214
|
+
inputRef: RefObject<HTMLInputElement | null>;
|
|
215
|
+
listRef: MutableRefObject<(HTMLElement | null)[]>;
|
|
216
|
+
getReferenceProps: (userProps?: React.HTMLProps<Element>) => Record<string, unknown>;
|
|
217
|
+
getFloatingProps: (userProps?: React.HTMLProps<HTMLElement>) => Record<string, unknown>;
|
|
218
|
+
getItemProps: (userProps?: React.HTMLProps<HTMLElement>) => Record<string, unknown>;
|
|
219
|
+
};
|
|
220
|
+
/**
|
|
221
|
+
* State context: values that change during interaction.
|
|
222
|
+
*/
|
|
223
|
+
export type MultiComboboxStateContextValue = {
|
|
224
|
+
open: boolean;
|
|
225
|
+
value: MultiComboboxValue;
|
|
226
|
+
inputValue: string;
|
|
227
|
+
maxReached: boolean;
|
|
228
|
+
isSelected: (value: OptionValue) => boolean;
|
|
229
|
+
query: string;
|
|
230
|
+
activeIndex: number;
|
|
231
|
+
activeOptionId: string | undefined;
|
|
232
|
+
orderedOptions: RegisteredOption[];
|
|
233
|
+
floatingStyles: CSSProperties;
|
|
234
|
+
floatingContext: FloatingContext;
|
|
235
|
+
};
|
|
236
|
+
/**
|
|
237
|
+
* Combined context value.
|
|
238
|
+
*/
|
|
239
|
+
export type MultiComboboxContextValue = MultiComboboxActionsContextValue & MultiComboboxStateContextValue;
|
|
240
|
+
export type MultiComboboxContentContextValue = {
|
|
241
|
+
listRef: MutableRefObject<(HTMLElement | null)[]>;
|
|
242
|
+
activeIndex: number;
|
|
243
|
+
orderedOptions: RegisteredOption[];
|
|
244
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const defaultMultiComboboxLabels = {
|
|
2
|
+
clear: 'Clear all',
|
|
3
|
+
remove: (label) => `Remove ${label}`,
|
|
4
|
+
status: (count, max) => count === 0
|
|
5
|
+
? '0 items selected'
|
|
6
|
+
: `${count} item${count === 1 ? '' : 's'} selected${max !== undefined && count >= max ? `. Maximum of ${max} reached` : ''}`,
|
|
7
|
+
};
|
|
@@ -5,6 +5,7 @@ import { useFloating, offset, flip, shift, size as sizeMiddleware, autoUpdate, F
|
|
|
5
5
|
import { cx } from '../../utils/cx.js';
|
|
6
6
|
import { getPortalRootFor } from '../../utils/portal.js';
|
|
7
7
|
import { Icon } from '../Icon/index.js';
|
|
8
|
+
import { Chip } from '../Chip/index.js';
|
|
8
9
|
import { MultiSelectActionsContext, MultiSelectStateContext, MultiSelectContentContext, useMultiSelectContext, useMultiSelectContentContext, } from './MultiSelectContext.js';
|
|
9
10
|
import { toKey, defaultMultiSelectLabels, } from './types.js';
|
|
10
11
|
// =============================================================================
|
|
@@ -431,11 +432,25 @@ function MultiSelectTriggerComponent({ asChild = false, className, children, })
|
|
|
431
432
|
return;
|
|
432
433
|
clearAll();
|
|
433
434
|
}, [disabled, clearAll]);
|
|
435
|
+
// Safari doesn't focus buttons on mousedown — focus jumps to <body>, firing
|
|
436
|
+
// a blur that handleBlur reads as focus-loss and closes the menu, so a click
|
|
437
|
+
// on the open trigger closes-then-reopens and never visibly toggles. Focus
|
|
438
|
+
// the trigger ourselves and cancel the browser's focus juggling. Mouse/pen
|
|
439
|
+
// only: cancelling pointerdown on touch swallows the compatibility click.
|
|
440
|
+
const handleTriggerPointerDown = useCallback((e) => {
|
|
441
|
+
if (e.pointerType !== 'mouse' && e.pointerType !== 'pen')
|
|
442
|
+
return;
|
|
443
|
+
if (e.button !== 0)
|
|
444
|
+
return;
|
|
445
|
+
e.preventDefault();
|
|
446
|
+
e.currentTarget.focus();
|
|
447
|
+
}, []);
|
|
434
448
|
// Get Floating UI's reference props
|
|
435
449
|
const floatingProps = getReferenceProps({
|
|
436
450
|
'aria-activedescendant': activeIndex !== null ? `${listboxId}-option-${activeIndex}` : undefined,
|
|
437
451
|
onKeyDown: handleKeyDown,
|
|
438
452
|
onBlur: handleBlur,
|
|
453
|
+
onPointerDown: handleTriggerPointerDown,
|
|
439
454
|
});
|
|
440
455
|
// Render trigger content based on display mode
|
|
441
456
|
const renderTriggerContent = () => {
|
|
@@ -445,10 +460,15 @@ function MultiSelectTriggerComponent({ asChild = false, className, children, })
|
|
|
445
460
|
if (display === 'count') {
|
|
446
461
|
return (_jsx("span", { className: "tui-multiselect__count", children: labels.selected(selectedOptions.length) }));
|
|
447
462
|
}
|
|
448
|
-
// chips mode
|
|
463
|
+
// chips mode — display-only Chips (the shared component, so they read the
|
|
464
|
+
// same as MultiCombobox's token chips). No remove button: MultiSelect
|
|
465
|
+
// manages selection through the dropdown, and a truncated summary (maxChips
|
|
466
|
+
// + "+N more") can't offer a per-chip × for the collapsed items anyway.
|
|
449
467
|
const visibleChips = selectedOptions.slice(0, maxChips);
|
|
450
468
|
const overflow = selectedOptions.length - maxChips;
|
|
451
|
-
|
|
469
|
+
// Chips track the control size, matching MultiCombobox.
|
|
470
|
+
const chipSize = size === 'lg' ? 'md' : size === 'sm' ? 'xs' : 'sm';
|
|
471
|
+
return (_jsxs("span", { className: "tui-multiselect__chips", children: [visibleChips.map((opt) => (_jsx(Chip, { size: chipSize, className: "tui-multiselect__chip", children: opt.textValue }, toKey(opt.value)))), overflow > 0 && (_jsx("span", { className: "tui-multiselect__more", children: labels.more(overflow) }))] }));
|
|
452
472
|
};
|
|
453
473
|
// Default trigger content (when not using asChild or custom children)
|
|
454
474
|
const defaultTriggerContent = (_jsxs(_Fragment, { children: [_jsx("span", { className: "tui-multiselect__value", children: renderTriggerContent() }), hasSelection && (_jsx("span", { className: "tui-multiselect__clear", onClick: handleClearClick, "aria-hidden": "true", children: _jsx(Icon, { name: "system/close" }) })), _jsx(Icon, { name: "system/chevron-down", className: "tui-multiselect__icon", "aria-hidden": "true" })] }));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import React, { useCallback, useEffect, useId, useMemo, useRef, useState, cloneElement, isValidElement, } from 'react';
|
|
3
|
-
import { useFloating, offset, flip, shift, autoUpdate, FloatingPortal, useDismiss, useInteractions, useRole, FloatingFocusManager, } from '@floating-ui/react';
|
|
3
|
+
import { useFloating, offset, flip, shift, size, autoUpdate, FloatingPortal, useDismiss, useInteractions, useRole, FloatingFocusManager, } from '@floating-ui/react';
|
|
4
4
|
import { cx } from '../../utils/cx.js';
|
|
5
5
|
import { getPortalRootFor } from '../../utils/portal.js';
|
|
6
6
|
import { PopoverContext, usePopoverContext } from './PopoverContext.js';
|
|
@@ -114,7 +114,21 @@ function PopoverContentInner({ side = 'bottom', align = 'start', sideOffset = 4,
|
|
|
114
114
|
placement: toPlacement(side, align),
|
|
115
115
|
open: true, // Always true when mounted (gate handles the conditional)
|
|
116
116
|
onOpenChange: setOpen,
|
|
117
|
-
middleware: [
|
|
117
|
+
middleware: [
|
|
118
|
+
offset(sideOffset),
|
|
119
|
+
flip(),
|
|
120
|
+
shift({ padding: 8 }),
|
|
121
|
+
// When even the best placement can't fit the content, expose the
|
|
122
|
+
// available height so the panel can cap itself and scroll (see
|
|
123
|
+
// --tui-popover-available-height in styles.scss). Output var, not an
|
|
124
|
+
// API token — the middleware writes it, the stylesheet reads it.
|
|
125
|
+
size({
|
|
126
|
+
padding: 8,
|
|
127
|
+
apply({ availableHeight, elements }) {
|
|
128
|
+
elements.floating.style.setProperty('--tui-popover-available-height', `${Math.floor(availableHeight)}px`);
|
|
129
|
+
},
|
|
130
|
+
}),
|
|
131
|
+
],
|
|
118
132
|
whileElementsMounted: autoUpdate,
|
|
119
133
|
});
|
|
120
134
|
// Sync reference element
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
2
|
import type { RovingItemRecord } from '../../utils/use-roving-group';
|
|
3
|
-
import type {
|
|
3
|
+
import type { Size } from '../../types/sizes';
|
|
4
4
|
export type SegmentedControlValue = string | number;
|
|
5
5
|
export type SegmentedControlVariant = 'pill' | 'outline' | 'underline';
|
|
6
|
-
export type SegmentedControlSize =
|
|
6
|
+
export type SegmentedControlSize = Size;
|
|
7
7
|
export type SegmentedControlOrientation = 'horizontal' | 'vertical';
|
|
8
8
|
export type SegmentedControlProps = {
|
|
9
9
|
/** Controlled selected value */
|
|
@@ -364,11 +364,25 @@ function SelectTriggerComponent({ asChild = false, className, children, }) {
|
|
|
364
364
|
// Return focus to trigger after clearing
|
|
365
365
|
refs.reference.current?.focus();
|
|
366
366
|
}, [disabled, setValue, refs.reference]);
|
|
367
|
+
// Safari doesn't focus buttons on mousedown — focus jumps to <body>, firing
|
|
368
|
+
// a blur that handleBlur reads as focus-loss and closes the menu, so a click
|
|
369
|
+
// on the open trigger closes-then-reopens and never visibly toggles. Focus
|
|
370
|
+
// the trigger ourselves and cancel the browser's focus juggling. Mouse/pen
|
|
371
|
+
// only: cancelling pointerdown on touch swallows the compatibility click.
|
|
372
|
+
const handleTriggerPointerDown = useCallback((e) => {
|
|
373
|
+
if (e.pointerType !== 'mouse' && e.pointerType !== 'pen')
|
|
374
|
+
return;
|
|
375
|
+
if (e.button !== 0)
|
|
376
|
+
return;
|
|
377
|
+
e.preventDefault();
|
|
378
|
+
e.currentTarget.focus();
|
|
379
|
+
}, []);
|
|
367
380
|
// Get Floating UI's reference props - pass our handlers so they get composed
|
|
368
381
|
const floatingProps = getReferenceProps({
|
|
369
382
|
'aria-activedescendant': activeIndex !== null ? `${listboxId}-option-${activeIndex}` : undefined,
|
|
370
383
|
onKeyDown: handleKeyDown,
|
|
371
384
|
onBlur: handleBlur,
|
|
385
|
+
onPointerDown: handleTriggerPointerDown,
|
|
372
386
|
});
|
|
373
387
|
const triggerProps = {
|
|
374
388
|
id: triggerId,
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import { cx } from '../../utils/cx.js';
|
|
4
|
+
import { useControllableState } from '../../utils/use-controllable-state.js';
|
|
5
|
+
// =============================================================================
|
|
6
|
+
// Slider Component
|
|
7
|
+
// =============================================================================
|
|
8
|
+
//
|
|
9
|
+
// A native <input type="range"> carries all interaction and a11y (keyboard,
|
|
10
|
+
// pointer, form participation, role=slider announcements); the visible track
|
|
11
|
+
// is custom-drawn behind it so it can do what native tracks can't — the
|
|
12
|
+
// segmented pill rhythm and a fill that follows the design system's tokens.
|
|
13
|
+
//
|
|
14
|
+
// The fill layer duplicates the segment row and clips itself to the value's
|
|
15
|
+
// percentage, so fill and rest segments stay perfectly aligned at any width.
|
|
16
|
+
export const Slider = forwardRef(function Slider({ value: controlledValue, defaultValue, min = 0, max = 100, step, onValueChange, segments = 1, startLabel, endLabel, getValueText, disabled = false, id, className, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledby, }, ref) {
|
|
17
|
+
const [rawValue, setValue] = useControllableState({
|
|
18
|
+
value: controlledValue,
|
|
19
|
+
defaultValue: defaultValue ?? min,
|
|
20
|
+
onChange: onValueChange,
|
|
21
|
+
});
|
|
22
|
+
const value = rawValue ?? min;
|
|
23
|
+
// Segments snap: a segmented track quantises to its boundaries unless an
|
|
24
|
+
// explicit step overrides it.
|
|
25
|
+
const effectiveStep = step ?? (segments > 1 ? (max - min) / segments : 1);
|
|
26
|
+
const fill = max > min ? ((value - min) / (max - min)) * 100 : 0;
|
|
27
|
+
const segmentRow = Array.from({ length: Math.max(1, segments) }, (_, i) => (_jsx("span", { className: "tui-slider__segment" }, i)));
|
|
28
|
+
return (_jsxs("div", { className: cx('tui-slider', disabled && 'is-disabled', className), children: [_jsxs("div", { className: "tui-slider__control", children: [_jsxs("div", { className: "tui-slider__track", "aria-hidden": "true", children: [segmentRow, _jsx("div", { className: "tui-slider__fill", style: { clipPath: `inset(0 ${100 - fill}% 0 0)` }, children: segmentRow })] }), _jsx("input", { ref: ref, type: "range", className: "tui-slider__input", id: id, min: min, max: max, step: effectiveStep, value: value, disabled: disabled, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledby, "aria-valuetext": getValueText ? getValueText(value) : undefined, onChange: (e) => setValue(Number(e.target.value)) })] }), (startLabel || endLabel) && (_jsxs("div", { className: "tui-slider__labels", children: [_jsx("span", { className: "tui-slider__label", children: startLabel }), _jsx("span", { className: "tui-slider__label", children: endLabel })] }))] }));
|
|
29
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Slider } from './Slider.js';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
export interface SliderProps {
|
|
3
|
+
/** Controlled value. */
|
|
4
|
+
value?: number;
|
|
5
|
+
/** Uncontrolled initial value. Defaults to `min`. */
|
|
6
|
+
defaultValue?: number;
|
|
7
|
+
/** Minimum value. Defaults to 0. */
|
|
8
|
+
min?: number;
|
|
9
|
+
/** Maximum value. Defaults to 100. */
|
|
10
|
+
max?: number;
|
|
11
|
+
/**
|
|
12
|
+
* Step increment. Defaults to 1 — except on a segmented track, where it
|
|
13
|
+
* defaults to the segment span so the value snaps to segment boundaries.
|
|
14
|
+
* Pass an explicit step to override either default.
|
|
15
|
+
*/
|
|
16
|
+
step?: number;
|
|
17
|
+
/** Called with the new value on every change. */
|
|
18
|
+
onValueChange?: (value: number) => void;
|
|
19
|
+
/**
|
|
20
|
+
* Track segmentation: renders the track as this many pill segments with
|
|
21
|
+
* gaps between them, and (unless `step` says otherwise) snaps the value
|
|
22
|
+
* to the segment boundaries. `1` (default) is a continuous track.
|
|
23
|
+
*/
|
|
24
|
+
segments?: number;
|
|
25
|
+
/** Label rendered under the track's start edge (e.g. "Less rounded"). */
|
|
26
|
+
startLabel?: ReactNode;
|
|
27
|
+
/** Label rendered under the track's end edge (e.g. "More rounded"). */
|
|
28
|
+
endLabel?: ReactNode;
|
|
29
|
+
/**
|
|
30
|
+
* Human-readable value for assistive tech (`aria-valuetext`), e.g.
|
|
31
|
+
* `(v) => `${v} pixels``. Without it screen readers announce the number.
|
|
32
|
+
*/
|
|
33
|
+
getValueText?: (value: number) => string;
|
|
34
|
+
disabled?: boolean;
|
|
35
|
+
id?: string;
|
|
36
|
+
className?: string;
|
|
37
|
+
'aria-label'?: string;
|
|
38
|
+
'aria-labelledby'?: string;
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/components/index.d.ts
CHANGED
|
@@ -10,7 +10,9 @@ export { Chip } from './Chip';
|
|
|
10
10
|
export { ChipGroup } from './ChipGroup';
|
|
11
11
|
export { Chips } from './Chips';
|
|
12
12
|
export { ContentIndicator } from './ContentIndicator';
|
|
13
|
+
export { Calendar, DatePicker, DateRangePicker, defaultDateRangePresets, defaultCalendarLabels, defaultDatePickerLabels, defaultDateRangePickerLabels, } from './DatePicker';
|
|
13
14
|
export { Combobox, ComboboxContent, ComboboxOption, ComboboxGroup, ComboboxLabel, useCombobox } from './Combobox';
|
|
15
|
+
export { MultiCombobox, MultiComboboxContent, MultiComboboxOption, MultiComboboxGroup, MultiComboboxLabel, useMultiCombobox } from './MultiCombobox';
|
|
14
16
|
export { Dropdown, DropdownTrigger, DropdownContent, DropdownItem, DropdownSeparator, DropdownHeader, useDropdown } from './Dropdown';
|
|
15
17
|
export { Field } from './Field';
|
|
16
18
|
export { MultiSelect, MultiSelectTrigger, MultiSelectContent, MultiSelectOption, MultiSelectGroup, MultiSelectLabel, useMultiSelect } from './MultiSelect';
|
|
@@ -27,6 +29,7 @@ export { Progress } from './Progress';
|
|
|
27
29
|
export { RadioGroup, Radio } from './Radio';
|
|
28
30
|
export { Rating } from './Rating';
|
|
29
31
|
export { SegmentedControl } from './SegmentedControl';
|
|
32
|
+
export { Slider } from './Slider';
|
|
30
33
|
export { Sidebar } from './Sidebar';
|
|
31
34
|
export { StepIndicator } from './StepIndicator';
|
|
32
35
|
export { StepList } from './StepList';
|
|
@@ -48,6 +51,7 @@ export type { ChipsProps, ChipOption } from './Chips';
|
|
|
48
51
|
export type { ContentIndicatorProps } from './ContentIndicator';
|
|
49
52
|
export type { DropdownProps, DropdownTriggerProps, DropdownContentProps, DropdownItemProps, DropdownSeparatorProps, DropdownHeaderProps, } from './Dropdown';
|
|
50
53
|
export type { ComboboxProps, ComboboxContentProps, ComboboxOptionProps, ComboboxGroupProps, ComboboxLabelProps, ComboboxRegisteredOption, } from './Combobox';
|
|
54
|
+
export type { MultiComboboxProps, MultiComboboxContentProps, MultiComboboxOptionProps, MultiComboboxGroupProps, MultiComboboxLabelProps, MultiComboboxLabels, MultiComboboxValue, MultiComboboxFilterMode, MultiComboboxRegisteredOption, } from './MultiCombobox';
|
|
51
55
|
export type { FieldProps } from './Field';
|
|
52
56
|
export type { MultiSelectProps, MultiSelectTriggerProps, MultiSelectContentProps, MultiSelectOptionProps, MultiSelectGroupProps, MultiSelectLabelProps, MultiSelectValue, OptionValue as MultiSelectOptionValue, DisplayMode as MultiSelectDisplayMode, MultiSelectRegisteredOption, } from './MultiSelect';
|
|
53
57
|
export type { SelectProps, SelectTriggerProps, SelectContentProps, SelectOptionProps, SelectGroupProps, SelectLabelProps, } from './Select';
|
package/components/index.js
CHANGED
|
@@ -8,7 +8,9 @@ export { Chip } from './Chip/index.js';
|
|
|
8
8
|
export { ChipGroup } from './ChipGroup/index.js';
|
|
9
9
|
export { Chips } from './Chips/index.js';
|
|
10
10
|
export { ContentIndicator } from './ContentIndicator/index.js';
|
|
11
|
+
export { Calendar, DatePicker, DateRangePicker, defaultDateRangePresets, defaultCalendarLabels, defaultDatePickerLabels, defaultDateRangePickerLabels, } from './DatePicker/index.js';
|
|
11
12
|
export { Combobox, ComboboxContent, ComboboxOption, ComboboxGroup, ComboboxLabel, useCombobox } from './Combobox/index.js';
|
|
13
|
+
export { MultiCombobox, MultiComboboxContent, MultiComboboxOption, MultiComboboxGroup, MultiComboboxLabel, useMultiCombobox } from './MultiCombobox/index.js';
|
|
12
14
|
export { Dropdown, DropdownTrigger, DropdownContent, DropdownItem, DropdownSeparator, DropdownHeader, useDropdown } from './Dropdown/index.js';
|
|
13
15
|
export { Field } from './Field/index.js';
|
|
14
16
|
export { MultiSelect, MultiSelectTrigger, MultiSelectContent, MultiSelectOption, MultiSelectGroup, MultiSelectLabel, useMultiSelect } from './MultiSelect/index.js';
|
|
@@ -25,6 +27,7 @@ export { Progress } from './Progress/index.js';
|
|
|
25
27
|
export { RadioGroup, Radio } from './Radio/index.js';
|
|
26
28
|
export { Rating } from './Rating/index.js';
|
|
27
29
|
export { SegmentedControl } from './SegmentedControl/index.js';
|
|
30
|
+
export { Slider } from './Slider/index.js';
|
|
28
31
|
export { Sidebar } from './Sidebar/index.js';
|
|
29
32
|
export { StepIndicator } from './StepIndicator/index.js';
|
|
30
33
|
export { StepList } from './StepList/index.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tangible/ui",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Tangible Design System",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./components/index.js",
|
|
@@ -88,6 +88,10 @@
|
|
|
88
88
|
"import": "./components/ContentIndicator/index.js",
|
|
89
89
|
"types": "./components/ContentIndicator/index.d.ts"
|
|
90
90
|
},
|
|
91
|
+
"./components/DatePicker": {
|
|
92
|
+
"import": "./components/DatePicker/index.js",
|
|
93
|
+
"types": "./components/DatePicker/index.d.ts"
|
|
94
|
+
},
|
|
91
95
|
"./components/Dropdown": {
|
|
92
96
|
"import": "./components/Dropdown/index.js",
|
|
93
97
|
"types": "./components/Dropdown/index.d.ts"
|
|
@@ -112,6 +116,10 @@
|
|
|
112
116
|
"import": "./components/MoveHandle/index.js",
|
|
113
117
|
"types": "./components/MoveHandle/index.d.ts"
|
|
114
118
|
},
|
|
119
|
+
"./components/MultiCombobox": {
|
|
120
|
+
"import": "./components/MultiCombobox/index.js",
|
|
121
|
+
"types": "./components/MultiCombobox/index.d.ts"
|
|
122
|
+
},
|
|
115
123
|
"./components/MultiSelect": {
|
|
116
124
|
"import": "./components/MultiSelect/index.js",
|
|
117
125
|
"types": "./components/MultiSelect/index.d.ts"
|
|
@@ -156,6 +164,10 @@
|
|
|
156
164
|
"import": "./components/Sidebar/index.js",
|
|
157
165
|
"types": "./components/Sidebar/index.d.ts"
|
|
158
166
|
},
|
|
167
|
+
"./components/Slider": {
|
|
168
|
+
"import": "./components/Slider/index.js",
|
|
169
|
+
"types": "./components/Slider/index.d.ts"
|
|
170
|
+
},
|
|
159
171
|
"./components/StepIndicator": {
|
|
160
172
|
"import": "./components/StepIndicator/index.js",
|
|
161
173
|
"types": "./components/StepIndicator/index.d.ts"
|