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

add theme to custom components #118

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
58 changes: 34 additions & 24 deletions src/components/Typography.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,30 +103,40 @@ export const ResponsiveText = styled.h2.withConfig(textPropFilter)<{
}
})

export const Hero1 = styled.h1<{ $color?: ColorKey }>(({ theme, $color }) => ({
...theme.partials.marketingText.hero1,
color: $color && (theme.colors[$color] as string),
}))
export const Hero1 = styled.h1<{ $color?: ColorKey }>(
({ theme, $color = 'text' }) => ({
...theme.partials.marketingText.hero1,
color: $color && (theme.colors[$color] as string),
})
)

export const Hero2 = styled.h2<{ $color?: ColorKey }>(({ theme, $color }) => ({
...theme.partials.marketingText.hero2,
color: $color && (theme.colors[$color] as string),
}))
export const Hero2 = styled.h2<{ $color?: ColorKey }>(
({ theme, $color = 'text' }) => ({
...theme.partials.marketingText.hero2,
color: $color && (theme.colors[$color] as string),
})
)

export const Title1 = styled.h3<{ $color?: ColorKey }>(({ theme, $color }) => ({
...theme.partials.marketingText.title1,
color: $color && (theme.colors[$color] as string),
}))
export const Title1 = styled.h3<{ $color?: ColorKey }>(
({ theme, $color = 'text' }) => ({
...theme.partials.marketingText.title1,
color: $color && (theme.colors[$color] as string),
})
)

export const Title2 = styled.h4<{ $color?: ColorKey }>(({ theme, $color }) => ({
...theme.partials.marketingText.title2,
color: $color && (theme.colors[$color] as string),
}))
export const Title2 = styled.h4<{ $color?: ColorKey }>(
({ theme, $color = 'text' }) => ({
...theme.partials.marketingText.title2,
color: $color && (theme.colors[$color] as string),
})
)

export const Body1 = styled.p<{ $color?: ColorKey }>(({ theme, $color }) => ({
...theme.partials.marketingText.body1,
color: $color && (theme.colors[$color] as string),
}))
export const Body1 = styled.p<{ $color?: ColorKey }>(
({ theme, $color = 'text-light' }) => ({
...theme.partials.marketingText.body1,
color: theme.colors[$color] as string,
})
)

export const Body2 = styled.p<{ $color?: ColorKey }>(
({ theme, $color = 'text-light' }) => ({
Expand All @@ -136,16 +146,16 @@ export const Body2 = styled.p<{ $color?: ColorKey }>(
)

export const Subtitle1 = styled.p<{ $color?: ColorKey }>(
({ theme, $color }) => ({
({ theme, $color = 'text' }) => ({
...theme.partials.marketingText.subtitle1,
color: $color && (theme.colors[$color] as string),
color: theme.colors[$color] as string,
})
)

export const Subtitle2 = styled.p<{ $color?: ColorKey }>(
({ theme, $color }) => ({
({ theme, $color = 'text' }) => ({
...theme.partials.marketingText.subtitle2,
color: $color && (theme.colors[$color] as string),
color: theme.colors[$color] as string,
})
)

Expand Down
2 changes: 1 addition & 1 deletion src/components/custom-page/Hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function Hero({
form,
}: HeroComponentFragment) {
return (
<section className={cn(getSpacingClassName(spacing), 'mx-xxxxxxlarge')}>
<section className={cn(getSpacingClassName(spacing), 'px-xxxxxxlarge')}>
<Flex gap="xxxlarge">
<Flex
flex={1}
Expand Down
4 changes: 2 additions & 2 deletions src/components/custom-page/TwoColumnText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export function TwoColumnText({
'mx-xxxxxxlarge flex gap-xxlarge'
)}
>
<div className="w-2/3">
<div className="w-2/3 text-text-light">
<Markdown text={mainContent} />
</div>
<div className="w-1/3">
<div className="w-1/3 text-text-light">
<Markdown text={sideContent} />
</div>
</section>
Expand Down
60 changes: 46 additions & 14 deletions src/components/custom-page/common.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import { type ReactElement } from 'react'

import { styledThemeDark, styledThemeLight } from '@pluralsh/design-system'

import { colorsToCSSVars } from '@pluralsh/design-system/dist/GlobalStyle'
import styled, { ThemeProvider } from 'styled-components'

import { type CustomPageFragment } from '@src/generated/graphqlDirectus'

import { BlogCards } from './BlogCards'
Expand All @@ -12,9 +19,9 @@ import { SectionHeader } from './SectionHeader'
import { TwoColumnText } from './TwoColumnText'

const spacingToClassName = {
relaxed: 'my-[192px]',
normal: 'my-[96px]',
compact: 'my-[48px]',
relaxed: 'py-[192px]',
normal: 'py-[96px]',
compact: 'py-[48px]',
}

export const getSpacingClassName = (spacing: Nullable<string>) =>
Expand All @@ -25,28 +32,53 @@ export function renderComponent(
NonNullable<CustomPageFragment['components']>[number]
>['item']
) {
let renderedComponent: ReactElement | null = null
const theme = component?.theme ?? 'dark'

switch (component?.__typename) {
case 'hero':
return <Hero {...component} />
renderedComponent = <Hero {...component} />
break
case 'logo_strip':
return <LogoStrip {...component} />
renderedComponent = <LogoStrip {...component} />
break
case 'section_header':
return <SectionHeader {...component} />
renderedComponent = <SectionHeader {...component} />
break
case 'large_image':
return <LargeImage {...component} />
renderedComponent = <LargeImage {...component} />
break
case 'cards':
return <Cards {...component} />
renderedComponent = <Cards {...component} />
break
case 'blog_cards':
return <BlogCards {...component} />
renderedComponent = <BlogCards {...component} />
break
case 'two_column_text':
return <TwoColumnText {...component} />
renderedComponent = <TwoColumnText {...component} />
break
case 'multi_column_text':
return <MultiColumnText {...component} />
renderedComponent = <MultiColumnText {...component} />
break
case 'customer_quote':
return <CustomerQuote {...component} />
renderedComponent = <CustomerQuote {...component} />
break
case 'cta':
return <CallToAction {...component} />
renderedComponent = <CallToAction {...component} />
break
default:
return null
break
}
const styles = theme === 'light' ? styledThemeLight : styledThemeDark

return (
<ThemeProvider theme={styles}>
<ComponentWrapperSC>{renderedComponent}</ComponentWrapperSC>
</ThemeProvider>
)
}

const ComponentWrapperSC = styled.div(({ theme }) => ({
backgroundColor: theme.colors['fill-zero'],
...colorsToCSSVars(theme.colors),
}))
Loading
Loading