@jdpo2008/ngx-ds 0.1.0 → 0.2.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 CHANGED
@@ -4,15 +4,25 @@ An Angular 21 component library: standalone components, a signal-based API, `OnP
4
4
 
5
5
  ## Install
6
6
 
7
+ ```bash
8
+ ng add @jdpo2008/ngx-ds
9
+ ```
10
+
11
+ `ng add` installs the package and `lucide-angular`, and adds the design tokens stylesheet to the `styles` of your application in `angular.json`. In a workspace with several applications, pass `--project <name>`.
12
+
13
+ To set it up by hand instead:
14
+
7
15
  ```bash
8
16
  npm install @jdpo2008/ngx-ds lucide-angular
9
17
  ```
10
18
 
19
+ then load the stylesheet as described in [Styles](#styles).
20
+
11
21
  Peer dependencies: `@angular/common`, `@angular/core`, `@angular/forms` and `@angular/platform-browser` 21, and `lucide-angular` 1.
12
22
 
13
23
  ## Styles
14
24
 
15
- Load the design tokens once, globally. Add the stylesheet to `angular.json`:
25
+ `ng add` does this for you. Otherwise, load the design tokens once, globally. Add the stylesheet to `angular.json`:
16
26
 
17
27
  ```json
18
28
  "styles": ["node_modules/@jdpo2008/ngx-ds/styles/ngx-ds.scss", "src/styles.scss"]
@@ -36,7 +46,7 @@ Every color is a CSS custom property (`--primary-600`, `--text-base`, `--surface
36
46
  }
37
47
  ```
38
48
 
39
- The dark theme is opt-in. Set `data-theme="dark"` on `<html>` or add the `dark` class to an ancestor.
49
+ The dark theme is opt-in. Set `data-theme="dark"` on `<html>`, add the `dark` class to an ancestor, or use the `theme` option of `provideNgxDs()` (see [Configuration](#configuration)).
40
50
 
41
51
  ## Usage
42
52
 
@@ -62,6 +72,23 @@ export class AppComponent {
62
72
 
63
73
  Form controls (Input, Select, Checkbox, Datepicker, …) implement `ControlValueAccessor`, so they also work with `ngModel` and reactive forms. SearchInput is the exception: bind it with `[(value)]`.
64
74
 
75
+ They also work with Signal Forms (`@angular/forms/signals`, experimental in Angular 21). Bind them with `[formField]`:
76
+
77
+ ```ts
78
+ import { FormField, form, required } from '@angular/forms/signals';
79
+
80
+ @Component({
81
+ imports: [FormField, InputComponent],
82
+ template: `<ngx-ds-input label="Name" [formField]="f.name" />`,
83
+ })
84
+ export class Profile {
85
+ model = signal({ name: '' });
86
+ f = form(this.model, (p) => required(p.name));
87
+ }
88
+ ```
89
+
90
+ The field's value, touched and disabled state stay in sync. The field's `min` and `max` validators also set the limits of NumberInput and RangeSlider, and `max` sets the star count of Rating. Error messages are not shown automatically: pass them with `[errorMessage]`.
91
+
65
92
  ### Toasts and confirmations
66
93
 
67
94
  Place the hosts once, usually in the root component, and trigger them from the services:
@@ -84,18 +111,26 @@ const ok = await confirmation.confirm({
84
111
  });
85
112
  ```
86
113
 
87
- ### Language
114
+ ### Configuration
88
115
 
89
- Labels default to Spanish and dates to `es-ES`. To switch app-wide:
116
+ Labels default to Spanish and dates to `es-ES`. Configure the library app-wide with `provideNgxDs()`:
90
117
 
91
118
  ```ts
92
- import { NGX_DS_LABELS_EN, provideNgxDsLabels, provideNgxDsLocale } from '@jdpo2008/ngx-ds';
119
+ import { provideNgxDs } from '@jdpo2008/ngx-ds';
93
120
 
94
121
  bootstrapApplication(AppComponent, {
95
- providers: [provideNgxDsLabels(NGX_DS_LABELS_EN), provideNgxDsLocale('en-US')],
122
+ providers: [provideNgxDs({ locale: 'en-US', labels: { close: 'Dismiss' }, theme: 'system' })],
96
123
  });
97
124
  ```
98
125
 
126
+ | Option | Default | Effect |
127
+ | -------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
128
+ | `locale` | `'es-ES'` | Month and weekday names, date and number formatting. An `en-*` locale also switches the labels to English. |
129
+ | `labels` | — | Overrides individual labels. Missing keys come from the locale's set. |
130
+ | `theme` | — | `'light'`, `'dark'` or `'system'` (follows `prefers-color-scheme` and updates live). Sets `data-theme` on `<html>`. Omit it to manage the theme yourself. |
131
+
132
+ `provideNgxDsLocale()` and `provideNgxDsLabels()` still work for setting one thing at a time.
133
+
99
134
  ## Components
100
135
 
101
136
  - **Atoms:** Avatar, Badge, Button, Divider, Icon, IconButton, Kbd, MenuButton, ProgressBar, Skeleton, Spinner, Tag, Tooltip.
@@ -1,6 +1,6 @@
1
1
  import * as i0 from '@angular/core';
2
- import { signal, Injectable, InjectionToken, inject, ElementRef, Directive, input, ChangeDetectionStrategy, Component, computed, output, ViewEncapsulation, ApplicationRef, EnvironmentInjector, createComponent, model, forwardRef, Renderer2, DestroyRef, viewChild, Injector, afterNextRender, effect, untracked, viewChildren, contentChildren, afterRenderEffect, TemplateRef, contentChild, linkedSignal } from '@angular/core';
3
- import { DOCUMENT, CommonModule, NgTemplateOutlet } from '@angular/common';
2
+ import { signal, Injectable, InjectionToken, inject, provideAppInitializer, makeEnvironmentProviders, DOCUMENT, DestroyRef, ElementRef, Directive, input, ChangeDetectionStrategy, Component, computed, output, ViewEncapsulation, ApplicationRef, EnvironmentInjector, createComponent, model, forwardRef, Renderer2, viewChild, Injector, afterNextRender, effect, untracked, viewChildren, contentChildren, afterRenderEffect, TemplateRef, contentChild, linkedSignal } from '@angular/core';
3
+ import { DOCUMENT as DOCUMENT$1, CommonModule, NgTemplateOutlet } from '@angular/common';
4
4
  import * as i1 from 'lucide-angular';
5
5
  import { LucideAngularModule, X, EyeOff, Eye, ChevronDown, ChevronUp, Check, Search, Calendar, ChevronLeft, ChevronRight, AlertCircle, AlertTriangle, CheckCircle2, Info, Upload, FileImage, FileVideo, FileText, File, Plus, Minus, Star, Columns3, MoreVertical, ArrowUpDown, ArrowDown, ArrowUp, Inbox, CheckCircle, Bell, BellOff, PanelLeftOpen, PanelLeftClose } from 'lucide-angular';
6
6
  import { NG_VALUE_ACCESSOR } from '@angular/forms';
@@ -348,6 +348,45 @@ function formatDayLabel(date, locale) {
348
348
  return date.toLocaleDateString(locale, { day: 'numeric', month: 'long', year: 'numeric' });
349
349
  }
350
350
 
351
+ /**
352
+ * Configures ngx-ds in one call:
353
+ *
354
+ * ```ts
355
+ * bootstrapApplication(AppComponent, {
356
+ * providers: [provideNgxDs({ locale: 'en-US', theme: 'system' })],
357
+ * });
358
+ * ```
359
+ */
360
+ function provideNgxDs(config = {}) {
361
+ const { locale, labels, theme } = config;
362
+ const providers = [];
363
+ if (locale)
364
+ providers.push(provideNgxDsLocale(locale));
365
+ if (locale || labels) {
366
+ const base = locale?.toLowerCase().startsWith('en') ? NGX_DS_LABELS_EN : NGX_DS_LABELS_ES;
367
+ providers.push(provideNgxDsLabels(labels ?? {}, base));
368
+ }
369
+ if (theme)
370
+ providers.push(provideAppInitializer(() => applyTheme(theme)));
371
+ return makeEnvironmentProviders(providers);
372
+ }
373
+ function applyTheme(theme) {
374
+ const doc = inject(DOCUMENT);
375
+ const root = doc.documentElement;
376
+ if (theme !== 'system') {
377
+ root.setAttribute('data-theme', theme);
378
+ return;
379
+ }
380
+ // matchMedia is missing during SSR; the browser applies the theme on hydration.
381
+ const query = doc.defaultView?.matchMedia?.('(prefers-color-scheme: dark)');
382
+ if (!query)
383
+ return;
384
+ const sync = () => root.setAttribute('data-theme', query.matches ? 'dark' : 'light');
385
+ sync();
386
+ query.addEventListener('change', sync);
387
+ inject(DestroyRef).onDestroy(() => query.removeEventListener('change', sync));
388
+ }
389
+
351
390
  const FOCUSABLE_SELECTOR = [
352
391
  'a[href]',
353
392
  'button:not([disabled])',
@@ -363,7 +402,7 @@ const FOCUSABLE_SELECTOR = [
363
402
  */
364
403
  class FocusTrapDirective {
365
404
  el = inject((ElementRef));
366
- doc = inject(DOCUMENT);
405
+ doc = inject(DOCUMENT$1);
367
406
  previouslyFocused = null;
368
407
  ngAfterViewInit() {
369
408
  this.previouslyFocused = this.doc.activeElement;
@@ -720,7 +759,7 @@ class TooltipDirective {
720
759
  el = inject((ElementRef));
721
760
  appRef = inject(ApplicationRef);
722
761
  envInjector = inject(EnvironmentInjector);
723
- doc = inject(DOCUMENT);
762
+ doc = inject(DOCUMENT$1);
724
763
  ngxTooltip = input('', ...(ngDevMode ? [{ debugName: "ngxTooltip" }] : /* istanbul ignore next */ []));
725
764
  tooltipPlacement = input('top', ...(ngDevMode ? [{ debugName: "tooltipPlacement" }] : /* istanbul ignore next */ []));
726
765
  tooltipDisabled = input(false, ...(ngDevMode ? [{ debugName: "tooltipDisabled" }] : /* istanbul ignore next */ []));
@@ -2770,8 +2809,9 @@ let nextId$7 = 0;
2770
2809
  class RangeSliderComponent {
2771
2810
  id = `ngx-range-slider-${nextId$7++}`;
2772
2811
  value = model(0, ...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
2773
- min = input(0, ...(ngDevMode ? [{ debugName: "min" }] : /* istanbul ignore next */ []));
2774
- max = input(100, ...(ngDevMode ? [{ debugName: "max" }] : /* istanbul ignore next */ []));
2812
+ // `undefined` is accepted so Signal Forms can bind the field's min/max.
2813
+ min = input(0, { ...(ngDevMode ? { debugName: "min" } : /* istanbul ignore next */ {}), transform: (v) => v ?? 0 });
2814
+ max = input(100, { ...(ngDevMode ? { debugName: "max" } : /* istanbul ignore next */ {}), transform: (v) => v ?? 100 });
2775
2815
  step = input(1, ...(ngDevMode ? [{ debugName: "step" }] : /* istanbul ignore next */ []));
2776
2816
  disabled = input(false, ...(ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []));
2777
2817
  label = input('', ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
@@ -3031,8 +3071,9 @@ let nextId$6 = 0;
3031
3071
  class NumberInputComponent {
3032
3072
  i18n = inject(NGX_DS_LABELS);
3033
3073
  value = model(0, ...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
3034
- min = input(null, ...(ngDevMode ? [{ debugName: "min" }] : /* istanbul ignore next */ []));
3035
- max = input(null, ...(ngDevMode ? [{ debugName: "max" }] : /* istanbul ignore next */ []));
3074
+ // `undefined` is accepted so Signal Forms can bind the field's min/max.
3075
+ min = input(null, { ...(ngDevMode ? { debugName: "min" } : /* istanbul ignore next */ {}), transform: (v) => v ?? null });
3076
+ max = input(null, { ...(ngDevMode ? { debugName: "max" } : /* istanbul ignore next */ {}), transform: (v) => v ?? null });
3036
3077
  step = input(1, ...(ngDevMode ? [{ debugName: "step" }] : /* istanbul ignore next */ []));
3037
3078
  size = input('md', ...(ngDevMode ? [{ debugName: "size" }] : /* istanbul ignore next */ []));
3038
3079
  label = input('', ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
@@ -3296,7 +3337,8 @@ const SIZES = { sm: 16, md: 22, lg: 28 };
3296
3337
  class RatingComponent {
3297
3338
  i18n = inject(NGX_DS_LABELS);
3298
3339
  value = model(0, ...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
3299
- max = input(5, ...(ngDevMode ? [{ debugName: "max" }] : /* istanbul ignore next */ []));
3340
+ // `undefined` is accepted so Signal Forms can bind the field's max.
3341
+ max = input(5, { ...(ngDevMode ? { debugName: "max" } : /* istanbul ignore next */ {}), transform: (v) => v ?? 5 });
3300
3342
  size = input('md', ...(ngDevMode ? [{ debugName: "size" }] : /* istanbul ignore next */ []));
3301
3343
  readonly = input(false, ...(ngDevMode ? [{ debugName: "readonly" }] : /* istanbul ignore next */ []));
3302
3344
  disabled = input(false, ...(ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []));
@@ -4594,7 +4636,7 @@ function formatDate(value, fmt) {
4594
4636
 
4595
4637
  class ModalComponent {
4596
4638
  i18n = inject(NGX_DS_LABELS);
4597
- doc = inject(DOCUMENT);
4639
+ doc = inject(DOCUMENT$1);
4598
4640
  icons = { X };
4599
4641
  // ── Inputs ───────────────────────────────────────────────────────────────
4600
4642
  open = model(false, ...(ngDevMode ? [{ debugName: "open" }] : /* istanbul ignore next */ []));
@@ -4781,7 +4823,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.12", ngImpo
4781
4823
 
4782
4824
  class DrawerComponent {
4783
4825
  i18n = inject(NGX_DS_LABELS);
4784
- doc = inject(DOCUMENT);
4826
+ doc = inject(DOCUMENT$1);
4785
4827
  icons = { X };
4786
4828
  // ── Inputs ───────────────────────────────────────────────────────────────
4787
4829
  open = model(false, ...(ngDevMode ? [{ debugName: "open" }] : /* istanbul ignore next */ []));
@@ -5480,7 +5522,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.12", ngImpo
5480
5522
  }], propDecorators: { user: [{ type: i0.Input, args: [{ isSignal: true, alias: "user", required: true }] }], actions: [{ type: i0.Input, args: [{ isSignal: true, alias: "actions", required: false }] }], placement: [{ type: i0.Input, args: [{ isSignal: true, alias: "placement", required: false }] }], size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: false }] }], actionClick: [{ type: i0.Output, args: ["actionClick"] }], popover: [{ type: i0.ViewChild, args: [i0.forwardRef(() => PopoverComponent), { isSignal: true }] }] } });
5481
5523
 
5482
5524
  class ContextMenuComponent {
5483
- doc = inject(DOCUMENT);
5525
+ doc = inject(DOCUMENT$1);
5484
5526
  items = input.required(...(ngDevMode ? [{ debugName: "items" }] : /* istanbul ignore next */ []));
5485
5527
  disabled = input(false, ...(ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []));
5486
5528
  size = input('md', ...(ngDevMode ? [{ debugName: "size" }] : /* istanbul ignore next */ []));
@@ -5588,5 +5630,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.12", ngImpo
5588
5630
  * Generated bundle index. Do not edit.
5589
5631
  */
5590
5632
 
5591
- export { ACCORDION_CONTROLLER, AccordionComponent, AccordionItemComponent, AlertComponent, AutocompleteComponent, AvatarComponent, AvatarGroupComponent, BadgeComponent, BreadcrumbComponent, ButtonComponent, ButtonGroupComponent, CalendarComponent, CardComponent, CheckboxComponent, ChipGroupComponent, ColorPickerComponent, CommandPaletteComponent, ConfirmationComponent, ConfirmationService, ContextMenuComponent, DateRangePickerComponent, DatepickerComponent, DividerComponent, DrawerComponent, DropdownComponent, EmptyStateComponent, FileUploadComponent, FocusTrapDirective, FormFieldComponent, IconButtonComponent, IconComponent, InputComponent, KbdComponent, MenuButtonComponent, MenuComponent, ModalComponent, MultiSelectComponent, NGX_DS_LABELS, NGX_DS_LABELS_EN, NGX_DS_LABELS_ES, NGX_DS_LOCALE, NotificationCenterComponent, NotificationItemComponent, NumberInputComponent, OtpInputComponent, PaginationComponent, PasswordStrengthComponent, PopoverComponent, ProgressBarComponent, RadioComponent, RangeSliderComponent, RatingComponent, SearchInputComponent, SegmentedControlComponent, SelectComponent, SidebarComponent, SkeletonComponent, SpinnerComponent, StepComponent, StepperComponent, SwitchComponent, TabComponent, TabContentDirective, TableComponent, TabsComponent, TagComponent, TextareaComponent, TimelineComponent, TimelineItemComponent, ToastComponent, ToastrService, TooltipDirective, TreeNodeComponent, TreeViewComponent, UserMenuComponent, formatDayLabel, monthNames, provideNgxDsLabels, provideNgxDsLocale, weekdayNames };
5633
+ export { ACCORDION_CONTROLLER, AccordionComponent, AccordionItemComponent, AlertComponent, AutocompleteComponent, AvatarComponent, AvatarGroupComponent, BadgeComponent, BreadcrumbComponent, ButtonComponent, ButtonGroupComponent, CalendarComponent, CardComponent, CheckboxComponent, ChipGroupComponent, ColorPickerComponent, CommandPaletteComponent, ConfirmationComponent, ConfirmationService, ContextMenuComponent, DateRangePickerComponent, DatepickerComponent, DividerComponent, DrawerComponent, DropdownComponent, EmptyStateComponent, FileUploadComponent, FocusTrapDirective, FormFieldComponent, IconButtonComponent, IconComponent, InputComponent, KbdComponent, MenuButtonComponent, MenuComponent, ModalComponent, MultiSelectComponent, NGX_DS_LABELS, NGX_DS_LABELS_EN, NGX_DS_LABELS_ES, NGX_DS_LOCALE, NotificationCenterComponent, NotificationItemComponent, NumberInputComponent, OtpInputComponent, PaginationComponent, PasswordStrengthComponent, PopoverComponent, ProgressBarComponent, RadioComponent, RangeSliderComponent, RatingComponent, SearchInputComponent, SegmentedControlComponent, SelectComponent, SidebarComponent, SkeletonComponent, SpinnerComponent, StepComponent, StepperComponent, SwitchComponent, TabComponent, TabContentDirective, TableComponent, TabsComponent, TagComponent, TextareaComponent, TimelineComponent, TimelineItemComponent, ToastComponent, ToastrService, TooltipDirective, TreeNodeComponent, TreeViewComponent, UserMenuComponent, formatDayLabel, monthNames, provideNgxDs, provideNgxDsLabels, provideNgxDsLocale, weekdayNames };
5592
5634
  //# sourceMappingURL=jdpo2008-ngx-ds.mjs.map