Skip to content

Conversation

colegoldsmith
Copy link
Collaborator

Figma Variables as CSS Variables

I exported our design tokens from Figma into CSS variables we can use for this project into ds-tokens.css.
In order for dark mode to work properly we need to use these global tokens everywhere we style a color.
Global tokens Figma

Open Question: Do we like the ds- prefix for our CSS variables?

I added this to make it clear they are custom variables for datastax, and to avoid potential collisions with existing classes.

I went ahead and replaced/reassigned the existing default antora css variables (vars.css) with the appropriate global token. This way the UI keeps it's original class names and we are simply applying different colors.

Theme Switcher

By using the html[data-theme] attribute with the new css variables we can change the theme with a little js code. I've added a new script 07-theme-toggle.js along with a new button in the top nav.

Screenshot 2023-09-11 at 6 11 35 PM

Dark mode! ✨
Screenshot 2023-09-11 at 6 21 48 PM

New Fonts

Roboto Flex is now the default font applied to most text.

I've also added the Material Icons Outlined and a bit of css so we can use Material Icons.

To use them we can add the textual icon name into an element (ligatures) with a specific class name

<span class="material-icons">light_mode</span>

Reference

Typography Helper Classes

I also added some helper classes in ds-typography.css so we can quickly use our typography specs

]),
postcssVar({ preserve: preview }),
// NOTE because css vars are our theme switching mechanism we must preserve them with preserve: true
postcssVar({ preserve: true }),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The result of this is I think about 150 extra lines of css, nothing major. By preserving the css vars it leaves them as is instead of trying to resolve the values into plain css

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I created these classes for some utility later on. When we start styling the app more we can quickly use one of these classes to get the right font size and weight. The Figma files will be using these names and styles for all the text

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I took a quick stab at mimicking the code block component styles from Astra-UI. We use Prism there so these highlightjs styles won't match exactly. We can tune it more later once we have actual vector docs in place

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I re-mapped all the default css variables from antora with an appropriate new variable. For the default UI this gets dark mode working pretty well. We will probably replace/remove a lot these soon but it was easy enough to start using our new tokens

</div>
<div class="navbar-item">
<span class="control">
<button class="button is-primary" id="theme-toggle"></button>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a placeholder button until we get our new nav structure in place, I just wanted to test the toggle mechanism


var storedTheme =
localStorage.getItem('theme') ||
(window.matchMedia('(prefers-color-scheme: dark)').matches
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

One problem I'm still looking into is the "flicker" that happens when your system/browser prefers dark mode. Light mode is the :root css default so the page flashes white initially before the JS code sees that it should be dark and switches

@mlr mlr self-requested a review September 12, 2023 18:02
@colegoldsmith colegoldsmith merged commit 7d04ac9 into main Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants