Skip to content

Commit

Permalink
Merge branch 'main' into renovate/babel-cli-7.x
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinrodrigues authored Jul 18, 2024
2 parents 7696814 + 46bdcbe commit 7270ebc
Show file tree
Hide file tree
Showing 14 changed files with 472 additions and 106 deletions.
6 changes: 6 additions & 0 deletions .changeset/dry-frogs-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@justeattakeaway/pie-checkbox-group": minor
"pie-storybook": patch
---

[Added] - main logic for checkbox-group
6 changes: 6 additions & 0 deletions .changeset/wicked-crews-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@justeattakeaway/pie-checkbox": minor
---

[Added] - event listener for pie-checkbox-group-disabled custom event
[Removed] - aria prop since aria attributes should be passed to the component directly
79 changes: 70 additions & 9 deletions apps/pie-storybook/stories/pie-checkbox-group.stories.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,97 @@
import { html } from 'lit';

import { ifDefined } from 'lit/directives/if-defined.js';
/* eslint-disable import/no-duplicates */
import '@justeattakeaway/pie-checkbox-group';
import { CheckboxGroupProps } from '@justeattakeaway/pie-checkbox-group';
import { CheckboxGroupProps, defaultProps, statusTypes } from '@justeattakeaway/pie-checkbox-group';
/* eslint-enable import/no-duplicates */

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

import '@justeattakeaway/pie-link';
import '@justeattakeaway/pie-checkbox';

type CheckboxGroupStoryMeta = StoryMeta<CheckboxGroupProps>;

const defaultArgs: CheckboxGroupProps = {};
const defaultArgs: CheckboxGroupProps = {
...defaultProps,
};

const checkboxGroupStoryMeta: CheckboxGroupStoryMeta = {
title: 'Checkbox Group',
component: 'pie-checkbox-group',
argTypes: {},
argTypes: {
name: {
description: 'The name associated with the group.',
control: 'text',
},
label: {
description: 'The visible label for the checkbox group.',
control: 'text',
},
status: {
description: 'The status of the checkbox group component / assistive text. Can be default, success or error.',
control: 'select',
options: statusTypes,
defaultValue: {
summary: defaultProps.status,
},
},
disabled: {
description: 'If true, disables the whole checkbox group. If you need to disable only one checkbox pass the disabled prop to the needed checkbox.',
control: 'boolean',
defaultValue: {
summary: defaultArgs.disabled,
},
},
assistiveText: {
description: 'An optional assistive text to display below the checkbox group.',
control: 'text',
defaultValue: {
summary: '',
},
},
},
args: defaultArgs,
parameters: {
design: {
type: 'figma',
url: '',
url: 'https://www.figma.com/file/aD4m0j97Ruw8Q4S5lED2Bl/Checkbox-audit?node-id=9938-14138&t=1V1VEYmtArFih6AX-4',
},
},
};

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>
const Template = ({
name,
label,
assistiveText,
status,
disabled,
}: CheckboxGroupProps) => html`
<p>Please note, the checkboxes are separate components. See
<pie-link href="/?path=/story/checkbox--default">pie-checkbox</pie-link>.</p>
<pie-checkbox-group
name="${ifDefined(name)}"
label="${ifDefined(label)}"
assistiveText="${ifDefined(assistiveText)}"
status=${ifDefined(status)}
?disabled="${disabled}"
>
<pie-checkbox
name="checkbox-one"
label="checkbox 1">
</pie-checkbox>
<pie-checkbox
name="checkbox-two"
label="checkbox 2">
</pie-checkbox>
<pie-checkbox
name="checkbox-three"
label="checkbox 3">
</pie-checkbox>
</pie-checkbox-group>
`;

export const Default = createStory<CheckboxGroupProps>(Template, defaultArgs)();
13 changes: 1 addition & 12 deletions apps/pie-storybook/stories/pie-checkbox.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ const defaultArgs: CheckboxProps = {
disabled: false,
indeterminate: false,
required: false,
aria: {
label: '',
labelledby: '',
},
};

const checkboxStoryMeta: CheckboxStoryMeta = {
Expand Down Expand Up @@ -91,17 +87,14 @@ const checkboxStoryMeta: CheckboxStoryMeta = {
},
},

aria: {
description: 'ARIA object to pass label/labelledby/describedby aria attributes',
control: 'object',
},
assistiveText: {
description: 'An optional assistive text to display below the checkbox element. Must be provided when the status is success or error.',
control: 'text',
defaultValue: {
summary: '',
},
},

status: {
description: 'The status of the checkbox component / assistive text. Can be default, success or error.',
control: 'select',
Expand Down Expand Up @@ -131,7 +124,6 @@ const Template = ({
disabled,
indeterminate,
required,
aria,
assistiveText,
status,
}: CheckboxProps) => {
Expand All @@ -151,7 +143,6 @@ const Template = ({
?disabled="${disabled}"
?indeterminate="${indeterminate}"
?required="${required}"
.aria="${aria}"
@change="${onChange}"
assistiveText="${ifDefined(assistiveText)}"
status=${ifDefined(status)}>
Expand All @@ -167,7 +158,6 @@ const ExampleFormTemplate: TemplateFunction<CheckboxProps> = ({
disabled,
indeterminate,
required,
aria,
assistiveText,
status,
}: CheckboxProps) => {
Expand All @@ -188,7 +178,6 @@ const ExampleFormTemplate: TemplateFunction<CheckboxProps> = ({
?disabled="${disabled}"
?indeterminate="${indeterminate}"
?required="${required}"
.aria="${aria}"
@change="${onChange}"
assistiveText="${ifDefined(assistiveText)}"
status=${ifDefined(status)}></pie-checkbox>
Expand Down
49 changes: 43 additions & 6 deletions packages/components/pie-checkbox-group/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

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

It is a helper component that groups PieCheckbox components into a visual and functional group.

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


Expand All @@ -29,10 +31,9 @@ This component can be easily integrated into various frontend frameworks and cus
To install `pie-checkbox-group` in your application, run the following on your command line:

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

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

Expand Down Expand Up @@ -74,18 +75,54 @@ import { PieCheckboxGroup } from '@justeattakeaway/pie-checkbox-group/dist/react

| Property | Type | Default | Description |
|---|---|---|---|
| - | - | - | - |
| `name` | string | - | The name associated with the group. |
| `label` | string | - | The label value of the component |
| `disabled` | boolean | - | Same as the HTML disabled attribute - indicates whether or not the checkbox group is disabled. |
| `assistiveText` | `string` | - | Allows assistive text to be displayed below the checkbox group. |
| `status` | `'default'`, `'error'`, `'success'` | `'default'` | The status of the checkbox group / assistive text. If you use `status` you must provide an `assistiveText` prop value for accessibility purposes. |


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>
<pie-checkbox-group name="TESTNAME">
<pie-checkbox
name="my-checkbox-one"
label="Checkbox Label 1">
</pie-checkbox>
<pie-checkbox
name="my-checkbox-two"
label="Checkbox Label 2">
</pie-checkbox>
<pie-checkbox
name="my-checkbox-three"
label="Checkbox Label 3">
</pie-checkbox>
</pie-checkbox-group>

<!-- JSX -->
<PieCheckboxGroup></PieCheckboxGroup>
<PieCheckboxGroup name="TESTNAME">
<PieCheckbox
name="my-checkbox-one"
label="Checkbox Label 1">
</PieCheckbox>
<PieCheckbox
name="my-checkbox-two"
label="Checkbox Label 2">
</PieCheckbox>
<PieCheckbox
name="my-checkbox-three"
label="Checkbox Label 3">
</PieCheckbox>
</PieCheckboxGroup>
```

## Events
| Event | Type | Description |
|-------|------|-------------|
| `pie-checkbox-group-disabled` | `CustomEvent` | Triggered after the disabled state of the checkbox group changes. |

## 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).
1 change: 1 addition & 0 deletions packages/components/pie-checkbox-group/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"cem-plugin-module-file-extensions": "0.0.5"
},
"dependencies": {
"@justeattakeaway/pie-assistive-text": "0.5.1",
"@justeattakeaway/pie-webc-core": "0.24.0"
},
"volta": {
Expand Down
9 changes: 2 additions & 7 deletions packages/components/pie-checkbox-group/src/defs-react.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
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>

export type ReactBaseType = React.FieldsetHTMLAttributes<HTMLFieldSetElement>
47 changes: 44 additions & 3 deletions packages/components/pie-checkbox-group/src/defs.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,44 @@
// 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 {}
import { type ComponentDefaultProps } from '@justeattakeaway/pie-webc-core';

export const statusTypes = ['default', 'success', 'error'] as const;

export interface CheckboxGroupProps {
/**
* The name associated with the group.
*/
name?: string;

/**
* The label value of the component
*/
label?: string;

/**
* An optional assistive text to display below the checkbox group.
*/
assistiveText?: string;

/**
* Same as the HTML disabled attribute - indicates whether or not the checkbox group is disabled.
*/
disabled?: boolean;

/**
* The status of the checkbox component / assistive text. Can be default, success or error.
*/
status?: typeof statusTypes[number];
}

/**
* Event name for when checkbox group becomes disabled.
*
* @constant
*/
export const ON_CHECKBOX_GROUP_DISABLED = 'pie-checkbox-group-disabled';

export type DefaultProps = ComponentDefaultProps<CheckboxGroupProps, 'status' | 'disabled'>;

export const defaultProps: DefaultProps = {
status: 'default',
disabled: false,
};
Loading

0 comments on commit 7270ebc

Please sign in to comment.