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

Commit c923458

Browse files
authored
Merge pull request #135 from contember/pr/upgrading-to-v1-2-0
Pr/upgrading to v1 2 0
2 parents 0b7e493 + fb46364 commit c923458

13 files changed

+418
-267
lines changed

docs/guides/migration-from-v1-1.md

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
---
2+
title: Migration from v1.1
3+
---
4+
5+
:::warning
6+
This guide is a work in progress to enable you to migrate your application from Contember v1.1 to v1.2.0 before the final release.
7+
:::
8+
9+
1.2.0 is a major release of the framework. It contains some pretty exciting features, but also a few breaking changes to make way for the future. This guide will help you upgrade your application to 1.2.0 and take advantage of the new features.
10+
11+
## Bump versions of `@contember/*` packages and run `npm install`.
12+
13+
```diff title="package.json"
14+
{
15+
"scripts": {
16+
- "contember": "docker-compose run contember-cli",
17+
+ "contember": "docker-compose run --rm contember-cli",
18+
...
19+
},
20+
"devDependencies": {
21+
- "@contember/schema": "1.2.1",
22+
+ "@contember/schema": "1.3.0-rc.1",
23+
- "@contember/schema-definition": "1.2.1",
24+
+ "@contember/schema-definition": "1.3.0-rc.1",
25+
- "@contember/admin": "^1.0.0",
26+
+ "@contember/admin": "^1.2.0-rc.14",
27+
...
28+
- "@types/react": "^17",
29+
+ "@types/react": "^18",
30+
+ "@types/react-dom": "^18",
31+
- "react": "^17",
32+
+ "react": "^18",
33+
- "react-dom": "^17",
34+
+ "react-dom": "^18",
35+
- "typescript": "^4.5",
36+
+ "typescript": "^5.0",
37+
- "vite": "^2.7"
38+
+ "vite": "^4"
39+
}
40+
}
41+
```
42+
43+
## Add support for React 17 JSX transform
44+
45+
Use React 17+ `react-jsx` transform instead of `react` in `tsconfig.json`:
46+
47+
```diff title="tsconfig.json"
48+
{
49+
"compilerOptions": {
50+
...
51+
- "jsx": "react",
52+
+ "jsx": "react-jsx",
53+
...
54+
```
55+
56+
Now you can remove all unnecessary `React` namespace imports from your codebase:
57+
58+
```diff
59+
-import * as React from 'react'
60+
```
61+
62+
## Add support for React 18
63+
64+
```diff title="admin/index.tsx"
65+
@@ -1,6 +1,6 @@
66+
-import * as React from 'react'
67+
-import { ApplicationEntrypoint, Pages, runReactApp } from '@contember/admin'
68+
+import { ApplicationEntrypoint, PageModule, Pages, runReactApp } from '@contember/admin'
69+
-import '@contember/admin/style.css'
70+
+import '@contember/admin/index.css'
71+
+import { createRoot } from 'react-dom/client'
72+
import { Layout } from './components/Layout'
73+
74+
runReactApp(
75+
<ApplicationEntrypoint
76+
basePath={import.meta.env.BASE_URL}
77+
apiBaseUrl={import.meta.env.VITE_CONTEMBER_ADMIN_API_BASE_URL}
78+
sessionToken={import.meta.env.VITE_CONTEMBER_ADMIN_SESSION_TOKEN}
79+
project={import.meta.env.VITE_CONTEMBER_ADMIN_PROJECT_NAME}
80+
stage="live"
81+
+ envVariables={{ WEB_URL: import.meta.env.VITE_CONTEMBER_ADMIN_WEB_URL }}
82+
- children={<Pages layout={Layout} children={import.meta.globEager('./pages/**/*.tsx')} />}
83+
+ children={
84+
+ <Pages
85+
+ layout={Layout}
86+
+ children={import.meta.glob<PageModule>(
87+
+ './pages/**/*.tsx',
88+
+ { eager: true },
89+
+ )}
90+
+ />
91+
+ }
92+
/>,
93+
+ null,
94+
+ (dom, react, onRecoverableError) => createRoot(dom, { onRecoverableError }).render(react),
95+
)
96+
```
97+
98+
## Admin Interface
99+
100+
Remove extra nesting of `Menu.Item` components:
101+
102+
```diff title="admin/components/Navigation.tsx"
103+
-import * as React from 'react'
104+
import { Menu } from '@contember/admin'
105+
+import * as React from 'react'
106+
107+
export const Navigation = () => (
108+
<Menu>
109+
- <Menu.Item>
110+
- <Menu.Item title="Dashboard" to="index" />
111+
- </Menu.Item>
112+
+ <Menu.Item title="Dashboard" to="index" />
113+
</Menu>
114+
)
115+
```
116+
117+
## Add favicon, Apple touch icon and theme color (optional but recommended):
118+
119+
```diff title="admin/index.html"
120+
<head>
121+
<meta charset="utf-8">
122+
<meta name="viewport" content="width=device-width, viewport-fit=cover, initial-scale=1">
123+
+ <link rel="icon" type="image/png" href="./favicon.png">
124+
+ <link rel="apple-touch-icon" href="./apple-touch-icon.png">
125+
<title>Admin quickstart</title>
126+
+ <meta name="theme-color" content="#F2F5F1" media="(prefers-color-scheme: light)">
127+
+ <meta name="theme-color" content="#000000" media="(prefers-color-scheme: dark)">
128+
<script type="module" src="./index.tsx"></script>
129+
</head>
130+
</html>
131+
```

docs/reference/admin/theming/introduction.mdx

+54-83
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
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,
99
ThemePreview,
1010
Scale,
1111
Swatch,
1212
} from "@src/theming"
13-
import LiveCode from "@src/components/liveCode"
1413

1514
With Contember you can change **theme** and **scheme** independently. Contember combine theme for content and controls with light and dark scheme resulting in many flexible combinations. By default, the content is themed with **default** theme and controls in **primary** theme.
1615

@@ -20,16 +19,16 @@ With Contember you can change **theme** and **scheme** independently. Contember
2019
## Color themes
2120

2221
**Contember supports 3 color palettes (themes) to suit your branding needs:**
23-
- <Scale name={THEMES_LIST_BRANDS[0]} direction="horizontal" />
24-
- <Scale name={THEMES_LIST_BRANDS[1]} direction="horizontal" />
25-
- <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>
2625

2726
**Besides the branding color palettes, there are system palettes:**
28-
- <Scale name={THEMES_LIST_SYSTEM[0]} direction="horizontal" />
29-
- <Scale name={THEMES_LIST_SYSTEM[1]} direction="horizontal" />
30-
- <Scale name={THEMES_LIST_SYSTEM[2]} direction="horizontal" />
31-
- <Scale name={THEMES_LIST_SYSTEM[3]} direction="horizontal" />
32-
- <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>
3332

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

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

42+
<StyleProvider>
4343
<Stack direction="horizontal" className="md:flex-wrap">
4444
<ThemePreview heading="Light scheme with default theming" scheme="light" />
4545
<ThemePreview heading="Dark scheme with default theming" scheme="dark" />
4646
<ThemePreview heading="System scheme with default theming" scheme="system" />
4747
</Stack>
48+
</StyleProvider>
4849

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

5152
### Secondary themed controls
5253

54+
<StyleProvider>
5355
<Stack direction="horizontal" className="md:flex-wrap">
5456
<ThemePreview heading="Light scheme with secondary themed primary button on default content theme" scheme="light" themeControls="secondary" />
5557
<ThemePreview heading="Dark scheme with secondary themed primary button on default content theme" scheme="dark" themeControls="secondary" />
5658
<ThemePreview heading="System scheme with secondary themed primary button on default content theme" scheme="system" themeControls="secondary" />
5759
</Stack>
60+
</StyleProvider>
5861

5962
### Examples of combinations
6063

64+
<StyleProvider>
6165
<Stack direction="horizontal" className="md:flex-wrap">
6266
<ThemePreview heading="Light scheme with success theme for content and positive for primary button and content" scheme="light" theme="success" themeControls="positive" />
6367
<ThemePreview heading="Dark scheme with success theme for content and positive for primary button and content" scheme="dark" theme="success" themeControls="positive" />
@@ -71,82 +75,49 @@ To generate class names responsible for changin color theme use `toSchemeClass(c
7175
<ThemePreview heading="Dark scheme with danger themed primary button on primary themed content" scheme="dark" theme="primary" themeControls="danger" controls />
7276
<ThemePreview heading="System scheme with danger themed primary button on primary themed content" scheme="system" theme="primary" themeControls="danger" controls />
7377
</Stack>
74-
75-
## Theming the Layout
76-
77-
With `Layout` component you are already able to set theme and scheme on 3 main parts of your admin application:
78-
79-
1. The whole app, including the side bar with navigation
80-
2. Page content (applied by the `PageLayout` component)
81-
3. Title bar of the page content (applied by the `PageLayout` component)
82-
83-
### Scheme props
84-
85-
Prop | Type | Description
86-
--------------|----------|------------
87-
`scheme` | [`Scheme`](#appendix-available-theme-and-scheme-values) | Sets the scheme of all layout parts
88-
`pageScheme` | [`Scheme`](#appendix-available-theme-and-scheme-values) | Sets the page scheme of the page part of the layout
89-
`titleScheme` | [`Scheme`](#appendix-available-theme-and-scheme-values) | Sets the scheme of the page title
90-
91-
### Theme props
92-
93-
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.
94-
95-
Prop | Type | Lyout content | Layout controls | Page content | Page controls | Page title content | Page title controls |
96-
---------------------|----------|:-------------:|:---------------:|:------------:|:-------------:|:------------------:|:-------------------:|
97-
`theme` | [`Intent`](#appendix-available-theme-and-scheme-values) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅
98-
`themeContent` | [`Intent`](#appendix-available-theme-and-scheme-values) | ✅ | ❌ | ✅ | ❌ | ✅ | ❌
99-
`themeControls` | [`Intent`](#appendix-available-theme-and-scheme-values) | ❌ | ✅ | ❌ | ✅ | ❌ | ✅
100-
`pageTheme` | [`Intent`](#appendix-available-theme-and-scheme-values) | ❌ | ❌ | ✅ | ✅ | ✅ | ✅
101-
`pageThemeContent` | [`Intent`](#appendix-available-theme-and-scheme-values) | ❌ | ❌ | ✅ | ❌ | ✅ | ❌
102-
`pageThemeControls` | [`Intent`](#appendix-available-theme-and-scheme-values) | ❌ | ❌ | ❌ | ✅ | ❌ | ✅
103-
`titleTheme` | [`Intent`](#appendix-available-theme-and-scheme-values) | ❌ | ❌ | ❌ | ❌ | ✅ | ✅
104-
`titleThemeContent` | [`Intent`](#appendix-available-theme-and-scheme-values) | ❌ | ❌ | ❌ | ❌ | ✅ | ❌
105-
`titleThemeControls` | [`Intent`](#appendix-available-theme-and-scheme-values) | ❌ | ❌ | ❌ | ❌ | ❌ | ✅
106-
107-
### Layout code example
108-
109-
<LiveCode
110-
noPreviewPadding
111-
code={`<Layout
112-
sidebarHeader={<a href="#home"><Icon blueprintIcon="home" /> ACME</a>}
113-
navigation={<Menu id="main-navigation">
114-
<Menu.Item>
115-
<Menu.Item title="Foo" href="#" />
116-
<Menu.Item title="Bar" href="#" />
117-
</Menu.Item>
118-
</Menu>}
119-
sidebarFooter={<a href="#logout">Log out</a>}
120-
scheme="dark" // The full layout is in dark mode and ignore the system settings
121-
// pageScheme="system" // Uncomment to allow page section to adapt to system mode
122-
// titleScheme="dark" // Uncomment to set page title in dark mode and ignore the system settings
123-
theme="default" // Both content and controls are colorless...
124-
pageTheme="secondary" // ... however the page theme is in secondary theme...
125-
titleTheme="secondary" // ... and the title theme is secondary too.
126-
// themeContent="tertiary" // Uncomment to override theme prop of the content
127-
// themeControls="secondary" // Uncomment to override theme prop of the control components
128-
// pageThemeContent="success" // turns page contents green
129-
// pageThemeControls="danger" // turns controls red
130-
// titleThemeContent="tertiary" // turns page title contents violet
131-
// titleThemeControls="primary" // // turns page title controls to primary blue
132-
>
133-
<LayoutPage title="Hello world!">
134-
<Box>
135-
<FieldContainer label="Your email">
136-
<TextInput name="email" />
137-
</FieldContainer>
138-
<Spacer />
139-
<Button distinction="primary">Continue</Button>
78+
</StyleProvider>
79+
80+
## Theming interface
81+
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`.
83+
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`.
85+
86+
```tsx
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>
140112
</Box>
141-
</LayoutPage>
142-
</Layout>`}
143-
/>
113+
</ColorSchemeProvider>
114+
)
115+
}
116+
```
144117

145118
## Appendix: Available theme and scheme values
146119

147120
Type | Values
148121
-----|--------
149-
Scheme | `"system"`, `"light"`, `"light-above"`, `"light-below"`, `"dark"`, `"dark-above"` or `"dark-below"`
150-
Intent | `"primary"`, `"secondary"`, `"tertiary"`, `"positive"`, `"success"`, `"warn"` or `"danger"`
151-
152-
_**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
}

docusaurus.config.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
require('dotenv').config()
22
const path = require('path')
33

4+
const prismTheme = require('prism-react-renderer/themes/nightOwl')
5+
46
/** @type {import('@docusaurus/types').Config} */
57
const config = {
68
title: 'Contember',
@@ -21,7 +23,26 @@ const config = {
2123
/** @type {import('@docusaurus/preset-classic').ThemeConfig} */
2224
({
2325
prism: {
24-
theme: require('prism-react-renderer/themes/nightOwl'),
26+
theme: {
27+
...prismTheme,
28+
styles: [
29+
...prismTheme.styles,
30+
{
31+
types: ["deleted"],
32+
style: {
33+
color: "rgb(255, 76, 76)",
34+
fontStyle: "italic",
35+
},
36+
},
37+
{
38+
types: ["inserted"],
39+
style: {
40+
color: "rgb(127, 219, 202)",
41+
fontStyle: "italic",
42+
},
43+
},
44+
]
45+
},
2546
additionalLanguages: ['typescript', 'json5'],
2647
},
2748
docs: {

0 commit comments

Comments
 (0)