@commmerce/ui 1.1.1 → 1.3.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 (45) hide show
  1. package/dist/calendar.d.ts +38 -0
  2. package/dist/calendar.js +109 -0
  3. package/dist/cdn.js +1010 -533
  4. package/dist/components/board.d.ts +338 -0
  5. package/dist/components/board.js +1017 -0
  6. package/dist/components/button.d.ts +10 -0
  7. package/dist/components/button.js +25 -0
  8. package/dist/components/card.d.ts +7 -1
  9. package/dist/components/card.js +58 -7
  10. package/dist/components/color-field.d.ts +153 -0
  11. package/dist/components/color-field.js +369 -0
  12. package/dist/components/combobox.d.ts +17 -4
  13. package/dist/components/combobox.js +55 -23
  14. package/dist/components/date-picker.d.ts +49 -5
  15. package/dist/components/date-picker.js +211 -48
  16. package/dist/components/empty-state.d.ts +19 -4
  17. package/dist/components/empty-state.js +59 -5
  18. package/dist/components/file-upload.d.ts +33 -0
  19. package/dist/components/file-upload.js +80 -9
  20. package/dist/components/global-search.js +2 -7
  21. package/dist/components/metric.d.ts +97 -0
  22. package/dist/components/metric.js +168 -0
  23. package/dist/components/nested-list.d.ts +33 -1
  24. package/dist/components/nested-list.js +197 -18
  25. package/dist/components/option-group.d.ts +15 -6
  26. package/dist/components/option-group.js +25 -6
  27. package/dist/components/page-header.js +3 -2
  28. package/dist/components/resource-list.d.ts +14 -2
  29. package/dist/components/resource-list.js +48 -6
  30. package/dist/components/select.d.ts +20 -3
  31. package/dist/components/select.js +35 -11
  32. package/dist/components/table-header.d.ts +14 -0
  33. package/dist/components/table-header.js +21 -0
  34. package/dist/components/text-field.d.ts +36 -2
  35. package/dist/components/text-field.js +86 -14
  36. package/dist/components/timeline.d.ts +210 -0
  37. package/dist/components/timeline.js +380 -0
  38. package/dist/custom-elements.json +9371 -4963
  39. package/dist/index.d.ts +10 -0
  40. package/dist/index.js +5 -0
  41. package/dist/move-model.d.ts +93 -0
  42. package/dist/move-model.js +169 -0
  43. package/dist/popover.d.ts +24 -0
  44. package/dist/popover.js +59 -0
  45. package/package.json +3 -3
@@ -3,17 +3,20 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
3
3
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
4
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
5
  };
6
- var _CmEmptyState_instances, _CmEmptyState_slot;
6
+ var _CmEmptyState_instances, _CmEmptyState_slot, _CmEmptyState_textAction, _CmEmptyState_renderInline;
7
7
  import { LitElement, html, css, nothing } from 'lit';
8
8
  import { base, define } from '../base.js';
9
9
  import './icon.js';
10
10
  /**
11
11
  * Shown in place of a list or page when there is nothing to show yet, with the next step to take.
12
12
  * A soft circle holds an illustration (an image, your own markup or one of the system icons).
13
+ * `size="inline"` is the compact form for an empty list inside a card or table: one or two left-aligned lines,
14
+ * an optional small icon and an optional text action, with no circle.
13
15
  * @element cm-empty-state
14
- * @slot - Optional supporting text under the heading.
15
- * @slot image - Your own illustration, drawn inside the circle. Decorative: give it `alt=""`.
16
+ * @slot - Optional supporting text under the heading (inline: after it, on the same line).
17
+ * @slot image - Your own illustration, drawn inside the circle. Decorative: give it `alt=""`. Inline: 20px.
16
18
  * @slot actions - The primary action (usually one primary `cm-button`), plus an optional link.
19
+ * @fires cm-action - The text action (`action`) was pressed. Not fired when it has `action-href` (it is then a link).
17
20
  */
18
21
  export class CmEmptyState extends LitElement {
19
22
  constructor() {
@@ -27,8 +30,16 @@ export class CmEmptyState extends LitElement {
27
30
  this.icon = 'box';
28
31
  /** Heading level, so the page outline stays correct. Default 2. */
29
32
  this.headingLevel = 2;
30
- /** `large` (250px circle, page-level) or `small` (200px circle, inside a card or on mobile). */
33
+ /**
34
+ * `large` (250px circle, page-level), `small` (200px circle, inside a card or on mobile) or `inline`
35
+ * (since 1.2: no circle, a 20px icon, heading and text on one or two left-aligned lines; for an empty list
36
+ * inside a card, panel or table). Inline shows the `icon` (default `box`); set `icon=""` for text only.
37
+ */
31
38
  this.size = 'large';
39
+ /** Text of one action drawn as a text button ("Add task", "View all"), after the text. Meant for `size="inline"`; larger sizes put a `cm-button` in the `actions` slot. Fires `cm-action`. Since 1.2. */
40
+ this.action = '';
41
+ /** Makes the text action a link to this URL instead of a button. Since 1.2. */
42
+ this.actionHref = '';
32
43
  /** @internal */
33
44
  this.hasText = false;
34
45
  /** @internal */
@@ -38,6 +49,8 @@ export class CmEmptyState extends LitElement {
38
49
  }
39
50
  render() {
40
51
  const level = Math.min(6, Math.max(2, this.headingLevel || 2));
52
+ if (this.size === 'inline')
53
+ return __classPrivateFieldGet(this, _CmEmptyState_instances, "m", _CmEmptyState_renderInline).call(this, level);
41
54
  const fallback = this.image
42
55
  ? html `<img src=${this.image} alt="" part="image">`
43
56
  : this.icon ? html `<cm-icon name=${this.icon} size="96"></cm-icon>` : nothing;
@@ -47,7 +60,7 @@ export class CmEmptyState extends LitElement {
47
60
  </div>
48
61
  <div class="title" role="heading" aria-level=${level} part="heading">${this.heading}</div>
49
62
  <div class="text" ?hidden=${!this.hasText}><slot @slotchange=${(e) => __classPrivateFieldGet(this, _CmEmptyState_instances, "m", _CmEmptyState_slot).call(this, e, 'hasText')}></slot></div>
50
- <div class="actions" ?hidden=${!this.hasActions}><slot name="actions" @slotchange=${(e) => __classPrivateFieldGet(this, _CmEmptyState_instances, "m", _CmEmptyState_slot).call(this, e, 'hasActions')}></slot></div>
63
+ <div class="actions" ?hidden=${!this.hasActions}><slot name="actions" @slotchange=${(e) => __classPrivateFieldGet(this, _CmEmptyState_instances, "m", _CmEmptyState_slot).call(this, e, 'hasActions')}></slot></div>${this.action ? html `<div class="actions">${__classPrivateFieldGet(this, _CmEmptyState_instances, "m", _CmEmptyState_textAction).call(this)}</div>` : nothing}
51
64
  </div>`;
52
65
  }
53
66
  }
@@ -55,6 +68,27 @@ _CmEmptyState_instances = new WeakSet(), _CmEmptyState_slot = function _CmEmptyS
55
68
  const s = e.target;
56
69
  this[key] = s.assignedNodes({ flatten: true }).some((n) => n.nodeType === 1 || n.textContent.trim());
57
70
  this.requestUpdate();
71
+ }, _CmEmptyState_textAction = function _CmEmptyState_textAction() {
72
+ if (!this.action)
73
+ return nothing;
74
+ return this.actionHref
75
+ ? html `<a class="text-action" part="action" href=${this.actionHref}>${this.action}</a>`
76
+ : html `<button class="text-action" type="button" part="action"
77
+ @click=${() => this.dispatchEvent(new CustomEvent('cm-action', { bubbles: true, composed: true }))}>${this.action}</button>`;
78
+ }, _CmEmptyState_renderInline = function _CmEmptyState_renderInline(level) {
79
+ const fallback = this.image
80
+ ? html `<img src=${this.image} alt="" part="image">`
81
+ : this.icon ? html `<cm-icon name=${this.icon} size="20"></cm-icon>` : nothing;
82
+ return html `<div class="wrap inline" part="empty-state">
83
+ <span class="icon" part="circle" aria-hidden=${this.hasImage ? nothing : 'true'} ?hidden=${!this.hasImage && !this.image && !this.icon}>
84
+ <slot name="image" @slotchange=${(e) => __classPrivateFieldGet(this, _CmEmptyState_instances, "m", _CmEmptyState_slot).call(this, e, 'hasImage')}>${fallback}</slot>
85
+ </span>
86
+ <div class="line">
87
+ <div class="title" role="heading" aria-level=${level} part="heading">${this.heading}</div>
88
+ <span class="text" ?hidden=${!this.hasText}> <slot @slotchange=${(e) => __classPrivateFieldGet(this, _CmEmptyState_instances, "m", _CmEmptyState_slot).call(this, e, 'hasText')}></slot></span>${__classPrivateFieldGet(this, _CmEmptyState_instances, "m", _CmEmptyState_textAction).call(this)}
89
+ <span class="actions" ?hidden=${!this.hasActions}><slot name="actions" @slotchange=${(e) => __classPrivateFieldGet(this, _CmEmptyState_instances, "m", _CmEmptyState_slot).call(this, e, 'hasActions')}></slot></span>
90
+ </div>
91
+ </div>`;
58
92
  };
59
93
  CmEmptyState.properties = {
60
94
  heading: {},
@@ -62,6 +96,8 @@ CmEmptyState.properties = {
62
96
  icon: {},
63
97
  headingLevel: { type: Number, attribute: 'heading-level' },
64
98
  size: { reflect: true },
99
+ action: {},
100
+ actionHref: { attribute: 'action-href' },
65
101
  };
66
102
  CmEmptyState.styles = [
67
103
  base,
@@ -84,6 +120,24 @@ CmEmptyState.styles = [
84
120
  :host([size='small']) .circle { width: 200px; height: 200px; }
85
121
  :host([size='small']) .title { margin-top: 30px; font-size: 14px; }
86
122
  :host([size='small']) .actions { gap: var(--cm-space-10); }
123
+ /* Inline (1.2): a line of text with an optional 20px icon, no circle, no extra height. */
124
+ .inline { flex-direction: row; align-items: flex-start; gap: var(--cm-space-10); padding: 0; text-align: start; font-size: 14px; line-height: 20px; }
125
+ .inline .icon { display: inline-flex; flex: none; width: 20px; height: 20px; overflow: hidden; color: var(--cm-icon-default); }
126
+ .inline .icon img, .inline ::slotted([slot='image']) { width: 20px; height: 20px; max-width: none; max-height: none; object-fit: contain; }
127
+ .inline .line { min-width: 0; text-align: start; }
128
+ .inline .title { display: inline; margin: 0; font-size: inherit; font-weight: 500; color: var(--cm-text-default); }
129
+ .inline .text { display: inline; margin: 0; font-size: inherit; color: var(--cm-text-tertiary); }
130
+ .inline .actions { display: inline-flex; vertical-align: middle; margin: 0; margin-inline-start: var(--cm-space-10); }
131
+ .inline .text[hidden], .inline .actions[hidden], .inline .icon[hidden] { display: none; }
132
+ .text-action {
133
+ display: inline-flex; align-items: center; min-height: 24px; vertical-align: middle;
134
+ margin: -2px 0; padding: 0 2px; border: 0; background: none; cursor: pointer;
135
+ font: inherit; font-weight: 500; color: var(--cm-text-default);
136
+ text-decoration: underline; text-underline-offset: 3px; border-radius: var(--cm-radius-xs);
137
+ }
138
+ .text-action:hover { text-decoration-thickness: 2px; }
139
+ .text-action:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
140
+ .inline .text-action { display: inline; min-height: 0; vertical-align: baseline; margin: 0; margin-inline-start: var(--cm-space-10); padding-block: 2px; }
87
141
  @media (max-width: 640px) {
88
142
  .circle { width: 200px; height: 200px; }
89
143
  .title { margin-top: 30px; font-size: 14px; }
@@ -17,6 +17,16 @@ declare const strings: {
17
17
  wrongType: string;
18
18
  tooLarge: string;
19
19
  tooMany: string;
20
+ /** `variant="photo"`: text of the empty tile when there is no `label`. */
21
+ takePhoto: string;
22
+ /** `variant="photo"`: visible text of the buttons under a taken photo. */
23
+ retake: string;
24
+ removePhoto: string;
25
+ /** `variant="photo"`: accessible names of those buttons. `{name}` is the `label`, or the `photo` string without one. */
26
+ retakeName: string;
27
+ removeName: string;
28
+ /** `variant="photo"`: what the photo is called in button names when there is no `label`. */
29
+ photo: string;
20
30
  };
21
31
  declare module '../localize.js' {
22
32
  interface CmStrings {
@@ -27,6 +37,10 @@ declare module '../localize.js' {
27
37
  * Drop zone for choosing files, with thumbnails of chosen images and a remove button on each.
28
38
  * Wraps a native file input, so it works with the keyboard, screen readers and drag and drop.
29
39
  * Participates in native forms (submit with `enctype="multipart/form-data"`).
40
+ *
41
+ * `variant="photo"` (since 1.3) is the phone capture pattern: one tile with a camera icon and the label; once a photo
42
+ * is taken or chosen, the tile shows it with Retake and Remove buttons. Add `capture="environment"` to open the
43
+ * back camera directly on phones.
30
44
  * @element cm-file-upload
31
45
  * @fires change - When files are added or removed. Read `files`.
32
46
  * @fires cm-reject - When chosen files are refused for type or size. `detail.files` lists them.
@@ -75,6 +89,12 @@ export declare class CmFileUpload extends CmLocalizedElement {
75
89
  files: {
76
90
  attribute: boolean;
77
91
  };
92
+ variant: {
93
+ reflect: boolean;
94
+ };
95
+ capture: {
96
+ reflect: boolean;
97
+ };
78
98
  _rejected: {
79
99
  state: boolean;
80
100
  };
@@ -103,6 +123,19 @@ export declare class CmFileUpload extends CmLocalizedElement {
103
123
  error: string;
104
124
  /** The chosen files. Set it to `[]` to clear. */
105
125
  files: File[];
126
+ /**
127
+ * `photo` (since 1.3): a single-photo tile for phones. It shows a camera icon and the `label` (or the prompt
128
+ * "Take a photo" without one); after a photo is taken it fills the tile, with Retake and Remove buttons under it.
129
+ * One file only (`multiple` is ignored); `accept` defaults to `image/*`. Size the tile with CSS on the element;
130
+ * it is 4:3 (change it with `::part(photo)`, e.g. `aspect-ratio: 16 / 10` for a visiting card).
131
+ */
132
+ variant?: 'photo';
133
+ /**
134
+ * Asks phones to open the camera instead of the file chooser, as `capture` on a native input (since 1.3):
135
+ * `environment` for the back camera (a shop front, a document), `user` for the front camera (a selfie).
136
+ * Desktop browsers ignore it and show the file chooser.
137
+ */
138
+ capture?: 'environment' | 'user';
106
139
  _rejected: string;
107
140
  static styles: import("lit").CSSResult[];
108
141
  get form(): HTMLFormElement | null;
@@ -3,7 +3,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
3
3
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
4
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
5
  };
6
- var _CmFileUpload_instances, _CmFileUpload_internals, _CmFileUpload_id, _CmFileUpload_urls, _CmFileUpload_size, _CmFileUpload_url, _CmFileUpload_onInputChange, _CmFileUpload_setOver, _CmFileUpload_zone;
6
+ var _CmFileUpload_instances, _CmFileUpload_internals, _CmFileUpload_id, _CmFileUpload_urls, _CmFileUpload_photo_get, _CmFileUpload_accept_get, _CmFileUpload_multiple_get, _CmFileUpload_size, _CmFileUpload_url, _CmFileUpload_onInputChange, _CmFileUpload_setOver, _CmFileUpload_zone, _CmFileUpload_retake, _CmFileUpload_renderPhoto;
7
7
  import { LitElement, html, css, nothing } from 'lit';
8
8
  import { base, define, nextId } from '../base.js';
9
9
  import { CmLocalizedElement, defineStrings } from '../localize.js';
@@ -25,6 +25,16 @@ const strings = defineStrings('fileUpload', {
25
25
  wrongType: '{name} is not an allowed file type',
26
26
  tooLarge: '{name} is larger than {size}',
27
27
  tooMany: 'You can add up to {max} files',
28
+ /** `variant="photo"`: text of the empty tile when there is no `label`. */
29
+ takePhoto: 'Take a photo',
30
+ /** `variant="photo"`: visible text of the buttons under a taken photo. */
31
+ retake: 'Retake',
32
+ removePhoto: 'Remove',
33
+ /** `variant="photo"`: accessible names of those buttons. `{name}` is the `label`, or the `photo` string without one. */
34
+ retakeName: 'Retake {name}',
35
+ removeName: 'Remove {name}',
36
+ /** `variant="photo"`: what the photo is called in button names when there is no `label`. */
37
+ photo: 'photo',
28
38
  });
29
39
  /** Does `file` match an `accept` list such as `image/*,.pdf`? */
30
40
  function accepts(file, accept) {
@@ -37,6 +47,10 @@ function accepts(file, accept) {
37
47
  * Drop zone for choosing files, with thumbnails of chosen images and a remove button on each.
38
48
  * Wraps a native file input, so it works with the keyboard, screen readers and drag and drop.
39
49
  * Participates in native forms (submit with `enctype="multipart/form-data"`).
50
+ *
51
+ * `variant="photo"` (since 1.3) is the phone capture pattern: one tile with a camera icon and the label; once a photo
52
+ * is taken or chosen, the tile shows it with Retake and Remove buttons. Add `capture="environment"` to open the
53
+ * back camera directly on phones.
40
54
  * @element cm-file-upload
41
55
  * @fires change - When files are added or removed. Read `files`.
42
56
  * @fires cm-reject - When chosen files are refused for type or size. `detail.files` lists them.
@@ -97,7 +111,8 @@ export class CmFileUpload extends CmLocalizedElement {
97
111
  for (const f of this.files)
98
112
  data.append(this.name || 'file', f);
99
113
  __classPrivateFieldGet(this, _CmFileUpload_internals, "f").setFormValue(this.files.length ? data : null);
100
- const input = this.renderRoot.querySelector('input') ?? undefined;
114
+ // The photo tile keeps a hidden input for Retake; with a photo shown, point validation at the Retake button.
115
+ const input = (__classPrivateFieldGet(this, _CmFileUpload_instances, "a", _CmFileUpload_photo_get) && this.files.length ? this.renderRoot.querySelector('.retake') : this.renderRoot.querySelector('input')) ?? undefined;
101
116
  const msg = this.error || this._rejected;
102
117
  if (msg)
103
118
  __classPrivateFieldGet(this, _CmFileUpload_internals, "f").setValidity({ customError: true }, msg, input);
@@ -111,7 +126,7 @@ export class CmFileUpload extends CmLocalizedElement {
111
126
  const incoming = [...list];
112
127
  const ok = [], refused = [], reasons = [];
113
128
  for (const f of incoming) {
114
- if (!accepts(f, this.accept)) {
129
+ if (!accepts(f, __classPrivateFieldGet(this, _CmFileUpload_instances, "a", _CmFileUpload_accept_get))) {
115
130
  refused.push(f);
116
131
  reasons.push(this.t('wrongType', { name: f.name }));
117
132
  }
@@ -122,10 +137,10 @@ export class CmFileUpload extends CmLocalizedElement {
122
137
  else
123
138
  ok.push(f);
124
139
  }
125
- let next = this.multiple ? [...this.files, ...ok] : ok.slice(-1);
126
- if (!this.multiple && !ok.length)
140
+ let next = __classPrivateFieldGet(this, _CmFileUpload_instances, "a", _CmFileUpload_multiple_get) ? [...this.files, ...ok] : ok.slice(-1);
141
+ if (!__classPrivateFieldGet(this, _CmFileUpload_instances, "a", _CmFileUpload_multiple_get) && !ok.length)
127
142
  next = this.files;
128
- if (this.multiple && this.maxFiles && next.length > this.maxFiles) {
143
+ if (__classPrivateFieldGet(this, _CmFileUpload_instances, "a", _CmFileUpload_multiple_get) && this.maxFiles && next.length > this.maxFiles) {
129
144
  refused.push(...next.slice(this.maxFiles));
130
145
  reasons.push(this.t('tooMany', { max: this.maxFiles }));
131
146
  next = next.slice(0, this.maxFiles);
@@ -148,6 +163,8 @@ export class CmFileUpload extends CmLocalizedElement {
148
163
  this.updateComplete.then(() => this.renderRoot.querySelector('input')?.focus());
149
164
  }
150
165
  render() {
166
+ if (__classPrivateFieldGet(this, _CmFileUpload_instances, "a", _CmFileUpload_photo_get))
167
+ return __classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_renderPhoto).call(this);
151
168
  const msg = this.error || this._rejected;
152
169
  const showZone = !this.files.length || this.multiple;
153
170
  const tile = this.files.length > 0;
@@ -173,7 +190,7 @@ export class CmFileUpload extends CmLocalizedElement {
173
190
  `;
174
191
  }
175
192
  }
176
- _CmFileUpload_internals = new WeakMap(), _CmFileUpload_id = new WeakMap(), _CmFileUpload_urls = new WeakMap(), _CmFileUpload_instances = new WeakSet(), _CmFileUpload_size = function _CmFileUpload_size(n) {
193
+ _CmFileUpload_internals = new WeakMap(), _CmFileUpload_id = new WeakMap(), _CmFileUpload_urls = new WeakMap(), _CmFileUpload_instances = new WeakSet(), _CmFileUpload_photo_get = function _CmFileUpload_photo_get() { return this.variant === 'photo'; }, _CmFileUpload_accept_get = function _CmFileUpload_accept_get() { return this.accept || (__classPrivateFieldGet(this, _CmFileUpload_instances, "a", _CmFileUpload_photo_get) ? 'image/*' : ''); }, _CmFileUpload_multiple_get = function _CmFileUpload_multiple_get() { return this.multiple && !__classPrivateFieldGet(this, _CmFileUpload_instances, "a", _CmFileUpload_photo_get); }, _CmFileUpload_size = function _CmFileUpload_size(n) {
177
194
  return n >= 1024 * 1024
178
195
  ? this.t('megabytes', { size: this.formatNumber(+(n / 1024 / 1024).toFixed(1), { useGrouping: false }) })
179
196
  : this.t('kilobytes', { size: this.formatNumber(Math.max(1, Math.round(n / 1024)), { useGrouping: false }) });
@@ -193,7 +210,7 @@ _CmFileUpload_internals = new WeakMap(), _CmFileUpload_id = new WeakMap(), _CmFi
193
210
  const described = [this.hint && `${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-hint`, (this.error || this._rejected) && `${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-msg`].filter(Boolean).join(' ');
194
211
  return html `<label class="zone ${tile ? 'tile' : ''}" part="zone"
195
212
  @dragenter=${() => __classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_setOver).call(this, true)} @dragleave=${() => __classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_setOver).call(this, false)} @drop=${() => __classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_setOver).call(this, false)}>
196
- <input type="file" id=${__classPrivateFieldGet(this, _CmFileUpload_id, "f")} accept=${this.accept || nothing} ?multiple=${this.multiple} ?disabled=${this.disabled}
213
+ <input type="file" id=${__classPrivateFieldGet(this, _CmFileUpload_id, "f")} accept=${this.accept || nothing} capture=${this.capture || nothing} ?multiple=${this.multiple} ?disabled=${this.disabled}
197
214
  ?required=${this.required && !this.files.length}
198
215
  aria-labelledby=${[this.label && `${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-l`, `${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-p`].filter(Boolean).join(' ')}
199
216
  aria-describedby=${described || nothing} aria-invalid=${this.error || this._rejected ? 'true' : nothing}
@@ -201,6 +218,38 @@ _CmFileUpload_internals = new WeakMap(), _CmFileUpload_id = new WeakMap(), _CmFi
201
218
  <cm-icon name=${tile ? 'plus' : 'upload'} size=${tile ? 24 : 38}></cm-icon>
202
219
  <span id="${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-p">${tile ? this.t('addMore') : this.prompt}</span>
203
220
  </label>`;
221
+ }, _CmFileUpload_retake = function _CmFileUpload_retake() { this.renderRoot.querySelector('input[type=file]')?.click(); }, _CmFileUpload_renderPhoto = function _CmFileUpload_renderPhoto() {
222
+ const msg = this.error || this._rejected;
223
+ const f = this.files[0];
224
+ const name = this.label || this.t('photo');
225
+ const described = [this.hint && `${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-hint`, msg && `${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-msg`].filter(Boolean).join(' ');
226
+ const input = (hidden) => html `<input type="file" id=${__classPrivateFieldGet(this, _CmFileUpload_id, "f")} accept=${__classPrivateFieldGet(this, _CmFileUpload_instances, "a", _CmFileUpload_accept_get)} capture=${this.capture || nothing}
227
+ ?disabled=${this.disabled} ?required=${this.required && !f} tabindex=${hidden ? '-1' : nothing} aria-hidden=${hidden ? 'true' : nothing}
228
+ ?hidden=${hidden} aria-labelledby=${hidden ? nothing : `${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-p`} aria-describedby=${(!hidden && described) || nothing} aria-invalid=${msg ? 'true' : nothing}
229
+ @change=${__classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_onInputChange)} @cancel=${(e) => e.stopPropagation()} />`;
230
+ const hint = this.hint ? html `<span class="hint" id="${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-hint">${this.hint}</span>` : nothing;
231
+ return html `
232
+ ${f
233
+ ? html `<div class="shot" part="photo">
234
+ ${f.type.startsWith('image/')
235
+ ? html `<img src=${__classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_url).call(this, f)} alt=${name} />`
236
+ : html `<div class="doc"><cm-icon name="book" size="24"></cm-icon><span class="name">${f.name}</span><span class="size">${__classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_size).call(this, f.size)}</span></div>`}
237
+ </div>
238
+ <p class="caption" aria-hidden="true">${this.label}</p>
239
+ ${input(true)}
240
+ ${this.disabled ? nothing : html `<div class="actions" part="actions">
241
+ <button type="button" class="action retake" aria-label=${this.t('retakeName', { name })} aria-describedby=${msg ? `${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-msg` : nothing} @click=${__classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_retake)}><cm-icon name="camera" size="16"></cm-icon>${this.t('retake')}</button>
242
+ <button type="button" class="action" aria-label=${this.t('removeName', { name })} @click=${() => this.removeFile(f)}><cm-icon name="trash" size="16"></cm-icon>${this.t('removePhoto')}</button>
243
+ </div>`}`
244
+ : html `<label class="zone photo ${msg ? 'invalid' : ''}" part="zone photo"
245
+ @dragenter=${() => __classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_setOver).call(this, true)} @dragleave=${() => __classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_setOver).call(this, false)} @drop=${() => __classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_setOver).call(this, false)}>
246
+ ${input(false)}
247
+ <cm-icon name="camera" size="32"></cm-icon>
248
+ <span class="photo-label" id="${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-p" part="label">${this.label || this.t('takePhoto')}${this.required ? html `<span class="req" aria-hidden="true">*</span>` : nothing}</span>
249
+ ${hint}
250
+ </label>`}
251
+ ${msg ? html `<p class="msg" id="${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-msg" role="alert">${msg}</p>` : nothing}
252
+ `;
204
253
  };
205
254
  CmFileUpload.formAssociated = true;
206
255
  CmFileUpload.shadowRootOptions = { ...LitElement.shadowRootOptions, delegatesFocus: true };
@@ -217,6 +266,8 @@ CmFileUpload.properties = {
217
266
  disabled: { type: Boolean, reflect: true },
218
267
  error: { reflect: true },
219
268
  files: { attribute: false },
269
+ variant: { reflect: true },
270
+ capture: { reflect: true },
220
271
  _rejected: { state: true },
221
272
  };
222
273
  CmFileUpload.styles = [
@@ -254,8 +305,28 @@ CmFileUpload.styles = [
254
305
  .msg { margin: var(--cm-space-10) 0 0; font-size: 12px; color: var(--cm-text-critical); }
255
306
  :host([disabled]) .zone { cursor: not-allowed; background: var(--cm-bg-input-filled); color: var(--cm-text-secondary); border-color: var(--cm-border-default); }
256
307
  :host([disabled]) .remove { display: none; }
308
+ /* variant="photo" (1.3) */
309
+ .zone.photo { min-height: 0; aspect-ratio: 4 / 3; border-radius: var(--cm-radius-md); font-size: 14px; }
310
+ .zone.photo.invalid { border-color: var(--cm-border-critical); }
311
+ .photo-label { font-weight: 500; overflow-wrap: anywhere; }
312
+ .shot {
313
+ aspect-ratio: 4 / 3; border-radius: var(--cm-radius-md); overflow: hidden;
314
+ background: var(--cm-bg-inset); border: var(--cm-border-1) solid var(--cm-border-card);
315
+ }
316
+ .shot img { width: 100%; height: 100%; object-fit: cover; display: block; }
317
+ .caption { margin: var(--cm-space-10) 0 0; font-size: 14px; font-weight: 500; overflow-wrap: anywhere; }
318
+ .caption:empty { display: none; }
319
+ .actions { display: flex; flex-wrap: wrap; gap: var(--cm-space-10); margin-top: var(--cm-space-10); }
320
+ .action {
321
+ display: inline-flex; align-items: center; justify-content: center; gap: 6px; flex: 1 1 0; min-width: max-content;
322
+ min-height: 40px; padding: 0 var(--cm-space-15); font: inherit; font-size: 14px; font-weight: 500; cursor: pointer;
323
+ background: var(--cm-bg-hover); color: var(--cm-text-default);
324
+ border: var(--cm-border-1) solid var(--cm-border-strong); border-radius: var(--cm-radius-sm);
325
+ }
326
+ .action:hover { background: var(--cm-bg-surface); }
327
+ .action:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
257
328
  @media (max-width: 640px) {
258
- .zone:not(.tile) { min-height: 100px; font-size: 14px; }
329
+ .zone:not(.tile):not(.photo) { min-height: 100px; font-size: 14px; }
259
330
  .label { font-size: var(--cm-type-heading-sm-resp-size); }
260
331
  }
261
332
  `,
@@ -14,7 +14,7 @@ import { LitElement, html, css, nothing } from 'lit';
14
14
  import { live } from 'lit/directives/live.js';
15
15
  import { base, define, nextId } from '../base.js';
16
16
  import { CmLocalizedElement, defineStrings } from '../localize.js';
17
- import { popoverStyles, closeOnOutsidePointer } from '../popover.js';
17
+ import { popoverStyles, groupStyles, closeOnOutsidePointer } from '../popover.js';
18
18
  import './icon.js';
19
19
  import './spinner.js';
20
20
  const strings = defineStrings('globalSearch', {
@@ -246,6 +246,7 @@ CmGlobalSearch.properties = {
246
246
  CmGlobalSearch.styles = [
247
247
  base,
248
248
  popoverStyles,
249
+ groupStyles,
249
250
  css `
250
251
  :host { display: block; position: relative; }
251
252
  .wrap { position: relative; }
@@ -281,12 +282,6 @@ CmGlobalSearch.styles = [
281
282
  }
282
283
  [role='listbox'] { padding-block: 6px; }
283
284
  [role='listbox'][hidden] { display: none; }
284
- [role='group'] + [role='group'] { margin-block-start: 6px; padding-block-start: 6px; border-top: var(--cm-border-1) solid var(--cm-border-default); }
285
- .gh {
286
- display: flex; align-items: baseline; gap: var(--cm-space-10); padding: 6px var(--cm-space-20) 2px;
287
- font-size: 12px; line-height: 16px; font-weight: 600; color: var(--cm-text-default);
288
- }
289
- .gh .count { font-weight: 400; color: var(--cm-text-tertiary); }
290
285
  [role='option'] {
291
286
  display: flex; align-items: center; gap: var(--cm-space-10); min-height: 40px; padding: 6px var(--cm-space-20);
292
287
  font-size: 14px; line-height: 20px; color: var(--cm-text-default); text-decoration: none; cursor: pointer;
@@ -0,0 +1,97 @@
1
+ import { CmLocalizedElement } from '../localize.js';
2
+ import './icon.js';
3
+ import './skeleton.js';
4
+ declare const strings: {
5
+ /** Read for a rising change. `{change}` is the `change` text, e.g. "+12%". */
6
+ up: string;
7
+ /** Read for a falling change. */
8
+ down: string;
9
+ /** Read for a change that is level. */
10
+ flat: string;
11
+ /** Added when the change is good news (`trend-sentiment`). `{trend}` is the text above. */
12
+ good: string;
13
+ /** Added when the change is bad news. */
14
+ bad: string;
15
+ /** Announced (politely) while the figure loads. */
16
+ loadingValue: string;
17
+ };
18
+ declare module '../localize.js' {
19
+ interface CmStrings {
20
+ metric: typeof strings;
21
+ }
22
+ }
23
+ export type MetricTrend = 'up' | 'down' | 'flat';
24
+ export type MetricSentiment = 'auto' | 'positive' | 'negative' | 'neutral';
25
+ /**
26
+ * One number with its name, for totals and KPIs: "SMB leads 1,240". A large figure in tabular numerals, an optional
27
+ * hint line ("2 past demos need a result") and an optional change ("+12%" with an arrow, coloured by whether it is
28
+ * good news). With `href` the whole tile is one link, e.g. to the list behind the number. Put a row of them in
29
+ * `cm-grid`.
30
+ * @element cm-metric
31
+ * @slot hint - A hint with markup (e.g. a bold count), used instead of `hint`. No links or buttons: with `href` the whole tile is already one link.
32
+ */
33
+ export declare class CmMetric extends CmLocalizedElement {
34
+ static properties: {
35
+ label: {};
36
+ value: {
37
+ converter: {
38
+ fromAttribute: (v: string | null) => string | number;
39
+ toAttribute: (v: unknown) => string | null | undefined;
40
+ };
41
+ };
42
+ hint: {};
43
+ change: {};
44
+ trend: {
45
+ reflect: boolean;
46
+ };
47
+ trendSentiment: {
48
+ attribute: string;
49
+ reflect: boolean;
50
+ };
51
+ href: {};
52
+ loading: {
53
+ type: BooleanConstructor;
54
+ reflect: boolean;
55
+ };
56
+ _hasHint: {
57
+ state: boolean;
58
+ };
59
+ };
60
+ /** What is counted, e.g. "SMB leads". Two to four words. */
61
+ label: string;
62
+ /**
63
+ * The figure. A number (or a plain number in the attribute, `value="1240"`) is formatted for the locale:
64
+ * "1,240", and lakh grouping "12,40,000" in `en-IN`. Any other text ("Rs. 2.4 L", "3 of 5") is shown as given.
65
+ */
66
+ value: number | string;
67
+ /** One line under the figure in a quieter colour, e.g. "2 past demos need a result". */
68
+ hint: string;
69
+ /** The change to show, written as you want it read, e.g. "+12%" or "-3 vs last week". */
70
+ change: string;
71
+ /** Direction of `change`: `up`, `down` or `flat`. Adds an arrow and says the direction to screen readers. */
72
+ trend?: MetricTrend;
73
+ /**
74
+ * Whether the change is good news. `auto` (default): up is positive (green), down is negative (red), flat is
75
+ * neutral. Set `negative` when up is bad (more refunds, more overdue tasks), `positive` when down is good.
76
+ */
77
+ trendSentiment: MetricSentiment;
78
+ /** Makes the whole tile one link, named by the label and figure, e.g. to the list behind the number. */
79
+ href: string;
80
+ /** Shows a placeholder instead of the figure and announces "Loading <label>" politely. */
81
+ loading: boolean;
82
+ private _hasHint;
83
+ static styles: import("lit").CSSResult[];
84
+ connectedCallback(): void;
85
+ /** The figure as shown: a number formatted for the locale, any other text as given. */
86
+ private figure;
87
+ private sentiment;
88
+ private renderChange;
89
+ render(): import("lit-html").TemplateResult<1>;
90
+ private onHintSlot;
91
+ }
92
+ declare global {
93
+ interface HTMLElementTagNameMap {
94
+ 'cm-metric': CmMetric;
95
+ }
96
+ }
97
+ export {};