@cngx/common 0.1.0-rc.9 → 0.3.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/a11y/README.md +15 -2
- package/button/README.md +258 -0
- package/command/README.md +19 -8
- package/data/README.md +10 -10
- package/fesm2022/cngx-common-a11y.mjs +701 -263
- package/fesm2022/cngx-common-a11y.mjs.map +1 -1
- package/fesm2022/cngx-common-audio.mjs +83 -64
- package/fesm2022/cngx-common-audio.mjs.map +1 -1
- package/fesm2022/cngx-common-button.mjs +1084 -0
- package/fesm2022/cngx-common-button.mjs.map +1 -0
- package/fesm2022/cngx-common-card.mjs +135 -76
- package/fesm2022/cngx-common-card.mjs.map +1 -1
- package/fesm2022/cngx-common-chart.mjs +749 -296
- package/fesm2022/cngx-common-chart.mjs.map +1 -1
- package/fesm2022/cngx-common-command.mjs +51 -29
- package/fesm2022/cngx-common-command.mjs.map +1 -1
- package/fesm2022/cngx-common-data.mjs +695 -405
- package/fesm2022/cngx-common-data.mjs.map +1 -1
- package/fesm2022/cngx-common-dialog.mjs +112 -112
- package/fesm2022/cngx-common-dialog.mjs.map +1 -1
- package/fesm2022/cngx-common-display.mjs +668 -308
- package/fesm2022/cngx-common-display.mjs.map +1 -1
- package/fesm2022/cngx-common-interactive.mjs +7066 -2739
- package/fesm2022/cngx-common-interactive.mjs.map +1 -1
- package/fesm2022/cngx-common-layout.mjs +2121 -492
- package/fesm2022/cngx-common-layout.mjs.map +1 -1
- package/fesm2022/cngx-common-menu-button.mjs +557 -0
- package/fesm2022/cngx-common-menu-button.mjs.map +1 -0
- package/fesm2022/cngx-common-popover.mjs +1207 -569
- package/fesm2022/cngx-common-popover.mjs.map +1 -1
- package/fesm2022/cngx-common-stepper.mjs +256 -261
- package/fesm2022/cngx-common-stepper.mjs.map +1 -1
- package/fesm2022/cngx-common-tabs.mjs +202 -262
- package/fesm2022/cngx-common-tabs.mjs.map +1 -1
- package/fesm2022/cngx-common-timeline.mjs +28 -61
- package/fesm2022/cngx-common-timeline.mjs.map +1 -1
- package/fesm2022/cngx-common.mjs +10 -10
- package/fesm2022/cngx-common.mjs.map +1 -1
- package/interactive/README.md +30 -19
- package/layout/README.md +1 -1
- package/menu-button/README.md +234 -0
- package/package.json +14 -4
- package/popover/README.md +42 -5
- package/popover/tooltip-indicator.scss +52 -0
- package/schematics/ng-add/index.js +7 -7
- package/schematics/ng-add/schema.json +5 -0
- package/stepper/README.md +0 -1
- package/theming/components/cngx-accordion.css +36 -7
- package/theming/components/cngx-async.css +185 -37
- package/theming/components/cngx-backdrop.css +3 -1
- package/theming/components/cngx-badge.css +20 -5
- package/theming/components/cngx-bottom-sheet.css +2 -0
- package/theming/components/cngx-breadcrumb.css +3 -1
- package/theming/components/cngx-button-group.css +325 -0
- package/theming/components/cngx-button-toggle.css +55 -23
- package/theming/components/cngx-button.css +975 -0
- package/theming/components/cngx-data-grid.css +2 -0
- package/theming/components/cngx-dialog.css +3 -1
- package/theming/components/cngx-divider.css +24 -9
- package/theming/components/cngx-drawer.css +153 -0
- package/theming/components/cngx-icon-glyph.css +76 -0
- package/theming/components/cngx-listbox.css +79 -25
- package/theming/components/cngx-menu.css +112 -52
- package/theming/components/cngx-nav.css +1220 -0
- package/theming/components/cngx-popover-sheet.css +43 -11
- package/theming/components/cngx-popover.css +37 -13
- package/theming/components/cngx-recycler-placeholder.css +2 -0
- package/theming/components/cngx-ripple.css +74 -16
- package/theming/components/cngx-sidebar.css +71 -0
- package/theming/components/cngx-slider.css +3 -1
- package/theming/components/cngx-tooltip.css +2 -0
- package/timeline/README.md +2 -2
- package/types/cngx-common-a11y.d.ts +343 -120
- package/types/cngx-common-audio.d.ts +60 -88
- package/types/cngx-common-button.d.ts +698 -0
- package/types/cngx-common-card.d.ts +104 -78
- package/types/cngx-common-chart.d.ts +671 -384
- package/types/cngx-common-command.d.ts +44 -47
- package/types/cngx-common-data.d.ts +350 -342
- package/types/cngx-common-dialog.d.ts +91 -120
- package/types/cngx-common-display.d.ts +475 -300
- package/types/cngx-common-interactive.d.ts +4350 -1723
- package/types/cngx-common-layout.d.ts +1365 -286
- package/types/cngx-common-menu-button.d.ts +382 -0
- package/types/cngx-common-popover.d.ts +671 -289
- package/types/cngx-common-stepper.d.ts +217 -347
- package/types/cngx-common-tabs.d.ts +173 -386
- package/types/cngx-common-timeline.d.ts +25 -104
|
@@ -0,0 +1,557 @@
|
|
|
1
|
+
import { NgComponentOutlet } from '@angular/common';
|
|
2
|
+
import * as i0 from '@angular/core';
|
|
3
|
+
import { InjectionToken, inject, computed, contentChild, ViewEncapsulation, ChangeDetectionStrategy, Component, Directive, contentChildren, ElementRef, effect, untracked, afterNextRender } from '@angular/core';
|
|
4
|
+
import * as i1 from '@cngx/common/button';
|
|
5
|
+
import { CngxButtonBrain, CngxButtonStart, CngxButtonEnd, CngxButtonAdornment, provideButtonHost, CNGX_BUTTON_STATE, CNGX_BUTTON_HOST_STATE, CngxButtonGroup } from '@cngx/common/button';
|
|
6
|
+
import { CngxIcon, CngxIconSvg } from '@cngx/common/display';
|
|
7
|
+
import * as i2 from '@cngx/common/interactive';
|
|
8
|
+
import { CngxMenuTrigger } from '@cngx/common/interactive';
|
|
9
|
+
import * as i3 from '@cngx/common/popover';
|
|
10
|
+
import { CngxPopoverTrigger } from '@cngx/common/popover';
|
|
11
|
+
import { CNGX_ICON_CHEVRON_DOWN, cngxDevWarn } from '@cngx/utils';
|
|
12
|
+
import { injectLazySelf, createOverrideMerge, nextUid, injectDescribedByContribution } from '@cngx/core/utils';
|
|
13
|
+
import { createLanguageSection } from '@cngx/core/i18n';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The caret glyph component of every `cngxMenuButton` without a projected `cngxButtonEnd`, and of
|
|
17
|
+
* every split caret. Without it the caret is `CNGX_ICON_CHEVRON_DOWN`. It renders inside an
|
|
18
|
+
* `aria-hidden` `<cngx-icon>`, so it draws a glyph and nothing else.
|
|
19
|
+
*
|
|
20
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/menu-button/caret-icon.token.ts
|
|
21
|
+
* @since 0.3.0
|
|
22
|
+
* @relatedTo provideButtonCaretIcon, injectButtonCaretIcon, CngxMenuButton, CngxIconMenuButton
|
|
23
|
+
* <example-url>/#/common/menu-button/menu-button/custom-caret</example-url>
|
|
24
|
+
*/
|
|
25
|
+
const CNGX_BUTTON_CARET_ICON = new InjectionToken('CngxButtonCaretIcon');
|
|
26
|
+
/**
|
|
27
|
+
* Provides the caret below the provider, in `providers` or `viewProviders`. The nearest provider
|
|
28
|
+
* wins.
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* bootstrapApplication(App, { providers: [provideButtonCaretIcon(MaterialCaret)] });
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @param component The glyph component; it renders inside the `aria-hidden` caret `<cngx-icon>`.
|
|
35
|
+
*
|
|
36
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/menu-button/caret-icon.token.ts
|
|
37
|
+
* @since 0.3.0
|
|
38
|
+
* @relatedTo CNGX_BUTTON_CARET_ICON, injectButtonCaretIcon
|
|
39
|
+
* <example-url>/#/common/menu-button/menu-button/custom-caret</example-url>
|
|
40
|
+
*/
|
|
41
|
+
function provideButtonCaretIcon(component) {
|
|
42
|
+
return { provide: CNGX_BUTTON_CARET_ICON, useValue: component };
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The caret set with `provideButtonCaretIcon`, or `null` for the default chevron.
|
|
46
|
+
*
|
|
47
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/menu-button/caret-icon.token.ts
|
|
48
|
+
* @since 0.3.0
|
|
49
|
+
* @relatedTo CNGX_BUTTON_CARET_ICON, provideButtonCaretIcon
|
|
50
|
+
*/
|
|
51
|
+
function injectButtonCaretIcon() {
|
|
52
|
+
return inject(CNGX_BUTTON_CARET_ICON, { optional: true });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Open/toggle glue shared by `cngxMenuButton` and `cngxIconMenuButton`.
|
|
57
|
+
* Both triggers are host directives on the same element, read lazily.
|
|
58
|
+
*
|
|
59
|
+
* @internal
|
|
60
|
+
*/
|
|
61
|
+
function injectMenuToggle(blocked) {
|
|
62
|
+
const menuTrigger = injectLazySelf(CngxMenuTrigger);
|
|
63
|
+
const popoverTrigger = injectLazySelf(CngxPopoverTrigger);
|
|
64
|
+
const expanded = computed(() => menuTrigger().isOpen(), ...(ngDevMode ? [{ debugName: "expanded" }] : /* istanbul ignore next */ []));
|
|
65
|
+
return {
|
|
66
|
+
expanded,
|
|
67
|
+
handleClick: () => {
|
|
68
|
+
// Unreachable behind the brain's capture guard; kept as the host
|
|
69
|
+
// contract, so a custom host never relies on listener order.
|
|
70
|
+
if (blocked()) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
popoverTrigger().popoverRef().toggle();
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* A button that opens a menu, after the WAI-ARIA APG Menu Button Pattern. Variant, tone, size,
|
|
80
|
+
* `disabled` with a reason and the busy layer come from `CngxButtonBrain`, as on `cngxButton`.
|
|
81
|
+
*
|
|
82
|
+
* `[menu]` takes the `cngxMenu`, `[popover]` the `cngxPopover` around it. `aria-haspopup` and
|
|
83
|
+
* `aria-controls` follow without a binding. ArrowDown, Enter or Space opens on the first item,
|
|
84
|
+
* ArrowUp on the last; Escape or an activation closes and returns focus to the button.
|
|
85
|
+
*
|
|
86
|
+
* The button has no action of its own: put async work on the menu items, not on a co-hosted
|
|
87
|
+
* `cngxAsyncClick`. A disabled menu button does not open, and an open menu closes when it becomes
|
|
88
|
+
* disabled.
|
|
89
|
+
*
|
|
90
|
+
* The end renders a decorative chevron caret. `provideButtonCaretIcon` swaps it, a projected
|
|
91
|
+
* `cngxButtonEnd` replaces it on one button.
|
|
92
|
+
*
|
|
93
|
+
* ```html
|
|
94
|
+
* <button cngxMenuButton="outline" [menu]="menu" [popover]="pop">Export</button>
|
|
95
|
+
* <div cngxPopover placement="bottom-start" #pop="cngxPopover">
|
|
96
|
+
* <ul cngxMenu label="Export format" #menu="cngxMenu">
|
|
97
|
+
* <li cngxMenuItem value="pdf">PDF</li>
|
|
98
|
+
* <li cngxMenuItem value="csv">CSV</li>
|
|
99
|
+
* </ul>
|
|
100
|
+
* </div>
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* @wcag AA
|
|
104
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/menu-button/menu-button.component.ts
|
|
105
|
+
* @since 0.3.0
|
|
106
|
+
* @relatedTo CngxButton, CngxButtonBrain, CngxMenuTrigger, CngxPopoverTrigger, CngxMenu, provideButtonCaretIcon, CngxIconMenuButton, CNGX_BUTTON_CARET_ICON
|
|
107
|
+
* <example-url>/#/common/menu-button/menu-button/basic</example-url>
|
|
108
|
+
* <example-url>/#/common/menu-button/menu-button/disabled-with-reason</example-url>
|
|
109
|
+
* <example-url>/#/common/menu-button/menu-button/custom-caret</example-url>
|
|
110
|
+
* @axis level molecule
|
|
111
|
+
*/
|
|
112
|
+
class CngxMenuButton {
|
|
113
|
+
/** @internal */
|
|
114
|
+
brain = inject(CngxButtonBrain);
|
|
115
|
+
/**
|
|
116
|
+
* @internal - neither opens nor closes on click while the button is
|
|
117
|
+
* blocked. The brain's capture guard swallows every click while blocked,
|
|
118
|
+
* consumer `(click)` handlers included.
|
|
119
|
+
*/
|
|
120
|
+
toggle = injectMenuToggle(this.brain.blocked);
|
|
121
|
+
/** `true` while the menu is open. */
|
|
122
|
+
expanded = this.toggle.expanded;
|
|
123
|
+
startSlot = contentChild(CngxButtonStart, ...(ngDevMode ? [{ debugName: "startSlot" }] : /* istanbul ignore next */ []));
|
|
124
|
+
endSlot = contentChild(CngxButtonEnd, ...(ngDevMode ? [{ debugName: "endSlot" }] : /* istanbul ignore next */ []));
|
|
125
|
+
/** @internal - app-wide glyph from `CNGX_BUTTON_CARET_ICON`. */
|
|
126
|
+
customCaret = injectButtonCaretIcon();
|
|
127
|
+
/** @internal - default chevron from the shared icon set. */
|
|
128
|
+
caretIcon = CNGX_ICON_CHEVRON_DOWN;
|
|
129
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxMenuButton, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
130
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.4", type: CngxMenuButton, isStandalone: true, selector: "button[cngxMenuButton]", host: { attributes: { "data-end": "" }, listeners: { "click": "toggle.handleClick()" }, properties: { "attr.data-start": "startSlot() ? \"\" : null", "attr.data-expanded": "expanded() ? \"true\" : \"false\"" }, classAttribute: "cngx-button cngx-menu-button" }, providers: [provideButtonHost('cngxMenuButton', { defaultVariant: 'solid' })], queries: [{ propertyName: "startSlot", first: true, predicate: CngxButtonStart, descendants: true, isSignal: true }, { propertyName: "endSlot", first: true, predicate: CngxButtonEnd, descendants: true, isSignal: true }], exportAs: ["cngxMenuButton"], hostDirectives: [{ directive: i1.CngxButtonBrain, inputs: ["variant", "cngxMenuButton", "tone", "tone", "size", "size", "disabled", "disabled", "disabledReason", "disabledReason", "cngxDescribedBy", "cngxDescribedBy", "type", "type"] }, { directive: i2.CngxMenuTrigger, inputs: ["cngxMenuTrigger", "menu", "popover", "popover"] }, { directive: i3.CngxPopoverTrigger, inputs: ["cngxPopoverTrigger", "popover"] }], ngImport: i0, template: `
|
|
131
|
+
<ng-content select="[cngxButtonStart]" />
|
|
132
|
+
<span class="cngx-button__label"><ng-content /></span>
|
|
133
|
+
<ng-content select="[cngxButtonEnd]" />
|
|
134
|
+
@if (!endSlot()) {
|
|
135
|
+
<cngx-icon class="cngx-button__slot cngx-button__slot--end cngx-menu-button__caret">
|
|
136
|
+
@if (customCaret) {
|
|
137
|
+
<ng-container *ngComponentOutlet="customCaret" />
|
|
138
|
+
} @else {
|
|
139
|
+
<svg [cngxIconSvg]="caretIcon"></svg>
|
|
140
|
+
}
|
|
141
|
+
</cngx-icon>
|
|
142
|
+
}
|
|
143
|
+
<cngx-button-adornment />
|
|
144
|
+
`, isInline: true, styles: ["@layer cngx.components{@scope(.cngx-menu-button,.cngx-icon-menu-button){:scope{--cngx-menu-button-caret-transition: var(--cngx-button-transition, .15s)}}@scope(.cngx-menu-button__caret){:scope.cngx-icon{--cngx-icon-size: var(--cngx-menu-button-caret-size, 1em);transition:rotate var(--cngx-menu-button-caret-transition, .15s) ease}:scope svg{inline-size:1em;block-size:1em}:scope>:not(svg){display:contents}}.cngx-sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}.cngx-menu-button[data-expanded=true]>.cngx-menu-button__caret,.cngx-icon-menu-button[data-expanded=true]>.cngx-icon-button__glyph>.cngx-menu-button__caret{rotate:180deg}}[data-motion=reduced] .cngx-menu-button__caret{transition:none}@media(prefers-reduced-motion:reduce){:root:not([data-motion=full]) .cngx-menu-button__caret{transition:none}}\n"], dependencies: [{ kind: "directive", type: NgComponentOutlet, selector: "[ngComponentOutlet]", inputs: ["ngComponentOutlet", "ngComponentOutletInputs", "ngComponentOutletInjector", "ngComponentOutletEnvironmentInjector", "ngComponentOutletContent", "ngComponentOutletNgModule"], exportAs: ["ngComponentOutlet"] }, { kind: "component", type: CngxIcon, selector: "cngx-icon, [cngxIcon]", inputs: ["label", "size"], exportAs: ["cngxIcon"] }, { kind: "component", type: CngxIconSvg, selector: "svg[cngxIconSvg]", inputs: ["cngxIconSvg"] }, { kind: "component", type: CngxButtonAdornment, selector: "cngx-button-adornment" }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
145
|
+
}
|
|
146
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxMenuButton, decorators: [{
|
|
147
|
+
type: Component,
|
|
148
|
+
args: [{ selector: 'button[cngxMenuButton]', standalone: true, exportAs: 'cngxMenuButton', imports: [NgComponentOutlet, CngxIcon, CngxIconSvg, CngxButtonAdornment], changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, hostDirectives: [
|
|
149
|
+
{
|
|
150
|
+
directive: CngxButtonBrain,
|
|
151
|
+
inputs: [
|
|
152
|
+
'variant: cngxMenuButton',
|
|
153
|
+
'tone',
|
|
154
|
+
'size',
|
|
155
|
+
'disabled',
|
|
156
|
+
'disabledReason',
|
|
157
|
+
'cngxDescribedBy',
|
|
158
|
+
'type',
|
|
159
|
+
],
|
|
160
|
+
},
|
|
161
|
+
{ directive: CngxMenuTrigger, inputs: ['cngxMenuTrigger: menu', 'popover'] },
|
|
162
|
+
{ directive: CngxPopoverTrigger, inputs: ['cngxPopoverTrigger: popover'] },
|
|
163
|
+
], providers: [provideButtonHost('cngxMenuButton', { defaultVariant: 'solid' })], host: {
|
|
164
|
+
class: 'cngx-button cngx-menu-button',
|
|
165
|
+
'[attr.data-start]': 'startSlot() ? "" : null',
|
|
166
|
+
// The end is never empty: a projected cngxButtonEnd or the caret.
|
|
167
|
+
'data-end': '',
|
|
168
|
+
'[attr.data-expanded]': 'expanded() ? "true" : "false"',
|
|
169
|
+
'(click)': 'toggle.handleClick()',
|
|
170
|
+
}, template: `
|
|
171
|
+
<ng-content select="[cngxButtonStart]" />
|
|
172
|
+
<span class="cngx-button__label"><ng-content /></span>
|
|
173
|
+
<ng-content select="[cngxButtonEnd]" />
|
|
174
|
+
@if (!endSlot()) {
|
|
175
|
+
<cngx-icon class="cngx-button__slot cngx-button__slot--end cngx-menu-button__caret">
|
|
176
|
+
@if (customCaret) {
|
|
177
|
+
<ng-container *ngComponentOutlet="customCaret" />
|
|
178
|
+
} @else {
|
|
179
|
+
<svg [cngxIconSvg]="caretIcon"></svg>
|
|
180
|
+
}
|
|
181
|
+
</cngx-icon>
|
|
182
|
+
}
|
|
183
|
+
<cngx-button-adornment />
|
|
184
|
+
`, styles: ["@layer cngx.components{@scope(.cngx-menu-button,.cngx-icon-menu-button){:scope{--cngx-menu-button-caret-transition: var(--cngx-button-transition, .15s)}}@scope(.cngx-menu-button__caret){:scope.cngx-icon{--cngx-icon-size: var(--cngx-menu-button-caret-size, 1em);transition:rotate var(--cngx-menu-button-caret-transition, .15s) ease}:scope svg{inline-size:1em;block-size:1em}:scope>:not(svg){display:contents}}.cngx-sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}.cngx-menu-button[data-expanded=true]>.cngx-menu-button__caret,.cngx-icon-menu-button[data-expanded=true]>.cngx-icon-button__glyph>.cngx-menu-button__caret{rotate:180deg}}[data-motion=reduced] .cngx-menu-button__caret{transition:none}@media(prefers-reduced-motion:reduce){:root:not([data-motion=full]) .cngx-menu-button__caret{transition:none}}\n"] }]
|
|
185
|
+
}], propDecorators: { startSlot: [{ type: i0.ContentChild, args: [i0.forwardRef(() => CngxButtonStart), { isSignal: true }] }], endSlot: [{ type: i0.ContentChild, args: [i0.forwardRef(() => CngxButtonEnd), { isSignal: true }] }] } });
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* The English `menuButton` section, the default of `CNGX_MENU_BUTTON_I18N`.
|
|
189
|
+
*
|
|
190
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/menu-button/i18n/menu-button-language-section.ts
|
|
191
|
+
* @since 0.3.0
|
|
192
|
+
* @relatedTo CNGX_MENU_BUTTON_I18N, CngxMenuButtonLanguageSection
|
|
193
|
+
*/
|
|
194
|
+
const CNGX_MENU_BUTTON_LANGUAGE_EN = {
|
|
195
|
+
splitToggle: 'More options',
|
|
196
|
+
splitMainBusy: 'The main action is running',
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
/** @internal The English section with the active pack's menu-button section on top. */
|
|
200
|
+
const menuButtonBundleFromPack = createLanguageSection('menuButton', CNGX_MENU_BUTTON_LANGUAGE_EN);
|
|
201
|
+
/**
|
|
202
|
+
* The resolved menu-button copy: the `menuButton` section of the active language pack over the
|
|
203
|
+
* English defaults. A `Signal`, so the names follow a runtime language switch.
|
|
204
|
+
*
|
|
205
|
+
* @wcag AA
|
|
206
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/menu-button/i18n/menu-button-i18n.ts
|
|
207
|
+
* @since 0.3.0
|
|
208
|
+
* @relatedTo CngxIconMenuButton, CngxSplitButton, CngxSplitCaret, provideMenuButtonI18n, injectMenuButtonI18n, CNGX_MENU_BUTTON_LANGUAGE_EN, provideCngxI18n
|
|
209
|
+
*/
|
|
210
|
+
const CNGX_MENU_BUTTON_I18N = new InjectionToken('CngxMenuButtonI18n', {
|
|
211
|
+
providedIn: 'root',
|
|
212
|
+
factory: menuButtonBundleFromPack,
|
|
213
|
+
});
|
|
214
|
+
/**
|
|
215
|
+
* Overrides single keys. Unset keys keep the language pack's phrase, or the English default. Pass
|
|
216
|
+
* a `Signal` to switch the language at runtime.
|
|
217
|
+
*
|
|
218
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/menu-button/i18n/menu-button-i18n.ts
|
|
219
|
+
* @since 0.3.0
|
|
220
|
+
* @relatedTo CNGX_MENU_BUTTON_I18N, provideMenuButtonI18n
|
|
221
|
+
*/
|
|
222
|
+
function withMenuButtonI18nLabels(overrides) {
|
|
223
|
+
return (bundle) => createOverrideMerge(bundle, overrides);
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Provides the menu-button copy. The features apply on top of the active language pack, so a
|
|
227
|
+
* subtree overrides single keys of the app's language.
|
|
228
|
+
* A nested provider starts again from the language pack instead of merging onto the outer one,
|
|
229
|
+
* so it repeats every outer override it still needs.
|
|
230
|
+
*
|
|
231
|
+
* ```ts
|
|
232
|
+
* providers: [provideMenuButtonI18n(withMenuButtonI18nLabels({ splitToggle: 'More actions' }))]
|
|
233
|
+
* ```
|
|
234
|
+
*
|
|
235
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/menu-button/i18n/menu-button-i18n.ts
|
|
236
|
+
* @since 0.3.0
|
|
237
|
+
* @relatedTo CNGX_MENU_BUTTON_I18N, withMenuButtonI18nLabels
|
|
238
|
+
*/
|
|
239
|
+
function provideMenuButtonI18n(...features) {
|
|
240
|
+
return {
|
|
241
|
+
provide: CNGX_MENU_BUTTON_I18N,
|
|
242
|
+
useFactory: () => features.reduce((bundle, feat) => feat(bundle), menuButtonBundleFromPack()),
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Reads the resolved copy. `CngxSplitCaret` already exposes it as `label()` and `busyNote()`.
|
|
247
|
+
*
|
|
248
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/menu-button/i18n/menu-button-i18n.ts
|
|
249
|
+
* @since 0.3.0
|
|
250
|
+
* @relatedTo CNGX_MENU_BUTTON_I18N, CngxSplitCaret
|
|
251
|
+
*/
|
|
252
|
+
function injectMenuButtonI18n() {
|
|
253
|
+
return inject(CNGX_MENU_BUTTON_I18N);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Provided by `CngxSplitButton`, injected by `CngxSplitCaret`.
|
|
258
|
+
*
|
|
259
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/menu-button/split-button.token.ts
|
|
260
|
+
* @since 0.3.0
|
|
261
|
+
* @relatedTo CngxSplitButton, CngxSplitCaret, CngxIconMenuButton, CngxSplitButtonContext, CNGX_BUTTON_STATE
|
|
262
|
+
*/
|
|
263
|
+
const CNGX_SPLIT_BUTTON = new InjectionToken('CngxSplitButton');
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Marks a possible caret of a `cngxSplitButton`: provided by
|
|
267
|
+
* `CngxSplitCaret`, queried by the split as a direct child, so the split
|
|
268
|
+
* never names a concrete class.
|
|
269
|
+
*
|
|
270
|
+
* @internal
|
|
271
|
+
*/
|
|
272
|
+
const CNGX_SPLIT_CARET = new InjectionToken('CngxSplitCaret');
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* The caret role of a `cngxSplitButton`, as a host directive on a button host on
|
|
276
|
+
* `CngxButtonBrain`. As a direct child of a split the host becomes the caret, anywhere else it
|
|
277
|
+
* stays an ordinary button. `cngxIconMenuButton` renders on it.
|
|
278
|
+
*
|
|
279
|
+
* While the main action is blocked it refuses activation through `CNGX_BUTTON_HOST_STATE` and
|
|
280
|
+
* adds the cause to `aria-describedby`. The host renders `label()` as visually hidden text (an
|
|
281
|
+
* `aria-label` still wins) and `busyNote()` in a `hidden` span with `[id]="busyNoteId"`. Its click
|
|
282
|
+
* toggle must refuse every click while the brain is `blocked()`.
|
|
283
|
+
*
|
|
284
|
+
* Co-host `CngxPopoverTrigger`: the split reads the caret's popover through it to hang the menu
|
|
285
|
+
* under the group. A host that provides `CNGX_BUTTON_HOST_STATE` itself replaces this entry and
|
|
286
|
+
* folds `refusing()` into its own state.
|
|
287
|
+
*
|
|
288
|
+
* @wcag AA
|
|
289
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/menu-button/split-caret.directive.ts
|
|
290
|
+
* @since 0.3.0
|
|
291
|
+
* @relatedTo CngxSplitButton, CngxIconMenuButton, CngxButtonBrain, CNGX_SPLIT_BUTTON, CNGX_MENU_BUTTON_I18N, CNGX_BUTTON_HOST_STATE, CngxPopoverTrigger
|
|
292
|
+
* <example-url>/#/common/menu-button/split-button/custom-caret-host</example-url>
|
|
293
|
+
* @axis level molecule
|
|
294
|
+
*/
|
|
295
|
+
class CngxSplitCaret {
|
|
296
|
+
state = inject(CNGX_BUTTON_STATE, { self: true });
|
|
297
|
+
split = inject(CNGX_SPLIT_BUTTON, { optional: true });
|
|
298
|
+
i18n = injectMenuButtonI18n();
|
|
299
|
+
/** `true` while the host is the caret of a split (its direct child). */
|
|
300
|
+
isCaret = computed(() => this.split?.caret() === this.state, ...(ngDevMode ? [{ debugName: "isCaret" }] : /* istanbul ignore next */ []));
|
|
301
|
+
/** `true` while the host is the caret and the main action is blocked. */
|
|
302
|
+
refusing = computed(() => this.isCaret() && (this.split?.mainBlocked() ?? false), ...(ngDevMode ? [{ debugName: "refusing" }] : /* istanbul ignore next */ []));
|
|
303
|
+
/** Id the host template puts on its hidden busy note. */
|
|
304
|
+
busyNoteId = nextUid('cngx-split-caret-busy');
|
|
305
|
+
/** The caret's name, `menuButton.splitToggle`. */
|
|
306
|
+
label = computed(() => this.i18n().splitToggle, ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
|
|
307
|
+
/** The busy note, `menuButton.splitMainBusy`. */
|
|
308
|
+
busyNote = computed(() => this.i18n().splitMainBusy, ...(ngDevMode ? [{ debugName: "busyNote" }] : /* istanbul ignore next */ []));
|
|
309
|
+
// The cause of a refusal that comes from the main: its reason, or the busy
|
|
310
|
+
// note while it runs.
|
|
311
|
+
mainDescriptionIds = computed(() => {
|
|
312
|
+
if (!this.isCaret() || !this.split) {
|
|
313
|
+
return null;
|
|
314
|
+
}
|
|
315
|
+
const ids = [this.split.mainReasonId(), this.split.mainBusy() ? this.busyNoteId : null];
|
|
316
|
+
return ids.filter(Boolean).join(' ') || null;
|
|
317
|
+
}, ...(ngDevMode ? [{ debugName: "mainDescriptionIds" }] : /* istanbul ignore next */ []));
|
|
318
|
+
constructor() {
|
|
319
|
+
injectDescribedByContribution(this.busyNoteId, this.mainDescriptionIds);
|
|
320
|
+
}
|
|
321
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxSplitCaret, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
322
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxSplitCaret, isStandalone: true, selector: "[cngxSplitCaret]", providers: [
|
|
323
|
+
// The same CNGX_BUTTON_STATE instance, so the split compares main and caret as states.
|
|
324
|
+
{ provide: CNGX_SPLIT_CARET, useFactory: splitCaretRole },
|
|
325
|
+
{ provide: CNGX_BUTTON_HOST_STATE, useExisting: CngxSplitCaret },
|
|
326
|
+
], exportAs: ["cngxSplitCaret"], ngImport: i0 });
|
|
327
|
+
}
|
|
328
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxSplitCaret, decorators: [{
|
|
329
|
+
type: Directive,
|
|
330
|
+
args: [{
|
|
331
|
+
selector: '[cngxSplitCaret]',
|
|
332
|
+
standalone: true,
|
|
333
|
+
exportAs: 'cngxSplitCaret',
|
|
334
|
+
providers: [
|
|
335
|
+
// The same CNGX_BUTTON_STATE instance, so the split compares main and caret as states.
|
|
336
|
+
{ provide: CNGX_SPLIT_CARET, useFactory: splitCaretRole },
|
|
337
|
+
{ provide: CNGX_BUTTON_HOST_STATE, useExisting: CngxSplitCaret },
|
|
338
|
+
],
|
|
339
|
+
}]
|
|
340
|
+
}], ctorParameters: () => [] });
|
|
341
|
+
function splitCaretRole() {
|
|
342
|
+
const trigger = inject(CngxPopoverTrigger, { self: true, optional: true });
|
|
343
|
+
return {
|
|
344
|
+
state: inject(CNGX_BUTTON_STATE, { self: true }),
|
|
345
|
+
popover: computed(() => trigger?.popoverRef() ?? null),
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* The square, icon-only menu button: the kebab of a row, toolbar or card, and the caret of a
|
|
351
|
+
* `cngxSplitButton`. Bindings and keyboard model of `cngxMenuButton`, `cngxIconButton` skin,
|
|
352
|
+
* `ghost` by default.
|
|
353
|
+
*
|
|
354
|
+
* Outside a split it renders the projected glyph and needs a name: without `aria-label`,
|
|
355
|
+
* `aria-labelledby` or `title` it warns [`CNGX1071`](/error-codes/cngx1071.md) in development. As
|
|
356
|
+
* the direct child of a `cngxSplitButton` it is the caret and needs neither glyph nor label.
|
|
357
|
+
*
|
|
358
|
+
* ```html
|
|
359
|
+
* <button cngxIconMenuButton aria-label="Row actions" [menu]="menu" [popover]="pop">
|
|
360
|
+
* <svg aria-hidden="true" viewBox="0 0 24 24" fill="currentColor">
|
|
361
|
+
* <circle cx="12" cy="5" r="2" /><circle cx="12" cy="12" r="2" /><circle cx="12" cy="19" r="2" />
|
|
362
|
+
* </svg>
|
|
363
|
+
* </button>
|
|
364
|
+
* ```
|
|
365
|
+
*
|
|
366
|
+
* @wcag AA
|
|
367
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/menu-button/icon-menu-button.component.ts
|
|
368
|
+
* @since 0.3.0
|
|
369
|
+
* @relatedTo CngxMenuButton, CngxButtonBrain, CngxSplitButton, CngxSplitCaret, CngxIconButton, CngxMenuTrigger, CNGX_MENU_BUTTON_I18N, CNGX_BUTTON_CARET_ICON, CngxPopoverTrigger
|
|
370
|
+
* <example-url>/#/common/menu-button/icon-menu-button/kebab</example-url>
|
|
371
|
+
* <example-url>/#/common/menu-button/split-button/basic</example-url>
|
|
372
|
+
* @axis level molecule
|
|
373
|
+
*/
|
|
374
|
+
class CngxIconMenuButton {
|
|
375
|
+
/** @internal */
|
|
376
|
+
brain = inject(CngxButtonBrain);
|
|
377
|
+
/** @internal - the caret role inside a `cngxSplitButton`. */
|
|
378
|
+
caret = inject(CngxSplitCaret);
|
|
379
|
+
/** @internal - neither opens nor closes on click while blocked. */
|
|
380
|
+
toggle = injectMenuToggle(this.brain.blocked);
|
|
381
|
+
/** `true` while the menu is open. */
|
|
382
|
+
expanded = this.toggle.expanded;
|
|
383
|
+
/** @internal - app-wide glyph from `CNGX_BUTTON_CARET_ICON`. */
|
|
384
|
+
customCaret = injectButtonCaretIcon();
|
|
385
|
+
/** @internal - default chevron from the shared icon set. */
|
|
386
|
+
caretIcon = CNGX_ICON_CHEVRON_DOWN;
|
|
387
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxIconMenuButton, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
388
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.4", type: CngxIconMenuButton, isStandalone: true, selector: "button[cngxIconMenuButton]", host: { listeners: { "click": "toggle.handleClick()" }, properties: { "attr.data-expanded": "expanded() ? \"true\" : \"false\"" }, classAttribute: "cngx-button cngx-icon-button cngx-icon-menu-button" }, providers: [provideButtonHost('cngxIconMenuButton', { defaultVariant: 'ghost', iconOnly: true })], exportAs: ["cngxIconMenuButton"], hostDirectives: [{ directive: i1.CngxButtonBrain, inputs: ["variant", "cngxIconMenuButton", "tone", "tone", "size", "size", "disabled", "disabled", "disabledReason", "disabledReason", "cngxDescribedBy", "cngxDescribedBy", "type", "type"] }, { directive: i2.CngxMenuTrigger, inputs: ["cngxMenuTrigger", "menu", "popover", "popover"] }, { directive: i3.CngxPopoverTrigger, inputs: ["cngxPopoverTrigger", "popover"] }, { directive: CngxSplitCaret }], ngImport: i0, template: `
|
|
389
|
+
<span class="cngx-button__label cngx-icon-button__glyph" aria-hidden="true">
|
|
390
|
+
@if (caret.isCaret()) {
|
|
391
|
+
<cngx-icon class="cngx-menu-button__caret">
|
|
392
|
+
@if (customCaret) {
|
|
393
|
+
<ng-container *ngComponentOutlet="customCaret" />
|
|
394
|
+
} @else {
|
|
395
|
+
<svg [cngxIconSvg]="caretIcon"></svg>
|
|
396
|
+
}
|
|
397
|
+
</cngx-icon>
|
|
398
|
+
} @else {
|
|
399
|
+
<ng-content />
|
|
400
|
+
}
|
|
401
|
+
</span>
|
|
402
|
+
@if (caret.isCaret()) {
|
|
403
|
+
<span class="cngx-sr-only">{{ caret.label() }}</span>
|
|
404
|
+
<span [id]="caret.busyNoteId" hidden>{{ caret.busyNote() }}</span>
|
|
405
|
+
}
|
|
406
|
+
<cngx-button-adornment />
|
|
407
|
+
`, isInline: true, styles: ["@layer cngx.components{@scope(.cngx-menu-button,.cngx-icon-menu-button){:scope{--cngx-menu-button-caret-transition: var(--cngx-button-transition, .15s)}}@scope(.cngx-menu-button__caret){:scope.cngx-icon{--cngx-icon-size: var(--cngx-menu-button-caret-size, 1em);transition:rotate var(--cngx-menu-button-caret-transition, .15s) ease}:scope svg{inline-size:1em;block-size:1em}:scope>:not(svg){display:contents}}.cngx-sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}.cngx-menu-button[data-expanded=true]>.cngx-menu-button__caret,.cngx-icon-menu-button[data-expanded=true]>.cngx-icon-button__glyph>.cngx-menu-button__caret{rotate:180deg}}[data-motion=reduced] .cngx-menu-button__caret{transition:none}@media(prefers-reduced-motion:reduce){:root:not([data-motion=full]) .cngx-menu-button__caret{transition:none}}\n"], dependencies: [{ kind: "directive", type: NgComponentOutlet, selector: "[ngComponentOutlet]", inputs: ["ngComponentOutlet", "ngComponentOutletInputs", "ngComponentOutletInjector", "ngComponentOutletEnvironmentInjector", "ngComponentOutletContent", "ngComponentOutletNgModule"], exportAs: ["ngComponentOutlet"] }, { kind: "component", type: CngxIcon, selector: "cngx-icon, [cngxIcon]", inputs: ["label", "size"], exportAs: ["cngxIcon"] }, { kind: "component", type: CngxIconSvg, selector: "svg[cngxIconSvg]", inputs: ["cngxIconSvg"] }, { kind: "component", type: CngxButtonAdornment, selector: "cngx-button-adornment" }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
408
|
+
}
|
|
409
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxIconMenuButton, decorators: [{
|
|
410
|
+
type: Component,
|
|
411
|
+
args: [{ selector: 'button[cngxIconMenuButton]', standalone: true, exportAs: 'cngxIconMenuButton', imports: [NgComponentOutlet, CngxIcon, CngxIconSvg, CngxButtonAdornment], changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, hostDirectives: [
|
|
412
|
+
{
|
|
413
|
+
directive: CngxButtonBrain,
|
|
414
|
+
inputs: [
|
|
415
|
+
'variant: cngxIconMenuButton',
|
|
416
|
+
'tone',
|
|
417
|
+
'size',
|
|
418
|
+
'disabled',
|
|
419
|
+
'disabledReason',
|
|
420
|
+
'cngxDescribedBy',
|
|
421
|
+
'type',
|
|
422
|
+
],
|
|
423
|
+
},
|
|
424
|
+
{ directive: CngxMenuTrigger, inputs: ['cngxMenuTrigger: menu', 'popover'] },
|
|
425
|
+
{ directive: CngxPopoverTrigger, inputs: ['cngxPopoverTrigger: popover'] },
|
|
426
|
+
CngxSplitCaret,
|
|
427
|
+
], providers: [provideButtonHost('cngxIconMenuButton', { defaultVariant: 'ghost', iconOnly: true })], host: {
|
|
428
|
+
class: 'cngx-button cngx-icon-button cngx-icon-menu-button',
|
|
429
|
+
'[attr.data-expanded]': 'expanded() ? "true" : "false"',
|
|
430
|
+
'(click)': 'toggle.handleClick()',
|
|
431
|
+
}, template: `
|
|
432
|
+
<span class="cngx-button__label cngx-icon-button__glyph" aria-hidden="true">
|
|
433
|
+
@if (caret.isCaret()) {
|
|
434
|
+
<cngx-icon class="cngx-menu-button__caret">
|
|
435
|
+
@if (customCaret) {
|
|
436
|
+
<ng-container *ngComponentOutlet="customCaret" />
|
|
437
|
+
} @else {
|
|
438
|
+
<svg [cngxIconSvg]="caretIcon"></svg>
|
|
439
|
+
}
|
|
440
|
+
</cngx-icon>
|
|
441
|
+
} @else {
|
|
442
|
+
<ng-content />
|
|
443
|
+
}
|
|
444
|
+
</span>
|
|
445
|
+
@if (caret.isCaret()) {
|
|
446
|
+
<span class="cngx-sr-only">{{ caret.label() }}</span>
|
|
447
|
+
<span [id]="caret.busyNoteId" hidden>{{ caret.busyNote() }}</span>
|
|
448
|
+
}
|
|
449
|
+
<cngx-button-adornment />
|
|
450
|
+
`, styles: ["@layer cngx.components{@scope(.cngx-menu-button,.cngx-icon-menu-button){:scope{--cngx-menu-button-caret-transition: var(--cngx-button-transition, .15s)}}@scope(.cngx-menu-button__caret){:scope.cngx-icon{--cngx-icon-size: var(--cngx-menu-button-caret-size, 1em);transition:rotate var(--cngx-menu-button-caret-transition, .15s) ease}:scope svg{inline-size:1em;block-size:1em}:scope>:not(svg){display:contents}}.cngx-sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}.cngx-menu-button[data-expanded=true]>.cngx-menu-button__caret,.cngx-icon-menu-button[data-expanded=true]>.cngx-icon-button__glyph>.cngx-menu-button__caret{rotate:180deg}}[data-motion=reduced] .cngx-menu-button__caret{transition:none}@media(prefers-reduced-motion:reduce){:root:not([data-motion=full]) .cngx-menu-button__caret{transition:none}}\n"] }]
|
|
451
|
+
}] });
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* A main button for the default action and a `cngxIconMenuButton` caret for the alternatives,
|
|
455
|
+
* framed as one `role="group"` button group. The group needs a name
|
|
456
|
+
* ([`CNGX1072`](/error-codes/cngx1072.md)); `variant` and `size` pass to both buttons.
|
|
457
|
+
*
|
|
458
|
+
* Both roles are direct children (an `ng-container` in between is fine): the caret carries
|
|
459
|
+
* `CngxSplitCaret`, the main action is the first other cngx button. Without a main button the
|
|
460
|
+
* split warns [`CNGX1073`](/error-codes/cngx1073.md).
|
|
461
|
+
*
|
|
462
|
+
* While the main button is disabled, running or refused by `[enabled]="false"`, the caret reads
|
|
463
|
+
* `aria-disabled`, does not open, closes an open menu and names the cause in `aria-describedby`.
|
|
464
|
+
* The main button keeps `aria-busy` and the announcement.
|
|
465
|
+
*
|
|
466
|
+
* The caret's menu hangs under the whole group. The split takes the explicit anchor slot of the
|
|
467
|
+
* caret's popover only while it is free, so a `[cngxPopoverAnchor]` of your own keeps precedence.
|
|
468
|
+
*
|
|
469
|
+
* ```html
|
|
470
|
+
* <div cngxSplitButton variant="solid" aria-label="Publish">
|
|
471
|
+
* <button cngxButton [cngxAsyncClick]="publish">Publish</button>
|
|
472
|
+
* <button cngxIconMenuButton [menu]="menu" [popover]="pop"></button>
|
|
473
|
+
* </div>
|
|
474
|
+
* ```
|
|
475
|
+
*
|
|
476
|
+
* @wcag AA
|
|
477
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/menu-button/split-button.directive.ts
|
|
478
|
+
* @since 0.3.0
|
|
479
|
+
* @relatedTo CngxIconMenuButton, CngxSplitCaret, CngxButton, CngxButtonGroup, CNGX_BUTTON_STATE, CngxAsyncClick, CNGX_MENU_BUTTON_I18N, CNGX_SPLIT_BUTTON, CngxPopoverAnchor
|
|
480
|
+
* <example-url>/#/common/menu-button/split-button/basic</example-url>
|
|
481
|
+
* <example-url>/#/common/menu-button/split-button/busy-and-disabled</example-url>
|
|
482
|
+
* @axis level molecule
|
|
483
|
+
*/
|
|
484
|
+
class CngxSplitButton {
|
|
485
|
+
// Direct children only, for both roles: a button inside a projected panel
|
|
486
|
+
// is neither the main action nor the caret.
|
|
487
|
+
buttons = contentChildren(CNGX_BUTTON_STATE, { ...(ngDevMode ? { debugName: "buttons" } : /* istanbul ignore next */ {}), descendants: false });
|
|
488
|
+
caretRole = contentChild(CNGX_SPLIT_CARET, { ...(ngDevMode ? { debugName: "caretRole" } : /* istanbul ignore next */ {}), descendants: false });
|
|
489
|
+
/** The caret's button state. */
|
|
490
|
+
caret = computed(() => this.caretRole()?.state, ...(ngDevMode ? [{ debugName: "caret" }] : /* istanbul ignore next */ []));
|
|
491
|
+
host = inject(ElementRef).nativeElement;
|
|
492
|
+
menuPopover = computed(() => this.caretRole()?.popover() ?? null, ...(ngDevMode ? [{ debugName: "menuPopover" }] : /* istanbul ignore next */ []));
|
|
493
|
+
/** `anchor-name` of the caret popover while the host holds its explicit anchor slot. */
|
|
494
|
+
anchorName = computed(() => {
|
|
495
|
+
const pop = this.menuPopover();
|
|
496
|
+
return pop?.explicitAnchorElement() === this.host ? `--cngx-pop-${pop.id()}` : null;
|
|
497
|
+
}, ...(ngDevMode ? [{ debugName: "anchorName" }] : /* istanbul ignore next */ []));
|
|
498
|
+
main = computed(() => this.buttons().find((button) => button !== this.caret()), ...(ngDevMode ? [{ debugName: "main" }] : /* istanbul ignore next */ []));
|
|
499
|
+
/** `true` while the main button refuses activation; `false` without one. */
|
|
500
|
+
mainBlocked = computed(() => this.main()?.blocked() ?? false, ...(ngDevMode ? [{ debugName: "mainBlocked" }] : /* istanbul ignore next */ []));
|
|
501
|
+
/** `true` while the main button runs; `false` without one. */
|
|
502
|
+
mainBusy = computed(() => this.main()?.busy() ?? false, ...(ngDevMode ? [{ debugName: "mainBusy" }] : /* istanbul ignore next */ []));
|
|
503
|
+
/** Id of the main button's reason while it is disabled with one, else `null`. */
|
|
504
|
+
mainReasonId = computed(() => this.main()?.activeReasonId() ?? null, ...(ngDevMode ? [{ debugName: "mainReasonId" }] : /* istanbul ignore next */ []));
|
|
505
|
+
constructor() {
|
|
506
|
+
// Same shape as CngxPopoverAnchor, but yields to a consumer anchor that
|
|
507
|
+
// already holds the slot.
|
|
508
|
+
effect((onCleanup) => {
|
|
509
|
+
const pop = this.menuPopover();
|
|
510
|
+
if (!pop) {
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
untracked(() => {
|
|
514
|
+
if (pop.explicitAnchorElement() === null) {
|
|
515
|
+
pop.registerAnchorElement(this.host);
|
|
516
|
+
}
|
|
517
|
+
});
|
|
518
|
+
onCleanup(() => pop.unregisterAnchorElement(this.host));
|
|
519
|
+
});
|
|
520
|
+
if (typeof ngDevMode !== 'undefined' && ngDevMode) {
|
|
521
|
+
const host = this.host;
|
|
522
|
+
afterNextRender(() => {
|
|
523
|
+
if (this.main()) {
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
cngxDevWarn('CNGX1073', '[cngxSplitButton] has no main button. Place a button host (cngxButton, cngxIconButton, cngxActionButton or a custom CngxButtonBrain host) as a direct child; the caret derives its blocked state from it.', host);
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxSplitButton, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
531
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.2.0", version: "21.2.4", type: CngxSplitButton, isStandalone: true, selector: "[cngxSplitButton]", host: { properties: { "style.anchor-name": "anchorName()" }, classAttribute: "cngx-split-button" }, providers: [{ provide: CNGX_SPLIT_BUTTON, useExisting: CngxSplitButton }], queries: [{ propertyName: "buttons", predicate: CNGX_BUTTON_STATE, isSignal: true }, { propertyName: "caretRole", first: true, predicate: CNGX_SPLIT_CARET, isSignal: true }], exportAs: ["cngxSplitButton"], hostDirectives: [{ directive: i1.CngxButtonGroup, inputs: ["variant", "variant", "size", "size"] }], ngImport: i0 });
|
|
532
|
+
}
|
|
533
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxSplitButton, decorators: [{
|
|
534
|
+
type: Directive,
|
|
535
|
+
args: [{
|
|
536
|
+
selector: '[cngxSplitButton]',
|
|
537
|
+
standalone: true,
|
|
538
|
+
exportAs: 'cngxSplitButton',
|
|
539
|
+
hostDirectives: [{ directive: CngxButtonGroup, inputs: ['variant', 'size'] }],
|
|
540
|
+
providers: [{ provide: CNGX_SPLIT_BUTTON, useExisting: CngxSplitButton }],
|
|
541
|
+
host: {
|
|
542
|
+
class: 'cngx-split-button',
|
|
543
|
+
'[style.anchor-name]': 'anchorName()',
|
|
544
|
+
},
|
|
545
|
+
}]
|
|
546
|
+
}], ctorParameters: () => [], propDecorators: { buttons: [{ type: i0.ContentChildren, args: [i0.forwardRef(() => CNGX_BUTTON_STATE), { ...{ descendants: false }, isSignal: true }] }], caretRole: [{ type: i0.ContentChild, args: [i0.forwardRef(() => CNGX_SPLIT_CARET), { ...{ descendants: false }, isSignal: true }] }] } });
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* @module `@cngx/common/menu-button`
|
|
550
|
+
*/
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* Generated bundle index. Do not edit.
|
|
554
|
+
*/
|
|
555
|
+
|
|
556
|
+
export { CNGX_BUTTON_CARET_ICON, CNGX_MENU_BUTTON_I18N, CNGX_MENU_BUTTON_LANGUAGE_EN, CNGX_SPLIT_BUTTON, CngxIconMenuButton, CngxMenuButton, CngxSplitButton, CngxSplitCaret, injectButtonCaretIcon, injectMenuButtonI18n, provideButtonCaretIcon, provideMenuButtonI18n, withMenuButtonI18nLabels };
|
|
557
|
+
//# sourceMappingURL=cngx-common-menu-button.mjs.map
|