-
Notifications
You must be signed in to change notification settings - Fork 91
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
feat(theming): add focus styling utilities #1542
Conversation
|
||
const palette = theme && theme.palette ? theme.palette : DEFAULT_THEME.palette; | ||
const colors = theme && theme.colors ? theme.colors : DEFAULT_THEME.colors; | ||
export const getColor = memoize( |
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.
Were there any performance concerns that prompted the lodash.memoize
utility usage?
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.
Yes, calling out to these utilities results in repeat getColor
calls in a lot of existing cases. But I think there's a massive savings potential overall.
* ``` | ||
*/ | ||
export const focusStyles = ({ | ||
condition = true, |
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.
I'm curious, what advantage does the condition
argument bring? The condition
argument can be done in the context of the code where focusStyles
is used; which reads clearer and less surface area to debug.
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.
See commit linked in description
|
||
/* | ||
* 1. Browser reset | ||
* 2. High contrast mode hack |
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 please share your resource/research on the high contrast mode hack? Very curious to learn more about this approach.
- Will there need to be other parts to this mechanism? An extension to the theme colors with a "high contrast color" token(s)?
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.
See link in description
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.
+1 for transparent.
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.
Nothing major to comment on. I dig it.
* @param {string} [options.shadowWidth='md'] Provides a theme object `shadowWidth` key for the cumulative width of the `box-shadow` | ||
* @param {string} [options.spacerWidth='xs'] Provides a theme object `shadowWidth` for the white spacer | ||
* @param {Object} [options.styles] Adds CSS property values to be rendered with `:focus-visible` | ||
* @param {Object} options.theme Provides values used to resolve the desired color |
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.
* @param {Object} options.theme Provides values used to resolve the desired color | |
* @param {Object} [options.theme] Provides values used to resolve the desired color |
Assuming the brackets were left out on accident. :)
import { math } from 'polished'; | ||
import { FocusBoxShadowParameters, getFocusBoxShadow } from './getFocusBoxShadow'; | ||
|
||
export const SELECTOR_FOCUS_VISIBLE = '&:focus-visible, &[data-garden-focus-visible="true"]'; |
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.
:focus-visible
π π
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.
Looks sharp!
Description
This PR adds
xs
units to theDEFAULT_THEME
to account for updated "spacer" focus styling, along with three new utilities:focusStyles
(preferred) provides a CSS block with focusoutline
reset, focus-visiblebox-shadow
styling, and transparent outline hack for high contrast modegetFocusBoxShadow
(fallback) in the case where existing code would be a tedious/surgical refactor, this utility provides the CSS value for thebox-shadow
propertySELECTOR_FOCUS_VISIBLE
constant that can be used together with theselector
parameter onfocusStyles
:Detail
For performance concerns, the
getColor
utility was memoized, resulting in an extensive diff due to thememoize
function wrap.This PR contains two commits (rolled back), demonstrating real utility usage within a couple of key styled components:
focusStyles
(note that the existing:focus
block should've also been removed)getFocusBoxShadow
(focusStyles
could be applied with extra effort)Checklist
demo is up-to-date (yarn start
)renders as expected with reversed (RTL) direction?bedrock
)