diff --git a/docs/theming/themes.md b/docs/theming/themes.md index 79408c5fa96..6d15b3b6872 100644 --- a/docs/theming/themes.md +++ b/docs/theming/themes.md @@ -58,10 +58,12 @@ While updating the background (`--ion-background-color`) and text (`--ion-text-c In some components we use a shade darker than the background or lighter than the text. For example, an item heading text may need to be #404040, which is a few shades lighter than our default text color. Meanwhile, the loading component background is a shade darker than white, using #f2f2f2. We use stepped colors in order to define these slight variations. It is important to update the stepped colors when updating the background or text color of an application. -By default, the Ionic stepped colors start at the default background color value #ffffff and mix with the text color value #000000 using an increasing percentage. The full list of stepped colors is shown in the generator below. +Ionic provides separate step colors for text and background colors so they can be updated separately. This is useful for components that use both text and background stepped colors and allows us to effectively implement the [high contrast theme](./high-contrast-mode). + +By default, the Ionic text stepped colors start at the default text color value #000000 and mix with the background color value #ffffff using an increasing percentage. The Ionic background stepped colors start at the default background color value #ffffff and mix with the text color value #000000 using an increasing percentage. The full list of stepped colors is shown in the generator below. ## Stepped Color Generator Create a custom background and text color theme for your app. Update the background or text color’s hex values below, then copy and paste the generated code directly into your Ionic project. - + diff --git a/src/components/page/theming/SteppedColorGenerator/index.tsx b/src/components/page/theming/SteppedColorGenerator/index.tsx index 35afde9a09f..226b6dfe51c 100755 --- a/src/components/page/theming/SteppedColorGenerator/index.tsx +++ b/src/components/page/theming/SteppedColorGenerator/index.tsx @@ -16,10 +16,14 @@ export default function ColorGenerator(props) { const [backgroundColor, setBackgroundColor] = useState('#ffffff'); const [textColor, setTextColor] = useState('#000000'); - const [steppedColors, setSteppedColors] = useState(generateSteppedColors(backgroundColor, textColor)); + const [textSteppedColors, setTextSteppedColors] = useState(generateSteppedColors(textColor, backgroundColor)); + const [backgroundSteppedColors, setBackgroundSteppedColors] = useState( + generateSteppedColors(backgroundColor, textColor) + ); useEffect(() => { - setSteppedColors(generateSteppedColors(backgroundColor, textColor)); + setTextSteppedColors(generateSteppedColors(textColor, backgroundColor)); + setBackgroundSteppedColors(generateSteppedColors(backgroundColor, textColor)); }, [backgroundColor, textColor]); return ( @@ -43,11 +47,15 @@ export default function ColorGenerator(props) { {'\t'}--ion-text-color: {textColor};{'\n'} {'\t'}--ion-text-color-rgb: {new Color(textColor).toList()};{'\n'} {'\n'} - {steppedColors.map((color, i) => ( - <> - {'\t'}--ion-color-step-{(i + 1) * 50}: {color};{'\n'} - - ))} + {/* + Ionic v8+ uses separate step colors for text and background. + We use a single component here for all versions of the docs, so newer + versions of the docs opt-in to showing separate step colors + using the useTextAndBackgroundStepColors property. + */} + {props.useTextAndBackgroundStepColors && + renderSeparateTextAndBackgroundColors(textSteppedColors, backgroundSteppedColors)} + {!props.useTextAndBackgroundStepColors && renderCombinedColors(backgroundSteppedColors)} {'}'} {'\n'} @@ -55,3 +63,37 @@ export default function ColorGenerator(props) { ); } + +/** + * Render `--ion-text-color-step-*` and `--ion-background-color-step-*` tokens. + * Use this for Ionic v8+ documentation. + */ +const renderSeparateTextAndBackgroundColors = (textSteppedColors: string[], backgroundSteppedColors: string[]) => { + return [ + textSteppedColors.map((color, i) => ( + <> + {'\t'}--ion-text-color-step-{(i + 1) * 50}: {color};{'\n'} + + )), + '\n', + backgroundSteppedColors.map((color, i) => ( + <> + {'\t'}--ion-background-color-step-{(i + 1) * 50}: {color};{'\n'} + + )), + ]; +}; + +/** + * Render `--ion-color-step-*` tokens. + * Use this for Ionic v4-v7 documentation. + */ +const renderCombinedColors = (steppedColors: string[]) => { + return [ + steppedColors.map((color, i) => ( + <> + {'\t'}--ion-color-step-{(i + 1) * 50}: {color};{'\n'} + + )), + ]; +};