@nanahoshi/mona-ui 0.25.1 → 0.26.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 +2 -0
- package/command/package.json +4 -0
- package/docs/auto-complete.md +733 -0
- package/docs/avatar.md +220 -0
- package/docs/breadcrumb.md +320 -0
- package/docs/button-group.md +392 -0
- package/docs/button.md +256 -0
- package/docs/calendar.md +515 -0
- package/docs/card.md +292 -0
- package/docs/chart.md +4058 -0
- package/docs/checkbox.md +374 -0
- package/docs/chip.md +339 -0
- package/docs/circular-progress-bar.md +287 -0
- package/docs/collapsible.md +308 -0
- package/docs/color-gradient.md +336 -0
- package/docs/color-palette.md +317 -0
- package/docs/color-picker.md +387 -0
- package/docs/combo-box.md +764 -0
- package/docs/command.md +582 -0
- package/docs/contextmenu.md +530 -0
- package/docs/date-picker.md +251 -0
- package/docs/datetime-picker.md +284 -0
- package/docs/decimal-textbox.md +260 -0
- package/docs/dialog.md +822 -0
- package/docs/dropdown-button.md +507 -0
- package/docs/dropdown-list.md +779 -0
- package/docs/editor.md +374 -0
- package/docs/expansion-panel.md +348 -0
- package/docs/fieldset.md +217 -0
- package/docs/forms.md +162 -0
- package/docs/grid.md +2053 -0
- package/docs/input.md +197 -0
- package/docs/installation.md +54 -0
- package/docs/introduction.md +46 -0
- package/docs/label.md +340 -0
- package/docs/list-box.md +637 -0
- package/docs/list-view.md +584 -0
- package/docs/menubar.md +559 -0
- package/docs/multi-select.md +765 -0
- package/docs/notification.md +460 -0
- package/docs/numeric-textbox.md +301 -0
- package/docs/otp-input.md +539 -0
- package/docs/pager.md +513 -0
- package/docs/placeholder.md +176 -0
- package/docs/popover.md +423 -0
- package/docs/popup-menu.md +658 -0
- package/docs/popup.md +617 -0
- package/docs/progress-bar.md +368 -0
- package/docs/radio-button.md +451 -0
- package/docs/range-slider.md +367 -0
- package/docs/rating.md +518 -0
- package/docs/scroll-view.md +375 -0
- package/docs/segmented.md +434 -0
- package/docs/sheet.md +348 -0
- package/docs/sidebar.md +1126 -0
- package/docs/skeleton.md +181 -0
- package/docs/slider.md +423 -0
- package/docs/spinner.md +370 -0
- package/docs/split-button.md +522 -0
- package/docs/splitter.md +342 -0
- package/docs/stepper.md +539 -0
- package/docs/switch.md +340 -0
- package/docs/tabs.md +542 -0
- package/docs/textarea.md +196 -0
- package/docs/textbox.md +332 -0
- package/docs/theming.md +403 -0
- package/docs/time-picker.md +254 -0
- package/docs/tooltip-directive.md +340 -0
- package/docs/tooltip.md +321 -0
- package/docs/tree-view.md +1018 -0
- package/docs/window.md +663 -0
- package/fesm2022/nanahoshi-mona-ui-auto-complete.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-breadcrumb.mjs +8 -0
- package/fesm2022/nanahoshi-mona-ui-button.mjs +12 -0
- package/fesm2022/nanahoshi-mona-ui-calendar.mjs +5 -2
- package/fesm2022/nanahoshi-mona-ui-chart.mjs +86 -0
- package/fesm2022/nanahoshi-mona-ui-check-box.mjs +4 -0
- package/fesm2022/nanahoshi-mona-ui-circular-progress-bar.mjs +4 -0
- package/fesm2022/nanahoshi-mona-ui-collapsible.mjs +16 -2
- package/fesm2022/nanahoshi-mona-ui-combo-box.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-command.mjs +924 -0
- package/fesm2022/nanahoshi-mona-ui-common.mjs +4 -0
- package/fesm2022/nanahoshi-mona-ui-contextmenu.mjs +10 -6
- package/fesm2022/nanahoshi-mona-ui-date-picker.mjs +2 -1
- package/fesm2022/nanahoshi-mona-ui-datetime-picker.mjs +2 -1
- package/fesm2022/nanahoshi-mona-ui-dialog.mjs +9 -5
- package/fesm2022/nanahoshi-mona-ui-dropdown-button.mjs +9 -5
- package/fesm2022/nanahoshi-mona-ui-dropdowns.mjs +55 -1
- package/fesm2022/nanahoshi-mona-ui-editor.mjs +3 -2
- package/fesm2022/nanahoshi-mona-ui-expansion-panel.mjs +13 -0
- package/fesm2022/nanahoshi-mona-ui-fieldset.mjs +5 -0
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-footer-row.component-2tVhD2hK.mjs → nanahoshi-mona-ui-grid-grid-footer-row.component-DjNnVxHE.mjs} +2 -2
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-list.component-BAN70Wcn.mjs → nanahoshi-mona-ui-grid-grid-list.component-ihQIKeP-.mjs} +5 -5
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-row.component-C_kCaA5b.mjs → nanahoshi-mona-ui-grid-grid-row.component-BpnybNcs.mjs} +18 -35
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-virtual-list.component-BsNfrAHz.mjs → nanahoshi-mona-ui-grid-grid-virtual-list.component-CYlgfc7c.mjs} +5 -5
- package/fesm2022/{nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-CEfVa7eo.mjs → nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-LCzfCYd3.mjs} +4653 -4529
- package/fesm2022/nanahoshi-mona-ui-grid.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-internal-list.mjs +1 -0
- package/fesm2022/nanahoshi-mona-ui-internal-popup-menu.mjs +168 -0
- package/fesm2022/nanahoshi-mona-ui-internal-tree.mjs +19 -1
- package/fesm2022/nanahoshi-mona-ui-list-box.mjs +14 -0
- package/fesm2022/nanahoshi-mona-ui-list-view.mjs +32 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-menubar.mjs +15 -8
- package/fesm2022/nanahoshi-mona-ui-multi-select.mjs +8 -5
- package/fesm2022/nanahoshi-mona-ui-notification.mjs +9 -0
- package/fesm2022/nanahoshi-mona-ui-numeric-text-box.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-otp-input.mjs +5 -0
- package/fesm2022/nanahoshi-mona-ui-pager.mjs +2 -1
- package/fesm2022/nanahoshi-mona-ui-popover.mjs +14 -6
- package/fesm2022/nanahoshi-mona-ui-popup-menu.mjs +48 -183
- package/fesm2022/nanahoshi-mona-ui-popup.mjs +16 -0
- package/fesm2022/nanahoshi-mona-ui-progress-bar.mjs +4 -0
- package/fesm2022/nanahoshi-mona-ui-rating.mjs +2 -0
- package/fesm2022/nanahoshi-mona-ui-segmented.mjs +1 -0
- package/fesm2022/nanahoshi-mona-ui-sheet.mjs +5 -5
- package/fesm2022/nanahoshi-mona-ui-sidebar.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-slider.mjs +7 -2
- package/fesm2022/nanahoshi-mona-ui-split-button.mjs +9 -6
- package/fesm2022/nanahoshi-mona-ui-stepper.mjs +18 -21
- package/fesm2022/nanahoshi-mona-ui-tabs.mjs +11 -8
- package/fesm2022/nanahoshi-mona-ui-text-box.mjs +9 -1
- package/fesm2022/nanahoshi-mona-ui-time-picker.mjs +2 -1
- package/fesm2022/nanahoshi-mona-ui-tooltip.mjs +16 -5
- package/fesm2022/nanahoshi-mona-ui-tree-view.mjs +13 -11
- package/fesm2022/nanahoshi-mona-ui-window.mjs +12 -5
- package/i18n/catalogs/en-US.messages.json +10 -0
- package/internal/popup-menu/package.json +4 -0
- package/llms.txt +123 -0
- package/locales/ar-sa/ar-sa.messages.json +10 -0
- package/locales/de-de/de-de.messages.json +10 -0
- package/locales/es-es/es-es.messages.json +10 -0
- package/locales/fr-fr/fr-fr.messages.json +10 -0
- package/locales/id-id/id-id.messages.json +10 -0
- package/locales/it-it/it-it.messages.json +10 -0
- package/locales/ja-jp/ja-jp.messages.json +10 -0
- package/locales/ko-kr/ko-kr.messages.json +10 -0
- package/locales/pt-br/pt-br.messages.json +10 -0
- package/locales/ru-ru/ru-ru.messages.json +10 -0
- package/locales/tr-tr/tr-tr.messages.json +10 -0
- package/locales/zh-cn/zh-cn.messages.json +10 -0
- package/locales/zh-tw/zh-tw.messages.json +10 -0
- package/package.json +9 -1
- package/types/nanahoshi-mona-ui-auto-complete.d.ts +1 -1
- package/types/nanahoshi-mona-ui-breadcrumb.d.ts +8 -0
- package/types/nanahoshi-mona-ui-button.d.ts +12 -0
- package/types/nanahoshi-mona-ui-calendar.d.ts +3 -0
- package/types/nanahoshi-mona-ui-chart.d.ts +200 -0
- package/types/nanahoshi-mona-ui-check-box.d.ts +4 -0
- package/types/nanahoshi-mona-ui-circular-progress-bar.d.ts +4 -0
- package/types/nanahoshi-mona-ui-collapsible.d.ts +10 -0
- package/types/nanahoshi-mona-ui-combo-box.d.ts +1 -1
- package/types/nanahoshi-mona-ui-command.d.ts +253 -0
- package/types/nanahoshi-mona-ui-common.d.ts +17 -1
- package/types/nanahoshi-mona-ui-contextmenu.d.ts +5 -2
- package/types/nanahoshi-mona-ui-date-picker.d.ts +2 -1
- package/types/nanahoshi-mona-ui-datetime-picker.d.ts +2 -1
- package/types/nanahoshi-mona-ui-dialog.d.ts +58 -1
- package/types/nanahoshi-mona-ui-dropdown-button.d.ts +7 -3
- package/types/nanahoshi-mona-ui-dropdowns.d.ts +55 -1
- package/types/nanahoshi-mona-ui-editor.d.ts +31 -0
- package/types/nanahoshi-mona-ui-expansion-panel.d.ts +13 -0
- package/types/nanahoshi-mona-ui-fieldset.d.ts +5 -0
- package/types/nanahoshi-mona-ui-grid.d.ts +162 -35
- package/types/nanahoshi-mona-ui-i18n.d.ts +144 -1
- package/types/nanahoshi-mona-ui-internal-list.d.ts +16 -1
- package/types/nanahoshi-mona-ui-internal-popup-menu.d.ts +165 -0
- package/types/nanahoshi-mona-ui-internal-tree.d.ts +21 -2
- package/types/nanahoshi-mona-ui-internal.d.ts +4 -5
- package/types/nanahoshi-mona-ui-label.d.ts +1 -0
- package/types/nanahoshi-mona-ui-list-box.d.ts +27 -4
- package/types/nanahoshi-mona-ui-list-view.d.ts +34 -1
- package/types/nanahoshi-mona-ui-list.d.ts +1 -1
- package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-de-de.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-es-es.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-id-id.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-it-it.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +10 -0
- package/types/nanahoshi-mona-ui-menubar.d.ts +10 -3
- package/types/nanahoshi-mona-ui-multi-select.d.ts +3 -3
- package/types/nanahoshi-mona-ui-notification.d.ts +9 -0
- package/types/nanahoshi-mona-ui-numeric-text-box.d.ts +1 -1
- package/types/nanahoshi-mona-ui-otp-input.d.ts +1 -0
- package/types/nanahoshi-mona-ui-pager.d.ts +5 -1
- package/types/nanahoshi-mona-ui-popover.d.ts +9 -1
- package/types/nanahoshi-mona-ui-popup-menu.d.ts +48 -161
- package/types/nanahoshi-mona-ui-popup.d.ts +16 -0
- package/types/nanahoshi-mona-ui-progress-bar.d.ts +4 -0
- package/types/nanahoshi-mona-ui-rating.d.ts +2 -0
- package/types/nanahoshi-mona-ui-segmented.d.ts +1 -0
- package/types/nanahoshi-mona-ui-sheet.d.ts +1 -1
- package/types/nanahoshi-mona-ui-slider.d.ts +2 -0
- package/types/nanahoshi-mona-ui-spinner.d.ts +7 -0
- package/types/nanahoshi-mona-ui-split-button.d.ts +7 -4
- package/types/nanahoshi-mona-ui-stepper.d.ts +11 -2
- package/types/nanahoshi-mona-ui-tabs.d.ts +4 -1
- package/types/nanahoshi-mona-ui-text-box.d.ts +9 -1
- package/types/nanahoshi-mona-ui-time-picker.d.ts +2 -1
- package/types/nanahoshi-mona-ui-tooltip.d.ts +10 -2
- package/types/nanahoshi-mona-ui-tree-view.d.ts +6 -5
- package/types/nanahoshi-mona-ui-window.d.ts +66 -1
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
# Button Group
|
|
2
|
+
|
|
3
|
+
> Joins related buttons into one control with a shared look and size.
|
|
4
|
+
|
|
5
|
+
Entry point: `@nanahoshi/mona-ui/button-group`
|
|
6
|
+
|
|
7
|
+
**Selector:** `mona-button-group`
|
|
8
|
+
|
|
9
|
+
`ButtonGroupComponent` wraps a set of `<button monaButton>` elements into a cohesive control that shares look, size, and border-radius across all child buttons and coordinates toggle selection in single or multiple mode.
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
`ButtonGroupComponent` groups native `<button monaButton>` children into a cohesive control. Its `look`, `size` and `rounded` replace each child's own, and its `disabled` disables every child, as well as any that its own `disabled` already disables.
|
|
14
|
+
|
|
15
|
+
Buttons in a group are toggle buttons, unless `[toggleable]="false"` makes one a plain action. `selection` coordinates the toggles. In `"multiple"` mode, the default, each button toggles independently. In `"single"` mode, activating one button deactivates all others.
|
|
16
|
+
|
|
17
|
+
`"single"` is a toggle group, not a radio group: each button keeps `aria-pressed` and its own Tab stop. For a choice that must always hold one value, use `mona-segmented`, which is a radio group with arrow keys.
|
|
18
|
+
|
|
19
|
+
**Use `ButtonGroupComponent` when you need to:**
|
|
20
|
+
|
|
21
|
+
- Group related action buttons that must share a visual style (toolbar rows, formatting controls), with `[toggleable]="false"` on each
|
|
22
|
+
- Implement mutually exclusive toggles, where one or none can be active (a text alignment that can be off)
|
|
23
|
+
- Implement multi-select filters where any combination of options can be active simultaneously
|
|
24
|
+
|
|
25
|
+
**Do not use `ButtonGroupComponent` when:**
|
|
26
|
+
|
|
27
|
+
- The buttons navigate to URLs — use a `<nav>` element with anchor tags instead
|
|
28
|
+
- There is only a single stand-alone toggle — apply `[toggleable]="true"` directly on one `<button monaButton>`
|
|
29
|
+
- A dropdown or split action is needed on its own — use `DropdownButton` or `SplitButton`
|
|
30
|
+
- One option must always be chosen, such as a view mode — use `mona-segmented`, which is a radio group with arrow keys
|
|
31
|
+
|
|
32
|
+
## Import & Quick Start
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { ButtonDirective } from "@nanahoshi/mona-ui/button";
|
|
36
|
+
import { ButtonGroupComponent } from "@nanahoshi/mona-ui/button-group";
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Add both to your standalone component's `imports` array. `ButtonDirective` is required on each child button.
|
|
40
|
+
|
|
41
|
+
**Basic group — shared styling, no selection:**
|
|
42
|
+
|
|
43
|
+
```html
|
|
44
|
+
<mona-button-group aria-label="Clipboard">
|
|
45
|
+
<button monaButton [toggleable]="false">Cut</button>
|
|
46
|
+
<button monaButton [toggleable]="false">Copy</button>
|
|
47
|
+
<button monaButton [toggleable]="false">Paste</button>
|
|
48
|
+
</mona-button-group>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**Disabled group:**
|
|
52
|
+
|
|
53
|
+
```html
|
|
54
|
+
<mona-button-group [disabled]="isDisabled()">
|
|
55
|
+
<button monaButton>Option A</button>
|
|
56
|
+
<button monaButton>Option B</button>
|
|
57
|
+
</mona-button-group>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
> **Group inputs override child inputs.** When a child button is inside a `ButtonGroupComponent`, the group's `look`, `size` and `rounded` values replace the child's own inputs for those properties. A child is disabled when either it or the group is.
|
|
61
|
+
|
|
62
|
+
> **Use `value` or `[(selected)]`, not both.** Without a `value`, each button's `[(selected)]` holds its state.
|
|
63
|
+
|
|
64
|
+
> **The selection policy holds for bindings too.** In `"single"` mode a second `selected` button deselects the other, keeping the newest, or the first when several arrive together. A disabled selected button is deselected as well, so the group never holds two.
|
|
65
|
+
|
|
66
|
+
> **A value with no button yet is kept,** so one that loads first isn't lost. A selected button's value stays in `value` if the button goes away, until the application removes it.
|
|
67
|
+
|
|
68
|
+
> **`allowEmpty` only applies to `"single"` selection mode.** In `"multiple"` mode, any number of buttons (including zero) can be active simultaneously. It keeps a selected button selected, against clicks and against `selected` bindings, but it doesn't choose a first one, and a `value` of `null` still clears the group so a form can reset it.
|
|
69
|
+
|
|
70
|
+
> **Other content is dropped.** Only `monaButton` buttons, `mona-dropdown-button` and `mona-split-button` placed directly in the group render. A `<span>`, a link or a button inside a `<div>` doesn't appear, and nothing warns about it.
|
|
71
|
+
|
|
72
|
+
> **Switching from `"multiple"` to `"single"` reconciles existing state.** When `selection` changes from `"multiple"` to `"single"` at runtime, all but the first currently-selected button are automatically deselected.
|
|
73
|
+
|
|
74
|
+
## Examples
|
|
75
|
+
|
|
76
|
+
### Action buttons
|
|
77
|
+
|
|
78
|
+
`[toggleable]="false"` makes each button a plain action, so the group only shares their style.
|
|
79
|
+
|
|
80
|
+
`actions-example.component.ts`
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import { Component, signal } from "@angular/core";
|
|
84
|
+
import { ButtonDirective } from "@nanahoshi/mona-ui/button";
|
|
85
|
+
import type { ButtonGroupClickEvent } from "@nanahoshi/mona-ui/button-group";
|
|
86
|
+
import { ButtonGroupComponent } from "@nanahoshi/mona-ui/button-group";
|
|
87
|
+
|
|
88
|
+
@Component({
|
|
89
|
+
selector: "app-button-group-actions-example",
|
|
90
|
+
imports: [ButtonDirective, ButtonGroupComponent],
|
|
91
|
+
templateUrl: "./actions-example.component.html"
|
|
92
|
+
})
|
|
93
|
+
export class ButtonGroupActionsExampleComponent {
|
|
94
|
+
protected readonly lastAction = signal("none");
|
|
95
|
+
|
|
96
|
+
protected onClick(event: ButtonGroupClickEvent): void {
|
|
97
|
+
this.lastAction.set(typeof event.value === "string" ? event.value : "none");
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
`actions-example.component.html`
|
|
103
|
+
|
|
104
|
+
```html
|
|
105
|
+
<div class="flex flex-wrap items-center gap-3">
|
|
106
|
+
<mona-button-group aria-label="Clipboard" (buttonClick)="onClick($event)">
|
|
107
|
+
<button monaButton type="button" value="cut" [toggleable]="false">Cut</button>
|
|
108
|
+
<button monaButton type="button" value="copy" [toggleable]="false">Copy</button>
|
|
109
|
+
<button monaButton type="button" value="paste" [toggleable]="false">Paste</button>
|
|
110
|
+
</mona-button-group>
|
|
111
|
+
<span aria-live="polite" class="text-sm">Last action: {{ lastAction() }}</span>
|
|
112
|
+
</div>
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
`buttonClick` reports which button was clicked:
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
import type { ButtonGroupClickEvent } from "@nanahoshi/mona-ui/button-group";
|
|
119
|
+
|
|
120
|
+
protected onClick({ button, selected, value }: ButtonGroupClickEvent): void {}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
| Property | Type | Description |
|
|
124
|
+
|------------|---------------------|---------------------------------------------------------------------|
|
|
125
|
+
| `button` | `HTMLButtonElement` | The button's element. |
|
|
126
|
+
| `selected` | `boolean` | Whether the button is selected now that the group has applied its selection. |
|
|
127
|
+
| `value` | `T \| undefined` | The button's `value`, if it has one. |
|
|
128
|
+
|
|
129
|
+
`buttonClick` fires for every button placed directly in the group, toggleable or not, after the selection has changed. It doesn't fire for a disabled or loading button, for a dropdown or split button's own buttons, or for a toggle button in a read-only group, since nothing was selected. A button that isn't toggleable still fires there.
|
|
130
|
+
|
|
131
|
+
### Holding the selection in one value
|
|
132
|
+
|
|
133
|
+
`multiple-example.component.ts`
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
import { Component, computed, signal } from "@angular/core";
|
|
137
|
+
import { ButtonDirective } from "@nanahoshi/mona-ui/button";
|
|
138
|
+
import { ButtonGroupComponent } from "@nanahoshi/mona-ui/button-group";
|
|
139
|
+
|
|
140
|
+
@Component({
|
|
141
|
+
selector: "app-button-group-multiple-example",
|
|
142
|
+
imports: [ButtonDirective, ButtonGroupComponent],
|
|
143
|
+
templateUrl: "./multiple-example.component.html"
|
|
144
|
+
})
|
|
145
|
+
export class ButtonGroupMultipleExampleComponent {
|
|
146
|
+
protected readonly formatting = signal<string | readonly string[] | null | undefined>(["bold"]);
|
|
147
|
+
protected readonly summary = computed(() => {
|
|
148
|
+
const value = this.formatting();
|
|
149
|
+
return Array.isArray(value) && value.length > 0 ? value.join(", ") : "none";
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
`multiple-example.component.html`
|
|
155
|
+
|
|
156
|
+
```html
|
|
157
|
+
<div class="flex flex-col items-start gap-3">
|
|
158
|
+
<mona-button-group aria-label="Text formatting" selection="multiple" [(value)]="formatting">
|
|
159
|
+
<button monaButton type="button" value="bold">Bold</button>
|
|
160
|
+
<button monaButton type="button" value="italic">Italic</button>
|
|
161
|
+
<button monaButton type="button" value="underline">Underline</button>
|
|
162
|
+
</mona-button-group>
|
|
163
|
+
<span class="text-sm">Value: {{ summary() }}</span>
|
|
164
|
+
</div>
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
`value` is the selected button's value or `null` in `"single"` mode, and an array of them in `"multiple"` mode. Values compare with `===`. Only toggleable buttons with a `value` take part, and action buttons in the same group keep working. While `value` is `undefined`, the group leaves each button's `selected` alone.
|
|
168
|
+
|
|
169
|
+
### Forms
|
|
170
|
+
|
|
171
|
+
`value` also works with `[formField]`, and through Angular's own binding of a control with no `ControlValueAccessor`, with `[(ngModel)]`, `[formControl]` and `formControlName`. In `"single"` mode, activating one button deactivates the others.
|
|
172
|
+
|
|
173
|
+
`forms-example.component.ts`
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
import { Component, signal } from "@angular/core";
|
|
177
|
+
import { form, FormField } from "@angular/forms/signals";
|
|
178
|
+
import { ButtonDirective } from "@nanahoshi/mona-ui/button";
|
|
179
|
+
import { ButtonGroupComponent } from "@nanahoshi/mona-ui/button-group";
|
|
180
|
+
|
|
181
|
+
@Component({
|
|
182
|
+
selector: "app-button-group-forms-example",
|
|
183
|
+
imports: [ButtonDirective, ButtonGroupComponent, FormField],
|
|
184
|
+
templateUrl: "./forms-example.component.html"
|
|
185
|
+
})
|
|
186
|
+
export class ButtonGroupFormsExampleComponent {
|
|
187
|
+
readonly #model = signal<{ align: string | null }>({ align: "left" });
|
|
188
|
+
protected readonly paragraph = form(this.#model);
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
`forms-example.component.html`
|
|
193
|
+
|
|
194
|
+
```html
|
|
195
|
+
<div class="flex flex-col items-start gap-3">
|
|
196
|
+
<mona-button-group aria-label="Text alignment" selection="single" [formField]="paragraph.align">
|
|
197
|
+
<button monaButton type="button" value="left">Left</button>
|
|
198
|
+
<button monaButton type="button" value="center">Center</button>
|
|
199
|
+
<button monaButton type="button" value="right">Right</button>
|
|
200
|
+
</mona-button-group>
|
|
201
|
+
<span class="text-sm">Alignment: {{ paragraph.align().value() ?? "none" }}</span>
|
|
202
|
+
</div>
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### With dropdown and split buttons
|
|
206
|
+
|
|
207
|
+
Dropdown and split buttons take the group's look, size, rounding and disabled state, but take no part in its selection.
|
|
208
|
+
|
|
209
|
+
`with-menus-example.component.ts`
|
|
210
|
+
|
|
211
|
+
```typescript
|
|
212
|
+
import { Component } from "@angular/core";
|
|
213
|
+
import { ButtonDirective } from "@nanahoshi/mona-ui/button";
|
|
214
|
+
import { ButtonGroupComponent } from "@nanahoshi/mona-ui/button-group";
|
|
215
|
+
import { DropdownButtonComponent, DropdownButtonItemComponent } from "@nanahoshi/mona-ui/dropdown-button";
|
|
216
|
+
import { SplitButtonComponent, SplitButtonItemComponent } from "@nanahoshi/mona-ui/split-button";
|
|
217
|
+
|
|
218
|
+
@Component({
|
|
219
|
+
selector: "app-button-group-with-menus-example",
|
|
220
|
+
imports: [
|
|
221
|
+
ButtonDirective,
|
|
222
|
+
ButtonGroupComponent,
|
|
223
|
+
DropdownButtonComponent,
|
|
224
|
+
DropdownButtonItemComponent,
|
|
225
|
+
SplitButtonComponent,
|
|
226
|
+
SplitButtonItemComponent
|
|
227
|
+
],
|
|
228
|
+
templateUrl: "./with-menus-example.component.html"
|
|
229
|
+
})
|
|
230
|
+
export class ButtonGroupWithMenusExampleComponent {}
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
`with-menus-example.component.html`
|
|
234
|
+
|
|
235
|
+
```html
|
|
236
|
+
<mona-button-group aria-label="Document">
|
|
237
|
+
<button monaButton type="button" [toggleable]="false">Undo</button>
|
|
238
|
+
<mona-dropdown-button text="Insert">
|
|
239
|
+
<mona-dropdown-button-item label="Table" />
|
|
240
|
+
<mona-dropdown-button-item label="Image" />
|
|
241
|
+
</mona-dropdown-button>
|
|
242
|
+
<mona-split-button text="Save">
|
|
243
|
+
<mona-split-button-item label="Save as" />
|
|
244
|
+
<mona-split-button-item label="Save a copy" />
|
|
245
|
+
</mona-split-button>
|
|
246
|
+
</mona-button-group>
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
## Appearance & Styling
|
|
250
|
+
|
|
251
|
+
### Look variants
|
|
252
|
+
|
|
253
|
+
`look` defaults to `"outline"`. Most values affect child button fill and border. The container also changes with it:
|
|
254
|
+
|
|
255
|
+
| `look` | Container effect |
|
|
256
|
+
|----------------------|------------------------------------------------------|
|
|
257
|
+
| `default`, `outline` | An outer border, and dividers between adjacent buttons |
|
|
258
|
+
| `ghost` | No outer border, and no dividers |
|
|
259
|
+
| others | No outer border, and dividers between adjacent buttons |
|
|
260
|
+
|
|
261
|
+
### Sizes
|
|
262
|
+
|
|
263
|
+
| `size` | Applied to |
|
|
264
|
+
|----------|-----------------------------|
|
|
265
|
+
| `small` | All child buttons |
|
|
266
|
+
| `medium` | All child buttons (default) |
|
|
267
|
+
| `large` | All child buttons |
|
|
268
|
+
|
|
269
|
+
### Rounded presets
|
|
270
|
+
|
|
271
|
+
`rounded` controls the outer container radius and the outer corners of the first and last child button.
|
|
272
|
+
|
|
273
|
+
| `rounded` | Shape |
|
|
274
|
+
|-----------|-----------------------------|
|
|
275
|
+
| `none` | No rounding |
|
|
276
|
+
| `small` | Slight rounding |
|
|
277
|
+
| `medium` | Moderate rounding (default) |
|
|
278
|
+
| `large` | Strong rounding |
|
|
279
|
+
| `full` | Pill shape |
|
|
280
|
+
|
|
281
|
+
### Custom classes and naming
|
|
282
|
+
|
|
283
|
+
Override container styles with the `class` input. When multiple groups appear on the same page, provide a unique `aria-label` on each so screen reader users can distinguish them:
|
|
284
|
+
|
|
285
|
+
```html
|
|
286
|
+
<mona-button-group aria-label="Text formatting" class="shadow-md">
|
|
287
|
+
<button monaButton>Bold</button>
|
|
288
|
+
<button monaButton>Italic</button>
|
|
289
|
+
</mona-button-group>
|
|
290
|
+
|
|
291
|
+
<mona-button-group aria-label="Text alignment">
|
|
292
|
+
<button monaButton>Left</button>
|
|
293
|
+
<button monaButton>Center</button>
|
|
294
|
+
<button monaButton>Right</button>
|
|
295
|
+
</mona-button-group>
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
## Behavior
|
|
299
|
+
|
|
300
|
+
- **Content projection:** accepts `monaButton` buttons, `mona-dropdown-button` and `mona-split-button` (`<ng-content select="[monaButton], mona-dropdown-button, mona-split-button">`). The buttons inside dropdown and split buttons take the group's look, size, rounding and disabled state, but they aren't toggles and take no part in its selection.
|
|
301
|
+
- The `value` input on `button[monaButton]` is what the group's `value` holds while that button is selected.
|
|
302
|
+
|
|
303
|
+
## Accessibility
|
|
304
|
+
|
|
305
|
+
The group host receives `role="group"` and an `aria-label` that defaults to `"Button group"`. A `mona-label` or `aria-labelledby` names it instead.
|
|
306
|
+
|
|
307
|
+
The buttons are toggle buttons in both selection modes: `aria-pressed`, each in the tab order. `"single"` isn't a radio group, so nothing tells a screen reader that the choices are exclusive. For one that must always hold a value, use `mona-segmented`.
|
|
308
|
+
|
|
309
|
+
A read-only group's toggle buttons stay focusable and report `aria-disabled`. `required` isn't offered, because `aria-required` isn't allowed on `role="group"`; say so in the label and let the form's validator enforce it.
|
|
310
|
+
|
|
311
|
+
| Attribute | When present | Value |
|
|
312
|
+
|--------------|--------------|---------------------------------|
|
|
313
|
+
| `role` | Always | `"group"` |
|
|
314
|
+
| `aria-label` | Unless a label or `aria-labelledby` names it | Value of the `aria-label` input, or the default |
|
|
315
|
+
| `aria-invalid` | While `touched` and `invalid` | `"true"` |
|
|
316
|
+
|
|
317
|
+
Each child button's `aria-pressed` attribute is managed by `ButtonDirective` and reflects the button's current `selected` state.
|
|
318
|
+
|
|
319
|
+
**Consumer responsibilities:**
|
|
320
|
+
|
|
321
|
+
- When multiple button groups appear on the same page, set a unique `aria-label` on each group so screen reader users can distinguish them.
|
|
322
|
+
- Individual icon-only child buttons still require their own `aria-label` on the `<button>` element.
|
|
323
|
+
|
|
324
|
+
## API
|
|
325
|
+
|
|
326
|
+
Everything below is imported from `@nanahoshi/mona-ui/button-group`.
|
|
327
|
+
|
|
328
|
+
### `ButtonGroupComponent`
|
|
329
|
+
|
|
330
|
+
**Selector:** `mona-button-group`
|
|
331
|
+
**Type parameters:** `T = unknown`
|
|
332
|
+
**Implements:** `FormValueControl<T \| readonly T[] \| null \| undefined>`
|
|
333
|
+
|
|
334
|
+
#### Inputs
|
|
335
|
+
|
|
336
|
+
| Name | Type | Default | Description |
|
|
337
|
+
| --- | --- | --- | --- |
|
|
338
|
+
| `allowEmpty` | `boolean` | `true` | When `false` and `selection` is `"single"`, a selected button stays selected until another one takes over: the active button can't be deselected, and clearing every `selected` brings it back. It doesn't choose a first button, and a `value` of `null` still clears the group, so a form can reset it. Has no effect in `"multiple"` mode. |
|
|
339
|
+
| `aria-label` | `string \| undefined` | `undefined` | Accessible name for the host element. Override when multiple button groups appear on the same page so screen reader users can distinguish them. |
|
|
340
|
+
| `aria-labelledby` | `string` | `""` | Id of the element that names the group. |
|
|
341
|
+
| `class` | `string` | `""` | Additional CSS classes merged onto the host element via `tailwind-merge`. |
|
|
342
|
+
| `disabled` | `boolean` | `false` | Renders all child buttons with reduced visual emphasis and removes pointer interaction. When bound to a signal form field via `[formField]`, this is written by the `FormField` directive. |
|
|
343
|
+
| `invalid` | `boolean` | `false` | Marks the group as invalid. Error styling requires both `invalid` and `touched` to be `true`. When bound to a signal form field via `[formField]`, this is written by the `FormField` directive. |
|
|
344
|
+
| `look` | `"default" \| "error" \| "ghost" \| "info" \| "outline" \| "primary" \| "secondary" \| "success" \| "warning"` | `"outline"` | Visual style variant propagated to all child buttons. Also controls container-level divider and border behavior. |
|
|
345
|
+
| `readonly` | `boolean` | `false` | Prevents selection changes while the buttons stay focusable. Buttons that aren't toggleable keep working. When bound to a signal form field via `[formField]`, this is written by the `FormField` directive. |
|
|
346
|
+
| `rounded` | `"full" \| "large" \| "medium" \| "none" \| "small"` | `"medium"` | Border-radius preset applied to the container and the outer corners of the first and last child button. |
|
|
347
|
+
| `selection` | `SelectionMode` | `"multiple"` | Whether one button can be selected at a time (`"single"`) or each toggles on its own (`"multiple"`). The buttons stay toggle buttons with `aria-pressed` in both. For a choice that must always hold one value, use `mona-segmented`, which is a radio group. |
|
|
348
|
+
| `size` | `"large" \| "medium" \| "small"` | `"medium"` | Size preset propagated to all child buttons, overriding their individual `size` inputs. |
|
|
349
|
+
| `touched` | `boolean` | `false` | Marks the group as touched. When bound to a signal form field via `[formField]`, this is written by the `FormField` directive. |
|
|
350
|
+
| `value` (two-way) | `T \| readonly T[] \| null \| undefined` | `undefined` | The value of the selected button in `"single"` mode, or `null`, and an array of the selected buttons' values in `"multiple"` mode. Buttons take part by having a `value`. While `undefined`, it leaves each button's `selected` alone. A value with no button yet stays, so one that loads before its button isn't lost. Use either this or `[(selected)]` on the buttons, not both. |
|
|
351
|
+
|
|
352
|
+
#### Outputs
|
|
353
|
+
|
|
354
|
+
| Name | Type | Description |
|
|
355
|
+
| --- | --- | --- |
|
|
356
|
+
| `buttonClick` | `ButtonGroupClickEvent<T>` | Emitted when a button placed directly in the group is clicked, toggleable or not, after the group has applied its selection. Not emitted for a dropdown or split button's own buttons, for a disabled button, or for a toggle button while the group is read-only, since nothing was selected. |
|
|
357
|
+
| `touch` | `void` | Emitted when a user changes the selection or focus leaves the group. The `FormField` directive listens to this to mark the field as touched. |
|
|
358
|
+
| `valueChange` | `T \| readonly T[] \| null \| undefined` | Emitted when `value` changes. |
|
|
359
|
+
|
|
360
|
+
#### Methods
|
|
361
|
+
|
|
362
|
+
| Signature | Description |
|
|
363
|
+
| --- | --- |
|
|
364
|
+
| `focus(options?: FocusOptions): void` | Moves focus to the selected button, or the first enabled one. |
|
|
365
|
+
|
|
366
|
+
### Types
|
|
367
|
+
|
|
368
|
+
#### `BUTTON_GROUP_DEFAULT_MESSAGES`
|
|
369
|
+
|
|
370
|
+
```typescript
|
|
371
|
+
const BUTTON_GROUP_DEFAULT_MESSAGES: { buttonGroup: string; };
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
#### `ButtonGroupClickEvent`
|
|
375
|
+
|
|
376
|
+
What `mona-button-group` reports about a clicked button.
|
|
377
|
+
|
|
378
|
+
**Type parameters:** `T = unknown`
|
|
379
|
+
|
|
380
|
+
| Name | Type | Description |
|
|
381
|
+
| --- | --- | --- |
|
|
382
|
+
| `button` (read-only) | `HTMLButtonElement` | The button's element. |
|
|
383
|
+
| `selected` (read-only) | `boolean` | Whether the button is selected now that the group has applied its selection. |
|
|
384
|
+
| `value` (read-only) | `T \| undefined` | The button's `value`, if it has one. |
|
|
385
|
+
|
|
386
|
+
#### `SelectionMode`
|
|
387
|
+
|
|
388
|
+
From `@nanahoshi/mona-ui/common`.
|
|
389
|
+
|
|
390
|
+
```typescript
|
|
391
|
+
type SelectionMode = "single" | "multiple";
|
|
392
|
+
```
|
package/docs/button.md
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
# Button
|
|
2
|
+
|
|
3
|
+
> Styles a native button and adds loading, toggle and disabled behavior.
|
|
4
|
+
|
|
5
|
+
Entry point: `@nanahoshi/mona-ui/button`
|
|
6
|
+
|
|
7
|
+
**Selector:** `button[monaButton]`
|
|
8
|
+
|
|
9
|
+
`ButtonDirective` applies Mona UI button styles and interactive behavior — loading state, toggle selection, disabled propagation, and ARIA attribute management — to a native `<button>` element.
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
`ButtonDirective` is a styling directive applied to a native `<button>` element via the `monaButton` attribute selector. It manages look, size, and border-radius variants, and handles interactive states including loading, disabled, and toggle selection.
|
|
14
|
+
|
|
15
|
+
The directive is restricted to `<button>` host elements. This preserves native keyboard activation (Enter, Space), form submission semantics, and assistive technology support without requiring additional ARIA roles.
|
|
16
|
+
|
|
17
|
+
When used inside a `ButtonGroup`, the group's look, size, and rounded values take precedence over the individual button's inputs.
|
|
18
|
+
|
|
19
|
+
**Use `monaButton` when you need to:**
|
|
20
|
+
|
|
21
|
+
- Trigger actions inside forms, toolbars, dialogs, or inline content
|
|
22
|
+
- Build a toggle control (on/off, active/inactive) that does not navigate to a URL
|
|
23
|
+
- Show a spinner while an async operation is in progress
|
|
24
|
+
- Place an icon-only button in a compact area such as a toolbar or list row action
|
|
25
|
+
|
|
26
|
+
**Do not use `monaButton` when:**
|
|
27
|
+
|
|
28
|
+
- The target navigates to a URL — use `<a>` instead; the directive does not support `<a>` hosts
|
|
29
|
+
- Multiple related buttons need shared look, size, or coordinated selection — use `ButtonGroup`
|
|
30
|
+
- A button opens a dropdown menu — use `DropdownButton` or `SplitButton`
|
|
31
|
+
|
|
32
|
+
## Import & Quick Start
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { ButtonDirective } from "@nanahoshi/mona-ui/button";
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Add `ButtonDirective` to your standalone component's `imports` array.
|
|
39
|
+
|
|
40
|
+
```html
|
|
41
|
+
<button monaButton>Default</button>
|
|
42
|
+
|
|
43
|
+
<button monaButton look="primary">Primary</button>
|
|
44
|
+
|
|
45
|
+
<button monaButton look="primary" [(loading)]="isSaving" (click)="save()">
|
|
46
|
+
Save changes
|
|
47
|
+
</button>
|
|
48
|
+
|
|
49
|
+
<button monaButton [toggleable]="true" [(selected)]="isBold">Bold</button>
|
|
50
|
+
|
|
51
|
+
<button monaButton [iconOnly]="true" look="ghost" aria-label="Search">
|
|
52
|
+
<svg lucideSearch [size]="16"></svg>
|
|
53
|
+
</button>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
> **Boolean inputs** have no `booleanAttribute` transform. Always use `[iconOnly]="true"` bracket binding syntax, not the bare attribute form.
|
|
57
|
+
|
|
58
|
+
## Examples
|
|
59
|
+
|
|
60
|
+
### Looks
|
|
61
|
+
|
|
62
|
+
`looks-example.component.ts`
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
import { Component } from "@angular/core";
|
|
66
|
+
import { ButtonDirective } from "@nanahoshi/mona-ui/button";
|
|
67
|
+
|
|
68
|
+
@Component({
|
|
69
|
+
selector: "app-button-looks-example",
|
|
70
|
+
imports: [ButtonDirective],
|
|
71
|
+
templateUrl: "./looks-example.component.html"
|
|
72
|
+
})
|
|
73
|
+
export class ButtonLooksExampleComponent {}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`looks-example.component.html`
|
|
77
|
+
|
|
78
|
+
```html
|
|
79
|
+
<div class="flex flex-wrap items-center gap-2">
|
|
80
|
+
<button monaButton type="button">Default</button>
|
|
81
|
+
<button monaButton look="primary" type="button">Primary</button>
|
|
82
|
+
<button monaButton look="secondary" type="button">Secondary</button>
|
|
83
|
+
<button monaButton look="outline" type="button">Outline</button>
|
|
84
|
+
<button monaButton look="ghost" type="button">Ghost</button>
|
|
85
|
+
<button monaButton look="link" type="button">Link</button>
|
|
86
|
+
<button monaButton look="error" type="button">Delete</button>
|
|
87
|
+
</div>
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### With icons
|
|
91
|
+
|
|
92
|
+
An icon-only button has no text to read out, so it needs an `aria-label`.
|
|
93
|
+
|
|
94
|
+
`icons-example.component.ts`
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
import { Component } from "@angular/core";
|
|
98
|
+
import { LucideDownload, LucideSettings } from "@lucide/angular";
|
|
99
|
+
import { ButtonDirective } from "@nanahoshi/mona-ui/button";
|
|
100
|
+
|
|
101
|
+
@Component({
|
|
102
|
+
selector: "app-button-icons-example",
|
|
103
|
+
imports: [ButtonDirective, LucideDownload, LucideSettings],
|
|
104
|
+
templateUrl: "./icons-example.component.html"
|
|
105
|
+
})
|
|
106
|
+
export class ButtonIconsExampleComponent {}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
`icons-example.component.html`
|
|
110
|
+
|
|
111
|
+
```html
|
|
112
|
+
<div class="flex flex-wrap items-center gap-2">
|
|
113
|
+
<button monaButton look="primary" type="button">
|
|
114
|
+
<svg lucideDownload aria-hidden="true" [size]="16"></svg>
|
|
115
|
+
Download
|
|
116
|
+
</button>
|
|
117
|
+
<button monaButton aria-label="Settings" type="button" [iconOnly]="true">
|
|
118
|
+
<svg lucideSettings aria-hidden="true" [size]="16"></svg>
|
|
119
|
+
</button>
|
|
120
|
+
</div>
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Appearance & Styling
|
|
124
|
+
|
|
125
|
+
### Look variants
|
|
126
|
+
|
|
127
|
+
| `look` | Appearance |
|
|
128
|
+
|------------------------------------------|-----------------------------------------------------------|
|
|
129
|
+
| `default` | Background with border; adapts to the active theme |
|
|
130
|
+
| `primary` | Filled primary color |
|
|
131
|
+
| `secondary` | Filled secondary color |
|
|
132
|
+
| `success` / `error` / `warning` / `info` | Semantic fill colors |
|
|
133
|
+
| `outline` | Transparent background with border |
|
|
134
|
+
| `ghost` | No border or shadow; hover reveals a subtle background |
|
|
135
|
+
| `link` | No border; hover adds underline |
|
|
136
|
+
| `clear` | Fully transparent; no border, shadow, or hover background |
|
|
137
|
+
|
|
138
|
+
### Sizes
|
|
139
|
+
|
|
140
|
+
| `size` | Description |
|
|
141
|
+
|----------|---------------------------------------|
|
|
142
|
+
| `small` | Compact height and padding |
|
|
143
|
+
| `medium` | Standard height and padding (default) |
|
|
144
|
+
| `large` | Taller height and wider padding |
|
|
145
|
+
|
|
146
|
+
When `iconOnly` is `true`, horizontal padding is removed and the button width is fixed to match its height.
|
|
147
|
+
|
|
148
|
+
### Rounded presets
|
|
149
|
+
|
|
150
|
+
| `rounded` | Shape |
|
|
151
|
+
|-----------|-----------------------------|
|
|
152
|
+
| `none` | No border radius |
|
|
153
|
+
| `small` | Slight rounding |
|
|
154
|
+
| `medium` | Moderate rounding (default) |
|
|
155
|
+
| `large` | Strong rounding |
|
|
156
|
+
| `full` | Pill / fully rounded |
|
|
157
|
+
|
|
158
|
+
### Theme tokens
|
|
159
|
+
|
|
160
|
+
Button colors are derived from Mona UI theme design tokens. Override them at `:root` or a scoped ancestor to customize button colors globally.
|
|
161
|
+
|
|
162
|
+
## Accessibility
|
|
163
|
+
|
|
164
|
+
The directive sets `type="button"` on the host, preventing accidental form submission when placed inside a `<form>`.
|
|
165
|
+
|
|
166
|
+
The following attributes are managed automatically:
|
|
167
|
+
|
|
168
|
+
| Attribute | When present | Value |
|
|
169
|
+
|-----------------|------------------------------------------------------------|--------------------------------|
|
|
170
|
+
| `aria-busy` | `loading` is `true` | `"true"` |
|
|
171
|
+
| `aria-disabled` | `disabled` or `loading` is `true` | `"true"` |
|
|
172
|
+
| `aria-haspopup` | `aria-haspopup` input is set to any value except `'false'` | The input value |
|
|
173
|
+
| `aria-pressed` | Button is toggleable (via `toggleable` or `ButtonGroup`) | `"true"` or `"false"` |
|
|
174
|
+
| `disabled` | `disabled` or `loading` is `true` | (empty string — presence-only) |
|
|
175
|
+
| `tabindex` | `disabled` or `loading` is `true` | `"-1"` |
|
|
176
|
+
| `type` | Always | `"button"` |
|
|
177
|
+
|
|
178
|
+
**Consumer responsibilities:**
|
|
179
|
+
|
|
180
|
+
- For icon-only buttons, provide `aria-label` on the `<button>` element so assistive technology announces a meaningful name.
|
|
181
|
+
- When a button opens a popup (menu, dialog, listbox, etc.), set the `aria-haspopup` input to the appropriate token (`"menu"`, `"dialog"`, etc.).
|
|
182
|
+
|
|
183
|
+
## API
|
|
184
|
+
|
|
185
|
+
Everything below is imported from `@nanahoshi/mona-ui/button`.
|
|
186
|
+
|
|
187
|
+
### `ButtonDirective`
|
|
188
|
+
|
|
189
|
+
**Selector:** `button[monaButton]`
|
|
190
|
+
|
|
191
|
+
#### Inputs
|
|
192
|
+
|
|
193
|
+
| Name | Type | Default | Description |
|
|
194
|
+
| --- | --- | --- | --- |
|
|
195
|
+
| `aria-haspopup` | `ButtonAriaHasPopup` | `"false"` | Value forwarded to the `aria-haspopup` attribute. Set when this button triggers a popup, menu, listbox, tree, grid, or dialog. Omit or leave as `"false"` for plain action buttons. |
|
|
196
|
+
| `class` | `string` | `""` | Additional CSS classes merged onto the host element via `tailwind-merge`. |
|
|
197
|
+
| `disabled` | `boolean` | `false` | Renders the component with reduced visual emphasis and removes pointer interaction. Accepts the bare attribute form (`<button monaButton disabled>`). When inside a `ButtonGroup`, the button is disabled when either it or the group is disabled. |
|
|
198
|
+
| `iconOnly` | `boolean` | `false` | Removes horizontal padding and fixes a square aspect ratio sized to match `size`. Provide `aria-label` on the host when using icon-only buttons; in dev mode, an icon-only button without an accessible name logs a warning. |
|
|
199
|
+
| `loading` | `boolean` | `false` | Displays a loading indicator and prevents interaction while an operation is in progress. Sets `aria-busy="true"` and `aria-disabled="true"` on the host. The button stays focusable, so keyboard focus isn't lost when loading starts, and clicks (including form submission) are blocked until it ends. |
|
|
200
|
+
| `look` (two-way) | `"clear" \| "default" \| "error" \| "ghost" \| "info" \| "link" \| "outline" \| "primary" \| "secondary" \| "success" \| "warning"` | `"default"` | Visual style variant of the button. When inside a `ButtonGroup`, the group's look takes precedence. `"outline"` looks the same as `"default"`. `"clear"` shows no selected state, so use another look for toggle buttons. |
|
|
201
|
+
| `rounded` | `"full" \| "large" \| "medium" \| "none" \| "small"` | `"medium"` | Border-radius preset applied to the component. When inside a `ButtonGroup`, the group's value takes precedence. |
|
|
202
|
+
| `selected` (two-way) | `boolean` | `false` | Whether the button is in the selected/pressed state. Drives `aria-pressed` when the button is toggleable. Managed by `toggleable` click handling or by `ButtonGroup` selection policy. |
|
|
203
|
+
| `size` | `"large" \| "medium" \| "small"` | `"medium"` | Size preset controlling the button's height and horizontal padding. When inside a `ButtonGroup`, the group's value takes precedence. |
|
|
204
|
+
| `tabindex` | `string \| number` | `0` | Tab index of the host element. Automatically overridden to `-1` when the button is disabled. Accepts a numeric string and converts it to a number; a value that is not a number falls back to `0`. |
|
|
205
|
+
| `toggleable` | `boolean \| undefined` | `undefined` | Enables toggle behavior — each click flips the `selected` state and `aria-pressed` is managed. Accepts the bare attribute form. Buttons in a `ButtonGroup` are toggleable unless this is set to `false`. |
|
|
206
|
+
| `type` | `"button" \| "reset" \| "submit"` | `"button"` | Native `type` attribute of the button. Defaults to `"button"` to prevent accidental form submission; set to `"submit"` or `"reset"` explicitly when that behavior is intended. |
|
|
207
|
+
| `value` | `unknown` | `undefined` | What a `ButtonGroup`'s `value` holds while this button is selected. A button without one takes no part in the group's `value`. |
|
|
208
|
+
|
|
209
|
+
#### Outputs
|
|
210
|
+
|
|
211
|
+
| Name | Type | Description |
|
|
212
|
+
| --- | --- | --- |
|
|
213
|
+
| `lookChange` | `"clear" \| "default" \| "error" \| "ghost" \| "info" \| "link" \| "outline" \| "primary" \| "secondary" \| "success" \| "warning"` | Emitted when `look` changes. |
|
|
214
|
+
| `selectedChange` | `boolean` | Emitted when `selected` changes. |
|
|
215
|
+
|
|
216
|
+
#### Properties
|
|
217
|
+
|
|
218
|
+
| Name | Type | Description |
|
|
219
|
+
| --- | --- | --- |
|
|
220
|
+
| `effectiveDisabled` (read-only) | `Signal<boolean>` | Whether the button is disabled, by its own input or its group's. A dropdown or split button reads this to close its menu. |
|
|
221
|
+
| `effectiveToggleable` (read-only) | `Signal<boolean>` | Whether a click toggles the button: buttons in a group do unless `toggleable` is `false`. The group reads this to know which buttons take part in its selection. |
|
|
222
|
+
|
|
223
|
+
### Types
|
|
224
|
+
|
|
225
|
+
#### `BUTTON_GROUP_MEMBER`
|
|
226
|
+
|
|
227
|
+
Provided by a component that implements `ButtonGroupMember`, so a `mona-button-group` can find it among its
|
|
228
|
+
content children.
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
const BUTTON_GROUP_MEMBER: InjectionToken<ButtonGroupMember>;
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
#### `ButtonGroupMember`
|
|
235
|
+
|
|
236
|
+
A component whose own buttons join the `mona-button-group` it is placed in, such as a dropdown or split button.
|
|
237
|
+
Those buttons follow the group's look, size, rounding and disabled state, but they aren't toggleable and take no
|
|
238
|
+
part in the group's selection.
|
|
239
|
+
|
|
240
|
+
| Name | Type | Description |
|
|
241
|
+
| --- | --- | --- |
|
|
242
|
+
| `groupButtons` (read-only) | `Signal<readonly ButtonDirective[]>` | The component's buttons that join the group. |
|
|
243
|
+
|
|
244
|
+
#### `ButtonAriaHasPopup`
|
|
245
|
+
|
|
246
|
+
Values accepted by the `aria-haspopup` input of `ButtonDirective`. `"false"` (the default) omits the attribute.
|
|
247
|
+
|
|
248
|
+
```typescript
|
|
249
|
+
type ButtonAriaHasPopup = "dialog" | "false" | "grid" | "listbox" | "menu" | "tree" | "true";
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
#### `ButtonVariantsInput`
|
|
253
|
+
|
|
254
|
+
```typescript
|
|
255
|
+
type ButtonVariantsInput = VariantInputs<ButtonVariantProps>;
|
|
256
|
+
```
|