Skip to content

Commit 22dee37

Browse files
committed
Add starburst on change to 2.0
1 parent b209f84 commit 22dee37

File tree

6 files changed

+116
-10
lines changed

6 files changed

+116
-10
lines changed

client/modules/IDE/components/Header/Toolbar.jsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import PlayIcon from '../../../../images/play.svg';
2020
import StopIcon from '../../../../images/stop.svg';
2121
import PreferencesIcon from '../../../../images/preferences.svg';
2222
import ProjectName from './ProjectName';
23-
import VersionPicker from '../VersionPicker';
2423

2524
const Toolbar = (props) => {
2625
const { isPlaying, infiniteLoop, preferencesIsVisible } = useSelector(
@@ -98,9 +97,6 @@ const Toolbar = (props) => {
9897
{t('Toolbar.Auto-refresh')}
9998
</label>
10099
</div>
101-
<div className="toolbar__version-picker">
102-
<VersionPicker />
103-
</div>
104100
<div className="toolbar__project-name-container">
105101
<ProjectName />
106102
{(() => {

client/modules/IDE/components/Preferences/index.jsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import VersionPicker from '../VersionPicker';
2424
import { updateFileContent } from '../../actions/files';
2525
import { CmControllerContext } from '../../pages/IDEView';
2626
import Button from '../../../../common/Button';
27+
import Stars from '../Stars';
2728

2829
export default function Preferences() {
2930
const { t } = useTranslation();
@@ -47,6 +48,18 @@ export default function Preferences() {
4748
const [state, setState] = useState({ fontSize });
4849
const { versionInfo, indexID } = useP5Version();
4950
const cmRef = useContext(CmControllerContext);
51+
const [showStars, setShowStars] = useState(null);
52+
const timerRef = useRef(null);
53+
const pickerRef = useRef(null);
54+
const onChangeVersion = (version) => {
55+
const shouldShowStars = version.startsWith('2.');
56+
const box = pickerRef.current?.getBoundingClientRect();
57+
if (shouldShowStars) {
58+
setShowStars({ left: box?.left || 0, top: box?.top || 0 });
59+
clearTimeout(timerRef.current);
60+
timerRef.current = setTimeout(() => setShowStars(null), 3000);
61+
}
62+
};
5063

5164
function onFontInputChange(event) {
5265
const INTEGER_REGEX = /^[0-9\b]+$/;
@@ -484,7 +497,11 @@ export default function Preferences() {
484497
{t('Preferences.LibraryVersion')}
485498
</h4>
486499
<div>
487-
<VersionPicker />
500+
{showStars && <Stars top={showStars.top} left={showStars.left} />}
501+
<VersionPicker
502+
ref={pickerRef}
503+
onChangeVersion={onChangeVersion}
504+
/>
488505
{versionInfo && indexID ? (
489506
<p className="preference__paragraph">
490507
{t('Preferences.LibraryVersionInfo')}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import React, { useMemo } from 'react';
2+
import PropTypes from 'prop-types';
3+
import AsteriskIcon from '../../../images/p5-asterisk.svg';
4+
5+
const Stars = ({ top, left }) => {
6+
const stars = useMemo(() => {
7+
const styles = [];
8+
9+
for (let i = 0; i < 20; i += 1) {
10+
const x = Math.round(Math.random() * 200 - 100);
11+
const y = Math.round(Math.random() * 200 - 100);
12+
const s = 3 + Math.random() * 2;
13+
const rotation = Math.random() * Math.PI * 2;
14+
const style = {
15+
transform: `translate(${x}px, ${y}px) scale(${s.toFixed(
16+
4
17+
)}) rotate(${rotation.toFixed(4)}rad)`
18+
};
19+
const key = i;
20+
styles.push({ style, key });
21+
}
22+
23+
return styles;
24+
}, []);
25+
26+
return (
27+
<div
28+
className="stars"
29+
style={{
30+
top,
31+
left
32+
}}
33+
>
34+
{stars.map(({ style, key }) => (
35+
<AsteriskIcon
36+
key={key}
37+
className="stars__star"
38+
style={style}
39+
focusable="false"
40+
/>
41+
))}
42+
</div>
43+
);
44+
};
45+
46+
Stars.propTypes = {
47+
top: PropTypes.number.isRequired,
48+
left: PropTypes.number.isRequired
49+
};
50+
51+
export default Stars;
Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
import React, { useCallback, useContext } from 'react';
22
import { useDispatch } from 'react-redux';
33
import { useTranslation } from 'react-i18next';
4+
import PropTypes from 'prop-types';
45

56
import { useP5Version, p5Versions } from '../hooks/useP5Version';
67
import MenuItem from '../../../components/Dropdown/MenuItem';
78
import DropdownMenu from '../../../components/Dropdown/DropdownMenu';
89
import { updateFileContent } from '../actions/files';
910
import { CmControllerContext } from '../pages/IDEView';
1011

11-
const VersionPicker = () => {
12+
const VersionPicker = React.forwardRef(({ onChangeVersion }, ref) => {
1213
const { indexID, versionInfo } = useP5Version();
1314
const { t } = useTranslation();
1415
const dispatch = useDispatch();
1516
const cmRef = useContext(CmControllerContext);
1617
const dispatchReplaceVersion = useCallback(
1718
(version) => {
1819
if (!indexID || !versionInfo) return;
20+
if (onChangeVersion) {
21+
onChangeVersion(version);
22+
}
1923
const src = versionInfo.replaceVersion(version);
2024
dispatch(updateFileContent(indexID, src));
2125
cmRef.current?.updateFileContent(indexID, src);
2226
},
23-
[indexID, versionInfo, cmRef]
27+
[indexID, versionInfo, cmRef, onChangeVersion]
2428
);
2529

2630
if (!versionInfo) {
@@ -31,7 +35,11 @@ const VersionPicker = () => {
3135

3236
return (
3337
<DropdownMenu
34-
anchor={<span className="versionPicker">{versionInfo.version}</span>}
38+
anchor={
39+
<span className="versionPicker" ref={ref}>
40+
{versionInfo.version}
41+
</span>
42+
}
3543
align="left"
3644
>
3745
{p5Versions.map((version) => (
@@ -41,8 +49,13 @@ const VersionPicker = () => {
4149
))}
4250
</DropdownMenu>
4351
);
44-
};
52+
});
4553

46-
VersionPicker.propTypes = {};
54+
VersionPicker.propTypes = {
55+
onChangeVersion: PropTypes.func
56+
};
57+
VersionPicker.defaultProps = {
58+
onChangeVersion: undefined
59+
};
4760

4861
export default VersionPicker;

client/styles/components/_stars.scss

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
@keyframes starburst {
2+
from {
3+
transform: translate(0, 0) scale(0) rotate(0);
4+
}
5+
to {
6+
opacity: 0;
7+
}
8+
}
9+
10+
.stars {
11+
position: fixed;
12+
top: 0;
13+
left: 0;
14+
z-index: 9000;
15+
width: 0;
16+
height: 0;
17+
pointer-events: none;
18+
}
19+
20+
.stars__star {
21+
position: absolute;
22+
left: 0;
23+
top: 0;
24+
transform-origin: 50% 50%;
25+
animation: starburst 1.5s;
26+
animation-timing-function: ease-out;
27+
animation-fill-mode: forwards;
28+
}

client/styles/main.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
@import 'components/collection-create';
5454
@import 'components/quick-add';
5555
@import 'components/skip-link';
56+
@import 'components/stars';
5657

5758
@import 'layout/dashboard';
5859
@import 'layout/ide';

0 commit comments

Comments
 (0)