@coopdigital/react 0.2.1 → 0.4.0
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/README.md +8 -26
- package/dist/components/Pill/Pill.d.ts +14 -0
- package/dist/components/Pill/Pill.js +20 -0
- package/dist/components/Pill/index.d.ts +4 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/package.json +20 -16
- package/src/components/Pill/Pill.tsx +45 -0
- package/src/components/Pill/index.ts +5 -0
- package/src/index.ts +2 -1
- package/dist/components/Button/Button.e2e.test.d.ts +0 -1
- package/dist/components/Button/Button.test.d.ts +0 -4
- package/src/components/Button/Button.e2e.test.ts +0 -8
- package/src/components/Button/Button.stories.tsx +0 -13
- package/src/components/Button/Button.test.tsx +0 -18
package/README.md
CHANGED
|
@@ -4,8 +4,6 @@
|
|
|
4
4
|
<br />
|
|
5
5
|
</nav>
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
7
|
# Experience Kit for React
|
|
10
8
|
|
|
11
9
|
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
@@ -18,9 +16,6 @@
|
|
|
18
16
|
<a href="https://static.coop.co.uk/experience-kit-storybook-react"><img src="https://img.shields.io/badge/storybook-react-F85792" alt="storybook" /></a>
|
|
19
17
|
[![All Contributors][all_contributors_badge]](#contributors)
|
|
20
18
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
19
|
## Getting started
|
|
25
20
|
|
|
26
21
|
Install the package from NPM:
|
|
@@ -33,16 +28,10 @@ Import the components that you need:
|
|
|
33
28
|
import { Button } from "@coopdigital/react"
|
|
34
29
|
```
|
|
35
30
|
|
|
36
|
-
## Developing
|
|
37
|
-
|
|
38
|
-
Refer to the [root README](https://gitlab.com/coopeng/sds/oneweb/experience-kit/-/blob/main/README.md) for general development setup and usage instructions (lint, formatting, etc).
|
|
39
|
-
|
|
40
|
-
|
|
41
31
|
### Package Scripts
|
|
42
32
|
|
|
43
33
|
The following scripts should be run inside the react package folder.
|
|
44
34
|
|
|
45
|
-
|
|
46
35
|
| Script | Action |
|
|
47
36
|
| -------------------- | ---------------------------------------- |
|
|
48
37
|
| `npm run test` | To run vitest |
|
|
@@ -53,8 +42,6 @@ The following scripts should be run inside the react package folder.
|
|
|
53
42
|
| `npm run build:storybook` | To build storybook |
|
|
54
43
|
| `npm run storybook` | To run storybook |
|
|
55
44
|
|
|
56
|
-
|
|
57
|
-
|
|
58
45
|
## Contributors ✨
|
|
59
46
|
|
|
60
47
|
Thanks goes to these wonderful people:
|
|
@@ -72,12 +59,12 @@ Thanks goes to these wonderful people:
|
|
|
72
59
|
<td align="center" valign="top" width="14.28%"><a href="https://gitlab.com/catia.costa1">
|
|
73
60
|
<div><img src="https://gitlab.com/uploads/-/system/user/avatar/25728410/avatar.png" width="200px;" alt=""/></div>
|
|
74
61
|
<small>Catia Costa</small>
|
|
75
|
-
<div><a href="#a11y-catia.costa1" title="Accessibility">️️️️♿️</a> <a href="
|
|
62
|
+
<div><a href="#a11y-catia.costa1" title="Accessibility">️️️️♿️</a> <a href="#code-catia.costa1" title="Code">💻</a> <a href="#doc-catia.costa1" title="Documentation">📖</a> <a href="#test-catia.costa1" title="Tests">⚠️</a></div>
|
|
76
63
|
</a></td>
|
|
77
64
|
<td align="center" valign="top" width="14.28%"><a href="https://gitlab.com/chris.latimer">
|
|
78
65
|
<div><img src="https://gitlab.com/uploads/-/system/user/avatar/10570471/avatar.png" width="200px;" alt=""/></div>
|
|
79
66
|
<small>Chris Latimer</small>
|
|
80
|
-
<div><a href="#infra-chris.latimer" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="
|
|
67
|
+
<div><a href="#infra-chris.latimer" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#code-chris.latimer" title="Code">💻</a></div>
|
|
81
68
|
</a></td>
|
|
82
69
|
<td align="center" valign="top" width="14.28%"><a href="https://gitlab.com/craig.mckay">
|
|
83
70
|
<div><img src="https://s3.eu-west-1.amazonaws.com/assets.digital.coop.co.uk/oneweb/blank.jpg" width="200px;" alt=""/></div>
|
|
@@ -92,7 +79,7 @@ Thanks goes to these wonderful people:
|
|
|
92
79
|
<td align="center" valign="top" width="14.28%"><a href="https://gitlab.com/emalin.matthews">
|
|
93
80
|
<div><img src="https://ca.slack-edge.com/T0C9E3ZF0-UMGDXU8JH-ade541a7f09e-150" width="200px;" alt=""/></div>
|
|
94
81
|
<small>Emalin Matthews</small>
|
|
95
|
-
<div><a href="#a11y-emalin.matthews" title="Accessibility">️️️️♿️</a> <a href="
|
|
82
|
+
<div><a href="#a11y-emalin.matthews" title="Accessibility">️️️️♿️</a> <a href="#code-emalin.matthews" title="Code">💻</a> <a href="#doc-emalin.matthews" title="Documentation">📖</a> <a href="#test-emalin.matthews" title="Tests">⚠️</a></div>
|
|
96
83
|
</a></td>
|
|
97
84
|
<td align="center" valign="top" width="14.28%"><a href="https://gitlab.com/jelena.milosevic">
|
|
98
85
|
<div><img src="https://s3.eu-west-1.amazonaws.com/assets.digital.coop.co.uk/oneweb/blank.jpg" width="200px;" alt=""/></div>
|
|
@@ -104,7 +91,7 @@ Thanks goes to these wonderful people:
|
|
|
104
91
|
<td align="center" valign="top" width="14.28%"><a href="https://gitlab.com/kamini.pagare">
|
|
105
92
|
<div><img src="https://s3.eu-west-1.amazonaws.com/assets.digital.coop.co.uk/oneweb/blank.jpg" width="200px;" alt=""/></div>
|
|
106
93
|
<small>Kamini Pagare</small>
|
|
107
|
-
<div><a href="#a11y-kamini.pagare" title="Accessibility">️️️️♿️</a> <a href="
|
|
94
|
+
<div><a href="#a11y-kamini.pagare" title="Accessibility">️️️️♿️</a> <a href="#code-kamini.pagare" title="Code">💻</a> <a href="#doc-kamini.pagare" title="Documentation">📖</a> <a href="#test-kamini.pagare" title="Tests">⚠️</a></div>
|
|
108
95
|
</a></td>
|
|
109
96
|
<td align="center" valign="top" width="14.28%"><a href="">
|
|
110
97
|
<div><img src="https://ca.slack-edge.com/T0C9E3ZF0-U3AJ40BGS-ec515dc443cb-150" width="200px;" alt=""/></div>
|
|
@@ -124,12 +111,12 @@ Thanks goes to these wonderful people:
|
|
|
124
111
|
<td align="center" valign="top" width="14.28%"><a href="https://gitlab.com/omid.kashan">
|
|
125
112
|
<div><img src="https://secure.gravatar.com/avatar/faf90b70d749cf9460eb603fa1700add94fd7d3a32645b4be6fa12eb45c4ffa3?s=80&d=identicon" width="200px;" alt=""/></div>
|
|
126
113
|
<small>Omid Kashan</small>
|
|
127
|
-
<div><a href="#a11y-omid.kashan" title="Accessibility">️️️️♿️</a> <a href="
|
|
114
|
+
<div><a href="#a11y-omid.kashan" title="Accessibility">️️️️♿️</a> <a href="#code-omid.kashan" title="Code">💻</a> <a href="#doc-omid.kashan" title="Documentation">📖</a> <a href="#test-omid.kashan" title="Tests">⚠️</a></div>
|
|
128
115
|
</a></td>
|
|
129
116
|
<td align="center" valign="top" width="14.28%"><a href="https://gitlab.com/sam.harden">
|
|
130
117
|
<div><img src="https://ca.slack-edge.com/T0C9E3ZF0-U03NT7D39L6-2fc82e7f7c6e-150" width="200px;" alt=""/></div>
|
|
131
118
|
<small>Sam Harden</small>
|
|
132
|
-
<div><a href="#a11y-sam.harden" title="Accessibility">️️️️♿️</a> <a href="
|
|
119
|
+
<div><a href="#a11y-sam.harden" title="Accessibility">️️️️♿️</a> <a href="#code-sam.harden" title="Code">💻</a> <a href="#doc-sam.harden" title="Documentation">📖</a> <a href="#test-sam.harden" title="Tests">⚠️</a></div>
|
|
133
120
|
</a></td>
|
|
134
121
|
<td align="center" valign="top" width="14.28%"><a href="">
|
|
135
122
|
<div><img src="https://s3.eu-west-1.amazonaws.com/assets.digital.coop.co.uk/oneweb/blank.jpg" width="200px;" alt=""/></div>
|
|
@@ -141,7 +128,7 @@ Thanks goes to these wonderful people:
|
|
|
141
128
|
<td align="center" valign="top" width="14.28%"><a href="https://gitlab.com/theodore.kouzelis">
|
|
142
129
|
<div><img src="https://secure.gravatar.com/avatar/3988f940029d9053174ac68e7f5bfa8fd61f184872d46281f44e2e698711d37d?s=80&d=identicon" width="200px;" alt=""/></div>
|
|
143
130
|
<small>Theo Kouzelis</small>
|
|
144
|
-
<div><a href="#a11y-theodore.kouzelis" title="Accessibility">️️️️♿️</a> <a href="
|
|
131
|
+
<div><a href="#a11y-theodore.kouzelis" title="Accessibility">️️️️♿️</a> <a href="#code-theodore.kouzelis" title="Code">💻</a> <a href="#doc-theodore.kouzelis" title="Documentation">📖</a> <a href="#test-theodore.kouzelis" title="Tests">⚠️</a></div>
|
|
145
132
|
</a></td>
|
|
146
133
|
</tr>
|
|
147
134
|
</tbody></table>
|
|
@@ -152,9 +139,4 @@ Thanks goes to these wonderful people:
|
|
|
152
139
|
|
|
153
140
|
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
|
154
141
|
|
|
155
|
-
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification.
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
## Troubleshooting
|
|
159
|
-
|
|
160
|
-
This is still a work in progress, we appreciate feedback. If you have any issues, please get in touch via [tech query channel on slack](https://co-opdigital.slack.com/archives/C0167V69R8W).
|
|
142
|
+
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React, { AnchorHTMLAttributes, ForwardRefExoticComponent } from "react";
|
|
2
|
+
export interface PillProps {
|
|
3
|
+
as?: React.FC<AnchorHTMLAttributes<HTMLElement>> | ForwardRefExoticComponent<any> | string;
|
|
4
|
+
ariaLabel?: string;
|
|
5
|
+
badge?: string;
|
|
6
|
+
badgeColor?: "green" | "orange" | "red" | "pink";
|
|
7
|
+
children?: React.ReactNode;
|
|
8
|
+
className?: string;
|
|
9
|
+
href?: string;
|
|
10
|
+
pillColor?: "blue" | "pink";
|
|
11
|
+
size?: "sm" | "md" | "lg" | "xl";
|
|
12
|
+
}
|
|
13
|
+
export declare const Pill: ({ ariaLabel, as, badge, badgeColor, children, className, href, pillColor, size, }: PillProps) => React.ReactElement<React.AnchorHTMLAttributes<HTMLElement>, string | React.JSXElementConstructor<any>>;
|
|
14
|
+
export default Pill;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
const Pill = ({ ariaLabel, as, badge, badgeColor = "red", children, className = "", href, pillColor = "blue", size = "md", }) => {
|
|
4
|
+
let element = href ? "a" : "span";
|
|
5
|
+
if (as) {
|
|
6
|
+
element = as;
|
|
7
|
+
}
|
|
8
|
+
const componentProps = {
|
|
9
|
+
"aria-label": ariaLabel,
|
|
10
|
+
className: `coop-pill ${className}`,
|
|
11
|
+
"data-badge": (badge === null || badge === void 0 ? void 0 : badge.length) ? badge : undefined,
|
|
12
|
+
"data-badge-color": badgeColor,
|
|
13
|
+
"data-pill-color": pillColor,
|
|
14
|
+
"data-size": size.length && size != "md" ? size : undefined,
|
|
15
|
+
href,
|
|
16
|
+
};
|
|
17
|
+
return React.createElement(element, Object.assign({}, componentProps), children);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { Pill, Pill as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from "
|
|
1
|
+
export * from "./components/Button";
|
|
2
|
+
export * from "./components/Pill";
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coopdigital/react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"main": "
|
|
4
|
+
"version": "0.4.0",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
6
|
"private": false,
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
10
10
|
"files": [
|
|
11
11
|
"dist",
|
|
12
|
-
"src"
|
|
12
|
+
"src",
|
|
13
|
+
"!**/__{screenshots,tests}__",
|
|
14
|
+
"!**/*.{stories,test}.*"
|
|
13
15
|
],
|
|
14
16
|
"scripts": {
|
|
15
17
|
"test": "vitest run",
|
|
18
|
+
"test:watch": "vitest",
|
|
16
19
|
"test:coverage": "vitest run --coverage",
|
|
17
20
|
"build": "tsx scripts build",
|
|
18
21
|
"build:storybook": "storybook build --disable-telemetry && npm run storybook:fix-paths",
|
|
@@ -27,30 +30,31 @@
|
|
|
27
30
|
"description": "",
|
|
28
31
|
"devDependencies": {
|
|
29
32
|
"@axe-core/playwright": "^4.10.1",
|
|
30
|
-
"@chromatic-com/storybook": "^3.2.
|
|
31
|
-
"@coopdigital/styles": "^0.
|
|
33
|
+
"@chromatic-com/storybook": "^3.2.5",
|
|
34
|
+
"@coopdigital/styles": "^0.5.1",
|
|
32
35
|
"@playwright/test": "^1.50.1",
|
|
33
36
|
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
34
37
|
"@rollup/plugin-typescript": "^12.1.2",
|
|
35
|
-
"@storybook/addon-essentials": "^8.
|
|
36
|
-
"@storybook/addon-interactions": "^8.
|
|
37
|
-
"@storybook/addon-
|
|
38
|
-
"@storybook/
|
|
39
|
-
"@storybook/
|
|
40
|
-
"@storybook/
|
|
41
|
-
"@storybook/react
|
|
42
|
-
"@storybook/
|
|
43
|
-
"@storybook/
|
|
38
|
+
"@storybook/addon-essentials": "^8.6.3",
|
|
39
|
+
"@storybook/addon-interactions": "^8.6.3",
|
|
40
|
+
"@storybook/addon-mdx-gfm": "^8.6.3",
|
|
41
|
+
"@storybook/addon-onboarding": "^8.6.3",
|
|
42
|
+
"@storybook/blocks": "^8.6.3",
|
|
43
|
+
"@storybook/manager-api": "^8.6.3",
|
|
44
|
+
"@storybook/react": "^8.6.3",
|
|
45
|
+
"@storybook/react-vite": "^8.6.3",
|
|
46
|
+
"@storybook/test": "^8.6.3",
|
|
47
|
+
"@storybook/theming": "^8.6.3",
|
|
44
48
|
"@testing-library/jest-dom": "^6.6.3",
|
|
45
49
|
"@testing-library/react": "^16.2.0",
|
|
46
50
|
"@types/react": "^19.0.10",
|
|
47
51
|
"@types/react-dom": "^19.0.4",
|
|
48
52
|
"rollup": "^4.34.8",
|
|
49
|
-
"storybook": "^8.
|
|
53
|
+
"storybook": "^8.6.3"
|
|
50
54
|
},
|
|
51
55
|
"peerDependencies": {
|
|
52
56
|
"react": "^19.0.0",
|
|
53
57
|
"react-dom": "^19.0.0"
|
|
54
58
|
},
|
|
55
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "5f4108a06b915b2bd2c757bd713026e0710b0eb9"
|
|
56
60
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import React, { AnchorHTMLAttributes, ForwardRefExoticComponent } from "react"
|
|
2
|
+
|
|
3
|
+
export interface PillProps {
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
|
+
as?: React.FC<AnchorHTMLAttributes<HTMLElement>> | ForwardRefExoticComponent<any> | string
|
|
6
|
+
ariaLabel?: string
|
|
7
|
+
badge?: string
|
|
8
|
+
badgeColor?: "green" | "orange" | "red" | "pink"
|
|
9
|
+
children?: React.ReactNode
|
|
10
|
+
className?: string
|
|
11
|
+
href?: string
|
|
12
|
+
pillColor?: "blue" | "pink"
|
|
13
|
+
size?: "sm" | "md" | "lg" | "xl"
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const Pill = ({
|
|
17
|
+
ariaLabel,
|
|
18
|
+
as,
|
|
19
|
+
badge,
|
|
20
|
+
badgeColor = "red",
|
|
21
|
+
children,
|
|
22
|
+
className = "",
|
|
23
|
+
href,
|
|
24
|
+
pillColor = "blue",
|
|
25
|
+
size = "md",
|
|
26
|
+
}: PillProps) => {
|
|
27
|
+
let element: PillProps["as"] = href ? "a" : "span"
|
|
28
|
+
|
|
29
|
+
if (as) {
|
|
30
|
+
element = as
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const componentProps = {
|
|
34
|
+
"aria-label": ariaLabel,
|
|
35
|
+
className: `coop-pill ${className}`,
|
|
36
|
+
"data-badge": badge?.length ? badge : undefined,
|
|
37
|
+
"data-badge-color": badgeColor,
|
|
38
|
+
"data-pill-color": pillColor,
|
|
39
|
+
"data-size": size.length && size != "md" ? size : undefined,
|
|
40
|
+
href,
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return React.createElement(element, { ...componentProps }, children)
|
|
44
|
+
}
|
|
45
|
+
export default Pill
|
package/src/index.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from "
|
|
1
|
+
export * from "./components/Button"
|
|
2
|
+
export * from "./components/Pill"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "@playwright/test"
|
|
2
|
-
|
|
3
|
-
const server_url = "/iframe.html?viewMode=story&id=components-button--primary&args=&globals="
|
|
4
|
-
|
|
5
|
-
test("Add to basket button visibility", async ({ page }) => {
|
|
6
|
-
await page.goto(server_url)
|
|
7
|
-
await expect(page.getByRole("button", { name: "Add to basket" })).toBeVisible()
|
|
8
|
-
})
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from "@storybook/react"
|
|
2
|
-
|
|
3
|
-
import Button from "./Button"
|
|
4
|
-
|
|
5
|
-
const meta = {
|
|
6
|
-
component: Button,
|
|
7
|
-
} satisfies Meta<typeof Button>
|
|
8
|
-
|
|
9
|
-
export default meta
|
|
10
|
-
|
|
11
|
-
type Story = StoryObj<typeof meta>
|
|
12
|
-
|
|
13
|
-
export const Primary: Story = {}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @vitest-environment jsdom
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { render } from "@testing-library/react"
|
|
6
|
-
import { describe, it, afterEach } from "vitest"
|
|
7
|
-
import { Button } from "."
|
|
8
|
-
import { cleanup } from "@testing-library/react"
|
|
9
|
-
afterEach(() => {
|
|
10
|
-
cleanup()
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
describe("Button", () => {
|
|
14
|
-
it("renders button", () => {
|
|
15
|
-
render(<Button />)
|
|
16
|
-
//screen.debug()
|
|
17
|
-
})
|
|
18
|
-
})
|