Skip to content

Commit

Permalink
docs: add button stories
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyPorthouse committed Oct 31, 2024
1 parent 534d799 commit 2c4ddec
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ initialize();
const preview: Preview = {
loaders: [mswLoader],

tags: ["autodocs"],

parameters: {
controls: {
matchers: {
Expand Down
32 changes: 32 additions & 0 deletions src/Components/Button.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { GlobeEuropeAfricaIcon } from "@heroicons/react/24/solid";
import { Meta, StoryObj } from "@storybook/react";
import { fn } from "@storybook/test";

import Button from "./Button";

const meta: Meta<typeof Button> = {
title: "Components/Button",
component: Button,

parameters: {
layout: "centered",
},

args: {
children: <span className="flex-grow">My Button</span>,
className: "!w-64",
onClick: fn(),
},
};

export default meta;

type Story = StoryObj<typeof meta>;

export const BasicButton: Story = {};

export const ButtonWithIcon: Story = {
args: {
renderIcon: () => <GlobeEuropeAfricaIcon className="w-6" />,
},
};
5 changes: 3 additions & 2 deletions src/Components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ import classNames from "classnames";
import { ButtonHTMLAttributes, PropsWithChildren, ReactElement } from "react";

interface Props extends ButtonHTMLAttributes<HTMLButtonElement> {
renderIcon?: () => ReactElement;
/** A function that returns a React component to use as an icon */
readonly renderIcon?: () => ReactElement;
}

function Button({
children,
className,
renderIcon,
...props
}: Readonly<PropsWithChildren<Props>>) {
}: PropsWithChildren<Props>) {
return (
<button className={classNames(`group relative focus:ring-0`)} {...props}>
<div
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Duration.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Temporal } from "temporal-polyfill";

interface DurationProps {
time: number;
readonly time: number;
}

function to2Digits(number: number) {
return String(number).padStart(2, "0");
}

function Duration({ time }: Readonly<DurationProps>) {
function Duration({ time }: DurationProps) {
if (isNaN(time)) {
time = 0;
}
Expand Down

0 comments on commit 2c4ddec

Please sign in to comment.