Skip to content

Conversation

@jzempel
Copy link
Member

@jzempel jzempel commented May 13, 2024

Description

...rooted in semantic variables.

Detail

Verified stateful (default, hover, active, focused) color treatment for the following in both light and dark modes – with icons enabled wherever applicable:

  • <Anchor>
    • <Anchor isDanger>
  • <Button isLink>
    • <Button isLink isNeutral> (no change)
    • <Button isLink isDanger>
    • <Button isLink isDanger focusInset>
    • <Button isLink disabled>
  • <Button isBasic>
    • <Button isBasic isNeutral>
    • <Button isBasic isNeutral focusInset>
    • <Button isBasic isDanger>
    • <Button isBasic isDanger focusInset>
    • <Button isBasic disabled>
  • <Button isPrimary>
    • <Button isPrimary isNeutral>
    • <Button isPrimary isNeutral focusInset>
    • <Button isPrimary isDanger>
    • <Button isPrimary isDanger focusInset>
    • <Button isPrimary disabled>
  • <Button>
    • <Button isNeutral>
    • <Button isNeutral focusInset>
    • <Button isDanger>
    • <Button isDanger focusInset>
    • <Button disabled>
  • <SplitButton>
    • isBasic
    • isBasic isNeutral
    • isBasic isDanger
    • isPrimary
    • isPrimary isNeutral
    • isPrimary isDanger
    • isNeutral
    • isDanger
    • disabled
  • <ToggleButton>
    • <TogglButton isPressed>

Checklist

  • 👌 design updates will be Garden Designer approved (add the designer as a reviewer)
  • 🌐 demo is up-to-date (npm start)
  • ⬅️ renders as expected with reversed (RTL) direction
  • 🤘 renders as expected with Bedrock CSS (?bedrock)
  • 💂‍♂️ includes new unit tests. Maintain existing coverage (always >= 96%)
  • tested for WCAG 2.1 AA accessibility compliance
  • 📝 tested in Chrome, Firefox, Safari, and Edge

@jzempel jzempel requested a review from a team as a code owner May 13, 2024 19:51
@coveralls
Copy link

coveralls commented May 13, 2024

Coverage Status

coverage: 96.184% (-0.04%) from 96.224%
when pulling c112705 on jzempel/recolor-buttons
into 5282298 on next.

}
const disabledBackgroundColor = getColor({ theme, variable: 'background.disabled' });
const disabledForegroundColor = getColor({ theme, variable: 'foreground.disabled' });
const offset100 = { dark: { offset: -100 }, light: { offset: +100 } };
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need the unary + operator?

Suggested change
const offset100 = { dark: { offset: -100 }, light: { offset: +100 } };
const offset100 = { dark: { offset: -100 }, light: { offset: 100 } };

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed - shouldn't be necessary if the base operation in theming is just + offset - the math works itself out 😁

Copy link
Member Author

Choose a reason for hiding this comment

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

I was preferring the unary for the sake of offset clarity and scannability. But if this feels odd to the team, I'll remove.

/*
* Anchor / link button styling
*/
const options = { theme, variable: `foreground.${isDanger ? 'danger' : 'primary'}` };
Copy link
Contributor

Choose a reason for hiding this comment

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

While elegant, this pattern might complicate searching for variable names. For ex, searching for all instances of foreground.primary.

Suggested change
const options = { theme, variable: `foreground.${isDanger ? 'danger' : 'primary'}` };
const options = { theme, variable: isDanger ? 'foreground.isDanger' : 'foreground.primary' };

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I agree with this as well... we'll also probably thank ourselves by helping the vars be searchable.

@jzempel jzempel changed the title feat(buttons): new light/dark mode colors feat(buttons)!: new light/dark mode colors May 15, 2024
Comment on lines 72 to 73
export const StyledIconButton = styled(StyledButton as 'button').attrs(props => ({
'data-garden-id': (props as any)['data-garden-id'] || COMPONENT_ID,
Copy link
Contributor

@ze-flo ze-flo May 15, 2024

Choose a reason for hiding this comment

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

I dug further into #1804 and found some regressions with this method. I'll share my findings and recommendation in that PR. Meanwhile, here's a summary.

Notice how IconButton now inherits the COMPONENT_ID buttons.button from StyledButton.

Screen Shot 2024-05-15 at 7 37 03 AM

When extending a styled-component with attrs already set, the props will include such attributes. In this case props['data-garden-id'] === 'buttons.button' and takes precedence over the StyledIconButton's COMPONENT_ID.

One way around that is to first check that the data-garden-id exist and doesn't match the id from the styled-component being extended:

Suggested change
export const StyledIconButton = styled(StyledButton as 'button').attrs(props => ({
'data-garden-id': (props as any)['data-garden-id'] || COMPONENT_ID,
export const StyledIconButton = styled(StyledButton as 'button').attrs(props => ({
'data-garden-id': (props as any)['data-garden-id'] && (props as any)['data-garden-id'] !== 'buttons.button' ?
(props as any)['data-garden-id'] : COMPONENT_ID,

I can't recommend this pattern. It's brittle and error-prone. My hunch is that we should set data-garden-id on the components we expose to the public and only rely on attrs for data-garden-version or other immutable attributes.

I'm happy to discuss further.

Copy link
Member Author

@jzempel jzempel May 15, 2024

Choose a reason for hiding this comment

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

I can't recommend this pattern.

Thanks for the careful review. I would say that, within the context of a package, this 2nd pattern (although somewhat awkward) is totally acceptable for now. Eventually, I agree we should probably move data-garden-id out of all view and into element-level components.

Copy link
Contributor

@ze-flo ze-flo May 15, 2024

Choose a reason for hiding this comment

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

The approach I highlighted above is not perfect but it's a good stepping stone. Glad you're okay with it. 😄

I updated all instances in #1804.

How should we move forward with merging these changes into this PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've reverted the changes here (and updated PR title, description, and tags) in favor of reviewing #1804

@lucijanblagonic
Copy link

Everything else look good, colors is correctly applied based on all the props tested. 🙌

Unrelated to the new palette and semantic variables, I see some weird pixel glitching for SplitButton (visible in current version as well).
image

@jzempel jzempel changed the title feat(buttons)!: new light/dark mode colors feat(buttons): new light/dark mode colors May 16, 2024
@jzempel jzempel requested a review from ze-flo May 16, 2024 14:35
@jzempel jzempel merged commit e1b1c46 into next May 16, 2024
@jzempel jzempel deleted the jzempel/recolor-buttons branch May 16, 2024 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

7 participants