@tedi-design-system/react 18.1.1-rc.1 → 18.2.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tedi-design-system/react",
3
- "version": "18.1.1-rc.1",
3
+ "version": "18.2.0-rc.1",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "exports": {
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),j=require("../../../../../external/classnames/index.cjs.js"),p=require("react"),de=require("../../../helpers/hooks/use-file-upload.cjs.js"),oe=require("../../base/typography/text/text.cjs.js"),S=require("../../buttons/button/button.cjs.js"),re=require("../../buttons/closing-button/closing-button.cjs.js"),ce=require("../form-label/form-label.cjs.js"),ue=require("../../misc/separator/separator.cjs.js"),fe=require("../../tags/tag/tag.cjs.js"),z=require("../feedback-text/feedback-text.cjs.js"),g=require("../input-group/input-group.cjs.js"),a=require("./file-upload.module.scss.cjs.js"),pe=require("../../../providers/label-provider/use-labels.cjs.js"),M=require("../../../helpers/hooks/use-breakpoint.cjs.js"),me=require("../../layout/grid/row.cjs.js"),O=require("../../layout/grid/col.cjs.js"),A=P=>{var U;const{getLabel:n}=pe.useLabels(),{id:V,name:$,label:v,accept:y,multiple:F,onChange:m,className:D,wrapperClassName:W,defaultFiles:H,onDelete:J,hasClearButton:K=!0,files:c,readOnly:x,disabled:s=!1,maxSize:Q,validateIndividually:X=!1,size:u="default",helper:i,...Y}=P,{innerFiles:_,uploadErrorHelper:t,onFileChange:Z,onFileRemove:E,handleClear:G,announcement:ee}=de.useFileUpload({accept:y,maxSize:Q,multiple:F,validateIndividually:X,defaultFiles:H,onChange:m,onDelete:J,files:c}),le=M.default(),ae=p.useId(),d=(U=g.useOptionalInputGroup)==null?void 0:U.call(g),te=d==null?void 0:d.hasExternalLabel,f=V??(d==null?void 0:d.inputId)??ae,q=p.useRef(null),N=p.useRef(null),ie=j.default(a.default["tedi-file-upload"],{[a.default["tedi-file-upload--disabled"]]:s},D),B=(t==null?void 0:t.type)==="error",h=i??(B?void 0:t),b=B?t:void 0,C=h?(i==null?void 0:i.id)??`${f}-helper`:void 0,L=b?`${f}-error`:void 0,k=[C,L].filter(Boolean).join(" ")||void 0,o=p.useMemo(()=>c&&m?c:_,[c,_,m]),R=()=>{var l;return(l=N.current)==null?void 0:l.focus()},se=l=>{E(l),R()},I=()=>{G(),R()},ne=(l,r)=>{const w=l.isValid===!1;return e.jsx("li",{children:e.jsxs(fe.Tag,{role:"presentation",color:w?"danger":"primary",onClose:!l.isLoading&&!s&&!x?()=>se(l):void 0,isLoading:l.isLoading,closeButtonProps:{title:`${n("remove")} ${l.name}`},children:[l.name,w&&e.jsxs("span",{className:"sr-only",children:[" (",n("file-upload.failed"),")"]})]})},l.id??r)},T=()=>{if(o.length>1)return e.jsx("ul",{className:a.default["tedi-file-upload__items"],children:o.map((l,r)=>ne(l,r))});if(o.length===1){const l=o[0],r=l.isValid===!1;return e.jsxs(oe.Text,{className:j.default(a.default["tedi-file-upload__items"],a.default["tedi-file-upload__items--truncate"]),children:[l.name,r&&e.jsxs("span",{className:"sr-only",children:[" (",n("file-upload.failed"),")"]})]})}return null};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:a.default["tedi-file-upload__label-wrapper"],children:!te&&v&&e.jsx(ce.FormLabel,{id:f,label:v??"",...Y,renderWithoutLabel:x,className:a.default["tedi-file-upload__label"],size:u})}),e.jsx("div",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:ee}),x?T():e.jsx("div",{className:j.default(a.default["tedi-file-upload__container"],{[a.default["tedi-file-upload--disabled"]]:s,[a.default["tedi-file-upload--error"]]:((t==null?void 0:t.type)||(i==null?void 0:i.type))==="error",[a.default["tedi-file-upload--valid"]]:((t==null?void 0:t.type)||(i==null?void 0:i.type))==="valid"},{[a.default[`tedi-file-upload__container--${u}`]]:u},W),children:e.jsx("div",{className:a.default["tedi-file-upload__content"],children:e.jsxs(me.Row,{children:[e.jsx(O.Col,{className:"display-flex",children:T()}),e.jsx(O.Col,{xs:12,md:"auto",children:e.jsxs("div",{className:ie,children:[e.jsx("input",{ref:q,id:f,type:"file",name:$,accept:y,onChange:Z,multiple:F,disabled:s,"aria-invalid":!!t&&t.type==="error","aria-describedby":k}),K&&o.length>0&&!s&&e.jsxs(e.Fragment,{children:[M.isBreakpointBelow(le,"md")?e.jsx(S.Button,{visualType:"neutral",iconLeft:"close",disabled:s,onClick:I,className:a.default["tedi-file-upload__button"],children:n("clear")}):e.jsx(re.ClosingButton,{onClick:I,iconSize:18,title:n("clear")}),e.jsx(ue.Separator,{axis:"vertical",height:1.5,spacing:.5,color:"primary"})]}),e.jsx(S.Button,{ref:N,visualType:"neutral",iconLeft:"file_upload",disabled:s,onClick:()=>{var l;return(l=q.current)==null?void 0:l.click()},className:a.default["tedi-file-upload__button"],size:u,"aria-describedby":k,children:n("file-upload.add")})]})})]})})}),h&&e.jsx(z.FeedbackText,{...h,id:C}),b&&e.jsx(z.FeedbackText,{...b,id:L})]})};A.displayName="FileUpload";exports.FileUpload=A;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),j=require("../../../../../external/classnames/index.cjs.js"),p=require("react"),de=require("../../../helpers/hooks/use-file-upload.cjs.js"),re=require("../../base/typography/text/text.cjs.js"),S=require("../../buttons/button/button.cjs.js"),ce=require("../../buttons/closing-button/closing-button.cjs.js"),ue=require("../form-label/form-label.cjs.js"),fe=require("../../misc/separator/separator.cjs.js"),pe=require("../../tags/tag/tag.cjs.js"),z=require("../feedback-text/feedback-text.cjs.js"),g=require("../input-group/input-group.cjs.js"),a=require("./file-upload.module.scss.cjs.js"),me=require("../../../providers/label-provider/use-labels.cjs.js"),M=require("../../../helpers/hooks/use-breakpoint.cjs.js"),xe=require("../../layout/grid/row.cjs.js"),O=require("../../layout/grid/col.cjs.js"),A=P=>{var U;const{getLabel:n}=me.useLabels(),{id:V,name:$,label:v,accept:y,multiple:F,onChange:m,className:D,wrapperClassName:W,defaultFiles:H,onDelete:J,hasClearButton:K=!0,files:c,readOnly:x,disabled:s=!1,maxSize:Q,validateIndividually:X=!1,showRestrictions:Y,size:u="default",helper:i,...Z}=P,{innerFiles:_,uploadErrorHelper:t,onFileChange:E,onFileRemove:G,handleClear:ee,announcement:le}=de.useFileUpload({accept:y,maxSize:Q,multiple:F,validateIndividually:X,defaultFiles:H,onChange:m,onDelete:J,files:c,showRestrictions:Y}),ae=M.default(),te=p.useId(),o=(U=g.useOptionalInputGroup)==null?void 0:U.call(g),ie=o==null?void 0:o.hasExternalLabel,f=V??(o==null?void 0:o.inputId)??te,q=p.useRef(null),N=p.useRef(null),se=j.default(a.default["tedi-file-upload"],{[a.default["tedi-file-upload--disabled"]]:s},D),B=(t==null?void 0:t.type)==="error",h=i??(B?void 0:t),b=B?t:void 0,C=h?(i==null?void 0:i.id)??`${f}-helper`:void 0,L=b?`${f}-error`:void 0,k=[C,L].filter(Boolean).join(" ")||void 0,d=p.useMemo(()=>c&&m?c:_,[c,_,m]),R=()=>{var l;return(l=N.current)==null?void 0:l.focus()},ne=l=>{G(l),R()},I=()=>{ee(),R()},oe=(l,r)=>{const w=l.isValid===!1;return e.jsx("li",{children:e.jsxs(pe.Tag,{role:"presentation",color:w?"danger":"primary",onClose:!l.isLoading&&!s&&!x?()=>ne(l):void 0,isLoading:l.isLoading,closeButtonProps:{title:`${n("remove")} ${l.name}`},children:[l.name,w&&e.jsxs("span",{className:"sr-only",children:[" (",n("file-upload.failed"),")"]})]})},l.id??r)},T=()=>{if(d.length>1)return e.jsx("ul",{className:a.default["tedi-file-upload__items"],children:d.map((l,r)=>oe(l,r))});if(d.length===1){const l=d[0],r=l.isValid===!1;return e.jsxs(re.Text,{className:j.default(a.default["tedi-file-upload__items"],a.default["tedi-file-upload__items--truncate"]),children:[l.name,r&&e.jsxs("span",{className:"sr-only",children:[" (",n("file-upload.failed"),")"]})]})}return null};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:a.default["tedi-file-upload__label-wrapper"],children:!ie&&v&&e.jsx(ue.FormLabel,{id:f,label:v??"",...Z,renderWithoutLabel:x,className:a.default["tedi-file-upload__label"],size:u})}),e.jsx("div",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:le}),x?T():e.jsx("div",{className:j.default(a.default["tedi-file-upload__container"],{[a.default["tedi-file-upload--disabled"]]:s,[a.default["tedi-file-upload--error"]]:((t==null?void 0:t.type)||(i==null?void 0:i.type))==="error",[a.default["tedi-file-upload--valid"]]:((t==null?void 0:t.type)||(i==null?void 0:i.type))==="valid"},{[a.default[`tedi-file-upload__container--${u}`]]:u},W),children:e.jsx("div",{className:a.default["tedi-file-upload__content"],children:e.jsxs(xe.Row,{children:[e.jsx(O.Col,{className:"display-flex",children:T()}),e.jsx(O.Col,{xs:12,md:"auto",children:e.jsxs("div",{className:se,children:[e.jsx("input",{ref:q,id:f,type:"file",name:$,accept:y,onChange:E,multiple:F,disabled:s,"aria-invalid":!!t&&t.type==="error","aria-describedby":k}),K&&d.length>0&&!s&&e.jsxs(e.Fragment,{children:[M.isBreakpointBelow(ae,"md")?e.jsx(S.Button,{visualType:"neutral",iconLeft:"close",disabled:s,onClick:I,className:a.default["tedi-file-upload__button"],children:n("clear")}):e.jsx(ce.ClosingButton,{onClick:I,iconSize:18,title:n("clear")}),e.jsx(fe.Separator,{axis:"vertical",height:1.5,spacing:.5,color:"primary"})]}),e.jsx(S.Button,{ref:N,visualType:"neutral",iconLeft:"file_upload",disabled:s,onClick:()=>{var l;return(l=q.current)==null?void 0:l.click()},className:a.default["tedi-file-upload__button"],size:u,"aria-describedby":k,children:n("file-upload.add")})]})})]})})}),h&&e.jsx(z.FeedbackText,{...h,id:C}),b&&e.jsx(z.FeedbackText,{...b,id:L})]})};A.displayName="FileUpload";exports.FileUpload=A;
@@ -79,6 +79,13 @@ export interface FileUploadProps extends Omit<FormLabelProps, 'id' | 'label'> {
79
79
  * If `true`, validates each file separately instead of rejecting all at once.
80
80
  */
81
81
  validateIndividually?: boolean;
82
+ /**
83
+ * Whether to show the auto-generated restrictions hint (allowed types / max size)
84
+ * below the field. Turn it off when the same info is shown elsewhere to avoid a
85
+ * duplicate — rejection error messages still render.
86
+ * @default true
87
+ */
88
+ showRestrictions?: boolean;
82
89
  /**
83
90
  * Determines the visual size of the file upload field. Defaults to `"default"`.
84
91
  */
@@ -2,22 +2,22 @@ import { jsxs as t, Fragment as z, jsx as i } from "react/jsx-runtime";
2
2
  import y from "../../../../../external/classnames/index.es.js";
3
3
  import f from "react";
4
4
  import { useFileUpload as ne } from "../../../helpers/hooks/use-file-upload.es.js";
5
- import { Text as se } from "../../base/typography/text/text.es.js";
5
+ import { Text as re } from "../../base/typography/text/text.es.js";
6
6
  import { Button as S } from "../../buttons/button/button.es.js";
7
- import { ClosingButton as re } from "../../buttons/closing-button/closing-button.es.js";
8
- import { FormLabel as de } from "../form-label/form-label.es.js";
9
- import { Separator as ce } from "../../misc/separator/separator.es.js";
10
- import { Tag as me } from "../../tags/tag/tag.es.js";
7
+ import { ClosingButton as de } from "../../buttons/closing-button/closing-button.es.js";
8
+ import { FormLabel as ce } from "../form-label/form-label.es.js";
9
+ import { Separator as me } from "../../misc/separator/separator.es.js";
10
+ import { Tag as pe } from "../../tags/tag/tag.es.js";
11
11
  import { FeedbackText as A } from "../feedback-text/feedback-text.es.js";
12
- import { useOptionalInputGroup as pe } from "../input-group/input-group.es.js";
12
+ import { useOptionalInputGroup as ue } from "../input-group/input-group.es.js";
13
13
  import l from "./file-upload.module.scss.es.js";
14
- import { useLabels as ue } from "../../../providers/label-provider/use-labels.es.js";
15
- import fe, { isBreakpointBelow as he } from "../../../helpers/hooks/use-breakpoint.es.js";
16
- import { Row as ve } from "../../layout/grid/row.es.js";
14
+ import { useLabels as fe } from "../../../providers/label-provider/use-labels.es.js";
15
+ import he, { isBreakpointBelow as ve } from "../../../helpers/hooks/use-breakpoint.es.js";
16
+ import { Row as be } from "../../layout/grid/row.es.js";
17
17
  import { Col as M } from "../../layout/grid/col.es.js";
18
- const be = (O) => {
18
+ const _e = (O) => {
19
19
  var $;
20
- const { getLabel: s } = ue(), {
20
+ const { getLabel: n } = fe(), {
21
21
  id: V,
22
22
  name: D,
23
23
  label: g,
@@ -31,13 +31,14 @@ const be = (O) => {
31
31
  hasClearButton: J = !0,
32
32
  files: m,
33
33
  readOnly: v,
34
- disabled: n = !1,
34
+ disabled: s = !1,
35
35
  maxSize: K,
36
36
  validateIndividually: Q = !1,
37
+ showRestrictions: X,
37
38
  size: p = "default",
38
39
  helper: o,
39
- ...X
40
- } = O, { innerFiles: B, uploadErrorHelper: a, onFileChange: Y, onFileRemove: Z, handleClear: E, announcement: G } = ne({
40
+ ...Y
41
+ } = O, { innerFiles: B, uploadErrorHelper: a, onFileChange: Z, onFileRemove: E, handleClear: G, announcement: ee } = ne({
41
42
  accept: F,
42
43
  maxSize: K,
43
44
  multiple: N,
@@ -45,29 +46,30 @@ const be = (O) => {
45
46
  defaultFiles: q,
46
47
  onChange: h,
47
48
  onDelete: H,
48
- files: m
49
- }), ee = fe(), ie = f.useId(), r = ($ = pe) == null ? void 0 : $(), le = r == null ? void 0 : r.hasExternalLabel, u = V ?? (r == null ? void 0 : r.inputId) ?? ie, C = f.useRef(null), L = f.useRef(null), ae = y(l["tedi-file-upload"], { [l["tedi-file-upload--disabled"]]: n }, P), x = (a == null ? void 0 : a.type) === "error", b = o ?? (x ? void 0 : a), _ = x ? a : void 0, k = b ? (o == null ? void 0 : o.id) ?? `${u}-helper` : void 0, I = _ ? `${u}-error` : void 0, R = [k, I].filter(Boolean).join(" ") || void 0, d = f.useMemo(() => m && h ? m : B, [m, B, h]), w = () => {
49
+ files: m,
50
+ showRestrictions: X
51
+ }), ie = he(), le = f.useId(), r = ($ = ue) == null ? void 0 : $(), ae = r == null ? void 0 : r.hasExternalLabel, u = V ?? (r == null ? void 0 : r.inputId) ?? le, C = f.useRef(null), L = f.useRef(null), oe = y(l["tedi-file-upload"], { [l["tedi-file-upload--disabled"]]: s }, P), x = (a == null ? void 0 : a.type) === "error", b = o ?? (x ? void 0 : a), _ = x ? a : void 0, R = b ? (o == null ? void 0 : o.id) ?? `${u}-helper` : void 0, k = _ ? `${u}-error` : void 0, I = [R, k].filter(Boolean).join(" ") || void 0, d = f.useMemo(() => m && h ? m : B, [m, B, h]), w = () => {
50
52
  var e;
51
53
  return (e = L.current) == null ? void 0 : e.focus();
52
- }, oe = (e) => {
53
- Z(e), w();
54
+ }, te = (e) => {
55
+ E(e), w();
54
56
  }, T = () => {
55
- E(), w();
56
- }, te = (e, c) => {
57
+ G(), w();
58
+ }, se = (e, c) => {
57
59
  const j = e.isValid === !1;
58
60
  return /* @__PURE__ */ i("li", { children: /* @__PURE__ */ t(
59
- me,
61
+ pe,
60
62
  {
61
63
  role: "presentation",
62
64
  color: j ? "danger" : "primary",
63
- onClose: !e.isLoading && !n && !v ? () => oe(e) : void 0,
65
+ onClose: !e.isLoading && !s && !v ? () => te(e) : void 0,
64
66
  isLoading: e.isLoading,
65
- closeButtonProps: { title: `${s("remove")} ${e.name}` },
67
+ closeButtonProps: { title: `${n("remove")} ${e.name}` },
66
68
  children: [
67
69
  e.name,
68
70
  j && /* @__PURE__ */ t("span", { className: "sr-only", children: [
69
71
  " (",
70
- s("file-upload.failed"),
72
+ n("file-upload.failed"),
71
73
  ")"
72
74
  ] })
73
75
  ]
@@ -75,14 +77,14 @@ const be = (O) => {
75
77
  ) }, e.id ?? c);
76
78
  }, U = () => {
77
79
  if (d.length > 1)
78
- return /* @__PURE__ */ i("ul", { className: l["tedi-file-upload__items"], children: d.map((e, c) => te(e, c)) });
80
+ return /* @__PURE__ */ i("ul", { className: l["tedi-file-upload__items"], children: d.map((e, c) => se(e, c)) });
79
81
  if (d.length === 1) {
80
82
  const e = d[0], c = e.isValid === !1;
81
- return /* @__PURE__ */ t(se, { className: y(l["tedi-file-upload__items"], l["tedi-file-upload__items--truncate"]), children: [
83
+ return /* @__PURE__ */ t(re, { className: y(l["tedi-file-upload__items"], l["tedi-file-upload__items--truncate"]), children: [
82
84
  e.name,
83
85
  c && /* @__PURE__ */ t("span", { className: "sr-only", children: [
84
86
  " (",
85
- s("file-upload.failed"),
87
+ n("file-upload.failed"),
86
88
  ")"
87
89
  ] })
88
90
  ] });
@@ -90,34 +92,34 @@ const be = (O) => {
90
92
  return null;
91
93
  };
92
94
  return /* @__PURE__ */ t(z, { children: [
93
- /* @__PURE__ */ i("div", { className: l["tedi-file-upload__label-wrapper"], children: !le && g && /* @__PURE__ */ i(
94
- de,
95
+ /* @__PURE__ */ i("div", { className: l["tedi-file-upload__label-wrapper"], children: !ae && g && /* @__PURE__ */ i(
96
+ ce,
95
97
  {
96
98
  id: u,
97
99
  label: g ?? "",
98
- ...X,
100
+ ...Y,
99
101
  renderWithoutLabel: v,
100
102
  className: l["tedi-file-upload__label"],
101
103
  size: p
102
104
  }
103
105
  ) }),
104
- /* @__PURE__ */ i("div", { role: "status", "aria-live": "polite", "aria-atomic": "true", className: "sr-only", children: G }),
106
+ /* @__PURE__ */ i("div", { role: "status", "aria-live": "polite", "aria-atomic": "true", className: "sr-only", children: ee }),
105
107
  v ? U() : /* @__PURE__ */ i(
106
108
  "div",
107
109
  {
108
110
  className: y(
109
111
  l["tedi-file-upload__container"],
110
112
  {
111
- [l["tedi-file-upload--disabled"]]: n,
113
+ [l["tedi-file-upload--disabled"]]: s,
112
114
  [l["tedi-file-upload--error"]]: ((a == null ? void 0 : a.type) || (o == null ? void 0 : o.type)) === "error",
113
115
  [l["tedi-file-upload--valid"]]: ((a == null ? void 0 : a.type) || (o == null ? void 0 : o.type)) === "valid"
114
116
  },
115
117
  { [l[`tedi-file-upload__container--${p}`]]: p },
116
118
  W
117
119
  ),
118
- children: /* @__PURE__ */ i("div", { className: l["tedi-file-upload__content"], children: /* @__PURE__ */ t(ve, { children: [
120
+ children: /* @__PURE__ */ i("div", { className: l["tedi-file-upload__content"], children: /* @__PURE__ */ t(be, { children: [
119
121
  /* @__PURE__ */ i(M, { className: "display-flex", children: U() }),
120
- /* @__PURE__ */ i(M, { xs: 12, md: "auto", children: /* @__PURE__ */ t("div", { className: ae, children: [
122
+ /* @__PURE__ */ i(M, { xs: 12, md: "auto", children: /* @__PURE__ */ t("div", { className: oe, children: [
121
123
  /* @__PURE__ */ i(
122
124
  "input",
123
125
  {
@@ -126,26 +128,26 @@ const be = (O) => {
126
128
  type: "file",
127
129
  name: D,
128
130
  accept: F,
129
- onChange: Y,
131
+ onChange: Z,
130
132
  multiple: N,
131
- disabled: n,
133
+ disabled: s,
132
134
  "aria-invalid": !!a && a.type === "error",
133
- "aria-describedby": R
135
+ "aria-describedby": I
134
136
  }
135
137
  ),
136
- J && d.length > 0 && !n && /* @__PURE__ */ t(z, { children: [
137
- he(ee, "md") ? /* @__PURE__ */ i(
138
+ J && d.length > 0 && !s && /* @__PURE__ */ t(z, { children: [
139
+ ve(ie, "md") ? /* @__PURE__ */ i(
138
140
  S,
139
141
  {
140
142
  visualType: "neutral",
141
143
  iconLeft: "close",
142
- disabled: n,
144
+ disabled: s,
143
145
  onClick: T,
144
146
  className: l["tedi-file-upload__button"],
145
- children: s("clear")
147
+ children: n("clear")
146
148
  }
147
- ) : /* @__PURE__ */ i(re, { onClick: T, iconSize: 18, title: s("clear") }),
148
- /* @__PURE__ */ i(ce, { axis: "vertical", height: 1.5, spacing: 0.5, color: "primary" })
149
+ ) : /* @__PURE__ */ i(de, { onClick: T, iconSize: 18, title: n("clear") }),
150
+ /* @__PURE__ */ i(me, { axis: "vertical", height: 1.5, spacing: 0.5, color: "primary" })
149
151
  ] }),
150
152
  /* @__PURE__ */ i(
151
153
  S,
@@ -153,26 +155,26 @@ const be = (O) => {
153
155
  ref: L,
154
156
  visualType: "neutral",
155
157
  iconLeft: "file_upload",
156
- disabled: n,
158
+ disabled: s,
157
159
  onClick: () => {
158
160
  var e;
159
161
  return (e = C.current) == null ? void 0 : e.click();
160
162
  },
161
163
  className: l["tedi-file-upload__button"],
162
164
  size: p,
163
- "aria-describedby": R,
164
- children: s("file-upload.add")
165
+ "aria-describedby": I,
166
+ children: n("file-upload.add")
165
167
  }
166
168
  )
167
169
  ] }) })
168
170
  ] }) })
169
171
  }
170
172
  ),
171
- b && /* @__PURE__ */ i(A, { ...b, id: k }),
172
- _ && /* @__PURE__ */ i(A, { ..._, id: I })
173
+ b && /* @__PURE__ */ i(A, { ...b, id: R }),
174
+ _ && /* @__PURE__ */ i(A, { ..._, id: k })
173
175
  ] });
174
176
  };
175
- be.displayName = "FileUpload";
177
+ _e.displayName = "FileUpload";
176
178
  export {
177
- be as FileUpload
179
+ _e as FileUpload
178
180
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react"),z=require("../../providers/label-provider/use-labels.cjs.js"),j=({accept:F,maxSize:s},o)=>{if(!F&&!s)return;const u=[F&&`${o("file-upload.accept")} ${F.replaceAll(",",", ")}`,s&&`${o("file-upload.max-size")} ${s}MB`].filter(Boolean).join(". ");return u.length?{text:u}:void 0},I=()=>`${Date.now()}-${Math.random().toString(36).slice(2)}`,O=100,_=F=>{const{getLabel:s}=z.useLabels(),{accept:o,maxSize:u,multiple:w=!1,validateIndividually:b=!1,defaultFiles:L=[],onChange:c,onDelete:f,files:R,announcementTimeout:S=5e3}=F,h=R!==void 0,[A,x]=a.useState(L),p=h?R:A,[C,y]=a.useState(j({accept:o,maxSize:u},s)),[H,M]=a.useState(""),v=a.useRef(!0),g=a.useRef(),T=a.useRef();a.useEffect(()=>()=>{v.current=!1,g.current&&clearTimeout(g.current),T.current&&clearTimeout(T.current)},[]);const E=a.useCallback(t=>{!t||!v.current||(M(""),g.current&&clearTimeout(g.current),T.current&&clearTimeout(T.current),g.current=setTimeout(()=>{v.current&&(M(t),T.current=setTimeout(()=>{v.current&&M("")},S))},O))},[S]),d=a.useRef(null),N=t=>{var n;if(!o)return!0;const l=o.split(",").map(e=>e.trim().toLowerCase()),r=t.name.includes(".")?`.${(n=t.name.split(".").pop())==null?void 0:n.toLowerCase()}`:"",i=t.type.toLowerCase();return l.includes(r)||l.includes(i)},U=t=>{const l=t.reduce((r,{type:i,file:n})=>(r[i].push(n.name),r),{extension:[],size:[]});return Object.entries(l).filter(([r,i])=>i.length).map(([r,i])=>{const n=i.map(e=>`'${e}'`).join(", ");return s(`file-upload.${r}-rejected`,n)}).join(". ")};return{innerFiles:p,uploadErrorHelper:C,onFileChange:t=>{if(t.target.files){const l=Array.from(t.target.files),r=[],i=l.map(e=>{const m=N(e),$=!u||e.size<=u*1024**2;m||r.push({type:"extension",file:e}),$||r.push({type:"size",file:e});const V=new File([e],e.name,{type:e.type,lastModified:e.lastModified});return Object.assign(V,{id:I(),isLoading:!1,isValid:m&&$})});let n=[];if(!w&&i.length>0)i[0].isValid&&(n=[i[0]]);else if(b)n=[...p,...i];else{const e=i.filter(m=>m.isValid);e.length>0&&(n=[...p,...e])}if(n.length>0&&(h||x(n),c==null||c(n)),r.length){const e=U(r);y({type:"error",text:e}),E(e)}else if(y(j({accept:o,maxSize:u},s)),n.length>0){const e=n.filter(m=>!p.includes(m)).length;E(s("file-upload.success-added",e.toString()))}t.target.value="",d.current&&(d.current.value="")}},onFileRemove:t=>{const l=p.filter(r=>r!==t);h||x(l),f==null||f(t),c==null||c(l),l.length===0&&y(j({accept:o,maxSize:u},s)),E(s("file-upload.removed",t.name??"")),d.current&&(d.current.value="")},handleClear:()=>{const t=[...p];return t.forEach(l=>f==null?void 0:f(l)),h||x([]),c==null||c([]),y(j({accept:o,maxSize:u},s)),E(s("file-upload.cleared")),d.current&&(d.current.value=""),t},fileInputRef:d,announcement:H}};exports.useFileUpload=_;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react"),_=require("../../providers/label-provider/use-labels.cjs.js"),q=({accept:F,maxSize:o},f)=>{if(!F&&!o)return;const p=[F&&`${f("file-upload.accept")} ${F.replaceAll(",",", ")}`,o&&`${f("file-upload.max-size")} ${o}MB`].filter(Boolean).join(". ");return p.length?{text:p}:void 0},B=()=>`${Date.now()}-${Math.random().toString(36).slice(2)}`,k=100,P=F=>{const{getLabel:o}=_.useLabels(),{accept:f,maxSize:p,multiple:$=!1,validateIndividually:b=!1,defaultFiles:H=[],onChange:l,onDelete:m,files:x,announcementTimeout:M=5e3,showRestrictions:L=!0}=F,g=x!==void 0,[A,j]=u.useState(H),c=g?x:A,C=L?q({accept:f,maxSize:p},o):void 0,[N,h]=u.useState(void 0),V=N??C,[z,w]=u.useState(""),y=u.useRef(!0),v=u.useRef(),T=u.useRef();u.useEffect(()=>()=>{y.current=!1,v.current&&clearTimeout(v.current),T.current&&clearTimeout(T.current)},[]);const E=u.useCallback(e=>{!e||!y.current||(w(""),v.current&&clearTimeout(v.current),T.current&&clearTimeout(T.current),v.current=setTimeout(()=>{y.current&&(w(e),T.current=setTimeout(()=>{y.current&&w("")},M))},k))},[M]),a=u.useRef(null),I=e=>{var i;if(!f)return!0;const s=f.split(",").map(d=>d.trim().toLowerCase()),n=e.name.includes(".")?`.${(i=e.name.split(".").pop())==null?void 0:i.toLowerCase()}`:"",r=e.type.toLowerCase();return s.includes(n)||s.includes(r)},O=e=>{const s=e.reduce((n,{type:r,file:i})=>(n[r].push(i.name),n),{extension:[],size:[]});return Object.entries(s).filter(([n,r])=>r.length).map(([n,r])=>{const i=r.map(d=>`'${d}'`).join(", ");return o(`file-upload.${n}-rejected`,i)}).join(". ")};return{innerFiles:c,uploadErrorHelper:V,onFileChange:e=>{if(e.target.files){const s=Array.from(e.target.files),n=[],r=s.map(t=>{const R=I(t),S=!p||t.size<=p*1024**2;R||n.push({type:"extension",file:t}),S||n.push({type:"size",file:t});const U=new File([t],t.name,{type:t.type,lastModified:t.lastModified});return Object.assign(U,{id:B(),isLoading:!1,isValid:R&&S})});let i;if(!$)i=r.length>0&&r[0].isValid?[r[0]]:c;else if(b)i=[...c,...r];else{const t=r.filter(R=>R.isValid);i=t.length>0?[...c,...t]:c}const d=i.filter(t=>!c.includes(t)).length;if(d>0&&!g&&j(i),l==null||l(i),n.length){const t=O(n);h({type:"error",text:t}),E(t)}else h(void 0),d>0&&E(o("file-upload.success-added",d.toString()));e.target.value="",a.current&&(a.current.value="")}},onFileRemove:e=>{const s=c.filter(n=>n!==e);g||j(s),m==null||m(e),l==null||l(s),s.length===0&&h(void 0),E(o("file-upload.removed",e.name??"")),a.current&&(a.current.value="")},handleClear:()=>{const e=[...c];return e.forEach(s=>m==null?void 0:m(s)),g||j([]),l==null||l([]),h(void 0),E(o("file-upload.cleared")),a.current&&(a.current.value=""),e},fileInputRef:a,announcement:z}};exports.useFileUpload=P;
@@ -67,6 +67,14 @@ export interface UseFileUploadProps {
67
67
  * @default 5000
68
68
  */
69
69
  announcementTimeout?: number;
70
+ /**
71
+ * Whether to show the auto-generated restrictions hint (allowed types / max size)
72
+ * below the field. Turn it off when the same information is presented elsewhere
73
+ * (e.g. a `tooltip`) to avoid a visible duplicate — rejection error messages are
74
+ * unaffected and still render.
75
+ * @default true
76
+ */
77
+ showRestrictions?: boolean;
70
78
  }
71
79
  export declare const useFileUpload: (props: UseFileUploadProps) => {
72
80
  innerFiles: FileUploadFile[];
@@ -1,102 +1,100 @@
1
- import a, { useEffect as z } from "react";
2
- import { useLabels as I } from "../../providers/label-provider/use-labels.es.js";
3
- const x = ({ accept: F, maxSize: s }, o) => {
4
- if (!F && !s) return;
5
- const u = [
6
- F && `${o("file-upload.accept")} ${F.replaceAll(",", ", ")}`,
7
- s && `${o("file-upload.max-size")} ${s}MB`
1
+ import c, { useEffect as U } from "react";
2
+ import { useLabels as B } from "../../providers/label-provider/use-labels.es.js";
3
+ const k = ({ accept: F, maxSize: o }, f) => {
4
+ if (!F && !o) return;
5
+ const p = [
6
+ F && `${f("file-upload.accept")} ${F.replaceAll(",", ", ")}`,
7
+ o && `${f("file-upload.max-size")} ${o}MB`
8
8
  ].filter(Boolean).join(". ");
9
- return u.length ? { text: u } : void 0;
10
- }, U = () => `${Date.now()}-${Math.random().toString(36).slice(2)}`, O = 100, G = (F) => {
11
- const { getLabel: s } = I(), {
12
- accept: o,
13
- maxSize: u,
14
- multiple: S = !1,
15
- validateIndividually: A = !1,
16
- defaultFiles: L = [],
17
- onChange: c,
18
- onDelete: f,
19
- files: j,
20
- announcementTimeout: w = 5e3
21
- } = F, h = j !== void 0, [C, R] = a.useState(L), p = h ? j : C, [H, v] = a.useState(
22
- x({ accept: o, maxSize: u }, s)
23
- ), [N, $] = a.useState(""), y = a.useRef(!0), T = a.useRef(), g = a.useRef();
24
- z(() => () => {
25
- y.current = !1, T.current && clearTimeout(T.current), g.current && clearTimeout(g.current);
9
+ return p.length ? { text: p } : void 0;
10
+ }, Y = () => `${Date.now()}-${Math.random().toString(36).slice(2)}`, q = 100, Q = (F) => {
11
+ const { getLabel: o } = B(), {
12
+ accept: f,
13
+ maxSize: p,
14
+ multiple: H = !1,
15
+ validateIndividually: S = !1,
16
+ defaultFiles: A = [],
17
+ onChange: l,
18
+ onDelete: m,
19
+ files: $,
20
+ announcementTimeout: j = 5e3,
21
+ showRestrictions: C = !0
22
+ } = F, h = $ !== void 0, [L, R] = c.useState(A), u = h ? $ : L, N = C ? k({ accept: f, maxSize: p }, o) : void 0, [V, g] = c.useState(void 0), _ = V ?? N, [b, w] = c.useState(""), y = c.useRef(!0), v = c.useRef(), T = c.useRef();
23
+ U(() => () => {
24
+ y.current = !1, v.current && clearTimeout(v.current), T.current && clearTimeout(T.current);
26
25
  }, []);
27
- const E = a.useCallback(
28
- (t) => {
29
- !t || !y.current || ($(""), T.current && clearTimeout(T.current), g.current && clearTimeout(g.current), T.current = setTimeout(() => {
30
- y.current && ($(t), g.current = setTimeout(() => {
31
- y.current && $("");
32
- }, w));
33
- }, O));
26
+ const E = c.useCallback(
27
+ (e) => {
28
+ !e || !y.current || (w(""), v.current && clearTimeout(v.current), T.current && clearTimeout(T.current), v.current = setTimeout(() => {
29
+ y.current && (w(e), T.current = setTimeout(() => {
30
+ y.current && w("");
31
+ }, j));
32
+ }, q));
34
33
  },
35
- [w]
36
- ), d = a.useRef(null), V = (t) => {
37
- var n;
38
- if (!o) return !0;
39
- const l = o.split(",").map((e) => e.trim().toLowerCase()), r = t.name.includes(".") ? `.${(n = t.name.split(".").pop()) == null ? void 0 : n.toLowerCase()}` : "", i = t.type.toLowerCase();
40
- return l.includes(r) || l.includes(i);
41
- }, _ = (t) => {
42
- const l = t.reduce(
43
- (r, { type: i, file: n }) => (r[i].push(n.name), r),
34
+ [j]
35
+ ), a = c.useRef(null), z = (e) => {
36
+ var i;
37
+ if (!f) return !0;
38
+ const s = f.split(",").map((d) => d.trim().toLowerCase()), n = e.name.includes(".") ? `.${(i = e.name.split(".").pop()) == null ? void 0 : i.toLowerCase()}` : "", r = e.type.toLowerCase();
39
+ return s.includes(n) || s.includes(r);
40
+ }, I = (e) => {
41
+ const s = e.reduce(
42
+ (n, { type: r, file: i }) => (n[r].push(i.name), n),
44
43
  { extension: [], size: [] }
45
44
  );
46
- return Object.entries(l).filter(([r, i]) => i.length).map(([r, i]) => {
47
- const n = i.map((e) => `'${e}'`).join(", ");
48
- return s(`file-upload.${r}-rejected`, n);
45
+ return Object.entries(s).filter(([n, r]) => r.length).map(([n, r]) => {
46
+ const i = r.map((d) => `'${d}'`).join(", ");
47
+ return o(`file-upload.${n}-rejected`, i);
49
48
  }).join(". ");
50
49
  };
51
50
  return {
52
- innerFiles: p,
53
- uploadErrorHelper: H,
54
- onFileChange: (t) => {
55
- if (t.target.files) {
56
- const l = Array.from(t.target.files), r = [], i = l.map((e) => {
57
- const m = V(e), M = !u || e.size <= u * 1024 ** 2;
58
- m || r.push({ type: "extension", file: e }), M || r.push({ type: "size", file: e });
59
- const b = new File([e], e.name, {
60
- type: e.type,
61
- lastModified: e.lastModified
51
+ innerFiles: u,
52
+ uploadErrorHelper: _,
53
+ onFileChange: (e) => {
54
+ if (e.target.files) {
55
+ const s = Array.from(e.target.files), n = [], r = s.map((t) => {
56
+ const x = z(t), M = !p || t.size <= p * 1024 ** 2;
57
+ x || n.push({ type: "extension", file: t }), M || n.push({ type: "size", file: t });
58
+ const O = new File([t], t.name, {
59
+ type: t.type,
60
+ lastModified: t.lastModified
62
61
  });
63
- return Object.assign(b, {
64
- id: U(),
62
+ return Object.assign(O, {
63
+ id: Y(),
65
64
  isLoading: !1,
66
- isValid: m && M
65
+ isValid: x && M
67
66
  });
68
67
  });
69
- let n = [];
70
- if (!S && i.length > 0)
71
- i[0].isValid && (n = [i[0]]);
72
- else if (A)
73
- n = [...p, ...i];
68
+ let i;
69
+ if (!H)
70
+ i = r.length > 0 && r[0].isValid ? [r[0]] : u;
71
+ else if (S)
72
+ i = [...u, ...r];
74
73
  else {
75
- const e = i.filter((m) => m.isValid);
76
- e.length > 0 && (n = [...p, ...e]);
74
+ const t = r.filter((x) => x.isValid);
75
+ i = t.length > 0 ? [...u, ...t] : u;
77
76
  }
78
- if (n.length > 0 && (h || R(n), c == null || c(n)), r.length) {
79
- const e = _(r);
80
- v({ type: "error", text: e }), E(e);
81
- } else if (v(x({ accept: o, maxSize: u }, s)), n.length > 0) {
82
- const e = n.filter((m) => !p.includes(m)).length;
83
- E(s("file-upload.success-added", e.toString()));
84
- }
85
- t.target.value = "", d.current && (d.current.value = "");
77
+ const d = i.filter((t) => !u.includes(t)).length;
78
+ if (d > 0 && !h && R(i), l == null || l(i), n.length) {
79
+ const t = I(n);
80
+ g({ type: "error", text: t }), E(t);
81
+ } else
82
+ g(void 0), d > 0 && E(o("file-upload.success-added", d.toString()));
83
+ e.target.value = "", a.current && (a.current.value = "");
86
84
  }
87
85
  },
88
- onFileRemove: (t) => {
89
- const l = p.filter((r) => r !== t);
90
- h || R(l), f == null || f(t), c == null || c(l), l.length === 0 && v(x({ accept: o, maxSize: u }, s)), E(s("file-upload.removed", t.name ?? "")), d.current && (d.current.value = "");
86
+ onFileRemove: (e) => {
87
+ const s = u.filter((n) => n !== e);
88
+ h || R(s), m == null || m(e), l == null || l(s), s.length === 0 && g(void 0), E(o("file-upload.removed", e.name ?? "")), a.current && (a.current.value = "");
91
89
  },
92
90
  handleClear: () => {
93
- const t = [...p];
94
- return t.forEach((l) => f == null ? void 0 : f(l)), h || R([]), c == null || c([]), v(x({ accept: o, maxSize: u }, s)), E(s("file-upload.cleared")), d.current && (d.current.value = ""), t;
91
+ const e = [...u];
92
+ return e.forEach((s) => m == null ? void 0 : m(s)), h || R([]), l == null || l([]), g(void 0), E(o("file-upload.cleared")), a.current && (a.current.value = ""), e;
95
93
  },
96
- fileInputRef: d,
97
- announcement: N
94
+ fileInputRef: a,
95
+ announcement: b
98
96
  };
99
97
  };
100
98
  export {
101
- G as useFileUpload
99
+ Q as useFileUpload
102
100
  };