@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,182 @@
|
|
|
1
|
+
# Form Slider (`@egose/shadcn-theme-ng/form-slider`)
|
|
2
|
+
|
|
3
|
+
A ready-made reactive-form numeric field: label + `hlm-slider` + validation error/hint display in one tag. The model is a `number[]` (one entry per thumb), matching `BrnSlider`.
|
|
4
|
+
|
|
5
|
+
The Angular implementation is a standalone wrapper: it renders `HlmFormField` / `HlmError` / `HlmHint` from `@egose/shadcn-theme-ng/form-field`, `HlmLabel`, and `HlmSlider` from `@egose/shadcn-theme-ng/slider`. The slider is bound with `[formControlName]="controlName()"`, so the parent `FormGroup` owns the value. It must live inside a `FormGroupDirective` (`[formGroup]` parent); ids come from `HlmFormIdGenerator` unless overridden.
|
|
6
|
+
|
|
7
|
+
> **Ships as:** `@egose/shadcn-theme-ng/form-slider` and `@egose/shadcn-theme-ng-tw/form-slider`
|
|
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/slider`, `@egose/shadcn-theme-ng/form-field`, and
|
|
25
|
+
`@egose/shadcn-theme-ng/label`.
|
|
26
|
+
|
|
27
|
+
## Imports
|
|
28
|
+
|
|
29
|
+
Exported from the subpath root (`projects/form-slider/src/public-api.ts`):
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { EgFormSlider, provideEgFormSliderConfig } from '@egose/shadcn-theme-ng/form-slider';
|
|
33
|
+
// tw variant: replace with '@egose/shadcn-theme-ng-tw/form-slider'
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Standalone usage:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { Component } from '@angular/core';
|
|
40
|
+
import { ReactiveFormsModule } from '@angular/forms';
|
|
41
|
+
import { EgFormSlider } from '@egose/shadcn-theme-ng/form-slider';
|
|
42
|
+
|
|
43
|
+
@Component({
|
|
44
|
+
selector: 'app-demo',
|
|
45
|
+
standalone: true,
|
|
46
|
+
imports: [ReactiveFormsModule, EgFormSlider],
|
|
47
|
+
template: `...`,
|
|
48
|
+
})
|
|
49
|
+
export class DemoComponent {}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
NgModule-based consumer: add `EgFormSlider` (and `ReactiveFormsModule`) to the module's
|
|
53
|
+
`imports` — it is a standalone component, not a module.
|
|
54
|
+
|
|
55
|
+
`ControlValueAccessor` behavior: `eg-form-slider` itself is not a `ControlValueAccessor`; the
|
|
56
|
+
inner `hlm-slider` is (bound via `formControlName`), so `formControlName`/`formGroup` handling,
|
|
57
|
+
`Validators`, and `disabled` state from the control all flow through the parent form. Thumb count
|
|
58
|
+
follows the model array length (e.g. `[20, 80]` renders two thumbs).
|
|
59
|
+
|
|
60
|
+
## Anatomy / Structure
|
|
61
|
+
|
|
62
|
+
```html
|
|
63
|
+
<form [formGroup]="form">
|
|
64
|
+
<eg-form-slider controlName="volume" label="Volume" [min]="0" [max]="100" [step]="5" />
|
|
65
|
+
</form>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Selector (from source): `eg-form-slider` (standalone component, host `tw:w-full`).
|
|
69
|
+
|
|
70
|
+
## API reference
|
|
71
|
+
|
|
72
|
+
### `EgFormSlider` — `eg-form-slider`
|
|
73
|
+
|
|
74
|
+
| Input | Type | Default | Description |
|
|
75
|
+
| ------------- | --------------------- | ------- | ------------------------------------------------------------------ |
|
|
76
|
+
| `controlName` | `string` | `''` | `formControlName` key inside the parent `FormGroup`. **Required.** |
|
|
77
|
+
| `label` | `string \| undefined` | — | Label text (hidden when omitted). |
|
|
78
|
+
| `error` | `string \| undefined` | — | Error text shown when invalid. |
|
|
79
|
+
| `hint` | `string \| undefined` | — | Hint text shown otherwise. |
|
|
80
|
+
| `controlId` | `string \| undefined` | — | Explicit id (first priority for `effectiveId`). |
|
|
81
|
+
| `id` | `string \| undefined` | — | Fallback id (second priority). |
|
|
82
|
+
| `min` | `number` | `0` | Minimum value forwarded to the slider. |
|
|
83
|
+
| `max` | `number` | `100` | Maximum value forwarded to the slider. |
|
|
84
|
+
| `step` | `number` | `1` | Step value forwarded to the slider. |
|
|
85
|
+
| `disabled` | `boolean` | `false` | Locks interaction (form control stays enabled). |
|
|
86
|
+
| `required` | `boolean` | `false` | Shows a red `*` next to the label. |
|
|
87
|
+
| `class` | `ClassValue` | `''` | Extra host classes (base `tw:w-full`). |
|
|
88
|
+
| `labelClass` | `string` | `''` | Extra label classes (base `tw:mb-1`). |
|
|
89
|
+
| `sliderClass` | `string` | `''` | Extra slider classes (base `tw:w-full`). |
|
|
90
|
+
| `errorClass` | `string` | `''` | Extra error classes (base `tw:mt-0`). |
|
|
91
|
+
| `hintClass` | `string` | `''` | Extra hint classes (base `tw:mt-0`). |
|
|
92
|
+
|
|
93
|
+
| Member | Description |
|
|
94
|
+
| -------------------- | -------------------------------------------------------------- |
|
|
95
|
+
| `effectiveId` | `controlId() \|\| id() \|\| generated` — wired to slider `id`. |
|
|
96
|
+
| `labelId` | `effectiveId + '-label'` — referenced by `aria-labelledby`. |
|
|
97
|
+
| `errorId` / `hintId` | `effectiveId + '-error' / '-hint'`. |
|
|
98
|
+
|
|
99
|
+
Requires a `[formGroup]` ancestor (injects `FormGroupDirective`, provides `ControlContainer → FormGroupDirective`).
|
|
100
|
+
|
|
101
|
+
## Examples
|
|
102
|
+
|
|
103
|
+
### 1. Basic volume slider
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
import { Component, inject } from '@angular/core';
|
|
107
|
+
import { FormBuilder, ReactiveFormsModule } from '@angular/forms';
|
|
108
|
+
import { EgFormSlider } from '@egose/shadcn-theme-ng/form-slider';
|
|
109
|
+
|
|
110
|
+
@Component({
|
|
111
|
+
selector: 'app-volume',
|
|
112
|
+
standalone: true,
|
|
113
|
+
imports: [ReactiveFormsModule, EgFormSlider],
|
|
114
|
+
template: `
|
|
115
|
+
<form [formGroup]="form">
|
|
116
|
+
<eg-form-slider controlName="volume" label="Volume" [min]="0" [max]="100" [step]="5" />
|
|
117
|
+
<p>Volume is {{ form.value.volume?.[0] }}.</p>
|
|
118
|
+
</form>
|
|
119
|
+
`,
|
|
120
|
+
})
|
|
121
|
+
export class VolumeComponent {
|
|
122
|
+
private readonly fb = inject(FormBuilder);
|
|
123
|
+
readonly form = this.fb.group({ volume: [[20] as number[]] });
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### 2. Price range (two thumbs)
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
import { Component, inject } from '@angular/core';
|
|
131
|
+
import { FormBuilder, ReactiveFormsModule } from '@angular/forms';
|
|
132
|
+
import { EgFormSlider } from '@egose/shadcn-theme-ng/form-slider';
|
|
133
|
+
|
|
134
|
+
@Component({
|
|
135
|
+
selector: 'app-price',
|
|
136
|
+
standalone: true,
|
|
137
|
+
imports: [ReactiveFormsModule, EgFormSlider],
|
|
138
|
+
template: `
|
|
139
|
+
<form [formGroup]="form">
|
|
140
|
+
<eg-form-slider
|
|
141
|
+
controlName="price"
|
|
142
|
+
label="Price range"
|
|
143
|
+
[min]="0"
|
|
144
|
+
[max]="500"
|
|
145
|
+
[step]="10"
|
|
146
|
+
hint="Drag either thumb."
|
|
147
|
+
/>
|
|
148
|
+
</form>
|
|
149
|
+
`,
|
|
150
|
+
})
|
|
151
|
+
export class PriceComponent {
|
|
152
|
+
private readonly fb = inject(FormBuilder);
|
|
153
|
+
readonly form = this.fb.group({ price: [[50, 300] as number[]] });
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Accessibility notes
|
|
158
|
+
|
|
159
|
+
- The label is linked via `aria-labelledby` (sliders have no `for`-compatible control); always pass a `label`.
|
|
160
|
+
- `BrnSlider` currently accepts but does not render `aria-labelledby` on its host — the binding documents intent and activates if upstream renders it. Error/hint ids render without an input-level `describedby` link for the same reason.
|
|
161
|
+
|
|
162
|
+
## Theming / CSS variables
|
|
163
|
+
|
|
164
|
+
No component-specific CSS variables. Style per-instance via `class` / `labelClass` / `sliderClass` / `errorClass` / `hintClass` (precedence: library base < global config < per-instance).
|
|
165
|
+
|
|
166
|
+
Global defaults per styling slot via the wrapper config:
|
|
167
|
+
|
|
168
|
+
```ts
|
|
169
|
+
import { provideEgFormSliderConfig } from '@egose/shadcn-theme-ng/form-slider';
|
|
170
|
+
|
|
171
|
+
await bootstrapApplication(App, {
|
|
172
|
+
providers: [provideEgFormSliderConfig({ labelClass: 'tw:font-medium' })],
|
|
173
|
+
});
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
The host keeps `tw:w-full`; constrain width with `class` (e.g. `tw:max-w-sm`) or a wrapping container.
|
|
177
|
+
|
|
178
|
+
## Related subpaths
|
|
179
|
+
|
|
180
|
+
- `@egose/shadcn-theme-ng/slider` — raw `hlm-slider` for custom layouts.
|
|
181
|
+
- `@egose/shadcn-theme-ng/form-field` — `hlm-form-field` / `hlm-error` / `hlm-hint` used internally.
|
|
182
|
+
- `@egose/shadcn-theme-ng/form-field-simple` — alternative minimal wrapper when you compose controls by hand.
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { InjectionToken, inject, input, numberAttribute, computed, Component } from '@angular/core';
|
|
3
|
+
import * as i1 from '@angular/forms';
|
|
4
|
+
import { FormGroupDirective, ReactiveFormsModule, ControlContainer } from '@angular/forms';
|
|
5
|
+
import { HlmFormIdGenerator, HlmFormField, HlmError, HlmHint } from '@egose/shadcn-theme-ng/form-field';
|
|
6
|
+
import { HlmLabel } from '@egose/shadcn-theme-ng/label';
|
|
7
|
+
import { HlmSlider } from '@egose/shadcn-theme-ng/slider';
|
|
8
|
+
import { hlm } from '@egose/shadcn-theme-ng/utils';
|
|
9
|
+
|
|
10
|
+
const EgFormSliderConfigToken = new InjectionToken('EgFormSliderConfig');
|
|
11
|
+
function provideEgFormSliderConfig(config) {
|
|
12
|
+
return { provide: EgFormSliderConfigToken, useValue: { ...config } };
|
|
13
|
+
}
|
|
14
|
+
function injectEgFormSliderConfig() {
|
|
15
|
+
return inject(EgFormSliderConfigToken, { optional: true }) ?? {};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
class EgFormSlider {
|
|
19
|
+
formGroupDirective = inject(FormGroupDirective);
|
|
20
|
+
generatedId = inject(HlmFormIdGenerator).generate('eg-form-slider');
|
|
21
|
+
_config = injectEgFormSliderConfig();
|
|
22
|
+
label = input(undefined, /* @ts-ignore */
|
|
23
|
+
...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
|
|
24
|
+
controlId = input(undefined, /* @ts-ignore */
|
|
25
|
+
...(ngDevMode ? [{ debugName: "controlId" }] : /* istanbul ignore next */ []));
|
|
26
|
+
controlName = input('', /* @ts-ignore */
|
|
27
|
+
...(ngDevMode ? [{ debugName: "controlName" }] : /* istanbul ignore next */ []));
|
|
28
|
+
error = input(undefined, /* @ts-ignore */
|
|
29
|
+
...(ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []));
|
|
30
|
+
hint = input(undefined, /* @ts-ignore */
|
|
31
|
+
...(ngDevMode ? [{ debugName: "hint" }] : /* istanbul ignore next */ []));
|
|
32
|
+
id = input(undefined, /* @ts-ignore */
|
|
33
|
+
...(ngDevMode ? [{ debugName: "id" }] : /* istanbul ignore next */ []));
|
|
34
|
+
disabled = input(false, /* @ts-ignore */
|
|
35
|
+
...(ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []));
|
|
36
|
+
required = input(false, /* @ts-ignore */
|
|
37
|
+
...(ngDevMode ? [{ debugName: "required" }] : /* istanbul ignore next */ []));
|
|
38
|
+
min = input(0, { ...(ngDevMode ? { debugName: "min" } : /* istanbul ignore next */ {}), transform: numberAttribute });
|
|
39
|
+
max = input(100, { ...(ngDevMode ? { debugName: "max" } : /* istanbul ignore next */ {}), transform: numberAttribute });
|
|
40
|
+
step = input(1, { ...(ngDevMode ? { debugName: "step" } : /* istanbul ignore next */ {}), transform: numberAttribute });
|
|
41
|
+
effectiveId = computed(() => this.controlId() || this.id() || this.generatedId, /* @ts-ignore */
|
|
42
|
+
...(ngDevMode ? [{ debugName: "effectiveId" }] : /* istanbul ignore next */ []));
|
|
43
|
+
labelId = computed(() => `${this.effectiveId()}-label`, /* @ts-ignore */
|
|
44
|
+
...(ngDevMode ? [{ debugName: "labelId" }] : /* istanbul ignore next */ []));
|
|
45
|
+
errorId = computed(() => `${this.effectiveId()}-error`, /* @ts-ignore */
|
|
46
|
+
...(ngDevMode ? [{ debugName: "errorId" }] : /* istanbul ignore next */ []));
|
|
47
|
+
hintId = computed(() => `${this.effectiveId()}-hint`, /* @ts-ignore */
|
|
48
|
+
...(ngDevMode ? [{ debugName: "hintId" }] : /* istanbul ignore next */ []));
|
|
49
|
+
/**
|
|
50
|
+
* Combined lock for the brain `linkedSignal`-based disabled state: the raw
|
|
51
|
+
* input write always carries the resolved value, so a same-pass
|
|
52
|
+
* wrapper-toggle + `control.disable()` cannot clobber CVA state.
|
|
53
|
+
*/
|
|
54
|
+
effectiveDisabled() {
|
|
55
|
+
return this.disabled() || !!this.formGroupDirective.form.get(this.controlName())?.disabled;
|
|
56
|
+
}
|
|
57
|
+
// NOTE: BrnSlider exposes aria-labelledby but no aria-describedby, so error/hint
|
|
58
|
+
// ids render for sighted users without an input-level describedby link.
|
|
59
|
+
// Styling
|
|
60
|
+
userClass = input('', { ...(ngDevMode ? { debugName: "userClass" } : /* istanbul ignore next */ {}), alias: 'class' });
|
|
61
|
+
labelClass = input('', /* @ts-ignore */
|
|
62
|
+
...(ngDevMode ? [{ debugName: "labelClass" }] : /* istanbul ignore next */ []));
|
|
63
|
+
sliderClass = input('', /* @ts-ignore */
|
|
64
|
+
...(ngDevMode ? [{ debugName: "sliderClass" }] : /* istanbul ignore next */ []));
|
|
65
|
+
errorClass = input('', /* @ts-ignore */
|
|
66
|
+
...(ngDevMode ? [{ debugName: "errorClass" }] : /* istanbul ignore next */ []));
|
|
67
|
+
hintClass = input('', /* @ts-ignore */
|
|
68
|
+
...(ngDevMode ? [{ debugName: "hintClass" }] : /* istanbul ignore next */ []));
|
|
69
|
+
// Computed classes (library base < global config < per-instance)
|
|
70
|
+
$userClass = computed(() => hlm("w-full", this.userClass()), /* @ts-ignore */
|
|
71
|
+
...(ngDevMode ? [{ debugName: "$userClass" }] : /* istanbul ignore next */ []));
|
|
72
|
+
$labelClass = computed(() => hlm("mb-1", this._config.labelClass, this.labelClass()), /* @ts-ignore */
|
|
73
|
+
...(ngDevMode ? [{ debugName: "$labelClass" }] : /* istanbul ignore next */ []));
|
|
74
|
+
$sliderClass = computed(() => hlm("w-full", this._config.sliderClass, this.sliderClass()), /* @ts-ignore */
|
|
75
|
+
...(ngDevMode ? [{ debugName: "$sliderClass" }] : /* istanbul ignore next */ []));
|
|
76
|
+
$errorClass = computed(() => hlm("mt-0", this._config.errorClass, this.errorClass()), /* @ts-ignore */
|
|
77
|
+
...(ngDevMode ? [{ debugName: "$errorClass" }] : /* istanbul ignore next */ []));
|
|
78
|
+
$hintClass = computed(() => hlm("mt-0", this._config.hintClass, this.hintClass()), /* @ts-ignore */
|
|
79
|
+
...(ngDevMode ? [{ debugName: "$hintClass" }] : /* istanbul ignore next */ []));
|
|
80
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: EgFormSlider, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
81
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.3", type: EgFormSlider, isStandalone: true, selector: "eg-form-slider", inputs: { label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, controlId: { classPropertyName: "controlId", publicName: "controlId", isSignal: true, isRequired: false, transformFunction: null }, controlName: { classPropertyName: "controlName", publicName: "controlName", 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 }, min: { classPropertyName: "min", publicName: "min", isSignal: true, isRequired: false, transformFunction: null }, max: { classPropertyName: "max", publicName: "max", isSignal: true, isRequired: false, transformFunction: null }, step: { classPropertyName: "step", publicName: "step", isSignal: true, isRequired: false, transformFunction: null }, userClass: { classPropertyName: "userClass", publicName: "class", isSignal: true, isRequired: false, transformFunction: null }, labelClass: { classPropertyName: "labelClass", publicName: "labelClass", isSignal: true, isRequired: false, transformFunction: null }, sliderClass: { classPropertyName: "sliderClass", publicName: "sliderClass", 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: [{ provide: ControlContainer, useExisting: FormGroupDirective }], ngImport: i0, template: "\n @let lbl = label();\n @let cnm = controlName();\n @let err = error();\n @let hnt = hint();\n @let rqrd = required();\n\n <hlm-form-field>\n @if (lbl) {\n <label hlmLabel [id]=\"labelId()\" [class]=\"$labelClass()\"\n >{{ lbl }}\n @if (rqrd) {\n <span class=\"text-red-500\">*</span>\n }\n </label>\n }\n\n <hlm-slider\n [id]=\"effectiveId()\"\n [formControlName]=\"cnm\"\n [min]=\"min()\"\n [max]=\"max()\"\n [step]=\"step()\"\n [disabled]=\"effectiveDisabled()\"\n [aria-labelledby]=\"lbl ? labelId() : null\"\n [class]=\"$sliderClass()\"\n />\n\n @if (err) {\n <hlm-error [id]=\"errorId()\" [class]=\"$errorClass()\">\n {{ err }}\n </hlm-error>\n }\n\n @if (hnt) {\n <hlm-hint [id]=\"hintId()\" [class]=\"$hintClass()\">\n {{ hnt }}\n </hlm-hint>\n }\n </hlm-form-field>\n ", isInline: true, dependencies: [{ kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.FormControlName, selector: "[formControlName]", inputs: ["formControlName", "disabled", "ngModel"], outputs: ["ngModelChange"] }, { kind: "component", type: HlmFormField, selector: "hlm-form-field", inputs: ["class"] }, { 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: HlmSlider, selector: "hlm-slider, brn-slider [hlm]" }] });
|
|
82
|
+
}
|
|
83
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: EgFormSlider, decorators: [{
|
|
84
|
+
type: Component,
|
|
85
|
+
args: [{
|
|
86
|
+
selector: 'eg-form-slider',
|
|
87
|
+
standalone: true,
|
|
88
|
+
host: {
|
|
89
|
+
'[class]': '$userClass()',
|
|
90
|
+
},
|
|
91
|
+
imports: [ReactiveFormsModule, HlmFormField, HlmError, HlmHint, HlmLabel, HlmSlider],
|
|
92
|
+
providers: [{ provide: ControlContainer, useExisting: FormGroupDirective }],
|
|
93
|
+
template: "\n @let lbl = label();\n @let cnm = controlName();\n @let err = error();\n @let hnt = hint();\n @let rqrd = required();\n\n <hlm-form-field>\n @if (lbl) {\n <label hlmLabel [id]=\"labelId()\" [class]=\"$labelClass()\"\n >{{ lbl }}\n @if (rqrd) {\n <span class=\"text-red-500\">*</span>\n }\n </label>\n }\n\n <hlm-slider\n [id]=\"effectiveId()\"\n [formControlName]=\"cnm\"\n [min]=\"min()\"\n [max]=\"max()\"\n [step]=\"step()\"\n [disabled]=\"effectiveDisabled()\"\n [aria-labelledby]=\"lbl ? labelId() : null\"\n [class]=\"$sliderClass()\"\n />\n\n @if (err) {\n <hlm-error [id]=\"errorId()\" [class]=\"$errorClass()\">\n {{ err }}\n </hlm-error>\n }\n\n @if (hnt) {\n <hlm-hint [id]=\"hintId()\" [class]=\"$hintClass()\">\n {{ hnt }}\n </hlm-hint>\n }\n </hlm-form-field>\n ",
|
|
94
|
+
}]
|
|
95
|
+
}], propDecorators: { label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], controlId: [{ type: i0.Input, args: [{ isSignal: true, alias: "controlId", required: false }] }], controlName: [{ type: i0.Input, args: [{ isSignal: true, alias: "controlName", 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 }] }], min: [{ type: i0.Input, args: [{ isSignal: true, alias: "min", required: false }] }], max: [{ type: i0.Input, args: [{ isSignal: true, alias: "max", required: false }] }], step: [{ type: i0.Input, args: [{ isSignal: true, alias: "step", required: false }] }], userClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "class", required: false }] }], labelClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "labelClass", required: false }] }], sliderClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "sliderClass", required: false }] }], errorClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "errorClass", required: false }] }], hintClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "hintClass", required: false }] }] } });
|
|
96
|
+
|
|
97
|
+
/*
|
|
98
|
+
* Public API Surface of form-slider
|
|
99
|
+
*/
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Generated bundle index. Do not edit.
|
|
103
|
+
*/
|
|
104
|
+
|
|
105
|
+
export { EgFormSlider, injectEgFormSliderConfig, provideEgFormSliderConfig };
|
|
106
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "form-slider",
|
|
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-slider.mjs",
|
|
13
|
+
"typings": "types/form-slider.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
"./package.json": {
|
|
16
|
+
"default": "./package.json"
|
|
17
|
+
},
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./types/form-slider.d.ts",
|
|
20
|
+
"default": "./fesm2022/form-slider.mjs"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"type": "module"
|
|
24
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as _angular_core from '@angular/core';
|
|
2
|
+
import { ValueProvider } from '@angular/core';
|
|
3
|
+
import { ClassValue } from 'clsx';
|
|
4
|
+
import { NumberInput } from '@angular/cdk/coercion';
|
|
5
|
+
|
|
6
|
+
declare class EgFormSlider {
|
|
7
|
+
private readonly formGroupDirective;
|
|
8
|
+
private readonly generatedId;
|
|
9
|
+
private readonly _config;
|
|
10
|
+
label: _angular_core.InputSignal<string | undefined>;
|
|
11
|
+
controlId: _angular_core.InputSignal<string | undefined>;
|
|
12
|
+
controlName: _angular_core.InputSignal<string>;
|
|
13
|
+
error: _angular_core.InputSignal<string | undefined>;
|
|
14
|
+
hint: _angular_core.InputSignal<string | undefined>;
|
|
15
|
+
id: _angular_core.InputSignal<string | undefined>;
|
|
16
|
+
disabled: _angular_core.InputSignal<boolean>;
|
|
17
|
+
required: _angular_core.InputSignal<boolean>;
|
|
18
|
+
min: _angular_core.InputSignalWithTransform<number, NumberInput>;
|
|
19
|
+
max: _angular_core.InputSignalWithTransform<number, NumberInput>;
|
|
20
|
+
step: _angular_core.InputSignalWithTransform<number, NumberInput>;
|
|
21
|
+
readonly effectiveId: _angular_core.Signal<string>;
|
|
22
|
+
readonly labelId: _angular_core.Signal<string>;
|
|
23
|
+
readonly errorId: _angular_core.Signal<string>;
|
|
24
|
+
readonly hintId: _angular_core.Signal<string>;
|
|
25
|
+
/**
|
|
26
|
+
* Combined lock for the brain `linkedSignal`-based disabled state: the raw
|
|
27
|
+
* input write always carries the resolved value, so a same-pass
|
|
28
|
+
* wrapper-toggle + `control.disable()` cannot clobber CVA state.
|
|
29
|
+
*/
|
|
30
|
+
effectiveDisabled(): boolean;
|
|
31
|
+
userClass: _angular_core.InputSignal<ClassValue>;
|
|
32
|
+
labelClass: _angular_core.InputSignal<string>;
|
|
33
|
+
sliderClass: _angular_core.InputSignal<string>;
|
|
34
|
+
errorClass: _angular_core.InputSignal<string>;
|
|
35
|
+
hintClass: _angular_core.InputSignal<string>;
|
|
36
|
+
$userClass: _angular_core.Signal<string>;
|
|
37
|
+
$labelClass: _angular_core.Signal<string>;
|
|
38
|
+
$sliderClass: _angular_core.Signal<string>;
|
|
39
|
+
$errorClass: _angular_core.Signal<string>;
|
|
40
|
+
$hintClass: _angular_core.Signal<string>;
|
|
41
|
+
static ɵfac: _angular_core.ɵɵFactoryDeclaration<EgFormSlider, never>;
|
|
42
|
+
static ɵcmp: _angular_core.ɵɵComponentDeclaration<EgFormSlider, "eg-form-slider", never, { "label": { "alias": "label"; "required": false; "isSignal": true; }; "controlId": { "alias": "controlId"; "required": false; "isSignal": true; }; "controlName": { "alias": "controlName"; "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; }; "min": { "alias": "min"; "required": false; "isSignal": true; }; "max": { "alias": "max"; "required": false; "isSignal": true; }; "step": { "alias": "step"; "required": false; "isSignal": true; }; "userClass": { "alias": "class"; "required": false; "isSignal": true; }; "labelClass": { "alias": "labelClass"; "required": false; "isSignal": true; }; "sliderClass": { "alias": "sliderClass"; "required": false; "isSignal": true; }; "errorClass": { "alias": "errorClass"; "required": false; "isSignal": true; }; "hintClass": { "alias": "hintClass"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface EgFormSliderConfig {
|
|
46
|
+
/**
|
|
47
|
+
* Global class defaults for `eg-form-slider` styling slots.
|
|
48
|
+
* Each is merged under the matching per-instance `*Class` input
|
|
49
|
+
* (library base < global config < per-instance).
|
|
50
|
+
*/
|
|
51
|
+
labelClass?: string;
|
|
52
|
+
sliderClass?: string;
|
|
53
|
+
errorClass?: string;
|
|
54
|
+
hintClass?: string;
|
|
55
|
+
}
|
|
56
|
+
declare function provideEgFormSliderConfig(config: Partial<EgFormSliderConfig>): ValueProvider;
|
|
57
|
+
declare function injectEgFormSliderConfig(): EgFormSliderConfig;
|
|
58
|
+
|
|
59
|
+
export { EgFormSlider, injectEgFormSliderConfig, provideEgFormSliderConfig };
|
|
60
|
+
export type { EgFormSliderConfig };
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# Form Switch (`@egose/shadcn-theme-ng/form-switch`)
|
|
2
|
+
|
|
3
|
+
A ready-made reactive-form boolean field: `hlm-switch` + label + validation error/hint display in one tag. The switch equivalent of `eg-form-checkbox` for on/off settings.
|
|
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-switch` exposes no `BrnFieldControl`), `HlmError` / `HlmHint`, `HlmLabel`, and `HlmSwitch` from `@egose/shadcn-theme-ng/switch`. The inner switch is bound with `[formControlName]="controlName()"`, so the parent `FormGroup` owns the `boolean` value. It must live inside a `FormGroupDirective` (`[formGroup]` parent); ids come from `HlmFormIdGenerator` unless overridden.
|
|
6
|
+
|
|
7
|
+
> **Ships as:** `@egose/shadcn-theme-ng/form-switch` and `@egose/shadcn-theme-ng-tw/form-switch`
|
|
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/switch`, `@egose/shadcn-theme-ng/form-field`, `@egose/shadcn-theme-ng/form-field-simple`, and
|
|
25
|
+
`@egose/shadcn-theme-ng/label`.
|
|
26
|
+
|
|
27
|
+
## Imports
|
|
28
|
+
|
|
29
|
+
Exported from the subpath root (`projects/form-switch/src/public-api.ts`):
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { EgFormSwitch, provideEgFormSwitchConfig } from '@egose/shadcn-theme-ng/form-switch';
|
|
33
|
+
// tw variant: replace with '@egose/shadcn-theme-ng-tw/form-switch'
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Standalone usage:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { Component } from '@angular/core';
|
|
40
|
+
import { ReactiveFormsModule } from '@angular/forms';
|
|
41
|
+
import { EgFormSwitch } from '@egose/shadcn-theme-ng/form-switch';
|
|
42
|
+
|
|
43
|
+
@Component({
|
|
44
|
+
selector: 'app-demo',
|
|
45
|
+
standalone: true,
|
|
46
|
+
imports: [ReactiveFormsModule, EgFormSwitch],
|
|
47
|
+
template: `...`,
|
|
48
|
+
})
|
|
49
|
+
export class DemoComponent {}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
NgModule-based consumer: add `EgFormSwitch` (and `ReactiveFormsModule`) to the module's
|
|
53
|
+
`imports` — it is a standalone component, not a module.
|
|
54
|
+
|
|
55
|
+
`ControlValueAccessor` behavior: `eg-form-switch` itself is not a `ControlValueAccessor`; the
|
|
56
|
+
inner `hlm-switch` is (bound via `formControlName`), so `formControlName`/`formGroup` handling,
|
|
57
|
+
`Validators`, and `disabled` state from the control all flow through the parent form.
|
|
58
|
+
|
|
59
|
+
## Anatomy / Structure
|
|
60
|
+
|
|
61
|
+
```html
|
|
62
|
+
<form [formGroup]="form">
|
|
63
|
+
<eg-form-switch controlName="notifications" label="Email notifications" hint="Toggle to subscribe." />
|
|
64
|
+
</form>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Selector (from source): `eg-form-switch` (standalone component, host `tw:w-full`).
|
|
68
|
+
|
|
69
|
+
## API reference
|
|
70
|
+
|
|
71
|
+
### `EgFormSwitch` — `eg-form-switch`
|
|
72
|
+
|
|
73
|
+
| Input | Type | Default | Description |
|
|
74
|
+
| ------------- | --------------------- | ------- | ------------------------------------------------------------------ |
|
|
75
|
+
| `controlName` | `string` | `''` | `formControlName` key inside the parent `FormGroup`. **Required.** |
|
|
76
|
+
| `label` | `string \| undefined` | — | Label text beside the switch (hidden when omitted). |
|
|
77
|
+
| `error` | `string \| undefined` | — | Error text shown when invalid. |
|
|
78
|
+
| `hint` | `string \| undefined` | — | Hint text shown otherwise. |
|
|
79
|
+
| `controlId` | `string \| undefined` | — | Explicit id (first priority for `effectiveId`). |
|
|
80
|
+
| `id` | `string \| undefined` | — | Fallback id (second priority). |
|
|
81
|
+
| `disabled` | `boolean` | `false` | Locks interaction (form control stays enabled). |
|
|
82
|
+
| `required` | `boolean` | `false` | Shows a red `*` next to the label; forwarded to the switch. |
|
|
83
|
+
| `class` | `ClassValue` | `''` | Extra host classes (base `tw:w-full`). |
|
|
84
|
+
| `switchClass` | `string` | `''` | Extra switch classes, merged into `HlmSwitch.userClass`. |
|
|
85
|
+
| `labelClass` | `string` | `''` | Extra label classes. |
|
|
86
|
+
| `errorClass` | `string` | `''` | Extra error classes (base `tw:mt-0`). |
|
|
87
|
+
| `hintClass` | `string` | `''` | Extra hint classes (base `tw:mt-0`). |
|
|
88
|
+
|
|
89
|
+
| Member | Description |
|
|
90
|
+
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
91
|
+
| `effectiveId` | `controlId() \|\| id() \|\| generated` — wired to switch `id` and label `for`. |
|
|
92
|
+
| `errorId` / `hintId` | `effectiveId + '-error' / '-hint'`. |
|
|
93
|
+
| `describedBy()` | `errorId` when `error()` is set and control is invalid + dirty/touched, else `hintId` when `hint()` is set, else `null` — wired to switch `aria-describedby`. |
|
|
94
|
+
|
|
95
|
+
Requires a `[formGroup]` ancestor (injects `FormGroupDirective`, provides `ControlContainer → FormGroupDirective`).
|
|
96
|
+
|
|
97
|
+
## Examples
|
|
98
|
+
|
|
99
|
+
### 1. Basic settings toggle
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
import { Component, inject } from '@angular/core';
|
|
103
|
+
import { FormBuilder, ReactiveFormsModule } from '@angular/forms';
|
|
104
|
+
import { EgFormSwitch } from '@egose/shadcn-theme-ng/form-switch';
|
|
105
|
+
|
|
106
|
+
@Component({
|
|
107
|
+
selector: 'app-settings',
|
|
108
|
+
standalone: true,
|
|
109
|
+
imports: [ReactiveFormsModule, EgFormSwitch],
|
|
110
|
+
template: `
|
|
111
|
+
<form [formGroup]="form">
|
|
112
|
+
<eg-form-switch controlName="notifications" label="Email notifications" hint="Toggle to subscribe." />
|
|
113
|
+
</form>
|
|
114
|
+
`,
|
|
115
|
+
})
|
|
116
|
+
export class SettingsComponent {
|
|
117
|
+
private readonly fb = inject(FormBuilder);
|
|
118
|
+
readonly form = this.fb.group({ notifications: [true] });
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### 2. Required opt-in with error
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
import { Component, inject } from '@angular/core';
|
|
126
|
+
import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
|
|
127
|
+
import { EgFormSwitch } from '@egose/shadcn-theme-ng/form-switch';
|
|
128
|
+
|
|
129
|
+
@Component({
|
|
130
|
+
selector: 'app-consent',
|
|
131
|
+
standalone: true,
|
|
132
|
+
imports: [ReactiveFormsModule, EgFormSwitch],
|
|
133
|
+
template: `
|
|
134
|
+
<form [formGroup]="form" (ngSubmit)="submit()">
|
|
135
|
+
<eg-form-switch controlName="consent" label="I accept the terms" [required]="true" error="Consent is required." />
|
|
136
|
+
<button type="submit" [disabled]="form.invalid">Continue</button>
|
|
137
|
+
</form>
|
|
138
|
+
`,
|
|
139
|
+
})
|
|
140
|
+
export class ConsentComponent {
|
|
141
|
+
private readonly fb = inject(FormBuilder);
|
|
142
|
+
readonly form = this.fb.group({ consent: [false, Validators.requiredTrue] });
|
|
143
|
+
submit() {
|
|
144
|
+
console.log(this.form.value.consent);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Accessibility notes
|
|
150
|
+
|
|
151
|
+
- Label `for` ↔ switch `id` wiring is automatic via `effectiveId`; the switch also receives `aria-describedby` (error/hint id) — always pass a `label`.
|
|
152
|
+
- The required `*` is visual; pair with `Validators.requiredTrue` so assistive tech and validation agree.
|
|
153
|
+
|
|
154
|
+
## Theming / CSS variables
|
|
155
|
+
|
|
156
|
+
No component-specific CSS variables. Style per-instance via `class` / `switchClass` / `labelClass` / `errorClass` / `hintClass` (precedence: library base < global config < per-instance). The row layout (`flex items-center gap-1`) is fixed in the template.
|
|
157
|
+
|
|
158
|
+
Global defaults per styling slot via the wrapper config:
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
import { provideEgFormSwitchConfig } from '@egose/shadcn-theme-ng/form-switch';
|
|
162
|
+
|
|
163
|
+
await bootstrapApplication(App, {
|
|
164
|
+
providers: [provideEgFormSwitchConfig({ labelClass: 'tw:font-medium' })],
|
|
165
|
+
});
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Related subpaths
|
|
169
|
+
|
|
170
|
+
- `@egose/shadcn-theme-ng/switch` — raw `hlm-switch` for custom layouts.
|
|
171
|
+
- `@egose/shadcn-theme-ng/form-checkbox` — the checkbox counterpart (`eg-form-checkbox`).
|
|
172
|
+
- `@egose/shadcn-theme-ng/form-field` — `hlm-error` / `hlm-hint` used internally.
|
|
173
|
+
- `@egose/shadcn-theme-ng/form-field-simple` — `eg-form-field` used internally.
|