Steve Kinney

Building Design Systems with Storybook

Implementing a Callout Component

Okay, it’s your turn to try this out. Consider this Callout component. Consider the following. You can choose to ignore the fact that they have different icons if you’d like.

Callout component designs

Colors

The callout makes use of the following colors from our theme.

NameLightDark
Callout / Primary
BackgroundPrimary/200Primary/800
BorderPrimary/500Primary/900
TextPrimary/900Primary/50
Callout / Information
BackgroundInformation/200Information/800
BorderInformation/500Information/500
TextInformation/900Information/50
Callout / Success
BackgroundSuccess/200Success/800
BorderSuccess/500Success/900
TextSuccess/900Success/50
Callout / Warning
BackgroundWarning/200Warning/800
BorderWarning/500Warning/900
TextWarning/900Warning/50
Callout / Danger
BackgroundDanger/200Danger/800
BorderDanger/500Danger/900
TextDanger/900Danger/50
Callout / Default
BackgroundSlate/200Slate/800
BorderSlate/500Slate/900
TextSlate/900Slate/50

Other Tasting Notes

  • The fonts are the base font, but the title of the callout is semibold.
  • The corners are rounded using Tailwind rounded class.

Some Starter Code

Here is some code to get your started if that’s helpful. Let’s start with the component.

import type { PropsWithChildren } from 'react';
import { cva, type VariantProps } from 'class-variance-authority';

type CalloutProps = PropsWithChildren<{ title: string }> & VariantProps<typeof variants>;

const variants = cva(['p-4', 'rounded', 'border', 'shadow-md', 'space-y-4']);

export const Callout = ({ title, children }: CalloutProps) => (
	<div className={variants({})}>
		<h2 className="font-semibold">{title}</h2>
		<p>{children}</p>
	</div>
);

And now for the story (ideally in src/components/callout/callout.stores.tsx):

import type { Meta, StoryObj } from '@storybook/react';
import { Callout } from './callout';

const meta = {
	title: 'Components/Callout',
	component: Callout,
	args: {
		title: 'An Important Message',
		children: 'This is a message that you should read.',
	},
} satisfies Meta<typeof Callout>;

export default meta;
type Story = StoryObj<typeof Callout>;

export const Default: Story = {};
Solution

Once you’ve gotten a chance to implement this component and write a story, we’ll take a look at a possible solution here.

Last modified on .