-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ec4b56e
commit 945c5a7
Showing
10 changed files
with
199 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,171 @@ | ||
import { clsx } from 'clsx' | ||
import { ElementType, forwardRef } from 'react' | ||
|
||
import { | ||
Box, | ||
PolymorphicComponent, | ||
PolymorphicProps, | ||
PolymorphicRef, | ||
} from '~/components/Box' | ||
|
||
import * as styles from './styles.css' | ||
|
||
type TextProps = styles.TextVariants | ||
|
||
export const Text: PolymorphicComponent<TextProps, 'span'> = forwardRef( | ||
<T extends ElementType>( | ||
props: PolymorphicProps<TextProps, T>, | ||
ref: PolymorphicRef<T> | ||
) => { | ||
const { | ||
as = 'span', | ||
variant = 'inherit', | ||
className, | ||
hidden, | ||
italic, | ||
underline, | ||
children, | ||
ellipsis, | ||
uppercase, | ||
capitalize, | ||
...boxProps | ||
} = props | ||
|
||
// Merge as variant as prop values so they can be overridden rather than using textVariants recipe | ||
const textVariantProps = styles.rawTextVariants[variant] | ||
|
||
return ( | ||
<Box | ||
as={as} | ||
className={clsx( | ||
className, | ||
styles.textVariants({ | ||
hidden, | ||
ellipsis, | ||
italic, | ||
underline, | ||
uppercase, | ||
capitalize, | ||
}) | ||
)} | ||
ref={ref} | ||
{...textVariantProps} | ||
{...boxProps} | ||
> | ||
{children} | ||
</Box> | ||
) | ||
} | ||
) | ||
import { Slot } from '@radix-ui/react-slot' | ||
import { cva, VariantProps } from 'class-variance-authority' | ||
|
||
import { cn } from '~/utils' | ||
|
||
export const textVariants = cva('', { | ||
variants: { | ||
variant: { | ||
inherit: [ | ||
'font-inherit', | ||
'text-inherit', | ||
'leading-inherit', | ||
'tracking-inherit', | ||
'font-inherit', | ||
], | ||
xlarge: [ | ||
'font-body', | ||
'text-3xl', | ||
'leading-9', | ||
'tracking-none', | ||
'font-bold', | ||
], | ||
large: [ | ||
'font-body', | ||
'text-xl', | ||
'leading-7', | ||
'tracking-normal', | ||
'font-semibold', | ||
], | ||
medium: [ | ||
'font-body', | ||
'text-base', | ||
'leading-6', | ||
'tracking-normal', | ||
'font-bold', | ||
], | ||
normal: [ | ||
'font-body', | ||
'text-sm', | ||
'leading-5', | ||
'tracking-wide', | ||
'font-normal', | ||
], | ||
small: [ | ||
'font-body', | ||
'text-xs', | ||
'leading-4', | ||
'tracking-wide', | ||
'font-medium', | ||
], | ||
xsmall: [ | ||
'font-body', | ||
'text-[0.625rem]', | ||
'leading-4', | ||
'tracking-wide', | ||
'font-bold', | ||
], | ||
code: [ | ||
'font-mono', | ||
'text-sm', | ||
'leading-5', | ||
'tracking-none', | ||
'font-normal', | ||
], | ||
}, | ||
|
||
fontWeight: { | ||
normal: 'font-normal', | ||
medium: 'font-medium', | ||
semibold: 'font-semibold', | ||
bold: 'font-bold', | ||
}, | ||
|
||
color: { | ||
text100: 'text-text-100', | ||
text80: 'text-text-80', | ||
text50: 'text-text-50', | ||
white: 'text-white', | ||
black: 'text-black', | ||
negative: 'text-negative', | ||
positive: 'text-positive', | ||
warning: 'text-warning', | ||
info: 'text-info', | ||
}, | ||
|
||
ellipsis: { | ||
true: ['overflow-hidden', 'whitespace-nowrap', 'text-ellipsis'], | ||
}, | ||
|
||
italic: { | ||
true: 'italic', | ||
}, | ||
|
||
underline: { | ||
true: 'underline', | ||
}, | ||
|
||
uppercase: { | ||
true: 'uppercase', | ||
}, | ||
|
||
capitalize: { | ||
true: 'capitalize', | ||
}, | ||
|
||
nowrap: { | ||
true: 'whitespace-nowrap', | ||
}, | ||
|
||
hidden: { | ||
true: [ | ||
'border-0', | ||
'clip-rect-0', | ||
'h-[1px]', | ||
'-m-[1px]', | ||
'overflow-hidden', | ||
'p-0', | ||
'absolute', | ||
'w-[1px]', | ||
], | ||
}, | ||
}, | ||
defaultVariants: { | ||
variant: 'inherit', | ||
}, | ||
}) | ||
|
||
export interface TextProps | ||
extends Omit<React.HTMLAttributes<HTMLSpanElement>, 'hidden' | 'color'>, | ||
VariantProps<typeof textVariants> { | ||
asChild?: boolean | ||
} | ||
|
||
export const Text = (props: TextProps) => { | ||
const { | ||
asChild, | ||
variant = 'inherit', | ||
color, | ||
fontWeight, | ||
className, | ||
hidden, | ||
italic, | ||
underline, | ||
ellipsis, | ||
uppercase, | ||
capitalize, | ||
...rest | ||
} = props | ||
|
||
const Component = asChild ? Slot : 'span' | ||
|
||
return ( | ||
<Component | ||
className={cn( | ||
textVariants({ | ||
variant, | ||
fontWeight, | ||
color, | ||
hidden, | ||
italic, | ||
underline, | ||
ellipsis, | ||
uppercase, | ||
capitalize, | ||
}), | ||
className | ||
)} | ||
{...rest} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export { Text } from './Text' | ||
export { textVariants } from './styles.css' | ||
export { textVariants } from './Text' |
Oops, something went wrong.