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

[docs] Add color selector #12053

Merged
merged 18 commits into from
Jul 11, 2018
Merged
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
8 changes: 4 additions & 4 deletions .size-limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@ module.exports = [
name: 'The initial cost people pay for using one component',
webpack: true,
path: 'packages/material-ui/build/Paper/index.js',
limit: '17.8 KB',
limit: '17.9 KB',
},
{
name: 'The size of all the modules of material-ui.',
webpack: true,
path: 'packages/material-ui/build/index.js',
limit: '94.5 KB',
limit: '94.6 KB',
},
{
name: 'The main bundle of the docs',
webpack: false,
path: getMainFile().path,
limit: '175 KB',
limit: '176 KB',
},
{
name: 'The home page of the docs',
webpack: false,
path: '.next/bundles/pages/index.js',
limit: '6 KB',
limit: '5.8 KB',
},
];
12 changes: 12 additions & 0 deletions docs/src/modules/components/AppFrame.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import Toolbar from '@material-ui/core/Toolbar';
import IconButton from '@material-ui/core/IconButton';
import Tooltip from '@material-ui/core/Tooltip';
import MenuIcon from '@material-ui/icons/Menu';
import ColorsIcon from '@material-ui/icons/InvertColors';
import LightbulbOutlineIcon from '@material-ui/docs/svgIcons/LightbulbOutline';
import LightbulbFullIcon from '@material-ui/docs/svgIcons/LightbulbFull';
import NProgressBar from '@material-ui/docs/NProgressBar';
import FormatTextdirectionLToR from '@material-ui/icons/FormatTextdirectionLToR';
import FormatTextdirectionRToL from '@material-ui/icons/FormatTextdirectionRToL';
import GithubIcon from '@material-ui/docs/svgIcons/GitHub';
import Link from 'docs/src/modules/components/Link';
import AppDrawer from 'docs/src/modules/components/AppDrawer';
import AppSearch from 'docs/src/modules/components/AppSearch';
import Notifications from 'docs/src/modules/components/Notifications';
Expand Down Expand Up @@ -146,6 +148,16 @@ class AppFrame extends React.Component {
)}
<div className={classes.grow} />
<AppSearch />
<Tooltip title="Edit docs colors" enterDelay={300}>
<IconButton
color="inherit"
aria-labelledby="appbar-color"
component={Link}
href="/style/color#color-tool"
>
<ColorsIcon />
</IconButton>
</Tooltip>
<Tooltip title="Toggle light/dark theme" enterDelay={300}>
<IconButton
color="inherit"
Expand Down
1 change: 1 addition & 0 deletions docs/src/modules/components/AppWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class AppWrapper extends React.Component {

if (
nextProps.uiTheme.paletteType !== prevProps.uiTheme.paletteType ||
nextProps.uiTheme.paletteColors !== prevProps.uiTheme.paletteColors ||
nextProps.uiTheme.direction !== prevProps.uiTheme.direction
) {
return {
Expand Down
3 changes: 2 additions & 1 deletion docs/src/modules/redux/actionTypes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const actionTypes = {
THEME_CHANGE_PALETTE_TYPE: 'THEME_CHANGE_PALETTE_TYPE',
THEME_CHANGE_DIRECTION: 'THEME_CHANGE_DIRECTION',
THEME_CHANGE_PALETTE_COLORS: 'THEME_CHANGE_PALETTE_COLORS',
THEME_CHANGE_PALETTE_TYPE: 'THEME_CHANGE_PALETTE_TYPE',
};

export default actionTypes;
14 changes: 14 additions & 0 deletions docs/src/modules/redux/themeReducer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import actionTypes from 'docs/src/modules/redux/actionTypes';
import blue from '@material-ui/core/colors/blue';
import pink from '@material-ui/core/colors/pink';
import { darken } from '@material-ui/core/styles/colorManipulator';

const initialState = {
paletteType: 'light',
paletteColors: {
primary: blue,
secondary: {
// Darken so we reach the AA contrast ratio level.
main: darken(pink.A400, 0.08),
},
},
direction: 'ltr',
};

Expand All @@ -14,6 +24,10 @@ const mapping = {
...state,
direction: action.payload.direction,
}),
[actionTypes.THEME_CHANGE_PALETTE_COLORS]: (state, action) => ({
...state,
paletteColors: action.payload.paletteColors,
}),
};

function themeReducer(state = initialState, action) {
Expand Down
16 changes: 8 additions & 8 deletions docs/src/modules/styles/getPageContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@ function getTheme(uiTheme) {
nprogress: {
color: uiTheme.paletteType === 'light' ? '#000' : '#fff',
},
palette: {
primary: blue,
secondary: {
// Darken so we reach the AA contrast ratio level.
main: darken(pink.A400, 0.08),
},
type: uiTheme.paletteType,
},
palette: { ...uiTheme.paletteColors, type: uiTheme.paletteType },
});

// Expose the theme as a global variable so people can play with it.
Expand All @@ -34,6 +27,13 @@ function getTheme(uiTheme) {
const theme = getTheme({
direction: 'ltr',
paletteType: 'light',
paletteColors: {
primary: blue,
secondary: {
// Darken so we reach the AA contrast ratio level.
main: darken(pink.A400, 0.08),
},
},
});

// Configure JSS
Expand Down
108 changes: 108 additions & 0 deletions docs/src/pages/style/color/ColorDemo.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 AppBar from '@material-ui/core/AppBar';
import Toolbar from '@material-ui/core/Toolbar';
import Button from '@material-ui/core/Button';
import IconButton from '@material-ui/core/IconButton';
import MenuIcon from '@material-ui/icons/Menu';
import Typography from '@material-ui/core/Typography';
import AddIcon from '@material-ui/icons/Add';
import MarkdownElement from '@material-ui/docs/MarkdownElement';

const styles = theme => ({
root: {
position: 'relative',
overflow: 'hidden',
},
appFrame: {
position: 'relative',
height: 360,
backgroundColor: theme.palette.background.paper,
},
statusBar: {
width: '100%',
height: 24,
},
menuButton: {
marginLeft: -12,
marginRight: 20,
},
code: {
marginTop: theme.spacing.unit,
'& pre': {
margin: '0px !important',
},
},
fab: {
position: 'absolute',
bottom: theme.spacing.unit * 2,
right: theme.spacing.unit * 2,
},
});

function ColorDemo(props) {
const { classes, data, theme } = props;
const primary = {
main: data.primary,
output:
data.primaryShade === 4
? `${data.primaryHue}`
: `{
main: '${data.primary}',
}`,
};
const secondary = {
main: data.secondary,
output:
data.secondaryShade === 11
? `${data.secondaryHue}`
: `{
main: '${data.secondary}',
}`,
};

theme.palette.augmentColor(primary);
theme.palette.augmentColor(secondary);

return (
<div className={classes.root}>
<div className={classes.appFrame}>
<div className={classes.statusBar} style={{ backgroundColor: primary.dark }} />
<AppBar position="static" style={{ backgroundColor: primary.main }}>
<Toolbar style={{ color: primary.contrastText }}>
<IconButton className={classes.menuButton} color="inherit" aria-label="Menu">
<MenuIcon />
</IconButton>
<Typography variant="title" color="inherit">
Color sample
</Typography>
</Toolbar>
</AppBar>
<MarkdownElement
dir="ltr"
className={classes.code}
text={`\`\`\`jsx
{
palette: {
primary: ${primary.output},
secondary: ${secondary.output},
},
}
\`\`\``}
/>
<Button variant="fab" className={classes.fab} style={{ backgroundColor: secondary.main }}>
<AddIcon nativeColor={secondary.contrastText} />
</Button>
</div>
</div>
);
}

ColorDemo.propTypes = {
classes: PropTypes.object.isRequired,
data: PropTypes.object.isRequired,
theme: PropTypes.object.isRequired,
};

export default withStyles(styles, { withTheme: true })(ColorDemo);
Loading