@internetarchive/elements 1.11.0 → 1.11.1-webdev-10173.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.
@@ -12,7 +12,7 @@ import '../ia-status-indicator/ia-status-indicator.js';
12
12
  *
13
13
  * The inner `<button>` takes focus, so that's where its role and ARIA state
14
14
  * belong. Set them with the `role`, `ariaChecked`, `ariaDisabled`,
15
- * `ariaHasPopup`, `ariaExpanded` and `ariaBusy` properties, e.g.
15
+ * `ariaHasPopup`, `ariaExpanded`, `ariaBusy` and `ariaCurrent` properties, e.g.
16
16
  * `<ia-button .role=${'menuitemcheckbox'} .ariaChecked=${'false'}>`. These
17
17
  * shadow the native ARIA reflection properties, so nothing lands on the host
18
18
  * and a screen reader hears the role or state once. `null`, `undefined` and
@@ -47,9 +47,18 @@ export declare class IAButton extends LitElement {
47
47
  ariaHasPopup: string | null;
48
48
  ariaExpanded: string | null;
49
49
  ariaBusy: string | null;
50
+ ariaCurrent: string | null;
50
51
  description: string;
51
52
  render(): TemplateResult;
52
53
  protected willUpdate(changed: PropertyValues): void;
54
+ /**
55
+ * Sets the role and ARIA state on the inner button, following the value
56
+ * rules in the class comment. They're set here rather than bound in the
57
+ * template because lit-plugin checks each `aria-*` binding against that
58
+ * attribute's allowed values, which these string-typed properties can't
59
+ * satisfy. A subclass that overrides this must call `super.updated()`.
60
+ */
61
+ protected updated(changed: PropertyValues): void;
53
62
  private get buttonTemplate();
54
63
  private get descriptionTemplate();
55
64
  private get buttonTextTemplate();
@@ -1 +1 @@
1
- {"version":3,"file":"ia-button.d.ts","sourceRoot":"","sources":["../../../../src/elements/ia-button/ia-button.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EACV,cAAc,EACd,cAAc,EAGd,cAAc,EAEf,MAAM,KAAK,CAAC;AAKb,OAAO,4CAA4C,CAAC;AAapD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,qBACa,QAAS,SAA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c9B;;;OAGG;IACH,OAAO,CAAC,oBAAoB;IAiB5B;;;;;;;;OAQG;IACH,OAAO,CAAC,eAAe;IAevB,sFAAsF;IACtF,OAAO,CAAC,iBAAiB;IAwBzB,MAAM,KAAK,MAAM,IAAI,cAAc,CAkNlC;CACF"}
@@ -4,16 +4,16 @@ import { property } from 'lit/decorators.js';
4
4
  import { customElement } from '../../utils/custom-element.js';
5
5
  import themeStyles from '../../themes/theme-styles.js';
6
6
  import '../ia-status-indicator/ia-status-indicator.js';
7
- /**
8
- * An ARIA property's value as an attribute value. `null`, `undefined` and `''`
9
- * leave the attribute off. Anything else, a boolean `false` from an untyped
10
- * binding included, is stringified, so `aria-expanded` can still say "false".
11
- */
12
- function ariaValue(value) {
13
- return value === null || value === undefined || value === ''
14
- ? nothing
15
- : String(value);
16
- }
7
+ /** The properties set on the inner button, and the attribute each one sets */
8
+ const INNER_BUTTON_ARIA = [
9
+ ['role', 'role'],
10
+ ['ariaChecked', 'aria-checked'],
11
+ ['ariaDisabled', 'aria-disabled'],
12
+ ['ariaHasPopup', 'aria-haspopup'],
13
+ ['ariaExpanded', 'aria-expanded'],
14
+ ['ariaBusy', 'aria-busy'],
15
+ ['ariaCurrent', 'aria-current'],
16
+ ];
17
17
  /**
18
18
  * Renders a standardized button built off the ia-button styling and the activity indicator, with the option to show
19
19
  * a loading indicator instead of the text or to customize the text, and the ability to pass in any
@@ -26,7 +26,7 @@ function ariaValue(value) {
26
26
  *
27
27
  * The inner `<button>` takes focus, so that's where its role and ARIA state
28
28
  * belong. Set them with the `role`, `ariaChecked`, `ariaDisabled`,
29
- * `ariaHasPopup`, `ariaExpanded` and `ariaBusy` properties, e.g.
29
+ * `ariaHasPopup`, `ariaExpanded`, `ariaBusy` and `ariaCurrent` properties, e.g.
30
30
  * `<ia-button .role=${'menuitemcheckbox'} .ariaChecked=${'false'}>`. These
31
31
  * shadow the native ARIA reflection properties, so nothing lands on the host
32
32
  * and a screen reader hears the role or state once. `null`, `undefined` and
@@ -71,6 +71,7 @@ let IAButton = class IAButton extends LitElement {
71
71
  this.ariaHasPopup = null;
72
72
  this.ariaExpanded = null;
73
73
  this.ariaBusy = null;
74
+ this.ariaCurrent = null;
74
75
  /* The inner button's accessible description, e.g. "List full" */
75
76
  this.description = '';
76
77
  }
@@ -93,18 +94,34 @@ let IAButton = class IAButton extends LitElement {
93
94
  this.setButtonTypeEmulation();
94
95
  }
95
96
  }
97
+ /**
98
+ * Sets the role and ARIA state on the inner button, following the value
99
+ * rules in the class comment. They're set here rather than bound in the
100
+ * template because lit-plugin checks each `aria-*` binding against that
101
+ * attribute's allowed values, which these string-typed properties can't
102
+ * satisfy. A subclass that overrides this must call `super.updated()`.
103
+ */
104
+ updated(changed) {
105
+ super.updated(changed);
106
+ const button = this.shadowRoot?.querySelector('button');
107
+ if (!button)
108
+ return;
109
+ for (const [prop, attr] of INNER_BUTTON_ARIA) {
110
+ const value = this[prop];
111
+ if (value === null || value === undefined || value === '') {
112
+ button.removeAttribute(attr);
113
+ }
114
+ else {
115
+ button.setAttribute(attr, String(value));
116
+ }
117
+ }
118
+ }
96
119
  /* The native button to render */
97
120
  get buttonTemplate() {
98
121
  return html `<button
99
122
  part="button"
100
123
  class=${this.mode}
101
124
  ?disabled=${this.disabled || this.loading}
102
- role=${ariaValue(this.role)}
103
- aria-checked=${ariaValue(this.ariaChecked)}
104
- aria-disabled=${ariaValue(this.ariaDisabled)}
105
- aria-haspopup=${ariaValue(this.ariaHasPopup)}
106
- aria-expanded=${ariaValue(this.ariaExpanded)}
107
- aria-busy=${ariaValue(this.ariaBusy)}
108
125
  aria-describedby=${this.description ? 'description' : nothing}
109
126
  >
110
127
  ${this.buttonTextTemplate}
@@ -154,9 +171,11 @@ let IAButton = class IAButton extends LitElement {
154
171
  const formActionsInProgress = e instanceof CustomEvent && e.detail.formActionsInProgress;
155
172
  if (formActionsInProgress)
156
173
  return;
157
- // Request form submission/reset by clicking the hidden native submit/reset button we added earlier
174
+ // Request form submission/reset by clicking the hidden native submit/reset button we added earlier.
175
+ // Uses click() because Firefox ESR 115 and 128 don't run a submit input's
176
+ // activation behavior for a dispatched PointerEvent.
158
177
  const hiddenButton = this.querySelector('input.hidden-button');
159
- hiddenButton.dispatchEvent(new PointerEvent('click'));
178
+ hiddenButton.click();
160
179
  }
161
180
  /**
162
181
  * Adds a hidden button to the light DOM to
@@ -454,6 +473,9 @@ __decorate([
454
473
  __decorate([
455
474
  property({ attribute: false })
456
475
  ], IAButton.prototype, "ariaBusy", void 0);
476
+ __decorate([
477
+ property({ attribute: false })
478
+ ], IAButton.prototype, "ariaCurrent", void 0);
457
479
  __decorate([
458
480
  property({ type: String })
459
481
  ], IAButton.prototype, "description", void 0);
@@ -1 +1 @@
1
- {"version":3,"file":"ia-button.js","sourceRoot":"","sources":["../../../../src/elements/ia-button/ia-button.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,IAAI,EACJ,UAAU,EAGV,GAAG,EACH,OAAO,EAEP,MAAM,GACP,MAAM,KAAK,CAAC;AACb,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,WAAW,MAAM,0BAA0B,CAAC;AAEnD,OAAO,4CAA4C,CAAC;AAEpD;;;;GAIG;AACH,SAAS,SAAS,CAAC,KAAc;IAC/B,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE;QAC1D,CAAC,CAAC,OAAO;QACT,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACpB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEI,IAAM,QAAQ,GAAd,MAAM,QAAS,SAAQ,UAAU;IAAjC;;QAML,4CAA4C;QAChB,SAAI,GASZ,SAAS,CAAC;QAE9B,+DAA+D;QAClC,YAAO,GAAY,KAAK,CAAC;QAEtD,4EAA4E;QAC/C,aAAQ,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import { property } from 'lit/decorators.js';\nimport { customElement } from '@src/utils/custom-element';\nimport themeStyles from '@src/themes/theme-styles';\n\nimport '../ia-status-indicator/ia-status-indicator';\n\n/**\n * An ARIA property's value as an attribute value. `null`, `undefined` and `''`\n * leave the attribute off. Anything else, a boolean `false` from an untyped\n * binding included, is stringified, so `aria-expanded` can still say \"false\".\n */\nfunction ariaValue(value: unknown): string | typeof nothing {\n return value === null || value === undefined || value === ''\n ? nothing\n : String(value);\n}\n\n/**\n * Renders a standardized button built off the ia-button styling and the activity indicator, with the option to show\n * a loading indicator instead of the text or to customize the text, and the ability to pass in any\n * function to run on click.\n *\n * Designed to behave exactly like a native type=\"submit\" or type=\"reset\" button if either type is supplied,\n * i.e. for an <ia-button type=\"submit\" @click=${doSideEffects}></ia-button>,\n * whether the form is submitted via enter or by clicking the button directly, the button will always\n * run doSideEffects() and then submit the form.\n *\n * The inner `<button>` takes focus, so that's where its role and ARIA state\n * belong. Set them with the `role`, `ariaChecked`, `ariaDisabled`,\n * `ariaHasPopup`, `ariaExpanded` and `ariaBusy` properties, e.g.\n * `<ia-button .role=${'menuitemcheckbox'} .ariaChecked=${'false'}>`. These\n * shadow the native ARIA reflection properties, so nothing lands on the host\n * and a screen reader hears the role or state once. `null`, `undefined` and\n * `''` leave an attribute off; anything else, `false` included, is set as a\n * string. Note:\n * - A `role` or `aria-*` *attribute* written on `<ia-button>` stays on the\n * host, as before, and these properties don't read it back: with\n * `<ia-button aria-disabled=\"true\">`, `ariaDisabled` is `null`.\n * - Set them once `ia-button` is defined. Before that, the native setter\n * writes the attribute onto the host instead.\n *\n * `description` becomes the inner button's accessible description, e.g.\n * \"List full\". It isn't part of the button's name.\n *\n * Focus is delegated, so `focus()` on `<ia-button>` focuses the inner button.\n * With `href`, the wrapping link is the first thing that can take focus, so\n * it takes it instead; the ARIA properties and description stay on the\n * button.\n */\n@customElement('ia-button')\nexport class IAButton extends LitElement {\n static shadowRootOptions: ShadowRootInit = {\n ...LitElement.shadowRootOptions,\n delegatesFocus: true,\n };\n\n /* Which version of the button to display */\n @property({ type: String }) mode:\n | 'primary'\n | 'secondary'\n | 'danger'\n | 'warning'\n | 'disabled'\n | 'transparent'\n | 'custom'\n | 'link'\n | 'danger-link' = 'primary';\n\n /* Whether to show a loading indicator instead of the button */\n @property({ type: Boolean }) loading: boolean = false;\n\n /* Whether the button should be disabled, regardless of submission status */\n @property({ type: Boolean }) disabled: boolean = false;\n\n /* Optional text to include next to the loading indicator */\n @property({ type: String }) loadingText: string = '';\n\n /* Type of the button - defaults to 'button' to prevent form submission */\n @property({ type: String, reflect: true }) type:\n | 'button'\n | 'submit'\n | 'reset' = 'button';\n\n /* An optional href to wrap around the button */\n @property({ type: String }) href?: string;\n\n /* Whether to add a target=\"_blank\" to any wrapping link */\n @property({ type: Boolean }) openLinksNewTab: boolean = false;\n\n /*\n * Role and ARIA state for the inner button. Property-only (no attribute), so\n * the host doesn't expose them too. See the class comment.\n */\n @property({ attribute: false }) role: string | null = null;\n\n @property({ attribute: false }) ariaChecked: string | null = null;\n\n @property({ attribute: false }) ariaDisabled: string | null = null;\n\n @property({ attribute: false }) ariaHasPopup: string | null = null;\n\n @property({ attribute: false }) ariaExpanded: string | null = null;\n\n @property({ attribute: false }) ariaBusy: string | null = null;\n\n /* The inner button's accessible description, e.g. \"List full\" */\n @property({ type: String }) description: string = '';\n\n render(): TemplateResult {\n // No whitespace between the top-level nodes: a text node in the shadow\n // root renders as a space when the host is display:inline.\n const control = this.href\n ? html`<a\n href=${this.href}\n target=${this.openLinksNewTab ? '_blank' : '_self'}\n >${this.buttonTemplate}</a\n >`\n : this.buttonTemplate;\n return html`${control}${this.descriptionTemplate}<slot\n name=\"hidden-button\"\n ></slot>`;\n }\n\n protected willUpdate(changed: PropertyValues): void {\n if (changed.has('type')) {\n this.setButtonTypeEmulation();\n }\n }\n\n /* The native button to render */\n private get buttonTemplate(): TemplateResult {\n return html`<button\n part=\"button\"\n class=${this.mode}\n ?disabled=${this.disabled || this.loading}\n role=${ariaValue(this.role)}\n aria-checked=${ariaValue(this.ariaChecked)}\n aria-disabled=${ariaValue(this.ariaDisabled)}\n aria-haspopup=${ariaValue(this.ariaHasPopup)}\n aria-expanded=${ariaValue(this.ariaExpanded)}\n aria-busy=${ariaValue(this.ariaBusy)}\n aria-describedby=${this.description ? 'description' : nothing}\n >\n ${this.buttonTextTemplate}\n </button>`;\n }\n\n /*\n * The description, in the shadow root because aria-describedby can't point\n * across it. Outside the button, so it isn't part of the button's name, and\n * hidden, since aria-describedby still reads a hidden element.\n */\n private get descriptionTemplate(): TemplateResult | typeof nothing {\n if (!this.description) return nothing;\n return html`<span id=\"description\" hidden>${this.description}</span>`;\n }\n\n /* The text to render within the button */\n private get buttonTextTemplate(): TemplateResult {\n return this.loading ? this.loadingStateTemplate : html`<slot></slot>`;\n }\n\n /* Content to render while button is loading */\n private get loadingStateTemplate(): TemplateResult {\n return html`\n <span class=\"loading-indicator\" alt=\"Loading indicator\">\n <ia-status-indicator mode=\"loading\"></ia-status-indicator> ${this\n .loadingText}\n </span>\n `;\n }\n\n /** Sets up or removes button type emulation as needed */\n private setButtonTypeEmulation(): void {\n const hiddenButton: HTMLInputElement | null = this.querySelector(\n 'input.hidden-button',\n );\n\n if (hiddenButton) {\n hiddenButton.type = this.type;\n return;\n }\n\n this.addHiddenButton();\n this.addEventListener('click', this.handleComponentClick);\n }\n\n /**\n * Triggers form actions (submit/reset) on click, if desired\n * and if actions not already in progress\n */\n private handleComponentClick(e: Event): void {\n if (this.type === 'button') return;\n\n // No need to submit/reset the form if it's already submitting/resetting\n const formActionsInProgress =\n e instanceof CustomEvent && e.detail.formActionsInProgress;\n if (formActionsInProgress) return;\n\n // Request form submission/reset by clicking the hidden native submit/reset button we added earlier\n const hiddenButton = this.querySelector(\n 'input.hidden-button',\n ) as HTMLInputElement;\n hiddenButton.dispatchEvent(new PointerEvent('click'));\n }\n\n /**\n * Adds a hidden button to the light DOM to\n * emulate native reset/submit button behavior.\n *\n * Used for:\n * - Submitting/resetting the form (on behalf of handleComponentClick)\n * - Activating any component click events if form is submitted with the enter key\n * (via handleFormActions)\n */\n private addHiddenButton(): void {\n if (this.type === 'button') return;\n\n render(\n html`<input\n type=${this.type}\n class=\"hidden-button\"\n style=\"display:none\"\n slot=\"hidden-button\"\n @click=${(e: Event) => this.handleFormActions(e)}\n />`,\n this,\n );\n }\n\n /** Triggers the component's click event manually to prevent extra submission/reset */\n private handleFormActions(e: Event): void {\n /**\n * Prevents the event from bubbling up to the ia-button component itself.\n * This way, if the click on this button is triggered by a click on the component,\n * we don't accidentally bubble up a second click and end up in an infinite loop.\n *\n * And if the click was triggered by form submission (via the enter key), we can hijack the click\n * event to pass that info to the component, so it knows not to\n * re-attempt submission.\n */\n e.stopPropagation();\n\n // Detect if click comes from the parent component,\n // in which case there's no need to trigger a second click on it\n const triggeredByComponentClick = !e.isTrusted;\n if (triggeredByComponentClick) return;\n\n // Trigger parent component click events manually,\n // so it knows not to try to re-submit/re-reset the form\n this.dispatchEvent(\n new CustomEvent('click', { detail: { formActionsInProgress: true } }),\n );\n }\n\n static get styles(): CSSResultGroup {\n return [\n themeStyles,\n css`\n :host {\n --primary-cta-text-color--: var(--primary-cta-text-color);\n --primary-cta-fill--: var(--primary-cta-fill);\n --primary-cta-border--: var(--primary-cta-border);\n\n --secondary-cta-text-color--: var(--secondary-cta-text-color);\n --secondary-cta-fill--: var(--secondary-cta-fill);\n --secondary-cta-border--: var(--secondary-cta-border);\n\n --danger-cta-text-color--: var(--danger-cta-text-color);\n --danger-cta-fill--: var(--danger-cta-fill);\n --danger-cta-border--: var(--danger-cta-border);\n\n --warning-cta-text-color--: var(--warning-cta-text-color);\n --warning-cta-fill--: var(--warning-cta-fill);\n --warning-cta-border--: var(--warning-cta-border);\n\n --disabled-cta-text-color--: var(--disabled-cta-text-color);\n --disabled-cta-fill--: var(--disabled-cta-fill);\n --disabled-cta-border--: var(--disabled-cta-border);\n\n --link-color--: var(--link-color);\n --color-danger--: var(--color-danger);\n\n --button-padding--: var(--button-padding);\n --button-width--: var(--button-width);\n --button-height--: var(--button-height);\n --button-border-width--: var(--button-border-width);\n --button-border-radius--: var(--button-border-radius);\n --base-font-family--: var(--base-font-family);\n --font-size-standard--: var(--font-size-standard);\n\n --ia-button-transition--: var(\n --ia-button-transition,\n all 0.1s ease 0s\n );\n\n --ia-button-custom-text-color--: var(\n --ia-button-custom-text-color,\n var(--primary-cta-text-color--)\n );\n --ia-button-custom-fill--: var(\n --ia-button-custom-fill,\n var(--primary-cta-fill--)\n );\n --ia-button-custom-border--: var(\n --ia-button-custom-border,\n var(--primary-cta-border--)\n );\n --ia-button-custom-active-text-color--: var(\n --ia-button-custom-active-text-color,\n var(--ia-button-custom-text-color--)\n );\n --ia-button-custom-active-fill--: var(\n --ia-button-custom-active-fill,\n var(--ia-button-custom-fill--)\n );\n --ia-button-custom-active-border--: var(\n --ia-button-custom-active-border,\n var(--ia-button-custom-border--)\n );\n\n display: inline-block; /* keeps host sized to button */\n }\n\n button {\n font-family: var(--base-font-family--);\n font-size: var(--font-size-standard--);\n height: var(--button-height--);\n min-height: var(--button-height--);\n width: var(--button-width--);\n padding: var(--button-padding--);\n border-width: var(--button-border-width--);\n border-radius: var(--button-border-radius--);\n transition: var(--ia-button-transition--);\n\n outline-color: currentColor;\n cursor: pointer;\n line-height: normal;\n border-style: solid;\n white-space: nowrap;\n appearance: auto;\n box-sizing: border-box;\n display: flex;\n align-items: center;\n justify-content: center;\n vertical-align: middle;\n outline-offset: -4px;\n user-select: none;\n text-decoration: none;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n -o-user-select: none;\n }\n\n a {\n text-decoration: none;\n }\n\n button:disabled,\n button.disabled {\n cursor: not-allowed;\n color: var(--disabled-cta-text-color--);\n background-color: var(--disabled-cta-fill--);\n border: 1px solid var(--disabled-cta-border--);\n opacity: 0.5;\n }\n\n button:enabled:hover {\n opacity: 0.9;\n }\n\n button:focus-visible {\n opacity: 0.8;\n outline-style: double;\n }\n\n button:active {\n opacity: 0.7;\n }\n\n button.primary {\n color: var(--primary-cta-text-color--);\n background-color: var(--primary-cta-fill--);\n border-color: var(--primary-cta-border--);\n }\n\n button.secondary {\n color: var(--secondary-cta-text-color--);\n background-color: var(--secondary-cta-fill--);\n border-color: var(--secondary-cta-border--);\n }\n\n button.danger {\n color: var(--danger-cta-text-color--);\n background-color: var(--danger-cta-fill--);\n border-color: var(--danger-cta-border--);\n }\n\n button.warning {\n color: var(--warning-cta-text-color--);\n background-color: var(--warning-cta-fill--);\n border-color: var(--warning-cta-border--);\n }\n\n button.transparent {\n color: inherit;\n border-width: 0;\n background-color: transparent;\n border-color: transparent;\n }\n\n button.custom {\n color: var(--ia-button-custom-text-color--);\n background-color: var(--ia-button-custom-fill--);\n border-color: var(--ia-button-custom-border--);\n }\n\n button.custom:enabled:is(:hover, :focus, :active, .active) {\n color: var(--ia-button-custom-active-text-color--);\n background-color: var(--ia-button-custom-active-fill--);\n border-color: var(--ia-button-custom-active-border--);\n }\n\n :host(.fit-content) button {\n padding: 0;\n height: fit-content;\n }\n\n button.link:enabled:hover,\n button.danger-link:enabled:hover {\n text-decoration: underline;\n }\n\n button.link,\n button.danger-link {\n margin: 0;\n border: 0;\n appearance: none;\n background: none;\n text-decoration: none;\n cursor: pointer;\n padding: 0;\n }\n\n button.link {\n color: var(--link-color--);\n }\n\n button.danger-link {\n color: var(--color-danger--);\n }\n\n .loading-indicator {\n display: flex;\n flex-direction: row;\n gap: 0.5rem;\n align-items: center;\n }\n\n ia-status-indicator {\n --ia-theme-primary-text-color: currentColor;\n }\n `,\n ];\n }\n}\n"]}
1
+ {"version":3,"file":"ia-button.js","sourceRoot":"","sources":["../../../../src/elements/ia-button/ia-button.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,IAAI,EACJ,UAAU,EAGV,GAAG,EACH,OAAO,EAEP,MAAM,GACP,MAAM,KAAK,CAAC;AACb,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB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B;AAGzB;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;0CAA2B;AAG3B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;6CAA0B;AAGV;IAA1C,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;sCAGnB;AAGK;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;sCAAe;AAGb;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;iDAAkC;AAM9B;IAA/B,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;sCAA4B;AAE3B;IAA/B,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;6CAAmC;AAElC;IAA/B,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;8CAAoC;AAEnC;IAA/B,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;8CAAoC;AAEnC;IAA/B,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;8CAAoC;AAEnC;IAA/B,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;0CAAgC;AAE/B;IAA/B,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;6CAAmC;AAGtC;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;6CAA0B;AA1D1C,QAAQ;IADpB,aAAa,CAAC,WAAW,CAAC;GACd,QAAQ,CAqbpB","sourcesContent":["import {\n html,\n LitElement,\n TemplateResult,\n CSSResultGroup,\n css,\n nothing,\n PropertyValues,\n render,\n} from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { customElement } from '@src/utils/custom-element';\nimport themeStyles from '@src/themes/theme-styles';\n\nimport '../ia-status-indicator/ia-status-indicator';\n\n/** The properties set on the inner button, and the attribute each one sets */\nconst INNER_BUTTON_ARIA = [\n ['role', 'role'],\n ['ariaChecked', 'aria-checked'],\n ['ariaDisabled', 'aria-disabled'],\n ['ariaHasPopup', 'aria-haspopup'],\n ['ariaExpanded', 'aria-expanded'],\n ['ariaBusy', 'aria-busy'],\n ['ariaCurrent', 'aria-current'],\n] as const;\n\n/**\n * Renders a standardized button built off the ia-button styling and the activity indicator, with the option to show\n * a loading indicator instead of the text or to customize the text, and the ability to pass in any\n * function to run on click.\n *\n * Designed to behave exactly like a native type=\"submit\" or type=\"reset\" button if either type is supplied,\n * i.e. for an <ia-button type=\"submit\" @click=${doSideEffects}></ia-button>,\n * whether the form is submitted via enter or by clicking the button directly, the button will always\n * run doSideEffects() and then submit the form.\n *\n * The inner `<button>` takes focus, so that's where its role and ARIA state\n * belong. Set them with the `role`, `ariaChecked`, `ariaDisabled`,\n * `ariaHasPopup`, `ariaExpanded`, `ariaBusy` and `ariaCurrent` properties, e.g.\n * `<ia-button .role=${'menuitemcheckbox'} .ariaChecked=${'false'}>`. These\n * shadow the native ARIA reflection properties, so nothing lands on the host\n * and a screen reader hears the role or state once. `null`, `undefined` and\n * `''` leave an attribute off; anything else, `false` included, is set as a\n * string. Note:\n * - A `role` or `aria-*` *attribute* written on `<ia-button>` stays on the\n * host, as before, and these properties don't read it back: with\n * `<ia-button aria-disabled=\"true\">`, `ariaDisabled` is `null`.\n * - Set them once `ia-button` is defined. Before that, the native setter\n * writes the attribute onto the host instead.\n *\n * `description` becomes the inner button's accessible description, e.g.\n * \"List full\". It isn't part of the button's name.\n *\n * Focus is delegated, so `focus()` on `<ia-button>` focuses the inner button.\n * With `href`, the wrapping link is the first thing that can take focus, so\n * it takes it instead; the ARIA properties and description stay on the\n * button.\n */\n@customElement('ia-button')\nexport class IAButton extends LitElement {\n static shadowRootOptions: ShadowRootInit = {\n ...LitElement.shadowRootOptions,\n delegatesFocus: true,\n };\n\n /* Which version of the button to display */\n @property({ type: String }) mode:\n | 'primary'\n | 'secondary'\n | 'danger'\n | 'warning'\n | 'disabled'\n | 'transparent'\n | 'custom'\n | 'link'\n | 'danger-link' = 'primary';\n\n /* Whether to show a loading indicator instead of the button */\n @property({ type: Boolean }) loading: boolean = false;\n\n /* Whether the button should be disabled, regardless of submission status */\n @property({ type: Boolean }) disabled: boolean = false;\n\n /* Optional text to include next to the loading indicator */\n @property({ type: String }) loadingText: string = '';\n\n /* Type of the button - defaults to 'button' to prevent form submission */\n @property({ type: String, reflect: true }) type:\n | 'button'\n | 'submit'\n | 'reset' = 'button';\n\n /* An optional href to wrap around the button */\n @property({ type: String }) href?: string;\n\n /* Whether to add a target=\"_blank\" to any wrapping link */\n @property({ type: Boolean }) openLinksNewTab: boolean = false;\n\n /*\n * Role and ARIA state for the inner button. Property-only (no attribute), so\n * the host doesn't expose them too. See the class comment.\n */\n @property({ attribute: false }) role: string | null = null;\n\n @property({ attribute: false }) ariaChecked: string | null = null;\n\n @property({ attribute: false }) ariaDisabled: string | null = null;\n\n @property({ attribute: false }) ariaHasPopup: string | null = null;\n\n @property({ attribute: false }) ariaExpanded: string | null = null;\n\n @property({ attribute: false }) ariaBusy: string | null = null;\n\n @property({ attribute: false }) ariaCurrent: string | null = null;\n\n /* The inner button's accessible description, e.g. \"List full\" */\n @property({ type: String }) description: string = '';\n\n render(): TemplateResult {\n // No whitespace between the top-level nodes: a text node in the shadow\n // root renders as a space when the host is display:inline.\n const control = this.href\n ? html`<a\n href=${this.href}\n target=${this.openLinksNewTab ? '_blank' : '_self'}\n >${this.buttonTemplate}</a\n >`\n : this.buttonTemplate;\n return html`${control}${this.descriptionTemplate}<slot\n name=\"hidden-button\"\n ></slot>`;\n }\n\n protected willUpdate(changed: PropertyValues): void {\n if (changed.has('type')) {\n this.setButtonTypeEmulation();\n }\n }\n\n /**\n * Sets the role and ARIA state on the inner button, following the value\n * rules in the class comment. They're set here rather than bound in the\n * template because lit-plugin checks each `aria-*` binding against that\n * attribute's allowed values, which these string-typed properties can't\n * satisfy. A subclass that overrides this must call `super.updated()`.\n */\n protected updated(changed: PropertyValues): void {\n super.updated(changed);\n\n const button = this.shadowRoot?.querySelector('button');\n if (!button) return;\n\n for (const [prop, attr] of INNER_BUTTON_ARIA) {\n const value: unknown = this[prop];\n if (value === null || value === undefined || value === '') {\n button.removeAttribute(attr);\n } else {\n button.setAttribute(attr, String(value));\n }\n }\n }\n\n /* The native button to render */\n private get buttonTemplate(): TemplateResult {\n return html`<button\n part=\"button\"\n class=${this.mode}\n ?disabled=${this.disabled || this.loading}\n aria-describedby=${this.description ? 'description' : nothing}\n >\n ${this.buttonTextTemplate}\n </button>`;\n }\n\n /*\n * The description, in the shadow root because aria-describedby can't point\n * across it. Outside the button, so it isn't part of the button's name, and\n * hidden, since aria-describedby still reads a hidden element.\n */\n private get descriptionTemplate(): TemplateResult | typeof nothing {\n if (!this.description) return nothing;\n return html`<span id=\"description\" hidden>${this.description}</span>`;\n }\n\n /* The text to render within the button */\n private get buttonTextTemplate(): TemplateResult {\n return this.loading ? this.loadingStateTemplate : html`<slot></slot>`;\n }\n\n /* Content to render while button is loading */\n private get loadingStateTemplate(): TemplateResult {\n return html`\n <span class=\"loading-indicator\" alt=\"Loading indicator\">\n <ia-status-indicator mode=\"loading\"></ia-status-indicator> ${this\n .loadingText}\n </span>\n `;\n }\n\n /** Sets up or removes button type emulation as needed */\n private setButtonTypeEmulation(): void {\n const hiddenButton: HTMLInputElement | null = this.querySelector(\n 'input.hidden-button',\n );\n\n if (hiddenButton) {\n hiddenButton.type = this.type;\n return;\n }\n\n this.addHiddenButton();\n this.addEventListener('click', this.handleComponentClick);\n }\n\n /**\n * Triggers form actions (submit/reset) on click, if desired\n * and if actions not already in progress\n */\n private handleComponentClick(e: Event): void {\n if (this.type === 'button') return;\n\n // No need to submit/reset the form if it's already submitting/resetting\n const formActionsInProgress =\n e instanceof CustomEvent && e.detail.formActionsInProgress;\n if (formActionsInProgress) return;\n\n // Request form submission/reset by clicking the hidden native submit/reset button we added earlier.\n // Uses click() because Firefox ESR 115 and 128 don't run a submit input's\n // activation behavior for a dispatched PointerEvent.\n const hiddenButton = this.querySelector(\n 'input.hidden-button',\n ) as HTMLInputElement;\n hiddenButton.click();\n }\n\n /**\n * Adds a hidden button to the light DOM to\n * emulate native reset/submit button behavior.\n *\n * Used for:\n * - Submitting/resetting the form (on behalf of handleComponentClick)\n * - Activating any component click events if form is submitted with the enter key\n * (via handleFormActions)\n */\n private addHiddenButton(): void {\n if (this.type === 'button') return;\n\n render(\n html`<input\n type=${this.type}\n class=\"hidden-button\"\n style=\"display:none\"\n slot=\"hidden-button\"\n @click=${(e: Event) => this.handleFormActions(e)}\n />`,\n this,\n );\n }\n\n /** Triggers the component's click event manually to prevent extra submission/reset */\n private handleFormActions(e: Event): void {\n /**\n * Prevents the event from bubbling up to the ia-button component itself.\n * This way, if the click on this button is triggered by a click on the component,\n * we don't accidentally bubble up a second click and end up in an infinite loop.\n *\n * And if the click was triggered by form submission (via the enter key), we can hijack the click\n * event to pass that info to the component, so it knows not to\n * re-attempt submission.\n */\n e.stopPropagation();\n\n // Detect if click comes from the parent component,\n // in which case there's no need to trigger a second click on it\n const triggeredByComponentClick = !e.isTrusted;\n if (triggeredByComponentClick) return;\n\n // Trigger parent component click events manually,\n // so it knows not to try to re-submit/re-reset the form\n this.dispatchEvent(\n new CustomEvent('click', { detail: { formActionsInProgress: true } }),\n );\n }\n\n static get styles(): CSSResultGroup {\n return [\n themeStyles,\n css`\n :host {\n --primary-cta-text-color--: var(--primary-cta-text-color);\n --primary-cta-fill--: var(--primary-cta-fill);\n --primary-cta-border--: var(--primary-cta-border);\n\n --secondary-cta-text-color--: var(--secondary-cta-text-color);\n --secondary-cta-fill--: var(--secondary-cta-fill);\n --secondary-cta-border--: var(--secondary-cta-border);\n\n --danger-cta-text-color--: var(--danger-cta-text-color);\n --danger-cta-fill--: var(--danger-cta-fill);\n --danger-cta-border--: var(--danger-cta-border);\n\n --warning-cta-text-color--: var(--warning-cta-text-color);\n --warning-cta-fill--: var(--warning-cta-fill);\n --warning-cta-border--: var(--warning-cta-border);\n\n --disabled-cta-text-color--: var(--disabled-cta-text-color);\n --disabled-cta-fill--: var(--disabled-cta-fill);\n --disabled-cta-border--: var(--disabled-cta-border);\n\n --link-color--: var(--link-color);\n --color-danger--: var(--color-danger);\n\n --button-padding--: var(--button-padding);\n --button-width--: var(--button-width);\n --button-height--: var(--button-height);\n --button-border-width--: var(--button-border-width);\n --button-border-radius--: var(--button-border-radius);\n --base-font-family--: var(--base-font-family);\n --font-size-standard--: var(--font-size-standard);\n\n --ia-button-transition--: var(\n --ia-button-transition,\n all 0.1s ease 0s\n );\n\n --ia-button-custom-text-color--: var(\n --ia-button-custom-text-color,\n var(--primary-cta-text-color--)\n );\n --ia-button-custom-fill--: var(\n --ia-button-custom-fill,\n var(--primary-cta-fill--)\n );\n --ia-button-custom-border--: var(\n --ia-button-custom-border,\n var(--primary-cta-border--)\n );\n --ia-button-custom-active-text-color--: var(\n --ia-button-custom-active-text-color,\n var(--ia-button-custom-text-color--)\n );\n --ia-button-custom-active-fill--: var(\n --ia-button-custom-active-fill,\n var(--ia-button-custom-fill--)\n );\n --ia-button-custom-active-border--: var(\n --ia-button-custom-active-border,\n var(--ia-button-custom-border--)\n );\n\n display: inline-block; /* keeps host sized to button */\n }\n\n button {\n font-family: var(--base-font-family--);\n font-size: var(--font-size-standard--);\n height: var(--button-height--);\n min-height: var(--button-height--);\n width: var(--button-width--);\n padding: var(--button-padding--);\n border-width: var(--button-border-width--);\n border-radius: var(--button-border-radius--);\n transition: var(--ia-button-transition--);\n\n outline-color: currentColor;\n cursor: pointer;\n line-height: normal;\n border-style: solid;\n white-space: nowrap;\n appearance: auto;\n box-sizing: border-box;\n display: flex;\n align-items: center;\n justify-content: center;\n vertical-align: middle;\n outline-offset: -4px;\n user-select: none;\n text-decoration: none;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n -o-user-select: none;\n }\n\n a {\n text-decoration: none;\n }\n\n button:disabled,\n button.disabled {\n cursor: not-allowed;\n color: var(--disabled-cta-text-color--);\n background-color: var(--disabled-cta-fill--);\n border: 1px solid var(--disabled-cta-border--);\n opacity: 0.5;\n }\n\n button:enabled:hover {\n opacity: 0.9;\n }\n\n button:focus-visible {\n opacity: 0.8;\n outline-style: double;\n }\n\n button:active {\n opacity: 0.7;\n }\n\n button.primary {\n color: var(--primary-cta-text-color--);\n background-color: var(--primary-cta-fill--);\n border-color: var(--primary-cta-border--);\n }\n\n button.secondary {\n color: var(--secondary-cta-text-color--);\n background-color: var(--secondary-cta-fill--);\n border-color: var(--secondary-cta-border--);\n }\n\n button.danger {\n color: var(--danger-cta-text-color--);\n background-color: var(--danger-cta-fill--);\n border-color: var(--danger-cta-border--);\n }\n\n button.warning {\n color: var(--warning-cta-text-color--);\n background-color: var(--warning-cta-fill--);\n border-color: var(--warning-cta-border--);\n }\n\n button.transparent {\n color: inherit;\n border-width: 0;\n background-color: transparent;\n border-color: transparent;\n }\n\n button.custom {\n color: var(--ia-button-custom-text-color--);\n background-color: var(--ia-button-custom-fill--);\n border-color: var(--ia-button-custom-border--);\n }\n\n button.custom:enabled:is(:hover, :focus, :active, .active) {\n color: var(--ia-button-custom-active-text-color--);\n background-color: var(--ia-button-custom-active-fill--);\n border-color: var(--ia-button-custom-active-border--);\n }\n\n :host(.fit-content) button {\n padding: 0;\n height: fit-content;\n }\n\n button.link:enabled:hover,\n button.danger-link:enabled:hover {\n text-decoration: underline;\n }\n\n button.link,\n button.danger-link {\n margin: 0;\n border: 0;\n appearance: none;\n background: none;\n text-decoration: none;\n cursor: pointer;\n padding: 0;\n }\n\n button.link {\n color: var(--link-color--);\n }\n\n button.danger-link {\n color: var(--color-danger--);\n }\n\n .loading-indicator {\n display: flex;\n flex-direction: row;\n gap: 0.5rem;\n align-items: center;\n }\n\n ia-status-indicator {\n --ia-theme-primary-text-color: currentColor;\n }\n `,\n ];\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/elements",
3
- "version": "1.11.0",
3
+ "version": "1.11.1-webdev-10173.0",
4
4
  "description": "A web component library from the Internet Archive.",
5
5
  "license": "AGPL-3.0-only",
6
6
  "type": "module",