Skip to content
Closed
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
74 changes: 74 additions & 0 deletions showcase/app/components/shw/theme/switcher.gts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/

import Component from '@glimmer/component';
import { on } from '@ember/modifier';
import { action } from '@ember/object';
import { service } from '@ember/service';

import type ShwThemingService from 'showcase/services/theming';

interface ShwThemeSwitcherSignature {
// Args: {};
Element: HTMLDivElement;
}

export default class ShwThemeSwitcher extends Component<ShwThemeSwitcherSignature> {
@service declare readonly theming: ShwThemingService;

@action
Copy link
Collaborator

Choose a reason for hiding this comment

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

in .gts files @action can be replaced with an arrow function

onChangePageTheme(event: Event) {
const select = event.target as HTMLSelectElement;
console.log(`Theme: ${select.value}`);
console.log(`theming.getTheme: ${this.theming.getTheme()}`);

let theme;
let type;
switch (select.value) {
case 'light-data-attribute':
theme = 'light';
type = 'data-attribute';
break;
case 'light-css-class':
theme = 'light';
type = 'css-class';
break;
case 'dark-data-attribute':
theme = 'dark';
type = 'data-attribute';
break;
case 'dark-css-class':
theme = 'dark';
type = 'css-class';
break;
default:
theme = 'auto';
break;
}

// we set the theme in the global service
this.theming.setTheme(theme, type, 'body');
}

<template>
<div class="shw-theme-switcher" ...attributes>
<label
for="shw-theme-switcher-control"
class="shw-theme-switcher__label"
>Theme:</label>
<select
id="shw-theme-switcher-control"
class="shw-theme-switcher__control"
{{on "change" this.onChangePageTheme}}
>
<option value="auto">Auto (prefers-color-scheme)</option>
<option value="light-css-class">Light (CSS class)</option>
<option value="light-data-attribute">Light (data-attribute)</option>
<option value="dark-css-class">Dark (CSS class)</option>
<option value="dark-data-attribute">Dark (data-attribute)</option>
</select>
</div>
</template>
}
19 changes: 19 additions & 0 deletions showcase/app/controllers/foundations/theming.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/

import Controller from '@ember/controller';
import { inject as service } from '@ember/service';

export default class ThemingController extends Controller {
@service theming;

get currentTheme() {
return this.theming.getTheme();
}

get inverseTheme() {
return this.theming.getInverseTheme();
}
}
2 changes: 2 additions & 0 deletions showcase/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

<link integrity="" rel="stylesheet" href="{{rootURL}}assets/vendor.css">
<link integrity="" rel="stylesheet" href="{{rootURL}}assets/showcase.css">
<!-- <link integrity="" rel="stylesheet" href="{{rootURL}}assets/showcase-theme-light.css"> -->
<!-- <link integrity="" rel="stylesheet" href="{{rootURL}}assets/showcase-theme-dark.css"> -->

<link rel="shortcut icon" href="/assets/logos/favicon.png" />

Expand Down
1 change: 1 addition & 0 deletions showcase/app/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Router.map(function () {
this.route('typography');
this.route('elevation');
this.route('focus-ring');
this.route('theming');
});
this.route('components', function () {
this.route('accordion');
Expand Down
36 changes: 36 additions & 0 deletions showcase/app/services/theming.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import Service from '@ember/service';
import { tracked } from '@glimmer/tracking';

export default class ShwThemingService extends Service {
// undefined means to use the default in the browser, which is "prefers-color-scheme"
@tracked currentTheme = 'auto';

getTheme() {
return this.currentTheme;
// return localStorage.getItem('shwCurrentTheme');
}

getInverseTheme() {
// TODO what happens if we have four themes, like IBM, instead of just two?
return this.currentTheme === 'dark' ? 'light' : 'dark';
}

setTheme(theme, type, target) {
// const fullKey = this.#buildKey(key, appName);
this.currentTheme = theme;
// localStorage.setItem('shwCurrentTheme', theme);
console.log('setting theme', theme, type, target);

const bodyElement = document.querySelector('body');
bodyElement.removeAttribute('data-shw-theme');
bodyElement.classList.remove('shw-theme-dark');
bodyElement.classList.remove('shw-theme-light');

if (type === 'data-attribute') {
bodyElement.setAttribute('data-shw-theme', theme);
} else if (type === 'css-class') {
bodyElement.classList.add(`shw-theme-${theme}`);
}
// }
}
}
6 changes: 5 additions & 1 deletion showcase/app/styles/_globals.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ body {
height: 68px;
padding: 0 24px;
color: var(--shw-color-black);
border-bottom: 1px solid #eaeaea;
border-bottom: 1px solid var(--shw-color-gray-500);
}

.shw-page-header__logo {
Expand Down Expand Up @@ -66,6 +66,10 @@ body {
line-height: 1;
}

.shw-page-header__theme-toggle {
margin-left: auto;
}

.shw-page-aside {
padding: 1rem;

Expand Down
30 changes: 0 additions & 30 deletions showcase/app/styles/_tokens.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,6 @@
// TOKENS (CSS PROPS)

:root {
// COLORS
--shw-color-white: #fff;
--shw-color-gray-600: #f2f2f3;
--shw-color-gray-500: #dbdbdc;
--shw-color-gray-400: #bfbfc0;
--shw-color-gray-300: #727374;
--shw-color-gray-200: #343536;
--shw-color-gray-100: #1d1e1f;
--shw-color-black: #000;
--shw-color-link-on-black: #4294ff;
--shw-color-link-on-white: #2264d6;
--shw-color-feedback-information-100: #0d44cc;
--shw-color-feedback-information-200: #1563ff;
--shw-color-feedback-information-300: #d0e0ff;
--shw-color-feedback-information-400: #eff5ff;
--shw-color-feedback-success-100: #007854;
--shw-color-feedback-success-200: #00bc7f;
--shw-color-feedback-success-300: #c1f1e0;
--shw-color-feedback-success-400: #ebfdf7;
--shw-color-feedback-warning-100: #975b06;
--shw-color-feedback-warning-200: #eaaa32;
--shw-color-feedback-warning-300: #f9eacd;
--shw-color-feedback-warning-400: #fcf6ea;
--shw-color-feedback-critical-100: #ba2226;
--shw-color-feedback-critical-200: #f25054;
--shw-color-feedback-critical-300: #ffd4d6;
--shw-color-feedback-critical-400: #fcf0f2;
--shw-color-action-active-foreground: #00f; // HTML "blue"
--shw-color-action-active-border: #00f; // HTML "blue"
--shw-color-action-active-background: #f0f8ff; // HTML "aliceblue"
// "FLEX/GRID" COMPONENTS
--shw-layout-gap-base: 1rem;
}
6 changes: 5 additions & 1 deletion showcase/app/styles/_typography.scss
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ $show-font-family-mono: ui-monospace, menlo, consolas, monospace;

@mixin shw-font-style-h1() {
@include shw-font-family("gilmer");
color: var(--shw-color-black);
font-weight: 700;
font-size: 3rem;
line-height: 1.3;
Expand All @@ -95,6 +96,7 @@ $show-font-family-mono: ui-monospace, menlo, consolas, monospace;

@mixin shw-font-style-h2() {
@include shw-font-family("gilmer");
color: var(--shw-color-black);
font-weight: 400;
font-size: 1.8rem;
line-height: 1.3;
Expand All @@ -104,6 +106,7 @@ $show-font-family-mono: ui-monospace, menlo, consolas, monospace;

@mixin shw-font-style-h3() {
@include shw-font-family("gilmer");
color: var(--shw-color-black);
font-weight: 400;
font-size: 1.4rem;
line-height: 1.3;
Expand All @@ -113,7 +116,7 @@ $show-font-family-mono: ui-monospace, menlo, consolas, monospace;

@mixin shw-font-style-h4() {
@include shw-font-family("gilmer");
color: #666; // equivalent to `opacity: 0.5`
color: var(--shw-color-gray-300);
font-weight: 500;
font-size: 1.2rem;
line-height: 1.3;
Expand All @@ -123,6 +126,7 @@ $show-font-family-mono: ui-monospace, menlo, consolas, monospace;

@mixin shw-font-style-body {
@include shw-font-family("gilmer");
color: var(--shw-color-black);
font-size: 1rem;
line-height: 1.4;
}
Expand Down
4 changes: 4 additions & 0 deletions showcase/app/styles/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
// global declarations

@import "./tokens";
@import "./showcase-theming/light";
@import "./showcase-theming/dark";
@import "./layout";
@import "./typography";
@import "./globals";
Expand All @@ -23,6 +25,7 @@
@import "./showcase-components/label";
@import "./showcase-components/outliner";
@import "./showcase-components/placeholder";
@import "./showcase-components/theme-switcher";
@import "./mock-components/app";


Expand Down Expand Up @@ -71,6 +74,7 @@
@import "./showcase-pages/tabs";
@import "./showcase-pages/tag";
@import "./showcase-pages/text";
@import "./showcase-pages/theming";
@import "./showcase-pages/tooltip";
@import "./showcase-pages/typography";
// END COMPONENT PAGES IMPORTS
4 changes: 2 additions & 2 deletions showcase/app/styles/showcase-components/divider.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
.shw-divider {
margin: 3rem 0;
border: none;
border-top: 2px solid #ccc;
border-top: 2px solid var(--shw-color-gray-500);
}

.shw-divider--level-2 {
border-top: 2px dotted #ddd;
border-top-style: dotted;
}
6 changes: 3 additions & 3 deletions showcase/app/styles/showcase-components/frame.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $shw-frame-navigation-bar-height: 48px;
max-width: 100%;
height: calc(var(--iframe-height) + #{$shw-frame-navigation-bar-height});
max-height: 100%;
outline: 1px solid #e4e4d4;
outline: 1px solid var(--shw-color-gray-500);
}

.shw-frame__browser-navigation {
Expand All @@ -25,12 +25,12 @@ $shw-frame-navigation-bar-height: 48px;
height: $shw-frame-navigation-bar-height;
// safe area for the dots
padding: 8px 24px 8px 120px;
background-color: #fafafa;
background-color: var(--shw-frame-browser-navigation-background);
background-image: url('data:image/svg+xml,<svg width="56" height="14" viewBox="0 0 56 14" fill="none" xmlns="http://www.w3.org/2000/svg"><circle cx="7" cy="7" r="7" fill="%23FC4847"/><circle cx="28" cy="7" r="7" fill="%23FDAF24"/><circle cx="49" cy="7" r="7" fill="%232AC131"/></svg>');
background-repeat: no-repeat;
background-position: 24px 50%;
background-size: 56px 14px;
border-bottom: 1px solid #e4e4d4;
border-bottom: 1px solid var(--shw-color-gray-500);
}

.shw-frame__open-link {
Expand Down
2 changes: 1 addition & 1 deletion showcase/app/styles/showcase-components/label.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
.shw-label {
@include shw-font-family("rubik");
margin: 0 0 10px 0;
color: #545454;
color: var(--shw-label-text-color);
font-size: 0.8rem;
line-height: 1.2;
}
8 changes: 4 additions & 4 deletions showcase/app/styles/showcase-components/placeholder.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
display: flex;
align-items: center;
justify-content: center;
color: #6b6b6b; // if background is #EEE then this has the appropriate color contrast (4.59:1)
color: var(--shw-placeholder-text-color);
font-weight: bold;
font-size: 10px;
font-family: monaco, Consolas, "Lucida Console", monospace;
line-height: 1.2;
text-align: center;
text-shadow: 0 0 5px #fff;
background-color: #eee;
text-shadow: 0 0 5px var(--shw-color-white);
background-color: var(--shw-placeholder-background-color);

a,
a > & {
color: #333;
color: var(--shw-placeholder-link-color);
text-decoration: underline;
}
}
32 changes: 32 additions & 0 deletions showcase/app/styles/showcase-components/theme-switcher.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/

.shw-theme-switcher {
display: flex;
gap: 8px;
align-items: center;
}

.shw-theme-switcher__label {
color: var(--shw-color-black);
font-size: 0.75rem;
font-family: monaco, Consolas, "Lucida Console", monospace;
}

.shw-theme-switcher__control {
height: 24px;
padding: 2px 24px 2px 8px;
color: var(--shw-color-gray-100);
font-size: 0.75rem;
font-family: monaco, Consolas, "Lucida Console", monospace;
background-color: var(--shw-color-gray-600);
background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M3.34572 7H20.6543C21.8517 7 22.4504 8.4463 21.6028 9.29391L12.9519 17.9515C12.4272 18.4763 11.5728 18.4763 11.0481 17.9515L2.39722 9.29391C1.54961 8.4463 2.14832 7 3.34572 7Z' fill='%23808080'/%3E%3C/svg%3E"); // notice: the 'caret' color is hardcoded here!
background-repeat: no-repeat;
background-position: right 6px top 4px;
background-size: 12px 12px;
border: 1px solid var(--shw-color-gray-400);
border-radius: 3px;
appearance: none;
}
Loading
Loading