-
Notifications
You must be signed in to change notification settings - Fork 22
feat(CoverHero): new component #1144
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
Changes from 7 commits
a8a2a35
b5a9e8d
6d9461c
ef3a01b
fe2d62c
48dd2ed
6ab715f
f06b9aa
7050a1d
1333362
65a68fc
07aa5e7
07892d8
280a690
6fc25a0
516baf5
68cca1f
5307fa6
e8fad1f
904e361
c591980
d465585
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,197 @@ | ||
| import {openStoryPage} from '../test-utils'; | ||
|
|
||
| const cases = [ | ||
| [ | ||
| 'desktop with background image', | ||
| { | ||
| device: 'DESKTOP', | ||
| args: {background: 'image'}, | ||
| }, | ||
| ], | ||
| [ | ||
| 'desktop with background video', | ||
| { | ||
| device: 'DESKTOP', | ||
| args: {background: 'video'}, | ||
| }, | ||
| ], | ||
| [ | ||
| 'desktop with variant inverse', | ||
| { | ||
| device: 'DESKTOP', | ||
| args: {background: 'color from skin', variant: 'inverse'}, | ||
| }, | ||
| ], | ||
| [ | ||
| 'desktop with variant alternative', | ||
| { | ||
| device: 'DESKTOP', | ||
| args: {background: 'color from skin', variant: 'alternative'}, | ||
| }, | ||
| ], | ||
| [ | ||
| 'desktop with variant default', | ||
| { | ||
| device: 'DESKTOP', | ||
| args: {background: 'color from skin', variant: 'default'}, | ||
| }, | ||
| ], | ||
| [ | ||
| 'desktop with extra and sideExtra', | ||
| { | ||
| device: 'DESKTOP', | ||
| args: {withExtra: true, withSideExtra: true}, | ||
| }, | ||
| ], | ||
| [ | ||
| 'mobile with extra and sideExtra', | ||
| { | ||
| device: 'MOBILE_IOS', | ||
| args: {withExtra: true, withSideExtra: true}, | ||
| }, | ||
| ], | ||
| [ | ||
| 'tablet with extra and sideExtra', | ||
| { | ||
| device: 'TABLET', | ||
| args: {withExtra: true, withSideExtra: true}, | ||
| }, | ||
| ], | ||
| [ | ||
| 'desktop centered', | ||
| { | ||
| device: 'DESKTOP', | ||
| args: {centered: true}, | ||
| }, | ||
| ], | ||
| [ | ||
| 'mobile centered', | ||
| { | ||
| device: 'MOBILE_IOS', | ||
| args: {centered: true}, | ||
| }, | ||
| ], | ||
| [ | ||
| 'desktop centered with extra and sideExtra', | ||
| { | ||
| device: 'DESKTOP', | ||
| args: {centered: true, withExtra: true, withSideExtra: true}, | ||
| }, | ||
| ], | ||
| [ | ||
| 'mobile centered with extra and sideExtra', | ||
| { | ||
| device: 'MOBILE_IOS', | ||
| args: {centered: true, withExtra: true, withSideExtra: true}, | ||
| }, | ||
| ], | ||
| [ | ||
| 'desktop one button', | ||
| { | ||
| device: 'DESKTOP', | ||
| args: {actions: 'button'}, | ||
| }, | ||
| ], | ||
| [ | ||
| 'desktop one link', | ||
| { | ||
| device: 'DESKTOP', | ||
| args: {actions: 'link'}, | ||
| }, | ||
| ], | ||
| [ | ||
| 'desktop long text', | ||
| { | ||
| device: 'DESKTOP', | ||
| args: { | ||
| title: 'Long title '.repeat(10), | ||
| description: 'This is a long description with a long text to see how this works'.repeat(10), | ||
| }, | ||
| }, | ||
| ], | ||
| [ | ||
| 'desktop long text with sideExtra', | ||
| { | ||
| device: 'DESKTOP', | ||
| args: { | ||
| title: 'Long title '.repeat(10), | ||
| description: 'This is a long description with a long text to see how this works'.repeat(10), | ||
| withSideExtra: true, | ||
| }, | ||
| }, | ||
| ], | ||
| [ | ||
| 'mobile long text', | ||
| { | ||
| device: 'MOBILE_IOS', | ||
| args: { | ||
| title: 'Long title '.repeat(10), | ||
| description: 'This is a long description with a long text to see how this works'.repeat(10), | ||
| }, | ||
| }, | ||
| ], | ||
| [ | ||
| 'desktop 16:9 aspect ratio', | ||
| { | ||
| device: 'DESKTOP', | ||
| args: { | ||
| aspectRatio: '16 9', | ||
| }, | ||
| }, | ||
| ], | ||
| [ | ||
| 'mobile 7:10 aspect ratio', | ||
| { | ||
| device: 'MOBILE_IOS', | ||
| args: { | ||
| aspectRatio: '7 10', | ||
| }, | ||
| }, | ||
| ], | ||
| [ | ||
| 'mobile minHeight 100vh', | ||
| { | ||
| device: 'MOBILE_IOS', | ||
| args: { | ||
| minHeight: '100vh', | ||
| }, | ||
| }, | ||
| ], | ||
| [ | ||
| 'desktop minimal', | ||
| { | ||
| device: 'DESKTOP', | ||
| args: { | ||
| headline: '', | ||
| pretitle: '', | ||
| title: 'Title', | ||
| description: '', | ||
| actions: 'button', | ||
| }, | ||
| }, | ||
| ], | ||
| [ | ||
| 'mobile minimal', | ||
| { | ||
| device: 'MOBILE_IOS', | ||
| args: { | ||
| headline: '', | ||
| pretitle: '', | ||
| title: 'Title', | ||
| description: '', | ||
| actions: 'button', | ||
| }, | ||
| }, | ||
| ], | ||
| ] as const; | ||
|
|
||
| test.each(cases)('CoverHero %s', async (_name, {device, args}) => { | ||
| const page = await openStoryPage({ | ||
| id: 'components-hero-coverhero--default', | ||
| device, | ||
| args, | ||
| }); | ||
|
|
||
| const image = await page.screenshot(); | ||
| expect(image).toMatchImageSnapshot(); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| import * as React from 'react'; | ||
| import {CoverHero, ButtonPrimary, ButtonLink, Tag, Placeholder, skinVars} from '..'; | ||
| import usingVrImg from './images/using-vr.jpg'; | ||
| import beachImg from './images/beach.jpg'; | ||
| import beachVideo from './videos/beach.mp4'; | ||
|
|
||
| import type {TagType} from '..'; | ||
|
|
||
| export default { | ||
| title: 'Components/Hero/CoverHero', | ||
| parameters: { | ||
| fullScreen: true, | ||
| }, | ||
| }; | ||
|
|
||
| type Args = { | ||
| background: 'image' | 'video' | 'custom color' | 'color from skin'; | ||
| backgroundColorCustom: string; | ||
| backgroundColorFromSkin: string; | ||
| variant: 'default' | 'inverse' | 'alternative'; | ||
| headlineType: TagType; | ||
| headline: string; | ||
| pretitle: string; | ||
| title: string; | ||
| description: string; | ||
| withExtra: boolean; | ||
| withSideExtra: boolean; | ||
| actions: 'button' | 'link' | 'button and link'; | ||
|
atabel marked this conversation as resolved.
Outdated
|
||
| minHeight: string | undefined; | ||
| aspectRatio: '1:1' | '16:9' | '7:10' | '4:3' | 'auto'; | ||
| centered: boolean; | ||
| noPaddingY: boolean; | ||
| }; | ||
|
|
||
| export const Default: StoryComponent<Args> = ({ | ||
| background, | ||
| backgroundColorCustom, | ||
| backgroundColorFromSkin, | ||
| variant, | ||
| headlineType, | ||
| headline, | ||
| pretitle, | ||
| title, | ||
| description, | ||
| withExtra, | ||
| withSideExtra, | ||
| actions, | ||
| minHeight, | ||
| aspectRatio, | ||
| centered, | ||
| noPaddingY, | ||
| }) => { | ||
| const backgroundProps = | ||
| background === 'image' | ||
| ? { | ||
| backgroundImage: usingVrImg, | ||
| } | ||
| : background === 'video' | ||
| ? { | ||
| backgroundVideo: beachVideo, | ||
| poster: beachImg, | ||
| } | ||
| : { | ||
| backgroundColor: backgroundColorFromSkin || backgroundColorCustom, | ||
| variant, | ||
| }; | ||
|
|
||
| const button = actions.includes('button') ? <ButtonPrimary fake>Action</ButtonPrimary> : undefined; | ||
| const buttonLink = actions.includes('link') ? <ButtonLink href="#">Link</ButtonLink> : undefined; | ||
|
|
||
| return ( | ||
| <CoverHero | ||
| headline={headline ? <Tag type={headlineType}>{headline}</Tag> : undefined} | ||
| pretitle={pretitle} | ||
| title={title} | ||
| description={description} | ||
| extra={withExtra ? <Placeholder /> : undefined} | ||
| sideExtra={withSideExtra ? <Placeholder /> : undefined} | ||
| button={button} | ||
| buttonLink={buttonLink} | ||
| minHeight={minHeight} | ||
| aspectRatio={aspectRatio} | ||
| centered={centered} | ||
| noPaddingY={noPaddingY} | ||
| {...backgroundProps} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| Default.storyName = 'CoverHero'; | ||
|
|
||
| Default.args = { | ||
| background: 'image', | ||
| backgroundColorCustom: '', | ||
| backgroundColorFromSkin: '', | ||
| variant: 'default', | ||
| headlineType: 'promo', | ||
| headline: 'Hero', | ||
| pretitle: 'Pretitle', | ||
| title: 'Title', | ||
| description: 'This is a long description with a long text to see how this works', | ||
| withExtra: false, | ||
| withSideExtra: false, | ||
| actions: 'button and link', | ||
| minHeight: undefined, | ||
| aspectRatio: 'auto', | ||
| centered: false, | ||
| noPaddingY: false, | ||
| }; | ||
|
|
||
| Default.argTypes = { | ||
| headlineType: { | ||
| options: ['promo', 'active', 'inactive', 'success', 'warning', 'error'], | ||
| control: {type: 'select'}, | ||
| }, | ||
| background: { | ||
| options: ['image', 'video', 'color from skin', 'custom color'], | ||
| control: {type: 'select'}, | ||
| }, | ||
| backgroundColorCustom: { | ||
| control: {type: 'color'}, | ||
| if: {arg: 'background', eq: 'custom color'}, | ||
| }, | ||
| backgroundColorFromSkin: { | ||
| control: {type: 'select'}, | ||
| options: {'none (determined by variant)': '', ...skinVars.colors}, | ||
| if: {arg: 'background', eq: 'color from skin'}, | ||
| }, | ||
| variant: { | ||
| options: ['default', 'inverse', 'alternative'], | ||
| control: {type: 'select'}, | ||
| // this control should only be visible when background is set to 'color from skin' or 'custom color' | ||
| // if: {arg: 'background', eq: 'color'}, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a missing storybook feature. I can configure the variant control to appear when background is
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it's a very annoying thing from Storybook, but why leaving this commented line? I'd remove it
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just to document the intention, but I can remove it
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've rewritten the comment with a better explanation and added a reference to this PR: ComponentDriven/csf#76 |
||
| }, | ||
| actions: { | ||
| options: ['button', 'link', 'button and link'], | ||
| control: {type: 'select'}, | ||
| }, | ||
| minHeight: { | ||
| control: {type: 'text'}, | ||
| }, | ||
| aspectRatio: { | ||
| options: ['1 1', '16 9', '7 10', '4 3', 'auto'], | ||
| mapping: { | ||
| '1 1': '1:1', | ||
| '16 9': '16:9', | ||
| '7 10': '7:10', | ||
| '4 3': '4:3', | ||
| }, | ||
| control: { | ||
| type: 'select', | ||
| labels: { | ||
| '1 1': '1:1', | ||
| '16 9': '16:9', | ||
| '7 10': '7:10', | ||
| '4 3': '4:3', | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.