From f4c06c0dfc26e219f5d9ee616d5a4aa415efe6fd Mon Sep 17 00:00:00 2001 From: Sean Chamberlain Date: Wed, 25 Jul 2018 10:46:45 +0930 Subject: [PATCH] Allows the actions of speed dial to be placed in any direction --- .../src/SpeedDial/SpeedDial.d.ts | 11 +++-- .../src/SpeedDial/SpeedDial.js | 40 +++++++++++++++++-- .../src/SpeedDial/SpeedDial.test.js | 22 ++++++++++ pages/lab/api/speed-dial.md | 5 +++ 4 files changed, 71 insertions(+), 7 deletions(-) diff --git a/packages/material-ui-lab/src/SpeedDial/SpeedDial.d.ts b/packages/material-ui-lab/src/SpeedDial/SpeedDial.d.ts index f7db93a28467bd..22deadaf281153 100644 --- a/packages/material-ui-lab/src/SpeedDial/SpeedDial.d.ts +++ b/packages/material-ui-lab/src/SpeedDial/SpeedDial.d.ts @@ -6,9 +6,14 @@ import { TransitionHandlerProps } from '@material-ui/core/transitions/transition export interface SpeedDialProps extends StandardProps< - React.HTMLAttributes & Partial, - SpeedDialClassKey - > { + React.HTMLAttributes & Partial, + SpeedDialClassKey + > { + actionsPlacement?: + | 'top' + | 'bottom' + | 'left' + | 'right'; ariaLabel: string; ButtonProps?: Partial; hidden?: boolean; diff --git a/packages/material-ui-lab/src/SpeedDial/SpeedDial.js b/packages/material-ui-lab/src/SpeedDial/SpeedDial.js index b1697a34f07faf..be9e92ef62c1de 100644 --- a/packages/material-ui-lab/src/SpeedDial/SpeedDial.js +++ b/packages/material-ui-lab/src/SpeedDial/SpeedDial.js @@ -15,12 +15,26 @@ export const styles = { root: { zIndex: 1050, display: 'flex', - flexDirection: 'column-reverse', // Place the Actions above the FAB. + }, + /* Styles when actions are placed to the top */ + actionsTop: { + flexDirection: 'column-reverse', + }, + /* Styles when actions are placed to the bottom */ + actionsBottom: { + flexDirection: 'column', + }, + /* Styles when actions are placed to the left */ + actionsLeft: { + flexDirection: 'row-reverse', + }, + /* Styles when actions are placed to the right */ + actionsRight: { + flexDirection: 'row', }, /* Styles applied to the actions (`children` wrapper) element. */ actions: { display: 'flex', - flexDirection: 'column-reverse', // Display the first action at the bottom. marginBottom: 16, }, /* Styles applied to the actions (`children` wrapper) element if `open={false}`. */ @@ -102,6 +116,7 @@ class SpeedDial extends React.Component { onClose, onKeyDown, open, + actionsPlacement, openIcon, TransitionComponent, transitionDuration, @@ -151,8 +166,15 @@ class SpeedDial extends React.Component { return icon; }; + const actionsPlacementClass = { + [classes.actionsTop]: actionsPlacement === 'top', + [classes.actionsBottom]: actionsPlacement === 'bottom', + [classes.actionsLeft]: actionsPlacement === 'left', + [classes.actionsRight]: actionsPlacement === 'right', + } + return ( -
+
{ this.actionsRef = ref; }} @@ -191,6 +213,15 @@ class SpeedDial extends React.Component { } SpeedDial.propTypes = { + /** + * The placement of floating actions buttons in relation to speed dial. + */ + actionsPlacement: PropTypes.oneOf([ + 'top', + 'bottom', + 'left', + 'right', + ]), /** * The aria-label of the `Button` element. * Also used to provide the `id` for the `SpeedDial` element and its children. @@ -265,6 +296,7 @@ SpeedDial.propTypes = { SpeedDial.defaultProps = { hidden: false, + actionsPlacement: 'top', TransitionComponent: Zoom, transitionDuration: { enter: duration.enteringScreen, diff --git a/packages/material-ui-lab/src/SpeedDial/SpeedDial.test.js b/packages/material-ui-lab/src/SpeedDial/SpeedDial.test.js index d38ca042a99be9..7143f51a15e036 100644 --- a/packages/material-ui-lab/src/SpeedDial/SpeedDial.test.js +++ b/packages/material-ui-lab/src/SpeedDial/SpeedDial.test.js @@ -129,4 +129,26 @@ describe('', () => { assert.strictEqual(handleKeyDown.args[0][0], event); }); }); + + describe('prop: actionPlacement', () => { + const testPlacement = placement => { + const className = `actions${placement}`; + const wrapper = shallow( + + + + , + ); + const actionsWrapper = wrapper.childAt(1); + assert.strictEqual(wrapper.hasClass(classes[className]), true); + assert.strictEqual(actionsWrapper.hasClass(classes[className]), true); + }; + + it('should place actions in correct position', () => { + testPlacement('Left'); + testPlacement('Right'); + testPlacement('Top'); + testPlacement('Bottom'); + }); + }); }); diff --git a/pages/lab/api/speed-dial.md b/pages/lab/api/speed-dial.md index 84129e6a88572c..bbb659c04f5023 100644 --- a/pages/lab/api/speed-dial.md +++ b/pages/lab/api/speed-dial.md @@ -15,6 +15,7 @@ title: SpeedDial API | Name | Type | Default | Description | |:-----|:-----|:--------|:------------| +| actionsPlacement | enum: 'top' |
 'bottom' |
 'left' |
 'right'
| 'top' | The placement of floating actions buttons in relation to speed dial. | | ariaLabel * | string |   | The aria-label of the `Button` element. Also used to provide the `id` for the `SpeedDial` element and its children. | | ButtonProps | object |   | Properties applied to the [`Button`](/api/button) element. | | children * | node |   | SpeedDialActions to display when the SpeedDial is `open`. | @@ -39,6 +40,10 @@ This property accepts the following keys: | Name | Description | |:-----|:------------| | root | Styles applied to the root element. +| actionsTop | Styles when actions are placed to the top +| actionsBottom | Styles when actions are placed to the bottom +| actionsLeft | Styles when actions are placed to the left +| actionsRight | Styles when actions are placed to the right | actions | Styles applied to the actions (`children` wrapper) element. | actionsClosed | Styles applied to the actions (`children` wrapper) element if `open={false}`.