karsten-design-system 1.2.52 → 1.2.53
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/index.js +127 -21
- package/dist/index.js.map +1 -1
- package/dist/stories/components/fileUpload.d.ts +2 -1
- package/dist/stories/components/multiselect.d.ts +1 -0
- package/dist/stories/components/select.d.ts +1 -0
- package/dist/stories/components/table.d.ts +2 -1
- package/dist/types/stories/components/fileUpload.d.ts +2 -1
- package/dist/types/stories/components/multiselect.d.ts +1 -0
- package/dist/types/stories/components/select.d.ts +1 -0
- package/dist/types/stories/components/table.d.ts +2 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -302,10 +302,43 @@ function ExpandablePanel({ title, children, defaultOpen = true, }) {
|
|
|
302
302
|
return (jsx("div", { className: "relative p-[2px] rounded-lg mb-4", children: jsxs("div", { className: "rounded-lg overflow-hidden border shadow-container\n bg-light-500 border-light-600 text-primary\n dark:bg-dark-100 dark:border-dark-500 dark:shadow-dark-400 dark:text-light-500", children: [jsxs("div", { className: "flex justify-between items-center px-4 py-2 cursor-pointer\n bg-gradient-to-r from-[#f3f4f6] to-light-500\n dark:from-dark-300 dark:to-dark-100 dark:border-dark-400", onClick: () => setIsOpen(!isOpen), children: [jsx("div", { className: "text-xl font-bold", children: title }), jsx("button", { children: jsx("i", { className: `pi ${isOpen ? 'pi-chevron-down' : 'pi-chevron-up'} text-primary dark:text-light-500` }) })] }), isOpen && jsx("div", { className: "p-4", children: children })] }) }));
|
|
303
303
|
}
|
|
304
304
|
|
|
305
|
-
function FileUpload({ label = 'Enviar arquivos', value = [], onChange, multiple = true, fileTypes, className, error, disabled = false, }) {
|
|
305
|
+
function FileUpload({ label = 'Enviar arquivos', value = [], onChange, multiple = true, fileTypes, className, error, disabled = false, systemLanguage = 'pt', }) {
|
|
306
306
|
const [isDragging, setIsDragging] = useState(false);
|
|
307
307
|
const fileInputRef = useRef(null);
|
|
308
308
|
const [uploadFiles, setUploadFiles] = useState(value);
|
|
309
|
+
const messages = {
|
|
310
|
+
pt: {
|
|
311
|
+
supportsImages: 'Suporta apenas imagens',
|
|
312
|
+
supportsPdf: 'Suporta apenas PDFs',
|
|
313
|
+
supportsBoth: 'Suporta imagens e PDFs',
|
|
314
|
+
limitReached: 'Limite atingido',
|
|
315
|
+
dragDrop: 'Arraste e solte os arquivos aqui',
|
|
316
|
+
alreadySelected: 'Já possui um arquivo selecionado',
|
|
317
|
+
orClick: 'ou clique para selecionar arquivos',
|
|
318
|
+
selectedFiles: 'Arquivos selecionados',
|
|
319
|
+
},
|
|
320
|
+
en: {
|
|
321
|
+
supportsImages: 'Supports only images',
|
|
322
|
+
supportsPdf: 'Supports only PDFs',
|
|
323
|
+
supportsBoth: 'Supports images and PDFs',
|
|
324
|
+
limitReached: 'Limit reached',
|
|
325
|
+
dragDrop: 'Drag and drop files here',
|
|
326
|
+
alreadySelected: 'File already selected',
|
|
327
|
+
orClick: 'or click to select files',
|
|
328
|
+
selectedFiles: 'Selected files',
|
|
329
|
+
},
|
|
330
|
+
es: {
|
|
331
|
+
supportsImages: 'Soporta solo imágenes',
|
|
332
|
+
supportsPdf: 'Soporta solo PDFs',
|
|
333
|
+
supportsBoth: 'Soporta imágenes y PDFs',
|
|
334
|
+
limitReached: 'Límite alcanzado',
|
|
335
|
+
dragDrop: 'Arrastra y suelta los archivos aquí',
|
|
336
|
+
alreadySelected: 'Ya hay un archivo seleccionado',
|
|
337
|
+
orClick: 'o haz clic para seleccionar archivos',
|
|
338
|
+
selectedFiles: 'Archivos seleccionados',
|
|
339
|
+
},
|
|
340
|
+
};
|
|
341
|
+
const lang = messages[systemLanguage || 'pt'];
|
|
309
342
|
useEffect(() => {
|
|
310
343
|
setUploadFiles(value);
|
|
311
344
|
}, [value]);
|
|
@@ -358,11 +391,11 @@ function FileUpload({ label = 'Enviar arquivos', value = [], onChange, multiple
|
|
|
358
391
|
const includesImage = types.includes('image');
|
|
359
392
|
const includesPdf = types.includes('pdf');
|
|
360
393
|
if (includesImage && includesPdf)
|
|
361
|
-
return
|
|
394
|
+
return lang.supportsBoth;
|
|
362
395
|
if (includesImage)
|
|
363
|
-
return
|
|
396
|
+
return lang.supportsImages;
|
|
364
397
|
if (includesPdf)
|
|
365
|
-
return
|
|
398
|
+
return lang.supportsPdf;
|
|
366
399
|
return '';
|
|
367
400
|
};
|
|
368
401
|
const handleDragOver = (e) => {
|
|
@@ -384,9 +417,7 @@ function FileUpload({ label = 'Enviar arquivos', value = [], onChange, multiple
|
|
|
384
417
|
const isDisabled = !multiple && visibleFiles.length > 0;
|
|
385
418
|
return (jsxs("div", { className: clsx('space-y-3', className), children: [jsx("label", { htmlFor: "file-upload", className: "text-[18px] font-medium text-primary dark:text-light-500", children: label }), jsxs("div", { role: "button", "aria-label": "\u00C1rea de envio de arquivos", "aria-disabled": isDisabled || disabled, className: clsx('border-2 border-dashed rounded-lg p-2 text-center cursor-pointer transition-colors', isDragging && !error
|
|
386
419
|
? 'border-primary bg-primary/5'
|
|
387
|
-
: 'border-[#e6e6e6] hover:border-primary/50 dark:hover:border-light-500 dark:border-light-100', isDisabled || (disabled && 'bg-gray-200 cursor-auto'), error && 'border-red-500 hover:border-red-500'), onDragOver: handleDragOver, onDragLeave: handleDragLeave, onDrop: handleDrop, onClick: () => fileInputRef.current?.click(), children: [jsx("input", { id: "file-upload", ref: fileInputRef, type: "file", onChange: (e) => handleFileChange(e.target.files), className: "hidden", multiple: multiple, accept: getAcceptedMimeTypes(fileTypes), disabled: isDisabled || disabled }), jsxs("div", { className: "flex flex-col items-center justify-center space-y-3", children: [jsx("i", { className: "pi pi-upload text-xl text-[#a0a4b3]" }), jsx("p", { className: "text-lg font-semibold text-primary dark:text-light-500", children: isDisabled ?
|
|
388
|
-
? 'Já possui um arquivo selecionado'
|
|
389
|
-
: 'ou clique para selecionar arquivos' }), jsx("p", { className: "text-xs text-[#a0a4b3]", children: getSupportedFileText(fileTypes) })] })] }), error && (jsx("span", { className: "text-redError text-xs", role: "alert", "aria-live": "assertive", children: error })), visibleFiles.length > 0 && (jsxs("div", { className: "space-y-4", children: [jsxs("p", { className: "text-base text-[#a0a4b3]", children: ["Arquivos selecionados (", visibleFiles.length, ")"] }), jsx("div", { className: "grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4", children: visibleFiles.map((file, index) => (jsxs("div", { className: "relative group overflow-hidden rounded border border-gray-200", children: [jsx("div", { className: "aspect-square bg-[#e6e6e6] flex items-center justify-center", children: file.type === 'image' && file.previewUrl ? (jsx("img", { src: file?.previewUrl, alt: file?.file?.name || file?.name, className: "object-cover w-full h-full transition-transform duration-300 ease-in-out group-hover:scale-105" })) : (jsxs("div", { className: "flex flex-col items-center justify-center p-4 transition-transform duration-300 ease-in-out group-hover:scale-105", children: [jsx("i", { className: "pi pi-file-pdf text-4xl text-primary" }), jsx("span", { className: "mt-2 text-xs text-center truncate max-w-full", children: file?.file?.name || file?.name })] })) }), jsx("button", { type: "button", className: "absolute top-1 right-1 w-6 h-6 flex items-center justify-center bg-primary hover:bg-primaryActive rounded-full transition-colors", onClick: (e) => {
|
|
420
|
+
: 'border-[#e6e6e6] hover:border-primary/50 dark:hover:border-light-500 dark:border-light-100', isDisabled || (disabled && 'bg-gray-200 cursor-auto'), error && 'border-red-500 hover:border-red-500'), onDragOver: handleDragOver, onDragLeave: handleDragLeave, onDrop: handleDrop, onClick: () => fileInputRef.current?.click(), children: [jsx("input", { id: "file-upload", ref: fileInputRef, type: "file", onChange: (e) => handleFileChange(e.target.files), className: "hidden", multiple: multiple, accept: getAcceptedMimeTypes(fileTypes), disabled: isDisabled || disabled }), jsxs("div", { className: "flex flex-col items-center justify-center space-y-3", children: [jsx("i", { className: "pi pi-upload text-xl text-[#a0a4b3]" }), jsx("p", { className: "text-lg font-semibold text-primary dark:text-light-500", children: isDisabled ? lang.limitReached : lang.dragDrop }), jsx("p", { className: "text-sm text-[#a0a4b3]", children: isDisabled ? lang.alreadySelected : lang.orClick }), jsx("p", { className: "text-xs text-[#a0a4b3]", children: getSupportedFileText(fileTypes) })] })] }), error && (jsx("span", { className: "text-redError text-xs", role: "alert", "aria-live": "assertive", children: error })), visibleFiles.length > 0 && (jsxs("div", { className: "space-y-4", children: [jsxs("p", { className: "text-base text-[#a0a4b3]", children: [lang.selectedFiles, " (", visibleFiles.length, ")"] }), jsx("div", { className: "grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4", children: visibleFiles.map((file, index) => (jsxs("div", { className: "relative group overflow-hidden rounded border border-gray-200", children: [jsx("div", { className: "aspect-square bg-[#e6e6e6] flex items-center justify-center", children: file.type === 'image' && file.previewUrl ? (jsx("img", { src: file?.previewUrl, alt: file?.file?.name || file?.name, className: "object-cover w-full h-full transition-transform duration-300 ease-in-out group-hover:scale-105" })) : (jsxs("div", { className: "flex flex-col items-center justify-center p-4 transition-transform duration-300 ease-in-out group-hover:scale-105", children: [jsx("i", { className: "pi pi-file-pdf text-4xl text-primary" }), jsx("span", { className: "mt-2 text-xs text-center truncate max-w-full", children: file?.file?.name || file?.name })] })) }), jsx("button", { type: "button", className: "absolute top-1 right-1 w-6 h-6 flex items-center justify-center bg-primary hover:bg-primaryActive rounded-full transition-colors", onClick: (e) => {
|
|
390
421
|
e.stopPropagation();
|
|
391
422
|
handleRemoveFile(file);
|
|
392
423
|
}, "aria-label": `Remover o arquivo ${file.file?.name || file.name}`, children: jsx("i", { className: "pi pi-times text-light-500 text-xs hover:text-slate-200" }) })] }, index))) })] }))] }));
|
|
@@ -789,7 +820,7 @@ function ModalForm({ isOpen, title, description, onClose, children, }) {
|
|
|
789
820
|
}
|
|
790
821
|
|
|
791
822
|
function MultiSelect(props) {
|
|
792
|
-
const { options, placeholder = 'Selecione uma opção', label = 'Opção', disabled = false, error, isLoading = false, isReadOnly = true, ariaLabel = 'Selecione uma ou mais opções', isLoadingOptions = false, } = props;
|
|
823
|
+
const { options, placeholder = 'Selecione uma opção', label = 'Opção', disabled = false, error, isLoading = false, isReadOnly = true, ariaLabel = 'Selecione uma ou mais opções', isLoadingOptions = false, systemLanguage = 'pt', } = props;
|
|
793
824
|
const [isOpen, setIsOpen] = useState(false);
|
|
794
825
|
const [visibleText, setVisibleText] = useState('');
|
|
795
826
|
const [searchText, setSearchText] = useState('');
|
|
@@ -797,6 +828,24 @@ function MultiSelect(props) {
|
|
|
797
828
|
const containerRef = useRef(null);
|
|
798
829
|
const inputRef = useRef(null);
|
|
799
830
|
const hasOnInputChange = props?.onInputChange !== undefined;
|
|
831
|
+
const messages = {
|
|
832
|
+
pt: {
|
|
833
|
+
loadingMessage: 'Carregando...',
|
|
834
|
+
typeToSearchMessage: 'Digite para buscar',
|
|
835
|
+
noResultsFoundMessage: 'Nenhum resultado encontrado',
|
|
836
|
+
},
|
|
837
|
+
en: {
|
|
838
|
+
loadingMessage: 'Loading...',
|
|
839
|
+
typeToSearchMessage: 'Type to search',
|
|
840
|
+
noResultsFoundMessage: 'No results found',
|
|
841
|
+
},
|
|
842
|
+
es: {
|
|
843
|
+
loadingMessage: 'Cargando...',
|
|
844
|
+
typeToSearchMessage: 'Escribe para buscar',
|
|
845
|
+
noResultsFoundMessage: 'No se encontraron resultados',
|
|
846
|
+
},
|
|
847
|
+
};
|
|
848
|
+
const lang = messages[systemLanguage || 'pt'];
|
|
800
849
|
const normalize = (str) => str
|
|
801
850
|
.normalize('NFD')
|
|
802
851
|
.replace(/[\u0300-\u036f]/g, '')
|
|
@@ -896,7 +945,7 @@ function MultiSelect(props) {
|
|
|
896
945
|
}
|
|
897
946
|
}, [props.value]);
|
|
898
947
|
return (jsxs("div", { ref: containerRef, className: "relative flex flex-col w-100", children: [jsxs("div", { className: "relative w-full cursor-pointer", onClick: toggleDropdown, children: [jsx(FloatingLabel, { value: selectedText(), label: label, disabled: isInputDisabled, error: error }), jsxs(IconField, { className: "w-full", children: [jsx(InputText, { ref: inputRef, placeholder: placeholder, type: "text", value: isLoading
|
|
899
|
-
?
|
|
948
|
+
? lang.loadingMessage
|
|
900
949
|
: isOpen && !isReadOnly
|
|
901
950
|
? searchText
|
|
902
951
|
: visibleText, onChange: (e) => {
|
|
@@ -935,8 +984,8 @@ function MultiSelect(props) {
|
|
|
935
984
|
? 'pi pi-spinner pi-spin'
|
|
936
985
|
: isOpen
|
|
937
986
|
? 'pi pi-angle-up'
|
|
938
|
-
: 'pi pi-angle-down', 'text-light-700 px-2 flex items-center cursor-pointer', isInputDisabled && 'text-disabled', error && 'text-redError'), onClick: toggleDropdown })] })] }), isOpen && (jsx("div", { className: clsx('absolute w-full bg-light-500 border shadow-md z-40 rounded-md p-2 -bottom-1 translate-y-full dark:bg-dark-100', error ? 'border-redError' : 'border-light-700'), children: isLoadingOptions ? (jsxs("div", { className: "p-4 text-center text-light-700 flex items-center justify-center gap-2", children: [
|
|
939
|
-
props.value.some((v) => v.value === option.value), onChange: () => handleSelect(option), className: clsx('appearance-none w-2 h-2 ring-1 ring-offset-2 ring-offset-light-500 ring-light-700 checked:bg-primary cursor-pointer rounded-md dark:bg-dark-100 dark:checked:bg-light-500 dark:checked:border-light-500 dark:ring-offset-dark-100 dark:ring-offset-2') })] }, option.value))) })) : (jsx("div", { className: "p-4 text-center text-light-700", children:
|
|
987
|
+
: 'pi pi-angle-down', 'text-light-700 px-2 flex items-center cursor-pointer', isInputDisabled && 'text-disabled', error && 'text-redError'), onClick: toggleDropdown })] })] }), isOpen && (jsx("div", { className: clsx('absolute w-full bg-light-500 border shadow-md z-40 rounded-md p-2 -bottom-1 translate-y-full dark:bg-dark-100', error ? 'border-redError' : 'border-light-700'), children: isLoadingOptions ? (jsxs("div", { className: "p-4 text-center text-light-700 flex items-center justify-center gap-2", children: [lang.loadingMessage, jsx("i", { className: "pi pi-spinner pi-spin" })] })) : props.onInputChange && searchText.length === 0 && !props.value ? (jsx("div", { className: "p-4 text-center text-light-700", children: lang.typeToSearchMessage })) : filteredOptions.length > 0 ? (jsx("ul", { className: "max-h-60 overflow-y-auto", children: filteredOptions.map((option, index) => (jsxs("li", { onClick: () => handleSelect(option), className: clsx('p-2 flex justify-between items-center cursor-pointer', 'hover:bg-light-300 hover:font-bold dark:bg-dark-100 dark:text-light-500 dark:hover:bg-dark-400', index === highlightedIndex && 'bg-light-300 font-bold'), title: option.label, children: [jsx("span", { className: "truncate max-w-[calc(100%-20px)]", children: option.label }), jsx("input", { type: 'checkbox', checked: Array.isArray(props.value) &&
|
|
988
|
+
props.value.some((v) => v.value === option.value), onChange: () => handleSelect(option), className: clsx('appearance-none w-2 h-2 ring-1 ring-offset-2 ring-offset-light-500 ring-light-700 checked:bg-primary cursor-pointer rounded-md dark:bg-dark-100 dark:checked:bg-light-500 dark:checked:border-light-500 dark:ring-offset-dark-100 dark:ring-offset-2') })] }, option.value))) })) : (jsx("div", { className: "p-4 text-center text-light-700", children: lang.noResultsFoundMessage })) })), hasError && jsx("span", { className: "text-redError text-xs px-2", children: error })] }));
|
|
940
989
|
}
|
|
941
990
|
|
|
942
991
|
/**
|
|
@@ -4265,12 +4314,30 @@ function RadioButton({ label, value, checked, onChange, disabled = false, error
|
|
|
4265
4314
|
}
|
|
4266
4315
|
|
|
4267
4316
|
function Select(props) {
|
|
4268
|
-
const { options, placeholder = 'Selecione uma opção', label = 'Opção', disabled = false, error, isLoading = false, isReadOnly = true, ariaLabel = 'Selecione uma opção', isLoadingOptions = false, } = props;
|
|
4317
|
+
const { options, placeholder = 'Selecione uma opção', label = 'Opção', disabled = false, error, isLoading = false, isReadOnly = true, ariaLabel = 'Selecione uma opção', isLoadingOptions = false, systemLanguage = 'pt', } = props;
|
|
4269
4318
|
const [isOpen, setIsOpen] = useState(false);
|
|
4270
4319
|
const [searchText, setSearchText] = useState('');
|
|
4271
4320
|
const [highlightedIndex, setHighlightedIndex] = useState(-1);
|
|
4272
4321
|
const containerRef = useRef(null);
|
|
4273
4322
|
const inputRef = useRef(null);
|
|
4323
|
+
const messages = {
|
|
4324
|
+
pt: {
|
|
4325
|
+
loadingMessage: 'Carregando...',
|
|
4326
|
+
typeToSearchMessage: 'Digite para buscar',
|
|
4327
|
+
noResultsFoundMessage: 'Nenhum resultado encontrado',
|
|
4328
|
+
},
|
|
4329
|
+
en: {
|
|
4330
|
+
loadingMessage: 'Loading...',
|
|
4331
|
+
typeToSearchMessage: 'Type to search',
|
|
4332
|
+
noResultsFoundMessage: 'No results found',
|
|
4333
|
+
},
|
|
4334
|
+
es: {
|
|
4335
|
+
loadingMessage: 'Cargando...',
|
|
4336
|
+
typeToSearchMessage: 'Escribe para buscar',
|
|
4337
|
+
noResultsFoundMessage: 'No se encontraron resultados',
|
|
4338
|
+
},
|
|
4339
|
+
};
|
|
4340
|
+
const lang = messages[systemLanguage || 'pt'];
|
|
4274
4341
|
const hasOnInputChange = props?.onInputChange !== undefined;
|
|
4275
4342
|
const normalize = (str) => str
|
|
4276
4343
|
.normalize('NFD')
|
|
@@ -4353,7 +4420,7 @@ function Select(props) {
|
|
|
4353
4420
|
};
|
|
4354
4421
|
}, []);
|
|
4355
4422
|
return (jsxs("div", { ref: containerRef, className: "relative flex flex-col w-100", children: [jsxs("div", { className: "relative w-full cursor-pointer", onClick: toggleDropdown, children: [jsx(FloatingLabel, { value: props.value ? props.value.label : '', label: label, disabled: isInputDisabled, error: error }), jsxs(IconField, { className: "w-full", children: [jsx(InputText, { ref: inputRef, placeholder: placeholder, type: "text", value: isLoading
|
|
4356
|
-
?
|
|
4423
|
+
? lang.loadingMessage
|
|
4357
4424
|
: isOpen
|
|
4358
4425
|
? searchText
|
|
4359
4426
|
: (props.value?.label ?? ''), onClick: toggleDropdown, onChange: (e) => {
|
|
@@ -4394,7 +4461,7 @@ function Select(props) {
|
|
|
4394
4461
|
? 'pi pi-spinner pi-spin'
|
|
4395
4462
|
: isOpen
|
|
4396
4463
|
? 'pi pi-angle-up'
|
|
4397
|
-
: 'pi pi-angle-down', 'text-light-700 px-2 flex items-center cursor-pointer', isInputDisabled && 'text-disabled', error && 'text-redError'), onClick: toggleDropdown })] })] }), isOpen && (jsx("div", { className: clsx('absolute w-full bg-light-500 border shadow-md z-40 rounded-md p-2 -bottom-1 translate-y-full dark:bg-dark-100', error ? 'border-redError' : 'border-light-700'), children: isLoadingOptions ? (jsxs("div", { className: "p-4 text-center text-light-700 flex items-center justify-center gap-2", children: [
|
|
4464
|
+
: 'pi pi-angle-down', 'text-light-700 px-2 flex items-center cursor-pointer', isInputDisabled && 'text-disabled', error && 'text-redError'), onClick: toggleDropdown })] })] }), isOpen && (jsx("div", { className: clsx('absolute w-full bg-light-500 border shadow-md z-40 rounded-md p-2 -bottom-1 translate-y-full dark:bg-dark-100', error ? 'border-redError' : 'border-light-700'), children: isLoadingOptions ? (jsxs("div", { className: "p-4 text-center text-light-700 flex items-center justify-center gap-2", children: [lang.loadingMessage, jsx("i", { className: "pi pi-spinner pi-spin" })] })) : props.onInputChange && searchText.length === 0 && !props.value ? (jsx("div", { className: "p-4 text-center text-light-700", children: lang.typeToSearchMessage })) : filteredOptions.length > 0 ? (jsx("ul", { className: "max-h-60 overflow-y-auto", children: filteredOptions.map((option, index) => (jsxs("li", { onClick: () => handleSelect(option), className: clsx('p-2 flex justify-between items-center cursor-pointer', 'hover:bg-light-300 hover:font-bold dark:bg-dark-100 dark:text-light-500 dark:hover:bg-dark-400', index === highlightedIndex && 'bg-light-300 font-bold'), children: [jsx("span", { className: "truncate max-w-[calc(100%-20px)]", children: option.label }), jsx("input", { type: 'radio', checked: props.value?.value === option.value, onChange: () => handleSelect(option), className: clsx('appearance-none w-2 h-2 rounded-full ring-1 ring-offset-2 ring-offset-light-500 ring-light-700 checked:bg-primary cursor-pointer dark:bg-dark-100 dark:checked:bg-light-500 dark:checked:border-light-500 dark:ring-offset-dark-100 dark:ring-offset-2') })] }, option.value))) })) : (jsx("div", { className: "p-4 text-center text-light-700", children: lang.noResultsFoundMessage })) })), hasError && jsx("span", { className: "text-redError text-xs px-2", children: error })] }));
|
|
4398
4465
|
}
|
|
4399
4466
|
|
|
4400
4467
|
function Skeleton({ shape = 'rectangle', width = '100%', height = '1rem', borderRadius, animation = 'wave', size, className, }) {
|
|
@@ -4476,7 +4543,7 @@ function parseDateRange(value) {
|
|
|
4476
4543
|
return [null, null];
|
|
4477
4544
|
}
|
|
4478
4545
|
}
|
|
4479
|
-
function Table({ columns, data, totalRecords, actions = [], isOrdered = true, actionsHeaderClassName = '', actionsColumnsClassName = '', rowsPerPage = 10, onPageChange, isPaginated = true, isLoading = false, onFilterChange, onSortChange, actionLabel = 'AÇÕES', }) {
|
|
4546
|
+
function Table({ columns, data, totalRecords, actions = [], isOrdered = true, actionsHeaderClassName = '', actionsColumnsClassName = '', rowsPerPage = 10, onPageChange, isPaginated = true, isLoading = false, onFilterChange, onSortChange, actionLabel = 'AÇÕES', systemLanguage = 'pt', }) {
|
|
4480
4547
|
const [sortDirection, setSortDirection] = useState({});
|
|
4481
4548
|
const [sortedData, setSortedData] = useState(data);
|
|
4482
4549
|
const [currentPage, setCurrentPage] = useState(1);
|
|
@@ -4486,6 +4553,45 @@ function Table({ columns, data, totalRecords, actions = [], isOrdered = true, ac
|
|
|
4486
4553
|
const filterButtonRefs = useRef({});
|
|
4487
4554
|
const [filterModalPosition, setFilterModalPosition] = useState(null);
|
|
4488
4555
|
const [filterStatus, setFilterStatus] = useState({});
|
|
4556
|
+
const messages = {
|
|
4557
|
+
pt: {
|
|
4558
|
+
filterByMessage: 'Filtrar por',
|
|
4559
|
+
typeToFilterMessage: 'Digite para filtrar',
|
|
4560
|
+
selectOptionMessage: 'Selecione uma opção',
|
|
4561
|
+
selectOneOrMoreOptionsMessage: 'Selecione uma ou mais opções',
|
|
4562
|
+
selectDateMessage: 'Selecione uma data',
|
|
4563
|
+
selectDatesMessage: 'Selecione as datas',
|
|
4564
|
+
buttonCloseMessage: 'Fechar',
|
|
4565
|
+
buttonClearFilterMessage: 'Limpar',
|
|
4566
|
+
buttonApplyFilterMessage: 'Aplicar',
|
|
4567
|
+
noResultsMessage: 'Não há dados disponíveis',
|
|
4568
|
+
},
|
|
4569
|
+
en: {
|
|
4570
|
+
filterByMessage: 'Filter by',
|
|
4571
|
+
typeToFilterMessage: 'Type to filter',
|
|
4572
|
+
selectOptionMessage: 'Select an option',
|
|
4573
|
+
selectOneOrMoreOptionsMessage: 'Select one or more options',
|
|
4574
|
+
selectDateMessage: 'Select a date',
|
|
4575
|
+
selectDatesMessage: 'Select dates',
|
|
4576
|
+
buttonCloseMessage: 'Close',
|
|
4577
|
+
buttonClearFilterMessage: 'Clear',
|
|
4578
|
+
buttonApplyFilterMessage: 'Apply',
|
|
4579
|
+
noResultsMessage: 'No data available',
|
|
4580
|
+
},
|
|
4581
|
+
es: {
|
|
4582
|
+
filterByMessage: 'Filtrar por',
|
|
4583
|
+
typeToFilterMessage: 'Escribe para filtrar',
|
|
4584
|
+
selectOptionMessage: 'Seleccione una opción',
|
|
4585
|
+
selectOneOrMoreOptionsMessage: 'Seleccione una o más opciones',
|
|
4586
|
+
selectDateMessage: 'Seleccione una fecha',
|
|
4587
|
+
selectDatesMessage: 'Seleccione las fechas',
|
|
4588
|
+
buttonCloseMessage: 'Cerrar',
|
|
4589
|
+
buttonClearFilterMessage: 'Limpiar',
|
|
4590
|
+
buttonApplyFilterMessage: 'Aplicar',
|
|
4591
|
+
noResultsMessage: 'No hay datos disponibles',
|
|
4592
|
+
},
|
|
4593
|
+
};
|
|
4594
|
+
const lang = messages[systemLanguage || 'pt'];
|
|
4489
4595
|
const handleSort = (dataIndex) => {
|
|
4490
4596
|
setSortDirection((prev) => {
|
|
4491
4597
|
const current = prev[dataIndex];
|
|
@@ -4586,21 +4692,21 @@ function Table({ columns, data, totalRecords, actions = [], isOrdered = true, ac
|
|
|
4586
4692
|
border: '1px solid var(--tw-border-light-500, #e5e7eb)',
|
|
4587
4693
|
color: 'var(--tw-text-primary, #222)',
|
|
4588
4694
|
padding: 16,
|
|
4589
|
-
}, className: "normal-case bg-light-500 dark:bg-dark-100 dark:text-light-500", children: [jsxs("div", { className: "space-y-4 text-primary dark:text-light-500", children: [jsxs("h1", { className: "text-primary text-sm dark:text-light-500", children: ["
|
|
4695
|
+
}, className: "normal-case bg-light-500 dark:bg-dark-100 dark:text-light-500", children: [jsxs("div", { className: "space-y-4 text-primary dark:text-light-500", children: [jsxs("h1", { className: "text-primary text-sm dark:text-light-500", children: [lang.filterByMessage, " ", column?.label?.toLowerCase()] }), jsxs("div", { className: "w-full", children: [column.filterType === 'text' && (jsx(Input, { placeholder: lang.typeToFilterMessage, value: filters[column.dataIndex] || '', onChange: (e) => setFilters((prev) => ({
|
|
4590
4696
|
...prev,
|
|
4591
4697
|
[column.dataIndex]: e,
|
|
4592
4698
|
})), mask: column?.mask, "aria-label": `Filtrar por ${column.label}`, maxLength: column?.maxLength || 40 })), column.filterType === 'select' && (jsx(Select, { options: column.filterOptions || [], value: column.filterOptions?.find((option) => option.value ===
|
|
4593
4699
|
filters[column.dataIndex]) || null, onChange: (selected) => setFilters((prev) => ({
|
|
4594
4700
|
...prev,
|
|
4595
4701
|
[column.dataIndex]: selected?.value ?? null,
|
|
4596
|
-
})), placeholder:
|
|
4702
|
+
})), placeholder: lang.selectOptionMessage, label: "", "aria-label": `Filtrar por ${column.label}`, isReadOnly: !column.isSearchableInSelectMode })), column.filterType === 'multiSelect' && (jsx(MultiSelect, { options: column.filterOptions || [], value: (filters[column.dataIndex]
|
|
4597
4703
|
? JSON.parse(filters[column.dataIndex])
|
|
4598
4704
|
: []), onChange: (selected) => setFilters((prev) => ({
|
|
4599
4705
|
...prev,
|
|
4600
4706
|
[column.dataIndex]: selected
|
|
4601
4707
|
? JSON.stringify(selected)
|
|
4602
4708
|
: '',
|
|
4603
|
-
})), placeholder:
|
|
4709
|
+
})), placeholder: lang.selectOneOrMoreOptionsMessage, label: "", "aria-label": `Filtrar por ${column.label}` })), column.filterType === 'singleDate' && (jsx(CalendarInput, { label: "", selectionMode: "single", placeholder: lang.selectDateMessage, value: filters[column.dataIndex]
|
|
4604
4710
|
? new Date(filters[column.dataIndex])
|
|
4605
4711
|
: null, onChange: (e) => {
|
|
4606
4712
|
const value = e?.value;
|
|
@@ -4610,7 +4716,7 @@ function Table({ columns, data, totalRecords, actions = [], isOrdered = true, ac
|
|
|
4610
4716
|
? value.toISOString()
|
|
4611
4717
|
: '',
|
|
4612
4718
|
}));
|
|
4613
|
-
}, ariaLabel: `Filtrar por ${column.label}`, showTime: column.isShowTimeInDateMode ? true : false })), column.filterType === 'rangeDate' && (jsx(CalendarInput, { label: "", selectionMode: "range", placeholder:
|
|
4719
|
+
}, ariaLabel: `Filtrar por ${column.label}`, showTime: column.isShowTimeInDateMode ? true : false })), column.filterType === 'rangeDate' && (jsx(CalendarInput, { label: "", selectionMode: "range", placeholder: lang.selectDatesMessage, value: filters[column.dataIndex]
|
|
4614
4720
|
? parseDateRange(filters[column.dataIndex])
|
|
4615
4721
|
: null, onChange: (e) => {
|
|
4616
4722
|
const range = e?.value;
|
|
@@ -4631,7 +4737,7 @@ function Table({ columns, data, totalRecords, actions = [], isOrdered = true, ac
|
|
|
4631
4737
|
}));
|
|
4632
4738
|
setOpenFilter(null);
|
|
4633
4739
|
setFilterModalPosition(null);
|
|
4634
|
-
}, label:
|
|
4740
|
+
}, label: lang.buttonCloseMessage, width: "10", size: "small", "aria-label": "Fechar filtro" }), jsx(Button, { variant: "secondary", onClick: () => handleClearFilter(column), label: lang.buttonClearFilterMessage, width: "10", size: "small", "aria-label": "Limpar filtro" }), jsx(Button, { variant: "primary", onClick: () => handleFilter(column), label: lang.buttonApplyFilterMessage, width: "10", size: "small", "aria-label": "Aplicar filtro" })] })] })) }), jsxs("div", { className: "flex flex-col items-start", children: [column.label, isOrdered && (jsxs("div", { className: "flex flex-row", children: [jsx("button", { onClick: () => handleSort(column.dataIndex), "aria-label": `Ordenar por ${column.label}`, children: jsx("i", { className: clsx('text-xs cursor-pointer pi', sortDirection[column.dataIndex] === 'ASC' &&
|
|
4635
4741
|
'pi-sort-amount-up-alt', sortDirection[column.dataIndex] === 'DESC' &&
|
|
4636
4742
|
'pi-sort-amount-down', !sortDirection[column.dataIndex] && 'pi-sort-alt') }) }), column.filterable && (jsx(Fragment, { children: jsx("button", { ref: (el) => {
|
|
4637
4743
|
filterButtonRefs.current[column.dataIndex] = el;
|
|
@@ -4657,7 +4763,7 @@ function Table({ columns, data, totalRecords, actions = [], isOrdered = true, ac
|
|
|
4657
4763
|
if (!isDisabled)
|
|
4658
4764
|
action.onClick(row);
|
|
4659
4765
|
}, "aria-label": action?.ariaLabel || action.label, role: "button", children: jsx(Tooltip, { text: action?.label, children: action.icon }) }, idx));
|
|
4660
|
-
}) }))] }, index)))) : (jsx("tr", { children: jsxs("td", { colSpan: columns.length + (actions.length > 0 ? 1 : 0), className: "p-6 text-center text-primary bg-light-300 dark:text-light-500 dark:bg-dark-200", children: [jsx("i", { className: "pi pi-database mr-2" }), "
|
|
4766
|
+
}) }))] }, index)))) : (jsx("tr", { children: jsxs("td", { colSpan: columns.length + (actions.length > 0 ? 1 : 0), className: "p-6 text-center text-primary bg-light-300 dark:text-light-500 dark:bg-dark-200", children: [jsx("i", { className: "pi pi-database mr-2" }), " ", lang.noResultsMessage] }) })) })] }), sortedData.length > 0 && isPaginated && (jsx(Paginator, { first: (currentPage - 1) * rowsPerPage, rows: rowsPerPage, totalRecords: totalRecords, onPageChange: (event) => {
|
|
4661
4767
|
setCurrentPage(event.page + 1);
|
|
4662
4768
|
onPageChange(event.page + 1);
|
|
4663
4769
|
} }))] }));
|