forked from ueberdosis/tiptap-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCtaBox.tsx
150 lines (124 loc) · 4.41 KB
/
CtaBox.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import { Slot } from '@radix-ui/react-slot'
import { forwardRef } from 'react'
import { CheckIcon } from 'lucide-react'
import { NoisePattern } from './NoisePattern'
import { cn } from '@/utils'
import gradientBgDark from '@/assets/gradient-bg.svg?url'
import gradientBgLight from '@/assets/gradient-bg-light.svg?url'
export type WrapperProps = {
asChild?: boolean
variant?: 'dark' | 'light'
} & React.HTMLAttributes<HTMLDivElement>
export const Wrapper = forwardRef<HTMLDivElement, WrapperProps>(
({ asChild, variant = 'dark', children, className, ...rest }, ref) => {
const boxClass = cn(
'no-markdown relative text-white rounded-xl bg-gray-950 overflow-hidden shadow-cardLight',
'transition-shadow hover:shadow-cardHover',
variant === 'dark' ? 'bg-gray-950 text-white' : 'bg-white text-black',
className,
)
const patternClass = cn(
'absolute bottom-0 right-0 rotate-45 z-0',
variant === 'dark' ? 'translate-x-[40%] translate-y-[52%] rotate-45' : '',
variant === 'light' ? 'translate-x-[40%] translate-y-[43%] rotate-12' : '',
)
const imageClass = cn('bg-cover', variant === 'dark' ? 'size-[48rem]' : 'size-[38rem]')
const Component = asChild ? Slot : 'section'
return (
<Component ref={ref} {...rest} className={boxClass}>
<div className="relative z-10 p-8">{children}</div>
<NoisePattern variant={variant} className={patternClass}>
<div
style={{
backgroundImage: `url(${variant === 'dark' ? gradientBgDark.src : gradientBgLight.src})`,
}}
className={imageClass}
/>
</NoisePattern>
</Component>
)
},
)
Wrapper.displayName = 'CtaBox.Wrapper'
export type TitleProps = {
asChild?: boolean
} & React.HTMLAttributes<HTMLHeadingElement>
export const Title = forwardRef<HTMLHeadingElement, TitleProps>(
({ asChild, children, className, ...rest }, ref) => {
const titleClass = cn('text-[1.75rem] leading-[110%] font-serif', className)
const Component = asChild ? Slot : 'h2'
return (
<Component ref={ref} {...rest} className={titleClass}>
{children}
</Component>
)
},
)
Title.displayName = 'CtaBox.Title'
export type DescriptionProps = {
asChild?: boolean
} & React.HTMLAttributes<HTMLParagraphElement>
export const Description = forwardRef<HTMLParagraphElement, DescriptionProps>(
({ asChild, children, className, ...rest }, ref) => {
const descriptionClass = cn('mt-2.5 text-[1.125rem] leading-[160%]', className)
const Component = asChild ? Slot : 'p'
return (
<Component ref={ref} {...rest} className={descriptionClass}>
{children}
</Component>
)
},
)
Description.displayName = 'CtaBox.Description'
export type ListProps = {
asChild?: boolean
} & React.HTMLAttributes<HTMLUListElement>
export const List = forwardRef<HTMLUListElement, ListProps>(
({ asChild, children, className, ...rest }, ref) => {
const listClass = cn('mt-5 space-y-1', className)
const Component = asChild ? Slot : 'ul'
return (
<Component ref={ref} {...rest} className={listClass}>
{children}
</Component>
)
},
)
List.displayName = 'CtaBox.List'
export type ListItemProps = {
asChild?: boolean
title?: string
} & React.HTMLAttributes<HTMLLIElement>
export const ListItem = forwardRef<HTMLLIElement, ListItemProps>(
({ asChild, children, className, title, ...rest }, ref) => {
const listItemClass = cn('flex items-center gap-2', className)
const Component = asChild ? Slot : 'li'
return (
<Component ref={ref} {...rest} className={listItemClass}>
<span className="block flex-none">
<CheckIcon className="size-5 text-green" />
</span>
<span className="block flex-1">
{title ? <span className="font-semibold">{title}</span> : null}
{children}
</span>
</Component>
)
},
)
ListItem.displayName = 'CtaBox.ListItem'
export type ActionsProps = {
asChild?: boolean
} & React.HTMLAttributes<HTMLDivElement>
export const Actions = forwardRef<HTMLDivElement, ActionsProps>(
({ asChild, children, className, ...rest }, ref) => {
const actionsClass = cn('mt-4 flex items-center gap-1', className)
const Component = asChild ? Slot : 'div'
return (
<Component ref={ref} {...rest} className={actionsClass}>
{children}
</Component>
)
},
)
Actions.displayName = 'CtaBox.Actions'