-
Notifications
You must be signed in to change notification settings - Fork 11
Default profile colors #27
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing PaletteProvider test cases. Minimal CC - 100% 😛
src/PaletteProvider.js
Outdated
|
||
_validateDefaults() { | ||
if (this.props.defaults) { | ||
if (typeof this.props.defaults !== 'object') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you flatten the conditionals?
if (this.props.defaults && typeof this.props.defaults !== 'object')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That part is not finished, I am about to complete the defaults
validation today
src/PaletteProvider.js
Outdated
const paletteWithDefaults = this._mergeWithDefaults(palette); | ||
execIfFunction(this.props.onFinish, paletteWithDefaults); | ||
if (!this.props.forceRender) { | ||
this.setState({ palette }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should pass paletteWithDefaults
instead of palette
src/PaletteProvider.js
Outdated
), | ||
}; | ||
return { | ||
...Object.keys(palette) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to spread the object inside object -> you're reducing it to object already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zamotany I think it's because he is merging it with defaults
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a ok, haven't seen that ...defaults
src/constants/defaults.js
Outdated
const defaultLightMuted = '#BDBDBD'; | ||
const defaultDarkMuted = '#616161'; | ||
|
||
export const validColorProfiles = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use an object here and reuse it for the typedef:
const validColorProfiles = {
vibrant: true,
lightVibrant: true,
darkVibrant: true,
muted: true,
lightMuted: true,
darkMuted: true,
};
type ColorProfile = $Keys<typeof validColorProfiles>;
src/utils/validate.js
Outdated
const validProfilesKeys = ['bodyTextColor', 'color', 'titleTextColor']; | ||
(Object.keys((defaults: any)): ColorProfile[]).forEach(profile => { | ||
if (!validColorProfiles.includes(profile)) { | ||
if (!Object.keys(validColorProfiles).includes(profile)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or profile in validColorProfiles
}, | ||
})); | ||
|
||
createPalette({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to return the Promise from createPalette
otherwise the test will assume it's sync and won't wait for it.
You guys are crazy |
@@ -0,0 +1,56 @@ | |||
/* eslint-disable import/first */ | |||
jest.mock('../validateCreatePaletteArgs', () => ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jest.mock('../validateCreatePaletteArgs')
is sufficient
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
After sampling some images, I extrapolated some greyscale colors as defaults for each profile.
See #2
This PR merges the palette instance with the defaults, before the event emitter publish the change to all subscribers.
TODO
this.props.defaults
createMaterialPalette
PaletteProvider
Note: I'll fix flow issues before merging this...couldn't run it again locally