vira 32.3.0 → 32.4.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.
@@ -1,5 +1,5 @@
1
1
  import { type PartialWithUndefined } from '@augment-vir/common';
2
- import { type AttributeValues, type CSSResult } from 'element-vir';
2
+ import { type AttributeValues, type CSSResult, type HtmlInterpolation } from 'element-vir';
3
3
  import { ViraIcon } from './vira-icon.element.js';
4
4
  /**
5
5
  * All inner elements supported by {@link ViraCheckbox}.
@@ -19,10 +19,10 @@ export type ViraCheckboxInputs = {
19
19
  attributePassthrough: Partial<Record<ViraCheckboxInnerElements, AttributeValues>>;
20
20
  isDisabled: boolean;
21
21
  /**
22
- * Text label for the checkbox. Used as the fallback when the `vira-checkbox-label` slot is not
22
+ * Label for the checkbox. Used as the fallback when the `vira-checkbox-label` slot is not
23
23
  * filled.
24
24
  */
25
- label: string;
25
+ label: string | HtmlInterpolation;
26
26
  hasError: boolean;
27
27
  useHorizontalLabel: boolean;
28
28
  /** The checkbox will be filled with a form selection color when it is checked. */
@@ -1,3 +1,4 @@
1
+ import { check } from '@augment-vir/assert';
1
2
  import { extractEventTarget } from '@augment-vir/web';
2
3
  import { attributes, classMap, css, defineElementEvent, html, ifDefined, listen, listenToActivate, } from 'element-vir';
3
4
  import { Check24Icon, viraIconCssVars } from '../icons/index.js';
@@ -168,7 +169,7 @@ export const ViraCheckbox = defineViraElement()({
168
169
  }
169
170
  }
170
171
  const hasLabel = !!inputs.label || state.hasSlottedLabel;
171
- const textLabel = html `
172
+ const labelTemplate = html `
172
173
  <span
173
174
  class="label-text ${classMap({
174
175
  empty: !hasLabel,
@@ -198,7 +199,7 @@ export const ViraCheckbox = defineViraElement()({
198
199
  style=${ifDefined(inputs.stylePassthrough?.label)}
199
200
  ${listen('mousedown', updateValue)}
200
201
  >
201
- ${textLabel}
202
+ ${labelTemplate}
202
203
  <span
203
204
  class="custom-checkbox ${classMap({
204
205
  checked: inputs.value,
@@ -206,7 +207,7 @@ export const ViraCheckbox = defineViraElement()({
206
207
  error: !!inputs.hasError,
207
208
  })}"
208
209
  role="checkbox"
209
- aria-label=${ifDefined(inputs.label || undefined)}
210
+ aria-label=${ifDefined((check.isString(inputs.label) && inputs.label) || undefined)}
210
211
  aria-checked=${inputs.value ? 'true' : 'false'}
211
212
  aria-disabled=${inputs.isDisabled ? 'true' : 'false'}
212
213
  tabindex=${inputs.isDisabled ? '-1' : '0'}
@@ -1,5 +1,6 @@
1
1
  import { type PartialWithUndefined } from '@augment-vir/common';
2
2
  import { type FullDate, type Timezone } from 'date-vir';
3
+ import { type HtmlInterpolation } from 'element-vir';
3
4
  /**
4
5
  * A native date picker input that emits `FullDate` values. Fires `valueChange` whenever the user
5
6
  * selects (or clears) a date.
@@ -18,7 +19,7 @@ export declare const ViraDateInput: import("element-vir").DeclarativeElementDefi
18
19
  /** If true, applies error styling. */
19
20
  hasError: boolean;
20
21
  /** A label that is shown above the input, if provided. */
21
- label: string;
22
+ label: string | HtmlInterpolation;
22
23
  /** If true, the input is disabled and cannot be edited. */
23
24
  isDisabled: boolean;
24
25
  /** If true, the current value is rendered as plain text instead of an editable input. */
@@ -1,7 +1,8 @@
1
+ import { check } from '@augment-vir/assert';
1
2
  import { randomString } from '@augment-vir/common';
2
3
  import { extractEventTarget } from '@augment-vir/web';
3
4
  import { calculateRelativeDate, createUtcFullDate, FullDatePart, getNowInUtcTimezone, parseInputElementValue, toHtmlInputString, userTimezone, } from 'date-vir';
4
- import { css, defineElementEvent, html, ifDefined, listen } from 'element-vir';
5
+ import { css, defineElementEvent, html, ifDefined, listen, } from 'element-vir';
5
6
  import { viraDisabledStyles } from '../styles/disabled.js';
6
7
  import { viraFormCssVars } from '../styles/form-styles.js';
7
8
  import { defineViraElement } from '../util/define-vira-element.js';
@@ -113,7 +114,7 @@ export const ViraDateInput = defineViraElement()({
113
114
  const inputTemplate = html `
114
115
  <input
115
116
  id=${ifDefined(inputs.label ? state.randomId : undefined)}
116
- aria-label=${ifDefined(inputs.label || undefined)}
117
+ aria-label=${ifDefined((check.isString(inputs.label) && inputs.label) || undefined)}
117
118
  type="date"
118
119
  min=${minDate}
119
120
  max=${maxDate}
@@ -1,4 +1,5 @@
1
1
  import { type PartialWithUndefined } from '@augment-vir/common';
2
+ import { type HtmlInterpolation } from 'element-vir';
2
3
  import { type ViraIconSvg } from '../icons/icon-svg.js';
3
4
  import { type ShowPopUpResult } from '../util/pop-up-manager.js';
4
5
  import { type ViraSelectOption } from '../util/vira-select-option.js';
@@ -25,7 +26,7 @@ export declare const ViraDropdown: import("element-vir").DeclarativeElementDefin
25
26
  icon: ViraIconSvg;
26
27
  selectionPrefix: string;
27
28
  isDisabled: boolean;
28
- label: string;
29
+ label: string | HtmlInterpolation;
29
30
  /** For debugging purposes only. Very bad for actual production code use. */
30
31
  z_debug_forceOpenState: boolean;
31
32
  } & PopUpTriggerPosition>, {
@@ -236,7 +236,7 @@ export const ViraDropdown = defineViraElement()({
236
236
  })}"
237
237
  slot=${ViraPopUpTrigger.slotNames['vira-pop-up-trigger-trigger']}
238
238
  id=${ifDefined(inputs.label ? state.randomId : undefined)}
239
- aria-label=${ifDefined(inputs.label || undefined)}
239
+ aria-label=${ifDefined((check.isString(inputs.label) && inputs.label) || undefined)}
240
240
  ${testId(testIds.trigger)}
241
241
  ${listen('mousedown', () => {
242
242
  if (!state.showPopUpResult) {
@@ -1,3 +1,4 @@
1
+ import { check } from '@augment-vir/assert';
1
2
  import { getObjectTypedEntries } from '@augment-vir/common';
2
3
  import { css, defineElementEvent, html, listen, nothing, testId, } from 'element-vir';
3
4
  import { viraFormCssVars } from '../styles/form-styles.js';
@@ -111,11 +112,7 @@ export const ViraForm = defineViraElement()({
111
112
  return nothing;
112
113
  }
113
114
  else if (field.type === ViraFormFieldType.Checkbox) {
114
- const checkboxLabel = showRequiredMarker
115
- ? html `
116
- ${field.label}*
117
- `
118
- : field.label;
115
+ const checkboxLabel = applyRequiredLabel(field.label, showRequiredMarker);
119
116
  return wrapFormField({
120
117
  label: checkboxLabel,
121
118
  fieldTemplate: html `
@@ -153,7 +150,7 @@ export const ViraForm = defineViraElement()({
153
150
  }
154
151
  const label = applyRequiredLabel(field.label, showRequiredMarker);
155
152
  const childLabel = inputs.useHorizontalLabels ? undefined : label;
156
- const horizontalLabelAttributes = inputs.useHorizontalLabels && label
153
+ const horizontalLabelAttributes = inputs.useHorizontalLabels && check.isString(label) && label
157
154
  ? {
158
155
  'aria-label': label,
159
156
  }
@@ -1,4 +1,5 @@
1
1
  import { type PartialWithUndefined } from '@augment-vir/common';
2
+ import { type HtmlInterpolation } from 'element-vir';
2
3
  import { type ViraIconSvg } from '../icons/index.js';
3
4
  export * from '../util/shared-text-input-logic.js';
4
5
  /**
@@ -25,7 +26,7 @@ export declare const ViraInput: import("element-vir").DeclarativeElementDefiniti
25
26
  /** A suffix that, if provided, is shown following the input field. */
26
27
  suffix: string;
27
28
  /** A label that is shown above the input, if provided. */
28
- label: string;
29
+ label: string | HtmlInterpolation;
29
30
  /** If true, applies error styling. */
30
31
  hasError: boolean;
31
32
  showClearButton: boolean;
@@ -1,4 +1,4 @@
1
- import { assertWrap } from '@augment-vir/assert';
1
+ import { assertWrap, check } from '@augment-vir/assert';
2
2
  import { randomString } from '@augment-vir/common';
3
3
  import { extractEventTarget } from '@augment-vir/web';
4
4
  import { attributes, css, defineElementEvent, html, ifDefined, listen, nothing, onResize, renderIf, } from 'element-vir';
@@ -374,7 +374,7 @@ export const ViraInput = defineViraElement()({
374
374
 
375
375
  <input
376
376
  id=${ifDefined(inputs.label ? state.randomId : undefined)}
377
- aria-label=${ifDefined(inputs.label || undefined)}
377
+ aria-label=${ifDefined((check.isString(inputs.label) && inputs.label) || undefined)}
378
378
  type=${calculateEffectiveInputType(inputs.type, state.showPassword)}
379
379
  style=${forcedInputWidthStyles}
380
380
  autocomplete=${ifDefined(shouldBlockBrowserHelps ? 'off' : undefined)}
@@ -1,5 +1,5 @@
1
1
  import { type PartialWithUndefined } from '@augment-vir/common';
2
- import { type AttributeValues } from 'element-vir';
2
+ import { type AttributeValues, type HtmlInterpolation } from 'element-vir';
3
3
  import { type ViraIconSvg } from '../icons/index.js';
4
4
  import { type ViraSelectOption, type ViraSelectOptionGroup } from '../util/vira-select-option.js';
5
5
  /**
@@ -16,7 +16,7 @@ export declare const ViraSelect: import("element-vir").DeclarativeElementDefinit
16
16
  } & PartialWithUndefined<{
17
17
  icon: Readonly<ViraIconSvg>;
18
18
  placeholder: string;
19
- label: string;
19
+ label: string | HtmlInterpolation;
20
20
  /** If set to `true`, only minimal styles are applied. */
21
21
  rawSelect: boolean;
22
22
  disabled: boolean;
@@ -1,4 +1,4 @@
1
- import { assertWrap } from '@augment-vir/assert';
1
+ import { assertWrap, check } from '@augment-vir/assert';
2
2
  import { randomString } from '@augment-vir/common';
3
3
  import { extractEventTarget } from '@augment-vir/web';
4
4
  import { attributes, classMap, css, defineElementEvent, html, ifDefined, listen, nothing, } from 'element-vir';
@@ -348,7 +348,7 @@ export const ViraSelect = defineViraElement()({
348
348
  })}
349
349
  tabindex=${inputs.disabled ? -1 : 0}
350
350
  id=${ifDefined(inputs.label ? state.randomId : undefined)}
351
- aria-label=${ifDefined(inputs.label || undefined)}
351
+ aria-label=${ifDefined((check.isString(inputs.label) && inputs.label) || undefined)}
352
352
  aria-disabled=${ifDefined(inputs.disabled ? 'true' : undefined)}
353
353
  ${listen('input', (event) => {
354
354
  const selectElement = extractEventTarget(event, HTMLSelectElement);
@@ -1,4 +1,5 @@
1
1
  import { type PartialWithUndefined } from '@augment-vir/common';
2
+ import { type HtmlInterpolation } from 'element-vir';
2
3
  /**
3
4
  * A multi-line text area element with all listeners properly attached. Mirrors the look and feel of
4
5
  * {@link ViraInput} but for multi-line text input.
@@ -9,7 +10,7 @@ import { type PartialWithUndefined } from '@augment-vir/common';
9
10
  */
10
11
  export declare const ViraTextArea: import("element-vir").DeclarativeElementDefinition<"vira-text-area", PartialWithUndefined<{
11
12
  /** A label that is shown above the text area, if provided. */
12
- label: string;
13
+ label: string | HtmlInterpolation;
13
14
  /** If true, applies error styling. */
14
15
  hasError: boolean;
15
16
  /** Number of visible text rows. Defaults to 4. */
@@ -1,5 +1,6 @@
1
+ import { check } from '@augment-vir/assert';
1
2
  import { randomString } from '@augment-vir/common';
2
- import { attributes, css, defineElementEvent, html, ifDefined, listen } from 'element-vir';
3
+ import { attributes, css, defineElementEvent, html, ifDefined, listen, } from 'element-vir';
3
4
  import { createFocusStyles } from '../styles/focus.js';
4
5
  import { viraFormCssVars } from '../styles/form-styles.js';
5
6
  import { viraDisabledStyles } from '../styles/index.js';
@@ -187,7 +188,7 @@ export const ViraTextArea = defineViraElement()({
187
188
  <span class="text-area-wrapper">
188
189
  <textarea
189
190
  id=${ifDefined(inputs.label ? state.randomId : undefined)}
190
- aria-label=${ifDefined(inputs.label || undefined)}
191
+ aria-label=${ifDefined((check.isString(inputs.label) && inputs.label) || undefined)}
191
192
  rows=${inputs.rows ?? 4}
192
193
  ?disabled=${inputs.disabled}
193
194
  autocomplete=${ifDefined(inputs.disableBrowserHelps ? 'off' : undefined)}
@@ -29,7 +29,7 @@ export declare enum ViraFormFieldType {
29
29
  * @category Internal
30
30
  */
31
31
  export type CommonViraFormFields = {
32
- label: string;
32
+ label: string | HtmlInterpolation;
33
33
  } & PartialWithUndefined<{
34
34
  /** Applies a test id to the form field element. */
35
35
  testId: string;
@@ -80,17 +80,12 @@ export type ViraFormField = ({
80
80
  }> & CommonViraFormFields) | ({
81
81
  type: ViraFormFieldType.Checkbox;
82
82
  value: boolean | undefined;
83
- /**
84
- * Label for the checkbox. Unlike other field types, this accepts arbitrary HTML so the
85
- * checkbox's label slot can be filled with rich content.
86
- */
87
- label: HtmlInterpolation;
88
83
  } & PartialWithUndefined<{
89
84
  /** The checkbox will be filled with a form selection color when it is checked. */
90
85
  fillWhenChecked: boolean;
91
86
  /** The checkbox will be filled with a form error color when it is unchecked. */
92
87
  fillWhenUnchecked: boolean;
93
- }> & Omit<CommonViraFormFields, 'label'>) | ({
88
+ }> & CommonViraFormFields) | ({
94
89
  type: ViraFormFieldType.Number;
95
90
  value: number | undefined;
96
91
  } & PartialWithUndefined<{
@@ -132,7 +127,7 @@ export type ViraFormFields = Record<string, ViraFormField>;
132
127
  *
133
128
  * @category Internal
134
129
  */
135
- export declare function applyRequiredLabel(label: string | undefined, isRequired: boolean): string | undefined;
130
+ export declare function applyRequiredLabel(label: string | HtmlInterpolation | undefined, isRequired: boolean): string | HtmlInterpolation | undefined;
136
131
  /**
137
132
  * Checks if all the {@link ViraFormField} entries in a given {@link ViraFormFields} are valid through
138
133
  * the following checks:
@@ -1,5 +1,6 @@
1
1
  import { check } from '@augment-vir/assert';
2
2
  import { addSuffix, getObjectTypedValues } from '@augment-vir/common';
3
+ import { html } from 'element-vir';
3
4
  /**
4
5
  * Form field types for {@link ViraFormField}.
5
6
  *
@@ -27,19 +28,22 @@ export var ViraFormFieldType;
27
28
  * @category Internal
28
29
  */
29
30
  export function applyRequiredLabel(label, isRequired) {
30
- if (label) {
31
- if (isRequired) {
32
- return addSuffix({
33
- value: label,
34
- suffix: '*',
35
- });
36
- }
37
- else {
38
- return label;
39
- }
31
+ if (!label) {
32
+ return undefined;
33
+ }
34
+ else if (!isRequired) {
35
+ return label;
36
+ }
37
+ else if (check.isString(label)) {
38
+ return addSuffix({
39
+ value: label,
40
+ suffix: '*',
41
+ });
40
42
  }
41
43
  else {
42
- return undefined;
44
+ return html `
45
+ ${label}*
46
+ `;
43
47
  }
44
48
  }
45
49
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vira",
3
- "version": "32.3.0",
3
+ "version": "32.4.0",
4
4
  "description": "A simple and highly versatile design system using element-vir.",
5
5
  "keywords": [
6
6
  "design",