-
Notifications
You must be signed in to change notification settings - Fork 72
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
[BD-46] docs: update color picker readme #2646
Conversation
Thanks for the pull request, @khudym! When this pull request is ready, tag your edX technical lead. |
✅ Deploy Preview for paragon-openedx ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
ad7f344
to
ae9928f
Compare
Codecov ReportPatch and project coverage have no change.
Additional details and impacted files@@ Coverage Diff @@
## master #2646 +/- ##
=======================================
Coverage 91.81% 91.81%
=======================================
Files 235 235
Lines 4217 4217
Branches 1020 1020
=======================================
Hits 3872 3872
Misses 341 341
Partials 4 4 ☔ View full report in Codecov by Sentry. |
ae9928f
to
6cdcca3
Compare
I was curious about this so I did a little bit of digging. It seems the issue is that the another thing I tried was changing paragon/src/ColorPicker/index.jsx Line 68 in 77ebd94
to be <HexColorPicker color={hexValid ? color : '#fff'} onChange={setColor} /> which fixes the I looked into the event handling for I then tried another workaround (which feels a little hacky), instead using <HexColorPicker color={hexValid ? color : '#fefefe'} onChange={setColor} /> and that seems to give us expected behavior at least. I'm not sure what the best path forward for this is. But at least it seems we have a few options to consider now! |
<HexColorPicker color={hexValid ? color : '#fefefe'} onChange={setColor} /> I think this is a good workaround for now to ensure there's always a hue to default to. Any idea why #fefefe turns into #fff? |
Good question! tl:dr - rounding inaccuracyfull explanation below:The hex value entered is parsed using export const hexToHsva = (hex: string): HsvaColor => rgbaToHsva(hexToRgba(hex)); which is calling export const hexToRgba = (hex: string): RgbaColor => {
if (hex[0] === "#") hex = hex.substring(1);
if (hex.length < 6) {
return {
r: parseInt(hex[0] + hex[0], 16),
g: parseInt(hex[1] + hex[1], 16),
b: parseInt(hex[2] + hex[2], 16),
a: hex.length === 4 ? round(parseInt(hex[3] + hex[3], 16) / 255, 2) : 1,
};
}
return {
r: parseInt(hex.substring(0, 2), 16),
g: parseInt(hex.substring(2, 4), 16),
b: parseInt(hex.substring(4, 6), 16),
a: hex.length === 8 ? round(parseInt(hex.substring(6, 8), 16) / 255, 2) : 1,
};
}; with
which then goes into export const rgbaToHsva = ({ r, g, b, a }: RgbaColor): HsvaColor => {
const max = Math.max(r, g, b);
const delta = max - Math.min(r, g, b);
// prettier-ignore
const hh = delta
? max === r
? (g - b) / delta
: max === g
? 2 + (b - r) / delta
: 4 + (r - g) / delta
: 0;
return {
h: round(60 * (hh < 0 ? hh + 6 : hh)),
s: round(max ? (delta / max) * 100 : 0),
v: round((max / 255) * 100),
a,
};
}; which returns
which is then stored as the internal color value for the picker. when we move the slider, const handleChange = useCallback((params: Partial<HsvaColor>) => {
updateHsva((current) => Object.assign({}, current, params));
}, []); which only modifies the fromHsva: ({ h, s, v }) => hsvaToHex({ h, s, v, a: 1 }), which uses export const hsvaToHex = (hsva: HsvaColor): string => rgbaToHex(hsvaToRgba(hsva)); which calls export const hsvaToRgba = ({ h, s, v, a }: HsvaColor): RgbaColor => {
h = (h / 360) * 6;
s = s / 100;
v = v / 100;
const hh = Math.floor(h),
b = v * (1 - s),
c = v * (1 - (h - hh) * s),
d = v * (1 - (1 - h + hh) * s),
module = hh % 6;
return {
r: round([v, c, b, b, d, v][module] * 255),
g: round([d, v, v, c, b, b][module] * 255),
b: round([b, b, d, v, v, c][module] * 255),
a: round(a, 2),
};
}; which, for
which, if we don't pay attention to a, is |
@khudym Even though your pull request wasn’t merged, please take a moment to answer a two question survey so we can improve your experience in the future. |
Description
Issue
Deploy Preview
Preview
Include a direct link to your changes in this PR's deploy preview here (e.g., a specific component page).
Merge Checklist
example
app?wittjeff
andadamstankiewicz
as reviewers on this PR.Post-merge Checklist