solid-tom-ui 1.0.11 → 1.0.15
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 +246 -246
- package/dist/README.md +246 -246
- package/dist/components/avatar/avatar.js.map +1 -1
- package/dist/components/badge/badge.js.map +1 -1
- package/dist/components/breadcrumb/breadcrumb.js.map +1 -1
- package/dist/components/button/button.js.map +1 -1
- package/dist/components/carousel/carousel.js.map +1 -1
- package/dist/components/chat-bubble/chatBubble.js.map +1 -1
- package/dist/components/checkbox/checkbox.js.map +1 -1
- package/dist/components/collapse/collapse.js.map +1 -1
- package/dist/components/context-menu/context-menu.js.map +1 -1
- package/dist/components/context-menu/context-menu.store.js.map +1 -1
- package/dist/components/divider/divider.js.map +1 -1
- package/dist/components/dropdown/dropdown.js.map +1 -1
- package/dist/components/dropdown/dropdown.store.js.map +1 -1
- package/dist/components/float-button/float-button.js.map +1 -1
- package/dist/components/hover-3d-image/hover-3d-image.js.map +1 -1
- package/dist/components/image-preview/image-preview.js.map +1 -1
- package/dist/components/input/input.js.map +1 -1
- package/dist/components/input/input.utils.js.map +1 -1
- package/dist/components/input/variants/input-color.js.map +1 -1
- package/dist/components/input/variants/input-date.js.map +1 -1
- package/dist/components/input/variants/input-number.d.ts.map +1 -1
- package/dist/components/input/variants/input-number.js +1 -1
- package/dist/components/input/variants/input-number.js.map +1 -1
- package/dist/components/input/variants/input-otp.js.map +1 -1
- package/dist/components/input/variants/input-password.js.map +1 -1
- package/dist/components/input/variants/input-radio.js.map +1 -1
- package/dist/components/input/variants/input-range.js.map +1 -1
- package/dist/components/input/variants/input-text.d.ts.map +1 -1
- package/dist/components/input/variants/input-text.js +1 -1
- package/dist/components/input/variants/input-text.js.map +1 -1
- package/dist/components/input/variants/input-textarea.js.map +1 -1
- package/dist/components/loading/loading.js.map +1 -1
- package/dist/components/mansory/mansory.js.map +1 -1
- package/dist/components/menu/menu.js.map +1 -1
- package/dist/components/modal/modal.js.map +1 -1
- package/dist/components/modal/modalContext.js.map +1 -1
- package/dist/components/pagination/pagination.js.map +1 -1
- package/dist/components/progress-bar/progress-bar.js.map +1 -1
- package/dist/components/qr-code/qr-code.js.map +1 -1
- package/dist/components/select/select.js +1 -1
- package/dist/components/select/select.js.map +1 -1
- package/dist/components/select-zone/select-zone.js.map +1 -1
- package/dist/components/skeleton/skeleton.js.map +1 -1
- package/dist/components/slider/slider.js.map +1 -1
- package/dist/components/splitter/splitter.js.map +1 -1
- package/dist/components/steps/steps.js.map +1 -1
- package/dist/components/swap/swap.js.map +1 -1
- package/dist/components/switch/switch.js.map +1 -1
- package/dist/components/tab/tab.js.map +1 -1
- package/dist/components/table/table.js.map +1 -1
- package/dist/components/timeline/timeline.js.map +1 -1
- package/dist/components/toast/icons/ErrorIcon.js.map +1 -1
- package/dist/components/toast/icons/IconCircle.js.map +1 -1
- package/dist/components/toast/icons/InfoIcon.js.map +1 -1
- package/dist/components/toast/icons/LoaderIcon.js.map +1 -1
- package/dist/components/toast/icons/SuccessIcon.js.map +1 -1
- package/dist/components/toast/icons/WarningIcon.js.map +1 -1
- package/dist/components/toast/toast.js.map +1 -1
- package/dist/components/toast/toast.store.js.map +1 -1
- package/dist/components/tooltip/tooltip.js.map +1 -1
- package/dist/components/tour/tour.js.map +1 -1
- package/dist/components/upload/upload.js.map +1 -1
- package/dist/components/z-index/z-index.context.js.map +1 -1
- package/dist/components/z-index/z-index.js.map +1 -1
- package/dist/components/z-index/z-index.store.js.map +1 -1
- package/dist/components/z-index/z-index.types.js.map +1 -1
- package/dist/package.json +1 -1
- package/dist/skill/avatar.skill.md.txt +255 -255
- package/dist/skill/badge.skill.md.txt +223 -223
- package/dist/skill/breadcrumb.skill.md.txt +177 -177
- package/dist/skill/button.skill.md.txt +198 -198
- package/dist/skill/carousel.skill.md.txt +406 -406
- package/dist/skill/chat-bubble.skill.md.txt +342 -342
- package/dist/skill/checkbox.skill.md.txt +326 -326
- package/dist/skill/code-preview.skill.md.txt +240 -240
- package/dist/skill/collapse.skill.md.txt +329 -329
- package/dist/skill/context-menu.skill.md.txt +233 -233
- package/dist/skill/diff.skill.md.txt +244 -244
- package/dist/skill/divider.skill.md.txt +151 -151
- package/dist/skill/doc.skill.md.txt +191 -191
- package/dist/skill/drawer.skill.md.txt +157 -157
- package/dist/skill/dropdown.skill.md.txt +198 -198
- package/dist/skill/float-button.skill.md.txt +315 -315
- package/dist/skill/hover-3d-image.skill.md.txt +120 -120
- package/dist/skill/iframe.skill.md.txt +114 -114
- package/dist/skill/image-preview.skill.md.txt +162 -162
- package/dist/skill/indicator.skill.md.txt +60 -60
- package/dist/skill/input.skill.md.txt +489 -489
- package/dist/skill/loading.skill.md.txt +127 -127
- package/dist/skill/menu.skill.md.txt +476 -476
- package/dist/skill/modal.skill.md.txt +359 -359
- package/dist/skill/pagination.skill.md.txt +405 -405
- package/dist/skill/progress-bar.skill.md.txt +207 -207
- package/dist/skill/qr-code.skill.md.txt +136 -136
- package/dist/skill/rating.skill.md.txt +167 -167
- package/dist/skill/select-zone.skill.md.txt +93 -93
- package/dist/skill/select.skill.md.txt +663 -663
- package/dist/skill/skeleton.skill.md.txt +192 -192
- package/dist/skill/slider.skill.md.txt +404 -404
- package/dist/skill/splitter.skill.md.txt +411 -411
- package/dist/skill/steps.skill.md.txt +264 -264
- package/dist/skill/swap.skill.md.txt +139 -139
- package/dist/skill/switch.skill.md.txt +191 -191
- package/dist/skill/tab.skill.md.txt +484 -484
- package/dist/skill/table.example.header.md.txt +666 -666
- package/dist/skill/table.skill.md.txt +1407 -1407
- package/dist/skill/text-rotate.skill.md.txt +186 -186
- package/dist/skill/timeline.skill.md.txt +247 -247
- package/dist/skill/toast.skill.md.txt +531 -531
- package/dist/skill/tooltip.skill.md.txt +222 -222
- package/dist/skill/tour.skill.md.txt +156 -156
- package/dist/skill/upload.skill.md.txt +358 -358
- package/dist/utils/cn.js.map +1 -1
- package/dist/utils/element-tracker.js.map +1 -1
- package/dist/utils/helper.js.map +1 -1
- package/dist/utils/hoc.js.map +1 -1
- package/package.json +132 -133
|
@@ -1,186 +1,186 @@
|
|
|
1
|
-
## COMPONENT IDENTITY
|
|
2
|
-
- **Import**: `import { TextRotate } from 'solid-tom-ui';`
|
|
3
|
-
- **Export**: `TextRotate` (named export)
|
|
4
|
-
- **Framework**: SolidJS
|
|
5
|
-
- **Purpose**: Pure-CSS animated text rotator — cycles through words/JSX elements driven by CSS `linear()` easing; zero JS timers; hover pauses animation
|
|
6
|
-
|
|
7
|
-
## Props
|
|
8
|
-
|
|
9
|
-
| Prop | Type | Default | Description |
|
|
10
|
-
| ------- | ----------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------- |
|
|
11
|
-
| `items` | `(string \| (() => JSX.Element))[]` | — | **Required.** List of text strings or render functions. Min: 2, Max: **6** |
|
|
12
|
-
| `class` | `{ root?: string; item?: string }` | — | Class overrides. `root` targets the outer `<span>`; `item` targets each string `<span>` (not render-function items) |
|
|
13
|
-
|
|
14
|
-
## Class Slots
|
|
15
|
-
|
|
16
|
-
`TextRotate` uses a slot object `{ root?, item? }` (equivalent to `Partial<Record<'root' | 'item', string>>`):
|
|
17
|
-
- `root` — outer `<span class="text-rotate ...">` wrapper
|
|
18
|
-
- `item` — each string item's inner `<span>` (not applied to render-function items)
|
|
19
|
-
|
|
20
|
-
> **CSS encoding**: internal CSS classes use short encoded names (e.g. `tr01`, `tr02`) per project convention.
|
|
21
|
-
|
|
22
|
-
### Item types
|
|
23
|
-
|
|
24
|
-
Each element in `items` can be:
|
|
25
|
-
|
|
26
|
-
- **`string`** — wrapped in `<span class={class.item}>`. Applies `class.item` if provided.
|
|
27
|
-
- **`() => JSX.Element`** — called directly and rendered as-is. `class.item` is **not** applied to render-function items; style them inside the function itself.
|
|
28
|
-
|
|
29
|
-
## Hard Limits
|
|
30
|
-
|
|
31
|
-
| Condition | Behavior |
|
|
32
|
-
| ----------------------------- | ----------------------------------------- |
|
|
33
|
-
| `items` is empty or undefined | Returns `<>` (empty), logs `console.warn` |
|
|
34
|
-
| `items.length > 6` | Returns `<>` (empty), logs `console.warn` |
|
|
35
|
-
|
|
36
|
-
Always pass **2–6 items**.
|
|
37
|
-
|
|
38
|
-
## Usage Examples
|
|
39
|
-
|
|
40
|
-
### Basic — strings
|
|
41
|
-
|
|
42
|
-
```tsx
|
|
43
|
-
<p class="text-2xl font-bold">
|
|
44
|
-
I{' '}
|
|
45
|
-
<TextRotate
|
|
46
|
-
items={['love', 'enjoy', 'build with']}
|
|
47
|
-
class={{ root: 'text-rotate text-primary' }}
|
|
48
|
-
/>{' '}
|
|
49
|
-
SolidJS
|
|
50
|
-
</p>
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
### Inline within text
|
|
54
|
-
|
|
55
|
-
`TextRotate` renders as an inline `<span>` — use it freely inside a sentence:
|
|
56
|
-
|
|
57
|
-
```tsx
|
|
58
|
-
<h1 class="text-4xl font-bold">
|
|
59
|
-
Build{' '}
|
|
60
|
-
<TextRotate items={['faster', 'better', 'smarter']} class={{ root: 'text-rotate text-accent' }} />{' '}
|
|
61
|
-
with SolidJS
|
|
62
|
-
</h1>
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
### Render functions — arbitrary JSX
|
|
66
|
-
|
|
67
|
-
When items need custom styling, badges, icons, or complex markup, use render functions:
|
|
68
|
-
|
|
69
|
-
```tsx
|
|
70
|
-
<TextRotate
|
|
71
|
-
items={[
|
|
72
|
-
() => <span class="badge badge-success font-bold">Online ✅</span>,
|
|
73
|
-
() => <span class="badge badge-error font-bold">Offline 🔴</span>,
|
|
74
|
-
() => <span class="badge badge-warning font-bold">Away 🟡</span>,
|
|
75
|
-
]}
|
|
76
|
-
/>
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### Mixed strings and render functions
|
|
80
|
-
|
|
81
|
-
```tsx
|
|
82
|
-
<TextRotate
|
|
83
|
-
items={[
|
|
84
|
-
'Vite ⚡',
|
|
85
|
-
() => <span class="text-success font-mono">TypeScript</span>,
|
|
86
|
-
'Tailwind 🎨',
|
|
87
|
-
() => <span class="text-secondary italic">DaisyUI</span>,
|
|
88
|
-
]}
|
|
89
|
-
class={{ root: 'text-rotate' }}
|
|
90
|
-
/>
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
### Custom item class (strings only)
|
|
94
|
-
|
|
95
|
-
`class.item` applies to the wrapping `<span>` of each **string** item:
|
|
96
|
-
|
|
97
|
-
```tsx
|
|
98
|
-
<TextRotate
|
|
99
|
-
items={['Creative', 'Efficient', 'Simple']}
|
|
100
|
-
class={{
|
|
101
|
-
root: 'text-rotate text-info',
|
|
102
|
-
item: 'font-mono uppercase',
|
|
103
|
-
}}
|
|
104
|
-
/>
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
### Controlling animation speed
|
|
108
|
-
|
|
109
|
-
The animation duration is driven by the `--duration` CSS custom property, which reads from Tailwind's `--tw-duration`. Override it with Tailwind's `duration-*` utility on the `root` element:
|
|
110
|
-
|
|
111
|
-
```tsx
|
|
112
|
-
{
|
|
113
|
-
/* Slow: 20s per full cycle */
|
|
114
|
-
}
|
|
115
|
-
<TextRotate items={['fast', 'slow', 'smooth']} class={{ root: 'text-rotate duration-20000' }} />;
|
|
116
|
-
|
|
117
|
-
{
|
|
118
|
-
/* Fast: 4s per full cycle */
|
|
119
|
-
}
|
|
120
|
-
<TextRotate items={['fast', 'slow', 'smooth']} class={{ root: 'text-rotate duration-4000ms' }} />;
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
Default duration when not set: `10s`.
|
|
124
|
-
|
|
125
|
-
### Hero heading
|
|
126
|
-
|
|
127
|
-
```tsx
|
|
128
|
-
<h1 class="text-5xl font-extrabold">
|
|
129
|
-
We build{' '}
|
|
130
|
-
<TextRotate
|
|
131
|
-
items={[
|
|
132
|
-
() => <span class="text-primary">faster</span>,
|
|
133
|
-
() => <span class="text-secondary">better</span>,
|
|
134
|
-
() => <span class="text-accent">smarter</span>,
|
|
135
|
-
]}
|
|
136
|
-
/>{' '}
|
|
137
|
-
products
|
|
138
|
-
</h1>
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
## How the Animation Works
|
|
142
|
-
|
|
143
|
-
The CSS class `text-rotate` (from `text-rotate.daisy.css`) does the following:
|
|
144
|
-
|
|
145
|
-
1. **Container** (`<span class="text-rotate">`):
|
|
146
|
-
- `display: inline-block; height: 1lh; overflow: hidden` — crops to exactly one line-height.
|
|
147
|
-
- `vertical-align: bottom` — aligns cleanly inside surrounding text.
|
|
148
|
-
|
|
149
|
-
2. **Inner grid** (the inner `<span>` wrapper):
|
|
150
|
-
- `display: grid; height: calc(N * 100%)` — stacks all `N` items vertically.
|
|
151
|
-
- Each item gets `align-content: baseline` and `clip-path: inset(0.5px 0 0.5px 0)` to clip half-pixels between items.
|
|
152
|
-
|
|
153
|
-
3. **Animation**:
|
|
154
|
-
- CSS `:has(*:nth-child(N))` selectors auto-detect item count (2–6) and apply the matching `rotator` keyframe.
|
|
155
|
-
- The `linear()` easing function creates discrete hold phases at each step position, then snaps to the next — giving the appearance of a pause-then-flip rather than a smooth scroll.
|
|
156
|
-
- A single `animation: rotator 10s linear(...) infinite` drives the whole thing.
|
|
157
|
-
|
|
158
|
-
4. **Hover pause**:
|
|
159
|
-
- `.text-rotate:hover > * { animation-play-state: paused }` — hover on the component pauses the cycle.
|
|
160
|
-
|
|
161
|
-
## Rendered HTML Structure
|
|
162
|
-
|
|
163
|
-
```html
|
|
164
|
-
<span class="text-rotate [root class]">
|
|
165
|
-
<span>
|
|
166
|
-
<!-- inner grid, height = N × 100% -->
|
|
167
|
-
<span class="[item class]">Item 1</span>
|
|
168
|
-
<!-- string item -->
|
|
169
|
-
<span class="[item class]">Item 2</span>
|
|
170
|
-
<!-- OR: raw JSX from render function, no wrapping span -->
|
|
171
|
-
</span>
|
|
172
|
-
</span>
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
## Common Mistakes
|
|
176
|
-
|
|
177
|
-
| Mistake | Fix |
|
|
178
|
-
| -------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
179
|
-
| Passing `items.length > 6` | Component silently returns empty — keep items ≤ 6 |
|
|
180
|
-
| Passing 0 or 1 items | Minimum 2 items required |
|
|
181
|
-
| Applying `class.item` expecting it to work on render functions | `class.item` only applies to string items. Style render-function items inline |
|
|
182
|
-
| Forgetting `text-rotate` in `class.root` | The `text-rotate` CSS class is what enables the animation. Without it, items render stacked but don't animate. Pass `class={{ root: 'text-rotate ...' }}` |
|
|
183
|
-
| Expecting the component to accept `duration` as a prop | Duration is CSS-driven: add `duration-[Xms]` Tailwind utility to `class.root` |
|
|
184
|
-
| Using `TextRotate` outside inline text context | It renders as `inline-block` with `height: 1lh` — works in paragraph and heading text. Avoid placing it in a `flex` container row where `1lh` might resolve unexpectedly |
|
|
185
|
-
|
|
186
|
-
> **Unique IDs**: if this component needs to generate HTML `id` attributes, always use `createUniqueId()` from `solid-js` — never `Math.random()` or `Date.now()`.
|
|
1
|
+
## COMPONENT IDENTITY
|
|
2
|
+
- **Import**: `import { TextRotate } from 'solid-tom-ui';`
|
|
3
|
+
- **Export**: `TextRotate` (named export)
|
|
4
|
+
- **Framework**: SolidJS
|
|
5
|
+
- **Purpose**: Pure-CSS animated text rotator — cycles through words/JSX elements driven by CSS `linear()` easing; zero JS timers; hover pauses animation
|
|
6
|
+
|
|
7
|
+
## Props
|
|
8
|
+
|
|
9
|
+
| Prop | Type | Default | Description |
|
|
10
|
+
| ------- | ----------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------- |
|
|
11
|
+
| `items` | `(string \| (() => JSX.Element))[]` | — | **Required.** List of text strings or render functions. Min: 2, Max: **6** |
|
|
12
|
+
| `class` | `{ root?: string; item?: string }` | — | Class overrides. `root` targets the outer `<span>`; `item` targets each string `<span>` (not render-function items) |
|
|
13
|
+
|
|
14
|
+
## Class Slots
|
|
15
|
+
|
|
16
|
+
`TextRotate` uses a slot object `{ root?, item? }` (equivalent to `Partial<Record<'root' | 'item', string>>`):
|
|
17
|
+
- `root` — outer `<span class="text-rotate ...">` wrapper
|
|
18
|
+
- `item` — each string item's inner `<span>` (not applied to render-function items)
|
|
19
|
+
|
|
20
|
+
> **CSS encoding**: internal CSS classes use short encoded names (e.g. `tr01`, `tr02`) per project convention.
|
|
21
|
+
|
|
22
|
+
### Item types
|
|
23
|
+
|
|
24
|
+
Each element in `items` can be:
|
|
25
|
+
|
|
26
|
+
- **`string`** — wrapped in `<span class={class.item}>`. Applies `class.item` if provided.
|
|
27
|
+
- **`() => JSX.Element`** — called directly and rendered as-is. `class.item` is **not** applied to render-function items; style them inside the function itself.
|
|
28
|
+
|
|
29
|
+
## Hard Limits
|
|
30
|
+
|
|
31
|
+
| Condition | Behavior |
|
|
32
|
+
| ----------------------------- | ----------------------------------------- |
|
|
33
|
+
| `items` is empty or undefined | Returns `<>` (empty), logs `console.warn` |
|
|
34
|
+
| `items.length > 6` | Returns `<>` (empty), logs `console.warn` |
|
|
35
|
+
|
|
36
|
+
Always pass **2–6 items**.
|
|
37
|
+
|
|
38
|
+
## Usage Examples
|
|
39
|
+
|
|
40
|
+
### Basic — strings
|
|
41
|
+
|
|
42
|
+
```tsx
|
|
43
|
+
<p class="text-2xl font-bold">
|
|
44
|
+
I{' '}
|
|
45
|
+
<TextRotate
|
|
46
|
+
items={['love', 'enjoy', 'build with']}
|
|
47
|
+
class={{ root: 'text-rotate text-primary' }}
|
|
48
|
+
/>{' '}
|
|
49
|
+
SolidJS
|
|
50
|
+
</p>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Inline within text
|
|
54
|
+
|
|
55
|
+
`TextRotate` renders as an inline `<span>` — use it freely inside a sentence:
|
|
56
|
+
|
|
57
|
+
```tsx
|
|
58
|
+
<h1 class="text-4xl font-bold">
|
|
59
|
+
Build{' '}
|
|
60
|
+
<TextRotate items={['faster', 'better', 'smarter']} class={{ root: 'text-rotate text-accent' }} />{' '}
|
|
61
|
+
with SolidJS
|
|
62
|
+
</h1>
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Render functions — arbitrary JSX
|
|
66
|
+
|
|
67
|
+
When items need custom styling, badges, icons, or complex markup, use render functions:
|
|
68
|
+
|
|
69
|
+
```tsx
|
|
70
|
+
<TextRotate
|
|
71
|
+
items={[
|
|
72
|
+
() => <span class="badge badge-success font-bold">Online ✅</span>,
|
|
73
|
+
() => <span class="badge badge-error font-bold">Offline 🔴</span>,
|
|
74
|
+
() => <span class="badge badge-warning font-bold">Away 🟡</span>,
|
|
75
|
+
]}
|
|
76
|
+
/>
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Mixed strings and render functions
|
|
80
|
+
|
|
81
|
+
```tsx
|
|
82
|
+
<TextRotate
|
|
83
|
+
items={[
|
|
84
|
+
'Vite ⚡',
|
|
85
|
+
() => <span class="text-success font-mono">TypeScript</span>,
|
|
86
|
+
'Tailwind 🎨',
|
|
87
|
+
() => <span class="text-secondary italic">DaisyUI</span>,
|
|
88
|
+
]}
|
|
89
|
+
class={{ root: 'text-rotate' }}
|
|
90
|
+
/>
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Custom item class (strings only)
|
|
94
|
+
|
|
95
|
+
`class.item` applies to the wrapping `<span>` of each **string** item:
|
|
96
|
+
|
|
97
|
+
```tsx
|
|
98
|
+
<TextRotate
|
|
99
|
+
items={['Creative', 'Efficient', 'Simple']}
|
|
100
|
+
class={{
|
|
101
|
+
root: 'text-rotate text-info',
|
|
102
|
+
item: 'font-mono uppercase',
|
|
103
|
+
}}
|
|
104
|
+
/>
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Controlling animation speed
|
|
108
|
+
|
|
109
|
+
The animation duration is driven by the `--duration` CSS custom property, which reads from Tailwind's `--tw-duration`. Override it with Tailwind's `duration-*` utility on the `root` element:
|
|
110
|
+
|
|
111
|
+
```tsx
|
|
112
|
+
{
|
|
113
|
+
/* Slow: 20s per full cycle */
|
|
114
|
+
}
|
|
115
|
+
<TextRotate items={['fast', 'slow', 'smooth']} class={{ root: 'text-rotate duration-20000' }} />;
|
|
116
|
+
|
|
117
|
+
{
|
|
118
|
+
/* Fast: 4s per full cycle */
|
|
119
|
+
}
|
|
120
|
+
<TextRotate items={['fast', 'slow', 'smooth']} class={{ root: 'text-rotate duration-4000ms' }} />;
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Default duration when not set: `10s`.
|
|
124
|
+
|
|
125
|
+
### Hero heading
|
|
126
|
+
|
|
127
|
+
```tsx
|
|
128
|
+
<h1 class="text-5xl font-extrabold">
|
|
129
|
+
We build{' '}
|
|
130
|
+
<TextRotate
|
|
131
|
+
items={[
|
|
132
|
+
() => <span class="text-primary">faster</span>,
|
|
133
|
+
() => <span class="text-secondary">better</span>,
|
|
134
|
+
() => <span class="text-accent">smarter</span>,
|
|
135
|
+
]}
|
|
136
|
+
/>{' '}
|
|
137
|
+
products
|
|
138
|
+
</h1>
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## How the Animation Works
|
|
142
|
+
|
|
143
|
+
The CSS class `text-rotate` (from `text-rotate.daisy.css`) does the following:
|
|
144
|
+
|
|
145
|
+
1. **Container** (`<span class="text-rotate">`):
|
|
146
|
+
- `display: inline-block; height: 1lh; overflow: hidden` — crops to exactly one line-height.
|
|
147
|
+
- `vertical-align: bottom` — aligns cleanly inside surrounding text.
|
|
148
|
+
|
|
149
|
+
2. **Inner grid** (the inner `<span>` wrapper):
|
|
150
|
+
- `display: grid; height: calc(N * 100%)` — stacks all `N` items vertically.
|
|
151
|
+
- Each item gets `align-content: baseline` and `clip-path: inset(0.5px 0 0.5px 0)` to clip half-pixels between items.
|
|
152
|
+
|
|
153
|
+
3. **Animation**:
|
|
154
|
+
- CSS `:has(*:nth-child(N))` selectors auto-detect item count (2–6) and apply the matching `rotator` keyframe.
|
|
155
|
+
- The `linear()` easing function creates discrete hold phases at each step position, then snaps to the next — giving the appearance of a pause-then-flip rather than a smooth scroll.
|
|
156
|
+
- A single `animation: rotator 10s linear(...) infinite` drives the whole thing.
|
|
157
|
+
|
|
158
|
+
4. **Hover pause**:
|
|
159
|
+
- `.text-rotate:hover > * { animation-play-state: paused }` — hover on the component pauses the cycle.
|
|
160
|
+
|
|
161
|
+
## Rendered HTML Structure
|
|
162
|
+
|
|
163
|
+
```html
|
|
164
|
+
<span class="text-rotate [root class]">
|
|
165
|
+
<span>
|
|
166
|
+
<!-- inner grid, height = N × 100% -->
|
|
167
|
+
<span class="[item class]">Item 1</span>
|
|
168
|
+
<!-- string item -->
|
|
169
|
+
<span class="[item class]">Item 2</span>
|
|
170
|
+
<!-- OR: raw JSX from render function, no wrapping span -->
|
|
171
|
+
</span>
|
|
172
|
+
</span>
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Common Mistakes
|
|
176
|
+
|
|
177
|
+
| Mistake | Fix |
|
|
178
|
+
| -------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
179
|
+
| Passing `items.length > 6` | Component silently returns empty — keep items ≤ 6 |
|
|
180
|
+
| Passing 0 or 1 items | Minimum 2 items required |
|
|
181
|
+
| Applying `class.item` expecting it to work on render functions | `class.item` only applies to string items. Style render-function items inline |
|
|
182
|
+
| Forgetting `text-rotate` in `class.root` | The `text-rotate` CSS class is what enables the animation. Without it, items render stacked but don't animate. Pass `class={{ root: 'text-rotate ...' }}` |
|
|
183
|
+
| Expecting the component to accept `duration` as a prop | Duration is CSS-driven: add `duration-[Xms]` Tailwind utility to `class.root` |
|
|
184
|
+
| Using `TextRotate` outside inline text context | It renders as `inline-block` with `height: 1lh` — works in paragraph and heading text. Avoid placing it in a `flex` container row where `1lh` might resolve unexpectedly |
|
|
185
|
+
|
|
186
|
+
> **Unique IDs**: if this component needs to generate HTML `id` attributes, always use `createUniqueId()` from `solid-js` — never `Math.random()` or `Date.now()`.
|