@hebium-ui/react 0.1.0-alpha.3 → 0.1.0-alpha.4
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/dist/components/alert/alert.d.ts +3 -4
- package/dist/components/alert/alert.js +4 -11
- package/dist/components/alert/alert.js.map +1 -1
- package/dist/components/anchor/anchor.d.ts +1 -2
- package/dist/components/anchor/anchor.js +2 -2
- package/dist/components/anchor/anchor.js.map +1 -1
- package/dist/components/avatar/avatar.d.ts +1 -2
- package/dist/components/avatar/avatar.js +2 -2
- package/dist/components/avatar/avatar.js.map +1 -1
- package/dist/components/blockquote/blockquote.d.ts +1 -2
- package/dist/components/blockquote/blockquote.js +2 -2
- package/dist/components/blockquote/blockquote.js.map +1 -1
- package/dist/components/button/button.d.ts +12 -2
- package/dist/components/button/button.js +29 -9
- package/dist/components/button/button.js.map +1 -1
- package/dist/components/checkbox/checkbox.d.ts +1 -2
- package/dist/components/checkbox/checkbox.js +2 -2
- package/dist/components/checkbox/checkbox.js.map +1 -1
- package/dist/components/code/code.d.ts +1 -2
- package/dist/components/code/code.js +2 -2
- package/dist/components/code/code.js.map +1 -1
- package/dist/components/combobox/combobox-option.js +33 -0
- package/dist/components/combobox/combobox-option.js.map +1 -0
- package/dist/components/combobox/combobox.d.ts +61 -0
- package/dist/components/combobox/combobox.js +208 -0
- package/dist/components/combobox/combobox.js.map +1 -0
- package/dist/components/combobox/index.d.ts +2 -0
- package/dist/components/combobox/use-combobox-form.js +33 -0
- package/dist/components/combobox/use-combobox-form.js.map +1 -0
- package/dist/components/combobox/use-combobox-popover.js +66 -0
- package/dist/components/combobox/use-combobox-popover.js.map +1 -0
- package/dist/components/combobox/use-combobox-state.js +96 -0
- package/dist/components/combobox/use-combobox-state.js.map +1 -0
- package/dist/components/details/details.d.ts +1 -2
- package/dist/components/details/details.js +2 -2
- package/dist/components/details/details.js.map +1 -1
- package/dist/components/dialog/dialog.d.ts +4 -5
- package/dist/components/dialog/dialog.js +26 -13
- package/dist/components/dialog/dialog.js.map +1 -1
- package/dist/components/dialog/index.d.ts +1 -2
- package/dist/components/dl/dl.d.ts +1 -2
- package/dist/components/dl/dl.js +6 -6
- package/dist/components/dl/dl.js.map +1 -1
- package/dist/components/drawer/drawer.d.ts +4 -5
- package/dist/components/drawer/drawer.js +26 -13
- package/dist/components/drawer/drawer.js.map +1 -1
- package/dist/components/drawer/index.d.ts +1 -2
- package/dist/components/fieldset/fieldset.d.ts +1 -2
- package/dist/components/fieldset/fieldset.js +2 -2
- package/dist/components/fieldset/fieldset.js.map +1 -1
- package/dist/components/heading/heading.d.ts +1 -2
- package/dist/components/heading/heading.js +2 -2
- package/dist/components/heading/heading.js.map +1 -1
- package/dist/components/hr/hr.d.ts +1 -2
- package/dist/components/hr/hr.js +2 -2
- package/dist/components/hr/hr.js.map +1 -1
- package/dist/components/index.d.ts +32 -27
- package/dist/components/inline-feedback/index.d.ts +2 -0
- package/dist/components/inline-feedback/inline-feedback.d.ts +33 -0
- package/dist/components/inline-feedback/inline-feedback.js +30 -0
- package/dist/components/inline-feedback/inline-feedback.js.map +1 -0
- package/dist/components/input/input.d.ts +1 -2
- package/dist/components/input/input.js +2 -2
- package/dist/components/input/input.js.map +1 -1
- package/dist/components/label/label.d.ts +1 -2
- package/dist/components/label/label.js +4 -4
- package/dist/components/label/label.js.map +1 -1
- package/dist/components/menu/index.d.ts +1 -2
- package/dist/components/menu/menu.d.ts +3 -4
- package/dist/components/menu/menu.js +20 -9
- package/dist/components/menu/menu.js.map +1 -1
- package/dist/components/multi-combobox/index.d.ts +2 -0
- package/dist/components/multi-combobox/multi-combobox-option.js +42 -0
- package/dist/components/multi-combobox/multi-combobox-option.js.map +1 -0
- package/dist/components/multi-combobox/multi-combobox-tag.js +54 -0
- package/dist/components/multi-combobox/multi-combobox-tag.js.map +1 -0
- package/dist/components/multi-combobox/multi-combobox.d.ts +72 -0
- package/dist/components/multi-combobox/multi-combobox.js +249 -0
- package/dist/components/multi-combobox/multi-combobox.js.map +1 -0
- package/dist/components/multi-combobox/use-multi-combobox-state.js +91 -0
- package/dist/components/multi-combobox/use-multi-combobox-state.js.map +1 -0
- package/dist/components/paragraph/paragraph.d.ts +1 -2
- package/dist/components/paragraph/paragraph.js +2 -2
- package/dist/components/paragraph/paragraph.js.map +1 -1
- package/dist/components/popover/index.d.ts +1 -2
- package/dist/components/popover/popover.d.ts +3 -4
- package/dist/components/popover/popover.js +18 -7
- package/dist/components/popover/popover.js.map +1 -1
- package/dist/components/progress/progress.d.ts +1 -2
- package/dist/components/progress/progress.js +2 -2
- package/dist/components/progress/progress.js.map +1 -1
- package/dist/components/radio/radio.d.ts +1 -2
- package/dist/components/radio/radio.js +2 -2
- package/dist/components/radio/radio.js.map +1 -1
- package/dist/components/radiogroup/radiogroup.d.ts +1 -2
- package/dist/components/radiogroup/radiogroup.js +5 -4
- package/dist/components/radiogroup/radiogroup.js.map +1 -1
- package/dist/components/section/section.d.ts +1 -2
- package/dist/components/section/section.js +2 -2
- package/dist/components/section/section.js.map +1 -1
- package/dist/components/segmented-control/segmented-control.d.ts +1 -2
- package/dist/components/segmented-control/segmented-control.js +10 -5
- package/dist/components/segmented-control/segmented-control.js.map +1 -1
- package/dist/components/select/select.d.ts +1 -2
- package/dist/components/select/select.js +2 -2
- package/dist/components/select/select.js.map +1 -1
- package/dist/components/skip-link/skip-link.d.ts +1 -2
- package/dist/components/skip-link/skip-link.js +2 -2
- package/dist/components/skip-link/skip-link.js.map +1 -1
- package/dist/components/status-icon/index.d.ts +2 -0
- package/dist/components/status-icon/status-icon.d.ts +19 -0
- package/dist/components/status-icon/status-icon.js +22 -0
- package/dist/components/status-icon/status-icon.js.map +1 -0
- package/dist/components/table/table.d.ts +4 -5
- package/dist/components/table/table.js +16 -16
- package/dist/components/table/table.js.map +1 -1
- package/dist/components/tabs/tabs.context.d.ts +1 -2
- package/dist/components/tabs/tabs.d.ts +1 -2
- package/dist/components/tabs/tabs.js +8 -8
- package/dist/components/tabs/tabs.js.map +1 -1
- package/dist/components/tag/index.d.ts +2 -0
- package/dist/components/tag/tag.d.ts +39 -0
- package/dist/components/tag/tag.js +41 -0
- package/dist/components/tag/tag.js.map +1 -0
- package/dist/components/text/text.d.ts +1 -2
- package/dist/components/text/text.js +2 -2
- package/dist/components/text/text.js.map +1 -1
- package/dist/components/textarea/textarea.d.ts +1 -2
- package/dist/components/textarea/textarea.js +2 -2
- package/dist/components/textarea/textarea.js.map +1 -1
- package/dist/components/tooltip/index.d.ts +1 -2
- package/dist/components/tooltip/tooltip.d.ts +3 -4
- package/dist/components/tooltip/tooltip.js +17 -6
- package/dist/components/tooltip/tooltip.js.map +1 -1
- package/dist/components/visually-hidden/visually-hidden.d.ts +1 -2
- package/dist/components/visually-hidden/visually-hidden.js +2 -2
- package/dist/components/visually-hidden/visually-hidden.js.map +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.js +7 -7
- package/dist/provider/hui-provider.context.d.ts +23 -7
- package/dist/provider/hui-provider.context.js +13 -12
- package/dist/provider/hui-provider.context.js.map +1 -1
- package/dist/provider/hui-provider.d.ts +1 -2
- package/dist/provider/index.d.ts +1 -1
- package/dist/types/distributive.d.ts +1 -0
- package/dist/types/hui-component.d.ts +11 -5
- package/dist/types/index.d.ts +3 -2
- package/dist/types/polymorphic.d.ts +4 -9
- package/package.json +9 -9
- package/dist/components/dialog/dialog.context.d.ts +0 -2
- package/dist/components/drawer/drawer.context.d.ts +0 -2
- package/dist/components/menu/menu.context.d.ts +0 -2
- package/dist/components/popover/popover.context.d.ts +0 -2
- package/dist/components/tooltip/tooltip.context.d.ts +0 -2
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { useHuiClassNames, useHuiProps, useHuiStyles } from "../../provider/hui-provider.context.js";
|
|
2
|
+
import { normalizeAttributes } from "../../utils/attributes/normalize-attributes.js";
|
|
3
|
+
import { useComboboxForm } from "../combobox/use-combobox-form.js";
|
|
4
|
+
import { useComboboxPopover } from "../combobox/use-combobox-popover.js";
|
|
5
|
+
import { Label } from "../label/label.js";
|
|
6
|
+
import { MultiComboboxOption } from "./multi-combobox-option.js";
|
|
7
|
+
import { MultiComboboxTag } from "./multi-combobox-tag.js";
|
|
8
|
+
import { useMultiComboboxState } from "./use-multi-combobox-state.js";
|
|
9
|
+
import { cc, comboboxControl, inputControl, moveComboboxActiveValue, multiComboboxControl, multiComboboxRecipe, popoverControl, toStrbool } from "@hebium-ui/core";
|
|
10
|
+
import { useCallback, useId, useMemo, useRef } from "react";
|
|
11
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
+
// src/components/multi-combobox/multi-combobox.tsx
|
|
13
|
+
function MultiCombobox(rawProps) {
|
|
14
|
+
const props = useHuiProps("MultiCombobox", rawProps);
|
|
15
|
+
const { options, color, label, labelProps, description, error, required = false, requiredMessage, name, form, inputProps = {}, listProps = {}, itemProps, renderItem, tagProps, renderFormValue } = props;
|
|
16
|
+
const generatedId = useId();
|
|
17
|
+
const inputId = inputProps.id ?? `${generatedId}-input`;
|
|
18
|
+
const listId = listProps.id ?? `${generatedId}-list`;
|
|
19
|
+
const labelId = labelProps?.id ?? `${generatedId}-label`;
|
|
20
|
+
const hasLabel = !!label || !!description || !!error;
|
|
21
|
+
const { state, filteredOptions, activeOption, setActiveValue, clearActiveValue, edit, toggle: toggleValue, remove: removeValue, finishQuery, reset } = useMultiComboboxState(props);
|
|
22
|
+
const inputRef = useRef(null);
|
|
23
|
+
const rootRef = useRef(null);
|
|
24
|
+
const composingRef = useRef(false);
|
|
25
|
+
const attachInput = useComboboxForm({
|
|
26
|
+
inputRef,
|
|
27
|
+
externalRef: inputProps.ref,
|
|
28
|
+
associatedFormId: inputProps.form ?? form,
|
|
29
|
+
validationMessage: multiComboboxControl.getValidationMessage({
|
|
30
|
+
value: state.value,
|
|
31
|
+
required,
|
|
32
|
+
disabled: state.disabled,
|
|
33
|
+
readOnly: state.readOnly,
|
|
34
|
+
requiredMessage
|
|
35
|
+
}),
|
|
36
|
+
onReset: reset
|
|
37
|
+
});
|
|
38
|
+
const { opened, listRef, attachList, showList, closeList, handleToggle } = useComboboxPopover({
|
|
39
|
+
state,
|
|
40
|
+
filteredOptions,
|
|
41
|
+
inputRef,
|
|
42
|
+
externalRef: listProps.ref,
|
|
43
|
+
onClose: clearActiveValue,
|
|
44
|
+
onToggle: listProps.onToggle
|
|
45
|
+
});
|
|
46
|
+
const remove = useCallback((value, button) => {
|
|
47
|
+
const moveFocus = multiComboboxControl.createTagRemovalFocus({
|
|
48
|
+
root: rootRef.current,
|
|
49
|
+
input: inputRef.current,
|
|
50
|
+
button,
|
|
51
|
+
value: state.value,
|
|
52
|
+
removedValue: value
|
|
53
|
+
});
|
|
54
|
+
removeValue(value, moveFocus);
|
|
55
|
+
}, [state.value, removeValue]);
|
|
56
|
+
const toggle = useCallback((value) => {
|
|
57
|
+
if (toggleValue(value)) inputRef.current?.focus({ preventScroll: true });
|
|
58
|
+
}, [toggleValue]);
|
|
59
|
+
const handleChange = useCallback((event) => {
|
|
60
|
+
inputProps.onChange?.(event);
|
|
61
|
+
if (event.defaultPrevented) return;
|
|
62
|
+
edit(event.currentTarget.value);
|
|
63
|
+
showList();
|
|
64
|
+
}, [
|
|
65
|
+
inputProps,
|
|
66
|
+
edit,
|
|
67
|
+
showList
|
|
68
|
+
]);
|
|
69
|
+
const handleKeyDown = useCallback((event) => {
|
|
70
|
+
inputProps.onKeyDown?.(event);
|
|
71
|
+
if (event.defaultPrevented || composingRef.current) return;
|
|
72
|
+
const visible = popoverControl.isOpened(listRef.current);
|
|
73
|
+
const action = multiComboboxControl.getKeyAction(event.nativeEvent, {
|
|
74
|
+
...state,
|
|
75
|
+
opened: visible
|
|
76
|
+
}, visible ? activeOption : void 0);
|
|
77
|
+
switch (action) {
|
|
78
|
+
case "next":
|
|
79
|
+
case "previous":
|
|
80
|
+
event.preventDefault();
|
|
81
|
+
if (showList()) setActiveValue(moveComboboxActiveValue(filteredOptions, visible ? state.activeValue : null, action));
|
|
82
|
+
return;
|
|
83
|
+
case "commit":
|
|
84
|
+
event.preventDefault();
|
|
85
|
+
if (activeOption) toggle(activeOption.value);
|
|
86
|
+
return;
|
|
87
|
+
case "blocked":
|
|
88
|
+
event.preventDefault();
|
|
89
|
+
return;
|
|
90
|
+
case "add":
|
|
91
|
+
event.preventDefault();
|
|
92
|
+
finishQuery();
|
|
93
|
+
showList();
|
|
94
|
+
return;
|
|
95
|
+
case "focus-tag":
|
|
96
|
+
event.preventDefault();
|
|
97
|
+
multiComboboxControl.focusLastTag(rootRef.current, state.value);
|
|
98
|
+
return;
|
|
99
|
+
case "submit":
|
|
100
|
+
closeList();
|
|
101
|
+
return;
|
|
102
|
+
case "none": return;
|
|
103
|
+
}
|
|
104
|
+
}, [
|
|
105
|
+
inputProps,
|
|
106
|
+
listRef,
|
|
107
|
+
state,
|
|
108
|
+
activeOption,
|
|
109
|
+
showList,
|
|
110
|
+
setActiveValue,
|
|
111
|
+
filteredOptions,
|
|
112
|
+
toggle,
|
|
113
|
+
finishQuery,
|
|
114
|
+
closeList
|
|
115
|
+
]);
|
|
116
|
+
const handleInputClick = useCallback((event) => {
|
|
117
|
+
inputProps.onClick?.(event);
|
|
118
|
+
if (!event.defaultPrevented) showList();
|
|
119
|
+
}, [inputProps, showList]);
|
|
120
|
+
const handleBlur = useCallback((event) => {
|
|
121
|
+
if (event.defaultPrevented || !(event.relatedTarget instanceof Node) || event.currentTarget.contains(event.relatedTarget)) return;
|
|
122
|
+
finishQuery();
|
|
123
|
+
closeList();
|
|
124
|
+
}, [finishQuery, closeList]);
|
|
125
|
+
const handleCompositionStart = useCallback((event) => {
|
|
126
|
+
inputProps.onCompositionStart?.(event);
|
|
127
|
+
composingRef.current = true;
|
|
128
|
+
}, [inputProps]);
|
|
129
|
+
const handleCompositionEnd = useCallback((event) => {
|
|
130
|
+
inputProps.onCompositionEnd?.(event);
|
|
131
|
+
composingRef.current = false;
|
|
132
|
+
}, [inputProps]);
|
|
133
|
+
const optionsByValue = useMemo(() => new Map(options.map((option) => [option.value, option])), [options]);
|
|
134
|
+
const itemIds = useMemo(() => new Map(options.map((option, index) => [option.value, `${listId}-option-${index}`])), [options, listId]);
|
|
135
|
+
const inputAttributes = normalizeAttributes(comboboxControl.getInputAttributes({
|
|
136
|
+
inputId,
|
|
137
|
+
listId,
|
|
138
|
+
opened,
|
|
139
|
+
required,
|
|
140
|
+
activeId: activeOption ? itemIds.get(activeOption.value) : void 0
|
|
141
|
+
}));
|
|
142
|
+
const labelAttributes = normalizeAttributes(inputControl.getLabelAttributes({
|
|
143
|
+
id: inputId,
|
|
144
|
+
invalid: !!error,
|
|
145
|
+
required,
|
|
146
|
+
disabled: state.disabled,
|
|
147
|
+
readOnly: state.readOnly
|
|
148
|
+
}));
|
|
149
|
+
const formValueProps = multiComboboxControl.getFormValueProps({
|
|
150
|
+
name,
|
|
151
|
+
value: state.value,
|
|
152
|
+
form
|
|
153
|
+
});
|
|
154
|
+
const recipe = multiComboboxRecipe({
|
|
155
|
+
color,
|
|
156
|
+
error: toStrbool(!!error)
|
|
157
|
+
});
|
|
158
|
+
const cls = useHuiClassNames("MultiCombobox", recipe, rawProps);
|
|
159
|
+
const sls = useHuiStyles("MultiCombobox", rawProps);
|
|
160
|
+
return /* @__PURE__ */ jsxs("fieldset", {
|
|
161
|
+
ref: rootRef,
|
|
162
|
+
disabled: state.disabled,
|
|
163
|
+
"aria-labelledby": hasLabel ? labelId : void 0,
|
|
164
|
+
className: cls.root,
|
|
165
|
+
style: sls.root,
|
|
166
|
+
onBlur: handleBlur,
|
|
167
|
+
children: [
|
|
168
|
+
hasLabel && /* @__PURE__ */ jsx(Label, {
|
|
169
|
+
...labelAttributes,
|
|
170
|
+
description,
|
|
171
|
+
error,
|
|
172
|
+
...labelProps,
|
|
173
|
+
id: labelId,
|
|
174
|
+
children: label
|
|
175
|
+
}),
|
|
176
|
+
state.value.length > 0 && /* @__PURE__ */ jsx("div", {
|
|
177
|
+
className: cls.tags,
|
|
178
|
+
style: sls.tags,
|
|
179
|
+
children: state.value.map((value) => {
|
|
180
|
+
const option = optionsByValue.get(value);
|
|
181
|
+
return /* @__PURE__ */ jsx(MultiComboboxTag, {
|
|
182
|
+
value,
|
|
183
|
+
label: multiComboboxControl.getTagLabel(state.mode, value, option),
|
|
184
|
+
option,
|
|
185
|
+
tagProps,
|
|
186
|
+
disabled: state.readOnly,
|
|
187
|
+
remove
|
|
188
|
+
}, value);
|
|
189
|
+
})
|
|
190
|
+
}),
|
|
191
|
+
/* @__PURE__ */ jsx("input", {
|
|
192
|
+
...inputAttributes,
|
|
193
|
+
"aria-invalid": !!error,
|
|
194
|
+
form,
|
|
195
|
+
value: state.query,
|
|
196
|
+
...inputProps,
|
|
197
|
+
readOnly: state.readOnly || inputProps.readOnly,
|
|
198
|
+
className: cc(cls.input, inputProps.className),
|
|
199
|
+
style: {
|
|
200
|
+
...sls.input,
|
|
201
|
+
...inputProps.style
|
|
202
|
+
},
|
|
203
|
+
ref: attachInput,
|
|
204
|
+
onChange: handleChange,
|
|
205
|
+
onKeyDown: handleKeyDown,
|
|
206
|
+
onClick: handleInputClick,
|
|
207
|
+
onCompositionStart: handleCompositionStart,
|
|
208
|
+
onCompositionEnd: handleCompositionEnd
|
|
209
|
+
}),
|
|
210
|
+
/* @__PURE__ */ jsx("div", {
|
|
211
|
+
...normalizeAttributes(multiComboboxControl.getListAttributes(listId, inputId, state)),
|
|
212
|
+
...listProps,
|
|
213
|
+
className: cc(cls.list, listProps.className),
|
|
214
|
+
style: {
|
|
215
|
+
...sls.list,
|
|
216
|
+
...listProps.style
|
|
217
|
+
},
|
|
218
|
+
ref: attachList,
|
|
219
|
+
onToggle: handleToggle,
|
|
220
|
+
children: filteredOptions.map((option) => {
|
|
221
|
+
const id = itemIds.get(option.value);
|
|
222
|
+
if (id === void 0) return null;
|
|
223
|
+
return /* @__PURE__ */ jsx(MultiComboboxOption, {
|
|
224
|
+
option,
|
|
225
|
+
id,
|
|
226
|
+
mode: state.mode,
|
|
227
|
+
selected: state.value.includes(option.value),
|
|
228
|
+
active: opened && activeOption?.value === option.value,
|
|
229
|
+
className: cls.item,
|
|
230
|
+
style: sls.item,
|
|
231
|
+
indicatorClassName: cls.itemIndicator,
|
|
232
|
+
indicatorStyle: sls.itemIndicator,
|
|
233
|
+
itemProps,
|
|
234
|
+
renderItem,
|
|
235
|
+
toggle
|
|
236
|
+
}, option.value);
|
|
237
|
+
})
|
|
238
|
+
}),
|
|
239
|
+
formValueProps && (renderFormValue ? renderFormValue(formValueProps) : formValueProps.value.map((value) => /* @__PURE__ */ jsx("input", {
|
|
240
|
+
type: "hidden",
|
|
241
|
+
...formValueProps,
|
|
242
|
+
value
|
|
243
|
+
}, value)))
|
|
244
|
+
]
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
export { MultiCombobox };
|
|
248
|
+
|
|
249
|
+
//# sourceMappingURL=multi-combobox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multi-combobox.js","names":[],"sources":["../../../src/components/multi-combobox/multi-combobox.tsx"],"sourcesContent":["import {\n cc,\n comboboxControl,\n type ComboboxSelectOption,\n type ComboboxTextOption,\n inputControl,\n moveComboboxActiveValue,\n multiComboboxControl,\n type MultiComboboxFormValueProps,\n type MultiComboboxItemState,\n multiComboboxRecipe,\n type MultiComboboxSlots,\n type MultiComboboxVariants,\n popoverControl,\n toStrbool,\n} from \"@hebium-ui/core\";\nimport {\n type ChangeEvent,\n type ComponentProps,\n type CompositionEvent,\n type FocusEvent,\n type KeyboardEvent,\n type MouseEvent,\n type ReactElement,\n type ReactNode,\n useCallback,\n useId,\n useMemo,\n useRef,\n} from \"react\";\nimport { useHuiClassNames, useHuiProps, useHuiStyles } from \"~/provider\";\nimport { type HuiComponentProps } from \"~/types\";\nimport { normalizeAttributes } from \"~/utils\";\nimport { useComboboxForm } from \"../combobox/use-combobox-form\";\nimport { useComboboxPopover } from \"../combobox/use-combobox-popover\";\nimport { Label, type LabelProps } from \"../label\";\nimport { type TagProps } from \"../tag\";\nimport { MultiComboboxOption } from \"./multi-combobox-option\";\nimport { MultiComboboxTag } from \"./multi-combobox-tag\";\nimport { useMultiComboboxState } from \"./use-multi-combobox-state\";\n\nexport interface MultiComboboxTagContext<O extends ComboboxSelectOption = ComboboxSelectOption> {\n value: string;\n /** Standard display text. In text mode this is the committed value itself. */\n label: string;\n /** The matching candidate, if one exists. */\n option: O | undefined;\n}\n\nexport type MultiComboboxTagProps = Omit<TagProps, \"label\" | \"onRemove\">;\n\ninterface MultiComboboxOwnProps<O extends ComboboxSelectOption> {\n /** Available options. Values must be unique. */\n options: readonly O[];\n /** The controlled values. Values must be unique. */\n value?: readonly string[] | undefined;\n /** The initial uncontrolled values. @default [] */\n defaultValue?: readonly string[] | undefined;\n /**\n * Called with the next values. In controlled mode, call the optional focus callback when accepting a Tag removal.\n */\n onChange?: ((value: string[], moveFocus?: () => void) => void) | undefined;\n /** The input's semantic color. @default \"accent\" */\n color?: MultiComboboxVariants[\"color\"] | undefined;\n /** The label displayed above the input. */\n label?: ReactNode | undefined;\n /** Additional props passed to the label. */\n labelProps?: LabelProps | undefined;\n /** Help text displayed below the label. */\n description?: ReactNode | undefined;\n /** Inline validation feedback. */\n error?: ReactNode | undefined;\n /** The name used for form submission. */\n name?: string | undefined;\n /** The id of the associated form. */\n form?: string | undefined;\n /** Prevents interaction and excludes values from form submission. */\n disabled?: boolean | undefined;\n /** Prevents editing and opening the list. Values are still submitted. */\n readOnly?: boolean | undefined;\n /** Requires at least one selected value. */\n required?: boolean | undefined;\n /** Native validation message. @default \"Please fill out this field.\" */\n requiredMessage?: string | undefined;\n /** Props passed to the input element. */\n inputProps?: Omit<ComponentProps<\"input\">, \"children\"> | undefined;\n /** Props passed to the listbox element. */\n listProps?: Omit<ComponentProps<\"div\">, \"children\"> | undefined;\n /** Props for each option wrapper. */\n itemProps?: ((option: O, state: MultiComboboxItemState) => Omit<ComponentProps<\"div\">, \"children\">) | undefined;\n /** Custom option content, including the check mark. */\n renderItem?: ((option: O, state: MultiComboboxItemState) => ReactNode) | undefined;\n /** Props for each selected Tag. */\n tagProps?: ((context: MultiComboboxTagContext<O>) => MultiComboboxTagProps) | undefined;\n /** Renders custom form submission elements for all selected values. */\n renderFormValue?: ((props: MultiComboboxFormValueProps) => ReactNode) | undefined;\n}\n\ntype MultiComboboxModeProps<O extends ComboboxSelectOption> =\n | {\n /** Select from options or allow free text. @default \"select\" */\n mode?: \"select\" | undefined;\n }\n | {\n mode: \"text\";\n options: readonly (O & ComboboxTextOption)[];\n };\n\nexport type MultiComboboxProps<O extends ComboboxSelectOption = ComboboxSelectOption> =\n & HuiComponentProps<MultiComboboxOwnProps<O>, MultiComboboxSlots>\n & MultiComboboxModeProps<O>;\n\nexport function MultiCombobox<O extends ComboboxSelectOption>(rawProps: MultiComboboxProps<O>): ReactElement {\n const props = useHuiProps(\"MultiCombobox\", rawProps);\n const {\n options,\n color,\n label,\n labelProps,\n description,\n error,\n required = false,\n requiredMessage,\n name,\n form,\n inputProps = {},\n listProps = {},\n itemProps,\n renderItem,\n tagProps,\n renderFormValue,\n } = props;\n const generatedId = useId();\n const inputId = inputProps.id ?? `${generatedId}-input`;\n const listId = listProps.id ?? `${generatedId}-list`;\n const labelId = labelProps?.id ?? `${generatedId}-label`;\n const hasLabel = !!label || !!description || !!error;\n\n const {\n state,\n filteredOptions,\n activeOption,\n setActiveValue,\n clearActiveValue,\n edit,\n toggle: toggleValue,\n remove: removeValue,\n finishQuery,\n reset,\n } = useMultiComboboxState<O>(props);\n const inputRef = useRef<HTMLInputElement | null>(null);\n const rootRef = useRef<HTMLFieldSetElement | null>(null);\n const composingRef = useRef(false);\n const attachInput = useComboboxForm({\n inputRef,\n externalRef: inputProps.ref,\n associatedFormId: inputProps.form ?? form,\n validationMessage: multiComboboxControl.getValidationMessage({\n value: state.value,\n required,\n disabled: state.disabled,\n readOnly: state.readOnly,\n requiredMessage,\n }),\n onReset: reset,\n });\n\n const {\n opened,\n listRef,\n attachList,\n showList,\n closeList,\n handleToggle,\n } = useComboboxPopover({\n state,\n filteredOptions,\n inputRef,\n externalRef: listProps.ref,\n onClose: clearActiveValue,\n onToggle: listProps.onToggle,\n });\n\n const remove = useCallback((value: string, button: HTMLButtonElement): void => {\n const moveFocus = multiComboboxControl.createTagRemovalFocus({\n root: rootRef.current,\n input: inputRef.current,\n button,\n value: state.value,\n removedValue: value,\n });\n removeValue(value, moveFocus);\n }, [state.value, removeValue]);\n const toggle = useCallback((value: string): void => {\n if (toggleValue(value)) inputRef.current?.focus({ preventScroll: true });\n }, [toggleValue]);\n\n const handleChange = useCallback((event: ChangeEvent<HTMLInputElement>): void => {\n inputProps.onChange?.(event);\n if (event.defaultPrevented) return;\n edit(event.currentTarget.value);\n showList();\n }, [inputProps, edit, showList]);\n\n const handleKeyDown = useCallback((event: KeyboardEvent<HTMLInputElement>): void => {\n inputProps.onKeyDown?.(event);\n if (event.defaultPrevented || composingRef.current) return;\n const visible = popoverControl.isOpened(listRef.current);\n const action = multiComboboxControl.getKeyAction(\n event.nativeEvent,\n { ...state, opened: visible },\n visible ? activeOption : undefined,\n );\n switch (action) {\n case \"next\":\n case \"previous\":\n event.preventDefault();\n if (showList()) {\n setActiveValue(moveComboboxActiveValue(filteredOptions, visible ? state.activeValue : null, action));\n }\n return;\n case \"commit\":\n event.preventDefault();\n if (activeOption) toggle(activeOption.value);\n return;\n case \"blocked\":\n event.preventDefault();\n return;\n case \"add\":\n event.preventDefault();\n finishQuery();\n showList();\n return;\n case \"focus-tag\":\n event.preventDefault();\n multiComboboxControl.focusLastTag(rootRef.current, state.value);\n return;\n case \"submit\":\n closeList();\n return;\n case \"none\":\n return;\n }\n }, [\n inputProps,\n listRef,\n state,\n activeOption,\n showList,\n setActiveValue,\n filteredOptions,\n toggle,\n finishQuery,\n closeList,\n ]);\n\n const handleInputClick = useCallback((event: MouseEvent<HTMLInputElement>): void => {\n inputProps.onClick?.(event);\n if (!event.defaultPrevented) showList();\n }, [inputProps, showList]);\n\n const handleBlur = useCallback((event: FocusEvent<HTMLFieldSetElement>): void => {\n if (\n event.defaultPrevented\n || !(event.relatedTarget instanceof Node)\n || event.currentTarget.contains(event.relatedTarget)\n ) return;\n finishQuery();\n closeList();\n }, [finishQuery, closeList]);\n\n const handleCompositionStart = useCallback((event: CompositionEvent<HTMLInputElement>): void => {\n inputProps.onCompositionStart?.(event);\n composingRef.current = true;\n }, [inputProps]);\n const handleCompositionEnd = useCallback((event: CompositionEvent<HTMLInputElement>): void => {\n inputProps.onCompositionEnd?.(event);\n composingRef.current = false;\n }, [inputProps]);\n\n const optionsByValue = useMemo(() => new Map(options.map((option) => [option.value, option])), [options]);\n const itemIds = useMemo(\n () => new Map(options.map((option, index) => [option.value, `${listId}-option-${index}`])),\n [options, listId],\n );\n const inputAttributes = normalizeAttributes(comboboxControl.getInputAttributes({\n inputId,\n listId,\n opened,\n required,\n activeId: activeOption ? itemIds.get(activeOption.value) : undefined,\n }));\n const labelAttributes = normalizeAttributes(inputControl.getLabelAttributes({\n id: inputId,\n invalid: !!error,\n required,\n disabled: state.disabled,\n readOnly: state.readOnly,\n }));\n const formValueProps = multiComboboxControl.getFormValueProps({\n name,\n value: state.value,\n form,\n });\n const recipe = multiComboboxRecipe({ color, error: toStrbool(!!error) });\n const cls = useHuiClassNames(\"MultiCombobox\", recipe, rawProps);\n const sls = useHuiStyles(\"MultiCombobox\", rawProps);\n\n return (\n // Blur only observes focus leaving the composite field; the fieldset itself is not interactive.\n // oxlint-disable-next-line jsx-a11y/no-noninteractive-element-interactions\n <fieldset\n ref={rootRef}\n disabled={state.disabled}\n aria-labelledby={hasLabel ? labelId : undefined}\n className={cls.root}\n style={sls.root}\n onBlur={handleBlur}\n >\n {hasLabel && (\n <Label\n {...labelAttributes}\n description={description}\n error={error}\n {...labelProps}\n id={labelId}\n >\n {label}\n </Label>\n )}\n {state.value.length > 0 && (\n <div\n className={cls.tags}\n style={sls.tags}\n >\n {state.value.map((value) => {\n const option = optionsByValue.get(value);\n return (\n <MultiComboboxTag\n key={value}\n value={value}\n label={multiComboboxControl.getTagLabel(state.mode, value, option)}\n option={option}\n tagProps={tagProps}\n disabled={state.readOnly}\n remove={remove}\n />\n );\n })}\n </div>\n )}\n <input\n {...inputAttributes}\n aria-invalid={!!error}\n form={form}\n value={state.query}\n {...inputProps}\n readOnly={state.readOnly || inputProps.readOnly}\n className={cc(cls.input, inputProps.className)}\n style={{ ...sls.input, ...inputProps.style }}\n ref={attachInput}\n onChange={handleChange}\n onKeyDown={handleKeyDown}\n onClick={handleInputClick}\n onCompositionStart={handleCompositionStart}\n onCompositionEnd={handleCompositionEnd}\n />\n <div\n {...normalizeAttributes(multiComboboxControl.getListAttributes(listId, inputId, state))}\n {...listProps}\n className={cc(cls.list, listProps.className)}\n style={{ ...sls.list, ...listProps.style }}\n ref={attachList}\n onToggle={handleToggle}\n >\n {filteredOptions.map((option) => {\n const id = itemIds.get(option.value);\n if (id === undefined) return null;\n return (\n <MultiComboboxOption\n key={option.value}\n option={option}\n id={id}\n mode={state.mode}\n selected={state.value.includes(option.value)}\n active={opened && activeOption?.value === option.value}\n className={cls.item}\n style={sls.item}\n indicatorClassName={cls.itemIndicator}\n indicatorStyle={sls.itemIndicator}\n itemProps={itemProps}\n renderItem={renderItem}\n toggle={toggle}\n />\n );\n })}\n </div>\n {formValueProps && (renderFormValue\n ? renderFormValue(formValueProps)\n : formValueProps.value.map((value) => (\n <input\n key={value}\n type=\"hidden\"\n {...formValueProps}\n value={value}\n />\n )))}\n </fieldset>\n );\n}\n\nexport type {\n ComboboxSelectOption,\n ComboboxTextOption,\n MultiComboboxFormValueProps,\n MultiComboboxItemState,\n} from \"@hebium-ui/core\";\n"],"mappings":";;;;;;;;;;;;AAgHA,SAAgB,cAA8C,UAA+C;CAC3G,MAAM,QAAQ,YAAY,iBAAiB,QAAQ;CACnD,MAAM,EACJ,SACA,OACA,OACA,YACA,aACA,OACA,WAAW,OACX,iBACA,MACA,MACA,aAAa,C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G;GACR,GAJM,KAIN,CACF;EACK;;AAEd"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { comboboxControl, filterComboboxOptions, multiComboboxControl } from "@hebium-ui/core";
|
|
2
|
+
import { useCallback, useMemo, useState } from "react";
|
|
3
|
+
// src/components/multi-combobox/use-multi-combobox-state.ts
|
|
4
|
+
const EMPTY_VALUE = [];
|
|
5
|
+
function useMultiComboboxState(props) {
|
|
6
|
+
const { options, mode = "select", value, defaultValue, onChange, disabled = false, readOnly = false } = props;
|
|
7
|
+
const isControlled = value !== void 0;
|
|
8
|
+
const initialValue = defaultValue ?? EMPTY_VALUE;
|
|
9
|
+
const [uncontrolledValue, setUncontrolledValue] = useState(initialValue);
|
|
10
|
+
const [query, setQuery] = useState("");
|
|
11
|
+
const [activeValue, setActiveValue] = useState(null);
|
|
12
|
+
const currentValue = isControlled ? value : uncontrolledValue;
|
|
13
|
+
const state = useMemo(() => ({
|
|
14
|
+
mode,
|
|
15
|
+
value: currentValue,
|
|
16
|
+
query,
|
|
17
|
+
activeValue,
|
|
18
|
+
disabled,
|
|
19
|
+
readOnly
|
|
20
|
+
}), [
|
|
21
|
+
mode,
|
|
22
|
+
currentValue,
|
|
23
|
+
query,
|
|
24
|
+
activeValue,
|
|
25
|
+
disabled,
|
|
26
|
+
readOnly
|
|
27
|
+
]);
|
|
28
|
+
const filteredOptions = useMemo(() => filterComboboxOptions(mode, options, query), [
|
|
29
|
+
mode,
|
|
30
|
+
options,
|
|
31
|
+
query
|
|
32
|
+
]);
|
|
33
|
+
const activeOption = filteredOptions.find((option) => option.value === activeValue);
|
|
34
|
+
const changeValue = useCallback((nextValue, moveFocus) => {
|
|
35
|
+
if (!isControlled) {
|
|
36
|
+
setUncontrolledValue(nextValue);
|
|
37
|
+
moveFocus?.();
|
|
38
|
+
}
|
|
39
|
+
if (isControlled && moveFocus) onChange?.(nextValue, moveFocus);
|
|
40
|
+
else onChange?.(nextValue);
|
|
41
|
+
}, [isControlled, onChange]);
|
|
42
|
+
const edit = useCallback((text) => {
|
|
43
|
+
if (!comboboxControl.canEdit(state)) return;
|
|
44
|
+
setActiveValue(null);
|
|
45
|
+
setQuery(text);
|
|
46
|
+
}, [state]);
|
|
47
|
+
const toggle = useCallback((candidateValue) => {
|
|
48
|
+
const option = options.find((candidate) => candidate.value === candidateValue);
|
|
49
|
+
if (!option) return false;
|
|
50
|
+
const nextValue = multiComboboxControl.toggle(state, option);
|
|
51
|
+
if (!nextValue) return false;
|
|
52
|
+
setQuery("");
|
|
53
|
+
setActiveValue(null);
|
|
54
|
+
changeValue(nextValue);
|
|
55
|
+
return true;
|
|
56
|
+
}, [
|
|
57
|
+
state,
|
|
58
|
+
options,
|
|
59
|
+
changeValue
|
|
60
|
+
]);
|
|
61
|
+
const remove = useCallback((selectedValue, moveFocus) => {
|
|
62
|
+
const nextValue = multiComboboxControl.remove(state, selectedValue);
|
|
63
|
+
if (nextValue) changeValue(nextValue, moveFocus);
|
|
64
|
+
}, [state, changeValue]);
|
|
65
|
+
const finishQuery = useCallback(() => {
|
|
66
|
+
if (!comboboxControl.canEdit(state)) return;
|
|
67
|
+
const nextValue = multiComboboxControl.addText(state);
|
|
68
|
+
setQuery("");
|
|
69
|
+
if (nextValue) changeValue(nextValue);
|
|
70
|
+
}, [state, changeValue]);
|
|
71
|
+
return {
|
|
72
|
+
state,
|
|
73
|
+
filteredOptions,
|
|
74
|
+
activeOption,
|
|
75
|
+
setActiveValue,
|
|
76
|
+
clearActiveValue: useCallback(() => {
|
|
77
|
+
setActiveValue(null);
|
|
78
|
+
}, []),
|
|
79
|
+
edit,
|
|
80
|
+
toggle,
|
|
81
|
+
remove,
|
|
82
|
+
finishQuery,
|
|
83
|
+
reset: useCallback(() => {
|
|
84
|
+
setQuery("");
|
|
85
|
+
if (!isControlled) setUncontrolledValue(initialValue);
|
|
86
|
+
}, [isControlled, initialValue])
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
export { useMultiComboboxState };
|
|
90
|
+
|
|
91
|
+
//# sourceMappingURL=use-multi-combobox-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-multi-combobox-state.js","names":[],"sources":["../../../src/components/multi-combobox/use-multi-combobox-state.ts"],"sourcesContent":["import {\n comboboxControl,\n type ComboboxSelectOption,\n filterComboboxOptions,\n multiComboboxControl,\n type MultiComboboxState,\n} from \"@hebium-ui/core\";\nimport { useCallback, useMemo, useState } from \"react\";\nimport { type MultiComboboxProps } from \"./multi-combobox\";\n\nconst EMPTY_VALUE: readonly string[] = [];\n\ntype UseMultiComboboxStateOptions<O extends ComboboxSelectOption> = Pick<\n MultiComboboxProps<O>,\n \"options\" | \"mode\" | \"value\" | \"defaultValue\" | \"onChange\" | \"disabled\" | \"readOnly\"\n>;\n\ninterface MultiComboboxStateController<O extends ComboboxSelectOption> {\n state: MultiComboboxState;\n filteredOptions: readonly O[];\n activeOption: O | undefined;\n setActiveValue: (value: string | null) => void;\n clearActiveValue: () => void;\n edit: (text: string) => void;\n toggle: (value: string) => boolean;\n remove: (value: string, moveFocus?: () => void) => void;\n finishQuery: () => void;\n reset: () => void;\n}\n\nexport function useMultiComboboxState<O extends ComboboxSelectOption>(\n props: UseMultiComboboxStateOptions<O>,\n): MultiComboboxStateController<O> {\n const {\n options,\n mode = \"select\",\n value,\n defaultValue,\n onChange,\n disabled = false,\n readOnly = false,\n } = props;\n const isControlled = value !== undefined;\n const initialValue = defaultValue ?? EMPTY_VALUE;\n const [uncontrolledValue, setUncontrolledValue] = useState<readonly string[]>(initialValue);\n const [query, setQuery] = useState(\"\");\n const [activeValue, setActiveValue] = useState<string | null>(null);\n const currentValue = isControlled ? value : uncontrolledValue;\n const state = useMemo<MultiComboboxState>(\n () => ({ mode, value: currentValue, query, activeValue, disabled, readOnly }),\n [mode, currentValue, query, activeValue, disabled, readOnly],\n );\n const filteredOptions = useMemo(() => filterComboboxOptions(mode, options, query), [mode, options, query]);\n const activeOption = filteredOptions.find((option) => option.value === activeValue);\n\n const changeValue = useCallback((nextValue: string[], moveFocus?: () => void): void => {\n if (!isControlled) {\n setUncontrolledValue(nextValue);\n moveFocus?.();\n }\n if (isControlled && moveFocus) onChange?.(nextValue, moveFocus);\n else onChange?.(nextValue);\n }, [isControlled, onChange]);\n\n const edit = useCallback((text: string): void => {\n if (!comboboxControl.canEdit(state)) return;\n setActiveValue(null);\n setQuery(text);\n }, [state]);\n\n const toggle = useCallback((candidateValue: string): boolean => {\n const option = options.find((candidate) => candidate.value === candidateValue);\n if (!option) return false;\n const nextValue = multiComboboxControl.toggle(state, option);\n if (!nextValue) return false;\n setQuery(\"\");\n setActiveValue(null);\n changeValue(nextValue);\n return true;\n }, [state, options, changeValue]);\n\n const remove = useCallback((selectedValue: string, moveFocus?: () => void): void => {\n const nextValue = multiComboboxControl.remove(state, selectedValue);\n if (nextValue) changeValue(nextValue, moveFocus);\n }, [state, changeValue]);\n\n const finishQuery = useCallback((): void => {\n if (!comboboxControl.canEdit(state)) return;\n const nextValue = multiComboboxControl.addText(state);\n setQuery(\"\");\n if (nextValue) changeValue(nextValue);\n }, [state, changeValue]);\n\n const clearActiveValue = useCallback((): void => {\n setActiveValue(null);\n }, []);\n\n const reset = useCallback((): void => {\n setQuery(\"\");\n if (!isControlled) setUncontrolledValue(initialValue);\n }, [isControlled, initialValue]);\n\n return {\n state,\n filteredOptions,\n activeOption,\n setActiveValue,\n clearActiveValue,\n edit,\n toggle,\n remove,\n finishQuery,\n reset,\n };\n}\n"],"mappings":";;;AAUA,MAAM,cAAiC,CAAC;AAoBxC,SAAgB,sBACd,OACiC;CACjC,MAAM,EACJ,SACA,OAAO,UACP,OACA,cACA,UACA,WAAW,OACX,WAAW,UACT;CACJ,MAAM,eAAe,UAAU,KAAA;CAC/B,MAAM,eAAe,gBAAgB;CACrC,MAAM,CAAC,mBAAmB,wBAAwB,SAA4B,YAAY;CAC1F,MAAM,CAAC,OAAO,YAAY,SAAS,EAAE;CACrC,MAAM,CAAC,aAAa,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B,QAAQ,KAAK;EACpD,SAAS,EAAE;EACX,IAAI,WAAW,YAAY,SAAS;CACtC,GAAG,CAAC,OAAO,WAAW,CAAC;CAWvB,OAAO;EACL;EACA;EACA;EACA;EACA,kBAduB,kBAAwB;GAC/C,eAAe,IAAI;EACrB,GAAG,CAAC,CAYa;EACf;EACA;EACA;EACA;EACA,OAfY,kBAAwB;GACpC,SAAS,EAAE;GACX,IAAI,CAAC,cAAc,qBAAqB,YAAY;EACtD,GAAG,CAAC,cAAc,YAAY,CAYxB;CACN;AACF"}
|
|
@@ -18,5 +18,4 @@ interface ParagraphOwnProps {
|
|
|
18
18
|
}
|
|
19
19
|
export type ParagraphProps<E extends ElementType = "p"> = HuiPolymorphicProps<E, ParagraphOwnProps, ParagraphSlots>;
|
|
20
20
|
export declare function Paragraph<E extends ElementType = "p">(rawProps: ParagraphProps<E>): ReactElement;
|
|
21
|
-
export {};
|
|
22
|
-
//# sourceMappingURL=paragraph.d.ts.map
|
|
21
|
+
export {};
|
|
@@ -9,8 +9,8 @@ function Paragraph(rawProps) {
|
|
|
9
9
|
color,
|
|
10
10
|
margin
|
|
11
11
|
});
|
|
12
|
-
const cls = useHuiClassNames("Paragraph", recipe,
|
|
13
|
-
const sls = useHuiStyles("Paragraph",
|
|
12
|
+
const cls = useHuiClassNames("Paragraph", recipe, rawProps);
|
|
13
|
+
const sls = useHuiStyles("Paragraph", rawProps);
|
|
14
14
|
return /* @__PURE__ */ jsx(Component, {
|
|
15
15
|
className: cls.root,
|
|
16
16
|
style: sls.root,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paragraph.js","names":[],"sources":["../../../src/components/paragraph/paragraph.tsx"],"sourcesContent":["import { paragraphRecipe, type ParagraphSlots, type ParagraphVariants } from \"@hebium-ui/core\";\nimport { type ElementType, type ReactElement } from \"react\";\nimport { useHuiClassNames, useHuiProps, useHuiStyles } from \"~/provider\";\nimport { type HuiPolymorphicProps } from \"~/types\";\n\ninterface ParagraphOwnProps {\n /**\n * The semantic color of the paragraph.\n *\n * @default \"text\"\n */\n color?: ParagraphVariants[\"color\"] | undefined;\n /**\n * The block margin applied to the paragraph.\n *\n * @default \"block\"\n */\n margin?: ParagraphVariants[\"margin\"] | undefined;\n}\n\nexport type ParagraphProps<E extends ElementType = \"p\"> = HuiPolymorphicProps<\n E,\n ParagraphOwnProps,\n ParagraphSlots\n>;\n\nexport function Paragraph<E extends ElementType = \"p\">(rawProps: ParagraphProps<E>): ReactElement {\n const {\n as,\n color,\n margin,\n children,\n ...restProps\n } = useHuiProps(\"Paragraph\", rawProps);\n\n const Component = as ?? \"p\";\n const recipe = paragraphRecipe({\n color,\n margin,\n });\n const cls = useHuiClassNames(\"Paragraph\", recipe,
|
|
1
|
+
{"version":3,"file":"paragraph.js","names":[],"sources":["../../../src/components/paragraph/paragraph.tsx"],"sourcesContent":["import { paragraphRecipe, type ParagraphSlots, type ParagraphVariants } from \"@hebium-ui/core\";\nimport { type ElementType, type ReactElement } from \"react\";\nimport { useHuiClassNames, useHuiProps, useHuiStyles } from \"~/provider\";\nimport { type HuiPolymorphicProps } from \"~/types\";\n\ninterface ParagraphOwnProps {\n /**\n * The semantic color of the paragraph.\n *\n * @default \"text\"\n */\n color?: ParagraphVariants[\"color\"] | undefined;\n /**\n * The block margin applied to the paragraph.\n *\n * @default \"block\"\n */\n margin?: ParagraphVariants[\"margin\"] | undefined;\n}\n\nexport type ParagraphProps<E extends ElementType = \"p\"> = HuiPolymorphicProps<\n E,\n ParagraphOwnProps,\n ParagraphSlots\n>;\n\nexport function Paragraph<E extends ElementType = \"p\">(rawProps: ParagraphProps<E>): ReactElement {\n const {\n as,\n color,\n margin,\n children,\n ...restProps\n } = useHuiProps(\"Paragraph\", rawProps);\n\n const Component = as ?? \"p\";\n const recipe = paragraphRecipe({\n color,\n margin,\n });\n const cls = useHuiClassNames(\"Paragraph\", recipe, rawProps);\n const sls = useHuiStyles(\"Paragraph\", rawProps);\n\n return (\n <Component\n className={cls.root}\n style={sls.root}\n {...restProps}\n >\n {children}\n </Component>\n );\n}\n"],"mappings":";;;;AA0BA,SAAgB,UAAuC,UAA2C;CAChG,MAAM,EACJ,IACA,OACA,QACA,UACA,GAAG,cACD,YAAY,aAAa,QAAQ;CAErC,MAAM,YAAY,MAAM;CACxB,MAAM,SAAS,gBAAgB;EAC7B;EACA;CACF,CAAC;CACD,MAAM,MAAM,iBAAiB,aAAa,QAAQ,QAAQ;CAC1D,MAAM,MAAM,aAAa,aAAa,QAAQ;CAE9C,OACE,oBAAC,WAAD;EACE,WAAW,IAAI;EACf,OAAO,IAAI;EACX,GAAI;EAEH;CACQ,CAAA;AAEf"}
|
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
import { Popover, PopoverContentProps, PopoverProps, PopoverTriggerProps } from "./popover.js";
|
|
2
|
-
|
|
3
|
-
export { Popover, PopoverContentProps, PopoverProps, PopoverTriggerProps, usePopoverId };
|
|
2
|
+
export { Popover, PopoverContentProps, PopoverProps, PopoverTriggerProps };
|
|
@@ -12,8 +12,8 @@ export interface PopoverProps {
|
|
|
12
12
|
children?: ReactNode | undefined;
|
|
13
13
|
}
|
|
14
14
|
declare function PopoverRoot(rawProps: PopoverProps): ReactElement;
|
|
15
|
-
export type PopoverTriggerProps<E extends ElementType = typeof Button
|
|
16
|
-
declare function Trigger<E extends ElementType = typeof Button
|
|
15
|
+
export type PopoverTriggerProps<E extends ElementType = typeof Button<"button">> = HuiPolymorphicProps<E, {}, ButtonSlots>;
|
|
16
|
+
declare function Trigger<E extends ElementType = typeof Button<"button">>(rawProps: PopoverTriggerProps<E>): ReactNode;
|
|
17
17
|
interface PopoverContentOwnProps {
|
|
18
18
|
/**
|
|
19
19
|
* The preferred anchor position of the popover.
|
|
@@ -47,5 +47,4 @@ export declare const Popover: typeof PopoverRoot & {
|
|
|
47
47
|
Trigger: typeof Trigger;
|
|
48
48
|
Content: typeof Content;
|
|
49
49
|
};
|
|
50
|
-
export {};
|
|
51
|
-
//# sourceMappingURL=popover.d.ts.map
|
|
50
|
+
export {};
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { useHuiClassNames, useHuiProps, useHuiStyles } from "../../provider/hui-provider.context.js";
|
|
2
|
-
import { Button } from "../button/button.js";
|
|
3
2
|
import { normalizeAttributes } from "../../utils/attributes/normalize-attributes.js";
|
|
3
|
+
import { Button } from "../button/button.js";
|
|
4
4
|
import { PopoverContext, usePopoverId } from "./popover.context.js";
|
|
5
5
|
import { popoverControl, popoverRecipe } from "@hebium-ui/core";
|
|
6
6
|
import { useId, useMemo } from "react";
|
|
7
7
|
import { jsx } from "react/jsx-runtime";
|
|
8
8
|
// src/components/popover/popover.tsx
|
|
9
|
+
const BUTTON_CLASSES = {
|
|
10
|
+
root: "",
|
|
11
|
+
content: "",
|
|
12
|
+
spinner: "",
|
|
13
|
+
status: ""
|
|
14
|
+
};
|
|
9
15
|
function PopoverRoot(rawProps) {
|
|
10
16
|
const { id, children } = useHuiProps("Popover", rawProps);
|
|
11
17
|
const tmpId = useId();
|
|
@@ -21,14 +27,19 @@ function PopoverRoot(rawProps) {
|
|
|
21
27
|
function Trigger(rawProps) {
|
|
22
28
|
const { as, children, ...restProps } = useHuiProps("PopoverTrigger", rawProps);
|
|
23
29
|
const Component = as ?? Button;
|
|
24
|
-
const cls = useHuiClassNames("PopoverTrigger",
|
|
25
|
-
const sls = useHuiStyles("PopoverTrigger",
|
|
30
|
+
const cls = useHuiClassNames("PopoverTrigger", BUTTON_CLASSES, rawProps);
|
|
31
|
+
const sls = useHuiStyles("PopoverTrigger", rawProps);
|
|
26
32
|
const popoverId = usePopoverId();
|
|
27
33
|
const attrs = normalizeAttributes(popoverControl.getTriggerAttributes({ popoverId }, { isButtonElement: as === void 0 }));
|
|
28
34
|
return /* @__PURE__ */ jsx(Component, {
|
|
29
35
|
...attrs,
|
|
30
|
-
|
|
31
|
-
|
|
36
|
+
...Component === Button ? {
|
|
37
|
+
classNames: cls,
|
|
38
|
+
styles: sls
|
|
39
|
+
} : {
|
|
40
|
+
className: cls.root,
|
|
41
|
+
style: sls.root
|
|
42
|
+
},
|
|
32
43
|
...restProps,
|
|
33
44
|
children
|
|
34
45
|
});
|
|
@@ -43,8 +54,8 @@ function Content(rawProps) {
|
|
|
43
54
|
visibility,
|
|
44
55
|
padding
|
|
45
56
|
});
|
|
46
|
-
const cls = useHuiClassNames("PopoverContent", recipe,
|
|
47
|
-
const sls = useHuiStyles("PopoverContent",
|
|
57
|
+
const cls = useHuiClassNames("PopoverContent", recipe, rawProps);
|
|
58
|
+
const sls = useHuiStyles("PopoverContent", rawProps);
|
|
48
59
|
const attrs = normalizeAttributes(popoverControl.getContentAttributes({ popoverId }));
|
|
49
60
|
return /* @__PURE__ */ jsx(Component, {
|
|
50
61
|
...attrs,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"popover.js","names":[],"sources":["../../../src/components/popover/popover.tsx"],"sourcesContent":["import {\n type ButtonSlots,\n popoverControl,\n popoverRecipe,\n type PopoverSlots,\n type PopoverVariants,\n} from \"@hebium-ui/core\";\nimport { type ElementType, type ReactElement, type ReactNode, useId, useMemo } from \"react\";\nimport { useHuiClassNames, useHuiProps, useHuiStyles } from \"~/provider\";\nimport { type HuiPolymorphicProps } from \"~/types\";\nimport { normalizeAttributes } from \"~/utils\";\nimport { Button } from \"../button\";\nimport { PopoverContext, type PopoverContextValue, usePopoverId } from \"./popover.context\";\n\nexport interface PopoverProps {\n /**\n * The id of the popover content element.\n */\n id?: string | undefined;\n children?: ReactNode | undefined;\n}\n\nfunction PopoverRoot(rawProps: PopoverProps): ReactElement {\n const {\n id,\n children,\n } = useHuiProps(\"Popover\", rawProps);\n\n const tmpId = useId();\n const popoverId = id || tmpId;\n\n const contextValue = useMemo<PopoverContextValue>(() => {\n return {\n popoverId,\n };\n }, [popoverId]);\n\n return (\n <PopoverContext.Provider\n value={contextValue}\n >\n {children}\n </PopoverContext.Provider>\n );\n}\n\nexport type PopoverTriggerProps<E extends ElementType = typeof Button
|
|
1
|
+
{"version":3,"file":"popover.js","names":[],"sources":["../../../src/components/popover/popover.tsx"],"sourcesContent":["import {\n type ButtonSlots,\n popoverControl,\n popoverRecipe,\n type PopoverSlots,\n type PopoverVariants,\n} from \"@hebium-ui/core\";\nimport { type ElementType, type ReactElement, type ReactNode, useId, useMemo } from \"react\";\nimport { useHuiClassNames, useHuiProps, useHuiStyles } from \"~/provider\";\nimport { type HuiPolymorphicProps } from \"~/types\";\nimport { normalizeAttributes } from \"~/utils\";\nimport { Button } from \"../button\";\nimport { PopoverContext, type PopoverContextValue, usePopoverId } from \"./popover.context\";\n\nconst BUTTON_CLASSES = { root: \"\", content: \"\", spinner: \"\", status: \"\" } satisfies Record<ButtonSlots, string>;\n\nexport interface PopoverProps {\n /**\n * The id of the popover content element.\n */\n id?: string | undefined;\n children?: ReactNode | undefined;\n}\n\nfunction PopoverRoot(rawProps: PopoverProps): ReactElement {\n const {\n id,\n children,\n } = useHuiProps(\"Popover\", rawProps);\n\n const tmpId = useId();\n const popoverId = id || tmpId;\n\n const contextValue = useMemo<PopoverContextValue>(() => {\n return {\n popoverId,\n };\n }, [popoverId]);\n\n return (\n <PopoverContext.Provider\n value={contextValue}\n >\n {children}\n </PopoverContext.Provider>\n );\n}\n\nexport type PopoverTriggerProps<E extends ElementType = typeof Button<\"button\">> = HuiPolymorphicProps<\n E,\n {},\n ButtonSlots\n>;\n\nfunction Trigger<E extends ElementType = typeof Button<\"button\">>(rawProps: PopoverTriggerProps<E>): ReactNode {\n const {\n as,\n children,\n ...restProps\n } = useHuiProps(\"PopoverTrigger\", rawProps);\n\n const Component = as ?? Button;\n const cls = useHuiClassNames(\"PopoverTrigger\", BUTTON_CLASSES, rawProps);\n const sls = useHuiStyles(\"PopoverTrigger\", rawProps);\n const popoverId = usePopoverId();\n const attrs = normalizeAttributes(\n popoverControl.getTriggerAttributes(\n { popoverId },\n { isButtonElement: as === undefined },\n ),\n );\n\n return (\n <Component\n {...attrs}\n {...(Component === Button\n ? { classNames: cls, styles: sls }\n : { className: cls.root, style: sls.root })}\n {...restProps}\n >\n {children}\n </Component>\n );\n}\n\ninterface PopoverContentOwnProps {\n /**\n * The preferred anchor position of the popover.\n *\n * @default \"block-start\"\n */\n position?: PopoverVariants[\"position\"] | undefined;\n /**\n * The fallback strategy used when the preferred position overflows.\n *\n * @default \"flip\"\n */\n fallbacks?: PopoverVariants[\"fallbacks\"] | undefined;\n /**\n * The visibility behavior when the anchor is off-screen or overflows.\n *\n * @default \"anchors-visible\"\n * @see This setting depends on browser support for {@link https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/position-visibility | MDN: position-visibility}.\n */\n visibility?: PopoverVariants[\"visibility\"] | undefined;\n /**\n * The padding size of the popover content.\n *\n * @default \"md\"\n */\n padding?: PopoverVariants[\"padding\"] | undefined;\n}\nexport type PopoverContentProps<E extends ElementType = \"div\"> = HuiPolymorphicProps<\n E,\n PopoverContentOwnProps,\n PopoverSlots\n>;\n\nfunction Content<E extends ElementType = \"div\">(rawProps: PopoverContentProps<E>): ReactElement {\n const {\n as,\n position,\n fallbacks,\n visibility,\n padding,\n children,\n ...restProps\n } = useHuiProps(\"PopoverContent\", rawProps);\n const Component = as ?? \"div\";\n\n const popoverId = usePopoverId();\n const recipe = popoverRecipe({ position, fallbacks, visibility, padding });\n const cls = useHuiClassNames(\"PopoverContent\", recipe, rawProps);\n const sls = useHuiStyles(\"PopoverContent\", rawProps);\n const attrs = normalizeAttributes(popoverControl.getContentAttributes({ popoverId }));\n\n return (\n <Component\n {...attrs}\n className={cls.root}\n style={sls.root}\n {...restProps}\n >\n {children}\n </Component>\n );\n}\n\nexport const Popover = Object.assign(PopoverRoot, {\n Trigger,\n Content,\n});\n"],"mappings":";;;;;;;;AAcA,MAAM,iBAAiB;CAAE,MAAM;CAAI,SAAS;CAAI,SAAS;CAAI,QAAQ;AAAG;AAUxE,SAAS,YAAY,UAAsC;CACzD,MAAM,EACJ,IACA,aACE,YAAY,WAAW,QAA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ACF,CAAC"}
|
|
@@ -49,5 +49,4 @@ interface ProgressOwnProps extends HtmlDivProps {
|
|
|
49
49
|
}
|
|
50
50
|
export type ProgressProps = HuiComponentProps<ProgressOwnProps, ProgressSlots>;
|
|
51
51
|
export declare function Progress(rawProps: ProgressProps): ReactElement;
|
|
52
|
-
export {};
|
|
53
|
-
//# sourceMappingURL=progress.d.ts.map
|
|
52
|
+
export {};
|
|
@@ -20,8 +20,8 @@ function Progress(rawProps) {
|
|
|
20
20
|
radius,
|
|
21
21
|
size
|
|
22
22
|
});
|
|
23
|
-
const cls = useHuiClassNames("Progress", recipe, rawProps
|
|
24
|
-
const sls = useHuiStyles("Progress", rawProps
|
|
23
|
+
const cls = useHuiClassNames("Progress", recipe, rawProps);
|
|
24
|
+
const sls = useHuiStyles("Progress", rawProps);
|
|
25
25
|
const labelAttrs = progressControl.getLabelAttributes(progress);
|
|
26
26
|
const barAttrs = progressControl.getBarAttributes(progress);
|
|
27
27
|
const valueAttrs = progressControl.getValueAttributes();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"progress.js","names":[],"sources":["../../../src/components/progress/progress.tsx"],"sourcesContent":["import {\n cc,\n CSS_VARS,\n progressControl,\n progressRecipe,\n type ProgressSlots,\n type ProgressVariants,\n toStrbool,\n} from \"@hebium-ui/core\";\nimport { type ComponentProps, type ReactElement, type ReactNode, useId } from \"react\";\nimport { useHuiClassNames, useHuiProps, useHuiStyles } from \"~/provider\";\nimport { type HuiComponentProps } from \"~/types\";\n\ntype HtmlDivProps = ComponentProps<\"div\">;\n\ninterface ProgressOwnProps extends HtmlDivProps {\n /**\n * The minimum value of the progress range.\n *\n * @default 0\n */\n min?: number | undefined;\n /**\n * The maximum value of the progress range.\n *\n * @default 100\n */\n max?: number | undefined;\n /**\n * The current value of the progress. Omit this prop when progress is indeterminate.\n */\n value?: number | undefined;\n /**\n * The human-readable text alternative for the current value.\n */\n valueText?: string | undefined;\n /**\n * The label displayed above the progressbar.\n */\n label?: ReactNode | undefined;\n /**\n * The semantic color of the progressbar.\n *\n * @default \"accent\"\n */\n color?: ProgressVariants[\"color\"] | undefined;\n /**\n * The border radius of the progressbar.\n *\n * @default \"rounded\"\n */\n radius?: ProgressVariants[\"radius\"] | undefined;\n /**\n * The size of the progressbar.\n *\n * @default \"md\"\n */\n size?: ProgressVariants[\"size\"] | undefined;\n}\n\nexport type ProgressProps = HuiComponentProps<\n ProgressOwnProps,\n ProgressSlots\n>;\n\nexport function Progress(rawProps: ProgressProps): ReactElement {\n const {\n min,\n max,\n value,\n valueText,\n label,\n color,\n radius,\n size,\n nonce,\n ...restProps\n } = useHuiProps(\"Progress\", rawProps);\n const progressId = useId();\n const progress = progressControl.resolve({\n progressId,\n hasLabel: Boolean(label),\n min,\n max,\n value,\n valueText,\n });\n\n const recipe = progressRecipe({\n color,\n indeterminate: toStrbool(progress.isIndeterminate),\n radius,\n size,\n });\n const cls = useHuiClassNames(\"Progress\", recipe, rawProps
|
|
1
|
+
{"version":3,"file":"progress.js","names":[],"sources":["../../../src/components/progress/progress.tsx"],"sourcesContent":["import {\n cc,\n CSS_VARS,\n progressControl,\n progressRecipe,\n type ProgressSlots,\n type ProgressVariants,\n toStrbool,\n} from \"@hebium-ui/core\";\nimport { type ComponentProps, type ReactElement, type ReactNode, useId } from \"react\";\nimport { useHuiClassNames, useHuiProps, useHuiStyles } from \"~/provider\";\nimport { type HuiComponentProps } from \"~/types\";\n\ntype HtmlDivProps = ComponentProps<\"div\">;\n\ninterface ProgressOwnProps extends HtmlDivProps {\n /**\n * The minimum value of the progress range.\n *\n * @default 0\n */\n min?: number | undefined;\n /**\n * The maximum value of the progress range.\n *\n * @default 100\n */\n max?: number | undefined;\n /**\n * The current value of the progress. Omit this prop when progress is indeterminate.\n */\n value?: number | undefined;\n /**\n * The human-readable text alternative for the current value.\n */\n valueText?: string | undefined;\n /**\n * The label displayed above the progressbar.\n */\n label?: ReactNode | undefined;\n /**\n * The semantic color of the progressbar.\n *\n * @default \"accent\"\n */\n color?: ProgressVariants[\"color\"] | undefined;\n /**\n * The border radius of the progressbar.\n *\n * @default \"rounded\"\n */\n radius?: ProgressVariants[\"radius\"] | undefined;\n /**\n * The size of the progressbar.\n *\n * @default \"md\"\n */\n size?: ProgressVariants[\"size\"] | undefined;\n}\n\nexport type ProgressProps = HuiComponentProps<\n ProgressOwnProps,\n ProgressSlots\n>;\n\nexport function Progress(rawProps: ProgressProps): ReactElement {\n const {\n min,\n max,\n value,\n valueText,\n label,\n color,\n radius,\n size,\n nonce,\n ...restProps\n } = useHuiProps(\"Progress\", rawProps);\n const progressId = useId();\n const progress = progressControl.resolve({\n progressId,\n hasLabel: Boolean(label),\n min,\n max,\n value,\n valueText,\n });\n\n const recipe = progressRecipe({\n color,\n indeterminate: toStrbool(progress.isIndeterminate),\n radius,\n size,\n });\n const cls = useHuiClassNames(\"Progress\", recipe, rawProps);\n const sls = useHuiStyles(\"Progress\", rawProps);\n const labelAttrs = progressControl.getLabelAttributes(progress);\n const barAttrs = progressControl.getBarAttributes(progress);\n const valueAttrs = progressControl.getValueAttributes();\n const valueClassName = `progress-value-${progress.progressId}`;\n\n return (\n <div\n className={cls.root}\n style={sls.root}\n >\n {label\n && (\n <div\n className={cls.label}\n style={sls.label}\n {...labelAttrs}\n >\n {label}\n </div>\n )}\n <div\n className={cls.bar}\n style={sls.bar}\n {...barAttrs}\n {...restProps}\n >\n <style nonce={nonce}>\n {`.${valueClassName} {${CSS_VARS.arbitraryWidth}: ${progress.width}}`}\n </style>\n <div\n className={cc(cls.value, valueClassName)}\n style={sls.value}\n {...valueAttrs}\n >\n {progress.isIndeterminate ? undefined : valueText}\n </div>\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;AAiEA,SAAgB,SAAS,UAAuC;CAC9D,MAAM,EACJ,KACA,KACA,OACA,WACA,OACA,OACA,QACA,MACA,OACA,GAAG,cACD,YAAY,YAAY,QAAQ;CACpC,MAAM,aAAa,MAAM;CACzB,MAAM,WAAW,gBAAgB,QAAQ;EACvC;EACA,UAAU,QAAQ,KAAK;EACvB;EACA;EACA;EACA;CACF,CAAC;CAED,MAAM,SAAS,eAAe;EAC5B;EACA,eAAe,UAAU,SAAS,eAAe;EACjD;EACA;CACF,CAAC;CACD,MAAM,MAAM,iBAAiB,YAAY,QAAQ,QAAQ;CACzD,MAAM,MAAM,aAAa,YAAY,QAAQ;CAC7C,MAAM,aAAa,gBAAgB,mBAAmB,QAAQ;CAC9D,MAAM,WAAW,gBAAgB,iBAAiB,QAAQ;CAC1D,MAAM,aAAa,gBAAgB,mBAAmB;CACtD,MAAM,iBAAiB,kBAAkB,SAAS;CAElD,OACE,qBAAC,OAAD;EACE,WAAW,IAAI;EACf,OAAO,IAAI;EAFb,UAAA,CAIG,SAEG,oBAAC,OAAD;GACE,WAAW,IAAI;GACf,OAAO,IAAI;GACX,GAAI;GAEH,UAAA;EACE,CAAA,GAET,qBAAC,OAAD;GACE,WAAW,IAAI;GACf,OAAO,IAAI;GACX,GAAI;GACJ,GAAI;GAJN,UAAA,CAME,oBAAC,SAAD;IAAc;IACX,UAAA,IAAI,eAAe,IAAI,SAAS,eAAe,IAAI,SAAS,MAAM;GAC9D,CAAA,GACP,oBAAC,OAAD;IACE,WAAW,GAAG,IAAI,OAAO,cAAc;IACvC,OAAO,IAAI;IACX,GAAI;IAEH,UAAA,SAAS,kBAAkB,KAAA,IAAY;GACrC,CAAA,CACF;EACF,CAAA,CAAA;;AAET"}
|
|
@@ -16,8 +16,8 @@ function Radio(rawProps) {
|
|
|
16
16
|
color,
|
|
17
17
|
error: toStrbool(radioState.invalid)
|
|
18
18
|
});
|
|
19
|
-
const cls = useHuiClassNames("Radio", recipe, rawProps
|
|
20
|
-
const sls = useHuiStyles("Radio", rawProps
|
|
19
|
+
const cls = useHuiClassNames("Radio", recipe, rawProps);
|
|
20
|
+
const sls = useHuiStyles("Radio", rawProps);
|
|
21
21
|
const controlAttrs = normalizeAttributes(radioControl.getControlAttributes(radioState));
|
|
22
22
|
const labelAttrs = normalizeAttributes(radioControl.getLabelAttributes(radioState));
|
|
23
23
|
const errorAttrs = radioControl.getErrorAttributes(radioState);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"radio.js","names":[],"sources":["../../../src/components/radio/radio.tsx"],"sourcesContent":["import { radioControl, radioRecipe, type RadioSlots, type RadioVariants, toBool, toStrbool } from \"@hebium-ui/core\";\nimport { type ComponentProps, type ReactElement, type ReactNode, useId } from \"react\";\nimport { useHuiClassNames, useHuiProps, useHuiStyles } from \"~/provider\";\nimport { type HuiComponentProps } from \"~/types\";\nimport { normalizeAttributes } from \"~/utils\";\n\ntype HtmlInputProps = Omit<ComponentProps<\"input\">, \"children\" | \"type\">;\n\ninterface RadioOwnProps extends HtmlInputProps {\n /**\n * The label displayed next to the radio control.\n */\n label?: ReactNode | undefined;\n /**\n * The error message displayed below the label.\n */\n error?: ReactNode | undefined;\n /**\n * The semantic color of the radio control.\n *\n * @default \"accent\"\n */\n color?: RadioVariants[\"color\"] | undefined;\n}\n\nexport type RadioProps = HuiComponentProps<\n RadioOwnProps,\n RadioSlots\n>;\n\nexport function Radio(rawProps: RadioProps): ReactElement {\n const {\n id,\n label,\n error,\n color,\n ref,\n ...restProps\n } = useHuiProps(\"Radio\", rawProps);\n\n const tmpId = useId();\n\n const radioState = {\n id: id ?? tmpId,\n invalid: !!error,\n disabled: toBool(restProps.disabled) || toBool(restProps[\"aria-disabled\"]),\n };\n const recipe = radioRecipe({\n color,\n error: toStrbool(radioState.invalid),\n });\n const cls = useHuiClassNames(\"Radio\", recipe, rawProps
|
|
1
|
+
{"version":3,"file":"radio.js","names":[],"sources":["../../../src/components/radio/radio.tsx"],"sourcesContent":["import { radioControl, radioRecipe, type RadioSlots, type RadioVariants, toBool, toStrbool } from \"@hebium-ui/core\";\nimport { type ComponentProps, type ReactElement, type ReactNode, useId } from \"react\";\nimport { useHuiClassNames, useHuiProps, useHuiStyles } from \"~/provider\";\nimport { type HuiComponentProps } from \"~/types\";\nimport { normalizeAttributes } from \"~/utils\";\n\ntype HtmlInputProps = Omit<ComponentProps<\"input\">, \"children\" | \"type\">;\n\ninterface RadioOwnProps extends HtmlInputProps {\n /**\n * The label displayed next to the radio control.\n */\n label?: ReactNode | undefined;\n /**\n * The error message displayed below the label.\n */\n error?: ReactNode | undefined;\n /**\n * The semantic color of the radio control.\n *\n * @default \"accent\"\n */\n color?: RadioVariants[\"color\"] | undefined;\n}\n\nexport type RadioProps = HuiComponentProps<\n RadioOwnProps,\n RadioSlots\n>;\n\nexport function Radio(rawProps: RadioProps): ReactElement {\n const {\n id,\n label,\n error,\n color,\n ref,\n ...restProps\n } = useHuiProps(\"Radio\", rawProps);\n\n const tmpId = useId();\n\n const radioState = {\n id: id ?? tmpId,\n invalid: !!error,\n disabled: toBool(restProps.disabled) || toBool(restProps[\"aria-disabled\"]),\n };\n const recipe = radioRecipe({\n color,\n error: toStrbool(radioState.invalid),\n });\n const cls = useHuiClassNames(\"Radio\", recipe, rawProps);\n const sls = useHuiStyles(\"Radio\", rawProps);\n const controlAttrs = normalizeAttributes(radioControl.getControlAttributes(radioState));\n const labelAttrs = normalizeAttributes(radioControl.getLabelAttributes(radioState));\n const errorAttrs = radioControl.getErrorAttributes(radioState);\n\n return (\n <div\n className={cls.root}\n style={sls.root}\n >\n <input\n ref={ref}\n className={cls.radio}\n style={sls.radio}\n {...controlAttrs}\n {...restProps}\n />\n <div>\n {label && (\n <label\n className={cls.label}\n style={sls.label}\n {...labelAttrs}\n >\n {label}\n </label>\n )}\n {error && (\n <p\n className={cls.error}\n style={sls.error}\n {...errorAttrs}\n >\n <span\n aria-hidden\n className={cls.errorIcon}\n style={sls.errorIcon}\n />\n <span\n className={cls.errorMessage}\n style={sls.errorMessage}\n >\n {error}\n </span>\n </p>\n )}\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;;AA8BA,SAAgB,MAAM,UAAoC;CACxD,MAAM,EACJ,IACA,OACA,OACA,OACA,KACA,GAAG,cACD,YAAY,SAAS,QAAQ;CAEjC,MAAM,QAAQ,MAAM;CAEpB,MAAM,aAAa;EACjB,IAAI,MAAM;EACV,SAAS,CAAC,CAAC;EACX,UAAU,OAAO,UAAU,QAAQ,KAAK,OAAO,UAAU,gBAAgB;CAC3E;CACA,MAAM,SAAS,YAAY;EACzB;EACA,OAAO,UAAU,WAAW,OAAO;CACrC,CAAC;CACD,MAAM,MAAM,iBAAiB,SAAS,QAAQ,QAAQ;CACtD,MAAM,MAAM,aAAa,SAAS,QAAQ;CAC1C,MAAM,eAAe,oBAAoB,aAAa,qBAAqB,UAAU,CAAC;CACtF,MAAM,aAAa,oBAAoB,aAAa,mBAAmB,UAAU,CAAC;CAClF,MAAM,aAAa,aAAa,mBAAmB,UAAU;CAE7D,OACE,qBAAC,OAAD;EACE,WAAW,IAAI;EACf,OAAO,IAAI;EAFb,UAAA,CAIE,oBAAC,SAAD;GACO;GACL,WAAW,IAAI;GACf,OAAO,IAAI;GACX,GAAI;GACJ,GAAI;EACL,CAAA,GACD,qBAAC,OAAD,EAAA,UAAA,CACG,SACC,oBAAC,SAAD;GACE,WAAW,IAAI;GACf,OAAO,IAAI;GACX,GAAI;GAEH,UAAA;EACI,CAAA,GAER,SACC,qBAAC,KAAD;GACE,WAAW,IAAI;GACf,OAAO,IAAI;GACX,GAAI;GAHN,UAAA,CAKE,oBAAC,QAAD;IACE,eAAA;IACA,WAAW,IAAI;IACf,OAAO,IAAI;GACZ,CAAA,GACD,oBAAC,QAAD;IACE,WAAW,IAAI;IACf,OAAO,IAAI;IAEV,UAAA;GACG,CAAA,CACL;EAEF,CAAA,CAAA,EAAA,CAAA,CACF;;AAET"}
|
|
@@ -30,5 +30,4 @@ interface RadiogroupOwnProps {
|
|
|
30
30
|
}
|
|
31
31
|
export type RadiogroupProps<E extends ElementType = "div"> = HuiPolymorphicProps<E, RadiogroupOwnProps, RadiogroupSlots>;
|
|
32
32
|
export declare function Radiogroup<E extends ElementType = "div">(rawProps: RadiogroupProps<E>): ReactElement;
|
|
33
|
-
export {};
|
|
34
|
-
//# sourceMappingURL=radiogroup.d.ts.map
|
|
33
|
+
export {};
|