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

[docs] Add color selector #12053

merged 18 commits into from
Jul 11, 2018

Conversation

mbrookes
Copy link
Member

@mbrookes mbrookes commented Jul 3, 2018

Customise the docs colors, and create palettes for use in createMuiTheme().

image

Closes #2009


<a href="https://material.io/tools/color/#!/?view.left=0&view.right=0&primary.color=3F51B5&secondary.color=F44336">
Copy link
Member

@oliviertassinari oliviertassinari Jul 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why removing this image? I find it complementary to the demo you added. It's providing context and guidance on how to use the tool.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this tool effectively replaces it. We're linking to the general Material Design color section rather than their color tool. We don't need a picture of theirs alongside ours.

I did wonder if I should add something to display all the generated dark and light colors along those lines.

Copy link
Member

@oliviertassinari oliviertassinari Jul 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this tool effectively replaces it

I don't think that the new tool answers the same problems. I don't see how it can be a replacement. Let me explain what I see.

tools/color provides:

  1. A official theme color picker
  2. A tool to help to pick accessible colors
  3. Force us to keep in sync with their palette model

the new demo provides:

  1. A way for users to see how the palette impacts all our components: solve [docs] Mapping color to components #2009

Vuetify has been trying to replace the official color picker, I don't think that it execute. I think that it's too much effort for the outcome. They would have been better off showing how to use the official pickers, a better output for less effort: https://vuetifyjs.com/en/theme-generator. At least, it's how I see it from an external point of vue view. @johnleider would you mind sharing your experience with the theme generator? :)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to keep developers on the docs as much as possible. Our jobs as framework developers is to bring all the good important stuff to the front. As this is a visual demo, I find it has a lot of value. This is why we are rebuilding ours :)

Copy link
Member Author

@mbrookes mbrookes Jul 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. So what?
  2. Wow, that accessibility tab has almost zero discoverability.
  3. How so?

As you know, I started with the ability to copy the URL from the MD color tool and paste it in a text field, but it was an extremely cumbersome way to try different color schemes with our components, hence the addition of the color pickers, to the point where I dropped the URL text field. I can add it back if you see value in it - but I'd love some analytics to see if it gets used!

Users can always populate the theme from the official color picker if they choose, and we can keep an explanation of that.

@johnleider Thanks for dropping by and sharing your view, you're doing awesome work over there!

Copy link
Member

@oliviertassinari oliviertassinari Jul 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I'd love some analytics to see if it gets used!

Good point, we can add one Google Analytics event.

Copy link
Member

@oliviertassinari oliviertassinari Jul 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Users can always populate the theme from the official color picker if they choose, and we can keep an explanation of that.

As long as we have some documentation around how to do such, I'm happy!

@@ -125,7 +125,7 @@ export default function createPalette(palette: Object) {
return contrastText;
}

function augmentColor(color, mainShade, lightShade, darkShade) {
function augmentColor(color, mainShade = 500, lightShade = 300, darkShade = 700) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -33,7 +33,7 @@ export const style = theme => {
root: {
position: 'relative',
width: '100%',
margin: '10px 0',
margin: '10px',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have a margin by default :o.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way the thumb is currently constructed, without it, the active thumb would overlap surrounding components. This was a quick fix for the horizontal overlap.

I guess it's tangentially related to #11889.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be using the padding instead? Using the margin is deceptive. One can't override it directly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's better that way.

main: '#3f50b5',
dark: '#002884',
contrastText: '#fff',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we document this feature somewhere else?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's covered in detail the "Themes" section, but we could add a note / cross reference here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, then the only advantage is to illustrate how to use the output of material.io/tools/color/.


export default compose(
withStyles(styles, {
name: 'ColorChooser',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We most likely don't need to give the style sheet a name.


const ColorDemo = props => {
const { classes, primary, theme, secondary } = props;
theme.palette.augmentColor(primary);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum, this is not immutable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, and it confused the heck out of me at first. It probably shouldn't have been added to the public API in that form (or written that way in the first place - my bad), but changing it now would be a breaking change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I screw up. We will sort that out in the next breaking change release. I'm keeping track of all the breaking changes we might introduce, I have 9 so far.

main: '#3f50b5',
dark: '#002884',
contrastText: '#fff',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, then the only advantage is to illustrate how to use the output of material.io/tools/color/.

@@ -33,7 +33,7 @@ export const style = theme => {
root: {
position: 'relative',
width: '100%',
margin: '10px 0',
margin: '10px',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be using the padding instead? Using the margin is deceptive. One can't override it directly.

@@ -1,6 +1,6 @@
import warning from 'warning';
import deepmerge from 'deepmerge'; // < 1kb payload overhead when lodash/merge is > 3kb.
import indigo from '../colors/indigo';
import blue from '../colors/blue';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


const shades = [900, 800, 700, 600, 500, 400, 300, 200, 100, 50, 'A700', 'A400', 'A200', 'A100'];

export const styles = theme => ({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to export the styles

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops no - same copypasta as the stylesheet naming :)

import actionTypes from 'docs/src/modules/redux/actionTypes';
import ColorDemo from './ColorDemo';

const hues = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you get this list out of Object.keys(colors)?

secondaryShade: 11,
};

hashPrefix = string => (string.charAt(0) === '#' ? string : `#${string}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why using a class method over a function on the root scope?


hashPrefix = string => (string.charAt(0) === '#' ? string : `#${string}`);

isRgb = string => /#?([0-9a-f]{6})/i.test(string);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why using a class method over a function on the root scope?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class methods can access the instance. I try to promote the function that doesn't need it to the top level to increase the isolation between the different sections of the code.

});
};

handleChangeDocsColors = values => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handleChangeDocsColors = event => {?


const ColorDemo = props => {
const { classes, primary, theme, secondary } = props;
theme.palette.augmentColor(primary);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I screw up. We will sort that out in the next breaking change release. I'm keeping track of all the breaking changes we might introduce, I have 9 so far.

export default compose(
withStyles(styles, {
name: 'ColorChooser',
withTheme: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dead code

@mbrookes mbrookes added docs Improvements or additions to the documentation PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI new feature New feature or request and removed PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI labels Jul 6, 2018
Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The layout of the Color tool demo is off for smaller screens. The new iteration on this pull request is really awesome 😍 !

<Tooltip id="appbar-color" title="Edit docs colors" enterDelay={300}>
<IconButton
color="inherit"
href="/style/color/#color-tool"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better use the next.js link. I can do it if you want.

Copy link
Member Author

@mbrookes mbrookes Jul 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried, but it doesn't seem to respect the hash (or I"m doing it wrong). It links to the page, but not to the section. You have to click twice - once to go to the page, once to go to the section.:

<IconButton
  color="inherit"
  component={buttonProps => (
    <Link variant="button" href="/style/color/#color-tool" {...buttonProps} />
  )}
  aria-labelledby="appbar-color"
 >

},
});

const ColorDemo = props => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I try to use function everywhere in the codebase for react components.

@oliviertassinari oliviertassinari self-assigned this Jul 11, 2018
mbrookes and others added 3 commits July 11, 2018 12:45
@oliviertassinari oliviertassinari merged commit 355317f into mui:master Jul 11, 2018
acroyear pushed a commit to acroyear/material-ui that referenced this pull request Jul 14, 2018
* [docs] Add color chooser

Add color swatches

Checkmark for selected colors

Fix imports

Add shade slider

basically working

Fix indigo glitch

* Add ColorDemo component

* Remove google color tool support

* Fix TextField input

* Rename ColorChooser to ColorTool

* Improve the layout

* Address the rest of Olivier's feedback

* Add toolbar icon

* Add docs-style-color to regression test blacklist

* Optimize sample palette

* Use MarkdownElement for code sample

* Add dark / main / light colorBar

* Display hex values in colorBar

* fix code layout

* Fix size limits

* DRY the colorPicker

Does this make the code to dense / hard to read?

* Hacky fix for layout at small screen size

* looking at the PR
@artivilla
Copy link

Can someone link me to this page on the documentation? Thank you for this :)

@oliviertassinari
Copy link
Member

@artivilla https://material-ui.com/style/color/#color-tool

@mbrookes
Copy link
Member Author

@artivilla You also have a new icon in the docs site Toolbar:

image

@mbrookes mbrookes deleted the docs-custom-colors branch July 17, 2018 11:53
@artivilla
Copy link

Just to confirm, this only allows us to modify primary/secondary base colors? Not the entire theme file.

@oliviertassinari
Copy link
Member

@artivilla Exactly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to the documentation new feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants