Skip to content

Commit c2c5846

Browse files
committed
feat: typos
1 parent 1b06c75 commit c2c5846

File tree

4 files changed

+37
-35
lines changed

4 files changed

+37
-35
lines changed

src/content/docs/components/text/variable-font-and-cursor.mdx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ The component interpolates between `min` and `max` based on the cursor position
6363

6464
For more information about variable fonts and how they work, please refer to the <Link href="/docs/components/text/variable-font-hover-by-letter#understanding-variable-fonts">Variable Font Hover By Letter</Link> documentation.
6565

66+
## Notes
67+
68+
Make sure the main container has enough space to hold the text at its full weight to avoid layout shifts. For example, you can use negative margins, or an invisible pseudo element.
69+
6670
## Props
6771

6872
<Table>
@@ -76,10 +80,16 @@ For more information about variable fonts and how they work, please refer to the
7680
</TableHeader>
7781
<TableBody>
7882
<TableRow>
79-
<TableCell>label<span className="text-red-500">*</span></TableCell>
80-
<TableCell>`string`</TableCell>
83+
<TableCell>children<span className="text-red-500">*</span></TableCell>
84+
<TableCell>`React.ReactNode`</TableCell>
8185
<TableCell>-</TableCell>
82-
<TableCell>The text content to display</TableCell>
86+
<TableCell>The text content to display and animate</TableCell>
87+
</TableRow>
88+
<TableRow>
89+
<TableCell>as</TableCell>
90+
<TableCell>`ElementType`</TableCell>
91+
<TableCell>`"span"`</TableCell>
92+
<TableCell>HTML tag to render the component as</TableCell>
8393
</TableRow>
8494
<TableRow>
8595
<TableCell>fontVariationMapping<span className="text-red-500">*</span></TableCell>
@@ -99,12 +109,6 @@ For more information about variable fonts and how they work, please refer to the
99109
<TableCell>-</TableCell>
100110
<TableCell>Additional CSS classes for styling</TableCell>
101111
</TableRow>
102-
<TableRow>
103-
<TableCell>onClick</TableCell>
104-
<TableCell>`() => void`</TableCell>
105-
<TableCell>`undefined`</TableCell>
106-
<TableCell>Click event handler for the text</TableCell>
107-
</TableRow>
108112
</TableBody>
109113
</Table>
110114

src/content/docs/components/text/variable-font-cursor-proximity.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ With the `falloff` prop, you can control the type of falloff. It can be either `
7373

7474
- Interpolating on large number of letters simultaneously can be a bit slow, even when we're avoiding re-renders with state updates. If you're experienceing performance issues, try to limit the length of the text you're animating.
7575

76-
- Make sure the main container have enough space to hold the text with full weight to avoid layout shifts. For example, you can use negative margins like in the 2nd example.
76+
- Make sure the main container has enough space to hold the text at its full weight to avoid layout shifts. For example, you can use negative margins like in the 2nd example.
7777

7878
## Credits
7979

src/fancy/components/text/variable-font-and-cursor.tsx

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"use client"
22

3-
import React, { useCallback, useRef } from "react"
3+
import React, { ElementType, useCallback, useRef } from "react"
44
import { motion, useAnimationFrame } from "motion/react"
55

6+
import { cn } from "@/lib/utils"
67
import { useMousePositionRef } from "@/hooks/use-mouse-position-ref"
78

89
/**
@@ -48,12 +49,18 @@ interface FontVariationMapping {
4849
/**
4950
* Props for the VariableFontAndCursor component.
5051
*/
51-
interface TextProps {
52+
interface TextProps extends React.HTMLAttributes<HTMLElement> {
5253
/**
5354
* The text content to display and animate.
5455
* Required prop with no default value.
5556
*/
56-
label: string
57+
children: React.ReactNode
58+
59+
/**
60+
* HTML Tag to render the component as.
61+
* @default "span"
62+
*/
63+
as?: ElementType
5764

5865
/**
5966
* Mapping configuration that defines how cursor position affects font variation settings.
@@ -68,26 +75,14 @@ interface TextProps {
6875
* Required prop with no default value.
6976
*/
7077
containerRef: React.RefObject<HTMLDivElement>
71-
72-
/**
73-
* Additional CSS classes for styling the text element.
74-
* @default undefined
75-
*/
76-
className?: string
77-
78-
/**
79-
* Click event handler for the text element.
80-
* @default undefined
81-
*/
82-
onClick?: () => void
8378
}
8479

8580
const VariableFontAndCursor = ({
86-
label,
81+
children,
82+
as = "span",
8783
fontVariationMapping,
8884
className,
8985
containerRef,
90-
onClick,
9186
...props
9287
}: TextProps) => {
9388
// Hook to track mouse position relative to the specified container
@@ -146,16 +141,18 @@ const VariableFontAndCursor = ({
146141
}
147142
})
148143

144+
// Custom motion component to render as the specified HTML tag
145+
const MotionComponent = motion.create(as)
146+
149147
return (
150-
<motion.span
151-
className={className}
152-
data-text={label}
153-
onClick={onClick}
148+
<MotionComponent
149+
className={cn(className)}
150+
data-text={children}
154151
ref={spanRef}
155152
{...props}
156153
>
157-
{label}
158-
</motion.span>
154+
<span className="inline-block">{children}</span>
155+
</MotionComponent>
159156
)
160157
}
161158

src/fancy/examples/text/variable-font-and-cursor-demo.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ export default function Preview() {
1818
{/* this is the important stuff */}
1919
<div className="w-full h-full items-center justify-center flex">
2020
<VariableFontAndCursor
21-
label="fancy!"
2221
className="text-5xl sm:text-7xl md:text-9xl text-primary-orange"
2322
fontVariationMapping={{
2423
y: { name: "wght", min: 100, max: 900 },
2524
x: { name: "slnt", min: 0, max: -10 },
2625
}}
2726
containerRef={containerRef}
28-
/>
27+
>
28+
fancy!
29+
</VariableFontAndCursor>
2930
</div>
3031

3132
{/* this is just fluff for the demo */}

0 commit comments

Comments
 (0)