File tree Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change 1+ import { css , cx } from "@styled-system/css" ;
2+ import { glassContainer } from "@styled-system/recipes" ;
3+
4+ export const glassEffect = cx ( glassContainer ( { border : "md" } ) ) ;
5+
6+ export const floatingButtonContainer = css ( {
7+ zIndex : "50" ,
8+ position : "fixed" ,
9+ right : "24px" ,
10+ bottom : "24px" ,
11+ } ) ;
12+
13+ export const buttonContainer = cx (
14+ glassContainer ( { border : "md" } ) ,
15+ css ( {
16+ padding : "12px" ,
17+ paddingX : "20px" ,
18+ backgroundColor : "white/40" ,
19+ cursor : "pointer" ,
20+ } ) ,
21+ ) ;
Original file line number Diff line number Diff line change 1+ import { useState , useRef , useEffect } from "react" ;
2+ import * as style from "./AIButton.style" ;
3+ import AIModal from "./AIModal" ;
4+
5+ const AIButton = ( ) => {
6+ const [ isOpen , setIsOpen ] = useState ( false ) ;
7+ const modalRef = useRef < HTMLDivElement > ( null ) ;
8+
9+ const handleClose = ( ) => {
10+ setIsOpen ( false ) ;
11+ } ;
12+
13+ useEffect ( ( ) => {
14+ const handleClickOutside = ( event : MouseEvent ) => {
15+ if ( modalRef . current && ! modalRef . current . contains ( event . target as Node ) ) {
16+ setIsOpen ( false ) ;
17+ }
18+ } ;
19+
20+ document . addEventListener ( "mousedown" , handleClickOutside ) ;
21+ return ( ) => {
22+ document . removeEventListener ( "mousedown" , handleClickOutside ) ;
23+ } ;
24+ } , [ ] ) ;
25+
26+ return (
27+ < div className = { style . floatingButtonContainer } >
28+ < div ref = { modalRef } >
29+ { isOpen && < AIModal onCloseButton = { handleClose } /> }
30+ < button onClick = { ( ) => setIsOpen ( ( prev ) => ! prev ) } className = { style . buttonContainer } >
31+ < span > AI ๋ฌธ์ ์์ฑ</ span >
32+ </ button >
33+ </ div >
34+ </ div >
35+ ) ;
36+ } ;
37+
38+ export default AIButton ;
You canโt perform that action at this time.
0 commit comments