Skip to content

Commit

Permalink
Initial version of Component Override V2 for the Hero Section
Browse files Browse the repository at this point in the history
  • Loading branch information
gvc committed Dec 6, 2023
1 parent 42551de commit 25a2c14
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 30 deletions.
11 changes: 11 additions & 0 deletions packages/core/src/components/sections/Hero/DefaultComponents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {
Hero as UIHero,
HeroImage as UIHeroImage,
HeroHeader as UIHeroHeader,
} from '@faststore/ui'

export const HeroDefaultComponents = {
Hero: UIHero,
HeroImage: UIHeroImage,
HeroHeader: UIHeroHeader,
}
21 changes: 12 additions & 9 deletions packages/core/src/components/sections/Hero/Hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ import {
} from '@faststore/ui'
import { ReactNode } from 'react'
import { Image } from 'src/components/ui/Image'
import {
Hero as HeroWrapper,
HeroImage,
HeroHeader,
} from 'src/components/sections/Hero/Overrides'

import { useOverrideComponents } from 'src/sdk/overrides/OverrideContext'

import Section from '../Section'

Expand Down Expand Up @@ -36,16 +33,22 @@ const Hero = ({
title,
subtitle,
image,
variant = HeroWrapper.props.variant ?? 'primary',
colorVariant = HeroWrapper.props.colorVariant ?? 'main',
variant = 'primary',
colorVariant = 'main',
icon,
}: HeroProps) => {
const {
Hero: HeroWrapper,
HeroImage,
HeroHeader,
} = useOverrideComponents<'Hero'>()

return (
<Section className={`${styles.section} section-hero`}>
<HeroWrapper.Component
{...HeroWrapper.props}
variant={variant}
colorVariant={colorVariant}
variant={HeroWrapper.props.variant ?? variant}
colorVariant={HeroWrapper.props.colorVariant ?? colorVariant}
>
<HeroImage.Component {...HeroImage.props}>
<Image
Expand Down
12 changes: 12 additions & 0 deletions packages/core/src/components/sections/Hero/OverridenDefaultHero.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { override } from 'src/customizations/src/components/overrides/Hero'
import { getOverriddenSection } from 'src/sdk/overrides/getOverriddenSection'
import type { SectionOverrideDefinition } from 'src/typings/overridesDefinition'

/**
* This component exists to support overrides 1.0
*
* This allows users to override the default Hero section present in the Headless CMS
*/
export const OverriddenDefaultHero = getOverriddenSection(
override as SectionOverrideDefinition<'Hero'>
)
20 changes: 0 additions & 20 deletions packages/core/src/components/sections/Hero/Overrides.tsx

This file was deleted.

4 changes: 4 additions & 0 deletions packages/core/src/sdk/overrides/sections.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import Alert from '../../components/sections/Alert'
import Hero from '../../components/sections/Hero'

import type { DefaultSectionComponentsDefinitions } from '../../typings/overridesDefinition'
import type { SectionsOverrides } from '../../typings/overrides'
import { AlertDefaultComponents } from '../../components/sections/Alert/DefaultComponents'
import { HeroDefaultComponents } from '../../components/sections/Hero/DefaultComponents'

export const Sections = {
Alert,
Hero,
}

export const DefaultComponents: Partial<
Expand All @@ -15,4 +18,5 @@ export const DefaultComponents: Partial<
>
> = {
Alert: AlertDefaultComponents,
Hero: HeroDefaultComponents,
}
2 changes: 1 addition & 1 deletion packages/core/src/typings/overrides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export type SectionOverride = {
}[keyof SectionsOverrides]

/** TODO: every use of this type should be replaced by SectionsOverrides after all sections are supported */
export type SupportedSectionsOverridesV2 = Pick<SectionsOverrides, 'Alert'>
export type SupportedSectionsOverridesV2 = Pick<SectionsOverrides, 'Alert' | 'Hero'>

/**
* Originally, these types were defined in their respective Overrides file
Expand Down

0 comments on commit 25a2c14

Please sign in to comment.