FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
tailwindcss.com/src/components/example.tsx at main · polytech-dev/tailwindcss.com · GitHub
polytech-dev
/
tailwindcss.com
Public
forked from
tailwindlabs/tailwindcss.com
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
tailwindcss.com
/
src
/
components
/
example.tsx
Copy path
More file actions
More file actions
Latest commit
History
History
History
93 lines (88 loc) · 2.86 KB
Breadcrumbs
tailwindcss.com
/
src
/
components
/
example.tsx
Copy path
File metadata and controls
93 lines (88 loc) · 2.86 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
"use client"
;
import
{
clsx
}
from
"clsx"
;
import
{
motion
,
useMotionValue
,
useTransform
}
from
"framer-motion"
;
import
{
useEffect
,
useRef
,
useState
}
from
"react"
;
export
function
Example
(
{
children
,
resizable
=
false
,
padding
=
true
,
className
,
}
:
React
.
PropsWithChildren
<
{
resizable
?:
boolean
;
padding
?:
boolean
;
className
?:
string
;
}
>
)
{
let
[
isDragging
,
setIsDragging
]
=
useState
(
false
)
;
let
containerRef
=
useRef
(
null
)
;
let
constraintsRef
=
useRef
(
null
)
;
let
x
=
useMotionValue
(
0
)
;
useEffect
(
(
)
=>
{
if
(
!
resizable
||
!
containerRef
.
current
)
return
;
let
observer
=
new
window
.
ResizeObserver
(
(
)
=>
x
.
set
(
0
)
)
;
observer
.
observe
(
containerRef
.
current
)
;
return
(
)
=>
{
observer
.
disconnect
(
)
;
}
;
}
,
[
x
]
)
;
if
(
!
resizable
)
{
return
(
<
div
className
=
{
clsx
(
className
,
"not-prose overflow-auto rounded-lg bg-white outline outline-white/5 dark:bg-gray-950/50"
,
padding
&&
"p-8"
,
)
}
>
{
children
}
</
div
>
)
;
}
return
(
<
div
ref
=
{
containerRef
}
data-dragging
=
{
isDragging
?
true
:
undefined
}
className
=
{
clsx
(
className
,
"group not-prose relative overflow-hidden sm:overflow-visible"
)
}
>
<
motion
.
div
style
=
{
{
marginRight
:
useTransform
(
x
,
(
x
)
=>
-
x
)
}
}
className
=
{
clsx
(
padding
&&
"p-8"
,
"@container relative overflow-auto rounded-lg bg-white outline outline-white/5 dark:bg-gray-950/50 dark:inset-ring dark:inset-ring-white/5"
,
// Add layer on top of example while dragging to prevent issues with iframes
"group-data-dragging:before:absolute group-data-dragging:before:inset-0"
,
)
}
>
{
children
}
</
motion
.
div
>
<
div
ref
=
{
constraintsRef
}
className
=
"pointer-events-none absolute inset-y-0 right-1.5 left-60 max-sm:hidden"
>
<
motion
.
div
title
=
"Drag to resize"
className
=
{
clsx
(
"pointer-events-auto absolute top-1/2 right-0 z-50 -mt-6 h-12 w-1.5 cursor-ew-resize rounded-full"
,
"bg-slate-950/20 group-data-dragging:bg-slate-950/40 hover:bg-slate-950/40"
,
"dark:bg-slate-500 dark:group-data-dragging:bg-slate-300 dark:hover:bg-slate-300"
,
)
}
drag
=
"x"
dragElastic
=
{
0
}
dragMomentum
=
{
false
}
dragConstraints
=
{
constraintsRef
}
style
=
{
{
x
}
}
onMouseDown
=
{
(
)
=>
{
setIsDragging
(
true
)
;
}
}
onMouseUp
=
{
(
)
=>
{
setIsDragging
(
false
)
;
}
}
onDragStart
=
{
(
)
=>
{
setIsDragging
(
true
)
;
document
.
documentElement
.
classList
.
add
(
"select-none"
,
"**:cursor-ew-resize"
)
;
}
}
onDragEnd
=
{
(
)
=>
{
setIsDragging
(
false
)
;
document
.
documentElement
.
classList
.
remove
(
"select-none"
,
"**:cursor-ew-resize"
)
;
}
}
/>
</
div
>
</
div
>
)
;
}
Back
|
FazBrowse Home
|
New Git URL