Merge pull request 'create badge component' (#45) from Create-Badge-component into develop

Reviewed-on: http://85.143.176.51:3000/free-land/front-end/pulls/45
This commit is contained in:
Denis Gorbunov 2022-08-05 13:24:58 +00:00
commit 389ed0511d
2 changed files with 81 additions and 0 deletions

View File

@ -0,0 +1,30 @@
import React, { Children } from "react";
import { ComponentStory, ComponentMeta } from '@storybook/react';
import Badge from "./Badge";
export default{
title: 'Badge',
component: Badge,
} as ComponentMeta<typeof Badge>;
const Template: ComponentStory<typeof Badge> = (args) => <Badge {...args} />;
export const High = Template.bind({});
High.args = {
emphasis: 'high',
children: ['Tom Cook'],
};
export const Medium = Template.bind({});
Medium.args = {
emphasis: 'medium',
children: ['Tanya Fox'],
};
export const Low = Template.bind({});
Low.args = {
emphasis:'low',
children:['Hellen Schmidt'],
};

51
src/components/Badge.tsx Normal file
View File

@ -0,0 +1,51 @@
/* -------------------------------------------------------------------------- */
/* Imports */
/* -------------------------------------------------------------------------- */
import classNames from "classnames";
import { StyleType } from "core/_variants";
import React from "react";
/* -------------------------------------------------------------------------- */
/* Component props */
/* -------------------------------------------------------------------------- */
type Props = {
emphasis?: StyleType;
children: React.ReactNode;
className?: string;
iconed?: boolean;
onClick?: () => void;
} & Omit<React.MouseEventHandler<HTMLSpanElement>, "">;
/* -------------------------------------------------------------------------- */
/* Component implementation */
/* -------------------------------------------------------------------------- */
function Badge({
className,
children,
onClick,
emphasis = "low",
...props
}: Props): JSX.Element {
return (
<span
onClick={onClick}
className={classNames(
"border p-2 rounded-sm text-xs text-center",
{
"cursor-pointer": onClick,
"border-transparent": emphasis == "low",
"bg-blue-400 text-white": emphasis == "high",
"border-gray-400 background-gray-200": emphasis == "medium",
},
className
)}
{...props}
>
{children}
</span>
);
}
export default Badge;