zaravand-ui 7.0.2 → 7.1.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/dist/components/Input/Input.formatting.cjs +1 -1
- package/dist/components/Input/Input.formatting.js +35 -17
- package/dist/components/Input/Input.interface.d.cts +5 -1
- package/dist/components/Input/Input.interface.d.ts +5 -1
- package/dist/components/OtpInput/OtpInput.cjs +1 -0
- package/dist/components/OtpInput/OtpInput.d.cts +10 -0
- package/dist/components/OtpInput/OtpInput.d.ts +10 -0
- package/dist/components/OtpInput/OtpInput.interface.d.cts +49 -0
- package/dist/components/OtpInput/OtpInput.interface.d.ts +49 -0
- package/dist/components/OtpInput/OtpInput.js +150 -0
- package/dist/components/OtpInput/OtpInput.variant.cjs +1 -0
- package/dist/components/OtpInput/OtpInput.variant.d.cts +6 -0
- package/dist/components/OtpInput/OtpInput.variant.d.ts +6 -0
- package/dist/components/OtpInput/OtpInput.variant.js +15 -0
- package/dist/components/Table/Table.cjs +1 -1
- package/dist/components/Table/Table.interface.d.cts +42 -1
- package/dist/components/Table/Table.interface.d.ts +42 -1
- package/dist/components/Table/Table.js +414 -373
- package/dist/components/Table/Table.utils.cjs +1 -1
- package/dist/components/Table/Table.utils.d.cts +2 -0
- package/dist/components/Table/Table.utils.d.ts +2 -0
- package/dist/components/Table/Table.utils.js +20 -16
- package/dist/components/Table/TableActionsContext.cjs +1 -0
- package/dist/components/Table/TableActionsContext.d.cts +26 -0
- package/dist/components/Table/TableActionsContext.d.ts +26 -0
- package/dist/components/Table/TableActionsContext.js +5 -0
- package/dist/components/Table/TableActiveFilters.d.cts +1 -1
- package/dist/components/Table/TableActiveFilters.d.ts +1 -1
- package/dist/components/Table/TableColumnFilter.cjs +1 -1
- package/dist/components/Table/TableColumnFilter.d.cts +3 -0
- package/dist/components/Table/TableColumnFilter.d.ts +3 -0
- package/dist/components/Table/TableColumnFilter.js +58 -28
- package/dist/components/Table/TableFilterRegistry.cjs +1 -0
- package/dist/components/Table/TableFilterRegistry.d.cts +13 -0
- package/dist/components/Table/TableFilterRegistry.d.ts +13 -0
- package/dist/components/Table/TableFilterRegistry.js +5 -0
- package/dist/components/Table/TableParts.cjs +1 -1
- package/dist/components/Table/TableParts.js +56 -34
- package/dist/components/Table/TableRowActions.cjs +1 -0
- package/dist/components/Table/TableRowActions.d.cts +14 -0
- package/dist/components/Table/TableRowActions.d.ts +14 -0
- package/dist/components/Table/TableRowActions.js +110 -0
- package/dist/components/VerticalTabs/VerticalTabs.cjs +1 -0
- package/dist/components/VerticalTabs/VerticalTabs.d.cts +4 -0
- package/dist/components/VerticalTabs/VerticalTabs.d.ts +4 -0
- package/dist/components/VerticalTabs/VerticalTabs.interface.d.cts +41 -0
- package/dist/components/VerticalTabs/VerticalTabs.interface.d.ts +41 -0
- package/dist/components/VerticalTabs/VerticalTabs.js +196 -0
- package/dist/components/VerticalTabs/VerticalTabs.variant.cjs +1 -0
- package/dist/components/VerticalTabs/VerticalTabs.variant.d.cts +19 -0
- package/dist/components/VerticalTabs/VerticalTabs.variant.d.ts +19 -0
- package/dist/components/VerticalTabs/VerticalTabs.variant.js +48 -0
- package/dist/components/shared/responsiveScale.cjs +1 -1
- package/dist/components/shared/responsiveScale.d.cts +3 -1
- package/dist/components/shared/responsiveScale.d.ts +3 -1
- package/dist/components/shared/responsiveScale.js +2 -2
- package/dist/config/messages.cjs +1 -1
- package/dist/config/messages.d.cts +4 -0
- package/dist/config/messages.d.ts +4 -0
- package/dist/config/messages.js +2 -0
- package/dist/index.cjs +1 -1
- package/dist/index.css +1 -1
- package/dist/index.d.cts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +20 -16
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../services/convertToEnglishDigits/convertToEnglishDigits.cjs`),t=require(`../../services/convertToPersianDigits/convertToPersianDigits.cjs`);var n=11;function r(t){return e.convertToEnglishDigits({value:t})}function i(e){return r(e).replace(/\D/g,``)}function a(e){return e.replace(/^0+(?=\d)/,``)}function o(e){return e.replace(/\B(?=(\d{3})+(?!\d))/g,`,`)}function s(e){let t=a(e);if(t===``)return t;let n=Number(t);return Number.isNaN(n)?t:n>100?`100`:String(n)}function c(e){let t=!1,n=``;for(let i of r(e).replace(/٫/g,`.`))/\d/.test(i)?n+=i:i===`.`&&!t&&(n+=i,t=!0);return n}function l(e){return e===``?``:(e[0]===`0`?e:`0${e}`).slice(0,n)}function u(e,t){let n=[],r=0;for(let i of t)n.push(e.slice(r,r+i)),r+=i;return n.filter(Boolean).join(`-`)}function d(e,t){let n=0;for(let r=0;r<t&&r<e.length;r+=1)/[0-9]/.test(e[r])&&(n+=1);return n}function f(e,t){let n=0,r=!1;for(let i=0;i<t&&i<e.length;i+=1){let t=e[i];/\d/.test(t)?n+=1:t===`.`&&!r&&(n+=1,r=!0)}return n}function p(e,t){if(t<=0)return 0;let n=0;for(let r=0;r<e.length;r+=1)if(/[0-9]/.test(e[r])&&(n+=1,n===t))return r+1;return e.length}function m(e){return(t,n)=>{let i=r(t),a=e(i);return{value:a,caret:Math.min(d(i,n),a.length)}}}function h(e){return(t,n)=>{let i=r(t),a=d(i,n),o=i.replace(/\D/g,``),s=l(o),c=+(o!==``&&o[0]!==`0`),f=u(s,e);return{value:f,caret:p(f,Math.min(a+c,s.length))}}}var g={normalize:e=>e,isFormatted:!1,isCentered:!1},
|
|
1
|
+
const e=require(`../../services/convertToEnglishDigits/convertToEnglishDigits.cjs`),t=require(`../../services/convertToPersianDigits/convertToPersianDigits.cjs`);var n=11;function r(t){return e.convertToEnglishDigits({value:t})}function i(e){return r(e).replace(/\D/g,``)}function a(e){return e.replace(/^0+(?=\d)/,``)}function o(e){return e.replace(/\B(?=(\d{3})+(?!\d))/g,`,`)}function s(e){let t=a(e);if(t===``)return t;let n=Number(t);return Number.isNaN(n)?t:n>100?`100`:String(n)}function c(e){let t=!1,n=``;for(let i of r(e).replace(/٫/g,`.`))/\d/.test(i)?n+=i:i===`.`&&!t&&(n+=i,t=!0);return n}function l(e){return e===``?``:(e[0]===`0`?e:`0${e}`).slice(0,n)}function u(e,t){let n=[],r=0;for(let i of t)n.push(e.slice(r,r+i)),r+=i;return n.filter(Boolean).join(`-`)}function d(e,t){let n=0;for(let r=0;r<t&&r<e.length;r+=1)/[0-9]/.test(e[r])&&(n+=1);return n}function f(e,t){let n=0,r=!1;for(let i=0;i<t&&i<e.length;i+=1){let t=e[i];/\d/.test(t)?n+=1:t===`.`&&!r&&(n+=1,r=!0)}return n}function p(e,t){if(t<=0)return 0;let n=0;for(let r=0;r<e.length;r+=1)if(/[0-9]/.test(e[r])&&(n+=1,n===t))return r+1;return e.length}function m(e){return(t,n)=>{let i=r(t),a=e(i);return{value:a,caret:Math.min(d(i,n),a.length)}}}function h(e){return(t,n)=>{let i=r(t),a=d(i,n),o=i.replace(/\D/g,``),s=l(o),c=+(o!==``&&o[0]!==`0`),f=u(s,e);return{value:f,caret:p(f,Math.min(a+c,s.length))}}}var g=/[\p{L}\p{M}\u200c ]/u;function _(e){return v(e,e.length).value}function v(e,t){let n=``,r=0,i=0;for(let a of e)g.test(a)&&!(a===` `&&n===``)&&(n+=a,i<t&&(r+=a.length)),i+=a.length;return{value:n,caret:r}}var y={normalize:e=>e,isFormatted:!1,isCentered:!1},b={text:y,search:y,username:{...y,isCentered:!0},name:{normalize:_,format:v,isFormatted:!1,isCentered:!1},password:{...y,isCentered:!0},number:{normalize:i,format:m(i),inputMode:`numeric`,isFormatted:!0,isCentered:!0},year:{normalize:e=>i(e).slice(0,4),format:m(e=>i(e).slice(0,4)),inputMode:`numeric`,maxLength:4,isFormatted:!0,isCentered:!0},money:{normalize:e=>o(a(i(e))),format:(e,t)=>{let n=r(e),i=d(n,t),s=n.replace(/\D/g,``),c=a(s),l=Math.min(s.length-c.length,i),u=o(c);return{value:u,caret:p(u,i-l)}},inputMode:`numeric`,isFormatted:!0,isCentered:!0},percent:{normalize:e=>s(i(e)),format:m(e=>s(i(e))),displayPrefix:`%`,inputMode:`numeric`,isFormatted:!0,isCentered:!0},decimal:{normalize:c,format:(e,t)=>{let n=r(e).replace(/٫/g,`.`),i=c(n);return{value:i,caret:Math.min(f(n,t),i.length)}},inputMode:`decimal`,isFormatted:!0,isCentered:!0},phone:{normalize:e=>u(l(i(e)),[4,3,4]),format:h([4,3,4]),inputMode:`numeric`,maxLength:13,isFormatted:!0,isCentered:!0},landline:{normalize:e=>u(l(i(e)),[3,4,4]),format:h([3,4,4]),inputMode:`numeric`,maxLength:13,isFormatted:!0,isCentered:!0}};function x(e){return b[e]??y}function S(e){return e==null?``:Array.isArray(e)?e.join(`, `):String(e)}function C(e,t){return x(t).normalize(S(e))}function w(e,n,r){let i=x(n).displayPrefix,a=i&&e!==``?`${i}${e}`:e;return r?t.convertToPersianDigits({value:a}):a}function T(e,n,i,a,o){let s=x(e);if(!s.format){let e=i===null?null:[i,a??i];return{asciiValue:r(n),asciiSelection:e,displayValue:o?t.convertToPersianDigits({value:r(n)}):null,displaySelection:o?e:null}}let{value:c,caret:l}=s.format(n,i??r(n).length),u=l+(s.displayPrefix&&c!==``?s.displayPrefix.length:0);return{asciiValue:c,asciiSelection:[l,l],displayValue:o?w(c,e,!0):null,displaySelection:o?[u,u]:null}}exports.applyInputChange=T,exports.resolveAsciiValue=C,exports.resolveDisplayValue=w,exports.resolveInputTypeStrategy=x;
|
|
@@ -70,19 +70,37 @@ function h(e) {
|
|
|
70
70
|
};
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
|
-
var g = {
|
|
73
|
+
var g = /[\p{L}\p{M}\u200c ]/u;
|
|
74
|
+
function _(e) {
|
|
75
|
+
return v(e, e.length).value;
|
|
76
|
+
}
|
|
77
|
+
function v(e, t) {
|
|
78
|
+
let n = "", r = 0, i = 0;
|
|
79
|
+
for (let a of e) g.test(a) && !(a === " " && n === "") && (n += a, i < t && (r += a.length)), i += a.length;
|
|
80
|
+
return {
|
|
81
|
+
value: n,
|
|
82
|
+
caret: r
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
var y = {
|
|
74
86
|
normalize: (e) => e,
|
|
75
87
|
isFormatted: !1,
|
|
76
88
|
isCentered: !1
|
|
77
|
-
},
|
|
78
|
-
text:
|
|
79
|
-
search:
|
|
89
|
+
}, b = {
|
|
90
|
+
text: y,
|
|
91
|
+
search: y,
|
|
80
92
|
username: {
|
|
81
|
-
...
|
|
93
|
+
...y,
|
|
82
94
|
isCentered: !0
|
|
83
95
|
},
|
|
96
|
+
name: {
|
|
97
|
+
normalize: _,
|
|
98
|
+
format: v,
|
|
99
|
+
isFormatted: !1,
|
|
100
|
+
isCentered: !1
|
|
101
|
+
},
|
|
84
102
|
password: {
|
|
85
|
-
...
|
|
103
|
+
...y,
|
|
86
104
|
isCentered: !0
|
|
87
105
|
},
|
|
88
106
|
number: {
|
|
@@ -167,21 +185,21 @@ var g = {
|
|
|
167
185
|
isCentered: !0
|
|
168
186
|
}
|
|
169
187
|
};
|
|
170
|
-
function
|
|
171
|
-
return
|
|
188
|
+
function x(e) {
|
|
189
|
+
return b[e] ?? y;
|
|
172
190
|
}
|
|
173
|
-
function
|
|
191
|
+
function S(e) {
|
|
174
192
|
return e == null ? "" : Array.isArray(e) ? e.join(", ") : String(e);
|
|
175
193
|
}
|
|
176
|
-
function
|
|
177
|
-
return
|
|
194
|
+
function C(e, t) {
|
|
195
|
+
return x(t).normalize(S(e));
|
|
178
196
|
}
|
|
179
|
-
function
|
|
180
|
-
let i =
|
|
197
|
+
function w(e, n, r) {
|
|
198
|
+
let i = x(n).displayPrefix, a = i && e !== "" ? `${i}${e}` : e;
|
|
181
199
|
return r ? t({ value: a }) : a;
|
|
182
200
|
}
|
|
183
|
-
function
|
|
184
|
-
let s =
|
|
201
|
+
function T(e, n, i, a, o) {
|
|
202
|
+
let s = x(e);
|
|
185
203
|
if (!s.format) {
|
|
186
204
|
let e = i === null ? null : [i, a ?? i];
|
|
187
205
|
return {
|
|
@@ -195,9 +213,9 @@ function S(e, n, i, a, o) {
|
|
|
195
213
|
return {
|
|
196
214
|
asciiValue: c,
|
|
197
215
|
asciiSelection: [l, l],
|
|
198
|
-
displayValue: o ?
|
|
216
|
+
displayValue: o ? w(c, e, !0) : null,
|
|
199
217
|
displaySelection: o ? [u, u] : null
|
|
200
218
|
};
|
|
201
219
|
}
|
|
202
220
|
//#endregion
|
|
203
|
-
export {
|
|
221
|
+
export { T as applyInputChange, C as resolveAsciiValue, w as resolveDisplayValue, x as resolveInputTypeStrategy };
|
|
@@ -4,7 +4,11 @@ import { inputVariants } from "./Input.variant.cjs";
|
|
|
4
4
|
/** Native `<input>` attributes that are passed straight through to the input element. */
|
|
5
5
|
type InputNativeProps = Omit<React.InputHTMLAttributes<HTMLInputElement>, "type" | "size" | "title" | "value" | "defaultValue" | "children" | "dangerouslySetInnerHTML">;
|
|
6
6
|
export interface InputProps extends InputNativeProps, VariantProps<typeof inputVariants> {
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Formats what is typed. `name` keeps only letters of any script, combining marks, spaces and
|
|
9
|
+
* the Persian half-space (digits and symbols are dropped).
|
|
10
|
+
*/
|
|
11
|
+
type?: "number" | "password" | "text" | "search" | "money" | "username" | "name" | "percent" | "decimal" | "year" | "phone" | "landline";
|
|
8
12
|
/** Label rendered above the input (not the native `title` tooltip). */
|
|
9
13
|
title?: string;
|
|
10
14
|
required?: boolean;
|
|
@@ -4,7 +4,11 @@ import { inputVariants } from "./Input.variant.js";
|
|
|
4
4
|
/** Native `<input>` attributes that are passed straight through to the input element. */
|
|
5
5
|
type InputNativeProps = Omit<React.InputHTMLAttributes<HTMLInputElement>, "type" | "size" | "title" | "value" | "defaultValue" | "children" | "dangerouslySetInnerHTML">;
|
|
6
6
|
export interface InputProps extends InputNativeProps, VariantProps<typeof inputVariants> {
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Formats what is typed. `name` keeps only letters of any script, combining marks, spaces and
|
|
9
|
+
* the Persian half-space (digits and symbols are dropped).
|
|
10
|
+
*/
|
|
11
|
+
type?: "number" | "password" | "text" | "search" | "money" | "username" | "name" | "percent" | "decimal" | "year" | "phone" | "landline";
|
|
8
12
|
/** Label rendered above the input (not the native `title` tooltip). */
|
|
9
13
|
title?: string;
|
|
10
14
|
required?: boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";const e=require(`../../_virtual/_rolldown/runtime.cjs`),t=require(`../../config/useZuiConfig.cjs`),n=require(`../../services/convertToEnglishDigits/convertToEnglishDigits.cjs`),r=require(`../../services/localizeDigits/localizeDigits.cjs`),i=require(`../../lib/utils.cjs`),a=require(`../shared/FieldLabel.cjs`),o=require(`../shared/useInvalidState.cjs`),s=require(`../shared/useControllableState.cjs`),c=require(`../shared/RequiredValidationInput.cjs`),l=require(`./OtpInput.variant.cjs`);let u=require(`react`);u=e.__toESM(u,1);let d=require(`react/jsx-runtime`);var f=6;function p(e,t,r){let i=n.convertToEnglishDigits({value:e});return(t===`number`?i.replace(/\D/g,``):i.replace(/[^A-Za-z0-9]/g,``)).slice(0,r)}var m=u.forwardRef(function({length:e=f,type:n=`number`,value:m,defaultValue:h,onChange:g,onComplete:_,title:v,required:y=!1,showRequiredMessage:b=!1,mask:x=!1,disabled:S=!1,readOnly:C=!1,invalid:w=!1,autoFocus:T=!1,groupSize:E,name:D,form:O,id:k,"aria-label":ee,onInvalid:A,wrapperClassName:j,className:M,inputClassName:N},P){let{messages:F,digits:I,dir:L}=t.useZuiConfig(),R=Math.max(1,Math.floor(e)),z=u.useId(),B=k??z,V=`${B}-label`,H=u.useRef([]),{isInvalid:U,setIsInvalid:W,handleInvalid:G}=o.useInvalidState(A),[K,q]=s.useControllableState({value:m===void 0?void 0:p(m,n,R),defaultValue:()=>p(h??``,n,R),onChange:g}),J=u.useRef(K);J.current=K;let Y=u.useCallback(e=>{let t=H.current[Math.min(Math.max(e,0),R-1)];t?.focus(),t?.select()},[R]);u.useEffect(()=>{T&&!S&&!C&&Y(K.length)},[]);let X=(e,t)=>{W(!1),e!==K&&(J.current=e,q(e),e.length===R&&_?.(e)),Y(t)},Z=(e,t)=>{if(S||C)return;let r=t.target.value,i=K[e]??``;if(r===``){X(K.slice(0,e)+K.slice(e+1),e);return}let a=p(i!==``&&r.length>1&&r.replace(i,``)||r,n,R-e);a!==``&&X((K.slice(0,e)+a+K.slice(e+a.length)).slice(0,R),e+a.length)},Q=(e,t)=>{switch(t.key){case`Backspace`:!C&&!S&&(K[e]??``)===``&&e>0&&(t.preventDefault(),X(K.slice(0,e-1)+K.slice(e),e-1));break;case`Delete`:!C&&!S&&(t.preventDefault(),X(K.slice(0,e)+K.slice(e+1),e));break;case`ArrowLeft`:t.preventDefault(),Y(e-1);break;case`ArrowRight`:t.preventDefault(),Y(Math.min(e+1,K.length));break;case`Home`:t.preventDefault(),Y(0);break;case`End`:t.preventDefault(),Y(K.length);break;default:break}},te=(e,t)=>{if(e>J.current.length){Y(J.current.length);return}t.target.select()},ne=w||U,re=r.localizeDigits(String(R),I),$=[];for(let e=0;e<R;e+=1){let t=K[e]??``,a=r.localizeDigits(String(e+1),I);$.push((0,d.jsxs)(`div`,{"data-slot":`otp-input-cell`,className:l.otpInputCellVariants(),children:[(0,d.jsx)(`input`,{ref:t=>{H.current[e]=t},id:e===0?B:`${B}-${e+1}`,"data-slot":`otp-input-box`,type:x?`password`:`text`,inputMode:n===`number`?`numeric`:`text`,autoComplete:e===0?`one-time-code`:`off`,autoCapitalize:`off`,autoCorrect:`off`,spellCheck:!1,"aria-label":F.otp.digitLabel(a,re),"aria-invalid":ne||void 0,"data-has-value":t!==``,disabled:S,readOnly:C,value:r.localizeDigits(t,I),onChange:t=>Z(e,t),onKeyDown:t=>Q(e,t),onFocus:t=>te(e,t),className:i.cn(l.otpInputBoxVariants(),N)}),t===``?null:(0,d.jsx)(`span`,{"aria-hidden":`true`,"data-slot":`otp-input-digit`,className:l.otpInputDigitVariants(),children:x?`•`:r.localizeDigits(t,I)},t)]},e)),E&&E>0&&(e+1)%E===0&&e+1<R&&$.push((0,d.jsx)(`span`,{"aria-hidden":`true`,"data-slot":`otp-input-separator`,className:l.otpInputSeparatorVariants()},`separator-${e}`))}return(0,d.jsxs)(`div`,{ref:P,"data-slot":`otp-input`,dir:L,className:i.cn(`zui:relative zui:w-full zui:space-y-1.5 zui:text-start`,j),children:[(0,d.jsx)(a.FieldLabel,{id:V,title:v,required:y,showRequiredMessage:b}),(0,d.jsx)(`div`,{role:`group`,"aria-label":v?void 0:ee,"aria-labelledby":v?V:void 0,dir:`ltr`,className:i.cn(l.otpInputRowVariants(),M),children:$}),D?(0,d.jsx)(`input`,{type:`hidden`,name:D,form:O,value:K,disabled:S}):null,y?(0,d.jsx)(c.default,{"data-slot":`otp-input-required`,hasValue:K.length===R,disabled:S,form:O,onInvalid:G}):null]})});exports.default=m;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { OtpInputProps } from "./OtpInput.interface.cjs";
|
|
3
|
+
/**
|
|
4
|
+
* A one-time code (SMS / e-mail verification) typed into one box per character. The code is one
|
|
5
|
+
* contiguous string: typing fills the next box, Backspace removes the previous character, and a
|
|
6
|
+
* paste or an autofilled code is spread over the boxes. The boxes always read left to right, like
|
|
7
|
+
* the digits of the code.
|
|
8
|
+
*/
|
|
9
|
+
declare const OtpInput: React.ForwardRefExoticComponent<OtpInputProps & React.RefAttributes<HTMLDivElement>>;
|
|
10
|
+
export default OtpInput;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { OtpInputProps } from "./OtpInput.interface.js";
|
|
3
|
+
/**
|
|
4
|
+
* A one-time code (SMS / e-mail verification) typed into one box per character. The code is one
|
|
5
|
+
* contiguous string: typing fills the next box, Backspace removes the previous character, and a
|
|
6
|
+
* paste or an autofilled code is spread over the boxes. The boxes always read left to right, like
|
|
7
|
+
* the digits of the code.
|
|
8
|
+
*/
|
|
9
|
+
declare const OtpInput: React.ForwardRefExoticComponent<OtpInputProps & React.RefAttributes<HTMLDivElement>>;
|
|
10
|
+
export default OtpInput;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
export interface OtpInputProps {
|
|
3
|
+
/** Number of boxes. @default 6 */
|
|
4
|
+
length?: number;
|
|
5
|
+
/**
|
|
6
|
+
* What the boxes accept: `number` takes digits only (Persian and Arabic digits are converted),
|
|
7
|
+
* `text` takes letters and digits.
|
|
8
|
+
* @default "number"
|
|
9
|
+
*/
|
|
10
|
+
type?: "number" | "text";
|
|
11
|
+
/** The code typed so far, as ASCII. Without it the component keeps the code itself. */
|
|
12
|
+
value?: string;
|
|
13
|
+
defaultValue?: string;
|
|
14
|
+
/** Called on every edit with the code typed so far (fewer characters than `length` until full). */
|
|
15
|
+
onChange?: (value: string) => void;
|
|
16
|
+
/** Called once, with the whole code, when the last box gets filled. */
|
|
17
|
+
onComplete?: (value: string) => void;
|
|
18
|
+
/** Label rendered above the boxes. */
|
|
19
|
+
title?: string;
|
|
20
|
+
required?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* When true and `required` is true, shows a "این فیلد اجباری است" hint next to the required star.
|
|
23
|
+
* @default false
|
|
24
|
+
*/
|
|
25
|
+
showRequiredMessage?: boolean;
|
|
26
|
+
/** Shows the characters as dots, like a password. */
|
|
27
|
+
mask?: boolean;
|
|
28
|
+
disabled?: boolean;
|
|
29
|
+
readOnly?: boolean;
|
|
30
|
+
/** Marks the boxes as wrong (for example after the server rejected the code). */
|
|
31
|
+
invalid?: boolean;
|
|
32
|
+
/** Focuses the first empty box when the component mounts. */
|
|
33
|
+
autoFocus?: boolean;
|
|
34
|
+
/** Draws a small dash after every `groupSize` boxes (for example 3 for `123-456`). */
|
|
35
|
+
groupSize?: number;
|
|
36
|
+
/** Name of the hidden field that carries the whole code in a native `<form>`. */
|
|
37
|
+
name?: string;
|
|
38
|
+
form?: string;
|
|
39
|
+
id?: string;
|
|
40
|
+
"aria-label"?: string;
|
|
41
|
+
/** Called when a native `<form>` rejects an incomplete `required` code. */
|
|
42
|
+
onInvalid?: React.FormEventHandler<HTMLInputElement>;
|
|
43
|
+
/** Applied to the outer field wrapper (label + boxes). */
|
|
44
|
+
wrapperClassName?: string;
|
|
45
|
+
/** Applied to the row of boxes. */
|
|
46
|
+
className?: string;
|
|
47
|
+
/** Applied to every box. */
|
|
48
|
+
inputClassName?: string;
|
|
49
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
export interface OtpInputProps {
|
|
3
|
+
/** Number of boxes. @default 6 */
|
|
4
|
+
length?: number;
|
|
5
|
+
/**
|
|
6
|
+
* What the boxes accept: `number` takes digits only (Persian and Arabic digits are converted),
|
|
7
|
+
* `text` takes letters and digits.
|
|
8
|
+
* @default "number"
|
|
9
|
+
*/
|
|
10
|
+
type?: "number" | "text";
|
|
11
|
+
/** The code typed so far, as ASCII. Without it the component keeps the code itself. */
|
|
12
|
+
value?: string;
|
|
13
|
+
defaultValue?: string;
|
|
14
|
+
/** Called on every edit with the code typed so far (fewer characters than `length` until full). */
|
|
15
|
+
onChange?: (value: string) => void;
|
|
16
|
+
/** Called once, with the whole code, when the last box gets filled. */
|
|
17
|
+
onComplete?: (value: string) => void;
|
|
18
|
+
/** Label rendered above the boxes. */
|
|
19
|
+
title?: string;
|
|
20
|
+
required?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* When true and `required` is true, shows a "این فیلد اجباری است" hint next to the required star.
|
|
23
|
+
* @default false
|
|
24
|
+
*/
|
|
25
|
+
showRequiredMessage?: boolean;
|
|
26
|
+
/** Shows the characters as dots, like a password. */
|
|
27
|
+
mask?: boolean;
|
|
28
|
+
disabled?: boolean;
|
|
29
|
+
readOnly?: boolean;
|
|
30
|
+
/** Marks the boxes as wrong (for example after the server rejected the code). */
|
|
31
|
+
invalid?: boolean;
|
|
32
|
+
/** Focuses the first empty box when the component mounts. */
|
|
33
|
+
autoFocus?: boolean;
|
|
34
|
+
/** Draws a small dash after every `groupSize` boxes (for example 3 for `123-456`). */
|
|
35
|
+
groupSize?: number;
|
|
36
|
+
/** Name of the hidden field that carries the whole code in a native `<form>`. */
|
|
37
|
+
name?: string;
|
|
38
|
+
form?: string;
|
|
39
|
+
id?: string;
|
|
40
|
+
"aria-label"?: string;
|
|
41
|
+
/** Called when a native `<form>` rejects an incomplete `required` code. */
|
|
42
|
+
onInvalid?: React.FormEventHandler<HTMLInputElement>;
|
|
43
|
+
/** Applied to the outer field wrapper (label + boxes). */
|
|
44
|
+
wrapperClassName?: string;
|
|
45
|
+
/** Applied to the row of boxes. */
|
|
46
|
+
className?: string;
|
|
47
|
+
/** Applied to every box. */
|
|
48
|
+
inputClassName?: string;
|
|
49
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useZuiConfig as e } from "../../config/useZuiConfig.js";
|
|
3
|
+
import { convertToEnglishDigits as t } from "../../services/convertToEnglishDigits/convertToEnglishDigits.js";
|
|
4
|
+
import { localizeDigits as n } from "../../services/localizeDigits/localizeDigits.js";
|
|
5
|
+
import { cn as r } from "../../lib/utils.js";
|
|
6
|
+
import { FieldLabel as i } from "../shared/FieldLabel.js";
|
|
7
|
+
import { useInvalidState as a } from "../shared/useInvalidState.js";
|
|
8
|
+
import { useControllableState as o } from "../shared/useControllableState.js";
|
|
9
|
+
import s from "../shared/RequiredValidationInput.js";
|
|
10
|
+
import { otpInputBoxVariants as c, otpInputCellVariants as l, otpInputDigitVariants as u, otpInputRowVariants as ee, otpInputSeparatorVariants as d } from "./OtpInput.variant.js";
|
|
11
|
+
import * as f from "react";
|
|
12
|
+
import { jsx as p, jsxs as m } from "react/jsx-runtime";
|
|
13
|
+
//#region src/components/OtpInput/OtpInput.tsx
|
|
14
|
+
var h = 6;
|
|
15
|
+
function g(e, n, r) {
|
|
16
|
+
let i = t({ value: e });
|
|
17
|
+
return (n === "number" ? i.replace(/\D/g, "") : i.replace(/[^A-Za-z0-9]/g, "")).slice(0, r);
|
|
18
|
+
}
|
|
19
|
+
var _ = f.forwardRef(function({ length: t = h, type: _ = "number", value: v, defaultValue: y, onChange: b, onComplete: x, title: S, required: C = !1, showRequiredMessage: te = !1, mask: w = !1, disabled: T = !1, readOnly: E = !1, invalid: ne = !1, autoFocus: re = !1, groupSize: D, name: O, form: k, id: A, "aria-label": j, onInvalid: M, wrapperClassName: N, className: P, inputClassName: F }, I) {
|
|
20
|
+
let { messages: L, digits: R, dir: z } = e(), B = Math.max(1, Math.floor(t)), V = f.useId(), H = A ?? V, U = `${H}-label`, W = f.useRef([]), { isInvalid: G, setIsInvalid: K, handleInvalid: q } = a(M), [J, Y] = o({
|
|
21
|
+
value: v === void 0 ? void 0 : g(v, _, B),
|
|
22
|
+
defaultValue: () => g(y ?? "", _, B),
|
|
23
|
+
onChange: b
|
|
24
|
+
}), X = f.useRef(J);
|
|
25
|
+
X.current = J;
|
|
26
|
+
let Z = f.useCallback((e) => {
|
|
27
|
+
let t = W.current[Math.min(Math.max(e, 0), B - 1)];
|
|
28
|
+
t?.focus(), t?.select();
|
|
29
|
+
}, [B]);
|
|
30
|
+
f.useEffect(() => {
|
|
31
|
+
re && !T && !E && Z(J.length);
|
|
32
|
+
}, []);
|
|
33
|
+
let Q = (e, t) => {
|
|
34
|
+
K(!1), e !== J && (X.current = e, Y(e), e.length === B && x?.(e)), Z(t);
|
|
35
|
+
}, ie = (e, t) => {
|
|
36
|
+
if (T || E) return;
|
|
37
|
+
let n = t.target.value, r = J[e] ?? "";
|
|
38
|
+
if (n === "") {
|
|
39
|
+
Q(J.slice(0, e) + J.slice(e + 1), e);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
let i = g(r !== "" && n.length > 1 && n.replace(r, "") || n, _, B - e);
|
|
43
|
+
i !== "" && Q((J.slice(0, e) + i + J.slice(e + i.length)).slice(0, B), e + i.length);
|
|
44
|
+
}, ae = (e, t) => {
|
|
45
|
+
switch (t.key) {
|
|
46
|
+
case "Backspace":
|
|
47
|
+
!E && !T && (J[e] ?? "") === "" && e > 0 && (t.preventDefault(), Q(J.slice(0, e - 1) + J.slice(e), e - 1));
|
|
48
|
+
break;
|
|
49
|
+
case "Delete":
|
|
50
|
+
!E && !T && (t.preventDefault(), Q(J.slice(0, e) + J.slice(e + 1), e));
|
|
51
|
+
break;
|
|
52
|
+
case "ArrowLeft":
|
|
53
|
+
t.preventDefault(), Z(e - 1);
|
|
54
|
+
break;
|
|
55
|
+
case "ArrowRight":
|
|
56
|
+
t.preventDefault(), Z(Math.min(e + 1, J.length));
|
|
57
|
+
break;
|
|
58
|
+
case "Home":
|
|
59
|
+
t.preventDefault(), Z(0);
|
|
60
|
+
break;
|
|
61
|
+
case "End":
|
|
62
|
+
t.preventDefault(), Z(J.length);
|
|
63
|
+
break;
|
|
64
|
+
default: break;
|
|
65
|
+
}
|
|
66
|
+
}, oe = (e, t) => {
|
|
67
|
+
if (e > X.current.length) {
|
|
68
|
+
Z(X.current.length);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
t.target.select();
|
|
72
|
+
}, se = ne || G, ce = n(String(B), R), $ = [];
|
|
73
|
+
for (let e = 0; e < B; e += 1) {
|
|
74
|
+
let t = J[e] ?? "", i = n(String(e + 1), R);
|
|
75
|
+
$.push(/* @__PURE__ */ m("div", {
|
|
76
|
+
"data-slot": "otp-input-cell",
|
|
77
|
+
className: l(),
|
|
78
|
+
children: [/* @__PURE__ */ p("input", {
|
|
79
|
+
ref: (t) => {
|
|
80
|
+
W.current[e] = t;
|
|
81
|
+
},
|
|
82
|
+
id: e === 0 ? H : `${H}-${e + 1}`,
|
|
83
|
+
"data-slot": "otp-input-box",
|
|
84
|
+
type: w ? "password" : "text",
|
|
85
|
+
inputMode: _ === "number" ? "numeric" : "text",
|
|
86
|
+
autoComplete: e === 0 ? "one-time-code" : "off",
|
|
87
|
+
autoCapitalize: "off",
|
|
88
|
+
autoCorrect: "off",
|
|
89
|
+
spellCheck: !1,
|
|
90
|
+
"aria-label": L.otp.digitLabel(i, ce),
|
|
91
|
+
"aria-invalid": se || void 0,
|
|
92
|
+
"data-has-value": t !== "",
|
|
93
|
+
disabled: T,
|
|
94
|
+
readOnly: E,
|
|
95
|
+
value: n(t, R),
|
|
96
|
+
onChange: (t) => ie(e, t),
|
|
97
|
+
onKeyDown: (t) => ae(e, t),
|
|
98
|
+
onFocus: (t) => oe(e, t),
|
|
99
|
+
className: r(c(), F)
|
|
100
|
+
}), t === "" ? null : /* @__PURE__ */ p("span", {
|
|
101
|
+
"aria-hidden": "true",
|
|
102
|
+
"data-slot": "otp-input-digit",
|
|
103
|
+
className: u(),
|
|
104
|
+
children: w ? "•" : n(t, R)
|
|
105
|
+
}, t)]
|
|
106
|
+
}, e)), D && D > 0 && (e + 1) % D === 0 && e + 1 < B && $.push(/* @__PURE__ */ p("span", {
|
|
107
|
+
"aria-hidden": "true",
|
|
108
|
+
"data-slot": "otp-input-separator",
|
|
109
|
+
className: d()
|
|
110
|
+
}, `separator-${e}`));
|
|
111
|
+
}
|
|
112
|
+
return /* @__PURE__ */ m("div", {
|
|
113
|
+
ref: I,
|
|
114
|
+
"data-slot": "otp-input",
|
|
115
|
+
dir: z,
|
|
116
|
+
className: r("zui:relative zui:w-full zui:space-y-1.5 zui:text-start", N),
|
|
117
|
+
children: [
|
|
118
|
+
/* @__PURE__ */ p(i, {
|
|
119
|
+
id: U,
|
|
120
|
+
title: S,
|
|
121
|
+
required: C,
|
|
122
|
+
showRequiredMessage: te
|
|
123
|
+
}),
|
|
124
|
+
/* @__PURE__ */ p("div", {
|
|
125
|
+
role: "group",
|
|
126
|
+
"aria-label": S ? void 0 : j,
|
|
127
|
+
"aria-labelledby": S ? U : void 0,
|
|
128
|
+
dir: "ltr",
|
|
129
|
+
className: r(ee(), P),
|
|
130
|
+
children: $
|
|
131
|
+
}),
|
|
132
|
+
O ? /* @__PURE__ */ p("input", {
|
|
133
|
+
type: "hidden",
|
|
134
|
+
name: O,
|
|
135
|
+
form: k,
|
|
136
|
+
value: J,
|
|
137
|
+
disabled: T
|
|
138
|
+
}) : null,
|
|
139
|
+
C ? /* @__PURE__ */ p(s, {
|
|
140
|
+
"data-slot": "otp-input-required",
|
|
141
|
+
hasValue: J.length === B,
|
|
142
|
+
disabled: T,
|
|
143
|
+
form: k,
|
|
144
|
+
onInvalid: q
|
|
145
|
+
}) : null
|
|
146
|
+
]
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
//#endregion
|
|
150
|
+
export { _ as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../shared/responsiveScale.cjs`),t=require(`../shared/fieldStyles.cjs`);let n=require(`class-variance-authority`);var r=(0,n.cva)(`zui:relative ${e.CONTROL_HEIGHT_LG} zui:min-w-0 zui:max-w-[calc(var(--zui-scale,10px)*5.76)] zui:flex-1`),i=(0,n.cva)([`zui:size-full zui-radius-xs zui:border zui:border-[var(--zui-color-border)] zui:bg-transparent zui:p-0 zui:text-center zui:text-lg zui:mobile:text-[max(var(--zui-text-lg),16px)] zui:font-medium zui:text-transparent zui:caret-[var(--zui-color-text)] zui:outline-none`,`zui:selection:bg-transparent zui:selection:text-transparent`,`zui:mobile:rounded-none! zui:mobile:border-x-0 zui:mobile:border-t-0 zui:mobile:border-b-2 zui:mobile:focus:shadow-none! zui:mobile:focus-visible:shadow-none! zui:mobile:aria-invalid:focus:shadow-none! zui:mobile:aria-invalid:focus-visible:shadow-none!`,`zui:data-[has-value=true]:border-[var(--zui-theme-action-primary)]`,`zui:[&:not(:focus):not(:focus-visible):not([aria-invalid=true]):not([data-has-value=true])]:border-[var(--zui-color-border)]`,`zui:disabled:pointer-events-none zui:disabled:cursor-not-allowed zui:disabled:bg-[var(--zui-color-muted-surface)] zui:disabled:opacity-50`,t.fieldInteractionClassName].join(` `)),a=(0,n.cva)(`zui:pointer-events-none zui:absolute zui:inset-0 zui:flex zui:items-center zui:justify-center zui:text-lg zui:mobile:text-[max(var(--zui-text-lg),16px)] zui:font-medium zui:text-[var(--zui-color-text)] zui:animate-[zui-otp-digit-in_520ms_cubic-bezier(0.22,0.9,0.3,1)]`),o=(0,n.cva)(`zui:flex zui:w-full zui:items-center zui:justify-center zui:gap-2`),s=(0,n.cva)(`zui:h-px zui:w-2 zui:shrink-0 zui:bg-[var(--zui-theme-text-muted)]`);exports.otpInputBoxVariants=i,exports.otpInputCellVariants=r,exports.otpInputDigitVariants=a,exports.otpInputRowVariants=o,exports.otpInputSeparatorVariants=s;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
declare const otpInputCellVariants: (props?: import("class-variance-authority/types").ClassProp | undefined) => string;
|
|
2
|
+
declare const otpInputBoxVariants: (props?: import("class-variance-authority/types").ClassProp | undefined) => string;
|
|
3
|
+
declare const otpInputDigitVariants: (props?: import("class-variance-authority/types").ClassProp | undefined) => string;
|
|
4
|
+
declare const otpInputRowVariants: (props?: import("class-variance-authority/types").ClassProp | undefined) => string;
|
|
5
|
+
declare const otpInputSeparatorVariants: (props?: import("class-variance-authority/types").ClassProp | undefined) => string;
|
|
6
|
+
export { otpInputBoxVariants, otpInputCellVariants, otpInputDigitVariants, otpInputRowVariants, otpInputSeparatorVariants, };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
declare const otpInputCellVariants: (props?: import("class-variance-authority/types").ClassProp | undefined) => string;
|
|
2
|
+
declare const otpInputBoxVariants: (props?: import("class-variance-authority/types").ClassProp | undefined) => string;
|
|
3
|
+
declare const otpInputDigitVariants: (props?: import("class-variance-authority/types").ClassProp | undefined) => string;
|
|
4
|
+
declare const otpInputRowVariants: (props?: import("class-variance-authority/types").ClassProp | undefined) => string;
|
|
5
|
+
declare const otpInputSeparatorVariants: (props?: import("class-variance-authority/types").ClassProp | undefined) => string;
|
|
6
|
+
export { otpInputBoxVariants, otpInputCellVariants, otpInputDigitVariants, otpInputRowVariants, otpInputSeparatorVariants, };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CONTROL_HEIGHT_LG as e } from "../shared/responsiveScale.js";
|
|
2
|
+
import { fieldInteractionClassName as t } from "../shared/fieldStyles.js";
|
|
3
|
+
import { cva as n } from "class-variance-authority";
|
|
4
|
+
//#region src/components/OtpInput/OtpInput.variant.ts
|
|
5
|
+
var r = n(`zui:relative ${e} zui:min-w-0 zui:max-w-[calc(var(--zui-scale,10px)*5.76)] zui:flex-1`), i = n([
|
|
6
|
+
"zui:size-full zui-radius-xs zui:border zui:border-[var(--zui-color-border)] zui:bg-transparent zui:p-0 zui:text-center zui:text-lg zui:mobile:text-[max(var(--zui-text-lg),16px)] zui:font-medium zui:text-transparent zui:caret-[var(--zui-color-text)] zui:outline-none",
|
|
7
|
+
"zui:selection:bg-transparent zui:selection:text-transparent",
|
|
8
|
+
"zui:mobile:rounded-none! zui:mobile:border-x-0 zui:mobile:border-t-0 zui:mobile:border-b-2 zui:mobile:focus:shadow-none! zui:mobile:focus-visible:shadow-none! zui:mobile:aria-invalid:focus:shadow-none! zui:mobile:aria-invalid:focus-visible:shadow-none!",
|
|
9
|
+
"zui:data-[has-value=true]:border-[var(--zui-theme-action-primary)]",
|
|
10
|
+
"zui:[&:not(:focus):not(:focus-visible):not([aria-invalid=true]):not([data-has-value=true])]:border-[var(--zui-color-border)]",
|
|
11
|
+
"zui:disabled:pointer-events-none zui:disabled:cursor-not-allowed zui:disabled:bg-[var(--zui-color-muted-surface)] zui:disabled:opacity-50",
|
|
12
|
+
t
|
|
13
|
+
].join(" ")), a = n("zui:pointer-events-none zui:absolute zui:inset-0 zui:flex zui:items-center zui:justify-center zui:text-lg zui:mobile:text-[max(var(--zui-text-lg),16px)] zui:font-medium zui:text-[var(--zui-color-text)] zui:animate-[zui-otp-digit-in_520ms_cubic-bezier(0.22,0.9,0.3,1)]"), o = n("zui:flex zui:w-full zui:items-center zui:justify-center zui:gap-2"), s = n("zui:h-px zui:w-2 zui:shrink-0 zui:bg-[var(--zui-theme-text-muted)]");
|
|
14
|
+
//#endregion
|
|
15
|
+
export { i as otpInputBoxVariants, r as otpInputCellVariants, a as otpInputDigitVariants, o as otpInputRowVariants, s as otpInputSeparatorVariants };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";const e=require(`../../_virtual/_rolldown/runtime.cjs`),t=require(`../../config/useZuiConfig.cjs`),n=require(`../../services/localizeDigits/localizeDigits.cjs`),r=require(`../../lib/utils.cjs`),i=require(`../shared/responsiveScale.cjs`),a=require(`../Button/Button.cjs`),o=require(`../shared/ActionSheet.cjs`),s=require(`../shared/FieldClearButton.cjs`),c=require(`../shared/IconActionButton.cjs`),ee=require(`../shared/useExclusiveAction.cjs`),te=require(`../shared/useStickyToolbar.cjs`),ne=require(`../shared/viewport.cjs`),re=require(`../Select/Select.cjs`),l=require(`./Table.constants.cjs`),u=require(`./Table.utils.cjs`),ie=require(`./Table.variant.cjs`),ae=require(`./TableActiveFilters.cjs`),oe=require(`./TableColumnFilter.cjs`),se=require(`./TableEmptyState.cjs`),ce=require(`./TablePaginationControls.cjs`),d=require(`./TableParts.cjs`),le=require(`./TableSkeletonRows.cjs`),ue=require(`./TableSortToggle.cjs`),de=require(`./hooks/useTablePagination.cjs`),fe=require(`./hooks/useTableCardLabels.cjs`),pe=require(`./hooks/useTableFilter.cjs`),me=require(`./hooks/useTableSearch.cjs`),he=require(`./hooks/useTableSort.cjs`);let f=require(`react`);f=e.__toESM(f,1);let p=require(`react/jsx-runtime`),m=require(`lucide-react`);var ge=f.forwardRef(function({className:e,containerClassName:ge,loading:h=!1,isMutating:g=!1,stickyHeaderOnScroll:_e=!0,maxVisibleRowsBeforeScroll:ve,allowInfiniteMode:ye=!0,stickyToolbar:be=!0,schema:_,data:v,setData:xe,onAdd:Se,onImportExcel:Ce,onEdit:we,onDelete:y,onPrint:b,onPreviewPrint:x,actions:Te,onCellSelectChange:Ee,getRowId:S,showNumberRow:De=!1,showColumnBorder:Oe=!1,showRowBorder:ke=!1,toolbarExtra:Ae,children:je},Me){let{messages:C,digits:w,dir:T}=t.useZuiConfig(),E=f.useMemo(()=>({digits:w,messages:C}),[w,C]),D=f.Children.count(je)>0,O=ne.useIsMobileViewport(),Ne=f.useRef(null),Pe=f.useMemo(()=>r.mergeRefs(Me,Ne),[Me]);fe.useTableCardLabels(Ne,D);let k=f.useMemo(()=>_.columns.filter(e=>e.view),[_.columns]),Fe=f.useMemo(()=>k.filter(e=>e.sortable),[k]),A=f.useMemo(()=>k.filter(e=>e.filterable),[k]),j=typeof Se==`function`,Ie=typeof Ce==`function`,M=typeof we==`function`,N=typeof y==`function`,P=typeof b==`function`,F=typeof x==`function`,I=Te??[],Le=I.length>0,L=_.searchable??!1,R=De&&!D,Re=Ae!=null&&Ae!==!1,ze=_.pagination,Be=ze?.onSearchChange,Ve=typeof Be==`function`,z=M||N||Le,{rowNumberColumnStyle:He,columnStyleByKey:Ue,actionsColumnStyle:We}=f.useMemo(()=>u.resolveColumnWidthPercentages(k,R,z),[z,R,k]),Ge=f.useMemo(()=>{let e=_.columns.map(e=>{if(e.type!==`select`&&e.type!==`radio`)return[e.key,[]];if(Array.isArray(e.options)&&e.options.length>0)return[e.key,e.options];if(e.optionsSource)return[e.key,[]];let t=new Set;return v.forEach(n=>{let r=n[e.key];if(typeof r==`string`||typeof r==`number`){let e=String(r).trim();e.length>0&&t.add(e)}}),[e.key,Array.from(t).map(e=>({value:e,label:e}))]});return Object.fromEntries(e)},[v,_.columns]),[Ke,B]=ee.useExclusiveAction(),[qe,Je]=f.useState(!1),[Ye,Xe]=f.useState(!1),[Ze,Qe]=f.useState(!1),[$e,et]=f.useState(null),[tt,nt]=f.useState(!1),[rt,it]=f.useState({open:!1,actions:[]}),V=g||Ke,at=f.useCallback(async()=>{g||!Se||await B(Se)},[g,Se,B]),ot=f.useCallback(async()=>{g||!Ce||await B(Ce)},[g,Ce,B]),H=f.useCallback(async(e,t,n,r)=>{g||await B(()=>e({row:t,rowIndex:n,rowId:r??u.resolveSafeRowId(t,n,S)}))},[S,g,B]),st=f.useCallback(async(e,t,n)=>{we&&await H(we,e,t,n)},[we,H]),ct=f.useCallback(async(e,t,n)=>{y&&await H(y,e,t,n)},[y,H]),lt=f.useCallback(async(e,t,n,r)=>{await H(e.onClick,t,n,r)},[H]),ut=f.useCallback(async(e,t,n,r,i)=>{if(g)return;let a=i.trim(),o=a.length>0?a:null;if(e[r]===o)return;let s=n??u.resolveSafeRowId(e,t,S),c={...e,[r]:o};await B(async()=>{try{if(Ee&&await Ee({row:c,previousRow:e,rowIndex:t,rowId:s,columnKey:r,value:a})===!1)return;xe(e=>u.replaceRowByIdentifier(e,t,s,S,c))}catch{return}})},[S,g,Ee,B,xe]),dt=f.useCallback((e,t,n)=>{let i=e=>(0,p.jsx)(`span`,{className:r.cn(`zui:inline-flex`,s.CLEAR_ICON_CLASS,`zui:[&>svg]:size-full`),children:e}),a=[];M&&a.push({key:`edit`,label:C.common.edit,icon:i((0,p.jsx)(m.Pencil,{"aria-hidden":`true`})),onSelect:()=>void st(e,t,n)}),I.forEach((r,o)=>{a.push({key:`custom-${o}`,label:r.tooltip,icon:i(r.icon),onSelect:()=>void lt(r,e,t,n)})}),N&&a.push({key:`delete`,label:C.common.delete,icon:i((0,p.jsx)(m.Trash2,{"aria-hidden":`true`})),danger:!0,onSelect:()=>void ct(e,t,n)}),it({open:!0,actions:a})},[lt,ct,st,C.common.delete,C.common.edit,I,N,M]),{searchTerm:ft,normalizedSearchTerm:pt,filteredRows:mt,handleSearchInputChange:ht}=me.useTableSearch({data:v,visibleColumns:k,showSearchInput:L,hasRemoteSearchHandler:Ve,onSearchChange:Be,getRowId:S,cellFormatOptions:E}),{filteredRows:gt,filterValues:U,activeFilterCount:_t,filterKey:vt,handleFilterChange:yt,handleFilterClear:bt}=pe.useTableFilter({rows:mt,columns:_.columns,filterConfig:_.filter}),W=f.useMemo(()=>Object.fromEntries(A.map(e=>[e.key,u.resolveFilterOptions(e,v,E)])),[E,v,A]),{sortedRows:G,activeSort:K,handleSortToggle:xt,handleSortClear:St}=he.useTableSort({rows:gt,columns:_.columns,sortConfig:_.sort}),Ct=f.useCallback(async()=>{b&&await b({rows:G.map(({row:e})=>e),columns:k})},[b,G,k]),wt=f.useCallback(async()=>{x&&await x({rows:G.map(({row:e})=>e),columns:k})},[x,G,k]),{pagingMode:q,currentPage:Tt,totalPages:Et,resolvedPageSize:Dt,visibleRows:J,showPagingModeToggle:Ot,shouldRenderPagination:kt,shouldRenderInfiniteMode:At,canLoadMoreInInfiniteMode:jt,shouldUseRemotePaging:Mt,shouldUseScrollableRows:Nt,tableScrollViewportRef:Pt,tableScrollViewportStyle:Ft,handlePageChange:It,handlePagingModeToggle:Lt,handleTableScrollViewport:Rt,isInfiniteRequestPending:zt}=de.useTablePagination({hasChildren:D,filteredRows:G,paginationConfig:ze,loading:h,isRowActionBusy:V,searchKey:`${pt}|${vt}`,sortKey:K?`${K.sortKey}:${K.direction}`:``,maxVisibleRowsBeforeScroll:ve,allowInfiniteMode:ye}),Bt=Nt&&_e,Vt=f.useMemo(()=>u.resolveLoadingRowsCount(_.pagination?.pageSize,v.length),[v.length,_.pagination?.pageSize]),Ht=h&&(J.length===0||Mt&&q===`pagination`),Ut=At&&h&&J.length>0,Wt=At&&J.length>0,Gt=Wt&&(h||zt),Kt=Wt&&jt&&!h&&!zt,qt=Wt&&!jt&&!h&&!zt,Jt=Math.min(Vt,Math.max(1,Math.min(Dt,3))),Y=h||V,Yt=+!!M+I.length+ +!!N,Xt=q===`pagination`?C.table.switchToInfinite:C.table.switchToPagination,Zt=j||Ie||Ot||P||F,X=O&&!D&&Fe.length>0,Z=O&&!D&&A.length>0,Q=!D&&(L||Zt||X||Z),Qt=f.useRef(null),$t=f.useRef(null);te.useStickyToolbar(Qt,$t,O&&be&&Q);let en=f.useMemo(()=>{let e=e=>(0,p.jsx)(e,{className:s.CLEAR_ICON_CLASS,"aria-hidden":`true`}),t=Fe.map(t=>{let r=K?.sortKey===t.key?K.direction:void 0,i=n.localizeDigits(t.label,w);return{key:t.key,label:r===void 0?i:`${i} (${r===`asc`?C.table.sortAscending:C.table.sortDescending})`,icon:e(r===`asc`?m.ArrowUp:r===`desc`?m.ArrowDown:m.ArrowUpDown),active:r!==void 0,onSelect:()=>xt(t.key)}});return K&&t.push({key:`clear-sort`,label:C.table.sortDefault,icon:e(m.RotateCcw),onSelect:St}),t},[K,w,St,xt,C.table.sortAscending,C.table.sortDefault,C.table.sortDescending,Fe]),tn=f.useCallback(e=>{et(e),nt(!0)},[]),nn=f.useMemo(()=>A.map(e=>{let t=U[e.key],r=t!==void 0&&!u.isEmptyFilterValue(t),i=n.localizeDigits(e.label,w),a=r?n.localizeDigits(u.resolveFilterText(t,W[e.key]??[]),w):``;return{key:e.key,label:r?`${i}: ${a}`:i,icon:(0,p.jsx)(m.Funnel,{className:s.CLEAR_ICON_CLASS,fill:r?`currentColor`:`none`,"aria-hidden":`true`}),active:r,onSelect:()=>tn(e.key)}}),[w,W,U,A,tn]),$=A.find(e=>e.key===$e),rn=f.useMemo(()=>{let e=e=>(0,p.jsx)(e,{className:s.CLEAR_ICON_CLASS,"aria-hidden":`true`});return[j?{key:`add`,label:C.common.add,icon:e(m.Plus),onSelect:()=>void at()}:null,Ie?{key:`import`,label:C.table.importExcel,icon:e(m.FileSpreadsheet),onSelect:()=>void ot()}:null,P?{key:`print`,label:C.table.print,icon:e(m.Printer),onSelect:()=>void Ct()}:null,F?{key:`preview-print`,label:C.table.printPreview,icon:e(m.Eye),onSelect:()=>void wt()}:null,Ot?{key:`paging-mode`,label:Xt,icon:e(q===`pagination`?m.Infinity:m.Rows3),onSelect:Lt}:null].filter(e=>e!==null)},[at,ot,Lt,wt,Ct,C.common.add,C.table.importExcel,C.table.print,C.table.printPreview,q,Xt,j,Ie,Ot,F,P]),an=O&&(rn.length>0||X||Z),on=O&&rn.length>1,sn=Re&&Q&&L,cn=Re&&Q&&!L,ln=Re&&!Q,un=(0,p.jsx)(`div`,{"data-slot":`table-toolbar-extra`,className:r.cn(`zui:flex zui:w-full zui:items-center`,i.CONTROL_HEIGHT_SM),children:Ae});return(0,p.jsxs)(`div`,{"data-slot":`table-container`,dir:T,className:r.cn(ie.tableContainerVariants(),ge),children:[ln?(0,p.jsx)(`div`,{"data-slot":`table-toolbar-extra-row`,className:`zui:mb-3`,children:un}):null,Q?(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(`div`,{ref:$t,"aria-hidden":`true`,"data-slot":`table-sticky-sentinel`}),(0,p.jsxs)(`div`,{ref:Qt,"data-slot":`table-sticky-toolbar`,"data-sticky-toolbar":O&&be?`true`:void 0,className:`zui:mb-3`,children:[sn?(0,p.jsx)(`div`,{"data-slot":`table-toolbar-extra-row`,className:`zui:mb-2`,children:un}):null,(0,p.jsx)(c.ListToolbar,{"data-slot":`table-controls`,searchSlot:`table-search-input`,actionsSlot:`table-add-action`,inlineActionsOnMobile:an,search:L?{value:ft,onChange:ht,placeholder:C.common.searchPlaceholder,ariaLabel:C.table.searchAriaLabel,disabled:V}:void 0,leading:cn?un:void 0,actions:X||Z||on||Zt?(0,p.jsxs)(p.Fragment,{children:[X?(0,p.jsx)(c.ToolbarIconButton,{"data-slot":`table-sort-button`,label:C.table.sortBy,disabled:Y,onClick:()=>Xe(!0),icon:(0,p.jsx)(m.ArrowUpDown,{"aria-hidden":`true`})}):null,Z?(0,p.jsx)(c.ToolbarIconButton,{"data-slot":`table-filter-button`,label:C.table.filterBy,disabled:Y,onClick:()=>Qe(!0),icon:(0,p.jsxs)(`span`,{className:`zui:relative zui:inline-flex`,children:[(0,p.jsx)(m.Funnel,{fill:_t>0?`currentColor`:`none`,"aria-hidden":`true`}),_t>0?(0,p.jsx)(`span`,{"aria-hidden":`true`,"data-slot":`table-filter-active-dot`,className:`zui:absolute zui:-end-1 zui:-top-1 zui:size-2 zui:rounded-full zui:bg-[var(--zui-theme-action-primary)] zui:ring-2 zui:ring-[var(--zui-color-surface)]`}):null]})}):null,on?(0,p.jsx)(c.ToolbarIconButton,{"data-slot":`table-toolbar-menu-button`,label:C.table.actions,disabled:Y,onClick:()=>Je(!0),icon:(0,p.jsx)(m.EllipsisVertical,{"aria-hidden":`true`})}):Zt?(0,p.jsxs)(p.Fragment,{children:[Ot?(0,p.jsx)(c.ToolbarIconButton,{"data-slot":`table-paging-mode-toggle-button`,label:Xt,disabled:Y,onClick:Lt,icon:q===`pagination`?(0,p.jsx)(m.Infinity,{className:l.pagingToggleIconClassName,"aria-hidden":`true`}):(0,p.jsx)(m.Rows3,{className:l.pagingToggleIconClassName,"aria-hidden":`true`})}):null,F?(0,p.jsx)(c.ToolbarIconButton,{"data-slot":`table-action-preview-print-button`,label:C.table.printPreview,disabled:Y,onClick:()=>void wt(),icon:(0,p.jsx)(m.Eye,{})}):null,P?(0,p.jsx)(c.ToolbarIconButton,{"data-slot":`table-action-print-button`,label:C.table.print,disabled:Y,onClick:()=>void Ct(),icon:(0,p.jsx)(m.Printer,{})}):null,Ie?(0,p.jsx)(c.ToolbarIconButton,{"data-slot":`table-action-import-excel-button`,label:C.table.importExcel,disabled:Y,onClick:()=>void ot(),icon:(0,p.jsx)(m.FileSpreadsheet,{})}):null,j?(0,p.jsx)(c.ToolbarIconButton,{"data-slot":`table-action-add-button`,label:C.common.add,disabled:Y,onClick:()=>void at(),icon:(0,p.jsx)(m.Plus,{})}):null]}):null]}):void 0})]}),X?(0,p.jsx)(o.default,{open:Ye,onOpenChange:Xe,actions:en,label:C.table.sortBy}):null,Z?(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(o.default,{open:Ze,onOpenChange:Qe,actions:nn,label:C.table.filterBy}),$?(0,p.jsx)(oe.TableColumnFilterSheet,{column:$,value:U[$.key],onChange:e=>yt($.key,e),options:W[$.key]??[],open:tt,onOpenChange:nt},$.key):null]}):null,on?(0,p.jsx)(o.default,{open:qe,onOpenChange:Je,actions:rn.map(e=>({...e,disabled:Y})),label:C.table.actions}):null]}):null,D?null:(0,p.jsx)(ae.default,{columns:k,values:U,optionsByColumn:W,onRemove:e=>yt(e,void 0),onSelect:O?tn:void 0}),(0,p.jsx)(`div`,{ref:Pt,"data-slot":`table-scroll-viewport`,className:r.cn(`zui:relative zui:w-full zui:min-w-0 zui:overflow-x-auto zui-radius-xs zui:bg-[var(--zui-color-surface)] zui:shadow-[0_4px_14px_-12px_var(--zui-effect-shadow-ink-35)]`,Nt?`zui:overflow-y-auto`:void 0),style:Ft,onScroll:Rt,children:(0,p.jsx)(`table`,{ref:Pe,"data-slot":`table`,className:r.cn(ie.tableVariants({showColumnBorder:Oe,showRowBorder:ke}),e),dir:T,children:D?je:k.length===0?(0,p.jsx)(d.TableBody,{children:(0,p.jsx)(d.TableRow,{children:(0,p.jsx)(d.TableCell,{className:`zui:py-7 zui:text-center zui:text-[var(--zui-color-text)]`,children:C.table.noColumns})})}):(0,p.jsxs)(p.Fragment,{children:[(0,p.jsxs)(`colgroup`,{children:[R?(0,p.jsx)(`col`,{style:He}):null,k.map(e=>(0,p.jsx)(`col`,{style:Ue[e.key]},`col-${e.key}`)),z?(0,p.jsx)(`col`,{style:We}):null]}),(0,p.jsx)(d.TableHeader,{children:(0,p.jsxs)(d.TableRow,{children:[R?(0,p.jsx)(d.TableHead,{align:`center`,className:r.cn(l.rowNumberColumnClassName,Bt?l.stickyHeaderCellClassName:void 0),children:C.table.rowNumber}):null,k.map(e=>{let t=e.sortable&&K?.sortKey===e.key?K.direction:void 0,r=e.sortable?(0,p.jsx)(ue.default,{columnLabel:e.label,direction:t,onToggle:()=>xt(e.key)}):null,i=e.filterable?(0,p.jsx)(oe.default,{column:e,value:U[e.key],onChange:t=>yt(e.key,t),options:W[e.key]??[]}):null;return(0,p.jsx)(d.TableHead,{align:e.align,className:Bt?l.stickyHeaderCellClassName:void 0,"aria-sort":e.sortable?u.resolveAriaSort(t):void 0,children:e.sortable||e.filterable?(0,p.jsxs)(`span`,{className:`zui:inline-flex zui:items-center zui:gap-2`,children:[n.localizeDigits(e.label,w),(0,p.jsxs)(`span`,{className:`zui:inline-flex zui:items-center`,children:[T===`rtl`?r:i,T===`rtl`?i:r]})]}):n.localizeDigits(e.label,w)},`head-${e.key}`)}),z?(0,p.jsx)(d.TableHead,{align:`center`,className:r.cn(l.actionsColumnClassName,l.actionsColumnStickyClassName,Bt?l.stickyHeaderCellClassName:void 0),children:C.table.actions}):null]})}),(0,p.jsx)(d.TableBody,{children:Ht?(0,p.jsx)(le.default,{count:Vt,keyPrefix:`loading`,showRowNumbers:R,columns:k,actionsCount:Yt}):J.length===0?(0,p.jsx)(se.default,{colSpan:k.length+ +!!z+ +!!R,showSearchInput:L,normalizedSearchTerm:pt,hasActiveFilters:_t>0,onClearFilters:bt}):(0,p.jsxs)(p.Fragment,{children:[J.map(({row:e,rowIndex:t,rowId:i},o)=>{let s=i===void 0?`row-${t}`:`row-id-${String(i)}`,ee=kt?(Tt-1)*Dt+o+1:o+1;return(0,p.jsxs)(d.TableRow,{children:[R?(0,p.jsx)(d.TableCell,{align:`center`,className:l.rowNumberColumnClassName,"data-label":C.table.rowNumber,children:n.localizeDigits(String(ee),w)}):null,k.map(r=>{let a=`cell-${r.key}-${s}`;if(r.viewType===`select`){let o=Ge[r.key]??[],s=e[r.key],c=typeof s==`string`||typeof s==`number`?String(s):``;return(0,p.jsx)(d.TableCell,{align:r.align,"data-label":n.localizeDigits(r.label,w),children:(0,p.jsx)(re.default,{disabled:V||o.length===0&&!r.optionsSource,placeholder:u.resolvePlaceholder(r),options:o,remoteOptions:r.optionsSource,value:c,onValueChange:n=>{let a=Array.isArray(n)?n[0]??``:n;ut(e,t,i,r.key,a)}})},a)}return(0,p.jsx)(d.TableCell,{align:r.align,"data-label":n.localizeDigits(r.label,w),children:u.formatCellValue(e[r.key],r,E)},a)}),z?(0,p.jsx)(d.TableCell,{align:`center`,"data-cell":`actions`,className:r.cn(l.actionsColumnClassName,l.actionsColumnStickyClassName),children:O?(0,p.jsx)(a.default,{"data-slot":`table-row-actions-button`,kind:`cancel`,fullWidth:!0,label:C.table.actions,disabled:V,onClick:()=>dt(e,t,i)}):(0,p.jsxs)(`div`,{"data-slot":`table-row-actions`,className:`zui:flex zui:items-center zui:justify-center zui:gap-0.5`,children:[M?(0,p.jsx)(c.IconActionButton,{"data-slot":`table-action-edit-button`,label:C.common.edit,icon:(0,p.jsx)(m.Pencil,{className:l.actionIconClassName,"aria-hidden":`true`}),disabled:V,className:r.cn(l.rowActionButtonClassName,`zui:text-[var(--zui-theme-text-primary)]`),onClick:()=>void st(e,t,i)}):null,I.map((n,a)=>(0,p.jsx)(c.IconActionButton,{"data-slot":`table-action-custom-button`,label:n.tooltip,icon:n.icon,disabled:V,className:r.cn(l.rowActionButtonClassName,`zui:text-[var(--zui-theme-text-primary)]`),onClick:()=>void lt(n,e,t,i)},`${n.tooltip}-${a}`)),N?(0,p.jsx)(c.IconActionButton,{"data-slot":`table-action-delete-button`,label:C.common.delete,icon:(0,p.jsx)(m.Trash2,{className:l.actionIconClassName,"aria-hidden":`true`}),disabled:V,className:r.cn(l.rowActionButtonClassName,`zui:text-[var(--zui-theme-status-danger)]`),onClick:()=>void ct(e,t,i)}):null]})}):null]},s)}),Ut?(0,p.jsx)(le.default,{count:Jt,keyPrefix:`infinite-loading`,showRowNumbers:R,columns:k,actionsCount:Yt}):null]})})]})})}),O&&z?(0,p.jsx)(o.default,{open:rt.open,onOpenChange:e=>it(t=>({...t,open:e})),actions:rt.actions,label:C.table.actions}):null,(0,p.jsx)(ce.default,{shouldRenderInfiniteMode:At,shouldShowInfiniteLoadingStatus:Gt,shouldShowInfiniteReadyStatus:Kt,shouldShowInfiniteCompletedStatus:qt,shouldRenderPagination:kt,loading:h,isRowActionBusy:V,currentPage:Tt,totalPages:Et,onPageChange:It})]})});ge.displayName=`Table`,exports.default=ge;
|
|
1
|
+
"use client";const e=require(`../../_virtual/_rolldown/runtime.cjs`),t=require(`../../config/useZuiConfig.cjs`),n=require(`../../services/localizeDigits/localizeDigits.cjs`),r=require(`../../lib/utils.cjs`),i=require(`../shared/responsiveScale.cjs`),a=require(`../shared/ActionSheet.cjs`),o=require(`../shared/FieldClearButton.cjs`),s=require(`../shared/IconActionButton.cjs`),c=require(`../shared/useExclusiveAction.cjs`),ee=require(`../shared/useStickyToolbar.cjs`),te=require(`../shared/viewport.cjs`),ne=require(`../Select/Select.cjs`),re=require(`./TableActionsContext.cjs`),l=require(`./Table.constants.cjs`),u=require(`./Table.utils.cjs`),ie=require(`./Table.variant.cjs`),ae=require(`./TableActiveFilters.cjs`),oe=require(`./TableFilterRegistry.cjs`),se=require(`./TableColumnFilter.cjs`),ce=require(`./TableEmptyState.cjs`),le=require(`./TablePaginationControls.cjs`),d=require(`./TableParts.cjs`),ue=require(`./TableSkeletonRows.cjs`),de=require(`./TableSortToggle.cjs`),fe=require(`./hooks/useTablePagination.cjs`),pe=require(`./hooks/useTableCardLabels.cjs`),me=require(`./hooks/useTableFilter.cjs`),he=require(`./hooks/useTableSearch.cjs`),ge=require(`./hooks/useTableSort.cjs`);let f=require(`react`);f=e.__toESM(f,1);let p=require(`react/jsx-runtime`),m=require(`lucide-react`);var _e=f.forwardRef(function({className:e,containerClassName:_e,loading:h=!1,isMutating:g=!1,stickyHeaderOnScroll:ve=!0,maxVisibleRowsBeforeScroll:ye,allowInfiniteMode:be=!0,stickyToolbar:xe=!0,schema:_,data:v,setData:Se,onAdd:y,onImportExcel:b,onEdit:x,onDelete:Ce,onPrint:we,onPreviewPrint:S,actions:Te,onCellSelectChange:Ee,getRowId:C,showNumberRow:De=!1,showColumnBorder:Oe=!1,showRowBorder:ke=!1,toolbarExtra:Ae,children:je},Me){let{messages:w,digits:T,dir:E}=t.useZuiConfig(),D=f.useMemo(()=>({digits:T,messages:w}),[T,w]),O=f.Children.count(je)>0,[Ne,Pe]=f.useState({}),Fe=f.useMemo(()=>({register:e=>Pe(t=>({...t,[e.column.key]:e})),unregister:e=>Pe(t=>Object.fromEntries(Object.entries(t).filter(([t])=>t!==e)))}),[]),Ie=Object.values(Ne),k=te.useIsMobileViewport(),Le=f.useRef(null),Re=f.useMemo(()=>r.mergeRefs(Me,Le),[Me]);pe.useTableCardLabels(Le,O);let A=f.useMemo(()=>_.columns.filter(e=>e.view),[_.columns]),ze=f.useMemo(()=>A.filter(e=>e.sortable),[A]),j=f.useMemo(()=>A.filter(e=>e.filterable),[A]),Be=typeof y==`function`,Ve=typeof b==`function`,M=typeof x==`function`,N=typeof Ce==`function`,P=typeof we==`function`,F=typeof S==`function`,I=(Te??[]).filter(e=>!e.hidden),He=I.length>0,L=_.searchable??!1,R=De&&!O,Ue=Ae!=null&&Ae!==!1,We=_.pagination,Ge=We?.onSearchChange,Ke=typeof Ge==`function`,qe=M||N||He,z=qe&&!k,{rowNumberColumnStyle:Je,columnStyleByKey:Ye,actionsColumnStyle:Xe}=f.useMemo(()=>u.resolveColumnWidthPercentages(A,R,z),[z,R,A]),Ze=f.useMemo(()=>{let e=_.columns.map(e=>{if(e.type!==`select`&&e.type!==`radio`)return[e.key,[]];if(Array.isArray(e.options)&&e.options.length>0)return[e.key,e.options];if(e.optionsSource)return[e.key,[]];let t=new Set;return v.forEach(n=>{let r=n[e.key];if(typeof r==`string`||typeof r==`number`){let e=String(r).trim();e.length>0&&t.add(e)}}),[e.key,Array.from(t).map(e=>({value:e,label:e}))]});return Object.fromEntries(e)},[v,_.columns]),[Qe,B]=c.useExclusiveAction(),[$e,et]=f.useState(!1),[tt,nt]=f.useState(!1),[rt,it]=f.useState(!1),[at,ot]=f.useState(null),[st,ct]=f.useState(!1),[lt,ut]=f.useState({open:!1,actions:[]}),V=g||Qe,dt=f.useCallback(async()=>{g||!y||await B(y)},[g,y,B]),ft=f.useCallback(async()=>{g||!b||await B(b)},[g,b,B]),H=f.useCallback(async(e,t,n,r)=>{g||await B(()=>e({row:t,rowIndex:n,rowId:r??u.resolveSafeRowId(t,n,C)}))},[C,g,B]),pt=f.useCallback(async(e,t,n)=>{x&&await H(x,e,t,n)},[x,H]),mt=f.useCallback(async(e,t,n)=>{Ce&&await H(Ce,e,t,n)},[Ce,H]),ht=f.useMemo(()=>({isMobile:k,isBusy:V,run:async e=>{g||await B(e)},openRowSheet:e=>ut({open:!0,actions:e})}),[V,k,g,B]),gt=f.useCallback(async(e,t,n,r)=>{await H(e.onClick,t,n,r)},[H]),_t=f.useCallback(async(e,t,n,r,i)=>{if(g)return;let a=i.trim(),o=a.length>0?a:null;if(e[r]===o)return;let s=n??u.resolveSafeRowId(e,t,C),c={...e,[r]:o};await B(async()=>{try{if(Ee&&await Ee({row:c,previousRow:e,rowIndex:t,rowId:s,columnKey:r,value:a})===!1)return;Se(e=>u.replaceRowByIdentifier(e,t,s,C,c))}catch{return}})},[C,g,Ee,B,Se]),vt=f.useCallback((e,t,n)=>{let i=e=>(0,p.jsx)(`span`,{className:r.cn(`zui:inline-flex`,o.CLEAR_ICON_CLASS,`zui:[&>svg]:size-full`),children:e}),a=[];M&&a.push({key:`edit`,label:w.common.edit,icon:i((0,p.jsx)(m.Pencil,{"aria-hidden":`true`})),onSelect:()=>void pt(e,t,n)}),I.forEach((r,o)=>{a.push({key:`custom-${o}`,label:r.tooltip,icon:i(r.icon),danger:r.danger,disabled:r.disabled,onSelect:()=>void gt(r,e,t,n)})}),N&&a.push({key:`delete`,label:w.common.delete,icon:i((0,p.jsx)(m.Trash2,{"aria-hidden":`true`})),danger:!0,onSelect:()=>void mt(e,t,n)}),ut({open:!0,actions:a})},[gt,mt,pt,w.common.delete,w.common.edit,I,N,M]),{searchTerm:yt,normalizedSearchTerm:bt,filteredRows:xt,handleSearchInputChange:St}=he.useTableSearch({data:v,visibleColumns:A,showSearchInput:L,hasRemoteSearchHandler:Ke,onSearchChange:Ge,getRowId:C,cellFormatOptions:D}),{filteredRows:Ct,filterValues:U,activeFilterCount:wt,filterKey:Tt,handleFilterChange:Et,handleFilterClear:Dt}=me.useTableFilter({rows:xt,columns:_.columns,filterConfig:_.filter}),W=f.useMemo(()=>Object.fromEntries(j.map(e=>[e.key,u.resolveFilterOptions(e,v,D)])),[D,v,j]),{sortedRows:G,activeSort:K,handleSortToggle:Ot,handleSortClear:kt}=ge.useTableSort({rows:Ct,columns:_.columns,sortConfig:_.sort}),At=f.useCallback(async()=>{we&&await we({rows:G.map(({row:e})=>e),columns:A})},[we,G,A]),jt=f.useCallback(async()=>{S&&await S({rows:G.map(({row:e})=>e),columns:A})},[S,G,A]),{pagingMode:q,currentPage:Mt,totalPages:Nt,resolvedPageSize:Pt,visibleRows:J,showPagingModeToggle:Ft,shouldRenderPagination:It,shouldRenderInfiniteMode:Lt,canLoadMoreInInfiniteMode:Rt,shouldUseRemotePaging:zt,shouldUseScrollableRows:Bt,tableScrollViewportRef:Vt,tableScrollViewportStyle:Ht,handlePageChange:Ut,handlePagingModeToggle:Wt,handleTableScrollViewport:Gt,isInfiniteRequestPending:Kt}=fe.useTablePagination({hasChildren:O,filteredRows:G,paginationConfig:We,loading:h,isRowActionBusy:V,searchKey:`${bt}|${Tt}`,sortKey:K?`${K.sortKey}:${K.direction}`:``,maxVisibleRowsBeforeScroll:ye,allowInfiniteMode:be}),qt=Bt&&ve,Jt=f.useMemo(()=>u.resolveLoadingRowsCount(_.pagination?.pageSize,v.length),[v.length,_.pagination?.pageSize]),Yt=h&&(J.length===0||zt&&q===`pagination`),Xt=Lt&&h&&J.length>0,Zt=Lt&&J.length>0,Qt=Zt&&(h||Kt),$t=Zt&&Rt&&!h&&!Kt,en=Zt&&!Rt&&!h&&!Kt,tn=Math.min(Jt,Math.max(1,Math.min(Pt,3))),Y=h||V,nn=k?0:+!!M+I.length+ +!!N,rn=q===`pagination`?w.table.switchToInfinite:w.table.switchToPagination,an=Be||Ve||Ft||P||F,X=k&&!O&&ze.length>0,Z=k&&!O&&j.length>0,Q=!O&&(L||an||X||Z),on=f.useRef(null),sn=f.useRef(null);ee.useStickyToolbar(on,sn,k&&xe&&Q);let cn=f.useMemo(()=>{let e=e=>(0,p.jsx)(e,{className:o.CLEAR_ICON_CLASS,"aria-hidden":`true`}),t=ze.map(t=>{let r=K?.sortKey===t.key?K.direction:void 0,i=n.localizeDigits(t.label,T);return{key:t.key,label:r===void 0?i:`${i} (${r===`asc`?w.table.sortAscending:w.table.sortDescending})`,icon:e(r===`asc`?m.ArrowUp:r===`desc`?m.ArrowDown:m.ArrowUpDown),active:r!==void 0,onSelect:()=>Ot(t.key)}});return K&&t.push({key:`clear-sort`,label:w.table.sortDefault,icon:e(m.RotateCcw),onSelect:kt}),t},[K,T,kt,Ot,w.table.sortAscending,w.table.sortDefault,w.table.sortDescending,ze]),ln=f.useCallback(e=>{ot(e),ct(!0)},[]),un=f.useMemo(()=>j.map(e=>{let t=U[e.key],r=t!==void 0&&!u.isEmptyFilterValue(t),i=n.localizeDigits(e.label,T),a=r?n.localizeDigits(u.resolveFilterText(t,W[e.key]??[]),T):``;return{key:e.key,label:r?`${i}: ${a}`:i,icon:(0,p.jsx)(m.Funnel,{className:o.CLEAR_ICON_CLASS,fill:r?`currentColor`:`none`,"aria-hidden":`true`}),active:r,onSelect:()=>ln(e.key)}}),[T,W,U,j,ln]),$=j.find(e=>e.key===at),dn=f.useMemo(()=>{let e=e=>(0,p.jsx)(e,{className:o.CLEAR_ICON_CLASS,"aria-hidden":`true`});return[Be?{key:`add`,label:w.common.add,icon:e(m.Plus),onSelect:()=>void dt()}:null,Ve?{key:`import`,label:w.table.importExcel,icon:e(m.FileSpreadsheet),onSelect:()=>void ft()}:null,P?{key:`print`,label:w.table.print,icon:e(m.Printer),onSelect:()=>void At()}:null,F?{key:`preview-print`,label:w.table.printPreview,icon:e(m.Eye),onSelect:()=>void jt()}:null,Ft?{key:`paging-mode`,label:rn,icon:e(q===`pagination`?m.Infinity:m.Rows3),onSelect:Wt}:null].filter(e=>e!==null)},[dt,ft,Wt,jt,At,w.common.add,w.table.importExcel,w.table.print,w.table.printPreview,q,rn,Be,Ve,Ft,F,P]),fn=k&&(dn.length>0||X||Z),pn=k&&dn.length>1,mn=Ue&&Q&&L,hn=Ue&&Q&&!L,gn=Ue&&!Q,_n=(0,p.jsx)(`div`,{"data-slot":`table-toolbar-extra`,className:r.cn(`zui:flex zui:w-full zui:items-center`,i.CONTROL_HEIGHT_SM),children:Ae});return(0,p.jsxs)(`div`,{"data-slot":`table-container`,dir:E,className:r.cn(ie.tableContainerVariants(),_e),children:[O?(0,p.jsx)(ae.default,{columns:Ie.map(e=>e.column),values:Object.fromEntries(Ie.flatMap(e=>e.value?[[e.column.key,e.value]]:[])),optionsByColumn:Object.fromEntries(Ie.map(e=>[e.column.key,e.options])),onRemove:e=>Ne[e]?.onChange(void 0)}):(0,p.jsx)(ae.default,{columns:A,values:U,optionsByColumn:W,onRemove:e=>Et(e,void 0),onSelect:k?ln:void 0}),gn?(0,p.jsx)(`div`,{"data-slot":`table-toolbar-extra-row`,className:`zui:mb-3`,children:_n}):null,Q?(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(`div`,{ref:sn,"aria-hidden":`true`,"data-slot":`table-sticky-sentinel`}),(0,p.jsxs)(`div`,{ref:on,"data-slot":`table-sticky-toolbar`,"data-sticky-toolbar":k&&xe?`true`:void 0,className:`zui:mb-3`,children:[mn?(0,p.jsx)(`div`,{"data-slot":`table-toolbar-extra-row`,className:`zui:mb-2`,children:_n}):null,(0,p.jsx)(s.ListToolbar,{"data-slot":`table-controls`,searchSlot:`table-search-input`,actionsSlot:`table-add-action`,inlineActionsOnMobile:fn,search:L?{value:yt,onChange:St,placeholder:w.common.searchPlaceholder,ariaLabel:w.table.searchAriaLabel,disabled:V}:void 0,leading:hn?_n:void 0,actions:X||Z||pn||an?(0,p.jsxs)(p.Fragment,{children:[X?(0,p.jsx)(s.ToolbarIconButton,{"data-slot":`table-sort-button`,label:w.table.sortBy,disabled:Y,onClick:()=>nt(!0),icon:(0,p.jsx)(m.ArrowUpDown,{"aria-hidden":`true`})}):null,Z?(0,p.jsx)(s.ToolbarIconButton,{"data-slot":`table-filter-button`,label:w.table.filterBy,disabled:Y,onClick:()=>it(!0),icon:(0,p.jsxs)(`span`,{className:`zui:relative zui:inline-flex`,children:[(0,p.jsx)(m.Funnel,{fill:wt>0?`currentColor`:`none`,"aria-hidden":`true`}),wt>0?(0,p.jsx)(`span`,{"aria-hidden":`true`,"data-slot":`table-filter-active-dot`,className:`zui:absolute zui:-end-1 zui:-top-1 zui:size-2 zui:rounded-full zui:bg-[var(--zui-theme-action-primary)] zui:ring-2 zui:ring-[var(--zui-color-surface)]`}):null]})}):null,pn?(0,p.jsx)(s.ToolbarIconButton,{"data-slot":`table-toolbar-menu-button`,label:w.table.actions,disabled:Y,onClick:()=>et(!0),icon:(0,p.jsx)(m.EllipsisVertical,{"aria-hidden":`true`})}):an?(0,p.jsxs)(p.Fragment,{children:[Ft?(0,p.jsx)(s.ToolbarIconButton,{"data-slot":`table-paging-mode-toggle-button`,label:rn,disabled:Y,onClick:Wt,icon:q===`pagination`?(0,p.jsx)(m.Infinity,{className:l.pagingToggleIconClassName,"aria-hidden":`true`}):(0,p.jsx)(m.Rows3,{className:l.pagingToggleIconClassName,"aria-hidden":`true`})}):null,F?(0,p.jsx)(s.ToolbarIconButton,{"data-slot":`table-action-preview-print-button`,label:w.table.printPreview,disabled:Y,onClick:()=>void jt(),icon:(0,p.jsx)(m.Eye,{})}):null,P?(0,p.jsx)(s.ToolbarIconButton,{"data-slot":`table-action-print-button`,label:w.table.print,disabled:Y,onClick:()=>void At(),icon:(0,p.jsx)(m.Printer,{})}):null,Ve?(0,p.jsx)(s.ToolbarIconButton,{"data-slot":`table-action-import-excel-button`,label:w.table.importExcel,disabled:Y,onClick:()=>void ft(),icon:(0,p.jsx)(m.FileSpreadsheet,{})}):null,Be?(0,p.jsx)(s.ToolbarIconButton,{"data-slot":`table-action-add-button`,label:w.common.add,disabled:Y,onClick:()=>void dt(),icon:(0,p.jsx)(m.Plus,{})}):null]}):null]}):void 0})]}),X?(0,p.jsx)(a.default,{open:tt,onOpenChange:nt,actions:cn,label:w.table.sortBy}):null,Z?(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(a.default,{open:rt,onOpenChange:it,actions:un,label:w.table.filterBy}),$?(0,p.jsx)(se.TableColumnFilterSheet,{column:$,value:U[$.key],onChange:e=>Et($.key,e),options:W[$.key]??[],open:st,onOpenChange:ct},$.key):null]}):null,pn?(0,p.jsx)(a.default,{open:$e,onOpenChange:et,actions:dn.map(e=>({...e,disabled:Y})),label:w.table.actions}):null]}):null,(0,p.jsx)(`div`,{ref:Vt,"data-slot":`table-scroll-viewport`,className:r.cn(`zui:relative zui:w-full zui:min-w-0 zui:overflow-x-auto zui-radius-xs zui:bg-[var(--zui-color-surface)] zui:shadow-[0_4px_14px_-12px_var(--zui-effect-shadow-ink-35)]`,Bt?`zui:overflow-y-auto`:void 0),style:Ht,onScroll:Gt,children:(0,p.jsx)(`table`,{ref:Re,"data-slot":`table`,className:r.cn(ie.tableVariants({showColumnBorder:Oe,showRowBorder:ke}),e),dir:E,children:O?(0,p.jsx)(re.TableActionsContext.Provider,{value:ht,children:(0,p.jsx)(oe.TableFilterRegistryContext.Provider,{value:Fe,children:je})}):A.length===0?(0,p.jsx)(d.TableBody,{children:(0,p.jsx)(d.TableRow,{children:(0,p.jsx)(d.TableCell,{className:`zui:py-7 zui:text-center zui:text-[var(--zui-color-text)]`,children:w.table.noColumns})})}):(0,p.jsxs)(p.Fragment,{children:[(0,p.jsxs)(`colgroup`,{children:[R?(0,p.jsx)(`col`,{style:Je}):null,A.map(e=>(0,p.jsx)(`col`,{style:Ye[e.key]},`col-${e.key}`)),z?(0,p.jsx)(`col`,{style:Xe}):null]}),(0,p.jsx)(d.TableHeader,{children:(0,p.jsxs)(d.TableRow,{children:[R?(0,p.jsx)(d.TableHead,{align:`center`,className:r.cn(l.rowNumberColumnClassName,qt?l.stickyHeaderCellClassName:void 0),children:w.table.rowNumber}):null,A.map(e=>{let t=e.sortable&&K?.sortKey===e.key?K.direction:void 0,r=e.sortable?(0,p.jsx)(de.default,{columnLabel:e.label,direction:t,onToggle:()=>Ot(e.key)}):null,i=e.filterable?(0,p.jsx)(se.default,{column:e,value:U[e.key],onChange:t=>Et(e.key,t),options:W[e.key]??[]}):null;return(0,p.jsx)(d.TableHead,{align:e.align,className:qt?l.stickyHeaderCellClassName:void 0,"aria-sort":e.sortable?u.resolveAriaSort(t):void 0,children:e.sortable||e.filterable?(0,p.jsxs)(`span`,{className:`zui:inline-flex zui:items-center zui:gap-2`,children:[n.localizeDigits(e.label,T),(0,p.jsxs)(`span`,{className:`zui:inline-flex zui:items-center`,children:[E===`rtl`?r:i,E===`rtl`?i:r]})]}):n.localizeDigits(e.label,T)},`head-${e.key}`)}),z?(0,p.jsx)(d.TableHead,{align:`center`,className:r.cn(l.actionsColumnClassName,l.actionsColumnStickyClassName,qt?l.stickyHeaderCellClassName:void 0),children:w.table.actions}):null]})}),(0,p.jsx)(d.TableBody,{children:Yt?(0,p.jsx)(ue.default,{count:Jt,keyPrefix:`loading`,showRowNumbers:R,columns:A,actionsCount:nn}):J.length===0?(0,p.jsx)(ce.default,{colSpan:A.length+ +!!z+ +!!R,showSearchInput:L,normalizedSearchTerm:bt,hasActiveFilters:wt>0,onClearFilters:Dt}):(0,p.jsxs)(p.Fragment,{children:[J.map(({row:e,rowIndex:t,rowId:i},a)=>{let o=i===void 0?`row-${t}`:`row-id-${String(i)}`,c=It?(Mt-1)*Pt+a+1:a+1;return(0,p.jsxs)(d.TableRow,{...k&&qe?{tabIndex:0,"aria-haspopup":`dialog`,"data-actionable":`true`,onClick:n=>{u.isInsideInteractiveControl(n)||vt(e,t,i)},onKeyDown:n=>{n.target===n.currentTarget&&(n.key===`Enter`||n.key===` `)&&(n.preventDefault(),vt(e,t,i))}}:{},children:[R?(0,p.jsx)(d.TableCell,{align:`center`,className:l.rowNumberColumnClassName,"data-label":w.table.rowNumber,children:n.localizeDigits(String(c),T)}):null,A.map(r=>{let a=`cell-${r.key}-${o}`;if(r.viewType===`select`){let o=Ze[r.key]??[],s=e[r.key],c=typeof s==`string`||typeof s==`number`?String(s):``;return(0,p.jsx)(d.TableCell,{align:r.align,"data-label":n.localizeDigits(r.label,T),children:(0,p.jsx)(ne.default,{disabled:V||o.length===0&&!r.optionsSource,placeholder:u.resolvePlaceholder(r),options:o,remoteOptions:r.optionsSource,value:c,onValueChange:n=>{let a=Array.isArray(n)?n[0]??``:n;_t(e,t,i,r.key,a)}})},a)}return(0,p.jsx)(d.TableCell,{align:r.align,"data-label":n.localizeDigits(r.label,T),children:u.formatCellValue(e[r.key],r,D)},a)}),z?(0,p.jsx)(d.TableCell,{align:`center`,"data-cell":`actions`,className:r.cn(l.actionsColumnClassName,l.actionsColumnStickyClassName),children:(0,p.jsxs)(`div`,{"data-slot":`table-row-actions`,className:`zui:flex zui:items-center zui:justify-center zui:gap-0.5`,children:[M?(0,p.jsx)(s.IconActionButton,{"data-slot":`table-action-edit-button`,label:w.common.edit,icon:(0,p.jsx)(m.Pencil,{className:l.actionIconClassName,"aria-hidden":`true`}),disabled:V,className:r.cn(l.rowActionButtonClassName,`zui:text-[var(--zui-theme-text-primary)]`),onClick:()=>void pt(e,t,i)}):null,I.map((n,a)=>(0,p.jsx)(s.IconActionButton,{"data-slot":`table-action-custom-button`,label:n.tooltip,icon:n.icon,disabled:V||n.disabled,className:r.cn(l.rowActionButtonClassName,n.danger?`zui:text-[var(--zui-theme-status-danger)]`:`zui:text-[var(--zui-theme-text-primary)]`,n.className),onClick:()=>void gt(n,e,t,i)},`${n.tooltip}-${a}`)),N?(0,p.jsx)(s.IconActionButton,{"data-slot":`table-action-delete-button`,label:w.common.delete,icon:(0,p.jsx)(m.Trash2,{className:l.actionIconClassName,"aria-hidden":`true`}),disabled:V,className:r.cn(l.rowActionButtonClassName,`zui:text-[var(--zui-theme-status-danger)]`),onClick:()=>void mt(e,t,i)}):null]})}):null]},o)}),Xt?(0,p.jsx)(ue.default,{count:tn,keyPrefix:`infinite-loading`,showRowNumbers:R,columns:A,actionsCount:nn}):null]})})]})})}),k&&(qe||O)?(0,p.jsx)(a.default,{open:lt.open,onOpenChange:e=>ut(t=>({...t,open:e})),actions:lt.actions,label:w.table.actions}):null,(0,p.jsx)(le.default,{shouldRenderInfiniteMode:Lt,shouldShowInfiniteLoadingStatus:Qt,shouldShowInfiniteReadyStatus:$t,shouldShowInfiniteCompletedStatus:en,shouldRenderPagination:It,loading:h,isRowActionBusy:V,currentPage:Mt,totalPages:Nt,onPageChange:Ut})]})});_e.displayName=`Table`,exports.default=_e;
|
|
@@ -54,7 +54,26 @@ export type TablePrintHandler = (input: TablePrintHandlerInput) => void | Promis
|
|
|
54
54
|
export type TableAction = {
|
|
55
55
|
icon: React.ReactNode;
|
|
56
56
|
onClick: (input: TableRowActionInput) => void | Promise<void>;
|
|
57
|
+
/** Shown as the button's tooltip and accessible name; on phones it is the label in the sheet. */
|
|
57
58
|
tooltip: string;
|
|
59
|
+
/** Added to the action's button (colour, size, hover...). Has no effect in the phone sheet. */
|
|
60
|
+
className?: string;
|
|
61
|
+
/** Greys the action out. */
|
|
62
|
+
disabled?: boolean;
|
|
63
|
+
/** Draws the action in the danger colour. */
|
|
64
|
+
danger?: boolean;
|
|
65
|
+
/** Leaves the action out (handy for per-row conditions). */
|
|
66
|
+
hidden?: boolean;
|
|
67
|
+
};
|
|
68
|
+
/** What a consumer may change about the built-in edit / delete actions of `TableRowActions`. */
|
|
69
|
+
export type TableDefaultActionOptions = {
|
|
70
|
+
/** Replaces the built-in icon. */
|
|
71
|
+
icon?: React.ReactNode;
|
|
72
|
+
/** Replaces the built-in tooltip (`messages.common.edit` / `messages.common.delete`). */
|
|
73
|
+
tooltip?: string;
|
|
74
|
+
className?: string;
|
|
75
|
+
disabled?: boolean;
|
|
76
|
+
hidden?: boolean;
|
|
58
77
|
};
|
|
59
78
|
export type TableCellSelectChangeHandlerInput = {
|
|
60
79
|
row: DynamicTableRow;
|
|
@@ -271,6 +290,28 @@ export type TableRowProps = Omit<React.ComponentPropsWithoutRef<"tr">, "slot"> &
|
|
|
271
290
|
/** Rendered as `data-slot`. */
|
|
272
291
|
slot?: "table-row" | "table-loading-row";
|
|
273
292
|
};
|
|
293
|
+
export type TableRowActionsProps = {
|
|
294
|
+
/**
|
|
295
|
+
* The row these actions belong to. A hand-written table does not hand its rows to the `Table`,
|
|
296
|
+
* so the handlers receive exactly what is given here (`row` falls back to `{}`, `rowIndex` to `0`).
|
|
297
|
+
*/
|
|
298
|
+
row?: DynamicTableRow;
|
|
299
|
+
rowIndex?: number;
|
|
300
|
+
rowId?: TableRowId;
|
|
301
|
+
/** Shows the built-in edit action (pencil). */
|
|
302
|
+
onEdit?: TableEditRowHandler;
|
|
303
|
+
/** Shows the built-in delete action (trash, danger colour). */
|
|
304
|
+
onDelete?: TableDeleteRowHandler;
|
|
305
|
+
/** Custom icon / tooltip / class for the built-in edit action. */
|
|
306
|
+
editAction?: TableDefaultActionOptions;
|
|
307
|
+
/** Custom icon / tooltip / class for the built-in delete action. */
|
|
308
|
+
deleteAction?: TableDefaultActionOptions;
|
|
309
|
+
/** Extra actions with their own icon, tooltip and handler; placed between edit and delete. */
|
|
310
|
+
actions?: TableAction[];
|
|
311
|
+
/** Added to the actions cell. */
|
|
312
|
+
className?: string;
|
|
313
|
+
};
|
|
314
|
+
export type TableActionsHeadProps = Omit<TableHeadProps, "align">;
|
|
274
315
|
export type TableHeadProps = Omit<React.ComponentPropsWithoutRef<"th">, "align"> & {
|
|
275
316
|
align?: TableColumnAlign;
|
|
276
317
|
/** @deprecated Use the standard `aria-sort` attribute. */
|
|
@@ -309,7 +350,7 @@ export type TableEmptyStateProps = {
|
|
|
309
350
|
onClearFilters?: () => void;
|
|
310
351
|
};
|
|
311
352
|
export type TableColumnFilterProps = {
|
|
312
|
-
column: TableSchemaColumn
|
|
353
|
+
column: Pick<TableSchemaColumn, "key" | "label" | "optionsSource">;
|
|
313
354
|
value: TableFilterValue | undefined;
|
|
314
355
|
onChange: (value: TableFilterValue | undefined) => void;
|
|
315
356
|
options: TableSelectOption[];
|