fluentui-webcomponents 0.0.1

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 (59) hide show
  1. package/AGENTS.md +212 -0
  2. package/README.md +99 -0
  3. package/components/avatar/fluent-avatar.css +481 -0
  4. package/components/avatar/fluent-avatar.js +80 -0
  5. package/components/badge/fluent-badge.css +289 -0
  6. package/components/badge/fluent-badge.js +20 -0
  7. package/components/breadcrumb/fluent-breadcrumb.css +29 -0
  8. package/components/breadcrumb/fluent-breadcrumb.js +33 -0
  9. package/components/breadcrumb-item/fluent-breadcrumb-item.css +70 -0
  10. package/components/breadcrumb-item/fluent-breadcrumb-item.js +77 -0
  11. package/components/button/fluent-button.css +265 -0
  12. package/components/button/fluent-button.js +326 -0
  13. package/components/card/fluent-card.css +85 -0
  14. package/components/card/fluent-card.js +21 -0
  15. package/components/checkbox/fluent-checkbox.css +171 -0
  16. package/components/checkbox/fluent-checkbox.js +294 -0
  17. package/components/dialog/fluent-dialog.css +82 -0
  18. package/components/dialog/fluent-dialog.js +137 -0
  19. package/components/divider/fluent-divider.css +124 -0
  20. package/components/divider/fluent-divider.js +14 -0
  21. package/components/image/fluent-image.css +73 -0
  22. package/components/image/fluent-image.js +36 -0
  23. package/components/label/fluent-label.css +49 -0
  24. package/components/label/fluent-label.js +61 -0
  25. package/components/link/fluent-link.css +72 -0
  26. package/components/link/fluent-link.js +109 -0
  27. package/components/menu/fluent-menu.css +57 -0
  28. package/components/menu/fluent-menu.js +202 -0
  29. package/components/menu-item/fluent-menu-item.css +152 -0
  30. package/components/menu-item/fluent-menu-item.js +177 -0
  31. package/components/popover/fluent-popover.css +95 -0
  32. package/components/popover/fluent-popover.js +93 -0
  33. package/components/radio/fluent-radio.css +123 -0
  34. package/components/radio/fluent-radio.js +257 -0
  35. package/components/select/fluent-select.css +194 -0
  36. package/components/select/fluent-select.js +245 -0
  37. package/components/slider/fluent-slider.css +199 -0
  38. package/components/slider/fluent-slider.js +438 -0
  39. package/components/spinner/fluent-spinner.css +160 -0
  40. package/components/spinner/fluent-spinner.js +30 -0
  41. package/components/switch/fluent-switch.css +154 -0
  42. package/components/switch/fluent-switch.js +260 -0
  43. package/components/text/fluent-text.css +128 -0
  44. package/components/text/fluent-text.js +21 -0
  45. package/components/text-input/fluent-text-input.css +227 -0
  46. package/components/text-input/fluent-text-input.js +298 -0
  47. package/components/textarea/fluent-textarea.css +227 -0
  48. package/components/textarea/fluent-textarea.js +400 -0
  49. package/components/tooltip/fluent-tooltip.css +65 -0
  50. package/components/tooltip/fluent-tooltip.js +102 -0
  51. package/components/tree/fluent-tree.css +16 -0
  52. package/components/tree/fluent-tree.js +167 -0
  53. package/components/tree-item/fluent-tree-item.css +147 -0
  54. package/components/tree-item/fluent-tree-item.js +163 -0
  55. package/core/fluent-element.js +34 -0
  56. package/gallery.html +492 -0
  57. package/package.json +19 -0
  58. package/theme/theme-picker.js +38 -0
  59. package/tokens.css +724 -0
@@ -0,0 +1,171 @@
1
+ @import url('../../tokens.css');
2
+
3
+ :host { display: inline-flex; }
4
+
5
+ :host([hidden]) .root {
6
+ display: none;
7
+ }
8
+
9
+ .root {
10
+ --size: 16px;
11
+ background-color: var(--colorNeutralBackground1);
12
+ border-radius: var(--borderRadiusSmall);
13
+ border: var(--strokeWidthThin) solid var(--colorNeutralStrokeAccessible);
14
+ box-sizing: border-box;
15
+ cursor: pointer;
16
+ position: relative;
17
+ width: var(--size);
18
+ aspect-ratio: 1;
19
+ display: inline-flex;
20
+ }
21
+
22
+ .root:hover {
23
+ border-color: var(--colorNeutralStrokeAccessibleHover);
24
+ }
25
+
26
+ .root:active {
27
+ border-color: var(--colorNeutralStrokeAccessiblePressed);
28
+ }
29
+
30
+ :host([checked]) .root:hover {
31
+ background-color: var(--colorCompoundBrandBackgroundHover);
32
+ border-color: var(--colorCompoundBrandStrokeHover);
33
+ }
34
+
35
+ :host([checked]) .root:active {
36
+ background-color: var(--colorCompoundBrandBackgroundPressed);
37
+ border-color: var(--colorCompoundBrandStrokePressed);
38
+ }
39
+
40
+ .root:focus-visible {
41
+ outline: none;
42
+ }
43
+
44
+ :host(:not([slot='input'])) .root::after {
45
+ content: '';
46
+ position: absolute;
47
+ inset: -8px;
48
+ box-sizing: border-box;
49
+ outline: none;
50
+ border: var(--strokeWidthThick) solid var(--colorTransparentStroke);
51
+ border-radius: var(--borderRadiusMedium);
52
+ }
53
+
54
+ :host(:not([slot='input'])) .root:focus-visible::after {
55
+ border-color: var(--colorStrokeFocus2);
56
+ }
57
+
58
+ .indeterminate-indicator,
59
+ .checked-indicator {
60
+ color: var(--colorNeutralForegroundInverted);
61
+ inset: 0;
62
+ margin: auto;
63
+ position: absolute;
64
+ aspect-ratio: 1;
65
+ }
66
+
67
+ ::slotted([slot='checked-indicator']),
68
+ .checked-indicator {
69
+ fill: currentColor;
70
+ display: inline-flex;
71
+ flex: 1 0 auto;
72
+ width: 12px;
73
+ }
74
+
75
+ :host(:not([checked])) .root ::slotted([slot='checked-indicator']),
76
+ :host(:not([checked])) .root .checked-indicator {
77
+ display: none;
78
+ }
79
+
80
+ :host([checked]) .root,
81
+ :host([indeterminate]) .root {
82
+ border-color: var(--colorCompoundBrandStroke);
83
+ }
84
+
85
+ :host([checked]) .root,
86
+ :host([indeterminate]) .root .indeterminate-indicator {
87
+ background-color: var(--colorCompoundBrandBackground);
88
+ }
89
+
90
+ :host([indeterminate]) .root .indeterminate-indicator {
91
+ border-radius: var(--borderRadiusSmall);
92
+ position: absolute;
93
+ width: calc(var(--size) / 2);
94
+ inset: 0;
95
+ }
96
+
97
+ :host([size='large']) .root {
98
+ --size: 20px;
99
+ }
100
+
101
+ :host([size='large']) .root ::slotted([slot='checked-indicator']),
102
+ :host([size='large']) .root .checked-indicator {
103
+ width: 16px;
104
+ }
105
+
106
+ :host([shape='circular']) .root,
107
+ :host([shape='circular']) .root .indeterminate-indicator {
108
+ border-radius: var(--borderRadiusCircular);
109
+ }
110
+
111
+ :host([disabled]) .root,
112
+ :host([disabled][checked]) .root {
113
+ background-color: var(--colorNeutralBackgroundDisabled);
114
+ border-color: var(--colorNeutralStrokeDisabled);
115
+ }
116
+
117
+ :host([disabled]) .root {
118
+ cursor: unset;
119
+ }
120
+
121
+ :host([disabled][indeterminate]) .root .indeterminate-indicator {
122
+ background-color: var(--colorNeutralStrokeDisabled);
123
+ }
124
+
125
+ :host([disabled][checked]) .root .checked-indicator {
126
+ color: var(--colorNeutralStrokeDisabled);
127
+ }
128
+
129
+ @media (forced-colors: active) {
130
+ .root {
131
+ border-color: FieldText;
132
+ }
133
+
134
+ :host(:not([slot='input']:focus-visible)) .root::after {
135
+ border-color: Canvas;
136
+ }
137
+
138
+ :host(:not([disabled])) .root:hover,
139
+ :host([checked]:not([disabled])) .root:hover,
140
+ :host(:not([slot='input'])) .root:focus-visible::after {
141
+ border-color: Highlight;
142
+ }
143
+
144
+ .indeterminate-indicator,
145
+ .checked-indicator {
146
+ color: HighlightText;
147
+ }
148
+
149
+ :host([checked]) .root,
150
+ :host([indeterminate]) .root .indeterminate-indicator {
151
+ background-color: FieldText;
152
+ }
153
+
154
+ :host([checked]:not([disabled])) .root:hover,
155
+ :host([indeterminate]:not([disabled])) .root:hover .indeterminate-indicator {
156
+ background-color: Highlight;
157
+ }
158
+
159
+ :host([disabled]) .root {
160
+ border-color: GrayText;
161
+ }
162
+
163
+ :host([disabled][indeterminate]) .root .indeterminate-indicator {
164
+ background-color: GrayText;
165
+ }
166
+
167
+ :host([disabled]) .root,
168
+ :host([disabled][checked]) .root .checked-indicator {
169
+ color: GrayText;
170
+ }
171
+ }
@@ -0,0 +1,294 @@
1
+ import { FluentElement } from '../../core/fluent-element.js';
2
+
3
+ const stylesUrl = new URL('./fluent-checkbox.css', import.meta.url).href;
4
+
5
+ class FluentCheckbox extends FluentElement {
6
+ static stylesUrl = stylesUrl;
7
+ static formAssociated = true;
8
+
9
+ static template = `
10
+ <div class="root">
11
+ <slot name="checked-indicator">
12
+ <svg fill="currentColor" aria-hidden="true" class="checked-indicator" width="1em" height="1em" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg">
13
+ <path d="M9.76 3.2c.3.29.32.76.04 1.06l-4.25 4.5a.75.75 0 0 1-1.08.02L2.22 6.53a.75.75 0 0 1 1.06-1.06l1.7 1.7L8.7 3.24a.75.75 0 0 1 1.06-.04Z" fill="currentColor"></path>
14
+ </svg>
15
+ </slot>
16
+ <slot name="indeterminate-indicator">
17
+ <span class="indeterminate-indicator"></span>
18
+ </slot>
19
+ </div>
20
+ `;
21
+
22
+ static get observedAttributes() {
23
+ return ['checked', 'disabled', 'required', 'value', 'name', 'size', 'shape', 'autofocus', 'indeterminate'];
24
+ }
25
+
26
+ constructor() {
27
+ super();
28
+ this._internals = this.attachInternals();
29
+ this._internals.role = 'checkbox';
30
+ this._checked = false;
31
+ this._dirtyChecked = false;
32
+ this._keydownPressed = false;
33
+ this._indeterminate = false;
34
+ this._value = 'on';
35
+ this._name = '';
36
+ this._size = 'medium';
37
+ this._shape = 'square';
38
+ }
39
+
40
+ connectedCallback() {
41
+ super.connectedCallback();
42
+ this._shadowRoot = this._root;
43
+ this._updateDisabled();
44
+ this._setAriaChecked();
45
+ this._setValidity();
46
+ this.addEventListener('click', this._clickHandler.bind(this));
47
+ this.addEventListener('keydown', this._keydownHandler.bind(this));
48
+ this.addEventListener('keyup', this._keyupHandler.bind(this));
49
+ }
50
+
51
+ changed(name, oldVal, newVal) {
52
+ switch (name) {
53
+ case 'checked':
54
+ if (!this._dirtyChecked) {
55
+ this._checked = newVal !== null;
56
+ this._setAriaChecked();
57
+ this._setValidity();
58
+ }
59
+ break;
60
+ case 'disabled':
61
+ this._updateDisabled();
62
+ break;
63
+ case 'indeterminate':
64
+ this._indeterminate = newVal !== null;
65
+ this._setAriaChecked();
66
+ break;
67
+ case 'required':
68
+ this._internals.ariaRequired = this.required ? 'true' : 'false';
69
+ this._setValidity();
70
+ break;
71
+ case 'value':
72
+ this._value = newVal || 'on';
73
+ break;
74
+ case 'name':
75
+ this._name = newVal || '';
76
+ if (this._name) {
77
+ this.setAttribute('name', this._name);
78
+ } else {
79
+ this.removeAttribute('name');
80
+ }
81
+ break;
82
+ case 'autofocus':
83
+ if (newVal !== null && !this.disabled) {
84
+ this.focus();
85
+ }
86
+ break;
87
+ case 'size':
88
+ this._size = newVal || 'medium';
89
+ break;
90
+ case 'shape':
91
+ this._shape = newVal || 'square';
92
+ break;
93
+ }
94
+ }
95
+
96
+ get checked() {
97
+ return this._checked;
98
+ }
99
+
100
+ set checked(val) {
101
+ this._checked = !!val;
102
+ this._setFormValue(this._checked ? this._value : null);
103
+ this._setAriaChecked();
104
+ this._setValidity();
105
+ if (this._checked) {
106
+ this.setAttribute('checked', '');
107
+ } else {
108
+ this.removeAttribute('checked');
109
+ }
110
+ }
111
+
112
+ get disabled() {
113
+ return this.hasAttribute('disabled');
114
+ }
115
+
116
+ set disabled(val) {
117
+ if (val) {
118
+ this.setAttribute('disabled', '');
119
+ } else {
120
+ this.removeAttribute('disabled');
121
+ }
122
+ }
123
+
124
+ get required() {
125
+ return this.hasAttribute('required');
126
+ }
127
+
128
+ get indeterminate() {
129
+ return this.hasAttribute('indeterminate');
130
+ }
131
+
132
+ set indeterminate(val) {
133
+ if (val) {
134
+ this.setAttribute('indeterminate', '');
135
+ } else {
136
+ this.removeAttribute('indeterminate');
137
+ }
138
+ this._setAriaChecked();
139
+ }
140
+
141
+ get value() {
142
+ return this._value || 'on';
143
+ }
144
+
145
+ set value(val) {
146
+ this._value = val;
147
+ if (this._checked) {
148
+ this._setFormValue(val);
149
+ }
150
+ }
151
+
152
+ get name() {
153
+ return this._name;
154
+ }
155
+
156
+ set name(val) {
157
+ this._name = val;
158
+ if (val) {
159
+ this.setAttribute('name', val);
160
+ } else {
161
+ this.removeAttribute('name');
162
+ }
163
+ }
164
+
165
+ get form() {
166
+ return this._internals.form;
167
+ }
168
+
169
+ get labels() {
170
+ return Object.freeze(Array.from(this._internals.labels));
171
+ }
172
+
173
+ get validity() {
174
+ return this._internals.validity;
175
+ }
176
+
177
+ get validationMessage() {
178
+ if (this._internals.validationMessage) {
179
+ return this._internals.validationMessage;
180
+ }
181
+ if (!this._validationFallbackMessage) {
182
+ const el = document.createElement('input');
183
+ el.type = 'checkbox';
184
+ el.required = true;
185
+ el.checked = false;
186
+ this._validationFallbackMessage = el.validationMessage;
187
+ }
188
+ return this._validationFallbackMessage;
189
+ }
190
+
191
+ get willValidate() {
192
+ return this._internals.willValidate;
193
+ }
194
+
195
+ toggleChecked(force) {
196
+ this.indeterminate = false;
197
+ this._checked = typeof force === 'boolean' ? force : !this._checked;
198
+ this._dirtyChecked = true;
199
+ this._setAriaChecked();
200
+ this._setFormValue(this._checked ? this._value : null);
201
+ this._setValidity();
202
+ if (this._checked) {
203
+ this.setAttribute('checked', '');
204
+ } else {
205
+ this.removeAttribute('checked');
206
+ }
207
+ }
208
+
209
+ checkValidity() {
210
+ return this._internals.checkValidity();
211
+ }
212
+
213
+ reportValidity() {
214
+ return this._internals.reportValidity();
215
+ }
216
+
217
+ setCustomValidity(message) {
218
+ this._internals.setValidity({ customError: !!message }, message);
219
+ this._setValidity();
220
+ }
221
+
222
+ _clickHandler(e) {
223
+ if (this.disabled) return;
224
+ this._dirtyChecked = true;
225
+ const prev = this._checked;
226
+ this.toggleChecked();
227
+ if (prev !== this._checked) {
228
+ this.dispatchEvent(new Event('change', { bubbles: true, composed: true }));
229
+ this.dispatchEvent(new Event('input', { bubbles: true, composed: true }));
230
+ }
231
+ }
232
+
233
+ _keydownHandler(e) {
234
+ if (e.key === ' ') {
235
+ e.preventDefault();
236
+ this._keydownPressed = true;
237
+ }
238
+ }
239
+
240
+ _keyupHandler(e) {
241
+ if (!this._keydownPressed || e.key !== ' ') return;
242
+ this._keydownPressed = false;
243
+ this.click();
244
+ }
245
+
246
+ _updateDisabled() {
247
+ const d = this.hasAttribute('disabled');
248
+ if (d) {
249
+ this.removeAttribute('tabindex');
250
+ } else {
251
+ const t = this.getAttribute('tabindex');
252
+ this.tabIndex = Number(t ?? 0) < 0 ? -1 : 0;
253
+ }
254
+ this._internals.ariaDisabled = d ? 'true' : 'false';
255
+ }
256
+
257
+ _setAriaChecked() {
258
+ if (this.indeterminate) {
259
+ this._internals.ariaChecked = 'mixed';
260
+ } else {
261
+ this._internals.ariaChecked = this._checked ? 'true' : 'false';
262
+ }
263
+ }
264
+
265
+ _setFormValue(value) {
266
+ this._internals.setFormValue(value, value);
267
+ }
268
+
269
+ _setValidity() {
270
+ if (this.disabled || !this.required) {
271
+ this._internals.setValidity({});
272
+ return;
273
+ }
274
+ const msg = this.validationMessage;
275
+ this._internals.setValidity(
276
+ { valueMissing: !!this.required && !this._checked },
277
+ msg || undefined
278
+ );
279
+ }
280
+
281
+ formResetCallback() {
282
+ const wasIndeterminate = this._indeterminate;
283
+ this._checked = this.hasAttribute('checked');
284
+ this._dirtyChecked = false;
285
+ if (wasIndeterminate) {
286
+ this._indeterminate = false;
287
+ this.removeAttribute('indeterminate');
288
+ }
289
+ this._setAriaChecked();
290
+ this._setValidity();
291
+ }
292
+ }
293
+
294
+ customElements.define('fluent-checkbox', FluentCheckbox);
@@ -0,0 +1,82 @@
1
+ @import url('../../tokens.css');
2
+
3
+ :host {
4
+ --dialog-backdrop: rgba(0, 0, 0, 0.4);
5
+ --dialog-starting-scale: 0.85;
6
+ display: none;
7
+ }
8
+
9
+ :host([open]) {
10
+ display: block;
11
+ }
12
+
13
+ ::backdrop {
14
+ background: var(--dialog-backdrop);
15
+ }
16
+
17
+ dialog {
18
+ background: var(--colorNeutralBackground1);
19
+ border-radius: var(--borderRadiusXLarge);
20
+ border: none;
21
+ box-shadow: var(--shadow64);
22
+ color: var(--colorNeutralForeground1);
23
+ max-height: 100vh;
24
+ padding: 0;
25
+ width: 100%;
26
+ max-width: 600px;
27
+ }
28
+
29
+ :host([type='non-modal']) .root dialog {
30
+ inset: 0;
31
+ position: fixed;
32
+ z-index: 2;
33
+ overflow: auto;
34
+ }
35
+
36
+ @supports (max-height: 1dvh) {
37
+ dialog {
38
+ max-height: 100dvh;
39
+ }
40
+ }
41
+
42
+ @media (prefers-reduced-motion: no-preference) {
43
+ dialog,
44
+ ::backdrop {
45
+ transition-behavior: allow-discrete;
46
+ transition-property: display, opacity, overlay, scale;
47
+ transition-duration: var(--durationGentle);
48
+ transition-timing-function: var(--curveDecelerateMid);
49
+ opacity: 0;
50
+ }
51
+
52
+ ::backdrop {
53
+ transition-timing-function: var(--curveLinear);
54
+ }
55
+
56
+ dialog[open],
57
+ dialog[open]::backdrop {
58
+ opacity: 1;
59
+ }
60
+
61
+ dialog:not([open]) {
62
+ scale: var(--dialog-starting-scale);
63
+ transition-timing-function: var(--curveAccelerateMid);
64
+ }
65
+ }
66
+
67
+ @starting-style {
68
+ dialog[open],
69
+ dialog[open]::backdrop {
70
+ opacity: 0;
71
+ }
72
+
73
+ dialog {
74
+ scale: var(--dialog-starting-scale);
75
+ }
76
+ }
77
+
78
+ @media (forced-colors: active) {
79
+ dialog {
80
+ border: var(--strokeWidthThin) solid var(--colorTransparentStroke);
81
+ }
82
+ }
@@ -0,0 +1,137 @@
1
+ import { FluentElement } from '../../core/fluent-element.js';
2
+
3
+ const stylesUrl = new URL('./fluent-dialog.css', import.meta.url).href;
4
+
5
+ class FluentDialog extends FluentElement {
6
+ static stylesUrl = stylesUrl;
7
+ static template = `
8
+ <div class="root">
9
+ <dialog class="dialog" part="dialog">
10
+ <slot></slot>
11
+ </dialog>
12
+ </div>
13
+ `;
14
+
15
+ static get observedAttributes() {
16
+ return ['type', 'trigger', 'close-on', 'aria-label', 'aria-labelledby', 'aria-describedby'];
17
+ }
18
+
19
+ connectedCallback() {
20
+ super.connectedCallback();
21
+ this._dialog = this._root.querySelector('dialog');
22
+ if (this._dialog) {
23
+ this._dialog.addEventListener('click', (e) => this._clickHandler(e));
24
+ this._dialog.addEventListener('cancel', () => this.hide());
25
+ this._updateDialogAttributes();
26
+ }
27
+ requestAnimationFrame(() => this._wireTrigger());
28
+ requestAnimationFrame(() => this._wireCloseOn());
29
+ }
30
+
31
+ attributeChangedCallback(name, oldVal, newVal) {
32
+ super.attributeChangedCallback(name, oldVal, newVal);
33
+ if (name === 'type') {
34
+ this._updateDialogAttributes();
35
+ }
36
+ if (name === 'trigger' && oldVal !== newVal) {
37
+ this._wireTrigger();
38
+ }
39
+ if (name === 'close-on' && oldVal !== newVal) {
40
+ this._wireCloseOn();
41
+ }
42
+ if (this._dialog && (name === 'aria-label' || name === 'aria-labelledby' || name === 'aria-describedby')) {
43
+ if (newVal !== null) {
44
+ this._dialog.setAttribute(name, newVal);
45
+ } else {
46
+ this._dialog.removeAttribute(name);
47
+ }
48
+ }
49
+ }
50
+
51
+ show() {
52
+ if (!this._dialog) return;
53
+ this.setAttribute('open', '');
54
+ this.dispatchEvent(new CustomEvent('beforetoggle', {
55
+ detail: { oldState: this._dialog.open ? 'open' : 'closed', newState: this._dialog.open ? 'closed' : 'open' }
56
+ }));
57
+ const type = this.getAttribute('type') || 'modal';
58
+ if (type === 'alert' || type === 'modal') {
59
+ this._dialog.showModal();
60
+ } else {
61
+ this._dialog.show();
62
+ }
63
+ this.dispatchEvent(new CustomEvent('toggle', {
64
+ detail: { oldState: 'closed', newState: 'open' }
65
+ }));
66
+ }
67
+
68
+ hide() {
69
+ if (!this._dialog) return;
70
+ this.removeAttribute('open');
71
+ this.dispatchEvent(new CustomEvent('beforetoggle', {
72
+ detail: { oldState: 'open', newState: 'closed' }
73
+ }));
74
+ this._dialog.close();
75
+ this.dispatchEvent(new CustomEvent('toggle', {
76
+ detail: { oldState: 'open', newState: 'closed' }
77
+ }));
78
+ }
79
+
80
+ _wireTrigger() {
81
+ const sel = this.getAttribute('trigger');
82
+ if (!sel) return;
83
+ if (this._triggerEl) {
84
+ this._triggerEl.removeEventListener('click', this._onTriggerClick);
85
+ }
86
+ const el = this._root.host?.ownerDocument?.querySelector(sel) ?? document.querySelector(sel);
87
+ if (el) {
88
+ this._triggerEl = el;
89
+ this._onTriggerClick = () => this.show();
90
+ el.addEventListener('click', this._onTriggerClick);
91
+ }
92
+ }
93
+
94
+ _wireCloseOn() {
95
+ const sel = this.getAttribute('close-on');
96
+ if (!sel) return;
97
+ if (this._closeOnCleanups) {
98
+ this._closeOnCleanups.forEach(fn => fn());
99
+ }
100
+ this._closeOnCleanups = [];
101
+ sel.split(',').forEach(s => {
102
+ const p = s.trim();
103
+ if (!p) return;
104
+ const doc = this._root.host?.ownerDocument ?? document;
105
+ const els = doc.querySelectorAll(p);
106
+ els.forEach(el => {
107
+ const handler = () => this.hide();
108
+ el.addEventListener('click', handler);
109
+ this._closeOnCleanups.push(() => el.removeEventListener('click', handler));
110
+ });
111
+ });
112
+ }
113
+
114
+ _clickHandler(event) {
115
+ const type = this.getAttribute('type') || 'modal';
116
+ if (this._dialog.open && type !== 'alert' && event.target === this._dialog) {
117
+ this.hide();
118
+ }
119
+ }
120
+
121
+ _updateDialogAttributes() {
122
+ if (!this._dialog) return;
123
+ const type = this.getAttribute('type') || 'modal';
124
+ if (type === 'alert') {
125
+ this._dialog.setAttribute('role', 'alertdialog');
126
+ } else {
127
+ this._dialog.removeAttribute('role');
128
+ }
129
+ if (type !== 'non-modal') {
130
+ this._dialog.setAttribute('aria-modal', 'true');
131
+ } else {
132
+ this._dialog.removeAttribute('aria-modal');
133
+ }
134
+ }
135
+ }
136
+
137
+ customElements.define('fluent-dialog', FluentDialog);