forked from riccardoperra/codeimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathText.tsx
More file actions
38 lines (34 loc) · 998 Bytes
/
Text.tsx
File metadata and controls
38 lines (34 loc) · 998 Bytes
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 clsx from 'clsx';
import {
DynamicProps,
ValidConstructor,
WithRef,
} from 'solid-headless/dist/types/utils/dynamic-prop';
import {JSXElement, ParentProps} from 'solid-js';
import {Dynamic} from 'solid-js/web';
import {omitProps} from 'solid-use';
import {useText, UseTextProps} from './useText';
export type TextComponentProps = {
size?: UseTextProps['size'];
weight?: UseTextProps['weight'];
};
export type TextProps<T extends ValidConstructor = 'span'> = {
as?: T | ValidConstructor;
innerHTML?: JSXElement | string;
} & WithRef<T> &
Omit<DynamicProps<T>, 'ref' | 'as'> &
TextComponentProps;
export function Text<T extends ValidConstructor = 'span'>(
props: ParentProps<TextProps<T>>,
): JSXElement {
const textClasses = useText(props);
return (
<Dynamic
component={props.as ?? 'span'}
{...omitProps(props, ['as', 'children', 'size', 'weight'])}
class={clsx(textClasses(), props.class)}
>
{props.children}
</Dynamic>
);
}