File tree Expand file tree Collapse file tree 2 files changed +30
-4
lines changed
Expand file tree Collapse file tree 2 files changed +30
-4
lines changed Original file line number Diff line number Diff line change 1+ interface SizeUpdaterProps {
2+ onChange : ( size : number ) => void
3+ }
4+ export const sizeUpdater = ( { onChange } : SizeUpdaterProps ) => {
5+ let size = 100
6+
7+ const sizeUpdater = document . createElement ( 'div' )
8+ const sizeInput = document . createElement ( 'input' )
9+ sizeInput . type = 'number'
10+ sizeInput . value = size . toString ( )
11+
12+ sizeInput . addEventListener ( 'change' , ( ) => {
13+ size = parseInt ( sizeInput . value )
14+ } )
15+
16+ sizeUpdater . appendChild ( sizeInput )
17+
18+ const sizeApplyButton = document . createElement ( 'button' )
19+ sizeApplyButton . textContent = 'Apply size'
20+ sizeUpdater . appendChild ( sizeApplyButton )
21+
22+ sizeApplyButton . addEventListener ( 'click' , ( ) => {
23+ onChange ( size )
24+ } )
25+
26+ return sizeUpdater
27+ }
Original file line number Diff line number Diff line change 1+ import { sizeUpdater } from './components/sizeUpdater'
12import { Board } from "./Board/Board"
23
34const container = document . getElementById ( 'app' )
45
56if ( container ) {
6- const sizeInput = document . createElement ( 'input' )
7- sizeInput . type = 'number'
8- sizeInput . value = '100'
9- container . appendChild ( sizeInput )
7+ const sizeUpdaterElement = sizeUpdater ( { onChange : console . log } )
8+ container . appendChild ( sizeUpdaterElement )
109
1110 const canvas = document . createElement ( 'canvas' )
1211 const ctx = canvas . getContext ( '2d' ) as CanvasRenderingContext2D
You can’t perform that action at this time.
0 commit comments