karsten-design-system 1.1.73 → 1.1.74

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 CHANGED
@@ -704,12 +704,13 @@ function Modal({ title, size = 'md', onClose, onConfirm, labelCloseButton = 'Fec
704
704
  }
705
705
 
706
706
  function MultiSelect(props) {
707
- const { options, placeholder = 'Selecione uma opção', label = 'Opção', disabled = false, error, isLoading = false, isReadOnly = true, ariaLabel = 'Selecione uma ou mais opções', } = props;
707
+ 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;
708
708
  const [isOpen, setIsOpen] = useState(false);
709
709
  const [visibleText, setVisibleText] = useState('');
710
710
  const [searchText, setSearchText] = useState('');
711
711
  const [highlightedIndex, setHighlightedIndex] = useState(-1);
712
712
  const containerRef = useRef(null);
713
+ const inputRef = useRef(null);
713
714
  const normalize = (str) => str
714
715
  .normalize('NFD')
715
716
  .replace(/[\u0300-\u036f]/g, '')
@@ -723,6 +724,11 @@ function MultiSelect(props) {
723
724
  setSearchText('');
724
725
  setHighlightedIndex(-1);
725
726
  }
727
+ else {
728
+ setTimeout(() => {
729
+ inputRef.current?.focus();
730
+ }, 0);
731
+ }
726
732
  }
727
733
  };
728
734
  const handleSelect = (option) => {
@@ -733,12 +739,17 @@ function MultiSelect(props) {
733
739
  : [...currentValues, option];
734
740
  props.onChange(newValues.length > 0 ? newValues : null);
735
741
  setSearchText('');
736
- const newFiltered = options.filter((opt) => normalize(opt.label).includes(normalize('')));
742
+ const newFiltered = options.filter((opt) => normalize(opt.label).includes(''));
737
743
  const newIndex = newFiltered.findIndex((o) => o.value === option.value);
738
744
  setHighlightedIndex(newIndex);
739
745
  };
740
746
  const hasError = !!error && !disabled;
741
747
  const isInputDisabled = disabled || isLoading;
748
+ useEffect(() => {
749
+ if (isOpen) {
750
+ inputRef.current?.focus();
751
+ }
752
+ }, [isOpen, options]);
742
753
  useEffect(() => {
743
754
  const handleClickOutside = (event) => {
744
755
  if (containerRef.current &&
@@ -774,7 +785,7 @@ function MultiSelect(props) {
774
785
  setVisibleText(`${count} itens selecionados`);
775
786
  }
776
787
  }, [props.value]);
777
- 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, { placeholder: placeholder, type: "text", value: isLoading
788
+ 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
778
789
  ? 'Carregando...'
779
790
  : isOpen && !isReadOnly
780
791
  ? searchText
@@ -814,9 +825,8 @@ function MultiSelect(props) {
814
825
  ? 'pi pi-spinner pi-spin'
815
826
  : isOpen
816
827
  ? 'pi pi-angle-up'
817
- : 'pi pi-angle-down', 'text-gray px-2 flex items-center cursor-pointer', isInputDisabled && 'text-disabled', error && 'text-redError'), onClick: toggleDropdown })] })] }), isOpen && !isLoading && (jsx("div", { className: clsx('absolute w-full bg-background border shadow-md z-40 rounded-md -bottom-1 translate-y-full', error ? 'border-redError' : 'border-gray'), children: props.onInputChange && searchText.length === 0 ? (jsx("div", { className: "p-4 text-center text-gray", children: "Digite para pesquisar" })) : (jsx("ul", { className: "max-h-60 overflow-y-auto", children: filteredOptions.length > 0 ? (filteredOptions.map((option, index) => (jsxs("li", { onClick: () => handleSelect(option), className: clsx('p-2 flex justify-between items-center cursor-pointer', 'hover:bg-stoneBackground hover:font-bold', index === highlightedIndex &&
818
- 'bg-stoneBackground 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) &&
819
- 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-background ring-gray checked:bg-primary cursor-pointer rounded-md') })] }, option.value)))) : (jsx("div", { className: "p-4 text-center text-gray", children: "Nenhum resultado encontrado" })) })) })), hasError && jsx("span", { className: "text-redError text-xs px-2", children: error })] }));
828
+ : 'pi pi-angle-down', 'text-gray px-2 flex items-center cursor-pointer', isInputDisabled && 'text-disabled', error && 'text-redError'), onClick: toggleDropdown })] })] }), isOpen && (jsx("div", { className: clsx('absolute w-full bg-background border shadow-md z-40 rounded-md -bottom-1 translate-y-full', error ? 'border-redError' : 'border-gray'), children: isLoadingOptions ? (jsxs("div", { className: "p-4 text-center text-gray flex items-center justify-center gap-2", children: ["Carregando", jsx("i", { className: "pi pi-spinner pi-spin" })] })) : props.onInputChange && searchText.length === 0 ? (jsx("div", { className: "p-4 text-center text-gray", children: "Digite para pesquisar" })) : 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-stoneBackground hover:font-bold', index === highlightedIndex && 'bg-stoneBackground 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) &&
829
+ 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-background ring-gray checked:bg-primary cursor-pointer rounded-md') })] }, option.value))) })) : (jsx("div", { className: "p-4 text-center text-gray", children: "Nenhum resultado encontrado" })) })), hasError && jsx("span", { className: "text-redError text-xs px-2", children: error })] }));
820
830
  }
821
831
 
822
832
  function FilterIcon({ color }) {
@@ -4144,11 +4154,12 @@ function RadioButton({ label, value, checked, onChange, disabled = false, error
4144
4154
  }
4145
4155
 
4146
4156
  function Select(props) {
4147
- const { options, placeholder = 'Selecione uma opção', label = 'Opção', disabled = false, error, isLoading = false, isReadOnly = true, ariaLabel = 'Selecione uma opção', } = props;
4157
+ 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;
4148
4158
  const [isOpen, setIsOpen] = useState(false);
4149
4159
  const [searchText, setSearchText] = useState('');
4150
4160
  const [highlightedIndex, setHighlightedIndex] = useState(-1);
4151
4161
  const containerRef = useRef(null);
4162
+ const inputRef = useRef(null);
4152
4163
  const normalize = (str) => str
4153
4164
  .normalize('NFD')
4154
4165
  .replace(/[\u0300-\u036f]/g, '')
@@ -4160,6 +4171,11 @@ function Select(props) {
4160
4171
  setIsOpen(newState);
4161
4172
  setSearchText('');
4162
4173
  setHighlightedIndex(-1);
4174
+ if (newState) {
4175
+ setTimeout(() => {
4176
+ inputRef.current?.focus();
4177
+ }, 0);
4178
+ }
4163
4179
  }
4164
4180
  };
4165
4181
  const handleSelect = (option) => {
@@ -4175,6 +4191,11 @@ function Select(props) {
4175
4191
  };
4176
4192
  const hasError = !!error && !disabled;
4177
4193
  const isInputDisabled = disabled || isLoading;
4194
+ useEffect(() => {
4195
+ if (isOpen) {
4196
+ inputRef.current?.focus();
4197
+ }
4198
+ }, [options, isOpen]);
4178
4199
  useEffect(() => {
4179
4200
  const handleClickOutside = (event) => {
4180
4201
  if (containerRef.current &&
@@ -4189,7 +4210,7 @@ function Select(props) {
4189
4210
  document.removeEventListener('mousedown', handleClickOutside);
4190
4211
  };
4191
4212
  }, []);
4192
- 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, { placeholder: placeholder, type: "text", value: isLoading
4213
+ 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
4193
4214
  ? 'Carregando...'
4194
4215
  : isOpen
4195
4216
  ? searchText
@@ -4229,8 +4250,7 @@ function Select(props) {
4229
4250
  ? 'pi pi-spinner pi-spin'
4230
4251
  : isOpen
4231
4252
  ? 'pi pi-angle-up'
4232
- : 'pi pi-angle-down', 'text-gray px-2 flex items-center cursor-pointer', isInputDisabled && 'text-disabled', error && 'text-redError'), onClick: toggleDropdown })] })] }), isOpen && !isLoading && (jsx("div", { className: clsx('absolute w-full bg-background border shadow-md z-40 rounded-md p-2 -bottom-1 translate-y-full', error ? 'border-redError' : 'border-gray'), children: props.onInputChange && searchText.length === 0 ? (jsx("div", { className: "p-4 text-center text-gray", children: "Digite para pesquisar" })) : (jsx("ul", { className: "max-h-60 overflow-y-auto", children: filteredOptions.length > 0 ? (filteredOptions.map((option, index) => (jsxs("li", { onClick: () => handleSelect(option), className: clsx('p-2 flex justify-between items-center cursor-pointer', 'hover:bg-stoneBackground hover:font-bold', index === highlightedIndex &&
4233
- 'bg-stoneBackground 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-background ring-gray checked:bg-primary cursor-pointer') })] }, option.value)))) : (jsx("div", { className: "p-4 text-center text-gray", children: "Nenhum resultado encontrado" })) })) })), hasError && jsx("span", { className: "text-redError text-xs px-2", children: error })] }));
4253
+ : 'pi pi-angle-down', 'text-gray px-2 flex items-center cursor-pointer', isInputDisabled && 'text-disabled', error && 'text-redError'), onClick: toggleDropdown })] })] }), isOpen && (jsx("div", { className: clsx('absolute w-full bg-background border shadow-md z-40 rounded-md p-2 -bottom-1 translate-y-full', error ? 'border-redError' : 'border-gray'), children: isLoadingOptions ? (jsxs("div", { className: "p-4 text-center text-gray flex items-center justify-center gap-2", children: ["Carregando", jsx("i", { className: "pi pi-spinner pi-spin" })] })) : props.onInputChange && searchText.length === 0 ? (jsx("div", { className: "p-4 text-center text-gray", children: "Digite para pesquisar" })) : 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-stoneBackground hover:font-bold', index === highlightedIndex && 'bg-stoneBackground 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-background ring-gray checked:bg-primary cursor-pointer') })] }, option.value))) })) : (jsx("div", { className: "p-4 text-center text-gray", children: "Nenhum resultado encontrado" })) })), hasError && jsx("span", { className: "text-redError text-xs px-2", children: error })] }));
4234
4254
  }
4235
4255
 
4236
4256
  function Skeleton({ shape = 'rectangle', width = '100%', height = '1rem', borderRadius, animation = 'wave', size, className, }) {