Skip to content

Commit

Permalink
docs: add documentation for ColorMode component
Browse files Browse the repository at this point in the history
  • Loading branch information
Phillip Barkmann committed Aug 18, 2023
1 parent 0c1e511 commit 5df8900
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
7 changes: 2 additions & 5 deletions src/components/ColorMode/ColorMode.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import React from 'react';
import { getSemanticValue } from '../../utils/cssVariables';

export const ColorMode = ({ dark, children }: { dark: boolean; children: React.ReactNode }) => (
<div className={dark ? 'dark-theme' : 'light-theme'}>
<div style={{ backgroundColor: getSemanticValue('background-page') }}>{children}</div>
</div>
export const ColorMode = ({ dark = true, children }: { dark?: boolean; children: React.ReactNode }) => (
<div className={dark ? 'dark-theme' : 'light-theme'}>{children}</div>
);
9 changes: 8 additions & 1 deletion src/components/ColorMode/docs/ColorMode.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ export default meta;

type Story = StoryObj<typeof ColorMode>;

export const WithButton: Story = {
export const DarkModeWithButton: Story = {
args: {
children: <Button>Test</Button>,
dark: true
}
};

export const LightModeWithButton: Story = {
args: {
children: <Button>Test</Button>,
dark: false
Expand Down
29 changes: 26 additions & 3 deletions src/components/ColorMode/docs/ColorMode.storybook.mdx
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
import { Meta, Primary, ArgTypes, Story, Stories, Source } from '@storybook/blocks';
import { StyledSystemLinks } from '../../../docs/StyledSystemLinks';
import { Meta, Primary, ArgTypes, Story, Stories, Source, Unstyled } from '@storybook/blocks';
import { ItemWrapper } from '../../../../docs/components/ItemWrapper';
import { Headline } from '../../Headline/Headline';
import * as ColorModeStories from './ColorMode.stories';

<Meta of={ColorModeStories} />

# ColorMode

This renders a `div` tag with a specific classname based on what boolean value is provided as the dark prop value.

The purpose is to be able to force a specific color theme to components that are children of this component.
As an example you could force the previous `<Button inverted />` behaviour with light button colors,
by wrapping your button inside `<ColorMode dark><Button /></ColorMode>` if you are sure it is always displayed on a darker background,
even if the users preferred color scheme specified in the operating system is light mode.

## Properties

<ArgTypes of={ColorModeStories} />

<Stories />
<Unstyled>
<ItemWrapper>
<Headline as="h3" inverted>
Light Mode with Button
</Headline>
<Story of={ColorModeStories.LightModeWithButton} />
<Source of={ColorModeStories.LightModeWithButton} />
</ItemWrapper>
<ItemWrapper inverted>
<Headline as="h3">Dark Mode with Button</Headline>
<Story of={ColorModeStories.DarkModeWithButton} />
<Source of={ColorModeStories.DarkModeWithButton} />
</ItemWrapper>
</Unstyled>

0 comments on commit 5df8900

Please sign in to comment.