Skip to content

Commit

Permalink
[SpeedDial] New component
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrookes authored and oliviertassinari committed Feb 19, 2018
1 parent 506a7a4 commit 602f4af
Show file tree
Hide file tree
Showing 44 changed files with 4,668 additions and 20 deletions.
15 changes: 13 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"development": {
"sourceMaps": "both",
"plugins": [
"transform-flow-strip-types"
"transform-flow-strip-types",
]
},
"docs-development": {
Expand All @@ -28,6 +28,7 @@
{
"alias": {
"pages": "./pages",
"@material-ui/lab": "./packages/lab/src",
"material-ui": "./src",
"material-ui-icons": "./packages/material-ui-icons/src",
"docs": "./docs"
Expand All @@ -49,6 +50,7 @@
"alias": {
"pages": "./pages",
"material-ui": "./src",
"@material-ui/lab": "./packages/lab/src",
"material-ui-icons": "./packages/material-ui-icons/src",
"docs": "./docs"
}
Expand Down Expand Up @@ -92,7 +94,16 @@
"test": {
"sourceMaps": "both",
"plugins": [
"transform-flow-strip-types"
"transform-flow-strip-types",
[
"module-resolver",
{
"alias": {
"material-ui": "./src",
"material-ui-icons": "./packages/material-ui-icons/src",
}
}
],
]
}
}
Expand Down
19 changes: 17 additions & 2 deletions docs/scripts/buildApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,21 @@ function ensureExists(pat, mask, cb) {
});
}

// Read the command-line args
const args = process.argv;

// Exit with a message
function exit(error) {
console.log(error, '\n');
process.exit();
}

if (args.length < 4) {
exit('\nERROR: syntax: buildApi source target');
}

const rootDirectory = path.resolve(__dirname, '../../');
const docsApiDirectory = path.resolve(rootDirectory, 'pages/api');
const docsApiDirectory = path.resolve(rootDirectory, args[3]);
const theme = createMuiTheme();

function buildDocs(options) {
Expand Down Expand Up @@ -114,6 +127,8 @@ const pagesMarkdown = findPagesMarkdown()
})
.filter(markdown => markdown.components.length > 0);

findComponents().forEach(component => {
const components = findComponents(path.resolve(rootDirectory, args[2]));

components.forEach(component => {
buildDocs({ component, pagesMarkdown });
});
7 changes: 4 additions & 3 deletions docs/src/modules/components/AppDrawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,16 @@ function renderNavItems(props, pages, activePage) {

function reduceChildRoutes(props, activePage, items, childPage, index) {
if (childPage.children && childPage.children.length > 1) {
const openImmediately = activePage.pathname.indexOf(childPage.pathname) !== -1 || false;

const openImmediately = activePage.pathname.indexOf(childPage.pathname) === 0 || false;
items.push(
<AppDrawerNavItem
key={index}
openImmediately={openImmediately}
title={pageToTitle(childPage)}
// Indent the nested list for Lab
{...(childPage.pathname === '/lab/api' ? { style: { paddingLeft: 18 } } : {})}
>
{renderNavItems(props, childPage.children, activePage)}
{renderNavItems(props, childPage.children, activePage, 0)}
</AppDrawerNavItem>,
);
} else if (childPage.title !== false) {
Expand Down
6 changes: 3 additions & 3 deletions docs/src/modules/components/AppDrawerNavItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ class AppDrawerNavItem extends React.Component {
};

render() {
const { children, classes, href, openImmediately, title } = this.props;
const { children, classes, href, openImmediately, title, ...other } = this.props;

if (href) {
return (
<ListItem className={classes.navLink} disableGutters>
<ListItem className={classes.navLink} disableGutters {...other}>
<Button
component={props => (
<Link
Expand All @@ -87,7 +87,7 @@ class AppDrawerNavItem extends React.Component {
}

return (
<ListItem className={classes.navItem} disableGutters>
<ListItem className={classes.navItem} disableGutters {...other}>
<Button
classes={{
root: classes.button,
Expand Down
9 changes: 8 additions & 1 deletion docs/src/modules/components/MarkdownDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ function MarkdownDocs(props, context) {
}
}

const section = markdownLocation.split('/')[4];

return (
<AppContent className={classes.root}>
<Head>
Expand Down Expand Up @@ -86,7 +88,12 @@ function MarkdownDocs(props, context) {
## API
${headers.components
.map(component => `- [&lt;${component} /&gt;](/api/${kebabCase(component)})`)
.map(
component =>
`- [&lt;${component} /&gt;](${section === 'lab' ? '/lab' : ''}/api/${kebabCase(
component,
)})`,
)
.join('\n')}
`}
/>
Expand Down
17 changes: 16 additions & 1 deletion docs/src/modules/components/withRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const pages = [
children: [
{
pathname: '/guides/api',
title: 'API',
title: 'API Design Approach',
},
{
pathname: '/guides/minimizing-bundle-size',
Expand Down Expand Up @@ -170,6 +170,21 @@ const pages = [
},
],
},
{
pathname: '/lab',
children: [
{
pathname: '/lab/about',
title: 'About The Lab',
},
{
pathname: '/lab/speed-dial',
},
{
...findPages[2].children[1],
},
],
},
{
pathname: '/discover-more',
children: [
Expand Down
4 changes: 2 additions & 2 deletions docs/src/modules/utils/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function findPagesMarkdown(
const componentRegex = /^([A-Z][a-z]+)+\.js/;

// Returns the component source in a flat array.
function findComponents(directory = path.resolve(__dirname, '../../../../src'), components = []) {
function findComponents(directory, components = []) {
const items = fs.readdirSync(directory);

items.forEach(item => {
Expand Down Expand Up @@ -90,7 +90,7 @@ function findPages(
.replace(/^.*\/pages/, '')
.replace('.js', '');

if (options.front && pathname.indexOf('/demos') === -1 && pathname.indexOf('/api') === -1) {
if (options.front && pathname.indexOf('/demos') === -1 && pathname.indexOf('/api') === -1 && pathname.indexOf('/lab') === -1) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion docs/src/modules/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function pageToTitle(page) {

const name = page.pathname.replace(/.*\//, '');

if (page.pathname.indexOf('/api') === 0) {
if (page.pathname.indexOf('/api') === 0 || page.pathname.indexOf('/lab/api') === 0) {
return upperFirst(camelCase(name));
}

Expand Down
5 changes: 3 additions & 2 deletions docs/src/pages/demos/buttons/buttons.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ Fancy larger or smaller buttons? Use the `size` or the `mini` property.

Icon buttons are commonly found in app bars and toolbars.

Icons are also appropriate for toggle buttons that allow a single choice to be selected or deselected, such as adding or removing a star to an item.
Icons are also appropriate for toggle buttons that allow a single choice to be selected or
deselected, such as adding or removing a star to an item.

{{"demo": "pages/demos/buttons/IconButtons.js"}}

### Buttons with icons and label

Sometimes you might want to have icons for certain button to enhance the UX of the application as humans recognize logos more than plain text. For example, if you have a delete button you can label it with a dustbin icon.
Sometimes you might want to have icons for certain button to enhance the UX of the application as we recognize logos more easily than plain text. For example, if you have a delete button you can label it with a dustbin icon.

{{"demo": "pages/demos/buttons/IconLabelButtons.js"}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ to discuss the approach before submitting a PR.
- **[Buttons: Floating Action Button](https://material.io/guidelines/components/buttons-floating-action-button.html)**
- **[Trigger](https://material.io/guidelines/components/buttons-floating-action-button.html#buttons-floating-action-button-transitions)**
- [Toolbar](https://material.io/guidelines/components/buttons-floating-action-button.html#buttons-floating-action-button-transitions)
- [Speed dial](https://material.io/guidelines/components/buttons-floating-action-button.html#buttons-floating-action-button-transitions)
- **[Speed dial](https://material.io/guidelines/components/buttons-floating-action-button.html#buttons-floating-action-button-transitions) ~ [Lab](/lab/about)**
- [Morph](http://www.google.com/design/spec/components/buttons-floating-action-button.html#buttons-floating-action-button-transitions)
- [Full screen](http://www.google.com/design/spec/components/buttons-floating-action-button.html#buttons-floating-action-button-transitions)
- **[Cards](https://material.io/guidelines/components/cards.html)**
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/guides/api/api.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# API
# API Design Approach

We have learned a lot regarding how people use Material-UI.
The 1.x.x rewrite allowed us to completely rethink our component API.
Expand Down
19 changes: 19 additions & 0 deletions docs/src/pages/lab/about.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Material-UI Lab

This package hosts the incubator components that are not yet ready to move to `core`.

## Installation

Install the package in your project directory with:

```
npm install --save @material-ui/lab
```

If you are not already using Material-UI in your project, you can add it with:

```
npm install --save material-ui@next
```


110 changes: 110 additions & 0 deletions docs/src/pages/lab/speed-dial/OpenIconSpeedDial.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from 'material-ui/styles';
import Button from 'material-ui/Button';
import SpeedDial from '@material-ui/lab/SpeedDial';
import SpeedDialIcon from '@material-ui/lab/SpeedDialIcon';
import SpeedDialAction from '@material-ui/lab/SpeedDialAction';
import ContentCopyIcon from 'material-ui-icons/ContentCopy';
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/ModeEdit';

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

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

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

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

handleClick = () => {
this.setState({
open: !this.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;

/* returns an array of buttons based on the `actions` array */
const SpeedDialActions = actions.map(action => {
return (
<SpeedDialAction
icon={action.icon}
tooltipTitle={action.name}
key={action.name}
onClick={this.handleClick}
/>
);
});

return (
<div className={classes.root}>
<Button onClick={this.handleVisibility}>Speed Dial with openIcon</Button>
<SpeedDial
icon={<SpeedDialIcon openIcon={<EditIcon />} />}
open={open}
hidden={hidden}
ariaLabel="SpeedDial openIcon example"
className={classes.speedDial}
onClick={this.handleClick}
onMouseEnter={this.handleOpen}
onMouseLeave={this.handleClose}
onFocus={this.handleOpen}
onBlur={this.handleClose}
onClose={this.handleClose}
>
{SpeedDialActions}
</SpeedDial>
</div>
);
}
}

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

export default withStyles(styles)(OpenIconSpeedDial);
Loading

0 comments on commit 602f4af

Please sign in to comment.