@purpurds/tabs 7.6.1 → 7.7.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/tab-content.d.ts +4 -8
- package/dist/tab-content.d.ts.map +1 -1
- package/dist/tabs.cjs.js +2 -2
- package/dist/tabs.cjs.js.map +1 -1
- package/dist/tabs.d.ts +2 -2
- package/dist/tabs.d.ts.map +1 -1
- package/dist/tabs.es.js +115 -139
- package/dist/tabs.es.js.map +1 -1
- package/dist/tabs.utils.d.ts +2 -1
- package/dist/tabs.utils.d.ts.map +1 -1
- package/package.json +9 -8
- package/src/tab-content.tsx +9 -32
- package/src/tab-header.tsx +1 -1
- package/src/tabs.tsx +13 -6
- package/src/tabs.utils.ts +4 -2
package/src/tab-content.tsx
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
|
|
3
|
-
type ForwardedRef,
|
|
4
|
-
forwardRef,
|
|
5
|
-
isValidElement,
|
|
6
|
-
type ReactElement,
|
|
7
|
-
type ReactNode,
|
|
8
|
-
} from "react";
|
|
1
|
+
import React, { forwardRef, isValidElement, type ReactElement, type ReactNode } from "react";
|
|
2
|
+
import type { BaseProps } from "@purpurds/common-types";
|
|
9
3
|
import { Content } from "@radix-ui/react-tabs";
|
|
10
4
|
import c from "classnames/bind";
|
|
11
5
|
|
|
12
6
|
import styles from "./tab-content.module.scss";
|
|
13
7
|
|
|
14
|
-
export type TabContentProps = {
|
|
8
|
+
export type TabContentProps = Omit<BaseProps, "children"> & {
|
|
15
9
|
/**
|
|
16
10
|
* Content to be rendered inside a `button` element.
|
|
17
11
|
* Only pass ReactNodes that are valid as children of a `button`, such as plain text,
|
|
@@ -26,36 +20,19 @@ export type TabContentProps = {
|
|
|
26
20
|
* If true, the inactive tab content will not be rendered.
|
|
27
21
|
*/
|
|
28
22
|
disableForceMount?: boolean;
|
|
29
|
-
|
|
23
|
+
children: ReactNode;
|
|
30
24
|
};
|
|
31
25
|
|
|
32
|
-
export type TabContentPropsWithChildren = ComponentPropsWithoutRef<"div"> &
|
|
33
|
-
TabContentProps & {
|
|
34
|
-
children: ReactNode;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
26
|
const cx = c.bind(styles);
|
|
38
27
|
const rootClassName = "purpur-tab-content";
|
|
39
28
|
|
|
40
|
-
export const TabContent = forwardRef(
|
|
41
|
-
(
|
|
42
|
-
{
|
|
43
|
-
children,
|
|
44
|
-
tabId,
|
|
45
|
-
"data-testid": dataTestId,
|
|
46
|
-
className,
|
|
47
|
-
disableForceMount,
|
|
48
|
-
...props
|
|
49
|
-
}: TabContentPropsWithChildren,
|
|
50
|
-
ref: ForwardedRef<HTMLDivElement>
|
|
51
|
-
) => (
|
|
29
|
+
export const TabContent = forwardRef<HTMLDivElement, TabContentProps>(
|
|
30
|
+
({ children, tabId, "data-testid": dataTestId, className, disableForceMount, ...props }, ref) => (
|
|
52
31
|
<Content
|
|
53
32
|
ref={ref}
|
|
54
|
-
className={cx(
|
|
55
|
-
rootClassName,
|
|
56
|
-
|
|
57
|
-
{ [`${rootClassName}--force-mount`]: !disableForceMount },
|
|
58
|
-
])}
|
|
33
|
+
className={cx(rootClassName, className, {
|
|
34
|
+
[`${rootClassName}--force-mount`]: !disableForceMount,
|
|
35
|
+
})}
|
|
59
36
|
data-testid={dataTestId}
|
|
60
37
|
value={tabId}
|
|
61
38
|
forceMount={!disableForceMount || undefined}
|
package/src/tab-header.tsx
CHANGED
|
@@ -38,7 +38,7 @@ export const TabHeader = forwardRef(
|
|
|
38
38
|
) => (
|
|
39
39
|
<Trigger
|
|
40
40
|
id={`${tabId}-trigger`}
|
|
41
|
-
className={cx(
|
|
41
|
+
className={cx(rootClassName, `${rootClassName}--${variant}${negative ? "-negative" : ""}`)}
|
|
42
42
|
value={tabId}
|
|
43
43
|
data-testid={dataTestId}
|
|
44
44
|
data-index={index}
|
package/src/tabs.tsx
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
Children,
|
|
3
|
+
type HTMLAttributes,
|
|
4
|
+
type ReactElement,
|
|
5
|
+
useEffect,
|
|
6
|
+
useRef,
|
|
7
|
+
useState,
|
|
8
|
+
} from "react";
|
|
2
9
|
import { Icon } from "@purpurds/icon";
|
|
3
10
|
import { chevronLeft } from "@purpurds/icon/assets/chevron-left";
|
|
4
11
|
import { chevronRight } from "@purpurds/icon/assets/chevron-right";
|
|
@@ -34,7 +41,7 @@ type TabsProps = {
|
|
|
34
41
|
* */
|
|
35
42
|
animateHeight?: boolean;
|
|
36
43
|
"data-testid"?: string;
|
|
37
|
-
} & Pick<
|
|
44
|
+
} & Pick<HTMLAttributes<HTMLDivElement>, "style" | "className">;
|
|
38
45
|
|
|
39
46
|
const cx = c.bind(styles);
|
|
40
47
|
const rootClassName = "purpur-tabs";
|
|
@@ -102,12 +109,12 @@ export const Tabs: TabsCmp<TabsProps> = ({
|
|
|
102
109
|
const sideScrollAdjustmentSize = 200;
|
|
103
110
|
const isLineVariant = variant === "line";
|
|
104
111
|
|
|
105
|
-
const classNames = cx(
|
|
112
|
+
const classNames = cx(
|
|
106
113
|
rootClassName,
|
|
107
114
|
`${rootClassName}--${variant}${negative ? "-negative" : ""}`,
|
|
108
115
|
{ [`${rootClassName}--fullWidth`]: fullWidth },
|
|
109
|
-
className
|
|
110
|
-
|
|
116
|
+
className
|
|
117
|
+
);
|
|
111
118
|
|
|
112
119
|
const tabIds = Children.map(tabContentChildren, ({ props: { tabId } }) => tabId);
|
|
113
120
|
|
|
@@ -249,7 +256,7 @@ export const Tabs: TabsCmp<TabsProps> = ({
|
|
|
249
256
|
{...props}
|
|
250
257
|
>
|
|
251
258
|
<div className={cx(`${rootClassName}__container`)}>
|
|
252
|
-
<div className={cx(
|
|
259
|
+
<div className={cx(`${rootClassName}__wrapper`, scrollClasses)}>
|
|
253
260
|
<List
|
|
254
261
|
ref={(el) => {
|
|
255
262
|
tabList.current = el;
|
package/src/tabs.utils.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { FunctionComponent } from "react";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import type { TabContent } from "./tab-content";
|
|
4
|
+
|
|
5
|
+
export type TabsCmp<P> = FunctionComponent<P> & {
|
|
4
6
|
Content: typeof TabContent;
|
|
5
7
|
};
|
|
6
8
|
|