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-lottie-player): DSW-2365 implement lottie player #1763

Merged
merged 34 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
55adddc
feat(pie-lottie-player): DSW-2365 create component skeleton
fernandofranca Aug 26, 2024
407a877
chore(pie-lottie-player): DSW-2365 set up the project label for Github
fernandofranca Aug 27, 2024
51b4239
chore(pie-lottie-player): DSW-2365 set up VRT token and script
fernandofranca Aug 27, 2024
a474e6f
feat(pie-lottie-player): DSW-2365 update animation methods
fernandofranca Aug 29, 2024
69032a5
feat(pie-storybook): DSW-2365 storybook
fernandofranca Aug 29, 2024
92fe2e9
feat(pie-lottie-player): DSW-2365 ensure that speed and direction set…
fernandofranca Aug 29, 2024
b1a7a08
feat(pie-lottie-player): DSW-2365 remove methods from TS props
fernandofranca Aug 30, 2024
cd9781f
feat(pie-lottie-player): DSW-2365 load Lottie dynamically
fernandofranca Aug 30, 2024
5886158
feat(pie-lottie-player): DSW-2365 add empty style to ensure ssr tests…
fernandofranca Sep 2, 2024
af30106
feat(pie-lottie-player): DSW-2365 provide TS declaration for async lo…
fernandofranca Sep 2, 2024
4ba0905
feat(pie-lottie-player): DSW-2365 small adjustments
fernandofranca Sep 2, 2024
3184eef
feat(pie-lottie-player): DSW-2365 rename props for clarity
fernandofranca Sep 2, 2024
7236514
feat(pie-lottie-player): DSW-2365 solve TS issue for any in error han…
fernandofranca Sep 2, 2024
4f5c173
feat(pie-lottie-player): DSW-2365 declare base type for React
fernandofranca Sep 2, 2024
dbd9714
chore(pie-lottie-player): DSW-2365 update dependency
fernandofranca Sep 2, 2024
2bc6bb8
chore(pie-monorepo): DSW-2365 changeset
fernandofranca Aug 28, 2024
e0d6dc9
feat(pie-lottie-player): DSW-2365 update component tests
fernandofranca Sep 2, 2024
722d290
feat(pie-lottie-player): DSW-2365 update visual test
fernandofranca Sep 2, 2024
0b9f75e
feat(pie-storybook): DSW-2365 update build script and copy static ass…
fernandofranca Sep 3, 2024
8cf10bf
feat(pie-lottie-player): DSW-2365 update MD props table
fernandofranca Sep 3, 2024
36010cc
feat(pie-lottie-player): DSW-2365 update MD with usage sample
fernandofranca Sep 4, 2024
4b86974
feat(pie-lottie-player): DSW-2365 replace utility method with isServer
fernandofranca Sep 4, 2024
2304226
feat(pie-lottie-player): DSW-2365 update tests
fernandofranca Sep 5, 2024
854625a
feat(pie-lottie-player): DSW-2365 adjustments
fernandofranca Sep 9, 2024
675ef71
feat(pie-lottie-player): DSW-2365 update lottie async import approach
fernandofranca Sep 9, 2024
4407d26
feat(pie-lottie-player): DSW-2365 update lottie README
fernandofranca Sep 9, 2024
ad4d154
feat(pie-lottie-player): DSW-2365 implement aria.describedby
fernandofranca Sep 10, 2024
d0c5952
Revert "feat(pie-lottie-player): DSW-2365 implement aria.describedby"
fernandofranca Sep 10, 2024
4d10c4d
feat(pie-lottie-player): DSW-2365 a11y related updates
fernandofranca Sep 10, 2024
a29006e
feat(pie-lottie-player): DSW-2365 a11y related updates
fernandofranca Sep 10, 2024
fdeb9fe
feat(pie-lottie-player): DSW-2365 code review updates
fernandofranca Sep 10, 2024
7123160
feat(pie-lottie-player): DSW-2365 code review updates
fernandofranca Sep 10, 2024
93bd062
chore(pie-monorepo): DSW-2365 update yarn.lock
fernandofranca Sep 10, 2024
9804b8d
feat(pie-lottie-player): DSW-2365 code review updates
fernandofranca Sep 10, 2024
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/itchy-lions-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"pie-storybook": patch
---

[Added] - story and controls for pie-lottie-player
5 changes: 5 additions & 0 deletions .changeset/shaggy-fishes-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@justeattakeaway/pie-lottie-player": patch
---

[Added] - Component for playing Lottie animation files
3 changes: 3 additions & 0 deletions .github/project-labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ pie-icon-button:
pie-link:
- 'packages/components/pie-link/**/*'

pie-lottie-player:
- 'packages/components/pie-lottie-player/**/*'

pie-modal:
- 'packages/components/pie-modal/**/*'

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ env:
PERCY_TOKEN_PIE_ICON_BUTTON: ${{ secrets.PERCY_TOKEN_PIE_ICON_BUTTON }}
PERCY_TOKEN_PIE_ICONS_WEBC: ${{ secrets.PERCY_TOKEN_PIE_ICONS_WEBC }}
PERCY_TOKEN_PIE_LINK: ${{ secrets.PERCY_TOKEN_PIE_LINK }}
PERCY_TOKEN_PIE_LOTTIE_PLAYER: ${{ secrets.PERCY_TOKEN_PIE_LOTTIE_PLAYER }}
PERCY_TOKEN_PIE_MODAL: ${{ secrets.PERCY_TOKEN_PIE_MODAL }}
PERCY_TOKEN_PIE_NOTIFICATION: ${{ secrets.PERCY_TOKEN_PIE_NOTIFICATION }}
PERCY_TOKEN_PIE_RADIO: ${{ secrets.PERCY_TOKEN_PIE_RADIO }}
Expand Down
2 changes: 1 addition & 1 deletion apps/pie-storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"description": "Storybook for PIE Design System components",
"scripts": {
"dev": "storybook dev -p 6006",
"build": "storybook build --output-dir dist",
"build": "storybook build --output-dir dist && cp -R ./static ./dist",
fernandofranca marked this conversation as resolved.
Show resolved Hide resolved
"lint:scripts": "run -T eslint .",
"lint:scripts:fix": "run -T eslint . --fix",
"generate:component-statuses": "npx generate-component-statuses"
Expand Down
1 change: 1 addition & 0 deletions apps/pie-storybook/static/animations/courier.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions apps/pie-storybook/static/animations/preparing.json

Large diffs are not rendered by default.

119 changes: 119 additions & 0 deletions apps/pie-storybook/stories/pie-lottie-player.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import { html } from 'lit';
/* eslint-disable import/no-duplicates */
import '@justeattakeaway/pie-lottie-player';
import {
type LottiePlayerProps as LottiePlayerBaseProps, PieLottiePlayer, defaultProps, directions,
} from '@justeattakeaway/pie-lottie-player';
/* eslint-enable import/no-duplicates */

import { type StoryMeta } from '../types';
import { createStory } from '../utilities';

type LottiePlayerProps = Omit<LottiePlayerBaseProps, 'play' | 'stop'>
type LottiePlayerStoryMeta = StoryMeta<LottiePlayerProps>;

const defaultArgs: LottiePlayerProps = { ...defaultProps };

const animationSrcOptions: string[] = [
'./static/animations/courier.json',
'./static/animations/order-confirmed.json',
'./static/animations/preparing.json',
];

const animationSrcLabels = animationSrcOptions.reduce<Record<string, string>>((acc, current) => {
const match = current.match(/.*\/(.*).json/);
acc[current] = match && match[1] ? match[1] : '';
return acc;
}, {});

const lottiePlayerStoryMeta: LottiePlayerStoryMeta = {
title: 'Lottie Player',
component: 'pie-lottie-player',
argTypes: {
animationSrc: {
description: 'Lottie animation JSON file URL or relative path.\n animationSrc and animationData are mutually exclusive.',
control: {
type: 'select',
labels: animationSrcLabels,
},
options: [...animationSrcOptions, ''],
defaultValue: {
summary: defaultArgs.animationSrc,
},
},
loopDisabled: {
description: 'By the default animations loop, setting this prop as true will prevent such behaviour.',
control: 'boolean',
defaultValue: {
summary: defaultArgs.loopDisabled,
},
},
autoPlayDisabled: {
description: 'By default animations start playing as soons as its data is available, setting this prop as true will prevent such behaviour.',
control: 'boolean',
defaultValue: {
summary: defaultArgs.autoPlayDisabled,
},
},
speed: {
description: 'Determines the animation reproduction speed.\n1 is the regular speed, 2 is twice as fast.',
control: {
type: 'number',
step: 0.25,
min: 0.25,
},
defaultValue: {
summary: defaultArgs.speed,
},
},
direction: {
description: 'Sets the animation reproduction direction',
control: 'select',
options: directions,
defaultValue: {
summary: defaultArgs.direction,
},
},
},
args: defaultArgs,
parameters: {
design: {
type: 'figma',
url: '',
},
},
};

export default lottiePlayerStoryMeta;

function handleStopAnimationClick () {
const player:PieLottiePlayer|null = document.querySelector('pie-lottie-player');
if (player) player.stop();
}

function handleStartAnimationClick () {
const player:PieLottiePlayer|null = document.querySelector('pie-lottie-player');
if (player) player.play();
}

const Template = ({
animationSrc,
loopDisabled,
autoPlayDisabled,
speed,
direction,
}: LottiePlayerProps) => html`
<div style="display: flex; justify-content: center;">
<pie-button size="xsmall" @click=${handleStopAnimationClick}>Stop animation</pie-button>
<pie-button size="xsmall" @click=${handleStartAnimationClick}>Start animation</pie-button>
</div>
<pie-lottie-player
.animationSrc="${animationSrc === undefined ? animationSrcOptions[0] : animationSrc}"
?loopDisabled="${loopDisabled}"
?autoPlayDisabled="${autoPlayDisabled}"
.speed="${speed}"
.direction="${direction}"
></pie-lottie-player>
`;

export const Default = createStory<LottiePlayerProps>(Template, defaultArgs)();
6 changes: 6 additions & 0 deletions packages/components/pie-lottie-player/.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
117 changes: 117 additions & 0 deletions packages/components/pie-lottie-player/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<p align="center">
fernandofranca marked this conversation as resolved.
Show resolved Hide resolved
<img align="center" src="../../../readme_image.png" height="200" alt="">
</p>

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

# Table of Contents

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

## pie-lottie-player

`pie-lottie-player` 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-lottie-player` in your application, run the following on your command line:

```bash
# npm
$ npm i @justeattakeaway/pie-lottie-player

# yarn
$ yarn add @justeattakeaway/pie-lottie-player
```

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 { PieLottiePlayer } from '@justeattakeaway/pie-lottie-player';

// 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-lottie-player';
```

#### React

```js
// React
// For React, you will need to import our React-specific component build
// which wraps the web component using ​@lit/react
import { PieLottiePlayer } from '@justeattakeaway/pie-lottie-player/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.

#### Nuxt and SSR

When adding this component to a Nuxt application in combination with SSR settings, it might happen to receive the error "500 customElements.get(...) is not a constructor" during the preview of the built application.

That is likely due [a known issue](https://github.com/prashantpalikhe/nuxt-ssr-lit/issues/137) with the module that enables using Lit components in Nuxt with SSR, `nuxt-ssr-lit`.

To solve the issue, update or add the `nitro.moduleSideEffects` array in `nuxt.config.ts`:

```
nitro: {
moduleSideEffects: [
'@justeattakeaway/pie-lottie-player',
],
},
```

## Peer Dependencies

> [!IMPORTANT]
> When using `pie-lottie-player`, 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 |
| ---------------- | --------- | ------- | ---------------------------------------------------------------------------------------------------------------------------- |
| animationSrc | `String` | - | Lottie animation JSON file URL or relative path. animationSrc and animationData are mutually exclusive. |
| animationData | `Object` | - | Object with Lottie animation data. animationSrc and animationData are mutually exclusive. |
| loopDisabled | `Boolean` | false | By the default animations loop, setting this prop as true will prevent such behaviour. |
| autoPlayDisabled | `Boolean` | false | By default animations start playing as soon as its data is available, setting this prop as true will prevent such behaviour. |
| speed | `Number` | 1 | Determines the animation reproduction speed. 1 is the regular speed, 2 is twice as fast. |
| direction | `String` | forward | Sets the animation reproduction direction. |

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

```html
<!-- Native HTML -->
<pie-lottie-player animationSrc="./animation-file.json"></pie-lottie-player>

<!-- JSX -->
<PieLottiePlayer animationSrc="./animation-file.json"></PieLottiePlayer>
```

## Acessibility

Currently the component is always hidden from screen readers because animations should only be decorative and supplementary. Any important meaning and context should be presented alongside the animation as text.

For the users with the "Reduce motion" setting enabled, the animation will be paused on the first frame.

## 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()],
};
17 changes: 17 additions & 0 deletions packages/components/pie-lottie-player/declaration.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

declare module '*.scss' {
const content: Record<string, string>;
export default content;
}

declare module '*.scss?inline' {
const content: Record<string, string>;
export default content;
}

declare module 'lottie-web/build/player/lottie_light_canvas.min.js' {
import { LottiePlayer } from 'lottie-web';

const lottie: LottiePlayer;
export default lottie;
}
52 changes: 52 additions & 0 deletions packages/components/pie-lottie-player/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "@justeattakeaway/pie-lottie-player",
"description": "PIE Design System Lottie Player 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",
"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_LOTTIE_PLAYER} percy exec --allowed-hostname cloudfront.net -- npx playwright test -c ./playwright-lit-visual.config.ts",
"test:visual:ci": "yarn test:visual",
"test:browsers-setup": "npx playwright-lit-setup"
},
"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.12.1",
"cem-plugin-module-file-extensions": "0.0.5"
},
"dependencies": {
"@justeattakeaway/pie-webc-core": "0.24.0",
"lottie-web": "5.12.2"
},
"volta": {
"extends": "../../../package.json"
},
"customElements": "custom-elements.json",
"sideEffects": [
"dist/*.js"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { defineConfig } from '@sand4rt/experimental-ct-web';
import { getPlaywrightVisualConfig } from '@justeattakeaway/pie-components-config';

export default defineConfig(getPlaywrightVisualConfig());
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { defineConfig } from '@sand4rt/experimental-ct-web';
import { getPlaywrightConfig } from '@justeattakeaway/pie-components-config';

export default defineConfig(getPlaywrightConfig());
8 changes: 8 additions & 0 deletions packages/components/pie-lottie-player/src/defs-react.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react';

/**
* 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<HTMLDivElement>
Loading
Loading