forked from riccardoperra/codeimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseText.tsx
More file actions
28 lines (22 loc) · 698 Bytes
/
useText.tsx
File metadata and controls
28 lines (22 loc) · 698 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
import clsx from 'clsx';
import {splitProps} from 'solid-js';
import * as styles from './Text.css';
export interface UseTextProps {
size?: keyof typeof styles.fontSize;
weight?: keyof typeof styles.fontWeight;
}
export const useText = (props: UseTextProps) => {
const [local] = splitProps(props, ['size', 'weight']);
const sizeClass = () => {
if (!local.size) {
return styles.baseText;
}
return styles.fontSize[local.size] ?? undefined;
};
const weightClass = () => {
if (!local.weight) return undefined;
return styles.fontWeight[local.weight] ?? undefined;
};
const mergedClasses = () => clsx(weightClass(), sizeClass());
return mergedClasses;
};