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
@@ -1,88 +0,0 @@
1
- import { css, html } from 'element-vir';
2
- import { viraFormCssVars } from '../../styles/form-styles.js';
3
- import { viraShadows } from '../../styles/shadows.js';
4
- import { defineViraElement } from '../../util/define-vira-element.js';
5
- /**
6
- * Possible corner styles for {@link ViraMenu}.
7
- *
8
- * @category Internal
9
- */
10
- export var ViraMenuCornerStyle;
11
- (function (ViraMenuCornerStyle) {
12
- /** Rounding of corners depends on the open direction of the menu. */
13
- ViraMenuCornerStyle["Directional"] = "directional";
14
- /** All of the menus corners should be rounded. */
15
- ViraMenuCornerStyle["AllRounded"] = "all-rounded";
16
- /** None of the menus corners should be rounded. */
17
- ViraMenuCornerStyle["AllSquare"] = "all-square";
18
- })(ViraMenuCornerStyle || (ViraMenuCornerStyle = {}));
19
- /**
20
- * Menu pop-up directions available for {@link ViraMenu}.
21
- *
22
- * @category Internal
23
- */
24
- export var ViraMenuPopUpDirection;
25
- (function (ViraMenuPopUpDirection) {
26
- ViraMenuPopUpDirection["Downwards"] = "downwards";
27
- ViraMenuPopUpDirection["Upwards"] = "upwards";
28
- })(ViraMenuPopUpDirection || (ViraMenuPopUpDirection = {}));
29
- /**
30
- * A simple default style wrapper for pop-up menus. Consider using `renderMenuItemEntries` to help
31
- * rendering many menu items.
32
- *
33
- * @category PopUp
34
- * @category Elements
35
- */
36
- export const ViraMenu = defineViraElement()({
37
- tagName: 'vira-menu',
38
- hostClasses: {
39
- 'vira-menu-open-upwards'({ inputs }) {
40
- return inputs.direction === ViraMenuPopUpDirection.Upwards;
41
- },
42
- 'vira-menu-rounded'({ inputs }) {
43
- return inputs.cornerStyle === ViraMenuCornerStyle.AllRounded;
44
- },
45
- 'vira-menu-square'({ inputs }) {
46
- return inputs.cornerStyle === ViraMenuCornerStyle.AllSquare;
47
- },
48
- },
49
- styles({ hostClasses }) {
50
- return css `
51
- :host {
52
- display: flex;
53
- flex-direction: column;
54
- max-width: 100%;
55
- max-height: 100%;
56
- overflow-y: auto;
57
- z-index: 99;
58
- box-sizing: border-box;
59
- border-radius: ${viraFormCssVars['vira-form-radius'].value};
60
- border-top-left-radius: 0;
61
- border-top-right-radius: 0;
62
- background-color: ${viraFormCssVars['vira-form-background-color'].value};
63
- border: 1px solid ${viraFormCssVars['vira-form-border-color'].value};
64
- color: ${viraFormCssVars['vira-form-foreground-color'].value};
65
- ${viraShadows.menuShadow}
66
- }
67
-
68
- ${hostClasses['vira-menu-open-upwards'].selector} {
69
- border-radius: ${viraFormCssVars['vira-form-radius'].value};
70
- border-bottom-left-radius: 0;
71
- border-bottom-right-radius: 0;
72
- }
73
-
74
- ${hostClasses['vira-menu-square'].selector} {
75
- border-radius: 0;
76
- }
77
-
78
- ${hostClasses['vira-menu-rounded'].selector} {
79
- border-radius: ${viraFormCssVars['vira-form-radius'].value};
80
- }
81
- `;
82
- },
83
- render() {
84
- return html `
85
- <slot>&nbsp;</slot>
86
- `;
87
- },
88
- });
@@ -1,109 +0,0 @@
1
- import { type PartialWithUndefined } from '@augment-vir/common';
2
- import { NavController, type Coords } from 'device-navigation';
3
- import { PopUpManager, type ShowPopUpResult } from '../../util/pop-up-manager.js';
4
- /**
5
- * Offsets applied to any menu opened by {@link ViraPopUpTrigger}.
6
- *
7
- * @category Internal
8
- */
9
- export type PopUpOffset = PartialWithUndefined<{
10
- vertical: number;
11
- right: number;
12
- left: number;
13
- }>;
14
- /**
15
- * Anchor options for pop-ups.
16
- *
17
- * @category Internal
18
- */
19
- export declare enum HorizontalAnchor {
20
- /**
21
- * The left side of the pop-up will be anchored to the left side of the trigger, allowing the
22
- * pop-up to grow on the right side of the trigger.
23
- */
24
- Left = "left",
25
- /**
26
- * The Right side of the pop-up will be anchored to the right side of the trigger, allowing the
27
- * pop-up to grow on the left side of the trigger.
28
- */
29
- Right = "right",
30
- /** Restrict the pop-up on both sides. */
31
- Both = "both",
32
- /**
33
- * Automatically choose left or right based on available space, defaulting to anchoring on the
34
- * left side.
35
- *
36
- * This is the default anchor for {@link ViraPopUpTrigger}.
37
- */
38
- Auto = "auto"
39
- }
40
- /**
41
- * Configs for {@link ViraPopUpTrigger} pop-up positioning and sizing.
42
- *
43
- * @category Internal
44
- */
45
- export type PopUpTriggerPosition = {
46
- /**
47
- * - `HorizontalAnchor.Left`: pop-up is anchored to the left side of the trigger and the pop-up
48
- * can grow to the right.
49
- * - `HorizontalAnchor.Right`: pop-up is anchored to the right side of the trigger and the pop-up
50
- * can grow to the left.
51
- * - `HorizontalAnchor.Both`: pop-up is anchored on both sides of the trigger and cannot grow
52
- * beyond it.
53
- * - `HorizontalAnchor.Auto`: automatically choose left or right anchor based on available space,
54
- * defaulting to left anchor. (This is the default experience.)
55
- *
56
- * Note that when `HorizontalAnchor.Both` is _not_ used, this anchor will cancel out any
57
- * `popUpOffset` for the direction _opposite_ of the chosen anchor.
58
- */
59
- horizontalAnchor: HorizontalAnchor;
60
- /**
61
- * When `true`, the pop-up will not have its maximum width constrained to fit within the
62
- * overflow container. The positioning logic (left/right) will still be applied.
63
- *
64
- * @default false
65
- */
66
- ignoreMaxWidth: boolean;
67
- /**
68
- * When `true`, the pop-up will not have its maximum height constrained to fit within the
69
- * overflow container. The positioning logic (up/down) will still be applied.
70
- *
71
- * @default false
72
- */
73
- ignoreMaxHeight: boolean;
74
- };
75
- /**
76
- * An element with slots for a pop-up trigger and pop-up contents.
77
- *
78
- * @category PopUp
79
- * @category Elements
80
- * @see https://electrovir.github.io/vira/book/elements/vira-pop-up-trigger
81
- */
82
- export declare const ViraPopUpTrigger: import("element-vir").DeclarativeElementDefinition<`vira-${string}`, PartialWithUndefined<PopUpTriggerPosition & {
83
- isDisabled: boolean;
84
- /** For debugging purposes only. Very bad for actual production code use. */
85
- z_debug_forceOpenState: boolean;
86
- /** Set to `true` to keep the pop-up open if it is interacted with. */
87
- keepOpenAfterInteraction: boolean;
88
- /** All values in px. */
89
- popUpOffset: PopUpOffset;
90
- /** If true, the focus outline is moved inside the element. */
91
- useInsideFocus: boolean;
92
- /** When `true`, the trigger will focus itself when the pop-up closes. */
93
- focusOnClose: boolean;
94
- }>, {
95
- /** `undefined` means the pop up is not currently showing. */
96
- showPopUpResult: ShowPopUpResult | undefined;
97
- popUpManager: PopUpManager;
98
- }, {
99
- navSelect: import("element-vir").DefineElementEvent<Coords>;
100
- /**
101
- * - `undefined` indicates that the pop-up just closed.
102
- * - {@link ShowPopUpResult} indicates that the pop-up just opened.
103
- */
104
- openChange: import("element-vir").DefineElementEvent<ShowPopUpResult | undefined>;
105
- init: import("element-vir").DefineElementEvent<{
106
- navController: NavController;
107
- popUpManager: PopUpManager;
108
- }>;
109
- }, "vira-pop-up-trigger-disabled" | "vira-pop-up-trigger-inside-focus" | "vira-pop-up-trigger-outside-focus", `vira-${string}-`, readonly ["vira-pop-up-trigger-trigger", "vira-pop-up-trigger-pop-up"], readonly []>;
@@ -1,408 +0,0 @@
1
- import { assert, assertWrap } from '@augment-vir/assert';
2
- import { walkActiveElement } from '@augment-vir/web';
3
- import { NavController } from 'device-navigation';
4
- import { classMap, css, defineElementEvent, html, listen, renderIf } from 'element-vir';
5
- import { createFocusStyles } from '../../styles/focus.js';
6
- import { noNativeFormStyles, noUserSelect, viraDisabledStyles } from '../../styles/index.js';
7
- import { defineViraElement } from '../../util/define-vira-element.js';
8
- import { triggerPopUpState } from '../../util/pop-up-helpers.js';
9
- import { HidePopUpEvent, isInputLikeElement, isMouseEventOnScrollbar, NavSelectEvent, PopUpManager, } from '../../util/pop-up-manager.js';
10
- import { ViraMenuItem } from './vira-menu-item.element.js';
11
- /**
12
- * Anchor options for pop-ups.
13
- *
14
- * @category Internal
15
- */
16
- export var HorizontalAnchor;
17
- (function (HorizontalAnchor) {
18
- /**
19
- * The left side of the pop-up will be anchored to the left side of the trigger, allowing the
20
- * pop-up to grow on the right side of the trigger.
21
- */
22
- HorizontalAnchor["Left"] = "left";
23
- /**
24
- * The Right side of the pop-up will be anchored to the right side of the trigger, allowing the
25
- * pop-up to grow on the left side of the trigger.
26
- */
27
- HorizontalAnchor["Right"] = "right";
28
- /** Restrict the pop-up on both sides. */
29
- HorizontalAnchor["Both"] = "both";
30
- /**
31
- * Automatically choose left or right based on available space, defaulting to anchoring on the
32
- * left side.
33
- *
34
- * This is the default anchor for {@link ViraPopUpTrigger}.
35
- */
36
- HorizontalAnchor["Auto"] = "auto";
37
- })(HorizontalAnchor || (HorizontalAnchor = {}));
38
- /**
39
- * An element with slots for a pop-up trigger and pop-up contents.
40
- *
41
- * @category PopUp
42
- * @category Elements
43
- * @see https://electrovir.github.io/vira/book/elements/vira-pop-up-trigger
44
- */
45
- export const ViraPopUpTrigger = defineViraElement()({
46
- tagName: 'vira-pop-up-trigger',
47
- state({ host }) {
48
- return {
49
- /** `undefined` means the pop up is not currently showing. */
50
- showPopUpResult: undefined,
51
- popUpManager: new PopUpManager(new NavController(host, {
52
- activateOnMouseUp: true,
53
- })),
54
- };
55
- },
56
- slotNames: [
57
- 'vira-pop-up-trigger-trigger',
58
- 'vira-pop-up-trigger-pop-up',
59
- ],
60
- hostClasses: {
61
- 'vira-pop-up-trigger-disabled'({ inputs }) {
62
- return !!inputs.isDisabled;
63
- },
64
- 'vira-pop-up-trigger-inside-focus'({ inputs }) {
65
- return !!inputs.useInsideFocus;
66
- },
67
- 'vira-pop-up-trigger-outside-focus'({ inputs }) {
68
- return !inputs.useInsideFocus;
69
- },
70
- },
71
- styles({ hostClasses }) {
72
- return css `
73
- :host {
74
- display: inline-flex;
75
- box-sizing: border-box;
76
- vertical-align: middle;
77
- position: relative;
78
- max-width: 100%;
79
- }
80
-
81
- .dropdown-wrapper {
82
- ${noNativeFormStyles};
83
- cursor: pointer;
84
- max-width: 100%;
85
- position: relative;
86
- flex-grow: 1;
87
- box-sizing: border-box;
88
- }
89
-
90
- ${hostClasses['vira-pop-up-trigger-inside-focus'].selector} .dropdown-wrapper {
91
- ${createFocusStyles({
92
- renderInside: true,
93
- })}
94
- }
95
- ${hostClasses['vira-pop-up-trigger-outside-focus'].selector} .dropdown-wrapper {
96
- ${createFocusStyles()}
97
- }
98
-
99
- .dropdown-trigger {
100
- box-sizing: border-box;
101
- ${noUserSelect};
102
- }
103
-
104
- ${hostClasses['vira-pop-up-trigger-disabled'].selector} {
105
- ${viraDisabledStyles}
106
- pointer-events: auto;
107
- }
108
-
109
- ${hostClasses['vira-pop-up-trigger-disabled'].selector} .dropdown-wrapper {
110
- pointer-events: none;
111
- }
112
-
113
- .pop-up-positioner {
114
- position: absolute;
115
- pointer-events: none;
116
- display: flex;
117
- box-sizing: border-box;
118
- flex-direction: column;
119
- align-items: flex-start;
120
-
121
- /* highest possible z-index */
122
- z-index: 2147483647;
123
-
124
- & > * {
125
- pointer-events: auto;
126
- max-width: 100%;
127
- }
128
-
129
- &.right-aligned {
130
- align-items: flex-end;
131
- }
132
- }
133
-
134
- .open-upwards .pop-up-positioner {
135
- flex-direction: column-reverse;
136
- }
137
- `;
138
- },
139
- events: {
140
- navSelect: defineElementEvent(),
141
- /**
142
- * - `undefined` indicates that the pop-up just closed.
143
- * - {@link ShowPopUpResult} indicates that the pop-up just opened.
144
- */
145
- openChange: defineElementEvent(),
146
- init: defineElementEvent(),
147
- },
148
- cleanup({ state, updateState }) {
149
- updateState({
150
- showPopUpResult: undefined,
151
- });
152
- state.popUpManager.destroy();
153
- },
154
- init({ state, updateState, host, inputs, dispatch, events }) {
155
- /** Refocus the trigger and set the result to `undefined` when the pop up closes. */
156
- state.popUpManager.listen(HidePopUpEvent, () => {
157
- updateState({
158
- showPopUpResult: undefined,
159
- });
160
- dispatch(new events.openChange({
161
- detail: undefined,
162
- }));
163
- if (inputs.focusOnClose && !inputs.isDisabled) {
164
- const dropdownWrapper = host.shadowRoot.querySelector('.dropdown-wrapper');
165
- assert.instanceOf(dropdownWrapper, HTMLButtonElement, 'failed to find dropdown wrapper child');
166
- dropdownWrapper.focus();
167
- }
168
- });
169
- state.popUpManager.listen(NavSelectEvent, (event) => {
170
- if (!inputs.keepOpenAfterInteraction) {
171
- triggerPopUpState({
172
- open: false,
173
- callback(showPopUpResult) {
174
- updateState({
175
- showPopUpResult,
176
- });
177
- },
178
- host,
179
- popUpManager: state.popUpManager,
180
- });
181
- }
182
- dispatch(new events.navSelect({
183
- detail: event.detail,
184
- }));
185
- });
186
- dispatch(new events.init({
187
- detail: {
188
- navController: state.popUpManager.navController,
189
- popUpManager: state.popUpManager,
190
- },
191
- }));
192
- },
193
- render({ dispatch, events, state, inputs, updateState, host, slotNames }) {
194
- function triggerPopUp({ emitEvent, open }, event) {
195
- if (state.showPopUpResult && inputs.keepOpenAfterInteraction && event) {
196
- const dropdownTrigger = host.shadowRoot.querySelector('.dropdown-trigger');
197
- if (dropdownTrigger && !event.composedPath().includes(dropdownTrigger)) {
198
- /**
199
- * Prevent closing the pop-up when `keepOpenAfterInteraction` is turned on and
200
- * the pop-up was interacted with.
201
- */
202
- return;
203
- }
204
- }
205
- triggerPopUpState({
206
- open,
207
- callback(showPopUpResult) {
208
- updateState({
209
- showPopUpResult,
210
- });
211
- if (emitEvent) {
212
- dispatch(new events.openChange({
213
- detail: showPopUpResult,
214
- }));
215
- }
216
- },
217
- host,
218
- popUpManager: state.popUpManager,
219
- });
220
- }
221
- if (inputs.isDisabled) {
222
- triggerPopUp({
223
- open: false,
224
- emitEvent: false,
225
- }, undefined);
226
- }
227
- else if (inputs.z_debug_forceOpenState != undefined) {
228
- if (!inputs.z_debug_forceOpenState && state.showPopUpResult) {
229
- triggerPopUp({
230
- emitEvent: false,
231
- open: false,
232
- }, undefined);
233
- }
234
- else if (inputs.z_debug_forceOpenState && !state.showPopUpResult) {
235
- triggerPopUp({
236
- emitEvent: false,
237
- open: true,
238
- }, undefined);
239
- }
240
- }
241
- /**
242
- * Resolve the effective horizontal anchor. For Auto, use the popRight calculation from
243
- * showPopUpResult to determine whether to anchor left or right.
244
- */
245
- const effectiveHorizontalAnchor = inputs.horizontalAnchor === HorizontalAnchor.Auto ||
246
- inputs.horizontalAnchor == undefined
247
- ? state.showPopUpResult?.popRight
248
- ? HorizontalAnchor.Left
249
- : HorizontalAnchor.Right
250
- : inputs.horizontalAnchor;
251
- const leftCss = effectiveHorizontalAnchor === HorizontalAnchor.Right && state.showPopUpResult
252
- ? inputs.ignoreMaxWidth
253
- ? css `
254
- left: unset;
255
- `
256
- : css `
257
- left: -${state.showPopUpResult.positions.diff.left}px;
258
- `
259
- : css `
260
- left: ${inputs.popUpOffset?.left || 0}px;
261
- `;
262
- const rightCss = state.showPopUpResult && effectiveHorizontalAnchor === HorizontalAnchor.Left
263
- ? inputs.ignoreMaxWidth
264
- ? css `
265
- right: unset;
266
- `
267
- : css `
268
- right: -${state.showPopUpResult.positions.diff.right}px;
269
- `
270
- : css `
271
- right: ${inputs.popUpOffset?.right || 0}px;
272
- `;
273
- const horizontalPositionStyle = css `
274
- ${leftCss}
275
- ${rightCss}
276
- `;
277
- /**
278
- * These styles do _not_ account for window resizing while the menu is open. I decided this
279
- * was not a major enough problem to tackle. If it becomes major enough in the future,
280
- * you'll need to hook into a window _or_ container resize listener inside `PopUpManager`
281
- * and emit a new `ShowPopUpResult` instance when it changes.
282
- */
283
- const positionerStyles = state.showPopUpResult
284
- ? state.showPopUpResult.popDown
285
- ? /** Dropdown going down position. */
286
- inputs.ignoreMaxHeight
287
- ? css `
288
- bottom: unset;
289
- top: calc(100% + ${inputs.popUpOffset?.vertical || 0}px);
290
- ${horizontalPositionStyle}
291
- `
292
- : css `
293
- bottom: -${state.showPopUpResult.positions.diff.bottom}px;
294
- top: calc(100% + ${inputs.popUpOffset?.vertical || 0}px);
295
- ${horizontalPositionStyle}
296
- `
297
- : /** Dropdown going up position. */
298
- inputs.ignoreMaxHeight
299
- ? css `
300
- top: unset;
301
- bottom: calc(100% + ${inputs.popUpOffset?.vertical || 0}px);
302
- ${horizontalPositionStyle}
303
- `
304
- : css `
305
- top: -${state.showPopUpResult.positions.diff.top}px;
306
- bottom: calc(100% + ${inputs.popUpOffset?.vertical || 0}px);
307
- ${horizontalPositionStyle}
308
- `
309
- : undefined;
310
- function respondToClick(event) {
311
- triggerPopUp({
312
- emitEvent: true,
313
- open: !state.showPopUpResult,
314
- }, event);
315
- }
316
- return html `
317
- <button
318
- ?disabled=${!!inputs.isDisabled}
319
- class="dropdown-wrapper ${classMap({
320
- open: !!state.showPopUpResult,
321
- 'open-upwards': !state.showPopUpResult?.popDown,
322
- })}"
323
- role="listbox"
324
- aria-expanded=${!!state.showPopUpResult}
325
- ${listen('keydown', (event) => {
326
- if (!state.showPopUpResult && event.code.startsWith('Arrow')) {
327
- triggerPopUp({
328
- emitEvent: true,
329
- open: true,
330
- }, event);
331
- }
332
- })}
333
- ${listen('click', (event) => {
334
- /** Detail is 0 if it was a keyboard key (like Enter) that triggered this click. */
335
- if (event.detail === 0) {
336
- let isTextActiveElement = false;
337
- walkActiveElement(({ element }) => {
338
- if (isInputLikeElement(element)) {
339
- isTextActiveElement = true;
340
- return true;
341
- }
342
- else {
343
- return false;
344
- }
345
- });
346
- if (isTextActiveElement) {
347
- return;
348
- }
349
- respondToClick(event);
350
- }
351
- else if (event.button === 0 &&
352
- state.showPopUpResult &&
353
- !isMouseEventOnScrollbar(event)) {
354
- const dropdownTrigger = host.shadowRoot.querySelector('.dropdown-trigger');
355
- /**
356
- * Close the menu when a mouse click originates from the pop-up area (e.g. a
357
- * menu item was clicked). The trigger's mousedown already handles
358
- * open/close toggling for the trigger itself.
359
- */
360
- if (dropdownTrigger && !event.composedPath().includes(dropdownTrigger)) {
361
- triggerPopUp({
362
- emitEvent: true,
363
- open: false,
364
- }, event);
365
- }
366
- }
367
- })}
368
- ${listen('mousedown', (event) => {
369
- /** Ignore any clicks that aren't the main button. */
370
- if (event.button !== 0) {
371
- return;
372
- }
373
- const dropdownTrigger = assertWrap.instanceOf(host.shadowRoot.querySelector('.dropdown-trigger'), HTMLElement);
374
- /**
375
- * Only respond if the mousedown originated from the trigger slot, not from
376
- * within the pop-up menu items, to avoid prematurely closing the menu.
377
- */
378
- if (event.composedPath().includes(dropdownTrigger)) {
379
- respondToClick(event);
380
- }
381
- })}
382
- ${listen(ViraMenuItem.events.activate, (event) => {
383
- if (state.showPopUpResult) {
384
- triggerPopUp({
385
- emitEvent: true,
386
- open: false,
387
- }, event);
388
- }
389
- })}
390
- >
391
- <div class="dropdown-trigger">
392
- <slot name=${slotNames['vira-pop-up-trigger-trigger']}></slot>
393
- </div>
394
-
395
- <div
396
- class="pop-up-positioner ${classMap({
397
- 'right-aligned': effectiveHorizontalAnchor === HorizontalAnchor.Right,
398
- })}"
399
- style=${positionerStyles}
400
- >
401
- ${renderIf(!!state.showPopUpResult, html `
402
- <slot name=${slotNames['vira-pop-up-trigger-pop-up']}></slot>
403
- `)}
404
- </div>
405
- </button>
406
- `;
407
- },
408
- });
@@ -1,44 +0,0 @@
1
- import { type PartialWithUndefined } from '@augment-vir/common';
2
- import { type AttributeValues } from 'element-vir';
3
- import { type ViraIconSvg } from '../icons/index.js';
4
- import { type ViraSelectOption, type ViraSelectOptionGroup } from '../util/vira-select-option.js';
5
- /**
6
- * Similar to {@link ViraDropdown} but is, instead, simply a wrapper for `<select>` and nothing more.
7
- *
8
- * @category Dropdown
9
- * @category Elements
10
- * @see https://electrovir.github.io/vira/book/elements/vira-select
11
- */
12
- export declare const ViraSelect: import("element-vir").DeclarativeElementDefinition<"vira-select", {
13
- options: ReadonlyArray<Readonly<ViraSelectOption> | Readonly<ViraSelectOptionGroup>>;
14
- /** The currently selected option value. */
15
- value: undefined | string;
16
- } & PartialWithUndefined<{
17
- icon: Readonly<ViraIconSvg>;
18
- placeholder: string;
19
- label: string;
20
- /** If set to `true`, only minimal styles are applied. */
21
- rawSelect: boolean;
22
- disabled: boolean;
23
- /**
24
- * When `true`, the currently selected option's label is rendered as plain text with no
25
- * wrapper, border, or focus styles.
26
- */
27
- isReadonly: boolean;
28
- attributePassthrough: Readonly<PartialWithUndefined<{
29
- label: AttributeValues;
30
- select: AttributeValues;
31
- option: AttributeValues;
32
- }>>;
33
- hasError: boolean;
34
- }>, {
35
- /**
36
- * Used to couple the label and select together. This is not applied if no label is
37
- * provided.
38
- */
39
- randomId: string;
40
- /** Removes event listeners registered during init. */
41
- cleanupListeners: undefined | (() => void);
42
- }, {
43
- valueChange: import("element-vir").DefineElementEvent<string>;
44
- }, "vira-select-disabled" | "vira-select-error" | "vira-select-has-label" | "vira-select-not-raw" | "vira-select-readonly", "vira-select-padding-horizontal" | "vira-select-padding-vertical" | "vira-select-icon-padding", readonly [], readonly []>;