Skip to content
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

Gracefully handle themes/color modes in design system #114

Closed
3 tasks
maxatdetroit opened this issue Oct 31, 2023 · 1 comment
Closed
3 tasks

Gracefully handle themes/color modes in design system #114

maxatdetroit opened this issue Oct 31, 2023 · 1 comment
Assignees
Labels
a11y Digital accessibility. enhancement New feature or request

Comments

@maxatdetroit
Copy link
Member

maxatdetroit commented Oct 31, 2023

Is your feature request related to a problem? Please describe.

When we want to nest our design system web components, the parent component colors (background, border, icons, etc.) do not take effect on child components. This forces the user of the design system to explicitly style the child component to match and contrast the parent component.

See CityOfDetroit/detroitmi#1167 as an example where a workaround is needed to make a button standout when nested within a card.

Describe the solution you'd like

Implement themes (i.e. color modes) for various styles of components. Themes / color modes override CSS variables (background, border, icons, etc.) to encapsulate colors that are consistent with one another. These variables bleed through the shadow DOM so they will also take effect on child components.

Work necessary to properly support themes / color modes in design system:

  • Customize bootstrap to include custom color modes for the city design system. Options to implement: light (white as primary color), dark (city green as primary color), highlight (accent yellow as primary color).
  • Update complex components to support setting themes. E.g., see Fix dark navbar theming #124 where setting a single theme can replace usage of various classes to colorize the navbars.
  • Remove custom attributes on complex components (e.g. data-background-color) currently used to colorize components. If users of the components would like to override specific colors (like background) they can use data-extra-classes and typical bootstrap classes to set those.

Describe alternatives you've considered

Alternatives considered:

  1. Allow the user of the design-system to explicitly set the borders in these scenarios. Cons: the user may forget, it takes more effort to use the components.
  2. Parent components communicate their background color to child components via Javascript, then child component styling is responsible for setting the sensible default colors (borders, background, text). Cons: implementation via Javascript is less desirable than implementation purely via stylesheets per Bootstrap approach.

Pseudocode example:

btnStyles = `
.btn.parent-bg-primary {
  --bs-btn-border-color: $light;
}
`;

class Button extends HTMLElement {
  constructor() {
    ...
    this.shadowDOM.appendChild(btnStyles);
  }

  connectedCallback() {...}

  setParentBackground(parentBackgroundClass) {
    this.btn.classList.add(parentBackgroundClass);
  }
}

class BoxWithButton extends HTMLElement {
  constructor() {...}

  connectedCallback() {
    const bgColor = this.getAttribute('data-bg');
    shadow.addEventListener('slotchange', () => {
      const tempElements = Array.from(this.children);
      tempElements.forEach((node) => {
        node.setParentBackground('parent-bg-' + bgColor);
        this.box.appendChild(node);
    }
  }

  setParentBackground(parentBackgroundClass) {
    this.btn.classList.add(parentBackgroundClass);
  }
}

Additional context
Add any other context or screenshots about the feature request here.

@maxatdetroit maxatdetroit self-assigned this Oct 31, 2023
@maxatdetroit maxatdetroit added enhancement New feature or request a11y Digital accessibility. labels Oct 31, 2023
@maxatdetroit maxatdetroit removed their assignment Nov 27, 2023
@maxatdetroit maxatdetroit added the good first issue Good for newcomers label Nov 27, 2023
@maxatdetroit maxatdetroit changed the title Gracefully handle border against various background colors Gracefully handle theming in design system Nov 29, 2023
@maxatdetroit maxatdetroit changed the title Gracefully handle theming in design system Gracefully handle themes/color modes in design system Nov 29, 2023
@maxatdetroit maxatdetroit self-assigned this Nov 29, 2023
@maxatdetroit maxatdetroit removed the good first issue Good for newcomers label Nov 29, 2023
@maxatdetroit
Copy link
Member Author

This is replaced by #198

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a11y Digital accessibility. enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant