@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.
@@ -11437,15 +11437,16 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
11437
11437
  const Checkbox = ({
11438
11438
  id,
11439
11439
  label,
11440
- variant,
11440
+ variant = "default",
11441
11441
  disabled,
11442
- orientation,
11443
- dir,
11442
+ orientation = "horizontal",
11443
+ dir = "end",
11444
+ checked,
11444
11445
  ...delegated
11445
11446
  }) => {
11446
11447
  const defaultId = React.useId();
11447
- return /* @__PURE__ */ jsxRuntime.jsxs(Wrapper$5, { $orientation: orientation ?? "horizontal", $dir: dir ?? "end", children: [
11448
- /* @__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" }) }) }),
11448
+ return /* @__PURE__ */ jsxRuntime.jsxs(Wrapper$5, { $orientation: orientation, $dir: dir, children: [
11449
+ /* @__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" }) }) }),
11449
11450
  label && /* @__PURE__ */ jsxRuntime.jsx(GenericLabel, { htmlFor: id ?? defaultId, disabled, children: label })
11450
11451
  ] });
11451
11452
  };
@@ -11453,7 +11454,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
11453
11454
  componentId: "sc-1sck1ja-1"
11454
11455
  })(["display:flex;align-items:center;justify-content:center;flex-shrink:0;", ";"], ({
11455
11456
  theme: theme2,
11456
- variant = "default"
11457
+ variant
11457
11458
  }) => `
11458
11459
  border-radius: ${theme2.click.checkbox.radii.all};
11459
11460
  width: ${theme2.click.checkbox.size.all};
@@ -11465,7 +11466,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
11465
11466
  &:hover {
11466
11467
  background: ${theme2.click.checkbox.color.variations[variant].background.hover};
11467
11468
  }
11468
- &[data-state="checked"] {
11469
+ &[data-state="checked"],
11470
+ &[data-state="indeterminate"] {
11469
11471
  border-color: ${theme2.click.checkbox.color.variations[variant].stroke.active};
11470
11472
  background: ${theme2.click.checkbox.color.variations[variant].background.active};
11471
11473
  }
@@ -11473,7 +11475,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
11473
11475
  background: ${theme2.click.checkbox.color.background.disabled};
11474
11476
  border-color: ${theme2.click.checkbox.color.stroke.disabled};
11475
11477
  cursor: not-allowed;
11476
- &[data-state="checked"] {
11478
+ &[data-state="checked"],
11479
+ &[data-state="indeterminate"] {
11477
11480
  background: ${theme2.click.checkbox.color.background.disabled};
11478
11481
  border-color: ${theme2.click.checkbox.color.stroke.disabled};
11479
11482
  }
@@ -40802,8 +40805,9 @@ Defaulting to \`${$89eedd556c436f6a$var$DEFAULT_ORIENTATION}\`.`;
40802
40805
  onSelectAll,
40803
40806
  actionsList,
40804
40807
  onSort: onSortProp,
40805
- hasRows,
40806
- size: size2
40808
+ size: size2,
40809
+ rows,
40810
+ selectedIds
40807
40811
  }) => {
40808
40812
  const onSort = (header, headerIndex) => () => {
40809
40813
  if (typeof onSortProp === "function" && header.isSortable) {
@@ -40817,7 +40821,7 @@ Defaulting to \`${$89eedd556c436f6a$var$DEFAULT_ORIENTATION}\`.`;
40817
40821
  actionsList.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("col", { width: (actionsList.length + 1) * 32 + 10 })
40818
40822
  ] }),
40819
40823
  /* @__PURE__ */ jsxRuntime.jsx(StyledThead, { children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
40820
- isSelectable && /* @__PURE__ */ jsxRuntime.jsx(StyledHeader, { $size: size2, "aria-label": "Select column", children: /* @__PURE__ */ jsxRuntime.jsx(Checkbox, { onCheckedChange: onSelectAll, disabled: !hasRows }) }),
40824
+ isSelectable && /* @__PURE__ */ jsxRuntime.jsx(StyledHeader, { $size: size2, "aria-label": "Select column", children: /* @__PURE__ */ jsxRuntime.jsx(SelectAllCheckbox, { onCheckedChange: onSelectAll, rows, selectedIds }) }),
40821
40825
  headers.map(({
40822
40826
  width,
40823
40827
  ...headerProps
@@ -40973,7 +40977,7 @@ Defaulting to \`${$89eedd556c436f6a$var$DEFAULT_ORIENTATION}\`.`;
40973
40977
  const isDeletable = typeof onDelete === "function";
40974
40978
  const isEditable = typeof onEdit === "function";
40975
40979
  return /* @__PURE__ */ jsxRuntime.jsxs(TableRow, { $isSelectable: isSelectable, $isDeleted: isDeleted, $isDisabled: isDisabled, $isActive: isActive, $showActions: isDeletable || isEditable, $rowHeight: rowHeight, ...rowProps, children: [
40976
- isSelectable && /* @__PURE__ */ jsxRuntime.jsx(SelectData, { $size: size2, children: /* @__PURE__ */ jsxRuntime.jsx(Checkbox, { checked: isSelected, onCheckedChange: onSelect }) }),
40980
+ isSelectable && /* @__PURE__ */ jsxRuntime.jsx(SelectData, { $size: size2, children: /* @__PURE__ */ jsxRuntime.jsx(Checkbox, { checked: isSelected, onCheckedChange: onSelect, disabled: isDisabled || isDeleted }) }),
40977
40981
  items.map(({
40978
40982
  label,
40979
40983
  ...cellProps
@@ -41025,19 +41029,10 @@ Defaulting to \`${$89eedd556c436f6a$var$DEFAULT_ORIENTATION}\`.`;
41025
41029
  }, ref) => {
41026
41030
  const isDeletable = typeof onDelete === "function";
41027
41031
  const isEditable = typeof onEdit === "function";
41028
- const onSelectAll = (checked) => {
41029
- if (typeof onSelect === "function") {
41030
- const ids = checked ? rows.map((row, index2) => ({
41031
- item: row,
41032
- index: index2
41033
- })) : [];
41034
- onSelect(ids);
41035
- }
41036
- };
41037
41032
  const onRowSelect = (id) => (checked) => {
41038
41033
  if (typeof onSelect == "function") {
41039
41034
  const selectedItems = rows.flatMap((row, index2) => {
41040
- if (id === row.id && checked || selectedIds.includes(id) && id !== row.id) {
41035
+ if (id === row.id && checked || selectedIds.includes(row.id) && id !== row.id) {
41041
41036
  return {
41042
41037
  item: row,
41043
41038
  index: index2
@@ -41057,9 +41052,9 @@ Defaulting to \`${$89eedd556c436f6a$var$DEFAULT_ORIENTATION}\`.`;
41057
41052
  actionsList.push("editAction");
41058
41053
  }
41059
41054
  return /* @__PURE__ */ jsxRuntime.jsxs(TableOuterContainer, { children: [
41060
- hasRows && showHeader && /* @__PURE__ */ jsxRuntime.jsx(MobileActions, { children: isSelectable && /* @__PURE__ */ jsxRuntime.jsx(Checkbox, { label: "Select All", checked: selectedIds.length === rows.length, onCheckedChange: onSelectAll }) }),
41055
+ hasRows && showHeader && /* @__PURE__ */ jsxRuntime.jsx(MobileActions, { children: isSelectable && /* @__PURE__ */ jsxRuntime.jsx(SelectAllCheckbox, { label: "Select All", onCheckedChange: onSelect, rows, selectedIds }) }),
41061
41056
  /* @__PURE__ */ jsxRuntime.jsx(TableWrapper, { children: /* @__PURE__ */ jsxRuntime.jsxs(StyledTable, { ref, ...props, children: [
41062
- showHeader && /* @__PURE__ */ jsxRuntime.jsx(Thead, { headers, isSelectable, onSelectAll, actionsList, onSort, hasRows, size: size2 }),
41057
+ showHeader && /* @__PURE__ */ jsxRuntime.jsx(Thead, { headers, isSelectable, onSelectAll: onSelect, actionsList, onSort, size: size2, rows, selectedIds }),
41063
41058
  /* @__PURE__ */ jsxRuntime.jsxs(Tbody, { children: [
41064
41059
  (loading || !hasRows) && /* @__PURE__ */ jsxRuntime.jsx(CustomTableRow, { colSpan: headers.length + (isEditable || isDeletable ? 1 : 0) + (isSelectable ? 1 : 0), loading, noDataMessage, size: size2 }),
41065
41060
  rows.map(({
@@ -41077,6 +41072,56 @@ Defaulting to \`${$89eedd556c436f6a$var$DEFAULT_ORIENTATION}\`.`;
41077
41072
  ] }) })
41078
41073
  ] });
41079
41074
  });
41075
+ const SelectAllCheckbox = ({
41076
+ rows,
41077
+ selectedIds,
41078
+ onCheckedChange,
41079
+ ...checkboxProps
41080
+ }) => {
41081
+ const selectedIdSet = React.useMemo(() => new Set(selectedIds), [selectedIds]);
41082
+ const {
41083
+ checked,
41084
+ disabled
41085
+ } = React.useMemo(() => {
41086
+ let areAllChecked = true;
41087
+ let maybeIndeterminate = false;
41088
+ let disabled2 = true;
41089
+ for (const row of rows) {
41090
+ if (row.isDisabled || row.isDeleted) {
41091
+ continue;
41092
+ } else {
41093
+ disabled2 = false;
41094
+ }
41095
+ if (selectedIdSet.has(row.id)) {
41096
+ maybeIndeterminate = "indeterminate";
41097
+ } else {
41098
+ areAllChecked = false;
41099
+ }
41100
+ }
41101
+ return {
41102
+ checked: disabled2 ? false : areAllChecked || maybeIndeterminate,
41103
+ disabled: disabled2
41104
+ };
41105
+ }, [rows, selectedIdSet]);
41106
+ const handleCheckedChange = (checked2) => {
41107
+ if (typeof onCheckedChange !== "function") {
41108
+ return;
41109
+ }
41110
+ const newSelectedRows = rows.reduce((acc, row, index2) => {
41111
+ const isDisabled = row.isDisabled || row.isDeleted;
41112
+ const shouldBeSelected = checked2 ? !isDisabled || selectedIdSet.has(row.id) : isDisabled && selectedIdSet.has(row.id);
41113
+ if (shouldBeSelected) {
41114
+ acc.push({
41115
+ item: row,
41116
+ index: index2
41117
+ });
41118
+ }
41119
+ return acc;
41120
+ }, []);
41121
+ onCheckedChange(newSelectedRows);
41122
+ };
41123
+ return /* @__PURE__ */ jsxRuntime.jsx(Checkbox, { checked, disabled, onCheckedChange: handleCheckedChange, ...checkboxProps });
41124
+ };
41080
41125
  const StyledTable = pt.table.withConfig({
41081
41126
  componentId: "sc-1q458rb-19"
41082
41127
  })(["width:100%;border-collapse:collapse;overflow:hidden;table-layout:fixed;@media (max-width:768px){border:none;table-layout:auto;}"]);
@@ -52139,3 +52184,4 @@ Defaulting to \`${$89eedd556c436f6a$var$DEFAULT_ORIENTATION}\`.`;
52139
52184
  exports2.useToast = useToast;
52140
52185
  Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
52141
52186
  });
52187
+ //# sourceMappingURL=click-ui.bundled.umd.js.map