From 422834e6d2fb6b3d4d8a674de07398e99cee3b81 Mon Sep 17 00:00:00 2001 From: Nathan Vasse Date: Tue, 26 Sep 2023 11:42:15 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D(react)=20make=20docs=20theme=20com?= =?UTF-8?q?patible?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some docs were using design tokens and classes that were not theme compliant, rendering ugly colors when switching to dark, it needed to be aligned. Also update some code example to match the new format. --- packages/react/src/docs/colors.mdx | 24 +++++--- packages/react/src/docs/customization.mdx | 68 +++++++++++++-------- packages/react/src/docs/spacings.mdx | 10 +-- packages/react/src/docs/typo.mdx | 74 +++++++++++++---------- 4 files changed, 106 insertions(+), 70 deletions(-) diff --git a/packages/react/src/docs/colors.mdx b/packages/react/src/docs/colors.mdx index dc4ba15..8b336e4 100644 --- a/packages/react/src/docs/colors.mdx +++ b/packages/react/src/docs/colors.mdx @@ -32,7 +32,7 @@ You can find all existing classes below. {tints.map(tint => (
-
bg-{color}-{tint}
+
bg-{color}-{tint}
))} @@ -57,7 +57,7 @@ You can find all existing classes below. {colors.map(color => (
- {['text', ...tints].map(tint => { + {tints.map(tint => { const classes = ['fs-s', 'mt-st', 'clr-' + color + '-' + tint]; if (tint === 'text') { classes.push('bg-' + color + '-500'); @@ -82,7 +82,7 @@ render readable text on top of a -500 background of its own color variation. Ple
I'm a text on top of a primary-500 background 👋
-
I'm a text on top of a secondary-500 background 👋
+
I'm a text on top of a secondary-500 background 👋
I'm a text on top of a danger-500 background 👋
@@ -97,12 +97,16 @@ You can customize the values of the color design tokens with the configuration f code={` // cunningham.ts|cjs export default { - theme: { - colors: { - 'primary-500': 'purple', // You can customize the existing primary-500 color. ( bg-primary-500, clr-primary-500 classes ), - 'primary-text': 'cream', - 'amazing-500': 'pink', // You can add a new color. ( bg-amazing-500, clr-amazing-500 classes will be generated ) - } + themes: { + default: { + theme: { + colors: { + 'primary-500': 'purple', // You can customize the existing primary-500 color. ( bg-primary-500, clr-primary-500 classes ), + 'primary-text': 'cream', + 'amazing-500': 'pink', // You can add a new color. ( bg-amazing-500, clr-amazing-500 classes will be generated ) + }, + }, + }, } `} -/> \ No newline at end of file +/> diff --git a/packages/react/src/docs/customization.mdx b/packages/react/src/docs/customization.mdx index 87cd8f0..a434cea 100644 --- a/packages/react/src/docs/customization.mdx +++ b/packages/react/src/docs/customization.mdx @@ -34,11 +34,15 @@ If you prefer using Typescript, create a file named `cunningham.ts` at the root import { DefaultTokens } from "@openfun/cunningham-react"; const config: DefaultTokens = { - theme: { - colors: { - "primary-500": "purple", + themes: { + default: { + theme: { + colors: { + "primary-500": "purple", + }, }, }, + }, }; export default config; @@ -52,9 +56,13 @@ Or if you prefer Javascript, create a file named `cunningham.cjs` at the root of @@ -93,12 +101,16 @@ For our example we focus on the `border-radius` design token. Now, incorporate t import { DefaultTokens } from "@openfun/cunningham-react"; const config: DefaultTokens = { - theme: { - ... - }, - components: { - button: { - "border-radius": "30px", + themes: { + default: { + theme: { + ... + }, + components: { + button: { + "border-radius": "30px", + }, + }, }, }, }; @@ -129,12 +141,16 @@ let's say we want keep the same border radius when the `Button` component is act import { defaultTokens, DefaultTokens } from "@openfun/cunningham-react"; const config: DefaultTokens = { - theme: { - ... - }, - components: { - button: { - "border-radius--active": defaultTokens.components.button["border-radius"], + themes: { + default: { + theme: { + ... + }, + components: { + button: { + "border-radius--active": defaultTokens.components.button["border-radius"], + }, + }, }, }, }; @@ -152,12 +168,16 @@ You can also use more global design tokens from `defaultTokens.theme`, like that import { defaultTokens, DefaultTokens } from "@openfun/cunningham-react"; const config: DefaultTokens = { - theme: { - ... - }, - components: { - button: { - "medium-font-size": defaultTokens.theme.font.sizes.s, + themes: { + default: { + theme: { + ... + }, + components: { + button: { + "medium-font-size": defaultTokens.theme.font.sizes.s, + }, + }, }, }, }; diff --git a/packages/react/src/docs/spacings.mdx b/packages/react/src/docs/spacings.mdx index 178bba9..4b22c80 100644 --- a/packages/react/src/docs/spacings.mdx +++ b/packages/react/src/docs/spacings.mdx @@ -11,10 +11,10 @@ Here are the existing spacings:
- {Object.keys(tokens.theme.spacings).map(key => ( + {Object.keys(tokens.themes.default.theme.spacings).map(key => (
-{key}
-
{tokens.theme.spacings[key]}
+
{tokens.themes.default.theme.spacings[key]}
))} @@ -51,8 +51,8 @@ You can use the following classes to add paddings to your elements: ## Example -
-
Tiny padding + Large margin bottom
-
Large padding + Base margin left
+
+
Tiny padding + Large margin bottom
+
Large padding + Base margin left
diff --git a/packages/react/src/docs/typo.mdx b/packages/react/src/docs/typo.mdx index 5eee95c..0d98ba6 100644 --- a/packages/react/src/docs/typo.mdx +++ b/packages/react/src/docs/typo.mdx @@ -22,8 +22,8 @@ You can use custom utility classes to set the font size of an element. These cla
- {Object.keys(tokens.theme.font.sizes).map(key => ( -
Using the fs-{key} class
+ {Object.keys(tokens.themes.default.theme.font.sizes).map(key => ( +
Using the fs-{key} class
))}
@@ -37,15 +37,19 @@ You can customize the values of the font size design tokens with the configurati code={` // cunningham.ts|cjs export default { - theme: { - typo: { - sizes: { - m: '0.5rem', // You can customize the size of the existing medium text ( 'fs-m' class ) - xxl: '3rem' // You can also add custom sizes yourself ( 'fs-xxl' class will be generated ) - ... + themes: { + default: { + theme: { + typo: { + sizes: { + m: '0.5rem', // You can customize the size of the existing medium text ( 'fs-m' class ) + xxl: '3rem' // You can also add custom sizes yourself ( 'fs-xxl' class will be generated ) + ... + }, + }, }, - } - } + }, + }, } `} /> @@ -65,8 +69,8 @@ You can use custom utility classes to set the font weight of an element. These c
- {Object.keys(tokens.theme.font.weights).map(key => ( -
Using the fw-{key} class
+ {Object.keys(tokens.themes.default.theme.font.weights).map(key => ( +
Using the fw-{key} class
))}
@@ -80,14 +84,18 @@ You can customize the values of the font weight design tokens with the configura code={` // cunningham.ts|cjs export default { - theme: { - typo: { - weights: { - regular: 500, // You can customize the size of the existing regular text ( 'fw-regular' class ) - chunky: 900 // You can also add custom weights yourself ( 'fw-chunky' class will be generated ) - ... + themes: { + default: { + theme: { + typo: { + weights: { + regular: 500, // You can customize the size of the existing regular text ( 'fw-regular' class ) + chunky: 900 // You can also add custom weights yourself ( 'fw-chunky' class will be generated ) + ... + }, + }, }, - } + }, } } `} @@ -106,14 +114,14 @@ class on every dom element. dark format={false} code={` -
Accent text
+
Accent text
`} />
- {Object.keys(tokens.theme.font.families).map(key => ( -
Using the f-{key} class
+ {Object.keys(tokens.themes.default.theme.font.families).map(key => ( +
Using the f-{key} class
))}
@@ -127,15 +135,19 @@ You can customize the values of the font family design tokens with the configura code={` // cunningham.ts|cjs export default { - theme: { - typo: { - families: { - base: 'Inter', // You can customize the font family of the existing base variation ( 'f-base' class ) - legend: 'Arial' // You can also add custom font families yourself ( 'f-legend' class will be generated ) - ... + themes: { + default: { + theme: { + typo: { + families: { + base: 'Inter', // You can customize the font family of the existing base variation ( 'f-base' class ) + legend: 'Arial' // You can also add custom font families yourself ( 'f-legend' class will be generated ) + ... + }, + }, }, - } - } + }, + }, } `} -/> \ No newline at end of file +/>