@frontify/fondue 12.0.0-beta.383 → 12.0.0-beta.385

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.
@@ -1,4 +1,4 @@
1
- import { jsxs as f, jsx as l } from "react/jsx-runtime";
1
+ import { jsxs as w, jsx as l } from "react/jsx-runtime";
2
2
  import { cloneElement as g } from "react";
3
3
  import { merge as x } from "../../utilities/merge.es.js";
4
4
  import { HelperText as h } from "../../utilities/input.es.js";
@@ -14,44 +14,43 @@ const F = ({ tooltips: a }) => a.map((t) => /* @__PURE__ */ l(
14
14
  children: t.children
15
15
  },
16
16
  `form-field-tooltip-${v()}`
17
- )), $ = ({ label: a, disabled: t, readOnly: m, dataTestId: c }) => {
18
- const { text: d, required: n, secondaryLabel: i, hugWidth: s, tooltips: e } = a, r = [], p = "tw-w-full tw-flex tw-flex-nowrap tw-justify-between", o = !s && i;
19
- let w = d;
20
- return n && (w += " *"), e != null && e.length ? r.push(
21
- /* @__PURE__ */ f("span", { className: "tw-flex tw-gap-2", children: [
22
- w,
17
+ )), $ = ({ label: a, disabled: t, readOnly: f, dataTestId: m }) => {
18
+ const { text: c, required: n, secondaryLabel: i, hugWidth: s, tooltips: e } = a, r = [], d = "tw-w-full tw-flex tw-flex-nowrap tw-justify-between", o = !s && i;
19
+ let p = c;
20
+ return n && (p += " *"), e != null && e.length ? r.push(
21
+ /* @__PURE__ */ w("span", { className: "tw-flex tw-gap-2", children: [
22
+ p,
23
23
  /* @__PURE__ */ l(F, { tooltips: e })
24
24
  ] })
25
- ) : r.push(/* @__PURE__ */ l("span", { children: w })), o && r.push(/* @__PURE__ */ l("span", { children: i })), /* @__PURE__ */ f(
25
+ ) : r.push(/* @__PURE__ */ l("span", { children: p })), o && r.push(/* @__PURE__ */ l("span", { children: i })), /* @__PURE__ */ w(
26
26
  "span",
27
27
  {
28
28
  className: x([
29
29
  "tw-whitespace-nowrap",
30
30
  s && "tw-pt-2",
31
- o && p,
32
- t || m ? "tw-text-black-60" : "tw-text-black-80"
31
+ o && d,
32
+ t || f ? "tw-text-black-60" : "tw-text-black-80"
33
33
  ]),
34
- "data-test-id": `${c}-label-text`,
35
- "aria-label": w,
34
+ "data-test-id": `${m}-label-text`,
36
35
  children: [
37
36
  ...r
38
37
  ]
39
38
  }
40
39
  );
41
- }, b = ({
40
+ }, L = ({
42
41
  children: a,
43
42
  disabled: t = !1,
44
- error: m = !1,
45
- errorText: c,
46
- errorTextColor: d = u.Error,
43
+ error: f = !1,
44
+ errorText: m,
45
+ errorTextColor: c = u.Error,
47
46
  helperText: n,
48
47
  helperTextColor: i = u.Default,
49
48
  hiddenLabel: s = !1,
50
49
  label: e,
51
50
  readOnly: r = !1,
52
- status: p = u.Default,
51
+ status: d = u.Default,
53
52
  "data-test-id": o = "fondue-form-field"
54
- }) => /* @__PURE__ */ f(
53
+ }) => /* @__PURE__ */ w(
55
54
  "label",
56
55
  {
57
56
  className: x([
@@ -60,22 +59,21 @@ const F = ({ tooltips: a }) => a.map((t) => /* @__PURE__ */ l(
60
59
  t || r ? "hover:tw-cursor-not-allowed tw-pointer-events-none" : "hover:tw-cursor-pointer hover:tw-text-text group-hover:tw-text-text"
61
60
  ]),
62
61
  "data-test-id": `${o}-label`,
63
- "aria-label": e.text,
64
62
  children: [
65
63
  s ? null : /* @__PURE__ */ l($, { label: e, dataTestId: o, disabled: t, readOnly: r }),
66
- /* @__PURE__ */ f("div", { className: "tw-w-full tw-flex tw-flex-col tw-gap-2", "data-test-id": `${o}-input`, children: [
64
+ /* @__PURE__ */ w("div", { className: "tw-w-full tw-flex tw-flex-col tw-gap-2", "data-test-id": `${o}-input`, children: [
67
65
  g(a, {
68
66
  hugWidth: e.hugWidth,
69
67
  required: e.required,
70
- status: p,
68
+ status: d,
71
69
  disabled: t,
72
70
  readOnly: r
73
71
  }),
74
- m && /* @__PURE__ */ l(
72
+ f && /* @__PURE__ */ l(
75
73
  h,
76
74
  {
77
- text: c ?? "Something went wrong",
78
- validationStyle: d,
75
+ text: m ?? "Something went wrong",
76
+ validationStyle: c,
79
77
  disabled: t,
80
78
  "data-test-id": `${o}-error-text`
81
79
  }
@@ -93,8 +91,8 @@ const F = ({ tooltips: a }) => a.map((t) => /* @__PURE__ */ l(
93
91
  ]
94
92
  }
95
93
  );
96
- b.displayname = "FondueFormField";
94
+ L.displayname = "FondueFormField";
97
95
  export {
98
- b as FormField
96
+ L as FormField
99
97
  };
100
98
  //# sourceMappingURL=FormField.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"FormField.es.js","sources":["../../../src/components/FormField/FormField.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport type { ReactElement } from 'react';\nimport { cloneElement } from 'react';\nimport { merge } from '@utilities/merge';\nimport { IconSize } from '@foundation/Icon';\nimport { HelperText } from '@utilities/input';\nimport { Validation } from '@utilities/validation';\nimport { generateRandomId } from '@utilities/generateRandomId';\nimport { Tooltip, TooltipProps } from '@components/Tooltip/Tooltip';\n\nexport type LabelProps = {\n text: string;\n hugWidth?: boolean;\n required?: boolean;\n secondaryLabel?: string;\n tooltips?: TooltipProps[];\n toolTipSize?: IconSize;\n};\n\nexport type FormFieldProps = {\n children: ReactElement;\n label: LabelProps;\n disabled?: boolean;\n error?: boolean;\n errorText?: string;\n errorTextColor?: Validation;\n helperText?: string;\n helperTextColor?: Validation;\n hiddenLabel?: boolean;\n readOnly?: boolean;\n status?: Validation;\n 'data-test-id'?: string;\n};\n\ntype FormatTooltipsProps = { tooltips: TooltipProps[] };\n\nconst FormatTooltips = ({ tooltips }: FormatTooltipsProps): ReactElement[] => {\n return tooltips.map((tip: TooltipProps) => (\n <Tooltip\n key={`form-field-tooltip-${generateRandomId()}`}\n content={tip.content}\n size={tip.size}\n data-test-id={tip['data-test-id']}\n >\n {tip.children}\n </Tooltip>\n ));\n};\n\ntype FormattedLabelProps = {\n label: FormFieldProps['label'];\n disabled: FormFieldProps['disabled'];\n readOnly: FormFieldProps['readOnly'];\n dataTestId: FormFieldProps['data-test-id'];\n};\n\nconst FormattedLabel = ({ label, disabled, readOnly, dataTestId }: FormattedLabelProps): ReactElement => {\n const { text, required, secondaryLabel, hugWidth, tooltips } = label;\n const elements: ReactElement[] = [];\n const secondaryLabelStyle = 'tw-w-full tw-flex tw-flex-nowrap tw-justify-between';\n const applySecondaryLabel = !hugWidth && secondaryLabel;\n let formattedLabel = text;\n\n if (required) {\n formattedLabel += ' *';\n }\n\n if (tooltips?.length) {\n elements.push(\n <span className={'tw-flex tw-gap-2'}>\n {formattedLabel}\n <FormatTooltips tooltips={tooltips} />\n </span>,\n );\n } else {\n elements.push(<span>{formattedLabel}</span>);\n }\n\n if (applySecondaryLabel) {\n elements.push(<span>{secondaryLabel}</span>);\n }\n\n return (\n <span\n className={merge([\n 'tw-whitespace-nowrap',\n hugWidth && 'tw-pt-2',\n applySecondaryLabel && secondaryLabelStyle,\n disabled || readOnly ? 'tw-text-black-60' : 'tw-text-black-80',\n ])}\n data-test-id={`${dataTestId}-label-text`}\n aria-label={formattedLabel}\n >\n {...elements}\n </span>\n );\n};\n\nexport const FormField = ({\n children,\n disabled = false,\n error = false,\n errorText,\n errorTextColor = Validation.Error,\n helperText,\n helperTextColor = Validation.Default,\n hiddenLabel = false,\n label,\n readOnly = false,\n status = Validation.Default,\n 'data-test-id': dataTestId = 'fondue-form-field',\n}: FormFieldProps): ReactElement => {\n return (\n <label\n className={merge([\n 'tw-flex tw-text-text-weak tw-gap-2 tw-select-none tw-max-w-full',\n label.hugWidth ? 'tw-w-fit tw-items-start tw-justify-start' : 'tw-w-full tw-flex-col',\n disabled || readOnly\n ? 'hover:tw-cursor-not-allowed tw-pointer-events-none'\n : 'hover:tw-cursor-pointer hover:tw-text-text group-hover:tw-text-text',\n ])}\n data-test-id={`${dataTestId}-label`}\n aria-label={label.text}\n >\n {hiddenLabel ? null : (\n <FormattedLabel label={label} dataTestId={dataTestId} disabled={disabled} readOnly={readOnly} />\n )}\n <div className={'tw-w-full tw-flex tw-flex-col tw-gap-2'} data-test-id={`${dataTestId}-input`}>\n {cloneElement(children, {\n hugWidth: label.hugWidth,\n required: label.required,\n status,\n disabled,\n readOnly,\n })}\n {error && (\n <HelperText\n text={errorText ?? 'Something went wrong'}\n validationStyle={errorTextColor}\n disabled={disabled}\n data-test-id={`${dataTestId}-error-text`}\n />\n )}\n {helperText && (\n <HelperText\n text={helperText}\n validationStyle={helperTextColor}\n disabled={disabled}\n data-test-id={`${dataTestId}-helper-text`}\n />\n )}\n </div>\n </label>\n );\n};\nFormField.displayname = 'FondueFormField';\n"],"names":["FormatTooltips","tooltips","tip","jsx","Tooltip","generateRandomId","FormattedLabel","label","disabled","readOnly","dataTestId","text","required","secondaryLabel","hugWidth","elements","secondaryLabelStyle","applySecondaryLabel","formattedLabel","jsxs","merge","FormField","children","error","errorText","errorTextColor","Validation","helperText","helperTextColor","hiddenLabel","status","cloneElement","HelperText"],"mappings":";;;;;;;AAqCA,MAAMA,IAAiB,CAAC,EAAE,UAAAC,QACfA,EAAS,IAAI,CAACC,MACjB,gBAAAC;AAAA,EAACC;AAAA,EAAA;AAAA,IAEG,SAASF,EAAI;AAAA,IACb,MAAMA,EAAI;AAAA,IACV,gBAAcA,EAAI,cAAc;AAAA,IAE/B,UAAIA,EAAA;AAAA,EAAA;AAAA,EALA,sBAAsBG,GAAkB;AAAA,CAOpD,GAUCC,IAAiB,CAAC,EAAE,OAAAC,GAAO,UAAAC,GAAU,UAAAC,GAAU,YAAAC,QAAoD;AACrG,QAAM,EAAE,MAAAC,GAAM,UAAAC,GAAU,gBAAAC,GAAgB,UAAAC,GAAU,UAAAb,EAAa,IAAAM,GACzDQ,IAA2B,CAAA,GAC3BC,IAAsB,uDACtBC,IAAsB,CAACH,KAAYD;AACzC,MAAIK,IAAiBP;AAErB,SAAIC,MACkBM,KAAA,OAGlBjB,KAAA,QAAAA,EAAU,SACDc,EAAA;AAAA,IACL,gBAAAI,EAAC,QAAK,EAAA,WAAW,oBACZ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BAEjG,OAAI,EAAA,WAAW,0CAA0C,gBAAc,GAAGC,CAAU,UAChF,UAAA;AAAA,QAAAqB,EAAaT,GAAU;AAAA,UACpB,UAAUf,EAAM;AAAA,UAChB,UAAUA,EAAM;AAAA,UAChB,QAAAuB;AAAA,UACA,UAAAtB;AAAA,UACA,UAAAC;AAAA,QAAA,CACH;AAAA,QACAc,KACG,gBAAApB;AAAA,UAAC6B;AAAA,UAAA;AAAA,YACG,MAAMR,KAAa;AAAA,YACnB,iBAAiBC;AAAA,YACjB,UAAAjB;AAAA,YACA,gBAAc,GAAGE,CAAU;AAAA,UAAA;AAAA,QAC/B;AAAA,QAEHiB,KACG,gBAAAxB;AAAA,UAAC6B;AAAA,UAAA;AAAA,YACG,MAAML;AAAA,YACN,iBAAiBC;AAAA,YACjB,UAAApB;AAAA,YACA,gBAAc,GAAGE,CAAU;AAAA,UAAA;AAAA,QAC/B;AAAA,MAAA,GAER;AAAA,IAAA;AAAA,EAAA;AAAA;AAIZW,EAAU,cAAc;"}
1
+ {"version":3,"file":"FormField.es.js","sources":["../../../src/components/FormField/FormField.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport type { ReactElement } from 'react';\nimport { cloneElement } from 'react';\nimport { merge } from '@utilities/merge';\nimport { IconSize } from '@foundation/Icon';\nimport { HelperText } from '@utilities/input';\nimport { Validation } from '@utilities/validation';\nimport { generateRandomId } from '@utilities/generateRandomId';\nimport { Tooltip, TooltipProps } from '@components/Tooltip/Tooltip';\n\nexport type LabelProps = {\n text: string;\n hugWidth?: boolean;\n required?: boolean;\n secondaryLabel?: string;\n tooltips?: TooltipProps[];\n toolTipSize?: IconSize;\n};\n\nexport type FormFieldProps = {\n children: ReactElement;\n label: LabelProps;\n disabled?: boolean;\n error?: boolean;\n errorText?: string;\n errorTextColor?: Validation;\n helperText?: string;\n helperTextColor?: Validation;\n hiddenLabel?: boolean;\n readOnly?: boolean;\n status?: Validation;\n 'data-test-id'?: string;\n};\n\ntype FormatTooltipsProps = { tooltips: TooltipProps[] };\n\nconst FormatTooltips = ({ tooltips }: FormatTooltipsProps): ReactElement[] => {\n return tooltips.map((tip: TooltipProps) => (\n <Tooltip\n key={`form-field-tooltip-${generateRandomId()}`}\n content={tip.content}\n size={tip.size}\n data-test-id={tip['data-test-id']}\n >\n {tip.children}\n </Tooltip>\n ));\n};\n\ntype FormattedLabelProps = {\n label: FormFieldProps['label'];\n disabled: FormFieldProps['disabled'];\n readOnly: FormFieldProps['readOnly'];\n dataTestId: FormFieldProps['data-test-id'];\n};\n\nconst FormattedLabel = ({ label, disabled, readOnly, dataTestId }: FormattedLabelProps): ReactElement => {\n const { text, required, secondaryLabel, hugWidth, tooltips } = label;\n const elements: ReactElement[] = [];\n const secondaryLabelStyle = 'tw-w-full tw-flex tw-flex-nowrap tw-justify-between';\n const applySecondaryLabel = !hugWidth && secondaryLabel;\n let formattedLabel = text;\n\n if (required) {\n formattedLabel += ' *';\n }\n\n if (tooltips?.length) {\n elements.push(\n <span className={'tw-flex tw-gap-2'}>\n {formattedLabel}\n <FormatTooltips tooltips={tooltips} />\n </span>,\n );\n } else {\n elements.push(<span>{formattedLabel}</span>);\n }\n\n if (applySecondaryLabel) {\n elements.push(<span>{secondaryLabel}</span>);\n }\n\n return (\n <span\n className={merge([\n 'tw-whitespace-nowrap',\n hugWidth && 'tw-pt-2',\n applySecondaryLabel && secondaryLabelStyle,\n disabled || readOnly ? 'tw-text-black-60' : 'tw-text-black-80',\n ])}\n data-test-id={`${dataTestId}-label-text`}\n >\n {...elements}\n </span>\n );\n};\n\nexport const FormField = ({\n children,\n disabled = false,\n error = false,\n errorText,\n errorTextColor = Validation.Error,\n helperText,\n helperTextColor = Validation.Default,\n hiddenLabel = false,\n label,\n readOnly = false,\n status = Validation.Default,\n 'data-test-id': dataTestId = 'fondue-form-field',\n}: FormFieldProps): ReactElement => {\n return (\n <label\n className={merge([\n 'tw-flex tw-text-text-weak tw-gap-2 tw-select-none tw-max-w-full',\n label.hugWidth ? 'tw-w-fit tw-items-start tw-justify-start' : 'tw-w-full tw-flex-col',\n disabled || readOnly\n ? 'hover:tw-cursor-not-allowed tw-pointer-events-none'\n : 'hover:tw-cursor-pointer hover:tw-text-text group-hover:tw-text-text',\n ])}\n data-test-id={`${dataTestId}-label`}\n >\n {hiddenLabel ? null : (\n <FormattedLabel label={label} dataTestId={dataTestId} disabled={disabled} readOnly={readOnly} />\n )}\n <div className={'tw-w-full tw-flex tw-flex-col tw-gap-2'} data-test-id={`${dataTestId}-input`}>\n {cloneElement(children, {\n hugWidth: label.hugWidth,\n required: label.required,\n status,\n disabled,\n readOnly,\n })}\n {error && (\n <HelperText\n text={errorText ?? 'Something went wrong'}\n validationStyle={errorTextColor}\n disabled={disabled}\n data-test-id={`${dataTestId}-error-text`}\n />\n )}\n {helperText && (\n <HelperText\n text={helperText}\n validationStyle={helperTextColor}\n disabled={disabled}\n data-test-id={`${dataTestId}-helper-text`}\n />\n )}\n </div>\n </label>\n );\n};\nFormField.displayname = 'FondueFormField';\n"],"names":["FormatTooltips","tooltips","tip","jsx","Tooltip","generateRandomId","FormattedLabel","label","disabled","readOnly","dataTestId","text","required","secondaryLabel","hugWidth","elements","secondaryLabelStyle","applySecondaryLabel","formattedLabel","jsxs","merge","FormField","children","error","errorText","errorTextColor","Validation","helperText","helperTextColor","hiddenLabel","status","cloneElement","HelperText"],"mappings":";;;;;;;AAqCA,MAAMA,IAAiB,CAAC,EAAE,UAAAC,QACfA,EAAS,IAAI,CAACC,MACjB,gBAAAC;AAAA,EAACC;AAAA,EAAA;AAAA,IAEG,SAASF,EAAI;AAAA,IACb,MAAMA,EAAI;AAAA,IACV,gBAAcA,EAAI,cAAc;AAAA,IAE/B,UAAIA,EAAA;AAAA,EAAA;AAAA,EALA,sBAAsBG,GAAkB;AAAA,CAOpD,GAUCC,IAAiB,CAAC,EAAE,OAAAC,GAAO,UAAAC,GAAU,UAAAC,GAAU,YAAAC,QAAoD;AACrG,QAAM,EAA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M,WAAW,6CAA6C;AAAA,MAC9DC,KAAYC,IACN,uDACA;AAAA,IAAA,CACT;AAAA,IACD,gBAAc,GAAGC,CAAU;AAAA,IAE1B,UAAA;AAAA,MAAAmB,IAAc,OACV,gBAAA1B,EAAAG,GAAA,EAAe,OAAAC,GAAc,YAAAG,GAAwB,UAAAF,GAAoB,UAAAC,GAAoB;AAAA,wBAEjG,OAAI,EAAA,WAAW,0CAA0C,gBAAc,GAAGC,CAAU,UAChF,UAAA;AAAA,QAAAqB,EAAaT,GAAU;AAAA,UACpB,UAAUf,EAAM;AAAA,UAChB,UAAUA,EAAM;AAAA,UAChB,QAAAuB;AAAA,UACA,UAAAtB;AAAA,UACA,UAAAC;AAAA,QAAA,CACH;AAAA,QACAc,KACG,gBAAApB;AAAA,UAAC6B;AAAA,UAAA;AAAA,YACG,MAAMR,KAAa;AAAA,YACnB,iBAAiBC;AAAA,YACjB,UAAAjB;AAAA,YACA,gBAAc,GAAGE,CAAU;AAAA,UAAA;AAAA,QAC/B;AAAA,QAEHiB,KACG,gBAAAxB;AAAA,UAAC6B;AAAA,UAAA;AAAA,YACG,MAAML;AAAA,YACN,iBAAiBC;AAAA,YACjB,UAAApB;AAAA,YACA,gBAAc,GAAGE,CAAU;AAAA,UAAA;AAAA,QAC/B;AAAA,MAAA,GAER;AAAA,IAAA;AAAA,EAAA;AAAA;AAIZW,EAAU,cAAc;"}
@@ -29,7 +29,7 @@ const at = ["ArrowUp", "ArrowRight"], it = ["ArrowDown", "ArrowLeft"], st = ["Ba
29
29
  onKeyDown: T,
30
30
  onBlur: $,
31
31
  onFocus: V,
32
- "aria-label": z,
32
+ "aria-label": z = "Number Input",
33
33
  "data-test-id": c = "fondue-number-input",
34
34
  ...G
35
35
  }) => {
@@ -63,17 +63,17 @@ const at = ["ArrowUp", "ArrowRight"], it = ["ArrowDown", "ArrowLeft"], st = ["Ba
63
63
  }, J = (t) => {
64
64
  const { key: e, shiftKey: a } = t;
65
65
  if (st.includes(e)) {
66
- const o = s(), I = o.length === 2 && o.includes("-");
67
- ((o == null ? void 0 : o.length) === 0 || I) && U();
66
+ const o = s(), y = o.length === 2 && o.includes("-");
67
+ ((o == null ? void 0 : o.length) === 0 || y) && U();
68
68
  return;
69
69
  } else if (!isNaN(Number(e)))
70
70
  return;
71
71
  t.preventDefault(), k.current = a, it.includes(e) ? w(l.DECREMENT) : at.includes(e) && w(l.INCREMENT), T && T(t);
72
72
  }, Q = (t) => {
73
- t.preventDefault(), k.current = t.shiftKey, n.current && y();
73
+ t.preventDefault(), k.current = t.shiftKey, n.current && I();
74
74
  }, w = (t, e = 1) => {
75
75
  const o = (() => {
76
- const I = s(), R = Number(I) || 0;
76
+ const y = s(), R = Number(y) || 0;
77
77
  switch (e = k.current ? g : e, t) {
78
78
  case l.DECREMENT:
79
79
  return R - e;
@@ -89,7 +89,7 @@ const at = ["ArrowUp", "ArrowRight"], it = ["ArrowDown", "ArrowLeft"], st = ["Ba
89
89
  const e = t.toString();
90
90
  if (n.current.value = r ? `${e} ${r}` : e, C.current)
91
91
  return;
92
- y();
92
+ I();
93
93
  }
94
94
  }, P = N(() => {
95
95
  if (i && n.current) {
@@ -101,11 +101,11 @@ const at = ["ArrowUp", "ArrowRight"], it = ["ArrowDown", "ArrowLeft"], st = ["Ba
101
101
  const t = n.current.value.length - r.length - 1;
102
102
  n.current.setSelectionRange(t, t);
103
103
  }
104
- }, [r, n]), y = N(() => {
104
+ }, [r, n]), I = N(() => {
105
105
  const t = s();
106
106
  h == null || h(t ? Number(t) : void 0), r && M(), i && P();
107
107
  }, [r, i, h, s, M, P]), U = () => {
108
- n.current && (n.current.value = x ? x.toString() : ""), y();
108
+ n.current && (n.current.value = x ? x.toString() : ""), I();
109
109
  }, X = (t) => {
110
110
  V && V(t);
111
111
  }, Z = (t) => {
@@ -1 +1 @@
1
- {"version":3,"file":"NumberInput.es.js","sources":["../../../src/components/NumberInput/NumberInput.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { useCallback, useEffect, useRef } from 'react';\nimport { NumberInputIncrement, NumberInputProps } from './types';\nimport { merge } from '@utilities/merge';\nimport { IconCross16, IconMinus16, IconPlus16 } from '@foundation/Icon';\nimport { useMemoizedId } from '@hooks/useMemoizedId';\nimport { Validation, validationClassMap } from '@utilities/validation';\nimport { KeyboardEvent } from '@react-types/shared';\nimport { GetStatusIcon } from '@utilities/input';\n\nconst INCREMENT_KEYS = ['ArrowUp', 'ArrowRight'];\nconst DECREMENT_KEYS = ['ArrowDown', 'ArrowLeft'];\nconst SPECIAL_KEYS = ['Backspace', 'Tab'];\n\nexport const NumberInput = ({\n id: propId,\n size,\n disabled = false,\n required,\n readOnly,\n status = Validation.Default,\n decorator,\n suffix = '',\n controls,\n clearable,\n placeholder,\n stepInterval = 10,\n title,\n defaultValue,\n value,\n valueSelect,\n onChange,\n onKeyDown,\n onBlur,\n onFocus,\n 'aria-label': ariaLabel,\n 'data-test-id': dataTestId = 'fondue-number-input',\n ...props\n}: NumberInputProps) => {\n const timer = useRef<number>(0);\n const isShift = useRef<boolean>(false);\n const isMouseHold = useRef<boolean>(false);\n const inputElement = useRef<HTMLInputElement | null>(null);\n\n const getCurrentValueWithoutSuffix = useCallback((): string => {\n if (inputElement.current) {\n const { value } = inputElement.current;\n if (suffix) {\n return value.replace(`${suffix}`, '').trim();\n }\n return value;\n }\n return '';\n }, [inputElement, suffix]);\n\n const stopIncrement = () => {\n clearInterval(timer.current);\n isMouseHold.current = false;\n };\n\n const startIncrement = (type: NumberInputIncrement) => {\n if (inputElement.current && !disabled) {\n isMouseHold.current = true;\n onHoldCount(type);\n }\n };\n\n const onHoldCount = (type: NumberInputIncrement) => {\n const getNewInputValue = () => {\n let elapsedSeconds = 0;\n let changeValue = 0;\n timer.current = window.setInterval(() => {\n switch (true) {\n case elapsedSeconds > 2000:\n changeValue += 5;\n break;\n case elapsedSeconds > 5000:\n changeValue += 10;\n break;\n default:\n changeValue = 1;\n }\n handleCount(type, changeValue);\n elapsedSeconds += 250;\n }, 250);\n };\n getNewInputValue();\n };\n\n const handleKeyDown = (event: KeyboardEvent) => {\n const { key, shiftKey } = event;\n if (SPECIAL_KEYS.includes(key)) {\n const currentValue = getCurrentValueWithoutSuffix();\n const isNegativeSymbol: boolean = currentValue.length === 2 && currentValue.includes('-');\n if (currentValue?.length === 0 || isNegativeSymbol) {\n handleClear();\n }\n return;\n } else if (!isNaN(Number(key))) {\n return;\n }\n\n event.preventDefault();\n isShift.current = shiftKey;\n if (DECREMENT_KEYS.includes(key)) {\n handleCount(NumberInputIncrement.DECREMENT);\n } else if (INCREMENT_KEYS.includes(key)) {\n handleCount(NumberInputIncrement.INCREMENT);\n }\n if (onKeyDown) {\n onKeyDown(event);\n }\n };\n\n const handleKeyUp = (event: KeyboardEvent) => {\n event.preventDefault();\n isShift.current = event.shiftKey;\n if (inputElement.current) {\n handleOnChange();\n }\n };\n\n const handleCount = (type: NumberInputIncrement, changeValue = 1) => {\n const getNewInputValue = () => {\n const value = getCurrentValueWithoutSuffix();\n const currentValue = Number(value) || 0;\n changeValue = isShift.current ? stepInterval : changeValue;\n switch (type) {\n case NumberInputIncrement.DECREMENT:\n return currentValue - changeValue;\n case NumberInputIncrement.INCREMENT:\n return currentValue + changeValue;\n default:\n return currentValue;\n }\n };\n\n const newValue = getNewInputValue();\n setValue(newValue);\n };\n\n const setValue = (value: number) => {\n if (inputElement.current) {\n const newValue = value.toString();\n inputElement.current.value = suffix ? `${newValue}${' '}${suffix}` : newValue;\n if (isMouseHold.current) {\n return;\n }\n handleOnChange();\n }\n };\n\n const handleValueSelect = useCallback(() => {\n if (valueSelect && inputElement.current) {\n const inputLength: number = inputElement.current.value.length;\n const caretPos: number = suffix ? inputLength - suffix.length - 1 : inputLength;\n inputElement.current.setSelectionRange(0, caretPos);\n }\n }, [suffix, valueSelect]);\n\n const handleCaretPosition = useCallback(() => {\n if (suffix && inputElement.current) {\n const caretPos: number = inputElement.current.value.length - suffix.length - 1;\n inputElement.current.setSelectionRange(caretPos, caretPos);\n }\n }, [suffix, inputElement]);\n\n const handleOnChange = useCallback(() => {\n const valueWithoutSuffix = getCurrentValueWithoutSuffix();\n onChange?.(valueWithoutSuffix ? Number(valueWithoutSuffix) : undefined);\n if (suffix) {\n handleCaretPosition();\n }\n if (valueSelect) {\n handleValueSelect();\n }\n }, [suffix, valueSelect, onChange, getCurrentValueWithoutSuffix, handleCaretPosition, handleValueSelect]);\n\n const handleClear = () => {\n if (inputElement.current) {\n inputElement.current.value = defaultValue ? defaultValue.toString() : '';\n }\n handleOnChange();\n };\n\n const handleFocus = (event: React.FocusEvent<HTMLInputElement, Element>) => {\n if (onFocus) {\n onFocus(event);\n }\n };\n\n const handleBlur = (event: React.FocusEvent<HTMLInputElement, Element>) => {\n if (onBlur) {\n onBlur(event);\n }\n };\n\n useEffect(() => {\n clearInterval(timer.current);\n }, []);\n\n return (\n <div\n className={merge([\n 'tw-w-full tw-flex tw-items-center tw-justify-between tw-h-9 tw-gap-2 tw-px-3 tw-transition tw-text-s tw-font-sans tw-relative tw-bg-white dark:tw-bg-transparent tw-border tw-rounded tw-line-strong hover:tw-border-line-x-strong focus-within:tw-border-line-xx-strong focus-within:hover:tw-border-line-xx-strong',\n status ? validationClassMap[status] : '',\n ])}\n data-test-id={dataTestId}\n >\n {decorator ? (\n <div\n className={merge([\n 'tw-flex tw-items-center tw-justify-center tw-pl-1',\n disabled || readOnly ? 'tw-text-black-60' : 'tw-text-black-80',\n ])}\n data-test-id={`${dataTestId}-decorator`}\n >\n {decorator}\n </div>\n ) : null}\n <input\n {...props}\n defaultValue={defaultValue}\n value={value}\n id={useMemoizedId(propId)}\n ref={inputElement}\n name={dataTestId}\n type={suffix || valueSelect ? 'text' : 'number'}\n placeholder={placeholder}\n className={merge([\n 'tw-w-full tw-border-none tw-outline-none tw-bg-transparent tw-hide-input-arrows',\n disabled || readOnly\n ? 'tw-text-black-40 tw-placeholder-black-30 dark:tw-text-black-30 dark:tw-placeholder-black-40'\n : 'tw-text-black tw-placeholder-black-60 dark:tw-text-white',\n ])}\n onClick={suffix ? handleCaretPosition : undefined}\n onChange={() => setValue(Number(getCurrentValueWithoutSuffix()))}\n onKeyDown={handleKeyDown}\n onKeyUp={handleKeyUp}\n onFocus={handleFocus}\n onBlur={handleBlur}\n size={size}\n title={title}\n aria-label={ariaLabel}\n required={required}\n readOnly={readOnly}\n disabled={disabled}\n data-test-id={`${dataTestId}-input`}\n />\n <span className={'tw-flex tw-items-center'}>\n {controls ? (\n <>\n <button\n className={\n 'tw-text-text-weak tw-p-1 hover:tw-rounded-sm hover:tw-bg-box-neutral hover:tw-text-box-neutral-inverse focus:tw-ring-line-xx-strong focus:tw-bg-box-neutral'\n }\n type=\"button\"\n onClick={(event) => {\n if (event.button === 0) {\n const changeValue = event.shiftKey ? stepInterval : 1;\n handleCount(NumberInputIncrement.DECREMENT, changeValue);\n }\n }}\n onMouseDown={(event) =>\n event.shiftKey || event.button > 0\n ? null\n : startIncrement(NumberInputIncrement.DECREMENT)\n }\n onMouseUp={stopIncrement}\n onTouchStart={(event) =>\n event.shiftKey ? null : startIncrement(NumberInputIncrement.DECREMENT)\n }\n onTouchEnd={stopIncrement}\n aria-label=\"Decrement value\"\n title=\"Decrement value\"\n data-test-id={`${dataTestId}-decrement`}\n >\n <IconMinus16 />\n </button>\n <button\n className={\n 'tw-text-text-weak tw-p-1 hover:tw-rounded-sm hover:tw-bg-box-neutral hover:tw-text-box-neutral-inverse focus:tw-ring-line-xx-strong focus:tw-bg-box-neutral'\n }\n type=\"button\"\n onClick={(event) => {\n if (event.button === 0) {\n const changeValue = event.shiftKey ? stepInterval : 1;\n handleCount(NumberInputIncrement.INCREMENT, changeValue);\n }\n }}\n onMouseDown={(event) =>\n event.shiftKey || event.button > 0\n ? null\n : startIncrement(NumberInputIncrement.INCREMENT)\n }\n onMouseUp={stopIncrement}\n onTouchStart={(event) =>\n event.shiftKey ? null : startIncrement(NumberInputIncrement.INCREMENT)\n }\n onTouchEnd={stopIncrement}\n aria-label=\"Increment value\"\n title=\"Increment value\"\n data-test-id={`${dataTestId}-increment`}\n >\n <IconPlus16 />\n </button>\n </>\n ) : null}\n {clearable ? (\n <button\n type=\"button\"\n onClick={handleClear}\n className={\n 'tw-text-text-weak tw-p-1 hover:tw-rounded-sm hover:tw-bg-box-neutral hover:tw-text-box-neutral-inverse focus:tw-ring-line-xx-strong focus:tw-bg-box-neutral'\n }\n aria-label=\"Clear value\"\n data-test-id={`${dataTestId}-clear`}\n >\n <IconCross16 />\n </button>\n ) : null}\n {status ? GetStatusIcon(status, dataTestId) : null}\n </span>\n </div>\n );\n};\n\nNumberInput.displayName = 'FondueNumberInput';\n"],"names":["INCREMENT_KEYS","DECREMENT_KEYS","SPECIAL_KEYS","NumberInput","propId","size","disabled","required","readOnly","status","Validation","decorator","suffix","controls","clearable","placeholder","stepInterval","title","defaultValue","value","valueSelect","onChange","onKeyDown","onBlur","onFocus","ariaLabel","dataTestId","props","timer","useRef","isShift","isMouseHold","inputElement","getCurrentValueWithoutSuffix","useCallback","stopIncrement","startIncrement","type","onHoldCount","elapsedSeconds","changeValue","handleCount","handleKeyDown","event","key","shiftKey","currentValue","isNegativeSymbol","handleClear","NumberInputIncrement","handleKeyUp","handleOnChange","newValue","setValue","handleValueSelect","inputLength","caretPos","handleCaretPosition","valueWithoutSuffix","handleFocus","handleBlur","useEffect","jsxs","merge","validationClassMap","jsx","useMemoizedId","Fragment","IconMinus16","IconPlus16","IconCross16","GetStatusIcon"],"mappings":";;;;;;;;;;AAWA,MAAMA,KAAiB,CAAC,WAAW,YAAY,GACzCC,KAAiB,CAAC,aAAa,WAAW,GAC1CC,KAAe,CAAC,aAAa,KAAK,GAE3BC,KAAc,CAAC;AAAA,EACxB,IAAIC;AAAA,EACJ,MAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,UAAAC;AAAA,EACA,UAAAC;AAAA,EACA,QAAAC,IAASC,GAAW;AAAA,EACpB,WAAAC;AAAA,EACA,QAAAC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AAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGZ;AAEAvB,GAAY,cAAc;"}
1
+ {"version":3,"file":"NumberInput.es.js","sources":["../../../src/components/NumberInput/NumberInput.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { useCallback, useEffect, useRef } from 'react';\nimport { NumberInputIncrement, NumberInputProps } from './types';\nimport { merge } from '@utilities/merge';\nimport { IconCross16, IconMinus16, IconPlus16 } from '@foundation/Icon';\nimport { useMemoizedId } from '@hooks/useMemoizedId';\nimport { Validation, validationClassMap } from '@utilities/validation';\nimport { KeyboardEvent } from '@react-types/shared';\nimport { GetStatusIcon } from '@utilities/input';\n\nconst INCREMENT_KEYS = ['ArrowUp', 'ArrowRight'];\nconst DECREMENT_KEYS = ['ArrowDown', 'ArrowLeft'];\nconst SPECIAL_KEYS = ['Backspace', 'Tab'];\n\nexport const NumberInput = ({\n id: propId,\n size,\n disabled = false,\n required,\n readOnly,\n status = Validation.Default,\n decorator,\n suffix = '',\n controls,\n clearable,\n placeholder,\n stepInterval = 10,\n title,\n defaultValue,\n value,\n valueSelect,\n onChange,\n onKeyDown,\n onBlur,\n onFocus,\n 'aria-label': ariaLabel = 'Number Input',\n 'data-test-id': dataTestId = 'fondue-number-input',\n ...props\n}: NumberInputProps) => {\n const timer = useRef<number>(0);\n const isShift = useRef<boolean>(false);\n const isMouseHold = useRef<boolean>(false);\n const inputElement = useRef<HTMLInputElement | null>(null);\n\n const getCurrentValueWithoutSuffix = useCallback((): string => {\n if (inputElement.current) {\n const { value } = inputElement.current;\n if (suffix) {\n return value.replace(`${suffix}`, '').trim();\n }\n return value;\n }\n return '';\n }, [inputElement, suffix]);\n\n const stopIncrement = () => {\n clearInterval(timer.current);\n isMouseHold.current = false;\n };\n\n const startIncrement = (type: NumberInputIncrement) => {\n if (inputElement.current && !disabled) {\n isMouseHold.current = true;\n onHoldCount(type);\n }\n };\n\n const onHoldCount = (type: NumberInputIncrement) => {\n const getNewInputValue = () => {\n let elapsedSeconds = 0;\n let changeValue = 0;\n timer.current = window.setInterval(() => {\n switch (true) {\n case elapsedSeconds > 2000:\n changeValue += 5;\n break;\n case elapsedSeconds > 5000:\n changeValue += 10;\n break;\n default:\n changeValue = 1;\n }\n handleCount(type, changeValue);\n elapsedSeconds += 250;\n }, 250);\n };\n getNewInputValue();\n };\n\n const handleKeyDown = (event: KeyboardEvent) => {\n const { key, shiftKey } = event;\n if (SPECIAL_KEYS.includes(key)) {\n const currentValue = getCurrentValueWithoutSuffix();\n const isNegativeSymbol: boolean = currentValue.length === 2 && currentValue.includes('-');\n if (currentValue?.length === 0 || isNegativeSymbol) {\n handleClear();\n }\n return;\n } else if (!isNaN(Number(key))) {\n return;\n }\n\n event.preventDefault();\n isShift.current = shiftKey;\n if (DECREMENT_KEYS.includes(key)) {\n handleCount(NumberInputIncrement.DECREMENT);\n } else if (INCREMENT_KEYS.includes(key)) {\n handleCount(NumberInputIncrement.INCREMENT);\n }\n if (onKeyDown) {\n onKeyDown(event);\n }\n };\n\n const handleKeyUp = (event: KeyboardEvent) => {\n event.preventDefault();\n isShift.current = event.shiftKey;\n if (inputElement.current) {\n handleOnChange();\n }\n };\n\n const handleCount = (type: NumberInputIncrement, changeValue = 1) => {\n const getNewInputValue = () => {\n const value = getCurrentValueWithoutSuffix();\n const currentValue = Number(value) || 0;\n changeValue = isShift.current ? stepInterval : changeValue;\n switch (type) {\n case NumberInputIncrement.DECREMENT:\n return currentValue - changeValue;\n case NumberInputIncrement.INCREMENT:\n return currentValue + changeValue;\n default:\n return currentValue;\n }\n };\n\n const newValue = getNewInputValue();\n setValue(newValue);\n };\n\n const setValue = (value: number) => {\n if (inputElement.current) {\n const newValue = value.toString();\n inputElement.current.value = suffix ? `${newValue}${' '}${suffix}` : newValue;\n if (isMouseHold.current) {\n return;\n }\n handleOnChange();\n }\n };\n\n const handleValueSelect = useCallback(() => {\n if (valueSelect && inputElement.current) {\n const inputLength: number = inputElement.current.value.length;\n const caretPos: number = suffix ? inputLength - suffix.length - 1 : inputLength;\n inputElement.current.setSelectionRange(0, caretPos);\n }\n }, [suffix, valueSelect]);\n\n const handleCaretPosition = useCallback(() => {\n if (suffix && inputElement.current) {\n const caretPos: number = inputElement.current.value.length - suffix.length - 1;\n inputElement.current.setSelectionRange(caretPos, caretPos);\n }\n }, [suffix, inputElement]);\n\n const handleOnChange = useCallback(() => {\n const valueWithoutSuffix = getCurrentValueWithoutSuffix();\n onChange?.(valueWithoutSuffix ? Number(valueWithoutSuffix) : undefined);\n if (suffix) {\n handleCaretPosition();\n }\n if (valueSelect) {\n handleValueSelect();\n }\n }, [suffix, valueSelect, onChange, getCurrentValueWithoutSuffix, handleCaretPosition, handleValueSelect]);\n\n const handleClear = () => {\n if (inputElement.current) {\n inputElement.current.value = defaultValue ? defaultValue.toString() : '';\n }\n handleOnChange();\n };\n\n const handleFocus = (event: React.FocusEvent<HTMLInputElement, Element>) => {\n if (onFocus) {\n onFocus(event);\n }\n };\n\n const handleBlur = (event: React.FocusEvent<HTMLInputElement, Element>) => {\n if (onBlur) {\n onBlur(event);\n }\n };\n\n useEffect(() => {\n clearInterval(timer.current);\n }, []);\n\n return (\n <div\n className={merge([\n 'tw-w-full tw-flex tw-items-center tw-justify-between tw-h-9 tw-gap-2 tw-px-3 tw-transition tw-text-s tw-font-sans tw-relative tw-bg-white dark:tw-bg-transparent tw-border tw-rounded tw-line-strong hover:tw-border-line-x-strong focus-within:tw-border-line-xx-strong focus-within:hover:tw-border-line-xx-strong',\n status ? validationClassMap[status] : '',\n ])}\n data-test-id={dataTestId}\n >\n {decorator ? (\n <div\n className={merge([\n 'tw-flex tw-items-center tw-justify-center tw-pl-1',\n disabled || readOnly ? 'tw-text-black-60' : 'tw-text-black-80',\n ])}\n data-test-id={`${dataTestId}-decorator`}\n >\n {decorator}\n </div>\n ) : null}\n <input\n {...props}\n defaultValue={defaultValue}\n value={value}\n id={useMemoizedId(propId)}\n ref={inputElement}\n name={dataTestId}\n type={suffix || valueSelect ? 'text' : 'number'}\n placeholder={placeholder}\n className={merge([\n 'tw-w-full tw-border-none tw-outline-none tw-bg-transparent tw-hide-input-arrows',\n disabled || readOnly\n ? 'tw-text-black-40 tw-placeholder-black-30 dark:tw-text-black-30 dark:tw-placeholder-black-40'\n : 'tw-text-black tw-placeholder-black-60 dark:tw-text-white',\n ])}\n onClick={suffix ? handleCaretPosition : undefined}\n onChange={() => setValue(Number(getCurrentValueWithoutSuffix()))}\n onKeyDown={handleKeyDown}\n onKeyUp={handleKeyUp}\n onFocus={handleFocus}\n onBlur={handleBlur}\n size={size}\n title={title}\n aria-label={ariaLabel}\n required={required}\n readOnly={readOnly}\n disabled={disabled}\n data-test-id={`${dataTestId}-input`}\n />\n <span className={'tw-flex tw-items-center'}>\n {controls ? (\n <>\n <button\n className={\n 'tw-text-text-weak tw-p-1 hover:tw-rounded-sm hover:tw-bg-box-neutral hover:tw-text-box-neutral-inverse focus:tw-ring-line-xx-strong focus:tw-bg-box-neutral'\n }\n type=\"button\"\n onClick={(event) => {\n if (event.button === 0) {\n const changeValue = event.shiftKey ? stepInterval : 1;\n handleCount(NumberInputIncrement.DECREMENT, changeValue);\n }\n }}\n onMouseDown={(event) =>\n event.shiftKey || event.button > 0\n ? null\n : startIncrement(NumberInputIncrement.DECREMENT)\n }\n onMouseUp={stopIncrement}\n onTouchStart={(event) =>\n event.shiftKey ? null : startIncrement(NumberInputIncrement.DECREMENT)\n }\n onTouchEnd={stopIncrement}\n aria-label=\"Decrement value\"\n title=\"Decrement value\"\n data-test-id={`${dataTestId}-decrement`}\n >\n <IconMinus16 />\n </button>\n <button\n className={\n 'tw-text-text-weak tw-p-1 hover:tw-rounded-sm hover:tw-bg-box-neutral hover:tw-text-box-neutral-inverse focus:tw-ring-line-xx-strong focus:tw-bg-box-neutral'\n }\n type=\"button\"\n onClick={(event) => {\n if (event.button === 0) {\n const changeValue = event.shiftKey ? stepInterval : 1;\n handleCount(NumberInputIncrement.INCREMENT, changeValue);\n }\n }}\n onMouseDown={(event) =>\n event.shiftKey || event.button > 0\n ? null\n : startIncrement(NumberInputIncrement.INCREMENT)\n }\n onMouseUp={stopIncrement}\n onTouchStart={(event) =>\n event.shiftKey ? null : startIncrement(NumberInputIncrement.INCREMENT)\n }\n onTouchEnd={stopIncrement}\n aria-label=\"Increment value\"\n title=\"Increment value\"\n data-test-id={`${dataTestId}-increment`}\n >\n <IconPlus16 />\n </button>\n </>\n ) : null}\n {clearable ? (\n <button\n type=\"button\"\n onClick={handleClear}\n className={\n 'tw-text-text-weak tw-p-1 hover:tw-rounded-sm hover:tw-bg-box-neutral hover:tw-text-box-neutral-inverse focus:tw-ring-line-xx-strong focus:tw-bg-box-neutral'\n }\n aria-label=\"Clear value\"\n data-test-id={`${dataTestId}-clear`}\n >\n <IconCross16 />\n </button>\n ) : null}\n {status ? GetStatusIcon(status, dataTestId) : null}\n </span>\n </div>\n );\n};\n\nNumberInput.displayName = 'FondueNumberInput';\n"],"names":["INCREMENT_KEYS","DECREMENT_KEYS","SPECIAL_KEYS","NumberInput","propId","size","disabled","required","readOnly","status","Validation","decorator","suffix","controls","clearable","placeholder","stepInterval","title","defaultValue","value","valueSelect","onChange","onKeyDown","onBlur","onFocus","ariaLabel","dataTestId","props","timer","useRef","isShift","isMouseHold","inputElement","getCurrentValueWithoutSuffix","useCallback","stopIncrement","startIncrement","type","onHoldCount","elapsedSeconds","changeValue","handleCount","handleKeyDown","event","key","shiftKey","currentValue","isNegativeSymbol","handleClear","NumberInputIncrement","handleKeyUp","handleOnChange","newValue","setValue","handleValueSelect","inputLength","caretPos","handleCaretPosition","valueWithoutSuffix","handleFocus","handleBlur","useEffect","jsxs","merge","validationClassMap","jsx","useMemoizedId","Fragment","IconMinus16","IconPlus16","IconCross16","GetStatusIcon"],"mappings":";;;;;;;;;;AAWA,MAAMA,KAAiB,CAAC,WAAW,YAAY,GACzCC,KAAiB,CAAC,aAAa,WAAW,GAC1CC,KAAe,CAAC,aAAa,KAAK,GAE3BC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AAA,cAEJ,cAAW;AAAA,cACX,gBAAc,GAAGtB,CAAU;AAAA,cAE3B,4BAAC4C,IAAY,EAAA;AAAA,YAAA;AAAA,UAAA,IAEjB;AAAA,UACH7D,IAAS8D,GAAc9D,GAAQiB,CAAU,IAAI;AAAA,QAAA,GAClD;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGZ;AAEAvB,GAAY,cAAc;"}
@@ -3,7 +3,7 @@ import { Children as b } from "react";
3
3
  import { merge as i } from "../../../utilities/merge.es.js";
4
4
  import f from "../../../foundation/Icon/Generated/IconGrabHandle12.es.js";
5
5
  import { INDENTATION_WIDTH as x } from "../helpers/constants.es.js";
6
- const g = ({
6
+ const h = ({
7
7
  id: d,
8
8
  label: e,
9
9
  level: r = 0,
@@ -13,7 +13,7 @@ const g = ({
13
13
  dragHandlerPosition: o = "left",
14
14
  showContentWhileDragging: l = !1
15
15
  }) => {
16
- const m = b.count(s) > 0, c = { marginLeft: r * x }, a = /* @__PURE__ */ t("button", { tabIndex: -1, className: "tw-p-1", children: /* @__PURE__ */ t(f, {}) });
16
+ const m = b.count(s) > 0, c = { marginLeft: r * x }, a = /* @__PURE__ */ t("button", { tabIndex: -1, className: "tw-p-1 tw-touch-none", children: /* @__PURE__ */ t(f, {}) });
17
17
  return /* @__PURE__ */ p(
18
18
  "li",
19
19
  {
@@ -46,8 +46,8 @@ const g = ({
46
46
  }
47
47
  );
48
48
  };
49
- g.displayName = "FondueTreeItemOverlay";
49
+ h.displayName = "FondueTreeItemOverlay";
50
50
  export {
51
- g as TreeItemOverlay
51
+ h as TreeItemOverlay
52
52
  };
53
53
  //# sourceMappingURL=TreeItemOverlay.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"TreeItemOverlay.es.js","sources":["../../../../src/components/Tree/TreeItem/TreeItemOverlay.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { Children, ReactNode } from 'react';\n\nimport { merge } from '@utilities/merge';\nimport { IconGrabHandle12 } from '@foundation/Icon';\n\nimport { INDENTATION_WIDTH } from '../helpers';\nimport { DragHandlerPosition } from '../types';\n\nexport type Overlay = {\n id: string;\n label?: string;\n level?: number;\n children: ReactNode;\n contentComponent?: ReactNode;\n isSelected?: boolean;\n dragHandlerPosition?: DragHandlerPosition;\n showContentWhileDragging: boolean;\n};\n\nexport const TreeItemOverlay = ({\n id,\n label,\n level = 0,\n children,\n contentComponent,\n isSelected,\n dragHandlerPosition = 'left',\n showContentWhileDragging = false,\n}: Overlay) => {\n const hasChildren = Children.count(children) > 0;\n\n const indentation = level * INDENTATION_WIDTH;\n\n const liStyle = { marginLeft: indentation };\n\n const dragHandler = (\n <button tabIndex={-1} className=\"tw-p-1\">\n <IconGrabHandle12 />\n </button>\n );\n\n return (\n <li\n role=\"treeitem\"\n style={liStyle}\n id={id.toString()}\n aria-label={label}\n aria-level={level + 1}\n aria-selected={isSelected}\n data-test-id=\"fondue-tree-item-overlay\"\n className={merge([\n 'tw-pointer-events-none tw-bg-white tw-flex tw-items-center tw-gap-x-1 tw-p-2 tw-no-underline tw-leading-5 tw-box-border tw-w-fit tw-drop-shadow-xl tw-rounded',\n showContentWhileDragging ? 'tw-opacity-90' : '',\n ])}\n >\n {dragHandlerPosition === 'left' && dragHandler}\n\n {hasChildren && (\n <button tabIndex={-1} data-test-id=\"tree-item-toggle\" className=\"tw-p-1\">\n <div\n className={merge([\n 'tw-transition-transform tw-w-0 tw-h-0 tw-text-black-100 tw-text-opacity-40 tw-font-normal tw-border-t-4 tw-border-t-transparent tw-border-b-4 tw-border-b-transparent tw-border-l-4 tw-border-l-x-strong',\n isSelected && 'tw-text-box-selected-strong-inverse',\n ])}\n />\n </button>\n )}\n\n {label !== undefined && <span>{label}</span>}\n\n {contentComponent}\n\n {dragHandlerPosition === 'right' && dragHandler}\n </li>\n );\n};\n\nTreeItemOverlay.displayName = 'FondueTreeItemOverlay';\n"],"names":["TreeItemOverlay","id","label","level","children","contentComponent","isSelected","dragHandlerPosition","showContentWhileDragging","hasChildren","Children","liStyle","INDENTATION_WIDTH","dragHandler","jsx","IconGrabHandle12","jsxs","merge"],"mappings":";;;;;AAqBO,MAAMA,IAAkB,CAAC;AAAA,EAC5B,IAAAC;AAAA,EACA,OAAAC;AAAA,EACA,OAAAC,IAAQ;AAAA,EACR,UAAAC;AAAA,EACA,kBAAAC;AAAA,EACA,YAAAC;AAAA,EACA,qBAAAC,IAAsB;AAAA,EACtB,0BAAAC,IAA2B;AAC/B,MAAe;AACX,QAAMC,IAAcC,EAAS,MAAMN,CAAQ,IAAI,GAIzCO,IAAU,EAAE,YAFER,IAAQS,KAItBC,sBACD,UAAO,EAAA,UAAU,IAAI,WAAU,UAC5B,UAAC,gBAAAC,EAAAC,GAAA,CAAiB,CAAA,EACtB,CAAA;AAIA,SAAA,gBAAAC;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,MAAK;AAAA,MACL,OAAOL;AAAA,MACP,IAAIV,EAAG,SAAS;AAAA,MAChB,cAAYC;AAAA,MACZ,cAAYC,IAAQ;AAAA,MACpB,iBAAeG;AAAA,MACf,gBAAa;AAAA,MACb,WAAWW,EAAM;AAAA,QACb;AAAA,QACAT,IAA2B,kBAAkB;AAAA,MAAA,CAChD;AAAA,MAEA,UAAA;AAAA,QAAAD,MAAwB,UAAUM;AAAA,QAElCJ,uBACI,UAAO,EAAA,UAAU,IAAI,gBAAa,oBAAmB,WAAU,UAC5D,UAAA,gBAAAK;AAAA,UAAC;AAAA,UAAA;AAAA,YACG,WAAWG,EAAM;AAAA,cACb;AAAA,cACAX,KAAc;AAAA,YAAA,CACjB;AAAA,UAAA;AAAA,QAAA,GAET;AAAA,QAGHJ,MAAU,UAAc,gBAAAY,EAAA,QAAA,EAAM,UAAMZ,GAAA;AAAA,QAEpCG;AAAA,QAEAE,MAAwB,WAAWM;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGhD;AAEAb,EAAgB,cAAc;"}
1
+ {"version":3,"file":"TreeItemOverlay.es.js","sources":["../../../../src/components/Tree/TreeItem/TreeItemOverlay.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { Children, ReactNode } from 'react';\n\nimport { merge } from '@utilities/merge';\nimport { IconGrabHandle12 } from '@foundation/Icon';\n\nimport { INDENTATION_WIDTH } from '../helpers';\nimport { DragHandlerPosition } from '../types';\n\nexport type Overlay = {\n id: string;\n label?: string;\n level?: number;\n children: ReactNode;\n contentComponent?: ReactNode;\n isSelected?: boolean;\n dragHandlerPosition?: DragHandlerPosition;\n showContentWhileDragging: boolean;\n};\n\nexport const TreeItemOverlay = ({\n id,\n label,\n level = 0,\n children,\n contentComponent,\n isSelected,\n dragHandlerPosition = 'left',\n showContentWhileDragging = false,\n}: Overlay) => {\n const hasChildren = Children.count(children) > 0;\n\n const indentation = level * INDENTATION_WIDTH;\n\n const liStyle = { marginLeft: indentation };\n\n const dragHandler = (\n <button tabIndex={-1} className=\"tw-p-1 tw-touch-none\">\n <IconGrabHandle12 />\n </button>\n );\n\n return (\n <li\n role=\"treeitem\"\n style={liStyle}\n id={id.toString()}\n aria-label={label}\n aria-level={level + 1}\n aria-selected={isSelected}\n data-test-id=\"fondue-tree-item-overlay\"\n className={merge([\n 'tw-pointer-events-none tw-bg-white tw-flex tw-items-center tw-gap-x-1 tw-p-2 tw-no-underline tw-leading-5 tw-box-border tw-w-fit tw-drop-shadow-xl tw-rounded',\n showContentWhileDragging ? 'tw-opacity-90' : '',\n ])}\n >\n {dragHandlerPosition === 'left' && dragHandler}\n\n {hasChildren && (\n <button tabIndex={-1} data-test-id=\"tree-item-toggle\" className=\"tw-p-1\">\n <div\n className={merge([\n 'tw-transition-transform tw-w-0 tw-h-0 tw-text-black-100 tw-text-opacity-40 tw-font-normal tw-border-t-4 tw-border-t-transparent tw-border-b-4 tw-border-b-transparent tw-border-l-4 tw-border-l-x-strong',\n isSelected && 'tw-text-box-selected-strong-inverse',\n ])}\n />\n </button>\n )}\n\n {label !== undefined && <span>{label}</span>}\n\n {contentComponent}\n\n {dragHandlerPosition === 'right' && dragHandler}\n </li>\n );\n};\n\nTreeItemOverlay.displayName = 'FondueTreeItemOverlay';\n"],"names":["TreeItemOverlay","id","label","level","children","contentComponent","isSelected","dragHandlerPosition","showContentWhileDragging","hasChildren","Children","liStyle","INDENTATION_WIDTH","dragHandler","jsx","IconGrabHandle12","jsxs","merge"],"mappings":";;;;;AAqBO,MAAMA,IAAkB,CAAC;AAAA,EAC5B,IAAAC;AAAA,EACA,OAAAC;AAAA,EACA,OAAAC,IAAQ;AAAA,EACR,UAAAC;AAAA,EACA,kBAAAC;AAAA,EACA,YAAAC;AAAA,EACA,qBAAAC,IAAsB;AAAA,EACtB,0BAAAC,IAA2B;AAC/B,MAAe;AACX,QAAMC,IAAcC,EAAS,MAAMN,CAAQ,IAAI,GAIzCO,IAAU,EAAE,YAFER,IAAQS,KAItBC,sBACD,UAAO,EAAA,UAAU,IAAI,WAAU,wBAC5B,UAAC,gBAAAC,EAAAC,GAAA,CAAiB,CAAA,EACtB,CAAA;AAIA,SAAA,gBAAAC;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,MAAK;AAAA,MACL,OAAOL;AAAA,MACP,IAAIV,EAAG,SAAS;AAAA,MAChB,cAAYC;AAAA,MACZ,cAAYC,IAAQ;AAAA,MACpB,iBAAeG;AAAA,MACf,gBAAa;AAAA,MACb,WAAWW,EAAM;AAAA,QACb;AAAA,QACAT,IAA2B,kBAAkB;AAAA,MAAA,CAChD;AAAA,MAEA,UAAA;AAAA,QAAAD,MAAwB,UAAUM;AAAA,QAElCJ,uBACI,UAAO,EAAA,UAAU,IAAI,gBAAa,oBAAmB,WAAU,UAC5D,UAAA,gBAAAK;AAAA,UAAC;AAAA,UAAA;AAAA,YACG,WAAWG,EAAM;AAAA,cACb;AAAA,cACAX,KAAc;AAAA,YAAA,CACjB;AAAA,UAAA;AAAA,QAAA,GAET;AAAA,QAGHJ,MAAU,UAAc,gBAAAY,EAAA,QAAA,EAAM,UAAMZ,GAAA;AAAA,QAEpCG;AAAA,QAEAE,MAAwB,WAAWM;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGhD;AAEAb,EAAgB,cAAc;"}
@@ -1,7 +1,7 @@
1
1
  const o = ({
2
2
  dragHandlerPosition: e,
3
3
  enableDragDelay: n
4
- }) => e === "none" ? { delay: n ? 150 : 0, tolerance: 2 } : { delay: 0, tolerance: 0 };
4
+ }) => e === "none" ? { delay: n ? 150 : 0, tolerance: 5 } : { delay: 0, tolerance: 5 };
5
5
  export {
6
6
  o as sensorsActivationConstraint
7
7
  };
@@ -1 +1 @@
1
- {"version":3,"file":"sensorsActivationConstraint.es.js","sources":["../../../../src/components/Tree/helpers/sensorsActivationConstraint.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { TreeProps } from '../types';\n\ntype SensorsActivationConstraintProps = {\n dragHandlerPosition: TreeProps['dragHandlerPosition'];\n enableDragDelay: TreeProps['enableDragDelay'];\n};\n\ntype SensorsActivationConstraint = {\n delay: number;\n tolerance: number;\n};\n\nexport const sensorsActivationConstraint = ({\n dragHandlerPosition,\n enableDragDelay,\n}: SensorsActivationConstraintProps): SensorsActivationConstraint => {\n const delay = enableDragDelay ? 150 : 0;\n return dragHandlerPosition === 'none' ? { delay, tolerance: 2 } : { delay: 0, tolerance: 0 };\n};\n"],"names":["sensorsActivationConstraint","dragHandlerPosition","enableDragDelay"],"mappings":"AAcO,MAAMA,IAA8B,CAAC;AAAA,EACxC,qBAAAC;AAAA,EACA,iBAAAC;AACJ,MAEWD,MAAwB,SAAS,EAAE,OAD5BC,IAAkB,MAAM,GACW,WAAW,MAAM,EAAE,OAAO,GAAG,WAAW,EAAE;"}
1
+ {"version":3,"file":"sensorsActivationConstraint.es.js","sources":["../../../../src/components/Tree/helpers/sensorsActivationConstraint.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { TreeProps } from '../types';\n\ntype SensorsActivationConstraintProps = {\n dragHandlerPosition: TreeProps['dragHandlerPosition'];\n enableDragDelay: TreeProps['enableDragDelay'];\n};\n\ntype SensorsActivationConstraint = {\n delay: number;\n tolerance: number;\n};\n\nexport const sensorsActivationConstraint = ({\n dragHandlerPosition,\n enableDragDelay,\n}: SensorsActivationConstraintProps): SensorsActivationConstraint => {\n const delay = enableDragDelay ? 150 : 0;\n return dragHandlerPosition === 'none' ? { delay, tolerance: 5 } : { delay: 0, tolerance: 5 };\n};\n"],"names":["sensorsActivationConstraint","dragHandlerPosition","enableDragDelay"],"mappings":"AAcO,MAAMA,IAA8B,CAAC;AAAA,EACxC,qBAAAC;AAAA,EACA,iBAAAC;AACJ,MAEWD,MAAwB,SAAS,EAAE,OAD5BC,IAAkB,MAAM,GACW,WAAW,MAAM,EAAE,OAAO,GAAG,WAAW,EAAE;"}