Skip to content

Commit 9423cf0

Browse files
committed
feat: add slow-pulse variant to ui/skeleton
add new keyframe animations for slow-pulse and fade-in
1 parent fa6cf03 commit 9423cf0

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

src/components/ui/skeleton.tsx

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { cva, type VariantProps } from "class-variance-authority"
2+
13
import { cn } from "@/lib/utils/cn"
24

35
import { Card, CardBanner, CardContent } from "../ui/card"
@@ -22,18 +24,27 @@ const widths = [
2224
"w-1/5",
2325
]
2426

25-
const Skeleton = ({
26-
className,
27-
...props
28-
}: React.HTMLAttributes<HTMLDivElement>) => {
27+
const skeletonVariants = cva(
28+
"h-4 rounded bg-disabled opacity-5 dark:opacity-60",
29+
{
30+
variants: {
31+
variant: {
32+
pulse: "animate-pulse-light",
33+
"slow-pulse": "animate-slow-pulse opacity-[0.01]",
34+
},
35+
},
36+
defaultVariants: {
37+
variant: "pulse",
38+
},
39+
}
40+
)
41+
42+
type SkeletonProps = React.HTMLAttributes<HTMLDivElement> &
43+
VariantProps<typeof skeletonVariants>
44+
45+
const Skeleton = ({ className, variant, ...props }: SkeletonProps) => {
2946
return (
30-
<div
31-
className={cn(
32-
"h-4 animate-pulse-light rounded bg-disabled opacity-5 dark:opacity-60",
33-
className
34-
)}
35-
{...props}
36-
/>
47+
<div className={cn(skeletonVariants({ variant }), className)} {...props} />
3748
)
3849
}
3950

tailwind.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,14 @@ const config = {
301301
"pulse-light": {
302302
"50%": { opacity: "0.2" },
303303
},
304+
"slow-pulse": {
305+
"70%": { opacity: "0" },
306+
"85%": { opacity: "0.2" },
307+
},
308+
"fade-in": {
309+
"0%": { opacity: "0" },
310+
"100%": { opacity: "1" },
311+
},
304312
},
305313
animation: {
306314
"accordion-down": "accordion-down 0.2s ease-out",
@@ -316,6 +324,8 @@ const config = {
316324
"spin-9": "spin 18s linear infinite",
317325
"counter-spin-9": "spin 18s linear infinite reverse",
318326
"pulse-light": "pulse-light 2s cubic-bezier(0.4, 0, 0.6, 1) infinite",
327+
"slow-pulse": "slow-pulse 4s linear infinite",
328+
"fade-in": "fade-in 150ms ease-in-out",
319329
},
320330
// Add custom border-radius tailwinds extension for "4xl" as "2rem"
321331
borderRadius: {

0 commit comments

Comments
 (0)