Skip to content

Commit

Permalink
Text converted to tailwind
Browse files Browse the repository at this point in the history
  • Loading branch information
corbanbrook committed Jan 16, 2025
1 parent ec4b56e commit 945c5a7
Show file tree
Hide file tree
Showing 10 changed files with 199 additions and 99 deletions.
12 changes: 3 additions & 9 deletions src/components/Breadcrumbs/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,7 @@ const BreadcrumbSegment = (props: BreadcrumbSegmentProps) => {
const { path, active, renderLink = defaultRenderLink } = props

return active ? (
<Text
variant="small"
fontWeight="medium"
color="text100"
whiteSpace="nowrap"
capitalize
>
<Text variant="small" fontWeight="medium" color="text100" nowrap capitalize>
{path.label}
</Text>
) : (
Expand All @@ -75,9 +69,9 @@ const BreadcrumbSegment = (props: BreadcrumbSegmentProps) => {
variant="small"
fontWeight="medium"
color="text50"
whiteSpace="nowrap"
nowrap
capitalize
opacity={{ hover: '80' }}
className="hover:opacity-80"
>
{path.label}
</Text>
Expand Down
8 changes: 4 additions & 4 deletions src/components/Collapsible/Collapsible.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ const CollapsibleStory = () => {
onOpenChange={open => setIsOpen(open)}
>
{[1, 2, 3, 4, 5].map(x => (
<Text variant="normal" as="p" color="text80" key={x}>
Item {x}
<Text variant="normal" color="text80" key={x} asChild>
<p>Item {x}</p>
</Text>
))}
</Collapsible>
Expand All @@ -38,8 +38,8 @@ export const Default: Story = {
args: {
label: 'My Heading',
children: [1, 2, 3, 4, 5].map(x => (
<Text variant="normal" as="p" color="text80" key={x}>
Item {x}
<Text variant="normal" color="text80" key={x} asChild>
<p>Item {x}</p>
</Text>
)),
},
Expand Down
4 changes: 2 additions & 2 deletions src/components/Collapsible/Collapsible.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export const Collapsible = (props: CollapsibleProps) => {
transition={{ ease: 'easeOut', duration: 0.3 }}
>
<CollapsiblePrimitive.Trigger className="flex items-center bg-transparent p-4 w-full cursor-pointer select-none rounded-md border-none appearance-none h-[64px] focus:outline-none">
<Text as="div" variant="normal" fontWeight="bold" color="text80">
{label}
<Text variant="normal" fontWeight="bold" color="text80" asChild>
<div>{label}</div>
</Text>
<motion.div
className="absolute right-0 mr-4"
Expand Down
2 changes: 1 addition & 1 deletion src/components/FileInput/FileInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const FileInput = forwardRef<HTMLInputElement, FileInputProps>(
{fileData ? (
<div className="flex flex-row gap-2 items-center min-w-0">
<Text ellipsis>{fileData.name}</Text>
<Text color="text50" variant="xsmall" whiteSpace="nowrap">
<Text color="text50" variant="xsmall" nowrap>
{fileData.size.toFixed(2)} kb
</Text>
</div>
Expand Down
10 changes: 2 additions & 8 deletions src/components/GradientAvatar/GradientAvatar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,8 @@ for (let row = 0; row < ROWS; row++) {
export const Multiple = () => {
return (
<>
<Text
as="div"
variant="normal"
color="text100"
fontWeight="bold"
marginBottom="4"
>
SVG
<Text variant="normal" color="text100" fontWeight="bold" asChild>
<div>SVG</div>
</Text>

<div className="flex flex-col gap-4">
Expand Down
20 changes: 11 additions & 9 deletions src/components/Modal/Modal.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ export const Default: Story = {
children: (
<div className="flex flex-col justify-between h-full p-4">
<div>
<Text as="h1" variant="medium" color="text100">
New Dapp
<Text variant="medium" color="text100" asChild>
<h1>New Dapp</h1>
</Text>
<Text as="p" variant="normal" color="text50">
You can always change these settings later.
<Text variant="normal" color="text50" asChild>
<p>You can always change these settings later.</p>
</Text>
</div>

Expand Down Expand Up @@ -67,12 +67,14 @@ export const CustomAnimation: Story = {
children: (
<div className="flex flex-col justify-between h-full p-4">
<div>
<Text as="h1" variant="medium" color="text100">
New Dapp
<Text variant="medium" color="text100" asChild>
<h1>New Dapp</h1>
</Text>
<Text as="p" variant="normal" color="text50">
Custom Open & Close Animated Modal. You can always change these
settings later.
<Text variant="normal" color="text50" asChild>
<p>
Custom Open & Close Animated Modal. You can always change these
settings later.
</p>
</Text>
</div>

Expand Down
2 changes: 0 additions & 2 deletions src/components/Text/Text.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export const BodyLarge: Story = {
args: {
variant: 'large',
color: 'text100',
as: 'p',
children: 'Hello, world!',
},
}
Expand All @@ -57,7 +56,6 @@ export const TextAsChild: Story = {
args: {
variant: 'normal',
color: 'text100',
as: 'p',
children: (
<>
<Text fontWeight="bold" color="positive">
Expand Down
230 changes: 171 additions & 59 deletions src/components/Text/Text.tsx
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}
/>
)
}
2 changes: 1 addition & 1 deletion src/components/Text/index.ts
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'
Loading

0 comments on commit 945c5a7

Please sign in to comment.