@redvars/peacock 4.5.0 → 4.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.
- package/dist/{BaseField-BbOj212R.js → BaseField-DOCmylob.js} +16 -3
- package/dist/BaseField-DOCmylob.js.map +1 -0
- package/dist/accordion.js +1 -1
- package/dist/activation-gate-D4IpmwyD.js +23 -0
- package/dist/activation-gate-D4IpmwyD.js.map +1 -0
- package/dist/avatar-group.js +2 -1
- package/dist/avatar-group.js.map +1 -1
- package/dist/avatar.js +3 -0
- package/dist/avatar.js.map +1 -1
- package/dist/{base-button-BJMGMcMv.js → base-button-9tGu5RSC.js} +30 -10
- package/dist/base-button-9tGu5RSC.js.map +1 -0
- package/dist/button-group.js +5 -3
- package/dist/button-group.js.map +1 -1
- package/dist/button.js +12 -16
- package/dist/button.js.map +1 -1
- package/dist/calendar-column-view.js +4 -4
- package/dist/{calendar-drag-IXMPZrTN.js → calendar-drag-DdJwSpEz.js} +2 -2
- package/dist/{calendar-drag-IXMPZrTN.js.map → calendar-drag-DdJwSpEz.js.map} +1 -1
- package/dist/{calendar-event-BQChlMXy.js → calendar-event-BvbYZHx1.js} +2 -2
- package/dist/{calendar-event-BQChlMXy.js.map → calendar-event-BvbYZHx1.js.map} +1 -1
- package/dist/calendar-month-view.js +65 -14
- package/dist/calendar-month-view.js.map +1 -1
- package/dist/calendar-timeline.js +13 -8
- package/dist/calendar-timeline.js.map +1 -1
- package/dist/calendar.js +21 -6
- package/dist/calendar.js.map +1 -1
- package/dist/card.js +29 -16
- package/dist/card.js.map +1 -1
- package/dist/chart-doughnut.js +3 -1
- package/dist/chart-doughnut.js.map +1 -1
- package/dist/chart-pie.js +9 -1
- package/dist/chart-pie.js.map +1 -1
- package/dist/chip-set.js +1 -1
- package/dist/chip.js +10 -19
- package/dist/chip.js.map +1 -1
- package/dist/color-field.js +4 -1
- package/dist/color-field.js.map +1 -1
- package/dist/currency-field.js +4 -1
- package/dist/currency-field.js.map +1 -1
- package/dist/custom-elements-jsdocs.json +26 -20
- package/dist/custom-elements.json +755 -90
- package/dist/{datasource-OwvH7SVq.js → datasource-DxEA6jHW.js} +6 -4
- package/dist/datasource-DxEA6jHW.js.map +1 -0
- package/dist/{date-cfPx3alz.js → date-DPQOY8Zd.js} +2 -2
- package/dist/{date-cfPx3alz.js.map → date-DPQOY8Zd.js.map} +1 -1
- package/dist/date-field.js +8 -5
- package/dist/date-field.js.map +1 -1
- package/dist/date-picker.js +2 -2
- package/dist/date-range-field.js +8 -5
- package/dist/date-range-field.js.map +1 -1
- package/dist/datetime-field.js +7 -4
- package/dist/datetime-field.js.map +1 -1
- package/dist/diagram-controls.js +1 -1
- package/dist/{throttle-SQ9t-HL7.js → dispatch-event-utils-DfgqVBK8.js} +2 -24
- package/dist/dispatch-event-utils-DfgqVBK8.js.map +1 -0
- package/dist/{form-submitter-beG1CXAn.js → dispatch-hooks-J_godlHh.js} +2 -87
- package/dist/dispatch-hooks-J_godlHh.js.map +1 -0
- package/dist/dropdown-button.js +11 -7
- package/dist/dropdown-button.js.map +1 -1
- package/dist/{event-manager-KGMT2x2Q.js → event-manager-DYfeN3VE.js} +3 -3
- package/dist/{event-manager-KGMT2x2Q.js.map → event-manager-DYfeN3VE.js.map} +1 -1
- package/dist/fab.js +15 -19
- package/dist/fab.js.map +1 -1
- package/dist/filter-bar.js +3 -3
- package/dist/form-submission-h40coUI8.js +13 -0
- package/dist/form-submission-h40coUI8.js.map +1 -0
- package/dist/form-submitter-BIFqZ0wq.js +88 -0
- package/dist/form-submitter-BIFqZ0wq.js.map +1 -0
- package/dist/form.js +1 -9
- package/dist/form.js.map +1 -1
- package/dist/icon-button.js +15 -19
- package/dist/icon-button.js.map +1 -1
- package/dist/icon.js +1 -1
- package/dist/implicit-submission-ChLdbxaR.js +100 -0
- package/dist/implicit-submission-ChLdbxaR.js.map +1 -0
- package/dist/index.js +20 -15
- package/dist/index.js.map +1 -1
- package/dist/{indicator-navigation-item-CmyhsOmy.js → indicator-navigation-item-BsQE3kUr.js} +2 -2
- package/dist/{indicator-navigation-item-CmyhsOmy.js.map → indicator-navigation-item-BsQE3kUr.js.map} +1 -1
- package/dist/input.js +13 -4
- package/dist/input.js.map +1 -1
- package/dist/json-viewer.js +1 -1
- package/dist/kanban.js +8 -7
- package/dist/kanban.js.map +1 -1
- package/dist/link-button.js +13 -14
- package/dist/link-button.js.map +1 -1
- package/dist/list-item.js +52 -16
- package/dist/list-item.js.map +1 -1
- package/dist/list.js +5 -3
- package/dist/list.js.map +1 -1
- package/dist/listbox.js +1 -1
- package/dist/loader-full.js +17 -12
- package/dist/loader-full.js.map +1 -1
- package/dist/loader.js +17 -12
- package/dist/loader.js.map +1 -1
- package/dist/locale-DEsJZCQG.js.map +1 -1
- package/dist/mention-input.js +8 -1
- package/dist/mention-input.js.map +1 -1
- package/dist/menu-item.js +12 -12
- package/dist/menu-item.js.map +1 -1
- package/dist/menu.js +7 -3
- package/dist/menu.js.map +1 -1
- package/dist/navigation-bar-item.js +4 -3
- package/dist/navigation-bar-item.js.map +1 -1
- package/dist/navigation-bar.js +4 -3
- package/dist/navigation-bar.js.map +1 -1
- package/dist/navigation-drawer-item.js +3 -2
- package/dist/navigation-drawer-item.js.map +1 -1
- package/dist/navigation-drawer.js +3 -2
- package/dist/navigation-drawer.js.map +1 -1
- package/dist/{navigation-item-base-kUrvJgCx.js → navigation-item-base-5ljwtLG_.js} +3 -2
- package/dist/{navigation-item-base-kUrvJgCx.js.map → navigation-item-base-5ljwtLG_.js.map} +1 -1
- package/dist/navigation-rail-item.js +4 -3
- package/dist/navigation-rail-item.js.map +1 -1
- package/dist/navigation-rail.js +6 -5
- package/dist/navigation-rail.js.map +1 -1
- package/dist/number-field.js +4 -1
- package/dist/number-field.js.map +1 -1
- package/dist/option.js +3 -2
- package/dist/option.js.map +1 -1
- package/dist/password-field.js +11 -4
- package/dist/password-field.js.map +1 -1
- package/dist/phone-field.js +4 -1
- package/dist/phone-field.js.map +1 -1
- package/dist/{picker-field-DmXYPvbF.js → picker-field-BiM3iXAQ.js} +2 -2
- package/dist/{picker-field-DmXYPvbF.js.map → picker-field-BiM3iXAQ.js.map} +1 -1
- package/dist/pin-input.js +4 -1
- package/dist/pin-input.js.map +1 -1
- package/dist/{range-utils-DZe96GnO.js → range-utils-vgG1SJ2o.js} +2 -2
- package/dist/{range-utils-DZe96GnO.js.map → range-utils-vgG1SJ2o.js.map} +1 -1
- package/dist/{roving-focus-controller-fm95JkZJ.js → roving-focus-controller-YtNbxH95.js} +30 -7
- package/dist/roving-focus-controller-YtNbxH95.js.map +1 -0
- package/dist/search.js +12 -6
- package/dist/search.js.map +1 -1
- package/dist/select.js +11 -3
- package/dist/select.js.map +1 -1
- package/dist/shipped-icons.js +1 -1
- package/dist/split-button.js +9 -1
- package/dist/split-button.js.map +1 -1
- package/dist/src/__internal/controllers/roving-focus-controller.d.ts +14 -2
- package/dist/src/__internal/implicit-submission.d.ts +25 -0
- package/dist/src/__internal/utils/activation-gate.d.ts +8 -0
- package/dist/src/__internal/utils/form-submission.d.ts +2 -0
- package/dist/src/avatar-group/avatar-group.d.ts +1 -1
- package/dist/src/button/base-button/base-button.d.ts +1 -1
- package/dist/src/button/button/button.d.ts +2 -1
- package/dist/src/button/fab/fab.d.ts +2 -1
- package/dist/src/button/icon-button/icon-button.d.ts +2 -1
- package/dist/src/button/link-button/link-button.d.ts +5 -1
- package/dist/src/calendar/calendar-month-view.d.ts +5 -1
- package/dist/src/calendar/calendar.d.ts +6 -1
- package/dist/src/card/card.d.ts +19 -9
- package/dist/src/chart-pie/chart-pie.d.ts +5 -0
- package/dist/src/chip/chip/chip.d.ts +4 -4
- package/dist/src/dropdown-button/dropdown-button.d.ts +5 -1
- package/dist/src/input/BaseField.d.ts +7 -0
- package/dist/src/input/input.d.ts +5 -1
- package/dist/src/list/list-item.d.ts +2 -1
- package/dist/src/mention-input/mention-input.d.ts +2 -0
- package/dist/src/menu/menu-item/menu-item.d.ts +6 -4
- package/dist/src/password-field/password-field.d.ts +3 -1
- package/dist/src/search/search.d.ts +1 -0
- package/dist/src/select/select.d.ts +2 -0
- package/dist/src/split-button/split-button.d.ts +6 -1
- package/dist/src/stepper/step.d.ts +3 -1
- package/dist/src/tabs/tab.d.ts +12 -2
- package/dist/src/textarea/textarea.d.ts +2 -0
- package/dist/src/toolbar/toolbar.d.ts +13 -2
- package/dist/step.js +7 -1
- package/dist/step.js.map +1 -1
- package/dist/stepper.js +10 -1
- package/dist/stepper.js.map +1 -1
- package/dist/sub-menu.js +3 -2
- package/dist/sub-menu.js.map +1 -1
- package/dist/svg.js +1 -1
- package/dist/tab-group.js +3 -2
- package/dist/tab-group.js.map +1 -1
- package/dist/tab.js +17 -12
- package/dist/tab.js.map +1 -1
- package/dist/tabs.js +3 -2
- package/dist/tabs.js.map +1 -1
- package/dist/test/accessible-name.test.d.ts +1 -0
- package/dist/test/helpers/count-activations.d.ts +9 -0
- package/dist/test/navigation-rail.test.d.ts +1 -0
- package/dist/test/throttle-delay.test.d.ts +1 -0
- package/dist/textarea.js +8 -1
- package/dist/textarea.js.map +1 -1
- package/dist/throttle-C7ZAPqtu.js +24 -0
- package/dist/throttle-C7ZAPqtu.js.map +1 -0
- package/dist/time-field.js +7 -4
- package/dist/time-field.js.map +1 -1
- package/dist/time-picker.js +2 -2
- package/dist/toolbar.js +25 -8
- package/dist/toolbar.js.map +1 -1
- package/dist/tree.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/url-field.js +4 -1
- package/dist/url-field.js.map +1 -1
- package/dist/{utils-DcvLgexs.js → utils-CQzycr9J.js} +2 -1
- package/dist/utils-CQzycr9J.js.map +1 -0
- package/package.json +2 -1
- package/src/__internal/controllers/roving-focus-controller.ts +35 -7
- package/src/__internal/i18n/locale.ts +1 -1
- package/src/__internal/implicit-submission.ts +102 -0
- package/src/__internal/utils/activation-gate.ts +20 -0
- package/src/__internal/utils/cache-fetch.ts +6 -3
- package/src/__internal/utils/form-submission.ts +11 -0
- package/src/avatar/avatar.scss +5 -0
- package/src/avatar-group/avatar-group.scss +3 -0
- package/src/avatar-group/avatar-group.ts +1 -1
- package/src/button/base-button/base-button.ts +41 -16
- package/src/button/button/button.ts +5 -16
- package/src/button/fab/fab.ts +7 -18
- package/src/button/icon-button/icon-button.ts +7 -18
- package/src/button/link-button/link-button.ts +8 -15
- package/src/calendar/_calendar-header.scss +7 -1
- package/src/calendar/calendar-month-view.scss +36 -2
- package/src/calendar/calendar-month-view.ts +33 -8
- package/src/calendar/calendar.ts +17 -2
- package/src/calendar/utils.ts +1 -0
- package/src/calendar-timeline/calendar-timeline.scss +15 -5
- package/src/card/card.ts +27 -16
- package/src/chart-doughnut/chart-doughnut.ts +6 -1
- package/src/chart-pie/chart-pie.ts +10 -1
- package/src/chip/chip/chip.ts +6 -26
- package/src/dropdown-button/dropdown-button.ts +7 -2
- package/src/form/form.ts +1 -9
- package/src/input/BaseField.ts +17 -0
- package/src/input/input.ts +13 -1
- package/src/kanban/kanban.scss +11 -7
- package/src/list/list-item.scss +5 -0
- package/src/list/list-item.ts +44 -16
- package/src/mention-input/mention-input.ts +5 -0
- package/src/menu/menu/menu.ts +4 -1
- package/src/menu/menu-item/menu-item.ts +9 -14
- package/src/navigation-rail/navigation-rail.scss +3 -2
- package/src/password-field/password-field.ts +11 -1
- package/src/search/search.ts +9 -0
- package/src/select/select.ts +5 -0
- package/src/split-button/split-button.ts +10 -1
- package/src/stepper/step.ts +7 -1
- package/src/stepper/stepper.scss +13 -0
- package/src/tabs/tab.ts +21 -17
- package/src/textarea/textarea.ts +5 -0
- package/src/toolbar/toolbar.ts +26 -7
- package/dist/BaseField-BbOj212R.js.map +0 -1
- package/dist/base-button-BJMGMcMv.js.map +0 -1
- package/dist/datasource-OwvH7SVq.js.map +0 -1
- package/dist/form-submitter-beG1CXAn.js.map +0 -1
- package/dist/roving-focus-controller-fm95JkZJ.js.map +0 -1
- package/dist/throttle-SQ9t-HL7.js.map +0 -1
- package/dist/utils-DcvLgexs.js.map +0 -1
|
@@ -2,6 +2,7 @@ import { _ as __decorate, A, b } from './IndividualComponent-BK7XZjE2.js';
|
|
|
2
2
|
import { n } from './property-B2TG3KEE.js';
|
|
3
3
|
import { r } from './state-BCeDVCI9.js';
|
|
4
4
|
import { p as peacockString } from './strings-DeiQWMd9.js';
|
|
5
|
+
import { r as registerTextField } from './implicit-submission-ChLdbxaR.js';
|
|
5
6
|
import { B as BaseInput } from './BaseInput-Cv03GZLu.js';
|
|
6
7
|
|
|
7
8
|
/** Below this width, in pixels, a field's Suggested badge shows just the sparkle. */
|
|
@@ -22,9 +23,10 @@ let fieldCount = 0;
|
|
|
22
23
|
* `clearValue()` if clearing means more than `value = ''`.
|
|
23
24
|
*/
|
|
24
25
|
class BaseField extends BaseInput {
|
|
26
|
+
// ── Lifecycle ────────────────────────────────────────────────────────────
|
|
25
27
|
constructor() {
|
|
28
|
+
super();
|
|
26
29
|
// ── Properties ───────────────────────────────────────────────────────────
|
|
27
|
-
super(...arguments);
|
|
28
30
|
/** Label shown above the field; also the control's accessible name. */
|
|
29
31
|
this.label = '';
|
|
30
32
|
/** Hint shown inside the empty control. */
|
|
@@ -58,8 +60,11 @@ class BaseField extends BaseInput {
|
|
|
58
60
|
this.handleFieldFocus = (event) => {
|
|
59
61
|
this.focused = event.type === 'focus';
|
|
60
62
|
};
|
|
63
|
+
// A single-line field keeps Enter in another field from submitting a form without a
|
|
64
|
+
// submit button, as a second native text input would.
|
|
65
|
+
if (this.singleLineTextField)
|
|
66
|
+
registerTextField(this);
|
|
61
67
|
}
|
|
62
|
-
// ── Lifecycle ────────────────────────────────────────────────────────────
|
|
63
68
|
connectedCallback() {
|
|
64
69
|
super.connectedCallback();
|
|
65
70
|
// `aria-*` and `tabindex` set on the host belong to the inner control; move them there.
|
|
@@ -101,6 +106,14 @@ class BaseField extends BaseInput {
|
|
|
101
106
|
get suggestionBadgeIconOnly() {
|
|
102
107
|
return false;
|
|
103
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Whether the field is a single-line text field, which counts like a native text input when
|
|
111
|
+
* Enter decides whether to submit a form that has no submit button. Multi-line fields and
|
|
112
|
+
* selects turn it off. Read in the constructor, so an override must not use instance fields.
|
|
113
|
+
*/
|
|
114
|
+
get singleLineTextField() {
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
104
117
|
/**
|
|
105
118
|
* The error text the field shows: the consumer's `error-text` while `error` is set, else an
|
|
106
119
|
* error the control found itself, else the validation message once it should show.
|
|
@@ -267,4 +280,4 @@ __decorate([
|
|
|
267
280
|
], BaseField.prototype, "__narrow", void 0);
|
|
268
281
|
|
|
269
282
|
export { BaseField as B };
|
|
270
|
-
//# sourceMappingURL=BaseField-
|
|
283
|
+
//# sourceMappingURL=BaseField-DOCmylob.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseField-DOCmylob.js","sources":["../../src/input/BaseField.ts"],"sourcesContent":["import { html, nothing, type PropertyValues, type TemplateResult } from 'lit';\nimport { property, state } from 'lit/decorators.js';\n\nimport { peacockString } from '@/__internal/i18n/strings.js';\nimport { registerTextField } from '@/__internal/implicit-submission.js';\nimport type { Size } from '@/__internal/utils/size.js';\nimport BaseInput from './BaseInput.js';\n\n/** Below this width, in pixels, a field's Suggested badge shows just the sparkle. */\nconst NARROW_FIELD_WIDTH = 320;\n\n/** What a field component passes to `renderField()`. */\nexport interface FieldRenderOptions {\n /** Whether the field has a value; outlined fields float their label when it does. */\n populated: boolean;\n /** Overrides the field's own focus state, for fields whose popup keeps them active. */\n focused?: boolean;\n /** An error the control found itself, such as text that does not parse. */\n controlError?: string;\n /** Extra content before the control (after the `start` slot). */\n start?: unknown;\n /** Extra content after the control (after the `end` slot), such as a picker button. */\n end?: unknown;\n /** Character counter shown in the footer, such as `12/100`; empty or unset for none. */\n textCount?: string;\n}\n\nlet fieldCount = 0;\n\n/**\n * Base class for Peacock's text-like fields (input, textarea, number, URL, select, date/time,\n * color). It adds the props every field shares (label, helper/error/warning text, variant, size,\n * clearable, `start`/`end` slots) and renders the `wc-field` frame.\n *\n * It also makes the inner control accessible across the shadow boundary: `fieldAria()` gives it\n * an accessible name from `label`, `aria-invalid` while an error shows, and `aria-describedby`\n * pointing at a hidden copy of the helper or error text in the same shadow root.\n *\n * Subclasses call `renderField(control, options)` in `render()`, spread `fieldAria()` onto the\n * native control, call `emitValue('input' | 'change')` instead of re-dispatching native events\n * (the field event contract: `CustomEvent<{ value }>`, bubbling and composed), and override\n * `clearValue()` if clearing means more than `value = ''`.\n */\nexport default abstract class BaseField extends BaseInput {\n // ── Properties ───────────────────────────────────────────────────────────\n\n /** Label shown above the field; also the control's accessible name. */\n @property({ type: String }) label = '';\n\n /** Hint shown inside the empty control. */\n @property({ type: String }) placeholder = '';\n\n /** Help text shown below the field. */\n @property({ type: String, attribute: 'helper-text' }) helperText = '';\n\n /** Shows the field in its error state with `error-text`. */\n @property({ type: Boolean }) error = false;\n\n /** Error message shown below the field while `error` is set; replaces the help text. */\n @property({ type: String, attribute: 'error-text' }) errorText = '';\n\n /** Shows the field in its warning state with `warning-text`. */\n @property({ type: Boolean }) warning = false;\n\n /** Warning message shown below the field while `warning` is set; replaces the help text. */\n @property({ type: String, attribute: 'warning-text' }) warningText = '';\n\n /** Visual variant of the field. */\n @property({ type: String }) variant: 'default' | 'filled' | 'outlined' =\n 'default';\n\n /** Height of the field: `sm` (2.5rem, default), `md` (3.5rem) or `lg` (4rem). */\n @property({ type: String, reflect: true }) size: Size = 'sm';\n\n /** Shows a button that clears the value while the field has one. */\n @property({ type: Boolean }) clearable = false;\n\n /** ARIA attributes moved from the host onto the inner control. */\n @property({ type: Object }) configAria: Record<string, string> = {};\n\n // ── State ────────────────────────────────────────────────────────────────\n\n @state() protected focused = false;\n\n /** The field is too narrow for the Suggested badge's label; it shows just the sparkle. */\n @state() private __narrow = false;\n\n // ── Private fields ───────────────────────────────────────────────────────\n\n /** Id of the hidden description the inner control points at. */\n protected readonly fieldDescriptionId = `wc-field-description-${(fieldCount += 1)}`;\n\n /** A `tabindex` set on the host, moved to the inner control. */\n protected controlTabIndex?: string;\n\n /** Watches the field's width while it holds a suggestion, so the badge can shrink. */\n private __widthObserver?: ResizeObserver;\n\n // ── Lifecycle ────────────────────────────────────────────────────────────\n\n constructor() {\n super();\n // A single-line field keeps Enter in another field from submitting a form without a\n // submit button, as a second native text input would.\n if (this.singleLineTextField) registerTextField(this);\n }\n\n override connectedCallback() {\n super.connectedCallback();\n // `aria-*` and `tabindex` set on the host belong to the inner control; move them there.\n for (const attr of Array.from(this.attributes)) {\n if (attr.name.startsWith('aria-')) {\n this.configAria = { ...this.configAria, [attr.name]: attr.value };\n this.removeAttribute(attr.name);\n }\n }\n if (this.hasAttribute('tabindex')) {\n this.controlTabIndex = this.getAttribute('tabindex') ?? undefined;\n this.removeAttribute('tabindex');\n }\n }\n\n override disconnectedCallback() {\n super.disconnectedCallback();\n this.__widthObserver?.disconnect();\n this.__widthObserver = undefined;\n }\n\n protected override updated(changed: PropertyValues) {\n super.updated(changed);\n // Only a field showing a suggestion pays for an observer.\n if (this.suggestionVisible && !this.__widthObserver) {\n this.__widthObserver = new ResizeObserver(([entry]) => {\n this.__narrow = entry.contentRect.width < NARROW_FIELD_WIDTH;\n });\n this.__widthObserver.observe(this);\n } else if (!this.suggestionVisible && this.__widthObserver) {\n this.__widthObserver.disconnect();\n this.__widthObserver = undefined;\n }\n }\n\n // ── Protected ────────────────────────────────────────────────────────────\n\n /**\n * Whether the Suggested badge always shows just the sparkle, whatever the width. A textarea\n * sets it: a label beside it would narrow every line of the text.\n */\n protected get suggestionBadgeIconOnly(): boolean {\n return false;\n }\n\n /**\n * Whether the field is a single-line text field, which counts like a native text input when\n * Enter decides whether to submit a form that has no submit button. Multi-line fields and\n * selects turn it off. Read in the constructor, so an override must not use instance fields.\n */\n protected get singleLineTextField(): boolean {\n return true;\n }\n\n /**\n * The error text the field shows: the consumer's `error-text` while `error` is set, else an\n * error the control found itself, else the validation message once it should show.\n */\n protected fieldErrorText(controlError = ''): string {\n if (this.error) return this.errorText;\n return controlError || this.validationText;\n }\n\n /**\n * Attributes for the native control: accessible name, invalid state, description and the\n * host's `tabindex`, plus `configAria`. Spread them onto it with `spread(this.fieldAria())`.\n */\n protected fieldAria(controlError = ''): Record<string, string | undefined> {\n const invalid = this.error || !!this.fieldErrorText(controlError);\n return {\n tabindex: this.controlTabIndex,\n 'aria-label': this.label || undefined,\n 'aria-invalid': invalid ? 'true' : undefined,\n 'aria-describedby': this.fieldDescription(controlError)\n ? this.fieldDescriptionId\n : undefined,\n ...this.configAria,\n };\n }\n\n /** Renders the `wc-field` frame around `control`, plus the hidden description. */\n protected renderField(\n control: unknown,\n options: FieldRenderOptions,\n ): TemplateResult {\n const errorText = this.fieldErrorText(options.controlError);\n const description = this.fieldDescription(options.controlError);\n // While a suggestion shows, its reason takes the helper text's place.\n const helperText = this.suggestionReason || this.helperText;\n return html`\n <wc-field\n label=${this.label}\n size=${this.size}\n variant=${this.variant}\n helper-text=${helperText}\n ?required=${this.required}\n ?disabled=${this.disabled}\n ?readonly=${this.readonly}\n ?skeleton=${this.skeleton}\n ?error=${this.error || !!errorText}\n error-text=${errorText}\n ?warning=${this.warning}\n warning-text=${this.warningText}\n text-count=${options.textCount ?? ''}\n ?populated=${options.populated}\n ?focused=${options.focused ?? this.focused}\n .host=${this}\n class=\"field\"\n >\n <slot name=\"start\" slot=\"field-start\"></slot>\n ${options.start ?? nothing} ${control}\n <slot name=\"end\" slot=\"field-end\"></slot>\n ${this.suggestionBadge({\n slot: 'field-end',\n iconOnly: this.__narrow || this.suggestionBadgeIconOnly,\n })}\n ${this.renderClearButton(options.populated)} ${options.end ?? nothing}\n </wc-field>\n ${description\n ? html`<span id=${this.fieldDescriptionId} hidden>${description}</span>`\n : nothing}\n `;\n }\n\n /** Dispatches `input` or `change` with the current value: the field event contract. */\n protected emitValue(type: 'input' | 'change') {\n this.dispatchEvent(\n new CustomEvent(type, {\n detail: { value: this.value },\n bubbles: true,\n composed: true,\n }),\n );\n }\n\n protected override emitSuggestionValue() {\n this.emitValue('input');\n this.emitValue('change');\n }\n\n /** Clears the value for the clear button. Fields with another empty value override it. */\n protected clearValue() {\n this.value = '';\n this.emitValue('input');\n this.emitValue('change');\n }\n\n /** The counter text for a field with a `maxlength`: `12/100`, or '' when there is no limit. */\n protected characterCount(maxLength: number | null | undefined): string {\n if (typeof maxLength !== 'number' || !Number.isFinite(maxLength)) return '';\n if (maxLength < 0) return '';\n const count = String(this.value ?? '').length;\n return peacockString('characterCount')(count, maxLength);\n }\n\n /** Tracks focus of the inner control; bind it to the control's `focus` and `blur`. */\n protected handleFieldFocus = (event: FocusEvent) => {\n this.focused = event.type === 'focus';\n };\n\n // ── Private ──────────────────────────────────────────────────────────────\n\n /** The text the description carries: the error, else the warning, else the help. */\n private fieldDescription(controlError = ''): string {\n const errorText = this.fieldErrorText(controlError);\n if (errorText) return errorText;\n if (this.warning && this.warningText) return this.warningText;\n if (this.suggestionVisible) {\n return peacockString('aiSuggestedDescription')(this.suggestionReason);\n }\n return this.helperText;\n }\n\n private renderClearButton(populated: boolean) {\n if (!this.clearable || !populated || this.disabled || this.readonly) {\n return nothing;\n }\n return html`<wc-icon-button\n slot=\"field-end\"\n class=\"clear-button\"\n shape=\"round\"\n variant=\"text\"\n size=\"sm\"\n aria-label=${peacockString('clear')}\n @click=${() => {\n this.clearValue();\n this.focus();\n }}\n >\n <wc-icon name=\"close\"></wc-icon>\n </wc-icon-button>`;\n }\n}\n"],"names":["html","nothing","property","state"],"mappings":";;;;;;;AAQA;AACA,MAAM,kBAAkB,GAAG,GAAG;AAkB9B,IAAI,UAAU,GAAG,CAAC;AAElB;;;;;;;;;;;;;AAaG;AACW,MAAgB,SAAU,SAAQ,SAAS,CAAA;;AAyDvD,IAAA,WAAA,GAAA;AACE,QAAA,KAAK,EAAE;;;QAtDmB,IAAA,CAAA,KAAK,GAAG,EAAE;;QAGV,IAAA,CAAA,WAAW,GAAG,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CAAC,EAAE,IAAI,EAAE,MAAM,EAAE;AAA0C,CAAA,EAAA,SAAA,CAAA,SAAA,EAAA,YAAA,EAAA,MAAA,CAAA;AAIjD,UAAA,CAAA;AAAlB,IAAAC,CAAK;AAA6B,CAAA,EAAA,SAAA,CAAA,SAAA,EAAA,SAAA,EAAA,MAAA,CAAA;AAGlB,UAAA,CAAA;AAAhB,IAAAA,CAAK;AAA4B,CAAA,EAAA,SAAA,CAAA,SAAA,EAAA,UAAA,EAAA,MAAA,CAAA;;;;"}
|
package/dist/accordion.js
CHANGED
|
@@ -2,7 +2,7 @@ import { i, _ as __decorate, I as IndividualComponent, a as i$1, b } from './Ind
|
|
|
2
2
|
import { n } from './property-B2TG3KEE.js';
|
|
3
3
|
import { o } from './query-assigned-elements-BJaGSqM0.js';
|
|
4
4
|
import { AccordionItem } from './accordion-item.js';
|
|
5
|
-
import { R as RovingFocusController } from './roving-focus-controller-
|
|
5
|
+
import { R as RovingFocusController } from './roving-focus-controller-YtNbxH95.js';
|
|
6
6
|
import './base-Cl6v8-BZ.js';
|
|
7
7
|
import './state-BCeDVCI9.js';
|
|
8
8
|
import './query-CHb9Ft_d.js';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gate for `throttle-delay`: the returned function says whether an activation may go ahead now.
|
|
3
|
+
* The first activation opens a window of `getDelay()` milliseconds, and every activation inside
|
|
4
|
+
* that window is refused, never deferred, so nothing runs later with a stale event. With no
|
|
5
|
+
* delay (unset, zero or negative) every activation goes ahead. The delay is read on each call, so
|
|
6
|
+
* a later change to it takes effect.
|
|
7
|
+
*/
|
|
8
|
+
function createActivationGate(getDelay) {
|
|
9
|
+
let windowStart = Number.NEGATIVE_INFINITY;
|
|
10
|
+
return () => {
|
|
11
|
+
const delay = getDelay();
|
|
12
|
+
if (typeof delay !== 'number' || !(delay > 0))
|
|
13
|
+
return true;
|
|
14
|
+
const now = performance.now();
|
|
15
|
+
if (now - windowStart < delay)
|
|
16
|
+
return false;
|
|
17
|
+
windowStart = now;
|
|
18
|
+
return true;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { createActivationGate as c };
|
|
23
|
+
//# sourceMappingURL=activation-gate-D4IpmwyD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"activation-gate-D4IpmwyD.js","sources":["../../src/__internal/utils/activation-gate.ts"],"sourcesContent":["/**\n * Gate for `throttle-delay`: the returned function says whether an activation may go ahead now.\n * The first activation opens a window of `getDelay()` milliseconds, and every activation inside\n * that window is refused, never deferred, so nothing runs later with a stale event. With no\n * delay (unset, zero or negative) every activation goes ahead. The delay is read on each call, so\n * a later change to it takes effect.\n */\nexport function createActivationGate(\n getDelay: () => number | undefined,\n): () => boolean {\n let windowStart = Number.NEGATIVE_INFINITY;\n return () => {\n const delay = getDelay();\n if (typeof delay !== 'number' || !(delay > 0)) return true;\n const now = performance.now();\n if (now - windowStart < delay) return false;\n windowStart = now;\n return true;\n };\n}\n"],"names":[],"mappings":"AAAA;;;;;;AAMG;AACG,SAAU,oBAAoB,CAClC,QAAkC,EAAA;AAElC,IAAA,IAAI,WAAW,GAAG,MAAM,CAAC,iBAAiB;AAC1C,IAAA,OAAO,MAAK;AACV,QAAA,MAAM,KAAK,GAAG,QAAQ,EAAE;QACxB,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,EAAE,KAAK,GAAG,CAAC,CAAC;AAAE,YAAA,OAAO,IAAI;AAC1D,QAAA,MAAM,GAAG,GAAG,WAAW,CAAC,GAAG,EAAE;AAC7B,QAAA,IAAI,GAAG,GAAG,WAAW,GAAG,KAAK;AAAE,YAAA,OAAO,KAAK;QAC3C,WAAW,GAAG,GAAG;AACjB,QAAA,OAAO,IAAI;AACb,IAAA,CAAC;AACH;;;;"}
|
package/dist/avatar-group.js
CHANGED
|
@@ -56,6 +56,7 @@ var css_248z = i`* {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
:host([size=sm]) {
|
|
59
|
+
--avatar-group-overlap: calc(var(--_size) * 0.1);
|
|
59
60
|
--_size: 1.5rem;
|
|
60
61
|
}
|
|
61
62
|
|
|
@@ -159,7 +160,7 @@ var css_248z = i`* {
|
|
|
159
160
|
*
|
|
160
161
|
* @slot - The `wc-avatar` elements.
|
|
161
162
|
*
|
|
162
|
-
* @cssprop --avatar-group-overlap - How far each avatar slides under the previous one. Defaults to a quarter of the avatar size
|
|
163
|
+
* @cssprop --avatar-group-overlap - How far each avatar slides under the previous one. Defaults to a quarter of the avatar size, a tenth at `size="sm"`.
|
|
163
164
|
* @cssprop --avatar-group-ring-width - Width of the ring between avatars. Defaults to `2px`.
|
|
164
165
|
* @cssprop --avatar-group-ring-color - Color of the ring between avatars. Defaults to `var(--color-surface)`; set it to the background the group sits on.
|
|
165
166
|
*
|
package/dist/avatar-group.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"avatar-group.js","sources":["../../src/avatar-group/avatar-group.ts"],"sourcesContent":["import { html, LitElement, nothing, type PropertyValues } from 'lit';\nimport { property, query, state } from 'lit/decorators.js';\nimport styles from './avatar-group.scss';\nimport IndividualComponent from '@/IndividualComponent.js';\nimport { I18nController } from '@/__internal/i18n/i18n-controller.js';\n\nexport type AvatarGroupSize = 'sm' | 'md' | 'lg';\n\n/** What the overflow list shows for an avatar the group hides. */\ninterface HiddenAvatar {\n name: string;\n src?: string;\n label: string;\n}\n\n/**\n * @label Avatar Group\n * @tag wc-avatar-group\n * @rawTag avatar-group\n * @summary Shows a row of overlapping avatars, such as the members of a team, with a count of the rest.\n * @overview\n * <p>Put <code>wc-avatar</code> elements inside. They overlap, each separated from the next by a\n * ring in the surface color, and stack from the start edge, so from the right in RTL.\n * <code>size</code> (<code>sm</code>, <code>md</code>, <code>lg</code>) is passed down to every\n * avatar.</p>\n * <p>With <code>max</code>, the group shows the first <code>max</code> avatars and then a\n * <em>+N</em> button for the rest; its accessible name is \"N more\". Pressing it opens a popover\n * that lists the hidden avatars by name. Without <code>max</code>, or with fewer avatars, every\n * avatar shows and there is no button.</p>\n * <p>The group has <code>role=\"group\"</code> and is named by <code>label</code>, \"Members\" by\n * default. Name each avatar with its <code>name</code> or <code>label</code>.</p>\n *\n * @slot - The `wc-avatar` elements.\n *\n * @cssprop --avatar-group-overlap - How far each avatar slides under the previous one. Defaults to a quarter of the avatar size.\n * @cssprop --avatar-group-ring-width - Width of the ring between avatars. Defaults to `2px`.\n * @cssprop --avatar-group-ring-color - Color of the ring between avatars. Defaults to `var(--color-surface)`; set it to the background the group sits on.\n *\n * @example\n * ```html\n * <wc-avatar-group max=\"3\" label=\"Project members\">\n * <wc-avatar name=\"Ada Lovelace\"></wc-avatar>\n * <wc-avatar name=\"Grace Hopper\"></wc-avatar>\n * <wc-avatar name=\"Alan Turing\"></wc-avatar>\n * <wc-avatar name=\"Katherine Johnson\"></wc-avatar>\n * <wc-avatar name=\"Edsger Dijkstra\"></wc-avatar>\n * </wc-avatar-group>\n * ```\n *\n * @tags display\n */\n@IndividualComponent\nexport class AvatarGroup extends LitElement {\n // ── Static ───────────────────────────────────────────────────────────────\n\n static override styles = [styles];\n\n /** The group chooses which children show, so it assigns them to its slot itself. */\n // eslint-disable-next-line no-undef\n static override shadowRootOptions: ShadowRootInit = {\n ...LitElement.shadowRootOptions,\n slotAssignment: 'manual',\n };\n\n // ── Properties ───────────────────────────────────────────────────────────\n\n /** How many avatars to show before the +N button. Unset, every avatar shows. */\n @property({ type: Number, reflect: true }) max?: number;\n\n /** Size of every avatar in the group: `sm`, `md` (default) or `lg`. */\n @property({ type: String, reflect: true }) size: AvatarGroupSize = 'md';\n\n /** The accessible name of the group. Defaults to \"Members\". */\n @property({ type: String }) label?: string;\n\n // ── State ────────────────────────────────────────────────────────────────\n\n /** Bumped when the children change, so the group renders again. */\n @state() private __childrenVersion = 0;\n\n // ── Queries ──────────────────────────────────────────────────────────────\n\n @query('slot') private readonly __slot!: HTMLSlotElement | null;\n\n // ── Private fields ───────────────────────────────────────────────────────\n\n private readonly i18n = new I18nController(this);\n\n /** Watches the children and the names on them. */\n private readonly __observer = new MutationObserver(() => {\n this.__childrenVersion += 1;\n });\n\n // ── Lifecycle ────────────────────────────────────────────────────────────\n\n override connectedCallback() {\n super.connectedCallback();\n this.__observer.observe(this, {\n childList: true,\n subtree: true,\n attributes: true,\n attributeFilter: ['name', 'src', 'label'],\n });\n }\n\n override disconnectedCallback() {\n super.disconnectedCallback();\n this.__observer.disconnect();\n }\n\n protected override updated(changed: PropertyValues<this>) {\n super.updated(changed);\n const items = this.__items();\n for (const item of items) {\n if (\n item.localName === 'wc-avatar' &&\n item.getAttribute('size') !== this.size\n ) {\n item.setAttribute('size', this.size);\n }\n }\n this.__slot?.assign(...items.slice(0, this.__visibleCount(items.length)));\n }\n\n // ── Private methods ──────────────────────────────────────────────────────\n\n /** The element children, in order. */\n private __items(): HTMLElement[] {\n return Array.from(this.children).filter(\n (child): child is HTMLElement => child instanceof HTMLElement,\n );\n }\n\n /** How many of `total` items show. */\n private __visibleCount(total: number): number {\n const max = Math.floor(Number(this.max));\n if (!Number.isFinite(max) || max < 0) return total;\n return Math.min(max, total);\n }\n\n private __describe(item: HTMLElement): HiddenAvatar {\n const name = item.getAttribute('name') ?? '';\n const label =\n item.getAttribute('label') ||\n name ||\n item.getAttribute('aria-label') ||\n (item.textContent ?? '').trim();\n return { name, src: item.getAttribute('src') ?? undefined, label };\n }\n\n /** The overflow popover's `open` / `close` are internal; they would escape as the group's. */\n // eslint-disable-next-line class-methods-use-this\n private __stopPopoverEvent(event: Event) {\n event.stopPropagation();\n }\n\n // ── Render helpers ───────────────────────────────────────────────────────\n\n private __renderOverflow(hidden: HTMLElement[]) {\n if (hidden.length === 0) return nothing;\n const count = new Intl.NumberFormat(this.i18n.locale).format(hidden.length);\n const moreLabel = this.i18n.t('avatarGroupMore')(count);\n return html`<wc-popover\n class=\"overflow\"\n trigger=\"click\"\n placement=\"bottom-start\"\n label=${moreLabel}\n @open=${this.__stopPopoverEvent}\n @close=${this.__stopPopoverEvent}\n >\n <button class=\"more\" type=\"button\" aria-label=${moreLabel}>\n +${count}\n </button>\n <wc-popover-content>\n <ul class=\"list\">\n ${hidden.map(item => {\n const { name, src, label } = this.__describe(item);\n return html`<li class=\"list-item\">\n <wc-avatar\n size=\"sm\"\n name=${name}\n src=${src ?? nothing}\n aria-hidden=\"true\"\n ></wc-avatar>\n <span class=\"list-label\">${label}</span>\n </li>`;\n })}\n </ul>\n </wc-popover-content>\n </wc-popover>`;\n }\n\n // ── Render ───────────────────────────────────────────────────────────────\n\n override render() {\n const items = this.__items();\n const hidden = items.slice(this.__visibleCount(items.length));\n return html`<div\n class=\"group\"\n role=\"group\"\n aria-label=${this.label || this.i18n.t('avatarGroupLabel')}\n >\n <slot></slot>\n ${this.__renderOverflow(hidden)}\n </div>`;\n }\n}\n"],"names":["LitElement","nothing","html","styles","property","state","query"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCG;AAEI,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQA,GAAU,CAAA;AAApC,IAAA,WAAA,GAAA;;;;QAkBsC,IAAA,CAAA,IAAI,GAAoB,IAAI;;;QAQtD,IAAA,CAAA,iBAAiB,GAAG,CAAC;;AAQrB,QAAA,IAAA,CAAA,IAAI,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC;;AAG/B,QAAA,IAAA,CAAA,UAAU,GAAG,IAAI,gBAAgB,CAAC,MAAK;AACtD,YAAA,IAAI,CAAC,iBAAiB,IAAI,CAAC;AAC7B,QAAA,CAAC,CAAC;IAmHJ;;IA/GW,iBAAiB,GAAA;QACxB,KAAK,CAAC,iBAAiB,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AAK1B,UAAA,CAAA;AAAhB,IAAAC,CAAK;AAAiC,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,mBAAA,EAAA,MAAA,CAAA;AAIP,UAAA,CAAA;IAA/BC,CAAK,CAAC,MAAM;AAAmD,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,QAAA,EAAA,MAAA,CAAA;AA9BrD,WAAW,GAAA,UAAA,CAAA;IADvB;AACY,CAAA,EAAA,WAAW,CA0JvB;;;;"}
|
|
1
|
+
{"version":3,"file":"avatar-group.js","sources":["../../src/avatar-group/avatar-group.ts"],"sourcesContent":["import { html, LitElement, nothing, type PropertyValues } from 'lit';\nimport { property, query, state } from 'lit/decorators.js';\nimport styles from './avatar-group.scss';\nimport IndividualComponent from '@/IndividualComponent.js';\nimport { I18nController } from '@/__internal/i18n/i18n-controller.js';\n\nexport type AvatarGroupSize = 'sm' | 'md' | 'lg';\n\n/** What the overflow list shows for an avatar the group hides. */\ninterface HiddenAvatar {\n name: string;\n src?: string;\n label: string;\n}\n\n/**\n * @label Avatar Group\n * @tag wc-avatar-group\n * @rawTag avatar-group\n * @summary Shows a row of overlapping avatars, such as the members of a team, with a count of the rest.\n * @overview\n * <p>Put <code>wc-avatar</code> elements inside. They overlap, each separated from the next by a\n * ring in the surface color, and stack from the start edge, so from the right in RTL.\n * <code>size</code> (<code>sm</code>, <code>md</code>, <code>lg</code>) is passed down to every\n * avatar.</p>\n * <p>With <code>max</code>, the group shows the first <code>max</code> avatars and then a\n * <em>+N</em> button for the rest; its accessible name is \"N more\". Pressing it opens a popover\n * that lists the hidden avatars by name. Without <code>max</code>, or with fewer avatars, every\n * avatar shows and there is no button.</p>\n * <p>The group has <code>role=\"group\"</code> and is named by <code>label</code>, \"Members\" by\n * default. Name each avatar with its <code>name</code> or <code>label</code>.</p>\n *\n * @slot - The `wc-avatar` elements.\n *\n * @cssprop --avatar-group-overlap - How far each avatar slides under the previous one. Defaults to a quarter of the avatar size, a tenth at `size=\"sm\"`.\n * @cssprop --avatar-group-ring-width - Width of the ring between avatars. Defaults to `2px`.\n * @cssprop --avatar-group-ring-color - Color of the ring between avatars. Defaults to `var(--color-surface)`; set it to the background the group sits on.\n *\n * @example\n * ```html\n * <wc-avatar-group max=\"3\" label=\"Project members\">\n * <wc-avatar name=\"Ada Lovelace\"></wc-avatar>\n * <wc-avatar name=\"Grace Hopper\"></wc-avatar>\n * <wc-avatar name=\"Alan Turing\"></wc-avatar>\n * <wc-avatar name=\"Katherine Johnson\"></wc-avatar>\n * <wc-avatar name=\"Edsger Dijkstra\"></wc-avatar>\n * </wc-avatar-group>\n * ```\n *\n * @tags display\n */\n@IndividualComponent\nexport class AvatarGroup extends LitElement {\n // ── Static ───────────────────────────────────────────────────────────────\n\n static override styles = [styles];\n\n /** The group chooses which children show, so it assigns them to its slot itself. */\n // eslint-disable-next-line no-undef\n static override shadowRootOptions: ShadowRootInit = {\n ...LitElement.shadowRootOptions,\n slotAssignment: 'manual',\n };\n\n // ── Properties ───────────────────────────────────────────────────────────\n\n /** How many avatars to show before the +N button. Unset, every avatar shows. */\n @property({ type: Number, reflect: true }) max?: number;\n\n /** Size of every avatar in the group: `sm`, `md` (default) or `lg`. */\n @property({ type: String, reflect: true }) size: AvatarGroupSize = 'md';\n\n /** The accessible name of the group. Defaults to \"Members\". */\n @property({ type: String }) label?: string;\n\n // ── State ────────────────────────────────────────────────────────────────\n\n /** Bumped when the children change, so the group renders again. */\n @state() private __childrenVersion = 0;\n\n // ── Queries ──────────────────────────────────────────────────────────────\n\n @query('slot') private readonly __slot!: HTMLSlotElement | null;\n\n // ── Private fields ───────────────────────────────────────────────────────\n\n private readonly i18n = new I18nController(this);\n\n /** Watches the children and the names on them. */\n private readonly __observer = new MutationObserver(() => {\n this.__childrenVersion += 1;\n });\n\n // ── Lifecycle ────────────────────────────────────────────────────────────\n\n override connectedCallback() {\n super.connectedCallback();\n this.__observer.observe(this, {\n childList: true,\n subtree: true,\n attributes: true,\n attributeFilter: ['name', 'src', 'label'],\n });\n }\n\n override disconnectedCallback() {\n super.disconnectedCallback();\n this.__observer.disconnect();\n }\n\n protected override updated(changed: PropertyValues<this>) {\n super.updated(changed);\n const items = this.__items();\n for (const item of items) {\n if (\n item.localName === 'wc-avatar' &&\n item.getAttribute('size') !== this.size\n ) {\n item.setAttribute('size', this.size);\n }\n }\n this.__slot?.assign(...items.slice(0, this.__visibleCount(items.length)));\n }\n\n // ── Private methods ──────────────────────────────────────────────────────\n\n /** The element children, in order. */\n private __items(): HTMLElement[] {\n return Array.from(this.children).filter(\n (child): child is HTMLElement => child instanceof HTMLElement,\n );\n }\n\n /** How many of `total` items show. */\n private __visibleCount(total: number): number {\n const max = Math.floor(Number(this.max));\n if (!Number.isFinite(max) || max < 0) return total;\n return Math.min(max, total);\n }\n\n private __describe(item: HTMLElement): HiddenAvatar {\n const name = item.getAttribute('name') ?? '';\n const label =\n item.getAttribute('label') ||\n name ||\n item.getAttribute('aria-label') ||\n (item.textContent ?? '').trim();\n return { name, src: item.getAttribute('src') ?? undefined, label };\n }\n\n /** The overflow popover's `open` / `close` are internal; they would escape as the group's. */\n // eslint-disable-next-line class-methods-use-this\n private __stopPopoverEvent(event: Event) {\n event.stopPropagation();\n }\n\n // ── Render helpers ───────────────────────────────────────────────────────\n\n private __renderOverflow(hidden: HTMLElement[]) {\n if (hidden.length === 0) return nothing;\n const count = new Intl.NumberFormat(this.i18n.locale).format(hidden.length);\n const moreLabel = this.i18n.t('avatarGroupMore')(count);\n return html`<wc-popover\n class=\"overflow\"\n trigger=\"click\"\n placement=\"bottom-start\"\n label=${moreLabel}\n @open=${this.__stopPopoverEvent}\n @close=${this.__stopPopoverEvent}\n >\n <button class=\"more\" type=\"button\" aria-label=${moreLabel}>\n +${count}\n </button>\n <wc-popover-content>\n <ul class=\"list\">\n ${hidden.map(item => {\n const { name, src, label } = this.__describe(item);\n return html`<li class=\"list-item\">\n <wc-avatar\n size=\"sm\"\n name=${name}\n src=${src ?? nothing}\n aria-hidden=\"true\"\n ></wc-avatar>\n <span class=\"list-label\">${label}</span>\n </li>`;\n })}\n </ul>\n </wc-popover-content>\n </wc-popover>`;\n }\n\n // ── Render ───────────────────────────────────────────────────────────────\n\n override render() {\n const items = this.__items();\n const hidden = items.slice(this.__visibleCount(items.length));\n return html`<div\n class=\"group\"\n role=\"group\"\n aria-label=${this.label || this.i18n.t('avatarGroupLabel')}\n >\n <slot></slot>\n ${this.__renderOverflow(hidden)}\n </div>`;\n }\n}\n"],"names":["LitElement","nothing","html","styles","property","state","query"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCG;AAEI,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQA,GAAU,CAAA;AAApC,IAAA,WAAA,GAAA;;;;QAkBsC,IAAA,CAAA,IAAI,GAAoB,IAAI;;;QAQtD,IAAA,CAAA,iBAAiB,GAAG,CAAC;;AAQrB,QAAA,IAAA,CAAA,IAAI,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC;;AAG/B,QAAA,IAAA,CAAA,UAAU,GAAG,IAAI,gBAAgB,CAAC,MAAK;AACtD,YAAA,IAAI,CAAC,iBAAiB,IAAI,CAAC;AAC7B,QAAA,CAAC,CAAC;IAmHJ;;IA/GW,iBAAiB,GAAA;QACxB,KAAK,CAAC,iBAAiB,EAAE;AACzB,QAAA,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,EAAE;AAC5B,YAAA,SAAS,EAAE,IAAI;AACf,YAAA,OAAO,EAAE,IAAI;AACb,YAAA,UAAU,EAAE,IAAI;AAChB,YAAA,eAAe,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC;AAC1C,SAAA,CAAC;IACJ;I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AAA;IADvB;AACY,CAAA,EAAA,WAAW,CA0JvB;;;;"}
|
package/dist/avatar.js
CHANGED
|
@@ -79,6 +79,9 @@ var css_248z = i`* {
|
|
|
79
79
|
background-color: var(--avatar-container-color);
|
|
80
80
|
font-size: calc(var(--avatar-size) * 0.5) !important;
|
|
81
81
|
}
|
|
82
|
+
:host([size=sm]) .avatar {
|
|
83
|
+
font-size: calc(var(--avatar-size) * 0.4) !important;
|
|
84
|
+
}
|
|
82
85
|
.avatar .image {
|
|
83
86
|
width: 100%;
|
|
84
87
|
height: 100%;
|
package/dist/avatar.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"avatar.js","sources":["../../src/avatar/avatar.ts"],"sourcesContent":["import { html, LitElement, nothing, type PropertyValues } from 'lit';\nimport { property, state } from 'lit/decorators.js';\nimport { classMap } from 'lit/directives/class-map.js';\nimport styles from './avatar.scss';\nimport IndividualComponent from '@/IndividualComponent.js';\n\n/**\n * @label Avatar\n * @tag wc-avatar\n * @rawTag avatar\n * @summary A person's picture, or their initials or a person icon when there is no picture.\n * @overview\n * <p>The avatar shows the image at <code>src</code>. Without one, or when the image fails to\n * load, it shows the initials of <code>name</code> (the first letters of its first and last\n * words), and without a name a person icon.</p>\n * <p>The avatar is named by <code>label</code>, or else <code>name</code>: the image gets it as\n * <code>alt</code>, the initials and the icon as <code>role=\"img\"</code> with\n * <code>aria-label</code>. An avatar with neither is decorative and hidden from assistive\n * technology.</p>\n * <p><code>size</code> (<code>sm</code>, <code>md</code>, <code>lg</code>) sets\n * <code>--avatar-size</code>; setting the custom property directly still wins.</p>\n *\n * @cssprop --avatar-border-radius - Controls the border radius of the avatar.\n * @cssprop --avatar-container-color - Controls the color of the avatar container.\n * @cssprop --avatar-size - Controls the size of the avatar.\n * @cssprop --avatar-text-color - Controls the color of the text inside the avatar.\n *\n *\n * @example\n * ```html\n * <wc-avatar name=\"Ada Lovelace\" src=\"https://peacock.redvars.com/assets/img/avatar.xs.webp\" size=\"lg\"></wc-avatar>\n * <wc-avatar name=\"Grace Brewster Hopper\"></wc-avatar>\n * ```\n *\n * @tags display\n */\n@IndividualComponent\nexport class Avatar extends LitElement {\n static styles = [styles];\n\n /** Full name of the person. Used to derive initials when no `src` is provided. */\n @property({ type: String, reflect: true }) name: string = '';\n\n /** URL of the avatar image. When provided, the image is displayed instead of initials. */\n @property({ type: String, reflect: true }) src?: string;\n\n /** The accessible name, when it should differ from `name` (for example \"Ada Lovelace, online\"). */\n @property({ type: String }) label?: string;\n\n /** Size of the avatar: `sm` (1.5rem), `md` (2rem, default) or `lg` (3rem). */\n @property({ type: String, reflect: true }) size: 'sm' | 'md' | 'lg' = 'md';\n\n /** True after the image at `src` failed to load, until `src` changes. */\n @state() private __imageFailed = false;\n\n protected override willUpdate(changed: PropertyValues<this>) {\n if (changed.has('src')) this.__imageFailed = false;\n }\n\n /** The initials shown without an image: first letters of the first and last words of `name`. */\n get initials(): string {\n const words = this.name.trim().split(/\\s+/).filter(Boolean);\n if (words.length === 0) return '';\n const first = Array.from(words[0])[0] ?? '';\n const last =\n words.length > 1 ? (Array.from(words[words.length - 1])[0] ?? '') : '';\n return `${first}${last}`.toUpperCase();\n }\n\n private __handleImageError = () => {\n this.__imageFailed = true;\n };\n\n private __renderContent(accessibleName: string) {\n if (this.src && !this.__imageFailed) {\n return html`<img\n class=\"image\"\n src=${this.src}\n alt=${accessibleName}\n @error=${this.__handleImageError}\n />`;\n }\n const { initials } = this;\n if (initials) {\n return html`<div\n class=\"initials\"\n role=${accessibleName ? 'img' : nothing}\n aria-label=${accessibleName || nothing}\n aria-hidden=${accessibleName ? nothing : 'true'}\n >\n ${initials}\n </div>`;\n }\n return html`<wc-icon\n class=\"fallback-icon\"\n name=\"person\"\n role=${accessibleName ? 'img' : nothing}\n aria-label=${accessibleName || nothing}\n aria-hidden=${accessibleName ? nothing : 'true'}\n ></wc-icon>`;\n }\n\n render() {\n const showImage = !!this.src && !this.__imageFailed;\n const accessibleName = this.label || this.name;\n return html`<div class=\"avatar-container\">\n <div\n class=${classMap({\n avatar: true,\n initials: !showImage,\n image: showImage,\n })}\n >\n ${this.__renderContent(accessibleName)}\n </div>\n </div>`;\n }\n}\n"],"names":["LitElement","html","nothing","classMap","styles","property","state"],"mappings":"
|
|
1
|
+
{"version":3,"file":"avatar.js","sources":["../../src/avatar/avatar.ts"],"sourcesContent":["import { html, LitElement, nothing, type PropertyValues } from 'lit';\nimport { property, state } from 'lit/decorators.js';\nimport { classMap } from 'lit/directives/class-map.js';\nimport styles from './avatar.scss';\nimport IndividualComponent from '@/IndividualComponent.js';\n\n/**\n * @label Avatar\n * @tag wc-avatar\n * @rawTag avatar\n * @summary A person's picture, or their initials or a person icon when there is no picture.\n * @overview\n * <p>The avatar shows the image at <code>src</code>. Without one, or when the image fails to\n * load, it shows the initials of <code>name</code> (the first letters of its first and last\n * words), and without a name a person icon.</p>\n * <p>The avatar is named by <code>label</code>, or else <code>name</code>: the image gets it as\n * <code>alt</code>, the initials and the icon as <code>role=\"img\"</code> with\n * <code>aria-label</code>. An avatar with neither is decorative and hidden from assistive\n * technology.</p>\n * <p><code>size</code> (<code>sm</code>, <code>md</code>, <code>lg</code>) sets\n * <code>--avatar-size</code>; setting the custom property directly still wins.</p>\n *\n * @cssprop --avatar-border-radius - Controls the border radius of the avatar.\n * @cssprop --avatar-container-color - Controls the color of the avatar container.\n * @cssprop --avatar-size - Controls the size of the avatar.\n * @cssprop --avatar-text-color - Controls the color of the text inside the avatar.\n *\n *\n * @example\n * ```html\n * <wc-avatar name=\"Ada Lovelace\" src=\"https://peacock.redvars.com/assets/img/avatar.xs.webp\" size=\"lg\"></wc-avatar>\n * <wc-avatar name=\"Grace Brewster Hopper\"></wc-avatar>\n * ```\n *\n * @tags display\n */\n@IndividualComponent\nexport class Avatar extends LitElement {\n static styles = [styles];\n\n /** Full name of the person. Used to derive initials when no `src` is provided. */\n @property({ type: String, reflect: true }) name: string = '';\n\n /** URL of the avatar image. When provided, the image is displayed instead of initials. */\n @property({ type: String, reflect: true }) src?: string;\n\n /** The accessible name, when it should differ from `name` (for example \"Ada Lovelace, online\"). */\n @property({ type: String }) label?: string;\n\n /** Size of the avatar: `sm` (1.5rem), `md` (2rem, default) or `lg` (3rem). */\n @property({ type: String, reflect: true }) size: 'sm' | 'md' | 'lg' = 'md';\n\n /** True after the image at `src` failed to load, until `src` changes. */\n @state() private __imageFailed = false;\n\n protected override willUpdate(changed: PropertyValues<this>) {\n if (changed.has('src')) this.__imageFailed = false;\n }\n\n /** The initials shown without an image: first letters of the first and last words of `name`. */\n get initials(): string {\n const words = this.name.trim().split(/\\s+/).filter(Boolean);\n if (words.length === 0) return '';\n const first = Array.from(words[0])[0] ?? '';\n const last =\n words.length > 1 ? (Array.from(words[words.length - 1])[0] ?? '') : '';\n return `${first}${last}`.toUpperCase();\n }\n\n private __handleImageError = () => {\n this.__imageFailed = true;\n };\n\n private __renderContent(accessibleName: string) {\n if (this.src && !this.__imageFailed) {\n return html`<img\n class=\"image\"\n src=${this.src}\n alt=${accessibleName}\n @error=${this.__handleImageError}\n />`;\n }\n const { initials } = this;\n if (initials) {\n return html`<div\n class=\"initials\"\n role=${accessibleName ? 'img' : nothing}\n aria-label=${accessibleName || nothing}\n aria-hidden=${accessibleName ? nothing : 'true'}\n >\n ${initials}\n </div>`;\n }\n return html`<wc-icon\n class=\"fallback-icon\"\n name=\"person\"\n role=${accessibleName ? 'img' : nothing}\n aria-label=${accessibleName || nothing}\n aria-hidden=${accessibleName ? nothing : 'true'}\n ></wc-icon>`;\n }\n\n render() {\n const showImage = !!this.src && !this.__imageFailed;\n const accessibleName = this.label || this.name;\n return html`<div class=\"avatar-container\">\n <div\n class=${classMap({\n avatar: true,\n initials: !showImage,\n image: showImage,\n })}\n >\n ${this.__renderContent(accessibleName)}\n </div>\n </div>`;\n }\n}\n"],"names":["LitElement","html","nothing","classMap","styles","property","state"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAA,CAAA,SAAA,EAAA,MAAA,EAAA,MAAA,CAAA;AAGlB,UAAA,CAAA;IAA1CA,CAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE;AAAe,CAAA,EAAA,MAAA,CAAA,SAAA,EAAA,KAAA,EAAA,MAAA,CAAA;AAG5B,UAAA,CAAA;AAA3B,IAAAA,CAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE;AAAiB,CAAA,EAAA,MAAA,CAAA,SAAA,EAAA,OAAA,EAAA,MAAA,CAAA;AAGA,UAAA,CAAA;IAA1CA,CAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE;AAAkC,CAAA,EAAA,MAAA,CAAA,SAAA,EAAA,MAAA,EAAA,MAAA,CAAA;AAG1D,UAAA,CAAA;AAAhB,IAAAC,CAAK;AAAiC,CAAA,EAAA,MAAA,CAAA,SAAA,EAAA,eAAA,EAAA,MAAA,CAAA;AAhB5B,MAAM,GAAA,UAAA,CAAA;IADlB;AACY,CAAA,EAAA,MAAM,CAgFlB;;;;"}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { _ as __decorate } from './IndividualComponent-BK7XZjE2.js';
|
|
2
2
|
import { n } from './property-B2TG3KEE.js';
|
|
3
|
-
import {
|
|
3
|
+
import { c as createActivationGate } from './activation-gate-D4IpmwyD.js';
|
|
4
4
|
import { w as warnOnce } from './warn-once-BNxX1Y98.js';
|
|
5
5
|
|
|
6
6
|
function mixinBaseButton(base) {
|
|
7
7
|
class BaseButtonElement extends base {
|
|
8
|
-
constructor
|
|
9
|
-
|
|
8
|
+
// Mixins must have a constructor with `...args: any[]`
|
|
9
|
+
// tslint:disable-next-line:no-any
|
|
10
|
+
constructor(...args) {
|
|
11
|
+
super(...args);
|
|
10
12
|
/** The visual style of the button, such as `"filled"`, `"tonal"`, `"outlined"` or `"text"`. */
|
|
11
13
|
this.variant = '';
|
|
12
14
|
/** The color role of the button, such as `"primary"`, `"surface"` or `"danger"`. */
|
|
@@ -27,15 +29,33 @@ function mixinBaseButton(base) {
|
|
|
27
29
|
* Maps to the `disabled-reason` attribute.
|
|
28
30
|
*/
|
|
29
31
|
this.disabledReason = '';
|
|
30
|
-
|
|
32
|
+
/** Whether `throttle-delay` lets a click through now; opens a new delay when it does. */
|
|
33
|
+
this.__throttleAllows = createActivationGate(() => this.throttleDelay);
|
|
34
|
+
/**
|
|
35
|
+
* Host click listener. Every activation reaches it once: a click on the inner control
|
|
36
|
+
* bubbling out, or a click fired at the host. It swallows a blocked click, and one inside the
|
|
37
|
+
* `throttle-delay` window, so later host listeners, ancestors' listeners and the form
|
|
38
|
+
* submitter (which checks `defaultPrevented`) never see it. A blocked click does not open a
|
|
39
|
+
* throttle window.
|
|
40
|
+
*/
|
|
41
|
+
this.__handleHostClick = (event) => {
|
|
42
|
+
if (this.__isClickBlocked() || !this.__throttleAllows()) {
|
|
43
|
+
// preventDefault() first: the dispatch hooks run the form submitter's afterDispatch()
|
|
44
|
+
// synchronously inside stopImmediatePropagation(), and it must see defaultPrevented.
|
|
45
|
+
event.preventDefault();
|
|
46
|
+
event.stopImmediatePropagation();
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
31
49
|
this.__dispatchClick(event);
|
|
32
50
|
};
|
|
51
|
+
this.addEventListener('click', this.__handleHostClick);
|
|
33
52
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Whether a click must be swallowed: it stops other listeners and the default action. A
|
|
55
|
+
* component returns `true` while it is soft-disabled, loading and so on.
|
|
56
|
+
*/
|
|
57
|
+
__isClickBlocked() {
|
|
58
|
+
return false;
|
|
39
59
|
}
|
|
40
60
|
}
|
|
41
61
|
__decorate([
|
|
@@ -173,4 +193,4 @@ function warnIfUnnamed(host, ariaLabel, ...otherNames) {
|
|
|
173
193
|
}
|
|
174
194
|
|
|
175
195
|
export { mixinBaseButton as a, iconButtonLabel as i, mixinButtonLevel as m, toggleButtonSelected as t, warnIfUnnamed as w };
|
|
176
|
-
//# sourceMappingURL=base-button-
|
|
196
|
+
//# sourceMappingURL=base-button-9tGu5RSC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-button-9tGu5RSC.js","sources":["../../src/button/base-button/base-button.ts"],"sourcesContent":["import { LitElement, PropertyValues } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { WithElementInternals } from '@/__internal/mixins/element-internals.js';\nimport { createActivationGate } from '@/__internal/utils/activation-gate.js';\nimport { warnOnce } from '@/__internal/utils/warn-once.js';\nimport { MixinBase, MixinReturn } from '@/__internal/mixins/mixin.js';\nimport type {\n ButtonColor,\n ButtonLevel,\n ButtonVariant,\n} from '@/button/ButtonTypes.js';\n\n/**\n * 1. Define an interface for the members the mixin adds.\n * This makes the type annotation much cleaner.\n */\nexport interface BaseButton {\n variant: string;\n\n color: string;\n\n disabled: boolean;\n\n softDisabled: boolean;\n\n disabledReason: string;\n\n throttleDelay?: number;\n\n __dispatchClick: (event: MouseEvent | KeyboardEvent) => void;\n\n __isClickBlocked(): boolean;\n}\n\nexport function mixinBaseButton<\n T extends MixinBase<LitElement & WithElementInternals>,\n>(base: T): MixinReturn<T, BaseButton> {\n abstract class BaseButtonElement extends base implements BaseButton {\n /** The visual style of the button, such as `\"filled\"`, `\"tonal\"`, `\"outlined\"` or `\"text\"`. */\n @property({ type: String, reflect: true })\n variant: string = '';\n\n /** The color role of the button, such as `\"primary\"`, `\"surface\"` or `\"danger\"`. */\n @property({ type: String, reflect: true })\n color: string = '';\n\n /**\n * When `true`, the button is disabled and cannot be interacted with. Reflects to the `disabled` attribute. Defaults to `false`.\n */\n @property({ type: Boolean, reflect: true })\n disabled: boolean = false;\n\n /**\n * When `true`, the button is visually styled as disabled and cannot be interacted with, but remains focusable.\n * Use this in combination with `disabledReason` to communicate why the button is unavailable.\n * Reflects to the `soft-disabled` attribute. Defaults to `false`.\n */\n @property({ type: Boolean, reflect: true, attribute: 'soft-disabled' })\n softDisabled: boolean = false;\n\n /**\n * A human-readable explanation of why the button is disabled or soft-disabled.\n * Rendered as a visually hidden tooltip and linked via `aria-describedby` for accessibility.\n * Maps to the `disabled-reason` attribute.\n */\n @property({ attribute: 'disabled-reason' })\n disabledReason: string = '';\n\n /**\n * Throttles activation by this many milliseconds: after a click, every click inside the delay\n * is swallowed (no `click` listeners, no form submit, no toggle). When undefined (default), no\n * throttle is applied.\n */\n @property({ type: Number, attribute: 'throttle-delay' })\n throttleDelay?: number;\n\n /** Whether `throttle-delay` lets a click through now; opens a new delay when it does. */\n private readonly __throttleAllows = createActivationGate(\n () => this.throttleDelay,\n );\n\n abstract __dispatchClick: (event: MouseEvent | KeyboardEvent) => void;\n\n // Mixins must have a constructor with `...args: any[]`\n // tslint:disable-next-line:no-any\n constructor(...args: any[]) {\n super(...args);\n this.addEventListener('click', this.__handleHostClick);\n }\n\n /**\n * Whether a click must be swallowed: it stops other listeners and the default action. A\n * component returns `true` while it is soft-disabled, loading and so on.\n */\n __isClickBlocked() {\n return false;\n }\n\n /**\n * Host click listener. Every activation reaches it once: a click on the inner control\n * bubbling out, or a click fired at the host. It swallows a blocked click, and one inside the\n * `throttle-delay` window, so later host listeners, ancestors' listeners and the form\n * submitter (which checks `defaultPrevented`) never see it. A blocked click does not open a\n * throttle window.\n */\n private __handleHostClick = (event: MouseEvent) => {\n if (this.__isClickBlocked() || !this.__throttleAllows()) {\n // preventDefault() first: the dispatch hooks run the form submitter's afterDispatch()\n // synchronously inside stopImmediatePropagation(), and it must see defaultPrevented.\n event.preventDefault();\n event.stopImmediatePropagation();\n return;\n }\n this.__dispatchClick(event);\n };\n }\n\n return BaseButtonElement;\n}\n\n// ── Level ────────────────────────────────────────────────────────────────────\n\n/**\n * What each `level` preset resolves to, shared by `wc-button`, `wc-icon-button` and\n * `wc-link-button`. A `color` or `variant` the consumer sets wins over the preset, one property at\n * a time, so `level=\"danger\" variant=\"outlined\"` is an outlined danger button.\n */\nexport const BUTTON_LEVEL_APPEARANCE: Readonly<\n Record<\n ButtonLevel,\n { readonly color: ButtonColor; readonly variant: ButtonVariant }\n >\n> = {\n primary: { color: 'primary', variant: 'filled' },\n secondary: { color: 'surface', variant: 'tonal' },\n tertiary: { color: 'primary', variant: 'text' },\n danger: { color: 'danger', variant: 'filled' },\n};\n\n/** Variant and color used when neither the consumer nor a `level` sets one. */\nexport const BUTTON_DEFAULT_APPEARANCE = {\n color: 'primary',\n variant: 'filled',\n} as const satisfies { color: ButtonColor; variant: ButtonVariant };\n\n/** The preset for `level`, or `undefined` for no level or an unknown one. */\nexport function levelAppearance(\n level: string | undefined | null,\n):\n | { readonly color: ButtonColor; readonly variant: ButtonVariant }\n | undefined {\n if (\n !level ||\n !Object.prototype.hasOwnProperty.call(BUTTON_LEVEL_APPEARANCE, level)\n )\n return undefined;\n return BUTTON_LEVEL_APPEARANCE[level as ButtonLevel];\n}\n\n/** The members `mixinButtonLevel` adds. */\nexport interface ButtonLevelAppearance {\n /**\n * Preset of `color` and `variant`: `primary` (primary, filled), `secondary` (surface, tonal),\n * `tertiary` (primary, text), `danger` (danger, filled). A `color` or `variant` set on the\n * element wins over the preset.\n */\n level?: ButtonLevel;\n\n /** The visual style. Reads back the resolved value: the one set, else the level's, else `filled`. */\n variant: ButtonVariant;\n\n /** The color role. Reads back the resolved value: the one set, else the level's, else `primary`. */\n color: ButtonColor;\n}\n\n/**\n * Adds `level` and resolves `variant` and `color` from it at render time. The `variant` and\n * `color` attributes reflect the resolved values (the styles key on them), but the level never\n * writes the consumer's own values, so a later change to `level` takes effect and an explicit\n * `color`/`variant` always wins.\n */\nexport function mixinButtonLevel<T extends MixinBase<LitElement & BaseButton>>(\n base: T,\n): MixinReturn<T, ButtonLevelAppearance> {\n abstract class ButtonLevelElement\n extends base\n implements ButtonLevelAppearance\n {\n /**\n * Preset of `color` and `variant`: `primary` (primary, filled), `secondary` (surface, tonal),\n * `tertiary` (primary, text), `danger` (danger, filled). A `color` or `variant` set on the\n * element wins over the preset.\n */\n @property({ type: String }) level?: ButtonLevel;\n\n /**\n * The visual style of the button: `\"filled\"`, `\"tonal\"`, `\"outlined\"`, `\"text\"`,\n * `\"elevated\"` or `\"neo\"`. Unset, it comes from `level`, else `\"filled\"`.\n */\n @property({ type: String, reflect: true })\n get variant(): ButtonVariant {\n return (\n this.__explicitVariant ||\n levelAppearance(this.level)?.variant ||\n BUTTON_DEFAULT_APPEARANCE.variant\n );\n }\n\n set variant(value: ButtonVariant) {\n this.__explicitVariant = value || undefined;\n }\n\n /**\n * The color role of the button. Unset, it comes from `level`, else `\"primary\"`.\n */\n @property({ type: String, reflect: true })\n get color(): ButtonColor {\n return (\n this.__explicitColor ||\n levelAppearance(this.level)?.color ||\n BUTTON_DEFAULT_APPEARANCE.color\n );\n }\n\n set color(value: ButtonColor) {\n this.__explicitColor = value || undefined;\n }\n\n __explicitVariant?: ButtonVariant;\n\n __explicitColor?: ButtonColor;\n\n override willUpdate(changedProperties: PropertyValues) {\n super.willUpdate(changedProperties);\n // The level changes the resolved values without going through their setters, so ask Lit\n // to reflect them (also on the first update, when nothing has set them yet).\n if (!this.hasUpdated || changedProperties.has('level')) {\n this.requestUpdate('variant', undefined);\n this.requestUpdate('color', undefined);\n }\n }\n }\n\n return ButtonLevelElement;\n}\n\n// ── Toggle ───────────────────────────────────────────────────────────────────\n\n/** A button that can act as a toggle: `toggle` turns it on, `selected` is its pressed state. */\nexport interface ToggleableButton extends HTMLElement {\n toggle: boolean;\n selected: boolean;\n disabled: boolean;\n}\n\n/**\n * Flips `selected` on a toggle button and fires `change` with the new state. Does nothing unless\n * `toggle` is set or while the button is disabled; callers block soft-disabled and loading first.\n */\nexport function toggleButtonSelected(host: ToggleableButton): void {\n if (!host.toggle || host.disabled) return;\n host.selected = !host.selected;\n host.dispatchEvent(\n new CustomEvent<{ selected: boolean }>('change', {\n detail: { selected: host.selected },\n bubbles: true,\n composed: true,\n }),\n );\n}\n\n// ── Accessible name ──────────────────────────────────────────────────────────\n\n/**\n * The name an icon-only button falls back to: its `aria-label`, else its tooltip text.\n */\nexport function iconButtonLabel(\n ariaLabel: string | null | undefined,\n tooltip: string | undefined,\n): string | undefined {\n return ariaLabel || tooltip || undefined;\n}\n\n/**\n * Warns once per tag when an icon-only button has nothing to be announced by: no `aria-label`,\n * no `aria-labelledby`, no `tooltip` and no slotted text.\n */\nexport function warnIfUnnamed(\n host: HTMLElement,\n ariaLabel: string | null | undefined,\n ...otherNames: (string | null | undefined)[]\n): void {\n if (ariaLabel || otherNames.some(name => !!name)) return;\n if (host.hasAttribute('aria-labelledby')) return;\n if (host.hasAttribute('data-aria-labelledby')) return;\n if (host.textContent?.trim()) return;\n const tag = host.localName;\n warnOnce(\n `${tag}:accessible-name`,\n `[peacock] ${tag} has no accessible name, so screen readers announce it as just \"button\". Give it an aria-label or a tooltip.`,\n );\n}\n"],"names":["property"],"mappings":";;;;;AAkCM,SAAU,eAAe,CAE7B,IAAO,EAAA;IACP,MAAe,iBAAkB,SAAQ,IAAI,CAAA;;;AAgD3C,QAAA,WAAA,CAAY,GAAG,IAAW,EAAA;AACxB,YAAA,KAAK,CAAC,GAAG,IAAI,CAAC;;YA9ChB,IAAA,CAAA,OAAO,GAAW,EAAE;;YAIpB,IAAA,CAAA,KAAK,GAAW,EAAE;AAElB;;AAEG;YAEH,IAAA,CAAA,QAAQ,GAAY,KAAK;AAEzB;;;;AAIG;YAEH,IAAA,CAAA,YAAY,GAAY,KAAK;AAE7B;;;;AAIG;YAEH,IAAA,CAAA,cAAc,GAAW,EAAE;;YAWV,IAAA,CAAA,gBAAgB,GAAG,oBAAoB,CACtD,MAAM,IAAI,CAAC,aAAa,CACzB;AAmBD;;;;;;AAMG;AACK,YAAA,IAAA,CAAA,iBAAiB,GAAG,CAAC,KAAiB,KAAI;gBAChD,IAAI,IAAI,CAAC,gBAAgB,EAAE,IAAI,CAAC,IAAI,CAAC,gBAAgB,E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CAAC,QAAQ;AAC9B,IAAA,IAAI,CAAC,aAAa,CAChB,IAAI,WAAW,CAAwB,QAAQ,EAAE;AAC/C,QAAA,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE;AACnC,QAAA,OAAO,EAAE,IAAI;AACb,QAAA,QAAQ,EAAE,IAAI;AACf,KAAA,CAAC,CACH;AACH;AAEA;AAEA;;AAEG;AACG,SAAU,eAAe,CAC7B,SAAoC,EACpC,OAA2B,EAAA;AAE3B,IAAA,OAAO,SAAS,IAAI,OAAO,IAAI,SAAS;AAC1C;AAEA;;;AAGG;AACG,SAAU,aAAa,CAC3B,IAAiB,EACjB,SAAoC,EACpC,GAAG,UAAyC,EAAA;AAE5C,IAAA,IAAI,SAAS,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC;QAAE;AAClD,IAAA,IAAI,IAAI,CAAC,YAAY,CAAC,iBAAiB,CAAC;QAAE;AAC1C,IAAA,IAAI,IAAI,CAAC,YAAY,CAAC,sBAAsB,CAAC;QAAE;AAC/C,IAAA,IAAI,IAAI,CAAC,WAAW,EAAE,IAAI,EAAE;QAAE;AAC9B,IAAA,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS;IAC1B,QAAQ,CACN,GAAG,GAAG,CAAA,gBAAA,CAAkB,EACxB,CAAA,UAAA,EAAa,GAAG,CAAA,4GAAA,CAA8G,CAC/H;AACH;;;;"}
|
package/dist/button-group.js
CHANGED
|
@@ -9,12 +9,14 @@ import './directive-ZPhl09Yt.js';
|
|
|
9
9
|
import './if-defined-D9DEJR_6.js';
|
|
10
10
|
import './when-DEJm_QN9.js';
|
|
11
11
|
import './observe-slot-change-DPxaZrZF.js';
|
|
12
|
-
import './
|
|
12
|
+
import './dispatch-event-utils-DfgqVBK8.js';
|
|
13
13
|
import './ButtonConstants-CahP2_NA.js';
|
|
14
14
|
import './delegate-Bw2wdPFP.js';
|
|
15
|
-
import './form-submitter-
|
|
15
|
+
import './form-submitter-BIFqZ0wq.js';
|
|
16
|
+
import './dispatch-hooks-J_godlHh.js';
|
|
16
17
|
import './element-internals-QME0yEz4.js';
|
|
17
|
-
import './base-button-
|
|
18
|
+
import './base-button-9tGu5RSC.js';
|
|
19
|
+
import './activation-gate-D4IpmwyD.js';
|
|
18
20
|
import './warn-once-BNxX1Y98.js';
|
|
19
21
|
import './form-associated-BHbg72PG.js';
|
|
20
22
|
import './is-link-Dk2OV3PM.js';
|
package/dist/button-group.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"button-group.js","sources":["../../src/button/button-group/button-group.ts"],"sourcesContent":["import { html, LitElement } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport IndividualComponent from '@/IndividualComponent.js';\nimport styles from './button-group.scss';\nimport { Button, ButtonColor } from '../button/button.js';\nimport { IconButton } from '../icon-button/icon-button.js';\n\n/**\n * @label Button Group\n * @tag wc-button-group\n * @rawTag button-group\n *\n * @summary A row of related buttons or icon buttons that share one size, color and style.\n *\n * @overview\n * <p>Put <code>wc-button</code> or <code>wc-icon-button</code> elements inside. The group passes\n * its <code>size</code> (<code>sm</code> by default), and its <code>color</code> and\n * <code>variant</code> when set, to every button, overriding what the buttons set themselves.</p>\n * <p>By default the buttons sit with a small gap between them. With <code>connected</code> they sit\n * 2px apart with rounded outer corners, for a set such as bold, italic and underline toggles.</p>\n * <p>The group is layout only: it adds no group role, keyboard handling or selection, so each\n * button keeps its own focus stop and toggle state. For choosing one or several options from a\n * set use <code>wc-segmented-button-group</code>.</p>\n *\n * @example\n * ```html\n * <wc-button-group connected>\n * <wc-icon-button toggle=\"true\" shape=\"wide\" selected>\n * <wc-icon name=\"format_bold\"></wc-icon>\n * </wc-icon-button>\n * <wc-icon-button toggle=\"true\" shape=\"wide\">\n * <wc-icon name=\"format_italic\"></wc-icon>\n * </wc-icon-button>\n * <wc-icon-button toggle=\"true\" shape=\"wide\">\n * <wc-icon name=\"format_underlined\"></wc-icon>\n * </wc-icon-button>\n * </wc-button-group>\n * ```\n *\n * @tags controls\n */\n@IndividualComponent\nclass ButtonGroup extends LitElement {\n // Lit prefers CSS-in-JS for better performance and scoping.\n // If you prefer keeping the SCSS file, you'll need a build tool (like Vite or Webpack)\n // that can import .scss files as lit-css.\n static styles = [styles];\n\n static Button = Button;\n\n static IconButton = IconButton;\n\n /**\n * Button size.\n * Possible values are `\"xs\"`, `\"sm\"`, `\"md\"`, `\"lg\"`, `\"xl\"`. Defaults to `\"sm\"`.\n */\n @property({ reflect: true }) size: 'xs' | 'sm' | 'md' | 'lg' | 'xl' = 'sm';\n\n /**\n * Layout variant of the button group.\n * `\"standard\"` shows buttons with a small gap between them.\n * `\"connected\"` places buttons with a 2px gap;\n * rounded outer corners and middle buttons keep standard rounded corners.\n * Defaults to `\"standard\"`.\n */\n @property({ type: Boolean, reflect: true }) connected = false;\n\n /**\n * Color applied to all buttons in the group.\n * Possible values are `\"primary\"`, `\"success\"`, `\"danger\"`, `\"warning\"`, `\"surface\"`, `\"on-surface\"`.\n */\n @property({ reflect: true }) color?: ButtonColor;\n\n /**\n * Visual style applied to all buttons in the group.\n * Possible values are `\"filled\"`, `\"tonal\"`, `\"outlined\"`.\n */\n @property({ attribute: 'variant', reflect: true }) variant?:\n | 'filled'\n | 'tonal'\n | 'outlined';\n\n override updated() {\n this._syncButtonProperties();\n }\n\n private _getSlottedElements(): HTMLElement[] {\n const slot = this.shadowRoot?.querySelector('slot');\n return (slot?.assignedElements({ flatten: true }) ?? []) as HTMLElement[];\n }\n\n private _syncButtonProperties() {\n const children = this._getSlottedElements();\n children.forEach((child, index) => {\n ['color', 'variant', 'toggle', 'size'].forEach(prop => {\n // @ts-ignore\n if (this[prop] && prop in child) {\n // @ts-ignore\n (child as any)[prop] = this[prop];\n }\n });\n });\n }\n\n render() {\n return html`\n <slot @slotchange=${() => this._syncButtonProperties()}></slot>\n `;\n }\n}\n\nexport default ButtonGroup;\n"],"names":["LitElement","html","styles","property"],"mappings":"
|
|
1
|
+
{"version":3,"file":"button-group.js","sources":["../../src/button/button-group/button-group.ts"],"sourcesContent":["import { html, LitElement } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport IndividualComponent from '@/IndividualComponent.js';\nimport styles from './button-group.scss';\nimport { Button, ButtonColor } from '../button/button.js';\nimport { IconButton } from '../icon-button/icon-button.js';\n\n/**\n * @label Button Group\n * @tag wc-button-group\n * @rawTag button-group\n *\n * @summary A row of related buttons or icon buttons that share one size, color and style.\n *\n * @overview\n * <p>Put <code>wc-button</code> or <code>wc-icon-button</code> elements inside. The group passes\n * its <code>size</code> (<code>sm</code> by default), and its <code>color</code> and\n * <code>variant</code> when set, to every button, overriding what the buttons set themselves.</p>\n * <p>By default the buttons sit with a small gap between them. With <code>connected</code> they sit\n * 2px apart with rounded outer corners, for a set such as bold, italic and underline toggles.</p>\n * <p>The group is layout only: it adds no group role, keyboard handling or selection, so each\n * button keeps its own focus stop and toggle state. For choosing one or several options from a\n * set use <code>wc-segmented-button-group</code>.</p>\n *\n * @example\n * ```html\n * <wc-button-group connected>\n * <wc-icon-button toggle=\"true\" shape=\"wide\" selected>\n * <wc-icon name=\"format_bold\"></wc-icon>\n * </wc-icon-button>\n * <wc-icon-button toggle=\"true\" shape=\"wide\">\n * <wc-icon name=\"format_italic\"></wc-icon>\n * </wc-icon-button>\n * <wc-icon-button toggle=\"true\" shape=\"wide\">\n * <wc-icon name=\"format_underlined\"></wc-icon>\n * </wc-icon-button>\n * </wc-button-group>\n * ```\n *\n * @tags controls\n */\n@IndividualComponent\nclass ButtonGroup extends LitElement {\n // Lit prefers CSS-in-JS for better performance and scoping.\n // If you prefer keeping the SCSS file, you'll need a build tool (like Vite or Webpack)\n // that can import .scss files as lit-css.\n static styles = [styles];\n\n static Button = Button;\n\n static IconButton = IconButton;\n\n /**\n * Button size.\n * Possible values are `\"xs\"`, `\"sm\"`, `\"md\"`, `\"lg\"`, `\"xl\"`. Defaults to `\"sm\"`.\n */\n @property({ reflect: true }) size: 'xs' | 'sm' | 'md' | 'lg' | 'xl' = 'sm';\n\n /**\n * Layout variant of the button group.\n * `\"standard\"` shows buttons with a small gap between them.\n * `\"connected\"` places buttons with a 2px gap;\n * rounded outer corners and middle buttons keep standard rounded corners.\n * Defaults to `\"standard\"`.\n */\n @property({ type: Boolean, reflect: true }) connected = false;\n\n /**\n * Color applied to all buttons in the group.\n * Possible values are `\"primary\"`, `\"success\"`, `\"danger\"`, `\"warning\"`, `\"surface\"`, `\"on-surface\"`.\n */\n @property({ reflect: true }) color?: ButtonColor;\n\n /**\n * Visual style applied to all buttons in the group.\n * Possible values are `\"filled\"`, `\"tonal\"`, `\"outlined\"`.\n */\n @property({ attribute: 'variant', reflect: true }) variant?:\n | 'filled'\n | 'tonal'\n | 'outlined';\n\n override updated() {\n this._syncButtonProperties();\n }\n\n private _getSlottedElements(): HTMLElement[] {\n const slot = this.shadowRoot?.querySelector('slot');\n return (slot?.assignedElements({ flatten: true }) ?? []) as HTMLElement[];\n }\n\n private _syncButtonProperties() {\n const children = this._getSlottedElements();\n children.forEach((child, index) => {\n ['color', 'variant', 'toggle', 'size'].forEach(prop => {\n // @ts-ignore\n if (this[prop] && prop in child) {\n // @ts-ignore\n (child as any)[prop] = this[prop];\n }\n });\n });\n }\n\n render() {\n return html`\n <slot @slotchange=${() => this._syncButtonProperties()}></slot>\n `;\n }\n}\n\nexport default ButtonGroup;\n"],"names":["LitElement","html","styles","property"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCG;AAEH,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQA,GAAU,CAAA;AAApC,IAAA,WAAA,GAAA;;AAUE;;;AAGG;QAC0B,IAAA,CAAA,IAAI,GAAqC,IAAI;A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AI,EAAE;AAAoB,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,WAAA,EAAA,MAAA,CAAA;AAMjC,UAAA,CAAA;AAA5B,IAAAA,CAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE;AAAsB,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,OAAA,EAAA,MAAA,CAAA;AAME,UAAA,CAAA;IAAlDA,CAAQ,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE;AAGlC,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,SAAA,EAAA,MAAA,CAAA;AAtCX,WAAW,GAAA,UAAA,CAAA;IADhB;AACK,CAAA,EAAA,WAAW,CAmEhB;AAED,oBAAe,WAAW;;;;"}
|
package/dist/button.js
CHANGED
|
@@ -5,15 +5,17 @@ import { e } from './class-map-NDIkZErE.js';
|
|
|
5
5
|
import { o } from './if-defined-D9DEJR_6.js';
|
|
6
6
|
import { n } from './when-DEJm_QN9.js';
|
|
7
7
|
import { o as observerSlotChangesWithCallback } from './observe-slot-change-DPxaZrZF.js';
|
|
8
|
-
import { i as isActivationClick, d as dispatchActivationClick } from './
|
|
8
|
+
import { i as isActivationClick, d as dispatchActivationClick } from './dispatch-event-utils-DfgqVBK8.js';
|
|
9
9
|
import { D as DISABLED_REASON_ID } from './ButtonConstants-CahP2_NA.js';
|
|
10
10
|
import { m as mixinDelegatesAria } from './delegate-Bw2wdPFP.js';
|
|
11
|
-
import { m as mixinFormSubmitter } from './form-submitter-
|
|
11
|
+
import { m as mixinFormSubmitter } from './form-submitter-BIFqZ0wq.js';
|
|
12
12
|
import { m as mixinElementInternals } from './element-internals-QME0yEz4.js';
|
|
13
|
-
import { m as mixinButtonLevel, a as mixinBaseButton, t as toggleButtonSelected } from './base-button-
|
|
13
|
+
import { m as mixinButtonLevel, a as mixinBaseButton, t as toggleButtonSelected } from './base-button-9tGu5RSC.js';
|
|
14
14
|
import { m as mixinFormAssociated } from './form-associated-BHbg72PG.js';
|
|
15
15
|
import './base-Cl6v8-BZ.js';
|
|
16
16
|
import './directive-ZPhl09Yt.js';
|
|
17
|
+
import './dispatch-hooks-J_godlHh.js';
|
|
18
|
+
import './activation-gate-D4IpmwyD.js';
|
|
17
19
|
import './warn-once-BNxX1Y98.js';
|
|
18
20
|
|
|
19
21
|
var css_248z = i`.button {
|
|
@@ -952,9 +954,9 @@ var css_248z = i`.button {
|
|
|
952
954
|
* @tags display
|
|
953
955
|
*/
|
|
954
956
|
let Button = class Button extends mixinButtonLevel(mixinBaseButton(mixinDelegatesAria(mixinFormSubmitter(mixinFormAssociated(mixinElementInternals(i$1)))))) {
|
|
955
|
-
// ── Constructor ───────────────────────────────────────────────────────────
|
|
956
957
|
constructor() {
|
|
957
|
-
|
|
958
|
+
// ── Static ───────────────────────────────────────────────────────────────
|
|
959
|
+
super(...arguments);
|
|
958
960
|
// ── Properties ───────────────────────────────────────────────────────────
|
|
959
961
|
/**
|
|
960
962
|
* When `true`, the icon is placed after the label (trailing).
|
|
@@ -987,16 +989,7 @@ let Button = class Button extends mixinButtonLevel(mixinBaseButton(mixinDelegate
|
|
|
987
989
|
this.__iconSlotCleanup = null;
|
|
988
990
|
/** Cleanup returned by observerSlotChangesWithCallback for the label slot. */
|
|
989
991
|
this.__labelSlotCleanup = null;
|
|
990
|
-
// ── Private methods ───────────────────────────────────────────────────────
|
|
991
992
|
this.__dispatchClick = (event) => {
|
|
992
|
-
// If the button is soft-disabled or loading, we need to explicitly prevent
|
|
993
|
-
// the click from propagating to other event listeners as well as prevent
|
|
994
|
-
// the default action.
|
|
995
|
-
if (this.softDisabled || this.loading || this.skeleton) {
|
|
996
|
-
event.stopImmediatePropagation();
|
|
997
|
-
event.preventDefault();
|
|
998
|
-
return;
|
|
999
|
-
}
|
|
1000
993
|
// Each activation reaches this listener once: either the inner button's
|
|
1001
994
|
// click bubbling out, or a click fired at the host and forwarded below.
|
|
1002
995
|
toggleButtonSelected(this);
|
|
@@ -1006,7 +999,6 @@ let Button = class Button extends mixinButtonLevel(mixinBaseButton(mixinDelegate
|
|
|
1006
999
|
this.focus();
|
|
1007
1000
|
dispatchActivationClick(this.buttonElement);
|
|
1008
1001
|
};
|
|
1009
|
-
this.addEventListener('click', this.__dispatchClickWithThrottle);
|
|
1010
1002
|
}
|
|
1011
1003
|
// ── Lifecycle ─────────────────────────────────────────────────────────────
|
|
1012
1004
|
disconnectedCallback() {
|
|
@@ -1049,6 +1041,11 @@ let Button = class Button extends mixinButtonLevel(mixinBaseButton(mixinDelegate
|
|
|
1049
1041
|
blur() {
|
|
1050
1042
|
this.buttonElement?.blur();
|
|
1051
1043
|
}
|
|
1044
|
+
// ── Private methods ───────────────────────────────────────────────────────
|
|
1045
|
+
/** A soft-disabled, loading or skeleton button swallows clicks. */
|
|
1046
|
+
__isClickBlocked() {
|
|
1047
|
+
return this.softDisabled || this.loading || this.skeleton;
|
|
1048
|
+
}
|
|
1052
1049
|
// ── Render helpers ────────────────────────────────────────────────────────
|
|
1053
1050
|
renderButtonElement() {
|
|
1054
1051
|
const cssClasses = {
|
|
@@ -1125,7 +1122,6 @@ let Button = class Button extends mixinButtonLevel(mixinBaseButton(mixinDelegate
|
|
|
1125
1122
|
`;
|
|
1126
1123
|
}
|
|
1127
1124
|
};
|
|
1128
|
-
// ── Static ───────────────────────────────────────────────────────────────
|
|
1129
1125
|
/** @nocollapse */ // eslint-disable-next-line
|
|
1130
1126
|
Button.shadowRootOptions = {
|
|
1131
1127
|
mode: 'open',
|