@purpurds/toggle 5.10.1 → 5.11.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.
@@ -1 +1 @@
1
- {"version":3,"file":"useToggleDrag.d.ts","sourceRoot":"","sources":["../src/useToggleDrag.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAqC,MAAM,OAAO,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,eAAO,MAAM,aAAa,0BAA2B,KAAK,WAAW,EAAE,SAAS,GAAG,UAAU,CAAC;;;;;;;;;;WAqBhE,MAAM;;;;CAiCnC,CAAC"}
1
+ {"version":3,"file":"useToggleDrag.d.ts","sourceRoot":"","sources":["../src/useToggleDrag.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAqC,MAAM,OAAO,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,eAAO,MAAM,aAAa,0BAA2B,IAAI,CAAC,WAAW,EAAE,SAAS,GAAG,UAAU,CAAC;;;;;;;;;oBAqBrE;QAAE,CAAC,EAAE,MAAM,CAAA;KAAE;;;CAiCrC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@purpurds/toggle",
3
- "version": "5.10.1",
3
+ "version": "5.11.1",
4
4
  "license": "AGPL-3.0-only",
5
5
  "main": "./dist/toggle.cjs.js",
6
6
  "types": "./dist/toggle.d.ts",
@@ -16,33 +16,33 @@
16
16
  "dependencies": {
17
17
  "@radix-ui/react-switch": "~1.0.3",
18
18
  "classnames": "~2.5.0",
19
- "@storybook/client-api": "~7.6.0",
20
- "@purpurds/label": "5.10.1",
21
- "@purpurds/tokens": "5.10.1",
22
- "@purpurds/paragraph": "5.10.1",
23
- "@purpurds/icon": "5.10.1"
19
+ "@purpurds/paragraph": "5.11.1",
20
+ "@purpurds/icon": "5.11.1",
21
+ "@purpurds/tokens": "5.11.1",
22
+ "@purpurds/label": "5.11.1"
24
23
  },
25
24
  "devDependencies": {
26
25
  "@rushstack/eslint-patch": "~1.10.0",
27
- "@storybook/blocks": "~7.6.0",
28
- "@storybook/react": "~7.6.0",
26
+ "@storybook/preview-api": "^8.2.6",
27
+ "@storybook/react": "^8.2.6",
29
28
  "@telia/base-rig": "~8.2.0",
30
29
  "@telia/react-rig": "~3.2.0",
31
30
  "@testing-library/dom": "~9.3.3",
32
31
  "@testing-library/jest-dom": "~6.4.0",
33
32
  "@testing-library/react": "~14.3.0",
34
33
  "@types/node": "20.12.12",
35
- "@types/react-dom": "~18.3.0",
36
- "@types/react": "~18.3.0",
34
+ "@types/react-dom": "^18.3.0",
35
+ "@types/react": "^18.3.3",
37
36
  "eslint-plugin-testing-library": "~6.2.0",
38
- "eslint": "~8.57.0",
37
+ "eslint": "^8.57.0",
39
38
  "jsdom": "~22.1.0",
40
39
  "lint-staged": "~10.5.3",
41
40
  "prettier": "~2.8.8",
42
- "react-dom": "~18.3.0",
43
- "react": "~18.3.0",
44
- "typescript": "~5.4.2",
45
- "vite": "~5.2.2",
41
+ "react-dom": "^18.3.1",
42
+ "react": "^18.3.1",
43
+ "storybook": "^8.2.6",
44
+ "typescript": "^5.5.4",
45
+ "vite": "5.3.4",
46
46
  "vitest": "~1.5.0",
47
47
  "@purpurds/component-rig": "1.0.0"
48
48
  },
@@ -1,16 +1,25 @@
1
1
  import React from "react";
2
+ import { useArgs } from "@storybook/preview-api";
2
3
  import type { Meta, StoryObj } from "@storybook/react";
3
- import { Toggle } from "./toggle";
4
- import { useArgs } from "@storybook/client-api";
5
4
 
6
5
  import "@purpurds/icon/styles";
7
6
  import "@purpurds/label/styles";
8
7
  import "@purpurds/paragraph/styles";
8
+ import { Toggle } from "./toggle";
9
9
 
10
- const meta: Meta<typeof Toggle> = {
10
+ const meta = {
11
11
  title: "Inputs/Toggle",
12
12
  component: Toggle,
13
- };
13
+ parameters: {
14
+ design: [
15
+ {
16
+ name: "Toggle",
17
+ type: "figma",
18
+ url: "https://www.figma.com/file/XEaIIFskrrxIBHMZDkIuIg/Purpur-DS---Component-library-%26-guidelines?type=design&node-id=1187-108",
19
+ },
20
+ ],
21
+ },
22
+ } satisfies Meta<typeof Toggle>;
14
23
 
15
24
  export default meta;
16
25
  type Story = StoryObj<typeof Toggle>;
@@ -24,18 +33,26 @@ export const Controlled: Story = {
24
33
  argTypes: {
25
34
  defaultChecked: { table: { disable: true } },
26
35
  labelPosition: {
27
- options: [undefined, "left", "right"],
36
+ options: ["left", "right"],
28
37
  control: "select",
38
+ table: { type: { summary: `"left" | "right"` } },
29
39
  },
30
40
  },
31
41
  parameters: {
32
- design: [
33
- {
34
- name: "Toggle",
35
- type: "figma",
36
- url: "https://www.figma.com/file/XEaIIFskrrxIBHMZDkIuIg/Purpur-DS---Component-library-%26-guidelines?type=design&node-id=1187-108",
42
+ docs: {
43
+ description: {
44
+ story: "For when you have to control and use the state of the toggle.",
37
45
  },
38
- ],
46
+ source: {
47
+ code: `
48
+ <Toggle
49
+ id="toggle-showcase"
50
+ checked={isChecked}
51
+ onChange={setIsChecked}
52
+ label="Controlled draggable toggle"
53
+ />`,
54
+ },
55
+ },
39
56
  },
40
57
  render: ({ ...args }) => {
41
58
  const [{ checked }, updateArgs] = useArgs(); // eslint-disable-line react-hooks/rules-of-hooks
@@ -58,13 +75,28 @@ export const Uncontrolled: Story = {
58
75
  onChange: { table: { disable: true } },
59
76
  },
60
77
  parameters: {
61
- design: [
62
- {
63
- name: "Toggle",
64
- type: "figma",
65
- url: "https://www.figma.com/file/XEaIIFskrrxIBHMZDkIuIg/Purpur-DS---Component-library-%26-guidelines?type=design&node-id=1187-108",
78
+ docs: {
79
+ description: {
80
+ story: `For when you don't have to controll state of the toggle, e.g. when in a form.
81
+
82
+ _NOTE: do not use toggles instead of checkboxes or radio buttons!_`,
66
83
  },
67
- ],
84
+ source: {
85
+ code: `
86
+ /**
87
+ * Toggle will render checked, and handle it's state itself.
88
+ *
89
+ * Since it is rendered in a form, it will render a checkbox input under the hood
90
+ * that will reflect its value and state.
91
+ */
92
+ <form>
93
+ <Toggle
94
+ id="toggle-uncontrolled"
95
+ defaultChecked
96
+ label="Uncontrolled toggle" />
97
+ </form>`,
98
+ },
99
+ },
68
100
  },
69
101
  decorators: [
70
102
  (Story) => {
@@ -91,5 +123,6 @@ export const Uncontrolled: Story = {
91
123
  );
92
124
  },
93
125
  ],
126
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
94
127
  render: ({ onChange: _onChange, checked: _checked, ...args }) => <Toggle {...args} />,
95
128
  };
package/readme.mdx DELETED
@@ -1,124 +0,0 @@
1
- import { Meta, Stories, ArgTypes, Primary, Subtitle } from "@storybook/blocks";
2
-
3
- import * as ToggleStories from "./src/toggle.stories";
4
- import packageInfo from "./package.json";
5
-
6
- <Meta name="Docs" title="Components/Toggle" of={ToggleStories} />
7
-
8
- # Toggle
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 toggle.
41
-
42
- ```tsx
43
- import { Toggle } from "@purpurds/purpur";
44
-
45
- export const MyComponent = () => {
46
- const [isChecked, setIsChecked] = useState(false);
47
- return (
48
- <div>
49
- <Toggle
50
- id="my-toggle"
51
- checked={isChecked}
52
- onChange={setIsChecked}
53
- label="My toggle"
54
- labelPosition="right"
55
- />
56
- </div>
57
- );
58
- };
59
- ```
60
-
61
- #### Uncontrolled
62
-
63
- ---
64
-
65
- For when you don't have to controll state of the toggle, e.g. when in a form.
66
-
67
- _NOTE: do not use toggles instead of checkboxes or radio buttons!_
68
-
69
- ```tsx
70
- import { Toggle } from "@purpurds/purpur";
71
-
72
- export const MyComponent = () => {
73
- /**
74
- * Toggle will render checked, and handle it's state itself.
75
- *
76
- * Since it is rendered in a form, it will render a checkbox input under the hood
77
- * that will reflect its value and state.
78
- */
79
- return (
80
- <form>
81
- <Toggle id="my-toggle" defaultChecked label="My uncontrolled toggle" />
82
- </form>
83
- );
84
- };
85
- ```
86
-
87
- #### With custom label (not recommended).
88
-
89
- ---
90
-
91
- Use the `aria-labelledby` property and pass the id of the label.
92
-
93
- ```tsx
94
- import { Toggle } from "@purpurds/purpur";
95
-
96
- export const MyComponent = () => {
97
- return (
98
- <div>
99
- <label id="my-custom-label" htmlFor="my-toggle">
100
- Custom label
101
- </label>
102
- <Toggle aria-labeledby="my-custom-label" id="my-toggle" {...otherProps} />
103
- </div>
104
- );
105
- };
106
- ```
107
-
108
- #### Without label (not recommended).
109
-
110
- ---
111
-
112
- If there should be no label at all, use the `aria-label` to label the toggle for screen readers.
113
-
114
- ```tsx
115
- import { Toggle } from "@purpurds/purpur";
116
-
117
- export const MyComponent = () => {
118
- return (
119
- <div>
120
- <Toggle aria-label="Toggle some awesome stuff!" id="my-toggle" {...otherProps} />
121
- </div>
122
- );
123
- };
124
- ```