@clickhouse/click-ui 0.0.220 → 0.0.222

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.
@@ -10240,15 +10240,16 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
10240
10240
  const Checkbox = ({
10241
10241
  id,
10242
10242
  label,
10243
- variant,
10243
+ variant = "default",
10244
10244
  disabled,
10245
- orientation,
10246
- dir,
10245
+ orientation = "horizontal",
10246
+ dir = "end",
10247
+ checked,
10247
10248
  ...delegated
10248
10249
  }) => {
10249
10250
  const defaultId = React.useId();
10250
- return /* @__PURE__ */ jsxRuntime.jsxs(Wrapper$5, { $orientation: orientation ?? "horizontal", $dir: dir ?? "end", children: [
10251
- /* @__PURE__ */ jsxRuntime.jsx(CheckInput, { id: id ?? defaultId, "data-testid": "checkbox", variant: variant ?? "default", disabled, "aria-label": `${label}`, ...delegated, children: /* @__PURE__ */ jsxRuntime.jsx(CheckIconWrapper, { children: /* @__PURE__ */ jsxRuntime.jsx(SvgImage, { name: "check", size: "sm" }) }) }),
10251
+ return /* @__PURE__ */ jsxRuntime.jsxs(Wrapper$5, { $orientation: orientation, $dir: dir, children: [
10252
+ /* @__PURE__ */ jsxRuntime.jsx(CheckInput, { id: id ?? defaultId, "data-testid": "checkbox", variant, disabled, "aria-label": `${label}`, checked, ...delegated, children: /* @__PURE__ */ jsxRuntime.jsx(CheckIconWrapper, { children: /* @__PURE__ */ jsxRuntime.jsx(SvgImage, { name: checked === "indeterminate" ? "minus" : "check", size: "sm" }) }) }),
10252
10253
  label && /* @__PURE__ */ jsxRuntime.jsx(GenericLabel, { htmlFor: id ?? defaultId, disabled, children: label })
10253
10254
  ] });
10254
10255
  };
@@ -10256,7 +10257,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
10256
10257
  componentId: "sc-1sck1ja-1"
10257
10258
  })(["display:flex;align-items:center;justify-content:center;flex-shrink:0;", ";"], ({
10258
10259
  theme: theme2,
10259
- variant = "default"
10260
+ variant
10260
10261
  }) => `
10261
10262
  border-radius: ${theme2.click.checkbox.radii.all};
10262
10263
  width: ${theme2.click.checkbox.size.all};
@@ -10268,7 +10269,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
10268
10269
  &:hover {
10269
10270
  background: ${theme2.click.checkbox.color.variations[variant].background.hover};
10270
10271
  }
10271
- &[data-state="checked"] {
10272
+ &[data-state="checked"],
10273
+ &[data-state="indeterminate"] {
10272
10274
  border-color: ${theme2.click.checkbox.color.variations[variant].stroke.active};
10273
10275
  background: ${theme2.click.checkbox.color.variations[variant].background.active};
10274
10276
  }
@@ -10276,7 +10278,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
10276
10278
  background: ${theme2.click.checkbox.color.background.disabled};
10277
10279
  border-color: ${theme2.click.checkbox.color.stroke.disabled};
10278
10280
  cursor: not-allowed;
10279
- &[data-state="checked"] {
10281
+ &[data-state="checked"],
10282
+ &[data-state="indeterminate"] {
10280
10283
  background: ${theme2.click.checkbox.color.background.disabled};
10281
10284
  border-color: ${theme2.click.checkbox.color.stroke.disabled};
10282
10285
  }
@@ -39633,8 +39636,9 @@ Defaulting to \`${$89eedd556c436f6a$var$DEFAULT_ORIENTATION}\`.`;
39633
39636
  onSelectAll,
39634
39637
  actionsList,
39635
39638
  onSort: onSortProp,
39636
- hasRows,
39637
- size: size2
39639
+ size: size2,
39640
+ rows,
39641
+ selectedIds
39638
39642
  }) => {
39639
39643
  const onSort = (header, headerIndex) => () => {
39640
39644
  if (typeof onSortProp === "function" && header.isSortable) {
@@ -39648,7 +39652,7 @@ Defaulting to \`${$89eedd556c436f6a$var$DEFAULT_ORIENTATION}\`.`;
39648
39652
  actionsList.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("col", { width: (actionsList.length + 1) * 32 + 10 })
39649
39653
  ] }),
39650
39654
  /* @__PURE__ */ jsxRuntime.jsx(StyledThead, { children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
39651
- isSelectable && /* @__PURE__ */ jsxRuntime.jsx(StyledHeader, { $size: size2, "aria-label": "Select column", children: /* @__PURE__ */ jsxRuntime.jsx(Checkbox, { onCheckedChange: onSelectAll, disabled: !hasRows }) }),
39655
+ isSelectable && /* @__PURE__ */ jsxRuntime.jsx(StyledHeader, { $size: size2, "aria-label": "Select column", children: /* @__PURE__ */ jsxRuntime.jsx(SelectAllCheckbox, { onCheckedChange: onSelectAll, rows, selectedIds }) }),
39652
39656
  headers.map(({
39653
39657
  width,
39654
39658
  ...headerProps
@@ -39804,7 +39808,7 @@ Defaulting to \`${$89eedd556c436f6a$var$DEFAULT_ORIENTATION}\`.`;
39804
39808
  const isDeletable = typeof onDelete === "function";
39805
39809
  const isEditable = typeof onEdit === "function";
39806
39810
  return /* @__PURE__ */ jsxRuntime.jsxs(TableRow, { $isSelectable: isSelectable, $isDeleted: isDeleted, $isDisabled: isDisabled, $isActive: isActive, $showActions: isDeletable || isEditable, $rowHeight: rowHeight, ...rowProps, children: [
39807
- isSelectable && /* @__PURE__ */ jsxRuntime.jsx(SelectData, { $size: size2, children: /* @__PURE__ */ jsxRuntime.jsx(Checkbox, { checked: isSelected, onCheckedChange: onSelect }) }),
39811
+ isSelectable && /* @__PURE__ */ jsxRuntime.jsx(SelectData, { $size: size2, children: /* @__PURE__ */ jsxRuntime.jsx(Checkbox, { checked: isSelected, onCheckedChange: onSelect, disabled: isDisabled || isDeleted }) }),
39808
39812
  items.map(({
39809
39813
  label,
39810
39814
  ...cellProps
@@ -39856,19 +39860,10 @@ Defaulting to \`${$89eedd556c436f6a$var$DEFAULT_ORIENTATION}\`.`;
39856
39860
  }, ref) => {
39857
39861
  const isDeletable = typeof onDelete === "function";
39858
39862
  const isEditable = typeof onEdit === "function";
39859
- const onSelectAll = (checked) => {
39860
- if (typeof onSelect === "function") {
39861
- const ids = checked ? rows.map((row, index2) => ({
39862
- item: row,
39863
- index: index2
39864
- })) : [];
39865
- onSelect(ids);
39866
- }
39867
- };
39868
39863
  const onRowSelect = (id) => (checked) => {
39869
39864
  if (typeof onSelect == "function") {
39870
39865
  const selectedItems = rows.flatMap((row, index2) => {
39871
- if (id === row.id && checked || selectedIds.includes(id) && id !== row.id) {
39866
+ if (id === row.id && checked || selectedIds.includes(row.id) && id !== row.id) {
39872
39867
  return {
39873
39868
  item: row,
39874
39869
  index: index2
@@ -39888,9 +39883,9 @@ Defaulting to \`${$89eedd556c436f6a$var$DEFAULT_ORIENTATION}\`.`;
39888
39883
  actionsList.push("editAction");
39889
39884
  }
39890
39885
  return /* @__PURE__ */ jsxRuntime.jsxs(TableOuterContainer, { children: [
39891
- hasRows && showHeader && /* @__PURE__ */ jsxRuntime.jsx(MobileActions, { children: isSelectable && /* @__PURE__ */ jsxRuntime.jsx(Checkbox, { label: "Select All", checked: selectedIds.length === rows.length, onCheckedChange: onSelectAll }) }),
39886
+ hasRows && showHeader && /* @__PURE__ */ jsxRuntime.jsx(MobileActions, { children: isSelectable && /* @__PURE__ */ jsxRuntime.jsx(SelectAllCheckbox, { label: "Select All", onCheckedChange: onSelect, rows, selectedIds }) }),
39892
39887
  /* @__PURE__ */ jsxRuntime.jsx(TableWrapper, { children: /* @__PURE__ */ jsxRuntime.jsxs(StyledTable, { ref, ...props, children: [
39893
- showHeader && /* @__PURE__ */ jsxRuntime.jsx(Thead, { headers, isSelectable, onSelectAll, actionsList, onSort, hasRows, size: size2 }),
39888
+ showHeader && /* @__PURE__ */ jsxRuntime.jsx(Thead, { headers, isSelectable, onSelectAll: onSelect, actionsList, onSort, size: size2, rows, selectedIds }),
39894
39889
  /* @__PURE__ */ jsxRuntime.jsxs(Tbody, { children: [
39895
39890
  (loading || !hasRows) && /* @__PURE__ */ jsxRuntime.jsx(CustomTableRow, { colSpan: headers.length + (isEditable || isDeletable ? 1 : 0) + (isSelectable ? 1 : 0), loading, noDataMessage, size: size2 }),
39896
39891
  rows.map(({
@@ -39908,6 +39903,56 @@ Defaulting to \`${$89eedd556c436f6a$var$DEFAULT_ORIENTATION}\`.`;
39908
39903
  ] }) })
39909
39904
  ] });
39910
39905
  });
39906
+ const SelectAllCheckbox = ({
39907
+ rows,
39908
+ selectedIds,
39909
+ onCheckedChange,
39910
+ ...checkboxProps
39911
+ }) => {
39912
+ const selectedIdSet = React.useMemo(() => new Set(selectedIds), [selectedIds]);
39913
+ const {
39914
+ checked,
39915
+ disabled
39916
+ } = React.useMemo(() => {
39917
+ let areAllChecked = true;
39918
+ let maybeIndeterminate = false;
39919
+ let disabled2 = true;
39920
+ for (const row of rows) {
39921
+ if (row.isDisabled || row.isDeleted) {
39922
+ continue;
39923
+ } else {
39924
+ disabled2 = false;
39925
+ }
39926
+ if (selectedIdSet.has(row.id)) {
39927
+ maybeIndeterminate = "indeterminate";
39928
+ } else {
39929
+ areAllChecked = false;
39930
+ }
39931
+ }
39932
+ return {
39933
+ checked: disabled2 ? false : areAllChecked || maybeIndeterminate,
39934
+ disabled: disabled2
39935
+ };
39936
+ }, [rows, selectedIdSet]);
39937
+ const handleCheckedChange = (checked2) => {
39938
+ if (typeof onCheckedChange !== "function") {
39939
+ return;
39940
+ }
39941
+ const newSelectedRows = rows.reduce((acc, row, index2) => {
39942
+ const isDisabled = row.isDisabled || row.isDeleted;
39943
+ const shouldBeSelected = checked2 ? !isDisabled || selectedIdSet.has(row.id) : isDisabled && selectedIdSet.has(row.id);
39944
+ if (shouldBeSelected) {
39945
+ acc.push({
39946
+ item: row,
39947
+ index: index2
39948
+ });
39949
+ }
39950
+ return acc;
39951
+ }, []);
39952
+ onCheckedChange(newSelectedRows);
39953
+ };
39954
+ return /* @__PURE__ */ jsxRuntime.jsx(Checkbox, { checked, disabled, onCheckedChange: handleCheckedChange, ...checkboxProps });
39955
+ };
39911
39956
  const StyledTable = styled.styled.table.withConfig({
39912
39957
  componentId: "sc-1q458rb-19"
39913
39958
  })(["width:100%;border-collapse:collapse;overflow:hidden;table-layout:fixed;@media (max-width:768px){border:none;table-layout:auto;}"]);
@@ -50970,3 +51015,4 @@ Defaulting to \`${$89eedd556c436f6a$var$DEFAULT_ORIENTATION}\`.`;
50970
51015
  exports2.useToast = useToast;
50971
51016
  Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
50972
51017
  });
51018
+ //# sourceMappingURL=click-ui.umd.js.map