vira 32.3.0 → 33.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/dist/directives/index.d.ts +2 -0
  2. package/dist/directives/index.js +2 -0
  3. package/dist/directives/popover.directive.d.ts +29 -0
  4. package/dist/directives/popover.directive.js +45 -0
  5. package/dist/directives/tooltip.directive.d.ts +60 -0
  6. package/dist/directives/tooltip.directive.js +99 -0
  7. package/dist/elements/color/vira-color-picker.element.d.ts +1 -1
  8. package/dist/elements/color/vira-color-picker.element.js +17 -15
  9. package/dist/elements/index.d.ts +5 -5
  10. package/dist/elements/index.js +5 -5
  11. package/dist/elements/{pop-up → popover}/vira-menu-item.element.d.ts +4 -4
  12. package/dist/elements/{pop-up → popover}/vira-menu-item.element.js +3 -3
  13. package/dist/elements/popover/vira-menu-trigger.element.d.ts +56 -0
  14. package/dist/elements/{pop-up → popover}/vira-menu-trigger.element.js +19 -30
  15. package/dist/elements/popover/vira-menu.element.d.ts +35 -0
  16. package/dist/elements/popover/vira-menu.element.js +262 -0
  17. package/dist/elements/popover/vira-popover-trigger.element.d.ts +49 -0
  18. package/dist/elements/popover/vira-popover-trigger.element.js +301 -0
  19. package/dist/elements/popover/vira-tooltip.element.d.ts +10 -0
  20. package/dist/elements/popover/vira-tooltip.element.js +176 -0
  21. package/dist/elements/vira-checkbox.element.d.ts +3 -3
  22. package/dist/elements/vira-checkbox.element.js +4 -3
  23. package/dist/elements/vira-date-input.element.d.ts +2 -1
  24. package/dist/elements/vira-date-input.element.js +3 -2
  25. package/dist/elements/vira-drawer.element.js +1 -1
  26. package/dist/elements/vira-dropdown.element.d.ts +29 -12
  27. package/dist/elements/vira-dropdown.element.js +173 -60
  28. package/dist/elements/vira-form.element.js +13 -22
  29. package/dist/elements/vira-input.element.d.ts +2 -1
  30. package/dist/elements/vira-input.element.js +2 -2
  31. package/dist/elements/vira-json-form.element.js +40 -36
  32. package/dist/elements/vira-modal.element.js +1 -1
  33. package/dist/elements/vira-tabs.element.d.ts +3 -9
  34. package/dist/elements/vira-tabs.element.js +5 -6
  35. package/dist/elements/vira-text-area.element.d.ts +2 -1
  36. package/dist/elements/vira-text-area.element.js +3 -2
  37. package/dist/elements/vira-theme-switcher.element.js +3 -3
  38. package/dist/index.d.ts +1 -0
  39. package/dist/index.js +1 -0
  40. package/dist/util/anchored-popover.d.ts +40 -0
  41. package/dist/util/anchored-popover.js +70 -0
  42. package/dist/util/index.d.ts +4 -3
  43. package/dist/util/index.js +4 -3
  44. package/dist/util/{pop-up-helpers.d.ts → menu-helpers.d.ts} +4 -18
  45. package/dist/util/{pop-up-helpers.js → menu-helpers.js} +2 -17
  46. package/dist/util/popover-manager.d.ts +123 -0
  47. package/dist/util/popover-manager.js +412 -0
  48. package/dist/util/vira-dropdown-option.d.ts +30 -0
  49. package/dist/util/vira-dropdown-option.js +8 -0
  50. package/dist/util/vira-form-fields.d.ts +5 -10
  51. package/dist/util/vira-form-fields.js +15 -11
  52. package/dist/util/vira-theme-client.d.ts +1 -1
  53. package/dist/util/vira-theme-client.js +3 -3
  54. package/package.json +2 -1
  55. package/dist/elements/pop-up/vira-menu-trigger.element.d.ts +0 -45
  56. package/dist/elements/pop-up/vira-menu.element.d.ts +0 -36
  57. package/dist/elements/pop-up/vira-menu.element.js +0 -88
  58. package/dist/elements/pop-up/vira-pop-up-trigger.element.d.ts +0 -109
  59. package/dist/elements/pop-up/vira-pop-up-trigger.element.js +0 -408
  60. package/dist/elements/vira-select.element.d.ts +0 -44
  61. package/dist/elements/vira-select.element.js +0 -418
  62. package/dist/util/pop-up-manager.d.ts +0 -200
  63. package/dist/util/pop-up-manager.js +0 -258
  64. package/dist/util/vira-select-option.d.ts +0 -31
  65. package/dist/util/vira-select-option.js +0 -8
@@ -0,0 +1,176 @@
1
+ import { colorCss } from '@electrovir/color';
2
+ import { css, html } from 'element-vir';
3
+ import { listenTo } from 'typed-event-target';
4
+ import { viraFormCssVars } from '../../styles/form-styles.js';
5
+ import { viraTheme } from '../../styles/vira-color-theme.js';
6
+ import { createAnchoredPopoverStyles } from '../../util/anchored-popover.js';
7
+ import { defineViraElement } from '../../util/define-vira-element.js';
8
+ /**
9
+ * Centered with insets instead of `position-area`, because browsers shift a centered
10
+ * `position-area` box back onto the screen rather than moving on to the next
11
+ * `position-try-fallbacks` entry. These insets leave a space that is centered on the anchor and as
12
+ * wide as possible, and `unsafe` stops the browser from shifting the tooltip, so a tooltip wider
13
+ * than that space overflows it and moves on to an aligned fallback. Each `anchor(center)` is
14
+ * measured from the side its inset is on, so the same formula works for `left` and `right`.
15
+ */
16
+ const centeredStyles = css `
17
+ position-area: none;
18
+ top: 0;
19
+ bottom: anchor(top);
20
+ left: max(0px, 2 * anchor(center) - 100%);
21
+ right: max(0px, 2 * anchor(center) - 100%);
22
+ align-self: end;
23
+ justify-self: unsafe center;
24
+ `;
25
+ /** `unsafe` for the same reason as {@link centeredStyles}. */
26
+ const leftAlignedStyles = css `
27
+ position-area: block-start span-inline-end;
28
+ inset: auto;
29
+ align-self: normal;
30
+ justify-self: unsafe start;
31
+ `;
32
+ /** `unsafe` for the same reason as {@link centeredStyles}. */
33
+ const rightAlignedStyles = css `
34
+ position-area: block-start span-inline-start;
35
+ inset: auto;
36
+ align-self: normal;
37
+ justify-self: unsafe end;
38
+ `;
39
+ /**
40
+ * Centered but shifted to stay on the screen. For a tooltip that fits on neither side of the
41
+ * anchor.
42
+ */
43
+ const shiftedStyles = css `
44
+ position-area: block-start span-all;
45
+ inset: auto;
46
+ align-self: normal;
47
+ justify-self: anchor-center;
48
+ `;
49
+ /**
50
+ * The popover rendered by the `tooltip` directive. The element itself is the popover, centered
51
+ * above `anchor` when there's room. Its children are the tooltip contents.
52
+ *
53
+ * @category Popover
54
+ * @category Elements
55
+ */
56
+ export const ViraTooltip = defineViraElement()({
57
+ tagName: 'vira-tooltip',
58
+ styles: css `
59
+ ${createAnchoredPopoverStyles({
60
+ fallbacks: [
61
+ {
62
+ name: 'vira-tooltip-above-left-aligned',
63
+ styles: leftAlignedStyles,
64
+ },
65
+ {
66
+ name: 'vira-tooltip-above-right-aligned',
67
+ styles: rightAlignedStyles,
68
+ },
69
+ {
70
+ name: 'vira-tooltip-below-centered',
71
+ styles: centeredStyles,
72
+ flipBlock: true,
73
+ },
74
+ {
75
+ name: 'vira-tooltip-below-left-aligned',
76
+ styles: leftAlignedStyles,
77
+ flipBlock: true,
78
+ },
79
+ {
80
+ name: 'vira-tooltip-below-right-aligned',
81
+ styles: rightAlignedStyles,
82
+ flipBlock: true,
83
+ },
84
+ {
85
+ name: 'vira-tooltip-above-shifted',
86
+ styles: shiftedStyles,
87
+ },
88
+ {
89
+ name: 'vira-tooltip-below-shifted',
90
+ styles: shiftedStyles,
91
+ flipBlock: true,
92
+ },
93
+ ],
94
+ })}
95
+
96
+ :host {
97
+ anchor-name: --vira-tooltip;
98
+ ${colorCss(viraTheme.colors['vira-grey-behind-bg-highest-contrast'])};
99
+ ${centeredStyles}
100
+ margin-bottom: 7px;
101
+ padding: 4px 8px;
102
+ border-radius: 6px;
103
+ box-sizing: border-box;
104
+ width: max-content;
105
+ /*
106
+ Not 100%, which is the width of the current position-area. A tooltip limited to that
107
+ width shrinks to fit it rather than overflowing onto the next fallback.
108
+ */
109
+ max-width: min(300px, 100vw);
110
+ font-size: ${viraFormCssVars['vira-form-small-text-size'].value};
111
+ overflow-wrap: break-word;
112
+ pointer-events: none;
113
+ }
114
+
115
+ /*
116
+ Separate popovers rather than children or pseudo-elements of the tooltip, because those can't
117
+ use anchor() to reach the anchor element from inside the tooltip's top-layer box.
118
+ */
119
+ .caret {
120
+ /*
121
+ position-anchor is set explicitly because its initial value differs between browsers.
122
+ */
123
+ position-anchor: auto;
124
+ position: fixed;
125
+ inset: auto;
126
+ margin: 0;
127
+ padding: 0;
128
+ border: none;
129
+ height: auto;
130
+ width: 10px;
131
+ left: calc(anchor(center) - 5px);
132
+ background-color: ${viraTheme.colors['vira-grey-behind-bg-highest-contrast'].background
133
+ .value};
134
+ pointer-events: none;
135
+ }
136
+
137
+ /*
138
+ Each caret spans the gap between the tooltip and the anchor on its own side, so the caret
139
+ on the side without the tooltip gets a negative height, which renders as nothing. This
140
+ follows the tooltip's position-try-fallbacks choice without knowing which one won.
141
+ */
142
+ .caret-down {
143
+ top: anchor(--vira-tooltip bottom);
144
+ bottom: calc(anchor(top) + 2px);
145
+ clip-path: polygon(0 0, 100% 0, 50% 100%);
146
+ }
147
+
148
+ .caret-up {
149
+ bottom: anchor(--vira-tooltip top);
150
+ top: calc(anchor(bottom) + 2px);
151
+ clip-path: polygon(50% 0, 100% 100%, 0 100%);
152
+ }
153
+ `,
154
+ init({ host }) {
155
+ /** The carets must open after the tooltip so they can anchor to it. */
156
+ listenTo(host, 'toggle', () => {
157
+ if (!host.matches(':popover-open')) {
158
+ return;
159
+ }
160
+ host.shadowRoot.querySelectorAll('.caret').forEach((caret) => {
161
+ if (caret instanceof HTMLElement && !caret.matches(':popover-open')) {
162
+ caret.showPopover({
163
+ source: host.instanceInputs.anchor,
164
+ });
165
+ }
166
+ });
167
+ });
168
+ },
169
+ render() {
170
+ return html `
171
+ <slot></slot>
172
+ <div class="caret caret-down" popover="manual"></div>
173
+ <div class="caret caret-up" popover="manual"></div>
174
+ `;
175
+ },
176
+ });
@@ -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}
@@ -11,7 +11,7 @@ import { viraShadows } from '../styles/shadows.js';
11
11
  import { noUserSelect } from '../styles/user-select.js';
12
12
  import { viraTheme } from '../styles/vira-color-theme.js';
13
13
  import { defineViraElement } from '../util/define-vira-element.js';
14
- import { isMouseEventOnScrollbar } from '../util/pop-up-manager.js';
14
+ import { isMouseEventOnScrollbar } from '../util/popover-manager.js';
15
15
  import { ViraIcon } from './vira-icon.element.js';
16
16
  const globalEventsToCloseDrawerOn = [
17
17
  'pagehide',
@@ -1,22 +1,26 @@
1
1
  import { type PartialWithUndefined } from '@augment-vir/common';
2
+ import { type AttributeValues, type HtmlInterpolation } from 'element-vir';
2
3
  import { type ViraIconSvg } from '../icons/icon-svg.js';
3
- import { type ShowPopUpResult } from '../util/pop-up-manager.js';
4
- import { type ViraSelectOption } from '../util/vira-select-option.js';
5
- import { type PopUpTriggerPosition } from './pop-up/vira-pop-up-trigger.element.js';
4
+ import { type ViraDropdownOption, type ViraDropdownOptionGroup } from '../util/vira-dropdown-option.js';
6
5
  /**
7
- * A dropdown element that uses pop-up menus.
6
+ * A dropdown element that uses popover menus.
8
7
  *
9
8
  * @category Dropdown
10
9
  * @category Elements
11
10
  * @see https://electrovir.github.io/vira/book/elements/dropdown/vira-dropdown
12
11
  */
13
12
  export declare const ViraDropdown: import("element-vir").DeclarativeElementDefinition<"vira-dropdown", {
14
- options: ReadonlyArray<Readonly<ViraSelectOption>>;
13
+ options: ReadonlyArray<Readonly<ViraDropdownOption> | Readonly<ViraDropdownOptionGroup>>;
15
14
  /** The selected id from the given options. */
16
15
  selected: ReadonlyArray<PropertyKey>;
17
16
  } & PartialWithUndefined<{
18
17
  /** Text to show if nothing is selected. */
19
18
  placeholder: string;
19
+ /**
20
+ * Text shown in the opened popover when `options` has no options. When omitted, opening a
21
+ * dropdown with no options shows no popover at all.
22
+ */
23
+ noOptionsText: string;
20
24
  /**
21
25
  * If false, this will behave like a single select dropdown, otherwise you can select
22
26
  * multiple.
@@ -25,12 +29,24 @@ export declare const ViraDropdown: import("element-vir").DeclarativeElementDefin
25
29
  icon: ViraIconSvg;
26
30
  selectionPrefix: string;
27
31
  isDisabled: boolean;
28
- label: string;
29
- /** For debugging purposes only. Very bad for actual production code use. */
30
- z_debug_forceOpenState: boolean;
31
- } & PopUpTriggerPosition>, {
32
- /** `undefined` means the pop up is not currently showing. */
33
- showPopUpResult: ShowPopUpResult | undefined;
32
+ /**
33
+ * When `true`, the currently selected options' labels are rendered as plain text with no
34
+ * trigger or menu.
35
+ */
36
+ isReadonly: boolean;
37
+ hasError: boolean;
38
+ label: string | HtmlInterpolation;
39
+ /** Attributes applied to the trigger element. */
40
+ attributePassthrough: Readonly<AttributeValues>;
41
+ /**
42
+ * Passed to {@link ViraMenu}'s `hoverScrollSpeed` input. How many menu items per second
43
+ * hovering a scroll arrow scrolls through.
44
+ *
45
+ * @default 24
46
+ */
47
+ menuHoverScrollSpeed: number;
48
+ }>, {
49
+ isOpen: boolean;
34
50
  shouldSelectOnMouseUp: boolean;
35
51
  /**
36
52
  * Used to couple the label and trigger together. This is not applied if no label is
@@ -40,5 +56,6 @@ export declare const ViraDropdown: import("element-vir").DeclarativeElementDefin
40
56
  }, {
41
57
  /** Emits all currently selected values. */
42
58
  selectedValuesChange: import("element-vir").DefineElementEvent<string[]>;
43
- openChange: import("element-vir").DefineElementEvent<ShowPopUpResult | undefined>;
59
+ /** `true` when the popover just opened, `false` when it just closed. */
60
+ openChange: import("element-vir").DefineElementEvent<boolean>;
44
61
  }, "vira-dropdown-", "vira-dropdown-", readonly [], readonly ["leadingIcon", "prefixText", "trigger"]>;