Skip to content

Commit 6602a89

Browse files
QZ-766 Navigation color schemes (#117)
* QZ-766 Navigation color schemes * Add TypeScript types Co-authored-by: GitHub Action <action@github.com>
1 parent 20adef8 commit 6602a89

File tree

3 files changed

+67
-11
lines changed

3 files changed

+67
-11
lines changed

dist/ColorScheme/ColorScheme.d.ts

Lines changed: 22 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ColorScheme/ColorScheme.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/ColorScheme/ColorScheme.tsx

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import colors from '@quartz/styles/dictionaries/colors.json';
1717
*
1818
* 1. Typography: Default font color.
1919
* 2. Background 1: Background color of the page.
20-
* 3. Accent 1: The color of focused interactive borders, accented color blocks,
20+
* 3. Accent: The color of focused interactive borders, accented color blocks,
2121
* article text links, certain headings and more.
2222
* 4. UI: The color of the site logo and other chrome in the navigation and
2323
* around the site.
@@ -31,10 +31,12 @@ import colors from '@quartz/styles/dictionaries/colors.json';
3131
* sections. Defaults to Background 1.
3232
* 7. Background 3: a second tint of the background color. Defaults to
3333
* Typography with 10% alpha channel.
34-
* 8. Navigation background: background of the navigation and tab bar. Defaults
35-
* to Background 1.
36-
* 9. Highlight: color used to highlight text or other UI elements for emphasis.
37-
* 10. Typography inverted: inverted type color used in overlaid elements.
34+
* 8. Highlight: color used to highlight text or other UI elements for emphasis.
35+
* 9. Typography inverted: inverted type color used in overlaid elements.
36+
* 10. Navigation background: background of navigation elements. Defaults
37+
* to Background 1.
38+
* 11. Navigation typography: Type color of navigation elements. Defaults to Typography.
39+
* 12. Navigation accent: Accent color of navigation elements. Defaults to Accent.
3840
*/
3941
export const schemes = {
4042
LIGHT: {
@@ -69,42 +71,53 @@ function createRgba( r: number, g: number, b: number, a: number ): string {
6971

7072
function getCss ( {
7173
accent,
74+
accentNavigation,
7275
background1,
7376
background2,
77+
backgroundNavigation,
7478
highlight,
7579
type,
7680
typography,
7781
typographyInverted,
82+
typographyNavigation,
7883
} ) {
7984
// Print color schemes are simpler.
8085
if ( 'print' === type ) {
8186
return `
8287
@media print {
8388
:root {
8489
--color-accent: ${accent};
90+
--color-accent-navigation: ${accent};
8591
--color-background-1: ${background1};
8692
--color-background-1-transparent: transparent;
8793
--color-background-2: transparent;
8894
--color-background-3: transparent;
8995
--color-background-4: transparent;
9096
--color-background-navigation: transparent;
97+
--color-background-navigation-faint: transparent;
9198
--color-border-decorative: ${typography};
9299
--color-border-interactive: ${typography};
93100
--color-highlight: transparent;
94101
--color-typography: ${typography};
95102
--color-typography-faint: ${typography};
96103
--color-typography-inverted: ${typographyInverted || background1};
104+
--color-typography-navigation: ${typography};
105+
--color-typography-navigation-faint: ${typography};
97106
}
98107
}`;
99108
}
100109

101110
// Colors derived from the typography color:
102111
const typographyRgb = hexToRGB( typography );
112+
const typographyNavigationRgb = hexToRGB( typographyNavigation || typography );
113+
const backgroundNavigationRgb = hexToRGB( backgroundNavigation || background1 );
103114
const typographyFaint = createRgba( ...typographyRgb, 0.7 ); // A fainter tint of the typography color, eg. for descriptions or subheadings.
115+
const typographyNavigationFaint = createRgba( ...typographyNavigationRgb, 0.7 ); // A fainter tint of the typography-navigation color, eg. for descriptions or subheadings under navigation elements.
104116
const borderDecorative = createRgba( ...typographyRgb, 0.15 );
105117
const borderInteractive = createRgba( ...typographyRgb, 0.3 );
106118
const background3 = createRgba( ...typographyRgb, 0.15 );
107119
const background4 = createRgba( ...typographyRgb, 0.07 );
120+
const backgroundNavigationFaint = backgroundNavigation ? createRgba( ...backgroundNavigationRgb, 0.98 ) : background2; // A fainter tint of the navigation background color, eg. nav flyouts
108121

109122
// Colors derived from the background color:
110123
const backgroundRgb = hexToRGB( background1 );
@@ -114,18 +127,23 @@ function getCss ( {
114127
const css = `
115128
:root {
116129
--color-accent: ${accent};
130+
--color-accent-navigation: ${accentNavigation || accent};
117131
--color-background-1: ${background1};
118132
--color-background-1-transparent: ${fakeTransparent};
119133
--color-background-2: ${background2 || background1};
120134
--color-background-3: ${background3};
121135
--color-background-4: ${background4};
136+
--color-background-navigation: ${backgroundNavigation || background1};
137+
--color-background-navigation-faint: ${backgroundNavigationFaint};
122138
--color-background-modal: ${backgroundModal};
123139
--color-border-decorative: ${borderDecorative};
124140
--color-border-interactive: ${borderInteractive};
125141
--color-highlight: ${highlight || borderDecorative};
126142
--color-typography: ${typography};
127143
--color-typography-faint: ${typographyFaint};
128144
--color-typography-inverted: ${typographyInverted || background1};
145+
--color-typography-navigation: ${typographyNavigation || typography};
146+
--color-typography-navigation-faint: ${typographyNavigationFaint};
129147
}
130148
`;
131149

@@ -143,6 +161,13 @@ export default function ColorScheme( props: {
143161
*/
144162
accent: string,
145163

164+
/**
165+
* The color used for borders of focused interactive elements, accented
166+
* color blocks, article text links, certain headings, etc. on navigation.
167+
* Defaults to `accent`.
168+
*/
169+
accentNavigation?: string,
170+
146171
/**
147172
* Primary background color of the page.
148173
*/
@@ -154,6 +179,12 @@ export default function ColorScheme( props: {
154179
*/
155180
background2?: string,
156181

182+
/**
183+
* Background of the navigation.
184+
* Defaults to `background1`.
185+
*/
186+
backgroundNavigation?: string,
187+
157188
/**
158189
* An optional render prop if you need to use the CSS in a non-HTML context or
159190
* if you need to provide it to an external dependency like React Helmet.
@@ -182,18 +213,26 @@ export default function ColorScheme( props: {
182213
* Inverted type color, for use in overlaid elements. Defaults to `background1`.
183214
*/
184215
typographyInverted?: string,
216+
217+
/**
218+
* Type color of the navigation.
219+
*/
220+
typographyNavigation?: string,
185221
} ) {
186222
// Reassembling ensures we don't have any hidden dependencies in our props (and
187223
// pleases the linter).
188224
const css = minifyCss(
189225
getCss( {
190226
accent: props.accent,
227+
accentNavigation: props.accentNavigation,
191228
background1: props.background1,
192229
background2: props.background2,
230+
backgroundNavigation: props.backgroundNavigation,
193231
highlight: props.highlight,
194232
type: props.type,
195233
typography: props.typography,
196234
typographyInverted: props.typographyInverted,
235+
typographyNavigation: props.typographyNavigation,
197236
} )
198237
);
199238

0 commit comments

Comments
 (0)