@toptal/picasso-tabs 2.0.9 → 3.0.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.
- package/dist-package/src/Tab/Tab.d.ts +3 -3
- package/dist-package/src/Tab/Tab.d.ts.map +1 -1
- package/dist-package/src/Tab/Tab.js +62 -14
- package/dist-package/src/Tab/Tab.js.map +1 -1
- package/dist-package/src/TabLabel/TabLabel.d.ts.map +1 -1
- package/dist-package/src/TabLabel/TabLabel.js +2 -3
- package/dist-package/src/TabLabel/TabLabel.js.map +1 -1
- package/dist-package/src/Tabs/Tabs.d.ts +19 -10
- package/dist-package/src/Tabs/Tabs.d.ts.map +1 -1
- package/dist-package/src/Tabs/Tabs.js +51 -21
- package/dist-package/src/Tabs/Tabs.js.map +1 -1
- package/dist-package/src/Tabs/index.d.ts +3 -2
- package/dist-package/src/Tabs/index.d.ts.map +1 -1
- package/dist-package/src/TabsCompound/index.d.ts +4 -2
- package/dist-package/src/TabsCompound/index.d.ts.map +1 -1
- package/dist-package/src/index.d.ts +0 -1
- package/dist-package/src/index.d.ts.map +1 -1
- package/dist-package/src/index.js +0 -1
- package/dist-package/src/index.js.map +1 -1
- package/package.json +11 -10
- package/src/Tab/Tab.tsx +100 -21
- package/src/Tab/__snapshots__/test.tsx.snap +91 -37
- package/src/Tab/story/CustomValue.example.tsx +2 -2
- package/src/Tab/test.tsx +9 -1
- package/src/TabLabel/TabLabel.tsx +10 -4
- package/src/Tabs/Tabs.tsx +114 -61
- package/src/Tabs/__snapshots__/test.tsx.snap +61 -76
- package/src/Tabs/index.ts +3 -2
- package/src/Tabs/story/Default.example.tsx +1 -1
- package/src/Tabs/story/FullWidth.example.tsx +1 -1
- package/src/Tabs/story/ScrollButtons.example.tsx +1 -1
- package/src/Tabs/story/Vertical.example.tsx +1 -1
- package/src/Tabs/test.tsx +11 -8
- package/src/index.ts +1 -2
- package/dist-package/src/Tab/styles.d.ts +0 -4
- package/dist-package/src/Tab/styles.d.ts.map +0 -1
- package/dist-package/src/Tab/styles.js +0 -94
- package/dist-package/src/Tab/styles.js.map +0 -1
- package/dist-package/src/TabScrollButton/TabScrollButton.d.ts +0 -12
- package/dist-package/src/TabScrollButton/TabScrollButton.d.ts.map +0 -1
- package/dist-package/src/TabScrollButton/TabScrollButton.js +0 -40
- package/dist-package/src/TabScrollButton/TabScrollButton.js.map +0 -1
- package/dist-package/src/TabScrollButton/index.d.ts +0 -5
- package/dist-package/src/TabScrollButton/index.d.ts.map +0 -1
- package/dist-package/src/TabScrollButton/index.js +0 -2
- package/dist-package/src/TabScrollButton/index.js.map +0 -1
- package/dist-package/src/TabScrollButton/styles.d.ts +0 -4
- package/dist-package/src/TabScrollButton/styles.d.ts.map +0 -1
- package/dist-package/src/TabScrollButton/styles.js +0 -35
- package/dist-package/src/TabScrollButton/styles.js.map +0 -1
- package/dist-package/src/Tabs/styles.d.ts +0 -4
- package/dist-package/src/Tabs/styles.d.ts.map +0 -1
- package/dist-package/src/Tabs/styles.js +0 -41
- package/dist-package/src/Tabs/styles.js.map +0 -1
- package/dist-package/src/Tabs/use-tab-action.d.ts +0 -5
- package/dist-package/src/Tabs/use-tab-action.d.ts.map +0 -1
- package/dist-package/src/Tabs/use-tab-action.js +0 -21
- package/dist-package/src/Tabs/use-tab-action.js.map +0 -1
- package/src/Tab/styles.ts +0 -106
- package/src/TabScrollButton/TabScrollButton.tsx +0 -64
- package/src/TabScrollButton/index.ts +0 -6
- package/src/TabScrollButton/styles.ts +0 -37
- package/src/Tabs/styles.ts +0 -45
- package/src/Tabs/use-tab-action.ts +0 -27
@@ -1,8 +1,8 @@
|
|
1
1
|
import type { ReactNode, HTMLAttributes, ReactElement } from 'react';
|
2
2
|
import React from 'react';
|
3
|
-
import type { TabProps } from '@
|
3
|
+
import type { TabProps } from '@mui/base/Tab';
|
4
4
|
import type { BaseProps, TextLabelProps } from '@toptal/picasso-shared';
|
5
|
-
export interface Props extends BaseProps, TextLabelProps, Omit<HTMLAttributes<
|
5
|
+
export interface Props extends BaseProps, TextLabelProps, Omit<HTMLAttributes<HTMLButtonElement>, 'onChange'> {
|
6
6
|
/**
|
7
7
|
* If true, the tab will be disabled
|
8
8
|
* @default false
|
@@ -22,6 +22,6 @@ export interface Props extends BaseProps, TextLabelProps, Omit<HTMLAttributes<HT
|
|
22
22
|
onChange?: TabProps['onChange'];
|
23
23
|
onClick?: TabProps['onClick'];
|
24
24
|
}
|
25
|
-
export declare const Tab: React.ForwardRefExoticComponent<Props & React.RefAttributes<
|
25
|
+
export declare const Tab: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLButtonElement>>;
|
26
26
|
export default Tab;
|
27
27
|
//# sourceMappingURL=Tab.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Tab.d.ts","sourceRoot":"","sources":["../../../src/Tab/Tab.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AACpE,OAAO,KAAiC,MAAM,OAAO,CAAA;
|
1
|
+
{"version":3,"file":"Tab.d.ts","sourceRoot":"","sources":["../../../src/Tab/Tab.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AACpE,OAAO,KAAiC,MAAM,OAAO,CAAA;AACrD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAE7C,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AASvE,MAAM,WAAW,KACf,SAAQ,SAAS,EACf,cAAc,EACd,IAAI,CAAC,cAAc,CAAC,iBAAiB,CAAC,EAAE,UAAU,CAAC;IACrD;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAElB,yFAAyF;IACzF,KAAK,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IAEzB,wBAAwB;IACxB,KAAK,CAAC,EAAE,SAAS,CAAA;IAEjB,uBAAuB;IACvB,IAAI,CAAC,EAAE,YAAY,CAAA;IAEnB,gBAAgB;IAChB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAEtB,kBAAkB;IAClB,WAAW,CAAC,EAAE,MAAM,CAAA;IAIpB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAA;IAC/B,OAAO,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAA;CAC9B;AAuDD,eAAO,MAAM,GAAG,iFA4Ed,CAAA;AAyDF,eAAe,GAAG,CAAA"}
|
@@ -10,21 +10,62 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
10
10
|
return t;
|
11
11
|
};
|
12
12
|
import React, { forwardRef, useContext } from 'react';
|
13
|
-
import {
|
14
|
-
import { Tab as MUITab } from '@material-ui/core';
|
13
|
+
import { Tab as MUITab } from '@mui/base/Tab';
|
15
14
|
import { useTitleCase } from '@toptal/picasso-shared';
|
16
15
|
import { UserBadge } from '@toptal/picasso-user-badge';
|
17
|
-
import
|
18
|
-
import {
|
16
|
+
import { twJoin, twMerge } from '@toptal/picasso-tailwind-merge';
|
17
|
+
import { TabsContext } from '../Tabs/Tabs';
|
19
18
|
import { TabLabel } from '../TabLabel';
|
20
19
|
import { TabDescription } from '../TabDescription';
|
21
|
-
const
|
20
|
+
const getOpacityClass = (selected, disabled, orientation) => {
|
21
|
+
if (disabled) {
|
22
|
+
return 'opacity-50';
|
23
|
+
}
|
24
|
+
if (selected || orientation === 'vertical') {
|
25
|
+
return 'opacity-100 ';
|
26
|
+
}
|
27
|
+
return 'opacity-70';
|
28
|
+
};
|
29
|
+
const wrapperClassesByOrientation = {
|
30
|
+
horizontal: 'inline-flex items-center flex-col justify-center',
|
31
|
+
vertical: 'block',
|
32
|
+
};
|
33
|
+
const rootClassesByOrientation = (selected) => ({
|
34
|
+
horizontal: [
|
35
|
+
'm-0 [&:not(:last-child)]:mr-8 pt-[0.5625rem] pb-[0.4375rem] px-0',
|
36
|
+
'text-center bg-transparent transition-shadow z-10 rounded-none',
|
37
|
+
selected ? 'text-black' : 'text-inheritColor',
|
38
|
+
selected && 'shadow-blue-500 shadow-[inset_0_-2px_0]',
|
39
|
+
],
|
40
|
+
vertical: [
|
41
|
+
' first:mt-4 last:mb-4 my-1 mx-0 py-2 px-4',
|
42
|
+
'text-left rounded-l-sm rounded-r-none transition-all',
|
43
|
+
'w-full overflow-hidden',
|
44
|
+
selected && 'shadow-1',
|
45
|
+
selected && [
|
46
|
+
'before:absolute',
|
47
|
+
'before:content-[""]',
|
48
|
+
'before:bottom-0',
|
49
|
+
'before:left-0',
|
50
|
+
'before:top-0',
|
51
|
+
'before:w-[3px]',
|
52
|
+
'before:bg-blue-500',
|
53
|
+
],
|
54
|
+
selected
|
55
|
+
? 'bg-gray-50 text-black'
|
56
|
+
: 'bg-gray-100 hover:bg-gray-200 text-graphite-700 hover:text-black',
|
57
|
+
],
|
58
|
+
});
|
59
|
+
const classesByVariant = {
|
60
|
+
scrollable: 'shrink-0 max-w-[264px]',
|
61
|
+
fullWidth: 'shrink flex-grow basis-0',
|
62
|
+
};
|
22
63
|
export const Tab = forwardRef(function Tab(props, ref) {
|
23
|
-
const { disabled, value, label, icon,
|
24
|
-
const classes = useStyles();
|
64
|
+
const { disabled, value, label, icon, onChange, onClick, titleCase: propsTitleCase, description, avatar, className } = props, rest = __rest(props, ["disabled", "value", "label", "icon", "onChange", "onClick", "titleCase", "description", "avatar", "className"]);
|
25
65
|
const titleCase = useTitleCase(propsTitleCase);
|
26
|
-
const orientation = useContext(
|
27
|
-
const
|
66
|
+
const { orientation, variant } = useContext(TabsContext);
|
67
|
+
const isHorizontal = orientation === 'horizontal';
|
68
|
+
const renderLabel = getLabelComponent({
|
28
69
|
avatar,
|
29
70
|
description,
|
30
71
|
disabled,
|
@@ -32,11 +73,18 @@ export const Tab = forwardRef(function Tab(props, ref) {
|
|
32
73
|
orientation,
|
33
74
|
titleCase,
|
34
75
|
});
|
35
|
-
return (React.createElement(MUITab, Object.assign({}, rest, { ref: ref, tabIndex: 0, disabled: disabled,
|
36
|
-
root:
|
37
|
-
|
38
|
-
|
39
|
-
|
76
|
+
return (React.createElement(MUITab, Object.assign({ className: '' }, rest, { ref: ref, tabIndex: 0, disabled: disabled, value: value, onChange: onChange, onClick: onClick, slotProps: {
|
77
|
+
root: ownerState => {
|
78
|
+
return {
|
79
|
+
className: twMerge(getOpacityClass(ownerState.selected, ownerState.disabled, orientation), rootClassesByOrientation(ownerState.selected)[orientation], classesByVariant[variant], ownerState.disabled
|
80
|
+
? 'cursor-default text-gray-500'
|
81
|
+
: 'cursor-pointer', ownerState.disabled && 'pointer-events-none', icon && isHorizontal && 'min-h-0 pt-[0.5625rem] pr-6', 'min-w-0 sm:min-w-[160px] md:min-w-[auto]', 'border-0 cursor-pointer inline-flex outline-none', 'items-center select-none align-middle appearance-none', 'justify-center no-underline [-webkit-tap-highlight-color:transparent]', 'normal-case whitespace-normal leading-4', 'relative ', className),
|
82
|
+
};
|
83
|
+
},
|
84
|
+
} }),
|
85
|
+
React.createElement("span", { className: twJoin('w-full', wrapperClassesByOrientation[orientation]) },
|
86
|
+
renderLabel,
|
87
|
+
icon && React.createElement("span", { className: 'absolute right-0 mb-0 h-4' }, icon))));
|
40
88
|
});
|
41
89
|
Tab.defaultProps = {};
|
42
90
|
Tab.displayName = 'Tab';
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Tab.js","sourceRoot":"","sources":["../../../src/Tab/Tab.tsx"],"names":[],"mappings":";;;;;;;;;;;AACA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAErD,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"Tab.js","sourceRoot":"","sources":["../../../src/Tab/Tab.tsx"],"names":[],"mappings":";;;;;;;;;;;AACA,OAAO,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CACJ,CAAA;KACF;IAED,OAAO,CACL,oBAAC,SAAS,IAAC,UAAU,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,IACtD,WAAW,IAAI,CACd,oBAAC,cAAc,IAAC,QAAQ,EAAE,QAAQ,IAAG,WAAW,CAAkB,CACnE,CACS,CACb,CAAA;AACH,CAAC,CAAA;AAED,eAAe,GAAG,CAAA"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"TabLabel.d.ts","sourceRoot":"","sources":["../../../src/TabLabel/TabLabel.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;
|
1
|
+
{"version":3,"file":"TabLabel.d.ts","sourceRoot":"","sources":["../../../src/TabLabel/TabLabel.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAIzB,UAAU,KAAK;IACb,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IACvB,WAAW,EAAE,YAAY,GAAG,UAAU,CAAA;IACtC,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAED,QAAA,MAAM,QAAQ,sCAAuC,KAAK,gBA4BzD,CAAA;AAED,eAAe,QAAQ,CAAA"}
|
@@ -1,12 +1,11 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { TypographyOverflow } from '@toptal/picasso-typography-overflow';
|
3
3
|
import { Typography } from '@toptal/picasso-typography';
|
4
|
-
import { toTitleCase } from '@toptal/picasso-utils';
|
5
4
|
const TabLabel = ({ label, orientation, titleCase }) => {
|
6
5
|
if (orientation === 'horizontal') {
|
7
|
-
return (React.createElement(Typography, { as: 'div', size: 'small', weight: 'semibold', color: 'inherit'
|
6
|
+
return (React.createElement(Typography, { as: 'div', size: 'small', weight: 'semibold', color: 'inherit', titleCase: titleCase }, label));
|
8
7
|
}
|
9
|
-
return (React.createElement(TypographyOverflow, { as: 'div', color: 'inherit', inline: true, size: 'medium', variant: 'body', weight: 'semibold'
|
8
|
+
return (React.createElement(TypographyOverflow, { as: 'div', color: 'inherit', inline: true, size: 'medium', variant: 'body', weight: 'semibold', titleCase: titleCase }, label));
|
10
9
|
};
|
11
10
|
export default TabLabel;
|
12
11
|
//# sourceMappingURL=TabLabel.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"TabLabel.js","sourceRoot":"","sources":["../../../src/TabLabel/TabLabel.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAA;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;
|
1
|
+
{"version":3,"file":"TabLabel.js","sourceRoot":"","sources":["../../../src/TabLabel/TabLabel.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAA;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AAQvD,MAAM,QAAQ,GAAG,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAS,EAAE,EAAE;IAC5D,IAAI,WAAW,KAAK,YAAY,EAAE;QAChC,OAAO,CACL,oBAAC,UAAU,IACT,EAAE,EAAC,KAAK,EACR,IAAI,EAAC,OAAO,EACZ,MAAM,EAAC,UAAU,EACjB,KAAK,EAAC,SAAS,EACf,SAAS,EAAE,SAAS,IAEnB,KAAK,CACK,CACd,CAAA;KACF;IAED,OAAO,CACL,oBAAC,kBAAkB,IACjB,EAAE,EAAC,KAAK,EACR,KAAK,EAAC,SAAS,EACf,MAAM,QACN,IAAI,EAAC,QAAQ,EACb,OAAO,EAAC,MAAM,EACd,MAAM,EAAC,UAAU,EACjB,SAAS,EAAE,SAAS,IAEnB,KAAK,CACa,CACtB,CAAA;AACH,CAAC,CAAA;AAED,eAAe,QAAQ,CAAA"}
|
@@ -1,20 +1,29 @@
|
|
1
|
-
import type { ReactNode } from 'react';
|
1
|
+
import type { ReactNode, ForwardedRef } from 'react';
|
2
2
|
import React from 'react';
|
3
|
-
import
|
4
|
-
import type {
|
5
|
-
export
|
3
|
+
import { Tabs as MUITabs } from '@mui/base/Tabs';
|
4
|
+
import type { BaseProps } from '@toptal/picasso-shared';
|
5
|
+
export declare type TabsValueType = string | number | null;
|
6
|
+
export interface Props<V extends TabsValueType> extends BaseProps {
|
6
7
|
/** Tabs content containing Tab components */
|
7
8
|
children: ReactNode;
|
8
9
|
/** Callback fired when the value changes. */
|
9
|
-
onChange?: (event: React.ChangeEvent<{}
|
10
|
-
/**
|
11
|
-
|
10
|
+
onChange?: (event: React.ChangeEvent<{}> | null, value: V) => void;
|
11
|
+
/**
|
12
|
+
* The value of the currently selected Tab.
|
13
|
+
* If you don't want any selected Tab, you can set this property to null.
|
14
|
+
*/
|
15
|
+
value: V;
|
12
16
|
/** The tabs orientation (layout flow direction). */
|
13
17
|
orientation?: 'horizontal' | 'vertical';
|
14
18
|
/** Determines additional display behavior of the tabs */
|
15
|
-
variant?:
|
19
|
+
variant?: 'scrollable' | 'fullWidth';
|
16
20
|
}
|
17
|
-
export declare const
|
18
|
-
|
21
|
+
export declare const TabsContext: React.Context<{
|
22
|
+
orientation: 'horizontal' | 'vertical';
|
23
|
+
variant: 'scrollable' | 'fullWidth';
|
24
|
+
}>;
|
25
|
+
declare const Tabs: <V extends TabsValueType = TabsValueType>(props: Props<V> & {
|
26
|
+
ref?: ForwardedRef<HTMLDivElement> | undefined;
|
27
|
+
}) => ReturnType<typeof MUITabs>;
|
19
28
|
export default Tabs;
|
20
29
|
//# sourceMappingURL=Tabs.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Tabs.d.ts","sourceRoot":"","sources":["../../../src/Tabs/Tabs.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;
|
1
|
+
{"version":3,"file":"Tabs.d.ts","sourceRoot":"","sources":["../../../src/Tabs/Tabs.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AACpD,OAAO,KAA8B,MAAM,OAAO,CAAA;AAClD,OAAO,EAAE,IAAI,IAAI,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAEhD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAGvD,oBAAY,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;AAElD,MAAM,WAAW,KAAK,CAAC,CAAC,SAAS,aAAa,CAAE,SAAQ,SAAS;IAC/D,6CAA6C;IAC7C,QAAQ,EAAE,SAAS,CAAA;IAEnB,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,WAAW,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,CAAC,KAAK,IAAI,CAAA;IAElE;;;OAGG;IACH,KAAK,EAAE,CAAC,CAAA;IAER,oDAAoD;IACpD,WAAW,CAAC,EAAE,YAAY,GAAG,UAAU,CAAA;IAEvC,yDAAyD;IACzD,OAAO,CAAC,EAAE,YAAY,GAAG,WAAW,CAAA;CACrC;AAED,eAAO,MAAM,WAAW;iBACT,YAAY,GAAG,UAAU;aAC7B,YAAY,GAAG,WAAW;EACmB,CAAA;AAmCxD,QAAA,MAAM,IAAI;;MAgEL,WAAW,cAAc,CAAC,CAAA;AAE/B,eAAe,IAAI,CAAA"}
|
@@ -9,27 +9,57 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
9
9
|
}
|
10
10
|
return t;
|
11
11
|
};
|
12
|
-
import React, { forwardRef } from 'react';
|
13
|
-
import {
|
14
|
-
import {
|
15
|
-
import {
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
12
|
+
import React, { forwardRef, useMemo } from 'react';
|
13
|
+
import { Tabs as MUITabs } from '@mui/base/Tabs';
|
14
|
+
import { TabsList } from '@mui/base/TabsList';
|
15
|
+
import { twJoin, twMerge } from '@toptal/picasso-tailwind-merge';
|
16
|
+
export const TabsContext = React.createContext({ orientation: 'horizontal', variant: 'scrollable' });
|
17
|
+
const indicatorClasses = [
|
18
|
+
'after:absolute',
|
19
|
+
'after:content-[""]',
|
20
|
+
'after:bottom-0',
|
21
|
+
'after:left-0',
|
22
|
+
'after:right-0',
|
23
|
+
'after:h-[1px]',
|
24
|
+
'after:bg-gray-500',
|
25
|
+
'after:z-0',
|
26
|
+
];
|
27
|
+
const classesByOrientation = {
|
28
|
+
vertical: {
|
29
|
+
root: 'w-[200px] m-0 flex-col',
|
30
|
+
scroller: 'pl-2',
|
31
|
+
},
|
32
|
+
horizontal: {
|
33
|
+
root: '',
|
34
|
+
scroller: indicatorClasses,
|
35
|
+
},
|
33
36
|
};
|
37
|
+
const classesByVariant = {
|
38
|
+
scrollable: {
|
39
|
+
root: 'overflow-x-auto',
|
40
|
+
scroller: '',
|
41
|
+
},
|
42
|
+
fullWidth: {
|
43
|
+
root: '',
|
44
|
+
scroller: 'w-full overflow-hidden',
|
45
|
+
},
|
46
|
+
};
|
47
|
+
const Tabs = forwardRef((_a, ref) => {
|
48
|
+
var { children, orientation = 'horizontal', onChange, value, variant = 'scrollable', className } = _a, rest = __rest(_a, ["children", "orientation", "onChange", "value", "variant", "className"]);
|
49
|
+
const contextValue = useMemo(() => ({
|
50
|
+
orientation,
|
51
|
+
variant,
|
52
|
+
}), [orientation, variant]);
|
53
|
+
const isVertical = orientation === 'vertical';
|
54
|
+
return (React.createElement(TabsContext.Provider, { value: contextValue },
|
55
|
+
React.createElement(MUITabs, Object.assign({}, rest, { slotProps: {
|
56
|
+
root: {
|
57
|
+
ref,
|
58
|
+
className: twMerge('relative min-h-0 flex overflow-hidden', classesByOrientation[orientation].root, classesByVariant[variant].root, className),
|
59
|
+
},
|
60
|
+
}, onChange: onChange, value: value, orientation: orientation }),
|
61
|
+
React.createElement("div", { className: twJoin(classesByVariant[variant].scroller, classesByOrientation[orientation].scroller, 'flex-auto inline-block relative whitespace-nowrap') },
|
62
|
+
React.createElement(TabsList, { className: twJoin('flex', isVertical && 'flex-col') }, children)))));
|
63
|
+
});
|
34
64
|
export default Tabs;
|
35
65
|
//# sourceMappingURL=Tabs.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Tabs.js","sourceRoot":"","sources":["../../../src/Tabs/Tabs.tsx"],"names":[],"mappings":";;;;;;;;;;;AACA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,
|
1
|
+
{"version":3,"file":"Tabs.js","sourceRoot":"","sources":["../../../src/Tabs/Tabs.tsx"],"names":[],"mappings":";;;;;;;;;;;AACA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAClD,OAAO,EAAE,IAAI,IAAI,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAE7C,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAA;AAwBhE,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,CAAC,aAAa,CAG3C,EAAE,WAAW,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,CAAA;AAExD,MAAM,gBAAgB,GAAG;IACvB,gBAAgB;IAChB,oBAAoB;IACpB,gBAAgB;IAChB,cAAc;IACd,eAAe;IACf,eAAe;IACf,mBAAmB;IACnB,WAAW;CACZ,CAAA;AAED,MAAM,oBAAoB,GAAG;IAC3B,QAAQ,EAAE;QACR,IAAI,EAAE,wBAAwB;QAC9B,QAAQ,EAAE,MAAM;KACjB;IACD,UAAU,EAAE;QACV,IAAI,EAAE,EAAE;QACR,QA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,CACA,CACP,CACE,CACW,CACxB,CAAA;AACH,CAAC,CAG4B,CAAA;AAE/B,eAAe,IAAI,CAAA"}
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import type { OmitInternalProps } from '@toptal/picasso-shared';
|
2
|
-
import type { Props } from './Tabs';
|
2
|
+
import type { Props, TabsValueType } from './Tabs';
|
3
3
|
export { default as Tabs } from './Tabs';
|
4
|
-
export declare type TabsProps = OmitInternalProps<Props
|
4
|
+
export declare type TabsProps = OmitInternalProps<Props<TabsValueType>>;
|
5
|
+
export type { TabsValueType } from './Tabs';
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Tabs/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE/D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Tabs/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE/D,OAAO,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AAElD,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,QAAQ,CAAA;AACxC,oBAAY,SAAS,GAAG,iBAAiB,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAA;AAC/D,YAAY,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA"}
|
@@ -1,5 +1,7 @@
|
|
1
1
|
/// <reference types="react" />
|
2
|
-
export declare const TabsCompound: import("
|
3
|
-
|
2
|
+
export declare const TabsCompound: (<V extends import("../Tabs").TabsValueType = import("../Tabs").TabsValueType>(props: import("../Tabs/Tabs").Props<V> & {
|
3
|
+
ref?: import("react").ForwardedRef<HTMLDivElement> | undefined;
|
4
|
+
}) => JSX.Element | null) & {
|
5
|
+
Tab: import("react").ForwardRefExoticComponent<import("../Tab/Tab").Props & import("react").RefAttributes<HTMLButtonElement>>;
|
4
6
|
};
|
5
7
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/TabsCompound/index.ts"],"names":[],"mappings":";AAGA,eAAO,MAAM,YAAY
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/TabsCompound/index.ts"],"names":[],"mappings":";AAGA,eAAO,MAAM,YAAY;;;;CAEvB,CAAA"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AACtB,cAAc,OAAO,CAAA;AACrB,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AACtB,cAAc,OAAO,CAAA;AACrB,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@toptal/picasso-tabs",
|
3
|
-
"version": "
|
3
|
+
"version": "3.0.1",
|
4
4
|
"description": "Toptal UI components library - Tabs",
|
5
5
|
"publishConfig": {
|
6
6
|
"access": "public"
|
@@ -22,12 +22,13 @@
|
|
22
22
|
},
|
23
23
|
"homepage": "https://github.com/toptal/picasso/tree/master/packages/picasso#readme",
|
24
24
|
"dependencies": {
|
25
|
-
"@
|
26
|
-
"@toptal/picasso-
|
25
|
+
"@mui/base": "5.0.0-beta.40",
|
26
|
+
"@toptal/picasso-container": "2.0.0",
|
27
|
+
"@toptal/picasso-icons": "1.6.0",
|
27
28
|
"@toptal/picasso-shared": "15.0.0",
|
28
|
-
"@toptal/picasso-typography": "
|
29
|
-
"@toptal/picasso-typography-overflow": "2.0.
|
30
|
-
"@toptal/picasso-user-badge": "
|
29
|
+
"@toptal/picasso-typography": "3.0.0",
|
30
|
+
"@toptal/picasso-typography-overflow": "2.0.4",
|
31
|
+
"@toptal/picasso-user-badge": "3.0.1",
|
31
32
|
"@toptal/picasso-utils": "1.0.3",
|
32
33
|
"ap-style-title-case": "^1.1.2",
|
33
34
|
"classnames": "^2.5.1"
|
@@ -37,16 +38,16 @@
|
|
37
38
|
"**/styles.js"
|
38
39
|
],
|
39
40
|
"peerDependencies": {
|
40
|
-
"@
|
41
|
-
"@toptal/picasso-
|
42
|
-
"tailwindcss": ">=3",
|
41
|
+
"@toptal/picasso-tailwind-merge": "1.2.0",
|
42
|
+
"@toptal/picasso-tailwind": ">=2.7",
|
43
43
|
"react": ">=16.12.0 < 19.0.0"
|
44
44
|
},
|
45
45
|
"exports": {
|
46
46
|
".": "./dist-package/src/index.js"
|
47
47
|
},
|
48
48
|
"devDependencies": {
|
49
|
-
"@toptal/picasso-provider": "
|
49
|
+
"@toptal/picasso-provider": "5.0.0",
|
50
|
+
"@toptal/picasso-tailwind-merge": "1.2.0",
|
50
51
|
"@toptal/picasso-test-utils": "1.1.1"
|
51
52
|
},
|
52
53
|
"files": [
|
package/src/Tab/Tab.tsx
CHANGED
@@ -1,22 +1,20 @@
|
|
1
1
|
import type { ReactNode, HTMLAttributes, ReactElement } from 'react'
|
2
2
|
import React, { forwardRef, useContext } from 'react'
|
3
|
-
import type {
|
4
|
-
import {
|
5
|
-
import type { TabProps } from '@material-ui/core'
|
6
|
-
import { Tab as MUITab } from '@material-ui/core'
|
3
|
+
import type { TabProps } from '@mui/base/Tab'
|
4
|
+
import { Tab as MUITab } from '@mui/base/Tab'
|
7
5
|
import type { BaseProps, TextLabelProps } from '@toptal/picasso-shared'
|
8
6
|
import { useTitleCase } from '@toptal/picasso-shared'
|
9
7
|
import { UserBadge } from '@toptal/picasso-user-badge'
|
8
|
+
import { twJoin, twMerge } from '@toptal/picasso-tailwind-merge'
|
10
9
|
|
11
|
-
import
|
12
|
-
import { TabsOrientationContext } from '../Tabs/Tabs'
|
10
|
+
import { TabsContext } from '../Tabs/Tabs'
|
13
11
|
import { TabLabel } from '../TabLabel'
|
14
12
|
import { TabDescription } from '../TabDescription'
|
15
13
|
|
16
14
|
export interface Props
|
17
15
|
extends BaseProps,
|
18
16
|
TextLabelProps,
|
19
|
-
Omit<HTMLAttributes<
|
17
|
+
Omit<HTMLAttributes<HTMLButtonElement>, 'onChange'> {
|
20
18
|
/**
|
21
19
|
* If true, the tab will be disabled
|
22
20
|
* @default false
|
@@ -45,27 +43,81 @@ export interface Props
|
|
45
43
|
onClick?: TabProps['onClick']
|
46
44
|
}
|
47
45
|
|
48
|
-
const
|
46
|
+
const getOpacityClass = (
|
47
|
+
selected: boolean,
|
48
|
+
disabled: boolean,
|
49
|
+
orientation: 'horizontal' | 'vertical'
|
50
|
+
) => {
|
51
|
+
if (disabled) {
|
52
|
+
return 'opacity-50'
|
53
|
+
}
|
54
|
+
|
55
|
+
if (selected || orientation === 'vertical') {
|
56
|
+
return 'opacity-100 '
|
57
|
+
}
|
49
58
|
|
50
|
-
|
59
|
+
return 'opacity-70'
|
60
|
+
}
|
61
|
+
|
62
|
+
const wrapperClassesByOrientation = {
|
63
|
+
horizontal: 'inline-flex items-center flex-col justify-center',
|
64
|
+
vertical: 'block',
|
65
|
+
}
|
66
|
+
|
67
|
+
const rootClassesByOrientation = (selected: boolean) => ({
|
68
|
+
horizontal: [
|
69
|
+
'm-0 [&:not(:last-child)]:mr-8 pt-[0.5625rem] pb-[0.4375rem] px-0',
|
70
|
+
'text-center bg-transparent transition-shadow z-10 rounded-none',
|
71
|
+
selected ? 'text-black' : 'text-inheritColor',
|
72
|
+
selected && 'shadow-blue-500 shadow-[inset_0_-2px_0]',
|
73
|
+
],
|
74
|
+
vertical: [
|
75
|
+
' first:mt-4 last:mb-4 my-1 mx-0 py-2 px-4',
|
76
|
+
'text-left rounded-l-sm rounded-r-none transition-all',
|
77
|
+
'w-full overflow-hidden',
|
78
|
+
selected && 'shadow-1',
|
79
|
+
selected && [
|
80
|
+
'before:absolute',
|
81
|
+
'before:content-[""]',
|
82
|
+
'before:bottom-0',
|
83
|
+
'before:left-0',
|
84
|
+
'before:top-0',
|
85
|
+
'before:w-[3px]',
|
86
|
+
'before:bg-blue-500',
|
87
|
+
],
|
88
|
+
selected
|
89
|
+
? 'bg-gray-50 text-black'
|
90
|
+
: 'bg-gray-100 hover:bg-gray-200 text-graphite-700 hover:text-black',
|
91
|
+
],
|
92
|
+
})
|
93
|
+
|
94
|
+
const classesByVariant = {
|
95
|
+
scrollable: 'shrink-0 max-w-[264px]',
|
96
|
+
fullWidth: 'shrink flex-grow basis-0',
|
97
|
+
}
|
98
|
+
|
99
|
+
export const Tab = forwardRef<HTMLButtonElement, Props>(function Tab(
|
100
|
+
props,
|
101
|
+
ref
|
102
|
+
) {
|
51
103
|
const {
|
52
104
|
disabled,
|
53
105
|
value,
|
54
106
|
label,
|
55
107
|
icon,
|
56
|
-
selected,
|
57
108
|
onChange,
|
58
109
|
onClick,
|
59
110
|
titleCase: propsTitleCase,
|
60
111
|
description,
|
61
112
|
avatar,
|
113
|
+
className,
|
62
114
|
...rest
|
63
115
|
} = props
|
64
|
-
const classes = useStyles()
|
65
116
|
const titleCase = useTitleCase(propsTitleCase)
|
66
|
-
const orientation = useContext(
|
117
|
+
const { orientation, variant } = useContext(TabsContext)
|
118
|
+
const isHorizontal = orientation === 'horizontal'
|
67
119
|
|
68
|
-
const
|
120
|
+
const renderLabel = getLabelComponent({
|
69
121
|
avatar,
|
70
122
|
description,
|
71
123
|
disabled,
|
@@ -76,22 +128,49 @@ export const Tab = forwardRef<HTMLDivElement, Props>(function Tab(props, ref) {
|
|
76
128
|
|
77
129
|
return (
|
78
130
|
<MUITab
|
131
|
+
className=''
|
79
132
|
{...rest}
|
80
133
|
ref={ref}
|
81
134
|
tabIndex={0}
|
82
135
|
disabled={disabled}
|
83
|
-
label={labelComponent}
|
84
|
-
icon={icon}
|
85
136
|
value={value}
|
86
|
-
selected={selected}
|
87
137
|
onChange={onChange}
|
88
138
|
onClick={onClick}
|
89
|
-
|
90
|
-
root:
|
91
|
-
|
92
|
-
|
139
|
+
slotProps={{
|
140
|
+
root: ownerState => {
|
141
|
+
return {
|
142
|
+
className: twMerge(
|
143
|
+
getOpacityClass(
|
144
|
+
ownerState.selected,
|
145
|
+
ownerState.disabled,
|
146
|
+
orientation
|
147
|
+
),
|
148
|
+
rootClassesByOrientation(ownerState.selected)[orientation],
|
149
|
+
classesByVariant[variant],
|
150
|
+
ownerState.disabled
|
151
|
+
? 'cursor-default text-gray-500'
|
152
|
+
: 'cursor-pointer',
|
153
|
+
ownerState.disabled && 'pointer-events-none',
|
154
|
+
icon && isHorizontal && 'min-h-0 pt-[0.5625rem] pr-6',
|
155
|
+
'min-w-0 sm:min-w-[160px] md:min-w-[auto]',
|
156
|
+
'border-0 cursor-pointer inline-flex outline-none',
|
157
|
+
'items-center select-none align-middle appearance-none',
|
158
|
+
'justify-center no-underline [-webkit-tap-highlight-color:transparent]',
|
159
|
+
'normal-case whitespace-normal leading-4',
|
160
|
+
'relative ',
|
161
|
+
className
|
162
|
+
),
|
163
|
+
}
|
164
|
+
},
|
93
165
|
}}
|
94
|
-
|
166
|
+
>
|
167
|
+
<span
|
168
|
+
className={twJoin('w-full', wrapperClassesByOrientation[orientation])}
|
169
|
+
>
|
170
|
+
{renderLabel}
|
171
|
+
{icon && <span className='absolute right-0 mb-0 h-4'>{icon}</span>}
|
172
|
+
</span>
|
173
|
+
</MUITab>
|
95
174
|
)
|
96
175
|
})
|
97
176
|
|