FoundationsTypography
Text component
Installation
npx shadcn@latest add @caprice/textpnpm dlx shadcn@latest add @caprice/textyarn dlx shadcn@latest add @caprice/textbunx shadcn@latest add @caprice/textnpm install @caprice-ui/reactpnpm add @caprice-ui/reactyarn add @caprice-ui/reactbun add @caprice-ui/reactInstall the following dependencies:
npm install @base-ui/react lucide-reactpnpm add @base-ui/react lucide-reactyarn add @base-ui/react lucide-reactbun add @base-ui/react lucide-reactAdd a cn helper
import { defineConfig, getSchema, type VariantProps } from 'cva';
import { twMerge } from 'tailwind-merge';
export const { cva, cx: cn } = defineConfig({
hooks: {
onComplete: (className: string) => twMerge(className),
},
});
export type { VariantProps };
export { getSchema };
Copy and paste the following code into your project.
import { mergeProps, useRender } from '@base-ui/react';
import { cva, type VariantProps } from '@/lib/utils';
// TODO: Use fluid typography
export const textVariants = cva({
base: 'text-pretty text-current',
variants: {
size: {
xs: 'text-xs',
sm: 'text-sm tracking-[-0.005em]',
md: 'text-base tracking-[-0.010em]',
lg: 'text-lg/6 tracking-[-0.015em]',
xl: 'text-xl/[30px] tracking-[-0.015em]',
},
weight: {
regular: 'font-normal',
medium: 'font-medium',
semibold: 'font-semibold',
bold: 'font-bold',
},
},
defaultVariants: {
size: 'md',
weight: 'regular',
},
});
/**
* Documentation: [Caprice UI Text](https://caprice-ui.com/docs/foundations/typography/text)
*/
export namespace Text {
export type Props = useRender.ComponentProps<'p'> & VariantProps<typeof textVariants>;
}
export function Text({
size = 'md',
weight = 'regular',
className,
children,
render,
...props
}: Text.Props) {
const defaultProps: useRender.ElementProps<'p'> & { 'data-slot'?: string } = {
'data-slot': 'text',
className: textVariants({
size,
weight,
className,
}),
};
return useRender({
render,
defaultTagName: 'p',
props: mergeProps<'p'>(defaultProps, props),
});
}
Update the import paths to match your project setup.
Usage
Examples
API Reference
Last updated on