diff --git a/packages/lsd-react/src/components/Badge/Badge.classes.ts b/packages/lsd-react/src/components/Badge/Badge.classes.ts new file mode 100644 index 0000000..84fc2ff --- /dev/null +++ b/packages/lsd-react/src/components/Badge/Badge.classes.ts @@ -0,0 +1,10 @@ +export const badgeClasses = { + root: `lsd-badge`, + + outlined: `lsd-badge--outlined`, + filled: `lsd-badge--filled`, + disabled: 'lsd-badge--disabled', + + small: 'lsd-badge--small', + large: 'lsd-badge--large', +} diff --git a/packages/lsd-react/src/components/Badge/Badge.stories.tsx b/packages/lsd-react/src/components/Badge/Badge.stories.tsx new file mode 100644 index 0000000..f8fdd92 --- /dev/null +++ b/packages/lsd-react/src/components/Badge/Badge.stories.tsx @@ -0,0 +1,47 @@ +import { Meta, Story } from '@storybook/react' +import { FolderIcon } from '../Icons' +import { Badge, BadgeProps } from './Badge' + +export default { + title: 'Badge', + component: Badge, + argTypes: { + variant: { + type: { + name: 'enum', + value: ['outlined', 'filled'], + }, + }, + size: { + type: { + name: 'enum', + value: ['large', 'small'], + }, + defaultValue: 'large', + }, + iconDirection: { + type: { + name: 'enum', + value: ['left', 'right', 'none'], + }, + }, + disabled: { + type: { + name: 'boolean', + value: [true, false], + }, + }, + }, +} as Meta + +export const Root: Story = (args) => ( + } /> +) + +Root.args = { + variant: 'outlined', + label: 'Badge', + iconDirection: 'left', + disabled: false, + size: 'large', +} diff --git a/packages/lsd-react/src/components/Badge/Badge.styles.ts b/packages/lsd-react/src/components/Badge/Badge.styles.ts new file mode 100644 index 0000000..a6b389b --- /dev/null +++ b/packages/lsd-react/src/components/Badge/Badge.styles.ts @@ -0,0 +1,52 @@ +import { css } from '@emotion/react' +import { badgeClasses } from './Badge.classes' + +export const BadgeStyles = css` + .${badgeClasses.root} { + width: fit-content; + + display: flex; + flex-direction: row; + align-items: center; + justify-content: center; + + border: 1px solid rgb(var(--lsd-icon-primary)); + border-radius: 20px; + + &:hover, + &:focus { + text-decoration: underline; + cursor: pointer; + } + } + + .${badgeClasses.large} { + padding: 4px 12px; + gap: 12px; + height: 28px; + } + + .${badgeClasses.small} { + padding: 4px 8px; + gap: 8px; + height: 24px; + } + + .${badgeClasses.filled} { + background-color: rgb(var(--lsd-icon-primary)); + color: rgb(var(--lsd-text-secondary)); + svg { + --lsd-icon-primary: var(--lsd-icon-secondary); + } + } + + .${badgeClasses.outlined} { + color: rgb(var(--lsd-text-primary)); + } + + .${badgeClasses.disabled} { + opacity: 0.3; + cursor: initial; + pointer-events: none; + } +` diff --git a/packages/lsd-react/src/components/Badge/Badge.tsx b/packages/lsd-react/src/components/Badge/Badge.tsx new file mode 100644 index 0000000..4000178 --- /dev/null +++ b/packages/lsd-react/src/components/Badge/Badge.tsx @@ -0,0 +1,57 @@ +import clsx from 'clsx' +import React from 'react' +import { Typography } from '../Typography' +import { badgeClasses } from './Badge.classes' + +export type BadgeProps = React.HTMLAttributes & { + variant?: 'outlined' | 'filled' + label: string + icon?: React.ReactNode + iconDirection?: 'left' | 'right' + size?: 'large' | 'small' + disabled?: boolean +} + +export const Badge: React.FC & { + classes: typeof badgeClasses +} = ({ + label, + variant = 'outlined', + disabled = 'false', + size = 'large', + icon, + iconDirection = 'left', + children, + ...props +}) => { + const renderItems = () => ( + <> + {iconDirection === 'left' && icon} + + {label} + + {iconDirection === 'right' && icon} + + ) + + return ( +
+ {renderItems()} +
+ ) +} + +Badge.classes = badgeClasses diff --git a/packages/lsd-react/src/components/Badge/index.ts b/packages/lsd-react/src/components/Badge/index.ts new file mode 100644 index 0000000..b9eff9e --- /dev/null +++ b/packages/lsd-react/src/components/Badge/index.ts @@ -0,0 +1 @@ +export * from './Badge' diff --git a/packages/lsd-react/src/components/CSSBaseline/CSSBaseline.tsx b/packages/lsd-react/src/components/CSSBaseline/CSSBaseline.tsx index 25e3b10..7fbc483 100644 --- a/packages/lsd-react/src/components/CSSBaseline/CSSBaseline.tsx +++ b/packages/lsd-react/src/components/CSSBaseline/CSSBaseline.tsx @@ -1,6 +1,7 @@ import { Global, SerializedStyles } from '@emotion/react' import React, { useMemo } from 'react' import { AutocompleteStyles } from '../Autocomplete/Autocomplete.styles' +import { BadgeStyles } from '../Badge/Badge.styles' import { BreadcrumbStyles } from '../Breadcrumb/Breadcrumb.styles' import { BreadcrumbItemStyles } from '../BreadcrumbItem/BreadcrumbItem.styles' import { ButtonStyles } from '../Button/Button.styles' @@ -48,6 +49,7 @@ const componentStyles: Array | SerializedStyles> = CollapseStyles, CollapseHeaderStyles, CheckboxGroupStyles, + BadgeStyles, ] export const CSSBaseline: React.FC<{ theme?: Theme }> = ({ diff --git a/packages/lsd-react/src/index.ts b/packages/lsd-react/src/index.ts index cc15bfb..a7dda93 100644 --- a/packages/lsd-react/src/index.ts +++ b/packages/lsd-react/src/index.ts @@ -20,3 +20,4 @@ export * from './components/Tag' export * from './components/Theme' export * from './components/Checkbox' export * from './components/CheckboxGroup' +export * from './components/Badge'