@coopdigital/react 0.2.0 → 0.3.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 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="https://gitlab.com/coopeng/sds/oneweb/experience-kit/commits/master" title="Code">💻</a> <a href="https://gitlab.com/coopeng/sds/oneweb/experience-kit/commits/master" title="Documentation">📖</a> <a href="https://gitlab.com/coopeng/sds/oneweb/experience-kit/commits/master" title="Tests">⚠️</a></div>
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="https://gitlab.com/coopeng/sds/oneweb/experience-kit/commits/master" title="Code">💻</a></div>
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="https://gitlab.com/coopeng/sds/oneweb/experience-kit/commits/master" title="Code">💻</a> <a href="https://gitlab.com/coopeng/sds/oneweb/experience-kit/commits/master" title="Documentation">📖</a> <a href="https://gitlab.com/coopeng/sds/oneweb/experience-kit/commits/master" title="Tests">⚠️</a></div>
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="https://gitlab.com/coopeng/sds/oneweb/experience-kit/commits/master" title="Code">💻</a> <a href="https://gitlab.com/coopeng/sds/oneweb/experience-kit/commits/master" title="Documentation">📖</a> <a href="https://gitlab.com/coopeng/sds/oneweb/experience-kit/commits/master" title="Tests">⚠️</a></div>
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="https://gitlab.com/coopeng/sds/oneweb/experience-kit/commits/master" title="Code">💻</a> <a href="https://gitlab.com/coopeng/sds/oneweb/experience-kit/commits/master" title="Documentation">📖</a> <a href="https://gitlab.com/coopeng/sds/oneweb/experience-kit/commits/master" title="Tests">⚠️</a></div>
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="https://gitlab.com/coopeng/sds/oneweb/experience-kit/commits/master" title="Code">💻</a> <a href="https://gitlab.com/coopeng/sds/oneweb/experience-kit/commits/master" title="Documentation">📖</a> <a href="https://gitlab.com/coopeng/sds/oneweb/experience-kit/commits/master" title="Tests">⚠️</a></div>
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="https://gitlab.com/coopeng/sds/oneweb/experience-kit/commits/master" title="Code">💻</a> <a href="https://gitlab.com/coopeng/sds/oneweb/experience-kit/commits/master" title="Documentation">📖</a> <a href="https://gitlab.com/coopeng/sds/oneweb/experience-kit/commits/master" title="Tests">⚠️</a></div>
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. Check out the [contributing guidelines](https://gitlab.com/coopeng/sds/oneweb/experience-kit/-/blob/main/CONTRIBUTING.md) to add new people. Contributions of any kind welcome!
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,21 @@
1
+ import React from "react";
2
+ export interface PillProps {
3
+ ariaLabel?: string;
4
+ badge?: string;
5
+ badgeColor?: "green" | "orange" | "red" | "pink";
6
+ children?: React.ReactNode;
7
+ className?: string;
8
+ href?: string;
9
+ pillColor?: "blue" | "pink";
10
+ size?: "sm" | "md" | "lg" | "xl";
11
+ }
12
+ export declare const Pill: ({ ariaLabel, badge, badgeColor, children, className, href, pillColor, size, }: PillProps) => React.DetailedReactHTMLElement<{
13
+ "aria-label": string | undefined;
14
+ className: string;
15
+ "data-badge": string | undefined;
16
+ "data-badge-color": "green" | "orange" | "red" | "pink";
17
+ "data-pill-color": "pink" | "blue";
18
+ "data-size": "sm" | "lg" | "xl" | undefined;
19
+ href: string | undefined;
20
+ }, HTMLElement>;
21
+ export default Pill;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+
3
+ const Pill = ({ ariaLabel, badge, badgeColor = "red", children, className = "", href, pillColor = "blue", size = "md", }) => {
4
+ const element = href ? "a" : "span";
5
+ const componentProps = {
6
+ "aria-label": ariaLabel,
7
+ className: `coop-pill ${className}`,
8
+ "data-badge": (badge === null || badge === void 0 ? void 0 : badge.length) ? badge : undefined,
9
+ "data-badge-color": badgeColor,
10
+ "data-pill-color": pillColor,
11
+ "data-size": size.length && size != "md" ? size : undefined,
12
+ href,
13
+ };
14
+ return React.createElement(element, Object.assign({}, componentProps), children);
15
+ };
16
+
17
+ export { Pill, Pill as default };
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @vitest-environment jsdom
3
+ */
4
+ export {};
@@ -0,0 +1,4 @@
1
+ import Pill from "./Pill";
2
+ export default Pill;
3
+ export { Pill };
4
+ export * from "./Pill";
package/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
- export * from "@/components/Button";
1
+ export * from "./components/Button";
2
+ export * from "./components/Pill";
package/dist/index.js CHANGED
@@ -1 +1,2 @@
1
1
  export { Button } from './components/Button/Button.js';
2
+ export { Pill } from './components/Pill/Pill.js';
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@coopdigital/react",
3
3
  "type": "module",
4
- "version": "0.2.0",
5
- "main": "src/index.ts",
4
+ "version": "0.3.0",
5
+ "main": "dist/index.js",
6
6
  "private": false,
7
7
  "publishConfig": {
8
8
  "access": "public"
@@ -27,30 +27,31 @@
27
27
  "description": "",
28
28
  "devDependencies": {
29
29
  "@axe-core/playwright": "^4.10.1",
30
- "@chromatic-com/storybook": "^3.2.4",
31
- "@coopdigital/styles": "^0.4.0",
30
+ "@chromatic-com/storybook": "^3.2.5",
31
+ "@coopdigital/styles": "^0.5.0",
32
32
  "@playwright/test": "^1.50.1",
33
33
  "@rollup/plugin-node-resolve": "^16.0.0",
34
34
  "@rollup/plugin-typescript": "^12.1.2",
35
- "@storybook/addon-essentials": "^8.5.8",
36
- "@storybook/addon-interactions": "^8.5.8",
37
- "@storybook/addon-onboarding": "^8.5.8",
38
- "@storybook/blocks": "^8.5.8",
39
- "@storybook/manager-api": "^8.5.8",
40
- "@storybook/react": "^8.5.8",
41
- "@storybook/react-vite": "^8.5.8",
42
- "@storybook/test": "^8.5.8",
43
- "@storybook/theming": "^8.5.8",
35
+ "@storybook/addon-essentials": "^8.6.3",
36
+ "@storybook/addon-interactions": "^8.6.3",
37
+ "@storybook/addon-mdx-gfm": "^8.6.3",
38
+ "@storybook/addon-onboarding": "^8.6.3",
39
+ "@storybook/blocks": "^8.6.3",
40
+ "@storybook/manager-api": "^8.6.3",
41
+ "@storybook/react": "^8.6.3",
42
+ "@storybook/react-vite": "^8.6.3",
43
+ "@storybook/test": "^8.6.3",
44
+ "@storybook/theming": "^8.6.3",
44
45
  "@testing-library/jest-dom": "^6.6.3",
45
46
  "@testing-library/react": "^16.2.0",
46
47
  "@types/react": "^19.0.10",
47
48
  "@types/react-dom": "^19.0.4",
48
49
  "rollup": "^4.34.8",
49
- "storybook": "^8.5.8"
50
+ "storybook": "^8.6.3"
50
51
  },
51
52
  "peerDependencies": {
52
53
  "react": "^19.0.0",
53
54
  "react-dom": "^19.0.0"
54
55
  },
55
- "gitHead": "500daac771417639d21d083af67e4570ad1da09b"
56
+ "gitHead": "ccedccf7209f30e95b5312052836bbd745410d0c"
56
57
  }
@@ -2,9 +2,9 @@ import type { Meta, StoryObj } from "@storybook/react"
2
2
 
3
3
  import Button from "./Button"
4
4
 
5
- const meta = {
5
+ const meta: Meta<typeof Button> = {
6
6
  component: Button,
7
- } satisfies Meta<typeof Button>
7
+ }
8
8
 
9
9
  export default meta
10
10
 
@@ -0,0 +1,134 @@
1
+ import { expect, test } from "@playwright/test"
2
+ import AxeBuilder from "@axe-core/playwright"
3
+
4
+ const defaultUrl = "/iframe.html?globals=&args=&id=components-pill--default&viewMode=story"
5
+ const withoutLinkUrl = "/iframe.html?globals=&args=&id=components-pill--without-link&viewMode=story"
6
+ const withBadgeUrl = "/iframe.html?globals=&args=&id=components-pill--with-badge&viewMode=story"
7
+
8
+ test.describe("Pill default", () => {
9
+ test("Renders", async ({ page }) => {
10
+ await page.goto(defaultUrl)
11
+ const pill = page.getByRole("link", { name: "Be more Co-op" })
12
+ await expect(pill).toBeVisible()
13
+ await expect(pill).toHaveAttribute("href", "/be-more-co-op")
14
+ })
15
+
16
+ test("Does accept additional classes", async ({ page }) => {
17
+ await page.goto(defaultUrl + "&args=className:coop--uppercase")
18
+ const pill = page.getByRole("link", { name: "Be more Co-op" })
19
+ await expect(pill).toHaveClass(/coop-pill/)
20
+ await expect(pill).toHaveClass(/coop--uppercase/)
21
+ })
22
+
23
+ test("Doesn't display new badge", async ({ page }) => {
24
+ await page.goto(defaultUrl)
25
+ const pill = page.getByRole("link", { name: "Be more Co-op" })
26
+ await expect(pill).not.toHaveAttribute("data-badge")
27
+ })
28
+
29
+ test("Doesn't have any automatically detectable accessibility issues", async ({ page }) => {
30
+ await page.goto(defaultUrl)
31
+
32
+ await page.locator("#storybook-root").waitFor()
33
+
34
+ const accessibilityScanResults = await new AxeBuilder({ page })
35
+ .include("#storybook-root")
36
+ .analyze()
37
+
38
+ expect(accessibilityScanResults.violations).toEqual([])
39
+ })
40
+
41
+ test("Does match the previous screenshot", async ({ page }) => {
42
+ await page.goto(defaultUrl)
43
+ await expect(page).toHaveScreenshot()
44
+ })
45
+ })
46
+
47
+ test.describe("Pill with badge", () => {
48
+ test("Renders and has the badge", async ({ page }) => {
49
+ await page.goto(withBadgeUrl)
50
+ const pill = page.getByRole("link", { name: "Your weekly offers" })
51
+ await expect(pill).toBeVisible()
52
+ await expect(pill).toHaveAttribute("href", "/your-weekly-offers")
53
+ await expect(pill).toHaveAttribute("data-badge")
54
+ })
55
+
56
+ test("Doesn't have any automatically detectable accessibility issues", async ({ page }) => {
57
+ await page.goto(withBadgeUrl)
58
+
59
+ await page.locator("#storybook-root").waitFor()
60
+
61
+ const accessibilityScanResults = await new AxeBuilder({ page })
62
+ .include("#storybook-root")
63
+ .analyze()
64
+
65
+ expect(accessibilityScanResults.violations).toEqual([])
66
+ })
67
+
68
+ test("Does match the previous screenshot", async ({ page }) => {
69
+ await page.goto(withBadgeUrl)
70
+ await expect(page).toHaveScreenshot()
71
+ })
72
+ })
73
+
74
+ test.describe("Pill with or without href", () => {
75
+ test("Doesn't add a link when href is not provided", async ({ page }) => {
76
+ await page.goto(withoutLinkUrl)
77
+ const pill = page.locator("span.coop-pill")
78
+ await expect(pill).toBeVisible()
79
+ })
80
+
81
+ test("Renders a link when href is provided", async ({ page }) => {
82
+ await page.goto(withoutLinkUrl + "&args=href:test")
83
+ const pill = page.locator("a.coop-pill")
84
+ await expect(pill).toBeVisible()
85
+ })
86
+ })
87
+
88
+ test.describe("Pill size attribute", () => {
89
+ test("Doesn't apply data-size when size is 'md' (default)", async ({ page }) => {
90
+ await page.goto(defaultUrl + "&args=size:md")
91
+ const pill = page.locator(".coop-pill")
92
+ await expect(pill).not.toHaveAttribute("data-size")
93
+ })
94
+
95
+ test("Doesn't apply data-size when size is undefined", async ({ page }) => {
96
+ await page.goto(defaultUrl)
97
+ const pill = page.locator(".coop-pill")
98
+ await expect(pill).not.toHaveAttribute("data-size")
99
+ })
100
+
101
+ test("Does NOT apply data-size when size is an empty string", async ({ page }) => {
102
+ await page.goto(defaultUrl + "&args=size:")
103
+ const pill = page.locator(".coop-pill")
104
+ await expect(pill).not.toHaveAttribute("data-size")
105
+ })
106
+ })
107
+
108
+ test.describe("Pill badge color attribute", () => {
109
+ test("Applies data-badge-color when badgeColor is 'orange'", async ({ page }) => {
110
+ await page.goto(defaultUrl + "&args=badgeColor:orange")
111
+ const pill = page.locator(".coop-pill")
112
+ await expect(pill).toHaveAttribute("data-badge-color", "orange")
113
+ })
114
+
115
+ test("Applies default badge color when badgeColor is not provided", async ({ page }) => {
116
+ await page.goto(defaultUrl)
117
+ const pill = page.locator(".coop-pill")
118
+ await expect(pill).toHaveAttribute("data-badge-color", "red")
119
+ })
120
+ })
121
+
122
+ test.describe("Pill color attribute", () => {
123
+ test("Applies data-pill-color when pillColor is 'pink'", async ({ page }) => {
124
+ await page.goto(defaultUrl + "&args=pillColor:pink")
125
+ const pill = page.locator(".coop-pill")
126
+ await expect(pill).toHaveAttribute("data-pill-color", "pink")
127
+ })
128
+
129
+ test("Applies default pill color when pillColor is not provided", async ({ page }) => {
130
+ await page.goto(defaultUrl)
131
+ const pill = page.locator(".coop-pill")
132
+ await expect(pill).toHaveAttribute("data-pill-color", "blue")
133
+ })
134
+ })
@@ -0,0 +1,138 @@
1
+ import type { Meta, StoryObj } from "@storybook/react"
2
+ import "../../../../styles/src/components/Pill.scss"
3
+
4
+ import Pill from "./Pill"
5
+
6
+ const meta: Meta<typeof Pill> = {
7
+ component: Pill,
8
+ argTypes: {
9
+ href: {
10
+ description: "Specifies the URL that the Pill component will link to when clicked.",
11
+ },
12
+ children: {
13
+ description:
14
+ "Represents the content inside the Pill component. It can be any valid JSX or string.",
15
+ control: false,
16
+ },
17
+ className: {
18
+ description: "Receives any optional className to be applied to Pill component.",
19
+ },
20
+ badge: {
21
+ description: "Specifies what text Pill should display on the badge.",
22
+ },
23
+ size: {
24
+ description: "Specifies what should be the Pill size.",
25
+ },
26
+ },
27
+ parameters: {
28
+ docs: {
29
+ description: {
30
+ component:
31
+ "The Pill component is a small, rounded label used to link and highlight information such as categories or articles. It can be customised with different content and styles to suit various use cases.",
32
+ },
33
+ },
34
+ },
35
+ }
36
+
37
+ export default meta
38
+
39
+ type Story = StoryObj<typeof meta>
40
+
41
+ export const Default: Story = {
42
+ args: { href: "/be-more-co-op", children: "Be more Co-op" },
43
+ parameters: {
44
+ docs: {
45
+ description: {
46
+ story: "Displays a basic Pill with default settings.",
47
+ },
48
+ },
49
+ },
50
+ }
51
+
52
+ export const WithoutLink: Story = {
53
+ args: { children: "Be more Co-op" },
54
+ parameters: {
55
+ docs: {
56
+ description: {
57
+ story: "Displays a basic Pill as basic <span> element.",
58
+ },
59
+ },
60
+ },
61
+ }
62
+
63
+ export const WithBadge: Story = {
64
+ args: {
65
+ href: "/your-weekly-offers",
66
+ badge: "NEW",
67
+ children: "Your weekly offers",
68
+ },
69
+ parameters: {
70
+ docs: {
71
+ description: {
72
+ story: "Displays a Pill with an additional custom badge to indicate new content.",
73
+ },
74
+ },
75
+ },
76
+ }
77
+
78
+ export const Sizes: Story = {
79
+ args: {
80
+ children: "Your weekly offers",
81
+ },
82
+ parameters: {
83
+ docs: {
84
+ description: {
85
+ story: "Displays all the 4 sizes supported.",
86
+ },
87
+ },
88
+ },
89
+ render: (args) => (
90
+ <>
91
+ <div className="coop-pill-group">
92
+ <Pill {...args} size="xl" />
93
+ <Pill {...args} size="lg" />
94
+ <Pill {...args} size="md" />
95
+ <Pill {...args} size="sm" />
96
+ </div>
97
+ <div className="coop-pill-group">
98
+ <Pill {...args} badge="NEW" size="xl" />
99
+ <Pill {...args} badge="NEW" size="lg" />
100
+ <Pill {...args} badge="NEW" size="md" />
101
+ <Pill {...args} badge="NEW" size="sm" />
102
+ </div>
103
+ </>
104
+ ),
105
+ }
106
+
107
+ export const ColourVariations: Story = {
108
+ args: {
109
+ children: "Your weekly offers",
110
+ },
111
+ parameters: {
112
+ docs: {
113
+ description: {
114
+ story: "Displays all the colour variations supported for Badge and Pill.",
115
+ },
116
+ },
117
+ },
118
+ render: (args) => (
119
+ <>
120
+ <div className="coop-pill-group">
121
+ <Pill {...args} pillColor="blue" />
122
+ <Pill {...args} pillColor="pink" />
123
+ </div>
124
+ <div className="coop-pill-group">
125
+ <Pill {...args} badge="NEW" pillColor="blue" badgeColor="red" />
126
+ <Pill {...args} badge="NEW" pillColor="blue" badgeColor="green" />
127
+ <Pill {...args} badge="NEW" pillColor="blue" badgeColor="orange" />
128
+ <Pill {...args} badge="NEW" pillColor="blue" badgeColor="pink" />
129
+ </div>
130
+ <div className="coop-pill-group">
131
+ <Pill {...args} badge="NEW" pillColor="pink" badgeColor="red" />
132
+ <Pill {...args} badge="NEW" pillColor="pink" badgeColor="green" />
133
+ <Pill {...args} badge="NEW" pillColor="pink" badgeColor="orange" />
134
+ <Pill {...args} badge="NEW" pillColor="pink" badgeColor="pink" />
135
+ </div>
136
+ </>
137
+ ),
138
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @vitest-environment jsdom
3
+ */
4
+
5
+ import { render, cleanup } from "@testing-library/react"
6
+ import { describe, it, afterEach } from "vitest"
7
+ import { Pill } from "."
8
+
9
+ afterEach(() => {
10
+ cleanup()
11
+ })
12
+
13
+ describe("Pill", () => {
14
+ it("Renders default Pill", () => {
15
+ render(<Pill href="test/abc">Add missing receipt</Pill>)
16
+ })
17
+
18
+ it("Renders Pill with badge", () => {
19
+ render(
20
+ <Pill href="test/abc" badge="NEW">
21
+ <span>Add missing receipt</span>
22
+ </Pill>
23
+ )
24
+ })
25
+ })
@@ -0,0 +1,38 @@
1
+ import React from "react"
2
+
3
+ export interface PillProps {
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
+
14
+ export const Pill = ({
15
+ ariaLabel,
16
+ badge,
17
+ badgeColor = "red",
18
+ children,
19
+ className = "",
20
+ href,
21
+ pillColor = "blue",
22
+ size = "md",
23
+ }: PillProps) => {
24
+ const element = href ? "a" : "span"
25
+
26
+ const componentProps = {
27
+ "aria-label": ariaLabel,
28
+ className: `coop-pill ${className}`,
29
+ "data-badge": badge?.length ? badge : undefined,
30
+ "data-badge-color": badgeColor,
31
+ "data-pill-color": pillColor,
32
+ "data-size": size.length && size != "md" ? size : undefined,
33
+ href,
34
+ }
35
+
36
+ return React.createElement(element, { ...componentProps }, children)
37
+ }
38
+ export default Pill
@@ -0,0 +1,5 @@
1
+ import Pill from "./Pill"
2
+
3
+ export default Pill
4
+ export { Pill }
5
+ export * from "./Pill"
package/src/index.ts CHANGED
@@ -1 +1,2 @@
1
- export * from "@/components/Button"
1
+ export * from "./components/Button"
2
+ export * from "./components/Pill"
@@ -0,0 +1,33 @@
1
+ import { ColorPalette, ColorItem } from "@storybook/blocks"
2
+
3
+ <ColorPalette>
4
+ <ColorItem
5
+ title="theme.color.greyscale"
6
+ subtitle="Some of the greys"
7
+ colors={{ White: "#FFFFFF", Alabaster: "#F8F8F8", Concrete: "#F3F3F3" }}
8
+ />
9
+ <ColorItem title="theme.color.primary" subtitle="Coral" colors={{ WildWatermelon: "#FF4785" }} />
10
+ <ColorItem title="theme.color.secondary" subtitle="Ocean" colors={{ DodgerBlue: "#1EA7FD" }} />
11
+ <ColorItem
12
+ title="theme.color.positive"
13
+ subtitle="Green"
14
+ colors={{
15
+ Apple: "rgba(102,191,60,1)",
16
+ Apple80: "rgba(102,191,60,.8)",
17
+ Apple60: "rgba(102,191,60,.6)",
18
+ Apple30: "rgba(102,191,60,.3)",
19
+ }}
20
+ />
21
+ <ColorItem
22
+ title="gradient"
23
+ subtitle="Grayscale"
24
+ colors={{
25
+ Gradient: "linear-gradient(to right,white,black)",
26
+ }}
27
+ />
28
+ <ColorItem
29
+ title="gradient"
30
+ subtitle="Grayscale"
31
+ colors={["linear-gradient(65deg,white,black)"]}
32
+ />
33
+ </ColorPalette>
@@ -0,0 +1,17 @@
1
+ import { Unstyled } from "@storybook/blocks"
2
+
3
+ <Unstyled>
4
+ <h1 className="coop-t-headline">h1</h1>
5
+ <h2>h2</h2>
6
+ <h3>h3</h3>
7
+ <h4>h4</h4>
8
+ <h5>h5</h5>
9
+ <h6>h6</h6>
10
+ <p>Paragraph text</p>
11
+ <hr />
12
+
13
+ <ul>
14
+ <li>Option 1</li>
15
+ <li>Option 1</li>
16
+ </ul>
17
+ </Unstyled>