diff --git a/.gitignore b/.gitignore index 9f11b75..ac54aa1 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,20 @@ .idea/ + +npm-debug.log* + +# Dist folder +dist + +# Dependency directories +node_modules + +# Optional npm cache directory +.npm + +# Optional REPL history +.node_repl_history + +# OS files +.DS_Store +.idea +npm-debug.log diff --git a/README.md b/README.md index 7513287..92d1af0 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,7 @@ transforms into a "close" icon. Note that `position` must remain `relative` or `absolute`. You might also want to encapsulate the `` in a positioned parent container to avoid problems. + - `itemsPosition` = show buttons above or below the main button ## `` props @@ -98,6 +99,7 @@ transforms into a "close" icon. vertically aligned to the FAB. - `onTouchTap` = called when the user clicks the mini-FAB (*not* called when the label is clicked) + - `secondary`, `backgroundColor`, `style`, `iconStyle` = material-ui FloatingActionButton exposed props ## License This project is licensed under the terms of the [MIT license](LICENSE) diff --git a/package.json b/package.json index e27b1fc..f9f02fa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-mui-speeddial", - "version": "0.0.6", + "version": "0.0.7", "description": "a speed dial component for Material UI", "repository": { "type": "git", diff --git a/scripts/build.sh b/scripts/build.sh old mode 100644 new mode 100755 diff --git a/src/speed-dial-item.jsx b/src/speed-dial-item.jsx index 51979d8..84ebd1b 100644 --- a/src/speed-dial-item.jsx +++ b/src/speed-dial-item.jsx @@ -18,79 +18,85 @@ const styles = { }; -const effects = { - - "none": (visible, index) => ({ - display: visible ? "" : "none" - }), - - "fade-staggered": (visible, index) => ({ - transition: visible ? "450ms" : "300ms", - transitionDelay: visible ? (index * 0.025) + "s" : "", - transform: "translateY(" + (visible ? 0 : "5px") + ")", - opacity: visible ? 1 : 0 - }), - - "fade": (visible, index) => ({ - transition: visible ? "450ms" : "300ms", - opacity: visible ? 1 : 0 - }), - - "slide": (visible, index) => ({ - transition: visible ? "250ms" : "300ms", - transform: "translateY(" + (visible ? 0 : getYPos(index) + "px") + ")", - opacity: visible ? 1 : 0 - }) - -}; +function getYPos(index, position) { + let newYPos = 81 + index * 56; + if (position === 'below') { + newYPos = -114 + (index * 56); + } -function getYPos(index) { - return 81 + index * 56; + return newYPos; } -export const SpeedDialItem = React.createClass({ +export class SpeedDialItem extends React.PureComponent { + effects = { + "none": (visible, index) => ({ + display: visible ? "" : "none" + }), + + "fade-staggered": (visible, index) => ({ + transition: visible ? "450ms" : "300ms", + transitionDelay: visible ? (index * 0.025) + "s" : "", + transform: "translateY(" + (visible ? 0 : (this.props.itemPosition === 'above' ? "5px" : "-5px")) + ")", + opacity: visible ? 1 : 0 + }), + + "fade": (visible, index) => ({ + transition: visible ? "450ms" : "300ms", + opacity: visible ? 1 : 0 + }), + + "slide": (visible, index) => ({ + transition: visible ? "250ms" : "300ms", + transform: "translateY(" + (visible ? 0 : getYPos(index, this.props.itemsPosition) + "px") + ")", + opacity: visible ? 1 : 0 + }), + }; handleTouchTap(ev) { this.props.onCloseRequest(); this.props.onTouchTap(ev); - }, - - render: function() { + } - const { index, visible } = this.props; + render() { + const { index, visible, itemPosition } = this.props; let style = { pointerEvents: visible ? "" : "none", position: "absolute", + zIndex: 9999, whiteSpace: "nowrap", right: 8, - bottom: getYPos(index) + bottom: getYPos(index, itemPosition) }; - let fx = effects[this.props.effect]; + let fx = this.effects[this.props.effect]; if (!fx) fx = effects.none; style = { ...style, ...fx(visible, index) }; - return
- -
+ return (
+
{this.props.label}
{ this.handleTouchTap(ev); }} > {this.props.fabContent} - -
; - +
); } +}; -}); \ No newline at end of file +SpeedDialItem.defaultProps = { + itemPosition: 'above', // above or below + secondary: true, +}; \ No newline at end of file diff --git a/src/speed-dial.jsx b/src/speed-dial.jsx index 99d722c..8a28e11 100644 --- a/src/speed-dial.jsx +++ b/src/speed-dial.jsx @@ -47,9 +47,11 @@ export const SpeedDial = React.createClass({ let enhancedChildren = React.Children.map(this.props.children, (child, index) => React.cloneElement(child, { + ...child.props, effect, index, visible: open, + itemPosition: this.props.itemsPosition, onCloseRequest: this.handleCloseRequest }) ); @@ -72,4 +74,8 @@ export const SpeedDial = React.createClass({
; } -}); \ No newline at end of file +}); + +SpeedDial.defaultProps = { + itemsPosition: 'above' // above or below +}; \ No newline at end of file