mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-17 06:00:20 +02:00
Set as polymorphic
This commit is contained in:
@@ -1,18 +1,13 @@
|
|||||||
import {
|
import { ComponentPropsWithoutRef, ReactNode } from 'react';
|
||||||
ComponentPropsWithoutRef,
|
|
||||||
ComponentPropsWithRef,
|
|
||||||
ReactNode,
|
|
||||||
} from 'react';
|
|
||||||
import styled from '@emotion/styled';
|
import styled from '@emotion/styled';
|
||||||
import {
|
import {
|
||||||
|
createPolymorphicComponent,
|
||||||
Text as MantineText,
|
Text as MantineText,
|
||||||
TextProps as MantineTextProps,
|
TextProps as MantineTextProps,
|
||||||
} from '@mantine/core';
|
} from '@mantine/core';
|
||||||
import { Link } from 'react-router-dom';
|
|
||||||
import { Font, textEllipsis } from '@/renderer/styles';
|
import { Font, textEllipsis } from '@/renderer/styles';
|
||||||
|
|
||||||
type MantineTextDivProps = MantineTextProps & ComponentPropsWithoutRef<'div'>;
|
type MantineTextDivProps = MantineTextProps & ComponentPropsWithoutRef<'div'>;
|
||||||
type MantineTextLinkProps = MantineTextProps & ComponentPropsWithRef<'link'>;
|
|
||||||
|
|
||||||
interface TextProps extends MantineTextDivProps {
|
interface TextProps extends MantineTextDivProps {
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
@@ -25,64 +20,31 @@ interface TextProps extends MantineTextDivProps {
|
|||||||
weight?: number;
|
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)<any>`
|
const BaseText = styled(MantineText)<any>`
|
||||||
color: ${(props) =>
|
color: ${(props) =>
|
||||||
props.$secondary
|
props.secondary ? 'var(--main-fg-secondary)' : 'var(--main-fg)'};
|
||||||
? 'var(--playerbar-text-secondary-color)'
|
font-family: ${(props) => props.font};
|
||||||
: 'var(--playerbar-text-primary-color)'};
|
|
||||||
font-family: ${(props) => props.font || Font.GOTHAM};
|
|
||||||
/* cursor: ${(props) => (props.link ? 'cursor' : 'default')}; */
|
/* 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}
|
${(props) => props.overflow === 'hidden' && textEllipsis}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const StyledText = styled(BaseText)<TextProps>``;
|
const StyledText = styled(BaseText)<TextProps>``;
|
||||||
|
|
||||||
const StyledLinkText = styled(BaseText)<LinkTextProps>``;
|
export const _Text = ({
|
||||||
|
|
||||||
export const Text = ({
|
|
||||||
children,
|
children,
|
||||||
link,
|
|
||||||
secondary,
|
secondary,
|
||||||
overflow,
|
overflow,
|
||||||
font,
|
font,
|
||||||
to,
|
|
||||||
noSelect,
|
noSelect,
|
||||||
...rest
|
...rest
|
||||||
}: TextProps) => {
|
}: TextProps) => {
|
||||||
if (link) {
|
|
||||||
return (
|
|
||||||
<StyledLinkText
|
|
||||||
$noSelect={noSelect}
|
|
||||||
$secondary={secondary}
|
|
||||||
component={Link}
|
|
||||||
font={font}
|
|
||||||
link="true"
|
|
||||||
overflow={overflow}
|
|
||||||
to={to || ''}
|
|
||||||
{...rest}
|
|
||||||
>
|
|
||||||
{children}
|
|
||||||
</StyledLinkText>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledText
|
<StyledText
|
||||||
$noSelect={noSelect}
|
|
||||||
$secondary={secondary}
|
|
||||||
font={font}
|
font={font}
|
||||||
|
noSelect={noSelect && noSelect}
|
||||||
overflow={overflow}
|
overflow={overflow}
|
||||||
|
secondary={secondary && secondary}
|
||||||
{...rest}
|
{...rest}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
@@ -90,8 +52,10 @@ export const Text = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
Text.defaultProps = {
|
export const Text = createPolymorphicComponent<'div', TextProps>(_Text);
|
||||||
font: Font.GOTHAM,
|
|
||||||
|
_Text.defaultProps = {
|
||||||
|
font: undefined,
|
||||||
link: false,
|
link: false,
|
||||||
noSelect: false,
|
noSelect: false,
|
||||||
overflow: 'visible',
|
overflow: 'visible',
|
||||||
|
|||||||
Reference in New Issue
Block a user