angular-tailwind-components 1.4.0 → 1.6.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,133 @@ 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`, `buttonKind`, `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
+ buttonKind: 'flat',
83
+ paginationSummary: 'Visualizzati {start}-{end} di {total}',
84
+ colors: {
85
+ primary: 'violet', // Forma oggetto: { 600: '#4f46e5', 700: '#4338ca' }
86
+ danger: 'rose',
87
+ neutral: 'zinc'
88
+ }
80
89
  })
81
90
  ]
82
91
  };
83
92
  ```
84
93
 
94
+ ### Example: tokens only
95
+
96
+ ```typescript
97
+ providers: [
98
+ defineTheme({
99
+ iconSize: 20,
100
+ datetimeLanguage: 'it',
101
+ componentsSize: 'md',
102
+ paginationSummary: 'Items {start}-{end} of {total}'
103
+ })
104
+ ];
105
+ ```
106
+
107
+ ### Example: colors only
108
+
109
+ ```typescript
110
+ providers: [defineTheme({ colors: { primary: 'indigo', neutral: 'zinc' } })];
111
+ ```
112
+
113
+ ### Example: spread a shared config object
114
+
115
+ ```typescript
116
+ import { ApplicationConfig } from '@angular/core';
117
+ import { defineTheme, type TailwindComponentsConfig } from 'angular-tailwind-components';
118
+
119
+ const shared: TailwindComponentsConfig = {
120
+ componentsSize: 'md',
121
+ datetimeLanguage: 'it'
122
+ };
123
+
124
+ export const appConfig: ApplicationConfig = {
125
+ providers: [defineTheme({ ...shared, colors: { primary: 'indigo' } })]
126
+ };
127
+ ```
128
+
129
+ You can omit **`colors`** if you only need token defaults, or omit token keys if you only need theme colors.
130
+
85
131
  | Config key | Token |
86
132
  | --- | --- |
87
133
  | `iconSize` | `TAILWIND_ICON_SIZE` |
88
134
  | `datetimeLanguage` | `TAILWIND_DATETIME_LANGUAGE` |
89
135
  | `componentsSize` | `TAILWIND_COMPONENTS_SIZE` |
136
+ | `buttonKind` | `TAILWIND_BUTTON_KIND` |
90
137
  | `paginationSummary` | `TAILWIND_PAGINATION_SUMMARY` |
91
- | `modalData` | `TAILWIND_MODAL_DATA` (rare at app scope; modal `open()` still supplies per-dialog data) |
138
+
139
+ **`provideTailwindComponents`** is still exported for backward compatibility (token providers only, same implementation as the token slice of `defineTheme`). It is **deprecated**; prefer **`defineTheme`**.
140
+
141
+ ## Theme colors (`defineTheme`)
142
+
143
+ 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).
144
+
145
+ | `colors` key | CSS variables | Default palette in `tailwind.css` |
146
+ | --- | --- | --- |
147
+ | `primary` | `--color-primary-*`, `--color-on-primary-*` | Tailwind `blue` |
148
+ | `neutral` | `--color-neutral-*`, `--color-on-neutral-*` | Tailwind `slate` |
149
+ | `success` | `--color-success-*`, `--color-on-success-*` | Tailwind `green` |
150
+ | `warning` | `--color-warning-*`, `--color-on-warning-*` | Tailwind `amber` |
151
+ | `danger` | `--color-danger-*`, `--color-on-danger-*` | Tailwind `red` |
152
+ | `error` | Same as `danger` if `danger` is omitted | — |
153
+ | `info` | `--color-info-*`, `--color-on-info-*` | Tailwind `sky` |
154
+
155
+ ### `TailwindThemeSeverityColor`
156
+
157
+ Each `colors.*` field uses the exported type **`TailwindThemeSeverityColor`**. It can be any of the following:
158
+
159
+ 1. **A string — Tailwind palette name**
160
+ 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'`.
161
+ 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.
162
+ For each configured shade, `defineTheme` sets `--color-<semantic>-<shade>` to `var(--color-<that-name>-<shade>)`.
163
+ **Foreground / contrast:** built-in components that sit on saturated semantic backgrounds (solid buttons, tags, semantic toolbar) use utilities like `text-on-success-600`, backed by **`--color-on-<semantic>-<shade>`** defaults in the library `@theme`. With a **palette string**, you usually do **not** need to set `on` yourself — Tailwind’s scales stay internally consistent.
164
+
165
+ 2. **A partial object — per-shade CSS (legacy flat form)**
166
+ 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 written to `--color-<semantic>-<shade>`.
167
+ **Optional `on`:** if you override background shades with custom values, set matching foreground tokens by using the structured form below so text stays readable.
168
+
169
+ 3. **A structured object — `{ shades, on? }`**
170
+ - **`shades`**: same as the flat object: maps to `--color-<semantic>-<shade>`.
171
+ - **`on`**: optional partial map of the same shade keys → CSS colors for **`--color-on-<semantic>-<shade>`** (recommended foreground on that semantic background). Solid `tailwind-button` / `tailwind-tag` / semantic `tailwind-toolbar` read these via `text-on-*` utilities.
172
+
173
+ Example:
174
+
175
+ ```typescript
176
+ defineTheme({
177
+ colors: {
178
+ success: {
179
+ shades: { 600: '#14532d', 700: '#0f3d21' },
180
+ on: { 600: '#ecfdf5', 700: '#ecfdf5' }
181
+ }
182
+ }
183
+ });
184
+ ```
185
+
186
+ When you use a **string**, shade coverage matches the library tokens: `primary` and `neutral` include `950`; `success`, `warning`, `danger`, and `info` stop at `900`.
187
+
188
+ 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.
189
+
190
+ `defineTheme` is a no-op during **SSR** (browser only).
92
191
 
93
192
  ## Content slots
94
193
 
@@ -150,7 +249,7 @@ Some components (for example `tailwind-card`, `tailwind-modal`, `tailwind-toolba
150
249
 
151
250
  The library uses a comprehensive design system defined via Tailwind CSS v4 `@theme` directive:
152
251
 
153
- - **Colors**: Primary (blue), Success (green), Warning (amber), Danger (red), Info (cyan), Neutral surfaces
252
+ - **Colors**: Semantic tokens alias Tailwind default palettes — Primary (`blue`), neutral (`slate`), Success (`green`), Warning (`amber`), Danger (`red`), Info (`sky`)
154
253
  - **Typography**: Inter (sans), JetBrains Mono (mono)
155
254
  - **Spacing**: Tailwind default scale
156
255
  - **Border Radius**: xs through full
@@ -159,12 +258,14 @@ The library uses a comprehensive design system defined via Tailwind CSS v4 `@the
159
258
 
160
259
  ### Customization
161
260
 
162
- Override tokens in your main CSS:
261
+ Prefer **`defineTheme({ … })`** in `ApplicationConfig.providers` for tokens and semantic colors (see [Application configuration](#application-configuration-definetheme)).
262
+
263
+ You can still override any token in your own CSS, for example:
163
264
 
164
265
  ```css
165
266
  @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);
267
+ --color-primary-500: var(--color-violet-500);
268
+ --color-primary-600: var(--color-violet-600);
168
269
  }
169
270
  ```
170
271