Skip to content

feat: label component #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { Preview } from '@storybook/nextjs-vite'

import "../src/app/globals.css";

const preview: Preview = {
parameters: {
controls: {
Expand Down
43 changes: 43 additions & 0 deletions src/components/label_component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import type { ReactNode } from "react";

interface ILabelProps {
children: ReactNode;
disabled?: boolean;
htmlFor?: string;
size?: 'small' | 'medium' | 'large';
onClick?: () => void;
}

const Label = ({
children,
disabled = false,
htmlFor,
size = 'medium',
onClick,
}: ILabelProps) => {
const getSizeClasses = () => {
switch (size) {
case 'small':
return 'text-xs';
case 'large':
return 'text-base';
default:
return 'text-sm';
}
};

const colorClass = disabled ? 'text-gray-400' : 'text-gray-700';
const cursorClass = disabled ? 'cursor-not-allowed' : 'cursor-pointer';

return (
<label
htmlFor={htmlFor}
onClick={disabled ? undefined : onClick}
className={`${getSizeClasses()} ${colorClass} ${cursorClass}`}
>
{children}
</label>
);
};

export default Label;
52 changes: 52 additions & 0 deletions src/stories/Label.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import type { Meta, StoryObj } from '@storybook/nextjs-vite';

import { fn } from 'storybook/test';

import Label from '../components/label_component';

const meta = {
title: 'Components/Label',
component: Label,
parameters: {
layout: 'centered',
},
tags: ['autodocs'],
argTypes: {
disabled: { control: 'boolean' },
size: {
control: { type: 'select' },
options: ['small', 'medium', 'large'],
},
},
args: { onClick: fn() },
} satisfies Meta<typeof Label>;

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

export const Enabled: Story = {
args: {
children: 'Label',
},
};

export const Disabled: Story = {
args: {
children: 'Label',
disabled: true,
},
};

export const Large: Story = {
args: {
size: 'large',
children: 'Label',
},
};

export const Small: Story = {
args: {
size: 'small',
children: 'Label',
},
};