-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
FloatingActionButton: added the component to be used in smaller views #2347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d492fda
c3a72d5
7cf588a
daa8bf5
b8adaf8
11f696d
fc4abb7
b5aae6b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
import classNames from 'classnames'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import PropTypes from 'prop-types'; | ||
import PlayIcon from '../../../images/triangle-arrow-right.svg'; | ||
import StopIcon from '../../../images/stop.svg'; | ||
import { prop, remSize } from '../../../theme'; | ||
import { startSketch, stopSketch } from '../actions/ide'; | ||
|
||
const Button = styled.button` | ||
position: fixed; | ||
right: ${remSize(20)}; | ||
bottom: ${remSize(20)}; | ||
height: ${remSize(60)}; | ||
width: ${remSize(60)}; | ||
z-index: 3; | ||
padding: 0; | ||
${prop('Button.secondary.default')}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another variable that's not assigned to any property. |
||
aspect-ratio: 1/1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This property has way more support than I thought! It's not really necessary since you've defined both a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah 😂😂 |
||
border-radius: 99999px; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px; | ||
&.stop { | ||
${prop('Button.primary.default')} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we've got a color here with no property! |
||
g { | ||
fill: ${prop('Button.primary.default.foreground')}; | ||
} | ||
} | ||
> svg { | ||
width: 35%; | ||
height: 35%; | ||
> g { | ||
fill: ${prop('Button.primary.hover.foreground')}; | ||
} | ||
} | ||
`; | ||
|
||
const FloatingActionButton = (props) => { | ||
const isPlaying = useSelector((state) => state.ide.isPlaying); | ||
const dispatch = useDispatch(); | ||
|
||
return ( | ||
<Button | ||
className={classNames({ stop: isPlaying })} | ||
style={{ paddingLeft: isPlaying ? 0 : remSize(5) }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't love this but I know it's here to fix a genuine problem so it's best to keep it for now so as not to fall deep into an SVG rabbit hole. We need this because the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah exactly that's what I thought, but let's keep it for now we'll remove it when we decide to replace the Icon with a better one. |
||
onClick={() => { | ||
if (!isPlaying) { | ||
props.syncFileContent(); | ||
dispatch(startSketch()); | ||
} else dispatch(stopSketch()); | ||
}} | ||
> | ||
{isPlaying ? <StopIcon /> : <PlayIcon />} | ||
</Button> | ||
); | ||
}; | ||
|
||
FloatingActionButton.propTypes = { | ||
syncFileContent: PropTypes.func.isRequired | ||
}; | ||
|
||
export default FloatingActionButton; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just want to note some of the ideas that we've tossed around regarding this element, potentially for future refactorings but not for right now:
styled
part as a reusableFloatingActionButton
UI component, and make this specificStartStopButton
be an instance of that commonFloatingActionButton
. (This fits with best practices, but is kind of silly since there are no other floating action buttons anywhere else in the app.)StartStopButton
from the desktop toolbar into its own component (see Break upToolbar
elements #2239). That component would need to take aclassName
prop in order to be stylable withstyled-components
. This floating version for mobile could be astyled(StartStopButton)
, where we only need to specify the styles to override like the position and size. The positioning could also potentially be handled by a separatediv
which has the button as a child.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the
StartStopButton
is a great idea and since we do not have any more floating action buttons anywhere else in the app but when I made it I thought it would be reusable and we should definitely export the styled part as a floating action button and the start-stop button should be passed in as a child element. let me know when we want to do it