@tedi-design-system/react 17.2.0-rc.1 → 18.0.0-rc.2
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/_virtual/index.cjs10.js +1 -1
- package/_virtual/index.cjs11.js +1 -1
- package/_virtual/index.cjs12.js +1 -1
- package/_virtual/index.cjs13.js +1 -1
- package/_virtual/index.cjs5.js +1 -1
- package/_virtual/index.cjs6.js +1 -1
- package/_virtual/index.cjs7.js +1 -1
- package/_virtual/index.cjs8.js +1 -1
- package/_virtual/index.cjs9.js +1 -1
- package/_virtual/index.es10.js +1 -1
- package/_virtual/index.es11.js +1 -1
- package/_virtual/index.es12.js +1 -1
- package/_virtual/index.es13.js +4 -2
- package/_virtual/index.es14.js +2 -2
- package/_virtual/index.es5.js +2 -4
- package/_virtual/index.es6.js +1 -1
- package/_virtual/index.es7.js +1 -1
- package/_virtual/index.es8.js +1 -1
- package/_virtual/index.es9.js +1 -1
- package/bundle-stats.html +1 -1
- package/external/@mui/system/colorManipulator.cjs.js +1 -1
- package/external/@mui/system/colorManipulator.es.js +2 -2
- package/external/@mui/system/createStyled.cjs.js +1 -1
- package/external/@mui/system/createStyled.es.js +6 -6
- package/external/@mui/system/useThemeWithoutDefault.cjs.js +1 -1
- package/external/@mui/system/useThemeWithoutDefault.es.js +1 -1
- package/external/react-is/index.cjs.js +1 -1
- package/external/react-is/index.es.js +1 -1
- package/external/toposort/index.cjs.js +1 -1
- package/external/toposort/index.es.js +1 -1
- package/index.css +1 -1
- package/package.json +1 -1
- package/src/tedi/components/buttons/collapse/collapse.cjs.js +1 -1
- package/src/tedi/components/buttons/collapse/collapse.d.ts +8 -0
- package/src/tedi/components/buttons/collapse/collapse.es.js +48 -46
- package/src/tedi/components/buttons/collapse/collapse.module.scss.cjs.js +1 -1
- package/src/tedi/components/buttons/collapse/collapse.module.scss.es.js +2 -1
- package/src/tedi/components/form/number-field/number-field.cjs.js +1 -1
- package/src/tedi/components/form/number-field/number-field.d.ts +16 -3
- package/src/tedi/components/form/number-field/number-field.es.js +121 -97
- package/src/tedi/providers/label-provider/label-provider.d.ts +5 -0
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("react/jsx-runtime"),
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("react/jsx-runtime"),n=require("../../../../../external/classnames/index.cjs.js"),_=require("react"),F=require("../../../../../external/react-animate-height/dist/esm/index.cjs.js"),G=require("../../../providers/printing-provider/printing-provider.cjs.js"),H=require("../../base/icon/icon.cjs.js"),J=require("../../base/typography/text/text.cjs.js"),Q=require("../../misc/print/print.cjs.js"),e=require("./collapse.module.scss.cjs.js"),U=require("../../../helpers/hooks/use-breakpoint-props.cjs.js"),V=require("../../../providers/label-provider/use-labels.cjs.js"),C=require("../../layout/grid/row.cjs.js"),o=require("../../layout/grid/col.cjs.js"),I=x=>{const{getCurrentBreakpointProps:N}=U.useBreakpointProps(x.defaultServerBreakpoint),{getLabel:h}=V.useLabels(),{id:r,children:w,className:P,openText:j=h("open"),closeText:g=h("close"),hideCollapseText:k=!1,title:d,titleRowProps:O,defaultOpen:$,open:c,onToggle:u,arrowType:s="default",size:i="default",underline:S=!0,toggleLabel:y,iconOnly:B=!1,inverted:M=!1,...R}=N(x),p=`${r}__trigger`,f=`${r}__content`,T=`${r}__animate`,[b,L]=_.useState(()=>$),m=G.usePrint(),a=_.useMemo(()=>m||(c!==void 0?c:b),[m,c,b]),D=B===!0&&!d,z=M&&s!=="secondary",E=n.default(e.default["tedi-collapse"],i==="small"&&e.default["tedi-collapse--small"],a&&e.default["tedi-collapse--is-open"],D&&e.default["tedi-collapse--icon-only"],z&&e.default["tedi-collapse--inverted"],e.default[`tedi-collapse--arrow-${s}`],P),v=()=>{const l=!a;L(l),u==null||u(l)},K=l=>{(l.key==="Enter"||l.key===" ")&&!l.repeat&&(l.preventDefault(),v())},A=y||(a?g:j),q=_.useMemo(()=>t.jsx("div",{id:f,role:"region","aria-labelledby":p,className:e.default["tedi-collapse__content"],children:w}),[w,f,p]);return t.jsxs("div",{"data-name":"collapse",...R,className:E,children:[t.jsx("button",{id:p,type:"button","data-name":"collapse-trigger",className:e.default["tedi-collapse__title"],"aria-label":A,"aria-expanded":a,"aria-controls":f,onKeyDown:K,onClick:v,children:t.jsxs(C.Row,{justifyContent:"between",alignItems:"center",wrap:"nowrap",...O,element:"span",children:[d&&t.jsx(o.Col,{"aria-hidden":"true",children:d}),t.jsx(o.Col,{width:"auto",children:t.jsxs(C.Row,{element:"span",alignItems:"center",gutter:0,wrap:"nowrap",children:[t.jsx(Q.Print,{visibility:"hide",children:t.jsx(o.Col,{width:"auto",className:n.default({"visually-hidden":k}),children:t.jsx(J.Text,{element:"span",className:n.default(e.default["tedi-collapse__text"],{[e.default["tedi-collapse__text--underline"]]:S}),children:a?g:j})})}),t.jsx(o.Col,{width:"auto",children:t.jsx("div",{className:n.default(e.default["tedi-collapse__icon-wrapper"],e.default[`tedi-collapse__icon-wrapper--${s}`],i==="small"&&e.default["tedi-collapse__icon-wrapper--small"]),children:t.jsx(H.Icon,{className:n.default(e.default["tedi-collapse__icon"],e.default[`tedi-collapse__icon--${s}`],i==="small"&&e.default["tedi-collapse__icon--small"]),name:"expand_more",size:i==="small"||s==="secondary"?18:24})})})]})})]})}),m?q:t.jsx(F.default,{id:T,duration:300,height:a?"auto":0,"data-testid":"collapse-inner",children:q})]})};exports.Collapse=I;exports.default=I;
|
|
@@ -40,6 +40,14 @@ type CollapseBreakpointProps = {
|
|
|
40
40
|
* @default false
|
|
41
41
|
*/
|
|
42
42
|
iconOnly?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Inverted color palette — flips the link / icon colors to their
|
|
45
|
+
* inverted-surface equivalents (white text + icon), for use on top of dark
|
|
46
|
+
* backgrounds. Pairs with both the with-text and icon-only variants; the
|
|
47
|
+
* secondary-arrow style has no inverted form in the design.
|
|
48
|
+
* @default false
|
|
49
|
+
*/
|
|
50
|
+
inverted?: boolean;
|
|
43
51
|
};
|
|
44
52
|
export interface CollapseProps extends BreakpointSupport<CollapseBreakpointProps> {
|
|
45
53
|
/**
|
|
@@ -1,55 +1,57 @@
|
|
|
1
|
-
import { jsx as t, jsxs as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import { usePrint as
|
|
6
|
-
import { Icon as
|
|
7
|
-
import { Text as
|
|
8
|
-
import { Print as
|
|
1
|
+
import { jsx as t, jsxs as f } from "react/jsx-runtime";
|
|
2
|
+
import n from "../../../../../external/classnames/index.es.js";
|
|
3
|
+
import h from "react";
|
|
4
|
+
import q from "../../../../../external/react-animate-height/dist/esm/index.es.js";
|
|
5
|
+
import { usePrint as F } from "../../../providers/printing-provider/printing-provider.es.js";
|
|
6
|
+
import { Icon as G } from "../../base/icon/icon.es.js";
|
|
7
|
+
import { Text as J } from "../../base/typography/text/text.es.js";
|
|
8
|
+
import { Print as Q } from "../../misc/print/print.es.js";
|
|
9
9
|
import e from "./collapse.module.scss.es.js";
|
|
10
|
-
import { useBreakpointProps as
|
|
11
|
-
import { useLabels as
|
|
10
|
+
import { useBreakpointProps as U } from "../../../helpers/hooks/use-breakpoint-props.es.js";
|
|
11
|
+
import { useLabels as V } from "../../../providers/label-provider/use-labels.es.js";
|
|
12
12
|
import { Row as k } from "../../layout/grid/row.es.js";
|
|
13
13
|
import { Col as s } from "../../layout/grid/col.es.js";
|
|
14
|
-
const
|
|
15
|
-
const { getCurrentBreakpointProps: O } =
|
|
14
|
+
const ce = (w) => {
|
|
15
|
+
const { getCurrentBreakpointProps: O } = U(w.defaultServerBreakpoint), { getLabel: y } = V(), {
|
|
16
16
|
id: r,
|
|
17
17
|
children: g,
|
|
18
18
|
className: P,
|
|
19
19
|
openText: b = y("open"),
|
|
20
|
-
closeText:
|
|
20
|
+
closeText: v = y("close"),
|
|
21
21
|
hideCollapseText: $ = !1,
|
|
22
22
|
title: c,
|
|
23
23
|
titleRowProps: B,
|
|
24
24
|
defaultOpen: S,
|
|
25
25
|
open: d,
|
|
26
26
|
onToggle: p,
|
|
27
|
-
arrowType:
|
|
27
|
+
arrowType: o = "default",
|
|
28
28
|
size: i = "default",
|
|
29
29
|
underline: T = !0,
|
|
30
|
-
toggleLabel:
|
|
30
|
+
toggleLabel: x,
|
|
31
31
|
iconOnly: j = !1,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
inverted: D = !1,
|
|
33
|
+
...L
|
|
34
|
+
} = O(w), m = `${r}__trigger`, u = `${r}__content`, M = `${r}__animate`, [N, R] = h.useState(() => S), _ = F(), a = h.useMemo(
|
|
35
|
+
() => _ || (d !== void 0 ? d : N),
|
|
36
|
+
[_, d, N]
|
|
37
|
+
), z = j === !0 && !c, E = D && o !== "secondary", K = n(
|
|
37
38
|
e["tedi-collapse"],
|
|
38
39
|
i === "small" && e["tedi-collapse--small"],
|
|
39
40
|
a && e["tedi-collapse--is-open"],
|
|
40
|
-
|
|
41
|
-
e[
|
|
41
|
+
z && e["tedi-collapse--icon-only"],
|
|
42
|
+
E && e["tedi-collapse--inverted"],
|
|
43
|
+
e[`tedi-collapse--arrow-${o}`],
|
|
42
44
|
P
|
|
43
|
-
),
|
|
45
|
+
), C = () => {
|
|
44
46
|
const l = !a;
|
|
45
|
-
|
|
46
|
-
},
|
|
47
|
-
(l.key === "Enter" || l.key === " ") && !l.repeat && (l.preventDefault(),
|
|
48
|
-
},
|
|
47
|
+
R(l), p == null || p(l);
|
|
48
|
+
}, A = (l) => {
|
|
49
|
+
(l.key === "Enter" || l.key === " ") && !l.repeat && (l.preventDefault(), C());
|
|
50
|
+
}, H = x || (a ? v : b), I = h.useMemo(
|
|
49
51
|
() => /* @__PURE__ */ t("div", { id: u, role: "region", "aria-labelledby": m, className: e["tedi-collapse__content"], children: g }),
|
|
50
52
|
[g, u, m]
|
|
51
53
|
);
|
|
52
|
-
return /* @__PURE__ */
|
|
54
|
+
return /* @__PURE__ */ f("div", { "data-name": "collapse", ...L, className: K, children: [
|
|
53
55
|
/* @__PURE__ */ t(
|
|
54
56
|
"button",
|
|
55
57
|
{
|
|
@@ -57,42 +59,42 @@ const se = (w) => {
|
|
|
57
59
|
type: "button",
|
|
58
60
|
"data-name": "collapse-trigger",
|
|
59
61
|
className: e["tedi-collapse__title"],
|
|
60
|
-
"aria-label":
|
|
62
|
+
"aria-label": H,
|
|
61
63
|
"aria-expanded": a,
|
|
62
64
|
"aria-controls": u,
|
|
63
|
-
onKeyDown:
|
|
64
|
-
onClick:
|
|
65
|
-
children: /* @__PURE__ */
|
|
65
|
+
onKeyDown: A,
|
|
66
|
+
onClick: C,
|
|
67
|
+
children: /* @__PURE__ */ f(k, { justifyContent: "between", alignItems: "center", wrap: "nowrap", ...B, element: "span", children: [
|
|
66
68
|
c && /* @__PURE__ */ t(s, { "aria-hidden": "true", children: c }),
|
|
67
|
-
/* @__PURE__ */ t(s, { width: "auto", children: /* @__PURE__ */
|
|
68
|
-
/* @__PURE__ */ t(
|
|
69
|
-
|
|
69
|
+
/* @__PURE__ */ t(s, { width: "auto", children: /* @__PURE__ */ f(k, { element: "span", alignItems: "center", gutter: 0, wrap: "nowrap", children: [
|
|
70
|
+
/* @__PURE__ */ t(Q, { visibility: "hide", children: /* @__PURE__ */ t(s, { width: "auto", className: n({ "visually-hidden": $ }), children: /* @__PURE__ */ t(
|
|
71
|
+
J,
|
|
70
72
|
{
|
|
71
73
|
element: "span",
|
|
72
|
-
className:
|
|
74
|
+
className: n(e["tedi-collapse__text"], {
|
|
73
75
|
[e["tedi-collapse__text--underline"]]: T
|
|
74
76
|
}),
|
|
75
|
-
children: a ?
|
|
77
|
+
children: a ? v : b
|
|
76
78
|
}
|
|
77
79
|
) }) }),
|
|
78
80
|
/* @__PURE__ */ t(s, { width: "auto", children: /* @__PURE__ */ t(
|
|
79
81
|
"div",
|
|
80
82
|
{
|
|
81
|
-
className:
|
|
83
|
+
className: n(
|
|
82
84
|
e["tedi-collapse__icon-wrapper"],
|
|
83
|
-
e[`tedi-collapse__icon-wrapper--${
|
|
85
|
+
e[`tedi-collapse__icon-wrapper--${o}`],
|
|
84
86
|
i === "small" && e["tedi-collapse__icon-wrapper--small"]
|
|
85
87
|
),
|
|
86
88
|
children: /* @__PURE__ */ t(
|
|
87
|
-
|
|
89
|
+
G,
|
|
88
90
|
{
|
|
89
|
-
className:
|
|
91
|
+
className: n(
|
|
90
92
|
e["tedi-collapse__icon"],
|
|
91
|
-
e[`tedi-collapse__icon--${
|
|
93
|
+
e[`tedi-collapse__icon--${o}`],
|
|
92
94
|
i === "small" && e["tedi-collapse__icon--small"]
|
|
93
95
|
),
|
|
94
96
|
name: "expand_more",
|
|
95
|
-
size: i === "small" ||
|
|
97
|
+
size: i === "small" || o === "secondary" ? 18 : 24
|
|
96
98
|
}
|
|
97
99
|
)
|
|
98
100
|
}
|
|
@@ -101,10 +103,10 @@ const se = (w) => {
|
|
|
101
103
|
] })
|
|
102
104
|
}
|
|
103
105
|
),
|
|
104
|
-
_ ? I : /* @__PURE__ */ t(
|
|
106
|
+
_ ? I : /* @__PURE__ */ t(q, { id: M, duration: 300, height: a ? "auto" : 0, "data-testid": "collapse-inner", children: I })
|
|
105
107
|
] });
|
|
106
108
|
};
|
|
107
109
|
export {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
+
ce as Collapse,
|
|
111
|
+
ce as default
|
|
110
112
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e={"tedi-collapse__title":"tedi-collapse__title-3e140e5c","tedi-collapse__text":"tedi-collapse__text-d150fea1","tedi-collapse__text--underline":"tedi-collapse__text--underline-73ca86bd","tedi-collapse__icon-wrapper":"tedi-collapse__icon-wrapper-d2b036ea","tedi-collapse__icon":"tedi-collapse__icon-5156e480","tedi-collapse__icon-wrapper--secondary":"tedi-collapse__icon-wrapper--secondary-3321348a","tedi-collapse__icon--secondary":"tedi-collapse__icon--secondary-f0f3125f","tedi-collapse__icon--default":"tedi-collapse__icon--default-9c7e19e4","tedi-collapse__icon-wrapper--default":"tedi-collapse__icon-wrapper--default-450808b2","tedi-collapse__icon-wrapper--small":"tedi-collapse__icon-wrapper--small-65e6d09a","tedi-collapse--icon-only":"tedi-collapse--icon-only-335962f8","tedi-collapse__content":"tedi-collapse__content-350b91f8","tedi-collapse--is-open":"tedi-collapse--is-open-b34b11c3"};exports.default=e;
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e={"tedi-collapse__title":"tedi-collapse__title-3e140e5c","tedi-collapse__text":"tedi-collapse__text-d150fea1","tedi-collapse__text--underline":"tedi-collapse__text--underline-73ca86bd","tedi-collapse__icon-wrapper":"tedi-collapse__icon-wrapper-d2b036ea","tedi-collapse__icon":"tedi-collapse__icon-5156e480","tedi-collapse__icon-wrapper--secondary":"tedi-collapse__icon-wrapper--secondary-3321348a","tedi-collapse__icon--secondary":"tedi-collapse__icon--secondary-f0f3125f","tedi-collapse__icon--default":"tedi-collapse__icon--default-9c7e19e4","tedi-collapse__icon-wrapper--default":"tedi-collapse__icon-wrapper--default-450808b2","tedi-collapse__icon-wrapper--small":"tedi-collapse__icon-wrapper--small-65e6d09a","tedi-collapse--icon-only":"tedi-collapse--icon-only-335962f8","tedi-collapse__content":"tedi-collapse__content-350b91f8","tedi-collapse--is-open":"tedi-collapse--is-open-b34b11c3","tedi-collapse--inverted":"tedi-collapse--inverted-bd2d0e21"};exports.default=e;
|
|
@@ -11,7 +11,8 @@ const e = {
|
|
|
11
11
|
"tedi-collapse__icon-wrapper--small": "tedi-collapse__icon-wrapper--small-65e6d09a",
|
|
12
12
|
"tedi-collapse--icon-only": "tedi-collapse--icon-only-335962f8",
|
|
13
13
|
"tedi-collapse__content": "tedi-collapse__content-350b91f8",
|
|
14
|
-
"tedi-collapse--is-open": "tedi-collapse--is-open-b34b11c3"
|
|
14
|
+
"tedi-collapse--is-open": "tedi-collapse--is-open-b34b11c3",
|
|
15
|
+
"tedi-collapse--inverted": "tedi-collapse--inverted-bd2d0e21"
|
|
15
16
|
};
|
|
16
17
|
export {
|
|
17
18
|
e as default
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("react/jsx-runtime"),B=require("../../../../../external/classnames/index.cjs.js"),u=require("react"),le=require("../../base/typography/text/text.cjs.js"),re=require("../../buttons/button/button.cjs.js"),se=require("../feedback-text/feedback-text.cjs.js"),ue=require("../form-label/form-label.cjs.js"),n=require("./number-field.module.scss.cjs.js"),de=require("../../../helpers/hooks/use-breakpoint-props.cjs.js"),oe=require("../../../providers/label-provider/use-labels.cjs.js"),S=L=>{const{getCurrentBreakpointProps:C}=de.useBreakpointProps(L.defaultServerBreakpoint),{getLabel:T,locale:D}=oe.useLabels(),W=D==="en"?".":",",{id:N,label:A,hideLabel:G,required:V,className:g,size:y,inputMode:H,decimalPlaces:p,decimalSeparator:F=W,min:d,max:o,step:I=1,defaultValue:w,value:c,onChange:a,suffix:h,fullWidth:J=!1,disabled:b=!1,invalid:k=!1,helper:i,input:v}=C(L),K=H??(p&&p>0||F===","?"decimal":"numeric"),m=u.useCallback(e=>e===void 0?"":F===","?String(e).replace(".",","):String(e),[F]),x=u.useRef(null),q=u.useRef(!1),[E,O]=u.useState(""),[Q,M]=u.useState(w),[X,_]=u.useState(()=>m(c??w)),l=a&&typeof c<"u"?c:Q;u.useEffect(()=>{!q.current&&typeof c<"u"&&_(m(c))},[c,m]);const P=i?`${N}-helper`:void 0,U=u.useCallback(e=>{if(e===void 0)return k||(i==null?void 0:i.type)==="error";const t=d!==void 0&&e<d,s=o!==void 0&&e>o;return k||t||s||(i==null?void 0:i.type)==="error"},[k,i,o,d]),R=e=>Math.min(o??1/0,Math.max(d??-1/0,e)),Y=e=>{const t=T("numberField.quantityUpdated",e);O(t),setTimeout(()=>{O("")},5e3)},$=e=>p!==void 0?parseFloat(e.toFixed(p)):e,Z=e=>{let t=l??0;e==="increment"&&(t=t+I),e==="decrement"&&(t=t-I),t=R(t),t=$(t),Y(t),a==null||a(t),M(t),_(m(t))},ee=({currentTarget:{value:e}})=>{if(_(e),e===""){l!==void 0&&(a==null||a(void 0),M(void 0));return}const t=e.replace(",",".");if(!/^-?(\d+(\.\d*)?|\.\d+)$/.test(t))return;const s=parseFloat(t);if(Number.isNaN(s))return;const f=R(s),j=$(f);j!==l&&(a==null||a(j),M(j))},te=()=>{q.current=!0},ne=()=>{q.current=!1,_(m(l))},z=e=>{const t=l!==void 0&&(e==="increment"?o!==void 0&&l>=o:d!==void 0&&l<=d),s=B.default(n.default["tedi-number-field__button"],n.default[`tedi-number-field__button--${e}`],{[n.default["tedi-number-field__button--disabled"]]:t||b}),f=T(`numberField.${e}`,I);return r.jsx(re.Button,{"aria-label":f,onClick:()=>Z(e),disabled:t||b,visualType:"secondary",className:s,icon:{name:e==="increment"?"add":"remove"},size:y==="small"?"small":void 0,children:e==="increment"?"+":"-"})},ae=()=>{const e=B.default(n.default["tedi-number-field__input-wrapper"],{[n.default["tedi-number-field__input-wrapper--with-suffix"]]:h,[n.default["tedi-number-field__input-wrapper--full-width"]]:J}),t=B.default(n.default["tedi-number-field__input"],v==null?void 0:v.className),s=()=>{var f;return(f=x==null?void 0:x.current)==null?void 0:f.focus()};return r.jsxs("div",{className:e,onClick:s,children:[r.jsx("input",{ref:x,id:N,role:"spinbutton","aria-valuemin":d,"aria-valuemax":o,"aria-valuenow":l,"aria-describedby":P,"aria-invalid":U(l)?"true":"false",type:"text",inputMode:K,value:X,required:V,disabled:b,onChange:ee,onFocus:te,onBlur:ne,className:t,...v}),h&&r.jsx(le.Text,{element:"span",modifiers:"small",color:"tertiary",className:n.default["tedi-number-field__suffix"],children:h})]})},ie=B.default(n.default["tedi-number-field"],{[n.default["tedi-number-field--invalid"]]:U(l)},{[n.default["tedi-number-field--disabled"]]:b},{[n.default["tedi-number-field--small"]]:y==="small"},g);return r.jsxs("div",{"data-name":"number-field",className:g,children:[r.jsx(ue.FormLabel,{id:N,label:A,required:V,hideLabel:G,size:y}),r.jsxs("div",{className:ie,children:[z("decrement"),ae(),z("increment")]}),i&&r.jsx(se.FeedbackText,{className:n.default["tedi-number-field__feedback"],...i,id:P}),E&&r.jsx("div",{"aria-live":"polite",className:"sr-only",children:E})]})};S.displayName="NumberField";exports.NumberField=S;exports.default=S;
|
|
@@ -36,18 +36,31 @@ export interface NumberFieldProps extends BreakpointSupport<NumberFieldBreakpoin
|
|
|
36
36
|
*/
|
|
37
37
|
value?: number;
|
|
38
38
|
/**
|
|
39
|
-
* Callback fired when the input value changes.
|
|
39
|
+
* Callback fired when the input value changes. Emits `undefined` when the
|
|
40
|
+
* field is cleared so consumers can distinguish *"user explicitly entered
|
|
41
|
+
* zero"* from *"field is empty"* — important for required-field validation
|
|
42
|
+
* and for fields where `0` is a meaningful selection.
|
|
40
43
|
*/
|
|
41
|
-
onChange?: (value: number) => void;
|
|
44
|
+
onChange?: (value: number | undefined) => void;
|
|
42
45
|
/**
|
|
43
46
|
* Specifies the input mode for the field (e.g., numeric or decimal).
|
|
44
|
-
*
|
|
47
|
+
* Defaults to `'decimal'` when `decimalPlaces > 0` or `decimalSeparator === ','`,
|
|
48
|
+
* otherwise numeric.
|
|
45
49
|
*/
|
|
46
50
|
inputMode?: 'numeric' | 'decimal';
|
|
47
51
|
/**
|
|
48
52
|
* Number of decimal places for rounding calculations.
|
|
49
53
|
*/
|
|
50
54
|
decimalPlaces?: number;
|
|
55
|
+
/**
|
|
56
|
+
* Character used as the decimal separator when displaying the value.
|
|
57
|
+
* Both `.` and `,` are always accepted as input regardless of this setting.
|
|
58
|
+
*
|
|
59
|
+
* Defaults are derived from `<LabelProvider locale>`: `en` → `.`, `et` / `ru`
|
|
60
|
+
* → `,`. Pass the prop explicitly to override the locale-derived default for
|
|
61
|
+
* a single field.
|
|
62
|
+
*/
|
|
63
|
+
decimalSeparator?: '.' | ',';
|
|
51
64
|
/**
|
|
52
65
|
* Minimum allowed value. Disables decrementing below this value and restricts manual input.
|
|
53
66
|
*/
|
|
@@ -1,122 +1,146 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import { Text as
|
|
5
|
-
import { Button as
|
|
6
|
-
import { FeedbackText as
|
|
7
|
-
import { FormLabel as
|
|
1
|
+
import { jsxs as L, jsx as c } from "react/jsx-runtime";
|
|
2
|
+
import _ from "../../../../../external/classnames/index.es.js";
|
|
3
|
+
import { useCallback as D, useRef as W, useState as S, useEffect as se } from "react";
|
|
4
|
+
import { Text as de } from "../../base/typography/text/text.es.js";
|
|
5
|
+
import { Button as oe } from "../../buttons/button/button.es.js";
|
|
6
|
+
import { FeedbackText as ue } from "../feedback-text/feedback-text.es.js";
|
|
7
|
+
import { FormLabel as ce } from "../form-label/form-label.es.js";
|
|
8
8
|
import n from "./number-field.module.scss.es.js";
|
|
9
|
-
import { useBreakpointProps as
|
|
10
|
-
import { useLabels as
|
|
11
|
-
const
|
|
12
|
-
const { getCurrentBreakpointProps:
|
|
13
|
-
id:
|
|
14
|
-
label:
|
|
15
|
-
hideLabel:
|
|
16
|
-
required:
|
|
17
|
-
className:
|
|
18
|
-
size:
|
|
19
|
-
inputMode:
|
|
20
|
-
decimalPlaces:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
9
|
+
import { useBreakpointProps as me } from "../../../helpers/hooks/use-breakpoint-props.es.js";
|
|
10
|
+
import { useLabels as fe } from "../../../providers/label-provider/use-labels.es.js";
|
|
11
|
+
const pe = (T) => {
|
|
12
|
+
const { getCurrentBreakpointProps: A } = me(T.defaultServerBreakpoint), { getLabel: w, locale: R } = fe(), G = R === "en" ? "." : ",", {
|
|
13
|
+
id: y,
|
|
14
|
+
label: H,
|
|
15
|
+
hideLabel: J,
|
|
16
|
+
required: E,
|
|
17
|
+
className: U,
|
|
18
|
+
size: B,
|
|
19
|
+
inputMode: K,
|
|
20
|
+
decimalPlaces: f,
|
|
21
|
+
decimalSeparator: I = G,
|
|
22
|
+
min: l,
|
|
23
|
+
max: s,
|
|
24
|
+
step: x = 1,
|
|
25
|
+
defaultValue: O,
|
|
26
|
+
value: o,
|
|
26
27
|
onChange: i,
|
|
27
|
-
suffix:
|
|
28
|
-
fullWidth:
|
|
29
|
-
disabled:
|
|
30
|
-
invalid:
|
|
31
|
-
helper:
|
|
32
|
-
input:
|
|
33
|
-
} =
|
|
34
|
-
() =>
|
|
35
|
-
[
|
|
36
|
-
),
|
|
28
|
+
suffix: h,
|
|
29
|
+
fullWidth: Q = !1,
|
|
30
|
+
disabled: p = !1,
|
|
31
|
+
invalid: F = !1,
|
|
32
|
+
helper: r,
|
|
33
|
+
input: b
|
|
34
|
+
} = A(T), X = K ?? (f && f > 0 || I === "," ? "decimal" : "numeric"), m = D(
|
|
35
|
+
(e) => e === void 0 ? "" : I === "," ? String(e).replace(".", ",") : String(e),
|
|
36
|
+
[I]
|
|
37
|
+
), v = W(null), M = W(!1), [$, g] = S(""), [Y, k] = S(O), [Z, N] = S(() => m(o ?? O)), a = i && typeof o < "u" ? o : Y;
|
|
38
|
+
se(() => {
|
|
39
|
+
!M.current && typeof o < "u" && N(m(o));
|
|
40
|
+
}, [o, m]);
|
|
41
|
+
const z = r ? `${y}-helper` : void 0, P = D(
|
|
37
42
|
(e) => {
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
if (e === void 0)
|
|
44
|
+
return F || (r == null ? void 0 : r.type) === "error";
|
|
45
|
+
const t = l !== void 0 && e < l, d = s !== void 0 && e > s;
|
|
46
|
+
return F || t || d || (r == null ? void 0 : r.type) === "error";
|
|
40
47
|
},
|
|
41
|
-
[
|
|
42
|
-
),
|
|
43
|
-
const t =
|
|
44
|
-
|
|
45
|
-
|
|
48
|
+
[F, r, s, l]
|
|
49
|
+
), j = (e) => Math.min(s ?? 1 / 0, Math.max(l ?? -1 / 0, e)), ee = (e) => {
|
|
50
|
+
const t = w("numberField.quantityUpdated", e);
|
|
51
|
+
g(t), setTimeout(() => {
|
|
52
|
+
g("");
|
|
46
53
|
}, 5e3);
|
|
47
|
-
},
|
|
48
|
-
let t =
|
|
49
|
-
e === "increment" && (t = t +
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
}, q = (e) => f !== void 0 ? parseFloat(e.toFixed(f)) : e, te = (e) => {
|
|
55
|
+
let t = a ?? 0;
|
|
56
|
+
e === "increment" && (t = t + x), e === "decrement" && (t = t - x), t = j(t), t = q(t), ee(t), i == null || i(t), k(t), N(m(t));
|
|
57
|
+
}, ne = ({ currentTarget: { value: e } }) => {
|
|
58
|
+
if (N(e), e === "") {
|
|
59
|
+
a !== void 0 && (i == null || i(void 0), k(void 0));
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const t = e.replace(",", ".");
|
|
63
|
+
if (!/^-?(\d+(\.\d*)?|\.\d+)$/.test(t))
|
|
64
|
+
return;
|
|
65
|
+
const d = parseFloat(t);
|
|
66
|
+
if (Number.isNaN(d)) return;
|
|
67
|
+
const u = j(d), V = q(u);
|
|
68
|
+
V !== a && (i == null || i(V), k(V));
|
|
69
|
+
}, ie = () => {
|
|
70
|
+
M.current = !0;
|
|
71
|
+
}, re = () => {
|
|
72
|
+
M.current = !1, N(m(a));
|
|
73
|
+
}, C = (e) => {
|
|
74
|
+
const t = a !== void 0 && (e === "increment" ? s !== void 0 && a >= s : l !== void 0 && a <= l), d = _(n["tedi-number-field__button"], n[`tedi-number-field__button--${e}`], {
|
|
75
|
+
[n["tedi-number-field__button--disabled"]]: t || p
|
|
76
|
+
}), u = w(`numberField.${e}`, x);
|
|
77
|
+
return /* @__PURE__ */ c(
|
|
78
|
+
oe,
|
|
58
79
|
{
|
|
59
|
-
"aria-label":
|
|
60
|
-
onClick: () =>
|
|
61
|
-
disabled: t ||
|
|
80
|
+
"aria-label": u,
|
|
81
|
+
onClick: () => te(e),
|
|
82
|
+
disabled: t || p,
|
|
62
83
|
visualType: "secondary",
|
|
63
|
-
className:
|
|
84
|
+
className: d,
|
|
64
85
|
icon: { name: e === "increment" ? "add" : "remove" },
|
|
65
|
-
size:
|
|
86
|
+
size: B === "small" ? "small" : void 0,
|
|
66
87
|
children: e === "increment" ? "+" : "-"
|
|
67
88
|
}
|
|
68
89
|
);
|
|
69
|
-
},
|
|
70
|
-
const e =
|
|
71
|
-
[n["tedi-number-field__input-wrapper--with-suffix"]]:
|
|
72
|
-
[n["tedi-number-field__input-wrapper--full-width"]]:
|
|
73
|
-
}), t =
|
|
74
|
-
return /* @__PURE__ */
|
|
75
|
-
var
|
|
76
|
-
return (
|
|
90
|
+
}, ae = () => {
|
|
91
|
+
const e = _(n["tedi-number-field__input-wrapper"], {
|
|
92
|
+
[n["tedi-number-field__input-wrapper--with-suffix"]]: h,
|
|
93
|
+
[n["tedi-number-field__input-wrapper--full-width"]]: Q
|
|
94
|
+
}), t = _(n["tedi-number-field__input"], b == null ? void 0 : b.className);
|
|
95
|
+
return /* @__PURE__ */ L("div", { className: e, onClick: () => {
|
|
96
|
+
var u;
|
|
97
|
+
return (u = v == null ? void 0 : v.current) == null ? void 0 : u.focus();
|
|
77
98
|
}, children: [
|
|
78
|
-
/* @__PURE__ */
|
|
99
|
+
/* @__PURE__ */ c(
|
|
79
100
|
"input",
|
|
80
101
|
{
|
|
81
|
-
ref:
|
|
82
|
-
id:
|
|
83
|
-
"
|
|
84
|
-
"aria-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
102
|
+
ref: v,
|
|
103
|
+
id: y,
|
|
104
|
+
role: "spinbutton",
|
|
105
|
+
"aria-valuemin": l,
|
|
106
|
+
"aria-valuemax": s,
|
|
107
|
+
"aria-valuenow": a,
|
|
108
|
+
"aria-describedby": z,
|
|
109
|
+
"aria-invalid": P(a) ? "true" : "false",
|
|
110
|
+
type: "text",
|
|
111
|
+
inputMode: X,
|
|
112
|
+
value: Z,
|
|
113
|
+
required: E,
|
|
114
|
+
disabled: p,
|
|
115
|
+
onChange: ne,
|
|
116
|
+
onFocus: ie,
|
|
117
|
+
onBlur: re,
|
|
94
118
|
className: t,
|
|
95
|
-
...
|
|
119
|
+
...b
|
|
96
120
|
}
|
|
97
121
|
),
|
|
98
|
-
|
|
122
|
+
h && /* @__PURE__ */ c(de, { element: "span", modifiers: "small", color: "tertiary", className: n["tedi-number-field__suffix"], children: h })
|
|
99
123
|
] });
|
|
100
|
-
},
|
|
124
|
+
}, le = _(
|
|
101
125
|
n["tedi-number-field"],
|
|
102
|
-
{ [n["tedi-number-field--invalid"]]:
|
|
103
|
-
{ [n["tedi-number-field--disabled"]]:
|
|
104
|
-
{ [n["tedi-number-field--small"]]:
|
|
105
|
-
|
|
126
|
+
{ [n["tedi-number-field--invalid"]]: P(a) },
|
|
127
|
+
{ [n["tedi-number-field--disabled"]]: p },
|
|
128
|
+
{ [n["tedi-number-field--small"]]: B === "small" },
|
|
129
|
+
U
|
|
106
130
|
);
|
|
107
|
-
return /* @__PURE__ */
|
|
108
|
-
/* @__PURE__ */
|
|
109
|
-
/* @__PURE__ */
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
131
|
+
return /* @__PURE__ */ L("div", { "data-name": "number-field", className: U, children: [
|
|
132
|
+
/* @__PURE__ */ c(ce, { id: y, label: H, required: E, hideLabel: J, size: B }),
|
|
133
|
+
/* @__PURE__ */ L("div", { className: le, children: [
|
|
134
|
+
C("decrement"),
|
|
135
|
+
ae(),
|
|
136
|
+
C("increment")
|
|
113
137
|
] }),
|
|
114
|
-
|
|
115
|
-
|
|
138
|
+
r && /* @__PURE__ */ c(ue, { className: n["tedi-number-field__feedback"], ...r, id: z }),
|
|
139
|
+
$ && /* @__PURE__ */ c("div", { "aria-live": "polite", className: "sr-only", children: $ })
|
|
116
140
|
] });
|
|
117
141
|
};
|
|
118
|
-
|
|
142
|
+
pe.displayName = "NumberField";
|
|
119
143
|
export {
|
|
120
|
-
|
|
121
|
-
|
|
144
|
+
pe as NumberField,
|
|
145
|
+
pe as default
|
|
122
146
|
};
|
|
@@ -3,6 +3,11 @@ import { TediLabelEntryRecord, TediLabels, TediLabelValuesRecord, TediLanguage }
|
|
|
3
3
|
export interface ILabelContext {
|
|
4
4
|
getLabel<TKey extends keyof TediLabels, TArgs extends TediLabels[TKey] extends Record<TediLanguage, infer FuncType> ? FuncType extends (...args: infer P) => string ? P : [] : TediLabels[TKey] extends (...args: infer P) => string ? P : []>(key: TKey, ...args: TArgs): string;
|
|
5
5
|
setLocale: (locale: TediLanguage) => void;
|
|
6
|
+
/**
|
|
7
|
+
* Currently active locale. Exposed so components can derive locale-sensitive
|
|
8
|
+
* formatting defaults (e.g. `NumberField`'s `decimalSeparator`) without
|
|
9
|
+
* forcing every consumer to repeat the prop on every instance.
|
|
10
|
+
*/
|
|
6
11
|
locale: TediLanguage;
|
|
7
12
|
}
|
|
8
13
|
export declare const LabelContext: React.Context<ILabelContext>;
|