From 659a9b949b277d82b0dd4ebf0796cc56a6ae698a Mon Sep 17 00:00:00 2001 From: jeffvli Date: Sun, 30 Oct 2022 20:18:16 -0700 Subject: [PATCH] Set as polymorphic --- src/renderer/components/text/index.tsx | 60 ++++++-------------------- 1 file changed, 12 insertions(+), 48 deletions(-) diff --git a/src/renderer/components/text/index.tsx b/src/renderer/components/text/index.tsx index b6e89daf5..ffad8973f 100644 --- a/src/renderer/components/text/index.tsx +++ b/src/renderer/components/text/index.tsx @@ -1,18 +1,13 @@ -import { - ComponentPropsWithoutRef, - ComponentPropsWithRef, - ReactNode, -} from 'react'; +import { ComponentPropsWithoutRef, ReactNode } from 'react'; import styled from '@emotion/styled'; import { + createPolymorphicComponent, Text as MantineText, TextProps as MantineTextProps, } from '@mantine/core'; -import { Link } from 'react-router-dom'; import { Font, textEllipsis } from '@/renderer/styles'; type MantineTextDivProps = MantineTextProps & ComponentPropsWithoutRef<'div'>; -type MantineTextLinkProps = MantineTextProps & ComponentPropsWithRef<'link'>; interface TextProps extends MantineTextDivProps { children: ReactNode; @@ -25,64 +20,31 @@ interface TextProps extends MantineTextDivProps { weight?: number; } -interface LinkTextProps extends MantineTextLinkProps { - children: ReactNode; - font?: Font; - link?: boolean; - overflow?: 'hidden' | 'visible'; - secondary?: boolean; - to: string; - weight?: number; -} - const BaseText = styled(MantineText)` color: ${(props) => - props.$secondary - ? 'var(--playerbar-text-secondary-color)' - : 'var(--playerbar-text-primary-color)'}; - font-family: ${(props) => props.font || Font.GOTHAM}; + props.secondary ? 'var(--main-fg-secondary)' : 'var(--main-fg)'}; + font-family: ${(props) => props.font}; /* cursor: ${(props) => (props.link ? 'cursor' : 'default')}; */ - user-select: ${(props) => (props.$noSelect ? 'none' : 'auto')}; + user-select: ${(props) => (props.noSelect ? 'none' : 'auto')}; ${(props) => props.overflow === 'hidden' && textEllipsis} `; const StyledText = styled(BaseText)``; -const StyledLinkText = styled(BaseText)``; - -export const Text = ({ +export const _Text = ({ children, - link, secondary, overflow, font, - to, noSelect, ...rest }: TextProps) => { - if (link) { - return ( - - {children} - - ); - } - return ( {children} @@ -90,8 +52,10 @@ export const Text = ({ ); }; -Text.defaultProps = { - font: Font.GOTHAM, +export const Text = createPolymorphicComponent<'div', TextProps>(_Text); + +_Text.defaultProps = { + font: undefined, link: false, noSelect: false, overflow: 'visible',