@overmap-ai/blocks 1.0.10 → 1.0.13-table-default-rows-and-topbar-components.0

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.
@@ -10,7 +10,7 @@ export interface TableCell {
10
10
  id: IdLabel;
11
11
  value: ValueLabel;
12
12
  label: TableLabel;
13
- onClick?: (cell: TableCell) => void;
13
+ onClick?: (e: Event) => void;
14
14
  filterValue?: ValueLabel;
15
15
  sortValue?: ValueLabel;
16
16
  searchValue?: ValueLabel;
@@ -41,6 +41,7 @@ export interface TableProps {
41
41
  color?: "light" | "dark";
42
42
  title?: string | ReactNode;
43
43
  description?: string | ReactNode;
44
+ defaultRowsPerPage?: number;
44
45
  rowsPerPage?: number[];
45
46
  showSearchBar?: boolean;
46
47
  searchBarPlaceholder?: string;
@@ -51,14 +52,9 @@ export interface TableProps {
51
52
  showPageNumber?: boolean;
52
53
  showPageNavigation?: boolean;
53
54
  children?: ReactNode;
54
- /**
55
- * Show top bar content which includes search bar, filter button, and edit and delete buttons
56
- * @default false
57
- */
55
+ topBarComponents?: ReactNode;
58
56
  showTopBar?: boolean;
59
57
  showBottomBar?: boolean;
60
- showTopButtons?: boolean;
61
- topButtons?: ReactNode[];
62
58
  emptyMessage?: string;
63
59
  className?: string;
64
60
  columnClassName?: string;
package/dist/blocks.js CHANGED
@@ -2967,19 +2967,21 @@ const SelectAllCheckbox = memo(function SelectAllCheckbox2({
2967
2967
  childrenWithProps
2968
2968
  ] });
2969
2969
  });
2970
- const tableContainer = "_tableContainer_t2fb9_1";
2971
- const headerContainer = "_headerContainer_t2fb9_14";
2972
- const tableTopContainer = "_tableTopContainer_t2fb9_18";
2973
- const searchContainer = "_searchContainer_t2fb9_22";
2974
- const columnFilterSelect = "_columnFilterSelect_t2fb9_32";
2975
- const table = "_table_t2fb9_1";
2976
- const tableHeaderCell = "_tableHeaderCell_t2fb9_50";
2977
- const tableRow = "_tableRow_t2fb9_56";
2978
- const tableCell = "_tableCell_t2fb9_71";
2979
- const noDataTextContainer = "_noDataTextContainer_t2fb9_81";
2980
- const tableBottomContainer = "_tableBottomContainer_t2fb9_87";
2981
- const rowsPerPageContainer = "_rowsPerPageContainer_t2fb9_91";
2982
- const rowsPerPageText = "_rowsPerPageText_t2fb9_101";
2970
+ const tableContainer = "_tableContainer_boacd_1";
2971
+ const headerContainer = "_headerContainer_boacd_14";
2972
+ const tableTopContainer = "_tableTopContainer_boacd_18";
2973
+ const searchContainer = "_searchContainer_boacd_22";
2974
+ const columnFilterSelect = "_columnFilterSelect_boacd_32";
2975
+ const table = "_table_boacd_1";
2976
+ const tableHeaderCell = "_tableHeaderCell_boacd_50";
2977
+ const showSortIcon = "_showSortIcon_boacd_59";
2978
+ const tableRow = "_tableRow_boacd_63";
2979
+ const tableCell = "_tableCell_boacd_78";
2980
+ const noDataTextContainer = "_noDataTextContainer_boacd_88";
2981
+ const tableBottomContainer = "_tableBottomContainer_boacd_94";
2982
+ const rowsPerPageContainer = "_rowsPerPageContainer_boacd_98";
2983
+ const rowsPerPageText = "_rowsPerPageText_boacd_108";
2984
+ const pageText = "_pageText_boacd_113";
2983
2985
  const styles$1 = {
2984
2986
  tableContainer,
2985
2987
  headerContainer,
@@ -2988,14 +2990,17 @@ const styles$1 = {
2988
2990
  columnFilterSelect,
2989
2991
  table,
2990
2992
  tableHeaderCell,
2993
+ showSortIcon,
2991
2994
  tableRow,
2992
2995
  tableCell,
2993
2996
  noDataTextContainer,
2994
2997
  tableBottomContainer,
2995
2998
  rowsPerPageContainer,
2996
- rowsPerPageText
2999
+ rowsPerPageText,
3000
+ pageText
2997
3001
  };
2998
3002
  const _Table = forwardRef(function Table2(props, ref) {
3003
+ var _a;
2999
3004
  const {
3000
3005
  columns,
3001
3006
  data,
@@ -3013,9 +3018,8 @@ const _Table = forwardRef(function Table2(props, ref) {
3013
3018
  showPageNavigation,
3014
3019
  showTopBar = true,
3015
3020
  showBottomBar = true,
3016
- showTopButtons,
3017
- topButtons,
3018
3021
  emptyMessage = "There is no data",
3022
+ topBarComponents,
3019
3023
  children,
3020
3024
  className,
3021
3025
  columnClassName,
@@ -3030,12 +3034,20 @@ const _Table = forwardRef(function Table2(props, ref) {
3030
3034
  if (!rowsColumnsHaveAllColumns) {
3031
3035
  throw new Error("Columns in rows do not match ones declared in columns variable.");
3032
3036
  }
3033
- const defaultColumnFilterValues = useMemo(
3034
- () => columns.filter((column) => column.filter).map((column) => ({ [column.id]: [] })).reduce((arr, column) => Object.assign(arr, column), {}),
3037
+ const defaultRowsPerPage = props.defaultRowsPerPage || rowsPerPage[0] || 10;
3038
+ const getDefaultColumnValues = useCallback(
3039
+ (defaultValue) => columns.filter((column) => column.filter).map((column) => ({ [column.id]: defaultValue })).reduce((arr, column) => Object.assign(arr, column), {}),
3035
3040
  [columns]
3036
3041
  );
3042
+ const defaultColumnFilterValues = useMemo(() => getDefaultColumnValues([]), [getDefaultColumnValues]);
3037
3043
  const [columnFilterValues, setColumnFilterValues] = useState(defaultColumnFilterValues);
3038
- const [numRowsPerPage, setNumRowsPerPage] = useState(rowsPerPage[0] ?? 10);
3044
+ const defaultColumnIsSortedValues = useMemo(() => getDefaultColumnValues(false), [getDefaultColumnValues]);
3045
+ const [columnIsSorted, setColumnIsSorted] = useState(defaultColumnIsSortedValues);
3046
+ if (!rowsPerPage.includes(defaultRowsPerPage)) {
3047
+ rowsPerPage.push(defaultRowsPerPage);
3048
+ }
3049
+ rowsPerPage.sort((a, b) => a - b);
3050
+ const [numRowsPerPage, setNumRowsPerPage] = useState(defaultRowsPerPage || (rowsPerPage[0] ?? 10));
3039
3051
  const rowsPerPageOptions = useMemo(
3040
3052
  () => rowsPerPage.map((numRows) => ({
3041
3053
  value: numRows.toString(),
@@ -3046,22 +3058,22 @@ const _Table = forwardRef(function Table2(props, ref) {
3046
3058
  const rowsHaveOnClick = data.some((row) => row.onClick);
3047
3059
  const searchFilter = useCallback(
3048
3060
  (cell) => {
3049
- var _a, _b;
3050
- const cellVal = ((_a = cell.searchValue) == null ? void 0 : _a.toString()) || ((_b = cell.value) == null ? void 0 : _b.toString()) || "";
3061
+ var _a2, _b;
3062
+ const cellVal = ((_a2 = cell.searchValue) == null ? void 0 : _a2.toString()) || ((_b = cell.value) == null ? void 0 : _b.toString()) || "";
3051
3063
  return cellVal.toLowerCase().includes(search.toLowerCase());
3052
3064
  },
3053
3065
  [search]
3054
3066
  );
3055
3067
  const sortFilter = useCallback((a, b) => {
3056
- var _a, _b, _c, _d;
3057
- const aVal = ((_a = a.sortValue) == null ? void 0 : _a.toString()) || ((_b = a.value) == null ? void 0 : _b.toString()) || "";
3068
+ var _a2, _b, _c, _d;
3069
+ const aVal = ((_a2 = a.sortValue) == null ? void 0 : _a2.toString()) || ((_b = a.value) == null ? void 0 : _b.toString()) || "";
3058
3070
  const bVal = ((_c = b.sortValue) == null ? void 0 : _c.toString()) || ((_d = b.value) == null ? void 0 : _d.toString()) || "";
3059
3071
  return aVal.toLowerCase().localeCompare(bVal.toLowerCase(), void 0, { numeric: true });
3060
3072
  }, []);
3061
3073
  const columnFilter = useCallback(
3062
3074
  (cell, column) => {
3063
- var _a, _b, _c;
3064
- const cellVal = ((_a = cell.filterValue) == null ? void 0 : _a.toString()) || ((_b = cell.value) == null ? void 0 : _b.toString()) || "";
3075
+ var _a2, _b, _c;
3076
+ const cellVal = ((_a2 = cell.filterValue) == null ? void 0 : _a2.toString()) || ((_b = cell.value) == null ? void 0 : _b.toString()) || "";
3065
3077
  return (_c = columnFilterValues[column.id]) == null ? void 0 : _c.some(
3066
3078
  (filter) => cellVal.toString().toLowerCase() === filter.toString().toLowerCase()
3067
3079
  );
@@ -3077,8 +3089,8 @@ const _Table = forwardRef(function Table2(props, ref) {
3077
3089
  );
3078
3090
  const isColumnFilterValueSelected = columns.some(
3079
3091
  (column) => {
3080
- var _a;
3081
- return column.filter && column.id in columnFilterValues && ((_a = columnFilterValues[column.id]) == null ? void 0 : _a.length) !== 0;
3092
+ var _a2;
3093
+ return column.filter && column.id in columnFilterValues && ((_a2 = columnFilterValues[column.id]) == null ? void 0 : _a2.length) !== 0;
3082
3094
  }
3083
3095
  );
3084
3096
  const rows = useMemo(
@@ -3091,8 +3103,8 @@ const _Table = forwardRef(function Table2(props, ref) {
3091
3103
  // column is not selected for filtering (has a filter prop). Second, return true if that column
3092
3104
  // has any values in it selected for filtering, lastly, return if row has that filter value
3093
3105
  columns.every((column) => {
3094
- var _a;
3095
- return !column.filter || ((_a = columnFilterValues[column.id]) == null ? void 0 : _a.length) === 0 || columnFilter(row.columns[column.id], column);
3106
+ var _a2;
3107
+ return !column.filter || ((_a2 = columnFilterValues[column.id]) == null ? void 0 : _a2.length) === 0 || columnFilter(row.columns[column.id], column);
3096
3108
  })
3097
3109
  )
3098
3110
  ).map((row) => {
@@ -3111,8 +3123,8 @@ const _Table = forwardRef(function Table2(props, ref) {
3111
3123
  const uniqueFilterValues = new Set(
3112
3124
  data.map(
3113
3125
  (row) => {
3114
- var _a, _b;
3115
- return ((_a = row.columns[column.id].filterValue) == null ? void 0 : _a.toString()) || ((_b = row.columns[column.id].value) == null ? void 0 : _b.toString()) || "";
3126
+ var _a2, _b;
3127
+ return ((_a2 = row.columns[column.id].filterValue) == null ? void 0 : _a2.toString()) || ((_b = row.columns[column.id].value) == null ? void 0 : _b.toString()) || "";
3116
3128
  }
3117
3129
  )
3118
3130
  );
@@ -3153,7 +3165,7 @@ const _Table = forwardRef(function Table2(props, ref) {
3153
3165
  {
3154
3166
  state: {
3155
3167
  page: 0,
3156
- size: rowsPerPage[0]
3168
+ size: defaultRowsPerPage || rowsPerPage[0]
3157
3169
  }
3158
3170
  },
3159
3171
  {
@@ -3162,7 +3174,11 @@ const _Table = forwardRef(function Table2(props, ref) {
3162
3174
  );
3163
3175
  const sort = useSort(
3164
3176
  tableData,
3165
- { onChange: () => null },
3177
+ {
3178
+ onChange: (_action, state) => {
3179
+ setColumnIsSorted({ ...defaultColumnIsSortedValues, [state.sortKey.toLowerCase()]: true });
3180
+ }
3181
+ },
3166
3182
  {
3167
3183
  sortIcon: {
3168
3184
  margin: "10px",
@@ -3201,23 +3217,23 @@ const _Table = forwardRef(function Table2(props, ref) {
3201
3217
  setColumnFilterValues(_columnFilterValues);
3202
3218
  },
3203
3219
  children: getFilterValues(column).map((filterValue, i) => {
3204
- var _a, _b;
3220
+ var _a2, _b;
3205
3221
  return /* @__PURE__ */ jsx(
3206
3222
  Checkbox,
3207
3223
  {
3208
3224
  label: filterValue.label,
3209
3225
  checked: (_b = columnFilterValues[column.id]) == null ? void 0 : _b.includes(
3210
- ((_a = filterValue.value) == null ? void 0 : _a.toString()) || ""
3226
+ ((_a2 = filterValue.value) == null ? void 0 : _a2.toString()) || ""
3211
3227
  ),
3212
3228
  onCheckedChange: (checked) => {
3213
3229
  setColumnFilterValues((prevColumnFilterValues) => {
3214
- var _a2;
3230
+ var _a3;
3215
3231
  const _columnFilterValues = { ...prevColumnFilterValues };
3216
3232
  const values = _columnFilterValues[column.id] || [];
3217
3233
  if (checked) {
3218
3234
  _columnFilterValues[column.id] = [
3219
3235
  ...values,
3220
- ((_a2 = filterValue.value) == null ? void 0 : _a2.toString()) || ""
3236
+ ((_a3 = filterValue.value) == null ? void 0 : _a3.toString()) || ""
3221
3237
  ];
3222
3238
  } else {
3223
3239
  _columnFilterValues[column.id] = values.filter(
@@ -3241,15 +3257,20 @@ const _Table = forwardRef(function Table2(props, ref) {
3241
3257
  );
3242
3258
  const columnCells = columnsData.map((column) => {
3243
3259
  const Component = column.sort ? HeaderCellSort : HeaderCell;
3244
- return /* @__PURE__ */ jsx(
3260
+ return /* @__PURE__ */ jsx(HoverUtility, { children: ({ isHovered, ...props2 }) => /* @__PURE__ */ jsx(
3245
3261
  Component,
3246
3262
  {
3247
- className: classNames(styles$1.tableHeaderCell, columnClassName, column.className),
3263
+ className: classNames(
3264
+ styles$1.tableHeaderCell,
3265
+ columnClassName,
3266
+ (columnIsSorted[column.id] || isHovered) && styles$1.showSortIcon,
3267
+ column.className
3268
+ ),
3248
3269
  sortKey: column.sort ? column.id.toString().toUpperCase() : "",
3270
+ ...props2,
3249
3271
  children: column.label
3250
- },
3251
- column.id
3252
- );
3272
+ }
3273
+ ) }, column.id);
3253
3274
  });
3254
3275
  const SelectedModeButton = isMobile ? IconButton : Button2;
3255
3276
  const layout = useMemo(() => ({ custom: true }), []);
@@ -3289,7 +3310,7 @@ const _Table = forwardRef(function Table2(props, ref) {
3289
3310
  !!title && /* @__PURE__ */ jsx(Text$1, { weight: "bold", size: "5", children: title }),
3290
3311
  !!description && /* @__PURE__ */ jsx(Text$1, { as: "div", children: description })
3291
3312
  ] }),
3292
- showTopBar && /* @__PURE__ */ jsxs(Flex$1, { direction: "column", children: [
3313
+ showTopBar && /* @__PURE__ */ jsxs(Flex$1, { justify: "between", gap: "2", className: styles$1.tableTopContainer, children: [
3293
3314
  /* @__PURE__ */ jsxs(Flex$1, { gap: "2", children: [
3294
3315
  showSearchBar && /* @__PURE__ */ jsx(Flex$1, { direction: "column", children: /* @__PURE__ */ jsx("div", { className: styles$1.searchContainer, children: /* @__PURE__ */ jsx(
3295
3316
  Input,
@@ -3325,19 +3346,15 @@ const _Table = forwardRef(function Table2(props, ref) {
3325
3346
  }
3326
3347
  )
3327
3348
  ] }),
3328
- /* @__PURE__ */ jsxs(Flex$1, { justify: "between", className: styles$1.tableTopContainer, children: [
3329
- showTopButtons && topButtons && /* @__PURE__ */ jsxs(Flex$1, { gap: "2", children: [
3330
- ...topButtons
3349
+ topBarComponents,
3350
+ showSelect && selected.length !== 0 && /* @__PURE__ */ jsxs(Flex$1, { gap: "2", children: [
3351
+ /* @__PURE__ */ jsxs(SelectedModeButton, { variant: "soft", "aria-label": "Edit rows", children: [
3352
+ /* @__PURE__ */ jsx(Pencil1Icon, {}),
3353
+ !isMobile && "Edit"
3331
3354
  ] }),
3332
- showSelect && selected.length !== 0 && /* @__PURE__ */ jsxs(Flex$1, { gap: "2", children: [
3333
- /* @__PURE__ */ jsxs(SelectedModeButton, { variant: "soft", "aria-label": "Edit rows", children: [
3334
- /* @__PURE__ */ jsx(Pencil1Icon, {}),
3335
- !isMobile && "Edit"
3336
- ] }),
3337
- /* @__PURE__ */ jsxs(SelectedModeButton, { color: "red", "aria-label": "Delete rows", children: [
3338
- /* @__PURE__ */ jsx(TrashIcon, {}),
3339
- !isMobile && "Delete"
3340
- ] })
3355
+ /* @__PURE__ */ jsxs(SelectedModeButton, { color: "red", "aria-label": "Delete rows", children: [
3356
+ /* @__PURE__ */ jsx(TrashIcon, {}),
3357
+ !isMobile && "Delete"
3341
3358
  ] })
3342
3359
  ] })
3343
3360
  ] }),
@@ -3377,7 +3394,7 @@ const _Table = forwardRef(function Table2(props, ref) {
3377
3394
  row[column.id].className
3378
3395
  ),
3379
3396
  onClick: row[column.id].onClick,
3380
- children: /* @__PURE__ */ jsx(Text$1, { children: row[column.id].label })
3397
+ children: /* @__PURE__ */ jsx(Text$1, { size: "2", children: row[column.id].label })
3381
3398
  },
3382
3399
  i
3383
3400
  ))
@@ -3391,12 +3408,12 @@ const _Table = forwardRef(function Table2(props, ref) {
3391
3408
  ),
3392
3409
  showBottomBar && /* @__PURE__ */ jsxs(Flex$1, { className: styles$1.tableBottomContainer, wrap: "wrap", direction: isMobile ? "column" : "row", children: [
3393
3410
  showRowsPerPage && /* @__PURE__ */ jsxs(Flex$1, { className: styles$1.rowsPerPageContainer, children: [
3394
- /* @__PURE__ */ jsx("div", { className: styles$1.rowsPerPageText, children: "Rows per page:" }),
3411
+ /* @__PURE__ */ jsx(Text$1, { className: styles$1.rowsPerPageText, size: "2", children: "Rows per page:" }),
3395
3412
  /* @__PURE__ */ jsx(
3396
3413
  Select,
3397
3414
  {
3398
3415
  items: rowsPerPageOptions,
3399
- defaultValue: rowsPerPageOptions[0].value.toString(),
3416
+ defaultValue: (_a = rowsPerPageOptions.find((rowPerPage) => rowPerPage.value === defaultRowsPerPage.toString())) == null ? void 0 : _a.value.toString(),
3400
3417
  onValueChange: (v) => {
3401
3418
  pagination.fns.onSetSize(Number(v));
3402
3419
  setNumRowsPerPage(Number(v));
@@ -3406,7 +3423,7 @@ const _Table = forwardRef(function Table2(props, ref) {
3406
3423
  }
3407
3424
  )
3408
3425
  ] }),
3409
- showPageNumber && /* @__PURE__ */ jsx(Flex$1, { justify: "center", children: totalPages > 0 && `Page ${pagination.state.page + 1} of ${totalPages}` }),
3426
+ showPageNumber && /* @__PURE__ */ jsx(Flex$1, { justify: "center", children: /* @__PURE__ */ jsx(Text$1, { className: styles$1.pageText, size: "2", children: totalPages > 0 && `Page ${pagination.state.page + 1} of ${totalPages}` }) }),
3410
3427
  showPageNavigation && /* @__PURE__ */ jsxs(Flex$1, { className: styles$1.rowsPerPageContainer, gap: "2", justify: "end", children: [
3411
3428
  /* @__PURE__ */ jsx(
3412
3429
  IconButton,