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

Use data attribute to choose component colors #2507

Closed
2 tasks done
Tracked by #2370
mimarz opened this issue Sep 24, 2024 · 7 comments
Closed
2 tasks done
Tracked by #2370

Use data attribute to choose component colors #2507

mimarz opened this issue Sep 24, 2024 · 7 comments
Assignees
Labels
cli @digdir/designsystemet 🎨 figma Everything related to changes in Figma 🕵️ investigate Needs investigation 🎨 theme-builder Everything related to our theme builder

Comments

@mimarz
Copy link
Collaborator

mimarz commented Sep 24, 2024

TLDR; Lift semantic color definition to a higher level and have components only use a generic --ds-color-* variable. Which semantic color i used for a component is then defined by the user using data-attributes ([data-color="accent|neutral|my-color"]). Users are free to add any number of colors and name them accordingly to their semantic needs.

Example code

/** In generated theme file from design-tokens */
:root, [data-ds-color-mode="light"] {

/** We probably need some default colors here. Neutral? */
--ds-color-surface-default: var(--ds-color-neutral-3);

[data-color="accent"] {
--ds-color-surface-default: var(--ds-color-accent-3);
}

[data-color="neutral"] {
--ds-color-surface-default: var(--ds-color-neutral-3);

}

[data-color="my-color"] {
--ds-color-surface-default: var(--ds-color-my-color-3);

}
}

/** In Button CSS */

.ds-button {
  background-color: var(--ds-color-surface-default);
}
<Button data-color="my-color" ></Button>
<Accordion data-color="my-color"></Accordion>

WIP Notes

  • Do we need neutral separaetly for things that are always neutral?
  • Users can add (and name) up to 3 additional "color" in theme-builder.
    • This limitation is due to Figma's restriction of only 4 modes in variables (accent + 3 custom colors)
  • Uses something like data-attributes (data-ds-color-scheme) to change which color scale the color variables are pointing to.
    • We current have --ds-color-accent-* which works like this, but might be hard to rename to --ds-color-* because of mapping to Figma variables.
    • We already have data-ds-color-mode, which users can use to switch between dark | light | auto

Tasks

@mimarz mimarz converted this from a draft issue Sep 24, 2024
@mimarz mimarz added 🎨 figma Everything related to changes in Figma 🎨 theme-builder Everything related to our theme builder cli @digdir/designsystemet labels Sep 24, 2024
@mimarz
Copy link
Collaborator Author

mimarz commented Sep 24, 2024

This needs to be done after #2287

@mimarz mimarz added the 🕵️ investigate Needs investigation label Sep 24, 2024
@mimarz mimarz changed the title POC: Add custom color-schemes Make color great again Sep 26, 2024
@unekinn
Copy link
Contributor

unekinn commented Oct 18, 2024

@mimarz & @Febakke Here's my step-by-step plan to implement this, based on my existing proof of concept. If this seems okay, should I add these as separate issues and add them to the board, or is it enough to track it here?

  • cli: Refactor build script for easier extension with new modes
    refactor(cli): declarative build configuration #2633

  • css/cli/themes: Output only global and semantic color variables
    feat(cli,theme): don't output underlying primitives for semantic color variables #2641

  • css/cli/themes: Output only semantic size/space/radius variables
    Flatten variables in semantic.css #2642
    Doing this the "easy way" (references: false) has some issues, and it is not necessary for the rest to work, so we leave it out for now

  • tokens: Add tokens and Tokens Studio themes for main-color and support-color, but without using them anywhere. The structure will be

    • main: [accent]
    • support: [brand1, brand2, brand3]

    Colors in semantic/colors.json remain the same, and CLI build output is unchanged.
    feat(tokens): add modes for semantic color categories main & support #2643

  • cli: Implement data-color , which combines colors from main and support , and the individual neutral/success/warning/danger colors.
    feat(cli,theme): add color category variables using data-color attribute #2644

  • css/react:

    • Use variables from data-color in components that already had a color prop (no implicit color inheritance yet)
    • Find a way to configure the default color for components that currently default to "accent", since we won't require a color named "accent" in the future. This should be done without changing the default of components that currently default to "neutral" (or other built-in colors)
    • Use variables from data-color in components that currently use accent and don't have a color prop, so they can be changed.
      feat(css,theme,react): use data-color in all components, with color inheritance for some #2703
  • Figma: Replace color props in Figma component variants with the combination of color: main | support and setting the correct mode

  • cli/theme-builder: Implement support for specifying your own color names and number of colors per color category. This will require some changes in the theme builder under the hood, but the GUI will remain the same for now.

    Example: my-theme.json

    {
      "colors": {
        "main": {
          "dominant": "#303030",
          "complimentary": "#BED5E8",
          "accent": "#76C69D"
        },
        "support": {
          "alt1": "#B9D9C8",
          "alt2": "#BAC6D8",
          "alt3": "#E5CEAE"
        }
      }
    }

    CLI:

    npx @digdir/designsystemet tokens create --json my-theme.json
    
  • theme-builder: Implement UI for configuring your own color names and number of colors per category

@mimarz
Copy link
Collaborator Author

mimarz commented Oct 30, 2024

After demo today we suggest the following.

  • We need a minimum of 1 user-defined color and neutral color for this system to work.
  • data-color does not override global colors such as info, warning, success and danger
  • We need to figure out how opt-out color subtle variant should be used. Currently only Card & Accordion
  • Some components have default neutral color instead of "default" color.
  • React Portal can cause issues with use of data-color as the portal element is put outside somewhere else in the dom-tree (usually on body)

@mimarz mimarz changed the title Make color great again Use data-color to choose component colors Oct 30, 2024
@mimarz mimarz changed the title Use data-color to choose component colors Use data attribute to choose component colors Oct 30, 2024
@Febakke
Copy link
Member

Febakke commented Nov 7, 2024

Figma testing with @unekinn

Color scales that will be included as Figma variables

Two new modes

  • Main
    • accent, primary and complimentary for example
    • Will reference color scales in the semantic/color collection
  • Support
    • Replace brand1, brand2...
    • Will reference support scales in semantic/color collection

Obs
We need to document that if users use the color scales from semantic that are used in main and support directly they might have issues if the change names later. For instance if you set background color to primary-background instead of main-background. We have experienced that Token Studio might not always be able to make Figma understand that they are the same scales. The consequence is dead token references in Figma

Figma tasks

  • Export the new collections from Token Studio. They are in the next branch now
  • Use Variables pro plug in to change from accent to main on all components. We might want to buy a pro lisence to do this.
    • We do not need to wait for sizing to do this as it is pretty quick
  •  Do the same with brand components
  • Maybe wait for sizing to be complete Add all relevant new variants of components. Most will have a main and neutral version and some will have a support version.

@mimarz
Copy link
Collaborator Author

mimarz commented Nov 15, 2024

Oppsumering av diskusjonen tidligere idag rundt data-color. Etter litt testing så har vi funnet ut at vi må ha minst èn farge og svart/hvit (neutral).
Vi har sparret litt på løsninger, men kom fram til at beste løsningen er å låse det slikt at vi alltid har èn predefinert farge.

Brukere kan fritt navngi fargen og første fargen blir satt som default farge for data-color attributtene.

Edit: Oppdatert

@mrosvik mrosvik removed this from the V1 - Helhetlig komponentbibliotek milestone Nov 26, 2024
@mimarz
Copy link
Collaborator Author

mimarz commented Dec 6, 2024

Fixes with #2836

@mimarz
Copy link
Collaborator Author

mimarz commented Dec 11, 2024

We have finished this feature, further tweaks and adjustments will be done in separate issues

@mimarz mimarz closed this as completed Dec 11, 2024
@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in Team Design System Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli @digdir/designsystemet 🎨 figma Everything related to changes in Figma 🕵️ investigate Needs investigation 🎨 theme-builder Everything related to our theme builder
Projects
Status: ✅ Done
Development

No branches or pull requests

5 participants