File tree Expand file tree Collapse file tree 2 files changed +87
-1
lines changed Expand file tree Collapse file tree 2 files changed +87
-1
lines changed Original file line number Diff line number Diff line change 1+ import { LucideIcon } from 'lucide-react'
2+ import { MouseEvent , MouseEventHandler , useState } from 'react'
3+
4+ const ActionButton = ( {
5+ clickAction,
6+ Icon,
7+ IconOnClick = undefined ,
8+ tooltip = '' ,
9+ } : ReplayButtonProps ) => {
10+ const [ clicked , setClicked ] = useState ( false )
11+ function handleClick ( e : MouseEvent ) {
12+ clickAction ( e )
13+ setClicked ( true )
14+ setTimeout ( ( ) => setClicked ( false ) , 2000 )
15+ }
16+ return (
17+ < div
18+ onClick = { ( e ) => {
19+ handleClick ( e )
20+ } }
21+ title = { tooltip }
22+ className = "group cursor-pointer p-1"
23+ >
24+ < div
25+ className = {
26+ 'ease-custom relative flex size-6 items-center justify-center rounded-full bg-gradient-to-tr from-slate-400 to-indigo-500 text-zinc-100 opacity-80 ' +
27+ 'overflow-hidden transition-[transform,opacity] duration-300 group-hover:scale-125 group-hover:opacity-100 ' +
28+ ( clicked ? 'scale-125' : 'group-hover:scale-125' )
29+ }
30+ >
31+ < Icon
32+ className = {
33+ 'ease-custom absolute size-3 transition-[opacity,transform] duration-500 group-hover:rotate-180 ' +
34+ ( clicked ? 'translate-y-24 rotate-180 delay-300' : 'translate-y-0 delay-75' )
35+ }
36+ />
37+ { IconOnClick && (
38+ < IconOnClick
39+ className = {
40+ 'ease-custom size-3 transition-[opacity,transform] duration-[1s] ' +
41+ ( clicked ? 'translate-y-0' : '-translate-y-24' )
42+ }
43+ />
44+ ) }
45+ </ div >
46+ </ div >
47+ )
48+ }
49+
50+ export interface ReplayButtonProps {
51+ clickAction : MouseEventHandler
52+ Icon : LucideIcon
53+ IconOnClick ?: LucideIcon | undefined
54+ tooltip : string
55+ }
56+
57+ export default ActionButton
Original file line number Diff line number Diff line change 11import { PropsWithChildren } from 'react'
22import { addWithSpace } from '../utils/addWithSpace'
3+ import ActionButton from '../components/ActionButton'
4+ import { Repeat , StepForward } from 'lucide-react'
35
4- const DemoWrapper = ( { children, className = '' } : PropsWithChildren < DemoWrapperProps > ) => {
6+ const replayButtonClick = ( element : string ) => {
7+ const wrapper = document . getElementById ( element )
8+ wrapper &&
9+ wrapper . getAnimations ( { subtree : true } ) . forEach ( ( anim ) => {
10+ anim . cancel ( )
11+ anim . play ( )
12+ } )
13+ }
14+
15+ const DemoWrapper = ( {
16+ children,
17+ className = '' ,
18+ actionButton = false ,
19+ actionButtonElement = 'element' ,
20+ } : PropsWithChildren < DemoWrapperProps > ) => {
521 return (
622 < div
23+ id = { actionButtonElement }
724 className = {
825 'relative mb-4 h-96 overflow-y-auto overflow-x-hidden rounded-lg border border-zinc-300 bg-zinc-100/70 dark:border-zinc-700 dark:bg-black/10' +
926 addWithSpace ( className )
1027 }
1128 >
1229 { children }
30+ { actionButton && (
31+ < div className = "absolute right-3 top-3" >
32+ < ActionButton
33+ Icon = { Repeat }
34+ IconOnClick = { StepForward }
35+ clickAction = { ( ) => replayButtonClick ( actionButtonElement ) }
36+ tooltip = "Replay"
37+ />
38+ </ div >
39+ ) }
1340 </ div >
1441 )
1542}
1643
1744export interface DemoWrapperProps {
1845 children : PropsWithChildren
1946 className ?: string
47+ actionButton ?: boolean
48+ actionButtonElement ?: string
2049}
2150
2251export default DemoWrapper
You can’t perform that action at this time.
0 commit comments