@nanahoshi/mona-ui 0.24.11 → 0.25.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.
- package/README.md +9 -0
- package/fesm2022/nanahoshi-mona-ui-auto-complete.mjs +11 -10
- package/fesm2022/nanahoshi-mona-ui-avatar.mjs +37 -20
- package/fesm2022/nanahoshi-mona-ui-breadcrumb.mjs +239 -47
- package/fesm2022/nanahoshi-mona-ui-button-group.mjs +184 -31
- package/fesm2022/nanahoshi-mona-ui-button.mjs +47 -11
- package/fesm2022/nanahoshi-mona-ui-calendar.mjs +17 -13
- package/fesm2022/nanahoshi-mona-ui-card.mjs +54 -30
- package/fesm2022/nanahoshi-mona-ui-chart.mjs +27 -22
- package/fesm2022/nanahoshi-mona-ui-check-box.mjs +112 -31
- package/fesm2022/nanahoshi-mona-ui-chip.mjs +131 -89
- package/fesm2022/nanahoshi-mona-ui-circular-progress-bar.mjs +59 -19
- package/fesm2022/nanahoshi-mona-ui-collapsible.mjs +118 -41
- package/fesm2022/nanahoshi-mona-ui-color-gradient.mjs +243 -212
- package/fesm2022/nanahoshi-mona-ui-color-palette.mjs +155 -86
- package/fesm2022/nanahoshi-mona-ui-color-picker.mjs +161 -131
- package/fesm2022/nanahoshi-mona-ui-combo-box.mjs +12 -11
- package/fesm2022/nanahoshi-mona-ui-common.mjs +18 -1
- package/fesm2022/nanahoshi-mona-ui-date-picker.mjs +10 -9
- package/fesm2022/nanahoshi-mona-ui-datetime-picker.mjs +10 -9
- package/fesm2022/nanahoshi-mona-ui-dialog.mjs +2 -2
- package/fesm2022/nanahoshi-mona-ui-dropdown-button.mjs +2 -2
- package/fesm2022/nanahoshi-mona-ui-dropdown-list.mjs +10 -9
- package/fesm2022/nanahoshi-mona-ui-editor.mjs +25 -24
- package/fesm2022/nanahoshi-mona-ui-expansion-panel.mjs +202 -33
- package/fesm2022/nanahoshi-mona-ui-fieldset.mjs +31 -10
- package/fesm2022/nanahoshi-mona-ui-filter.mjs +1 -1
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-footer-row.component-DhKLnW06.mjs → nanahoshi-mona-ui-grid-grid-footer-row.component-2tVhD2hK.mjs} +2 -2
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-list.component-voGbKOiB.mjs → nanahoshi-mona-ui-grid-grid-list.component-BAN70Wcn.mjs} +4 -4
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-row.component-HQ1Kv6R9.mjs → nanahoshi-mona-ui-grid-grid-row.component-C_kCaA5b.mjs} +7 -7
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-virtual-list.component-PNLJFcuH.mjs → nanahoshi-mona-ui-grid-grid-virtual-list.component-BsNfrAHz.mjs} +4 -4
- package/fesm2022/{nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-BO19AVwC.mjs → nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-CEfVa7eo.mjs} +27 -29
- package/fesm2022/nanahoshi-mona-ui-grid.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +39 -4
- package/fesm2022/nanahoshi-mona-ui-internal-filter-input.mjs +2 -2
- package/fesm2022/nanahoshi-mona-ui-internal-indicator-icon.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-internal-list.mjs +5 -5
- package/fesm2022/nanahoshi-mona-ui-internal-tree.mjs +7 -7
- package/fesm2022/nanahoshi-mona-ui-internal.mjs +183 -47
- package/fesm2022/nanahoshi-mona-ui-label.mjs +111 -15
- package/fesm2022/nanahoshi-mona-ui-list-box.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-list-view.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +33 -4
- package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +33 -4
- package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +33 -4
- package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +33 -4
- package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +33 -4
- package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +33 -4
- package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +33 -4
- package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +33 -4
- package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +33 -4
- package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +33 -4
- package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +33 -4
- package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +33 -4
- package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +33 -4
- package/fesm2022/nanahoshi-mona-ui-menubar.mjs +2 -2
- package/fesm2022/nanahoshi-mona-ui-multi-select.mjs +14 -13
- package/fesm2022/nanahoshi-mona-ui-notification.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-numeric-text-box.mjs +13 -12
- package/fesm2022/nanahoshi-mona-ui-otp-input.mjs +192 -56
- package/fesm2022/nanahoshi-mona-ui-pager.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-placeholder.mjs +3 -1
- package/fesm2022/nanahoshi-mona-ui-popup-menu.mjs +2 -2
- package/fesm2022/nanahoshi-mona-ui-progress-bar.mjs +60 -29
- package/fesm2022/nanahoshi-mona-ui-radio-button.mjs +334 -37
- package/fesm2022/nanahoshi-mona-ui-rating.mjs +84 -30
- package/fesm2022/nanahoshi-mona-ui-scroll-view.mjs +274 -108
- package/fesm2022/nanahoshi-mona-ui-segmented.mjs +127 -37
- package/fesm2022/nanahoshi-mona-ui-sheet.mjs +2 -2
- package/fesm2022/nanahoshi-mona-ui-sidebar.mjs +595 -170
- package/fesm2022/nanahoshi-mona-ui-skeleton.mjs +3 -2
- package/fesm2022/nanahoshi-mona-ui-slider.mjs +323 -166
- package/fesm2022/nanahoshi-mona-ui-spinner.mjs +167 -82
- package/fesm2022/nanahoshi-mona-ui-split-button.mjs +3 -3
- package/fesm2022/nanahoshi-mona-ui-splitter.mjs +273 -165
- package/fesm2022/nanahoshi-mona-ui-stepper.mjs +219 -132
- package/fesm2022/nanahoshi-mona-ui-switch.mjs +84 -32
- package/fesm2022/nanahoshi-mona-ui-tabs.mjs +337 -116
- package/fesm2022/nanahoshi-mona-ui-text-area.mjs +10 -12
- package/fesm2022/nanahoshi-mona-ui-text-box.mjs +21 -8
- package/fesm2022/nanahoshi-mona-ui-theme.mjs +444 -88
- package/fesm2022/nanahoshi-mona-ui-time-picker.mjs +10 -9
- package/fesm2022/nanahoshi-mona-ui-time-selector.mjs +15 -14
- package/fesm2022/nanahoshi-mona-ui-tooltip.mjs +17 -3
- package/fesm2022/nanahoshi-mona-ui-window.mjs +1 -1
- package/i18n/catalogs/en-US.messages.json +33 -4
- package/locales/ar-sa/ar-sa.messages.json +33 -4
- package/locales/de-de/de-de.messages.json +33 -4
- package/locales/es-es/es-es.messages.json +33 -4
- package/locales/fr-fr/fr-fr.messages.json +33 -4
- package/locales/id-id/id-id.messages.json +33 -4
- package/locales/it-it/it-it.messages.json +33 -4
- package/locales/ja-jp/ja-jp.messages.json +33 -4
- package/locales/ko-kr/ko-kr.messages.json +33 -4
- package/locales/pt-br/pt-br.messages.json +33 -4
- package/locales/ru-ru/ru-ru.messages.json +33 -4
- package/locales/tr-tr/tr-tr.messages.json +33 -4
- package/locales/zh-cn/zh-cn.messages.json +33 -4
- package/locales/zh-tw/zh-tw.messages.json +33 -4
- package/package.json +2 -1
- package/styles.css +156 -0
- package/types/nanahoshi-mona-ui-auto-complete.d.ts +1 -0
- package/types/nanahoshi-mona-ui-avatar.d.ts +18 -11
- package/types/nanahoshi-mona-ui-breadcrumb.d.ts +62 -14
- package/types/nanahoshi-mona-ui-button-group.d.ts +86 -16
- package/types/nanahoshi-mona-ui-button.d.ts +26 -3
- package/types/nanahoshi-mona-ui-calendar.d.ts +1 -0
- package/types/nanahoshi-mona-ui-card.d.ts +22 -6
- package/types/nanahoshi-mona-ui-check-box.d.ts +54 -13
- package/types/nanahoshi-mona-ui-chip.d.ts +31 -18
- package/types/nanahoshi-mona-ui-circular-progress-bar.d.ts +21 -5
- package/types/nanahoshi-mona-ui-collapsible.d.ts +20 -11
- package/types/nanahoshi-mona-ui-color-gradient.d.ts +62 -36
- package/types/nanahoshi-mona-ui-color-palette.d.ts +65 -27
- package/types/nanahoshi-mona-ui-color-picker.d.ts +64 -23
- package/types/nanahoshi-mona-ui-combo-box.d.ts +1 -0
- package/types/nanahoshi-mona-ui-common.d.ts +28 -2
- package/types/nanahoshi-mona-ui-date-picker.d.ts +1 -0
- package/types/nanahoshi-mona-ui-datetime-picker.d.ts +1 -0
- package/types/nanahoshi-mona-ui-dropdown-list.d.ts +1 -0
- package/types/nanahoshi-mona-ui-editor.d.ts +1 -0
- package/types/nanahoshi-mona-ui-expansion-panel.d.ts +51 -7
- package/types/nanahoshi-mona-ui-fieldset.d.ts +18 -4
- package/types/nanahoshi-mona-ui-grid.d.ts +0 -1
- package/types/nanahoshi-mona-ui-i18n.d.ts +38 -3
- package/types/nanahoshi-mona-ui-internal.d.ts +95 -14
- package/types/nanahoshi-mona-ui-label.d.ts +17 -2
- package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +29 -0
- package/types/nanahoshi-mona-ui-locales-de-de.d.ts +29 -0
- package/types/nanahoshi-mona-ui-locales-es-es.d.ts +29 -0
- package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +29 -0
- package/types/nanahoshi-mona-ui-locales-id-id.d.ts +29 -0
- package/types/nanahoshi-mona-ui-locales-it-it.d.ts +29 -0
- package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +29 -0
- package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +29 -0
- package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +29 -0
- package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +29 -0
- package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +29 -0
- package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +29 -0
- package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +29 -0
- package/types/nanahoshi-mona-ui-multi-select.d.ts +1 -0
- package/types/nanahoshi-mona-ui-numeric-text-box.d.ts +1 -0
- package/types/nanahoshi-mona-ui-otp-input.d.ts +49 -12
- package/types/nanahoshi-mona-ui-placeholder.d.ts +2 -1
- package/types/nanahoshi-mona-ui-progress-bar.d.ts +21 -9
- package/types/nanahoshi-mona-ui-radio-button.d.ts +165 -20
- package/types/nanahoshi-mona-ui-rating.d.ts +21 -6
- package/types/nanahoshi-mona-ui-scroll-view.d.ts +59 -27
- package/types/nanahoshi-mona-ui-segmented.d.ts +52 -24
- package/types/nanahoshi-mona-ui-sidebar.d.ts +104 -41
- package/types/nanahoshi-mona-ui-skeleton.d.ts +1 -1
- package/types/nanahoshi-mona-ui-slider.d.ts +99 -35
- package/types/nanahoshi-mona-ui-spinner.d.ts +9 -5
- package/types/nanahoshi-mona-ui-splitter.d.ts +31 -10
- package/types/nanahoshi-mona-ui-stepper.d.ts +58 -12
- package/types/nanahoshi-mona-ui-switch.d.ts +32 -10
- package/types/nanahoshi-mona-ui-tabs.d.ts +75 -20
- package/types/nanahoshi-mona-ui-text-area.d.ts +7 -7
- package/types/nanahoshi-mona-ui-text-box.d.ts +2 -0
- package/types/nanahoshi-mona-ui-theme.d.ts +392 -15
- package/types/nanahoshi-mona-ui-time-picker.d.ts +1 -0
- package/types/nanahoshi-mona-ui-time-selector.d.ts +1 -0
- package/types/nanahoshi-mona-ui-tooltip.d.ts +7 -1
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { inject, DestroyRef, computed, contentChildren, input, model, effect, untracked, afterNextRender, Component } from '@angular/core';
|
|
3
|
-
import { outputFromObservable, takeUntilDestroyed
|
|
2
|
+
import { inject, DestroyRef, ElementRef, computed, contentChildren, input, booleanAttribute, output, model, effect, untracked, afterNextRender, Component } from '@angular/core';
|
|
3
|
+
import { outputFromObservable, takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
4
4
|
import { ButtonService, ButtonDirective, BUTTON_GROUP_MEMBER } from '@nanahoshi/mona-ui/button';
|
|
5
5
|
import { MonaI18nService } from '@nanahoshi/mona-ui/i18n';
|
|
6
|
-
import {
|
|
6
|
+
import { injectLabelAssociation, injectEffectiveDisabled } from '@nanahoshi/mona-ui/internal';
|
|
7
|
+
import { filter, map } from 'rxjs';
|
|
7
8
|
import { twMerge } from 'tailwind-merge';
|
|
8
9
|
import { cva } from 'class-variance-authority';
|
|
9
10
|
|
|
@@ -15,7 +16,10 @@ const BUTTON_GROUP_DEFAULT_MESSAGES = {
|
|
|
15
16
|
|
|
16
17
|
const buttonGroupThemeVariants = cva(`
|
|
17
18
|
inline-flex items-center justify-center
|
|
18
|
-
border border-
|
|
19
|
+
border border-border
|
|
20
|
+
data-[invalid='true']:border-error
|
|
21
|
+
data-[invalid='true']:ring-2 data-[invalid='true']:ring-error/35
|
|
22
|
+
data-[readonly='true']:[&_button[aria-pressed]]:cursor-default
|
|
19
23
|
[&>button]:border-0
|
|
20
24
|
[&>button]:shadow-none
|
|
21
25
|
[&>*:not(:last-child)]:border-e
|
|
@@ -89,11 +93,23 @@ const buttonGroupThemeVariants = cva(`
|
|
|
89
93
|
class ButtonGroupComponent {
|
|
90
94
|
#buttonService;
|
|
91
95
|
#destroyRef;
|
|
96
|
+
#hostElementRef;
|
|
92
97
|
#i18n;
|
|
98
|
+
#label;
|
|
99
|
+
/** The buttons seen selected last time, to tell which one is new and which one to bring back. */
|
|
100
|
+
#lastSelected;
|
|
93
101
|
constructor() {
|
|
94
102
|
this.#buttonService = inject(ButtonService, { self: true });
|
|
95
103
|
this.#destroyRef = inject(DestroyRef);
|
|
104
|
+
this.#hostElementRef = inject(ElementRef);
|
|
96
105
|
this.#i18n = inject(MonaI18nService);
|
|
106
|
+
this.#label = injectLabelAssociation({
|
|
107
|
+
activate: () => this.focus(),
|
|
108
|
+
ariaLabel: () => this.ariaLabel(),
|
|
109
|
+
ariaLabelledBy: () => this.ariaLabelledBy()
|
|
110
|
+
});
|
|
111
|
+
/** The buttons seen selected last time, to tell which one is new and which one to bring back. */
|
|
112
|
+
this.#lastSelected = [];
|
|
97
113
|
this.baseClass = computed(() => {
|
|
98
114
|
const look = this.look();
|
|
99
115
|
const rounded = this.rounded();
|
|
@@ -114,8 +130,10 @@ class ButtonGroupComponent {
|
|
|
114
130
|
*/
|
|
115
131
|
this.components = contentChildren(BUTTON_GROUP_MEMBER, /* @ts-ignore */
|
|
116
132
|
...(ngDevMode ? [{ debugName: "components" }] : /* istanbul ignore next */ []));
|
|
117
|
-
this.
|
|
118
|
-
|
|
133
|
+
this.effectiveDisabled = injectEffectiveDisabled(() => this.disabled());
|
|
134
|
+
this.invalidState = computed(() => this.touched() && this.invalid(), /* @ts-ignore */
|
|
135
|
+
...(ngDevMode ? [{ debugName: "invalidState" }] : /* istanbul ignore next */ []));
|
|
136
|
+
this.labelledBy = this.#label.labelledBy;
|
|
119
137
|
this.members = computed(() => [
|
|
120
138
|
...this.buttons(),
|
|
121
139
|
...this.components().flatMap(component => component.groupButtons())
|
|
@@ -123,28 +141,45 @@ class ButtonGroupComponent {
|
|
|
123
141
|
...(ngDevMode ? [{ debugName: "members" }] : /* istanbul ignore next */ []));
|
|
124
142
|
this.messages = this.#i18n.componentMessages("buttonGroup", BUTTON_GROUP_DEFAULT_MESSAGES);
|
|
125
143
|
/**
|
|
126
|
-
* @description When `false` and `selection` is `"single"`,
|
|
127
|
-
* the active button
|
|
144
|
+
* @description When `false` and `selection` is `"single"`, a selected button stays selected until another one takes
|
|
145
|
+
* over: the active button can't be deselected, and clearing every `selected` brings it back. It doesn't choose a
|
|
146
|
+
* first button, and a `value` of `null` still clears the group, so a form can reset it. Has no effect in `"multiple"`
|
|
147
|
+
* mode.
|
|
128
148
|
* @default true
|
|
129
149
|
*/
|
|
130
|
-
this.allowEmpty = input(true, /*
|
|
131
|
-
...(ngDevMode ? [{ debugName: "allowEmpty" }] : /* istanbul ignore next */ []));
|
|
150
|
+
this.allowEmpty = input(true, { ...(ngDevMode ? { debugName: "allowEmpty" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
132
151
|
/**
|
|
133
152
|
* @description Accessible name for the host element. Override when multiple button groups appear on the same page
|
|
134
153
|
* so screen reader users can distinguish them.
|
|
135
154
|
*/
|
|
136
155
|
this.ariaLabel = input(undefined, { ...(ngDevMode ? { debugName: "ariaLabel" } : /* istanbul ignore next */ {}), alias: "aria-label" });
|
|
137
156
|
/**
|
|
138
|
-
* @description
|
|
139
|
-
*
|
|
157
|
+
* @description Id of the element that names the group.
|
|
158
|
+
* @default ""
|
|
159
|
+
*/
|
|
160
|
+
this.ariaLabelledBy = input("", { ...(ngDevMode ? { debugName: "ariaLabelledBy" } : /* istanbul ignore next */ {}), alias: "aria-labelledby" });
|
|
161
|
+
/**
|
|
162
|
+
* @description Emitted when a button placed directly in the group is clicked, toggleable or not, after the group has
|
|
163
|
+
* applied its selection. Not emitted for a dropdown or split button's own buttons, for a disabled button, or for a
|
|
164
|
+
* toggle button while the group is read-only, since nothing was selected.
|
|
165
|
+
*/
|
|
166
|
+
this.buttonClick = outputFromObservable(this.#buttonService.memberClick$.pipe(filter(([button]) => this.buttons().includes(button) && !(this.readonly() && button.effectiveToggleable())), map(([button, element]) => ({
|
|
167
|
+
button: element,
|
|
168
|
+
selected: button.selected(),
|
|
169
|
+
value: button.value()
|
|
170
|
+
})), takeUntilDestroyed(this.#destroyRef)));
|
|
171
|
+
/**
|
|
172
|
+
* @description Renders all child buttons with reduced visual emphasis and removes pointer interaction. When bound to
|
|
173
|
+
* a signal form field via `[formField]`, this is written by the `FormField` directive.
|
|
174
|
+
* @default false
|
|
140
175
|
*/
|
|
141
|
-
this.
|
|
176
|
+
this.disabled = input(false, { ...(ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
142
177
|
/**
|
|
143
|
-
* @description
|
|
178
|
+
* @description Marks the group as invalid. Error styling requires both `invalid` and `touched` to be `true`. When
|
|
179
|
+
* bound to a signal form field via `[formField]`, this is written by the `FormField` directive.
|
|
144
180
|
* @default false
|
|
145
181
|
*/
|
|
146
|
-
this.
|
|
147
|
-
...(ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []));
|
|
182
|
+
this.invalid = input(false, { ...(ngDevMode ? { debugName: "invalid" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
148
183
|
/**
|
|
149
184
|
* @description Visual style variant propagated to all child buttons.
|
|
150
185
|
* Also controls container-level divider and border behavior.
|
|
@@ -152,6 +187,12 @@ class ButtonGroupComponent {
|
|
|
152
187
|
*/
|
|
153
188
|
this.look = input("outline", /* @ts-ignore */
|
|
154
189
|
...(ngDevMode ? [{ debugName: "look" }] : /* istanbul ignore next */ []));
|
|
190
|
+
/**
|
|
191
|
+
* @description Prevents selection changes while the buttons stay focusable. Buttons that aren't toggleable keep
|
|
192
|
+
* working. When bound to a signal form field via `[formField]`, this is written by the `FormField` directive.
|
|
193
|
+
* @default false
|
|
194
|
+
*/
|
|
195
|
+
this.readonly = input(false, { ...(ngDevMode ? { debugName: "readonly" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
155
196
|
/**
|
|
156
197
|
* @description Border-radius preset applied to the container and the outer corners of the first and last child button.
|
|
157
198
|
* @default "medium"
|
|
@@ -159,11 +200,12 @@ class ButtonGroupComponent {
|
|
|
159
200
|
this.rounded = input("medium", /* @ts-ignore */
|
|
160
201
|
...(ngDevMode ? [{ debugName: "rounded" }] : /* istanbul ignore next */ []));
|
|
161
202
|
/**
|
|
162
|
-
* @description
|
|
163
|
-
*
|
|
203
|
+
* @description Whether one button can be selected at a time (`"single"`) or each toggles on its own (`"multiple"`).
|
|
204
|
+
* The buttons stay toggle buttons with `aria-pressed` in both. For a choice that must always hold one value, use
|
|
205
|
+
* `mona-segmented`, which is a radio group.
|
|
164
206
|
* @default "multiple"
|
|
165
207
|
*/
|
|
166
|
-
this.selection =
|
|
208
|
+
this.selection = input("multiple", /* @ts-ignore */
|
|
167
209
|
...(ngDevMode ? [{ debugName: "selection" }] : /* istanbul ignore next */ []));
|
|
168
210
|
/**
|
|
169
211
|
* @description Size preset propagated to all child buttons, overriding their individual `size` inputs.
|
|
@@ -171,16 +213,40 @@ class ButtonGroupComponent {
|
|
|
171
213
|
*/
|
|
172
214
|
this.size = input("medium", /* @ts-ignore */
|
|
173
215
|
...(ngDevMode ? [{ debugName: "size" }] : /* istanbul ignore next */ []));
|
|
216
|
+
/**
|
|
217
|
+
* @description Emitted when a user changes the selection or focus leaves the group.
|
|
218
|
+
* The `FormField` directive listens to this to mark the field as touched.
|
|
219
|
+
*/
|
|
220
|
+
this.touch = output();
|
|
221
|
+
/**
|
|
222
|
+
* @description Marks the group as touched. When bound to a signal form field via `[formField]`, this is written by
|
|
223
|
+
* the `FormField` directive.
|
|
224
|
+
* @default false
|
|
225
|
+
*/
|
|
226
|
+
this.touched = input(false, { ...(ngDevMode ? { debugName: "touched" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
174
227
|
/**
|
|
175
228
|
* @description Additional CSS classes merged onto the host element via `tailwind-merge`.
|
|
176
229
|
* @default ""
|
|
177
230
|
*/
|
|
178
231
|
this.userClass = input("", { ...(ngDevMode ? { debugName: "userClass" } : /* istanbul ignore next */ {}), alias: "class" });
|
|
232
|
+
/**
|
|
233
|
+
* @description The value of the selected button in `"single"` mode, or `null`, and an array of the selected buttons'
|
|
234
|
+
* values in `"multiple"` mode. Buttons take part by having a `value`. While `undefined`, it leaves each button's
|
|
235
|
+
* `selected` alone. A value with no button yet stays, so one that loads before its button isn't lost. Use either this
|
|
236
|
+
* or `[(selected)]` on the buttons, not both.
|
|
237
|
+
* @default undefined
|
|
238
|
+
*/
|
|
239
|
+
this.value = model(undefined, /* @ts-ignore */
|
|
240
|
+
...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
|
|
179
241
|
this.#buttonService.setMembers(this.members);
|
|
180
242
|
effect(() => {
|
|
181
|
-
const disabled = this.
|
|
243
|
+
const disabled = this.effectiveDisabled();
|
|
182
244
|
untracked(() => this.#buttonService.groupDisabled.set(disabled));
|
|
183
245
|
});
|
|
246
|
+
effect(() => {
|
|
247
|
+
const readonly = this.readonly();
|
|
248
|
+
untracked(() => this.#buttonService.groupReadonly.set(readonly));
|
|
249
|
+
});
|
|
184
250
|
effect(() => {
|
|
185
251
|
const look = this.look();
|
|
186
252
|
untracked(() => this.#buttonService.groupLook.set(look));
|
|
@@ -193,24 +259,95 @@ class ButtonGroupComponent {
|
|
|
193
259
|
const size = this.size();
|
|
194
260
|
untracked(() => this.#buttonService.groupSize.set(size));
|
|
195
261
|
});
|
|
196
|
-
|
|
197
|
-
.
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
262
|
+
effect(() => {
|
|
263
|
+
const value = this.value();
|
|
264
|
+
if (value === undefined) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
const values = this.valuesOf(value);
|
|
268
|
+
for (const button of this.valueButtons()) {
|
|
269
|
+
const selected = values.includes(button.value());
|
|
270
|
+
untracked(() => button.selected.set(selected));
|
|
204
271
|
}
|
|
205
272
|
});
|
|
273
|
+
effect(() => {
|
|
274
|
+
const buttons = this.buttons();
|
|
275
|
+
const selected = buttons.filter(button => button.selected());
|
|
276
|
+
const single = this.selection() === "single";
|
|
277
|
+
const allowEmpty = this.allowEmpty();
|
|
278
|
+
untracked(() => this.enforceSelectionPolicy(buttons, selected, single, allowEmpty));
|
|
279
|
+
});
|
|
206
280
|
afterNextRender({
|
|
207
281
|
read: () => this.setSubscriptions()
|
|
208
282
|
});
|
|
209
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* @description Moves focus to the selected button, or the first enabled one.
|
|
286
|
+
* @param options Options passed to the native `focus()` call, such as `preventScroll`.
|
|
287
|
+
*/
|
|
288
|
+
focus(options) {
|
|
289
|
+
const host = this.#hostElementRef.nativeElement;
|
|
290
|
+
const target = host.querySelector("button[aria-pressed='true']:not(:disabled)") ??
|
|
291
|
+
host.querySelector("button:not(:disabled)");
|
|
292
|
+
target?.focus(options);
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* @internal
|
|
296
|
+
*/
|
|
297
|
+
setLabelledBy(id) {
|
|
298
|
+
this.#label.setLabelledBy(id);
|
|
299
|
+
}
|
|
300
|
+
onFocusOut(event) {
|
|
301
|
+
const nextTarget = event.relatedTarget;
|
|
302
|
+
if (nextTarget instanceof Node && this.#hostElementRef.nativeElement.contains(nextTarget)) {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
this.touch.emit();
|
|
306
|
+
}
|
|
307
|
+
commitValue() {
|
|
308
|
+
const buttons = this.valueButtons();
|
|
309
|
+
if (buttons.length === 0) {
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
const selected = buttons.filter(button => button.selected()).map(button => button.value());
|
|
313
|
+
if (this.selection() === "single") {
|
|
314
|
+
this.value.set(selected[0] ?? null);
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
const known = buttons.map(button => button.value());
|
|
318
|
+
const waiting = this.valuesOf(this.value()).filter(value => !known.includes(value));
|
|
319
|
+
this.value.set([...waiting, ...selected]);
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Holds the group to `selection` and `allowEmpty` however a button's `selected` changed, since a binding can change
|
|
323
|
+
* it as well as a click. A form's `value` of `null` is left alone, so the form can reset the group.
|
|
324
|
+
*/
|
|
325
|
+
enforceSelectionPolicy(buttons, selected, single, allowEmpty) {
|
|
326
|
+
if (single && selected.length > 1) {
|
|
327
|
+
// Both new, as on the first render, keeps the first. A new one next to an old one keeps the new one.
|
|
328
|
+
const fresh = selected.filter(button => !this.#lastSelected.includes(button));
|
|
329
|
+
const keep = fresh.length < selected.length ? (fresh[fresh.length - 1] ?? selected[0]) : selected[0];
|
|
330
|
+
selected.filter(button => button !== keep).forEach(button => button.selected.set(false));
|
|
331
|
+
this.#lastSelected = [keep];
|
|
332
|
+
this.commitValue();
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
if (single && !allowEmpty && selected.length === 0 && this.value() === undefined) {
|
|
336
|
+
const previous = this.#lastSelected.find(button => buttons.includes(button));
|
|
337
|
+
previous?.selected.set(true);
|
|
338
|
+
if (previous) {
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
this.#lastSelected = selected;
|
|
343
|
+
}
|
|
210
344
|
setSubscriptions() {
|
|
211
345
|
this.#buttonService.buttonClick$
|
|
212
346
|
.pipe(takeUntilDestroyed(this.#destroyRef))
|
|
213
347
|
.subscribe(([button, wasSelected]) => {
|
|
348
|
+
if (this.readonly()) {
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
214
351
|
if (this.selection() === "single") {
|
|
215
352
|
if (wasSelected && !this.allowEmpty()) {
|
|
216
353
|
return;
|
|
@@ -227,19 +364,35 @@ class ButtonGroupComponent {
|
|
|
227
364
|
else {
|
|
228
365
|
this.#buttonService.buttonSelect$.next([button, !wasSelected]);
|
|
229
366
|
}
|
|
367
|
+
this.commitValue();
|
|
368
|
+
this.touch.emit();
|
|
230
369
|
});
|
|
231
370
|
}
|
|
371
|
+
valueButtons() {
|
|
372
|
+
return this.buttons().filter(button => button.effectiveToggleable() && button.value() !== undefined);
|
|
373
|
+
}
|
|
374
|
+
valuesOf(value) {
|
|
375
|
+
if (value == null) {
|
|
376
|
+
return [];
|
|
377
|
+
}
|
|
378
|
+
return Array.isArray(value) ? value : [value];
|
|
379
|
+
}
|
|
232
380
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: ButtonGroupComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
233
|
-
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.0.6", type: ButtonGroupComponent, isStandalone: true, selector: "mona-button-group", inputs: { allowEmpty: { classPropertyName: "allowEmpty", publicName: "allowEmpty", isSignal: true, isRequired: false, transformFunction: null }, ariaLabel: { classPropertyName: "ariaLabel", publicName: "aria-label", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, look: { classPropertyName: "look", publicName: "look", isSignal: true, isRequired: false, transformFunction: null }, rounded: { classPropertyName: "rounded", publicName: "rounded", isSignal: true, isRequired: false, transformFunction: null }, selection: { classPropertyName: "selection", publicName: "selection", isSignal: true, isRequired: false, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, userClass: { classPropertyName: "userClass", publicName: "class", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { buttonClick: "buttonClick",
|
|
381
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.0.6", type: ButtonGroupComponent, isStandalone: true, selector: "mona-button-group", inputs: { allowEmpty: { classPropertyName: "allowEmpty", publicName: "allowEmpty", isSignal: true, isRequired: false, transformFunction: null }, ariaLabel: { classPropertyName: "ariaLabel", publicName: "aria-label", isSignal: true, isRequired: false, transformFunction: null }, ariaLabelledBy: { classPropertyName: "ariaLabelledBy", publicName: "aria-labelledby", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, invalid: { classPropertyName: "invalid", publicName: "invalid", isSignal: true, isRequired: false, transformFunction: null }, look: { classPropertyName: "look", publicName: "look", isSignal: true, isRequired: false, transformFunction: null }, readonly: { classPropertyName: "readonly", publicName: "readonly", isSignal: true, isRequired: false, transformFunction: null }, rounded: { classPropertyName: "rounded", publicName: "rounded", isSignal: true, isRequired: false, transformFunction: null }, selection: { classPropertyName: "selection", publicName: "selection", isSignal: true, isRequired: false, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, touched: { classPropertyName: "touched", publicName: "touched", isSignal: true, isRequired: false, transformFunction: null }, userClass: { classPropertyName: "userClass", publicName: "class", isSignal: true, isRequired: false, transformFunction: null }, value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { buttonClick: "buttonClick", touch: "touch", value: "valueChange" }, host: { attributes: { "role": "group" }, listeners: { "focusout": "onFocusOut($event)" }, properties: { "attr.aria-invalid": "invalidState() ? 'true' : null", "attr.aria-label": "labelledBy() ? null : ariaLabel() || messages().buttonGroup", "attr.aria-labelledby": "labelledBy()", "attr.data-invalid": "invalidState() || null", "attr.data-readonly": "readonly() || null", "class": "baseClass()" } }, providers: [ButtonService], queries: [{ propertyName: "buttons", predicate: ButtonDirective, isSignal: true }, { propertyName: "components", predicate: BUTTON_GROUP_MEMBER, isSignal: true }], ngImport: i0, template: "<ng-content select=\"[monaButton], mona-dropdown-button, mona-split-button\"></ng-content>\n" }); }
|
|
234
382
|
}
|
|
235
383
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: ButtonGroupComponent, decorators: [{
|
|
236
384
|
type: Component,
|
|
237
385
|
args: [{ selector: "mona-button-group", providers: [ButtonService], host: {
|
|
238
|
-
"[attr.aria-
|
|
386
|
+
"[attr.aria-invalid]": "invalidState() ? 'true' : null",
|
|
387
|
+
"[attr.aria-label]": "labelledBy() ? null : ariaLabel() || messages().buttonGroup",
|
|
388
|
+
"[attr.aria-labelledby]": "labelledBy()",
|
|
389
|
+
"[attr.data-invalid]": "invalidState() || null",
|
|
390
|
+
"[attr.data-readonly]": "readonly() || null",
|
|
391
|
+
"(focusout)": "onFocusOut($event)",
|
|
239
392
|
"[class]": "baseClass()",
|
|
240
393
|
role: "group"
|
|
241
394
|
}, template: "<ng-content select=\"[monaButton], mona-dropdown-button, mona-split-button\"></ng-content>\n" }]
|
|
242
|
-
}], ctorParameters: () => [], propDecorators: { buttons: [{ type: i0.ContentChildren, args: [i0.forwardRef(() => ButtonDirective), { isSignal: true }] }], components: [{ type: i0.ContentChildren, args: [i0.forwardRef(() => BUTTON_GROUP_MEMBER), { isSignal: true }] }], allowEmpty: [{ type: i0.Input, args: [{ isSignal: true, alias: "allowEmpty", required: false }] }], ariaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "aria-label", required: false }] }], buttonClick: [{ type: i0.Output, args: ["buttonClick"] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }, { type: i0.
|
|
395
|
+
}], ctorParameters: () => [], propDecorators: { buttons: [{ type: i0.ContentChildren, args: [i0.forwardRef(() => ButtonDirective), { isSignal: true }] }], components: [{ type: i0.ContentChildren, args: [i0.forwardRef(() => BUTTON_GROUP_MEMBER), { isSignal: true }] }], allowEmpty: [{ type: i0.Input, args: [{ isSignal: true, alias: "allowEmpty", required: false }] }], ariaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "aria-label", required: false }] }], ariaLabelledBy: [{ type: i0.Input, args: [{ isSignal: true, alias: "aria-labelledby", required: false }] }], buttonClick: [{ type: i0.Output, args: ["buttonClick"] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], invalid: [{ type: i0.Input, args: [{ isSignal: true, alias: "invalid", required: false }] }], look: [{ type: i0.Input, args: [{ isSignal: true, alias: "look", required: false }] }], readonly: [{ type: i0.Input, args: [{ isSignal: true, alias: "readonly", required: false }] }], rounded: [{ type: i0.Input, args: [{ isSignal: true, alias: "rounded", required: false }] }], selection: [{ type: i0.Input, args: [{ isSignal: true, alias: "selection", required: false }] }], size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: false }] }], touch: [{ type: i0.Output, args: ["touch"] }], touched: [{ type: i0.Input, args: [{ isSignal: true, alias: "touched", required: false }] }], userClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "class", required: false }] }], value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: false }] }, { type: i0.Output, args: ["valueChange"] }] } });
|
|
243
396
|
|
|
244
397
|
/*
|
|
245
398
|
* Public API Surface of @nanahoshi/mona-ui/button-group
|
|
@@ -5,7 +5,7 @@ import { IndicatorIconComponent } from '@nanahoshi/mona-ui/internal/indicator-ic
|
|
|
5
5
|
import { Subject, fromEvent, takeWhile } from 'rxjs';
|
|
6
6
|
import { twMerge } from 'tailwind-merge';
|
|
7
7
|
import { cva } from 'class-variance-authority';
|
|
8
|
-
import { themeControlSurfaceClasses } from '@nanahoshi/mona-ui/internal';
|
|
8
|
+
import { themeSelectionBorderClasses, themeControlSurfaceClasses } from '@nanahoshi/mona-ui/internal';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Coordinates a `mona-button-group` with its buttons: the group publishes its look, size, rounding, disabled state
|
|
@@ -22,10 +22,16 @@ class ButtonService {
|
|
|
22
22
|
...(ngDevMode ? [{ debugName: "groupDisabled" }] : /* istanbul ignore next */ []));
|
|
23
23
|
this.groupLook = signal(undefined, /* @ts-ignore */
|
|
24
24
|
...(ngDevMode ? [{ debugName: "groupLook" }] : /* istanbul ignore next */ []));
|
|
25
|
+
this.groupReadonly = signal(false, /* @ts-ignore */
|
|
26
|
+
...(ngDevMode ? [{ debugName: "groupReadonly" }] : /* istanbul ignore next */ []));
|
|
25
27
|
this.groupRounded = signal(undefined, /* @ts-ignore */
|
|
26
28
|
...(ngDevMode ? [{ debugName: "groupRounded" }] : /* istanbul ignore next */ []));
|
|
27
29
|
this.groupSize = signal(undefined, /* @ts-ignore */
|
|
28
30
|
...(ngDevMode ? [{ debugName: "groupSize" }] : /* istanbul ignore next */ []));
|
|
31
|
+
/**
|
|
32
|
+
* Every click on a member, toggleable or not, reported after the group has applied its selection.
|
|
33
|
+
*/
|
|
34
|
+
this.memberClick$ = new Subject();
|
|
29
35
|
/**
|
|
30
36
|
* The buttons that belong to the group. Only these follow the group's look, size, rounding, disabled state and
|
|
31
37
|
* selection; other buttons that can inject this service ignore it.
|
|
@@ -53,6 +59,7 @@ const buttonThemeVariants = cva(`
|
|
|
53
59
|
text-sm font-medium
|
|
54
60
|
transition-colors duration-100 ease-in-out
|
|
55
61
|
focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus-indicator
|
|
62
|
+
forced-colors:border forced-colors:border-[ButtonBorder]
|
|
56
63
|
`, {
|
|
57
64
|
variants: {
|
|
58
65
|
disabled: {
|
|
@@ -74,7 +81,7 @@ const buttonThemeVariants = cva(`
|
|
|
74
81
|
look: {
|
|
75
82
|
default: `
|
|
76
83
|
${themeControlSurfaceClasses} text-foreground
|
|
77
|
-
border border-
|
|
84
|
+
border border-border
|
|
78
85
|
hover:bg-hover active:bg-active
|
|
79
86
|
focus-visible:border-focus-indicator
|
|
80
87
|
`,
|
|
@@ -104,7 +111,7 @@ const buttonThemeVariants = cva(`
|
|
|
104
111
|
`,
|
|
105
112
|
outline: `
|
|
106
113
|
${themeControlSurfaceClasses} text-foreground
|
|
107
|
-
border border-
|
|
114
|
+
border border-border
|
|
108
115
|
hover:bg-hover active:bg-active
|
|
109
116
|
focus-visible:border-focus-indicator
|
|
110
117
|
`,
|
|
@@ -142,7 +149,7 @@ const buttonThemeVariants = cva(`
|
|
|
142
149
|
small: "h-8 px-3 text-xs"
|
|
143
150
|
},
|
|
144
151
|
selected: {
|
|
145
|
-
true:
|
|
152
|
+
true: themeSelectionBorderClasses
|
|
146
153
|
}
|
|
147
154
|
},
|
|
148
155
|
compoundVariants: [
|
|
@@ -319,16 +326,17 @@ class ButtonDirective {
|
|
|
319
326
|
return twMerge(variantClasses, userClass);
|
|
320
327
|
}, /* @ts-ignore */
|
|
321
328
|
...(ngDevMode ? [{ debugName: "baseClass" }] : /* istanbul ignore next */ []));
|
|
322
|
-
this.effectiveDisabled = computed(() => this.#group()?.groupDisabled() || this.disabled(), /* @ts-ignore */
|
|
323
|
-
...(ngDevMode ? [{ debugName: "effectiveDisabled" }] : /* istanbul ignore next */ []));
|
|
324
329
|
this.effectiveLook = computed(() => this.#group()?.groupLook() ?? this.look(), /* @ts-ignore */
|
|
325
330
|
...(ngDevMode ? [{ debugName: "effectiveLook" }] : /* istanbul ignore next */ []));
|
|
326
331
|
this.effectiveRounded = computed(() => this.#group()?.groupRounded() ?? this.rounded(), /* @ts-ignore */
|
|
327
332
|
...(ngDevMode ? [{ debugName: "effectiveRounded" }] : /* istanbul ignore next */ []));
|
|
328
333
|
this.effectiveSize = computed(() => this.#group()?.groupSize() ?? this.size(), /* @ts-ignore */
|
|
329
334
|
...(ngDevMode ? [{ debugName: "effectiveSize" }] : /* istanbul ignore next */ []));
|
|
330
|
-
|
|
331
|
-
|
|
335
|
+
/**
|
|
336
|
+
* A read-only group's toggle buttons keep focus, so they can't be natively disabled.
|
|
337
|
+
*/
|
|
338
|
+
this.groupReadonly = computed(() => !!this.#group()?.groupReadonly() && this.effectiveToggleable(), /* @ts-ignore */
|
|
339
|
+
...(ngDevMode ? [{ debugName: "groupReadonly" }] : /* istanbul ignore next */ []));
|
|
332
340
|
this.loadingSize = computed(() => {
|
|
333
341
|
const size = this.effectiveSize();
|
|
334
342
|
switch (size) {
|
|
@@ -355,6 +363,18 @@ class ButtonDirective {
|
|
|
355
363
|
* @default false
|
|
356
364
|
*/
|
|
357
365
|
this.disabled = input(false, { ...(ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
366
|
+
/**
|
|
367
|
+
* Whether the button is disabled, by its own input or its group's. A dropdown or split button reads this to close
|
|
368
|
+
* its menu.
|
|
369
|
+
*/
|
|
370
|
+
this.effectiveDisabled = computed(() => this.#group()?.groupDisabled() || this.disabled(), /* @ts-ignore */
|
|
371
|
+
...(ngDevMode ? [{ debugName: "effectiveDisabled" }] : /* istanbul ignore next */ []));
|
|
372
|
+
/**
|
|
373
|
+
* Whether a click toggles the button: buttons in a group do unless `toggleable` is `false`. The group reads this to
|
|
374
|
+
* know which buttons take part in its selection.
|
|
375
|
+
*/
|
|
376
|
+
this.effectiveToggleable = computed(() => this.toggleable() ?? !!this.#group(), /* @ts-ignore */
|
|
377
|
+
...(ngDevMode ? [{ debugName: "effectiveToggleable" }] : /* istanbul ignore next */ []));
|
|
358
378
|
/**
|
|
359
379
|
* @description Removes horizontal padding and fixes a square aspect ratio sized to match `size`.
|
|
360
380
|
* Provide `aria-label` on the host when using icon-only buttons; in dev mode, an icon-only button without an
|
|
@@ -422,6 +442,13 @@ class ButtonDirective {
|
|
|
422
442
|
* @default ""
|
|
423
443
|
*/
|
|
424
444
|
this.userClass = input("", { ...(ngDevMode ? { debugName: "userClass" } : /* istanbul ignore next */ {}), alias: "class" });
|
|
445
|
+
/**
|
|
446
|
+
* @description What a `ButtonGroup`'s `value` holds while this button is selected. A button without one takes no part
|
|
447
|
+
* in the group's `value`.
|
|
448
|
+
* @default undefined
|
|
449
|
+
*/
|
|
450
|
+
this.value = input(/* @ts-ignore */
|
|
451
|
+
...(ngDevMode ? [undefined, { debugName: "value" }] : /* istanbul ignore next */ []));
|
|
425
452
|
effect(() => {
|
|
426
453
|
const toggleable = this.effectiveToggleable();
|
|
427
454
|
if (toggleable) {
|
|
@@ -496,6 +523,14 @@ class ButtonDirective {
|
|
|
496
523
|
this.selected.set(selected);
|
|
497
524
|
}
|
|
498
525
|
});
|
|
526
|
+
const host = this.#hostElementRef.nativeElement;
|
|
527
|
+
fromEvent(host, "click")
|
|
528
|
+
.pipe(takeUntilDestroyed(this.#destroyRef))
|
|
529
|
+
.subscribe(() => {
|
|
530
|
+
if (!this.effectiveToggleable()) {
|
|
531
|
+
this.#group()?.memberClick$.next([this, host]);
|
|
532
|
+
}
|
|
533
|
+
});
|
|
499
534
|
}
|
|
500
535
|
#hasAccessibleName() {
|
|
501
536
|
const host = this.#hostElementRef.nativeElement;
|
|
@@ -514,6 +549,7 @@ class ButtonDirective {
|
|
|
514
549
|
const group = this.#group();
|
|
515
550
|
if (group) {
|
|
516
551
|
group.buttonClick$.next([this, wasSelected]);
|
|
552
|
+
group.memberClick$.next([this, this.#hostElementRef.nativeElement]);
|
|
517
553
|
}
|
|
518
554
|
else {
|
|
519
555
|
this.selected.set(!this.selected());
|
|
@@ -533,7 +569,7 @@ class ButtonDirective {
|
|
|
533
569
|
});
|
|
534
570
|
}
|
|
535
571
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: ButtonDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
536
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.0.6", type: ButtonDirective, isStandalone: true, selector: "button[monaButton]", inputs: { ariaHasPopup: { classPropertyName: "ariaHasPopup", publicName: "aria-haspopup", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, iconOnly: { classPropertyName: "iconOnly", publicName: "iconOnly", isSignal: true, isRequired: false, transformFunction: null }, loading: { classPropertyName: "loading", publicName: "loading", isSignal: true, isRequired: false, transformFunction: null }, look: { classPropertyName: "look", publicName: "look", isSignal: true, isRequired: false, transformFunction: null }, rounded: { classPropertyName: "rounded", publicName: "rounded", isSignal: true, isRequired: false, transformFunction: null }, selected: { classPropertyName: "selected", publicName: "selected", isSignal: true, isRequired: false, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, tabindex: { classPropertyName: "tabindex", publicName: "tabindex", isSignal: true, isRequired: false, transformFunction: null }, toggleable: { classPropertyName: "toggleable", publicName: "toggleable", isSignal: true, isRequired: false, transformFunction: null }, type: { classPropertyName: "type", publicName: "type", isSignal: true, isRequired: false, transformFunction: null }, userClass: { classPropertyName: "userClass", publicName: "class", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { look: "lookChange", selected: "selectedChange" }, host: { properties: { "attr.aria-busy": "loading() ? 'true' : undefined", "attr.aria-disabled": "effectiveDisabled() || loading() ? 'true' : undefined", "attr.aria-haspopup": "ariaHasPopup() !== 'false' ? ariaHasPopup() : null", "attr.aria-pressed": "effectiveToggleable() ? (selected() ? 'true' : 'false') : undefined", "attr.data-look": "effectiveLook()", "attr.data-size": "effectiveSize()", "attr.disabled": "effectiveDisabled() ? '' : undefined", "attr.tabindex": "effectiveDisabled() ? -1 : tabindex()", "attr.type": "type()", "class": "baseClass()" } }, ngImport: i0 }); }
|
|
572
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.0.6", type: ButtonDirective, isStandalone: true, selector: "button[monaButton]", inputs: { ariaHasPopup: { classPropertyName: "ariaHasPopup", publicName: "aria-haspopup", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, iconOnly: { classPropertyName: "iconOnly", publicName: "iconOnly", isSignal: true, isRequired: false, transformFunction: null }, loading: { classPropertyName: "loading", publicName: "loading", isSignal: true, isRequired: false, transformFunction: null }, look: { classPropertyName: "look", publicName: "look", isSignal: true, isRequired: false, transformFunction: null }, rounded: { classPropertyName: "rounded", publicName: "rounded", isSignal: true, isRequired: false, transformFunction: null }, selected: { classPropertyName: "selected", publicName: "selected", isSignal: true, isRequired: false, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, tabindex: { classPropertyName: "tabindex", publicName: "tabindex", isSignal: true, isRequired: false, transformFunction: null }, toggleable: { classPropertyName: "toggleable", publicName: "toggleable", isSignal: true, isRequired: false, transformFunction: null }, type: { classPropertyName: "type", publicName: "type", isSignal: true, isRequired: false, transformFunction: null }, userClass: { classPropertyName: "userClass", publicName: "class", isSignal: true, isRequired: false, transformFunction: null }, value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { look: "lookChange", selected: "selectedChange" }, host: { properties: { "attr.aria-busy": "loading() ? 'true' : undefined", "attr.aria-disabled": "effectiveDisabled() || loading() || groupReadonly() ? 'true' : undefined", "attr.aria-haspopup": "ariaHasPopup() !== 'false' ? ariaHasPopup() : null", "attr.aria-pressed": "effectiveToggleable() ? (selected() ? 'true' : 'false') : undefined", "attr.data-look": "effectiveLook()", "attr.data-size": "effectiveSize()", "attr.disabled": "effectiveDisabled() ? '' : undefined", "attr.tabindex": "effectiveDisabled() ? -1 : tabindex()", "attr.type": "type()", "class": "baseClass()" } }, ngImport: i0 }); }
|
|
537
573
|
}
|
|
538
574
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: ButtonDirective, decorators: [{
|
|
539
575
|
type: Directive,
|
|
@@ -541,7 +577,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImpor
|
|
|
541
577
|
selector: "button[monaButton]",
|
|
542
578
|
host: {
|
|
543
579
|
"[attr.aria-busy]": "loading() ? 'true' : undefined",
|
|
544
|
-
"[attr.aria-disabled]": "effectiveDisabled() || loading() ? 'true' : undefined",
|
|
580
|
+
"[attr.aria-disabled]": "effectiveDisabled() || loading() || groupReadonly() ? 'true' : undefined",
|
|
545
581
|
"[attr.aria-haspopup]": "ariaHasPopup() !== 'false' ? ariaHasPopup() : null",
|
|
546
582
|
"[attr.aria-pressed]": "effectiveToggleable() ? (selected() ? 'true' : 'false') : undefined",
|
|
547
583
|
"[attr.data-look]": "effectiveLook()",
|
|
@@ -552,7 +588,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImpor
|
|
|
552
588
|
"[class]": "baseClass()"
|
|
553
589
|
}
|
|
554
590
|
}]
|
|
555
|
-
}], ctorParameters: () => [], propDecorators: { ariaHasPopup: [{ type: i0.Input, args: [{ isSignal: true, alias: "aria-haspopup", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], iconOnly: [{ type: i0.Input, args: [{ isSignal: true, alias: "iconOnly", required: false }] }], loading: [{ type: i0.Input, args: [{ isSignal: true, alias: "loading", required: false }] }], look: [{ type: i0.Input, args: [{ isSignal: true, alias: "look", required: false }] }, { type: i0.Output, args: ["lookChange"] }], rounded: [{ type: i0.Input, args: [{ isSignal: true, alias: "rounded", required: false }] }], selected: [{ type: i0.Input, args: [{ isSignal: true, alias: "selected", required: false }] }, { type: i0.Output, args: ["selectedChange"] }], size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: false }] }], tabindex: [{ type: i0.Input, args: [{ isSignal: true, alias: "tabindex", required: false }] }], toggleable: [{ type: i0.Input, args: [{ isSignal: true, alias: "toggleable", required: false }] }], type: [{ type: i0.Input, args: [{ isSignal: true, alias: "type", required: false }] }], userClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "class", required: false }] }] } });
|
|
591
|
+
}], ctorParameters: () => [], propDecorators: { ariaHasPopup: [{ type: i0.Input, args: [{ isSignal: true, alias: "aria-haspopup", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], iconOnly: [{ type: i0.Input, args: [{ isSignal: true, alias: "iconOnly", required: false }] }], loading: [{ type: i0.Input, args: [{ isSignal: true, alias: "loading", required: false }] }], look: [{ type: i0.Input, args: [{ isSignal: true, alias: "look", required: false }] }, { type: i0.Output, args: ["lookChange"] }], rounded: [{ type: i0.Input, args: [{ isSignal: true, alias: "rounded", required: false }] }], selected: [{ type: i0.Input, args: [{ isSignal: true, alias: "selected", required: false }] }, { type: i0.Output, args: ["selectedChange"] }], size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: false }] }], tabindex: [{ type: i0.Input, args: [{ isSignal: true, alias: "tabindex", required: false }] }], toggleable: [{ type: i0.Input, args: [{ isSignal: true, alias: "toggleable", required: false }] }], type: [{ type: i0.Input, args: [{ isSignal: true, alias: "type", required: false }] }], userClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "class", required: false }] }], value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: false }] }] } });
|
|
556
592
|
|
|
557
593
|
/**
|
|
558
594
|
* Provided by a component that implements {@link ButtonGroupMember}, so a `mona-button-group` can find it among its
|