Skip to content

Commit

Permalink
feat(pie-checkbox-group): DSW-2182 component skeleton (#1570)
Browse files Browse the repository at this point in the history
  • Loading branch information
dandel10n authored Jul 4, 2024
1 parent 491a8d2 commit 96ea944
Show file tree
Hide file tree
Showing 28 changed files with 370 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .changeset/silver-badgers-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@justeattakeaway/pie-checkbox-group": minor
"@justeattakeaway/pie-webc": patch
"pie-storybook": patch
---

[Added] - initial pie-checkbox-group files from component generator
5 changes: 5 additions & 0 deletions .changeset/strange-poets-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"pie-monorepo": patch
---

[Changed] - update github workflows for new pie-checkbox-group component
3 changes: 3 additions & 0 deletions .github/project-labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,8 @@ pie-webc-testing:
pie-checkbox:
- 'packages/components/pie-checkbox/**/*'

pie-checkbox-group:
- 'packages/components/pie-checkbox-group/**/*'

pie-toast:
- 'packages/components/pie-toast/**/*'
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ env:
PERCY_TOKEN_PIE_BUTTON: ${{ secrets.PERCY_TOKEN_PIE_BUTTON }}
PERCY_TOKEN_PIE_CARD: ${{ secrets.PERCY_TOKEN_PIE_CARD }}
PERCY_TOKEN_PIE_CHECKBOX: ${{ secrets.PERCY_TOKEN_PIE_CHECKBOX }}
PERCY_TOKEN_PIE_CHECKBOX_GROUP: ${{ secrets.PERCY_TOKEN_PIE_CHECKBOX_GROUP }}
PERCY_TOKEN_PIE_CHIP: ${{ secrets.PERCY_TOKEN_PIE_CHIP }}
PERCY_TOKEN_PIE_COOKIE_BANNER: ${{ secrets.PERCY_TOKEN_PIE_COOKIE_BANNER }}
PERCY_TOKEN_PIE_DIVIDER: ${{ secrets.PERCY_TOKEN_PIE_DIVIDER }}
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 @@ -18,6 +18,7 @@
"@justeattakeaway/pie-button": "0.47.7",
"@justeattakeaway/pie-card": "0.19.6",
"@justeattakeaway/pie-checkbox": "0.7.0",
"@justeattakeaway/pie-checkbox-group": "0.0.0",
"@justeattakeaway/pie-chip": "0.7.0",
"@justeattakeaway/pie-cookie-banner": "0.20.5",
"@justeattakeaway/pie-css": "0.12.1",
Expand Down
36 changes: 36 additions & 0 deletions apps/pie-storybook/stories/pie-checkbox-group.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { html } from 'lit';

/* eslint-disable import/no-duplicates */
import '@justeattakeaway/pie-checkbox-group';
import { CheckboxGroupProps } from '@justeattakeaway/pie-checkbox-group';
/* eslint-enable import/no-duplicates */

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

type CheckboxGroupStoryMeta = StoryMeta<CheckboxGroupProps>;

const defaultArgs: CheckboxGroupProps = {};

const checkboxGroupStoryMeta: CheckboxGroupStoryMeta = {
title: 'Checkbox Group',
component: 'pie-checkbox-group',
argTypes: {},
args: defaultArgs,
parameters: {
design: {
type: 'figma',
url: '',
},
},
};

export default checkboxGroupStoryMeta;

// TODO: remove the eslint-disable rule when props are added
// eslint-disable-next-line no-empty-pattern
const Template = ({}: CheckboxGroupProps) => html`
<pie-checkbox-group></pie-checkbox-group>
`;

export const Default = createStory<CheckboxGroupProps>(Template, defaultArgs)();
6 changes: 6 additions & 0 deletions packages/components/pie-checkbox-group/.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-checkbox-group/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-checkbox-group">
<img alt="GitHub Workflow Status" src="https://img.shields.io/npm/v/@justeattakeaway/pie-checkbox-group.svg">
</a>
</p>

# Table of Contents

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

## pie-checkbox-group

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

```bash
# npm
$ npm i @justeattakeaway/pie-checkbox-group

# yarn
$ yarn add @justeattakeaway/pie-checkbox-group
```

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 { PieCheckboxGroup } from '@justeattakeaway/pie-checkbox-group';

// 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-checkbox-group';
```

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

```html
<!-- Native HTML -->
<pie-checkbox-group></pie-checkbox-group>

<!-- JSX -->
<PieCheckboxGroup></PieCheckboxGroup>
```

## 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-checkbox-group/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-checkbox-group/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "@justeattakeaway/pie-checkbox-group",
"description": "PIE Design System Checkbox Group 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_CHECKBOX_GROUP} 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.16.0",
"cem-plugin-module-file-extensions": "0.0.5"
},
"dependencies": {
"@justeattakeaway/pie-webc-core": "0.23.0"
},
"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());
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@use '@justeattakeaway/pie-css/scss' as p;
8 changes: 8 additions & 0 deletions packages/components/pie-checkbox-group/src/defs-react.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import 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-checkbox-group/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 CheckboxGroupProps {}
30 changes: 30 additions & 0 deletions packages/components/pie-checkbox-group/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { LitElement, html, unsafeCSS } from 'lit';
import { RtlMixin, defineCustomElement } from '@justeattakeaway/pie-webc-core';

import styles from './checkbox-group.scss?inline';
import { CheckboxGroupProps } from './defs';

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

const componentSelector = 'pie-checkbox-group';

/**
* @tagname pie-checkbox-group
*/
export class PieCheckboxGroup extends RtlMixin(LitElement) implements CheckboxGroupProps {
render () {
return html`<h1 data-test-id="pie-checkbox-group">Hello world!</h1>`;
}

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

defineCustomElement(componentSelector, PieCheckboxGroup);

declare global {
interface HTMLElementTagNameMap {
[componentSelector]: PieCheckboxGroup;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

import { test, expect } from '@justeattakeaway/pie-webc-testing/src/playwright/webc-fixtures.ts';
import { PieCheckboxGroup, CheckboxGroupProps } from '../../src/index.ts';

test.describe('PieCheckboxGroup - Accessibility tests', () => {
test('a11y - should test the PieCheckboxGroup component WCAG compliance', async ({ makeAxeBuilder, mount }) => {
await mount(
PieCheckboxGroup,
{
props: {} as CheckboxGroupProps,
},
);

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

expect(results.violations).toEqual([]);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

import { test, expect } from '@sand4rt/experimental-ct-web';
import { PieCheckboxGroup, CheckboxGroupProps } from '../../src/index.ts';

const componentSelector = '[data-test-id="pie-checkbox-group"]';

test.describe('PieCheckboxGroup - Component tests', () => {
test('should render successfully', async ({ mount, page }) => {
// Arrange
await mount(PieCheckboxGroup, {
props: {} as CheckboxGroupProps,
});

// Act
const checkboxGroup = page.locator(componentSelector);

// Assert
expect(checkboxGroup).toBeVisible();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

import { test } from '@sand4rt/experimental-ct-web';
import percySnapshot from '@percy/playwright';
import { PieCheckboxGroup, CheckboxGroupProps } from '../../src/index.ts';

test.describe('PieCheckboxGroup - Visual tests`', () => {
test('should display the PieCheckboxGroup component successfully', async ({ page, mount }) => {
await mount(PieCheckboxGroup, {
props: {} as CheckboxGroupProps,
});

await percySnapshot(page, 'PieCheckboxGroup - Visual Test');
});
});
8 changes: 8 additions & 0 deletions packages/components/pie-checkbox-group/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "@justeattakeaway/pie-components-config/tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"rootDir": ".",
},
"include": ["src/**/*.ts","./declaration.d.ts", "test/**/*.ts", "playwright-lit-visual.config.ts", "playwright-lit.config.ts"],
}
3 changes: 3 additions & 0 deletions packages/components/pie-checkbox-group/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import viteConfig from '@justeattakeaway/pie-components-config/vite.config';

export default viteConfig;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '@justeattakeaway/pie-checkbox-group';
1 change: 1 addition & 0 deletions packages/components/pie-webc/components/checkbox-group.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '@justeattakeaway/pie-checkbox-group';
Loading

0 comments on commit 96ea944

Please sign in to comment.