fluid-primitives 0.19.1 → 1.0.0-beta.1
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/README.md +9 -0
- package/dist/Client-HrMIqv7d.js +1934 -0
- package/dist/accordion.d.ts +2 -2
- package/dist/accordion.js +25 -29
- package/dist/button.d.ts +52 -0
- package/dist/button.js +135 -0
- package/dist/checkbox-group.d.ts +6 -5
- package/dist/checkbox-group.js +36 -20
- package/dist/{checkbox-group.registry-CGwuF7SF.js → checkbox-group.registry-D8P8A4LY.js} +13 -8
- package/dist/checkbox.d.ts +18 -4
- package/dist/checkbox.js +30 -27
- package/dist/client.d.ts +2 -2
- package/dist/client.js +2 -2
- package/dist/clipboard.d.ts +12 -5
- package/dist/clipboard.js +14 -16
- package/dist/collapsible.d.ts +3 -3
- package/dist/collapsible.js +13 -17
- package/dist/combobox.d.ts +37 -0
- package/dist/combobox.js +151 -0
- package/dist/date-picker.d.ts +67 -0
- package/dist/date-picker.js +289 -0
- package/dist/dialog.d.ts +3 -3
- package/dist/dialog.js +11 -12
- package/dist/field-array.d.ts +97 -0
- package/dist/field-array.js +223 -0
- package/dist/field.d.ts +30 -54
- package/dist/field.js +589 -175
- package/dist/fieldset.d.ts +15 -0
- package/dist/fieldset.js +27 -0
- package/dist/file-upload.d.ts +85 -0
- package/dist/file-upload.js +255 -0
- package/dist/form.d.ts +2 -83
- package/dist/form.fields-B58TZukv.js +329 -0
- package/dist/form.js +263 -276
- package/dist/index-B06gIN_k.d.ts +1358 -0
- package/dist/input.d.ts +96 -0
- package/dist/input.js +233 -0
- package/dist/menu.d.ts +55 -0
- package/dist/menu.js +144 -0
- package/dist/navigation-menu.d.ts +3 -3
- package/dist/navigation-menu.js +29 -43
- package/dist/number-input.d.ts +13 -4
- package/dist/number-input.js +30 -31
- package/dist/popover.d.ts +11 -3
- package/dist/popover.js +17 -18
- package/dist/radio-group.d.ts +4 -4
- package/dist/radio-group.js +35 -42
- package/dist/scroll-area.d.ts +3 -3
- package/dist/scroll-area.js +10 -9
- package/dist/select.d.ts +13 -51
- package/dist/select.js +62 -55
- package/dist/slider.d.ts +27 -0
- package/dist/slider.js +71 -0
- package/dist/switch.d.ts +4 -4
- package/dist/switch.js +24 -33
- package/dist/tabs.d.ts +3 -3
- package/dist/tabs.js +12 -15
- package/dist/textarea.d.ts +101 -0
- package/dist/textarea.js +231 -0
- package/dist/tooltip.d.ts +11 -3
- package/dist/tooltip.js +11 -10
- package/package.json +79 -24
- package/dist/Client-C51NSHxg.js +0 -248
- package/dist/field.dom-CJQXpQbZ.js +0 -11
- package/dist/form.registry-Cb8Pvoe8.d.ts +0 -7
- package/dist/form.registry-CmpTny_s.js +0 -51
- package/dist/index-B8JCdyld.d.ts +0 -118
package/dist/slider.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { K as registerClientPropConverters, a as normalizeProps, at as Machine, o as mergeProps, s as FieldAwareComponent } from "./Client-HrMIqv7d.js";
|
|
2
|
+
import * as slider from "@zag-js/slider";
|
|
3
|
+
|
|
4
|
+
//#region Resources/Private/Primitives/Slider/Slider.ts
|
|
5
|
+
registerClientPropConverters("slider", { thumbSize: (thumbSize) => thumbSize });
|
|
6
|
+
var Slider = class extends FieldAwareComponent {
|
|
7
|
+
static componentName = "slider";
|
|
8
|
+
propsWithField(props, field) {
|
|
9
|
+
return {
|
|
10
|
+
...props,
|
|
11
|
+
disabled: props.disabled ?? field.disabled,
|
|
12
|
+
readOnly: props.readOnly ?? field.readOnly,
|
|
13
|
+
invalid: props.invalid ?? field.invalid,
|
|
14
|
+
name: props.name ?? field.name
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
initMachine(props) {
|
|
18
|
+
props = this.withFieldProps(props);
|
|
19
|
+
const [machineProps] = slider.splitProps(props);
|
|
20
|
+
return new Machine(slider.machine, machineProps);
|
|
21
|
+
}
|
|
22
|
+
initApi() {
|
|
23
|
+
return slider.connect(this.machine.service, normalizeProps);
|
|
24
|
+
}
|
|
25
|
+
render() {
|
|
26
|
+
this.subscribeToFieldService();
|
|
27
|
+
const rootEl = this.hydrator.query("root");
|
|
28
|
+
if (rootEl) this.spreadProps(rootEl, this.api.getRootProps());
|
|
29
|
+
const labelEl = this.hydrator.query("label");
|
|
30
|
+
if (labelEl) this.spreadProps(labelEl, this.api.getLabelProps());
|
|
31
|
+
const valueTextEl = this.hydrator.query("valueText");
|
|
32
|
+
if (valueTextEl) {
|
|
33
|
+
this.spreadProps(valueTextEl, this.api.getValueTextProps());
|
|
34
|
+
valueTextEl.textContent = this.api.value.join(" - ");
|
|
35
|
+
}
|
|
36
|
+
const trackEl = this.hydrator.query("track");
|
|
37
|
+
if (trackEl) this.spreadProps(trackEl, this.api.getTrackProps());
|
|
38
|
+
const rangeEl = this.hydrator.query("range");
|
|
39
|
+
if (rangeEl) this.spreadProps(rangeEl, this.api.getRangeProps());
|
|
40
|
+
const controlEl = this.hydrator.query("control");
|
|
41
|
+
if (controlEl) this.spreadProps(controlEl, this.api.getControlProps());
|
|
42
|
+
const markerGroupEl = this.hydrator.query("markerGroup");
|
|
43
|
+
if (markerGroupEl) this.spreadProps(markerGroupEl, this.api.getMarkerGroupProps());
|
|
44
|
+
this.hydrator.queryAll("thumb").forEach((thumbEl) => {
|
|
45
|
+
const index = Number(thumbEl.dataset.value ?? 0);
|
|
46
|
+
const name = thumbEl.dataset.name;
|
|
47
|
+
const thumbProps = mergeProps(this.api.getThumbProps({
|
|
48
|
+
index,
|
|
49
|
+
name
|
|
50
|
+
}), {
|
|
51
|
+
"aria-describedby": this.field?.ariaDescribedby,
|
|
52
|
+
"aria-invalid": this.field?.invalid || void 0
|
|
53
|
+
});
|
|
54
|
+
this.spreadProps(thumbEl, thumbProps);
|
|
55
|
+
const hiddenInputEl = this.hydrator.query("hiddenInput", thumbEl);
|
|
56
|
+
if (hiddenInputEl) this.spreadProps(hiddenInputEl, this.api.getHiddenInputProps({
|
|
57
|
+
index,
|
|
58
|
+
name
|
|
59
|
+
}));
|
|
60
|
+
});
|
|
61
|
+
this.spreadPropsByValue("marker", ({ value }) => this.api.getMarkerProps({ value: Number(value) }));
|
|
62
|
+
this.hydrator.queryAll("draggingIndicator").forEach((el) => {
|
|
63
|
+
const index = Number(el.dataset.value ?? 0);
|
|
64
|
+
this.spreadProps(el, this.api.getDraggingIndicatorProps({ index }));
|
|
65
|
+
el.textContent = String(this.api.getThumbValue(index));
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
//#endregion
|
|
71
|
+
export { Slider };
|
package/dist/switch.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import * as zagSwitch from "@zag-js/switch";
|
|
1
|
+
import { b as FieldClientApi, c as Machine, y as FieldAwareComponent } from "./index-B06gIN_k.js";
|
|
3
2
|
import * as _$_zag_js_types0 from "@zag-js/types";
|
|
3
|
+
import * as zagSwitch from "@zag-js/switch";
|
|
4
4
|
|
|
5
5
|
//#region Resources/Private/Primitives/Switch/Switch.d.ts
|
|
6
6
|
declare class Switch extends FieldAwareComponent<zagSwitch.Props, zagSwitch.Api> {
|
|
7
|
-
static
|
|
8
|
-
propsWithField(props: zagSwitch.Props,
|
|
7
|
+
static componentName: string;
|
|
8
|
+
propsWithField(props: zagSwitch.Props, field: FieldClientApi): zagSwitch.Props;
|
|
9
9
|
initMachine(props: zagSwitch.Props): Machine<any>;
|
|
10
10
|
initApi(): zagSwitch.Api<_$_zag_js_types0.PropTypes<{
|
|
11
11
|
[x: string]: any;
|
package/dist/switch.js
CHANGED
|
@@ -1,59 +1,50 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import { a as getLabelId, t as getControlId } from "./field.dom-CJQXpQbZ.js";
|
|
1
|
+
import { a as normalizeProps, at as Machine, o as mergeProps, s as FieldAwareComponent } from "./Client-HrMIqv7d.js";
|
|
3
2
|
import * as zagSwitch from "@zag-js/switch";
|
|
4
3
|
|
|
5
4
|
//#region Resources/Private/Primitives/Switch/Switch.ts
|
|
6
5
|
var Switch = class extends FieldAwareComponent {
|
|
7
|
-
static
|
|
8
|
-
propsWithField(props,
|
|
6
|
+
static componentName = "switch";
|
|
7
|
+
propsWithField(props, field) {
|
|
9
8
|
return {
|
|
10
9
|
...props,
|
|
11
|
-
disabled: props.disabled ??
|
|
12
|
-
readOnly: props.readOnly ??
|
|
13
|
-
required: props.required ??
|
|
14
|
-
invalid: props.invalid ??
|
|
15
|
-
name: props.name ??
|
|
16
|
-
ids: {
|
|
17
|
-
...props.ids,
|
|
18
|
-
label: getLabelId(fieldMachine.scope),
|
|
19
|
-
hiddenInput: getControlId(fieldMachine.scope)
|
|
20
|
-
}
|
|
10
|
+
disabled: props.disabled ?? field.disabled,
|
|
11
|
+
readOnly: props.readOnly ?? field.readOnly,
|
|
12
|
+
required: props.required ?? field.required,
|
|
13
|
+
invalid: props.invalid ?? field.invalid,
|
|
14
|
+
name: props.name ?? field.name
|
|
21
15
|
};
|
|
22
16
|
}
|
|
23
17
|
initMachine(props) {
|
|
24
18
|
props = this.withFieldProps(props);
|
|
25
|
-
|
|
19
|
+
const [machineProps] = zagSwitch.splitProps(props);
|
|
20
|
+
return new Machine(zagSwitch.machine, machineProps);
|
|
26
21
|
}
|
|
27
22
|
initApi() {
|
|
28
23
|
return zagSwitch.connect(this.machine.service, normalizeProps);
|
|
29
24
|
}
|
|
30
25
|
render() {
|
|
31
26
|
this.subscribeToFieldService();
|
|
32
|
-
const rootEl = this.
|
|
27
|
+
const rootEl = this.hydrator.query("root");
|
|
33
28
|
if (rootEl) this.spreadProps(rootEl, this.api.getRootProps());
|
|
34
|
-
const labelEl = this.
|
|
29
|
+
const labelEl = this.hydrator.query("label");
|
|
35
30
|
if (labelEl) this.spreadProps(labelEl, this.api.getLabelProps());
|
|
36
|
-
const controlEl = this.
|
|
31
|
+
const controlEl = this.hydrator.query("control");
|
|
37
32
|
if (controlEl) this.spreadProps(controlEl, this.api.getControlProps());
|
|
38
|
-
const thumbEl = this.
|
|
33
|
+
const thumbEl = this.hydrator.query("thumb");
|
|
39
34
|
if (thumbEl) this.spreadProps(thumbEl, this.api.getThumbProps());
|
|
40
|
-
const hiddenInputEl = this.
|
|
35
|
+
const hiddenInputEl = this.hydrator.query("hiddenInput");
|
|
41
36
|
if (hiddenInputEl) {
|
|
42
|
-
const mergedProps = mergeProps(this.api.getHiddenInputProps(), { "aria-describedby": this.
|
|
37
|
+
const mergedProps = mergeProps(this.api.getHiddenInputProps(), { "aria-describedby": this.field?.ariaDescribedby });
|
|
43
38
|
this.spreadProps(hiddenInputEl, mergedProps);
|
|
44
39
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
"aria-hidden": true,
|
|
54
|
-
hidden: this.api.checked ? true : void 0,
|
|
55
|
-
"data-state": "unchecked"
|
|
56
|
-
}));
|
|
40
|
+
this.spreadPropsByValue("indicator", ({ value }) => {
|
|
41
|
+
const isActive = value === "checked" === this.api.checked;
|
|
42
|
+
return normalizeProps.element({
|
|
43
|
+
"aria-hidden": true,
|
|
44
|
+
hidden: isActive ? void 0 : true,
|
|
45
|
+
"data-state": value
|
|
46
|
+
});
|
|
47
|
+
});
|
|
57
48
|
}
|
|
58
49
|
};
|
|
59
50
|
|
package/dist/tabs.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import * as tabs from "@zag-js/tabs";
|
|
1
|
+
import { c as Machine, z as Component } from "./index-B06gIN_k.js";
|
|
3
2
|
import * as _$_zag_js_types0 from "@zag-js/types";
|
|
3
|
+
import * as tabs from "@zag-js/tabs";
|
|
4
4
|
|
|
5
5
|
//#region Resources/Private/Primitives/Tabs/Tabs.d.ts
|
|
6
6
|
declare class Tabs extends Component<tabs.Props, tabs.Api> {
|
|
7
|
-
static
|
|
7
|
+
static componentName: string;
|
|
8
8
|
initMachine(props: tabs.Props): Machine<any>;
|
|
9
9
|
initApi(): tabs.Api<_$_zag_js_types0.PropTypes<{
|
|
10
10
|
[x: string]: any;
|
package/dist/tabs.js
CHANGED
|
@@ -1,30 +1,27 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as normalizeProps, at as Machine, rt as Component } from "./Client-HrMIqv7d.js";
|
|
2
2
|
import * as tabs from "@zag-js/tabs";
|
|
3
3
|
|
|
4
4
|
//#region Resources/Private/Primitives/Tabs/Tabs.ts
|
|
5
5
|
var Tabs = class extends Component {
|
|
6
|
-
static
|
|
6
|
+
static componentName = "tabs";
|
|
7
7
|
initMachine(props) {
|
|
8
|
-
|
|
8
|
+
const [machineProps] = tabs.splitProps(props);
|
|
9
|
+
return new Machine(tabs.machine, machineProps);
|
|
9
10
|
}
|
|
10
11
|
initApi() {
|
|
11
12
|
return tabs.connect(this.machine.service, normalizeProps);
|
|
12
13
|
}
|
|
13
14
|
render = () => {
|
|
14
|
-
const rootEl = this.
|
|
15
|
+
const rootEl = this.hydrator.query("root");
|
|
15
16
|
if (rootEl) this.spreadProps(rootEl, this.api.getRootProps());
|
|
16
|
-
const listEl = this.
|
|
17
|
+
const listEl = this.hydrator.query("list");
|
|
17
18
|
if (listEl) this.spreadProps(listEl, this.api.getListProps());
|
|
18
|
-
this.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
this.getElements("content").forEach((contentEl) => {
|
|
25
|
-
this.spreadProps(contentEl, this.api.getContentProps({ value: contentEl.dataset.value }));
|
|
26
|
-
});
|
|
27
|
-
const indicatorEl = this.getElement("indicator");
|
|
19
|
+
this.spreadPropsByValue("trigger", ({ el, value }) => this.api.getTriggerProps({
|
|
20
|
+
value,
|
|
21
|
+
disabled: el.hasAttribute("data-disabled")
|
|
22
|
+
}));
|
|
23
|
+
this.spreadPropsByValue("content", ({ value }) => this.api.getContentProps({ value }));
|
|
24
|
+
const indicatorEl = this.hydrator.query("indicator");
|
|
28
25
|
if (indicatorEl) this.spreadProps(indicatorEl, this.api.getIndicatorProps());
|
|
29
26
|
};
|
|
30
27
|
};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { b as FieldClientApi, c as Machine$1, y as FieldAwareComponent } from "./index-B06gIN_k.js";
|
|
2
|
+
import { EventObject } from "@zag-js/core";
|
|
3
|
+
import { PropTypes } from "@zag-js/types";
|
|
4
|
+
|
|
5
|
+
//#region Resources/Private/Primitives/Textarea/src/textarea.types.d.ts
|
|
6
|
+
interface TextareaTranslations {
|
|
7
|
+
/**
|
|
8
|
+
* The text of the word count part. `%count%` is replaced with the number of characters, `%max%`
|
|
9
|
+
* with `maxLength`, e.g. `%count% / %max% characters`.
|
|
10
|
+
*/
|
|
11
|
+
wordCount?: string;
|
|
12
|
+
}
|
|
13
|
+
type TextareaSubmitOn = 'enter' | 'mod+enter';
|
|
14
|
+
interface TextareaProps {
|
|
15
|
+
/** The unique identifier of the textarea. */
|
|
16
|
+
id: string;
|
|
17
|
+
/** The ids of the parts other elements reference: `textarea` (the `for` of its label) and `wordCount`. */
|
|
18
|
+
ids?: Record<string, string>;
|
|
19
|
+
/** The name of the textarea, as it is submitted with the form. Taken from the closest field. */
|
|
20
|
+
name?: string;
|
|
21
|
+
/** Whether the textarea is disabled. Taken from the closest field. */
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
/** Whether the textarea is read-only. Taken from the closest field. */
|
|
24
|
+
readOnly?: boolean;
|
|
25
|
+
/** Whether the textarea is required. Taken from the closest field. */
|
|
26
|
+
required?: boolean;
|
|
27
|
+
/** Whether the textarea is invalid. Taken from the closest field. */
|
|
28
|
+
invalid?: boolean;
|
|
29
|
+
/** The initial value of the textarea. */
|
|
30
|
+
defaultValue?: string;
|
|
31
|
+
/** The most characters allowed. It also drives the word count, e.g. `42 / 250 characters`. */
|
|
32
|
+
maxLength?: number;
|
|
33
|
+
/** The number of visible lines. */
|
|
34
|
+
rows?: number;
|
|
35
|
+
/**
|
|
36
|
+
* Submits the closest `<form>` on a keypress instead of inserting a newline. `'enter'` submits on
|
|
37
|
+
* Enter, Shift+Enter still inserts a newline. `'mod+enter'` submits on Cmd or Ctrl+Enter, Enter
|
|
38
|
+
* always inserts a newline. By default Enter is never intercepted.
|
|
39
|
+
*/
|
|
40
|
+
submitOn?: TextareaSubmitOn;
|
|
41
|
+
/** The localized texts of the textarea. */
|
|
42
|
+
translations?: TextareaTranslations;
|
|
43
|
+
/**
|
|
44
|
+
* Whether the word count is announced to assistive tech. Set to `false` to stay silent.
|
|
45
|
+
* @default true
|
|
46
|
+
*/
|
|
47
|
+
announce?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Milliseconds to debounce word count announcements by, so rapid typing doesn't
|
|
50
|
+
* spam assistive tech on every keystroke. Set to 0 to announce every change immediately.
|
|
51
|
+
* @default 600
|
|
52
|
+
*/
|
|
53
|
+
announceDebounce?: number;
|
|
54
|
+
/**
|
|
55
|
+
* Runs on every native `input` event, before the value is committed. Return the value to write
|
|
56
|
+
* back to the textarea, e.g. trimmed. The cursor position is kept. It cannot be set from a Fluid
|
|
57
|
+
* template, only by constructing `Textarea` in your own entry file.
|
|
58
|
+
*/
|
|
59
|
+
transform?: (value: string, event: Event) => string;
|
|
60
|
+
/** Called when the value changes. */
|
|
61
|
+
onValueChange?: (details: {
|
|
62
|
+
value: string;
|
|
63
|
+
}) => void;
|
|
64
|
+
}
|
|
65
|
+
interface TextareaHandle {
|
|
66
|
+
/** The current value of the textarea. */
|
|
67
|
+
value: string;
|
|
68
|
+
/** The number of characters in the value. */
|
|
69
|
+
count: number;
|
|
70
|
+
/** The word count text, e.g. `42 / 250 characters`. `null` without `maxLength` or when the text is turned off. */
|
|
71
|
+
countText: string | null;
|
|
72
|
+
/** Whether the textarea is disabled. */
|
|
73
|
+
disabled: boolean;
|
|
74
|
+
/** Whether the textarea is read-only. */
|
|
75
|
+
readOnly: boolean;
|
|
76
|
+
/** Whether the textarea is required. */
|
|
77
|
+
required: boolean;
|
|
78
|
+
/** Whether the textarea is invalid. */
|
|
79
|
+
invalid: boolean;
|
|
80
|
+
/** The name of the textarea. */
|
|
81
|
+
name: string | undefined;
|
|
82
|
+
/** The most characters allowed. */
|
|
83
|
+
maxLength: number | undefined;
|
|
84
|
+
}
|
|
85
|
+
interface TextareaApi extends TextareaHandle {
|
|
86
|
+
getRootProps(): PropTypes['element'];
|
|
87
|
+
getTextareaProps(): PropTypes['textarea'];
|
|
88
|
+
getLabelProps(): PropTypes['label'];
|
|
89
|
+
getWordCountProps(): PropTypes['element'];
|
|
90
|
+
}
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region Resources/Private/Primitives/Textarea/Textarea.d.ts
|
|
93
|
+
declare class Textarea extends FieldAwareComponent<TextareaProps, TextareaApi> {
|
|
94
|
+
static componentName: string;
|
|
95
|
+
propsWithField(props: TextareaProps, field: FieldClientApi): TextareaProps;
|
|
96
|
+
initMachine(props: TextareaProps): Machine$1<any>;
|
|
97
|
+
initApi(): TextareaApi;
|
|
98
|
+
render(): void;
|
|
99
|
+
}
|
|
100
|
+
//#endregion
|
|
101
|
+
export { Textarea };
|
package/dist/textarea.js
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { a as normalizeProps, at as Machine$1, o as mergeProps, s as FieldAwareComponent } from "./Client-HrMIqv7d.js";
|
|
2
|
+
import { createSplitProps, debounce } from "@zag-js/utils";
|
|
3
|
+
import { createAnatomy } from "@zag-js/anatomy";
|
|
4
|
+
import { createMachine } from "@zag-js/core";
|
|
5
|
+
import { createProps } from "@zag-js/types";
|
|
6
|
+
import { createLiveRegion } from "@zag-js/live-region";
|
|
7
|
+
|
|
8
|
+
//#region Resources/Private/Primitives/Textarea/src/textarea.anatomy.ts
|
|
9
|
+
const anatomy = createAnatomy("textarea").parts("root", "label", "textarea", "wordCount");
|
|
10
|
+
const parts = anatomy.build();
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region Resources/Private/Primitives/Textarea/src/textarea.dom.ts
|
|
14
|
+
const getTextareaId = (scope) => scope.ids?.textarea ?? `textarea:${scope.id}:textarea`;
|
|
15
|
+
const getWordCountId = (scope) => scope.ids?.wordCount ?? `textarea:${scope.id}:wordCount`;
|
|
16
|
+
const getTextareaEl = (scope) => scope.query(scope.selector(parts.textarea));
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region Resources/Private/Primitives/Textarea/src/textarea.connect.ts
|
|
20
|
+
function createTextareaHandle(service) {
|
|
21
|
+
const { prop, context, computed } = service;
|
|
22
|
+
return {
|
|
23
|
+
value: context.get("value"),
|
|
24
|
+
count: computed("count"),
|
|
25
|
+
countText: computed("countText"),
|
|
26
|
+
disabled: !!prop("disabled"),
|
|
27
|
+
readOnly: !!prop("readOnly"),
|
|
28
|
+
required: !!prop("required"),
|
|
29
|
+
invalid: !!prop("invalid"),
|
|
30
|
+
name: prop("name"),
|
|
31
|
+
maxLength: prop("maxLength")
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function connect(service, normalize) {
|
|
35
|
+
const { scope, prop, send } = service;
|
|
36
|
+
const handle = createTextareaHandle(service);
|
|
37
|
+
return {
|
|
38
|
+
...handle,
|
|
39
|
+
getRootProps() {
|
|
40
|
+
return normalize.element({
|
|
41
|
+
...parts.root.attrs(scope.id),
|
|
42
|
+
"data-invalid": handle.invalid ? "" : void 0,
|
|
43
|
+
"data-disabled": handle.disabled ? "" : void 0,
|
|
44
|
+
"data-readonly": handle.readOnly ? "" : void 0
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
getTextareaProps() {
|
|
48
|
+
return normalize.textarea({
|
|
49
|
+
...parts.textarea.attrs(scope.id),
|
|
50
|
+
id: getTextareaId(scope),
|
|
51
|
+
name: handle.name,
|
|
52
|
+
disabled: handle.disabled || void 0,
|
|
53
|
+
readOnly: handle.readOnly || void 0,
|
|
54
|
+
required: handle.required || void 0,
|
|
55
|
+
maxLength: handle.maxLength,
|
|
56
|
+
rows: prop("rows"),
|
|
57
|
+
value: handle.value,
|
|
58
|
+
"aria-invalid": handle.invalid ? "true" : void 0,
|
|
59
|
+
"data-invalid": handle.invalid ? "" : void 0,
|
|
60
|
+
"data-disabled": handle.disabled ? "" : void 0,
|
|
61
|
+
"data-readonly": handle.readOnly ? "" : void 0,
|
|
62
|
+
onInput(event) {
|
|
63
|
+
const target = event.currentTarget;
|
|
64
|
+
const transform = prop("transform");
|
|
65
|
+
let value = target.value;
|
|
66
|
+
if (transform) {
|
|
67
|
+
const transformed = transform(value, event);
|
|
68
|
+
if (transformed !== value) {
|
|
69
|
+
value = transformed;
|
|
70
|
+
const { selectionStart, selectionEnd } = target;
|
|
71
|
+
target.value = value;
|
|
72
|
+
if (selectionStart != null) target.selectionStart = selectionStart;
|
|
73
|
+
if (selectionEnd != null) target.selectionEnd = selectionEnd;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
send({
|
|
77
|
+
type: "VALUE_CHANGE",
|
|
78
|
+
value
|
|
79
|
+
});
|
|
80
|
+
},
|
|
81
|
+
onKeyDown(event) {
|
|
82
|
+
const submitOn = prop("submitOn");
|
|
83
|
+
if (!submitOn || event.key !== "Enter" || "isComposing" in event && event.isComposing) return;
|
|
84
|
+
const modPressed = event.metaKey || event.ctrlKey;
|
|
85
|
+
if (!(submitOn === "enter" && !event.shiftKey && !modPressed || submitOn === "mod+enter" && modPressed)) return;
|
|
86
|
+
event.preventDefault();
|
|
87
|
+
event.currentTarget.closest("form")?.requestSubmit();
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
getLabelProps() {
|
|
92
|
+
return normalize.label({
|
|
93
|
+
...parts.label.attrs(scope.id),
|
|
94
|
+
htmlFor: getTextareaId(scope),
|
|
95
|
+
"data-invalid": handle.invalid ? "" : void 0,
|
|
96
|
+
"data-disabled": handle.disabled ? "" : void 0,
|
|
97
|
+
"data-required": handle.required ? "" : void 0
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
getWordCountProps() {
|
|
101
|
+
return normalize.element({
|
|
102
|
+
...parts.wordCount.attrs(scope.id),
|
|
103
|
+
id: getWordCountId(scope),
|
|
104
|
+
"aria-hidden": "true"
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region Resources/Private/Primitives/Textarea/src/textarea.machine.ts
|
|
112
|
+
const machine = createMachine({
|
|
113
|
+
initialState() {
|
|
114
|
+
return "idle";
|
|
115
|
+
},
|
|
116
|
+
context({ bindable, prop }) {
|
|
117
|
+
return { value: bindable(() => ({ defaultValue: prop("defaultValue") ?? "" })) };
|
|
118
|
+
},
|
|
119
|
+
refs() {
|
|
120
|
+
return { announce: null };
|
|
121
|
+
},
|
|
122
|
+
computed: {
|
|
123
|
+
count({ context }) {
|
|
124
|
+
return context.get("value").length;
|
|
125
|
+
},
|
|
126
|
+
countText({ prop, computed }) {
|
|
127
|
+
const wordCountTemplate = prop("translations")?.wordCount;
|
|
128
|
+
const maxLength = prop("maxLength");
|
|
129
|
+
if (!wordCountTemplate || maxLength == null) return null;
|
|
130
|
+
const count = computed("count");
|
|
131
|
+
return wordCountTemplate.replaceAll("%count%", String(count)).replaceAll("%max%", String(maxLength));
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
entry: ["syncValueFromDom"],
|
|
135
|
+
effects: ["manageLiveRegion"],
|
|
136
|
+
states: { idle: {} },
|
|
137
|
+
on: { VALUE_CHANGE: { actions: ["setValue"] } },
|
|
138
|
+
implementations: {
|
|
139
|
+
actions: {
|
|
140
|
+
setValue({ context, event, prop, refs, computed }) {
|
|
141
|
+
const value = event.value;
|
|
142
|
+
context.set("value", value);
|
|
143
|
+
prop("onValueChange")?.({ value });
|
|
144
|
+
const countText = computed("countText");
|
|
145
|
+
if (countText) refs.get("announce")?.(countText);
|
|
146
|
+
},
|
|
147
|
+
syncValueFromDom({ context, scope }) {
|
|
148
|
+
const textareaEl = getTextareaEl(scope);
|
|
149
|
+
if (textareaEl) context.set("value", textareaEl.value);
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
effects: { manageLiveRegion({ refs, prop, computed }) {
|
|
153
|
+
if (prop("announce") === false || computed("countText") === null) return void 0;
|
|
154
|
+
const liveRegion = createLiveRegion({ level: "polite" });
|
|
155
|
+
const debounceMs = prop("announceDebounce") ?? 600;
|
|
156
|
+
const announce = debounceMs > 0 ? debounce((text) => liveRegion.announce(text), debounceMs) : (text) => liveRegion.announce(text);
|
|
157
|
+
refs.set("announce", announce);
|
|
158
|
+
return () => {
|
|
159
|
+
liveRegion.destroy();
|
|
160
|
+
};
|
|
161
|
+
} }
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
//#endregion
|
|
166
|
+
//#region Resources/Private/Primitives/Textarea/src/textarea.props.ts
|
|
167
|
+
const props = createProps()([
|
|
168
|
+
"id",
|
|
169
|
+
"ids",
|
|
170
|
+
"name",
|
|
171
|
+
"disabled",
|
|
172
|
+
"readOnly",
|
|
173
|
+
"required",
|
|
174
|
+
"invalid",
|
|
175
|
+
"defaultValue",
|
|
176
|
+
"maxLength",
|
|
177
|
+
"rows",
|
|
178
|
+
"submitOn",
|
|
179
|
+
"translations",
|
|
180
|
+
"announce",
|
|
181
|
+
"announceDebounce",
|
|
182
|
+
"transform",
|
|
183
|
+
"onValueChange"
|
|
184
|
+
]);
|
|
185
|
+
const splitProps = createSplitProps(props);
|
|
186
|
+
|
|
187
|
+
//#endregion
|
|
188
|
+
//#region Resources/Private/Primitives/Textarea/Textarea.ts
|
|
189
|
+
var Textarea = class extends FieldAwareComponent {
|
|
190
|
+
static componentName = "textarea";
|
|
191
|
+
propsWithField(props, field) {
|
|
192
|
+
return {
|
|
193
|
+
...props,
|
|
194
|
+
disabled: props.disabled ?? field.disabled,
|
|
195
|
+
readOnly: props.readOnly ?? field.readOnly,
|
|
196
|
+
required: props.required ?? field.required,
|
|
197
|
+
invalid: props.invalid ?? field.invalid,
|
|
198
|
+
name: props.name ?? field.name
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
initMachine(props) {
|
|
202
|
+
props = this.withFieldProps(props);
|
|
203
|
+
const [machineProps] = splitProps(props);
|
|
204
|
+
return new Machine$1(machine, machineProps);
|
|
205
|
+
}
|
|
206
|
+
initApi() {
|
|
207
|
+
return connect(this.machine.service, normalizeProps);
|
|
208
|
+
}
|
|
209
|
+
render() {
|
|
210
|
+
this.subscribeToFieldService();
|
|
211
|
+
const rootEl = this.hydrator.query("root");
|
|
212
|
+
if (rootEl) this.spreadProps(rootEl, this.api.getRootProps());
|
|
213
|
+
const wordCountEl = this.hydrator.query("wordCount");
|
|
214
|
+
const wordCountId = wordCountEl ? getWordCountId(this.machine.scope) : void 0;
|
|
215
|
+
const textareaEl = this.hydrator.query("textarea");
|
|
216
|
+
if (textareaEl) {
|
|
217
|
+
const describeIds = [this.field?.ariaDescribedby, wordCountId].filter(Boolean).join(" ");
|
|
218
|
+
const mergedProps = mergeProps(this.api.getTextareaProps(), { "aria-describedby": describeIds || void 0 });
|
|
219
|
+
this.spreadTextControlProps(textareaEl, mergedProps);
|
|
220
|
+
}
|
|
221
|
+
const labelEl = this.hydrator.query("label");
|
|
222
|
+
if (labelEl) this.spreadProps(labelEl, this.api.getLabelProps());
|
|
223
|
+
if (wordCountEl) {
|
|
224
|
+
this.spreadProps(wordCountEl, this.api.getWordCountProps());
|
|
225
|
+
wordCountEl.textContent = this.api.countText ?? "";
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
//#endregion
|
|
231
|
+
export { Textarea };
|
package/dist/tooltip.d.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import * as tooltip from "@zag-js/tooltip";
|
|
1
|
+
import { X as ConverterMachineProps, c as Machine, z as Component } from "./index-B06gIN_k.js";
|
|
3
2
|
import * as _$_zag_js_types0 from "@zag-js/types";
|
|
3
|
+
import * as tooltip from "@zag-js/tooltip";
|
|
4
4
|
|
|
5
5
|
//#region Resources/Private/Primitives/Tooltip/Tooltip.d.ts
|
|
6
|
+
declare const tooltipPropConverters: {
|
|
7
|
+
positioning: (positioning: tooltip.Props["positioning"]) => tooltip.PositioningOptions | undefined;
|
|
8
|
+
};
|
|
9
|
+
declare module 'fluid-primitives' {
|
|
10
|
+
interface HydrationPropsOverrides {
|
|
11
|
+
tooltip: ConverterMachineProps<typeof tooltipPropConverters>;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
6
14
|
declare class Tooltip extends Component<tooltip.Props, tooltip.Api> {
|
|
7
|
-
static
|
|
15
|
+
static componentName: string;
|
|
8
16
|
initMachine(props: tooltip.Props): Machine<any>;
|
|
9
17
|
initApi(): tooltip.Api<_$_zag_js_types0.PropTypes<{
|
|
10
18
|
[x: string]: any;
|
package/dist/tooltip.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { K as registerClientPropConverters, a as normalizeProps, at as Machine, rt as Component } from "./Client-HrMIqv7d.js";
|
|
2
2
|
import * as tooltip from "@zag-js/tooltip";
|
|
3
3
|
|
|
4
4
|
//#region Resources/Private/Primitives/Tooltip/Tooltip.ts
|
|
5
|
+
registerClientPropConverters("tooltip", { positioning: (positioning) => positioning });
|
|
5
6
|
var Tooltip = class extends Component {
|
|
6
|
-
static
|
|
7
|
+
static componentName = "tooltip";
|
|
7
8
|
initMachine(props) {
|
|
9
|
+
const [machineProps] = tooltip.splitProps(props);
|
|
8
10
|
return new Machine(tooltip.machine, {
|
|
9
11
|
interactive: true,
|
|
10
|
-
...
|
|
12
|
+
...machineProps,
|
|
11
13
|
positioning: {
|
|
12
14
|
placement: "top",
|
|
13
15
|
gutter: 6,
|
|
14
|
-
...
|
|
16
|
+
...machineProps.positioning
|
|
15
17
|
}
|
|
16
18
|
});
|
|
17
19
|
}
|
|
@@ -19,15 +21,14 @@ var Tooltip = class extends Component {
|
|
|
19
21
|
return tooltip.connect(this.machine.service, normalizeProps);
|
|
20
22
|
}
|
|
21
23
|
render() {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const positionerEl = this.getElement("positioner");
|
|
24
|
+
this.spreadPropsByOptionalValue("trigger", ({ value }) => this.api.getTriggerProps({ value }));
|
|
25
|
+
const positionerEl = this.hydrator.query("positioner");
|
|
25
26
|
if (positionerEl) this.spreadProps(positionerEl, this.api.getPositionerProps());
|
|
26
|
-
const arrowEl = this.
|
|
27
|
+
const arrowEl = this.hydrator.query("arrow");
|
|
27
28
|
if (arrowEl) this.spreadProps(arrowEl, this.api.getArrowProps());
|
|
28
|
-
const arrowTipEl = this.
|
|
29
|
+
const arrowTipEl = this.hydrator.query("arrowTip");
|
|
29
30
|
if (arrowTipEl) this.spreadProps(arrowTipEl, this.api.getArrowTipProps());
|
|
30
|
-
const contentEl = this.
|
|
31
|
+
const contentEl = this.hydrator.query("content");
|
|
31
32
|
if (contentEl) this.spreadProps(contentEl, this.api.getContentProps());
|
|
32
33
|
}
|
|
33
34
|
};
|