@purpurds/checkbox 5.11.0 → 5.11.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@purpurds/checkbox",
3
- "version": "5.11.0",
3
+ "version": "5.11.2",
4
4
  "license": "AGPL-3.0-only",
5
5
  "main": "./dist/checkbox.cjs.js",
6
6
  "types": "./dist/checkbox.d.ts",
@@ -14,36 +14,36 @@
14
14
  },
15
15
  "source": "src/checkbox.tsx",
16
16
  "dependencies": {
17
- "classnames": "~2.5.0",
18
17
  "@radix-ui/react-checkbox": "~1.0.4",
19
- "@storybook/client-api": "~7.6.0",
20
- "@purpurds/tokens": "5.11.0",
21
- "@purpurds/field-error-text": "5.11.0",
22
- "@purpurds/icon": "5.11.0",
23
- "@purpurds/paragraph": "5.11.0",
24
- "@purpurds/label": "5.11.0"
18
+ "classnames": "~2.5.0",
19
+ "@purpurds/field-error-text": "5.11.2",
20
+ "@purpurds/label": "5.11.2",
21
+ "@purpurds/paragraph": "5.11.2",
22
+ "@purpurds/icon": "5.11.2",
23
+ "@purpurds/tokens": "5.11.2"
25
24
  },
26
25
  "devDependencies": {
27
26
  "@rushstack/eslint-patch": "~1.10.0",
28
- "@storybook/blocks": "~7.6.0",
29
- "@storybook/react": "~7.6.0",
27
+ "@storybook/preview-api": "^8.2.6",
28
+ "@storybook/react": "^8.2.6",
30
29
  "@telia/base-rig": "~8.2.0",
31
30
  "@telia/react-rig": "~3.2.0",
32
31
  "@testing-library/dom": "~9.3.3",
33
32
  "@testing-library/jest-dom": "~6.4.0",
34
33
  "@testing-library/react": "~14.3.0",
35
34
  "@types/node": "20.12.12",
36
- "@types/react-dom": "~18.3.0",
37
- "@types/react": "~18.3.0",
35
+ "@types/react-dom": "^18.3.0",
36
+ "@types/react": "^18.3.3",
38
37
  "eslint-plugin-testing-library": "~6.2.0",
39
- "eslint": "~8.57.0",
38
+ "eslint": "^8.57.0",
40
39
  "jsdom": "~22.1.0",
41
40
  "lint-staged": "~10.5.3",
42
41
  "prettier": "~2.8.8",
43
- "react-dom": "~18.3.0",
44
- "react": "~18.3.0",
45
- "typescript": "~5.4.2",
46
- "vite": "~5.2.2",
42
+ "react-dom": "^18.3.1",
43
+ "react": "^18.3.1",
44
+ "storybook": "^8.2.6",
45
+ "typescript": "^5.5.4",
46
+ "vite": "5.3.4",
47
47
  "vitest": "~1.5.0",
48
48
  "@purpurds/component-rig": "1.0.0"
49
49
  },
@@ -1,17 +1,26 @@
1
- import { useArgs } from "@storybook/client-api";
2
- import type { Meta, StoryObj } from "@storybook/react";
3
1
  import React from "react";
4
- import { Checkbox, CheckedState } from "./checkbox";
2
+ import { useArgs } from "@storybook/preview-api";
3
+ import type { Meta, StoryObj } from "@storybook/react";
5
4
 
6
5
  import "@purpurds/icon/styles";
7
6
  import "@purpurds/field-error-text/styles";
8
7
  import "@purpurds/label/styles";
9
8
  import "@purpurds/paragraph/styles";
9
+ import { Checkbox, CheckedState, checkedState } from "./checkbox";
10
10
 
11
- const meta: Meta<typeof Checkbox> = {
11
+ const meta = {
12
12
  title: "Inputs/Checkbox",
13
13
  component: Checkbox,
14
- };
14
+ parameters: {
15
+ design: [
16
+ {
17
+ name: "Checkbox",
18
+ type: "figma",
19
+ url: "https://www.figma.com/file/XEaIIFskrrxIBHMZDkIuIg/Purpur-DS---Component-library-%26-guidelines?type=design&node-id=1274-614&mode=dev",
20
+ },
21
+ ],
22
+ },
23
+ } satisfies Meta<typeof Checkbox>;
15
24
 
16
25
  export default meta;
17
26
  type Story = StoryObj<typeof Checkbox>;
@@ -19,22 +28,19 @@ type Story = StoryObj<typeof Checkbox>;
19
28
  export const Controlled: Story = {
20
29
  argTypes: {
21
30
  checked: {
22
- options: [true, false, "indeterminate"],
31
+ table: {
32
+ type: {
33
+ summary: checkedState.map((x) => `${x === "indeterminate" ? `"${x}"` : x}`).join(" | "),
34
+ },
35
+ },
36
+ options: checkedState,
23
37
  },
24
38
  },
25
39
  args: {
26
40
  id: "checkbox-showcase",
27
41
  label: "Controlled checkbox",
28
42
  },
29
- parameters: {
30
- design: [
31
- {
32
- name: "Checkbox",
33
- type: "figma",
34
- url: "https://www.figma.com/file/XEaIIFskrrxIBHMZDkIuIg/Purpur-DS---Component-library-%26-guidelines?type=design&node-id=1274-614&mode=dev",
35
- },
36
- ],
37
- },
43
+
38
44
  render: ({ ...args }) => {
39
45
  const [{ checked }, updateArgs] = useArgs(); // eslint-disable-line react-hooks/rules-of-hooks
40
46
  const setChecked = (value: CheckedState) => {
@@ -55,15 +61,6 @@ export const Uncontrolled: Story = {
55
61
  id: "checkbox-showcase",
56
62
  label: "Uncontrolled checkbox",
57
63
  },
58
- parameters: {
59
- design: [
60
- {
61
- name: "Checkbox",
62
- type: "figma",
63
- url: "https://www.figma.com/file/XEaIIFskrrxIBHMZDkIuIg/Purpur-DS---Component-library-%26-guidelines?type=design&node-id=1274-614&mode=dev",
64
- },
65
- ],
66
- },
67
64
  decorators: [
68
65
  (Story) => {
69
66
  const codeStyle = {
@@ -89,5 +86,6 @@ export const Uncontrolled: Story = {
89
86
  );
90
87
  },
91
88
  ],
89
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
92
90
  render: ({ onChange: _onChange, checked: _checked, ...args }) => <Checkbox {...args} />,
93
91
  };
package/src/checkbox.tsx CHANGED
@@ -8,7 +8,9 @@ import c from "classnames";
8
8
 
9
9
  import styles from "./checkbox.module.scss";
10
10
 
11
- export type CheckedState = boolean | "indeterminate";
11
+ export const checkedState = ["indeterminate", true, false] as const;
12
+
13
+ export type CheckedState = (typeof checkedState)[number];
12
14
  export type CheckboxProps = {
13
15
  /**
14
16
  * To use when no label is given (not recommended).
package/readme.mdx DELETED
@@ -1,156 +0,0 @@
1
- import { Meta, ArgTypes, Primary, Subtitle } from "@storybook/blocks";
2
-
3
- import * as CheckboxStories from "./src/checkbox.stories";
4
- import packageInfo from "./package.json";
5
-
6
- <Meta name="Docs" title="Components/Checkbox" of={CheckboxStories} />
7
-
8
- # Checkbox
9
-
10
- <Subtitle>Version {packageInfo.version}</Subtitle>
11
-
12
- ### Showcase
13
-
14
- <Primary />
15
-
16
- ### Properties
17
-
18
- <ArgTypes />
19
-
20
- ### Installation
21
-
22
- #### Via NPM
23
-
24
- Add the dependency to your consumer app like `"@purpurds/purpur": "^x.y.z"`
25
-
26
- In MyApp.tsx
27
-
28
- ```tsx
29
- import "@purpurds/purpur/styles";
30
- ```
31
-
32
- ### Examples
33
-
34
- In MyComponent.tsx
35
-
36
- #### Controlled.
37
-
38
- ---
39
-
40
- For when you have to controll and use the state of the checkbox.
41
-
42
- ```tsx
43
- import { Checkbox } from "@purpurds/purpur";
44
-
45
- export const MyComponent = () => {
46
- const [checked, setChecked] = useState(false);
47
- return (
48
- <div>
49
- <Checkbox
50
- id="my-checkbox"
51
- checked={checked}
52
- onChange={setChecked}
53
- label="My checkbox"
54
- labelPosition="right"
55
- />
56
- </div>
57
- );
58
- };
59
- ```
60
-
61
- #### Indeterminate.
62
-
63
- ---
64
-
65
- When using the Indeterminate state, the toggle must be controlled.
66
-
67
- ```tsx
68
- import { Checkbox } from "@purpurds/purpur";
69
-
70
- export const MyComponent = () => {
71
- const [checked, setChecked] = useState(false);
72
-
73
- return (
74
- <div>
75
- <Checkbox
76
- id="my-checkbox"
77
- checked={checked}
78
- onChange={setChecked}
79
- label="My checkbox"
80
- labelPosition="right"
81
- />
82
- <Button
83
- variant="primary"
84
- onClick={() =>
85
- setChecked((prevChecked) => (prevChecked === "indeterminate" ? false : "indeterminate"))
86
- }
87
- >
88
- Toggle indeterminate
89
- </Button>
90
- </div>
91
- );
92
- };
93
- ```
94
-
95
- #### Uncontrolled
96
-
97
- ---
98
-
99
- For when you don't have to controll state of the checkbox, e.g. when in a form.
100
-
101
- ```tsx
102
- import { Checkbox } from "@purpurds/purpur";
103
-
104
- export const MyComponent = () => {
105
- /**
106
- * The checkbox will render checked, and handle it's state itself.
107
- *
108
- * Since it is rendered in a form, it will render a checkbox input under the hood
109
- * that reflects its value and state.
110
- */
111
- return (
112
- <form>
113
- <Checkbox id="my-checkbox" defaultChecked label="My uncontrolled checkbox" />
114
- </form>
115
- );
116
- };
117
- ```
118
-
119
- #### With custom label (not recommended).
120
-
121
- ---
122
-
123
- Use the `aria-labelledby` property and pass the id of the label.
124
-
125
- ```tsx
126
- import { Checkbox } from "@purpurds/purpur";
127
-
128
- export const MyComponent = () => {
129
- return (
130
- <div>
131
- <label id="my-custom-label" htmlFor="my-checkbox">
132
- Custom label
133
- </label>
134
- <Checkbox aria-labeledby="my-custom-label" id="my-checkbox" {...otherProps} />
135
- </div>
136
- );
137
- };
138
- ```
139
-
140
- #### Without label (not recommended).
141
-
142
- ---
143
-
144
- If there should be no label at all, use the `aria-label` to label the checkbox for screen readers.
145
-
146
- ```tsx
147
- import { Checkbox } from "@purpurds/purpur";
148
-
149
- export const MyComponent = () => {
150
- return (
151
- <div>
152
- <Checkbox aria-label="checkbox some awesome stuff!" id="my-checkbox" {...otherProps} />
153
- </div>
154
- );
155
- };
156
- ```