@commmerce/ui 1.5.1 → 1.6.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.
Files changed (65) hide show
  1. package/dist/calendar.js +2 -0
  2. package/dist/cdn.js +1018 -659
  3. package/dist/components/action-menu.d.ts +28 -1
  4. package/dist/components/action-menu.js +86 -17
  5. package/dist/components/badge.d.ts +3 -2
  6. package/dist/components/badge.js +4 -3
  7. package/dist/components/bottom-sheet.js +1 -1
  8. package/dist/components/button.d.ts +5 -1
  9. package/dist/components/button.js +18 -6
  10. package/dist/components/calendar.d.ts +6 -1
  11. package/dist/components/calendar.js +15 -1
  12. package/dist/components/card.d.ts +38 -0
  13. package/dist/components/card.js +77 -12
  14. package/dist/components/checkbox.js +7 -2
  15. package/dist/components/color-field.js +2 -0
  16. package/dist/components/combobox.d.ts +27 -2
  17. package/dist/components/combobox.js +109 -15
  18. package/dist/components/data-table.d.ts +127 -9
  19. package/dist/components/data-table.js +577 -67
  20. package/dist/components/date-picker.d.ts +1 -1
  21. package/dist/components/date-picker.js +1 -1
  22. package/dist/components/date-range-picker.d.ts +1 -1
  23. package/dist/components/date-range-picker.js +2 -2
  24. package/dist/components/empty-state.d.ts +8 -6
  25. package/dist/components/empty-state.js +26 -17
  26. package/dist/components/file-upload.d.ts +49 -4
  27. package/dist/components/file-upload.js +136 -29
  28. package/dist/components/layout.d.ts +2 -2
  29. package/dist/components/layout.js +5 -5
  30. package/dist/components/menu-item.d.ts +18 -0
  31. package/dist/components/menu-item.js +8 -0
  32. package/dist/components/page-header.d.ts +6 -0
  33. package/dist/components/page-header.js +22 -5
  34. package/dist/components/pagination.d.ts +3 -2
  35. package/dist/components/pagination.js +13 -10
  36. package/dist/components/radio.js +4 -2
  37. package/dist/components/resource-list.d.ts +28 -3
  38. package/dist/components/resource-list.js +47 -15
  39. package/dist/components/search.d.ts +2 -2
  40. package/dist/components/search.js +4 -2
  41. package/dist/components/segmented-control.js +1 -1
  42. package/dist/components/select.d.ts +11 -1
  43. package/dist/components/select.js +17 -4
  44. package/dist/components/side-navigation.d.ts +1 -1
  45. package/dist/components/side-navigation.js +5 -3
  46. package/dist/components/signature-field.js +2 -2
  47. package/dist/components/status-tabs.d.ts +24 -4
  48. package/dist/components/status-tabs.js +82 -9
  49. package/dist/components/table-header.d.ts +1 -1
  50. package/dist/components/table-header.js +3 -3
  51. package/dist/components/tag.d.ts +7 -0
  52. package/dist/components/tag.js +6 -3
  53. package/dist/components/text-field.d.ts +1 -1
  54. package/dist/components/text-field.js +3 -1
  55. package/dist/components/toggle.js +3 -1
  56. package/dist/components/tooltip.d.ts +5 -2
  57. package/dist/components/tooltip.js +14 -9
  58. package/dist/custom-elements.json +1599 -129
  59. package/dist/density.d.ts +21 -0
  60. package/dist/density.js +46 -0
  61. package/dist/field.d.ts +9 -5
  62. package/dist/field.js +16 -10
  63. package/dist/index.d.ts +1 -1
  64. package/dist/popover.js +1 -1
  65. package/package.json +3 -3
@@ -1,42 +1,91 @@
1
1
  import { CmLocalizedElement } from '../localize.js';
2
2
  import './icon.js';
3
3
  import './skeleton.js';
4
+ import './button.js';
4
5
  declare const strings: {
5
6
  /** Shown when there are no rows and no `empty` slot. */
6
7
  empty: string;
7
8
  /** Announced after a sort. `{direction}` is the common `ascending` or `descending`. */
8
9
  sorted: string;
10
+ /** Under a table wider than its box, while there is more to scroll to. */
11
+ scrollHint: string;
12
+ /** The column picker's button, and the name of its list of choices. */
13
+ columns: string;
14
+ showColumns: string;
15
+ /** Accessible name of a column's resize handle. */
16
+ resize: string;
17
+ /** Announced after a column is resized. */
18
+ resized: string;
19
+ /** With `mobile="priority"` on a narrow table: shows and hides a row's low-priority fields. */
20
+ viewAll: string;
21
+ viewLess: string;
22
+ /** Accessible name of a row action: `{action}` is its label, `{name}` the row's first (or `primary`) value. */
23
+ rowAction: string;
9
24
  };
10
25
  declare module '../localize.js' {
11
26
  interface CmStrings {
12
27
  dataTable: typeof strings;
13
28
  }
14
29
  }
30
+ /** A button in an `actions` column. */
31
+ export interface DataTableAction {
32
+ /** Button text, e.g. "Edit". With `iconOnly`, the accessible name (the row's name is added for screen readers). */
33
+ label: string;
34
+ /** Identifies the action in `cm-row-action`. Defaults to the label. */
35
+ value?: string;
36
+ /** A @commmerce/icons name shown before the label. */
37
+ icon?: string;
38
+ /** Shows only the icon (give it one). */
39
+ iconOnly?: boolean;
40
+ /** `critical` for destructive actions such as Delete. */
41
+ tone?: 'critical';
42
+ }
15
43
  /** One column of a data table. */
16
44
  export interface DataTableColumn {
17
45
  /** The property of each row shown in this column, and the key in `cm-sort`. */
18
46
  key: string;
19
47
  /** Column heading. */
20
48
  label: string;
21
- /** Text alignment. Default: `end` for `numeric` and `money`, otherwise `start`. */
49
+ /** Text alignment. Default: `end` for `numeric`, `money` and `actions`, otherwise `start`. */
22
50
  align?: 'start' | 'end';
23
51
  /** Lets the merchant sort by this column. */
24
52
  sortable?: boolean;
25
53
  /**
26
- * How values are compared and laid out. `numeric` and `money` are right-aligned with tabular figures;
27
- * `date` sorts by date (ISO strings, timestamps or `Date` objects).
54
+ * How values are compared and laid out. `text` (the default) stays on one line and ends in "…" when it is too long
55
+ * (the full value shows on hover and is always read by screen readers). `numeric` and `money` are right-aligned with
56
+ * tabular figures; `date` sorts by date (ISO strings, timestamps or `Date` objects); numbers and dates never wrap.
57
+ * `actions` (since 1.6) shows the column's `actions` as buttons, right-aligned, with the heading for screen readers only.
28
58
  */
29
- type?: 'text' | 'numeric' | 'money' | 'date';
30
- /** Heading for screen readers only, e.g. for an actions column. */
59
+ type?: 'text' | 'numeric' | 'money' | 'date' | 'actions';
60
+ /** Heading for screen readers only, e.g. for an actions column. (It does not hide the column: see `visible`.) */
31
61
  hidden?: boolean;
62
+ /** `false` leaves the column out (since 1.6). The column picker lists it, unticked, so the merchant can show it. */
63
+ visible?: boolean;
64
+ /** `low`: with `mobile="priority"`, hidden when the table is 640px wide or less (since 1.6). */
65
+ priority?: 'high' | 'low';
66
+ /** The column that names each row: its cells are row headers and card titles. Default: the first column. */
67
+ primary?: boolean;
68
+ /** Starting width in pixels (since 1.6). Text that doesn't fit ends in "…". Without it, columns size to their content. */
69
+ width?: number;
70
+ /** With `type: 'actions'`: the buttons in every row (since 1.6). A row can list its own as an array under the column's key. */
71
+ actions?: DataTableAction[];
32
72
  }
33
73
  /** A row: column keys to cell values. Values are shown as text, never as HTML. */
34
74
  export type DataTableRow = Record<string, unknown>;
35
75
  export type SortDirection = 'ascending' | 'descending';
36
76
  /**
37
- * A data table for reports and read-only lists: sales by day, stock by location, order lines.
77
+ * A data table for reports and lists of records: sales by day, stock by location, accounts, tasks.
38
78
  * A real `<table>` with column headings, sortable columns, a totals row, a sticky header and first column,
39
- * loading rows and an empty state. For lists merchants select and act on, use Resource list.
79
+ * loading rows and an empty state. For lists merchants select and act on in bulk, use Resource list.
80
+ *
81
+ * The table standard (since 1.6): a 40px heading row in 12px semibold; 48px body rows (`density="compact"`: 40px;
82
+ * at least 44px on touch screens) with cells padded 12px across and 10px down in 13px text; numbers, money and
83
+ * actions right-aligned; numbers and dates never wrap; text ends in "…" with the full value on hover.
84
+ * Set `data-cm-density="compact"` on any ancestor to make every table and list in it compact.
85
+ *
86
+ * On phones each table picks a strategy with `mobile` (judged by the table's own width, 640px or less):
87
+ * `scroll` (default) keeps the columns and shows that it scrolls sideways; `cards` turns each row into a card;
88
+ * `priority` hides `priority: 'low'` columns and adds "View all fields" to each row.
40
89
  *
41
90
  * Give it `columns` and `rows`, or write a native `<table>` inside it (for server-rendered pages): that
42
91
  * table is styled to match. Mark a heading `<th data-sort="text|numeric|money|date">` to make its column sortable
@@ -47,7 +96,18 @@ export type SortDirection = 'ascending' | 'descending';
47
96
  * @slot empty - Shown instead of the rows when `rows` is empty, e.g. a `cm-empty-state`.
48
97
  * @fires cm-sort - `detail: { key, direction }` when a sortable heading is clicked. Cancelable: call
49
98
  * `preventDefault()` to stop the table sorting itself. With `sort-mode="manual"` it never sorts itself.
50
- * @cssprop --cm-data-table-max-height - With `sticky-header`, the table scrolls inside this height. Default `none`.
99
+ * @fires cm-row-action - `detail: { action, row, index }` when a button in an `actions` column is pressed: the action's
100
+ * `value`, the row object and its index in `rows`.
101
+ * @fires cm-column-resize - `detail: { key, width }` when the merchant resizes a column (`resizable`), in pixels. Store
102
+ * it and pass it back as the column's `width`.
103
+ * @fires cm-columns-change - `detail: { key, visible, columns }` when the merchant shows or hides a column with the column
104
+ * picker. `columns` is the new array (the table has already switched to it); store it to keep the choice.
105
+ * @cssprop --cm-data-table-max-height - With `sticky-header`, the table scrolls inside this height. Default `none`: the
106
+ * heading row sticks to the page or to the nearest scrolling box instead.
107
+ * @cssprop --cm-data-table-sticky-top - With `sticky-header`, how far from the top the heading row sticks, e.g. under a
108
+ * sticky app header. Default `0px`.
109
+ * @cssprop --cm-data-table-cell-max-width - Widest a text column grows before its text ends in "…". Default `320px` (and never more than 45% of the table's width).
110
+ * @cssprop --cm-table-row-height - Height of body rows. Set by `density`/`data-cm-density`: 48px, compact 40px.
51
111
  */
52
112
  export declare class CmDataTable extends CmLocalizedElement {
53
113
  #private;
@@ -95,12 +155,43 @@ export declare class CmDataTable extends CmLocalizedElement {
95
155
  type: NumberConstructor;
96
156
  attribute: string;
97
157
  };
158
+ density: {
159
+ reflect: boolean;
160
+ };
161
+ mobile: {
162
+ reflect: boolean;
163
+ };
164
+ rowActions: {
165
+ attribute: string;
166
+ reflect: boolean;
167
+ };
168
+ resizable: {
169
+ type: BooleanConstructor;
170
+ reflect: boolean;
171
+ };
172
+ columnPicker: {
173
+ type: BooleanConstructor;
174
+ attribute: string;
175
+ reflect: boolean;
176
+ };
98
177
  _light: {
99
178
  state: boolean;
100
179
  };
101
180
  _announce: {
102
181
  state: boolean;
103
182
  };
183
+ _widths: {
184
+ state: boolean;
185
+ };
186
+ _expanded: {
187
+ state: boolean;
188
+ };
189
+ _picker: {
190
+ state: boolean;
191
+ };
192
+ _overflows: {
193
+ state: boolean;
194
+ };
104
195
  };
105
196
  /** The columns, in order. */
106
197
  columns: DataTableColumn[];
@@ -118,7 +209,10 @@ export declare class CmDataTable extends CmLocalizedElement {
118
209
  direction: SortDirection;
119
210
  /** `auto`: the table sorts its own rows. `manual`: it only fires `cm-sort` (sort on your server, then set `rows`). */
120
211
  sortMode: 'auto' | 'manual';
121
- /** Keeps the heading row visible while the table scrolls inside `--cm-data-table-max-height`. */
212
+ /**
213
+ * Keeps the heading row in view while the rows scroll: inside `--cm-data-table-max-height` when you set one,
214
+ * otherwise under the top of the page or of the nearest scrolling box (plus `--cm-data-table-sticky-top`).
215
+ */
122
216
  stickyHeader: boolean;
123
217
  /** Keeps the first column visible while the table scrolls sideways (on narrow screens). */
124
218
  stickyFirstColumn: boolean;
@@ -126,13 +220,37 @@ export declare class CmDataTable extends CmLocalizedElement {
126
220
  loading: boolean;
127
221
  /** How many placeholder rows `loading` shows. */
128
222
  loadingRows: number;
223
+ /**
224
+ * Row height (since 1.6): `comfortable` 48px rows or `compact` 40px rows. Unset: the nearest `data-cm-density` on an
225
+ * ancestor, else comfortable. On touch screens rows are at least 44px tall either way.
226
+ */
227
+ density?: 'comfortable' | 'compact';
228
+ /**
229
+ * What the table does when it is 640px wide or less (since 1.6): `scroll` keeps every column, scrolls sideways and
230
+ * says so ("Scroll for more", faded edges); `cards` shows each row as a card of label and value pairs with the primary
231
+ * column as its title and the actions at the bottom; `priority` hides `priority: 'low'` columns and gives each row a
232
+ * "View all fields" button that shows them. Pick one per table: see the "Tables on phones" pattern.
233
+ */
234
+ mobile: 'scroll' | 'cards' | 'priority';
235
+ /** `hover` (default): an `actions` column's buttons appear when the row is hovered or has focus (always on touch screens). `always`: always shown. */
236
+ rowActions: 'hover' | 'always';
237
+ /** Adds a resize handle to each heading: drag it, or focus it and press the left and right arrow keys (16px a press). */
238
+ resizable: boolean;
239
+ /** Adds a "Columns" button above the table that shows and hides columns. */
240
+ columnPicker: boolean;
129
241
  _light: boolean;
130
242
  _announce: string;
243
+ _widths: Record<string, number>;
244
+ _expanded: Set<DataTableRow>;
245
+ _picker: boolean;
246
+ _overflows: boolean;
131
247
  static styles: import("lit").CSSResult[];
132
248
  connectedCallback(): void;
133
249
  disconnectedCallback(): void;
134
250
  /** The rows in display order: sorted when `sort` is set and `sort-mode` is `auto`. */
135
251
  get sortedRows(): DataTableRow[];
252
+ /** The columns shown: every column whose `visible` isn't `false`. */
253
+ get visibleColumns(): DataTableColumn[];
136
254
  updated(changed: Map<string, unknown>): void;
137
255
  render(): import("lit-html").TemplateResult<1>;
138
256
  }