๋ฐ˜์‘ํ˜•

Framework 86

[Angular] SVG path element click ์ด๋ฒคํŠธ ํ•จ์ˆ˜ ์‹คํ–‰ํ•˜๋Š” ๋ฐฉ๋ฒ•

Intro ์•ˆ๋…•ํ•˜์„ธ์š”. ์•ต๊ทค๋Ÿฌ์—์„œ SVG path element์— click ์ด๋ฒคํŠธ ํ•จ์ˆ˜ ์‹คํ–‰ํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. My Case ์ œ ์ผ€์ด์Šค์˜ ๊ฒฝ์šฐ ํŠน์ • SVG ์š”์†Œ๋ฅผ ํด๋ฆญํ–ˆ์„ ๋•Œ ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๋„๋ก ํ•˜๊ณ  ์‹ถ์—ˆ์Šต๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ์•„๋ž˜์™€ ๊ฐ™์ด ๊ตฌํ˜„ํ•˜์˜€์Šต๋‹ˆ๋‹ค. svg ํŒŒ์ผ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. ts ํŒŒ์ผ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. @ViewChild('myPath') myPath: ElementRef; handleClick() { console.log("handleClick!!"); } ํ•˜์ง€๋งŒ, svg ํŒŒ์ผ์˜ path ์š”์†Œ๋ฅผ ํด๋ฆญํ•ด๋„ handleClick ํ•จ์ˆ˜๊ฐ€ ๋™์ž‘ํ•˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค. Why? ํด๋ฆญ ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•˜์ง€ ์•Š๋Š” ๋ฌธ์ œ๋Š” ์กฐ๊ฑด์ด ์ถฉ์กฑํ•˜์ง€ ์•Š์•˜๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค. ํด๋ฆญ ์ด๋ฒคํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ํ•ด๋‹น ์š”์†Œ..

Framework/Angular 2023.04.10

[React] ๋ฆฌ์•กํŠธ innerHtml ํ‘œ์‹œํ•˜๊ธฐ (dangerouslySetInnerHTML)์‚ฌ์šฉ ์ฃผ์˜์  ๋ฐ ๋ณด์•ˆ ๋ฐฉ๋ฒ•

Intro ์•ˆ๋…•ํ•˜์„ธ์š”. ๋ฆฌ์•กํŠธ์—์„œ innerHtml์„ ํ‘œ์‹œํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ์ตœ๊ทผ์— ์Šค๋งˆํŠธ์—๋””ํ„ฐ ๊ด€๋ จํ•œ ์ž‘์—…์„ ์ง„ํ–‰ํ•˜๊ณ  ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค. ์—๋””ํ„ฐ์— ์ €์žฅ๋œ ๋‚ด์šฉ์ด ๊ทธ๋Œ€๋กœ html tag๋กœ ์ €์žฅ๋˜๊ณ , ์ €์žฅ๋œ html tag๋ฅผ ๊ทธ๋Œ€๋กœ ํ™”๋ฉด์— ํ‘œ์‹œํ•ด์•ผ ํ–ˆ์ฃ . ์ €์žฅ๋œ ์ด innerHtml๋ฅผ ์–ด๋–ป๊ฒŒ ํ‘œ์‹œํ•ด์•ผ ํ• ๊นŒ์š”? ํ•จ๊ป˜ ์•Œ์•„๋ด…์‹œ๋‹ค :) How to solve the problem React์—์„œ innerHtml๋ฅผ ํ‘œ์‹œํ•˜๋Š” ์œ„ํ•ด์„œ๋Š” ์•„๋ž˜ ์ฝ”๋“œ์™€ ๊ฐ™์ด dangerouslySetInnerHTML๋ฅผ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. import React from 'react'; function MyComponent() { const sampleHtml = 'Hello world! '; return ( ); } ์—ฌ๊ธฐ์„œ da..

Framework/React 2023.04.06

[React] ๋กœ๋”ฉ๋ฐ”(loading bar) ํ‘œ์‹œ ๋ฐ ๋กœ๋”ฉ ์†๋„ ์กฐ์ ˆํ•˜๋Š” ๋ฐฉ๋ฒ• (+ setTimeout)

Intro ์•ˆ๋…•ํ•˜์„ธ์š”. ์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š” ๋ฆฌ์•กํŠธ์—์„œ ๋กœ๋”ฉ๋ฐ” ํ‘œ์‹œ ๋ฐ ๋กœ๋”ฉ ์†๋„๋ฅผ ์กฐ์ ˆํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. How to solve the problem ๋‹ค์Œ์˜ List ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•ด๋ด…์‹œ๋‹ค. handleFilterClickํ•จ์ˆ˜๋ฅผ ํด๋ฆญ ํ• ๋•Œ๋งˆ๋‹ค ํ•„ํ„ฐ๊ธฐ๋Šฅ์ด ์ž‘๋™๋˜๋Š” ๋กœ์ง์ž…๋‹ˆ๋‹ค. ํ•„ํ„ฐ๋ฅผ ๋ˆ„๋ฅผ ๋•Œ๋งˆ๋‹ค ํ•„ํ„ฐ๊ฐ€ ๋œ๋“ฏํ•œ ๋™์ž‘์„ ํ‘œํ˜„ํ•˜๊ธฐ ์œ„ํ•ด ๋กœ๋”ฉ๋ฐ”๋ฅผ ์ถ”๊ฐ€๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. const List: NextPage = () => { const {dataList, setDataList} = useLoginStore(); const [totalCtn, setTotalCtn] = useState(); const [filterStatus, setFilterStatus] = useState("ALL"); const..

Framework/React 2023.04.05

[React] array data ๋งˆ์ง€๋ง‰ ์ž์‹ ์š”์†Œ์— border bottom line css ์ถ”๊ฐ€ํ•˜๋Š” ๋ฐฉ๋ฒ•

Intro ์•ˆ๋…•ํ•˜์„ธ์š”. ์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š” ๋ฆฌ์•กํŠธ์—์„œ array ๋ฐ์ดํ„ฐ์˜ ๋งˆ์ง€๋ง‰ ์ž์‹ ์š”์†Œ์— border bottom line ์ถ”๊ฐ€ํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. How to solve the problem 1. map ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ์ดํ„ฐ ๋ฐฐ์—ด์˜ ๊ธธ์ด๋ฅผ ๊ตฌํ•ด์ค๋‹ˆ๋‹ค. const arrayLength = array.length; 2. map ํ•จ์ˆ˜์—์„œ ํ˜„์žฌ ๋ฐ์ดํ„ฐ ์š”์†Œ์˜ ์ธ๋ฑ์Šค ๊ฐ’์„ ๋ฐ›์•„ ์˜ต๋‹ˆ๋‹ค. array.map((item, index) => { //... }) 3. ์ธ๋ฑ์Šค ๊ฐ’์ด ๋ฐฐ์—ด ๊ธธ์ด๋ณด๋‹ค 1 ์ž‘์€ ๊ฒฝ์šฐ์—๋Š” border bottom์„ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค array.map((item, index) => { const isLastItem = index === arrayLength - 1; return ( {item}..

Framework/React 2023.03.31

[React] typescript useRef ์‚ฌ์šฉ์‹œ undefined / null ์˜ค๋ฅ˜ ๋ฐœ์ƒ ์›์ธ ๋ฐ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•

Intro ์•ˆ๋…•ํ•˜์„ธ์š”. ์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š” react ์—์„œ useRef ์‚ฌ์šฉ์‹œ undefined / null ์˜ค๋ฅ˜ ๋ฐœ์ƒ ์›์ธ๊ณผ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ์šฐ์„  ์ œ๊ฐ€ useRef๋ฅผ ์‚ฌ์šฉํ•œ ์ฝ”๋“œ ์˜ˆ์ œ๋Š” ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค. clientHeight๋ฅผ ์กฐ์ ˆํ•˜๊ธฐ ์œ„ํ•ด useRef๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ div tag์— ์ ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค. const divRef = useRef(null); const [handlePosition, setHandlePosition] = useState('300vh'); useEffect(() => { setHandlePosition(`${(divRef.current.clientHeight * 3) / 300}px`); }, []); return ( {/* some content */} ); ํ•˜์ง€..

Framework/React 2023.03.29

[React] ๋ฆฌ์•กํŠธ apexcharts x์ถ•(xaxis) ํŠน์ • ๊ฐ’์œผ๋กœ ์‹œ์ž‘ํ•˜๋„๋ก ์„ค์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•

Intro ์•ˆ๋…•ํ•˜์„ธ์š”. ์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š” ๋ฆฌ์•กํŠธ apexcharts x์ถ• ๊ฐ’์„ ํŠน์ • ๊ฐ’์œผ๋กœ ์‹œ์ž‘ํ•˜๋„๋ก ์„ค์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. How to solve the problem ์ œ ๊ฒฝ์šฐ์—๋Š” ์ƒˆ๋ฒฝ 5์‹œ๋ผ๋Š” ํŠน์ • ๊ฐ’์œผ๋กœ x์ถ•์„ ์‹œ์ž‘ํ•˜๊ณ  ์‹ถ์—ˆ์Šต๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ์ €๋Š” apxechart xaxis์˜ min ์†์„ฑ์„ ์‚ฌ์šฉํ•ด ์ œ๊ฐ€ ์›ํ•˜๋Š” ์‹œ๊ฐ„์„ ์•„๋ž˜์™€ ๊ฐ™์ด ์„ค์ •ํ•ด์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค. x์ถ• ๊ฐ’์€ ์ƒํ™ฉ์— ๋”ฐ๋ผ ๋‹ค๋ฅผํ…Œ๋‹ˆ ๋…„๋„/๋‹ฌ/์ผ ๋“ฑ์ด ํ•„์š”ํ•˜๋‹ค๋ฉด ์ปค์Šคํ…€ํ•˜์—ฌ ์‚ฌ์šฉํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค. xaxis: { min: new Date(new Date().setHours(5, 0, 0, 0)).getTime(), } ์•„๋ž˜๋Š” ์ „์ฒด ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค. var options = { chart: { type: 'line' }, series: [{ name: ..

Framework/React 2023.03.28

[React] ๋ฆฌ์•กํŠธ ํˆดํŒ (Tooltip) ๊ตฌํ˜„ํ•˜๊ธฐ / ์™ธ๋ถ€์˜์—ญ ํด๋ฆญ ์‹œ ํˆดํŒ ์ˆจ๊ธฐ๋Š” ๋ฐฉ๋ฒ•

Intro ์•ˆ๋…•ํ•˜์„ธ์š”. ์ด๋ฒˆ์‹œ๊ฐ„์—๋Š” ๋ฆฌ์•กํŠธ์—์„œ ํˆดํŒ์„ ๊ตฌํ˜„ํ•˜๋Š” ๋ฐฉ๋ฒ•, ํˆดํŒ ์™ธ๋ถ€ ์˜์—ญ ํด๋ฆญ ์‹œ ํˆดํŒ์„ ์ˆจ๊ธฐ๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. Let's look at detail ์•„๋ž˜์™€ ๊ฐ™์€ ๋ถ€๋ชจ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•ด๋ด…์‹œ๋‹ค. 3๊ฐœ์˜ ํˆดํŒ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์žˆ๊ณ , ํˆดํŒ ์ปดํฌ๋„ŒํŠธ์—๋Š” ๊ฐ๊ธฐ ๋‹ค๋ฅธ ํˆดํŒ ์„ค๋ช…์„ props๋กœ ์ „๋‹ฌํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. const SomeComponent: NextPage = props => { return ( ๋‰ด์Šค ์‡ผํ•‘ ์ง€๋„ ); } export default SomeComponent; ํˆดํŒ ์ปดํฌ๋„ŒํŠธ๋Š” ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ํ˜„์žฌ ๊ตฌํ˜„๋˜์–ด ์žˆ๋Š” ํˆดํŒ ์ปดํฌ๋„ŒํŠธ๋Š” ๋ฌธ์ œ๊ฐ€ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค, ์„ ํƒ๋œ ํˆดํŒ์ด ์žˆ์„ ๋•Œ ๋‹ค๋ฅธ ํˆดํŒ์ด ์„ ํƒ๋˜์–ด๋„, ๋™์‹œ์— ํˆดํŒ desc๊ฐ€ ํ‘œ์ถœ๋ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ ์™ธ๋ถ€ ์˜์—ญ์„ ํด๋ฆญ ํ• ๋•Œ ์—ฌ..

Framework/React 2023.03.21

[React] ๋ฆฌ์•กํŠธ apexcharts ์ปค์Šคํ…€ ํˆดํŒ (custom tooltip) ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•, ํˆดํŒ์— ์‹œ๊ฐ„ ๋ฐ์ดํ„ฐ์™€ ๊ฐ’ ํ‘œ์‹œํ•˜๊ธฐ

Intro ์•ˆ๋…•ํ•˜์„ธ์š”. ์ด๋ฒˆ์‹œ๊ฐ„์—๋Š” ๋ฆฌ์•กํŠธ์—์„œ apexcharts ๋ฅผ ์ด์šฉํ•˜์—ฌ ์ปค์Šคํ…€ ํˆดํŒ์„ ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. How to solve the problem apexcharts ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค๋Š” ๊ฐ€์ •ํ•˜์—, ์•„๋ž˜์˜ series ๋ฐ์ดํ„ฐ์™€ chart option์ด ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ•ด๋ด…์‹œ๋‹ค. const series: any = [ { name: 'EBAY', data: [ ['2023-03-20T07:00:22.625Z', '123124.82'], ['2023-03-20T06:00:20.103Z', '52353.83'], ['2023-03-20T05:00:16.960Z', '98943.91'], ['2023-03-20T04:00:15.051Z', '796756.65'], ['2023-03-20T0..

Framework/React 2023.03.20

[React] useState๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ† ๊ธ€ ๋ฒ„ํŠผ ๊ตฌํ˜„ํ•˜๋Š” ๋ฐฉ๋ฒ• Button toggle on off

Intro ์•ˆ๋…•ํ•˜์„ธ์š”. ์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š” react ๋ฆฌ์•กํŠธ์—์„œ ํ† ๊ธ€ ๋ฒ„ํŠผ์„ ๊ตฌํ˜„ํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. How to solve the problem ์ €๋Š” ํ† ๊ธ€ ๋ฒ„ํŠผ์„ ๊ตฌํ˜„ํ•˜๊ธฐ ์œ„ํ•ด์„œ useState hook์„ ์‚ฌ์šฉํ•˜์˜€์Šต๋‹ˆ๋‹ค. useState hook is used to initialize with initial value and function which changes its value on click event handler. ์šฐ์„  ์ฒ˜์Œ ํ† ๊ธ€๋ฒ„ํŠผ์˜ on/off ์ƒํƒœ๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” state๋ฅผ ๋งŒ๋“ค์–ด์ค๋‹ˆ๋‹ค. const [isOff, setIsOff] = useState(true); ์ดํ›„ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•  ๋•Œ๋งˆ๋‹ค, ํ•ด๋‹น state๋ฅผ ์‚ฌ์šฉํ•ด์ค๋‹ˆ๋‹ค. on/off ์ƒํƒœ์— ๋”ฐ๋ผ css class๋„ ๋‹ค๋ฅด๊ฒŒ ์ ์šฉํ•ด์ค„ ..

Framework/React 2023.03.11

[React] apexcharts legend ๋ฒ”๋ก€ padding ์กฐ์ ˆํ•˜๋Š” ๋ฐฉ๋ฒ•

Intro ์•ˆ๋…•ํ•˜์„ธ์š”. ์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š” apexcharts ์—์„œ legend(๋ฒ”๋ก€) padding์„ ์กฐ์ ˆํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ์ œ ๊ฒฝ์šฐ ์•„๋ž˜์˜ ์ฐจํŠธ legend ๋ฒ”๋ก€๊ฐ€ ๊ธฐ์ค€ ์ขŒํ‘œ์— ๋น„ํ•ด ๋„ˆ๋ฌด ์™ผ์ชฝ์œผ๋กœ ์น˜์šฐ์ณ์ ธ ์žˆ์–ด์„œ left-padding์œผ๋กœ ํ•ด๊ฒฐํ•˜๊ณ  ์‹ถ์—ˆ์Šต๋‹ˆ๋‹ค. First try ์šฐ์„  ์ €๋Š”apexchart lengend ์˜ ์†์„ฑ์— padding ์†์„ฑ ์œ ๋ฌด๊ฐ€ ์žˆ๋Š”์ง€ ๊ฒ€์ƒ‰ํ•ด๋ดค์Šต๋‹ˆ๋‹ค. apexChart ๋‚ด legend ์†์„ฑ์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค. padding ๊ด€๋ จ ์†์„ฑ์ด ์—†๋Š” ๊ฒƒ ๊ฐ™์•˜์Šต๋‹ˆ๋‹ค. legend: { show: true, showForSingleSeries: false, showForNullSeries: true, showForZeroSeries: true, position: 'bottom'..

Framework/React 2023.03.09
๋ฐ˜์‘ํ˜•