Skip to content

Commit

Permalink
Merge pull request #16 from Netcentric/feature/na-add-component-tag
Browse files Browse the repository at this point in the history
NA - Added tag component
  • Loading branch information
nagarajnetcentric authored Feb 1, 2024
2 parents 6bb4f12 + 5ce9363 commit 39bebf2
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
3 changes: 3 additions & 0 deletions apps/frontend/src/assets/icons/cross.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions apps/frontend/src/components/Tag/Tag.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { Meta, StoryObj } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import { Tag } from './Tag';

const meta = {
title: 'Tag',
component: Tag,
parameters: {
layout: 'centered',
},
tags: ['autodocs'],
} satisfies Meta<typeof Tag>;

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

export const Default: Story = {
args: {
label: 'intersteller collaboration',
isSelected: false
},
};

export const Selected: Story = {
args: {
label: 'scientific research',
isSelected: true,
onClick: action('on-click'),
},
};
30 changes: 30 additions & 0 deletions apps/frontend/src/components/Tag/Tag.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react';
import cross from '../../assets/icons/cross.svg';
import clsx from 'clsx';

interface TagProps {
label: string;
isSelected?: boolean;
onClick: () => void;
}

export const Tag = ({ label, isSelected, onClick }: TagProps) => {
const [selected, setSelected] = React.useState<boolean>(isSelected || false);

const commonClasses = 'rounded-full font-gellix font-semibold text-xl leading-5 px-7 py-3.5 border ';

const handleClick = ()=> {
setSelected(selected => !selected);
onClick();
}

return (
<button className={clsx(commonClasses,{
'flex bg-midnight-blue text-white': selected === true,
'text-midnight-blue border-midnight-blue hover:bg-midnight-blue hover:text-white': selected === false
})} onClick={handleClick}>
{label}
{selected && <img className='pl-5 pt-1' src={cross} alt="cancel" />}
</button>
);
};

0 comments on commit 39bebf2

Please sign in to comment.