@egose/shadcn-theme-ng-tw 0.2.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 +1 -1
- package/alert/fesm2022/alert.mjs +1 -1
- package/autocomplete/fesm2022/autocomplete.mjs +1 -1
- package/button/fesm2022/button.mjs +3 -3
- package/checkbox/fesm2022/checkbox.mjs +6 -7
- package/checkbox/types/checkbox.d.ts +1 -1
- package/combobox/fesm2022/combobox.mjs +1 -1
- package/date-picker/README.md +15 -11
- package/date-picker/fesm2022/date-picker.mjs +148 -30
- package/date-picker/types/date-picker.d.ts +102 -9
- package/form-autocomplete/README.md +177 -0
- package/form-autocomplete/fesm2022/form-autocomplete.mjs +211 -0
- package/form-autocomplete/package.json +24 -0
- package/form-autocomplete/types/form-autocomplete.d.ts +61 -0
- package/form-checkbox/README.md +13 -3
- 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 +273 -0
- package/form-combobox/package.json +24 -0
- package/form-combobox/types/form-combobox.d.ts +73 -0
- package/form-date-picker/README.md +48 -22
- package/form-date-picker/fesm2022/form-date-picker.mjs +60 -16
- 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 +239 -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 +236 -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-input-otp/README.md +194 -0
- package/form-input-otp/fesm2022/form-input-otp.mjs +194 -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 +229 -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 +187 -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 +203 -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 +211 -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 +11 -1
- 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 +10 -0
- package/form-select/fesm2022/form-select.mjs +24 -15
- package/form-select/types/form-select.d.ts +18 -1
- package/form-slider/README.md +182 -0
- package/form-slider/fesm2022/form-slider.mjs +186 -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 +178 -0
- package/form-switch/package.json +24 -0
- package/form-switch/types/form-switch.d.ts +50 -0
- package/form-text-input/README.md +10 -0
- 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 +11 -1
- 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 +241 -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 +216 -0
- package/form-toggle-group/package.json +24 -0
- package/form-toggle-group/types/form-toggle-group.d.ts +65 -0
- package/input-group/fesm2022/input-group.mjs +20 -10
- package/input-group/types/input-group.d.ts +4 -1
- package/native-select/fesm2022/native-select.mjs +18 -6
- package/native-select/types/native-select.d.ts +7 -2
- package/package.json +57 -1
- 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/sheet/fesm2022/sheet.mjs +1 -1
- package/switch/fesm2022/switch.mjs +7 -5
- package/switch/types/switch.d.ts +2 -1
|
@@ -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,241 @@
|
|
|
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-tw/form-field';
|
|
6
|
+
import { HlmLabel } from '@egose/shadcn-theme-ng-tw/label';
|
|
7
|
+
import { HlmToggle } from '@egose/shadcn-theme-ng-tw/toggle';
|
|
8
|
+
import { hlm } from '@egose/shadcn-theme-ng-tw/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('tw: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('tw:mt-0', this._config.errorClass, this.errorClass()), /* @ts-ignore */
|
|
129
|
+
...(ngDevMode ? [{ debugName: "$errorClass" }] : /* istanbul ignore next */ []));
|
|
130
|
+
$hintClass = computed(() => hlm('tw: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: `
|
|
134
|
+
@let lbl = label();
|
|
135
|
+
@let rqrd = required();
|
|
136
|
+
|
|
137
|
+
<div>
|
|
138
|
+
<div class="tw:flex tw:items-center tw:gap-1">
|
|
139
|
+
<button
|
|
140
|
+
hlmToggle
|
|
141
|
+
type="button"
|
|
142
|
+
[id]="effectiveId()"
|
|
143
|
+
[state]="_state() ? 'on' : 'off'"
|
|
144
|
+
(stateChange)="_handleStateChange($event)"
|
|
145
|
+
[disabled]="_disabled()"
|
|
146
|
+
[variant]="variant()"
|
|
147
|
+
[size]="size()"
|
|
148
|
+
[class]="$toggleClass()"
|
|
149
|
+
>
|
|
150
|
+
@if (_state()) {
|
|
151
|
+
<ng-icon name="lucideCheck" />
|
|
152
|
+
}
|
|
153
|
+
</button>
|
|
154
|
+
@if (lbl) {
|
|
155
|
+
<label hlmLabel [for]="effectiveId()" [class]="$labelClass()"
|
|
156
|
+
>{{ lbl }}
|
|
157
|
+
@if (rqrd) {
|
|
158
|
+
<span class="tw:text-red-500">*</span>
|
|
159
|
+
}
|
|
160
|
+
</label>
|
|
161
|
+
}
|
|
162
|
+
</div>
|
|
163
|
+
|
|
164
|
+
@if (showError()) {
|
|
165
|
+
<hlm-error [id]="errorId()" [class]="$errorClass()">
|
|
166
|
+
{{ error() }}
|
|
167
|
+
</hlm-error>
|
|
168
|
+
} @else if (showHint()) {
|
|
169
|
+
<hlm-hint [id]="hintId()" [class]="$hintClass()">
|
|
170
|
+
{{ hint() }}
|
|
171
|
+
</hlm-hint>
|
|
172
|
+
}
|
|
173
|
+
</div>
|
|
174
|
+
`, 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 });
|
|
175
|
+
}
|
|
176
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: EgFormToggle, decorators: [{
|
|
177
|
+
type: Component,
|
|
178
|
+
args: [{
|
|
179
|
+
selector: 'eg-form-toggle',
|
|
180
|
+
standalone: true,
|
|
181
|
+
host: {
|
|
182
|
+
'[class]': '$userClass()',
|
|
183
|
+
},
|
|
184
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
185
|
+
imports: [HlmToggle, HlmError, HlmHint, HlmLabel, NgIcon],
|
|
186
|
+
providers: [EG_FORM_TOGGLE_VALUE_ACCESSOR, provideIcons({ lucideCheck })],
|
|
187
|
+
template: `
|
|
188
|
+
@let lbl = label();
|
|
189
|
+
@let rqrd = required();
|
|
190
|
+
|
|
191
|
+
<div>
|
|
192
|
+
<div class="tw:flex tw:items-center tw:gap-1">
|
|
193
|
+
<button
|
|
194
|
+
hlmToggle
|
|
195
|
+
type="button"
|
|
196
|
+
[id]="effectiveId()"
|
|
197
|
+
[state]="_state() ? 'on' : 'off'"
|
|
198
|
+
(stateChange)="_handleStateChange($event)"
|
|
199
|
+
[disabled]="_disabled()"
|
|
200
|
+
[variant]="variant()"
|
|
201
|
+
[size]="size()"
|
|
202
|
+
[class]="$toggleClass()"
|
|
203
|
+
>
|
|
204
|
+
@if (_state()) {
|
|
205
|
+
<ng-icon name="lucideCheck" />
|
|
206
|
+
}
|
|
207
|
+
</button>
|
|
208
|
+
@if (lbl) {
|
|
209
|
+
<label hlmLabel [for]="effectiveId()" [class]="$labelClass()"
|
|
210
|
+
>{{ lbl }}
|
|
211
|
+
@if (rqrd) {
|
|
212
|
+
<span class="tw:text-red-500">*</span>
|
|
213
|
+
}
|
|
214
|
+
</label>
|
|
215
|
+
}
|
|
216
|
+
</div>
|
|
217
|
+
|
|
218
|
+
@if (showError()) {
|
|
219
|
+
<hlm-error [id]="errorId()" [class]="$errorClass()">
|
|
220
|
+
{{ error() }}
|
|
221
|
+
</hlm-error>
|
|
222
|
+
} @else if (showHint()) {
|
|
223
|
+
<hlm-hint [id]="hintId()" [class]="$hintClass()">
|
|
224
|
+
{{ hint() }}
|
|
225
|
+
</hlm-hint>
|
|
226
|
+
}
|
|
227
|
+
</div>
|
|
228
|
+
`,
|
|
229
|
+
}]
|
|
230
|
+
}], 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 }] }] } });
|
|
231
|
+
|
|
232
|
+
/*
|
|
233
|
+
* Public API Surface of form-toggle
|
|
234
|
+
*/
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Generated bundle index. Do not edit.
|
|
238
|
+
*/
|
|
239
|
+
|
|
240
|
+
export { EG_FORM_TOGGLE_VALUE_ACCESSOR, EgFormToggle, injectEgFormToggleConfig, provideEgFormToggleConfig };
|
|
241
|
+
|
|
@@ -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 };
|