Theme Blocks
Theme blocks are a collection of components designed to display the various elements of your theme within Storybook. These components offer a visual representation of your design system, including typography, colors, spacing, borders, shadows, palette variations, and more. By incorporating these blocks into your Storybook, you can easily document and showcase your theme's design tokens.
Available Theme Block Components
- Typography Block: Demonstrates the font families, sizes, and weights available in your theme.
- Color Block: Displays the color palette defined in your theme, including primary, secondary, and any other custom colors.
- Spacing Block: Visualizes the spacing scale used in your theme, helpful for understanding and using consistent spacing throughout your UI.
- Border Block: Shows the available border radius options, aiding in the application of consistent border styles.
- Shadow Block: Exhibits the shadow options defined in your theme, making it easy to apply consistent shadow effects.
- Components Block: A comprehensive showcase of the styled components within your theme, including buttons, inputs, and more.
- Icons Block: Displays the icons used in your theme. NOTE that icons are not included and must be supplied.
Implementing Theme Blocks in a Storybook Story
Below is an example that demonstrates how to use the theme block components in a Storybook story.
import React from 'react';
import {
TypographyBlocks,
ColorBlocks,
SpacingBlocks,
BorderBlocks,
ShadowBlocks,
ThemeProvider,
theme,
useTheme,
extractTheme
} from 'reablocks';
import resolveConfig from 'tailwindcss/resolveConfig';
import tailwindConfig from '[PATH TO YOUR TW CONFIG]/tailwind.config';
const { theme: TWConfig } = resolveConfig(tailwindConfig);
export default {
title: 'General/Theme',
component: ThemeProvider,
decorators: [
Story => (
<ThemeProvider theme={theme}>
<div style={{ width: '90vw' }}>
<Story />
</div>
</ThemeProvider>
)
]
};
const {
colors,
borderRadius,
boxShadow,
spacing,
fontFamily,
fontSize,
fontWeight
} = extractTheme(TWConfig);
export const Colors = () => <ColorBlocks colors={colors} />;
export const Typography = () => (
<TypographyBlocks
families={fontFamily}
sizes={fontSize}
weights={fontWeight}
/>
);
export const Spacings = () => <SpacingBlocks spacings={spacing} />;
export const Borders = () => <BorderBlocks borders={borderRadius} />;
export const Shadows = () => <ShadowBlocks shadows={boxShadow} />;
export const Components = () => {
const { theme } = useTheme();
return <ComponentBlocks components={theme.components} />;
};
NOTE: This example utilizes the ThemeProvider
in the story decorator, allowing each story
to inherit the dark theme context. Alternatively, you could use ThemeProvider
in your
.storybook/preview.js
file to apply the theme globally to all stories.
You can see how it looks in the Storybook here (opens in a new tab).
Examples
Color
black
white
slate
gray
zinc
neutral
stone
red
orange
amber
yellow
lime
green
emerald
teal
cyan
sky
blue
indigo
violet
purple
fuchsia
pink
rose
primary
secondary
content
Typography
Typography
Font Families
font-sans
ui-sans-serifsystem-uisans-serif"Apple Color Emoji""Segoe UI Emoji""Segoe UI Symbol""Noto Color Emoji"
font-xs
0.75rem
font-sm
0.75rem
font-base
0.875rem
font-lg
1rem
font-xl
1.25rem
font-2xl
1.5rem
font-3xl
1.875rem
font-4xl
2.25rem
font-5xl
3rem
font-6xl
3.75rem
font-7xl
4.5rem
font-8xl
6rem
font-9xl
8rem
font-serif
ui-serifGeorgiaCambria"Times New Roman"Timesserif
font-xs
0.75rem
font-sm
0.75rem
font-base
0.875rem
font-lg
1rem
font-xl
1.25rem
font-2xl
1.5rem
font-3xl
1.875rem
font-4xl
2.25rem
font-5xl
3rem
font-6xl
3.75rem
font-7xl
4.5rem
font-8xl
6rem
font-9xl
8rem
font-mono
ui-monospaceSFMono-RegularMenloMonacoConsolas"Liberation Mono""Courier New"monospace
font-xs
0.75rem
font-sm
0.75rem
font-base
0.875rem
font-lg
1rem
font-xl
1.25rem
font-2xl
1.5rem
font-3xl
1.875rem
font-4xl
2.25rem
font-5xl
3rem
font-6xl
3.75rem
font-7xl
4.5rem
font-8xl
6rem
font-9xl
8rem
Font Weights
font-thin
100
font-extralight
200
font-light
300
font-normal
400
font-medium
500
font-semibold
600
font-bold
700
font-extrabold
800
font-black
900