@sonny-ui/core 0.1.0-alpha.1 → 0.1.0-alpha.11
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 +101 -32
- package/fesm2022/sonny-ui-core.mjs +3031 -42
- package/fesm2022/sonny-ui-core.mjs.map +1 -1
- package/package.json +8 -5
- package/schematics/ng-add/schema.json +1 -1
- package/schematics/ng-generate/component/index.js +182 -1
- package/schematics/ng-generate/component/schema.json +2 -2
- package/src/lib/accordion/accordion.directives.spec.ts +173 -0
- package/src/lib/accordion/accordion.directives.ts +147 -0
- package/src/lib/accordion/index.ts +8 -0
- package/src/lib/alert/alert.directives.spec.ts +154 -0
- package/src/lib/alert/alert.directives.ts +70 -0
- package/src/lib/alert/alert.variants.ts +25 -0
- package/src/lib/alert/index.ts +6 -0
- package/src/lib/avatar/avatar.component.spec.ts +75 -0
- package/src/lib/avatar/avatar.component.ts +44 -0
- package/src/lib/avatar/avatar.variants.ts +26 -0
- package/src/lib/avatar/index.ts +2 -0
- package/src/lib/badge/badge.directive.spec.ts +74 -0
- package/src/lib/badge/badge.directive.ts +18 -0
- package/src/lib/badge/badge.variants.ts +29 -0
- package/src/lib/badge/index.ts +2 -0
- package/src/lib/breadcrumb/breadcrumb.directives.spec.ts +80 -0
- package/src/lib/breadcrumb/breadcrumb.directives.ts +84 -0
- package/src/lib/breadcrumb/index.ts +8 -0
- package/src/lib/button/button.directive.spec.ts +92 -0
- package/src/lib/button/button.directive.ts +29 -0
- package/src/lib/button/button.variants.ts +30 -0
- package/src/lib/button/index.ts +2 -0
- package/src/lib/button-group/button-group.directive.spec.ts +46 -0
- package/src/lib/button-group/button-group.directive.ts +20 -0
- package/src/lib/button-group/button-group.variants.ts +18 -0
- package/src/lib/button-group/index.ts +2 -0
- package/src/lib/calendar/calendar.component.spec.ts +105 -0
- package/src/lib/calendar/calendar.component.ts +231 -0
- package/src/lib/calendar/index.ts +1 -0
- package/src/lib/card/card.directives.spec.ts +104 -0
- package/src/lib/card/card.directives.ts +78 -0
- package/src/lib/card/card.variants.ts +28 -0
- package/src/lib/card/index.ts +9 -0
- package/src/lib/carousel/carousel.directives.spec.ts +85 -0
- package/src/lib/carousel/carousel.directives.ts +164 -0
- package/src/lib/carousel/index.ts +8 -0
- package/src/lib/chat-bubble/chat-bubble.directives.spec.ts +52 -0
- package/src/lib/chat-bubble/chat-bubble.directives.ts +102 -0
- package/src/lib/chat-bubble/index.ts +11 -0
- package/src/lib/checkbox/checkbox.directive.spec.ts +57 -0
- package/src/lib/checkbox/checkbox.directive.ts +17 -0
- package/src/lib/checkbox/checkbox.variants.ts +19 -0
- package/src/lib/checkbox/index.ts +2 -0
- package/src/lib/combobox/combobox.component.spec.ts +151 -0
- package/src/lib/combobox/combobox.component.ts +279 -0
- package/src/lib/combobox/combobox.variants.ts +19 -0
- package/src/lib/combobox/index.ts +2 -0
- package/src/lib/diff/diff.component.spec.ts +47 -0
- package/src/lib/diff/diff.component.ts +83 -0
- package/src/lib/diff/index.ts +1 -0
- package/src/lib/divider/divider.component.spec.ts +48 -0
- package/src/lib/divider/divider.component.ts +52 -0
- package/src/lib/divider/divider.variants.ts +22 -0
- package/src/lib/divider/index.ts +2 -0
- package/src/lib/dock/dock.directives.spec.ts +85 -0
- package/src/lib/dock/dock.directives.ts +83 -0
- package/src/lib/dock/index.ts +1 -0
- package/src/lib/drawer/drawer.directives.spec.ts +62 -0
- package/src/lib/drawer/drawer.directives.ts +83 -0
- package/src/lib/drawer/index.ts +8 -0
- package/src/lib/dropdown/dropdown.directives.spec.ts +106 -0
- package/src/lib/dropdown/dropdown.directives.ts +143 -0
- package/src/lib/dropdown/dropdown.variants.ts +27 -0
- package/src/lib/dropdown/index.ts +15 -0
- package/src/lib/fab/fab.directives.spec.ts +60 -0
- package/src/lib/fab/fab.directives.ts +80 -0
- package/src/lib/fab/index.ts +8 -0
- package/src/lib/fieldset/fieldset.directives.spec.ts +74 -0
- package/src/lib/fieldset/fieldset.directives.ts +52 -0
- package/src/lib/fieldset/fieldset.variants.ts +15 -0
- package/src/lib/fieldset/index.ts +6 -0
- package/src/lib/file-input/file-input.component.spec.ts +114 -0
- package/src/lib/file-input/file-input.component.ts +168 -0
- package/src/lib/file-input/file-input.variants.ts +25 -0
- package/src/lib/file-input/index.ts +6 -0
- package/src/lib/indicator/index.ts +6 -0
- package/src/lib/indicator/indicator.directives.spec.ts +64 -0
- package/src/lib/indicator/indicator.directives.ts +61 -0
- package/src/lib/input/index.ts +3 -0
- package/src/lib/input/input.directive.spec.ts +103 -0
- package/src/lib/input/input.directive.ts +26 -0
- package/src/lib/input/input.variants.ts +42 -0
- package/src/lib/input/label.directive.ts +17 -0
- package/src/lib/kbd/index.ts +2 -0
- package/src/lib/kbd/kbd.directive.spec.ts +42 -0
- package/src/lib/kbd/kbd.directive.ts +19 -0
- package/src/lib/kbd/kbd.variants.ts +19 -0
- package/src/lib/link/index.ts +2 -0
- package/src/lib/link/link.directive.spec.ts +41 -0
- package/src/lib/link/link.directive.ts +19 -0
- package/src/lib/link/link.variants.ts +20 -0
- package/src/lib/list/index.ts +8 -0
- package/src/lib/list/list.directives.spec.ts +65 -0
- package/src/lib/list/list.directives.ts +86 -0
- package/src/lib/loader/index.ts +2 -0
- package/src/lib/loader/loader.component.spec.ts +58 -0
- package/src/lib/loader/loader.component.ts +48 -0
- package/src/lib/loader/loader.variants.ts +21 -0
- package/src/lib/modal/dialog-ref.ts +19 -0
- package/src/lib/modal/dialog.directives.ts +90 -0
- package/src/lib/modal/dialog.service.spec.ts +52 -0
- package/src/lib/modal/dialog.service.ts +61 -0
- package/src/lib/modal/dialog.types.ts +16 -0
- package/src/lib/modal/index.ts +11 -0
- package/src/lib/navbar/index.ts +7 -0
- package/src/lib/navbar/navbar.directives.spec.ts +59 -0
- package/src/lib/navbar/navbar.directives.ts +61 -0
- package/src/lib/pagination/index.ts +6 -0
- package/src/lib/pagination/pagination.component.spec.ts +59 -0
- package/src/lib/pagination/pagination.component.ts +144 -0
- package/src/lib/pagination/pagination.variants.ts +31 -0
- package/src/lib/progress/index.ts +7 -0
- package/src/lib/progress/progress.component.spec.ts +117 -0
- package/src/lib/progress/progress.component.ts +65 -0
- package/src/lib/progress/progress.variants.ts +43 -0
- package/src/lib/radial-progress/index.ts +5 -0
- package/src/lib/radial-progress/radial-progress.component.spec.ts +41 -0
- package/src/lib/radial-progress/radial-progress.component.ts +71 -0
- package/src/lib/radio/index.ts +2 -0
- package/src/lib/radio/radio.directive.spec.ts +46 -0
- package/src/lib/radio/radio.directive.ts +17 -0
- package/src/lib/radio/radio.variants.ts +19 -0
- package/src/lib/rating/index.ts +2 -0
- package/src/lib/rating/rating.component.spec.ts +157 -0
- package/src/lib/rating/rating.component.ts +171 -0
- package/src/lib/rating/rating.variants.ts +20 -0
- package/src/lib/select/index.ts +2 -0
- package/src/lib/select/select.component.spec.ts +112 -0
- package/src/lib/select/select.component.ts +250 -0
- package/src/lib/select/select.variants.ts +19 -0
- package/src/lib/sheet/index.ts +10 -0
- package/src/lib/sheet/sheet-ref.ts +18 -0
- package/src/lib/sheet/sheet.component.spec.ts +67 -0
- package/src/lib/sheet/sheet.directives.ts +75 -0
- package/src/lib/sheet/sheet.service.ts +100 -0
- package/src/lib/sheet/sheet.types.ts +23 -0
- package/src/lib/skeleton/index.ts +2 -0
- package/src/lib/skeleton/skeleton.directive.spec.ts +63 -0
- package/src/lib/skeleton/skeleton.directive.ts +22 -0
- package/src/lib/skeleton/skeleton.variants.ts +27 -0
- package/src/lib/slider/index.ts +2 -0
- package/src/lib/slider/slider.component.spec.ts +104 -0
- package/src/lib/slider/slider.component.ts +188 -0
- package/src/lib/slider/slider.variants.ts +25 -0
- package/src/lib/stat/index.ts +8 -0
- package/src/lib/stat/stat.directives.spec.ts +60 -0
- package/src/lib/stat/stat.directives.ts +84 -0
- package/src/lib/status/index.ts +2 -0
- package/src/lib/status/status.directive.spec.ts +43 -0
- package/src/lib/status/status.directive.ts +38 -0
- package/src/lib/status/status.variants.ts +26 -0
- package/src/lib/steps/index.ts +8 -0
- package/src/lib/steps/steps.directives.spec.ts +52 -0
- package/src/lib/steps/steps.directives.ts +80 -0
- package/src/lib/switch/index.ts +2 -0
- package/src/lib/switch/switch.component.spec.ts +98 -0
- package/src/lib/switch/switch.component.ts +84 -0
- package/src/lib/switch/switch.variants.ts +31 -0
- package/src/lib/table/index.ts +12 -0
- package/src/lib/table/table.directives.spec.ts +111 -0
- package/src/lib/table/table.directives.ts +134 -0
- package/src/lib/table/table.variants.ts +36 -0
- package/src/lib/tabs/index.ts +8 -0
- package/src/lib/tabs/tabs.directives.spec.ts +136 -0
- package/src/lib/tabs/tabs.directives.ts +130 -0
- package/src/lib/tabs/tabs.variants.ts +17 -0
- package/src/lib/textarea/index.ts +7 -0
- package/src/lib/textarea/textarea.directive.spec.ts +84 -0
- package/src/lib/textarea/textarea.directive.ts +72 -0
- package/src/lib/textarea/textarea.variants.ts +34 -0
- package/src/lib/timeline/index.ts +11 -0
- package/src/lib/timeline/timeline.directives.spec.ts +55 -0
- package/src/lib/timeline/timeline.directives.ts +90 -0
- package/src/lib/toast/index.ts +3 -0
- package/src/lib/toast/toast.service.spec.ts +71 -0
- package/src/lib/toast/toast.service.ts +60 -0
- package/src/lib/toast/toast.variants.ts +38 -0
- package/src/lib/toast/toaster.component.spec.ts +38 -0
- package/src/lib/toast/toaster.component.ts +82 -0
- package/src/lib/toggle/index.ts +2 -0
- package/src/lib/toggle/toggle.directive.spec.ts +100 -0
- package/src/lib/toggle/toggle.directive.ts +73 -0
- package/src/lib/toggle/toggle.variants.ts +25 -0
- package/src/lib/tooltip/index.ts +2 -0
- package/src/lib/tooltip/tooltip.directive.spec.ts +113 -0
- package/src/lib/tooltip/tooltip.directive.ts +131 -0
- package/src/lib/tooltip/tooltip.variants.ts +20 -0
- package/src/lib/validator/index.ts +5 -0
- package/src/lib/validator/validator.directives.spec.ts +47 -0
- package/src/lib/validator/validator.directives.ts +52 -0
- package/types/sonny-ui-core.d.ts +878 -11
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Directive,
|
|
3
|
+
ElementRef,
|
|
4
|
+
OnDestroy,
|
|
5
|
+
Renderer2,
|
|
6
|
+
computed,
|
|
7
|
+
inject,
|
|
8
|
+
input,
|
|
9
|
+
signal,
|
|
10
|
+
afterNextRender,
|
|
11
|
+
} from '@angular/core';
|
|
12
|
+
import { cn } from '../core/utils/cn';
|
|
13
|
+
import { tooltipVariants, type TooltipPosition } from './tooltip.variants';
|
|
14
|
+
|
|
15
|
+
let tooltipIdCounter = 0;
|
|
16
|
+
|
|
17
|
+
@Directive({
|
|
18
|
+
selector: '[snyTooltip]',
|
|
19
|
+
standalone: true,
|
|
20
|
+
exportAs: 'snyTooltip',
|
|
21
|
+
host: {
|
|
22
|
+
'(mouseenter)': 'show()',
|
|
23
|
+
'(mouseleave)': 'hide()',
|
|
24
|
+
'(focus)': 'show()',
|
|
25
|
+
'(blur)': 'hide()',
|
|
26
|
+
'(keydown.escape)': 'hide()',
|
|
27
|
+
'[attr.aria-describedby]': 'isOpen() ? tooltipId : null',
|
|
28
|
+
},
|
|
29
|
+
})
|
|
30
|
+
export class SnyTooltipDirective implements OnDestroy {
|
|
31
|
+
readonly snyTooltip = input.required<string>();
|
|
32
|
+
readonly tooltipPosition = input<TooltipPosition>('top');
|
|
33
|
+
readonly tooltipDelay = input(300);
|
|
34
|
+
readonly tooltipDisabled = input(false);
|
|
35
|
+
readonly class = input<string>('');
|
|
36
|
+
|
|
37
|
+
readonly isOpen = signal(false);
|
|
38
|
+
readonly tooltipId = `sny-tooltip-${++tooltipIdCounter}`;
|
|
39
|
+
|
|
40
|
+
private readonly el = inject(ElementRef<HTMLElement>);
|
|
41
|
+
private readonly renderer = inject(Renderer2);
|
|
42
|
+
private showTimeout: ReturnType<typeof setTimeout> | null = null;
|
|
43
|
+
private tooltipEl: HTMLElement | null = null;
|
|
44
|
+
|
|
45
|
+
constructor() {
|
|
46
|
+
afterNextRender(() => {
|
|
47
|
+
// cleanup handled in ngOnDestroy
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
show(): void {
|
|
52
|
+
if (this.tooltipDisabled()) return;
|
|
53
|
+
this.showTimeout = setTimeout(() => {
|
|
54
|
+
this.createTooltip();
|
|
55
|
+
this.isOpen.set(true);
|
|
56
|
+
}, this.tooltipDelay());
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
hide(): void {
|
|
60
|
+
if (this.showTimeout) {
|
|
61
|
+
clearTimeout(this.showTimeout);
|
|
62
|
+
this.showTimeout = null;
|
|
63
|
+
}
|
|
64
|
+
this.destroyTooltip();
|
|
65
|
+
this.isOpen.set(false);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
ngOnDestroy(): void {
|
|
69
|
+
this.hide();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private createTooltip(): void {
|
|
73
|
+
if (this.tooltipEl) return;
|
|
74
|
+
|
|
75
|
+
const tooltip = this.renderer.createElement('div') as HTMLElement;
|
|
76
|
+
tooltip.id = this.tooltipId;
|
|
77
|
+
tooltip.setAttribute('role', 'tooltip');
|
|
78
|
+
tooltip.className = cn(
|
|
79
|
+
tooltipVariants({ position: this.tooltipPosition() }),
|
|
80
|
+
'fixed pointer-events-none',
|
|
81
|
+
this.class()
|
|
82
|
+
);
|
|
83
|
+
tooltip.textContent = this.snyTooltip();
|
|
84
|
+
|
|
85
|
+
this.renderer.appendChild(document.body, tooltip);
|
|
86
|
+
this.tooltipEl = tooltip;
|
|
87
|
+
|
|
88
|
+
this.positionTooltip();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private positionTooltip(): void {
|
|
92
|
+
if (!this.tooltipEl) return;
|
|
93
|
+
|
|
94
|
+
const hostRect = this.el.nativeElement.getBoundingClientRect();
|
|
95
|
+
const tooltipRect = this.tooltipEl.getBoundingClientRect();
|
|
96
|
+
const position = this.tooltipPosition();
|
|
97
|
+
const gap = 8;
|
|
98
|
+
|
|
99
|
+
let top = 0;
|
|
100
|
+
let left = 0;
|
|
101
|
+
|
|
102
|
+
switch (position) {
|
|
103
|
+
case 'top':
|
|
104
|
+
top = hostRect.top - tooltipRect.height - gap;
|
|
105
|
+
left = hostRect.left + (hostRect.width - tooltipRect.width) / 2;
|
|
106
|
+
break;
|
|
107
|
+
case 'bottom':
|
|
108
|
+
top = hostRect.bottom + gap;
|
|
109
|
+
left = hostRect.left + (hostRect.width - tooltipRect.width) / 2;
|
|
110
|
+
break;
|
|
111
|
+
case 'left':
|
|
112
|
+
top = hostRect.top + (hostRect.height - tooltipRect.height) / 2;
|
|
113
|
+
left = hostRect.left - tooltipRect.width - gap;
|
|
114
|
+
break;
|
|
115
|
+
case 'right':
|
|
116
|
+
top = hostRect.top + (hostRect.height - tooltipRect.height) / 2;
|
|
117
|
+
left = hostRect.right + gap;
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
this.tooltipEl.style.top = `${top}px`;
|
|
122
|
+
this.tooltipEl.style.left = `${left}px`;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private destroyTooltip(): void {
|
|
126
|
+
if (this.tooltipEl) {
|
|
127
|
+
this.tooltipEl.remove();
|
|
128
|
+
this.tooltipEl = null;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { cva } from 'class-variance-authority';
|
|
2
|
+
|
|
3
|
+
export const tooltipVariants = cva(
|
|
4
|
+
'z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95',
|
|
5
|
+
{
|
|
6
|
+
variants: {
|
|
7
|
+
position: {
|
|
8
|
+
top: 'slide-in-from-bottom-2',
|
|
9
|
+
bottom: 'slide-in-from-top-2',
|
|
10
|
+
left: 'slide-in-from-right-2',
|
|
11
|
+
right: 'slide-in-from-left-2',
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
defaultVariants: {
|
|
15
|
+
position: 'top',
|
|
16
|
+
},
|
|
17
|
+
}
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
export type TooltipPosition = 'top' | 'bottom' | 'left' | 'right';
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Component, signal } from '@angular/core';
|
|
2
|
+
import { TestBed, type ComponentFixture } from '@angular/core/testing';
|
|
3
|
+
import { SnyValidatorDirective, SnyValidatorHintDirective } from './validator.directives';
|
|
4
|
+
|
|
5
|
+
@Component({
|
|
6
|
+
standalone: true,
|
|
7
|
+
imports: [SnyValidatorDirective, SnyValidatorHintDirective],
|
|
8
|
+
template: `
|
|
9
|
+
<div snyValidator>
|
|
10
|
+
<div snyValidatorHint when="required" variant="error">Required</div>
|
|
11
|
+
<div snyValidatorHint when="minlength" variant="error">Too short</div>
|
|
12
|
+
<div snyValidatorHint variant="success">Looks good!</div>
|
|
13
|
+
</div>
|
|
14
|
+
`,
|
|
15
|
+
})
|
|
16
|
+
class TestHostComponent {}
|
|
17
|
+
|
|
18
|
+
describe('SnyValidatorDirective', () => {
|
|
19
|
+
let fixture: ComponentFixture<TestHostComponent>;
|
|
20
|
+
|
|
21
|
+
beforeEach(async () => {
|
|
22
|
+
await TestBed.configureTestingModule({ imports: [TestHostComponent] }).compileComponents();
|
|
23
|
+
fixture = TestBed.createComponent(TestHostComponent);
|
|
24
|
+
fixture.detectChanges();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should render validator container', () => {
|
|
28
|
+
const el = fixture.nativeElement.querySelector('[snyValidator]');
|
|
29
|
+
expect(el).toBeTruthy();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should render hints with alert role', () => {
|
|
33
|
+
const hints = fixture.nativeElement.querySelectorAll('[snyValidatorHint]');
|
|
34
|
+
expect(hints.length).toBe(3);
|
|
35
|
+
hints.forEach((h: HTMLElement) => expect(h.getAttribute('role')).toBe('alert'));
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should apply error variant to error hints', () => {
|
|
39
|
+
const hints = fixture.nativeElement.querySelectorAll('[snyValidatorHint]');
|
|
40
|
+
expect(hints[0].className).toContain('text-destructive');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should apply success variant', () => {
|
|
44
|
+
const hints = fixture.nativeElement.querySelectorAll('[snyValidatorHint]');
|
|
45
|
+
expect(hints[2].className).toContain('text-green-600');
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Directive, computed, input } from '@angular/core';
|
|
2
|
+
import { cn } from '../core/utils/cn';
|
|
3
|
+
import type { AbstractControl } from '@angular/forms';
|
|
4
|
+
|
|
5
|
+
export type ValidatorHintVariant = 'error' | 'success' | 'warning' | 'info';
|
|
6
|
+
|
|
7
|
+
@Directive({
|
|
8
|
+
selector: '[snyValidator]',
|
|
9
|
+
standalone: true,
|
|
10
|
+
host: { '[class]': 'computedClass()' },
|
|
11
|
+
})
|
|
12
|
+
export class SnyValidatorDirective {
|
|
13
|
+
readonly control = input<AbstractControl | null>(null);
|
|
14
|
+
readonly state = input<'default' | 'error' | 'success' | 'warning'>('default');
|
|
15
|
+
readonly class = input<string>('');
|
|
16
|
+
|
|
17
|
+
readonly errors = computed(() => this.control()?.errors ?? null);
|
|
18
|
+
readonly showErrors = computed(() => {
|
|
19
|
+
const c = this.control();
|
|
20
|
+
return c ? c.touched && c.invalid : false;
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
protected readonly computedClass = computed(() =>
|
|
24
|
+
cn('flex flex-col gap-1 mt-1', this.class())
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@Directive({
|
|
29
|
+
selector: '[snyValidatorHint]',
|
|
30
|
+
standalone: true,
|
|
31
|
+
host: {
|
|
32
|
+
'role': 'alert',
|
|
33
|
+
'[class]': 'computedClass()',
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
export class SnyValidatorHintDirective {
|
|
37
|
+
readonly when = input<string>('');
|
|
38
|
+
readonly type = input<ValidatorHintVariant>('error');
|
|
39
|
+
/** @deprecated Use `type` instead */
|
|
40
|
+
readonly variant = input<ValidatorHintVariant | undefined>(undefined);
|
|
41
|
+
readonly class = input<string>('');
|
|
42
|
+
|
|
43
|
+
protected readonly computedClass = computed(() => {
|
|
44
|
+
const v = this.variant() ?? this.type();
|
|
45
|
+
const variantClass =
|
|
46
|
+
v === 'success' ? 'text-green-600 dark:text-green-400' :
|
|
47
|
+
v === 'warning' ? 'text-amber-600 dark:text-amber-400' :
|
|
48
|
+
v === 'info' ? 'text-blue-600 dark:text-blue-400' :
|
|
49
|
+
'text-destructive';
|
|
50
|
+
return cn('text-xs', variantClass, this.class());
|
|
51
|
+
});
|
|
52
|
+
}
|