Skip to content
This repository was archived by the owner on Oct 7, 2024. It is now read-only.

Commit fb46364

Browse files
committed
feat: Update theming
- Fixes missing `StyleProvider` - Removes unused schemes
1 parent b13a306 commit fb46364

File tree

6 files changed

+76
-110
lines changed

6 files changed

+76
-110
lines changed

docs/reference/admin/theming/introduction.mdx

+48-76
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Theming overview
33
---
44

5-
import { Spacer, Stack } from '@contember/ui'
5+
import { Spacer, Stack, StyleProvider } from '@contember/ui'
66
import {
77
THEMES_LIST_BRANDS,
88
THEMES_LIST_SYSTEM,
@@ -19,16 +19,16 @@ With Contember you can change **theme** and **scheme** independently. Contember
1919
## Color themes
2020

2121
**Contember supports 3 color palettes (themes) to suit your branding needs:**
22-
- <Scale name={THEMES_LIST_BRANDS[0]} direction="horizontal" />
23-
- <Scale name={THEMES_LIST_BRANDS[1]} direction="horizontal" />
24-
- <Scale name={THEMES_LIST_BRANDS[2]} direction="horizontal" />
22+
- <StyleProvider><Scale name={THEMES_LIST_BRANDS[0]} direction="horizontal" /></StyleProvider>
23+
- <StyleProvider><Scale name={THEMES_LIST_BRANDS[1]} direction="horizontal" /></StyleProvider>
24+
- <StyleProvider><Scale name={THEMES_LIST_BRANDS[2]} direction="horizontal" /></StyleProvider>
2525

2626
**Besides the branding color palettes, there are system palettes:**
27-
- <Scale name={THEMES_LIST_SYSTEM[0]} direction="horizontal" />
28-
- <Scale name={THEMES_LIST_SYSTEM[1]} direction="horizontal" />
29-
- <Scale name={THEMES_LIST_SYSTEM[2]} direction="horizontal" />
30-
- <Scale name={THEMES_LIST_SYSTEM[3]} direction="horizontal" />
31-
- <Scale name={THEMES_LIST_SYSTEM[4]} direction="horizontal" />
27+
- <StyleProvider><Scale name={THEMES_LIST_SYSTEM[0]} direction="horizontal" /></StyleProvider>
28+
- <StyleProvider><Scale name={THEMES_LIST_SYSTEM[1]} direction="horizontal" /></StyleProvider>
29+
- <StyleProvider><Scale name={THEMES_LIST_SYSTEM[2]} direction="horizontal" /></StyleProvider>
30+
- <StyleProvider><Scale name={THEMES_LIST_SYSTEM[3]} direction="horizontal" /></StyleProvider>
31+
- <StyleProvider><Scale name={THEMES_LIST_SYSTEM[4]} direction="horizontal" /></StyleProvider>
3232

3333
To generate class names responsible for changing color theme use `toThemeClass(contentTheme, controlsTheme)` helper.
3434

@@ -39,24 +39,29 @@ To generate class names responsible for changing color theme use `toThemeClass(c
3939
- `light` – container and it's descendants will be always displayed in the light mode
4040
- `dark` – container and it's descendants will be always displayed in the dark mode
4141

42+
<StyleProvider>
4243
<Stack direction="horizontal" className="md:flex-wrap">
4344
<ThemePreview heading="Light scheme with default theming" scheme="light" />
4445
<ThemePreview heading="Dark scheme with default theming" scheme="dark" />
4546
<ThemePreview heading="System scheme with default theming" scheme="system" />
4647
</Stack>
48+
</StyleProvider>
4749

4850
To generate class names responsible for changin color theme use `toSchemeClass(contentTheme, controlsTheme)` helper.
4951

5052
### Secondary themed controls
5153

54+
<StyleProvider>
5255
<Stack direction="horizontal" className="md:flex-wrap">
5356
<ThemePreview heading="Light scheme with secondary themed primary button on default content theme" scheme="light" themeControls="secondary" />
5457
<ThemePreview heading="Dark scheme with secondary themed primary button on default content theme" scheme="dark" themeControls="secondary" />
5558
<ThemePreview heading="System scheme with secondary themed primary button on default content theme" scheme="system" themeControls="secondary" />
5659
</Stack>
60+
</StyleProvider>
5761

5862
### Examples of combinations
5963

64+
<StyleProvider>
6065
<Stack direction="horizontal" className="md:flex-wrap">
6166
<ThemePreview heading="Light scheme with success theme for content and positive for primary button and content" scheme="light" theme="success" themeControls="positive" />
6267
<ThemePreview heading="Dark scheme with success theme for content and positive for primary button and content" scheme="dark" theme="success" themeControls="positive" />
@@ -70,82 +75,49 @@ To generate class names responsible for changin color theme use `toSchemeClass(c
7075
<ThemePreview heading="Dark scheme with danger themed primary button on primary themed content" scheme="dark" theme="primary" themeControls="danger" controls />
7176
<ThemePreview heading="System scheme with danger themed primary button on primary themed content" scheme="system" theme="primary" themeControls="danger" controls />
7277
</Stack>
78+
</StyleProvider>
7379

74-
## Theming the Layout
80+
## Theming interface
7581

76-
With `Layout` component you are already able to set theme and scheme on 3 main parts of your admin application:
82+
In Contember you need to use `ColorSchemeProvider` to set the color schema for its children. The `ColorSchemeProvider` accepts `scheme` prop which can be either `light`, `dark` or `system`.
7783

78-
1. The whole app, including the side bar with navigation
79-
2. Page content (applied by the `PageLayout` component)
80-
3. Title bar of the page content (applied by the `PageLayout` component)
81-
82-
### Scheme props
83-
84-
Prop | Type | Description
85-
--------------|----------|------------
86-
`scheme` | [`Scheme`](#appendix-available-theme-and-scheme-values) | Sets the scheme of all layout parts
87-
`pageScheme` | [`Scheme`](#appendix-available-theme-and-scheme-values) | Sets the page scheme of the page part of the layout
88-
`titleScheme` | [`Scheme`](#appendix-available-theme-and-scheme-values) | Sets the scheme of the page title
89-
90-
### Theme props
91-
92-
You can fine-tune layout using only the props to target specific regions of the layout, also you can target the content of the controls independently. See the table for the list of affected regions by the props.
93-
94-
Prop | Type | Lyout content | Layout controls | Page content | Page controls | Page title content | Page title controls |
95-
---------------------|----------|:-------------:|:---------------:|:------------:|:-------------:|:------------------:|:-------------------:|
96-
`theme` | [`Intent`](#appendix-available-theme-and-scheme-values) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅
97-
`themeContent` | [`Intent`](#appendix-available-theme-and-scheme-values) | ✅ | ❌ | ✅ | ❌ | ✅ | ❌
98-
`themeControls` | [`Intent`](#appendix-available-theme-and-scheme-values) | ❌ | ✅ | ❌ | ✅ | ❌ | ✅
99-
`pageTheme` | [`Intent`](#appendix-available-theme-and-scheme-values) | ❌ | ❌ | ✅ | ✅ | ✅ | ✅
100-
`pageThemeContent` | [`Intent`](#appendix-available-theme-and-scheme-values) | ❌ | ❌ | ✅ | ❌ | ✅ | ❌
101-
`pageThemeControls` | [`Intent`](#appendix-available-theme-and-scheme-values) | ❌ | ❌ | ❌ | ✅ | ❌ | ✅
102-
`titleTheme` | [`Intent`](#appendix-available-theme-and-scheme-values) | ❌ | ❌ | ❌ | ❌ | ✅ | ✅
103-
`titleThemeContent` | [`Intent`](#appendix-available-theme-and-scheme-values) | ❌ | ❌ | ❌ | ❌ | ✅ | ❌
104-
`titleThemeControls` | [`Intent`](#appendix-available-theme-and-scheme-values) | ❌ | ❌ | ❌ | ❌ | ❌ | ✅
105-
106-
### Layout code example
84+
Content and controls theme can be set using `contentThemeClassName` and `controlsThemeClassName` helper functions. These functions accept `theme` argument which can be either `primary`, `secondary`, `tertiary`, `success`, `warn` or `danger`.
10785

10886
```tsx
109-
<Layout
110-
sidebarHeader={<a href="#home"><Icon blueprintIcon="home" /> ACME</a>}
111-
navigation={<Menu id="main-navigation">
112-
<Menu.Item>
113-
<Menu.Item title="Foo" href="#" />
114-
<Menu.Item title="Bar" href="#" />
115-
</Menu.Item>
116-
</Menu>}
117-
sidebarFooter={<a href="#logout">Log out</a>}
118-
scheme="dark" // The full layout is in dark mode and ignore the system settings
119-
// pageScheme="system" // Uncomment to allow page section to adapt to system mode
120-
// titleScheme="dark" // Uncomment to set page title in dark mode and ignore the system settings
121-
theme="default" // Both content and controls are colorless...
122-
pageTheme="secondary" // ... however the page theme is in secondary theme...
123-
titleTheme="secondary" // ... and the title theme is secondary too.
124-
// themeContent="tertiary" // Uncomment to override theme prop of the content
125-
// themeControls="secondary" // Uncomment to override theme prop of the control components
126-
// pageThemeContent="success" // turns page contents green
127-
// pageThemeControls="danger" // turns controls red
128-
// titleThemeContent="tertiary" // turns page title contents violet
129-
// titleThemeControls="primary" // // turns page title controls to primary blue
130-
>
131-
<LayoutPage title="Hello world!">
132-
<Box>
133-
<FieldContainer label="Your email">
134-
<TextInput name="email" />
135-
</FieldContainer>
136-
<Spacer />
137-
<Button distinction="primary">Continue</Button>
87+
import { Box, Button, Intent, Scheme, } from "@contember/admin"
88+
import { ColorSchemeProvider } from "@contember/react-utils"
89+
import { colorSchemeClassName, contentThemeClassName, controlsThemeClassName, listClassName } from '@contember/utilities'
90+
91+
export const Example = ({
92+
scheme,
93+
themeContent,
94+
themeControls,
95+
}: {
96+
scheme: Scheme,
97+
themeContent?: Intent,
98+
themeControls?: Intent,
99+
}) => {
100+
const colorScheme = colorSchemeClassName(scheme)
101+
const contentTheme = contentThemeClassName(themeContent ?? theme)
102+
const controlsTheme = controlsThemeClassName(themeControls ?? theme)
103+
104+
return (
105+
<ColorSchemeProvider scheme={scheme}>
106+
<Box className={listClassName([colorScheme, contentTheme, controlsTheme])}>
107+
<Button intent={themeControls}>Button with intent</Button>
108+
<Button distinction="inverse">Inverse button</Button>
109+
<Button distinction="primary" intent={themeControls}>I am important!</Button>
110+
<Button distinction="toned">Toned button</Button>
111+
<Button disabled>Disabled</Button>
138112
</Box>
139-
</LayoutPage>
140-
</Layout>`}
141-
/>
113+
</ColorSchemeProvider>
114+
)
115+
}
142116
```
143117

144118
## Appendix: Available theme and scheme values
145119

146120
Type | Values
147121
-----|--------
148-
Scheme | `"system"`, `"light"`, `"light-above"`, `"light-below"`, `"dark"`, `"dark-above"` or `"dark-below"`
149-
Intent | `"primary"`, `"secondary"`, `"tertiary"`, `"positive"`, `"success"`, `"warn"` or `"danger"`
150-
151-
_**Note:** Internally, Contember uses the `*-above` schema variants to make compoents stand out (lighter) and `*-below` schema variants to push them a litthe to the back (darker). We don't endorse nor discourage you to use these in your layouts._
122+
Scheme | `"system"`, `"light"` or `"dark"`
123+
Intent | `"accent"`, `"primary"`, `"secondary"`, `"tertiary"`, `"positive"`, `"success"`, `"warn"` or `"danger"`

docs/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"skipLibCheck": true,
1010
"strict": true,
1111
"target": "esnext",
12-
"jsx": "react-jsx",
12+
"jsx": "react",
1313
"types": [ "@docusaurus/module-type-aliases", "node", "vite/client" ],
1414
},
1515
}

package-lock.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"@contember/react-utils": "1.2.0-rc.14",
3737
"@contember/schema": "1.2.1",
3838
"@contember/schema-definition": "1.2.1",
39+
"@contember/utilities": "1.2.0-rc.14",
3940
"@docusaurus/module-type-aliases": "^2.4.0",
4041
"@tsconfig/docusaurus": "^1.0.7",
4142
"@types/chroma-js": "^2.4.0",
+21-24
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
import {
2-
Box,
3-
Button,
4-
Heading,
5-
Intent,
6-
Scheme,
7-
toSchemeClass,
8-
toThemeClass
9-
} from "@contember/ui"
10-
import classNames from "classnames"
1+
import { ColorSchemeProvider } from "@contember/react-utils"
2+
import { Box, Button, Heading, Intent, Scheme, } from "@contember/ui"
3+
import { colorSchemeClassName, contentThemeClassName, controlsThemeClassName, listClassName } from '@contember/utilities'
114
import * as React from 'react'
125

136
export const ThemePreview = ({
@@ -23,19 +16,23 @@ export const ThemePreview = ({
2316
themeContent?: Intent,
2417
themeControls?: Intent,
2518
}) => {
26-
const themeClassNames = toThemeClass(themeContent ?? theme, themeContent ?? theme)
27-
const schemeClassName = toSchemeClass(scheme)
2819

29-
return <Box gap="default" className={classNames('theming-theme-preview', schemeClassName, themeClassNames)}>
30-
<Heading>{heading}</Heading>
31-
{(themeClassNames || schemeClassName) && <p>CSS classes: {classNames(schemeClassName, themeClassNames)}</p>}
32-
<Button>Button</Button>
33-
<Button intent={themeControls ?? theme}>Button with intent</Button>
34-
<Button distinction="toned">Toned button</Button>
35-
<Button disabled>Disabled</Button>
36-
<Button
37-
distinction="primary"
38-
intent={themeControls ?? theme}
39-
>I am important!</Button>
40-
</Box>
20+
const colorScheme = colorSchemeClassName(scheme)
21+
const contentTheme = contentThemeClassName(themeContent ?? theme)
22+
const controlsTheme = controlsThemeClassName(themeControls ?? theme)
23+
24+
return (
25+
<ColorSchemeProvider scheme={scheme}>
26+
<Box gap="default" className={listClassName(['theming-theme-preview', colorScheme, contentTheme, controlsTheme])}>
27+
<Heading>{heading}</Heading>
28+
{(contentTheme || controlsTheme || colorScheme) && <p>CSS classes: {listClassName([colorScheme, contentTheme, controlsTheme])}</p>}
29+
<Button>Button</Button>
30+
<Button intent={themeControls ?? theme}>Button with intent</Button>
31+
<Button distinction="inverse">Inverse button</Button>
32+
<Button distinction="primary" intent={themeControls ?? theme}>I am important!</Button>
33+
<Button distinction="toned">Toned button</Button>
34+
<Button disabled>Disabled</Button>
35+
</Box>
36+
</ColorSchemeProvider>
37+
)
4138
}

src/theming/Config.ts

+4-9
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,14 @@ export const WEIGHT_STEP = WEIGHT_MAXIMUM / (COLORS_COUNT - 1);
1010
export const WEIGHT_STEP_LIGHT = WEIGHT_STEP * 1
1111
export const WEIGHT_STEP_DARK = WEIGHT_STEP * 1
1212

13-
/**
14-
* @deprecated
15-
*/
1613
export const THEMES_LIST_BRANDS = [
1714
'primary',
1815
'secondary',
1916
'tertiary',
2017
]
2118

22-
/**
23-
* @deprecated
24-
*/
2519
export const THEMES_LIST_SYSTEM = [
20+
'accent',
2621
'positive',
2722
'success',
2823
'warn',
@@ -49,13 +44,13 @@ export const themeNames = {
4944
export type ThemeName = keyof typeof themeNames
5045

5146
export const CONTEMBER_THEMES: {[Property in ThemeName]: [string, string, string]} = Object.freeze({
52-
accent: ['#AFE9FF', '#00AEFF', '#004397'],
47+
accent: ['#006AFF', '#006AFF', '#006AFF'],
5348
primary: ['#AFE9FF', '#00AEFF', '#004397'],
5449
secondary: ["#A980FD", "#841DFB", "#54017E"],
5550
tertiary: ["#EEEDA1", "#DCDA41", "#97961D"],
56-
positive: ['#AFE9FF', '#00AEFF', '#004397'],
51+
positive: ['#006AFF', '#006AFF', '#006AFF'],
5752
success: ["#97E6C0", "#4AD18F", "#008B46" /* "#007F40" */],
5853
warn: ["#F9A986", "#FF4E00" /*"#D94C0F"*/, "#B43E09" /* "#792A06" */],
5954
danger: ["#FF004C", "#FF4D00", "#FF0000"], //"#FF4827",
60-
default: ["#FFFFFA", "#FFFFFA", "#FFFFFA"]
55+
default: ["#FFFFFA", "#FFFFFA", "#FFFFFA"],
6156
})

0 commit comments

Comments
 (0)