@purpurds/tabs 5.35.0 → 6.0.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/dist/LICENSE.txt +1 -1
- package/dist/styles.css +1 -1
- package/dist/tab-content.d.ts +4 -0
- package/dist/tab-content.d.ts.map +1 -1
- package/dist/tabs.cjs.js +3 -3
- package/dist/tabs.cjs.js.map +1 -1
- package/dist/tabs.d.ts.map +1 -1
- package/dist/tabs.es.js +164 -150
- package/dist/tabs.es.js.map +1 -1
- package/package.json +7 -6
- package/src/tab-content.module.scss +6 -0
- package/src/tab-content.test.tsx +39 -6
- package/src/tab-content.tsx +18 -2
- package/src/tabs.stories.tsx +3 -4
- package/src/tabs.tsx +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@purpurds/tabs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"license": "AGPL-3.0-only",
|
|
5
5
|
"main": "./dist/tabs.cjs.js",
|
|
6
6
|
"types": "./dist/tabs.d.ts",
|
|
@@ -17,12 +17,13 @@
|
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"classnames": "~2.5.0",
|
|
19
19
|
"@radix-ui/react-tabs": "~1.0.4",
|
|
20
|
-
"@purpurds/
|
|
21
|
-
"@purpurds/
|
|
22
|
-
"@purpurds/icon": "
|
|
20
|
+
"@purpurds/paragraph": "6.0.0",
|
|
21
|
+
"@purpurds/tokens": "6.0.0",
|
|
22
|
+
"@purpurds/icon": "6.0.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@rushstack/eslint-patch": "~1.10.0",
|
|
26
|
+
"@storybook/preview-api": "^8.3.5",
|
|
26
27
|
"@storybook/react": "^8.3.5",
|
|
27
28
|
"storybook": "^8.3.5",
|
|
28
29
|
"@telia/base-rig": "~8.2.0",
|
|
@@ -43,8 +44,8 @@
|
|
|
43
44
|
"typescript": "^5.6.3",
|
|
44
45
|
"vite": "5.4.8",
|
|
45
46
|
"vitest": "^2.1.2",
|
|
46
|
-
"@purpurds/
|
|
47
|
-
"@purpurds/
|
|
47
|
+
"@purpurds/button": "6.0.0",
|
|
48
|
+
"@purpurds/component-rig": "1.0.0"
|
|
48
49
|
},
|
|
49
50
|
"scripts": {
|
|
50
51
|
"build:dev": "vite",
|
package/src/tab-content.test.tsx
CHANGED
|
@@ -14,18 +14,51 @@ expect.extend(matchers);
|
|
|
14
14
|
describe("TabContent", () => {
|
|
15
15
|
afterEach(cleanup);
|
|
16
16
|
|
|
17
|
-
it("should render
|
|
17
|
+
it("should render tab contents", () => {
|
|
18
18
|
render(
|
|
19
19
|
<Tabs variant="line">
|
|
20
|
-
<TabContent tabId="tab-1" name="Tab name 1" data-testid="tab-content">
|
|
21
|
-
<div>
|
|
20
|
+
<TabContent tabId="tab-1" name="Tab name 1" data-testid="tab-content-1">
|
|
21
|
+
<div>content-one</div>
|
|
22
|
+
</TabContent>
|
|
23
|
+
<TabContent tabId="tab-2" name="Tab name 2" data-testid="tab-content-2">
|
|
24
|
+
<div>content-two</div>
|
|
25
|
+
</TabContent>
|
|
26
|
+
</Tabs>
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const tabContent1 = screen.getByTestId("tab-content-1");
|
|
30
|
+
const tabContent2 = screen.getByTestId("tab-content-2");
|
|
31
|
+
expect(tabContent1).toHaveTextContent("content-one");
|
|
32
|
+
expect(tabContent2).toHaveTextContent("content-two");
|
|
33
|
+
expect(tabContent1.classList.value).toContain(`${rootClassName} ${rootClassName}--force-mount`);
|
|
34
|
+
expect(tabContent2.classList.value).toContain(`${rootClassName} ${rootClassName}--force-mount`);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("should only render active content when disableForceMount is true", () => {
|
|
38
|
+
render(
|
|
39
|
+
<Tabs variant="line">
|
|
40
|
+
<TabContent tabId="tab-1" name="Tab name 1" disableForceMount data-testid="tab-content-1">
|
|
41
|
+
<div>content-one</div>
|
|
42
|
+
</TabContent>
|
|
43
|
+
<TabContent tabId="tab-2" name="Tab name 2" disableForceMount data-testid="tab-content-2">
|
|
44
|
+
<div>content-two</div>
|
|
45
|
+
</TabContent>
|
|
46
|
+
<TabContent tabId="tab-3" name="Tab name 3" disableForceMount data-testid="tab-content-3">
|
|
47
|
+
<div>content-three</div>
|
|
22
48
|
</TabContent>
|
|
23
49
|
</Tabs>
|
|
24
50
|
);
|
|
25
51
|
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
52
|
+
const tabContent1 = screen.getByTestId("tab-content-1");
|
|
53
|
+
const tabContent2 = screen.getByTestId("tab-content-2");
|
|
54
|
+
const tabContent3 = screen.getByTestId("tab-content-3");
|
|
55
|
+
|
|
56
|
+
expect(tabContent1.classList.value).not.toContain(`${rootClassName}--force-mount`);
|
|
57
|
+
expect(tabContent2.classList.value).not.toContain(`${rootClassName}--force-mount`);
|
|
58
|
+
expect(tabContent3.classList.value).not.toContain(`${rootClassName}--force-mount`);
|
|
59
|
+
expect(tabContent1).toHaveTextContent("content-one");
|
|
60
|
+
expect(tabContent2).not.toHaveTextContent("content-two");
|
|
61
|
+
expect(tabContent3).not.toHaveTextContent("content-three");
|
|
29
62
|
});
|
|
30
63
|
|
|
31
64
|
it("should throw error if not used within Tab component", () => {
|
package/src/tab-content.tsx
CHANGED
|
@@ -23,6 +23,10 @@ export type TabContentProps = {
|
|
|
23
23
|
* A unique ID that associates the tab with a content.
|
|
24
24
|
* */
|
|
25
25
|
tabId: string;
|
|
26
|
+
/**
|
|
27
|
+
* If true, the inactive tab content will not be rendered.
|
|
28
|
+
*/
|
|
29
|
+
disableForceMount?: boolean;
|
|
26
30
|
className?: string;
|
|
27
31
|
"data-testid"?: string;
|
|
28
32
|
};
|
|
@@ -37,14 +41,26 @@ const rootClassName = "purpur-tab-content";
|
|
|
37
41
|
|
|
38
42
|
export const TabContent = forwardRef(
|
|
39
43
|
(
|
|
40
|
-
{
|
|
44
|
+
{
|
|
45
|
+
children,
|
|
46
|
+
tabId,
|
|
47
|
+
"data-testid": dataTestId,
|
|
48
|
+
className,
|
|
49
|
+
disableForceMount,
|
|
50
|
+
...rest
|
|
51
|
+
}: TabContentPropsWithChildren,
|
|
41
52
|
ref: ForwardedRef<HTMLDivElement>
|
|
42
53
|
) => (
|
|
43
54
|
<Content
|
|
44
55
|
ref={ref}
|
|
45
|
-
className={cx([
|
|
56
|
+
className={cx([
|
|
57
|
+
rootClassName,
|
|
58
|
+
className,
|
|
59
|
+
{ [`${rootClassName}--force-mount`]: !disableForceMount },
|
|
60
|
+
])}
|
|
46
61
|
data-testid={dataTestId}
|
|
47
62
|
value={tabId}
|
|
63
|
+
forceMount={!disableForceMount || undefined}
|
|
48
64
|
{...rest}
|
|
49
65
|
>
|
|
50
66
|
{children}
|
package/src/tabs.stories.tsx
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import
|
|
2
|
+
import { Button } from "@purpurds/button";
|
|
3
3
|
import { useArgs } from "@storybook/preview-api";
|
|
4
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
4
5
|
|
|
6
|
+
import "@purpurds/button/styles";
|
|
5
7
|
import { Tabs } from "./tabs";
|
|
6
8
|
import { tabsVariants } from "./tabs.utils";
|
|
7
9
|
|
|
8
|
-
import { Button } from "@purpurds/button";
|
|
9
|
-
import "@purpurds/button/styles";
|
|
10
|
-
|
|
11
10
|
const meta = {
|
|
12
11
|
title: "Components/Tabs",
|
|
13
12
|
component: Tabs,
|
package/src/tabs.tsx
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import React, { Children, ReactElement, useEffect, useRef, useState } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { Icon } from "@purpurds/icon";
|
|
3
|
+
import { chevronLeft } from "@purpurds/icon/assets/chevron-left";
|
|
4
|
+
import { chevronRight } from "@purpurds/icon/assets/chevron-right";
|
|
3
5
|
import { List, Root } from "@radix-ui/react-tabs";
|
|
4
6
|
import c from "classnames/bind";
|
|
5
7
|
|