@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.
@@ -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;}"]);
@@ -52123,3 +52168,4 @@ export {
52123
52168
  useCUITheme,
52124
52169
  useToast
52125
52170
  };
52171
+ //# sourceMappingURL=click-ui.bundled.es.js.map