angular-tailwind-components 1.4.0 → 1.5.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
@@ -11,7 +11,7 @@ A comprehensive Angular component library built entirely with **Tailwind CSS v4*
11
11
  - ♿ **Accessible** — WCAG-compliant with proper ARIA roles and keyboard support
12
12
  - 🧪 **Tested** — Unit tests with Vitest
13
13
  - 📖 **Storybook** — Visual documentation for all components
14
- - 🎭 **Customizable** — Override theme tokens via Tailwind `@theme` directive
14
+ - 🎭 **Customizable** — **`defineTheme()`** for injection-token defaults and runtime semantic colors; optional CSS overrides via `@theme`
15
15
 
16
16
  ## Installation
17
17
 
@@ -30,10 +30,9 @@ Your consuming project must have **Tailwind CSS v4** configured. Add the library
30
30
  The published `styles/tailwind.css` scans the sibling `fesm2022` bundle plus library `.html` / `.ts` sources for development. You do **not** need a separate `@source` to `node_modules/.../fesm2022` in the consumer.
31
31
 
32
32
  The same import also pulls in:
33
-
34
- ```css
35
33
  @import 'tailwindcss';
36
- ```
34
+
35
+ So you don't need to import the base styles
37
36
 
38
37
  ## Quick Start
39
38
 
@@ -62,33 +61,112 @@ export class ExampleComponent {
62
61
  }
63
62
  ```
64
63
 
65
- ## Application configuration
64
+ ## Application configuration (`defineTheme`)
65
+
66
+ Use **`defineTheme`** from `angular-tailwind-components` as the single app-level entry: it registers **`EnvironmentProviders`** for optional **injection tokens** (`iconSize`, `datetimeLanguage`, `componentsSize`, `paginationSummary`) and, when you pass **`colors`**, an app initializer that applies semantic CSS variables on `document.documentElement` in the browser. Add **one** entry to `providers` without spreading.
66
67
 
67
- Register shared defaults for library injection tokens with **`provideTailwindComponents`**. Each property is optional; only set keys produce `Provider` entries (same effect as individual `{ provide: TAILWIND_…, useValue: … }`). The function returns **`EnvironmentProviders`** (`makeEnvironmentProviders`), so you add it as **one** entry in `providers` without the spread operator.
68
+ `TailwindDefineThemeConfig` extends **`TailwindComponentsConfig`** with an optional **`colors`** field.
69
+
70
+ ### Example (tokens + colors)
68
71
 
69
72
  ```typescript
70
73
  import { ApplicationConfig } from '@angular/core';
71
- import { provideTailwindComponents } from 'angular-tailwind-components';
74
+ import { defineTheme } from 'angular-tailwind-components';
72
75
 
73
76
  export const appConfig: ApplicationConfig = {
74
77
  providers: [
75
- provideTailwindComponents({
78
+ defineTheme({
76
79
  iconSize: 20,
77
80
  datetimeLanguage: 'it',
78
81
  componentsSize: 'md',
79
- paginationSummary: 'Visualizzati {start}-{end} di {total}'
82
+ paginationSummary: 'Visualizzati {start}-{end} di {total}',
83
+ colors: {
84
+ primary: 'violet', // Forma oggetto: { 600: '#4f46e5', 700: '#4338ca' }
85
+ danger: 'rose',
86
+ neutral: 'zinc'
87
+ }
80
88
  })
81
89
  ]
82
90
  };
83
91
  ```
84
92
 
93
+ ### Example: tokens only
94
+
95
+ ```typescript
96
+ providers: [
97
+ defineTheme({
98
+ iconSize: 20,
99
+ datetimeLanguage: 'it',
100
+ componentsSize: 'md',
101
+ paginationSummary: 'Items {start}-{end} of {total}'
102
+ })
103
+ ];
104
+ ```
105
+
106
+ ### Example: colors only
107
+
108
+ ```typescript
109
+ providers: [defineTheme({ colors: { primary: 'indigo', neutral: 'zinc' } })];
110
+ ```
111
+
112
+ ### Example: spread a shared config object
113
+
114
+ ```typescript
115
+ import { ApplicationConfig } from '@angular/core';
116
+ import { defineTheme, type TailwindComponentsConfig } from 'angular-tailwind-components';
117
+
118
+ const shared: TailwindComponentsConfig = {
119
+ componentsSize: 'md',
120
+ datetimeLanguage: 'it'
121
+ };
122
+
123
+ export const appConfig: ApplicationConfig = {
124
+ providers: [defineTheme({ ...shared, colors: { primary: 'indigo' } })]
125
+ };
126
+ ```
127
+
128
+ You can omit **`colors`** if you only need token defaults, or omit token keys if you only need theme colors.
129
+
85
130
  | Config key | Token |
86
131
  | --- | --- |
87
132
  | `iconSize` | `TAILWIND_ICON_SIZE` |
88
133
  | `datetimeLanguage` | `TAILWIND_DATETIME_LANGUAGE` |
89
134
  | `componentsSize` | `TAILWIND_COMPONENTS_SIZE` |
90
135
  | `paginationSummary` | `TAILWIND_PAGINATION_SUMMARY` |
91
- | `modalData` | `TAILWIND_MODAL_DATA` (rare at app scope; modal `open()` still supplies per-dialog data) |
136
+
137
+ **`provideTailwindComponents`** is still exported for backward compatibility (token providers only, same implementation as the token slice of `defineTheme`). It is **deprecated**; prefer **`defineTheme`**.
138
+
139
+ ## Theme colors (`defineTheme`)
140
+
141
+ The optional **`colors`** object remaps semantic design tokens (`primary`, `neutral`, `success`, `warning`, `danger`, `info`) at **runtime** using the same `--color-*` names as the library `@theme` block (for example `--color-primary-500`), so classes like `bg-primary-600` update without changing templates. Color application is a **no-op during SSR** (browser only).
142
+
143
+ | `colors` key | CSS variables | Default palette in `tailwind.css` |
144
+ | --- | --- | --- |
145
+ | `primary` | `--color-primary-*` | Tailwind `blue` |
146
+ | `neutral` | `--color-neutral-*` | Tailwind `slate` |
147
+ | `success` | `--color-success-*` | Tailwind `green` |
148
+ | `warning` | `--color-warning-*` | Tailwind `amber` |
149
+ | `danger` | `--color-danger-*` | Tailwind `red` |
150
+ | `error` | Same as `danger` if `danger` is omitted | — |
151
+ | `info` | `--color-info-*` | Tailwind `sky` |
152
+
153
+ ### `TailwindThemeSeverityColor`
154
+
155
+ Each `colors.*` field uses the exported type **`TailwindThemeSeverityColor`**. It can be either of the following:
156
+
157
+ 1. **A string — Tailwind palette name**
158
+ Use the lowercase **family name** only (the segment between the utility prefix and the shade), e.g. `bg-indigo-600` → `'indigo'`, `text-slate-500` → `'slate'`.
159
+ The full list of built-in names and swatches is in the official **[Tailwind CSS color reference](https://tailwindcss.com/docs/colors)** — pick any name from that page for the string form.
160
+ For each configured shade, `defineTheme` sets `--color-<semantic>-<shade>` to `var(--color-<that-name>-<shade>)`.
161
+
162
+ 2. **A partial object — per-shade CSS**
163
+ Keys are optional shade steps: `'50'`, `'100'`, …, `'950'`. Values are any valid CSS color (`#hex`, `rgb()`, `oklch()`, `var(--color-fuchsia-600)`, etc.). Only the keys you pass are overridden.
164
+
165
+ When you use a **string**, shade coverage matches the library tokens: `primary` and `neutral` include `950`; `success`, `warning`, `danger`, and `info` stop at `900`.
166
+
167
+ When you pass a **palette string** (e.g. `primary: 'indigo'`), the target variables `--color-indigo-*` must exist in the compiled CSS. Tailwind v4 only emits palette variables that are referenced at build time, so the library’s `tailwind.css` **safelists** the default Tailwind families (`slate`, `gray`, `indigo`, …) with `@source inline(...)`. For a custom family name not covered there, use the object form with explicit colors, or add your own `@source inline("bg-<name>-{50,{100..900..100},950}")` in your app stylesheet.
168
+
169
+ `defineTheme` is a no-op during **SSR** (browser only).
92
170
 
93
171
  ## Content slots
94
172
 
@@ -150,7 +228,7 @@ Some components (for example `tailwind-card`, `tailwind-modal`, `tailwind-toolba
150
228
 
151
229
  The library uses a comprehensive design system defined via Tailwind CSS v4 `@theme` directive:
152
230
 
153
- - **Colors**: Primary (blue), Success (green), Warning (amber), Danger (red), Info (cyan), Neutral surfaces
231
+ - **Colors**: Semantic tokens alias Tailwind default palettes — Primary (`blue`), neutral (`slate`), Success (`green`), Warning (`amber`), Danger (`red`), Info (`sky`)
154
232
  - **Typography**: Inter (sans), JetBrains Mono (mono)
155
233
  - **Spacing**: Tailwind default scale
156
234
  - **Border Radius**: xs through full
@@ -159,12 +237,14 @@ The library uses a comprehensive design system defined via Tailwind CSS v4 `@the
159
237
 
160
238
  ### Customization
161
239
 
162
- Override tokens in your main CSS:
240
+ Prefer **`defineTheme({ … })`** in `ApplicationConfig.providers` for tokens and semantic colors (see [Application configuration](#application-configuration-definetheme)).
241
+
242
+ You can still override any token in your own CSS, for example:
163
243
 
164
244
  ```css
165
245
  @theme {
166
- --color-primary-500: oklch(0.55 0.2 280); /* Change primary to purple */
167
- --color-primary-600: oklch(0.48 0.22 280);
246
+ --color-primary-500: var(--color-violet-500);
247
+ --color-primary-600: var(--color-violet-600);
168
248
  }
169
249
  ```
170
250