@plenustech/design-system 0.2.4 → 0.2.5
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 +8 -0
- package/dist/components/actions/ButtonTile/ButtonTile.module.css.cjs +1 -1
- package/dist/components/actions/ButtonTile/ButtonTile.module.css.js +10 -10
- package/dist/components/actions/Toolbar/Toolbar.cjs +1 -1
- package/dist/components/actions/Toolbar/Toolbar.cjs.map +1 -1
- package/dist/components/actions/Toolbar/Toolbar.js +64 -53
- package/dist/components/actions/Toolbar/Toolbar.js.map +1 -1
- package/dist/components/data-display/CodeBlock/syntax.cjs +10 -3
- package/dist/components/data-display/CodeBlock/syntax.cjs.map +1 -1
- package/dist/components/data-display/CodeBlock/syntax.js +68 -48
- package/dist/components/data-display/CodeBlock/syntax.js.map +1 -1
- package/dist/components/data-display/Timeline/Timeline.cjs +1 -1
- package/dist/components/data-display/Timeline/Timeline.cjs.map +1 -1
- package/dist/components/data-display/Timeline/Timeline.js +6 -6
- package/dist/components/data-display/Timeline/Timeline.js.map +1 -1
- package/dist/components/data-display/Timeline/Timeline.module.css.cjs +1 -1
- package/dist/components/data-display/Timeline/Timeline.module.css.js +18 -16
- package/dist/components/data-display/Timeline/Timeline.module.css.js.map +1 -1
- package/dist/components/forms/Checkbox/Checkbox.module.css.cjs +1 -1
- package/dist/components/forms/Checkbox/Checkbox.module.css.js +5 -5
- package/dist/components/forms/CheckboxGroup/CheckboxGroup.module.css.cjs +1 -1
- package/dist/components/forms/CheckboxGroup/CheckboxGroup.module.css.js +1 -1
- package/dist/components/forms/Field/Field.cjs +1 -1
- package/dist/components/forms/Field/Field.cjs.map +1 -1
- package/dist/components/forms/Field/Field.js +22 -22
- package/dist/components/forms/Field/Field.js.map +1 -1
- package/dist/components/forms/Field/Field.module.css.cjs +1 -1
- package/dist/components/forms/Field/Field.module.css.js +19 -17
- package/dist/components/forms/Field/Field.module.css.js.map +1 -1
- package/dist/components/forms/InputText/InputText.cjs +1 -1
- package/dist/components/forms/InputText/InputText.cjs.map +1 -1
- package/dist/components/forms/InputText/InputText.js +24 -24
- package/dist/components/forms/InputText/InputText.js.map +1 -1
- package/dist/components/forms/InputText/InputText.module.css.cjs +1 -1
- package/dist/components/forms/InputText/InputText.module.css.js +9 -7
- package/dist/components/forms/InputText/InputText.module.css.js.map +1 -1
- package/dist/components/forms/RadioGroup/RadioGroup.module.css.cjs +1 -1
- package/dist/components/forms/RadioGroup/RadioGroup.module.css.js +4 -4
- package/dist/components/forms/Select/Select.cjs.map +1 -1
- package/dist/components/forms/Select/Select.js.map +1 -1
- package/dist/components/forms/Switch/Switch.module.css.cjs +1 -1
- package/dist/components/forms/Switch/Switch.module.css.js +6 -6
- package/dist/components/icons/suite.cjs +1 -0
- package/dist/components/icons/suite.js +10894 -0
- package/dist/components/navigation/Pagination/Pagination.cjs +1 -1
- package/dist/components/navigation/Pagination/Pagination.cjs.map +1 -1
- package/dist/components/navigation/Pagination/Pagination.js +71 -44
- package/dist/components/navigation/Pagination/Pagination.js.map +1 -1
- package/dist/components/navigation/Pagination/Pagination.module.css.cjs +1 -1
- package/dist/components/navigation/Pagination/Pagination.module.css.js +18 -14
- package/dist/components/navigation/Pagination/Pagination.module.css.js.map +1 -1
- package/dist/components/overlays/Menu/Menu.cjs +1 -1
- package/dist/components/overlays/Menu/Menu.cjs.map +1 -1
- package/dist/components/overlays/Menu/Menu.js +37 -36
- package/dist/components/overlays/Menu/Menu.js.map +1 -1
- package/dist/components/overlays/Menu/keyShortcuts.cjs +2 -0
- package/dist/components/overlays/Menu/keyShortcuts.cjs.map +1 -0
- package/dist/components/overlays/Menu/keyShortcuts.js +55 -0
- package/dist/components/overlays/Menu/keyShortcuts.js.map +1 -0
- package/dist/components/overlays/Tooltip/Tooltip.cjs +1 -1
- package/dist/components/overlays/Tooltip/Tooltip.cjs.map +1 -1
- package/dist/components/overlays/Tooltip/Tooltip.js +81 -56
- package/dist/components/overlays/Tooltip/Tooltip.js.map +1 -1
- package/dist/design-system.css +1 -1
- package/dist/icons.cjs +2 -0
- package/dist/icons.cjs.map +1 -0
- package/dist/icons.js +2054 -0
- package/dist/icons.js.map +1 -0
- package/dist/types/components/data-display/CodeBlock/syntax.d.ts +1 -1
- package/dist/types/components/data-display/Timeline/Timeline.d.ts +4 -1
- package/dist/types/components/data-display/Timeline/index.d.ts +1 -1
- package/dist/types/components/forms/Field/Field.d.ts +1 -1
- package/dist/types/components/forms/InputText/InputText.d.ts +1 -1
- package/dist/types/components/forms/Select/Select.d.ts +5 -1
- package/dist/types/components/icons/suite.d.ts +2051 -0
- package/dist/types/components/navigation/Pagination/Pagination.d.ts +13 -1
- package/dist/types/components/navigation/Pagination/index.d.ts +1 -1
- package/dist/types/components/overlays/Menu/Menu.d.ts +3 -1
- package/dist/types/components/overlays/Menu/keyShortcuts.d.ts +2 -0
- package/dist/types/components/overlays/Tooltip/Tooltip.d.ts +26 -5
- package/dist/types/icons.d.ts +6 -0
- package/dist/types/index.d.ts +2 -2
- package/package.json +8 -1
|
@@ -1,22 +1,24 @@
|
|
|
1
|
-
const
|
|
2
|
-
field:
|
|
3
|
-
hint:
|
|
4
|
-
errorMessage:
|
|
5
|
-
characterCount:
|
|
6
|
-
formValue:
|
|
7
|
-
control:
|
|
8
|
-
invalid:
|
|
9
|
-
sm: c
|
|
1
|
+
const n = "_field_1ndjk_1", _ = "_hint_1ndjk_8", o = "_errorMessage_1ndjk_9", t = "_characterCount_1ndjk_10", r = "_formValue_1ndjk_31", s = "_control_1ndjk_40", e = "_invalid_1ndjk_59", c = "_sm_1ndjk_77", a = "_lg_1ndjk_84", l = {
|
|
2
|
+
field: n,
|
|
3
|
+
hint: _,
|
|
4
|
+
errorMessage: o,
|
|
5
|
+
characterCount: t,
|
|
6
|
+
formValue: r,
|
|
7
|
+
control: s,
|
|
8
|
+
invalid: e,
|
|
9
|
+
sm: c,
|
|
10
|
+
lg: a
|
|
10
11
|
};
|
|
11
12
|
export {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
t as characterCount,
|
|
14
|
+
s as control,
|
|
15
|
+
l as default,
|
|
16
|
+
o as errorMessage,
|
|
17
|
+
n as field,
|
|
18
|
+
r as formValue,
|
|
19
|
+
_ as hint,
|
|
20
|
+
e as invalid,
|
|
21
|
+
a as lg,
|
|
20
22
|
c as sm
|
|
21
23
|
};
|
|
22
24
|
//# sourceMappingURL=Field.module.css.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Field.module.css.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Field.module.css.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),B=require("../../../hooks/useMergedRefs.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),B=require("../../../hooks/useMergedRefs.cjs"),e=require("./InputText.module.css.cjs"),F=require("../../../hooks/useCharacterCount/useCharacterCount.cjs"),S=require("../Field/Field.cjs");function w({"aria-describedby":o,"aria-invalid":f,className:m,error:p,hint:b,icon:a,id:j,label:x,maxLength:n,required:u=!1,size:i="md",showCharacterCount:h=!1,defaultValue:d,onChange:s,value:c,ref:g,...y}){const{ref:R,count:q,updateCount:C}=F.useCharacterCount(c,d),I=B.useMergedRefs(R,g);function N(t){C(t.target.value),s==null||s(t)}return r.jsx(S.Field,{"aria-describedby":o,characterCount:q,error:p,hint:b,id:j,label:x,maxLength:n,required:u,showCharacterCount:h,size:i,children:({className:t,id:T,describedBy:v,invalid:M})=>{const l=r.jsx("input",{...y,defaultValue:d,id:T,ref:I,"aria-describedby":v,"aria-invalid":M||f,className:[t,a&&e.default.withIcon,m].filter(Boolean).join(" "),maxLength:n,onChange:N,required:u,value:c});return a?r.jsxs("div",{className:[e.default.control,i==="sm"&&e.default.sm,i==="lg"&&e.default.lg].filter(Boolean).join(" "),children:[r.jsx("span",{"aria-hidden":"true",className:e.default.icon,children:a}),l]}):l}})}exports.InputText=w;
|
|
2
2
|
//# sourceMappingURL=InputText.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InputText.cjs","sources":["../../../../src/components/forms/InputText/InputText.tsx"],"sourcesContent":["import { type ChangeEvent, type ComponentPropsWithRef, type ReactNode } from 'react';\nimport { useCharacterCount } from '../../../hooks/useCharacterCount';\nimport { Field } from '../Field';\nimport { useMergedRefs } from '../../../hooks/useMergedRefs';\nimport styles from './InputText.module.css';\n\nexport type InputTextSize = 'sm' | 'md';\n\nexport interface InputTextProps extends Omit<ComponentPropsWithRef<'input'>, 'size'> {\n error?: string;\n hint?: string;\n /** Icone decorativo a frente do texto, como a lupa de uma busca. O nome do campo continua no `label`. */\n icon?: ReactNode;\n label?: string;\n size?: InputTextSize;\n showCharacterCount?: boolean;\n}\n\nexport function InputText({\n 'aria-describedby': ariaDescribedBy,\n 'aria-invalid': ariaInvalid,\n className,\n error,\n hint,\n icon,\n id: providedId,\n label,\n maxLength,\n required = false,\n size = 'md',\n showCharacterCount = false,\n defaultValue,\n onChange,\n value,\n ref,\n ...props\n}: InputTextProps) {\n const { ref: inputRef, count, updateCount } = useCharacterCount<HTMLInputElement>(value, defaultValue);\n const mergedRef = useMergedRefs(inputRef, ref);\n\n function handleChange(event: ChangeEvent<HTMLInputElement>) {\n updateCount(event.target.value);\n onChange?.(event);\n }\n\n return (\n <Field\n aria-describedby={ariaDescribedBy}\n characterCount={count}\n error={error}\n hint={hint}\n id={providedId}\n label={label}\n maxLength={maxLength}\n required={required}\n showCharacterCount={showCharacterCount}\n size={size}\n >\n {({ className: controlClassName, id, describedBy, invalid }) => {\n const input = (\n <input\n {...props}\n defaultValue={defaultValue}\n id={id}\n ref={mergedRef}\n aria-describedby={describedBy}\n aria-invalid={invalid || ariaInvalid}\n className={[controlClassName, icon && styles.withIcon, className].filter(Boolean).join(' ')}\n maxLength={maxLength}\n onChange={handleChange}\n required={required}\n value={value}\n />\n );\n\n if (!icon) {\n return input;\n }\n\n return (\n <div className={[styles.control, size === 'sm' && styles.sm].filter(Boolean).join(' ')}>\n <span aria-hidden=\"true\" className={styles.icon}>\n {icon}\n </span>\n {input}\n </div>\n );\n }}\n </Field>\n );\n}\n"],"names":["InputText","ariaDescribedBy","ariaInvalid","className","error","hint","icon","providedId","label","maxLength","required","size","showCharacterCount","defaultValue","onChange","value","ref","props","inputRef","count","updateCount","useCharacterCount","mergedRef","useMergedRefs","handleChange","event","jsx","Field","controlClassName","id","describedBy","invalid","input","styles"],"mappings":"+SAkBO,SAASA,EAAU,CACxB,mBAAoBC,EACpB,eAAgBC,EAChB,UAAAC,EACA,MAAAC,EACA,KAAAC,EACA,KAAAC,EACA,GAAIC,EACJ,MAAAC,EACA,UAAAC,EACA,SAAAC,EAAW,GACX,KAAAC,EAAO,KACP,mBAAAC,EAAqB,GACrB,aAAAC,EACA,SAAAC,EACA,MAAAC,EACA,IAAAC,EACA,GAAGC,CACL,EAAmB,CACjB,KAAM,CAAE,IAAKC,EAAU,MAAAC,EAAO,YAAAC,GAAgBC,EAAAA,kBAAoCN,EAAOF,CAAY,EAC/FS,EAAYC,EAAAA,cAAcL,EAAUF,CAAG,EAE7C,SAASQ,EAAaC,EAAsC,CAC1DL,EAAYK,EAAM,OAAO,KAAK,EAC9BX,GAAA,MAAAA,EAAWW,EACb,CAEA,OACEC,EAAAA,IAACC,EAAAA,MAAA,CACC,mBAAkB1B,EAClB,eAAgBkB,EAChB,MAAAf,EACA,KAAAC,EACA,GAAIE,EACJ,MAAAC,EACA,UAAAC,EACA,SAAAC,EACA,mBAAAE,EACA,KAAAD,EAEC,UAAC,CAAE,UAAWiB,EAAkB,GAAAC,EAAI,YAAAC,EAAa,QAAAC,KAAc,CAC9D,MAAMC,EACJN,EAAAA,IAAC,QAAA,CACE,GAAGT,EACJ,aAAAJ,EACA,GAAAgB,EACA,IAAKP,EACL,mBAAkBQ,EAClB,eAAcC,GAAW7B,EACzB,UAAW,CAAC0B,EAAkBtB,GAAQ2B,EAAAA,QAAO,SAAU9B,CAAS,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG,EAC1F,UAAAM,EACA,SAAUe,EACV,SAAAd,EACA,MAAAK,CAAA,CAAA,EAIJ,OAAKT,
|
|
1
|
+
{"version":3,"file":"InputText.cjs","sources":["../../../../src/components/forms/InputText/InputText.tsx"],"sourcesContent":["import { type ChangeEvent, type ComponentPropsWithRef, type ReactNode } from 'react';\nimport { useCharacterCount } from '../../../hooks/useCharacterCount';\nimport { Field } from '../Field';\nimport { useMergedRefs } from '../../../hooks/useMergedRefs';\nimport styles from './InputText.module.css';\n\nexport type InputTextSize = 'sm' | 'md' | 'lg';\n\nexport interface InputTextProps extends Omit<ComponentPropsWithRef<'input'>, 'size'> {\n error?: string;\n hint?: string;\n /** Icone decorativo a frente do texto, como a lupa de uma busca. O nome do campo continua no `label`. */\n icon?: ReactNode;\n label?: string;\n size?: InputTextSize;\n showCharacterCount?: boolean;\n}\n\nexport function InputText({\n 'aria-describedby': ariaDescribedBy,\n 'aria-invalid': ariaInvalid,\n className,\n error,\n hint,\n icon,\n id: providedId,\n label,\n maxLength,\n required = false,\n size = 'md',\n showCharacterCount = false,\n defaultValue,\n onChange,\n value,\n ref,\n ...props\n}: InputTextProps) {\n const { ref: inputRef, count, updateCount } = useCharacterCount<HTMLInputElement>(value, defaultValue);\n const mergedRef = useMergedRefs(inputRef, ref);\n\n function handleChange(event: ChangeEvent<HTMLInputElement>) {\n updateCount(event.target.value);\n onChange?.(event);\n }\n\n return (\n <Field\n aria-describedby={ariaDescribedBy}\n characterCount={count}\n error={error}\n hint={hint}\n id={providedId}\n label={label}\n maxLength={maxLength}\n required={required}\n showCharacterCount={showCharacterCount}\n size={size}\n >\n {({ className: controlClassName, id, describedBy, invalid }) => {\n const input = (\n <input\n {...props}\n defaultValue={defaultValue}\n id={id}\n ref={mergedRef}\n aria-describedby={describedBy}\n aria-invalid={invalid || ariaInvalid}\n className={[controlClassName, icon && styles.withIcon, className].filter(Boolean).join(' ')}\n maxLength={maxLength}\n onChange={handleChange}\n required={required}\n value={value}\n />\n );\n\n if (!icon) {\n return input;\n }\n\n return (\n <div className={[styles.control, size === 'sm' && styles.sm, size === 'lg' && styles.lg].filter(Boolean).join(' ')}>\n <span aria-hidden=\"true\" className={styles.icon}>\n {icon}\n </span>\n {input}\n </div>\n );\n }}\n </Field>\n );\n}\n"],"names":["InputText","ariaDescribedBy","ariaInvalid","className","error","hint","icon","providedId","label","maxLength","required","size","showCharacterCount","defaultValue","onChange","value","ref","props","inputRef","count","updateCount","useCharacterCount","mergedRef","useMergedRefs","handleChange","event","jsx","Field","controlClassName","id","describedBy","invalid","input","styles","jsxs"],"mappings":"+SAkBO,SAASA,EAAU,CACxB,mBAAoBC,EACpB,eAAgBC,EAChB,UAAAC,EACA,MAAAC,EACA,KAAAC,EACA,KAAAC,EACA,GAAIC,EACJ,MAAAC,EACA,UAAAC,EACA,SAAAC,EAAW,GACX,KAAAC,EAAO,KACP,mBAAAC,EAAqB,GACrB,aAAAC,EACA,SAAAC,EACA,MAAAC,EACA,IAAAC,EACA,GAAGC,CACL,EAAmB,CACjB,KAAM,CAAE,IAAKC,EAAU,MAAAC,EAAO,YAAAC,GAAgBC,EAAAA,kBAAoCN,EAAOF,CAAY,EAC/FS,EAAYC,EAAAA,cAAcL,EAAUF,CAAG,EAE7C,SAASQ,EAAaC,EAAsC,CAC1DL,EAAYK,EAAM,OAAO,KAAK,EAC9BX,GAAA,MAAAA,EAAWW,EACb,CAEA,OACEC,EAAAA,IAACC,EAAAA,MAAA,CACC,mBAAkB1B,EAClB,eAAgBkB,EAChB,MAAAf,EACA,KAAAC,EACA,GAAIE,EACJ,MAAAC,EACA,UAAAC,EACA,SAAAC,EACA,mBAAAE,EACA,KAAAD,EAEC,UAAC,CAAE,UAAWiB,EAAkB,GAAAC,EAAI,YAAAC,EAAa,QAAAC,KAAc,CAC9D,MAAMC,EACJN,EAAAA,IAAC,QAAA,CACE,GAAGT,EACJ,aAAAJ,EACA,GAAAgB,EACA,IAAKP,EACL,mBAAkBQ,EAClB,eAAcC,GAAW7B,EACzB,UAAW,CAAC0B,EAAkBtB,GAAQ2B,EAAAA,QAAO,SAAU9B,CAAS,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG,EAC1F,UAAAM,EACA,SAAUe,EACV,SAAAd,EACA,MAAAK,CAAA,CAAA,EAIJ,OAAKT,EAKH4B,EAAAA,KAAC,OAAI,UAAW,CAACD,EAAAA,QAAO,QAAStB,IAAS,MAAQsB,UAAO,GAAItB,IAAS,MAAQsB,UAAO,EAAE,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG,EAC/G,SAAA,CAAAP,MAAC,QAAK,cAAY,OAAO,UAAWO,EAAAA,QAAO,KACxC,SAAA3B,EACH,EACC0B,CAAA,EACH,EATOA,CAWX,CAAA,CAAA,CAGN"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useMergedRefs as
|
|
3
|
-
import
|
|
1
|
+
import { jsx as o, jsxs as M } from "react/jsx-runtime";
|
|
2
|
+
import { useMergedRefs as T } from "../../../hooks/useMergedRefs.js";
|
|
3
|
+
import r from "./InputText.module.css.js";
|
|
4
4
|
import { useCharacterCount as k } from "../../../hooks/useCharacterCount/useCharacterCount.js";
|
|
5
5
|
import { Field as A } from "../Field/Field.js";
|
|
6
6
|
function K({
|
|
@@ -13,51 +13,51 @@ function K({
|
|
|
13
13
|
id: h,
|
|
14
14
|
label: j,
|
|
15
15
|
maxLength: s,
|
|
16
|
-
required:
|
|
17
|
-
size:
|
|
16
|
+
required: n = !1,
|
|
17
|
+
size: t = "md",
|
|
18
18
|
showCharacterCount: y = !1,
|
|
19
19
|
defaultValue: c,
|
|
20
|
-
onChange:
|
|
20
|
+
onChange: a,
|
|
21
21
|
value: d,
|
|
22
22
|
ref: N,
|
|
23
23
|
...x
|
|
24
24
|
}) {
|
|
25
|
-
const { ref: R, count:
|
|
26
|
-
function
|
|
27
|
-
|
|
25
|
+
const { ref: R, count: g, updateCount: v } = k(d, c), B = T(R, N);
|
|
26
|
+
function C(e) {
|
|
27
|
+
v(e.target.value), a == null || a(e);
|
|
28
28
|
}
|
|
29
|
-
return /* @__PURE__ */
|
|
29
|
+
return /* @__PURE__ */ o(
|
|
30
30
|
A,
|
|
31
31
|
{
|
|
32
32
|
"aria-describedby": m,
|
|
33
|
-
characterCount:
|
|
33
|
+
characterCount: g,
|
|
34
34
|
error: p,
|
|
35
35
|
hint: b,
|
|
36
36
|
id: h,
|
|
37
37
|
label: j,
|
|
38
38
|
maxLength: s,
|
|
39
|
-
required:
|
|
39
|
+
required: n,
|
|
40
40
|
showCharacterCount: y,
|
|
41
|
-
size:
|
|
42
|
-
children: ({ className:
|
|
43
|
-
const l = /* @__PURE__ */
|
|
41
|
+
size: t,
|
|
42
|
+
children: ({ className: e, id: I, describedBy: w, invalid: F }) => {
|
|
43
|
+
const l = /* @__PURE__ */ o(
|
|
44
44
|
"input",
|
|
45
45
|
{
|
|
46
46
|
...x,
|
|
47
47
|
defaultValue: c,
|
|
48
|
-
id:
|
|
49
|
-
ref:
|
|
50
|
-
"aria-describedby":
|
|
51
|
-
"aria-invalid":
|
|
52
|
-
className: [
|
|
48
|
+
id: I,
|
|
49
|
+
ref: B,
|
|
50
|
+
"aria-describedby": w,
|
|
51
|
+
"aria-invalid": F || f,
|
|
52
|
+
className: [e, i && r.withIcon, u].filter(Boolean).join(" "),
|
|
53
53
|
maxLength: s,
|
|
54
|
-
onChange:
|
|
55
|
-
required:
|
|
54
|
+
onChange: C,
|
|
55
|
+
required: n,
|
|
56
56
|
value: d
|
|
57
57
|
}
|
|
58
58
|
);
|
|
59
|
-
return i ? /* @__PURE__ */
|
|
60
|
-
/* @__PURE__ */
|
|
59
|
+
return i ? /* @__PURE__ */ M("div", { className: [r.control, t === "sm" && r.sm, t === "lg" && r.lg].filter(Boolean).join(" "), children: [
|
|
60
|
+
/* @__PURE__ */ o("span", { "aria-hidden": "true", className: r.icon, children: i }),
|
|
61
61
|
l
|
|
62
62
|
] }) : l;
|
|
63
63
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InputText.js","sources":["../../../../src/components/forms/InputText/InputText.tsx"],"sourcesContent":["import { type ChangeEvent, type ComponentPropsWithRef, type ReactNode } from 'react';\nimport { useCharacterCount } from '../../../hooks/useCharacterCount';\nimport { Field } from '../Field';\nimport { useMergedRefs } from '../../../hooks/useMergedRefs';\nimport styles from './InputText.module.css';\n\nexport type InputTextSize = 'sm' | 'md';\n\nexport interface InputTextProps extends Omit<ComponentPropsWithRef<'input'>, 'size'> {\n error?: string;\n hint?: string;\n /** Icone decorativo a frente do texto, como a lupa de uma busca. O nome do campo continua no `label`. */\n icon?: ReactNode;\n label?: string;\n size?: InputTextSize;\n showCharacterCount?: boolean;\n}\n\nexport function InputText({\n 'aria-describedby': ariaDescribedBy,\n 'aria-invalid': ariaInvalid,\n className,\n error,\n hint,\n icon,\n id: providedId,\n label,\n maxLength,\n required = false,\n size = 'md',\n showCharacterCount = false,\n defaultValue,\n onChange,\n value,\n ref,\n ...props\n}: InputTextProps) {\n const { ref: inputRef, count, updateCount } = useCharacterCount<HTMLInputElement>(value, defaultValue);\n const mergedRef = useMergedRefs(inputRef, ref);\n\n function handleChange(event: ChangeEvent<HTMLInputElement>) {\n updateCount(event.target.value);\n onChange?.(event);\n }\n\n return (\n <Field\n aria-describedby={ariaDescribedBy}\n characterCount={count}\n error={error}\n hint={hint}\n id={providedId}\n label={label}\n maxLength={maxLength}\n required={required}\n showCharacterCount={showCharacterCount}\n size={size}\n >\n {({ className: controlClassName, id, describedBy, invalid }) => {\n const input = (\n <input\n {...props}\n defaultValue={defaultValue}\n id={id}\n ref={mergedRef}\n aria-describedby={describedBy}\n aria-invalid={invalid || ariaInvalid}\n className={[controlClassName, icon && styles.withIcon, className].filter(Boolean).join(' ')}\n maxLength={maxLength}\n onChange={handleChange}\n required={required}\n value={value}\n />\n );\n\n if (!icon) {\n return input;\n }\n\n return (\n <div className={[styles.control, size === 'sm' && styles.sm].filter(Boolean).join(' ')}>\n <span aria-hidden=\"true\" className={styles.icon}>\n {icon}\n </span>\n {input}\n </div>\n );\n }}\n </Field>\n );\n}\n"],"names":["InputText","ariaDescribedBy","ariaInvalid","className","error","hint","icon","providedId","label","maxLength","required","size","showCharacterCount","defaultValue","onChange","value","ref","props","inputRef","count","updateCount","useCharacterCount","mergedRef","useMergedRefs","handleChange","event","jsx","Field","controlClassName","id","describedBy","invalid","input","styles"],"mappings":";;;;;AAkBO,SAASA,EAAU;AAAA,EACxB,oBAAoBC;AAAA,EACpB,gBAAgBC;AAAA,EAChB,WAAAC;AAAA,EACA,OAAAC;AAAA,EACA,MAAAC;AAAA,EACA,MAAAC;AAAA,EACA,IAAIC;AAAA,EACJ,OAAAC;AAAA,EACA,WAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,MAAAC,IAAO;AAAA,EACP,oBAAAC,IAAqB;AAAA,EACrB,cAAAC;AAAA,EACA,UAAAC;AAAA,EACA,OAAAC;AAAA,EACA,KAAAC;AAAA,EACA,GAAGC;AACL,GAAmB;AACjB,QAAM,EAAE,KAAKC,GAAU,OAAAC,GAAO,aAAAC,MAAgBC,EAAoCN,GAAOF,CAAY,GAC/FS,IAAYC,EAAcL,GAAUF,CAAG;AAE7C,WAASQ,EAAaC,GAAsC;AAC1D,IAAAL,EAAYK,EAAM,OAAO,KAAK,GAC9BX,KAAA,QAAAA,EAAWW;AAAA,EACb;AAEA,SACE,gBAAAC;AAAA,IAACC;AAAA,IAAA;AAAA,MACC,oBAAkB1B;AAAA,MAClB,gBAAgBkB;AAAA,MAChB,OAAAf;AAAA,MACA,MAAAC;AAAA,MACA,IAAIE;AAAA,MACJ,OAAAC;AAAA,MACA,WAAAC;AAAA,MACA,UAAAC;AAAA,MACA,oBAAAE;AAAA,MACA,MAAAD;AAAA,MAEC,WAAC,EAAE,WAAWiB,GAAkB,IAAAC,GAAI,aAAAC,GAAa,SAAAC,QAAc;AAC9D,cAAMC,IACJ,gBAAAN;AAAA,UAAC;AAAA,UAAA;AAAA,YACE,GAAGT;AAAA,YACJ,cAAAJ;AAAA,YACA,IAAAgB;AAAA,YACA,KAAKP;AAAA,YACL,oBAAkBQ;AAAA,YAClB,gBAAcC,KAAW7B;AAAA,YACzB,WAAW,CAAC0B,GAAkBtB,KAAQ2B,EAAO,UAAU9B,CAAS,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG;AAAA,YAC1F,WAAAM;AAAA,YACA,UAAUe;AAAA,YACV,UAAAd;AAAA,YACA,OAAAK;AAAA,UAAA;AAAA,QAAA;AAIJ,eAAKT,
|
|
1
|
+
{"version":3,"file":"InputText.js","sources":["../../../../src/components/forms/InputText/InputText.tsx"],"sourcesContent":["import { type ChangeEvent, type ComponentPropsWithRef, type ReactNode } from 'react';\nimport { useCharacterCount } from '../../../hooks/useCharacterCount';\nimport { Field } from '../Field';\nimport { useMergedRefs } from '../../../hooks/useMergedRefs';\nimport styles from './InputText.module.css';\n\nexport type InputTextSize = 'sm' | 'md' | 'lg';\n\nexport interface InputTextProps extends Omit<ComponentPropsWithRef<'input'>, 'size'> {\n error?: string;\n hint?: string;\n /** Icone decorativo a frente do texto, como a lupa de uma busca. O nome do campo continua no `label`. */\n icon?: ReactNode;\n label?: string;\n size?: InputTextSize;\n showCharacterCount?: boolean;\n}\n\nexport function InputText({\n 'aria-describedby': ariaDescribedBy,\n 'aria-invalid': ariaInvalid,\n className,\n error,\n hint,\n icon,\n id: providedId,\n label,\n maxLength,\n required = false,\n size = 'md',\n showCharacterCount = false,\n defaultValue,\n onChange,\n value,\n ref,\n ...props\n}: InputTextProps) {\n const { ref: inputRef, count, updateCount } = useCharacterCount<HTMLInputElement>(value, defaultValue);\n const mergedRef = useMergedRefs(inputRef, ref);\n\n function handleChange(event: ChangeEvent<HTMLInputElement>) {\n updateCount(event.target.value);\n onChange?.(event);\n }\n\n return (\n <Field\n aria-describedby={ariaDescribedBy}\n characterCount={count}\n error={error}\n hint={hint}\n id={providedId}\n label={label}\n maxLength={maxLength}\n required={required}\n showCharacterCount={showCharacterCount}\n size={size}\n >\n {({ className: controlClassName, id, describedBy, invalid }) => {\n const input = (\n <input\n {...props}\n defaultValue={defaultValue}\n id={id}\n ref={mergedRef}\n aria-describedby={describedBy}\n aria-invalid={invalid || ariaInvalid}\n className={[controlClassName, icon && styles.withIcon, className].filter(Boolean).join(' ')}\n maxLength={maxLength}\n onChange={handleChange}\n required={required}\n value={value}\n />\n );\n\n if (!icon) {\n return input;\n }\n\n return (\n <div className={[styles.control, size === 'sm' && styles.sm, size === 'lg' && styles.lg].filter(Boolean).join(' ')}>\n <span aria-hidden=\"true\" className={styles.icon}>\n {icon}\n </span>\n {input}\n </div>\n );\n }}\n </Field>\n );\n}\n"],"names":["InputText","ariaDescribedBy","ariaInvalid","className","error","hint","icon","providedId","label","maxLength","required","size","showCharacterCount","defaultValue","onChange","value","ref","props","inputRef","count","updateCount","useCharacterCount","mergedRef","useMergedRefs","handleChange","event","jsx","Field","controlClassName","id","describedBy","invalid","input","styles","jsxs"],"mappings":";;;;;AAkBO,SAASA,EAAU;AAAA,EACxB,oBAAoBC;AAAA,EACpB,gBAAgBC;AAAA,EAChB,WAAAC;AAAA,EACA,OAAAC;AAAA,EACA,MAAAC;AAAA,EACA,MAAAC;AAAA,EACA,IAAIC;AAAA,EACJ,OAAAC;AAAA,EACA,WAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,MAAAC,IAAO;AAAA,EACP,oBAAAC,IAAqB;AAAA,EACrB,cAAAC;AAAA,EACA,UAAAC;AAAA,EACA,OAAAC;AAAA,EACA,KAAAC;AAAA,EACA,G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WX;AAAA,IAAA;AAAA,EAAA;AAGN;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const o="
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const o="_control_1pe0o_2",t="_icon_1pe0o_8",c="_withIcon_1pe0o_17",n="_sm_1pe0o_21",e="_lg_1pe0o_30",_={control:o,icon:t,withIcon:c,sm:n,lg:e};exports.control=o;exports.default=_;exports.icon=t;exports.lg=e;exports.sm=n;exports.withIcon=c;
|
|
2
2
|
//# sourceMappingURL=InputText.module.css.cjs.map
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
const
|
|
2
|
-
control:
|
|
3
|
-
icon:
|
|
1
|
+
const o = "_control_1pe0o_2", c = "_icon_1pe0o_8", n = "_withIcon_1pe0o_17", t = "_sm_1pe0o_21", _ = "_lg_1pe0o_30", s = {
|
|
2
|
+
control: o,
|
|
3
|
+
icon: c,
|
|
4
4
|
withIcon: n,
|
|
5
|
-
sm: t
|
|
5
|
+
sm: t,
|
|
6
|
+
lg: _
|
|
6
7
|
};
|
|
7
8
|
export {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
o as control,
|
|
10
|
+
s as default,
|
|
11
|
+
c as icon,
|
|
12
|
+
_ as lg,
|
|
11
13
|
t as sm,
|
|
12
14
|
n as withIcon
|
|
13
15
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InputText.module.css.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"InputText.module.css.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e="_group_1nbsm_1",r="_legend_1nbsm_11",
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e="_group_1nbsm_1",r="_legend_1nbsm_11",n="_required_1nbsm_20",o="_options_1nbsm_25",t="_control_1nbsm_31",s="_input_1nbsm_38",_="_error_1nbsm_59",i="_text_1nbsm_90",u="_hint_1nbsm_98 _hint_1ndjk_8",c="_errorMessage_1nbsm_102 _errorMessage_1ndjk_9",g={group:e,legend:r,required:n,options:o,control:t,input:s,error:_,text:i,hint:u,errorMessage:c};exports.control=t;exports.default=g;exports.error=_;exports.errorMessage=c;exports.group=e;exports.hint=u;exports.input=s;exports.legend=r;exports.options=o;exports.required=n;exports.text=i;
|
|
2
2
|
//# sourceMappingURL=RadioGroup.module.css.cjs.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const n = "_group_1nbsm_1", _ = "_legend_1nbsm_11", s = "_required_1nbsm_20", o = "_options_1nbsm_25", r = "_control_1nbsm_31", e = "_input_1nbsm_38", t = "_error_1nbsm_59", c = "_text_1nbsm_90", i = "_hint_1nbsm_98
|
|
1
|
+
const n = "_group_1nbsm_1", _ = "_legend_1nbsm_11", s = "_required_1nbsm_20", o = "_options_1nbsm_25", r = "_control_1nbsm_31", e = "_input_1nbsm_38", t = "_error_1nbsm_59", c = "_text_1nbsm_90", i = "_hint_1nbsm_98 _hint_1ndjk_8", b = "_errorMessage_1nbsm_102 _errorMessage_1ndjk_9", g = {
|
|
2
2
|
group: n,
|
|
3
3
|
legend: _,
|
|
4
4
|
required: s,
|
|
@@ -8,13 +8,13 @@ const n = "_group_1nbsm_1", _ = "_legend_1nbsm_11", s = "_required_1nbsm_20", o
|
|
|
8
8
|
error: t,
|
|
9
9
|
text: c,
|
|
10
10
|
hint: i,
|
|
11
|
-
errorMessage:
|
|
11
|
+
errorMessage: b
|
|
12
12
|
};
|
|
13
13
|
export {
|
|
14
14
|
r as control,
|
|
15
|
-
|
|
15
|
+
g as default,
|
|
16
16
|
t as error,
|
|
17
|
-
|
|
17
|
+
b as errorMessage,
|
|
18
18
|
n as group,
|
|
19
19
|
i as hint,
|
|
20
20
|
e as input,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Select.cjs","sources":["../../../../src/components/forms/Select/Select.tsx"],"sourcesContent":["import {\n useEffect,\n useId,\n useLayoutEffect,\n useRef,\n useState,\n type ComponentPropsWithRef,\n type KeyboardEvent,\n type MouseEvent,\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport { useOverlay, useOverlayPosition } from '@react-aria/overlays';\nimport { ListingOptions } from '../../data-display/List/ListingOptions';\nimport { useListing, type Listing } from '../../data-display/List/useListing';\nimport { useFormReset } from '../../../hooks/useFormReset';\nimport { useMergedRefs } from '../../../hooks/useMergedRefs';\nimport { Field } from '../Field';\nimport { FormValue } from '../Field/FormValue';\nimport styles from './Select.module.css';\nimport { IconChevronDown } from '../../icons';\n\nexport type SelectSize = 'sm' | 'md';\n\nexport interface SelectOption {\n disabled?: boolean;\n label: string;\n value: string;\n}\n\n/** As propriedades nativas vao ao gatilho, que e o controle; o `className` soma ao do sistema. */\nexport interface SelectProps\n extends Omit<ComponentPropsWithRef<'button'>, 'children' | 'defaultValue' | 'name' | 'onChange' | 'type' | 'value'> {\n defaultValue?: string;\n error?: string;\n hint?: string;\n label?: string;\n /**\n * Nome do campo no formulario. Com ele, um input oculto carrega o valor para\n * o `FormData`: sem controle nativo por baixo, o envio ignorava o campo.\n */\n name?: string;\n onValueChange?: (value: string) => void;\n options: readonly SelectOption[];\n placeholder?: string;\n required?: boolean;\n size?: SelectSize;\n value?: string;\n}\n\nexport function Select({\n 'aria-describedby': ariaDescribedBy,\n className,\n defaultValue,\n name,\n disabled = false,\n error,\n hint,\n id: providedId,\n label,\n onClick,\n onKeyDown,\n onValueChange,\n options,\n placeholder = 'Selecione',\n ref,\n required = false,\n size = 'md',\n value,\n ...props\n}: SelectProps) {\n const triggerRef = useRef<HTMLButtonElement>(null);\n const [open, setOpen] = useState(false);\n const resetRef = useFormReset<HTMLButtonElement>(() => listing.reset());\n const mergedRef = useMergedRefs(triggerRef, resetRef, ref);\n\n // O valor e a chave, e nao a opcao: com opcoes que chegam depois, filtrar por elas perdia a escolha.\n const listing = useListing({\n items: options,\n selectionMode: 'single',\n defaultValue: defaultValue === undefined ? undefined : [{ value: defaultValue, label: '' }],\n value: value === undefined ? undefined : [{ value, label: '' }],\n onSelectionChange: (chosen) => {\n const [first] = chosen;\n\n if (first) {\n onValueChange?.(first.value);\n }\n },\n });\n\n const [chosen] = listing.selected;\n\n function fechar() {\n setOpen(false);\n triggerRef.current?.focus();\n }\n\n function abrir() {\n if (disabled) {\n return;\n }\n\n listing.focus(chosen?.value ?? options.find((option) => !option.disabled)?.value);\n setOpen(true);\n }\n\n function handleTriggerKeyDown(event: KeyboardEvent<HTMLButtonElement>) {\n onKeyDown?.(event);\n\n if (['ArrowDown', 'ArrowUp', 'Enter', ' '].includes(event.key)) {\n event.preventDefault();\n abrir();\n }\n }\n\n function handleTriggerClick(event: MouseEvent<HTMLButtonElement>) {\n onClick?.(event);\n\n if (open) {\n fechar();\n } else {\n abrir();\n }\n }\n\n return (\n <Field aria-describedby={ariaDescribedBy} error={error} hint={hint} id={providedId} label={label} required={required}>\n {({ id, describedBy, invalid }) => (\n <>\n <FormValue\n disabled={disabled}\n name={name}\n onFocus={() => triggerRef.current?.focus()}\n required={required}\n value={chosen?.value ?? ''}\n />\n <button\n {...props}\n ref={mergedRef}\n className={[styles.trigger, styles[size], error && styles.error, className].filter(Boolean).join(' ')}\n type=\"button\"\n id={id}\n role=\"combobox\"\n aria-describedby={describedBy}\n aria-invalid={invalid || undefined}\n aria-haspopup=\"listbox\"\n aria-expanded={open}\n aria-required={required || undefined}\n disabled={disabled}\n onClick={handleTriggerClick}\n onKeyDown={handleTriggerKeyDown}\n >\n <span className={chosen?.label ? styles.value : styles.placeholder}>{chosen?.label || placeholder}</span>\n <IconChevronDown className={styles.chevron} size={14} />\n </button>\n {open &&\n createPortal(\n <SelectListbox\n label={label ?? placeholder}\n listing={listing}\n onClose={fechar}\n triggerRef={triggerRef}\n />,\n document.body,\n )}\n </>\n )}\n </Field>\n );\n}\n\nfunction SelectListbox({\n label,\n listing,\n onClose,\n triggerRef,\n}: {\n label: string;\n listing: Listing;\n onClose: () => void;\n triggerRef: React.RefObject<HTMLButtonElement | null>;\n}) {\n const panelRef = useRef<HTMLDivElement>(null);\n const listboxRef = useRef<HTMLElement | null>(null);\n // `Math.random` mudava entre servidor e cliente.\n const baseId = `listbox-${useId()}`;\n\n const { overlayProps } = useOverlay(\n {\n isOpen: true,\n onClose,\n isDismissable: true,\n shouldCloseOnBlur: false,\n // O gatilho nao conta como \"fora\": sem isto o ponteiro fecha o painel e o\n // clique dele reabre em seguida, e ele pisca sem abrir.\n shouldCloseOnInteractOutside: (elemento) => !triggerRef.current?.contains(elemento),\n },\n panelRef,\n );\n const { overlayProps: positionProps } = useOverlayPosition({\n targetRef: triggerRef,\n overlayRef: panelRef,\n placement: 'bottom start',\n offset: 6,\n containerPadding: 8,\n isOpen: true,\n });\n const [largura, setLargura] = useState<number>();\n // useOverlayPosition entrega toda a altura disponivel; limitamos para que\n // uma lista longa nao ocupe a tela inteira.\n const alturaMaxima = Math.min(Number(positionProps.style?.maxHeight) || 280, 280);\n\n useLayoutEffect(() => {\n setLargura(triggerRef.current?.offsetWidth);\n }, [triggerRef]);\n\n useEffect(() => {\n listboxRef.current?.focus();\n }, []);\n\n function handleKeyDown(event: KeyboardEvent<HTMLElement>) {\n if (event.key === 'Escape' || event.key === 'Tab') {\n onClose();\n return;\n }\n\n if (event.key === 'Enter' || event.key === ' ') {\n event.preventDefault();\n const alvo = listing.visible.find((option) => option.value === listing.focusedKey);\n\n if (alvo && !alvo.disabled) {\n listing.select(alvo);\n onClose();\n }\n return;\n }\n\n if (event.key.length === 1 && !event.metaKey && !event.ctrlKey) {\n listing.typeahead(event.key);\n return;\n }\n\n listing.handleKeyDown(event);\n }\n\n return (\n <div\n {...overlayProps}\n ref={panelRef}\n className={styles.panel}\n // Camada de cima: o `ariaHideOutside` do Dialog ignora quem a declara.\n data-react-aria-top-layer=\"true\"\n style={{ ...positionProps.style, width: largura, maxHeight: alturaMaxima }}\n >\n <ListingOptions\n baseId={baseId}\n elementRef={listboxRef}\n label={label}\n listing={listing}\n onKeyDown={(event) => {\n // Espalhar overlayProps antes nao basta: este onKeyDown o substituiria.\n handleKeyDown(event);\n overlayProps.onKeyDown?.(event as KeyboardEvent<HTMLDivElement>);\n }}\n onSelect={onClose}\n tabIndex={-1}\n />\n </div>\n );\n}\n"],"names":["Select","ariaDescribedBy","className","defaultValue","name","disabled","error","hint","providedId","label","onClick","onKeyDown","onValueChange","options","placeholder","ref","required","size","value","props","triggerRef","useRef","open","setOpen","useState","resetRef","useFormReset","listing","mergedRef","useMergedRefs","useListing","chosen","first","fechar","_a","abrir","option","handleTriggerKeyDown","event","handleTriggerClick","Field","id","describedBy","invalid","jsxs","Fragment","jsx","FormValue","styles","IconChevronDown","createPortal","SelectListbox","onClose","panelRef","listboxRef","baseId","useId","overlayProps","useOverlay","elemento","positionProps","useOverlayPosition","largura","setLargura","alturaMaxima","useLayoutEffect","useEffect","handleKeyDown","alvo","ListingOptions"],"mappings":"ohBAiDO,SAASA,EAAO,CACrB,mBAAoBC,EACpB,UAAAC,EACA,aAAAC,EACA,KAAAC,EACA,SAAAC,EAAW,GACX,MAAAC,EACA,KAAAC,EACA,GAAIC,EACJ,MAAAC,EACA,QAAAC,EACA,UAAAC,EACA,cAAAC,EACA,QAAAC,EACA,YAAAC,EAAc,YACd,IAAAC,EACA,SAAAC,EAAW,GACX,KAAAC,EAAO,KACP,MAAAC,EACA,GAAGC,CACL,EAAgB,CACd,MAAMC,EAAaC,EAAAA,OAA0B,IAAI,EAC3C,CAACC,EAAMC,CAAO,EAAIC,EAAAA,SAAS,EAAK,EAChCC,EAAWC,EAAAA,aAAgC,IAAMC,EAAQ,OAAO,EAChEC,EAAYC,EAAA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AYW,GAAU,OAEpB6B,EAAc7B,CAAK,GACnBJ,EAAAuB,EAAa,YAAb,MAAAvB,EAAA,KAAAuB,EAAyBnB,EAC3B,EACA,SAAUc,EACV,SAAU,EAAA,CAAA,CACZ,CAAA,CAGN"}
|
|
1
|
+
{"version":3,"file":"Select.cjs","sources":["../../../../src/components/forms/Select/Select.tsx"],"sourcesContent":["import {\n useEffect,\n useId,\n useLayoutEffect,\n useRef,\n useState,\n type ComponentPropsWithRef,\n type KeyboardEvent,\n type MouseEvent,\n type ReactNode,\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport { useOverlay, useOverlayPosition } from '@react-aria/overlays';\nimport { ListingOptions } from '../../data-display/List/ListingOptions';\nimport { useListing, type Listing } from '../../data-display/List/useListing';\nimport { useFormReset } from '../../../hooks/useFormReset';\nimport { useMergedRefs } from '../../../hooks/useMergedRefs';\nimport { Field } from '../Field';\nimport { FormValue } from '../Field/FormValue';\nimport styles from './Select.module.css';\nimport { IconChevronDown } from '../../icons';\n\nexport type SelectSize = 'sm' | 'md';\n\nexport interface SelectOption {\n /** Segunda linha da opção, na lista aberta. O nome da opção e o gatilho fechado ficam no rótulo. */\n description?: string;\n disabled?: boolean;\n /** Decorativo, à frente do rótulo, na lista aberta. */\n icon?: ReactNode;\n label: string;\n value: string;\n}\n\n/** As propriedades nativas vao ao gatilho, que e o controle; o `className` soma ao do sistema. */\nexport interface SelectProps\n extends Omit<ComponentPropsWithRef<'button'>, 'children' | 'defaultValue' | 'name' | 'onChange' | 'type' | 'value'> {\n defaultValue?: string;\n error?: string;\n hint?: string;\n label?: string;\n /**\n * Nome do campo no formulario. Com ele, um input oculto carrega o valor para\n * o `FormData`: sem controle nativo por baixo, o envio ignorava o campo.\n */\n name?: string;\n onValueChange?: (value: string) => void;\n options: readonly SelectOption[];\n placeholder?: string;\n required?: boolean;\n size?: SelectSize;\n value?: string;\n}\n\nexport function Select({\n 'aria-describedby': ariaDescribedBy,\n className,\n defaultValue,\n name,\n disabled = false,\n error,\n hint,\n id: providedId,\n label,\n onClick,\n onKeyDown,\n onValueChange,\n options,\n placeholder = 'Selecione',\n ref,\n required = false,\n size = 'md',\n value,\n ...props\n}: SelectProps) {\n const triggerRef = useRef<HTMLButtonElement>(null);\n const [open, setOpen] = useState(false);\n const resetRef = useFormReset<HTMLButtonElement>(() => listing.reset());\n const mergedRef = useMergedRefs(triggerRef, resetRef, ref);\n\n // O valor e a chave, e nao a opcao: com opcoes que chegam depois, filtrar por elas perdia a escolha.\n const listing = useListing({\n items: options,\n selectionMode: 'single',\n defaultValue: defaultValue === undefined ? undefined : [{ value: defaultValue, label: '' }],\n value: value === undefined ? undefined : [{ value, label: '' }],\n onSelectionChange: (chosen) => {\n const [first] = chosen;\n\n if (first) {\n onValueChange?.(first.value);\n }\n },\n });\n\n const [chosen] = listing.selected;\n\n function fechar() {\n setOpen(false);\n triggerRef.current?.focus();\n }\n\n function abrir() {\n if (disabled) {\n return;\n }\n\n listing.focus(chosen?.value ?? options.find((option) => !option.disabled)?.value);\n setOpen(true);\n }\n\n function handleTriggerKeyDown(event: KeyboardEvent<HTMLButtonElement>) {\n onKeyDown?.(event);\n\n if (['ArrowDown', 'ArrowUp', 'Enter', ' '].includes(event.key)) {\n event.preventDefault();\n abrir();\n }\n }\n\n function handleTriggerClick(event: MouseEvent<HTMLButtonElement>) {\n onClick?.(event);\n\n if (open) {\n fechar();\n } else {\n abrir();\n }\n }\n\n return (\n <Field aria-describedby={ariaDescribedBy} error={error} hint={hint} id={providedId} label={label} required={required}>\n {({ id, describedBy, invalid }) => (\n <>\n <FormValue\n disabled={disabled}\n name={name}\n onFocus={() => triggerRef.current?.focus()}\n required={required}\n value={chosen?.value ?? ''}\n />\n <button\n {...props}\n ref={mergedRef}\n className={[styles.trigger, styles[size], error && styles.error, className].filter(Boolean).join(' ')}\n type=\"button\"\n id={id}\n role=\"combobox\"\n aria-describedby={describedBy}\n aria-invalid={invalid || undefined}\n aria-haspopup=\"listbox\"\n aria-expanded={open}\n aria-required={required || undefined}\n disabled={disabled}\n onClick={handleTriggerClick}\n onKeyDown={handleTriggerKeyDown}\n >\n <span className={chosen?.label ? styles.value : styles.placeholder}>{chosen?.label || placeholder}</span>\n <IconChevronDown className={styles.chevron} size={14} />\n </button>\n {open &&\n createPortal(\n <SelectListbox\n label={label ?? placeholder}\n listing={listing}\n onClose={fechar}\n triggerRef={triggerRef}\n />,\n document.body,\n )}\n </>\n )}\n </Field>\n );\n}\n\nfunction SelectListbox({\n label,\n listing,\n onClose,\n triggerRef,\n}: {\n label: string;\n listing: Listing;\n onClose: () => void;\n triggerRef: React.RefObject<HTMLButtonElement | null>;\n}) {\n const panelRef = useRef<HTMLDivElement>(null);\n const listboxRef = useRef<HTMLElement | null>(null);\n // `Math.random` mudava entre servidor e cliente.\n const baseId = `listbox-${useId()}`;\n\n const { overlayProps } = useOverlay(\n {\n isOpen: true,\n onClose,\n isDismissable: true,\n shouldCloseOnBlur: false,\n // O gatilho nao conta como \"fora\": sem isto o ponteiro fecha o painel e o\n // clique dele reabre em seguida, e ele pisca sem abrir.\n shouldCloseOnInteractOutside: (elemento) => !triggerRef.current?.contains(elemento),\n },\n panelRef,\n );\n const { overlayProps: positionProps } = useOverlayPosition({\n targetRef: triggerRef,\n overlayRef: panelRef,\n placement: 'bottom start',\n offset: 6,\n containerPadding: 8,\n isOpen: true,\n });\n const [largura, setLargura] = useState<number>();\n // useOverlayPosition entrega toda a altura disponivel; limitamos para que\n // uma lista longa nao ocupe a tela inteira.\n const alturaMaxima = Math.min(Number(positionProps.style?.maxHeight) || 280, 280);\n\n useLayoutEffect(() => {\n setLargura(triggerRef.current?.offsetWidth);\n }, [triggerRef]);\n\n useEffect(() => {\n listboxRef.current?.focus();\n }, []);\n\n function handleKeyDown(event: KeyboardEvent<HTMLElement>) {\n if (event.key === 'Escape' || event.key === 'Tab') {\n onClose();\n return;\n }\n\n if (event.key === 'Enter' || event.key === ' ') {\n event.preventDefault();\n const alvo = listing.visible.find((option) => option.value === listing.focusedKey);\n\n if (alvo && !alvo.disabled) {\n listing.select(alvo);\n onClose();\n }\n return;\n }\n\n if (event.key.length === 1 && !event.metaKey && !event.ctrlKey) {\n listing.typeahead(event.key);\n return;\n }\n\n listing.handleKeyDown(event);\n }\n\n return (\n <div\n {...overlayProps}\n ref={panelRef}\n className={styles.panel}\n // Camada de cima: o `ariaHideOutside` do Dialog ignora quem a declara.\n data-react-aria-top-layer=\"true\"\n style={{ ...positionProps.style, width: largura, maxHeight: alturaMaxima }}\n >\n <ListingOptions\n baseId={baseId}\n elementRef={listboxRef}\n label={label}\n listing={listing}\n onKeyDown={(event) => {\n // Espalhar overlayProps antes nao basta: este onKeyDown o substituiria.\n handleKeyDown(event);\n overlayProps.onKeyDown?.(event as KeyboardEvent<HTMLDivElement>);\n }}\n onSelect={onClose}\n tabIndex={-1}\n />\n </div>\n );\n}\n"],"names":["Select","ariaDescribedBy","className","defaultValue","name","disabled","error","hint","providedId","label","onClick","onKeyDown","onValueChange","options","placeholder","ref","required","size","value","props","triggerRef","useRef","open","setOpen","useState","resetRef","useFormReset","listing","mergedRef","useMergedRefs","useListing","chosen","first","fechar","_a","abrir","option","handleTriggerKeyDown","event","handleTriggerClick","Field","id","describedBy","invalid","jsxs","Fragment","jsx","FormValue","styles","IconChevronDown","createPortal","SelectListbox","onClose","panelRef","listboxRef","baseId","useId","overlayProps","useOverlay","elemento","positionProps","useOverlayPosition","largura","setLargura","alturaMaxima","useLayoutEffect","useEffect","handleKeyDown","alvo","ListingOptions"],"mappings":"ohBAsDO,SAASA,EAAO,CACrB,mBAAoBC,EACpB,UAAAC,EACA,aAAAC,EACA,KAAAC,EACA,SAAAC,EAAW,GACX,MAAAC,EACA,KAAAC,EACA,GAAIC,EACJ,MAAAC,EACA,QAAAC,EACA,UAAAC,EACA,cAAAC,EACA,QAAAC,EACA,YAAAC,EAAc,YACd,IAAAC,EACA,SAAAC,EAAW,GACX,KAAAC,EAAO,KACP,MAAAC,EACA,GAAGC,CACL,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,OAC1B,MAAO,CAAE,GAAGY,EAAc,MAAO,MAAOE,EAAS,UAAWE,CAAA,EAE5D,SAAAlB,EAAAA,IAACuB,EAAAA,eAAA,CACC,OAAAd,EACA,WAAYD,EACZ,MAAA7C,EACA,QAAAkB,EACA,UAAYW,GAAU,OAEpB6B,EAAc7B,CAAK,GACnBJ,EAAAuB,EAAa,YAAb,MAAAvB,EAAA,KAAAuB,EAAyBnB,EAC3B,EACA,SAAUc,EACV,SAAU,EAAA,CAAA,CACZ,CAAA,CAGN"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Select.js","sources":["../../../../src/components/forms/Select/Select.tsx"],"sourcesContent":["import {\n useEffect,\n useId,\n useLayoutEffect,\n useRef,\n useState,\n type ComponentPropsWithRef,\n type KeyboardEvent,\n type MouseEvent,\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport { useOverlay, useOverlayPosition } from '@react-aria/overlays';\nimport { ListingOptions } from '../../data-display/List/ListingOptions';\nimport { useListing, type Listing } from '../../data-display/List/useListing';\nimport { useFormReset } from '../../../hooks/useFormReset';\nimport { useMergedRefs } from '../../../hooks/useMergedRefs';\nimport { Field } from '../Field';\nimport { FormValue } from '../Field/FormValue';\nimport styles from './Select.module.css';\nimport { IconChevronDown } from '../../icons';\n\nexport type SelectSize = 'sm' | 'md';\n\nexport interface SelectOption {\n disabled?: boolean;\n label: string;\n value: string;\n}\n\n/** As propriedades nativas vao ao gatilho, que e o controle; o `className` soma ao do sistema. */\nexport interface SelectProps\n extends Omit<ComponentPropsWithRef<'button'>, 'children' | 'defaultValue' | 'name' | 'onChange' | 'type' | 'value'> {\n defaultValue?: string;\n error?: string;\n hint?: string;\n label?: string;\n /**\n * Nome do campo no formulario. Com ele, um input oculto carrega o valor para\n * o `FormData`: sem controle nativo por baixo, o envio ignorava o campo.\n */\n name?: string;\n onValueChange?: (value: string) => void;\n options: readonly SelectOption[];\n placeholder?: string;\n required?: boolean;\n size?: SelectSize;\n value?: string;\n}\n\nexport function Select({\n 'aria-describedby': ariaDescribedBy,\n className,\n defaultValue,\n name,\n disabled = false,\n error,\n hint,\n id: providedId,\n label,\n onClick,\n onKeyDown,\n onValueChange,\n options,\n placeholder = 'Selecione',\n ref,\n required = false,\n size = 'md',\n value,\n ...props\n}: SelectProps) {\n const triggerRef = useRef<HTMLButtonElement>(null);\n const [open, setOpen] = useState(false);\n const resetRef = useFormReset<HTMLButtonElement>(() => listing.reset());\n const mergedRef = useMergedRefs(triggerRef, resetRef, ref);\n\n // O valor e a chave, e nao a opcao: com opcoes que chegam depois, filtrar por elas perdia a escolha.\n const listing = useListing({\n items: options,\n selectionMode: 'single',\n defaultValue: defaultValue === undefined ? undefined : [{ value: defaultValue, label: '' }],\n value: value === undefined ? undefined : [{ value, label: '' }],\n onSelectionChange: (chosen) => {\n const [first] = chosen;\n\n if (first) {\n onValueChange?.(first.value);\n }\n },\n });\n\n const [chosen] = listing.selected;\n\n function fechar() {\n setOpen(false);\n triggerRef.current?.focus();\n }\n\n function abrir() {\n if (disabled) {\n return;\n }\n\n listing.focus(chosen?.value ?? options.find((option) => !option.disabled)?.value);\n setOpen(true);\n }\n\n function handleTriggerKeyDown(event: KeyboardEvent<HTMLButtonElement>) {\n onKeyDown?.(event);\n\n if (['ArrowDown', 'ArrowUp', 'Enter', ' '].includes(event.key)) {\n event.preventDefault();\n abrir();\n }\n }\n\n function handleTriggerClick(event: MouseEvent<HTMLButtonElement>) {\n onClick?.(event);\n\n if (open) {\n fechar();\n } else {\n abrir();\n }\n }\n\n return (\n <Field aria-describedby={ariaDescribedBy} error={error} hint={hint} id={providedId} label={label} required={required}>\n {({ id, describedBy, invalid }) => (\n <>\n <FormValue\n disabled={disabled}\n name={name}\n onFocus={() => triggerRef.current?.focus()}\n required={required}\n value={chosen?.value ?? ''}\n />\n <button\n {...props}\n ref={mergedRef}\n className={[styles.trigger, styles[size], error && styles.error, className].filter(Boolean).join(' ')}\n type=\"button\"\n id={id}\n role=\"combobox\"\n aria-describedby={describedBy}\n aria-invalid={invalid || undefined}\n aria-haspopup=\"listbox\"\n aria-expanded={open}\n aria-required={required || undefined}\n disabled={disabled}\n onClick={handleTriggerClick}\n onKeyDown={handleTriggerKeyDown}\n >\n <span className={chosen?.label ? styles.value : styles.placeholder}>{chosen?.label || placeholder}</span>\n <IconChevronDown className={styles.chevron} size={14} />\n </button>\n {open &&\n createPortal(\n <SelectListbox\n label={label ?? placeholder}\n listing={listing}\n onClose={fechar}\n triggerRef={triggerRef}\n />,\n document.body,\n )}\n </>\n )}\n </Field>\n );\n}\n\nfunction SelectListbox({\n label,\n listing,\n onClose,\n triggerRef,\n}: {\n label: string;\n listing: Listing;\n onClose: () => void;\n triggerRef: React.RefObject<HTMLButtonElement | null>;\n}) {\n const panelRef = useRef<HTMLDivElement>(null);\n const listboxRef = useRef<HTMLElement | null>(null);\n // `Math.random` mudava entre servidor e cliente.\n const baseId = `listbox-${useId()}`;\n\n const { overlayProps } = useOverlay(\n {\n isOpen: true,\n onClose,\n isDismissable: true,\n shouldCloseOnBlur: false,\n // O gatilho nao conta como \"fora\": sem isto o ponteiro fecha o painel e o\n // clique dele reabre em seguida, e ele pisca sem abrir.\n shouldCloseOnInteractOutside: (elemento) => !triggerRef.current?.contains(elemento),\n },\n panelRef,\n );\n const { overlayProps: positionProps } = useOverlayPosition({\n targetRef: triggerRef,\n overlayRef: panelRef,\n placement: 'bottom start',\n offset: 6,\n containerPadding: 8,\n isOpen: true,\n });\n const [largura, setLargura] = useState<number>();\n // useOverlayPosition entrega toda a altura disponivel; limitamos para que\n // uma lista longa nao ocupe a tela inteira.\n const alturaMaxima = Math.min(Number(positionProps.style?.maxHeight) || 280, 280);\n\n useLayoutEffect(() => {\n setLargura(triggerRef.current?.offsetWidth);\n }, [triggerRef]);\n\n useEffect(() => {\n listboxRef.current?.focus();\n }, []);\n\n function handleKeyDown(event: KeyboardEvent<HTMLElement>) {\n if (event.key === 'Escape' || event.key === 'Tab') {\n onClose();\n return;\n }\n\n if (event.key === 'Enter' || event.key === ' ') {\n event.preventDefault();\n const alvo = listing.visible.find((option) => option.value === listing.focusedKey);\n\n if (alvo && !alvo.disabled) {\n listing.select(alvo);\n onClose();\n }\n return;\n }\n\n if (event.key.length === 1 && !event.metaKey && !event.ctrlKey) {\n listing.typeahead(event.key);\n return;\n }\n\n listing.handleKeyDown(event);\n }\n\n return (\n <div\n {...overlayProps}\n ref={panelRef}\n className={styles.panel}\n // Camada de cima: o `ariaHideOutside` do Dialog ignora quem a declara.\n data-react-aria-top-layer=\"true\"\n style={{ ...positionProps.style, width: largura, maxHeight: alturaMaxima }}\n >\n <ListingOptions\n baseId={baseId}\n elementRef={listboxRef}\n label={label}\n listing={listing}\n onKeyDown={(event) => {\n // Espalhar overlayProps antes nao basta: este onKeyDown o substituiria.\n handleKeyDown(event);\n overlayProps.onKeyDown?.(event as KeyboardEvent<HTMLDivElement>);\n }}\n onSelect={onClose}\n tabIndex={-1}\n />\n </div>\n );\n}\n"],"names":["Select","ariaDescribedBy","className","defaultValue","name","disabled","error","hint","providedId","label","onClick","onKeyDown","onValueChange","options","placeholder","ref","required","size","value","props","triggerRef","useRef","open","setOpen","useState","resetRef","useFormReset","listing","mergedRef","useMergedRefs","useListing","chosen","first","fechar","_a","abrir","option","handleTriggerKeyDown","event","handleTriggerClick","Field","id","describedBy","invalid","jsxs","Fragment","jsx","FormValue","styles","IconChevronDown","createPortal","SelectListbox","onClose","panelRef","listboxRef","baseId","useId","overlayProps","useOverlay","elemento","positionProps","useOverlayPosition","largura","setLargura","alturaMaxima","useLayoutEffect","useEffect","handleKeyDown","alvo","ListingOptions"],"mappings":";;;;;;;;;;;;AAiDO,SAASA,GAAO;AAAA,EACrB,oBAAoBC;AAAA,EACpB,WAAAC;AAAA,EACA,cAAAC;AAAA,EACA,MAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,OAAAC;AAAA,EACA,MAAAC;AAAA,EACA,IAAIC;AAAA,EACJ,OAAAC;AAAA,EACA,S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ayoutEffect,\n useRef,\n useState,\n type ComponentPropsWithRef,\n type KeyboardEvent,\n type MouseEvent,\n type ReactNode,\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport { useOverlay, useOverlayPosition } from '@react-aria/overlays';\nimport { ListingOptions } from '../../data-display/List/ListingOptions';\nimport { useListing, type Listing } from '../../data-display/List/useListing';\nimport { useFormReset } from '../../../hooks/useFormReset';\nimport { useMergedRefs } from '../../../hooks/useMergedRefs';\nimport { Field } from '../Field';\nimport { FormValue } from '../Field/FormValue';\nimport styles from './Select.module.css';\nimport { IconChevronDown } from '../../icons';\n\nexport type SelectSize = 'sm' | 'md';\n\nexport interface SelectOption {\n /** Segunda linha da opção, na lista aberta. O nome da opção e o gatilho fechado ficam no rótulo. */\n description?: string;\n disabled?: boolean;\n /** Decorativo, à frente do rótulo, na lista aberta. */\n icon?: ReactNode;\n label: string;\n value: string;\n}\n\n/** As propriedades nativas vao ao gatilho, que e o controle; o `className` soma ao do sistema. */\nexport interface SelectProps\n extends Omit<ComponentPropsWithRef<'button'>, 'children' | 'defaultValue' | 'name' | 'onChange' | 'type' | 'value'> {\n defaultValue?: string;\n error?: string;\n hint?: string;\n label?: string;\n /**\n * Nome do campo no formulario. Com ele, um input oculto carrega o valor para\n * o `FormData`: sem controle nativo por baixo, o envio ignorava o campo.\n */\n name?: string;\n onValueChange?: (value: string) => void;\n options: readonly SelectOption[];\n placeholder?: string;\n required?: boolean;\n size?: SelectSize;\n value?: string;\n}\n\nexport function Select({\n 'aria-describedby': ariaDescribedBy,\n className,\n defaultValue,\n name,\n disabled = false,\n error,\n hint,\n id: providedId,\n label,\n onClick,\n onKeyDown,\n onValueChange,\n options,\n placeholder = 'Selecione',\n ref,\n required = false,\n size = 'md',\n value,\n ...props\n}: SelectProps) {\n const triggerRef = useRef<HTMLButtonElement>(null);\n const [open, setOpen] = useState(false);\n const resetRef = useFormReset<HTMLButtonElement>(() => listing.reset());\n const mergedRef = useMergedRefs(triggerRef, resetRef, ref);\n\n // O valor e a chave, e nao a opcao: com opcoes que chegam depois, filtrar por elas perdia a escolha.\n const listing = useListing({\n items: options,\n selectionMode: 'single',\n defaultValue: defaultValue === undefined ? undefined : [{ value: defaultValue, label: '' }],\n value: value === undefined ? undefined : [{ value, label: '' }],\n onSelectionChange: (chosen) => {\n const [first] = chosen;\n\n if (first) {\n onValueChange?.(first.value);\n }\n },\n });\n\n const [chosen] = listing.selected;\n\n function fechar() {\n setOpen(false);\n triggerRef.current?.focus();\n }\n\n function abrir() {\n if (disabled) {\n return;\n }\n\n listing.focus(chosen?.value ?? options.find((option) => !option.disabled)?.value);\n setOpen(true);\n }\n\n function handleTriggerKeyDown(event: KeyboardEvent<HTMLButtonElement>) {\n onKeyDown?.(event);\n\n if (['ArrowDown', 'ArrowUp', 'Enter', ' '].includes(event.key)) {\n event.preventDefault();\n abrir();\n }\n }\n\n function handleTriggerClick(event: MouseEvent<HTMLButtonElement>) {\n onClick?.(event);\n\n if (open) {\n fechar();\n } else {\n abrir();\n }\n }\n\n return (\n <Field aria-describedby={ariaDescribedBy} error={error} hint={hint} id={providedId} label={label} required={required}>\n {({ id, describedBy, invalid }) => (\n <>\n <FormValue\n disabled={disabled}\n name={name}\n onFocus={() => triggerRef.current?.focus()}\n required={required}\n value={chosen?.value ?? ''}\n />\n <button\n {...props}\n ref={mergedRef}\n className={[styles.trigger, styles[size], error && styles.error, className].filter(Boolean).join(' ')}\n type=\"button\"\n id={id}\n role=\"combobox\"\n aria-describedby={describedBy}\n aria-invalid={invalid || undefined}\n aria-haspopup=\"listbox\"\n aria-expanded={open}\n aria-required={required || undefined}\n disabled={disabled}\n onClick={handleTriggerClick}\n onKeyDown={handleTriggerKeyDown}\n >\n <span className={chosen?.label ? styles.value : styles.placeholder}>{chosen?.label || placeholder}</span>\n <IconChevronDown className={styles.chevron} size={14} />\n </button>\n {open &&\n createPortal(\n <SelectListbox\n label={label ?? placeholder}\n listing={listing}\n onClose={fechar}\n triggerRef={triggerRef}\n />,\n document.body,\n )}\n </>\n )}\n </Field>\n );\n}\n\nfunction SelectListbox({\n label,\n listing,\n onClose,\n triggerRef,\n}: {\n label: string;\n listing: Listing;\n onClose: () => void;\n triggerRef: React.RefObject<HTMLButtonElement | null>;\n}) {\n const panelRef = useRef<HTMLDivElement>(null);\n const listboxRef = useRef<HTMLElement | null>(null);\n // `Math.random` mudava entre servidor e cliente.\n const baseId = `listbox-${useId()}`;\n\n const { overlayProps } = useOverlay(\n {\n isOpen: true,\n onClose,\n isDismissable: true,\n shouldCloseOnBlur: false,\n // O gatilho nao conta como \"fora\": sem isto o ponteiro fecha o painel e o\n // clique dele reabre em seguida, e ele pisca sem abrir.\n shouldCloseOnInteractOutside: (elemento) => !triggerRef.current?.contains(elemento),\n },\n panelRef,\n );\n const { overlayProps: positionProps } = useOverlayPosition({\n targetRef: triggerRef,\n overlayRef: panelRef,\n placement: 'bottom start',\n offset: 6,\n containerPadding: 8,\n isOpen: true,\n });\n const [largura, setLargura] = useState<number>();\n // useOverlayPosition entrega toda a altura disponivel; limitamos para que\n // uma lista longa nao ocupe a tela inteira.\n const alturaMaxima = Math.min(Number(positionProps.style?.maxHeight) || 280, 280);\n\n useLayoutEffect(() => {\n setLargura(triggerRef.current?.offsetWidth);\n }, [triggerRef]);\n\n useEffect(() => {\n listboxRef.current?.focus();\n }, []);\n\n function handleKeyDown(event: KeyboardEvent<HTMLElement>) {\n if (event.key === 'Escape' || event.key === 'Tab') {\n onClose();\n return;\n }\n\n if (event.key === 'Enter' || event.key === ' ') {\n event.preventDefault();\n const alvo = listing.visible.find((option) => option.value === listing.focusedKey);\n\n if (alvo && !alvo.disabled) {\n listing.select(alvo);\n onClose();\n }\n return;\n }\n\n if (event.key.length === 1 && !event.metaKey && !event.ctrlKey) {\n listing.typeahead(event.key);\n return;\n }\n\n listing.handleKeyDown(event);\n }\n\n return (\n <div\n {...overlayProps}\n ref={panelRef}\n className={styles.panel}\n // Camada de cima: o `ariaHideOutside` do Dialog ignora quem a declara.\n data-react-aria-top-layer=\"true\"\n style={{ ...positionProps.style, width: largura, maxHeight: alturaMaxima }}\n >\n <ListingOptions\n baseId={baseId}\n elementRef={listboxRef}\n label={label}\n listing={listing}\n onKeyDown={(event) => {\n // Espalhar overlayProps antes nao basta: este onKeyDown o substituiria.\n handleKeyDown(event);\n overlayProps.onKeyDown?.(event as KeyboardEvent<HTMLDivElement>);\n }}\n onSelect={onClose}\n tabIndex={-1}\n />\n </div>\n );\n}\n"],"names":["Select","ariaDescribedBy","className","defaultValue","name","disabled","error","hint","providedId","label","onClick","onKeyDown","onValueChange","options","placeholder","ref","required","size","value","props","triggerRef","useRef","open","setOpen","useState","resetRef","useFormReset","listing","mergedRef","useMergedRefs","useListing","chosen","first","fechar","_a","abrir","option","handleTriggerKeyDown","event","handleTriggerClick","Field","id","describedBy","invalid","jsxs","Fragment","jsx","FormValue","styles","IconChevronDown","createPortal","SelectListbox","onClose","panelRef","listboxRef","baseId","useId","overlayProps","useOverlay","elemento","positionProps","useOverlayPosition","largura","setLargura","alturaMaxima","useLayoutEffect","useEffect","handleKeyDown","alvo","ListingOptions"],"mappings":";;;;;;;;;;;;AAsDO,SAASA,GAAO;AAAA,EACrB,oBAAoBC;AAAA,EACpB,WAAAC;AAAA,EACA,cAAAC;AAAA,EACA,MAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,OAAAC;AAAA,EACA,MAAAC;AAAA,EACA,IAAIC;AAAA,EACJ,OAAAC;AAAA,EACA,SAAAC;AAAA,EACA,WAAAC;AAAA,EACA,eAAAC;AAAA,EACA,SAAAC;AAAA,EACA,aAAAC,IAAc;AAAA,EACd,KAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,MAAAC,IAAO;AAAA,EACP,OAAAC;AAAA,EACA,GAAGC;AACL,GAAgB;AACd,QAAMC,IAAaC,EAA0B,IAAI,GAC3C,CAACC,GAAMC,CAAO,IAAIC,EAAS,EAAK,GAChCC,IAAWC,EAAgC,MAAMC,EAAQ,OAAO,GA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C,KAAQ,CAACA,EAAK,aAChBzC,EAAQ,OAAOyC,CAAI,GACnBhB,EAAA;AAEF;AAAA,IACF;AAEA,QAAId,EAAM,IAAI,WAAW,KAAK,CAACA,EAAM,WAAW,CAACA,EAAM,SAAS;AAC9D,MAAAX,EAAQ,UAAUW,EAAM,GAAG;AAC3B;AAAA,IACF;AAEA,IAAAX,EAAQ,cAAcW,CAAK;AAAA,EAC7B;AAEA,SACE,gBAAAQ;AAAA,IAAC;AAAA,IAAA;AAAA,MACE,GAAGW;AAAA,MACJ,KAAKJ;AAAA,MACL,WAAWL,EAAO;AAAA,MAElB,6BAA0B;AAAA,MAC1B,OAAO,EAAE,GAAGY,EAAc,OAAO,OAAOE,GAAS,WAAWE,EAAA;AAAA,MAE5D,UAAA,gBAAAlB;AAAA,QAACuB;AAAA,QAAA;AAAA,UACC,QAAAd;AAAA,UACA,YAAYD;AAAA,UACZ,OAAA7C;AAAA,UACA,SAAAkB;AAAA,UACA,WAAW,CAACW,MAAU;;AAEpB,YAAA6B,EAAc7B,CAAK,IACnBJ,IAAAuB,EAAa,cAAb,QAAAvB,EAAA,KAAAuB,GAAyBnB;AAAA,UAC3B;AAAA,UACA,UAAUc;AAAA,UACV,UAAU;AAAA,QAAA;AAAA,MAAA;AAAA,IACZ;AAAA,EAAA;AAGN;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r="_field_1g7qr_1",e="_control_1g7qr_8",t="_input_1g7qr_15",o="_error_1g7qr_56",_="_text_1g7qr_79",
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r="_field_1g7qr_1",e="_control_1g7qr_8",t="_input_1g7qr_15",o="_error_1g7qr_56",_="_text_1g7qr_79",n="_hint_1g7qr_87 _hint_1ndjk_8",s="_errorMessage_1g7qr_91 _errorMessage_1ndjk_9",i={field:r,control:e,input:t,error:o,text:_,hint:n,errorMessage:s};exports.control=e;exports.default=i;exports.error=o;exports.errorMessage=s;exports.field=r;exports.hint=n;exports.input=t;exports.text=_;
|
|
2
2
|
//# sourceMappingURL=Switch.module.css.cjs.map
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
const r = "_field_1g7qr_1", t = "_control_1g7qr_8", _ = "_input_1g7qr_15", e = "_error_1g7qr_56", o = "_text_1g7qr_79",
|
|
1
|
+
const r = "_field_1g7qr_1", t = "_control_1g7qr_8", _ = "_input_1g7qr_15", e = "_error_1g7qr_56", o = "_text_1g7qr_79", n = "_hint_1g7qr_87 _hint_1ndjk_8", s = "_errorMessage_1g7qr_91 _errorMessage_1ndjk_9", c = {
|
|
2
2
|
field: r,
|
|
3
3
|
control: t,
|
|
4
4
|
input: _,
|
|
5
5
|
error: e,
|
|
6
6
|
text: o,
|
|
7
|
-
hint:
|
|
8
|
-
errorMessage:
|
|
7
|
+
hint: n,
|
|
8
|
+
errorMessage: s
|
|
9
9
|
};
|
|
10
10
|
export {
|
|
11
11
|
t as control,
|
|
12
|
-
|
|
12
|
+
c as default,
|
|
13
13
|
e as error,
|
|
14
|
-
|
|
14
|
+
s as errorMessage,
|
|
15
15
|
r as field,
|
|
16
|
-
|
|
16
|
+
n as hint,
|
|
17
17
|
_ as input,
|
|
18
18
|
o as text
|
|
19
19
|
};
|