@clickhouse/click-ui 0.0.220 → 0.0.221

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.
@@ -11421,15 +11421,16 @@ const Wrapper$5 = pt(FormRoot).withConfig({
11421
11421
  const Checkbox = ({
11422
11422
  id,
11423
11423
  label,
11424
- variant,
11424
+ variant = "default",
11425
11425
  disabled,
11426
- orientation,
11427
- dir,
11426
+ orientation = "horizontal",
11427
+ dir = "end",
11428
+ checked,
11428
11429
  ...delegated
11429
11430
  }) => {
11430
11431
  const defaultId = useId();
11431
- return /* @__PURE__ */ jsxs(Wrapper$5, { $orientation: orientation ?? "horizontal", $dir: dir ?? "end", children: [
11432
- /* @__PURE__ */ jsx(CheckInput, { id: id ?? defaultId, "data-testid": "checkbox", variant: variant ?? "default", disabled, "aria-label": `${label}`, ...delegated, children: /* @__PURE__ */ jsx(CheckIconWrapper, { children: /* @__PURE__ */ jsx(SvgImage, { name: "check", size: "sm" }) }) }),
11432
+ return /* @__PURE__ */ jsxs(Wrapper$5, { $orientation: orientation, $dir: dir, children: [
11433
+ /* @__PURE__ */ jsx(CheckInput, { id: id ?? defaultId, "data-testid": "checkbox", variant, disabled, "aria-label": `${label}`, checked, ...delegated, children: /* @__PURE__ */ jsx(CheckIconWrapper, { children: /* @__PURE__ */ jsx(SvgImage, { name: checked === "indeterminate" ? "minus" : "check", size: "sm" }) }) }),
11433
11434
  label && /* @__PURE__ */ jsx(GenericLabel, { htmlFor: id ?? defaultId, disabled, children: label })
11434
11435
  ] });
11435
11436
  };
@@ -11437,7 +11438,7 @@ const CheckInput = pt($e698a72e93240346$export$be92b6f5f03c0fe9).withConfig({
11437
11438
  componentId: "sc-1sck1ja-1"
11438
11439
  })(["display:flex;align-items:center;justify-content:center;flex-shrink:0;", ";"], ({
11439
11440
  theme: theme2,
11440
- variant = "default"
11441
+ variant
11441
11442
  }) => `
11442
11443
  border-radius: ${theme2.click.checkbox.radii.all};
11443
11444
  width: ${theme2.click.checkbox.size.all};
@@ -11449,7 +11450,8 @@ const CheckInput = pt($e698a72e93240346$export$be92b6f5f03c0fe9).withConfig({
11449
11450
  &:hover {
11450
11451
  background: ${theme2.click.checkbox.color.variations[variant].background.hover};
11451
11452
  }
11452
- &[data-state="checked"] {
11453
+ &[data-state="checked"],
11454
+ &[data-state="indeterminate"] {
11453
11455
  border-color: ${theme2.click.checkbox.color.variations[variant].stroke.active};
11454
11456
  background: ${theme2.click.checkbox.color.variations[variant].background.active};
11455
11457
  }
@@ -11457,7 +11459,8 @@ const CheckInput = pt($e698a72e93240346$export$be92b6f5f03c0fe9).withConfig({
11457
11459
  background: ${theme2.click.checkbox.color.background.disabled};
11458
11460
  border-color: ${theme2.click.checkbox.color.stroke.disabled};
11459
11461
  cursor: not-allowed;
11460
- &[data-state="checked"] {
11462
+ &[data-state="checked"],
11463
+ &[data-state="indeterminate"] {
11461
11464
  background: ${theme2.click.checkbox.color.background.disabled};
11462
11465
  border-color: ${theme2.click.checkbox.color.stroke.disabled};
11463
11466
  }
@@ -40786,8 +40789,9 @@ const Thead = ({
40786
40789
  onSelectAll,
40787
40790
  actionsList,
40788
40791
  onSort: onSortProp,
40789
- hasRows,
40790
- size: size2
40792
+ size: size2,
40793
+ rows,
40794
+ selectedIds
40791
40795
  }) => {
40792
40796
  const onSort = (header, headerIndex) => () => {
40793
40797
  if (typeof onSortProp === "function" && header.isSortable) {
@@ -40801,7 +40805,7 @@ const Thead = ({
40801
40805
  actionsList.length > 0 && /* @__PURE__ */ jsx("col", { width: (actionsList.length + 1) * 32 + 10 })
40802
40806
  ] }),
40803
40807
  /* @__PURE__ */ jsx(StyledThead, { children: /* @__PURE__ */ jsxs("tr", { children: [
40804
- isSelectable && /* @__PURE__ */ jsx(StyledHeader, { $size: size2, "aria-label": "Select column", children: /* @__PURE__ */ jsx(Checkbox, { onCheckedChange: onSelectAll, disabled: !hasRows }) }),
40808
+ isSelectable && /* @__PURE__ */ jsx(StyledHeader, { $size: size2, "aria-label": "Select column", children: /* @__PURE__ */ jsx(SelectAllCheckbox, { onCheckedChange: onSelectAll, rows, selectedIds }) }),
40805
40809
  headers.map(({
40806
40810
  width,
40807
40811
  ...headerProps
@@ -40957,7 +40961,7 @@ const TableBodyRow = ({
40957
40961
  const isDeletable = typeof onDelete === "function";
40958
40962
  const isEditable = typeof onEdit === "function";
40959
40963
  return /* @__PURE__ */ jsxs(TableRow, { $isSelectable: isSelectable, $isDeleted: isDeleted, $isDisabled: isDisabled, $isActive: isActive, $showActions: isDeletable || isEditable, $rowHeight: rowHeight, ...rowProps, children: [
40960
- isSelectable && /* @__PURE__ */ jsx(SelectData, { $size: size2, children: /* @__PURE__ */ jsx(Checkbox, { checked: isSelected, onCheckedChange: onSelect }) }),
40964
+ isSelectable && /* @__PURE__ */ jsx(SelectData, { $size: size2, children: /* @__PURE__ */ jsx(Checkbox, { checked: isSelected, onCheckedChange: onSelect, disabled: isDisabled || isDeleted }) }),
40961
40965
  items.map(({
40962
40966
  label,
40963
40967
  ...cellProps
@@ -41009,19 +41013,10 @@ const Table = forwardRef(({
41009
41013
  }, ref) => {
41010
41014
  const isDeletable = typeof onDelete === "function";
41011
41015
  const isEditable = typeof onEdit === "function";
41012
- const onSelectAll = (checked) => {
41013
- if (typeof onSelect === "function") {
41014
- const ids = checked ? rows.map((row, index2) => ({
41015
- item: row,
41016
- index: index2
41017
- })) : [];
41018
- onSelect(ids);
41019
- }
41020
- };
41021
41016
  const onRowSelect = (id) => (checked) => {
41022
41017
  if (typeof onSelect == "function") {
41023
41018
  const selectedItems = rows.flatMap((row, index2) => {
41024
- if (id === row.id && checked || selectedIds.includes(id) && id !== row.id) {
41019
+ if (id === row.id && checked || selectedIds.includes(row.id) && id !== row.id) {
41025
41020
  return {
41026
41021
  item: row,
41027
41022
  index: index2
@@ -41041,9 +41036,9 @@ const Table = forwardRef(({
41041
41036
  actionsList.push("editAction");
41042
41037
  }
41043
41038
  return /* @__PURE__ */ jsxs(TableOuterContainer, { children: [
41044
- hasRows && showHeader && /* @__PURE__ */ jsx(MobileActions, { children: isSelectable && /* @__PURE__ */ jsx(Checkbox, { label: "Select All", checked: selectedIds.length === rows.length, onCheckedChange: onSelectAll }) }),
41039
+ hasRows && showHeader && /* @__PURE__ */ jsx(MobileActions, { children: isSelectable && /* @__PURE__ */ jsx(SelectAllCheckbox, { label: "Select All", onCheckedChange: onSelect, rows, selectedIds }) }),
41045
41040
  /* @__PURE__ */ jsx(TableWrapper, { children: /* @__PURE__ */ jsxs(StyledTable, { ref, ...props, children: [
41046
- showHeader && /* @__PURE__ */ jsx(Thead, { headers, isSelectable, onSelectAll, actionsList, onSort, hasRows, size: size2 }),
41041
+ showHeader && /* @__PURE__ */ jsx(Thead, { headers, isSelectable, onSelectAll: onSelect, actionsList, onSort, size: size2, rows, selectedIds }),
41047
41042
  /* @__PURE__ */ jsxs(Tbody, { children: [
41048
41043
  (loading || !hasRows) && /* @__PURE__ */ jsx(CustomTableRow, { colSpan: headers.length + (isEditable || isDeletable ? 1 : 0) + (isSelectable ? 1 : 0), loading, noDataMessage, size: size2 }),
41049
41044
  rows.map(({
@@ -41061,6 +41056,56 @@ const Table = forwardRef(({
41061
41056
  ] }) })
41062
41057
  ] });
41063
41058
  });
41059
+ const SelectAllCheckbox = ({
41060
+ rows,
41061
+ selectedIds,
41062
+ onCheckedChange,
41063
+ ...checkboxProps
41064
+ }) => {
41065
+ const selectedIdSet = useMemo(() => new Set(selectedIds), [selectedIds]);
41066
+ const {
41067
+ checked,
41068
+ disabled
41069
+ } = useMemo(() => {
41070
+ let areAllChecked = true;
41071
+ let maybeIndeterminate = false;
41072
+ let disabled2 = true;
41073
+ for (const row of rows) {
41074
+ if (row.isDisabled || row.isDeleted) {
41075
+ continue;
41076
+ } else {
41077
+ disabled2 = false;
41078
+ }
41079
+ if (selectedIdSet.has(row.id)) {
41080
+ maybeIndeterminate = "indeterminate";
41081
+ } else {
41082
+ areAllChecked = false;
41083
+ }
41084
+ }
41085
+ return {
41086
+ checked: disabled2 ? false : areAllChecked || maybeIndeterminate,
41087
+ disabled: disabled2
41088
+ };
41089
+ }, [rows, selectedIdSet]);
41090
+ const handleCheckedChange = (checked2) => {
41091
+ if (typeof onCheckedChange !== "function") {
41092
+ return;
41093
+ }
41094
+ const newSelectedRows = rows.reduce((acc, row, index2) => {
41095
+ const isDisabled = row.isDisabled || row.isDeleted;
41096
+ const shouldBeSelected = checked2 ? !isDisabled || selectedIdSet.has(row.id) : isDisabled && selectedIdSet.has(row.id);
41097
+ if (shouldBeSelected) {
41098
+ acc.push({
41099
+ item: row,
41100
+ index: index2
41101
+ });
41102
+ }
41103
+ return acc;
41104
+ }, []);
41105
+ onCheckedChange(newSelectedRows);
41106
+ };
41107
+ return /* @__PURE__ */ jsx(Checkbox, { checked, disabled, onCheckedChange: handleCheckedChange, ...checkboxProps });
41108
+ };
41064
41109
  const StyledTable = pt.table.withConfig({
41065
41110
  componentId: "sc-1q458rb-19"
41066
41111
  })(["width:100%;border-collapse:collapse;overflow:hidden;table-layout:fixed;@media (max-width:768px){border:none;table-layout:auto;}"]);
@@ -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;}"]);
@@ -10225,15 +10225,16 @@ const Wrapper$5 = styled(FormRoot).withConfig({
10225
10225
  const Checkbox = ({
10226
10226
  id,
10227
10227
  label,
10228
- variant,
10228
+ variant = "default",
10229
10229
  disabled,
10230
- orientation,
10231
- dir,
10230
+ orientation = "horizontal",
10231
+ dir = "end",
10232
+ checked,
10232
10233
  ...delegated
10233
10234
  }) => {
10234
10235
  const defaultId = useId();
10235
- return /* @__PURE__ */ jsxs(Wrapper$5, { $orientation: orientation ?? "horizontal", $dir: dir ?? "end", children: [
10236
- /* @__PURE__ */ jsx(CheckInput, { id: id ?? defaultId, "data-testid": "checkbox", variant: variant ?? "default", disabled, "aria-label": `${label}`, ...delegated, children: /* @__PURE__ */ jsx(CheckIconWrapper, { children: /* @__PURE__ */ jsx(SvgImage, { name: "check", size: "sm" }) }) }),
10236
+ return /* @__PURE__ */ jsxs(Wrapper$5, { $orientation: orientation, $dir: dir, children: [
10237
+ /* @__PURE__ */ jsx(CheckInput, { id: id ?? defaultId, "data-testid": "checkbox", variant, disabled, "aria-label": `${label}`, checked, ...delegated, children: /* @__PURE__ */ jsx(CheckIconWrapper, { children: /* @__PURE__ */ jsx(SvgImage, { name: checked === "indeterminate" ? "minus" : "check", size: "sm" }) }) }),
10237
10238
  label && /* @__PURE__ */ jsx(GenericLabel, { htmlFor: id ?? defaultId, disabled, children: label })
10238
10239
  ] });
10239
10240
  };
@@ -10241,7 +10242,7 @@ const CheckInput = styled($e698a72e93240346$export$be92b6f5f03c0fe9).withConfig(
10241
10242
  componentId: "sc-1sck1ja-1"
10242
10243
  })(["display:flex;align-items:center;justify-content:center;flex-shrink:0;", ";"], ({
10243
10244
  theme: theme2,
10244
- variant = "default"
10245
+ variant
10245
10246
  }) => `
10246
10247
  border-radius: ${theme2.click.checkbox.radii.all};
10247
10248
  width: ${theme2.click.checkbox.size.all};
@@ -10253,7 +10254,8 @@ const CheckInput = styled($e698a72e93240346$export$be92b6f5f03c0fe9).withConfig(
10253
10254
  &:hover {
10254
10255
  background: ${theme2.click.checkbox.color.variations[variant].background.hover};
10255
10256
  }
10256
- &[data-state="checked"] {
10257
+ &[data-state="checked"],
10258
+ &[data-state="indeterminate"] {
10257
10259
  border-color: ${theme2.click.checkbox.color.variations[variant].stroke.active};
10258
10260
  background: ${theme2.click.checkbox.color.variations[variant].background.active};
10259
10261
  }
@@ -10261,7 +10263,8 @@ const CheckInput = styled($e698a72e93240346$export$be92b6f5f03c0fe9).withConfig(
10261
10263
  background: ${theme2.click.checkbox.color.background.disabled};
10262
10264
  border-color: ${theme2.click.checkbox.color.stroke.disabled};
10263
10265
  cursor: not-allowed;
10264
- &[data-state="checked"] {
10266
+ &[data-state="checked"],
10267
+ &[data-state="indeterminate"] {
10265
10268
  background: ${theme2.click.checkbox.color.background.disabled};
10266
10269
  border-color: ${theme2.click.checkbox.color.stroke.disabled};
10267
10270
  }
@@ -39618,8 +39621,9 @@ const Thead = ({
39618
39621
  onSelectAll,
39619
39622
  actionsList,
39620
39623
  onSort: onSortProp,
39621
- hasRows,
39622
- size: size2
39624
+ size: size2,
39625
+ rows,
39626
+ selectedIds
39623
39627
  }) => {
39624
39628
  const onSort = (header, headerIndex) => () => {
39625
39629
  if (typeof onSortProp === "function" && header.isSortable) {
@@ -39633,7 +39637,7 @@ const Thead = ({
39633
39637
  actionsList.length > 0 && /* @__PURE__ */ jsx("col", { width: (actionsList.length + 1) * 32 + 10 })
39634
39638
  ] }),
39635
39639
  /* @__PURE__ */ jsx(StyledThead, { children: /* @__PURE__ */ jsxs("tr", { children: [
39636
- isSelectable && /* @__PURE__ */ jsx(StyledHeader, { $size: size2, "aria-label": "Select column", children: /* @__PURE__ */ jsx(Checkbox, { onCheckedChange: onSelectAll, disabled: !hasRows }) }),
39640
+ isSelectable && /* @__PURE__ */ jsx(StyledHeader, { $size: size2, "aria-label": "Select column", children: /* @__PURE__ */ jsx(SelectAllCheckbox, { onCheckedChange: onSelectAll, rows, selectedIds }) }),
39637
39641
  headers.map(({
39638
39642
  width,
39639
39643
  ...headerProps
@@ -39789,7 +39793,7 @@ const TableBodyRow = ({
39789
39793
  const isDeletable = typeof onDelete === "function";
39790
39794
  const isEditable = typeof onEdit === "function";
39791
39795
  return /* @__PURE__ */ jsxs(TableRow, { $isSelectable: isSelectable, $isDeleted: isDeleted, $isDisabled: isDisabled, $isActive: isActive, $showActions: isDeletable || isEditable, $rowHeight: rowHeight, ...rowProps, children: [
39792
- isSelectable && /* @__PURE__ */ jsx(SelectData, { $size: size2, children: /* @__PURE__ */ jsx(Checkbox, { checked: isSelected, onCheckedChange: onSelect }) }),
39796
+ isSelectable && /* @__PURE__ */ jsx(SelectData, { $size: size2, children: /* @__PURE__ */ jsx(Checkbox, { checked: isSelected, onCheckedChange: onSelect, disabled: isDisabled || isDeleted }) }),
39793
39797
  items.map(({
39794
39798
  label,
39795
39799
  ...cellProps
@@ -39841,19 +39845,10 @@ const Table = forwardRef(({
39841
39845
  }, ref) => {
39842
39846
  const isDeletable = typeof onDelete === "function";
39843
39847
  const isEditable = typeof onEdit === "function";
39844
- const onSelectAll = (checked) => {
39845
- if (typeof onSelect === "function") {
39846
- const ids = checked ? rows.map((row, index2) => ({
39847
- item: row,
39848
- index: index2
39849
- })) : [];
39850
- onSelect(ids);
39851
- }
39852
- };
39853
39848
  const onRowSelect = (id) => (checked) => {
39854
39849
  if (typeof onSelect == "function") {
39855
39850
  const selectedItems = rows.flatMap((row, index2) => {
39856
- if (id === row.id && checked || selectedIds.includes(id) && id !== row.id) {
39851
+ if (id === row.id && checked || selectedIds.includes(row.id) && id !== row.id) {
39857
39852
  return {
39858
39853
  item: row,
39859
39854
  index: index2
@@ -39873,9 +39868,9 @@ const Table = forwardRef(({
39873
39868
  actionsList.push("editAction");
39874
39869
  }
39875
39870
  return /* @__PURE__ */ jsxs(TableOuterContainer, { children: [
39876
- hasRows && showHeader && /* @__PURE__ */ jsx(MobileActions, { children: isSelectable && /* @__PURE__ */ jsx(Checkbox, { label: "Select All", checked: selectedIds.length === rows.length, onCheckedChange: onSelectAll }) }),
39871
+ hasRows && showHeader && /* @__PURE__ */ jsx(MobileActions, { children: isSelectable && /* @__PURE__ */ jsx(SelectAllCheckbox, { label: "Select All", onCheckedChange: onSelect, rows, selectedIds }) }),
39877
39872
  /* @__PURE__ */ jsx(TableWrapper, { children: /* @__PURE__ */ jsxs(StyledTable, { ref, ...props, children: [
39878
- showHeader && /* @__PURE__ */ jsx(Thead, { headers, isSelectable, onSelectAll, actionsList, onSort, hasRows, size: size2 }),
39873
+ showHeader && /* @__PURE__ */ jsx(Thead, { headers, isSelectable, onSelectAll: onSelect, actionsList, onSort, size: size2, rows, selectedIds }),
39879
39874
  /* @__PURE__ */ jsxs(Tbody, { children: [
39880
39875
  (loading || !hasRows) && /* @__PURE__ */ jsx(CustomTableRow, { colSpan: headers.length + (isEditable || isDeletable ? 1 : 0) + (isSelectable ? 1 : 0), loading, noDataMessage, size: size2 }),
39881
39876
  rows.map(({
@@ -39893,6 +39888,56 @@ const Table = forwardRef(({
39893
39888
  ] }) })
39894
39889
  ] });
39895
39890
  });
39891
+ const SelectAllCheckbox = ({
39892
+ rows,
39893
+ selectedIds,
39894
+ onCheckedChange,
39895
+ ...checkboxProps
39896
+ }) => {
39897
+ const selectedIdSet = useMemo(() => new Set(selectedIds), [selectedIds]);
39898
+ const {
39899
+ checked,
39900
+ disabled
39901
+ } = useMemo(() => {
39902
+ let areAllChecked = true;
39903
+ let maybeIndeterminate = false;
39904
+ let disabled2 = true;
39905
+ for (const row of rows) {
39906
+ if (row.isDisabled || row.isDeleted) {
39907
+ continue;
39908
+ } else {
39909
+ disabled2 = false;
39910
+ }
39911
+ if (selectedIdSet.has(row.id)) {
39912
+ maybeIndeterminate = "indeterminate";
39913
+ } else {
39914
+ areAllChecked = false;
39915
+ }
39916
+ }
39917
+ return {
39918
+ checked: disabled2 ? false : areAllChecked || maybeIndeterminate,
39919
+ disabled: disabled2
39920
+ };
39921
+ }, [rows, selectedIdSet]);
39922
+ const handleCheckedChange = (checked2) => {
39923
+ if (typeof onCheckedChange !== "function") {
39924
+ return;
39925
+ }
39926
+ const newSelectedRows = rows.reduce((acc, row, index2) => {
39927
+ const isDisabled = row.isDisabled || row.isDeleted;
39928
+ const shouldBeSelected = checked2 ? !isDisabled || selectedIdSet.has(row.id) : isDisabled && selectedIdSet.has(row.id);
39929
+ if (shouldBeSelected) {
39930
+ acc.push({
39931
+ item: row,
39932
+ index: index2
39933
+ });
39934
+ }
39935
+ return acc;
39936
+ }, []);
39937
+ onCheckedChange(newSelectedRows);
39938
+ };
39939
+ return /* @__PURE__ */ jsx(Checkbox, { checked, disabled, onCheckedChange: handleCheckedChange, ...checkboxProps });
39940
+ };
39896
39941
  const StyledTable = styled.table.withConfig({
39897
39942
  componentId: "sc-1q458rb-19"
39898
39943
  })(["width:100%;border-collapse:collapse;overflow:hidden;table-layout:fixed;@media (max-width:768px){border:none;table-layout:auto;}"]);
@@ -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;}"]);
@@ -7,4 +7,4 @@ export interface CheckboxProps extends RadixCheckbox.CheckboxProps {
7
7
  variant?: CheckboxVariants;
8
8
  dir?: "start" | "end";
9
9
  }
10
- export declare const Checkbox: ({ id, label, variant, disabled, orientation, dir, ...delegated }: CheckboxProps) => import("react/jsx-runtime").JSX.Element;
10
+ export declare const Checkbox: ({ id, label, variant, disabled, orientation, dir, checked, ...delegated }: CheckboxProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,5 +1,5 @@
1
- import { HorizontalDirection } from '..';
2
1
  import { HTMLAttributes, ReactNode } from 'react';
2
+ import { HorizontalDirection } from '..';
3
3
 
4
4
  type SortDir = "asc" | "desc";
5
5
  type SortFn = (sortDir: SortDir, header: TableHeaderType, index: number) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clickhouse/click-ui",
3
- "version": "0.0.220",
3
+ "version": "0.0.221",
4
4
  "description": "Official ClickHouse design system react library",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",