Skip to content

Commit

Permalink
NA- Added tag component
Browse files Browse the repository at this point in the history
  • Loading branch information
nagarajnetcentric committed Jan 30, 2024
1 parent 68eb203 commit 8165dbc
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 0 deletions.
50 changes: 50 additions & 0 deletions apps/frontend/src/stories/Tag.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import type { Meta, StoryObj } from '@storybook/react';

import { Tag } from './Tag';

// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
const meta = {
title: 'Example/Tag',
component: Tag,
parameters: {
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
layout: 'centered',
},
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
tags: ['autodocs'],
// More on argTypes: https://storybook.js.org/docs/api/argtypes
argTypes: {
backgroundColor: { control: 'color' },
},
} satisfies Meta<typeof Tag>;

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

// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
export const Selected: Story = {
args: {
selected: true,
label: 'This is a selected tag',
},
};

export const Unselected: Story = {
args: {
label: 'This tag is not selected',
},
};

export const Large: Story = {
args: {
size: 'large',
label: 'Simple large tag',
},
};

export const Small: Story = {
args: {
size: 'small',
label: 'Small tag',
},
};
47 changes: 47 additions & 0 deletions apps/frontend/src/stories/Tag.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from 'react';
import './tag.css';

interface TagProps {
/**
* Is this the principal call to action on the page?
*/
selected?: boolean;
/**
* What background color to use
*/
backgroundColor?: string;
/**
* How large should the button be?
*/
size?: 'small' | 'medium' | 'large';
/**
* Button contents
*/
label: string;
/**
* Optional click handler
*/
onClick?: () => void;
}

/**
* Primary UI component for user interaction
*/
export const Tag = ({
selected = false,
size = 'medium',
backgroundColor,
label,
...props
}: TagProps) => {
const mode = selected ? 'storybook-tag--selected' : 'storybook-tag-unselected';
return (
<div
className={['storybook-tag', `storybook-tag--${size}`, mode].join(' ')}
style={{ backgroundColor }}
{...props}
>
{label}
</div>
);
};
32 changes: 32 additions & 0 deletions apps/frontend/src/stories/tag.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.storybook-tag {
font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-weight: 700;
border: 0;
border-radius: 3em;
cursor: pointer;
display: inline-block;
line-height: 1;
}
.storybook-tag-unselected {
color: #000048;
background-color: white;
border: 1px solid #000048;;
}
.storybook-tag-unselected:hover,
.storybook-tag--selected {
color: white;
background-color: #000048;;
border: 1px solid white;
}
.storybook-tag--small {
font-size: 12px;
padding: 10px 16px;
}
.storybook-tag--medium {
font-size: 14px;
padding: 11px 20px;
}
.storybook-tag--large {
font-size: 16px;
padding: 12px 24px;
}

0 comments on commit 8165dbc

Please sign in to comment.