@sveltia/ui 0.1.4 → 0.2.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 (105) hide show
  1. package/package.json +23 -12
  2. package/package/components/composite/calendar.svelte +0 -240
  3. package/package/components/composite/calendar.svelte.d.ts +0 -20
  4. package/package/components/composite/checkbox-group.svelte +0 -43
  5. package/package/components/composite/checkbox-group.svelte.d.ts +0 -24
  6. package/package/components/composite/combobox.svelte +0 -197
  7. package/package/components/composite/combobox.svelte.d.ts +0 -32
  8. package/package/components/composite/disclosure.svelte +0 -60
  9. package/package/components/composite/disclosure.svelte.d.ts +0 -26
  10. package/package/components/composite/grid.svelte +0 -24
  11. package/package/components/composite/grid.svelte.d.ts +0 -22
  12. package/package/components/composite/listbox.svelte +0 -63
  13. package/package/components/composite/listbox.svelte.d.ts +0 -39
  14. package/package/components/composite/menu-item-group.svelte +0 -31
  15. package/package/components/composite/menu-item-group.svelte.d.ts +0 -23
  16. package/package/components/composite/menu.svelte +0 -44
  17. package/package/components/composite/menu.svelte.d.ts +0 -32
  18. package/package/components/composite/radio-button-group.svelte +0 -45
  19. package/package/components/composite/radio-button-group.svelte.d.ts +0 -27
  20. package/package/components/composite/select-button-group.svelte +0 -70
  21. package/package/components/composite/select-button-group.svelte.d.ts +0 -31
  22. package/package/components/composite/select.svelte +0 -34
  23. package/package/components/composite/select.svelte.d.ts +0 -26
  24. package/package/components/composite/tab-list.svelte +0 -76
  25. package/package/components/composite/tab-list.svelte.d.ts +0 -42
  26. package/package/components/core/button.svelte +0 -205
  27. package/package/components/core/button.svelte.d.ts +0 -78
  28. package/package/components/core/checkbox.svelte +0 -107
  29. package/package/components/core/checkbox.svelte.d.ts +0 -30
  30. package/package/components/core/dialog.svelte +0 -274
  31. package/package/components/core/dialog.svelte.d.ts +0 -45
  32. package/package/components/core/grid-cell.svelte +0 -14
  33. package/package/components/core/grid-cell.svelte.d.ts +0 -21
  34. package/package/components/core/group.svelte +0 -31
  35. package/package/components/core/group.svelte.d.ts +0 -23
  36. package/package/components/core/icon.svelte +0 -21
  37. package/package/components/core/icon.svelte.d.ts +0 -20
  38. package/package/components/core/menu-button.svelte +0 -57
  39. package/package/components/core/menu-button.svelte.d.ts +0 -30
  40. package/package/components/core/menu-item-checkbox.svelte +0 -24
  41. package/package/components/core/menu-item-checkbox.svelte.d.ts +0 -24
  42. package/package/components/core/menu-item-radio.svelte +0 -19
  43. package/package/components/core/menu-item-radio.svelte.d.ts +0 -24
  44. package/package/components/core/menu-item.svelte +0 -113
  45. package/package/components/core/menu-item.svelte.d.ts +0 -29
  46. package/package/components/core/number-input.svelte +0 -112
  47. package/package/components/core/number-input.svelte.d.ts +0 -28
  48. package/package/components/core/option.svelte +0 -59
  49. package/package/components/core/option.svelte.d.ts +0 -35
  50. package/package/components/core/password-input.svelte +0 -81
  51. package/package/components/core/password-input.svelte.d.ts +0 -25
  52. package/package/components/core/radio-button.svelte +0 -93
  53. package/package/components/core/radio-button.svelte.d.ts +0 -27
  54. package/package/components/core/row-group.svelte +0 -14
  55. package/package/components/core/row-group.svelte.d.ts +0 -21
  56. package/package/components/core/row.svelte +0 -14
  57. package/package/components/core/row.svelte.d.ts +0 -23
  58. package/package/components/core/search-bar.svelte +0 -90
  59. package/package/components/core/search-bar.svelte.d.ts +0 -35
  60. package/package/components/core/select-button.svelte +0 -31
  61. package/package/components/core/select-button.svelte.d.ts +0 -35
  62. package/package/components/core/separator.svelte +0 -28
  63. package/package/components/core/separator.svelte.d.ts +0 -20
  64. package/package/components/core/slider.svelte +0 -270
  65. package/package/components/core/slider.svelte.d.ts +0 -35
  66. package/package/components/core/spacer.svelte +0 -22
  67. package/package/components/core/spacer.svelte.d.ts +0 -19
  68. package/package/components/core/switch.svelte +0 -80
  69. package/package/components/core/switch.svelte.d.ts +0 -27
  70. package/package/components/core/tab-panel.svelte +0 -23
  71. package/package/components/core/tab-panel.svelte.d.ts +0 -25
  72. package/package/components/core/tab.svelte +0 -22
  73. package/package/components/core/tab.svelte.d.ts +0 -31
  74. package/package/components/core/text-area.svelte +0 -90
  75. package/package/components/core/text-area.svelte.d.ts +0 -43
  76. package/package/components/core/text-input.svelte +0 -145
  77. package/package/components/core/text-input.svelte.d.ts +0 -53
  78. package/package/components/core/toolbar.svelte +0 -74
  79. package/package/components/core/toolbar.svelte.d.ts +0 -26
  80. package/package/components/editor/markdown.svelte +0 -78
  81. package/package/components/editor/markdown.svelte.d.ts +0 -19
  82. package/package/components/helpers/group.d.ts +0 -37
  83. package/package/components/helpers/group.js +0 -246
  84. package/package/components/helpers/popup.d.ts +0 -26
  85. package/package/components/helpers/popup.js +0 -146
  86. package/package/components/helpers/util.d.ts +0 -1
  87. package/package/components/helpers/util.js +0 -8
  88. package/package/components/util/app-shell.svelte +0 -284
  89. package/package/components/util/app-shell.svelte.d.ts +0 -28
  90. package/package/components/util/misc.d.ts +0 -2
  91. package/package/components/util/misc.js +0 -22
  92. package/package/components/util/popup.svelte +0 -131
  93. package/package/components/util/popup.svelte.d.ts +0 -37
  94. package/package/components/util/portal.svelte +0 -34
  95. package/package/components/util/portal.svelte.d.ts +0 -21
  96. package/package/index.d.ts +0 -41
  97. package/package/index.js +0 -66
  98. package/package/locales/en.d.ts +0 -42
  99. package/package/locales/en.js +0 -41
  100. package/package/locales/ja.d.ts +0 -42
  101. package/package/locales/ja.js +0 -41
  102. package/package/styles/core.scss +0 -134
  103. package/package/styles/variables.scss +0 -114
  104. package/package/typedef.d.ts +0 -0
  105. package/package/typedef.js +0 -0
@@ -1,145 +0,0 @@
1
- <!--
2
- @component
3
- @see https://w3c.github.io/aria/#textbox
4
- -->
5
- <svelte:options accessors={true} />
6
-
7
- <script>
8
- import { getRandomId } from '../helpers/util';
9
-
10
- /**
11
- * CSS class name on the button.
12
- * @type {String}
13
- */
14
- let className = '';
15
-
16
- export { className as class };
17
-
18
- /** @type {(HTMLInputElement|undefined)} */
19
- export let element = undefined;
20
-
21
- /** @type {('textbox'|'searchbox'|'combobox'|'spinbutton')} */
22
- export let role = 'textbox';
23
-
24
- /**
25
- * Whether the textbox is editable.
26
- */
27
- export let readOnly = false;
28
-
29
- export let disabled = false;
30
-
31
- export let name = '';
32
-
33
- /** @type {(String|undefined)} */
34
- export let value = undefined;
35
-
36
- const id = getRandomId('input');
37
- let ariaLabel = '';
38
-
39
- $: {
40
- // Replace `aria-label` with a visible label if `<input placeholder>` is not defined
41
- if ('aria-label' in $$restProps && !('placeholder' in $$restProps)) {
42
- ariaLabel = $$restProps['aria-label'];
43
- delete $$restProps['aria-label'];
44
- $$restProps['aria-labelledby'] = `${id}-label`;
45
- }
46
- }
47
- </script>
48
-
49
- <div class="sui text-input {className}">
50
- <input
51
- type="text"
52
- {role}
53
- name={name || undefined}
54
- {readOnly}
55
- aria-readonly={readOnly ? true : undefined}
56
- {disabled}
57
- aria-disabled={disabled ? true : undefined}
58
- {...$$restProps}
59
- bind:this={element}
60
- bind:value
61
- on:input
62
- on:keydown
63
- on:keyup
64
- on:keypress
65
- on:change
66
- />
67
- {#if ariaLabel}
68
- <span id="{id}-label" class="label" class:hidden={!!value}>
69
- {ariaLabel}
70
- </span>
71
- {/if}
72
- </div>
73
-
74
- <style>.text-input {
75
- position: relative;
76
- width: 100%;
77
- display: inline-flex;
78
- align-items: center;
79
- }
80
-
81
- input {
82
- z-index: 1;
83
- display: inline-block;
84
- flex: auto;
85
- border-width: 1px;
86
- border-color: var(--control-border-color);
87
- border-radius: var(--input--medium--border-radius);
88
- padding: 0 8px;
89
- min-width: 0;
90
- height: var(--input--medium--height);
91
- background-color: var(--control-background-color);
92
- color: inherit;
93
- font-family: inherit;
94
- font-size: inherit;
95
- line-height: 30px;
96
- transition: all 200ms;
97
- }
98
- input:focus {
99
- border-color: var(--primary-accent-color);
100
- }
101
- input:read-only {
102
- color: var(--ternary-foreground-color);
103
- border-color: var(--control-border-color) !important;
104
- }
105
- input:disabled {
106
- background-color: var(--disabled-background-color);
107
- opacity: 0.4;
108
- cursor: default;
109
- }
110
- input[aria-invalid=true] {
111
- border-color: deeppink;
112
- }
113
- input ~ :global(button) {
114
- flex: none;
115
- margin-left: -1px;
116
- border-width: 1px;
117
- border-color: var(--control-border-color);
118
- height: var(--input--medium--height);
119
- aspect-ratio: 1/1;
120
- }
121
- input ~ :global(button):last-child {
122
- border-radius: 0 4px 4px 0;
123
- }
124
- input ~ :global(button) :global(.icon) {
125
- font-size: 20px;
126
- }
127
-
128
- .label {
129
- position: absolute;
130
- inset: 0 8px;
131
- z-index: 2;
132
- display: flex;
133
- justify-content: var(--input-label-align, flex-start);
134
- align-items: center;
135
- color: var(--primary-foreground-color);
136
- opacity: 0.5;
137
- pointer-events: none;
138
- }
139
- .label.hidden {
140
- opacity: 0;
141
- }
142
-
143
- input:focus + .label {
144
- opacity: 0;
145
- }</style>
@@ -1,53 +0,0 @@
1
- /** @typedef {typeof __propDef.props} TextInputProps */
2
- /** @typedef {typeof __propDef.events} TextInputEvents */
3
- /** @typedef {typeof __propDef.slots} TextInputSlots */
4
- /** @see https://w3c.github.io/aria/#textbox */
5
- export default class TextInput {
6
- /**accessor*/
7
- set class(arg: any);
8
- get class(): any;
9
- /**accessor*/
10
- set element(arg: any);
11
- get element(): any;
12
- /**accessor*/
13
- set role(arg: any);
14
- get role(): any;
15
- /**accessor*/
16
- set readOnly(arg: any);
17
- get readOnly(): any;
18
- /**accessor*/
19
- set disabled(arg: any);
20
- get disabled(): any;
21
- /**accessor*/
22
- set name(arg: any);
23
- get name(): any;
24
- /**accessor*/
25
- set value(arg: any);
26
- get value(): any;
27
- }
28
- export type TextInputProps = typeof __propDef.props;
29
- export type TextInputEvents = typeof __propDef.events;
30
- export type TextInputSlots = typeof __propDef.slots;
31
- declare const __propDef: {
32
- props: {
33
- [x: string]: any;
34
- class?: string;
35
- element?: (HTMLInputElement | undefined);
36
- role?: ('textbox' | 'searchbox' | 'combobox' | 'spinbutton');
37
- disabled?: boolean;
38
- name?: string;
39
- value?: (string | undefined);
40
- readOnly?: boolean;
41
- };
42
- events: {
43
- input: Event;
44
- keydown: KeyboardEvent;
45
- keyup: KeyboardEvent;
46
- keypress: KeyboardEvent;
47
- change: Event;
48
- } & {
49
- [evt: string]: CustomEvent<any>;
50
- };
51
- slots: {};
52
- };
53
- export {};
@@ -1,74 +0,0 @@
1
- <!--
2
- @component
3
- @see https://w3c.github.io/aria/#toolbar
4
- @see https://w3c.github.io/aria-practices/#toolbar
5
- -->
6
- <script>
7
- /**
8
- * CSS class name on the button.
9
- * @type {String}
10
- */
11
- // eslint-disable-next-line padding-line-between-statements
12
- let className = '';
13
-
14
- export { className as class };
15
-
16
- /**
17
- * Define the `aria-orientation` property on the toolbar element.
18
- * @type {('horizontal'|'vertical')}
19
- */
20
- export let orientation = 'horizontal';
21
- </script>
22
-
23
- <div
24
- class="sui toolbar {orientation} {className}"
25
- role="toolbar"
26
- aria-orientation={orientation}
27
- {...$$restProps}
28
- >
29
- <slot />
30
- </div>
31
-
32
- <style>[role=toolbar] {
33
- --toolbar-size: 40px;
34
- flex: none !important;
35
- display: flex;
36
- align-items: center;
37
- gap: 8px;
38
- padding: 8px;
39
- }
40
- [role=toolbar].primary {
41
- --toolbar-size: 48px;
42
- background-color: var(--secondary-background-color);
43
- }
44
- [role=toolbar].secondary {
45
- background-color: var(--ternary-background-color);
46
- }
47
- [role=toolbar][aria-orientation=horizontal] {
48
- height: var(--toolbar-size);
49
- }
50
- [role=toolbar][aria-orientation=vertical] {
51
- flex-direction: column;
52
- width: var(--toolbar-size);
53
- }
54
- [role=toolbar]:not(:last-child) {
55
- border-width: 0 0 1px;
56
- border-color: var(--primary-border-color);
57
- }
58
- [role=toolbar] :global(button[role="button"][aria-pressed="true"]),
59
- [role=toolbar] :global(button[role="button"][aria-checked="true"]) {
60
- background-color: var(--highlight-background-color);
61
- }
62
- [role=toolbar] :global(h2) {
63
- display: flex;
64
- align-items: center;
65
- gap: 8px;
66
- margin: 0;
67
- padding: 0 8px;
68
- font-size: 16px;
69
- }
70
- [role=toolbar] :global(h2) :global(span) {
71
- font-size: 12px;
72
- font-weight: normal;
73
- opacity: 0.8;
74
- }</style>
@@ -1,26 +0,0 @@
1
- /** @typedef {typeof __propDef.props} ToolbarProps */
2
- /** @typedef {typeof __propDef.events} ToolbarEvents */
3
- /** @typedef {typeof __propDef.slots} ToolbarSlots */
4
- /**
5
- * @see https://w3c.github.io/aria/#toolbar
6
- * @see https://w3c.github.io/aria-practices/#toolbar
7
- */
8
- export default class Toolbar {
9
- }
10
- export type ToolbarProps = typeof __propDef.props;
11
- export type ToolbarEvents = typeof __propDef.events;
12
- export type ToolbarSlots = typeof __propDef.slots;
13
- declare const __propDef: {
14
- props: {
15
- [x: string]: any;
16
- class?: string;
17
- orientation?: ('horizontal' | 'vertical');
18
- };
19
- events: {
20
- [evt: string]: CustomEvent<any>;
21
- };
22
- slots: {
23
- default: {};
24
- };
25
- };
26
- export {};
@@ -1,78 +0,0 @@
1
- <script>
2
- import { _ } from 'svelte-i18n';
3
- import Button from '../core/button.svelte';
4
- import Icon from '../core/icon.svelte';
5
- import Separator from '../core/separator.svelte';
6
- import TextArea from '../core/text-area.svelte';
7
- import Toolbar from '../core/toolbar.svelte';
8
-
9
- /** @type {(String|undefined)} */
10
- export let value = undefined;
11
-
12
- export let disabled = false;
13
-
14
- const defaultButtons = [
15
- { name: 'bold', label: $_('sui.markdown_editor.bold'), icon: 'format_bold' },
16
- { name: 'italic', label: $_('sui.markdown_editor.italic'), icon: 'format_italic' },
17
- { name: 'code', label: $_('sui.markdown_editor.code'), icon: 'code' },
18
- { name: 'link', label: $_('sui.markdown_editor.link'), icon: 'link' },
19
- { separator: true },
20
- {
21
- name: 'heading-one',
22
- label: $_('sui.markdown_editor.heading_x', { values: { level: 1 } }),
23
- icon: 'format_h1',
24
- },
25
- {
26
- name: 'heading-two',
27
- label: $_('sui.markdown_editor.heading_x', { values: { level: 2 } }),
28
- icon: 'format_h2',
29
- },
30
- { name: 'quote', label: $_('sui.markdown_editor.quote'), icon: 'format_quote' },
31
- { separator: true },
32
- {
33
- name: 'bulleted-list',
34
- label: $_('sui.markdown_editor.bulleted_list'),
35
- icon: 'format_list_bulleted',
36
- },
37
- {
38
- name: 'numbered-list',
39
- label: $_('sui.markdown_editor.numbered_list'),
40
- icon: 'format_list_numbered',
41
- },
42
- ];
43
- </script>
44
-
45
- <div>
46
- <Toolbar aria-label={$_('sui.markdown_editor.markdown_editor')}>
47
- {#each defaultButtons as { label, icon, separator }}
48
- {#if separator}
49
- <Separator />
50
- {:else}
51
- <Button {disabled}>
52
- <Icon slot="start-icon" name={icon} {label} />
53
- </Button>
54
- {/if}
55
- {/each}
56
- </Toolbar>
57
- <TextArea autoResize={true} {disabled} bind:value />
58
- </div>
59
-
60
- <style>div {
61
- display: contents;
62
- }
63
- div :global([role="toolbar"]) {
64
- display: flex;
65
- gap: 8px;
66
- border-radius: 4px 4px 0 0;
67
- padding: 8px;
68
- background-color: var(--ternary-background-color);
69
- }
70
- div :global([role="toolbar"]) :global(button) {
71
- flex: none;
72
- }
73
- div :global([role="toolbar"]) + :global(div) {
74
- width: 100%;
75
- }
76
- div :global([role="toolbar"]) + :global(div) :global(textarea) {
77
- border-radius: 0 0 4px 4px !important;
78
- }</style>
@@ -1,19 +0,0 @@
1
- /** @typedef {typeof __propDef.props} MarkdownProps */
2
- /** @typedef {typeof __propDef.events} MarkdownEvents */
3
- /** @typedef {typeof __propDef.slots} MarkdownSlots */
4
- export default class Markdown {
5
- }
6
- export type MarkdownProps = typeof __propDef.props;
7
- export type MarkdownEvents = typeof __propDef.events;
8
- export type MarkdownSlots = typeof __propDef.slots;
9
- declare const __propDef: {
10
- props: {
11
- disabled?: boolean;
12
- value?: (string | undefined);
13
- };
14
- events: {
15
- [evt: string]: CustomEvent<any>;
16
- };
17
- slots: {};
18
- };
19
- export {};
@@ -1,37 +0,0 @@
1
- export function activateGroup(...args: any[]): Promise<Group>;
2
- /**
3
- * Implement keyboard and mouse interactions for a grouping composite widget.
4
- */
5
- declare class Group {
6
- /**
7
- *
8
- * @param {HTMLElement} parent
9
- * @todo Check for added elements probably with `MutationObserver`.
10
- */
11
- constructor(parent: HTMLElement);
12
- parent: HTMLElement;
13
- role: string;
14
- grid: boolean;
15
- multi: boolean;
16
- id: string;
17
- parentGroupSelector: string;
18
- orientation: any;
19
- childSelectedAttr: any;
20
- /** @type {string} */
21
- get selector(): string;
22
- /** @type {HTMLElement[]} */
23
- get allMembers(): HTMLElement[];
24
- /** @type {HTMLElement[]} */
25
- get activeMembers(): HTMLElement[];
26
- /**
27
- *
28
- * @param {KeyboardEvent}
29
- */
30
- onClick(event: any): void;
31
- /**
32
- *
33
- * @param {KeyboardEvent}
34
- */
35
- onKeyDown(event: any): void;
36
- }
37
- export {};
@@ -1,246 +0,0 @@
1
- /* eslint-disable no-plusplus */
2
- /* eslint-disable no-param-reassign */
3
-
4
- import { sleep } from '../util/misc';
5
- import { getRandomId } from './util';
6
-
7
- const config = {
8
- grid: {
9
- orientation: 'vertical',
10
- childRoles: ['row'],
11
- childSelectedAttr: 'aria-selected',
12
- },
13
- listbox: {
14
- orientation: 'vertical',
15
- childRoles: ['option'],
16
- childSelectedAttr: 'aria-selected',
17
- },
18
- menu: {
19
- orientation: 'vertical',
20
- childRoles: ['menuitem', 'menuitemcheckbox', 'menuitemradio'],
21
- childSelectedAttr: 'aria-checked',
22
- },
23
- menubar: {
24
- orientation: 'horizontal',
25
- childRoles: ['menuitem', 'menuitemcheckbox', 'menuitemradio'],
26
- childSelectedAttr: 'aria-checked',
27
- },
28
- radiogroup: {
29
- orientation: 'horizontal',
30
- childRoles: ['radio'],
31
- childSelectedAttr: 'aria-checked',
32
- },
33
- tablist: {
34
- orientation: 'horizontal',
35
- childRoles: ['tab'],
36
- childSelectedAttr: 'aria-selected',
37
- },
38
- };
39
-
40
- /**
41
- * Implement keyboard and mouse interactions for a grouping composite widget.
42
- */
43
- class Group {
44
- /**
45
- *
46
- * @param {HTMLElement} parent
47
- * @todo Check for added elements probably with `MutationObserver`.
48
- */
49
- constructor(parent) {
50
- this.parent = parent;
51
- this.role = parent.getAttribute('role');
52
- this.grid = this.role === 'listbox' && parent.matches('.grid');
53
- this.multi = this.parent.getAttribute('aria-multiselectable') === 'true';
54
- this.id = getRandomId(this.role);
55
- this.parentGroupSelector = `[role="group"], [role="${this.role}"]`;
56
-
57
- const { orientation, childSelectedAttr } = config[this.role];
58
-
59
- this.orientation = this.grid
60
- ? 'horizontal'
61
- : this.parent.getAttribute('aria-orientation') || orientation;
62
- this.childSelectedAttr = childSelectedAttr;
63
-
64
- const { allMembers } = this;
65
-
66
- const hasSelected = allMembers.some((element) =>
67
- element.matches(`[${childSelectedAttr}="true"]`),
68
- );
69
-
70
- allMembers.forEach((element, index) => {
71
- const isSelected = element.matches(`[${childSelectedAttr}="true"]`);
72
- const controls = document.querySelector(`#${element.getAttribute('aria-controls')}`);
73
-
74
- element.id ||= `${this.id}-item-${index}`;
75
- element.tabIndex ||= isSelected || (!hasSelected && index === 0) ? 0 : -1;
76
- element.setAttribute(this.childSelectedAttr, isSelected);
77
- controls?.setAttribute('aria-labelledby', element.id);
78
- controls?.setAttribute('aria-hidden', !isSelected);
79
- });
80
-
81
- parent.addEventListener('click', (event) => {
82
- this.onClick(event);
83
- });
84
-
85
- parent.addEventListener('keydown', (event) => {
86
- this.onKeyDown(event);
87
- });
88
- }
89
-
90
- /** @type {string} */
91
- get selector() {
92
- const roles = config[this.role].childRoles;
93
-
94
- return roles ? roles.map((role) => `[role="${role}"]`).join(',') : '';
95
- }
96
-
97
- /** @type {HTMLElement[]} */
98
- get allMembers() {
99
- return [...this.parent.querySelectorAll(this.selector)];
100
- }
101
-
102
- /** @type {HTMLElement[]} */
103
- get activeMembers() {
104
- return this.allMembers.filter((element) => !element.matches('[aria-disabled="true"]'));
105
- }
106
-
107
- /**
108
- *
109
- * @param {KeyboardEvent}
110
- */
111
- onClick(event) {
112
- const { target } = event;
113
-
114
- if (!target.matches(this.selector)) {
115
- return;
116
- }
117
-
118
- const targetParentGroup = target.closest(this.parentGroupSelector);
119
-
120
- this.allMembers.forEach((element) => {
121
- const isTarget = element === target;
122
-
123
- element.tabIndex = element === target ? 0 : -1;
124
-
125
- // Groups can be nested, e.g. `menu` > `group` > `menuitem`, so check if the parent is the
126
- // same as the target’s parent
127
- if (
128
- (element.matches('[role="radio"], [role="menuitemradio"]') ||
129
- (element.matches('[role="row"], [role="option"], [role="tab"]') && !this.multi)) &&
130
- element.closest(this.parentGroupSelector) === targetParentGroup
131
- ) {
132
- element.setAttribute(this.childSelectedAttr, isTarget);
133
- }
134
-
135
- const controls = element.getAttribute('aria-controls');
136
-
137
- if (controls) {
138
- document.getElementById(controls)?.setAttribute('aria-hidden', !isTarget);
139
- }
140
- });
141
-
142
- this.parent.dispatchEvent(
143
- new CustomEvent('select', {
144
- detail: {
145
- value: target.value,
146
- name: target.name,
147
- },
148
- }),
149
- );
150
- }
151
-
152
- /**
153
- *
154
- * @param {KeyboardEvent}
155
- */
156
- onKeyDown(event) {
157
- const { target, key, ctrlKey, metaKey, shiftKey, altKey } = event;
158
-
159
- if (target.matches(this.selector) && !ctrlKey && !metaKey && !shiftKey && !altKey) {
160
- if ([' ', 'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'].includes(key)) {
161
- event.preventDefault();
162
- }
163
-
164
- if (key === ' ' || (key === 'Enter' && !target.matches('button'))) {
165
- event.preventDefault();
166
- target.click();
167
-
168
- return;
169
- }
170
-
171
- const { allMembers, activeMembers } = this;
172
- let index;
173
- let newTarget;
174
-
175
- if (this.grid) {
176
- const colCount = Math.floor(this.parent.clientWidth / target.clientWidth);
177
-
178
- index = allMembers.indexOf(target);
179
-
180
- if (key === 'ArrowUp' && index > 0) {
181
- newTarget = allMembers[index - colCount];
182
- }
183
-
184
- if (key === 'ArrowDown' && index < allMembers.length - 1) {
185
- newTarget = allMembers[index + colCount];
186
- }
187
-
188
- if (key === 'ArrowLeft' && index > 0) {
189
- newTarget = allMembers[index - 1];
190
- }
191
-
192
- if (key === 'ArrowRight' && index < allMembers.length - 1) {
193
- newTarget = allMembers[index + 1];
194
- }
195
-
196
- if (newTarget?.getAttribute('aria-disabled') === 'true') {
197
- newTarget = undefined;
198
- }
199
- } else {
200
- index = activeMembers.indexOf(target);
201
-
202
- if (key === (this.orientation === 'horizontal' ? 'ArrowLeft' : 'ArrowUp')) {
203
- if (index > 0) {
204
- // Previous member
205
- newTarget = activeMembers[index - 1];
206
- }
207
-
208
- if (index === 0) {
209
- // Last member
210
- newTarget = activeMembers[activeMembers.length - 1];
211
- }
212
- }
213
-
214
- if (key === (this.orientation === 'horizontal' ? 'ArrowRight' : 'ArrowDown')) {
215
- if (index < activeMembers.length - 1) {
216
- // Next member
217
- newTarget = activeMembers[index + 1];
218
- }
219
-
220
- if (index === activeMembers.length - 1) {
221
- // First member
222
- [newTarget] = activeMembers;
223
- }
224
- }
225
- }
226
-
227
- if (newTarget && newTarget !== target) {
228
- activeMembers.forEach((element) => {
229
- element.tabIndex = element === newTarget ? 0 : -1;
230
- });
231
-
232
- newTarget.focus();
233
- }
234
- }
235
- }
236
- }
237
-
238
- /**
239
- *
240
- */
241
- export const activateGroup = async (...args) => {
242
- // Wait a bit before the relevant components, including the `aria-controls` target are mounted
243
- await sleep(100);
244
-
245
- return new Group(...args);
246
- };
@@ -1,26 +0,0 @@
1
- export function activatePopup(...args: any[]): Popup;
2
- export type PopupPosition = ('top-left' | 'top-right' | 'right-top' | 'right-bottom' | 'bottom-left' | 'bottom-right' | 'left-top' | 'left-bottom');
3
- /**
4
- * @typedef {('top-left'|'top-right'|'right-top'|'right-bottom'|'bottom-left'|'bottom-right'|'left-top'|'left-bottom')} PopupPosition
5
- */
6
- declare class Popup {
7
- /**
8
- *
9
- * @param {HTMLElement} anchorElement
10
- * @param {HTMLElement} popupElement
11
- * @param {PopupPosition} position
12
- */
13
- constructor(anchorElement: HTMLElement, popupElement: HTMLElement, position: PopupPosition);
14
- open: any;
15
- style: any;
16
- observer: IntersectionObserver;
17
- anchorElement: HTMLElement;
18
- popupElement: HTMLElement;
19
- position: PopupPosition;
20
- id: string;
21
- /**
22
- * Continue checking the position in case the window or parent element resizes.
23
- */
24
- checkPosition(): void;
25
- }
26
- export {};