Skip to content

Commit cd6c759

Browse files
authored
Merge pull request #2 from GuiEpi/expand-color-formats
✨ defaultColor support multiple formats
2 parents dfd3d79 + 955b45c commit cd6c759

5 files changed

Lines changed: 48 additions & 20 deletions

File tree

src/index.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ const Cursor: React.FC<CursorProps> = ({
3030
}
3131
}, [currentVariant]);
3232

33-
const defaultColor = useMemo(
34-
() =>
35-
customDefaultColor || (window.matchMedia('(prefers-color-scheme: dark)').matches ? '0 0% 98%' : '240 10% 3.9%'),
36-
[customDefaultColor],
37-
);
33+
const defaultColor = useMemo(() => {
34+
const fallbackColor = window.matchMedia('(prefers-color-scheme: dark)').matches
35+
? 'hsl(0 0% 98%)'
36+
: 'hsl(240 10% 3.9%)';
37+
return customDefaultColor || fallbackColor;
38+
}, [customDefaultColor]);
3839

3940
const defaultVariants: Record<CursorType, CursorVariant> = {
4041
default: {
@@ -185,7 +186,7 @@ const Cursor: React.FC<CursorProps> = ({
185186
left: position.x,
186187
pointerEvents: 'none',
187188
zIndex,
188-
backgroundColor: `hsl(var(--cursor-color, ${defaultColor}))`,
189+
backgroundColor: `var(--cursor-color, ${defaultColor})`,
189190
transformOrigin: 'left center',
190191
overflow: 'hidden', // Important for the compression effect
191192
}}

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export interface CursorProps {
4747
theme?: CursorTheme;
4848
/** Whether to scale cursor on click */
4949
scaleOnClick?: boolean;
50-
/** Default color in HSL format */
50+
/** Default color in valid CSS format (e.g., 'hsl(240 10% 3.9%)', '#ff4081', 'rgb(255 64 129)', 'oklch(0.7 0.15 330)') */
5151
defaultColor?: string;
5252
}
5353

website/src/index.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
--chart-4: 43 74% 66%;
3030
--chart-5: 27 87% 67%;
3131
--radius: 0.5rem;
32-
--cursor-color: 349, 80%, 59%;
32+
--cursor-color: hsl(349, 80%, 59%);
3333
}
3434
.dark {
3535
--background: 240 10% 3.9%;
@@ -56,7 +56,7 @@
5656
--chart-3: 30 80% 55%;
5757
--chart-4: 280 65% 60%;
5858
--chart-5: 340 75% 55%;
59-
--cursor-color: 349, 80%, 59%;
59+
--cursor-color: hsl(349, 80%, 59%);
6060
}
6161
}
6262

website/src/pages/docs/cursor.mdx

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ This component will render the cursor.
3636
<td>[defaultColor](#default-color-prop)</td>
3737
<td>string</td>
3838
<td>auto</td>
39-
<td>Default HSL color value</td>
39+
<td>Default color in valid CSS format</td>
4040
</tr>
4141
</tbody>
4242
</table>
@@ -96,11 +96,34 @@ If `false`, do not scale cursor when clicking. Defaults to `true`.
9696

9797
### <a name="default-color-prop"></a>`defaultColor` Prop
9898

99-
Change the default cursor color. The value should be in **HSL format**. By default, the cursor uses the HSL values from the <a href="https://ui.shadcn.com/colors" target="_blank" rel="noopener noreferrer">Tailwind CSS color palette</a>:
99+
Change the default cursor color using any **valid CSS color format**. By default, the cursor uses HSL colors from the <a href="https://ui.shadcn.com/colors" target="_blank" rel="noopener noreferrer">Tailwind CSS color palette</a>:
100100

101-
- Dark mode: `0 0% 98%` (zinc-50)
102-
- Light mode: `240 10% 3.9%` (zinc-950)
101+
- Dark mode: `hsl(0 0% 98%)` (zinc-50)
102+
- Light mode: `hsl(240 10% 3.9%)` (zinc-950)
103+
104+
**Examples with explicit CSS color formats:**
103105

104106
```jsx
105-
<Cursor defaultColor="349, 80%, 59%" />
107+
// HSL colors
108+
<Cursor defaultColor="hsl(349 80% 59%)" />
109+
<Cursor defaultColor="hsl(349, 80%, 59%)" />
110+
111+
// RGB colors
112+
<Cursor defaultColor="rgb(255 64 129)" />
113+
<Cursor defaultColor="rgb(255, 64, 129)" />
114+
115+
// OKLCH colors
116+
<Cursor defaultColor="oklch(0.7 0.15 330)" />
117+
118+
// Hex colors
119+
<Cursor defaultColor="#ff4081" />
120+
<Cursor defaultColor="#f41" />
121+
122+
// Named colors
123+
<Cursor defaultColor="red" />
124+
<Cursor defaultColor="hotpink" />
125+
126+
// Other CSS color functions
127+
<Cursor defaultColor="lab(50% 20 -30)" />
128+
<Cursor defaultColor="lch(50% 50 130)" />
106129
```

website/src/pages/docs/styling.mdx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,32 @@
44

55
### <a name="using-css-variables"></a>Using CSS Variables
66

7-
You can style the cursor by setting the `--cursor-color` CSS variable. The value should be in **HSL format**.
7+
You can style the cursor by setting the `--cursor-color` CSS variable using any **valid CSS color format**.
88

99
```css
1010
:root {
11-
--cursor-color: 349, 80%, 59%;
11+
--cursor-color: hsl(349 80% 59%); /* HSL */
12+
--cursor-color: #ff4081; /* Hex */
13+
--cursor-color: rgb(255 64 129); /* RGB */
14+
--cursor-color: oklch(0.7 0.15 330); /* OKLCH */
15+
--cursor-color: hotpink; /* Named color */
1216
}
1317
```
1418

1519
### <a name="dark-mode-support"></a>Dark Mode Support
1620

17-
The cursor automatically detects system dark mode preferences and adjusts its color. You can override this behavior:
21+
The cursor automatically detects system dark mode preferences and adjusts its color. You can override this behavior using any valid CSS color format:
1822

1923
```css
2024
/* Light mode */
2125
:root {
22-
--cursor-color: 240, 10%, 3.9%;
26+
--cursor-color: hsl(240 10% 3.9%);
2327
}
2428

2529
/* Dark mode */
2630
@media (prefers-color-scheme: dark) {
2731
:root {
28-
--cursor-color: 0, 0%, 98%;
32+
--cursor-color: hsl(0 0% 98%);
2933
}
3034
}
3135
```
@@ -103,7 +107,7 @@ const theme: CursorTheme = {
103107
padding: '1em',
104108

105109
// Optional: override color for this variant
106-
backgroundColor: 'hsl(160, 100%, 50%)',
110+
backgroundColor: 'hsl(160, 100%, 50%)', // Or any other format: '#00ff80', 'oklch(0.8 0.2 150)', etc.
107111
},
108112
// Optional: content styling
109113
content: {

0 commit comments

Comments
 (0)