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

Theming experiments: dark mode variables #280

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gallery/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sonatype/react-shared-components-gallery",
"version": "3.3.4",
"version": "3.3.5",
"description": "Gallery application to demonstrate usage and look of Sonatype shared UI components",
"main": "src/main.ts",
"scripts": {
Expand Down
17 changes: 14 additions & 3 deletions gallery/src/PageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* the terms of the Eclipse Public License 2.0 which accompanies this
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/.
*/
import React from 'react';
import { NxPageHeader } from '@sonatype/react-shared-components';
import React, { useEffect, useState } from 'react';
import { NxPageHeader, NxToggle } from '@sonatype/react-shared-components';

import packageJson from '../package.json';

Expand All @@ -15,7 +15,18 @@ function PageHeader() {
version: packageJson.version
};

return <NxPageHeader homeLink="#" productInfo={productInfo} />;
const [darkMode, setDarkMode] = useState(window.localStorage.getItem('darkMode') === 'true');

useEffect(function() {
document.body.classList.toggle('nx-dark-theme', darkMode);
window.localStorage.setItem('darkMode', darkMode.toString());
}, [darkMode]);

return (
<NxPageHeader homeLink="#" productInfo={productInfo}>
<NxToggle isChecked={darkMode} onChange={() => setDarkMode(!darkMode)}>Dark Mode</NxToggle>
</NxPageHeader>
);
}

export default PageHeader;
2 changes: 1 addition & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sonatype/react-shared-components",
"version": "3.3.4",
"version": "3.3.5",
"description": "Sonatype shared UI components and utilities written in React",
"main": "index.js",
"repository": {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions lib/src/base-styles/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
//@import '~normalize.css';

@import 'nx-globals';
@import 'nx-dark-theme';
@import 'nx-typography';

@import 'nx-page-header';
Expand Down
3 changes: 2 additions & 1 deletion lib/src/base-styles/_nx-alert.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@

align-items: first baseline;
background-color: $nx-off-white;
border: $nx-border-darker;
border: 1px solid var(--nx-border-color-starker);
border-radius: $nx-border-radius;
box-sizing: border-box;
color: $nx-text-color;
display: flex;
margin: 16px auto 24px auto;
max-width: 950px;
Expand Down
10 changes: 5 additions & 5 deletions lib/src/base-styles/_nx-btn.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
%nx-btn--disabled {
&.disabled, &[disabled] {
&, &:hover, &:focus {
background-color:$nx-disabled-background;
border-color: $nx-disabled-border;
color: $nx-text-color-disabled;
background-color: var(--nx-interactive-disabled-background-color);
border-color: var(--nx-interactive-disabled-border-color);
color: var(--nx-text-color-disabled);
cursor: default;
}
}
Expand Down Expand Up @@ -38,7 +38,7 @@
}

&:focus {
border: 1px solid $nx-focus-border-color;
border: 1px solid var(--nx-interactive-focus-border-color);
box-shadow: $nx-focus-box-shadow;
outline: 0;
}
Expand Down Expand Up @@ -73,7 +73,7 @@

background-color: transparent;
border-color: #d1d6f0;
color: $nx-text-color-dark;
color: var(--nx-text-color-stark);

&:hover {
background-color: transparent;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/base-styles/_nx-card.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}

.nx-card {
background-color: #fff;
background-color: var(--nx-component-background-color);
border-radius: $nx-border-radius;
box-sizing: border-box;
margin-bottom: $nx-spacing-md;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/base-styles/_nx-counter.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
background-color: #fff;
border: 1px solid $nx-blue-1000;
border-radius: 12px;
color: $nx-text-color-dark;
color: var(--nx-text-color-stark);
display: inline-block;
font-size: 14px;
line-height: $nx-line-height;
Expand Down
55 changes: 55 additions & 0 deletions lib/src/base-styles/_nx-dark-theme.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Copyright (c) 2019-present Sonatype, Inc.
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/.
*/
@mixin dark-theme {
// global CSS variables/custom properties
--nx-site-background-color: #{invert($nx-site-background-color)};
--nx-component-background-color: #{invert($nx-white)};
--nx-form-field-background-color: var(--nx-component-background-color);

--nx-text-color: #{invert($nx-text-color)};
--nx-text-color-stark: #{invert($nx-text-color-dark)};
--nx-heading-color: var(--nx-text-color-stark);
--nx-text-color-disabled: #{invert($nx-text-color-disabled)};

--nx-interactive-selected-background-color: #{invert($nx-selected-background)};
--nx-interactive-active-background-color: #{invert($nx-active-background)};
--nx-interactive-hover-background-color: #{invert($nx-hover-background)};
--nx-interactive-disabled-background-color: #{invert($nx-disabled-background)};
--nx-interactive-disabled-border-color: #{invert($nx-disabled-border)};
--nx-interactive-focus-border-color: #{invert($nx-focus-border-color)};

--nx-border-color: #{invert($nx-grey-3)};
--nx-border-color-stark: #{invert($nx-grey-4)};
--nx-border-color-starker: #{invert($nx-slate)};
--nx-border-color-faded: #{invert($nx-grey-2)};
--nx-border-color-very-faded: #{invert($nx-grey-1)};

--nx-form-field-border-color: #{invert($nx-grey-1100)};

--nx-page-header-background-color: #{invert($nx-off-white)};
--nx-page-header-border-color: #{invert($nx-grey-100)};

--nx-code-background-color: #{invert($nx-grey-1)};

.nx-product__logo-image {
display: none;
}

.nx-product__logo-image--light-text {
display: revert;
}
}

.nx-dark-theme {
@include dark-theme;
}

@media (prefers-color-scheme: dark) {
:root {
@include dark-theme;
}
}
10 changes: 5 additions & 5 deletions lib/src/base-styles/_nx-form-select.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@
background-repeat: no-repeat;
border: 1px solid #d1d6f0;
border-radius: $nx-border-radius;
color: $nx-text-color;
color: var(--nx-text-color);
font-size: $nx-font-size;
line-height: $nx-line-height;
padding: $nx-spacing-xs $nx-spacing-md;
width: $nx-form-element-width-normal;

&:hover {
border-color: $nx-form-element-border-color;
border-color: var(--nx-form-field-border-color);
}

&:focus {
box-shadow: $nx-focus-box-shadow;
border-color: $nx-focus-border-color;
border-color: var(--nx-interactive-focus-border-color);
outline: none;
}

&.disabled {
background-color:$nx-disabled-background;
border-color: $nx-disabled-border;
background-color: var(--nx-interactive-disabled-background-color);
border-color: var(--nx-interactive-disabled-border-color);
}
}

Expand Down
6 changes: 3 additions & 3 deletions lib/src/base-styles/_nx-forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
@include bold();
@include container-horizontal;

color: $nx-text-color-dark;
color: var(--nx-text-color-stark);
cursor: default;
display: block;
margin-bottom: $nx-spacing-xs;
Expand All @@ -66,7 +66,7 @@
.nx-label__text::after, .nx-legend__text::after {
@include regular();

color: $nx-text-color;
color: var(--nx-text-color);
content: "Optional";
font-size: $nx-font-size-xs;
font-style: italic;
Expand All @@ -78,7 +78,7 @@
@include container-horizontal;
@include semi-bold();

color: $nx-text-color-dark;
color: var(--nx-text-color-stark);
font-size: $nx-font-size-s;
display: block;
margin-bottom: $nx-spacing-md;
Expand Down
33 changes: 33 additions & 0 deletions lib/src/base-styles/_nx-globals.scss
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,36 @@ $nx-scrollable-default-height: 400px;
.nx-blockquote {
@extend %nx-blockquote;
}

:root {
// global CSS variables/custom properties
--nx-site-background-color: #{$nx-site-background-color};
--nx-component-background-color: #{$nx-white};
--nx-form-field-background-color: var(--nx-component-background-color);

--nx-text-color: #{$nx-text-color};
--nx-text-color-stark: #{$nx-text-color-dark};
--nx-heading-color: var(--nx-text-color-stark);
--nx-text-color-disabled: #{$nx-text-color-disabled};

--nx-interactive-selected-background-color: #{$nx-selected-background};
--nx-interactive-active-background-color: #{$nx-active-background};
--nx-interactive-hover-background-color: #{$nx-hover-background};
--nx-interactive-disabled-background-color: #{$nx-disabled-background};
--nx-interactive-disabled-border-color: #{$nx-disabled-border};
--nx-interactive-focus-border-color: #{$nx-focus-border-color};
--nx-interactive-focus-shadow-color: #{transparentize($nx-focus-border-color, 0.7)};

--nx-border-color: #{$nx-grey-3};
--nx-border-color-stark: #{$nx-grey-4};
--nx-border-color-starker: #{$nx-slate};
--nx-border-color-faded: #{$nx-grey-2};
--nx-border-color-very-faded: #{$nx-grey-1};

--nx-form-field-border-color: #{$nx-grey-1100};

--nx-page-header-background-color: #{$nx-off-white};
--nx-page-header-border-color: #{$nx-grey-100};

--nx-code-background-color: #{$nx-grey-1};
}
4 changes: 2 additions & 2 deletions lib/src/base-styles/_nx-grid.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
.nx-grid-col {
flex: 1 0;

border-left: $nx-border-light;
border-left: 1px solid var(--nx-border-color-faded);
box-sizing: border-box;
margin: 8px 0;
overflow-x: hidden;
Expand Down Expand Up @@ -59,7 +59,7 @@

.nx-grid-h-keyline {
border: none;
border-top: $nx-border-light;
border-top: 1px solid var(--nx-border-color-faded);
margin: 0;
}

Expand Down
16 changes: 8 additions & 8 deletions lib/src/base-styles/_nx-lists.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
}

&.disabled {
color: $nx-text-color-disabled;
color: var(--nx-text-color-disabled);
cursor: default;
}

Expand Down Expand Up @@ -163,33 +163,33 @@
.nx-list__item {
&.selected {
&, &:hover {
background-color: $nx-selected-background;
background-color: var(--nx-interactive-selected-background-color);
}
}

&:hover {
background-color: $nx-hover-background;
background-color: var(--nx-interactive-hover-background-color);
cursor: pointer;
}

&:active {
background-color: $nx-active-background;
background-color: var(--nx-interactive-active-background-color);
}

&:focus {
box-shadow: $nx-focus-box-shadow;
border-color: $nx-focus-border-color;
border-color: var(--nx-interactive-focus-border-color);
outline: none;
}

&.nx-list__item--empty {
@include regular();

color: $nx-text-color;
color: var(--nx-text-color);
}

&.disabled {
color: $nx-text-color-disabled;
color: var(--nx-text-color-disabled);

&:hover {
background-color: transparent;
Expand All @@ -204,7 +204,7 @@
> .nx-chevron {
align-self: center;
-ms-grid-row-align: center;
color: $nx-text-color-dark;
color: var(--nx-text-color-stark);
-ms-grid-row: 1;
-ms-grid-row-span: 2;
-ms-grid-column: 3;
Expand Down
10 changes: 6 additions & 4 deletions lib/src/base-styles/_nx-page-header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/.
*/

$main-header-background: $nx-off-white;
$main-header-color: $nx-off-black;
$main-header-product-height: 52px;
$main-header-product-title-row-height: 2fr;
Expand All @@ -18,8 +17,8 @@ $main-header-product-version-row-height: 1fr;
.nx-page-header {
box-sizing: content-box;

background-color: $main-header-background;
border-bottom: 1px solid $nx-header-border;
background-color: var(--nx-page-header-background-color);
border-bottom: 1px solid var(--nx-page-header-border-color);
flex-shrink: 0; // needed for IE11
height: $nx-main-header-height;
width: 100%;
Expand All @@ -46,7 +45,6 @@ $main-header-product-version-row-height: 1fr;
.nx-page-header__link {
border-bottom: 2px solid transparent;

color: #515151;
display: inline-block;
font-size: $nx-font-size-s;
margin-right: $nx-spacing-l;
Expand Down Expand Up @@ -105,6 +103,10 @@ $main-header-product-version-row-height: 1fr;
margin-top: 13px; // fix vertical centering
}

.nx-product__logo-image--light-text {
display: none;
}

.nx-product__name {
display: inline-block;
font-size: 26px;
Expand Down
3 changes: 1 addition & 2 deletions lib/src/base-styles/_nx-page-layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}

.nx-body {
background-color: $nx-site-background-color;
background-color: var(--nx-site-background-color);
height: 100%;
margin: 0;
// prevents scrollbar flicker as tooltips appear in IE11
Expand Down Expand Up @@ -52,7 +52,6 @@
.nx-page-sidebar {
@include container-vertical;

background-color: $nx-sidebar-background-color;
box-sizing: border-box;
flex-basis: $nx-sidebar-width;
overflow-x: hidden;
Expand Down
Loading