Skip to content

Commit

Permalink
Refactor CTAButtonGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
mirhamasala committed Aug 29, 2024
1 parent e7df934 commit 255c6b9
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"plugin:import/errors",
"plugin:import/warnings"
],
"plugins": ["@typescript-eslint"],
// "plugins": ["@typescript-eslint"],
"rules": {
// React specific rules
"react/no-unescaped-entities": "warn",
Expand Down
37 changes: 37 additions & 0 deletions src/app/_components/CTAButtonGroup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { clsx } from 'clsx'

import { Button } from '@/components/Button'

import type { CTAProps } from '@/types/sharedProps/ctaType'

export type CTAButtonGroupProps = {
cta: CTAProps | [CTAProps, CTAProps]
}

export function CTAButtonGroup({ cta }: CTAButtonGroupProps) {
const ctaArray = Array.isArray(cta) ? cta : [cta]

const gridClasses = clsx(
'grid gap-4',
ctaArray.length === 1
? 'lg:grid-cols-1'
: 'sm:grid-cols-2 sm:gap-3 lg:grid-cols-1 lg:gap-4',
)

return (
<div className={gridClasses}>
{ctaArray.map(
(button, index) =>
button && (
<Button
key={index}
href={button.href}
variant={index === 0 ? 'primary' : 'ghost'}
>
{button.text}
</Button>
),
)}
</div>
)
}
34 changes: 6 additions & 28 deletions src/app/_components/PageHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { clsx } from 'clsx'

import { Button } from '@/components/Button'
import {
type CTAButtonGroupProps,
CTAButtonGroup,
} from '@/components/CTAButtonGroup'
import {
DescriptionText,
type DescriptionTextType,
Expand All @@ -11,8 +15,6 @@ import { Meta, type MetaDataType } from '@/components/Meta'
import { SectionDivider } from '@/components/SectionDivider'
import { StaticImage, type StaticImageProps } from '@/components/StaticImage'

import { type CTAProps } from '@/types/sharedProps/ctaType'

import { buildImageSizeProp } from '@/utils/buildImageSizeProp'

type TitleProps = {
Expand All @@ -22,7 +24,7 @@ type TitleProps = {
type PageHeaderProps = {
title: TitleProps['children']
description?: DescriptionTextType
cta?: CTAProps | [CTAProps, CTAProps]
cta?: CTAButtonGroupProps['cta']
metaData?: MetaDataType
isFeatured?: boolean
image: StaticImageProps | DynamicImageProps
Expand Down Expand Up @@ -77,8 +79,6 @@ export function PageHeader({
metaData,
isFeatured = false,
}: PageHeaderProps) {
const ctaArray = Array.isArray(cta) ? cta : [cta]

return (
<header className="grid gap-4">
{isFeatured && <SectionDivider title="Featured" />}
Expand All @@ -94,29 +94,7 @@ export function PageHeader({

{description && <DescriptionText>{description}</DescriptionText>}

{ctaArray && (
<div
className={clsx(
'grid gap-4',
ctaArray.length === 1
? 'lg:grid-cols-1'
: 'sm:grid-cols-2 sm:gap-3 lg:grid-cols-1 lg:gap-4',
)}
>
{ctaArray.map(
(button, index) =>
button && (
<Button
key={index}
href={button.href}
variant={index === 0 ? 'primary' : 'ghost'}
>
{button.text}
</Button>
),
)}
</div>
)}
{cta && <CTAButtonGroup cta={cta} />}
</div>

<div className="lg:w-1/2">
Expand Down
38 changes: 8 additions & 30 deletions src/app/_components/PageSection.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { clsx } from 'clsx'

import { Button } from '@/components/Button'
import type { CTAButtonGroupProps } from '@/components/CTAButtonGroup'
import {
type DescriptionTextType,
DescriptionText,
type DescriptionTextType,
} from '@/components/DescriptionText'
import { Heading } from '@/components/Heading'
import {
Expand All @@ -12,16 +12,16 @@ import {
} from '@/components/SectionDivider'
import { StaticImage, type StaticImageProps } from '@/components/StaticImage'

import type { CTAProps } from '@/types/sharedProps/ctaType'

import { buildImageSizeProp } from '@/utils/buildImageSizeProp'

import { CTAButtonGroup } from './CTAButtonGroup'

type PageSectionProps = {
kicker: SectionDividerProps['title']
title: string
description?: DescriptionTextType
image?: StaticImageProps
cta?: CTAProps | [CTAProps, CTAProps]
cta?: CTAButtonGroupProps['cta']
children?: React.ReactNode
}

Expand All @@ -33,8 +33,6 @@ export function PageSection({
children,
cta,
}: PageSectionProps) {
const ctaArray = Array.isArray(cta) ? cta : [cta]

return (
<section>
<SectionDivider title={kicker} />
Expand All @@ -51,30 +49,9 @@ export function PageSection({

{description && <DescriptionText>{description}</DescriptionText>}

{ctaArray && (
<div
className={clsx(
'grid gap-4',
ctaArray.length === 1
? 'lg:grid-cols-1'
: 'sm:grid-cols-2 sm:gap-3 lg:grid-cols-1 lg:gap-4',
)}
>
{ctaArray.map(
(button, index) =>
button && (
<Button
key={index}
href={button.href}
variant={index === 0 ? 'primary' : 'ghost'}
>
{button.text}
</Button>
),
)}
</div>
)}
{cta && <CTAButtonGroup cta={cta} />}
</div>

{image && (
<div className="relative aspect-video lg:aspect-auto">
<StaticImage
Expand All @@ -86,6 +63,7 @@ export function PageSection({
</div>
)}
</div>

{children && <div className="flex flex-col gap-6">{children}</div>}
</section>
)
Expand Down

0 comments on commit 255c6b9

Please sign in to comment.