Skip to content

Commit d492fda

Browse files
committed
floating action button for mobile
1 parent 279364f commit d492fda

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import React from 'react';
2+
import styled from 'styled-components';
3+
import { useDispatch, useSelector } from 'react-redux';
4+
import PropTypes from 'prop-types';
5+
import PlayIcon from '../../../images/triangle-arrow-right.svg';
6+
import StopIcon from '../../../images/stop.svg';
7+
import { prop, remSize } from '../../../theme';
8+
import { startSketch, stopSketch } from '../actions/ide';
9+
10+
const Button = styled.div`
11+
position: fixed;
12+
right: ${remSize(20)};
13+
bottom: ${remSize(20)};
14+
height: ${remSize(60)};
15+
width: ${remSize(60)};
16+
z-index: 3;
17+
cursor: pointer;
18+
${prop('Button.secondary.default')};
19+
aspect-ratio: 1/1;
20+
border-radius: 99999px;
21+
display: flex;
22+
justify-content: center;
23+
align-items: center;
24+
box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
25+
/* scale: 0.75; */
26+
/* padding-left: 1.8rem; */
27+
&[data-behaviour='stop'] {
28+
${prop('Button.primary.default')}
29+
g {
30+
fill: ${prop('Button.primary.default.foreground')};
31+
}
32+
}
33+
> svg {
34+
width: 35%;
35+
height: 35%;
36+
> g {
37+
fill: white;
38+
}
39+
}
40+
`;
41+
42+
const FloatingActionButton = (props) => {
43+
const isPlaying = useSelector((state) => state.ide.isPlaying);
44+
const dispatch = useDispatch();
45+
46+
return (
47+
<Button
48+
data-behaviour={isPlaying ? 'stop' : 'run'}
49+
style={{ paddingLeft: isPlaying ? 0 : remSize(5) }}
50+
onClick={() => {
51+
if (!isPlaying) {
52+
props.syncFileContent();
53+
dispatch(startSketch());
54+
}
55+
if (isPlaying) dispatch(stopSketch());
56+
}}
57+
>
58+
{isPlaying ? <StopIcon /> : <PlayIcon />}
59+
</Button>
60+
);
61+
};
62+
63+
FloatingActionButton.propTypes = {
64+
syncFileContent: PropTypes.func.isRequired
65+
};
66+
67+
export default FloatingActionButton;

0 commit comments

Comments
 (0)