kiban-design-system 1.0.275-alpha.0 → 1.0.277-alpha.0

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
@@ -30662,18 +30662,17 @@ const AlphaGraphicCard = ({ data }) => {
30662
30662
  };
30663
30663
 
30664
30664
  const COMPONENT_NAME = 'AlphaZipCodeInput';
30665
- const AlphaZipCodeInput = ({ label, isRequired, items, onBlur, onFocus, onChange, value, labelEmpty, }) => {
30665
+ const AlphaZipCodeInput = ({ label, isRequired, items, onBlur, onFocus, onChange, value, labelEmpty, loading, placeholder, }) => {
30666
30666
  const [isFocusActive, setIsFocusActive] = useState(false);
30667
30667
  const [showPopover, setShowPopover] = useState(false);
30668
30668
  const handleOnBlur = () => {
30669
- setShowPopover(false);
30670
30669
  setIsFocusActive(false);
30671
30670
  if (onBlur)
30672
30671
  onBlur();
30673
30672
  };
30674
30673
  const handleOnFocus = () => {
30675
30674
  setIsFocusActive(true);
30676
- setShowPopover(Boolean(value && (value === null || value === void 0 ? void 0 : value.length) > 2));
30675
+ setShowPopover(Boolean(value && (value === null || value === void 0 ? void 0 : value.length) === 5 && items));
30677
30676
  if (onFocus)
30678
30677
  onFocus();
30679
30678
  };
@@ -30681,26 +30680,25 @@ const AlphaZipCodeInput = ({ label, isRequired, items, onBlur, onFocus, onChange
30681
30680
  const handleOnChange = (event) => {
30682
30681
  const isValid = /^[0-9]+$/i.test(event.target.value) || event.target.value === '';
30683
30682
  if (isValid && onChange) {
30684
- setShowPopover(event.target.value.length > 2);
30685
30683
  onChange(event.target.value);
30686
30684
  }
30687
30685
  };
30688
30686
  const labelMarkup = label ? (jsx("div", Object.assign({ className: `${COMPONENT_NAME}__LabelWrapper` }, { children: jsxs("label", Object.assign({ className: `${COMPONENT_NAME}__Label` }, { children: [label, isRequired ? (jsx("span", Object.assign({ className: `${COMPONENT_NAME}__Label--isRequired` }, { children: "*" }), void 0)) : null] }), void 0) }), void 0)) : null;
30689
- const classesInput = cssClassName(`${COMPONENT_NAME}__InputWrapper`, isFocusActive && 'isFocus');
30690
- const inputMarkup = (jsx("div", Object.assign({ className: classesInput }, { children: jsx("input", { className: `${COMPONENT_NAME}__InputWrapper--input`, onBlur: handleOnBlur, onFocus: handleOnFocus, onChange: handleOnChange, maxLength: 5, value: value }, void 0) }), void 0));
30687
+ const classesInput = cssClassName(`${COMPONENT_NAME}__InputWrapper`, isFocusActive && 'isFocus', loading && 'loading');
30688
+ const inputMarkup = (jsx("div", Object.assign({ className: classesInput }, { children: jsx("input", { className: `${COMPONENT_NAME}__InputWrapper--input`, onBlur: handleOnBlur, onFocus: handleOnFocus, onChange: handleOnChange, maxLength: 5, value: value, placeholder: placeholder }, void 0) }), void 0));
30691
30689
  const handleOnSelectItem = (item) => {
30692
30690
  if (onChange)
30693
30691
  onChange(item[0]);
30694
30692
  setShowPopover(false);
30695
30693
  };
30696
30694
  const renderLabelItem = (item) => (jsxs("div", Object.assign({ className: `${COMPONENT_NAME}__ItemWrapper` }, { children: [jsx("div", Object.assign({ className: `${COMPONENT_NAME}__Item__Value` }, { children: item.cp }), void 0), jsxs("div", Object.assign({ className: `${COMPONENT_NAME}__Item__Description` }, { children: [item.municipality, ", ", item.city, ", ", item.state] }), void 0)] }), void 0));
30697
- const itemsOptions = items.map((item) => ({
30695
+ const itemsOptions = items === null || items === void 0 ? void 0 : items.map((item) => ({
30698
30696
  label: renderLabelItem(item),
30699
30697
  value: item.id,
30700
30698
  }));
30701
- const optionListMarkup = items.length > 0 ? (jsx(OptionList, { items: itemsOptions, selected: [''], onChange: handleOnSelectItem }, void 0)) : null;
30702
- const emptyItemsMarkup = items.length === 0 ? (jsx("div", Object.assign({ className: `${COMPONENT_NAME}__EmptyItems` }, { children: labelEmpty }), void 0)) : null;
30703
- const popoverMarkup = useMemo(() => (jsx(Popover$1, Object.assign({ activator: inputMarkup, isActive: showPopover, isFullWidth: true, onClose: () => setShowPopover(false), isFixed: true }, { children: jsxs(Popover$1.Pane, { children: [optionListMarkup, emptyItemsMarkup] }, void 0) }), items.length)), [
30699
+ const optionListMarkup = items && items.length > 0 ? (jsx(OptionList, { items: itemsOptions, selected: [''], onChange: handleOnSelectItem }, void 0)) : null;
30700
+ const emptyItemsMarkup = items && items.length === 0 ? (jsx("div", Object.assign({ className: `${COMPONENT_NAME}__EmptyItems` }, { children: labelEmpty }), void 0)) : null;
30701
+ const popoverMarkup = useMemo(() => (jsx(Popover$1, Object.assign({ activator: inputMarkup, isActive: showPopover, isFullWidth: true, onClose: () => setShowPopover(false), isFixed: true }, { children: jsxs(Popover$1.Pane, { children: [optionListMarkup, emptyItemsMarkup] }, void 0) }), void 0)), [
30704
30702
  items,
30705
30703
  value,
30706
30704
  showPopover,
@@ -30709,10 +30707,11 @@ const AlphaZipCodeInput = ({ label, isRequired, items, onBlur, onFocus, onChange
30709
30707
  isFocusActive,
30710
30708
  ]);
30711
30709
  useEffect(() => {
30712
- if (showPopover) {
30713
- setShowPopover(false);
30714
- requestAnimationFrame(() => setShowPopover(true));
30710
+ if (items) {
30711
+ setShowPopover(true);
30715
30712
  }
30713
+ else
30714
+ setShowPopover(false);
30716
30715
  }, [items]);
30717
30716
  return (jsxs("div", Object.assign({ className: `${COMPONENT_NAME}__Wrapper` }, { children: [labelMarkup, popoverMarkup] }), void 0));
30718
30717
  };