/** * Copyright (c) Paymium. * * This source code is licensed under the MIT license found in the * LICENSE file in the root of this projects source tree. */ import { ComponentProps, memo } from 'react'; import { Text } from '../typography/Text'; import { Box } from '../layout/Box'; import { composeStyles, createStyles } from '@crossed/styled'; import { createScope, withStaticProperties } from '@crossed/core'; const badgeStyles = createStyles(({ space, colors }) => ({ default: { base: { paddingLeft: space.md, paddingRight: space.md, paddingTop: space.md, paddingBottom: space.md, marginTop: 0, borderRadius: 4, backgroundColor: colors.background.primary, }, }, success: { base: { backgroundColor: colors.success.light } }, warning: { base: { backgroundColor: colors.warning.light } }, error: { base: { backgroundColor: colors.error.low } }, info: { base: { backgroundColor: colors.info.light } }, })); const badgeTextStyles = createStyles(({ colors }) => ({ success: { base: { color: colors.success.primary } }, warning: { base: { color: colors.warning.primary } }, error: { base: { color: colors.error.primary } }, info: { base: { color: colors.info.primary } }, })); type Variants = Exclude; type BadgeProps = ComponentProps & { variant?: Variants }; const [Provider, useContext] = createScope<{ variant?: Variants }>({}); const BadgeText = memo>(({ style, ...props }) => { const { variant } = useContext(); return ( ); }); const BadgeRoot = memo(({ children, style, variant, ...props }) => { return ( {children} ); }); export const Badge = withStaticProperties(BadgeRoot, { Text: BadgeText });