diff --git a/src/components/Button.tsx b/src/components/Button.tsx index 84183d6..668bc06 100644 --- a/src/components/Button.tsx +++ b/src/components/Button.tsx @@ -1,4 +1,4 @@ -import type { ComponentPropsWithRef, ReactElement } from 'react'; +import type { ComponentProps, ComponentPropsWithRef, ReactElement } from 'react'; import { forwardRef } from 'react'; import { usePagodaUi } from '../context/PagodaUi'; @@ -13,7 +13,7 @@ type Props = Omit, 'size'> & { count?: number; fill?: Fill; href?: string; - target?: ComponentPropsWithRef<'a'>['target']; + target?: ComponentProps<'a'>['target']; icon?: ReactElement; iconLeft?: ReactElement; iconRight?: ReactElement; diff --git a/src/components/Text.README.md b/src/components/Text.README.md index 4aedd55..0b6179a 100644 --- a/src/components/Text.README.md +++ b/src/components/Text.README.md @@ -10,6 +10,8 @@ import { Text } from '~/components/lib/Text'; My Text My Text My Text +My Text +My Text ``` ## Line Clamp diff --git a/src/components/Text.module.scss b/src/components/Text.module.scss index 84d6fc2..02308ff 100644 --- a/src/components/Text.module.scss +++ b/src/components/Text.module.scss @@ -1,3 +1,11 @@ +a.text { + &:hover, + &:focus-visible { + color: var(--violet-11) !important; + text-decoration: underline; + } +} + .text { text-wrap: pretty; text-underline-offset: 0.2em; @@ -17,11 +25,9 @@ a > & { display: inline; } - a:has(&) { line-height: 0; } - &[role='button']:hover, &[role='button']:focus-visible, [role='button']:hover > &, diff --git a/src/components/Text.tsx b/src/components/Text.tsx index f2dd810..199e2db 100644 --- a/src/components/Text.tsx +++ b/src/components/Text.tsx @@ -1,5 +1,6 @@ -import { type CSSProperties, type MouseEventHandler, type ReactNode } from 'react'; +import { ComponentProps, ComponentPropsWithRef, type CSSProperties, forwardRef } from 'react'; +import { usePagodaUi } from '../context/PagodaUi'; import { type ThemeColor, type ThemeFontSize } from '../utils/theme'; import s from './Text.module.scss'; @@ -17,71 +18,78 @@ const defaultSizes: Record = { label: 'text-base', }; -type Props = { +type Props = Omit, 'color'> & { as?: Tag; - children: ReactNode; clampLines?: number; - className?: string; clickableHighlight?: boolean; color?: ThemeColor; decoration?: CSSProperties['textDecoration']; family?: 'standard' | 'monospace'; forceWordBreak?: boolean; - id?: string; + href?: string; + target?: ComponentProps<'a'>['target']; size?: ThemeFontSize; sizePhone?: ThemeFontSize; sizeTablet?: ThemeFontSize; - style?: CSSProperties; noWrap?: boolean; - onClick?: MouseEventHandler; weight?: string | number; uppercase?: boolean; }; -export const Text = ({ - as = 'p', - children, - clampLines, - className = '', - clickableHighlight, - color, - decoration, - family, - forceWordBreak, - size, - style, - weight, - noWrap, - onClick, - uppercase, - ...props -}: Props) => { - const Tag = as; - const defaultSize = defaultSizes[as]; +export const Text = forwardRef( + ( + { + as = 'p', + children, + clampLines, + className = '', + clickableHighlight, + color, + decoration, + family, + forceWordBreak, + size, + style, + weight, + noWrap, + onClick, + uppercase, + ...props + }, + ref, + ) => { + const Tag = as; + const defaultSize = defaultSizes[as]; + const { Link } = usePagodaUi(); + const Element: any = props.href ? Link : Tag; - return ( - - {children} - - ); -}; + return ( + + {children} + + ); + }, +); + +Text.displayName = 'Text';