Skip to content

DEV: define CSS variables for button colors #33162

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

awesomerobot
Copy link
Member

This adds sets of CSS button variables that can be overridden in themes. This won't change any default styles, but just provides a less problematic method of customization.

The current suggested way of doing this is with SCSS like so:

.btn-default {
  @include btn(
    $text-color: var(--tertiary),
    $bg-color: var(--secondary),
    $icon-color: var(--tertiary-high),
    $hover-text-color: var(--tertiary),
    $hover-bg-color: var(--tertiary-very-low),
    $hover-icon-color: var(--tertiary)
  );
}

The trouble with this is that it brings along all the btn mixin styles, so you also end up re-setting things like this, in addition to changing colors:

.btn-default {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  // and also the colors 
}

That can problematic because it can override existing button styles (e.g., if you already altered a single instance of margin). With these new CSS custom properties, you can avoid this by doing:

:root {
  --d-button-default-text-color: var(--tertiary);
  --d-button-default-text-color--hover: var(--tertiary);
  --d-button-default-bg-color: var(--secondary);
  --d-button-default-bg-color--hover: var(--tertiary-very-low);
  --d-button-default-icon-color: var(--tertiary-high);
  --d-button-default-icon-color--hover: var(--tertiary);
}

So now you can override the button colors without bringing along other styles from the btn mixin.

I also removed an old .btn.hidden style, as we already apply !important to the .hidden class elsewhere. Comments have also been updated to pass our new linting rules.

@@ -30,9 +85,10 @@
cursor: pointer;

@include form-item-sizing;
border: var(--d-button-border);
Copy link
Contributor

Choose a reason for hiding this comment

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

This border looks to be new, not sure if it's intended, it wasn't mentioned in the PR description. It makes sense, though there is a risk of possible regressions in some cases... not sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants