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-2578 add pie thumbnail skeleton #2112

Merged
merged 7 commits into from
Dec 12, 2024
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
5 changes: 5 additions & 0 deletions .changeset/happy-beds-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@justeattakeaway/pie-thumbnail": minor
---

[Added] - Created skeleton component
2 changes: 2 additions & 0 deletions .github/project-labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,5 @@ pie-webc-testing:
- 'packages/components/pie-webc-testing/**/*'
pie-toast-provider:
- packages/components/pie-toast-provider/**/*
pie-thumbnail:
- packages/components/pie-thumbnail/**/*
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ env:
PERCY_PAGE_LOAD_TIMEOUT: ${{ vars.PERCY_PAGE_LOAD_TIMEOUT }}
PERCY_NETWORK_IDLE_WAIT_TIMEOUT: ${{ vars.PERCY_NETWORK_IDLE_WAIT_TIMEOUT }}
PERCY_TOKEN_PIE_TOAST_PROVIDER: ${{ secrets.PERCY_TOKEN_PIE_TOAST_PROVIDER }}
PERCY_TOKEN_PIE_THUMBNAIL: ${{ secrets.PERCY_TOKEN_PIE_THUMBNAIL }}

jobs:
check-change-type:
Expand Down
1 change: 1 addition & 0 deletions apps/pie-storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@justeattakeaway/pie-tag": "0.12.0",
"@justeattakeaway/pie-text-input": "0.24.6",
"@justeattakeaway/pie-textarea": "0.13.1",
"@justeattakeaway/pie-thumbnail": "0.0.0",
"@justeattakeaway/pie-toast": "0.5.2",
"@justeattakeaway/pie-toast-provider": "0.0.0",
"dompurify": "3.1.3"
Expand Down
34 changes: 34 additions & 0 deletions apps/pie-storybook/stories/pie-thumbnail.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { html } from 'lit';
import { type Meta } from '@storybook/web-components';

import '@justeattakeaway/pie-thumbnail';
import { type ThumbnailProps } from '@justeattakeaway/pie-thumbnail';

import { createStory } from '../utilities';

type ThumbnailStoryMeta = Meta<ThumbnailProps>;

const defaultArgs: ThumbnailProps = {};

const thumbnailStoryMeta: ThumbnailStoryMeta = {
title: 'Thumbnail',
component: 'pie-thumbnail',
argTypes: {},
args: defaultArgs,
parameters: {
design: {
type: 'figma',
url: '',
},
},
};

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>
`;

export const Default = createStory<ThumbnailProps>(Template, defaultArgs)();
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { html } from 'lit';
import { type Meta } from '@storybook/web-components';

import '@justeattakeaway/pie-thumbnail';
import { type ThumbnailProps } from '@justeattakeaway/pie-thumbnail';

import { createStory } from '../../utilities';

type ThumbnailStoryMeta = Meta<ThumbnailProps>;

const defaultArgs: ThumbnailProps = {};

const thumbnailStoryMeta: ThumbnailStoryMeta = {
title: 'Thumbnail',
component: 'pie-thumbnail',
argTypes: {},
args: defaultArgs,
parameters: {
design: {
type: 'figma',
url: '',
},
},
};

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>
`;

export const Default = createStory<ThumbnailProps>(Template, defaultArgs)();
4 changes: 4 additions & 0 deletions bundlewatch.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@
{
"path": "./packages/components/pie-toast-provider/dist/*.js",
"maxSize": "3 KB"
},
{
"path": "./packages/components/pie-thumbnail/dist/*.js",
"maxSize": "3 KB"
}
],
"defaultCompression": "gzip",
Expand Down
6 changes: 6 additions & 0 deletions packages/components/pie-thumbnail/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.turbo
dist
node_modules
lit-browsers-report
lit-visual-report
test-results
91 changes: 91 additions & 0 deletions packages/components/pie-thumbnail/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<p align="center">
<img align="center" src="../../../readme_image.png" height="200" alt="">
</p>

<p align="center">
<a href="https://www.npmjs.com/@justeattakeaway/pie-thumbnail">
<img alt="GitHub Workflow Status" src="https://img.shields.io/npm/v/@justeattakeaway/pie-thumbnail.svg">
</a>
</p>

# Table of Contents

1. [Introduction](#pie-thumbnail)
2. [Installation](#installation)
3. [Importing the component](#importing-the-component)
4. [Peer Dependencies](#peer-dependencies)
5. [Props](#props)
6. [Contributing](#contributing)

## pie-thumbnail

`pie-thumbnail` is a Web Component built using the Lit library.

This component can be easily integrated into various frontend frameworks and customized through a set of properties.


## Installation

To install `pie-thumbnail` in your application, run the following on your command line:

```bash
# npm
$ npm i @justeattakeaway/pie-thumbnail

# yarn
$ yarn add @justeattakeaway/pie-thumbnail
```

For full information on using PIE components as part of an application, check out the [Getting Started Guide](https://github.com/justeattakeaway/pie/wiki/Getting-started-with-PIE-Web-Components).


### Importing the component

#### JavaScript
```js
// Default – for Native JS Applications, Vue, Angular, Svelte, etc.
import { PieThumbnail } from '@justeattakeaway/pie-thumbnail';

// If you don't need to reference the imported object, you can simply
// import the module which registers the component as a custom element.
import '@justeattakeaway/pie-thumbnail';
```

#### React
```js
// React
// For React, you will need to import our React-specific component build
// which wraps the web component using ​@lit/react
import { PieThumbnail } from '@justeattakeaway/pie-thumbnail/dist/react';
```

> [!NOTE]
> When using the React version of the component, please make sure to also
> include React as a [peer dependency](#peer-dependencies) in your project.


## Peer Dependencies

> [!IMPORTANT]
> When using `pie-thumbnail`, you will also need to include a couple of dependencies to ensure the component renders as expected. See [the PIE Wiki](https://github.com/justeattakeaway/pie/wiki/Getting-started-with-PIE-Web-Components#expected-dependencies) for more information and how to include these in your application.


## Props

| Property | Type | Default | Description |
|---|---|---|---|
| - | - | - | - |

In your markup or JSX, you can then use these to set the properties for the `pie-thumbnail` component:

```html
<!-- Native HTML -->
<pie-thumbnail></pie-thumbnail>

<!-- JSX -->
<PieThumbnail></PieThumbnail>
```

## Contributing

Check out our [contributing guide](https://github.com/justeattakeaway/pie/wiki/Contributing-Guide) for more information on [local development](https://github.com/justeattakeaway/pie/wiki/Contributing-Guide#local-development) and how to run specific [component tests](https://github.com/justeattakeaway/pie/wiki/Contributing-Guide#testing).
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { moduleFileExtensionsPlugin } from 'cem-plugin-module-file-extensions';

export default {
globs: [
'./src/**/!(*.css).ts',
],
exclude: [
'**/*.d.ts',
'**/*.d.js',
'**/react.ts',
'**/test/**',
'**/node_modules/**',
],
plugins: [moduleFileExtensionsPlugin()],
};
9 changes: 9 additions & 0 deletions packages/components/pie-thumbnail/declaration.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
declare module '*.scss' {
const content: Record<string, string>;
export default content;
}

declare module '*.scss?inline' {
const content: Record<string, string>;
export default content;
}
52 changes: 52 additions & 0 deletions packages/components/pie-thumbnail/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "@justeattakeaway/pie-thumbnail",
"description": "PIE Design System Thumbnail built using Web Components",
"version": "0.0.0",
"type": "module",
"main": "dist/index.js",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"custom-elements.json",
"src",
"dist",
"**/*.d.ts"
],
"pieMetadata": {
"componentStatus": "alpha"
},
"scripts": {
"build": "run -T vite build",
"build:react-wrapper": "npx build-react-wrapper",
"create:manifest": "yarn cem analyze --litelement",
"lint:scripts": "run -T eslint .",
"lint:scripts:fix": "yarn lint:scripts --fix",
"lint:style": "run -T stylelint ./src/**/*.{css,scss}",
"lint:style:fix": "yarn lint:style --fix",
"watch": "run -T vite build --watch",
"test": "echo \"Error: no test specified\" && exit 0",
"test:ci": "yarn test",
"test:browsers": "npx playwright test -c ./playwright-lit.config.ts",
"test:browsers:ci": "yarn test:browsers",
"test:visual": "run -T cross-env-shell PERCY_TOKEN=${PERCY_TOKEN_PIE_THUMBNAIL} percy exec --allowed-hostname cloudfront.net -- npx playwright test -c ./playwright-lit-visual.config.ts",
"test:visual:ci": "yarn test:visual"
},
"author": "Just Eat Takeaway.com - Design System Team",
"license": "Apache-2.0",
"devDependencies": {
"@custom-elements-manifest/analyzer": "0.9.0",
"@justeattakeaway/pie-components-config": "0.18.0",
"@justeattakeaway/pie-css": "0.13.1",
"cem-plugin-module-file-extensions": "0.0.5"
},
"dependencies": {
"@justeattakeaway/pie-webc-core": "0.24.2"
},
"volta": {
"extends": "../../../package.json"
},
"customElements": "custom-elements.json",
"sideEffects": [
"dist/*.js"
]
}
34 changes: 34 additions & 0 deletions packages/components/pie-thumbnail/pie-thumbnail.test.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { html } from 'lit';
import { type Meta } from '@storybook/web-components';

import '@justeattakeaway/pie-thumbnail';
import { type ThumbnailProps } from '@justeattakeaway/pie-thumbnail';

import { createStory } from '../../utilities';

type ThumbnailStoryMeta = Meta<ThumbnailProps>;

const defaultArgs: ThumbnailProps = {};

const thumbnailStoryMeta: ThumbnailStoryMeta = {
title: 'Thumbnail',
component: 'pie-thumbnail',
argTypes: {},
args: defaultArgs,
parameters: {
design: {
type: 'figma',
url: '',
},
},
};

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>
`;

export const Default = createStory<ThumbnailProps>(Template, defaultArgs)();
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineConfig } from '@playwright/test';
import { getPlaywrightNativeVisualConfig } from '@justeattakeaway/pie-components-config';

export default defineConfig(getPlaywrightNativeVisualConfig());

4 changes: 4 additions & 0 deletions packages/components/pie-thumbnail/playwright-lit.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { defineConfig } from '@playwright/test';
import { getPlaywrightNativeConfig } from '@justeattakeaway/pie-components-config';

export default defineConfig(getPlaywrightNativeConfig());
8 changes: 8 additions & 0 deletions packages/components/pie-thumbnail/src/defs-react.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type React from 'react';
/**
* TODO: Verify if ReactBaseType can be set as a more specific React interface
* Use the React IntrinsicElements interface to find how to map standard HTML elements to existing React Interfaces
* Example: an HTML button maps to `React.ButtonHTMLAttributes<HTMLButtonElement>`
* https://github.com/DefinitelyTyped/DefinitelyTyped/blob/0bb210867d16170c4a08d9ce5d132817651a0f80/types/react/index.d.ts#L2829
*/
export type ReactBaseType = React.HTMLAttributes<HTMLElement>
3 changes: 3 additions & 0 deletions packages/components/pie-thumbnail/src/defs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// 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 {}
30 changes: 30 additions & 0 deletions packages/components/pie-thumbnail/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { LitElement, html, unsafeCSS } from 'lit';

import { defineCustomElement } from '@justeattakeaway/pie-webc-core';
import styles from './thumbnail.scss?inline';
import { type ThumbnailProps } from './defs';

// Valid values available to consumers
export * from './defs';

const componentSelector = 'pie-thumbnail';

/**
* @tagname pie-thumbnail
*/
export class PieThumbnail extends LitElement implements ThumbnailProps {
render () {
return html`<h1 data-test-id="pie-thumbnail">Hello world!</h1>`;
}

// Renders a `CSSResult` generated from SCSS by Vite
static styles = unsafeCSS(styles);
}

defineCustomElement(componentSelector, PieThumbnail);

declare global {
interface HTMLElementTagNameMap {
[componentSelector]: PieThumbnail;
}
}
1 change: 1 addition & 0 deletions packages/components/pie-thumbnail/src/thumbnail.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@use '@justeattakeaway/pie-css/scss' as p;
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { test, expect } from '@justeattakeaway/pie-webc-testing/src/playwright/playwright-fixtures.ts';
import { BasePage } from '@justeattakeaway/pie-webc-testing/src/helpers/page-object/base-page.ts';
import { PieThumbnail } from '../../src/index.ts';

Check warning on line 3 in packages/components/pie-thumbnail/test/accessibility/pie-thumbnail.spec.ts

View workflow job for this annotation

GitHub Actions / lint-js

'PieThumbnail' is defined but never used

test.describe('PieThumbnail - Accessibility tests', () => {
test('a11y - should test the PieThumbnail component WCAG compliance', async ({ page, makeAxeBuilder }) => {
// Arrange
const basePage = new BasePage(page, 'thumbnail--default');

basePage.load();
await page.waitForTimeout(2500);

// Act
const results = await makeAxeBuilder().analyze();

expect(results.violations).toEqual([]);
});
});
Loading
Loading