@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.
Files changed (198) hide show
  1. package/README.md +101 -32
  2. package/fesm2022/sonny-ui-core.mjs +3031 -42
  3. package/fesm2022/sonny-ui-core.mjs.map +1 -1
  4. package/package.json +8 -5
  5. package/schematics/ng-add/schema.json +1 -1
  6. package/schematics/ng-generate/component/index.js +182 -1
  7. package/schematics/ng-generate/component/schema.json +2 -2
  8. package/src/lib/accordion/accordion.directives.spec.ts +173 -0
  9. package/src/lib/accordion/accordion.directives.ts +147 -0
  10. package/src/lib/accordion/index.ts +8 -0
  11. package/src/lib/alert/alert.directives.spec.ts +154 -0
  12. package/src/lib/alert/alert.directives.ts +70 -0
  13. package/src/lib/alert/alert.variants.ts +25 -0
  14. package/src/lib/alert/index.ts +6 -0
  15. package/src/lib/avatar/avatar.component.spec.ts +75 -0
  16. package/src/lib/avatar/avatar.component.ts +44 -0
  17. package/src/lib/avatar/avatar.variants.ts +26 -0
  18. package/src/lib/avatar/index.ts +2 -0
  19. package/src/lib/badge/badge.directive.spec.ts +74 -0
  20. package/src/lib/badge/badge.directive.ts +18 -0
  21. package/src/lib/badge/badge.variants.ts +29 -0
  22. package/src/lib/badge/index.ts +2 -0
  23. package/src/lib/breadcrumb/breadcrumb.directives.spec.ts +80 -0
  24. package/src/lib/breadcrumb/breadcrumb.directives.ts +84 -0
  25. package/src/lib/breadcrumb/index.ts +8 -0
  26. package/src/lib/button/button.directive.spec.ts +92 -0
  27. package/src/lib/button/button.directive.ts +29 -0
  28. package/src/lib/button/button.variants.ts +30 -0
  29. package/src/lib/button/index.ts +2 -0
  30. package/src/lib/button-group/button-group.directive.spec.ts +46 -0
  31. package/src/lib/button-group/button-group.directive.ts +20 -0
  32. package/src/lib/button-group/button-group.variants.ts +18 -0
  33. package/src/lib/button-group/index.ts +2 -0
  34. package/src/lib/calendar/calendar.component.spec.ts +105 -0
  35. package/src/lib/calendar/calendar.component.ts +231 -0
  36. package/src/lib/calendar/index.ts +1 -0
  37. package/src/lib/card/card.directives.spec.ts +104 -0
  38. package/src/lib/card/card.directives.ts +78 -0
  39. package/src/lib/card/card.variants.ts +28 -0
  40. package/src/lib/card/index.ts +9 -0
  41. package/src/lib/carousel/carousel.directives.spec.ts +85 -0
  42. package/src/lib/carousel/carousel.directives.ts +164 -0
  43. package/src/lib/carousel/index.ts +8 -0
  44. package/src/lib/chat-bubble/chat-bubble.directives.spec.ts +52 -0
  45. package/src/lib/chat-bubble/chat-bubble.directives.ts +102 -0
  46. package/src/lib/chat-bubble/index.ts +11 -0
  47. package/src/lib/checkbox/checkbox.directive.spec.ts +57 -0
  48. package/src/lib/checkbox/checkbox.directive.ts +17 -0
  49. package/src/lib/checkbox/checkbox.variants.ts +19 -0
  50. package/src/lib/checkbox/index.ts +2 -0
  51. package/src/lib/combobox/combobox.component.spec.ts +151 -0
  52. package/src/lib/combobox/combobox.component.ts +279 -0
  53. package/src/lib/combobox/combobox.variants.ts +19 -0
  54. package/src/lib/combobox/index.ts +2 -0
  55. package/src/lib/diff/diff.component.spec.ts +47 -0
  56. package/src/lib/diff/diff.component.ts +83 -0
  57. package/src/lib/diff/index.ts +1 -0
  58. package/src/lib/divider/divider.component.spec.ts +48 -0
  59. package/src/lib/divider/divider.component.ts +52 -0
  60. package/src/lib/divider/divider.variants.ts +22 -0
  61. package/src/lib/divider/index.ts +2 -0
  62. package/src/lib/dock/dock.directives.spec.ts +85 -0
  63. package/src/lib/dock/dock.directives.ts +83 -0
  64. package/src/lib/dock/index.ts +1 -0
  65. package/src/lib/drawer/drawer.directives.spec.ts +62 -0
  66. package/src/lib/drawer/drawer.directives.ts +83 -0
  67. package/src/lib/drawer/index.ts +8 -0
  68. package/src/lib/dropdown/dropdown.directives.spec.ts +106 -0
  69. package/src/lib/dropdown/dropdown.directives.ts +143 -0
  70. package/src/lib/dropdown/dropdown.variants.ts +27 -0
  71. package/src/lib/dropdown/index.ts +15 -0
  72. package/src/lib/fab/fab.directives.spec.ts +60 -0
  73. package/src/lib/fab/fab.directives.ts +80 -0
  74. package/src/lib/fab/index.ts +8 -0
  75. package/src/lib/fieldset/fieldset.directives.spec.ts +74 -0
  76. package/src/lib/fieldset/fieldset.directives.ts +52 -0
  77. package/src/lib/fieldset/fieldset.variants.ts +15 -0
  78. package/src/lib/fieldset/index.ts +6 -0
  79. package/src/lib/file-input/file-input.component.spec.ts +114 -0
  80. package/src/lib/file-input/file-input.component.ts +168 -0
  81. package/src/lib/file-input/file-input.variants.ts +25 -0
  82. package/src/lib/file-input/index.ts +6 -0
  83. package/src/lib/indicator/index.ts +6 -0
  84. package/src/lib/indicator/indicator.directives.spec.ts +64 -0
  85. package/src/lib/indicator/indicator.directives.ts +61 -0
  86. package/src/lib/input/index.ts +3 -0
  87. package/src/lib/input/input.directive.spec.ts +103 -0
  88. package/src/lib/input/input.directive.ts +26 -0
  89. package/src/lib/input/input.variants.ts +42 -0
  90. package/src/lib/input/label.directive.ts +17 -0
  91. package/src/lib/kbd/index.ts +2 -0
  92. package/src/lib/kbd/kbd.directive.spec.ts +42 -0
  93. package/src/lib/kbd/kbd.directive.ts +19 -0
  94. package/src/lib/kbd/kbd.variants.ts +19 -0
  95. package/src/lib/link/index.ts +2 -0
  96. package/src/lib/link/link.directive.spec.ts +41 -0
  97. package/src/lib/link/link.directive.ts +19 -0
  98. package/src/lib/link/link.variants.ts +20 -0
  99. package/src/lib/list/index.ts +8 -0
  100. package/src/lib/list/list.directives.spec.ts +65 -0
  101. package/src/lib/list/list.directives.ts +86 -0
  102. package/src/lib/loader/index.ts +2 -0
  103. package/src/lib/loader/loader.component.spec.ts +58 -0
  104. package/src/lib/loader/loader.component.ts +48 -0
  105. package/src/lib/loader/loader.variants.ts +21 -0
  106. package/src/lib/modal/dialog-ref.ts +19 -0
  107. package/src/lib/modal/dialog.directives.ts +90 -0
  108. package/src/lib/modal/dialog.service.spec.ts +52 -0
  109. package/src/lib/modal/dialog.service.ts +61 -0
  110. package/src/lib/modal/dialog.types.ts +16 -0
  111. package/src/lib/modal/index.ts +11 -0
  112. package/src/lib/navbar/index.ts +7 -0
  113. package/src/lib/navbar/navbar.directives.spec.ts +59 -0
  114. package/src/lib/navbar/navbar.directives.ts +61 -0
  115. package/src/lib/pagination/index.ts +6 -0
  116. package/src/lib/pagination/pagination.component.spec.ts +59 -0
  117. package/src/lib/pagination/pagination.component.ts +144 -0
  118. package/src/lib/pagination/pagination.variants.ts +31 -0
  119. package/src/lib/progress/index.ts +7 -0
  120. package/src/lib/progress/progress.component.spec.ts +117 -0
  121. package/src/lib/progress/progress.component.ts +65 -0
  122. package/src/lib/progress/progress.variants.ts +43 -0
  123. package/src/lib/radial-progress/index.ts +5 -0
  124. package/src/lib/radial-progress/radial-progress.component.spec.ts +41 -0
  125. package/src/lib/radial-progress/radial-progress.component.ts +71 -0
  126. package/src/lib/radio/index.ts +2 -0
  127. package/src/lib/radio/radio.directive.spec.ts +46 -0
  128. package/src/lib/radio/radio.directive.ts +17 -0
  129. package/src/lib/radio/radio.variants.ts +19 -0
  130. package/src/lib/rating/index.ts +2 -0
  131. package/src/lib/rating/rating.component.spec.ts +157 -0
  132. package/src/lib/rating/rating.component.ts +171 -0
  133. package/src/lib/rating/rating.variants.ts +20 -0
  134. package/src/lib/select/index.ts +2 -0
  135. package/src/lib/select/select.component.spec.ts +112 -0
  136. package/src/lib/select/select.component.ts +250 -0
  137. package/src/lib/select/select.variants.ts +19 -0
  138. package/src/lib/sheet/index.ts +10 -0
  139. package/src/lib/sheet/sheet-ref.ts +18 -0
  140. package/src/lib/sheet/sheet.component.spec.ts +67 -0
  141. package/src/lib/sheet/sheet.directives.ts +75 -0
  142. package/src/lib/sheet/sheet.service.ts +100 -0
  143. package/src/lib/sheet/sheet.types.ts +23 -0
  144. package/src/lib/skeleton/index.ts +2 -0
  145. package/src/lib/skeleton/skeleton.directive.spec.ts +63 -0
  146. package/src/lib/skeleton/skeleton.directive.ts +22 -0
  147. package/src/lib/skeleton/skeleton.variants.ts +27 -0
  148. package/src/lib/slider/index.ts +2 -0
  149. package/src/lib/slider/slider.component.spec.ts +104 -0
  150. package/src/lib/slider/slider.component.ts +188 -0
  151. package/src/lib/slider/slider.variants.ts +25 -0
  152. package/src/lib/stat/index.ts +8 -0
  153. package/src/lib/stat/stat.directives.spec.ts +60 -0
  154. package/src/lib/stat/stat.directives.ts +84 -0
  155. package/src/lib/status/index.ts +2 -0
  156. package/src/lib/status/status.directive.spec.ts +43 -0
  157. package/src/lib/status/status.directive.ts +38 -0
  158. package/src/lib/status/status.variants.ts +26 -0
  159. package/src/lib/steps/index.ts +8 -0
  160. package/src/lib/steps/steps.directives.spec.ts +52 -0
  161. package/src/lib/steps/steps.directives.ts +80 -0
  162. package/src/lib/switch/index.ts +2 -0
  163. package/src/lib/switch/switch.component.spec.ts +98 -0
  164. package/src/lib/switch/switch.component.ts +84 -0
  165. package/src/lib/switch/switch.variants.ts +31 -0
  166. package/src/lib/table/index.ts +12 -0
  167. package/src/lib/table/table.directives.spec.ts +111 -0
  168. package/src/lib/table/table.directives.ts +134 -0
  169. package/src/lib/table/table.variants.ts +36 -0
  170. package/src/lib/tabs/index.ts +8 -0
  171. package/src/lib/tabs/tabs.directives.spec.ts +136 -0
  172. package/src/lib/tabs/tabs.directives.ts +130 -0
  173. package/src/lib/tabs/tabs.variants.ts +17 -0
  174. package/src/lib/textarea/index.ts +7 -0
  175. package/src/lib/textarea/textarea.directive.spec.ts +84 -0
  176. package/src/lib/textarea/textarea.directive.ts +72 -0
  177. package/src/lib/textarea/textarea.variants.ts +34 -0
  178. package/src/lib/timeline/index.ts +11 -0
  179. package/src/lib/timeline/timeline.directives.spec.ts +55 -0
  180. package/src/lib/timeline/timeline.directives.ts +90 -0
  181. package/src/lib/toast/index.ts +3 -0
  182. package/src/lib/toast/toast.service.spec.ts +71 -0
  183. package/src/lib/toast/toast.service.ts +60 -0
  184. package/src/lib/toast/toast.variants.ts +38 -0
  185. package/src/lib/toast/toaster.component.spec.ts +38 -0
  186. package/src/lib/toast/toaster.component.ts +82 -0
  187. package/src/lib/toggle/index.ts +2 -0
  188. package/src/lib/toggle/toggle.directive.spec.ts +100 -0
  189. package/src/lib/toggle/toggle.directive.ts +73 -0
  190. package/src/lib/toggle/toggle.variants.ts +25 -0
  191. package/src/lib/tooltip/index.ts +2 -0
  192. package/src/lib/tooltip/tooltip.directive.spec.ts +113 -0
  193. package/src/lib/tooltip/tooltip.directive.ts +131 -0
  194. package/src/lib/tooltip/tooltip.variants.ts +20 -0
  195. package/src/lib/validator/index.ts +5 -0
  196. package/src/lib/validator/validator.directives.spec.ts +47 -0
  197. package/src/lib/validator/validator.directives.ts +52 -0
  198. package/types/sonny-ui-core.d.ts +878 -11
@@ -0,0 +1,250 @@
1
+ import {
2
+ ChangeDetectionStrategy,
3
+ Component,
4
+ computed,
5
+ effect,
6
+ ElementRef,
7
+ forwardRef,
8
+ HostListener,
9
+ inject,
10
+ input,
11
+ model,
12
+ OnDestroy,
13
+ signal,
14
+ viewChild,
15
+ } from '@angular/core';
16
+ import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
17
+ import { cn } from '../core/utils/cn';
18
+ import { selectTriggerVariants, type SelectSize } from './select.variants';
19
+
20
+ export interface SelectOption {
21
+ value: string;
22
+ label: string;
23
+ }
24
+
25
+ @Component({
26
+ selector: 'sny-select',
27
+ standalone: true,
28
+ changeDetection: ChangeDetectionStrategy.OnPush,
29
+ host: {
30
+ class: 'relative inline-block w-full',
31
+ },
32
+ providers: [
33
+ { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => SnySelectComponent), multi: true },
34
+ ],
35
+ template: `
36
+ <button
37
+ #triggerEl
38
+ type="button"
39
+ role="combobox"
40
+ [attr.aria-expanded]="open()"
41
+ aria-haspopup="listbox"
42
+ [disabled]="isDisabled()"
43
+ [class]="triggerClass()"
44
+ (click)="toggle()"
45
+ (keydown)="onTriggerKeydown($event)"
46
+ (blur)="onTouched()"
47
+ >
48
+ <span [class]="selectedLabel() ? '' : 'text-muted-foreground'">
49
+ {{ selectedLabel() || placeholder() }}
50
+ </span>
51
+ <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="shrink-0 opacity-50"><path d="m6 9 6 6 6-6"/></svg>
52
+ </button>
53
+
54
+ @if (open()) {
55
+ <div
56
+ #dropdownEl
57
+ class="fixed z-50 rounded-sm border border-border bg-popover text-popover-foreground shadow-md"
58
+ >
59
+ <ul role="listbox" class="max-h-60 overflow-auto p-1">
60
+ @for (opt of options(); track opt.value; let i = $index) {
61
+ <li
62
+ role="option"
63
+ [attr.aria-selected]="value() === opt.value"
64
+ [class]="optionClass(i)"
65
+ (mousedown)="select(opt); $event.preventDefault()"
66
+ (mouseenter)="activeIndex.set(i)"
67
+ >
68
+ <svg
69
+ xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"
70
+ fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
71
+ [class]="value() === opt.value ? 'mr-2 shrink-0 opacity-100' : 'mr-2 shrink-0 opacity-0'"
72
+ ><path d="M20 6 9 17l-5-5"/></svg>
73
+ {{ opt.label }}
74
+ </li>
75
+ }
76
+ </ul>
77
+ </div>
78
+ }
79
+ `,
80
+ })
81
+ export class SnySelectComponent implements ControlValueAccessor, OnDestroy {
82
+ readonly options = input<SelectOption[]>([]);
83
+ readonly placeholder = input('Select...');
84
+ readonly size = input<SelectSize>('md');
85
+ readonly disabled = input(false);
86
+ readonly class = input<string>('');
87
+ readonly value = model<string>('');
88
+
89
+ readonly open = signal(false);
90
+ readonly activeIndex = signal(0);
91
+
92
+ private readonly _disabledByCva = signal(false);
93
+ protected readonly isDisabled = computed(() => this.disabled() || this._disabledByCva());
94
+
95
+ private readonly triggerRef = viewChild<ElementRef<HTMLButtonElement>>('triggerEl');
96
+ private readonly dropdownRef = viewChild<ElementRef<HTMLDivElement>>('dropdownEl');
97
+ private readonly elRef = inject(ElementRef);
98
+
99
+ private scrollHandler: (() => void) | null = null;
100
+ private resizeHandler: (() => void) | null = null;
101
+
102
+ private _onChange: (value: string) => void = () => {};
103
+ protected onTouched: () => void = () => {};
104
+ private _writing = false;
105
+
106
+ constructor() {
107
+ effect(() => {
108
+ const val = this.value();
109
+ if (this._writing) {
110
+ this._writing = false;
111
+ return;
112
+ }
113
+ this._onChange(val);
114
+ });
115
+ }
116
+
117
+ writeValue(val: string): void {
118
+ this._writing = true;
119
+ this.value.set(val ?? '');
120
+ }
121
+
122
+ registerOnChange(fn: (value: string) => void): void {
123
+ this._onChange = fn;
124
+ }
125
+
126
+ registerOnTouched(fn: () => void): void {
127
+ this.onTouched = fn;
128
+ }
129
+
130
+ setDisabledState(isDisabled: boolean): void {
131
+ this._disabledByCva.set(isDisabled);
132
+ }
133
+
134
+ readonly selectedLabel = computed(() => {
135
+ const v = this.value();
136
+ if (!v) return '';
137
+ const opt = this.options().find(o => o.value === v);
138
+ return opt?.label ?? '';
139
+ });
140
+
141
+ protected readonly triggerClass = computed(() =>
142
+ cn(selectTriggerVariants({ size: this.size() }), this.class())
143
+ );
144
+
145
+ optionClass(index: number): string {
146
+ const base = 'relative flex cursor-pointer select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors';
147
+ const active = index === this.activeIndex() ? 'bg-accent text-accent-foreground' : 'hover:bg-accent/50';
148
+ return cn(base, active);
149
+ }
150
+
151
+ private updateDropdownPosition(): void {
152
+ const trigger = this.triggerRef()?.nativeElement;
153
+ if (!trigger) return;
154
+ const rect = trigger.getBoundingClientRect();
155
+ const dropdown = this.dropdownRef()?.nativeElement;
156
+ if (dropdown) {
157
+ dropdown.style.top = `${rect.bottom + 4}px`;
158
+ dropdown.style.left = `${rect.left}px`;
159
+ dropdown.style.width = `${rect.width}px`;
160
+ }
161
+ }
162
+
163
+ private addGlobalListeners(): void {
164
+ this.removeGlobalListeners();
165
+ this.scrollHandler = () => {
166
+ requestAnimationFrame(() => this.updateDropdownPosition());
167
+ };
168
+ this.resizeHandler = () => {
169
+ requestAnimationFrame(() => this.updateDropdownPosition());
170
+ };
171
+ document.addEventListener('scroll', this.scrollHandler, { capture: true, passive: true });
172
+ window.addEventListener('resize', this.resizeHandler, { passive: true });
173
+ }
174
+
175
+ private removeGlobalListeners(): void {
176
+ if (this.scrollHandler) {
177
+ document.removeEventListener('scroll', this.scrollHandler, { capture: true } as EventListenerOptions);
178
+ this.scrollHandler = null;
179
+ }
180
+ if (this.resizeHandler) {
181
+ window.removeEventListener('resize', this.resizeHandler);
182
+ this.resizeHandler = null;
183
+ }
184
+ }
185
+
186
+ ngOnDestroy(): void {
187
+ this.removeGlobalListeners();
188
+ }
189
+
190
+ toggle(): void {
191
+ if (this.open()) {
192
+ this.close();
193
+ } else {
194
+ this.open.set(true);
195
+ this.activeIndex.set(
196
+ Math.max(0, this.options().findIndex(o => o.value === this.value()))
197
+ );
198
+ this.addGlobalListeners();
199
+ setTimeout(() => this.updateDropdownPosition());
200
+ }
201
+ }
202
+
203
+ close(): void {
204
+ this.open.set(false);
205
+ this.removeGlobalListeners();
206
+ }
207
+
208
+ select(opt: SelectOption): void {
209
+ this.value.set(opt.value);
210
+ this.close();
211
+ }
212
+
213
+ onTriggerKeydown(event: KeyboardEvent): void {
214
+ const items = this.options();
215
+ if (!this.open()) {
216
+ if (event.key === 'ArrowDown' || event.key === 'Enter' || event.key === ' ') {
217
+ event.preventDefault();
218
+ this.toggle();
219
+ }
220
+ return;
221
+ }
222
+ switch (event.key) {
223
+ case 'ArrowDown':
224
+ event.preventDefault();
225
+ this.activeIndex.update(i => Math.min(i + 1, items.length - 1));
226
+ break;
227
+ case 'ArrowUp':
228
+ event.preventDefault();
229
+ this.activeIndex.update(i => Math.max(i - 1, 0));
230
+ break;
231
+ case 'Enter':
232
+ case ' ':
233
+ event.preventDefault();
234
+ if (items[this.activeIndex()]) {
235
+ this.select(items[this.activeIndex()]);
236
+ }
237
+ break;
238
+ case 'Escape':
239
+ this.close();
240
+ break;
241
+ }
242
+ }
243
+
244
+ @HostListener('document:click', ['$event'])
245
+ onDocumentClick(event: MouseEvent): void {
246
+ if (!this.elRef.nativeElement.contains(event.target)) {
247
+ this.close();
248
+ }
249
+ }
250
+ }
@@ -0,0 +1,19 @@
1
+ import { cva } from 'class-variance-authority';
2
+
3
+ export const selectTriggerVariants = cva(
4
+ 'inline-flex w-full items-center justify-between whitespace-nowrap rounded-sm border border-border bg-background px-3 py-2 text-sm ring-offset-background transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50',
5
+ {
6
+ variants: {
7
+ size: {
8
+ sm: 'h-9 text-xs',
9
+ md: 'h-10 text-sm',
10
+ lg: 'h-11 text-base',
11
+ },
12
+ },
13
+ defaultVariants: {
14
+ size: 'md',
15
+ },
16
+ }
17
+ );
18
+
19
+ export type SelectSize = 'sm' | 'md' | 'lg';
@@ -0,0 +1,10 @@
1
+ export { SnySheetService, SNY_SHEET_DATA } from './sheet.service';
2
+ export { SnySheetRef } from './sheet-ref';
3
+ export {
4
+ SnySheetHeaderDirective,
5
+ SnySheetTitleDirective,
6
+ SnySheetDescriptionDirective,
7
+ SnySheetContentDirective,
8
+ SnySheetCloseDirective,
9
+ } from './sheet.directives';
10
+ export { type SnySheetConfig, type SheetSide } from './sheet.types';
@@ -0,0 +1,18 @@
1
+ import type { Observable } from 'rxjs';
2
+
3
+ interface CdkDialogRefLike<R> {
4
+ close(result?: R): void;
5
+ readonly closed: Observable<R | undefined>;
6
+ }
7
+
8
+ export class SnySheetRef<R = unknown> {
9
+ constructor(private readonly cdkRef: CdkDialogRefLike<R>) {}
10
+
11
+ close(result?: R): void {
12
+ this.cdkRef.close(result);
13
+ }
14
+
15
+ get closed(): Observable<R | undefined> {
16
+ return this.cdkRef.closed;
17
+ }
18
+ }
@@ -0,0 +1,67 @@
1
+ import { Component, inject } from '@angular/core';
2
+ import { TestBed } from '@angular/core/testing';
3
+ import { DialogModule, DialogRef } from '@angular/cdk/dialog';
4
+ import { SnySheetService } from './sheet.service';
5
+ import {
6
+ SnySheetHeaderDirective,
7
+ SnySheetTitleDirective,
8
+ SnySheetDescriptionDirective,
9
+ SnySheetCloseDirective,
10
+ } from './sheet.directives';
11
+ import { SnyButtonDirective } from '../button/button.directive';
12
+
13
+ @Component({
14
+ standalone: true,
15
+ imports: [
16
+ SnySheetHeaderDirective,
17
+ SnySheetTitleDirective,
18
+ SnySheetDescriptionDirective,
19
+ SnySheetCloseDirective,
20
+ SnyButtonDirective,
21
+ ],
22
+ template: `
23
+ <div>
24
+ <div snySheetHeader>
25
+ <h2 snySheetTitle>Test Sheet</h2>
26
+ <p snySheetDescription>A test sheet.</p>
27
+ </div>
28
+ <button snySheetClose aria-label="Close">X</button>
29
+ <button snyBtn (click)="dialogRef.close('done')">Done</button>
30
+ </div>
31
+ `,
32
+ })
33
+ class TestSheetComponent {
34
+ readonly dialogRef = inject(DialogRef);
35
+ }
36
+
37
+ describe('SnySheetService', () => {
38
+ let service: SnySheetService;
39
+
40
+ beforeEach(async () => {
41
+ await TestBed.configureTestingModule({
42
+ imports: [DialogModule],
43
+ }).compileComponents();
44
+
45
+ service = TestBed.inject(SnySheetService);
46
+ });
47
+
48
+ it('should be created', () => {
49
+ expect(service).toBeTruthy();
50
+ });
51
+
52
+ it('should open a sheet', () => {
53
+ const ref = service.open(TestSheetComponent, { side: 'right' });
54
+ expect(ref).toBeTruthy();
55
+ ref.close();
56
+ });
57
+
58
+ it('should open from different sides', () => {
59
+ const refLeft = service.open(TestSheetComponent, { side: 'left' });
60
+ expect(refLeft).toBeTruthy();
61
+ refLeft.close();
62
+
63
+ const refTop = service.open(TestSheetComponent, { side: 'top' });
64
+ expect(refTop).toBeTruthy();
65
+ refTop.close();
66
+ });
67
+ });
@@ -0,0 +1,75 @@
1
+ import { Directive, computed, input, inject } from '@angular/core';
2
+ import { DialogRef } from '@angular/cdk/dialog';
3
+ import { cn } from '../core/utils/cn';
4
+
5
+ @Directive({
6
+ selector: '[snySheetHeader]',
7
+ standalone: true,
8
+ host: { '[class]': 'computedClass()' },
9
+ })
10
+ export class SnySheetHeaderDirective {
11
+ readonly class = input<string>('');
12
+ protected readonly computedClass = computed(() =>
13
+ cn('flex flex-col space-y-2', this.class())
14
+ );
15
+ }
16
+
17
+ @Directive({
18
+ selector: '[snySheetTitle]',
19
+ standalone: true,
20
+ host: { '[class]': 'computedClass()' },
21
+ })
22
+ export class SnySheetTitleDirective {
23
+ readonly class = input<string>('');
24
+ protected readonly computedClass = computed(() =>
25
+ cn('text-lg font-semibold text-foreground', this.class())
26
+ );
27
+ }
28
+
29
+ @Directive({
30
+ selector: '[snySheetDescription]',
31
+ standalone: true,
32
+ host: { '[class]': 'computedClass()' },
33
+ })
34
+ export class SnySheetDescriptionDirective {
35
+ readonly class = input<string>('');
36
+ protected readonly computedClass = computed(() =>
37
+ cn('text-sm text-muted-foreground', this.class())
38
+ );
39
+ }
40
+
41
+ @Directive({
42
+ selector: '[snySheetContent]',
43
+ standalone: true,
44
+ host: { '[class]': 'computedClass()' },
45
+ })
46
+ export class SnySheetContentDirective {
47
+ readonly class = input<string>('');
48
+ protected readonly computedClass = computed(() =>
49
+ cn('py-4', this.class())
50
+ );
51
+ }
52
+
53
+ @Directive({
54
+ selector: '[snySheetClose]',
55
+ standalone: true,
56
+ host: {
57
+ '[class]': 'computedClass()',
58
+ '(click)': 'onClick()',
59
+ },
60
+ })
61
+ export class SnySheetCloseDirective {
62
+ readonly class = input<string>('');
63
+ protected readonly computedClass = computed(() =>
64
+ cn(
65
+ 'absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2',
66
+ this.class()
67
+ )
68
+ );
69
+
70
+ private readonly dialogRef = inject(DialogRef, { optional: true });
71
+
72
+ onClick(): void {
73
+ this.dialogRef?.close();
74
+ }
75
+ }
@@ -0,0 +1,100 @@
1
+ import { Injectable, inject, InjectionToken, Injector } from '@angular/core';
2
+ import { Dialog, DialogRef as CdkDialogRef } from '@angular/cdk/dialog';
3
+ import { type ComponentType, createGlobalPositionStrategy, type GlobalPositionStrategy } from '@angular/cdk/overlay';
4
+ import { SnySheetRef } from './sheet-ref';
5
+ import { DEFAULT_SHEET_CONFIG, SHEET_PANEL_CLASS, type SheetSide, type SnySheetConfig } from './sheet.types';
6
+
7
+ export const SNY_SHEET_DATA = new InjectionToken<unknown>('SNY_SHEET_DATA');
8
+
9
+ interface SheetOverlayConfig {
10
+ positionStrategy: GlobalPositionStrategy;
11
+ width?: string;
12
+ maxWidth?: string;
13
+ height?: string;
14
+ maxHeight?: string;
15
+ }
16
+
17
+ @Injectable({ providedIn: 'root' })
18
+ export class SnySheetService {
19
+ private readonly cdkDialog = inject(Dialog);
20
+ private readonly injector = inject(Injector);
21
+
22
+ open<T, R = unknown>(component: ComponentType<T>, config: SnySheetConfig = {}): SnySheetRef<R> {
23
+ const merged = { ...DEFAULT_SHEET_CONFIG, ...config };
24
+ const side = merged.side ?? 'right';
25
+ const disableClose = !merged.closeOnBackdrop || !merged.closeOnEsc;
26
+ const overlay = this._getOverlayConfig(side);
27
+
28
+ const cdkRef: CdkDialogRef<R, T> = this.cdkDialog.open(component, {
29
+ disableClose,
30
+ hasBackdrop: true,
31
+ backdropClass: 'sny-dialog-backdrop',
32
+ panelClass: ['sny-sheet-panel', SHEET_PANEL_CLASS[side]],
33
+ positionStrategy: overlay.positionStrategy,
34
+ width: overlay.width,
35
+ maxWidth: overlay.maxWidth,
36
+ height: overlay.height,
37
+ maxHeight: overlay.maxHeight,
38
+ ariaLabelledBy: merged.ariaLabelledBy,
39
+ ariaDescribedBy: merged.ariaDescribedBy,
40
+ data: merged.data,
41
+ providers: merged.data != null
42
+ ? [{ provide: SNY_SHEET_DATA, useValue: merged.data }]
43
+ : [],
44
+ });
45
+
46
+ if (disableClose) {
47
+ if (merged.closeOnBackdrop) {
48
+ const sub = cdkRef.backdropClick.subscribe(() => cdkRef.close());
49
+ cdkRef.closed.subscribe(() => sub.unsubscribe());
50
+ }
51
+ if (merged.closeOnEsc) {
52
+ const sub = cdkRef.keydownEvents.subscribe(event => {
53
+ if (event.key === 'Escape') cdkRef.close();
54
+ });
55
+ cdkRef.closed.subscribe(() => sub.unsubscribe());
56
+ }
57
+ }
58
+
59
+ return new SnySheetRef<R>(cdkRef);
60
+ }
61
+
62
+ closeAll(): void {
63
+ this.cdkDialog.closeAll();
64
+ }
65
+
66
+ private _getOverlayConfig(side: SheetSide): SheetOverlayConfig {
67
+ const strategy = createGlobalPositionStrategy(this.injector);
68
+
69
+ switch (side) {
70
+ case 'right':
71
+ return {
72
+ positionStrategy: strategy.top('0').right('0'),
73
+ width: '75%',
74
+ maxWidth: '24rem',
75
+ height: '100vh',
76
+ maxHeight: '100vh',
77
+ };
78
+ case 'left':
79
+ return {
80
+ positionStrategy: strategy.top('0').left('0'),
81
+ width: '75%',
82
+ maxWidth: '24rem',
83
+ height: '100vh',
84
+ maxHeight: '100vh',
85
+ };
86
+ case 'top':
87
+ return {
88
+ positionStrategy: strategy.top('0').centerHorizontally(),
89
+ width: '100vw',
90
+ maxWidth: '100vw',
91
+ };
92
+ case 'bottom':
93
+ return {
94
+ positionStrategy: strategy.bottom('0').centerHorizontally(),
95
+ width: '100vw',
96
+ maxWidth: '100vw',
97
+ };
98
+ }
99
+ }
100
+ }
@@ -0,0 +1,23 @@
1
+ export type SheetSide = 'left' | 'right' | 'top' | 'bottom';
2
+
3
+ export interface SnySheetConfig {
4
+ side?: SheetSide;
5
+ closeOnBackdrop?: boolean;
6
+ closeOnEsc?: boolean;
7
+ data?: unknown;
8
+ ariaLabelledBy?: string;
9
+ ariaDescribedBy?: string;
10
+ }
11
+
12
+ export const DEFAULT_SHEET_CONFIG: SnySheetConfig = {
13
+ side: 'right',
14
+ closeOnBackdrop: true,
15
+ closeOnEsc: true,
16
+ };
17
+
18
+ export const SHEET_PANEL_CLASS: Record<SheetSide, string> = {
19
+ right: 'sny-sheet-right',
20
+ left: 'sny-sheet-left',
21
+ top: 'sny-sheet-top',
22
+ bottom: 'sny-sheet-bottom',
23
+ };
@@ -0,0 +1,2 @@
1
+ export { SnySkeletonDirective } from './skeleton.directive';
2
+ export { skeletonVariants, type SkeletonVariant, type SkeletonSize } from './skeleton.variants';
@@ -0,0 +1,63 @@
1
+ import { Component, signal } from '@angular/core';
2
+ import { TestBed, ComponentFixture } from '@angular/core/testing';
3
+ import { SnySkeletonDirective } from './skeleton.directive';
4
+ import type { SkeletonVariant, SkeletonSize } from './skeleton.variants';
5
+
6
+ @Component({
7
+ standalone: true,
8
+ imports: [SnySkeletonDirective],
9
+ template: `<div snySkeleton [variant]="variant()" [size]="size()"></div>`,
10
+ })
11
+ class TestHostComponent {
12
+ variant = signal<SkeletonVariant>('line');
13
+ size = signal<SkeletonSize>('md');
14
+ }
15
+
16
+ describe('SnySkeletonDirective', () => {
17
+ let fixture: ComponentFixture<TestHostComponent>;
18
+ let el: HTMLElement;
19
+
20
+ beforeEach(async () => {
21
+ await TestBed.configureTestingModule({
22
+ imports: [TestHostComponent],
23
+ }).compileComponents();
24
+
25
+ fixture = TestBed.createComponent(TestHostComponent);
26
+ fixture.detectChanges();
27
+ el = fixture.nativeElement.querySelector('div');
28
+ });
29
+
30
+ it('should apply default classes', () => {
31
+ expect(el.className).toContain('animate-pulse');
32
+ expect(el.className).toContain('bg-muted');
33
+ expect(el.className).toContain('rounded-sm');
34
+ expect(el.className).toContain('h-6');
35
+ });
36
+
37
+ it('should apply circular variant', () => {
38
+ fixture.componentInstance.variant.set('circular');
39
+ fixture.detectChanges();
40
+ expect(el.className).toContain('rounded-full');
41
+ expect(el.className).toContain('aspect-square');
42
+ });
43
+
44
+ it('should apply sm size', () => {
45
+ fixture.componentInstance.size.set('sm');
46
+ fixture.detectChanges();
47
+ expect(el.className).toContain('h-4');
48
+ });
49
+
50
+ it('should apply xl size', () => {
51
+ fixture.componentInstance.size.set('xl');
52
+ fixture.detectChanges();
53
+ expect(el.className).toContain('h-12');
54
+ });
55
+
56
+ it('should have aria-busy="true"', () => {
57
+ expect(el.getAttribute('aria-busy')).toBe('true');
58
+ });
59
+
60
+ it('should have aria-hidden="true"', () => {
61
+ expect(el.getAttribute('aria-hidden')).toBe('true');
62
+ });
63
+ });
@@ -0,0 +1,22 @@
1
+ import { Directive, computed, input } from '@angular/core';
2
+ import { cn } from '../core/utils/cn';
3
+ import { skeletonVariants, type SkeletonVariant, type SkeletonSize } from './skeleton.variants';
4
+
5
+ @Directive({
6
+ selector: '[snySkeleton]',
7
+ standalone: true,
8
+ host: {
9
+ '[class]': 'computedClass()',
10
+ 'aria-busy': 'true',
11
+ 'aria-hidden': 'true',
12
+ },
13
+ })
14
+ export class SnySkeletonDirective {
15
+ readonly variant = input<SkeletonVariant>('line');
16
+ readonly size = input<SkeletonSize>('md');
17
+ readonly class = input<string>('');
18
+
19
+ protected readonly computedClass = computed(() =>
20
+ cn(skeletonVariants({ variant: this.variant(), size: this.size() }), this.class())
21
+ );
22
+ }
@@ -0,0 +1,27 @@
1
+ import { cva } from 'class-variance-authority';
2
+
3
+ export const skeletonVariants = cva(
4
+ 'animate-pulse bg-muted block',
5
+ {
6
+ variants: {
7
+ variant: {
8
+ line: 'rounded-sm',
9
+ circular: 'rounded-full aspect-square',
10
+ rounded: 'rounded-lg',
11
+ },
12
+ size: {
13
+ sm: 'h-4',
14
+ md: 'h-6',
15
+ lg: 'h-8',
16
+ xl: 'h-12',
17
+ },
18
+ },
19
+ defaultVariants: {
20
+ variant: 'line',
21
+ size: 'md',
22
+ },
23
+ }
24
+ );
25
+
26
+ export type SkeletonVariant = 'line' | 'circular' | 'rounded';
27
+ export type SkeletonSize = 'sm' | 'md' | 'lg' | 'xl';
@@ -0,0 +1,2 @@
1
+ export { SnySliderComponent } from './slider.component';
2
+ export { sliderTrackVariants, type SliderSize } from './slider.variants';