Skip to content

Commit

Permalink
Merge pull request #851 from hackforla/835-settingGear-button
Browse files Browse the repository at this point in the history
Add GearButton
  • Loading branch information
Tanvez authored Dec 3, 2020
2 parents 697459d + c0cf646 commit 2dcf7c4
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions client/components/GearButton/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import React, { useState } from 'react';
import PropTypes from 'proptypes';
import { IconButton } from '@material-ui/core';
import { makeStyles } from '@material-ui/core/styles';
import SettingsSharpIcon from '@material-ui/icons/SettingsSharp';

const useStyles = makeStyles({
gearIcon: {
color: 'white',
background: '#29404F',
borderRadius: '12px',
height: '33px',
width: '33px',
padding: '6px',
},
button: {
padding: '0',
},
});

const GearButton = ({ onClick }) => {
const { gearIcon, button } = useStyles();
const [pressed, setPressed] = useState(false);

const onKeyDown = e => {
e.preventDefault();
if (e.key === ' '
|| e.key === 'Enter'
|| e.key === 'Spacebar'
) {
setPressed(!pressed);
onClick();
}
};
const toggleClick = () => {
setPressed(!pressed);
onClick();
};
return (
<IconButton
className={button}
onClick={toggleClick}
onKeyDown={onKeyDown}
role="button"
aria-pressed={pressed}
aria-label="Toggle Sidebar"
>
<SettingsSharpIcon className={gearIcon} />
</IconButton>
);
};

GearButton.propTypes = {
onClick: PropTypes.func,
};
GearButton.defaultProps = {
onClick: undefined,
};

export default GearButton;

0 comments on commit 2dcf7c4

Please sign in to comment.