Skip to content

Commit

Permalink
fixup! ✨(frontend) create Text component
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoLC committed Oct 3, 2023
1 parent c7dd4d5 commit 5fe6b0a
Showing 1 changed file with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { Maybe } from 'lib-common';
import { ReactHTML } from 'react';

import {
ObtainHTMLProps,
Typo,
TypoPropsOnly,
} from '@lib-components/common/Typo';
import { Typo, TypoProps } from '@lib-components/common/Typo';

export const TextWeights = {
black: 'fw-black',
Expand All @@ -25,15 +22,24 @@ export const TextSizes = {
tiny: 'fs-t',
} as const;

export interface TextPropsOnly<T> extends TypoPropsOnly<T> {
export interface TextPropsOnly {
size?: keyof typeof TextSizes;
weight?: keyof typeof TextWeights;
}

type TextTypes = Pick<ReactHTML, 'p' | 'span' | 'div'>;

export type TextProps<T extends keyof TextTypes> = TextPropsOnly<TextTypes> &
ObtainHTMLProps<TextTypes[T]>;
/**
* @description Typo props
* @param T - keyof TextTypes
* @example
* type Props = TextProps<'div'>;
* // type Props = ReactHTMLInfer<div> & TextPropsOnly & TypoPropsOnly & HTMLAttributes<HTMLDivElement>
*/
export type TextProps<T extends Maybe<keyof TextTypes>> = TypoProps<
T,
TextPropsOnly
>;

/**
* @param TextPropsOnly -
Expand All @@ -43,7 +49,7 @@ export type TextProps<T extends keyof TextTypes> = TextPropsOnly<TextTypes> &
* @See {@link Typo }
* @returns Text component
*/
export const Text = <T extends keyof TextTypes>({
export const Text = <T extends Maybe<keyof TextTypes>>({
className,
size = 'medium-large',
type = 'span',
Expand Down

0 comments on commit 5fe6b0a

Please sign in to comment.