-
-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathText.tsx
38 lines (34 loc) · 1.03 KB
/
Text.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import {ElementType} from '@solid-aria/types';
import clsx from 'clsx';
import {
DynamicProps,
WithRef,
} from 'solid-headless/dist/types/utils/dynamic-prop';
import {JSXElement, ParentProps, splitProps} from 'solid-js';
import {Dynamic} from 'solid-js/web';
import {useText, UseTextProps} from './useText';
export type TextComponentProps = {
size?: UseTextProps['size'];
weight?: UseTextProps['weight'];
};
export type TextProps<T extends ElementType = 'span'> = TextComponentProps & {
as?: T | ElementType;
innerHTML?: JSXElement | string;
} & WithRef<T> &
Omit<DynamicProps<T>, 'ref' | 'as'>;
export function Text<T extends ElementType = 'span'>(
props: ParentProps<TextProps<T>>,
): JSXElement {
// @ts-expect-error TODO: find why class is not present
const [local, others] = splitProps(props, ['as', 'class']);
const textClasses = useText(props);
return (
<Dynamic
component={local.as ?? 'span'}
class={clsx(textClasses(), local.class)}
{...others}
>
{props.children}
</Dynamic>
);
}