Skip to content

Commit

Permalink
misc(Typography): use tailwind (#1817)
Browse files Browse the repository at this point in the history
  • Loading branch information
ansmonjol authored Oct 23, 2024
1 parent a4896b2 commit 18ced4a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 38 deletions.
53 changes: 15 additions & 38 deletions src/components/designSystem/Typography.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import _isEqual from 'lodash/isEqual'
import { ElementType, memo } from 'react'
import { Link } from 'react-router-dom'
import sanitizeHtml from 'sanitize-html'
import styled, { css } from 'styled-components'

import { tw } from '~/styles/utils'

const defaultSanitizerOptions = {
allowedTags: ['b', 'i', 'em', 'strong', 'a', 'sup', 'span'],
Expand Down Expand Up @@ -74,8 +75,8 @@ export const Typography = memo(
html,
component = 'div',
noWrap,
forceBreak,
blur,
forceBreak = false,
blur = false,
...props
}: TypographyProps) => {
const getSanitizedHtml = (htmlString: string) => {
Expand Down Expand Up @@ -130,9 +131,17 @@ export const Typography = memo(
}

return (
<StyledMuiTypography
<MuiTypography
variant={variant}
className={className}
className={tw(
{
'whitespace-pre-line': !noWrap && variant !== 'captionCode',
'whitespace-pre': !noWrap && variant === 'captionCode',
'pointer-events-none select-none blur-sm': blur,
'line-break-anywhere': forceBreak,
},
className,
)}
color={mapColor(variant, color)}
data-test={variant}
variantMapping={{
Expand All @@ -142,16 +151,12 @@ export const Typography = memo(
noteHl: 'div',
captionCode: 'code',
}}
$code={variant === 'captionCode'}
$forceBreak={forceBreak}
$noWrap={noWrap}
$blur={blur}
noWrap={noWrap}
component={component}
{...props}
>
{html ? getSanitizedHtml(html) : children}
</StyledMuiTypography>
</MuiTypography>
)
},
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand All @@ -160,31 +165,3 @@ export const Typography = memo(
)

Typography.displayName = 'Typography'

const StyledMuiTypography = styled(MuiTypography)<{
component?: unknown
$code?: boolean
$noWrap?: boolean
$forceBreak?: boolean
$blur?: boolean
}>`
${({ $noWrap, $code }) =>
!$noWrap &&
css`
white-space: ${$code ? 'pre' : 'pre-line'};
`}
${({ $forceBreak }) =>
!!$forceBreak &&
css`
line-break: anywhere;
`}
${({ $blur }) =>
$blur &&
css`
filter: blur(4px);
pointer-events: none;
user-select: none;
`}
`
1 change: 1 addition & 0 deletions src/pages/__devOnly/DesignSystem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,7 @@ const DesignSystem = () => {
<Typography variant="captionCode">CaptionCode</Typography>
<Typography variant="note">Note</Typography>
<Typography variant="noteHl">NoteHl</Typography>
<Typography blur>Amma blurred text</Typography>
<Typography
color="textSecondary"
html="I'm a bit <b>special</b>, I <i>understand</i> html"
Expand Down

0 comments on commit 18ced4a

Please sign in to comment.