@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.
@@ -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;}"]);
@@ -50955,3 +51000,4 @@ export {
50955
51000
  useCUITheme,
50956
51001
  useToast
50957
51002
  };
51003
+ //# sourceMappingURL=click-ui.es.js.map