-
Notifications
You must be signed in to change notification settings - Fork 8
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
feat(pie-thumbnail): DSW-2580 add basic thumbnail functionality #2138
Open
bntsv
wants to merge
8
commits into
main
Choose a base branch
from
dsw-2580-add-basic-thumbnail-functionality
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+202
−42
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c45ca33
feat(pie-thumbnail): DSW-2580 add basic thumbnail functionality
e402b05
format(pie-thumbnail): DSW-2580 lint
24cbcc5
test(pie-thumbnail): DSW-2580 add visual tests
737345f
test(pie-thumbnail): DSW-2580 update visual tests
3a48b44
refactor(pie-thumbnail): DSW-2580 address comments
a57aedf
refactor(pie-thumbnail): DSW-2580 remove placeholder image from story…
793c6bf
chore(pie-thumbnail): DSW-2580 update changelog
46438fb
refactor(pie-thumbnail): DSW-2580 add default src and alt props to vi…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@justeattakeaway/pie-thumbnail": minor | ||
"pie-storybook": minor | ||
--- | ||
|
||
added basic functionality of thumbnail component |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 59 additions & 16 deletions
75
apps/pie-storybook/stories/testing/pie-thumbnail.test.stories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,77 @@ | ||
import { html } from 'lit'; | ||
import { type Meta } from '@storybook/web-components'; | ||
|
||
import '@justeattakeaway/pie-thumbnail'; | ||
import { type ThumbnailProps } from '@justeattakeaway/pie-thumbnail'; | ||
import { type ThumbnailProps, defaultProps, variants } from '@justeattakeaway/pie-thumbnail'; | ||
|
||
import { createStory } from '../../utilities'; | ||
import { type Meta } from '@storybook/web-components'; | ||
import { createVariantStory, type TemplateFunction } from '../../utilities'; | ||
|
||
type ThumbnailStoryMeta = Meta<ThumbnailProps>; | ||
|
||
const defaultArgs: ThumbnailProps = {}; | ||
const defaultArgs: ThumbnailProps = { | ||
...defaultProps, | ||
src: 'https://www.takeaway.com/consumer-web/images/takeaway-brand.61e55e0b.svg', | ||
alt: 'JET logo', | ||
}; | ||
|
||
const thumbnailStoryMeta: ThumbnailStoryMeta = { | ||
title: 'Thumbnail', | ||
component: 'pie-thumbnail', | ||
argTypes: {}, | ||
args: defaultArgs, | ||
raoufswe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
parameters: { | ||
design: { | ||
type: 'figma', | ||
url: '', | ||
argTypes: { | ||
variant: { | ||
description: 'Set the variant of the thumbnail.', | ||
control: 'select', | ||
options: variants, | ||
defaultValue: { | ||
summary: defaultArgs.variant, | ||
}, | ||
}, | ||
src: { | ||
description: 'Set the src attribute for the underlying image tag.', | ||
control: 'text', | ||
defaultValue: { | ||
summary: defaultArgs.src, | ||
}, | ||
}, | ||
alt: { | ||
description: 'Set the alt attribute for the underlying image tag.', | ||
control: 'text', | ||
defaultValue: { | ||
summary: defaultArgs.alt, | ||
}, | ||
}, | ||
}, | ||
args: defaultArgs, | ||
}; | ||
|
||
export default thumbnailStoryMeta; | ||
|
||
// TODO: remove the eslint-disable rule when props are added | ||
// eslint-disable-next-line no-empty-pattern | ||
const Template = ({}: ThumbnailProps) => html` | ||
<pie-thumbnail></pie-thumbnail> | ||
`; | ||
const Template: TemplateFunction<ThumbnailProps> = ({ | ||
variant, | ||
src, | ||
alt, | ||
}) => html` | ||
<pie-thumbnail | ||
variant="${variant}" | ||
src="${src}" | ||
alt="${alt}"> | ||
</pie-thumbnail>`; | ||
|
||
// Define the prop options for the matrix | ||
const sharedPropOptions = { | ||
src: ['https://www.takeaway.com/consumer-web/images/takeaway-brand.61e55e0b.svg'], | ||
alt: ['JET logo'], | ||
}; | ||
|
||
const defaultPropOptions = { | ||
...sharedPropOptions, | ||
variant: ['default'], | ||
}; | ||
|
||
const outlinePropOptions = { | ||
...sharedPropOptions, | ||
variant: ['outline'], | ||
}; | ||
|
||
export const Default = createStory<ThumbnailProps>(Template, defaultArgs)(); | ||
export const DefaultPropVariations = createVariantStory<ThumbnailProps>(Template, defaultPropOptions); | ||
export const OutlinePropVariations = createVariantStory<ThumbnailProps>(Template, outlinePropOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,19 @@ | ||
// TODO - please remove the eslint disable comment below when you add props to this interface | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface ThumbnailProps {} | ||
import type { ComponentDefaultProps } from '@justeattakeaway/pie-webc-core'; | ||
|
||
export const variants = [ | ||
'default', 'outline', | ||
] as const; | ||
|
||
export interface ThumbnailProps { | ||
variant?: typeof variants[number]; | ||
src?: string; | ||
alt?: string; | ||
} | ||
|
||
export type DefaultProps = ComponentDefaultProps<ThumbnailProps, 'variant' | 'src' | 'alt'>; | ||
|
||
export const defaultProps: DefaultProps = { | ||
variant: 'default', | ||
src: '', | ||
alt: '', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,28 @@ | ||
@use '@justeattakeaway/pie-css/scss' as p; | ||
|
||
// Base thumbnail styles | ||
.c-thumbnail { | ||
--thumbnail-size-small: var(--dt-spacing-g); | ||
--thumbnail-border-radius-small: var(--dt-radius-rounded-b); | ||
--thumbnail-bg-color: var(--dt-color-container-default); | ||
--thumbnail-border-outline: 1px solid var(--dt-color-border-default); | ||
|
||
&.c-thumbnail--outline { | ||
--thumbnail-border: var(--thumbnail-border-outline); | ||
} | ||
|
||
box-sizing: border-box; | ||
width: var(--thumbnail-size-small); | ||
height: var(--thumbnail-size-small); | ||
border-radius: var(--thumbnail-border-radius-small); | ||
border: var(--thumbnail-border); | ||
background-color: var(--thumbnail-bg-color); | ||
} | ||
|
||
.c-thumbnail-img { | ||
width: 100%; | ||
height: 100%; | ||
object-fit: contain; | ||
display: block; | ||
border-radius: var(--thumbnail-border-radius-small); | ||
} |
17 changes: 9 additions & 8 deletions
17
packages/components/pie-thumbnail/test/visual/pie-thumbnail.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
import { test } from '@playwright/test'; | ||
import percySnapshot from '@percy/playwright'; | ||
import { percyWidths } from '@justeattakeaway/pie-webc-testing/src/percy/breakpoints.ts'; | ||
import { BasePage } from '@justeattakeaway/pie-webc-testing/src/helpers/page-object/base-page.ts'; | ||
import { variants } from '../../src/defs.ts'; | ||
|
||
test.describe('PieThumbnail - Visual tests`', () => { | ||
test('should display the PieThumbnail component successfully', async ({ page }) => { | ||
const basePage = new BasePage(page, 'thumbnail--default'); | ||
variants.forEach((variant) => test(`should render all prop variations for Variant: ${variant}`, async ({ page }) => { | ||
const basePage = new BasePage(page, `thumbnail--${variant}-prop-variations`); | ||
|
||
basePage.load(); | ||
await page.waitForTimeout(2500); | ||
basePage.load(); | ||
|
||
await percySnapshot(page, 'PieThumbnail - Visual Test'); | ||
}); | ||
}); | ||
await page.waitForTimeout(5000); | ||
|
||
await percySnapshot(page, `PIE Thumbnail - Variant: ${variant}`, percyWidths); | ||
})); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we need to revert this line and assign the default values from the component itself
it will be something like
const defaultArgs: ThumbnailProps = { ...defaultProps, };
and defaultProps is imported from '@justeattakeaway/pie-thumbnail'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The defaults for storybook are
do you think we should use the same for tests? (Component defaults for src and alt are now empty strings)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we can use the same for tests