-
Notifications
You must be signed in to change notification settings - Fork 34
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
Wcag color a11y tool #683
base: master
Are you sure you want to change the base?
Wcag color a11y tool #683
Conversation
@@ -9,6 +9,7 @@ | |||
"module": "esm/index.js", | |||
"private": false, | |||
"dependencies": { | |||
"color-contrast": "^1.0.0", |
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.
There are already some methods in core-utils that do this! No need for an extra library
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.
const [foregroundError, setForegroundError] = useState(false); | ||
const [backgroundError, setBackgroundError] = useState(false); | ||
|
||
const REX_EXP = /(^#[0-9A-F]{6}$)/i; |
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.
Oh my god
can we at least name this HEX_REGEXP?
let hexcode = code; | ||
if (!code.startsWith("#")) hexcode = `#${code}`; | ||
return REX_EXP.test(hexcode); |
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.
Could this not be cleaner as
let hexcode = code; | |
if (!code.startsWith("#")) hexcode = `#${code}`; | |
return REX_EXP.test(hexcode); | |
return REX_EXP.test(hexcode) || REX_EXP.test(`#${code}`); |
}; | ||
|
||
const backgroundHandleChange = event => { | ||
const value = event.target.value; |
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.
Could this be cleaner as
const value = event.target.value; | |
const { value } = event.target; |
useEffect(() => { | ||
if (selectedColorReset) { | ||
setSelectedColor(undefined); | ||
} | ||
if (!isValidHexCode(foregroundColorInput)) { | ||
setForegroundError(true); | ||
} else { | ||
setForegroundError(false); | ||
setForegroundColor(foregroundColorInput); | ||
} | ||
}, [foregroundColorInput]); | ||
|
||
useEffect(() => { | ||
if (selectedColorReset) { | ||
setSelectedColor(undefined); | ||
} | ||
if (!isValidHexCode(backgroundColorInput)) { | ||
setBackgroundError(true); | ||
} else { | ||
setBackgroundError(false); | ||
setBackgroundColor(backgroundColorInput); | ||
} | ||
}, [backgroundColorInput]); |
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.
Why is this in here twice? Also, how is this using variables that aren't in the variable array?
Some of this will be fixed by #726. Let's block this until 726 is merged |
Adds a wcag color contrast tool on the color palette component.
Also, fixes an issue where story docs were getting exported to npm