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

feat(pie-thumbnail): DSW-2583 2584 2585 Add disabled, has padding, backgroundColor and placeholder props #2168

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8f4767d
feat(pie-thumbnail): DSW-2580 add basic thumbnail functionality
Dec 27, 2024
09774ae
format(pie-thumbnail): DSW-2580 lint
Dec 27, 2024
032551a
feat(pie-thumbnail): DSW-2583 add disabled thumbnail prop
Dec 31, 2024
8e5a62a
feat(pie-thumbnail): DSW-2583 add hasPadding thumbnail prop
Dec 31, 2024
760ff98
Merge branch 'main' into dsw-2583-add-disabled-and-has-padding-props
Jan 20, 2025
0caf2c6
fix(pie-thumbnail): DSW-2583 update scss class names to match
Jan 20, 2025
64fbde9
feat(pie-thumbnail): DSW-2583 add backgroundColor prop
Jan 20, 2025
9f41b74
feat(pie-thumbnail): DSW-2583 add placeholder functionality
Jan 20, 2025
15b7822
fix(pie-thumbnail): DSW-2583 fix placeholder alt logic
Jan 21, 2025
afc4e9e
test(pie-thumbnail): DSW-2583 add component tests for placeholder beh…
Jan 21, 2025
d630c00
chore(pie-thumbnail): DSW-2583 add changeset
Jan 21, 2025
7f41839
fix(pie-thumbnail): DSW-2583 update placeholder value
Jan 21, 2025
25d8dde
format(pie-thumbnail): DSW-2583 remove id from img tag
Jan 21, 2025
6684f69
refactor(pie-thumbnail): DSW-2583 address comments
Jan 22, 2025
76bb5fe
fix(pie-thumbnail): DSW-2583 use alpha value for opacity
Jan 22, 2025
978b5d6
Merge branch 'main' into dsw-2583-add-disabled-and-has-padding-props
raoufswe Jan 22, 2025
62bb39e
refactor(pie-thumbnail): DSW-2583 address comments
Jan 24, 2025
ac90f8e
Merge branch 'main' into dsw-2583-add-disabled-and-has-padding-props
bntsv Jan 24, 2025
6e0457f
refactor(pie-thumbnail): DSW-2583 pull changes from main
Jan 24, 2025
2309518
refactor(pie-thumbnail): DSW-2583 remove box-sizing on thumbnail img
Jan 24, 2025
23f8797
test(pie-thumbnail): DSW-2583 fix tests
Jan 24, 2025
869e2be
revert
Jan 24, 2025
68e6481
feat(pie-thumbnail): DSW-2583 add visual tests for backgroundColor an…
Jan 24, 2025
025a4f5
format(pie-thumbnail): DSW-2583 remove white space from placeholder d…
Jan 24, 2025
b9d0d98
feat(pie-thumbnail): DSW-2583 add variants for background colors
Jan 24, 2025
31b5336
fix(pie-thumbnail): DSW-2583 update backgroundColors type cast
Jan 24, 2025
a065e98
format(pie-thumbnail): DSW-2583 update component test titles
Jan 24, 2025
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
6 changes: 6 additions & 0 deletions .changeset/selfish-walls-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@justeattakeaway/pie-thumbnail": minor
"pie-storybook": minor
---

[Added] - disabled, hasPadding, backgroundColor and placeholder properties to Thumbnail component
53 changes: 48 additions & 5 deletions apps/pie-storybook/stories/pie-thumbnail.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { html } from 'lit';
import { type Meta } from '@storybook/web-components';

import '@justeattakeaway/pie-thumbnail';
import { type ThumbnailProps, defaultProps, variants } from '@justeattakeaway/pie-thumbnail';
import {
type ThumbnailProps, defaultProps, variants, backgroundColors,
} from '@justeattakeaway/pie-thumbnail';

import { createStory, type TemplateFunction } from '../utilities';

Expand All @@ -12,6 +14,10 @@ const defaultArgs: ThumbnailProps = {
...defaultProps,
src: 'https://www.pie.design/assets/img/jet-logo-narrow.svg',
alt: 'JET logo',
placeholder: {
src: 'https://www.pie.design/assets/img/404_narrow.png',
alt: 'Thumbnail placeholder image',
},
};

const thumbnailStoryMeta: ThumbnailStoryMeta = {
Expand All @@ -23,21 +29,50 @@ const thumbnailStoryMeta: ThumbnailStoryMeta = {
control: 'select',
options: variants,
defaultValue: {
summary: defaultArgs.variant,
summary: defaultProps.variant,
},
},
src: {
description: 'Set the src attribute for the underlying image tag.',
control: 'text',
defaultValue: {
summary: defaultArgs.src,
summary: defaultProps.src,
},
},
alt: {
description: 'Set the alt attribute for the underlying image tag.',
control: 'text',
defaultValue: {
summary: defaultArgs.alt,
summary: defaultProps.alt,
},
},
disabled: {
description: 'Applies the disabled styling to the thumbnail component.',
control: 'boolean',
defaultValue: {
summary: defaultProps.disabled,
},
},
hasPadding: {
description: 'Adds extra space around the thumbnail container.',
control: 'boolean',
defaultValue: {
summary: defaultProps.hasPadding,
},
},
backgroundColor: {
description: 'Applies a background color to the thumbnail container.',
control: 'select',
options: backgroundColors,
defaultValue: {
summary: defaultProps.backgroundColor,
},
},
placeholder: {
description: 'If an image is unavailable, the placeholder prop can be used to ensure there is always something visible to users.',
control: 'object',
defaultValue: {
summary: defaultProps.placeholder,
},
},
},
Expand All @@ -56,11 +91,19 @@ const Template: TemplateFunction<ThumbnailProps> = ({
variant,
src,
alt,
disabled,
hasPadding,
backgroundColor,
placeholder,
}) => html`
<pie-thumbnail
variant="${variant}"
src="${src}"
alt="${alt}">
alt="${alt}"
?disabled="${disabled}"
?hasPadding="${hasPadding}"
backgroundColor="${backgroundColor}"
.placeholder="${placeholder}"
</pie-thumbnail>`;

const createThumbnailStory = createStory<ThumbnailProps>(Template, defaultArgs);
Expand Down
96 changes: 85 additions & 11 deletions apps/pie-storybook/stories/testing/pie-thumbnail.test.stories.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import { html } from 'lit';

import '@justeattakeaway/pie-thumbnail';
import { type ThumbnailProps, defaultProps, variants } from '@justeattakeaway/pie-thumbnail';
import {
type ThumbnailProps, defaultProps, variants, backgroundColors,
} from '@justeattakeaway/pie-thumbnail';

import { type Meta } from '@storybook/web-components';
import { createVariantStory, type TemplateFunction } from '../../utilities';
import { createStory, createVariantStory, type TemplateFunction } from '../../utilities';

type ThumbnailStoryMeta = Meta<ThumbnailProps>;

const defaultArgs: ThumbnailProps = {
...defaultProps,
src: 'https://www.pie.design/assets/img/jet-logo-narrow.svg',
alt: 'JET logo',
placeholder: {
src: 'https://www.pie.design/assets/img/404_narrow.png',
alt: 'Thumbnail placeholder image',
},
};

const thumbnailStoryMeta: ThumbnailStoryMeta = {
Expand All @@ -23,21 +29,50 @@ const thumbnailStoryMeta: ThumbnailStoryMeta = {
control: 'select',
options: variants,
defaultValue: {
summary: defaultArgs.variant,
summary: defaultProps.variant,
},
},
src: {
description: 'Set the src attribute for the underlying image tag.',
control: 'text',
defaultValue: {
summary: defaultArgs.src,
summary: defaultProps.src,
},
},
alt: {
description: 'Set the alt attribute for the underlying image tag.',
control: 'text',
defaultValue: {
summary: defaultArgs.alt,
summary: defaultProps.alt,
},
},
disabled: {
description: 'Applies the disabled styling to the thumbnail component.',
control: 'boolean',
defaultValue: {
summary: defaultProps.disabled,
},
},
hasPadding: {
description: 'Adds extra space around the thumbnail container.',
control: 'boolean',
defaultValue: {
summary: defaultProps.hasPadding,
},
},
backgroundColor: {
description: 'Applies a background color to the thumbnail container.',
control: 'select',
options: backgroundColors,
defaultValue: {
summary: defaultProps.backgroundColor,
},
},
placeholder: {
description: 'If an image is unavailable, the placeholder prop can be used to ensure there is always something visible to users.',
control: 'object',
defaultValue: {
summary: defaultProps.placeholder,
},
},
},
Expand All @@ -50,28 +85,67 @@ const Template: TemplateFunction<ThumbnailProps> = ({
variant,
src,
alt,
disabled,
hasPadding,
backgroundColor,
placeholder,
}) => html`
<pie-thumbnail
variant="${variant}"
src="${src}"
alt="${alt}">
alt="${alt}"
?disabled="${disabled}"
?hasPadding="${hasPadding}"
backgroundColor="${backgroundColor}"
.placeholder="${placeholder}">
</pie-thumbnail>`;

// Define the prop options for the matrix
const sharedPropOptions = {
src: ['https://www.pie.design/assets/img/jet-logo-narrow.svg'],
alt: ['JET logo'],
const sharedPropOptions: Partial<Record<keyof ThumbnailProps, unknown[]>> = {
src: [defaultArgs.src],
alt: [defaultArgs.alt],
disabled: [true, false],
hasPadding: [true, false],
backgroundColor: [defaultArgs.backgroundColor],
placeholder: [defaultArgs.placeholder],
};

const defaultPropOptions = {
const defaultPropOptions: Partial<Record<keyof ThumbnailProps, unknown[]>> = {
...sharedPropOptions,
variant: ['default'],
};

const outlinePropOptions = {
const outlinePropOptions: Partial<Record<keyof ThumbnailProps, unknown[]>> = {
...sharedPropOptions,
variant: ['outline'],
};

const backgroundPropOptions: Partial<Record<keyof ThumbnailProps, unknown[]>> = {
backgroundColor: backgroundColors,
variant: variants,
src: ['https://www.pie.design/assets/img/404_narrow.png'],
};

export const Default = createStory<ThumbnailProps>(Template, defaultArgs)();

export const InvalidSrc = createStory<ThumbnailProps>(Template, {
placeholder: {
src: 'https://www.pie.design/assets/img/404_narrow.png',
alt: 'Placeholder Alt',
},
src: 'invalid-url.com',
alt: 'Invalid text',
})();

export const InvalidPlaceholder = createStory<ThumbnailProps>(Template, {
placeholder: {
src: 'https://www.pie.design/assets/img/404_narrow.png',
alt: 'Placeholder Alt',
},
src: 'https://www.pie.design/assets/img/jet-logo-narrow.svg',
alt: 'JET Logo',
})();

export const DefaultPropVariations = createVariantStory<ThumbnailProps>(Template, defaultPropOptions);
export const OutlinePropVariations = createVariantStory<ThumbnailProps>(Template, outlinePropOptions);
export const BackgroundPropVariations = createVariantStory<ThumbnailProps>(Template, backgroundPropOptions);
22 changes: 21 additions & 1 deletion packages/components/pie-thumbnail/src/defs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,36 @@ export const variants = [
'default', 'outline',
] as const;

export const backgroundColors = [
'default', 'subtle', 'strong', 'dark', 'inverse', 'inverse-alternative'
]as const;

type PlaceholderProps = {
src?: string;
alt?: string;
}

export interface ThumbnailProps {
variant?: typeof variants[number];
src?: string;
alt?: string;
disabled?: boolean;
hasPadding?: boolean;
backgroundColor?: typeof backgroundColors[number];
placeholder?: PlaceholderProps;
}

export type DefaultProps = ComponentDefaultProps<ThumbnailProps, 'variant' | 'src' | 'alt'>;
export type DefaultProps = ComponentDefaultProps<ThumbnailProps, 'variant' | 'src' | 'alt' | 'disabled' | 'hasPadding' | 'backgroundColor' | 'placeholder'>;

export const defaultProps: DefaultProps = {
variant: 'default',
src: '',
alt: '',
disabled: false,
hasPadding: false,
backgroundColor: 'default',
placeholder: {
src: '',
alt: '',
},
};
31 changes: 29 additions & 2 deletions packages/components/pie-thumbnail/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import {
import { defineCustomElement, validPropertyValues } from '@justeattakeaway/pie-webc-core';
import { classMap } from 'lit/directives/class-map.js';
import { property } from 'lit/decorators.js';
import { type ThumbnailProps, defaultProps, variants } from './defs';
import {
type ThumbnailProps, defaultProps, variants, backgroundColors,
} from './defs';
import styles from './thumbnail.scss?inline';

// Valid values available to consumers
Expand All @@ -27,21 +29,46 @@ export class PieThumbnail extends LitElement implements ThumbnailProps {
@property({ type: String })
public alt = defaultProps.alt;

@property({ type: Boolean })
public disabled = defaultProps.disabled;

@property({ type: Boolean })
public hasPadding = defaultProps.hasPadding;

@property({ type: String })
@validPropertyValues(componentSelector, backgroundColors, defaultProps.backgroundColor)
public backgroundColor = defaultProps.backgroundColor;

@property({ type: Object })
public placeholder: ThumbnailProps['placeholder'];

private handleImageError = () => {
if (this.placeholder?.src) this.src = this.placeholder.src as string;
if (this.placeholder?.alt) this.alt = this.placeholder.alt as string;
};

render () {
const {
variant,
src,
alt,
disabled,
hasPadding,
backgroundColor,
handleImageError,
} = this;

const wrapperClasses = {
'c-thumbnail': true,
[`c-thumbnail--${variant}`]: true,
[`c-thumbnail--background-${backgroundColor}`]: true,
'c-thumbnail--disabled': disabled,
'c-thumbnail--padding': hasPadding,
};

return html`
<div data-test-id="pie-thumbnail" class="${classMap(wrapperClasses)}">
<img data-test-id="pie-thumbnail-img" src="${src}" class="c-thumbnail-img" alt="${alt}">
<img data-test-id="pie-thumbnail-img" src="${src}" class="c-thumbnail-img" alt="${alt}" @error="${handleImageError}">
</div>
`;
}
Expand Down
29 changes: 29 additions & 0 deletions packages/components/pie-thumbnail/src/thumbnail.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
--thumbnail-border-radius: var(--dt-radius-rounded-b);
--thumbnail-bg-color: var(--dt-color-container-default);
--thumbnail-border-color: transparent;
--thumbnail-padding: calc(var(--dt-spacing-a) / 2);
raoufswe marked this conversation as resolved.
Show resolved Hide resolved

box-sizing: border-box;
overflow: hidden;
Expand All @@ -16,6 +17,34 @@
--thumbnail-border-color: var(--dt-color-border-default);
}

&.c-thumbnail--disabled {
opacity: 0.5;
}

&.c-thumbnail--background-subtle {
--thumbnail-bg-color: var(--dt-color-container-subtle);
}

&.c-thumbnail--background-strong {
--thumbnail-bg-color: var(--dt-color-container-strong);
}

&.c-thumbnail--background-dark {
--thumbnail-bg-color: var(--dt-color-container-dark);
}

&.c-thumbnail--background-inverse {
--thumbnail-bg-color: var(--dt-color-container-inverse);
}

&.c-thumbnail--background-inverse-alternative {
--thumbnail-bg-color: var(--dt-color-container-inverse-alternative);
}

&.c-thumbnail--padding {
padding: var(--thumbnail-padding);
}

.c-thumbnail-img {
width: 100%;
height: 100%;
Expand Down
Loading
Loading