Skip to content

Commit 803f5c8

Browse files
committed
Modal base
1 parent d6c1602 commit 803f5c8

File tree

7 files changed

+106
-18
lines changed

7 files changed

+106
-18
lines changed

app/components/mappings/rotate.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { environment } from '#store/environment';
33
import { observer } from 'mobx-react';
44
import { exportSprite } from '#formats/image';
55
import rotSprite, { Pixels, addMarginToImageData, getRotateDiagonal } from '#util/rotsprite';
6-
import { Input, Slider, Item, SelectBase, Button } from '#ui';
6+
import { Input, Slider, Item, SelectBase, Button, Modal } from '#ui';
77
import { mappingState } from './state';
88

99
export const Rotate = observer(() => {
@@ -12,6 +12,7 @@ export const Rotate = observer(() => {
1212
const [value, setValue] = useState(0);
1313

1414
useEffect(() => {
15+
if (!canvasRef.current) return;
1516
const spriteCanv = exportSprite(environment.currentSprite);
1617
const spriteCtx = spriteCanv.getContext('2d');
1718

@@ -71,14 +72,20 @@ export const Rotate = observer(() => {
7172
};
7273

7374
return (
74-
<div className="rotsprite">
75-
<Item>Rotate Sprite</Item>
76-
<canvas ref={canvasRef} />
75+
<>
76+
{String(!!value)}
7777
<SelectBase
78-
options={[...Array(7).keys()].map(d => String(d*90))}
78+
options={[...Array(2).keys()].map(d => String(d))}
7979
value={value}
80-
onChange={e => setValue(e.value)}
80+
onChange={e => setValue(e.value==='1')}
8181
/>
82+
83+
<Modal className="rotsprite" spring={({
84+
top: value ? -150 : 50,
85+
opacity: value? 1 : 0.5,
86+
})}>
87+
<Item>Rotate Sprite</Item>
88+
<canvas ref={canvasRef} />
8289
<Input
8390
store={mappingState}
8491
assert={assertInput}
@@ -94,6 +101,7 @@ export const Rotate = observer(() => {
94101
/>
95102
<Button color="red">Reimport</Button>
96103
<Button color="magenta">close</Button>
97-
</div>
104+
</Modal>
105+
</>
98106
);
99107
});

app/components/ui/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ export { File } from './file';
55
export { Select, SelectBase } from './select';
66
export { Slider } from './slider';
77
export { Checkbox } from './checkbox';
8+
export { Modal } from './modal';

app/components/ui/modal/index.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React, { useState, useEffect } from 'react';
2+
import { useSpring, animated } from '@react-spring/web';
3+
4+
export function Modal({ spring, children, className = '' }) {
5+
const isOpen = spring.opacity === 1;
6+
const [shouldRender, setShouldRender] = useState(isOpen);
7+
8+
useEffect(() => {
9+
if (isOpen) {
10+
setShouldRender(true);
11+
}
12+
}, [isOpen]);
13+
14+
const styles = useSpring({
15+
to: spring,
16+
onRest: () => {
17+
setShouldRender(isOpen);
18+
},
19+
});
20+
21+
if (!shouldRender) return false;
22+
23+
return (
24+
<animated.div style={styles} className={`modal ${className}`}>
25+
{children}
26+
</animated.div>
27+
);
28+
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
},
1111
"dependencies": {
1212
"@electron/remote": "^1.1.0",
13+
"@react-spring/web": "^9.6.0",
1314
"arcsecond": "^3.1.2",
1415
"array-move": "^3.0.1",
1516
"classnames": "^2.2.5",

styles/components/rotsprite.scss

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11
.rotsprite {
2-
.close {
3-
display: flex;
4-
justify-content: space-between;
5-
margin-bottom: 10px;
6-
}
7-
box-sizing: content-box;
8-
position: absolute;
92
z-index: 3;
10-
background-color: $black;
113
left: 15px;
124
right: 15px;
13-
box-shadow: 2px 2px 4px $black;
14-
padding: 15px;
15-
margin-top: 100px;
165

176
canvas {
187
background-image: url(../images/t.png);
198
border: 3px solid $grey;
209
width: 400px;
2110
height: 400px;
2211
}
12+
13+
.close {
14+
display: flex;
15+
justify-content: space-between;
16+
margin-bottom: 10px;
17+
}
2318
}

styles/components/ui.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,12 @@ input {
170170
}
171171

172172
}
173+
174+
.modal {
175+
box-sizing: content-box;
176+
position: absolute;
177+
z-index: 1;
178+
background-color: $black;
179+
box-shadow: 2px 2px 4px $black;
180+
padding: 15px;
181+
}

yarn.lock

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,52 @@
165165
resolved "https://registry.yarnpkg.com/@react-dnd/shallowequal/-/shallowequal-2.0.0.tgz#a3031eb54129f2c66b2753f8404266ec7bf67f0a"
166166
integrity sha512-Pc/AFTdwZwEKJxFJvlxrSmGe/di+aAOBn60sremrpLo6VI/6cmiUYNNwlI5KNYttg7uypzA3ILPMPgxB2GYZEg==
167167

168+
"@react-spring/animated@~9.6.0":
169+
version "9.6.0"
170+
resolved "https://registry.yarnpkg.com/@react-spring/animated/-/animated-9.6.0.tgz#3ac531d82e35e4ad205456f9fe9464e2bbcb1c5f"
171+
integrity sha512-YFBLQ3bnGlUaWA9eVcZ7K1nfgVSF30XPfwqag5hlswYcMi7C5zVriFqN4oxRyDAFHfmNpPfFCRHmgP52L3GF1A==
172+
dependencies:
173+
"@react-spring/shared" "~9.6.0"
174+
"@react-spring/types" "~9.6.0"
175+
176+
"@react-spring/core@~9.6.0":
177+
version "9.6.0"
178+
resolved "https://registry.yarnpkg.com/@react-spring/core/-/core-9.6.0.tgz#081c44e4005c52e7e6957ba151a697709cc0b05a"
179+
integrity sha512-CCU6MOp6Hk29qFhC+8/Hty5Rh8b4TcHvLjFX1GP9i2iXvw77WayRyy+Wi+KCt+RD+xXO2fi9bNWcloOHPHJp/g==
180+
dependencies:
181+
"@react-spring/animated" "~9.6.0"
182+
"@react-spring/rafz" "~9.6.0"
183+
"@react-spring/shared" "~9.6.0"
184+
"@react-spring/types" "~9.6.0"
185+
186+
"@react-spring/rafz@~9.6.0":
187+
version "9.6.0"
188+
resolved "https://registry.yarnpkg.com/@react-spring/rafz/-/rafz-9.6.0.tgz#8c46fff30157159775eb9007094dae3400390728"
189+
integrity sha512-Vw8IwWXWEMszef8V/yemSR8YZe4cbX84JrMMuW+UE5Ha1/mOCznlFU59fKJxQQA/UJlfY70K9oZ+aboFgWWk0g==
190+
191+
"@react-spring/shared@~9.6.0":
192+
version "9.6.0"
193+
resolved "https://registry.yarnpkg.com/@react-spring/shared/-/shared-9.6.0.tgz#4ccdf911d64dacb409c5f292de65fdb8ad41508f"
194+
integrity sha512-Kama7SJiAajZsjfTJAxLDndxeYr0Qin6Ust9Wn/gRCVC1maXJ79Su0gsQYapSA0+Nmkxdi+RiXJUDmGX6LMuuw==
195+
dependencies:
196+
"@react-spring/rafz" "~9.6.0"
197+
"@react-spring/types" "~9.6.0"
198+
199+
"@react-spring/types@~9.6.0":
200+
version "9.6.0"
201+
resolved "https://registry.yarnpkg.com/@react-spring/types/-/types-9.6.0.tgz#9ba7061fef88ffa872b7898fcf008ffb29a51d90"
202+
integrity sha512-XOWupgf+/rMhQTiIxZzjVRw+4ZNkXcO5tuha3pOBNK88a7LPGjM6imdS1aQ2kl3y1sBy0f9JrclNShfASbkvTw==
203+
204+
"@react-spring/web@^9.6.0":
205+
version "9.6.0"
206+
resolved "https://registry.yarnpkg.com/@react-spring/web/-/web-9.6.0.tgz#81fcdc1dc6efe6caedf2ef7f706bd18500e7b582"
207+
integrity sha512-ztdkBmRZB020MEPEU8gXlbkE6858/IdA2P37RvcjOHq4tEpIizrsh/XTipU+T5iyrbT6UQLnh4JnIWow4jfOmg==
208+
dependencies:
209+
"@react-spring/animated" "~9.6.0"
210+
"@react-spring/core" "~9.6.0"
211+
"@react-spring/shared" "~9.6.0"
212+
"@react-spring/types" "~9.6.0"
213+
168214
"@sindresorhus/is@^0.14.0":
169215
version "0.14.0"
170216
resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-0.14.0.tgz#9fb3a3cf3132328151f353de4632e01e52102bea"

0 commit comments

Comments
 (0)