Skip to content

Commit f7ace88

Browse files
authored
Merge pull request #2347 from dewanshDT/dewanshmobile/FAB
FloatingActionButton: added the component to be used in smaller views
2 parents 37ee7af + b5aae6b commit f7ace88

File tree

1 file changed

+65
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)