Skip to content

Commit 2984b61

Browse files
v2.0.0 is out with many features
1 parent c96d6b1 commit 2984b61

File tree

7 files changed

+79
-83
lines changed

7 files changed

+79
-83
lines changed

.babelrc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,4 @@
44
"stage-0",
55
"react"
66
],
7-
"plugins": [
8-
"react-hot-loader/babel"
9-
]
107
}

docs/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-floating-button-menu-docs",
3-
"version": "1.0.0",
3+
"version": "2.0.0",
44
"description": "docs",
55
"main": "src/index.js",
66
"scripts": {
@@ -27,17 +27,17 @@
2727
"gh-pages": "^2.0.1",
2828
"html-webpack-plugin": "^2.28.0",
2929
"webpack": "2.4.1",
30+
"react-hot-loader": "next",
3031
"webpack-dev-server": "2.4.3"
3132
},
3233
"dependencies": {
3334
"@material-ui/core": "^1.5.1",
35+
"@material-ui/icons": "^3.0.1",
3436
"jss": "^9.8.2",
3537
"jss-preset-default": "^4.5.0",
3638
"prop-types": "^15.5.8",
3739
"react": "^16.4.0",
3840
"react-dom": "^16.3.0",
39-
"react-hot-loader": "next",
40-
"react-icons": "^2.2.3",
4141
"react-jss": "^8.4.0",
4242
"styled-components": "1.4.5",
4343
"yargs": "^8.0.1"

docs/src/App.js

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
1-
/* eslint-disable */
21
import React, { Component } from 'react';
3-
import styled from 'styled-components';
4-
import MdAdd from 'react-icons/lib/md/add';
5-
import MdClose from 'react-icons/lib/md/close';
6-
import {
7-
FloatingMenu,
8-
MainButton,
9-
ChildButton,
10-
} from 'react-floating-button-menu';
2+
import MdAdd from '@material-ui/icons/add';
3+
import MdClose from '@material-ui/icons/clear';
4+
import MdFavorite from '@material-ui/icons/favorite';
5+
import { FloatingMenu, MainButton, ChildButton } from 'react-floating-button-menu';
116
import PropTypes from 'prop-types';
127
import { withStyles } from '@material-ui/core/styles';
13-
import Input from '@material-ui/core/Input';
148
import Paper from '@material-ui/core/Paper';
159
import InputLabel from '@material-ui/core/InputLabel';
1610
import MenuItem from '@material-ui/core/MenuItem';
17-
import FormHelperText from '@material-ui/core/FormHelperText';
1811
import FormControl from '@material-ui/core/FormControl';
1912
import Select from '@material-ui/core/Select';
2013

@@ -48,13 +41,13 @@ const styles = theme => ({
4841
class App extends Component {
4942
static propTypes = {
5043
classes: PropTypes.object.isRequired,
51-
}
44+
};
5245
state = {
5346
direction: 'up',
5447
isOpen: false,
5548
};
5649

57-
handleChange = event => {
50+
handleChange = (event) => {
5851
this.setState({ direction: event.target.value });
5952
};
6053

@@ -65,7 +58,7 @@ class App extends Component {
6558
<div className={classes.root}>
6659
<h2>Material Floating Button Menu Demo</h2>
6760
<FormControl className={classes.formControl}>
68-
<InputLabel htmlFor="age-simple">Age</InputLabel>
61+
<InputLabel>Direction</InputLabel>
6962
<Select
7063
value={this.state.direction}
7164
onChange={this.handleChange}
@@ -80,35 +73,29 @@ class App extends Component {
8073
</Select>
8174
</FormControl>
8275
<Paper className={classes.paper} elevation={4}>
83-
<FloatingMenu
84-
slideSpeed={500}
85-
direction={direction}
86-
isOpen={isOpen}
87-
>
76+
<FloatingMenu slideSpeed={500} direction={direction} isOpen={isOpen} spacing={8}>
8877
<MainButton
89-
iconResting={MdAdd}
90-
iconActive={MdClose}
91-
iconColor="white"
78+
iconResting={<MdAdd style={{ fontSize: 20 }} nativeColor="white" />}
79+
iconActive={<MdClose style={{ fontSize: 20 }} nativeColor="white" />}
9280
backgroundColor="black"
9381
onClick={() => this.setState({ isOpen: !this.state.isOpen })}
9482
size={56}
9583
/>
9684
<ChildButton
97-
iconButton={MdAdd}
98-
iconColor="black"
99-
order={1}
85+
icon={<MdFavorite style={{ fontSize: 20 }} nativeColor="black" />}
10086
backgroundColor="white"
10187
size={40}
102-
margin={16}
10388
onClick={() => console.log('First button clicked')}
10489
/>
10590
<ChildButton
106-
iconButton={MdAdd}
107-
iconColor="black"
108-
order={2}
91+
icon={<MdFavorite style={{ fontSize: 20 }} nativeColor="black" />}
92+
backgroundColor="white"
93+
size={40}
94+
/>
95+
<ChildButton
96+
icon={<MdFavorite style={{ fontSize: 20 }} nativeColor="black" />}
10997
backgroundColor="white"
11098
size={40}
111-
margin={8}
11299
/>
113100
</FloatingMenu>
114101
</Paper>

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"prop-types": "^15.5.8",
3232
"react": "^16.4.0",
3333
"react-dom": "^16.3.0",
34-
"react-icons": "^2.2.3",
3534
"styled-components": "1.4.5",
3635
"styled-jss": "^2.2.3",
3736
"yargs": "^8.0.1"

src/ChildButton.js

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
/* eslint-disable no-nested-ternary */
12
import React, { Component } from 'react';
23
import styled from 'styled-jss';
34
import PropTypes from 'prop-types';
45

56
const Wrapper = styled('li')(
6-
({ isOpen, slideSpeed, backgroundColor, size, iconColor, margin, direction }) => ({
7+
({ isOpen, slideSpeed, backgroundColor, size, iconColor, spacing, direction }) => ({
78
backgroundColor,
89
display: 'flex',
910
border: 'none',
@@ -20,43 +21,61 @@ const Wrapper = styled('li')(
2021
transition: `all ${slideSpeed}ms`,
2122
width: size,
2223
height: size,
23-
marginTop: (direction === 'down') ? margin : 0,
24-
marginBottom: (direction === 'up') ? margin : 0,
25-
marginLeft: (direction === 'right') ? margin : 0,
26-
marginRight: (direction === 'left') ? margin : 0,
27-
'& > a > svg': {
28-
fill: iconColor,
29-
},
24+
marginTop: direction === 'down' ? spacing : 0,
25+
marginBottom: direction === 'up' ? spacing : 0,
26+
marginLeft: direction === 'right' ? spacing : 0,
27+
marginRight: direction === 'left' ? spacing : 0,
28+
color: iconColor,
3029
}),
3130
);
3231

3332
class ChildButton extends Component {
3433
static propTypes = {
35-
iconButton: PropTypes.func.isRequired,
36-
direction: PropTypes.string.isRequired,
37-
iconColor: PropTypes.string,
34+
icon: PropTypes.node.isRequired,
35+
direction: PropTypes.string,
36+
index: PropTypes.number,
3837
onClick: PropTypes.func,
3938
isOpen: PropTypes.bool,
4039
size: PropTypes.number,
41-
margin: PropTypes.number,
40+
spacing: PropTypes.number,
4241
};
4342

4443
static defaultProps = {
44+
direction: 'up',
45+
index: 1,
4546
iconColor: 'black',
4647
size: '40',
47-
margin: 0,
48+
spacing: 0,
4849
isOpen: false,
49-
onClick: null
50+
onClick: null,
5051
};
5152

5253
render() {
53-
const { iconButton: IconButton, ...other } = this.props;
54+
const {
55+
icon,
56+
index,
57+
direction,
58+
size,
59+
spacing,
60+
isOpen,
61+
onClick,
62+
} = this.props;
63+
const offsetX =
64+
direction === 'right' ? (size + spacing) * index :
65+
direction === 'left' ? (size + spacing) * index * -1 : 0;
66+
const offsetY =
67+
direction === 'down' ? (size + spacing) * index :
68+
direction === 'up' ? (size + spacing) * index * -1 : 0;
5469

5570
return (
56-
<Wrapper {...other} onClick={this.props.isOpen ? this.props.onClick : null}>
57-
<a>
58-
<IconButton />
59-
</a>
71+
<Wrapper
72+
{...this.props}
73+
onClick={isOpen ? onClick : null}
74+
style={{
75+
transform: `translate(${isOpen ? 0 : -offsetX}px, ${isOpen ? 0 : -offsetY}px)`,
76+
}}
77+
>
78+
{icon}
6079
</Wrapper>
6180
);
6281
}

src/FloatingMenu.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ const StyledUl = styledJss('ul')(
1919
flexDirection: DIRECTIONS[direction],
2020
justifyContent: 'center',
2121
alignItems: 'center',
22-
'& > a + li, li + li': {
23-
marginLeft: 8,
24-
},
2522
}),
2623
);
2724

@@ -30,6 +27,7 @@ class FloatingMenu extends Component {
3027
className: PropTypes.string,
3128
children: PropTypes.arrayOf(PropTypes.element).isRequired,
3229
slideSpeed: PropTypes.number,
30+
spacing: PropTypes.number,
3331
direction: PropTypes.string,
3432
isOpen: PropTypes.bool,
3533
};
@@ -39,15 +37,18 @@ class FloatingMenu extends Component {
3937
slideSpeed: 500,
4038
direction: 'down',
4139
isOpen: false,
40+
spacing: 8,
4241
};
4342

4443
render() {
45-
const { slideSpeed, direction, className, isOpen } = this.props;
46-
const childrenWithProps = React.Children.map(this.props.children, child =>
44+
const { slideSpeed, direction, className, isOpen, spacing } = this.props;
45+
const childrenWithProps = React.Children.map(this.props.children, (child, index) =>
4746
React.cloneElement(child, {
4847
isOpen,
4948
slideSpeed,
5049
direction,
50+
index,
51+
spacing,
5152
}),
5253
);
5354

src/MainButton.js

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import PropTypes from 'prop-types';
55

66
const Wrapper = styled('a')(
77
({ backgroundColor, size, iconColor }) => ({
8-
'& > a > svg': {
9-
fill: iconColor,
10-
},
8+
color: iconColor,
119
zIndex: '1',
1210
display: 'flex',
1311
border: 'none',
@@ -18,7 +16,6 @@ const Wrapper = styled('a')(
1816
padding: '0',
1917
WebkitUserDrag: 'none',
2018
fontWeight: 'bold',
21-
color: '#f1f1f1',
2219
justifyContent: 'center',
2320
alignItems: 'center',
2421
WebkitTransition: '-webkit-transform 300ms',
@@ -32,41 +29,37 @@ const Wrapper = styled('a')(
3229
transform: `rotate(${isOpen ? 180 : 0}deg)`,
3330
}),
3431
);
35-
const IconResting = ({ iconResting, isOpen }) =>
36-
styled(iconResting)({
37-
position: 'absolute',
38-
opacity: isOpen ? 0 : 1,
39-
});
40-
const IconActive = ({ iconActive, isOpen }) =>
41-
styled(iconActive)({
42-
position: 'absolute',
43-
opacity: isOpen ? 1 : 0,
44-
});
32+
33+
const IconWrapper = styled('div')(({ isOpen }) => ({
34+
display: 'flex',
35+
position: 'absolute',
36+
opacity: isOpen ? 1 : 0,
37+
}));
4538

4639
class MainButton extends Component {
4740
static propTypes = {
48-
iconResting: PropTypes.func.isRequired,
49-
iconActive: PropTypes.func.isRequired,
50-
iconColor: PropTypes.string,
41+
iconResting: PropTypes.node.isRequired,
42+
iconActive: PropTypes.node.isRequired,
5143
isOpen: PropTypes.bool,
5244
size: PropTypes.number,
5345
};
5446

5547
static defaultProps = {
56-
iconColor: '#ff1744',
5748
isOpen: false,
5849
size: 56,
5950
};
6051

6152
render() {
6253
const { iconResting, iconActive, isOpen } = this.props;
63-
const StyledIconResting = IconResting({ iconResting, isOpen });
64-
const StyledIconActive = IconActive({ iconActive, isOpen });
6554

6655
return (
6756
<Wrapper {...this.props}>
68-
<StyledIconResting />
69-
<StyledIconActive />
57+
<IconWrapper isOpen={!isOpen}>
58+
{iconResting}
59+
</IconWrapper>
60+
<IconWrapper isOpen={isOpen}>
61+
{iconActive}
62+
</IconWrapper>
7063
</Wrapper>
7164
);
7265
}

0 commit comments

Comments
 (0)