Skip to content
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

[SpeedDialAction] pass through button color props to speed dial action button #12986

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions docs/src/pages/lab/speed-dial/ColoredSpeedDialActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import Button from '@material-ui/core/Button';
import SpeedDial from '@material-ui/lab/SpeedDial';
import SpeedDialIcon from '@material-ui/lab/SpeedDialIcon';
import SpeedDialAction from '@material-ui/lab/SpeedDialAction';
import FileCopyIcon from '@material-ui/icons/FileCopyOutlined';
import SaveIcon from '@material-ui/icons/Save';
import PrintIcon from '@material-ui/icons/Print';
import ShareIcon from '@material-ui/icons/Share';
import DeleteIcon from '@material-ui/icons/Delete';
import EditIcon from '@material-ui/icons/Edit';

const styles = theme => ({
root: {
height: 380,
},
speedDial: {
position: 'absolute',
bottom: theme.spacing.unit * 2,
right: theme.spacing.unit * 3,
},
});

const actions = [
{ icon: <FileCopyIcon />, name: 'Copy', color: 'primary' },
{ icon: <SaveIcon />, name: 'Save', color: 'secondary' },
{ icon: <PrintIcon />, name: 'Print' },
{ icon: <ShareIcon />, name: 'Share' },
{ icon: <DeleteIcon />, name: 'Delete' },
];

class ColoredSpeedDialActions extends React.Component {
state = {
open: false,
hidden: false,
};

handleVisibility = () => {
this.setState(state => ({
open: false,
hidden: !state.hidden,
}));
};

handleClick = () => {
this.setState(state => ({
open: !state.open,
}));
};

handleOpen = () => {
if (!this.state.hidden) {
this.setState({
open: true,
});
}
};

handleClose = () => {
this.setState({
open: false,
});
};

render() {
const { classes } = this.props;
const { hidden, open } = this.state;

return (
<div className={classes.root}>
<Button onClick={this.handleVisibility}>Toggle Speed Dial</Button>
<SpeedDial
ariaLabel="SpeedDial openIcon example"
className={classes.speedDial}
hidden={hidden}
icon={<SpeedDialIcon openIcon={<EditIcon />} />}
onBlur={this.handleClose}
onClick={this.handleClick}
onClose={this.handleClose}
onFocus={this.handleOpen}
onMouseEnter={this.handleOpen}
onMouseLeave={this.handleClose}
open={open}
>
{actions.map(action => (
<SpeedDialAction
key={action.name}
ButtonProps={{
color: action.color,
}}
icon={action.icon}
tooltipTitle={action.name}
onClick={this.handleClick}
/>
))}
</SpeedDial>
</div>
);
}
}

ColoredSpeedDialActions.propTypes = {
classes: PropTypes.object.isRequired,
};

export default withStyles(styles)(ColoredSpeedDialActions);
6 changes: 6 additions & 0 deletions docs/src/pages/lab/speed-dial/speed-dial.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ The SpeedDialActions tooltips can be be displayed persistently so that users don
It is enabled here across all devices for demo purposes, but in production it could use the `isTouch` logic to conditionally set the property.

{{"demo": "pages/lab/speed-dial/SpeedDialTooltipOpen.js"}}

## Colored action buttons

The SpeedDialActions can be colored.

{{"demo": "pages/lab/speed-dial/ColoredSpeedDialActions.js"}}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { withStyles } from '@material-ui/core/styles';
import { emphasize } from '@material-ui/core/styles/colorManipulator';
import Button from '@material-ui/core/Button';
import Tooltip from '@material-ui/core/Tooltip';

Expand All @@ -14,11 +13,6 @@ export const styles = theme => ({
/* Styles applied to the `Button` component. */
button: {
margin: 8,
color: theme.palette.text.secondary,
backgroundColor: emphasize(theme.palette.background.default, 0.12),
'&:hover': {
backgroundColor: emphasize(theme.palette.background.default, 0.15),
},
transition: `${theme.transitions.create('transform', {
duration: theme.transitions.duration.shorter,
})}, opacity 0.8s`,
Expand Down
7 changes: 7 additions & 0 deletions pages/lab/speed-dial.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ module.exports = require('fs')
raw: preval`
module.exports = require('fs')
.readFileSync(require.resolve('docs/src/pages/lab/speed-dial/SpeedDialTooltipOpen'), 'utf8')
`,
},
'pages/lab/speed-dial/ColoredSpeedDialActions.js': {
js: require('docs/src/pages/lab/speed-dial/ColoredSpeedDialActions').default,
raw: preval`
module.exports = require('fs')
.readFileSync(require.resolve('docs/src/pages/lab/speed-dial/ColoredSpeedDialActions'), 'utf8')
`,
},
}}
Expand Down