@justeattakeaway/pie-icon-button 0.5.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +6 -6
- package/CHANGELOG.md +12 -0
- package/README.md +114 -9
- package/dist/index.js +54 -42
- package/dist/react.js +209 -223
- package/dist/types/packages/components/pie-icon-button/src/defs.d.ts +19 -1
- package/dist/types/packages/components/pie-icon-button/src/defs.d.ts.map +1 -1
- package/dist/types/packages/components/pie-icon-button/src/index.d.ts +3 -2
- package/dist/types/packages/components/pie-icon-button/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/defs.ts +25 -1
- package/src/iconButton.scss +27 -7
- package/src/index.ts +13 -5
- package/test/accessibility/pie-icon-button.spec.ts +8 -5
- package/test/visual/pie-icon-button.spec.ts +4 -3
- package/vite.config.js +1 -1
|
@@ -1,8 +1,26 @@
|
|
|
1
1
|
export interface IconButtonProps {
|
|
2
|
+
/**
|
|
3
|
+
* the size of the icon button.
|
|
4
|
+
* @default medium
|
|
5
|
+
*/
|
|
6
|
+
size: 'xsmall' | 'small' | 'medium' | 'large';
|
|
7
|
+
/**
|
|
8
|
+
* the variant of the icon button.
|
|
9
|
+
* @default primary
|
|
10
|
+
*/
|
|
2
11
|
variant: 'primary' | 'secondary' | 'outline' | 'ghost' | 'ghost-tertiary';
|
|
12
|
+
/**
|
|
13
|
+
* If `true`, the icon button will be disabled.
|
|
14
|
+
* @default false
|
|
15
|
+
*/
|
|
16
|
+
disabled?: boolean;
|
|
3
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Icon Button size variants
|
|
20
|
+
*/
|
|
21
|
+
export declare const iconButtonSizes: Array<IconButtonProps['size']>;
|
|
4
22
|
/**
|
|
5
23
|
* Icon Button style variants
|
|
6
24
|
*/
|
|
7
|
-
export declare const iconButtonVariants: IconButtonProps['variant']
|
|
25
|
+
export declare const iconButtonVariants: Array<IconButtonProps['variant']>;
|
|
8
26
|
//# sourceMappingURL=defs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defs.d.ts","sourceRoot":"","sources":["../../../src/defs.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC5B,OAAO,EAAE,SAAS,GAAG,WAAW,GAAG,SAAS,GAAG,OAAO,GAAG,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"defs.d.ts","sourceRoot":"","sources":["../../../src/defs.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC5B;;;OAGG;IACH,IAAI,EAAE,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;IAC9C;;;OAGG;IACH,OAAO,EAAE,SAAS,GAAG,WAAW,GAAG,SAAS,GAAG,OAAO,GAAG,gBAAgB,CAAC;IAC1E;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,eAAe,CAAC,MAAM,CAAC,CAK1D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,eAAe,CAAC,SAAS,CAAC,CAMhE,CAAC"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { LitElement } from 'lit';
|
|
2
|
-
import { IconButtonProps, iconButtonVariants } from './defs';
|
|
3
|
-
export { type IconButtonProps, iconButtonVariants };
|
|
2
|
+
import { IconButtonProps, iconButtonSizes, iconButtonVariants } from './defs';
|
|
3
|
+
export { type IconButtonProps, iconButtonSizes, iconButtonVariants };
|
|
4
4
|
declare const componentSelector = "pie-icon-button";
|
|
5
5
|
export declare class PieIconButton extends LitElement {
|
|
6
|
+
size: IconButtonProps['size'];
|
|
6
7
|
variant: IconButtonProps['variant'];
|
|
7
8
|
disabled: boolean;
|
|
8
9
|
render(): import("lit-html").TemplateResult<1>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAmB,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAmB,MAAM,KAAK,CAAC;AAKlD,OAAO,EACH,eAAe,EAAE,eAAe,EAAE,kBAAkB,EACvD,MAAM,QAAQ,CAAC;AAGhB,OAAO,EAAE,KAAK,eAAe,EAAE,eAAe,EAAE,kBAAkB,EAAE,CAAC;AAErE,QAAA,MAAM,iBAAiB,oBAAoB,CAAC;AAE5C,qBAAa,aAAc,SAAQ,UAAU;IAGrC,IAAI,EAAE,eAAe,CAAC,MAAM,CAAC,CAAY;IAIzC,OAAO,EAAE,eAAe,CAAC,SAAS,CAAC,CAAa;IAGhD,QAAQ,UAAS;IAErB,MAAM;IAmBN,MAAM,CAAC,MAAM,0BAAqB;CACrC;AAID,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,qBAAqB;QAC3B,CAAC,iBAAiB,CAAC,EAAE,aAAa,CAAC;KACtC;CACJ"}
|
package/package.json
CHANGED
package/src/defs.ts
CHANGED
|
@@ -1,11 +1,35 @@
|
|
|
1
1
|
export interface IconButtonProps {
|
|
2
|
+
/**
|
|
3
|
+
* the size of the icon button.
|
|
4
|
+
* @default medium
|
|
5
|
+
*/
|
|
6
|
+
size: 'xsmall' | 'small' | 'medium' | 'large';
|
|
7
|
+
/**
|
|
8
|
+
* the variant of the icon button.
|
|
9
|
+
* @default primary
|
|
10
|
+
*/
|
|
2
11
|
variant: 'primary' | 'secondary' | 'outline' | 'ghost' | 'ghost-tertiary';
|
|
12
|
+
/**
|
|
13
|
+
* If `true`, the icon button will be disabled.
|
|
14
|
+
* @default false
|
|
15
|
+
*/
|
|
16
|
+
disabled?: boolean;
|
|
3
17
|
}
|
|
4
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Icon Button size variants
|
|
21
|
+
*/
|
|
22
|
+
export const iconButtonSizes: Array<IconButtonProps['size']> = [
|
|
23
|
+
'xsmall',
|
|
24
|
+
'small',
|
|
25
|
+
'medium',
|
|
26
|
+
'large'
|
|
27
|
+
];
|
|
28
|
+
|
|
5
29
|
/**
|
|
6
30
|
* Icon Button style variants
|
|
7
31
|
*/
|
|
8
|
-
export const iconButtonVariants: IconButtonProps['variant']
|
|
32
|
+
export const iconButtonVariants: Array<IconButtonProps['variant']> = [
|
|
9
33
|
'primary',
|
|
10
34
|
'secondary',
|
|
11
35
|
'outline',
|
package/src/iconButton.scss
CHANGED
|
@@ -13,8 +13,7 @@
|
|
|
13
13
|
--btn-border-radius: var(--dt-radius-rounded-e);
|
|
14
14
|
|
|
15
15
|
// The base values are set to the size default, which is for the medium button size
|
|
16
|
-
--btn-
|
|
17
|
-
--btn-width: var(--btn-height);
|
|
16
|
+
--btn-dimension: 48px;
|
|
18
17
|
|
|
19
18
|
// The following values set to default background and color
|
|
20
19
|
// currently this sets the primary button styles
|
|
@@ -22,11 +21,14 @@
|
|
|
22
21
|
--btn-icon-fill: var(--dt-color-content-interactive-primary);
|
|
23
22
|
--btn-focus: var(--dt-color-focus-outer);
|
|
24
23
|
|
|
25
|
-
|
|
24
|
+
// Sizing is set to Medium button icon size, as that is the default
|
|
25
|
+
--btn-icon-size: 24px;
|
|
26
|
+
|
|
27
|
+
min-block-size: var(--btn-dimension);
|
|
26
28
|
aspect-ratio: 1 / 1;
|
|
27
29
|
|
|
28
30
|
@supports not (aspect-ratio: 1 / 1) {
|
|
29
|
-
min-inline-size: var(--btn-
|
|
31
|
+
min-inline-size: var(--btn-dimension);
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
border: none;
|
|
@@ -46,11 +48,12 @@
|
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
svg {
|
|
49
|
-
height:
|
|
50
|
-
width:
|
|
51
|
+
height: var(--btn-icon-size);
|
|
52
|
+
width: var(--btn-icon-size);
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
svg,
|
|
55
|
+
svg,
|
|
56
|
+
path {
|
|
54
57
|
fill: var(--btn-icon-fill);
|
|
55
58
|
}
|
|
56
59
|
|
|
@@ -116,5 +119,22 @@
|
|
|
116
119
|
border: none;
|
|
117
120
|
}
|
|
118
121
|
}
|
|
122
|
+
|
|
123
|
+
&[size='xsmall'] {
|
|
124
|
+
--btn-dimension: 32px;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
&[size='small'] {
|
|
128
|
+
--btn-dimension: 40px;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
&[size='medium'] {
|
|
132
|
+
/* Same as default styles */
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
&[size='large'] {
|
|
136
|
+
--btn-dimension: 56px;
|
|
137
|
+
--btn-icon-size: 28px;
|
|
138
|
+
}
|
|
119
139
|
}
|
|
120
140
|
|
package/src/index.ts
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
|
-
import { LitElement, html, unsafeCSS } from 'lit';
|
|
2
|
-
import { property } from 'lit/decorators.js';
|
|
1
|
+
import { LitElement, html, unsafeCSS } from 'lit';
|
|
2
|
+
import { property } from 'lit/decorators.js';
|
|
3
3
|
import { validPropertyValues } from '@justeattakeaway/pie-webc-core';
|
|
4
|
+
|
|
4
5
|
import styles from './iconButton.scss?inline';
|
|
5
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
IconButtonProps, iconButtonSizes, iconButtonVariants,
|
|
8
|
+
} from './defs';
|
|
6
9
|
|
|
7
10
|
// Valid values available to consumers
|
|
8
|
-
export { type IconButtonProps, iconButtonVariants };
|
|
11
|
+
export { type IconButtonProps, iconButtonSizes, iconButtonVariants };
|
|
9
12
|
|
|
10
13
|
const componentSelector = 'pie-icon-button';
|
|
11
14
|
|
|
12
15
|
export class PieIconButton extends LitElement {
|
|
16
|
+
@property()
|
|
17
|
+
@validPropertyValues(componentSelector, iconButtonSizes, 'medium')
|
|
18
|
+
size: IconButtonProps['size'] = 'medium';
|
|
19
|
+
|
|
13
20
|
@property()
|
|
14
21
|
@validPropertyValues(componentSelector, iconButtonVariants, 'primary')
|
|
15
22
|
variant: IconButtonProps['variant'] = 'primary';
|
|
@@ -19,13 +26,14 @@ export class PieIconButton extends LitElement {
|
|
|
19
26
|
|
|
20
27
|
render () {
|
|
21
28
|
const {
|
|
22
|
-
disabled, variant,
|
|
29
|
+
disabled, size, variant,
|
|
23
30
|
} = this;
|
|
24
31
|
|
|
25
32
|
// The inline SVG is temporary until we have a proper icon integration
|
|
26
33
|
return html`
|
|
27
34
|
<button
|
|
28
35
|
class="o-iconBtn"
|
|
36
|
+
size=${size}
|
|
29
37
|
variant=${variant}
|
|
30
38
|
?disabled=${disabled}>
|
|
31
39
|
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { test, expect } from '@sand4rt/experimental-ct-web';
|
|
2
2
|
import AxeBuilder from '@axe-core/playwright';
|
|
3
|
+
import type {
|
|
4
|
+
PropObject, WebComponentPropValues,
|
|
5
|
+
} from '@justeattakeaway/pie-webc-core/src/test-helpers/defs.ts';
|
|
3
6
|
import {
|
|
4
|
-
|
|
7
|
+
getAllPropCombinations, splitCombinationsByPropertyValue,
|
|
5
8
|
} from '@justeattakeaway/pie-webc-core/src/test-helpers/get-all-prop-combos.ts';
|
|
6
9
|
import { PieIconButton } from '@/index';
|
|
7
10
|
import { iconButtonVariants } from '@/defs';
|
|
@@ -11,12 +14,12 @@ const props: PropObject = {
|
|
|
11
14
|
disabled: [true, false],
|
|
12
15
|
};
|
|
13
16
|
|
|
14
|
-
const componentPropsMatrix :
|
|
15
|
-
const componentPropsMatrixByVariant: Record<string,
|
|
17
|
+
const componentPropsMatrix : WebComponentPropValues[] = getAllPropCombinations(props);
|
|
18
|
+
const componentPropsMatrixByVariant: Record<string, WebComponentPropValues[]> = splitCombinationsByPropertyValue(componentPropsMatrix, 'variant');
|
|
16
19
|
const componentVariants: string[] = Object.keys(componentPropsMatrixByVariant);
|
|
17
20
|
|
|
18
21
|
componentVariants.forEach((variant) => test(`Render all prop variations for Variant: ${variant}`, async ({ page, mount }) => {
|
|
19
|
-
await Promise.all(componentPropsMatrixByVariant[variant].map(async (combo:
|
|
22
|
+
await Promise.all(componentPropsMatrixByVariant[variant].map(async (combo: WebComponentPropValues) => {
|
|
20
23
|
await mount(
|
|
21
24
|
PieIconButton,
|
|
22
25
|
{
|
|
@@ -28,7 +31,7 @@ componentVariants.forEach((variant) => test(`Render all prop variations for Vari
|
|
|
28
31
|
);
|
|
29
32
|
}));
|
|
30
33
|
|
|
31
|
-
const results = await new AxeBuilder
|
|
34
|
+
const results = await new AxeBuilder({ page })
|
|
32
35
|
.withTags(['wcag21a', 'wcag21aa', 'wcag143', 'cat.color', 'cat.aria'])
|
|
33
36
|
.disableRules(['color-contrast', 'color-contrast-enhanced'])
|
|
34
37
|
.analyze();
|
|
@@ -14,15 +14,16 @@ import {
|
|
|
14
14
|
WebComponentTestWrapper,
|
|
15
15
|
} from '@justeattakeaway/pie-webc-core/src/test-helpers/components/web-component-test-wrapper/WebComponentTestWrapper.ts';
|
|
16
16
|
import { PieIconButton } from '@/index';
|
|
17
|
-
import { iconButtonVariants } from '@/defs';
|
|
17
|
+
import { iconButtonSizes, iconButtonVariants } from '@/defs';
|
|
18
18
|
|
|
19
19
|
const props: PropObject = {
|
|
20
|
+
size: iconButtonSizes,
|
|
20
21
|
variant: iconButtonVariants,
|
|
21
22
|
disabled: [true, false],
|
|
22
23
|
};
|
|
23
24
|
|
|
24
25
|
// Renders a <pie-icon-button> HTML string with the given prop values
|
|
25
|
-
const renderTestPieIconButton = (propVals: WebComponentPropValues) => `<pie-icon-button variant="${propVals.variant}" ${propVals.disabled ? 'disabled' : ''}></pie-icon-button>`;
|
|
26
|
+
const renderTestPieIconButton = (propVals: WebComponentPropValues) => `<pie-icon-button size="${propVals.size}" variant="${propVals.variant}" ${propVals.disabled ? 'disabled' : ''}></pie-icon-button>`;
|
|
26
27
|
|
|
27
28
|
const componentPropsMatrix : WebComponentPropValues[] = getAllPropCombinations(props);
|
|
28
29
|
const componentPropsMatrixByVariant: Record<string, WebComponentPropValues[]> = splitCombinationsByPropertyValue(componentPropsMatrix, 'variant');
|
|
@@ -42,7 +43,7 @@ test('Component registered in the DOM', async ({ mount }) => {
|
|
|
42
43
|
componentVariants.forEach((variant) => test(`Render all prop variations for Variant: ${variant}`, async ({ page, mount }) => {
|
|
43
44
|
await Promise.all(componentPropsMatrixByVariant[variant].map(async (combo: WebComponentPropValues) => {
|
|
44
45
|
const testComponent: WebComponentTestInput = createTestWebComponent(combo, renderTestPieIconButton);
|
|
45
|
-
const propKeyValues = `disabled: ${testComponent.propValues.disabled}`;
|
|
46
|
+
const propKeyValues = `size: ${testComponent.propValues.size}, disabled: ${testComponent.propValues.disabled}`;
|
|
46
47
|
|
|
47
48
|
await mount(
|
|
48
49
|
WebComponentTestWrapper,
|
package/vite.config.js
CHANGED