@egose/shadcn-theme-ng 0.1.0 → 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/README.md +2 -2
- package/accordion/README.md +405 -2
- package/alert/README.md +372 -2
- package/alert-dialog/README.md +471 -5
- package/aspect-ratio/README.md +272 -5
- package/autocomplete/README.md +502 -2
- package/autocomplete/fesm2022/autocomplete.mjs +1 -1
- package/avatar/README.md +357 -5
- package/badge/README.md +318 -2
- package/basic-alert/README.md +353 -2
- package/breadcrumb/README.md +406 -5
- package/button/README.md +482 -2
- package/button/fesm2022/button.mjs +85 -107
- package/button/types/button.d.ts +5 -8
- package/button-group/README.md +318 -5
- package/calendar/README.md +357 -2
- package/card/README.md +331 -5
- package/carousel/README.md +333 -5
- package/carousel/fesm2022/carousel.mjs +4 -1
- package/checkbox/README.md +320 -2
- package/checkbox/fesm2022/checkbox.mjs +6 -7
- package/checkbox/types/checkbox.d.ts +1 -1
- package/collapsible/README.md +332 -5
- package/combobox/README.md +507 -5
- package/combobox/fesm2022/combobox.mjs +5 -2
- package/command/README.md +435 -5
- package/confirmation-dialog/README.md +301 -2
- package/context-menu/README.md +366 -5
- package/date-picker/README.md +469 -2
- package/date-picker/fesm2022/date-picker.mjs +150 -32
- package/date-picker/types/date-picker.d.ts +102 -9
- package/dialog/README.md +448 -2
- package/drawer/README.md +395 -5
- package/dropdown-menu/README.md +417 -5
- package/empty/README.md +329 -5
- package/field/README.md +385 -5
- package/form-autocomplete/README.md +177 -0
- package/form-autocomplete/fesm2022/form-autocomplete.mjs +125 -0
- package/form-autocomplete/package.json +24 -0
- package/form-autocomplete/types/form-autocomplete.d.ts +61 -0
- package/form-checkbox/README.md +322 -2
- package/form-checkbox/fesm2022/form-checkbox.mjs +22 -9
- package/form-checkbox/types/form-checkbox.d.ts +23 -4
- package/form-combobox/README.md +202 -0
- package/form-combobox/fesm2022/form-combobox.mjs +147 -0
- package/form-combobox/package.json +24 -0
- package/form-combobox/types/form-combobox.d.ts +73 -0
- package/form-date-picker/README.md +348 -2
- package/form-date-picker/fesm2022/form-date-picker.mjs +38 -12
- package/form-date-picker/types/form-date-picker.d.ts +17 -1
- package/form-date-picker-multi/README.md +191 -0
- package/form-date-picker-multi/fesm2022/form-date-picker-multi.mjs +129 -0
- package/form-date-picker-multi/package.json +24 -0
- package/form-date-picker-multi/types/form-date-picker-multi.d.ts +58 -0
- package/form-date-range-picker/README.md +253 -0
- package/form-date-range-picker/fesm2022/form-date-range-picker.mjs +130 -0
- package/form-date-range-picker/package.json +24 -0
- package/form-date-range-picker/types/form-date-range-picker.d.ts +55 -0
- package/form-field/README.md +356 -2
- package/form-field-simple/README.md +340 -2
- package/form-input-otp/README.md +194 -0
- package/form-input-otp/fesm2022/form-input-otp.mjs +106 -0
- package/form-input-otp/package.json +24 -0
- package/form-input-otp/types/form-input-otp.d.ts +58 -0
- package/form-month-year-picker/README.md +188 -0
- package/form-month-year-picker/fesm2022/form-month-year-picker.mjs +125 -0
- package/form-month-year-picker/package.json +24 -0
- package/form-month-year-picker/types/form-month-year-picker.d.ts +53 -0
- package/form-native-select/README.md +205 -0
- package/form-native-select/fesm2022/form-native-select.mjs +103 -0
- package/form-native-select/package.json +24 -0
- package/form-native-select/types/form-native-select.d.ts +57 -0
- package/form-phone-input/README.md +188 -0
- package/form-phone-input/fesm2022/form-phone-input.mjs +113 -0
- package/form-phone-input/package.json +24 -0
- package/form-phone-input/types/form-phone-input.d.ts +58 -0
- package/form-radio-group/README.md +198 -0
- package/form-radio-group/fesm2022/form-radio-group.mjs +111 -0
- package/form-radio-group/package.json +24 -0
- package/form-radio-group/types/form-radio-group.d.ts +63 -0
- package/form-searchable-multiselect/README.md +371 -2
- package/form-searchable-multiselect/fesm2022/form-searchable-multiselect.mjs +19 -10
- package/form-searchable-multiselect/types/form-searchable-multiselect.d.ts +18 -1
- package/form-select/README.md +360 -2
- package/form-select/fesm2022/form-select.mjs +20 -11
- package/form-select/types/form-select.d.ts +18 -1
- package/form-slider/README.md +182 -0
- package/form-slider/fesm2022/form-slider.mjs +106 -0
- package/form-slider/package.json +24 -0
- package/form-slider/types/form-slider.d.ts +60 -0
- package/form-switch/README.md +173 -0
- package/form-switch/fesm2022/form-switch.mjs +100 -0
- package/form-switch/package.json +24 -0
- package/form-switch/types/form-switch.d.ts +50 -0
- package/form-text-input/README.md +381 -2
- package/form-text-input/fesm2022/form-text-input.mjs +19 -10
- package/form-text-input/types/form-text-input.d.ts +18 -1
- package/form-textarea/README.md +357 -2
- package/form-textarea/fesm2022/form-textarea.mjs +19 -10
- package/form-textarea/types/form-textarea.d.ts +18 -1
- package/form-toggle/README.md +186 -0
- package/form-toggle/fesm2022/form-toggle.mjs +159 -0
- package/form-toggle/package.json +24 -0
- package/form-toggle/types/form-toggle.d.ts +82 -0
- package/form-toggle-group/README.md +176 -0
- package/form-toggle-group/fesm2022/form-toggle-group.mjs +116 -0
- package/form-toggle-group/package.json +24 -0
- package/form-toggle-group/types/form-toggle-group.d.ts +65 -0
- package/hover-card/README.md +256 -5
- package/icon/README.md +239 -2
- package/input/README.md +269 -2
- package/input-group/README.md +335 -5
- package/input-group/fesm2022/input-group.mjs +22 -12
- package/input-group/types/input-group.d.ts +4 -1
- package/input-otp/README.md +375 -5
- package/item/README.md +385 -5
- package/item/fesm2022/item.mjs +3 -3
- package/kbd/README.md +291 -5
- package/label/README.md +272 -2
- package/layout-simple/README.md +193 -2
- package/layout-simple/fesm2022/layout-simple.mjs +472 -236
- package/layout-simple/types/layout-simple.d.ts +174 -137
- package/menu/README.md +417 -2
- package/menubar/README.md +343 -5
- package/native-select/README.md +323 -5
- package/native-select/fesm2022/native-select.mjs +18 -6
- package/native-select/types/native-select.d.ts +7 -2
- package/navigation-menu/README.md +369 -5
- package/package.json +57 -1
- package/pagination/README.md +388 -5
- package/phone-input/README.md +114 -0
- package/phone-input/fesm2022/phone-input.mjs +191 -0
- package/phone-input/package.json +24 -0
- package/phone-input/types/phone-input.d.ts +67 -0
- package/popover/README.md +331 -2
- package/progress/README.md +311 -5
- package/radio-group/README.md +364 -2
- package/radio-group/fesm2022/radio-group.mjs +5 -1
- package/resizable/README.md +269 -5
- package/scroll-area/README.md +233 -5
- package/searchable-multiselect/README.md +323 -2
- package/select/README.md +437 -2
- package/separator/README.md +222 -2
- package/sheet/README.md +311 -2
- package/sidebar/README.md +457 -5
- package/skeleton/README.md +217 -5
- package/slider/README.md +273 -5
- package/slider/fesm2022/slider.mjs +3 -3
- package/sonner/README.md +346 -2
- package/spinner/README.md +284 -2
- package/switch/README.md +310 -2
- package/switch/fesm2022/switch.mjs +7 -5
- package/switch/types/switch.d.ts +2 -1
- package/table/README.md +423 -5
- package/tabs/README.md +411 -2
- package/tabs/fesm2022/tabs.mjs +2 -2
- package/textarea/README.md +282 -5
- package/toggle/README.md +270 -5
- package/toggle-group/README.md +340 -5
- package/tooltip/README.md +269 -2
- package/typography/README.md +271 -5
- package/utils/README.md +303 -2
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# Form Toggle (`@egose/shadcn-theme-ng/form-toggle`)
|
|
2
|
+
|
|
3
|
+
A ready-made reactive-form boolean field: toggle button + label + validation error/hint display in one tag. For on/off settings where a button-style toggle fits better than a switch or checkbox.
|
|
4
|
+
|
|
5
|
+
The Angular implementation is a standalone wrapper: it renders `HlmError` / `HlmHint` from `@egose/shadcn-theme-ng/form-field`, `HlmLabel`, and a `button[hlmToggle]` from `@egose/shadcn-theme-ng/toggle`.
|
|
6
|
+
|
|
7
|
+
> **Structural note:** unlike the other `eg-form-*` wrappers, the toggle itself is the
|
|
8
|
+
> `ControlValueAccessor` (`BrnToggle` exposes no CVA, speaking `'on'`/`'off'` strings while the
|
|
9
|
+
> form model stays `boolean`). Bind `formControlName` **directly on this element** instead of
|
|
10
|
+
> using a `controlName` input:
|
|
11
|
+
>
|
|
12
|
+
> ```html
|
|
13
|
+
> <eg-form-toggle formControlName="bold" label="Bold" />
|
|
14
|
+
> ```
|
|
15
|
+
|
|
16
|
+
> **Ships as:** `@egose/shadcn-theme-ng/form-toggle` and `@egose/shadcn-theme-ng-tw/form-toggle`
|
|
17
|
+
> (the `tw:`-prefixed Tailwind variant). Both expose the identical TypeScript surface; only the
|
|
18
|
+
> emitted Tailwind class strings differ. See the [package README](../../README.md) for install
|
|
19
|
+
> steps, peer dependencies, and Tailwind setup. Do not publish this project directory independently.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# Plain Tailwind (no prefix)
|
|
25
|
+
npm install @egose/shadcn-theme-ng
|
|
26
|
+
|
|
27
|
+
# tw:-prefixed Tailwind variant
|
|
28
|
+
npm install @egose/shadcn-theme-ng-tw
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Peer dependencies (Angular, `@spartan-ng/brain`, `@ng-icons/*`, `rxjs`, …) are documented in the
|
|
32
|
+
[package README](../../README.md#peer-dependencies). This subpath additionally relies at runtime on
|
|
33
|
+
`@egose/shadcn-theme-ng/toggle`, `@egose/shadcn-theme-ng/form-field`, and
|
|
34
|
+
`@egose/shadcn-theme-ng/label`.
|
|
35
|
+
|
|
36
|
+
## Imports
|
|
37
|
+
|
|
38
|
+
Exported from the subpath root (`projects/form-toggle/src/public-api.ts`):
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import { EgFormToggle, provideEgFormToggleConfig } from '@egose/shadcn-theme-ng/form-toggle';
|
|
42
|
+
// tw variant: replace with '@egose/shadcn-theme-ng-tw/form-toggle'
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Standalone usage:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { Component } from '@angular/core';
|
|
49
|
+
import { ReactiveFormsModule } from '@angular/forms';
|
|
50
|
+
import { EgFormToggle } from '@egose/shadcn-theme-ng/form-toggle';
|
|
51
|
+
|
|
52
|
+
@Component({
|
|
53
|
+
selector: 'app-demo',
|
|
54
|
+
standalone: true,
|
|
55
|
+
imports: [ReactiveFormsModule, EgFormToggle],
|
|
56
|
+
template: `...`,
|
|
57
|
+
})
|
|
58
|
+
export class DemoComponent {}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
NgModule-based consumer: add `EgFormToggle` (and `ReactiveFormsModule`) to the module's
|
|
62
|
+
`imports` — it is a standalone component, not a module.
|
|
63
|
+
|
|
64
|
+
## Anatomy / Structure
|
|
65
|
+
|
|
66
|
+
```html
|
|
67
|
+
<form [formGroup]="form">
|
|
68
|
+
<eg-form-toggle formControlName="bold" label="Bold" hint="Toggle rich-text formatting." />
|
|
69
|
+
</form>
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Selector (from source): `eg-form-toggle` (standalone component, host `tw:w-full`).
|
|
73
|
+
|
|
74
|
+
## API reference
|
|
75
|
+
|
|
76
|
+
### `EgFormToggle` — `eg-form-toggle`
|
|
77
|
+
|
|
78
|
+
Bind `formControlName` on the element; there is no `controlName` input.
|
|
79
|
+
|
|
80
|
+
| Input | Type | Default | Description |
|
|
81
|
+
| ------------- | --------------------------- | ----------- | --------------------------------------------------- |
|
|
82
|
+
| `label` | `string \| undefined` | — | Label text beside the toggle (hidden when omitted). |
|
|
83
|
+
| `error` | `string \| undefined` | — | Error text shown when invalid. |
|
|
84
|
+
| `hint` | `string \| undefined` | — | Hint text shown otherwise. |
|
|
85
|
+
| `controlId` | `string \| undefined` | — | Explicit id (first priority for `effectiveId`). |
|
|
86
|
+
| `id` | `string \| undefined` | — | Fallback id (second priority). |
|
|
87
|
+
| `disabled` | `boolean` | `false` | Locks interaction (form control stays enabled). |
|
|
88
|
+
| `required` | `boolean` | `false` | Shows a red `*` next to the label. |
|
|
89
|
+
| `variant` | `'default' \| 'outline'` | `'default'` | Toggle variant forwarded to `hlmToggle`. |
|
|
90
|
+
| `size` | `'default' \| 'sm' \| 'lg'` | `'default'` | Toggle size forwarded to `hlmToggle`. |
|
|
91
|
+
| `class` | `ClassValue` | `''` | Extra host classes (base `tw:w-full`). |
|
|
92
|
+
| `toggleClass` | `string` | `''` | Extra toggle-button classes. |
|
|
93
|
+
| `labelClass` | `string` | `''` | Extra label classes. |
|
|
94
|
+
| `errorClass` | `string` | `''` | Extra error classes (base `tw:mt-0`). |
|
|
95
|
+
| `hintClass` | `string` | `''` | Extra hint classes (base `tw:mt-0`). |
|
|
96
|
+
|
|
97
|
+
| Member | Description |
|
|
98
|
+
| -------------------- | ------------------------------------------------------------------------------ |
|
|
99
|
+
| `effectiveId` | `controlId() \|\| id() \|\| generated` — wired to button `id` and label `for`. |
|
|
100
|
+
| `errorId` / `hintId` | `effectiveId + '-error' / '-hint'`. |
|
|
101
|
+
|
|
102
|
+
Requires a `[formGroup]` ancestor (or a standalone `formControl` binding).
|
|
103
|
+
|
|
104
|
+
## Examples
|
|
105
|
+
|
|
106
|
+
### 1. Text-formatting toggles
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
import { Component, inject } from '@angular/core';
|
|
110
|
+
import { FormBuilder, ReactiveFormsModule } from '@angular/forms';
|
|
111
|
+
import { EgFormToggle } from '@egose/shadcn-theme-ng/form-toggle';
|
|
112
|
+
|
|
113
|
+
@Component({
|
|
114
|
+
selector: 'app-format',
|
|
115
|
+
standalone: true,
|
|
116
|
+
imports: [ReactiveFormsModule, EgFormToggle],
|
|
117
|
+
template: `
|
|
118
|
+
<form [formGroup]="form" class="tw:flex tw:gap-4">
|
|
119
|
+
<eg-form-toggle formControlName="bold" label="Bold" />
|
|
120
|
+
<eg-form-toggle formControlName="italic" label="Italic" />
|
|
121
|
+
</form>
|
|
122
|
+
`,
|
|
123
|
+
})
|
|
124
|
+
export class FormatComponent {
|
|
125
|
+
private readonly fb = inject(FormBuilder);
|
|
126
|
+
readonly form = this.fb.group({ bold: [false], italic: [false] });
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### 2. Required opt-in with error
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
import { Component, inject } from '@angular/core';
|
|
134
|
+
import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
|
|
135
|
+
import { EgFormToggle } from '@egose/shadcn-theme-ng/form-toggle';
|
|
136
|
+
|
|
137
|
+
@Component({
|
|
138
|
+
selector: 'app-consent-toggle',
|
|
139
|
+
standalone: true,
|
|
140
|
+
imports: [ReactiveFormsModule, EgFormToggle],
|
|
141
|
+
template: `
|
|
142
|
+
<form [formGroup]="form" (ngSubmit)="submit()">
|
|
143
|
+
<eg-form-toggle
|
|
144
|
+
formControlName="consent"
|
|
145
|
+
label="I accept the terms"
|
|
146
|
+
[required]="true"
|
|
147
|
+
error="Consent is required."
|
|
148
|
+
/>
|
|
149
|
+
<button type="submit" [disabled]="form.invalid">Continue</button>
|
|
150
|
+
</form>
|
|
151
|
+
`,
|
|
152
|
+
})
|
|
153
|
+
export class ConsentToggleComponent {
|
|
154
|
+
private readonly fb = inject(FormBuilder);
|
|
155
|
+
readonly form = this.fb.group({ consent: [false, Validators.requiredTrue] });
|
|
156
|
+
submit() {
|
|
157
|
+
console.log(this.form.value.consent);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Accessibility notes
|
|
163
|
+
|
|
164
|
+
- Label `for` ↔ button `id` wiring is automatic via `effectiveId` — always pass a `label`.
|
|
165
|
+
- The required `*` is visual; pair with `Validators.requiredTrue` so assistive tech and validation agree.
|
|
166
|
+
|
|
167
|
+
## Theming / CSS variables
|
|
168
|
+
|
|
169
|
+
No component-specific CSS variables. Style per-instance via `class` / `toggleClass` / `labelClass` / `errorClass` / `hintClass` (precedence: library base < global config < per-instance). The row layout (`flex items-center gap-1`) is fixed in the template.
|
|
170
|
+
|
|
171
|
+
Global defaults per styling slot via the wrapper config:
|
|
172
|
+
|
|
173
|
+
```ts
|
|
174
|
+
import { provideEgFormToggleConfig } from '@egose/shadcn-theme-ng/form-toggle';
|
|
175
|
+
|
|
176
|
+
await bootstrapApplication(App, {
|
|
177
|
+
providers: [provideEgFormToggleConfig({ labelClass: 'tw:font-medium' })],
|
|
178
|
+
});
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Related subpaths
|
|
182
|
+
|
|
183
|
+
- `@egose/shadcn-theme-ng/toggle` — raw `hlmToggle` directive for custom layouts.
|
|
184
|
+
- `@egose/shadcn-theme-ng/form-toggle-group` — multi-option button group (`eg-form-toggle-group`).
|
|
185
|
+
- `@egose/shadcn-theme-ng/form-switch` / `@egose/shadcn-theme-ng/form-checkbox` — boolean alternatives.
|
|
186
|
+
- `@egose/shadcn-theme-ng/form-field` — `hlm-error` / `hlm-hint` used internally.
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { InjectionToken, inject, forwardRef, Injector, DestroyRef, input, booleanAttribute, computed, signal, ChangeDetectionStrategy, Component } from '@angular/core';
|
|
3
|
+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
4
|
+
import { NG_VALUE_ACCESSOR, FormControlName } from '@angular/forms';
|
|
5
|
+
import { HlmFormIdGenerator, HlmError, HlmHint } from '@egose/shadcn-theme-ng/form-field';
|
|
6
|
+
import { HlmLabel } from '@egose/shadcn-theme-ng/label';
|
|
7
|
+
import { HlmToggle } from '@egose/shadcn-theme-ng/toggle';
|
|
8
|
+
import { hlm } from '@egose/shadcn-theme-ng/utils';
|
|
9
|
+
import { NgIcon, provideIcons } from '@ng-icons/core';
|
|
10
|
+
import { lucideCheck } from '@ng-icons/lucide';
|
|
11
|
+
|
|
12
|
+
const EgFormToggleConfigToken = new InjectionToken('EgFormToggleConfig');
|
|
13
|
+
function provideEgFormToggleConfig(config) {
|
|
14
|
+
return { provide: EgFormToggleConfigToken, useValue: { ...config } };
|
|
15
|
+
}
|
|
16
|
+
function injectEgFormToggleConfig() {
|
|
17
|
+
return inject(EgFormToggleConfigToken, { optional: true }) ?? {};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const EG_FORM_TOGGLE_VALUE_ACCESSOR = {
|
|
21
|
+
provide: NG_VALUE_ACCESSOR,
|
|
22
|
+
useExisting: forwardRef(() => EgFormToggle),
|
|
23
|
+
multi: true,
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* A single boolean toggle bound to ReactiveForms.
|
|
27
|
+
*
|
|
28
|
+
* Unlike the other `eg-form-*` wrappers, the toggle itself is the
|
|
29
|
+
* `ControlValueAccessor` (`BrnToggle` exposes no CVA): bind `formControlName`
|
|
30
|
+
* directly on this element instead of using a `controlName` input.
|
|
31
|
+
*/
|
|
32
|
+
class EgFormToggle {
|
|
33
|
+
generatedId = inject(HlmFormIdGenerator).generate('eg-form-toggle');
|
|
34
|
+
_config = injectEgFormToggleConfig();
|
|
35
|
+
_injector = inject(Injector);
|
|
36
|
+
_destroyRef = inject(DestroyRef);
|
|
37
|
+
_controlDir = null;
|
|
38
|
+
label = input(undefined, /* @ts-ignore */
|
|
39
|
+
...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
|
|
40
|
+
controlId = input(undefined, /* @ts-ignore */
|
|
41
|
+
...(ngDevMode ? [{ debugName: "controlId" }] : /* istanbul ignore next */ []));
|
|
42
|
+
error = input(undefined, /* @ts-ignore */
|
|
43
|
+
...(ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []));
|
|
44
|
+
hint = input(undefined, /* @ts-ignore */
|
|
45
|
+
...(ngDevMode ? [{ debugName: "hint" }] : /* istanbul ignore next */ []));
|
|
46
|
+
id = input(undefined, /* @ts-ignore */
|
|
47
|
+
...(ngDevMode ? [{ debugName: "id" }] : /* istanbul ignore next */ []));
|
|
48
|
+
disabled = input(false, { ...(ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
49
|
+
required = input(false, /* @ts-ignore */
|
|
50
|
+
...(ngDevMode ? [{ debugName: "required" }] : /* istanbul ignore next */ []));
|
|
51
|
+
variant = input('default', /* @ts-ignore */
|
|
52
|
+
...(ngDevMode ? [{ debugName: "variant" }] : /* istanbul ignore next */ []));
|
|
53
|
+
size = input('default', /* @ts-ignore */
|
|
54
|
+
...(ngDevMode ? [{ debugName: "size" }] : /* istanbul ignore next */ []));
|
|
55
|
+
effectiveId = computed(() => this.controlId() || this.id() || this.generatedId, /* @ts-ignore */
|
|
56
|
+
...(ngDevMode ? [{ debugName: "effectiveId" }] : /* istanbul ignore next */ []));
|
|
57
|
+
errorId = computed(() => `${this.effectiveId()}-error`, /* @ts-ignore */
|
|
58
|
+
...(ngDevMode ? [{ debugName: "errorId" }] : /* istanbul ignore next */ []));
|
|
59
|
+
hintId = computed(() => `${this.effectiveId()}-hint`, /* @ts-ignore */
|
|
60
|
+
...(ngDevMode ? [{ debugName: "hintId" }] : /* istanbul ignore next */ []));
|
|
61
|
+
_state = signal(false, /* @ts-ignore */
|
|
62
|
+
...(ngDevMode ? [{ debugName: "_state" }] : /* istanbul ignore next */ []));
|
|
63
|
+
_formDisabled = signal(false, /* @ts-ignore */
|
|
64
|
+
...(ngDevMode ? [{ debugName: "_formDisabled" }] : /* istanbul ignore next */ []));
|
|
65
|
+
_disabled = computed(() => this.disabled() || this._formDisabled(), /* @ts-ignore */
|
|
66
|
+
...(ngDevMode ? [{ debugName: "_disabled" }] : /* istanbul ignore next */ []));
|
|
67
|
+
_status = signal(null, /* @ts-ignore */
|
|
68
|
+
...(ngDevMode ? [{ debugName: "_status" }] : /* istanbul ignore next */ []));
|
|
69
|
+
showError = computed(() => {
|
|
70
|
+
this._status();
|
|
71
|
+
const control = this._controlDir?.control;
|
|
72
|
+
return !!this.error() && !!control?.errors && (control.touched || control.dirty);
|
|
73
|
+
}, /* @ts-ignore */
|
|
74
|
+
...(ngDevMode ? [{ debugName: "showError" }] : /* istanbul ignore next */ []));
|
|
75
|
+
showHint = computed(() => !this.showError() && !!this.hint(), /* @ts-ignore */
|
|
76
|
+
...(ngDevMode ? [{ debugName: "showHint" }] : /* istanbul ignore next */ []));
|
|
77
|
+
_onChange;
|
|
78
|
+
_onTouched;
|
|
79
|
+
ngAfterViewInit() {
|
|
80
|
+
// Resolved here (not earlier): this component IS the value accessor for
|
|
81
|
+
// the host FormControlName, so eager self-injection would close a
|
|
82
|
+
// circular dependency (NG0200) — and the directive's `control` is only
|
|
83
|
+
// assigned once its own setup has run.
|
|
84
|
+
this._controlDir = this._injector.get(FormControlName, null, { self: true, optional: true }) ?? null;
|
|
85
|
+
const control = this._controlDir?.control;
|
|
86
|
+
this._status.set(control?.status ?? null);
|
|
87
|
+
control?.statusChanges.pipe(takeUntilDestroyed(this._destroyRef)).subscribe((status) => {
|
|
88
|
+
this._status.set(status);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
_handleStateChange(state) {
|
|
92
|
+
// BrnToggle speaks 'on'/'off' strings; the form model stays boolean.
|
|
93
|
+
const on = state === 'on';
|
|
94
|
+
this._state.set(on);
|
|
95
|
+
this._onChange?.(on);
|
|
96
|
+
this._onTouched?.();
|
|
97
|
+
}
|
|
98
|
+
/** CONTROL VALUE ACCESSOR */
|
|
99
|
+
writeValue(value) {
|
|
100
|
+
this._state.set(!!value);
|
|
101
|
+
}
|
|
102
|
+
registerOnChange(fn) {
|
|
103
|
+
this._onChange = fn;
|
|
104
|
+
}
|
|
105
|
+
registerOnTouched(fn) {
|
|
106
|
+
this._onTouched = fn;
|
|
107
|
+
}
|
|
108
|
+
setDisabledState(isDisabled) {
|
|
109
|
+
this._formDisabled.set(isDisabled);
|
|
110
|
+
}
|
|
111
|
+
// Styling
|
|
112
|
+
userClass = input('', { ...(ngDevMode ? { debugName: "userClass" } : /* istanbul ignore next */ {}), alias: 'class' });
|
|
113
|
+
toggleClass = input('', /* @ts-ignore */
|
|
114
|
+
...(ngDevMode ? [{ debugName: "toggleClass" }] : /* istanbul ignore next */ []));
|
|
115
|
+
labelClass = input('', /* @ts-ignore */
|
|
116
|
+
...(ngDevMode ? [{ debugName: "labelClass" }] : /* istanbul ignore next */ []));
|
|
117
|
+
errorClass = input('', /* @ts-ignore */
|
|
118
|
+
...(ngDevMode ? [{ debugName: "errorClass" }] : /* istanbul ignore next */ []));
|
|
119
|
+
hintClass = input('', /* @ts-ignore */
|
|
120
|
+
...(ngDevMode ? [{ debugName: "hintClass" }] : /* istanbul ignore next */ []));
|
|
121
|
+
// Computed classes (library base < global config < per-instance)
|
|
122
|
+
$userClass = computed(() => hlm("w-full", this.userClass()), /* @ts-ignore */
|
|
123
|
+
...(ngDevMode ? [{ debugName: "$userClass" }] : /* istanbul ignore next */ []));
|
|
124
|
+
$toggleClass = computed(() => hlm(this._config.toggleClass, this.toggleClass()), /* @ts-ignore */
|
|
125
|
+
...(ngDevMode ? [{ debugName: "$toggleClass" }] : /* istanbul ignore next */ []));
|
|
126
|
+
$labelClass = computed(() => hlm(this._config.labelClass, this.labelClass()), /* @ts-ignore */
|
|
127
|
+
...(ngDevMode ? [{ debugName: "$labelClass" }] : /* istanbul ignore next */ []));
|
|
128
|
+
$errorClass = computed(() => hlm("mt-0", this._config.errorClass, this.errorClass()), /* @ts-ignore */
|
|
129
|
+
...(ngDevMode ? [{ debugName: "$errorClass" }] : /* istanbul ignore next */ []));
|
|
130
|
+
$hintClass = computed(() => hlm("mt-0", this._config.hintClass, this.hintClass()), /* @ts-ignore */
|
|
131
|
+
...(ngDevMode ? [{ debugName: "$hintClass" }] : /* istanbul ignore next */ []));
|
|
132
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: EgFormToggle, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
133
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.3", type: EgFormToggle, isStandalone: true, selector: "eg-form-toggle", inputs: { label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, controlId: { classPropertyName: "controlId", publicName: "controlId", isSignal: true, isRequired: false, transformFunction: null }, error: { classPropertyName: "error", publicName: "error", isSignal: true, isRequired: false, transformFunction: null }, hint: { classPropertyName: "hint", publicName: "hint", isSignal: true, isRequired: false, transformFunction: null }, id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: true, isRequired: false, transformFunction: null }, variant: { classPropertyName: "variant", publicName: "variant", isSignal: true, isRequired: false, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, userClass: { classPropertyName: "userClass", publicName: "class", isSignal: true, isRequired: false, transformFunction: null }, toggleClass: { classPropertyName: "toggleClass", publicName: "toggleClass", isSignal: true, isRequired: false, transformFunction: null }, labelClass: { classPropertyName: "labelClass", publicName: "labelClass", isSignal: true, isRequired: false, transformFunction: null }, errorClass: { classPropertyName: "errorClass", publicName: "errorClass", isSignal: true, isRequired: false, transformFunction: null }, hintClass: { classPropertyName: "hintClass", publicName: "hintClass", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "class": "$userClass()" } }, providers: [EG_FORM_TOGGLE_VALUE_ACCESSOR, provideIcons({ lucideCheck })], ngImport: i0, template: "\n @let lbl = label();\n @let rqrd = required();\n\n <div>\n <div class=\"flex items-center gap-1\">\n <button\n hlmToggle\n type=\"button\"\n [id]=\"effectiveId()\"\n [state]=\"_state() ? 'on' : 'off'\"\n (stateChange)=\"_handleStateChange($event)\"\n [disabled]=\"_disabled()\"\n [variant]=\"variant()\"\n [size]=\"size()\"\n [class]=\"$toggleClass()\"\n >\n @if (_state()) {\n <ng-icon name=\"lucideCheck\" />\n }\n </button>\n @if (lbl) {\n <label hlmLabel [for]=\"effectiveId()\" [class]=\"$labelClass()\"\n >{{ lbl }}\n @if (rqrd) {\n <span class=\"text-red-500\">*</span>\n }\n </label>\n }\n </div>\n\n @if (showError()) {\n <hlm-error [id]=\"errorId()\" [class]=\"$errorClass()\">\n {{ error() }}\n </hlm-error>\n } @else if (showHint()) {\n <hlm-hint [id]=\"hintId()\" [class]=\"$hintClass()\">\n {{ hint() }}\n </hlm-hint>\n }\n </div>\n ", isInline: true, dependencies: [{ kind: "directive", type: HlmToggle, selector: "button[hlmToggle]", inputs: ["variant", "size"] }, { kind: "directive", type: HlmError, selector: "hlm-error", inputs: ["class"] }, { kind: "directive", type: HlmHint, selector: "hlm-hint", inputs: ["class"] }, { kind: "directive", type: HlmLabel, selector: "[hlmLabel]", inputs: ["class"] }, { kind: "component", type: NgIcon, selector: "ng-icon", inputs: ["name", "svg", "size", "strokeWidth", "color"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
134
|
+
}
|
|
135
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: EgFormToggle, decorators: [{
|
|
136
|
+
type: Component,
|
|
137
|
+
args: [{
|
|
138
|
+
selector: 'eg-form-toggle',
|
|
139
|
+
standalone: true,
|
|
140
|
+
host: {
|
|
141
|
+
'[class]': '$userClass()',
|
|
142
|
+
},
|
|
143
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
144
|
+
imports: [HlmToggle, HlmError, HlmHint, HlmLabel, NgIcon],
|
|
145
|
+
providers: [EG_FORM_TOGGLE_VALUE_ACCESSOR, provideIcons({ lucideCheck })],
|
|
146
|
+
template: "\n @let lbl = label();\n @let rqrd = required();\n\n <div>\n <div class=\"flex items-center gap-1\">\n <button\n hlmToggle\n type=\"button\"\n [id]=\"effectiveId()\"\n [state]=\"_state() ? 'on' : 'off'\"\n (stateChange)=\"_handleStateChange($event)\"\n [disabled]=\"_disabled()\"\n [variant]=\"variant()\"\n [size]=\"size()\"\n [class]=\"$toggleClass()\"\n >\n @if (_state()) {\n <ng-icon name=\"lucideCheck\" />\n }\n </button>\n @if (lbl) {\n <label hlmLabel [for]=\"effectiveId()\" [class]=\"$labelClass()\"\n >{{ lbl }}\n @if (rqrd) {\n <span class=\"text-red-500\">*</span>\n }\n </label>\n }\n </div>\n\n @if (showError()) {\n <hlm-error [id]=\"errorId()\" [class]=\"$errorClass()\">\n {{ error() }}\n </hlm-error>\n } @else if (showHint()) {\n <hlm-hint [id]=\"hintId()\" [class]=\"$hintClass()\">\n {{ hint() }}\n </hlm-hint>\n }\n </div>\n ",
|
|
147
|
+
}]
|
|
148
|
+
}], propDecorators: { label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], controlId: [{ type: i0.Input, args: [{ isSignal: true, alias: "controlId", required: false }] }], error: [{ type: i0.Input, args: [{ isSignal: true, alias: "error", required: false }] }], hint: [{ type: i0.Input, args: [{ isSignal: true, alias: "hint", required: false }] }], id: [{ type: i0.Input, args: [{ isSignal: true, alias: "id", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], required: [{ type: i0.Input, args: [{ isSignal: true, alias: "required", required: false }] }], variant: [{ type: i0.Input, args: [{ isSignal: true, alias: "variant", required: false }] }], size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: false }] }], userClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "class", required: false }] }], toggleClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "toggleClass", required: false }] }], labelClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "labelClass", required: false }] }], errorClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "errorClass", required: false }] }], hintClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "hintClass", required: false }] }] } });
|
|
149
|
+
|
|
150
|
+
/*
|
|
151
|
+
* Public API Surface of form-toggle
|
|
152
|
+
*/
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Generated bundle index. Do not edit.
|
|
156
|
+
*/
|
|
157
|
+
|
|
158
|
+
export { EG_FORM_TOGGLE_VALUE_ACCESSOR, EgFormToggle, injectEgFormToggleConfig, provideEgFormToggleConfig };
|
|
159
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "form-toggle",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"peerDependencies": {
|
|
5
|
+
"@angular/common": "^20.3.0 || ^22.0.0",
|
|
6
|
+
"@angular/core": "^20.3.0 || ^22.0.0"
|
|
7
|
+
},
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"tslib": "^2.3.0"
|
|
10
|
+
},
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"module": "fesm2022/form-toggle.mjs",
|
|
13
|
+
"typings": "types/form-toggle.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
"./package.json": {
|
|
16
|
+
"default": "./package.json"
|
|
17
|
+
},
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./types/form-toggle.d.ts",
|
|
20
|
+
"default": "./fesm2022/form-toggle.mjs"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"type": "module"
|
|
24
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import * as _angular_core from '@angular/core';
|
|
2
|
+
import { AfterViewInit, ValueProvider } from '@angular/core';
|
|
3
|
+
import { BooleanInput } from '@angular/cdk/coercion';
|
|
4
|
+
import { ControlValueAccessor } from '@angular/forms';
|
|
5
|
+
import { ChangeFn, TouchFn } from '@spartan-ng/brain/forms';
|
|
6
|
+
import { ClassValue } from 'clsx';
|
|
7
|
+
|
|
8
|
+
declare const EG_FORM_TOGGLE_VALUE_ACCESSOR: {
|
|
9
|
+
provide: _angular_core.InjectionToken<readonly ControlValueAccessor[]>;
|
|
10
|
+
useExisting: _angular_core.Type<any>;
|
|
11
|
+
multi: boolean;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* A single boolean toggle bound to ReactiveForms.
|
|
15
|
+
*
|
|
16
|
+
* Unlike the other `eg-form-*` wrappers, the toggle itself is the
|
|
17
|
+
* `ControlValueAccessor` (`BrnToggle` exposes no CVA): bind `formControlName`
|
|
18
|
+
* directly on this element instead of using a `controlName` input.
|
|
19
|
+
*/
|
|
20
|
+
declare class EgFormToggle implements ControlValueAccessor, AfterViewInit {
|
|
21
|
+
private readonly generatedId;
|
|
22
|
+
private readonly _config;
|
|
23
|
+
private readonly _injector;
|
|
24
|
+
private readonly _destroyRef;
|
|
25
|
+
private _controlDir;
|
|
26
|
+
label: _angular_core.InputSignal<string | undefined>;
|
|
27
|
+
controlId: _angular_core.InputSignal<string | undefined>;
|
|
28
|
+
error: _angular_core.InputSignal<string | undefined>;
|
|
29
|
+
hint: _angular_core.InputSignal<string | undefined>;
|
|
30
|
+
id: _angular_core.InputSignal<string | undefined>;
|
|
31
|
+
disabled: _angular_core.InputSignalWithTransform<boolean, BooleanInput>;
|
|
32
|
+
required: _angular_core.InputSignal<boolean>;
|
|
33
|
+
variant: _angular_core.InputSignal<"default" | "outline" | null | undefined>;
|
|
34
|
+
size: _angular_core.InputSignal<"default" | "sm" | "lg" | null | undefined>;
|
|
35
|
+
readonly effectiveId: _angular_core.Signal<string>;
|
|
36
|
+
readonly errorId: _angular_core.Signal<string>;
|
|
37
|
+
readonly hintId: _angular_core.Signal<string>;
|
|
38
|
+
protected readonly _state: _angular_core.WritableSignal<boolean>;
|
|
39
|
+
private readonly _formDisabled;
|
|
40
|
+
protected readonly _disabled: _angular_core.Signal<boolean>;
|
|
41
|
+
private readonly _status;
|
|
42
|
+
protected readonly showError: _angular_core.Signal<boolean>;
|
|
43
|
+
protected readonly showHint: _angular_core.Signal<boolean>;
|
|
44
|
+
protected _onChange?: ChangeFn<boolean>;
|
|
45
|
+
protected _onTouched?: TouchFn;
|
|
46
|
+
ngAfterViewInit(): void;
|
|
47
|
+
protected _handleStateChange(state: string): void;
|
|
48
|
+
/** CONTROL VALUE ACCESSOR */
|
|
49
|
+
writeValue(value: boolean | null | undefined): void;
|
|
50
|
+
registerOnChange(fn: ChangeFn<boolean>): void;
|
|
51
|
+
registerOnTouched(fn: TouchFn): void;
|
|
52
|
+
setDisabledState(isDisabled: boolean): void;
|
|
53
|
+
userClass: _angular_core.InputSignal<ClassValue>;
|
|
54
|
+
toggleClass: _angular_core.InputSignal<string>;
|
|
55
|
+
labelClass: _angular_core.InputSignal<string>;
|
|
56
|
+
errorClass: _angular_core.InputSignal<string>;
|
|
57
|
+
hintClass: _angular_core.InputSignal<string>;
|
|
58
|
+
$userClass: _angular_core.Signal<string>;
|
|
59
|
+
$toggleClass: _angular_core.Signal<string>;
|
|
60
|
+
$labelClass: _angular_core.Signal<string>;
|
|
61
|
+
$errorClass: _angular_core.Signal<string>;
|
|
62
|
+
$hintClass: _angular_core.Signal<string>;
|
|
63
|
+
static ɵfac: _angular_core.ɵɵFactoryDeclaration<EgFormToggle, never>;
|
|
64
|
+
static ɵcmp: _angular_core.ɵɵComponentDeclaration<EgFormToggle, "eg-form-toggle", never, { "label": { "alias": "label"; "required": false; "isSignal": true; }; "controlId": { "alias": "controlId"; "required": false; "isSignal": true; }; "error": { "alias": "error"; "required": false; "isSignal": true; }; "hint": { "alias": "hint"; "required": false; "isSignal": true; }; "id": { "alias": "id"; "required": false; "isSignal": true; }; "disabled": { "alias": "disabled"; "required": false; "isSignal": true; }; "required": { "alias": "required"; "required": false; "isSignal": true; }; "variant": { "alias": "variant"; "required": false; "isSignal": true; }; "size": { "alias": "size"; "required": false; "isSignal": true; }; "userClass": { "alias": "class"; "required": false; "isSignal": true; }; "toggleClass": { "alias": "toggleClass"; "required": false; "isSignal": true; }; "labelClass": { "alias": "labelClass"; "required": false; "isSignal": true; }; "errorClass": { "alias": "errorClass"; "required": false; "isSignal": true; }; "hintClass": { "alias": "hintClass"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
interface EgFormToggleConfig {
|
|
68
|
+
/**
|
|
69
|
+
* Global class defaults for `eg-form-toggle` styling slots.
|
|
70
|
+
* Each is merged under the matching per-instance `*Class` input
|
|
71
|
+
* (library base < global config < per-instance).
|
|
72
|
+
*/
|
|
73
|
+
toggleClass?: string;
|
|
74
|
+
labelClass?: string;
|
|
75
|
+
errorClass?: string;
|
|
76
|
+
hintClass?: string;
|
|
77
|
+
}
|
|
78
|
+
declare function provideEgFormToggleConfig(config: Partial<EgFormToggleConfig>): ValueProvider;
|
|
79
|
+
declare function injectEgFormToggleConfig(): EgFormToggleConfig;
|
|
80
|
+
|
|
81
|
+
export { EG_FORM_TOGGLE_VALUE_ACCESSOR, EgFormToggle, injectEgFormToggleConfig, provideEgFormToggleConfig };
|
|
82
|
+
export type { EgFormToggleConfig };
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# Form Toggle Group (`@egose/shadcn-theme-ng/form-toggle-group`)
|
|
2
|
+
|
|
3
|
+
A ready-made reactive-form option group: label + `hlm-toggle-group` buttons + validation error/hint display in one tag. For single- or multi-select button groups (alignment, view modes, formatting).
|
|
4
|
+
|
|
5
|
+
The Angular implementation is a standalone wrapper: it renders `EgFormField` from `@egose/shadcn-theme-ng/form-field-simple` (like `eg-form-checkbox`, because `hlm-toggle-group` exposes no `BrnFieldControl`), `HlmError` / `HlmHint`, `HlmLabel`, and `HlmToggleGroup` / `HlmToggleGroupItem` from `@egose/shadcn-theme-ng/toggle-group`. The group is bound with `[formControlName]="controlName()"`, so the parent `FormGroup` owns the `string | string[]` value. It must live inside a `FormGroupDirective` (`[formGroup]` parent); ids come from `HlmFormIdGenerator` unless overridden.
|
|
6
|
+
|
|
7
|
+
> **Ships as:** `@egose/shadcn-theme-ng/form-toggle-group` and `@egose/shadcn-theme-ng-tw/form-toggle-group`
|
|
8
|
+
> (the `tw:`-prefixed Tailwind variant). Both expose the identical TypeScript surface; only the
|
|
9
|
+
> emitted Tailwind class strings differ. See the [package README](../../README.md) for install
|
|
10
|
+
> steps, peer dependencies, and Tailwind setup. Do not publish this project directory independently.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
# Plain Tailwind (no prefix)
|
|
16
|
+
npm install @egose/shadcn-theme-ng
|
|
17
|
+
|
|
18
|
+
# tw:-prefixed Tailwind variant
|
|
19
|
+
npm install @egose/shadcn-theme-ng-tw
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Peer dependencies (Angular, `@spartan-ng/brain`, `rxjs`, …) are documented in the
|
|
23
|
+
[package README](../../README.md#peer-dependencies). This subpath additionally relies at runtime on
|
|
24
|
+
`@egose/shadcn-theme-ng/toggle-group`, `@egose/shadcn-theme-ng/toggle`, `@egose/shadcn-theme-ng/form-field`,
|
|
25
|
+
`@egose/shadcn-theme-ng/form-field-simple`, and `@egose/shadcn-theme-ng/label`.
|
|
26
|
+
|
|
27
|
+
## Imports
|
|
28
|
+
|
|
29
|
+
Exported from the subpath root (`projects/form-toggle-group/src/public-api.ts`):
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { EgFormToggleGroup, provideEgFormToggleGroupConfig } from '@egose/shadcn-theme-ng/form-toggle-group';
|
|
33
|
+
// tw variant: replace with '@egose/shadcn-theme-ng-tw/form-toggle-group'
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`ControlValueAccessor` behavior: `eg-form-toggle-group` itself is not a `ControlValueAccessor`; the
|
|
37
|
+
inner `hlm-toggle-group` is (bound via `formControlName`), so `formControlName`/`formGroup` handling,
|
|
38
|
+
`Validators`, and `disabled` state from the control all flow through the parent form.
|
|
39
|
+
|
|
40
|
+
## Anatomy / Structure
|
|
41
|
+
|
|
42
|
+
```html
|
|
43
|
+
<form [formGroup]="form">
|
|
44
|
+
<eg-form-toggle-group controlName="align" label="Align" [options]="options" [required]="true" error="Pick one." />
|
|
45
|
+
</form>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Selector (from source): `eg-form-toggle-group` (standalone component, host `tw:w-full`).
|
|
49
|
+
|
|
50
|
+
## API reference
|
|
51
|
+
|
|
52
|
+
### `EgFormToggleGroup` — `eg-form-toggle-group`
|
|
53
|
+
|
|
54
|
+
| Input | Type | Default | Description |
|
|
55
|
+
| ------------- | ------------------------------- | ----------- | ------------------------------------------------------------------ |
|
|
56
|
+
| `controlName` | `string` | `''` | `formControlName` key inside the parent `FormGroup`. **Required.** |
|
|
57
|
+
| `label` | `string \| undefined` | — | Group label text (hidden when omitted). |
|
|
58
|
+
| `error` | `string \| undefined` | — | Error text shown when invalid. |
|
|
59
|
+
| `hint` | `string \| undefined` | — | Hint text shown otherwise. |
|
|
60
|
+
| `controlId` | `string \| undefined` | — | Explicit id prefix (first priority for `effectiveId`). |
|
|
61
|
+
| `id` | `string \| undefined` | — | Fallback id prefix (second priority). |
|
|
62
|
+
| `type` | `'single' \| 'multiple'` | `'single'` | Selection mode forwarded to the group. |
|
|
63
|
+
| `disabled` | `boolean` | `false` | Locks interaction (form control stays enabled). |
|
|
64
|
+
| `required` | `boolean` | `false` | Shows a red `*` next to the label. |
|
|
65
|
+
| `variant` | toggle variant | `'default'` | Variant forwarded to the group. |
|
|
66
|
+
| `size` | toggle size | `'default'` | Size forwarded to the group. |
|
|
67
|
+
| `options` | `{ value, label, disabled? }[]` | `[]` | Rendered as `hlmToggleGroupItem` buttons. |
|
|
68
|
+
| `class` | `ClassValue` | `''` | Extra host classes (base `tw:w-full`). |
|
|
69
|
+
| `labelClass` | `string` | `''` | Extra group-label classes (base `tw:mb-1`). |
|
|
70
|
+
| `groupClass` | `string` | `''` | Extra group classes. |
|
|
71
|
+
| `errorClass` | `string` | `''` | Extra error classes (base `tw:mt-0`). |
|
|
72
|
+
| `hintClass` | `string` | `''` | Extra hint classes (base `tw:mt-0`). |
|
|
73
|
+
|
|
74
|
+
| Member | Description |
|
|
75
|
+
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
76
|
+
| `effectiveId` | `controlId() \|\| id() \|\| generated` — id prefix for `errorId` / `hintId`. |
|
|
77
|
+
| `errorId` / `hintId` | `effectiveId + '-error' / '-hint'`. |
|
|
78
|
+
| `describedBy()` | `errorId` when `error()` is set and control is invalid + dirty/touched, else `hintId` when `hint()` is set, else `null` — wired to each item's `aria-describedby`. |
|
|
79
|
+
|
|
80
|
+
Requires a `[formGroup]` ancestor (injects `FormGroupDirective`, provides `ControlContainer → FormGroupDirective`).
|
|
81
|
+
|
|
82
|
+
## Examples
|
|
83
|
+
|
|
84
|
+
### 1. Single-select alignment
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
import { Component, inject } from '@angular/core';
|
|
88
|
+
import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
|
|
89
|
+
import { EgFormToggleGroup } from '@egose/shadcn-theme-ng/form-toggle-group';
|
|
90
|
+
|
|
91
|
+
@Component({
|
|
92
|
+
selector: 'app-align',
|
|
93
|
+
standalone: true,
|
|
94
|
+
imports: [ReactiveFormsModule, EgFormToggleGroup],
|
|
95
|
+
template: `
|
|
96
|
+
<form [formGroup]="form" (ngSubmit)="submit()">
|
|
97
|
+
<eg-form-toggle-group controlName="align" label="Align" [options]="options" [required]="true" error="Pick one." />
|
|
98
|
+
<button type="submit" [disabled]="form.invalid">Save</button>
|
|
99
|
+
</form>
|
|
100
|
+
`,
|
|
101
|
+
})
|
|
102
|
+
export class AlignComponent {
|
|
103
|
+
private readonly fb = inject(FormBuilder);
|
|
104
|
+
readonly form = this.fb.group({ align: ['', Validators.required] });
|
|
105
|
+
readonly options = [
|
|
106
|
+
{ value: 'left', label: 'Left' },
|
|
107
|
+
{ value: 'center', label: 'Center' },
|
|
108
|
+
{ value: 'right', label: 'Right' },
|
|
109
|
+
];
|
|
110
|
+
submit() {
|
|
111
|
+
console.log(this.form.value.align);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### 2. Multi-select formats
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
import { Component, inject } from '@angular/core';
|
|
120
|
+
import { FormBuilder, ReactiveFormsModule } from '@angular/forms';
|
|
121
|
+
import { EgFormToggleGroup } from '@egose/shadcn-theme-ng/form-toggle-group';
|
|
122
|
+
|
|
123
|
+
@Component({
|
|
124
|
+
selector: 'app-format-group',
|
|
125
|
+
standalone: true,
|
|
126
|
+
imports: [ReactiveFormsModule, EgFormToggleGroup],
|
|
127
|
+
template: `
|
|
128
|
+
<form [formGroup]="form">
|
|
129
|
+
<eg-form-toggle-group
|
|
130
|
+
controlName="formats"
|
|
131
|
+
label="Formats"
|
|
132
|
+
type="multiple"
|
|
133
|
+
[options]="options"
|
|
134
|
+
hint="Combine as needed."
|
|
135
|
+
/>
|
|
136
|
+
</form>
|
|
137
|
+
`,
|
|
138
|
+
})
|
|
139
|
+
export class FormatGroupComponent {
|
|
140
|
+
private readonly fb = inject(FormBuilder);
|
|
141
|
+
readonly form = this.fb.group({ formats: [<string[]>[]] });
|
|
142
|
+
readonly options = [
|
|
143
|
+
{ value: 'bold', label: 'Bold' },
|
|
144
|
+
{ value: 'italic', label: 'Italic' },
|
|
145
|
+
{ value: 'underline', label: 'Underline' },
|
|
146
|
+
];
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Accessibility notes
|
|
151
|
+
|
|
152
|
+
- The group label is visual; each item carries its option text and `aria-describedby` (error/hint id).
|
|
153
|
+
- The required `*` is visual; pair with `Validators.required` so assistive tech and validation agree.
|
|
154
|
+
|
|
155
|
+
## Theming / CSS variables
|
|
156
|
+
|
|
157
|
+
No component-specific CSS variables. Style per-instance via `class` / `labelClass` / `groupClass` / `errorClass` / `hintClass` (precedence: library base < global config < per-instance); `variant` / `size` drive the button look.
|
|
158
|
+
|
|
159
|
+
Global defaults per styling slot via the wrapper config:
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
import { provideEgFormToggleGroupConfig } from '@egose/shadcn-theme-ng/form-toggle-group';
|
|
163
|
+
|
|
164
|
+
await bootstrapApplication(App, {
|
|
165
|
+
providers: [provideEgFormToggleGroupConfig({ labelClass: 'tw:font-medium' })],
|
|
166
|
+
});
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Related subpaths
|
|
170
|
+
|
|
171
|
+
- `@egose/shadcn-theme-ng/toggle-group` — raw `hlm-toggle-group` / `hlmToggleGroupItem` for custom layouts.
|
|
172
|
+
- `@egose/shadcn-theme-ng/toggle` — raw `hlmToggle` directive.
|
|
173
|
+
- `@egose/shadcn-theme-ng/form-toggle` — the single boolean toggle (`eg-form-toggle`).
|
|
174
|
+
- `@egose/shadcn-theme-ng/form-radio-group` — single-choice alternative with radios.
|
|
175
|
+
- `@egose/shadcn-theme-ng/form-field` — `hlm-error` / `hlm-hint` used internally.
|
|
176
|
+
- `@egose/shadcn-theme-ng/form-field-simple` — `eg-form-field` used internally.
|