Skip to content

Commit

Permalink
default theme; docs setup
Browse files Browse the repository at this point in the history
  • Loading branch information
thompsongl committed Jan 15, 2021
1 parent 7e13703 commit e45fb50
Show file tree
Hide file tree
Showing 4 changed files with 243 additions and 43 deletions.
14 changes: 12 additions & 2 deletions src-docs/src/components/with_theme/theme_context.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import React from 'react';
import { EUI_THEMES, EUI_THEME } from '../../../../src/themes';
import { EUI_THEMES, EUI_THEME, DefaultEuiTheme } from '../../../../src/themes';
// @ts-ignore importing from a JS file
import { applyTheme } from '../../services';
import {
// buildTheme,
// computed,
// useEuiTheme,
EuiThemeProvider,
} from '../../../../src/services/theme';

const THEME_NAMES = EUI_THEMES.map(({ value }) => value);

Expand Down Expand Up @@ -47,7 +53,11 @@ export class ThemeProvider extends React.Component<object, State> {
theme,
changeTheme: this.changeTheme,
}}>
{children}
<EuiThemeProvider
theme={DefaultEuiTheme}
colorMode={theme.includes('light') ? 'light' : 'dark'}>
{children}
</EuiThemeProvider>
</ThemeContext.Provider>
);
}
Expand Down
57 changes: 16 additions & 41 deletions src-docs/src/views/emotion/canopy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,12 @@ import chroma from 'chroma-js';
import { EuiSpacer } from '../../../../src/components/spacer';
import { EuiIcon } from '../../../../src/components/icon';
import {
buildTheme,
computed,
// buildTheme,
// computed,
useEuiTheme,
EuiThemeProvider,
} from '../../../../src/services/theme';

const globalTheme = buildTheme({
light: {
colors: {
primary: '#006BB4',
secondary: computed(['light.colors.primary'], ([primary]) => {
return chroma(primary).darken(2).hex();
}),
tertiary: computed(['light.colors.secondary'], ([secondary]) => {
return chroma(secondary).brighten().hex();
}),
},
},
dark: {
colors: {
primary: '#DD0A73',
secondary: computed(['dark.colors.primary'], ([primary]) => {
return chroma(primary).brighten(3).hex();
}),
tertiary: computed(['dark.colors.secondary'], ([secondary]) => {
return chroma(secondary).darken().hex();
}),
},
},
});
import { DefaultEuiTheme } from '../../../../src/themes';

const View = () => {
const [theme, , colorMode] = useEuiTheme();
Expand All @@ -65,28 +41,28 @@ const View = () => {
</pre>
</div>
<div>
<h3 id={theme.colors.primary}>
<h3>
<EuiIcon
aria-hidden="true"
type="stopFilled"
size="xxl"
css={{ color: theme.colors.primary }}
css={{ color: theme.colors.euiColorPrimary }}
/>
</h3>
<h3 id={theme.colors.secondary}>
<h3>
<EuiIcon
aria-hidden="true"
type="stopFilled"
size="xxl"
css={{ color: theme.colors.secondary }}
css={{ color: theme.colors.euiColorSecondary }}
/>
</h3>
<h3 id={theme.colors.tertiary}>
<h3>
<EuiIcon
aria-hidden="true"
type="stopFilled"
size="xxl"
css={{ color: theme.colors.tertiary }}
css={{ color: theme.colors.euiTextColor }}
/>
</h3>
</div>
Expand All @@ -97,10 +73,10 @@ const View = () => {
const View3 = () => {
const overrides = {
light: {
colors: { primary: '#017D73' },
colors: { euiColorPrimary: '#8A07BD' },
},
dark: {
colors: { primary: '#F5A700' },
colors: { euiColorPrimary: '#bd07a5' },
},
};
return (
Expand All @@ -119,10 +95,10 @@ const View3 = () => {
const View2 = () => {
const overrides = {
light: {
colors: { secondary: '#017D73' },
colors: { euiColorSecondary: '#85e89d' },
},
dark: {
colors: { secondary: '#F5A700' },
colors: { euiColorSecondary: '#f0fff4' },
},
};
return (
Expand All @@ -147,7 +123,7 @@ export default () => {
...overrides,
light: {
colors: {
primary: chroma.random().hex(),
euiColorPrimary: chroma.random().hex(),
},
},
});
Expand All @@ -157,7 +133,7 @@ export default () => {
...overrides,
dark: {
colors: {
primary: chroma.random().hex(),
euiColorPrimary: chroma.random().hex(),
},
},
});
Expand All @@ -166,7 +142,7 @@ export default () => {
return (
<>
<EuiThemeProvider
theme={globalTheme}
theme={DefaultEuiTheme}
colorMode={colorMode}
overrides={overrides}>
<button type="button" onClick={toggleTheme}>
Expand All @@ -180,7 +156,6 @@ export default () => {
<button type="button" onClick={darkColors}>
Randomize Dark Primary!
</button>

<EuiSpacer />
<em>Default view</em>
<View />
Expand Down
1 change: 1 addition & 0 deletions src/themes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
*/

export { EUI_THEMES, EUI_THEME } from './themes';
export { DefaultEuiTheme } from './theme';
214 changes: 214 additions & 0 deletions src/themes/theme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import chroma from 'chroma-js';
import { buildTheme, computed } from '../services/theme';

export const tint = (c: string, pct: any) =>
pct && chroma.mix(c, '#fff', pct).hex();
export const shade = (c: string, pct: any) =>
pct && chroma.mix(c, '#000', pct).hex();
const makeHighContrastColor = (c: string) => c;
const makeDisabledContrastColor = (c: string) => c;

export const light = {
euiColorPrimary: '#006BB4',
euiColorSecondary: '#017D73',
euiColorAccent: '#DD0A73',

// These colors stay the same no matter the theme
euiColorGhost: '#FFF',
euiColorInk: '#000',

// Status
euiColorSuccess: computed(
['light.colors.euiColorSecondary'],
([euiColorSecondary]) => euiColorSecondary
),
euiColorDanger: '#BD271E',
euiColorWarning: '#F5A700',

// Grays
euiColorEmptyShade: '#FFF',
euiColorLightestShade: '#F5F7FA',
euiColorLightShade: '#D3DAE6',
euiColorMediumShade: '#98A2B3',
euiColorDarkShade: '#69707D',
euiColorDarkestShade: '#343741',
euiColorFullShade: '#000',

// Backgrounds
euiPageBackgroundColor: computed(
['light.colors.euiColorLightestShade'],
([euiColorLightestShade]) => tint(euiColorLightestShade, 0.5)
),
euiColorHighlight: '#FFFCDD',

// Every color below must be based mathematically on the set above and in a particular order.
euiTextColor: computed(
['light.colors.euiColorDarkestShade'],
([euiColorDarkestShade]) => euiColorDarkestShade
),
euiTitleColor: computed(['light.colors.euiTextColor'], ([euiTextColor]) =>
shade(euiTextColor, 0.5)
),
euiTextSubduedColor: computed(
['light.colors.euiColorMediumShade'],
([euiColorMediumShade]) => makeHighContrastColor(euiColorMediumShade)
),
euiColorDisabled: computed(['light.colors.euiTextColor'], ([euiTextColor]) =>
tint(euiTextColor, 0.7)
),

// Contrasty text variants
euiColorPrimaryText: computed(
['light.colors.euiColorPrimary'],
([euiColorPrimary]) => makeHighContrastColor(euiColorPrimary)
),
euiColorSecondaryText: computed(
['light.colors.euiColorSecondary'],
([euiColorSecondary]) => makeHighContrastColor(euiColorSecondary)
),
euiColorAccentText: computed(
['light.colors.euiColorAccent'],
([euiColorAccent]) => makeHighContrastColor(euiColorAccent)
),
euiColorWarningText: computed(
['light.colors.euiColorWarning'],
([euiColorWarning]) => makeHighContrastColor(euiColorWarning)
),
euiColorDangerText: computed(
['light.colors.euiColorDanger'],
([euiColorDanger]) => makeHighContrastColor(euiColorDanger)
),
euiColorDisabledText: computed(
['light.colors.euiColorDisabled'],
([euiColorDisabled]) => makeDisabledContrastColor(euiColorDisabled)
),
euiColorSuccessText: computed(
['light.colors.euiColorSecondaryText'],
([euiColorSecondaryText]) => euiColorSecondaryText
),
euiLinkColor: computed(
['light.colors.euiColorPrimaryText'],
([euiColorPrimaryText]) => euiColorPrimaryText
),
// State
euiFocusTransparency: 0.1,
euiFocusBackgroundColor: computed(
['light.colors.euiColorPrimary', 'light.colors.euiFocusTransparency'],
([euiColorPrimary, euiFocusTransparency]) =>
tint(euiColorPrimary, 1 - euiFocusTransparency)
),
};

export const dark = {
// These colors stay the same no matter the theme
euiColorGhost: '#FFF',
euiColorInk: '#000',

// Core
euiColorPrimary: '#1BA9F5',
euiColorSecondary: '#7DE2D1',
euiColorAccent: '#F990C0',

// Status
euiColorSuccess: computed(
['dark.colors.euiColorSecondary'],
([euiColorSecondary]) => euiColorSecondary
),
euiColorWarning: '#FFCE7A',
euiColorDanger: '#F66',

// Grays
euiColorEmptyShade: '#1D1E24',
euiColorLightestShade: '#25262E',
euiColorLightShade: '#343741',
euiColorMediumShade: '#535966',
euiColorDarkShade: '#98A2B3',
euiColorDarkestShade: '#D4DAE5',
euiColorFullShade: '#FFF',

// Backgrounds
euiPageBackgroundColor: computed(
['light.colors.euiColorLightestShade'],
([euiColorLightestShade]) => shade(euiColorLightestShade, 0.3)
),
euiColorHighlight: '#2E2D25',

// Variations from core
euiTextColor: '#DFE5EF',
euiTitleColor: computed(
['dark.colors.euiTextColor'],
([euiTextColor]) => euiTextColor
),
euiTextSubduedColor: computed(
['light.colors.euiColorMediumShade'],
([euiColorMediumShade]) => makeHighContrastColor(euiColorMediumShade)
),
euiColorDisabled: computed(['light.colors.euiTextColor'], ([euiTextColor]) =>
shade(euiTextColor, 0.7)
),

// Contrasty text variants
euiColorPrimaryText: computed(
['light.colors.euiColorPrimary'],
([euiColorPrimary]) => makeHighContrastColor(euiColorPrimary)
),
euiColorSecondaryText: computed(
['light.colors.euiColorSecondary'],
([euiColorSecondary]) => makeHighContrastColor(euiColorSecondary)
),
euiColorAccentText: computed(
['light.colors.euiColorAccent'],
([euiColorAccent]) => makeHighContrastColor(euiColorAccent)
),
euiColorWarningText: computed(
['light.colors.euiColorWarning'],
([euiColorWarning]) => makeHighContrastColor(euiColorWarning)
),
euiColorDangerText: computed(
['light.colors.euiColorDanger'],
([euiColorDanger]) => makeHighContrastColor(euiColorDanger)
),
euiColorDisabledText: computed(
['light.colors.euiColorDisabled'],
([euiColorDisabled]) => makeDisabledContrastColor(euiColorDisabled)
),
euiColorSuccessText: computed(
['light.colors.euiColorSecondaryText'],
([euiColorSecondaryText]) => euiColorSecondaryText
),
euiLinkColor: computed(
['light.colors.euiColorPrimaryText'],
([euiColorPrimaryText]) => euiColorPrimaryText
),
// State
euiFocusTransparency: 0.3,
euiFocusBackgroundColor: computed(
['dark.colors.euiColorPrimary', 'dark.colors.euiFocusTransparency'],
([euiColorPrimary, euiFocusTransparency]) =>
shade(euiColorPrimary, 1 - euiFocusTransparency)
),
};

export const DefaultEuiTheme = buildTheme({
light: { colors: light },
dark: { colors: dark },
});

0 comments on commit e45fb50

Please sign in to comment.