Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc: refactor shared styled typography to render FC with TW #1950

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/customers/CustomerCreditNotesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const CustomerCreditNotesList = ({

return (
<SideSection>
<SectionHeader variant="subhead" color="grey700" $hideBottomShadow>
<SectionHeader variant="subhead" color="grey700" hideBottomShadow>
{translate('text_63725b30957fd5b26b308dd7')}
</SectionHeader>
<div className="mb-8 flex h-18 items-center justify-between rounded-xl border border-grey-400 px-4 py-3">
Expand Down
2 changes: 1 addition & 1 deletion src/components/customers/overview/CustomerCoupons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const CustomerCoupons = memo(() => {
<>
{!!(coupons || [])?.length && (
<Container data-test="customer-coupon-container">
<SectionHeader variant="subhead" $hideBottomShadow>
<SectionHeader variant="subhead" hideBottomShadow>
{translate('text_628b8c693e464200e00e469d')}
<Button
variant="quaternary"
Expand Down
2 changes: 1 addition & 1 deletion src/components/customers/overview/CustomerOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export const CustomerOverview: FC<CustomerOverviewProps> = ({
<>
{(!overdueBalancesError || !grossRevenuesError) && (
<section>
<SectionHeader variant="subhead" $hideBottomShadow>
<SectionHeader variant="subhead" hideBottomShadow>
{translate('text_6670a7222702d70114cc7954')}

<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const CustomerSubscriptionsList = ({ customerTimezone }: CustomerSubscrip

return (
<SideSection>
<Header variant="subhead" $hideBottomShadow>
<Header variant="subhead" hideBottomShadow>
{translate('text_6250304370f0f700a8fdc28d')}

{hasPermissions(['subscriptionsCreate']) && (
Expand Down
2 changes: 1 addition & 1 deletion src/components/wallets/CustomerWalletList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const CustomerWalletsList = ({ customerId, customerTimezone }: CustommerW
return (
<>
<SideSection $empty={!!hasNoWallet}>
<SectionHeader variant="subhead" $hideBottomShadow={!!loading || !hasNoWallet}>
<SectionHeader variant="subhead" hideBottomShadow={!!loading || !hasNoWallet}>
{translate('text_62d175066d2dbf1d50bc9384')}

{hasAnyPermissionsToShowActions && (
Expand Down
5 changes: 2 additions & 3 deletions src/pages/CreateTax.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
Content,
LineSplit,
Main,
SectionTitle,
Side,
SkeletonHeader,
Subtitle,
Expand Down Expand Up @@ -118,9 +117,9 @@ const CreateTaxRate = () => {
</div>

<Card>
<SectionTitle variant="subhead">
<Typography variant="subhead">
{translate('text_645bb193927b375079d28a91')}
</SectionTitle>
</Typography>

<LineSplit>
<TextInputField
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Invitation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ const Invitation = () => {
<StyledLogo height={24} />
{(!!error || !data?.invite) && !loading ? (
<>
<Title variant="headline">{translate('text_63246f875e2228ab7b63dcf4')}</Title>
<Subtitle $noMargins>{translate('text_63246f875e2228ab7b63dcfe')}</Subtitle>
<Title>{translate('text_63246f875e2228ab7b63dcf4')}</Title>
<Subtitle noMargins>{translate('text_63246f875e2228ab7b63dcfe')}</Subtitle>
</>
) : !!loading ? (
<>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/auth/ForgotPassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const ForgotPassword = () => {
<StyledLogo height={24} />
{hasSubmitted ? (
<>
<Title variant="headline">{translate('text_642707b0da1753a9bb66728e')}</Title>
<Title>{translate('text_642707b0da1753a9bb66728e')}</Title>
<Subtitle>{translate('text_642707b0da1753a9bb667298')}</Subtitle>
<ButtonLink
type="button"
Expand All @@ -83,7 +83,7 @@ const ForgotPassword = () => {
</>
) : (
<>
<Title variant="headline">{translate('text_642707b0da1753a9bb66728c')}</Title>
<Title>{translate('text_642707b0da1753a9bb66728c')}</Title>
<Subtitle>{translate('text_642707b0da1753a9bb667296')}</Subtitle>
<form onSubmit={(e) => e.preventDefault()}>
<TextInputField
Expand Down
6 changes: 3 additions & 3 deletions src/pages/auth/ResetPassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ const ResetPassword = () => {
</>
) : !!error && !loading ? (
<>
<Title variant="headline">{translate('text_642707b0da1753a9bb667292')}</Title>
<Subtitle $noMargins>{translate('text_642707b0da1753a9bb66729c')}</Subtitle>
<Title>{translate('text_642707b0da1753a9bb667292')}</Title>
<Subtitle noMargins>{translate('text_642707b0da1753a9bb66729c')}</Subtitle>
</>
) : (
<>
<Title variant="headline">{translate('text_642707b0da1753a9bb667290')}</Title>
<Title>{translate('text_642707b0da1753a9bb667290')}</Title>
<Subtitle>{translate('text_642707b0da1753a9bb66729a')}</Subtitle>

<form>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/auth/SignUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ const SignUp = () => {

<Stack spacing={8}>
<Stack spacing={3}>
<Title variant="headline">
<Title>
{translate(
isGoogleRegister
? 'text_660bf95c75dd928ced0ecb04'
Expand Down
19 changes: 13 additions & 6 deletions src/styles/auth.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { FC, PropsWithChildren } from 'react'
import styled from 'styled-components'

import { Typography } from '~/components/designSystem'
import Logo from '~/public/images/logo/lago-logo.svg'
import { theme } from '~/styles'

import { tw } from './utils'

export const Page = styled.div`
box-sizing: border-box;
background-color: ${theme.palette.grey[100]};
Expand All @@ -29,9 +32,13 @@ export const Card = styled.div`
box-sizing: border-box;
`

export const Title = styled(Typography)`
margin-bottom: ${theme.spacing(3)};
`
export const Subtitle = styled(Typography)<{ $noMargins?: boolean }>`
margin-bottom: ${({ $noMargins }) => ($noMargins ? 0 : theme.spacing(8))};
`
export const Title: FC<PropsWithChildren> = ({ children }) => (
<Typography className="mb-3" variant="headline">
{children}
</Typography>
)

export const Subtitle: FC<PropsWithChildren<{ noMargins?: boolean }>> = ({
children,
noMargins,
}) => <Typography className={tw('mb-8', { '!mb-0': !!noMargins })}>{children}</Typography>
26 changes: 17 additions & 9 deletions src/styles/customer.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
import { FC, PropsWithChildren } from 'react'
import styled from 'styled-components'

import { Typography } from '~/components/designSystem'
import { NAV_HEIGHT, theme } from '~/styles'
import { Typography, TypographyProps } from '~/components/designSystem'
import { theme } from '~/styles'

import { tw } from './utils'

export const SideSection = styled.div<{ $empty?: boolean }>`
> *:first-child {
margin-bottom: ${({ $empty }) => ($empty ? theme.spacing(6) : 0)};
}
`

export const SectionHeader = styled(Typography)<{ $hideBottomShadow?: boolean }>`
height: ${NAV_HEIGHT}px;
box-shadow: ${({ $hideBottomShadow }) => ($hideBottomShadow ? undefined : theme.shadows[7])};
display: flex;
align-items: center;
justify-content: space-between;
`
export const SectionHeader: FC<
PropsWithChildren<{ hideBottomShadow?: boolean } & TypographyProps>
> = ({ children, hideBottomShadow, ...props }) => (
<Typography
className={tw('flex h-18 items-center justify-between', {
'shadow-b': !hideBottomShadow,
})}
{...props}
>
{children}
</Typography>
)
19 changes: 11 additions & 8 deletions src/styles/detailsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ReactNode } from 'react'
import { FC, PropsWithChildren, ReactNode } from 'react'
import styled from 'styled-components'

import { Typography } from '~/components/designSystem'
import { NAV_HEIGHT, theme } from '~/styles'
import { Typography, TypographyProps } from '~/components/designSystem'
import { theme } from '~/styles'

interface DetailsInfoItemProps {
label: string
Expand All @@ -19,11 +19,14 @@ export const DetailsInfoItem = ({ label, value }: DetailsInfoItemProps) => {
)
}

export const DetailsSectionTitle = styled(Typography)`
display: flex;
align-items: center;
height: ${NAV_HEIGHT}px;
`
export const DetailsSectionTitle: FC<PropsWithChildren<TypographyProps>> = ({
children,
...props
}) => (
<Typography className="flex h-18 items-center" {...props}>
{children}
</Typography>
)

export const DetailsInfoGrid = ({ grid }: { grid: Array<DetailsInfoItemProps | false> }) => {
return (
Expand Down
30 changes: 13 additions & 17 deletions src/styles/mainObjectsForm.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// This file contains styled components for the main objects form
// Ultimately, only general rules such as responsive or block size should be kept here
// Parts about spacing between elements should be moved to the components themselves
import { FC, PropsWithChildren } from 'react'
import styled from 'styled-components'

import { Skeleton, Typography } from '~/components/designSystem'
import { Skeleton, Typography, TypographyProps } from '~/components/designSystem'

import { NAV_HEIGHT, theme } from './muiTheme'

Expand Down Expand Up @@ -32,16 +33,17 @@ export const Content = styled.div`
display: flex;
min-height: calc(100vh - ${NAV_HEIGHT}px);
`

export const Title = styled(Typography)`
margin-bottom: ${theme.spacing(1)};
padding: 0 ${theme.spacing(8)};
`

export const Subtitle = styled(Typography)`
margin-bottom: ${theme.spacing(8)};
padding: 0 ${theme.spacing(8)};
`
export const Title: FC<PropsWithChildren<TypographyProps>> = ({ children, ...props }) => (
<Typography className="mb-1 px-8" {...props}>
{children}
</Typography>
)

export const Subtitle: FC<PropsWithChildren<TypographyProps>> = ({ children, ...props }) => (
<Typography className="mb-8 px-8" {...props}>
{children}
</Typography>
)

export const Side = styled.div`
width: 40%;
Expand Down Expand Up @@ -112,12 +114,6 @@ export const StickySubmitBar = styled.div`

// ------------------------------------------------------------

export const SectionTitle = styled(Typography)`
> div:first-child {
margin-bottom: ${theme.spacing(3)};
}
`

export const FormLoadingSkeleton = ({ id, length = 2 }: { id: string; length?: number }) => {
const array = Array.from({ length }, (_, index) => index)

Expand Down
Loading