Skip to content

Commit 0091f08

Browse files
committed
🎨 Move isText in utils
1 parent af017c9 commit 0091f08

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import React, { useState, useEffect, useCallback, useMemo, useRef } from 'react';
44
import { motion } from 'motion/react';
55
import { CursorProps, Position, CursorRule, CursorVariant, CursorType, CursorTheme } from './types';
6-
import { isMobile, isInteractive } from './utils';
6+
import { isMobile, isInteractive, isText } from './utils';
77
import { TEXT_ELEMENTS } from './constants';
88

99
const Cursor: React.FC<CursorProps> = ({ zIndex = 9999, theme = {}, defaultColor: customDefaultColor }) => {
@@ -104,7 +104,7 @@ const Cursor: React.FC<CursorProps> = ({ zIndex = 9999, theme = {}, defaultColor
104104
// Prioritize interactive elements
105105
} else if (isInteractive(target)) {
106106
setCurrentVariant('hover');
107-
} else if (TEXT_ELEMENTS.includes(target.tagName as any)) {
107+
} else if (isText(target)) {
108108
setFontSize(parseFloat(window.getComputedStyle(target).fontSize));
109109
setCurrentVariant('text');
110110
} else {

src/utils.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import { INTERACTIVE_ELEMENTS } from './constants';
1+
import { INTERACTIVE_ELEMENTS, TEXT_ELEMENTS } from './constants';
22

3+
/** Check if the user is on a mobile device */
34
export const isMobile = (): boolean => {
45
return /iPhone|iPad|iPod|Android|WebOS/i.test(navigator.userAgent);
56
};
67

8+
/** Check if the target is an interactive element */
79
export const isInteractive = (target: HTMLElement): boolean => {
810
if (INTERACTIVE_ELEMENTS.includes(target.tagName as any)) {
911
return true;
@@ -23,3 +25,10 @@ export const isInteractive = (target: HTMLElement): boolean => {
2325

2426
return false;
2527
};
28+
29+
/** Check if the target is a text element */
30+
export const isText = (target: HTMLElement): boolean => {
31+
if (TEXT_ELEMENTS.includes(target.tagName as any)) {
32+
return true;
33+
}
34+
};

0 commit comments

Comments
 (0)