klun-ui 0.2.2 → 0.3.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.
@@ -6541,25 +6541,30 @@ var AutoComplete = react.forwardRef(
6541
6541
  AutoComplete.displayName = "AutoComplete";
6542
6542
  var Cascader = react.forwardRef(function Cascader2({
6543
6543
  options = [],
6544
- value = [],
6544
+ value,
6545
+ defaultValue,
6545
6546
  onChange,
6546
6547
  placeholder: placeholderProp,
6547
6548
  size: sizeProp,
6548
6549
  disabled = false,
6549
6550
  separator = " / ",
6550
6551
  changeOnSelect = false,
6552
+ clearable = false,
6553
+ renderOption,
6551
6554
  error = false,
6552
6555
  className,
6553
6556
  ...props
6554
6557
  }, ref) {
6555
6558
  const size = useSize(sizeProp);
6556
- const { cascader } = useLocale();
6559
+ const { cascader, input: inputText } = useLocale();
6557
6560
  const placeholder = placeholderProp ?? cascader.placeholder;
6561
+ const [inner, setInner] = react.useState(defaultValue ?? []);
6562
+ const current = value ?? inner;
6558
6563
  const [open, setOpen] = react.useState(false);
6559
- const [active, setActive] = react.useState(value);
6564
+ const [active, setActive] = react.useState(current);
6560
6565
  const rootRef = react.useRef(null);
6561
6566
  react.useEffect(() => {
6562
- setActive(value);
6567
+ setActive(current);
6563
6568
  }, [open]);
6564
6569
  react.useEffect(() => {
6565
6570
  if (!open) return;
@@ -6588,7 +6593,7 @@ var Cascader = react.forwardRef(function Cascader2({
6588
6593
  }
6589
6594
  const labelPath = [];
6590
6595
  let lvl = options;
6591
- for (const key of value) {
6596
+ for (const key of current) {
6592
6597
  const found = (lvl || []).find((o) => o.value === key);
6593
6598
  if (!found) break;
6594
6599
  labelPath.push(found.label);
@@ -6600,10 +6605,16 @@ var Cascader = react.forwardRef(function Cascader2({
6600
6605
  setActive(nextPath);
6601
6606
  const leaf = !opt.children || !opt.children.length;
6602
6607
  if (leaf || changeOnSelect) {
6608
+ if (value === void 0) setInner(nextPath);
6603
6609
  onChange && onChange(nextPath);
6604
6610
  if (leaf) setOpen(false);
6605
6611
  }
6606
6612
  };
6613
+ const clear = () => {
6614
+ if (value === void 0) setInner([]);
6615
+ setActive([]);
6616
+ onChange && onChange([]);
6617
+ };
6607
6618
  const setRefs = (node) => {
6608
6619
  rootRef.current = node;
6609
6620
  if (typeof ref === "function") ref(node);
@@ -6633,6 +6644,20 @@ var Cascader = react.forwardRef(function Cascader2({
6633
6644
  i > 0 ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "klun-cascader__separator", children: separator }) : null,
6634
6645
  lbl
6635
6646
  ] }, i)) : placeholder }),
6647
+ clearable && labelPath.length && !disabled ? /* @__PURE__ */ jsxRuntime.jsx(
6648
+ "span",
6649
+ {
6650
+ role: "button",
6651
+ tabIndex: -1,
6652
+ "aria-label": inputText.clear,
6653
+ className: "klun-cascader__clear",
6654
+ onClick: (e) => {
6655
+ e.stopPropagation();
6656
+ clear();
6657
+ },
6658
+ children: /* @__PURE__ */ jsxRuntime.jsx("i", { className: "ri-close-circle-fill" })
6659
+ }
6660
+ ) : null,
6636
6661
  /* @__PURE__ */ jsxRuntime.jsx(
6637
6662
  "svg",
6638
6663
  {
@@ -6657,7 +6682,7 @@ var Cascader = react.forwardRef(function Cascader2({
6657
6682
  ]
6658
6683
  }
6659
6684
  ),
6660
- open ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "klun-cascader__panel", children: columns.map((col, ci) => /* @__PURE__ */ jsxRuntime.jsx(
6685
+ open ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "klun-cascader__panel", role: "menu", children: columns.map((col, ci) => /* @__PURE__ */ jsxRuntime.jsx(
6661
6686
  "div",
6662
6687
  {
6663
6688
  className: chunkTPGAXYFU_cjs.cx(
@@ -6671,12 +6696,14 @@ var Cascader = react.forwardRef(function Cascader2({
6671
6696
  "button",
6672
6697
  {
6673
6698
  type: "button",
6699
+ role: "menuitem",
6674
6700
  className: "klun-cascader__option",
6675
6701
  disabled: opt.disabled,
6676
6702
  onClick: () => pick(ci, opt),
6703
+ "aria-selected": selected,
6677
6704
  "data-selected": selected || void 0,
6678
6705
  children: [
6679
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "klun-cascader__option-label", children: opt.label }),
6706
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "klun-cascader__option-label", children: renderOption ? renderOption(opt, ci) : opt.label }),
6680
6707
  hasChildren2 ? /* @__PURE__ */ jsxRuntime.jsx("i", { className: "ri-arrow-right-s-line klun-cascader__option-arrow" }) : selected ? /* @__PURE__ */ jsxRuntime.jsx("i", { className: "ri-check-line klun-cascader__option-check" }) : null
6681
6708
  ]
6682
6709
  },
@@ -11759,5 +11786,5 @@ exports.useSize = useSize;
11759
11786
  exports.viVN = viVN;
11760
11787
  exports.zhCN = zhCN;
11761
11788
  exports.zhTW = zhTW;
11762
- //# sourceMappingURL=chunk-T7O3RMWL.cjs.map
11763
- //# sourceMappingURL=chunk-T7O3RMWL.cjs.map
11789
+ //# sourceMappingURL=chunk-YSCRS555.cjs.map
11790
+ //# sourceMappingURL=chunk-YSCRS555.cjs.map