Skip to content

Commit

Permalink
feat: add props for colors
Browse files Browse the repository at this point in the history
  • Loading branch information
S-N-O-R-L-A-X committed Oct 10, 2024
1 parent 03385ee commit d93ec07
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
10 changes: 8 additions & 2 deletions src/SpotlightText/SpotlightText.module.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.spotlight {
--backgroundImageURL: "";
color: #333;
margin: 0;
padding: 0;
Expand All @@ -17,13 +16,20 @@
-webkit-clip-path: ellipse(100px 100px at 0% 50%);
clip-path: ellipse(100px 100px at 0% 50%);
animation: spotlight 5s infinite;
background-image: var(--background-image);
background-size: 150%;
background-position: center center;
-webkit-background-clip: text;
background-clip: text;
}

.spotlight-color::after {
background-image: linear-gradient(to right, var(--spotlight-colors));
}

.spotlight-image::after {
background-image: var(--spotlight-image);
}

@keyframes spotlight {
0% {
-webkit-clip-path: ellipse(100px 100px at 0% 50%);
Expand Down
33 changes: 19 additions & 14 deletions src/SpotlightText/SpotlightText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,30 @@ import styles from "./SpotlightText.module.css";
export interface SpotlightTextProps extends HTMLAttributes<HTMLDivElement> {
text?: string;
backgroundImageURL?: string;
colors?: {
startColor: string;
middleColor?: string;
endColor: string;
}
colors?: string[];
}

export default function SpotlightText(props: SpotlightTextProps) {
const { backgroundImageURL = "https://images.unsplash.com/photo-1579547621869-0ddb5f237392?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1500&q=80", colors, className, text = "Hello World!", ...rest } = props;
return colors ?
(
<div data-spotlight={text} className={styles.spotlight + " " + styles['spotlight-color'] + className} {...rest}>
if (colors && colors.length) {
return (
<div data-spotlight={text}
className={styles.spotlight + " " + styles['spotlight-color'] + " " + className}
style={{ "--spotlight-colors": colors.join(', ') } as CSSProperties}
{...rest}
>
{text}
</div>
)
:
(
<div data-spotlight={text} style={{ "--background-image": `url(${backgroundImageURL})` } as CSSProperties} className={styles.spotlight + " " + className} {...rest}>
{text}
</div >
)
}

return (
<div data-spotlight={text}
className={styles.spotlight + " " + styles['spotlight-image'] + " " + className}
style={{ "--spotlight-image": `url(${backgroundImageURL})` } as CSSProperties}
{...rest}
>
{text}
</div >
)
}

0 comments on commit d93ec07

Please sign in to comment.