@particle-academy/react-fancy 5.27.0 → 5.27.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 +1 -3
- package/dist/{chunk-7HN4M5MV.cjs → chunk-JX6NKLQV.cjs} +8 -8
- package/dist/{chunk-7HN4M5MV.cjs.map → chunk-JX6NKLQV.cjs.map} +1 -1
- package/dist/{chunk-JAAJJJKI.js → chunk-L5KKMJ2Q.js} +52 -7
- package/dist/chunk-L5KKMJ2Q.js.map +1 -0
- package/dist/{chunk-HBCKKE24.cjs → chunk-LHNC42J3.cjs} +51 -6
- package/dist/chunk-LHNC42J3.cjs.map +1 -0
- package/dist/{chunk-IUWUXCCB.js → chunk-ZDVVE4OV.js} +3 -3
- package/dist/{chunk-IUWUXCCB.js.map → chunk-ZDVVE4OV.js.map} +1 -1
- package/dist/index.cjs +15 -15
- package/dist/index.js +2 -2
- package/dist/input.cjs +2 -2
- package/dist/input.js +1 -1
- package/dist/inputs.cjs +2 -2
- package/dist/inputs.js +1 -1
- package/dist/json-editor.cjs +13 -13
- package/dist/json-editor.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-HBCKKE24.cjs.map +0 -1
- package/dist/chunk-JAAJJJKI.js.map +0 -1
|
@@ -6,9 +6,27 @@ import { useInlineEdit } from './chunk-OL53XYHF.js';
|
|
|
6
6
|
import { useFieldMode } from './chunk-NRXK42LO.js';
|
|
7
7
|
import { useControllableState } from './chunk-6FQGMVF2.js';
|
|
8
8
|
import { cn } from './chunk-MMW2JGKZ.js';
|
|
9
|
-
import { forwardRef, useId } from 'react';
|
|
9
|
+
import { forwardRef, useId, useState, useCallback, useEffect } from 'react';
|
|
10
10
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
11
11
|
|
|
12
|
+
function useAdornmentWidth() {
|
|
13
|
+
const [width, setWidth] = useState(0);
|
|
14
|
+
const [node, setNode] = useState(null);
|
|
15
|
+
const ref = useCallback((n) => setNode(n), []);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (!node) {
|
|
18
|
+
setWidth(0);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const read = () => setWidth(node.getBoundingClientRect().width);
|
|
22
|
+
read();
|
|
23
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
24
|
+
const observer = new ResizeObserver(read);
|
|
25
|
+
observer.observe(node);
|
|
26
|
+
return () => observer.disconnect();
|
|
27
|
+
}, [node]);
|
|
28
|
+
return [ref, width];
|
|
29
|
+
}
|
|
12
30
|
var Input = forwardRef(
|
|
13
31
|
({
|
|
14
32
|
type = "text",
|
|
@@ -42,6 +60,8 @@ var Input = forwardRef(
|
|
|
42
60
|
const inputId = id ?? autoId;
|
|
43
61
|
const resolvedMode = useFieldMode(mode);
|
|
44
62
|
const { showControl, interactive, enterEdit, exitEdit } = useInlineEdit(resolvedMode, disabled);
|
|
63
|
+
const [leadingRef, leadingWidth] = useAdornmentWidth();
|
|
64
|
+
const [trailingRef, trailingWidth] = useAdornmentWidth();
|
|
45
65
|
const canReveal = reveal === true && type === "password";
|
|
46
66
|
const [isRevealed, setRevealed] = useControllableState(revealed, false, onRevealedChange);
|
|
47
67
|
const shown = canReveal && isRevealed;
|
|
@@ -65,7 +85,14 @@ var Input = forwardRef(
|
|
|
65
85
|
suffixPosition,
|
|
66
86
|
size,
|
|
67
87
|
children: /* @__PURE__ */ jsxs("div", { "data-react-fancy-input": "", className: "relative flex items-center", children: [
|
|
68
|
-
leading && /* @__PURE__ */ jsx(
|
|
88
|
+
leading && /* @__PURE__ */ jsx(
|
|
89
|
+
"span",
|
|
90
|
+
{
|
|
91
|
+
ref: leadingRef,
|
|
92
|
+
className: "pointer-events-none absolute left-3 text-zinc-400 dark:text-zinc-500",
|
|
93
|
+
children: leading
|
|
94
|
+
}
|
|
95
|
+
),
|
|
69
96
|
/* @__PURE__ */ jsx(
|
|
70
97
|
"input",
|
|
71
98
|
{
|
|
@@ -80,10 +107,21 @@ var Input = forwardRef(
|
|
|
80
107
|
dirtyClasses(dirty),
|
|
81
108
|
errorClasses(error),
|
|
82
109
|
"w-full",
|
|
83
|
-
|
|
84
|
-
|
|
110
|
+
// The fixed classes are the PRE-MEASURE fallback only. Once the
|
|
111
|
+
// adornment is measured, the inline style below overrides them
|
|
112
|
+
// with its real width -- a fixed 36px is correct for one icon and
|
|
113
|
+
// wrong for anything wider, which is how `https://` came to
|
|
114
|
+
// render on top of the value.
|
|
115
|
+
leading && !leadingWidth && "pl-9",
|
|
116
|
+
(trailing || canReveal) && !trailingWidth && "pr-9",
|
|
85
117
|
className
|
|
86
118
|
),
|
|
119
|
+
style: {
|
|
120
|
+
// 12px clears `left-3`/`right-3`; 8px is the gap to the text.
|
|
121
|
+
...leadingWidth ? { paddingLeft: leadingWidth + 20 } : null,
|
|
122
|
+
...trailingWidth ? { paddingRight: trailingWidth + 20 } : null,
|
|
123
|
+
...props.style
|
|
124
|
+
},
|
|
87
125
|
onChange: (e) => {
|
|
88
126
|
onChange?.(e);
|
|
89
127
|
onValueChange?.(e.target.value);
|
|
@@ -112,7 +150,14 @@ var Input = forwardRef(
|
|
|
112
150
|
className: "absolute right-2 inline-flex items-center justify-center rounded p-1 text-zinc-400 transition-colors hover:text-zinc-600 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500/40 disabled:cursor-not-allowed disabled:opacity-50 dark:text-zinc-500 dark:hover:text-zinc-300",
|
|
113
151
|
children: shown ? /* @__PURE__ */ jsx(EyeOffIcon, {}) : /* @__PURE__ */ jsx(EyeIcon, {})
|
|
114
152
|
}
|
|
115
|
-
) : trailing && /* @__PURE__ */ jsx(
|
|
153
|
+
) : trailing && /* @__PURE__ */ jsx(
|
|
154
|
+
"span",
|
|
155
|
+
{
|
|
156
|
+
ref: trailingRef,
|
|
157
|
+
className: "pointer-events-none absolute right-3 text-zinc-400 dark:text-zinc-500",
|
|
158
|
+
children: trailing
|
|
159
|
+
}
|
|
160
|
+
)
|
|
116
161
|
] })
|
|
117
162
|
}
|
|
118
163
|
);
|
|
@@ -151,5 +196,5 @@ function EyeOffIcon() {
|
|
|
151
196
|
}
|
|
152
197
|
|
|
153
198
|
export { Input };
|
|
154
|
-
//# sourceMappingURL=chunk-
|
|
155
|
-
//# sourceMappingURL=chunk-
|
|
199
|
+
//# sourceMappingURL=chunk-L5KKMJ2Q.js.map
|
|
200
|
+
//# sourceMappingURL=chunk-L5KKMJ2Q.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/use-adornment-width.ts","../src/components/inputs/Input/Input.tsx"],"names":[],"mappings":";;;;;;;;;;;AA0BO,SAAS,iBAAA,GAAkE;AAChF,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAI,SAAS,CAAC,CAAA;AACpC,EAAA,MAAM,CAAC,IAAA,EAAM,OAAO,CAAA,GAAI,SAA6B,IAAI,CAAA;AAEzD,EAAA,MAAM,GAAA,GAAM,YAAY,CAAC,CAAA,KAA0B,QAAQ,CAAC,CAAA,EAAG,EAAE,CAAA;AAEjE,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,IAAI,CAAC,IAAA,EAAM;AACT,MAAA,QAAA,CAAS,CAAC,CAAA;AAEV,MAAA;AAAA,IACF;AAEA,IAAA,MAAM,OAAO,MAAM,QAAA,CAAS,IAAA,CAAK,qBAAA,GAAwB,KAAK,CAAA;AAC9D,IAAA,IAAA,EAAK;AAEL,IAAA,IAAI,OAAO,mBAAmB,WAAA,EAAa;AAE3C,IAAA,MAAM,QAAA,GAAW,IAAI,cAAA,CAAe,IAAI,CAAA;AACxC,IAAA,QAAA,CAAS,QAAQ,IAAI,CAAA;AAErB,IAAA,OAAO,MAAM,SAAS,UAAA,EAAW;AAAA,EACnC,CAAA,EAAG,CAAC,IAAI,CAAC,CAAA;AAET,EAAA,OAAO,CAAC,KAAK,KAAK,CAAA;AACpB;AClCO,IAAM,KAAA,GAAQ,UAAA;AAAA,EACnB,CACE;AAAA,I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,CAAA,EAAE,sCAAA,EAAuC,CAAA;AAAA,oBAC/C,GAAA,CAAC,MAAA,EAAA,EAAK,CAAA,EAAE,8FAAA,EAA+F,CAAA;AAAA,oBACvG,GAAA,CAAC,MAAA,EAAA,EAAK,CAAA,EAAE,YAAA,EAAa;AAAA,GAAA,EACvB,CAAA;AAEJ","file":"chunk-L5KKMJ2Q.js","sourcesContent":["import { useCallback, useEffect, useState } from \"react\";\n\n/**\n * Measure an inline adornment so the input can reserve exactly its width.\n *\n * ## Why this exists\n *\n * `leading` / `trailing` render ABSOLUTELY over the input, so they take no\n * space in flow and the input must be padded by hand to keep text clear of\n * them. That padding used to be a fixed `pl-9` / `pr-9` — 36px, sized for a\n * single icon. Any wider adornment ran straight under the value: `leading =\n * \"https://\"` is roughly 50px, so `https://` and `fancy.app` rendered on top of\n * one another.\n *\n * A fixed padding cannot be right for arbitrary content, and these props accept\n * arbitrary content — a currency code, a unit, a protocol, a short label. So\n * the width is measured rather than assumed.\n *\n * Returns `0` until measured (and on the server), which is the signal to keep\n * the old fixed padding as a fallback: an unmeasured render is then no worse\n * than it was before, rather than unpadded.\n *\n * `ResizeObserver` rather than a one-shot read, because the width changes after\n * first paint for reasons the first paint cannot see — a webfont swapping in,\n * the adornment's own content changing, a container query resizing the text.\n */\nexport function useAdornmentWidth(): [(node: HTMLElement | null) => void, number] {\n const [width, setWidth] = useState(0);\n const [node, setNode] = useState<HTMLElement | null>(null);\n\n const ref = useCallback((n: HTMLElement | null) => setNode(n), []);\n\n useEffect(() => {\n if (!node) {\n setWidth(0);\n\n return;\n }\n\n const read = () => setWidth(node.getBoundingClientRect().width);\n read();\n\n if (typeof ResizeObserver === \"undefined\") return;\n\n const observer = new ResizeObserver(read);\n observer.observe(node);\n\n return () => observer.disconnect();\n }, [node]);\n\n return [ref, width];\n}\n","import { forwardRef, useId } from \"react\";\nimport { cn } from \"../../../utils/cn\";\nimport { useControllableState } from \"../../../hooks/use-controllable-state\";\nimport { useAdornmentWidth } from \"../../../hooks/use-adornment-width\";\nimport { Field } from \"../Field\";\nimport { InputWrapper } from \"../InputWrapper\";\nimport {\n dirtyClasses,\n errorClasses,\n inputBaseClasses,\n inputSizeClasses,\n} from \"../inputs.utils\";\nimport { useFieldMode } from \"../mode/FieldMode.context\";\nimport { DisplayValue } from \"../mode/DisplayValue\";\nimport { useInlineEdit } from \"../mode/useInlineEdit\";\nimport type { InputProps } from \"./Input.types\";\n\nexport const Input = forwardRef<HTMLInputElement, InputProps>(\n (\n {\n type = \"text\",\n size = \"md\",\n dirty,\n error,\n label,\n labelHidden,\n description,\n required,\n disabled,\n className,\n id,\n leading,\n trailing,\n prefix,\n suffix,\n prefixPosition,\n suffixPosition,\n mode,\n onValueChange,\n onChange,\n reveal,\n revealed,\n onRevealedChange,\n revealLabel = \"Show password\",\n hideLabel = \"Hide password\",\n ...props\n },\n ref,\n ) => {\n const autoId = useId();\n const inputId = id ?? autoId;\n const resolvedMode = useFieldMode(mode);\n const { showControl, interactive, enterEdit, exitEdit } = useInlineEdit(resolvedMode, disabled);\n\n // Measured, not assumed: `leading`/`trailing` take arbitrary content, and a\n // fixed padding can only ever be right for one width. See\n // `useAdornmentWidth` for what went wrong with the fixed version.\n const [leadingRef, leadingWidth] = useAdornmentWidth();\n const [trailingRef, trailingWidth] = useAdornmentWidth();\n\n // Only meaningful on a password field: a reveal on an already-visible input\n // is a button that does nothing.\n const canReveal = reveal === true && type === \"password\";\n const [isRevealed, setRevealed] = useControllableState(revealed, false, onRevealedChange);\n const shown = canReveal && isRevealed;\n // The rendered type, NOT the declared one — `type` stays \"password\" so the\n // display-mode masking below and any caller reading props are unaffected.\n const renderedType = shown ? \"text\" : type;\n\n const input = !showControl ? (\n <DisplayValue\n size={size}\n interactive={interactive}\n onActivate={enterEdit}\n leading={leading ?? prefix}\n trailing={trailing ?? suffix}\n >\n {type === \"password\" ? (props.value ? \"••••••\" : \"\") : (props.value as string | undefined)}\n </DisplayValue>\n ) : (\n <InputWrapper\n prefix={prefix}\n suffix={suffix}\n prefixPosition={prefixPosition}\n suffixPosition={suffixPosition}\n size={size}\n >\n <div data-react-fancy-input=\"\" className=\"relative flex items-center\">\n {leading && (\n <span\n ref={leadingRef}\n className=\"pointer-events-none absolute left-3 text-zinc-400 dark:text-zinc-500\"\n >\n {leading}\n </span>\n )}\n <input\n ref={ref}\n id={inputId}\n type={renderedType}\n disabled={disabled}\n required={required}\n className={cn(\n inputBaseClasses,\n inputSizeClasses[size],\n dirtyClasses(dirty),\n errorClasses(error),\n \"w-full\",\n // The fixed classes are the PRE-MEASURE fallback only. Once the\n // adornment is measured, the inline style below overrides them\n // with its real width -- a fixed 36px is correct for one icon and\n // wrong for anything wider, which is how `https://` came to\n // render on top of the value.\n leading && !leadingWidth && \"pl-9\",\n (trailing || canReveal) && !trailingWidth && \"pr-9\",\n className,\n )}\n style={{\n // 12px clears `left-3`/`right-3`; 8px is the gap to the text.\n ...(leadingWidth ? { paddingLeft: leadingWidth + 20 } : null),\n ...(trailingWidth ? { paddingRight: trailingWidth + 20 } : null),\n ...props.style,\n }}\n onChange={(e) => {\n onChange?.(e);\n onValueChange?.(e.target.value);\n }}\n {...props}\n // Inline click-to-edit: focus on entering edit, return to the display\n // (and run the host's onBlur) when focus leaves.\n autoFocus={interactive || props.autoFocus}\n onBlur={(e) => {\n props.onBlur?.(e);\n if (interactive) exitEdit();\n }}\n />\n {canReveal ? (\n <button\n type=\"button\"\n // type=\"button\" is load-bearing: the default is \"submit\", so a\n // reveal inside a login form would submit it on every click.\n id={`${inputId}-reveal`}\n data-react-fancy-reveal=\"\"\n onClick={() => setRevealed((v) => !v)}\n disabled={disabled}\n aria-controls={inputId}\n aria-pressed={shown}\n aria-label={shown ? hideLabel : revealLabel}\n title={shown ? hideLabel : revealLabel}\n // Not focusable by tab: the field and the submit button are the\n // path through a login form, and a reveal in between is a stop\n // most people do not want. Still reachable by click and by\n // screen readers.\n tabIndex={-1}\n className=\"absolute right-2 inline-flex items-center justify-center rounded p-1 text-zinc-400 transition-colors hover:text-zinc-600 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500/40 disabled:cursor-not-allowed disabled:opacity-50 dark:text-zinc-500 dark:hover:text-zinc-300\"\n >\n {shown ? <EyeOffIcon /> : <EyeIcon />}\n </button>\n ) : (\n trailing && (\n <span\n ref={trailingRef}\n className=\"pointer-events-none absolute right-3 text-zinc-400 dark:text-zinc-500\"\n >\n {trailing}\n </span>\n )\n )}\n </div>\n </InputWrapper>\n );\n\n if (label || error || description) {\n return (\n <Field\n label={label}\n labelHidden={labelHidden}\n description={description}\n error={error}\n required={required}\n htmlFor={inputId}\n size={size}\n >\n {input}\n </Field>\n );\n }\n\n return input;\n },\n);\n\nInput.displayName = \"Input\";\n\n/**\n * Inline SVGs rather than the Icon component: Input is the most-installed\n * primitive in the kit, and routing it through the icon registry would make\n * every consumer's password field depend on an icon set being configured.\n */\nfunction EyeIcon() {\n return (\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n <path d=\"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0\" />\n <circle cx=\"12\" cy=\"12\" r=\"3\" />\n </svg>\n );\n}\n\nfunction EyeOffIcon() {\n return (\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n <path d=\"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49\" />\n <path d=\"M14.084 14.158a3 3 0 0 1-4.242-4.242\" />\n <path d=\"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143\" />\n <path d=\"m2 2 20 20\" />\n </svg>\n );\n}\n"]}
|
|
@@ -11,6 +11,24 @@ var chunkZU5Q77OT_cjs = require('./chunk-ZU5Q77OT.cjs');
|
|
|
11
11
|
var react = require('react');
|
|
12
12
|
var jsxRuntime = require('react/jsx-runtime');
|
|
13
13
|
|
|
14
|
+
function useAdornmentWidth() {
|
|
15
|
+
const [width, setWidth] = react.useState(0);
|
|
16
|
+
const [node, setNode] = react.useState(null);
|
|
17
|
+
const ref = react.useCallback((n) => setNode(n), []);
|
|
18
|
+
react.useEffect(() => {
|
|
19
|
+
if (!node) {
|
|
20
|
+
setWidth(0);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const read = () => setWidth(node.getBoundingClientRect().width);
|
|
24
|
+
read();
|
|
25
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
26
|
+
const observer = new ResizeObserver(read);
|
|
27
|
+
observer.observe(node);
|
|
28
|
+
return () => observer.disconnect();
|
|
29
|
+
}, [node]);
|
|
30
|
+
return [ref, width];
|
|
31
|
+
}
|
|
14
32
|
var Input = react.forwardRef(
|
|
15
33
|
({
|
|
16
34
|
type = "text",
|
|
@@ -44,6 +62,8 @@ var Input = react.forwardRef(
|
|
|
44
62
|
const inputId = id ?? autoId;
|
|
45
63
|
const resolvedMode = chunkL3V3BYVS_cjs.useFieldMode(mode);
|
|
46
64
|
const { showControl, interactive, enterEdit, exitEdit } = chunkKJ22KE56_cjs.useInlineEdit(resolvedMode, disabled);
|
|
65
|
+
const [leadingRef, leadingWidth] = useAdornmentWidth();
|
|
66
|
+
const [trailingRef, trailingWidth] = useAdornmentWidth();
|
|
47
67
|
const canReveal = reveal === true && type === "password";
|
|
48
68
|
const [isRevealed, setRevealed] = chunkOUOEQZHY_cjs.useControllableState(revealed, false, onRevealedChange);
|
|
49
69
|
const shown = canReveal && isRevealed;
|
|
@@ -67,7 +87,14 @@ var Input = react.forwardRef(
|
|
|
67
87
|
suffixPosition,
|
|
68
88
|
size,
|
|
69
89
|
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-react-fancy-input": "", className: "relative flex items-center", children: [
|
|
70
|
-
leading && /* @__PURE__ */ jsxRuntime.jsx(
|
|
90
|
+
leading && /* @__PURE__ */ jsxRuntime.jsx(
|
|
91
|
+
"span",
|
|
92
|
+
{
|
|
93
|
+
ref: leadingRef,
|
|
94
|
+
className: "pointer-events-none absolute left-3 text-zinc-400 dark:text-zinc-500",
|
|
95
|
+
children: leading
|
|
96
|
+
}
|
|
97
|
+
),
|
|
71
98
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
72
99
|
"input",
|
|
73
100
|
{
|
|
@@ -82,10 +109,21 @@ var Input = react.forwardRef(
|
|
|
82
109
|
chunkYLGTDBB2_cjs.dirtyClasses(dirty),
|
|
83
110
|
chunkYLGTDBB2_cjs.errorClasses(error),
|
|
84
111
|
"w-full",
|
|
85
|
-
|
|
86
|
-
|
|
112
|
+
// The fixed classes are the PRE-MEASURE fallback only. Once the
|
|
113
|
+
// adornment is measured, the inline style below overrides them
|
|
114
|
+
// with its real width -- a fixed 36px is correct for one icon and
|
|
115
|
+
// wrong for anything wider, which is how `https://` came to
|
|
116
|
+
// render on top of the value.
|
|
117
|
+
leading && !leadingWidth && "pl-9",
|
|
118
|
+
(trailing || canReveal) && !trailingWidth && "pr-9",
|
|
87
119
|
className
|
|
88
120
|
),
|
|
121
|
+
style: {
|
|
122
|
+
// 12px clears `left-3`/`right-3`; 8px is the gap to the text.
|
|
123
|
+
...leadingWidth ? { paddingLeft: leadingWidth + 20 } : null,
|
|
124
|
+
...trailingWidth ? { paddingRight: trailingWidth + 20 } : null,
|
|
125
|
+
...props.style
|
|
126
|
+
},
|
|
89
127
|
onChange: (e) => {
|
|
90
128
|
onChange?.(e);
|
|
91
129
|
onValueChange?.(e.target.value);
|
|
@@ -114,7 +152,14 @@ var Input = react.forwardRef(
|
|
|
114
152
|
className: "absolute right-2 inline-flex items-center justify-center rounded p-1 text-zinc-400 transition-colors hover:text-zinc-600 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500/40 disabled:cursor-not-allowed disabled:opacity-50 dark:text-zinc-500 dark:hover:text-zinc-300",
|
|
115
153
|
children: shown ? /* @__PURE__ */ jsxRuntime.jsx(EyeOffIcon, {}) : /* @__PURE__ */ jsxRuntime.jsx(EyeIcon, {})
|
|
116
154
|
}
|
|
117
|
-
) : trailing && /* @__PURE__ */ jsxRuntime.jsx(
|
|
155
|
+
) : trailing && /* @__PURE__ */ jsxRuntime.jsx(
|
|
156
|
+
"span",
|
|
157
|
+
{
|
|
158
|
+
ref: trailingRef,
|
|
159
|
+
className: "pointer-events-none absolute right-3 text-zinc-400 dark:text-zinc-500",
|
|
160
|
+
children: trailing
|
|
161
|
+
}
|
|
162
|
+
)
|
|
118
163
|
] })
|
|
119
164
|
}
|
|
120
165
|
);
|
|
@@ -153,5 +198,5 @@ function EyeOffIcon() {
|
|
|
153
198
|
}
|
|
154
199
|
|
|
155
200
|
exports.Input = Input;
|
|
156
|
-
//# sourceMappingURL=chunk-
|
|
157
|
-
//# sourceMappingURL=chunk-
|
|
201
|
+
//# sourceMappingURL=chunk-LHNC42J3.cjs.map
|
|
202
|
+
//# sourceMappingURL=chunk-LHNC42J3.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/use-adornment-width.ts","../src/components/inputs/Input/Input.tsx"],"names":["useState","useCallback","useEffect","forwardRef","useId","useFieldMode","useInlineEdit","useControllableState","jsx","DisplayValue","InputWrapper","jsxs","cn","inputBaseClasses","inputSizeClasses","dirtyClasses","errorClasses","Field"],"mappings":";;;;;;;;;;;;;AA0BO,SAAS,iBAAA,GAAkE;AAChF,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAIA,eAAS,CAAC,CAAA;AACpC,EAAA,MAAM,CAAC,IAAA,EAAM,OAAO,CAAA,GAAIA,eAA6B,IAAI,CAAA;AAEzD,EAAA,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AAO,MAAA,EAAO,cAAA,EAAe,aAAY,GAAA,EAAI,aAAA,EAAc,SAAQ,cAAA,EAAe,OAAA,EAAQ,eAAY,MAAA,EACzJ,QAAA,EAAA;AAAA,oBAAAT,cAAA,CAAC,MAAA,EAAA,EAAK,GAAE,uGAAA,EAAwG,CAAA;AAAA,mCAC/G,QAAA,EAAA,EAAO,EAAA,EAAG,MAAK,EAAA,EAAG,IAAA,EAAK,GAAE,GAAA,EAAI;AAAA,GAAA,EAChC,CAAA;AAEJ;AAEA,SAAS,UAAA,GAAa;AACpB,EAAA,uCACG,KAAA,EAAA,EAAI,KAAA,EAAM,MAAK,MAAA,EAAO,IAAA,EAAK,SAAQ,WAAA,EAAY,IAAA,EAAK,QAAO,MAAA,EAAO,cAAA,EAAe,aAAY,GAAA,EAAI,aAAA,EAAc,SAAQ,cAAA,EAAe,OAAA,EAAQ,eAAY,MAAA,EACzJ,QAAA,EAAA;AAAA,oBAAAA,cAAA,CAAC,MAAA,EAAA,EAAK,GAAE,gGAAA,EAAiG,CAAA;AAAA,oBACzGA,cAAA,CAAC,MAAA,EAAA,EAAK,CAAA,EAAE,sCAAA,EAAuC,CAAA;AAAA,oBAC/CA,cAAA,CAAC,MAAA,EAAA,EAAK,CAAA,EAAE,8FAAA,EAA+F,CAAA;AAAA,oBACvGA,cAAA,CAAC,MAAA,EAAA,EAAK,CAAA,EAAE,YAAA,EAAa;AAAA,GAAA,EACvB,CAAA;AAEJ","file":"chunk-LHNC42J3.cjs","sourcesContent":["import { useCallback, useEffect, useState } from \"react\";\n\n/**\n * Measure an inline adornment so the input can reserve exactly its width.\n *\n * ## Why this exists\n *\n * `leading` / `trailing` render ABSOLUTELY over the input, so they take no\n * space in flow and the input must be padded by hand to keep text clear of\n * them. That padding used to be a fixed `pl-9` / `pr-9` — 36px, sized for a\n * single icon. Any wider adornment ran straight under the value: `leading =\n * \"https://\"` is roughly 50px, so `https://` and `fancy.app` rendered on top of\n * one another.\n *\n * A fixed padding cannot be right for arbitrary content, and these props accept\n * arbitrary content — a currency code, a unit, a protocol, a short label. So\n * the width is measured rather than assumed.\n *\n * Returns `0` until measured (and on the server), which is the signal to keep\n * the old fixed padding as a fallback: an unmeasured render is then no worse\n * than it was before, rather than unpadded.\n *\n * `ResizeObserver` rather than a one-shot read, because the width changes after\n * first paint for reasons the first paint cannot see — a webfont swapping in,\n * the adornment's own content changing, a container query resizing the text.\n */\nexport function useAdornmentWidth(): [(node: HTMLElement | null) => void, number] {\n const [width, setWidth] = useState(0);\n const [node, setNode] = useState<HTMLElement | null>(null);\n\n const ref = useCallback((n: HTMLElement | null) => setNode(n), []);\n\n useEffect(() => {\n if (!node) {\n setWidth(0);\n\n return;\n }\n\n const read = () => setWidth(node.getBoundingClientRect().width);\n read();\n\n if (typeof ResizeObserver === \"undefined\") return;\n\n const observer = new ResizeObserver(read);\n observer.observe(node);\n\n return () => observer.disconnect();\n }, [node]);\n\n return [ref, width];\n}\n","import { forwardRef, useId } from \"react\";\nimport { cn } from \"../../../utils/cn\";\nimport { useControllableState } from \"../../../hooks/use-controllable-state\";\nimport { useAdornmentWidth } from \"../../../hooks/use-adornment-width\";\nimport { Field } from \"../Field\";\nimport { InputWrapper } from \"../InputWrapper\";\nimport {\n dirtyClasses,\n errorClasses,\n inputBaseClasses,\n inputSizeClasses,\n} from \"../inputs.utils\";\nimport { useFieldMode } from \"../mode/FieldMode.context\";\nimport { DisplayValue } from \"../mode/DisplayValue\";\nimport { useInlineEdit } from \"../mode/useInlineEdit\";\nimport type { InputProps } from \"./Input.types\";\n\nexport const Input = forwardRef<HTMLInputElement, InputProps>(\n (\n {\n type = \"text\",\n size = \"md\",\n dirty,\n error,\n label,\n labelHidden,\n description,\n required,\n disabled,\n className,\n id,\n leading,\n trailing,\n prefix,\n suffix,\n prefixPosition,\n suffixPosition,\n mode,\n onValueChange,\n onChange,\n reveal,\n revealed,\n onRevealedChange,\n revealLabel = \"Show password\",\n hideLabel = \"Hide password\",\n ...props\n },\n ref,\n ) => {\n const autoId = useId();\n const inputId = id ?? autoId;\n const resolvedMode = useFieldMode(mode);\n const { showControl, interactive, enterEdit, exitEdit } = useInlineEdit(resolvedMode, disabled);\n\n // Measured, not assumed: `leading`/`trailing` take arbitrary content, and a\n // fixed padding can only ever be right for one width. See\n // `useAdornmentWidth` for what went wrong with the fixed version.\n const [leadingRef, leadingWidth] = useAdornmentWidth();\n const [trailingRef, trailingWidth] = useAdornmentWidth();\n\n // Only meaningful on a password field: a reveal on an already-visible input\n // is a button that does nothing.\n const canReveal = reveal === true && type === \"password\";\n const [isRevealed, setRevealed] = useControllableState(revealed, false, onRevealedChange);\n const shown = canReveal && isRevealed;\n // The rendered type, NOT the declared one — `type` stays \"password\" so the\n // display-mode masking below and any caller reading props are unaffected.\n const renderedType = shown ? \"text\" : type;\n\n const input = !showControl ? (\n <DisplayValue\n size={size}\n interactive={interactive}\n onActivate={enterEdit}\n leading={leading ?? prefix}\n trailing={trailing ?? suffix}\n >\n {type === \"password\" ? (props.value ? \"••••••\" : \"\") : (props.value as string | undefined)}\n </DisplayValue>\n ) : (\n <InputWrapper\n prefix={prefix}\n suffix={suffix}\n prefixPosition={prefixPosition}\n suffixPosition={suffixPosition}\n size={size}\n >\n <div data-react-fancy-input=\"\" className=\"relative flex items-center\">\n {leading && (\n <span\n ref={leadingRef}\n className=\"pointer-events-none absolute left-3 text-zinc-400 dark:text-zinc-500\"\n >\n {leading}\n </span>\n )}\n <input\n ref={ref}\n id={inputId}\n type={renderedType}\n disabled={disabled}\n required={required}\n className={cn(\n inputBaseClasses,\n inputSizeClasses[size],\n dirtyClasses(dirty),\n errorClasses(error),\n \"w-full\",\n // The fixed classes are the PRE-MEASURE fallback only. Once the\n // adornment is measured, the inline style below overrides them\n // with its real width -- a fixed 36px is correct for one icon and\n // wrong for anything wider, which is how `https://` came to\n // render on top of the value.\n leading && !leadingWidth && \"pl-9\",\n (trailing || canReveal) && !trailingWidth && \"pr-9\",\n className,\n )}\n style={{\n // 12px clears `left-3`/`right-3`; 8px is the gap to the text.\n ...(leadingWidth ? { paddingLeft: leadingWidth + 20 } : null),\n ...(trailingWidth ? { paddingRight: trailingWidth + 20 } : null),\n ...props.style,\n }}\n onChange={(e) => {\n onChange?.(e);\n onValueChange?.(e.target.value);\n }}\n {...props}\n // Inline click-to-edit: focus on entering edit, return to the display\n // (and run the host's onBlur) when focus leaves.\n autoFocus={interactive || props.autoFocus}\n onBlur={(e) => {\n props.onBlur?.(e);\n if (interactive) exitEdit();\n }}\n />\n {canReveal ? (\n <button\n type=\"button\"\n // type=\"button\" is load-bearing: the default is \"submit\", so a\n // reveal inside a login form would submit it on every click.\n id={`${inputId}-reveal`}\n data-react-fancy-reveal=\"\"\n onClick={() => setRevealed((v) => !v)}\n disabled={disabled}\n aria-controls={inputId}\n aria-pressed={shown}\n aria-label={shown ? hideLabel : revealLabel}\n title={shown ? hideLabel : revealLabel}\n // Not focusable by tab: the field and the submit button are the\n // path through a login form, and a reveal in between is a stop\n // most people do not want. Still reachable by click and by\n // screen readers.\n tabIndex={-1}\n className=\"absolute right-2 inline-flex items-center justify-center rounded p-1 text-zinc-400 transition-colors hover:text-zinc-600 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500/40 disabled:cursor-not-allowed disabled:opacity-50 dark:text-zinc-500 dark:hover:text-zinc-300\"\n >\n {shown ? <EyeOffIcon /> : <EyeIcon />}\n </button>\n ) : (\n trailing && (\n <span\n ref={trailingRef}\n className=\"pointer-events-none absolute right-3 text-zinc-400 dark:text-zinc-500\"\n >\n {trailing}\n </span>\n )\n )}\n </div>\n </InputWrapper>\n );\n\n if (label || error || description) {\n return (\n <Field\n label={label}\n labelHidden={labelHidden}\n description={description}\n error={error}\n required={required}\n htmlFor={inputId}\n size={size}\n >\n {input}\n </Field>\n );\n }\n\n return input;\n },\n);\n\nInput.displayName = \"Input\";\n\n/**\n * Inline SVGs rather than the Icon component: Input is the most-installed\n * primitive in the kit, and routing it through the icon registry would make\n * every consumer's password field depend on an icon set being configured.\n */\nfunction EyeIcon() {\n return (\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n <path d=\"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0\" />\n <circle cx=\"12\" cy=\"12\" r=\"3\" />\n </svg>\n );\n}\n\nfunction EyeOffIcon() {\n return (\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n <path d=\"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49\" />\n <path d=\"M14.084 14.158a3 3 0 0 1-4.242-4.242\" />\n <path d=\"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143\" />\n <path d=\"m2 2 20 20\" />\n </svg>\n );\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Switch } from './chunk-QJKWBU3I.js';
|
|
2
2
|
import { DatePicker } from './chunk-L2FPIFMN.js';
|
|
3
|
-
import { Input } from './chunk-
|
|
3
|
+
import { Input } from './chunk-L5KKMJ2Q.js';
|
|
4
4
|
import { Select } from './chunk-ZH3SPBVB.js';
|
|
5
5
|
import { Text } from './chunk-5RLP77KK.js';
|
|
6
6
|
import { Textarea } from './chunk-DEFGT75G.js';
|
|
@@ -1337,5 +1337,5 @@ function buildItems({
|
|
|
1337
1337
|
}
|
|
1338
1338
|
|
|
1339
1339
|
export { JSON_FIELD_TYPES, JsonEditor, applyJsonEdit, describeEdit, findJsonConflicts, getAtPath, inferType, parseKeyMap, parsePath, pathToString, resolveKeyRule, typeMatches };
|
|
1340
|
-
//# sourceMappingURL=chunk-
|
|
1341
|
-
//# sourceMappingURL=chunk-
|
|
1340
|
+
//# sourceMappingURL=chunk-ZDVVE4OV.js.map
|
|
1341
|
+
//# sourceMappingURL=chunk-ZDVVE4OV.js.map
|