Skip to content

Commit 62a0a3b

Browse files
committed
changing brush width
1 parent 280829f commit 62a0a3b

File tree

4 files changed

+54
-7
lines changed

4 files changed

+54
-7
lines changed

src/components/AccessibilityButton.tsx

+21-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState } from "react";
1+
import { useEffect, useState } from "react";
22

33
type AccessibilityButtonProps = {
44
name: string,
@@ -9,11 +9,28 @@ type AccessibilityButtonProps = {
99
function AccessibilityButton({ name, icon, modal }: AccessibilityButtonProps ) {
1010
const [active, setActive] = useState(false);
1111

12+
useEffect(() => {
13+
if(!active) return;
14+
15+
const handleModal = () => {
16+
setActive(false);
17+
}
18+
19+
window.addEventListener("click", handleModal);
20+
return () => window.removeEventListener("click", handleModal);
21+
}, [active]);
22+
23+
const handleIconClick = (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
24+
e.preventDefault();
25+
e.stopPropagation();
26+
if(modal) setActive(!active);
27+
}
28+
1229
return (
13-
<div>
14-
<div onClick={() => modal && setActive(!active)} className="relative">
30+
<div className="relative">
31+
<div onClick={(e) => handleIconClick(e)} className="relative">
1532
<span className="peer">{icon}</span>
16-
<p className={(!active && 'peer-hover:visible peer-hover:h-6') + ' duration-75 delay-100 h-0 invisible w-max flex justify-center items-center transition-all text-center left-1/2 absolute bg-neutral-700/70 text-neutral-50 px-3 rounded-lg -translate-x-1/2 translate-y-2'}>
33+
<p className={(!active && 'peer-hover:visible peer-hover:h-6') + ' duration-75 delay-700 h-0 invisible w-max flex justify-center items-center transition-all text-center left-1/2 absolute bg-neutral-700/70 text-neutral-50 px-3 rounded-lg -translate-x-1/2 translate-y-2'}>
1734
<span className="text-sm">{name}</span>
1835
</p>
1936
</div>

src/components/modals/LineWidthModal.tsx

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
1+
import { useEffect, useRef } from "react";
2+
13
type LineWidthModalProps = {
24
brush: {type: string, width: number, color: string},
35
setBrush: Function
46
}
57

68
function LineWidthModal({ brush, setBrush }: LineWidthModalProps) {
79

10+
const handleClick = (val: number) => {
11+
setBrush({type: brush.type, width: val, color: brush.color});
12+
}
813

914
return (
10-
<div className="absolute bg-neutral-100 border border-neutral-300 p-2 -translate-x-1/2 left-0">
11-
test
15+
<div className="animate-slideFromTop absolute w-max bg-white border border-neutral-300 p-2 left-1/2 rounded-lg">
16+
{[1,3,5,8].map((val) => {
17+
return (
18+
<div onClick={() => handleClick(val)} key={val} className={(brush.width === val && 'bg-neutral-100') + ' hover:bg-neutral-100 py-2 px-3 rounded-lg text-xs flex justify-center items-center gap-4 relative'}>
19+
<span>{val}px</span>
20+
<div className="w-16 bg-neutral-700" style={{height: val + 'px'}}></div>
21+
22+
{brush.width === val && <>
23+
<div className="absolute h-3 rounded-lg w-1 bg-indigo-600 left-0 -translate-x-1/2"></div>
24+
</>}
25+
</div>
26+
)
27+
})}
1228
</div>
1329
)
1430
}

src/index.css

+4
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@
1616

1717
.icon-accessibility {
1818
@apply h-6 w-6 cursor-pointer hover:text-neutral-800;
19+
}
20+
21+
* {
22+
@apply select-none;
1923
}

tailwind.config.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@ module.exports = {
44
"./src/**/*.{js,jsx,ts,tsx}",
55
],
66
theme: {
7-
extend: {},
7+
extend: {
8+
keyframes: {
9+
slideFromTop: {
10+
'0%': { transform: 'translate(-50%, -10px)', opacity: '50%' },
11+
'100%': { transform: 'translate(-50%, 5px)', opacity: '100%' }
12+
}
13+
},
14+
animation: {
15+
slideFromTop: 'slideFromTop 0.1s linear forwards',
16+
}
17+
},
818
},
919
plugins: [],
1020
}

0 commit comments

Comments
 (0)