Skip to content

Commit 7ef6205

Browse files
committed
✨ Add support for cursor text color customization and update documentation
1 parent a4fd220 commit 7ef6205

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

src/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ const Cursor: React.FC<CursorProps> = ({
3737
return customDefaultColor || fallbackColor;
3838
}, [customDefaultColor]);
3939

40+
const defaultTextColor = useMemo(() => {
41+
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'hsl(240 10% 3.9%)' : 'hsl(0 0% 98%)';
42+
}, []);
43+
4044
const defaultVariants: Record<CursorType, CursorVariant> = {
4145
default: {
4246
style: {
@@ -206,7 +210,7 @@ const Cursor: React.FC<CursorProps> = ({
206210
ref={contentRef}
207211
className={`react-dot-cursor-content ${currentVariantData.content.className || ''}`}
208212
style={{
209-
color: 'white',
213+
color: `var(--cursor-text-color, ${defaultTextColor})`,
210214
fontSize: '16px',
211215
...currentVariantData.content.style,
212216
}}

website/src/index.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
--chart-5: 27 87% 67%;
4949
--radius: 0.5rem;
5050
--cursor-color: hsl(349, 80%, 59%);
51+
--cursor-text-color: white;
5152
}
5253
.dark {
5354
--background: 240 10% 3.9%;
@@ -75,6 +76,7 @@
7576
--chart-4: 280 65% 60%;
7677
--chart-5: 340 75% 55%;
7778
--cursor-color: hsl(349, 80%, 59%);
79+
--cursor-text-color: white;
7880
}
7981
}
8082

website/src/pages/docs/styling.mdx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,12 @@
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 using any **valid CSS color format**.
7+
You can style the cursor by setting the `--cursor-color` and `--cursor-text-color` CSS variable using any **valid CSS color format**.
88

99
```css
1010
:root {
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 */
11+
--cursor-color: hsl(349 80% 59%);
12+
--cursor-text-color: white;
1613
}
1714
```
1815

@@ -24,12 +21,14 @@ The cursor automatically detects system dark mode preferences and adjusts its co
2421
/* Light mode */
2522
:root {
2623
--cursor-color: hsl(240 10% 3.9%);
24+
--cursor-text-color: hsl(0 0% 98%);
2725
}
2826

2927
/* Dark mode */
3028
@media (prefers-color-scheme: dark) {
3129
:root {
3230
--cursor-color: hsl(0 0% 98%);
31+
--cursor-text-color: hsl(240 10% 3.9%);
3332
}
3433
}
3534
```

0 commit comments

Comments
 (0)