Skip to content

Commit

Permalink
fix(Hero): use background instead of backgroundColor to support gradi…
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoskolodny authored Apr 23, 2024
1 parent edd7173 commit f4ba119
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 22 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions src/__screenshot_tests__/hero-screenshot-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,14 @@ test('Hero - custom height', async () => {
const story = await screen.findByTestId('hero');
expect(await story.screenshot()).toMatchImageSnapshot();
});

test('Hero - background brand in O2-new skin', async () => {
await openStoryPage({
id: 'components-hero--default',
skin: 'O2-new',
args: {background: 'brand'},
});

const story = await screen.findByTestId('hero');
expect(await story.screenshot()).toMatchImageSnapshot();
});
39 changes: 36 additions & 3 deletions src/hero.css.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {createVar, fallbackVar, style} from '@vanilla-extract/css';
import {createVar, fallbackVar, style, styleVariants} from '@vanilla-extract/css';
import * as mq from './media-queries.css';
import {sprinkles} from './sprinkles.css';
import {vars as responsiveLayoutVars} from './responsive-layout.css';
import {vars as skinVars} from './skins/skin-contract.css';

const height = createVar();

Expand Down Expand Up @@ -43,11 +44,43 @@ export const layout = style({
},
});

export const mediaContainer = style({
export const contentContainer = style({
'@media': {
[mq.tabletOrSmaller]: {
width: 'auto',
margin: `0 calc(-1 * ${responsiveLayoutSideMargin})`,
margin: `0 ${responsiveLayoutSideMargin}`,
},
},
});

export const expandedContent = style({
display: 'flex',
flexDirection: 'column',
flex: 1,
});

export const contentWrapper = style([
expandedContent,
{
width: 'auto',
margin: `0 calc(-1 * ${responsiveLayoutSideMargin})`,
},
]);

export const containerBackground = styleVariants({
default: {
background: skinVars.colors.background,
},
alternative: {
background: skinVars.colors.backgroundAlternative,
},
brand: {
background: skinVars.colors.backgroundBrand,
},
'brand-secondary': {
background: skinVars.colors.backgroundBrandSecondary,
},
none: {
background: 'transparent',
},
});
41 changes: 22 additions & 19 deletions src/hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,6 @@ type HeroProps = {
desktopMediaPosition?: 'left' | 'right';
};

const BACKGROUND_COLOR = {
default: vars.colors.background,
alternative: vars.colors.backgroundAlternative,
brand: vars.colors.backgroundBrand,
'brand-secondary': vars.colors.backgroundBrandSecondary,
none: 'transparent',
};

const Hero = React.forwardRef<HTMLDivElement, HeroProps>(
(
{
Expand Down Expand Up @@ -160,7 +152,6 @@ const Hero = React.forwardRef<HTMLDivElement, HeroProps>(
{...getPrefixedDataAttributes({'component-name': 'Hero', ...dataAttributes})}
ref={ref}
style={{
backgroundColor: BACKGROUND_COLOR[background],
...(height === '100vh' ? {maxHeight: '-webkit-fill-available'} : {}), // Hack to avoid issues in Safari with 100vh
...applyCssVars({
[styles.vars.height]: height ?? '100%',
Expand All @@ -171,14 +162,24 @@ const Hero = React.forwardRef<HTMLDivElement, HeroProps>(
})}
>
<Layout isInverse={isInverse} isInsideSlideShow={isInsideSlideShow}>
<div className={styles.mediaContainer}>{media}</div>
<Box
paddingTop={24}
paddingBottom={isInsideSlideShow ? 48 : noPaddingY ? 0 : 24}
className={styles.layout}
>
<HeroContent {...rest} />
</Box>
<div className={classnames(styles.contentWrapper)}>
{media}

<div
className={classnames(
styles.containerBackground[background],
styles.expandedContent
)}
>
<Box
paddingTop={24}
paddingBottom={isInsideSlideShow ? 48 : noPaddingY ? 0 : 24}
className={classnames(styles.layout, styles.contentContainer)}
>
<HeroContent {...rest} />
</Box>
</div>
</div>
</Layout>
</div>
</div>
Expand Down Expand Up @@ -209,13 +210,15 @@ const Hero = React.forwardRef<HTMLDivElement, HeroProps>(
{...getPrefixedDataAttributes({'component-name': 'Hero', ...dataAttributes})}
ref={ref}
style={{
backgroundColor: BACKGROUND_COLOR[background],
...(height === '100vh' ? {maxHeight: '-webkit-fill-available'} : {}), // Hack to avoid issues in Safari with 100vh
...applyCssVars({
[styles.vars.height]: height ?? '100%',
}),
}}
className={sprinkles({height: '100%'})}
className={classnames(
sprinkles({height: '100%'}),
styles.containerBackground[background]
)}
>
<Layout isInverse={isInverse}>
<GridLayout
Expand Down

1 comment on commit f4ba119

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for mistica-web ready!

✅ Preview
https://mistica-4omvp5qgh-flows-projects-65bb050e.vercel.app

Built with commit f4ba119.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.