@toptal/picasso-tabs 5.0.15-alpha-MP-955-fix-section-closing-animation-d279e2398.0 → 5.0.15-alpha-ff-7-tabs-19babbfd6.8
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/Tabs/Tabs.d.ts +11 -8
- package/dist-package/src/Tabs/Tabs.d.ts.map +1 -1
- package/dist-package/src/Tabs/Tabs.js +53 -16
- package/dist-package/src/Tabs/Tabs.js.map +1 -1
- package/dist-package/src/TabsCompound/index.d.ts +2 -4
- 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 +14 -13
- package/src/Tab/Tab.tsx +99 -21
- package/src/Tabs/Tabs.tsx +88 -37
- package/src/Tabs/__snapshots__/test.tsx.snap +56 -71
- package/src/Tabs/test.tsx +4 -4
- package/src/index.ts +0 -1
- 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 -95
- 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 -30
- 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/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 -107
- package/src/TabScrollButton/TabScrollButton.tsx +0 -59
- package/src/TabScrollButton/index.ts +0 -6
- 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
|
+
'text-black',
|
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({ className: '' }, 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,KAAK,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAErD,OAAO,EAAE,GAAG,IAAI,MAAM,EAAE,MAAM,eAAe,CAAA;AAE7C,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AACtD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAA;AAEhE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAkClD,MAAM,eAAe,GAAG,CACtB,QAAiB,EACjB,QAAiB,EACjB,WAAsC,EACtC,EAAE;IACF,IAAI,QAAQ,EAAE;QACZ,OAAO,YAAY,CAAA;KACpB;IAED,IAAI,QAAQ,IAAI,WAAW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,EAAmB,EAAE;IAC5C,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,IAAI,CAAA;KACZ;IAED,MAAM,YAAY,GAAG,WAAW,KAAK,YAAY,CAAA;IACjD,MAAM,aAAa,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAA;IAE/C,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC,CAClB,oBAAC,QAAQ,IAAC,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,WAAW,GAAI,CAC3E,CAAA;IAED,IAAI,YAAY,IAAI,aAAa,EAAE;QACjC,OAAO,oBAAC,KAAK,OAAG,CAAA;KACjB;IAED,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QACjC,OAAO,CACL;YACE,oBAAC,KAAK,OAAG;YACR,WAAW,IAAI,CACd,oBAAC,cAAc,IAAC,QAAQ,EAAE,QAAQ,IAAG,WAAW,CAAkB,CACnE,CACA,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,23 +1,26 @@
|
|
1
|
-
import type {
|
1
|
+
import type { ReactNode } from 'react';
|
2
2
|
import React from 'react';
|
3
|
-
import { Tabs as MUITabs } from '@material-ui/core';
|
4
3
|
import type { BaseProps } from '@toptal/picasso-shared';
|
5
|
-
export declare type TabsValueType = string | number |
|
4
|
+
export declare type TabsValueType = string | number | null;
|
6
5
|
export interface Props<V extends TabsValueType> extends BaseProps {
|
7
6
|
/** Tabs content containing Tab components */
|
8
7
|
children: ReactNode;
|
9
8
|
/** Callback fired when the value changes. */
|
10
9
|
onChange?: (event: React.ChangeEvent<{}> | null, value: V) => void;
|
11
|
-
/**
|
10
|
+
/**
|
11
|
+
* The value of the currently selected Tab.
|
12
|
+
* If you don't want any selected Tab, you can set this property to null.
|
13
|
+
*/
|
12
14
|
value: V;
|
13
15
|
/** The tabs orientation (layout flow direction). */
|
14
16
|
orientation?: 'horizontal' | 'vertical';
|
15
17
|
/** Determines additional display behavior of the tabs */
|
16
18
|
variant?: 'scrollable' | 'fullWidth';
|
17
19
|
}
|
18
|
-
export declare const
|
19
|
-
|
20
|
-
|
21
|
-
}
|
20
|
+
export declare const TabsContext: React.Context<{
|
21
|
+
orientation: 'horizontal' | 'vertical';
|
22
|
+
variant: 'scrollable' | 'fullWidth';
|
23
|
+
}>;
|
24
|
+
export declare const Tabs: React.ForwardRefExoticComponent<Props<TabsValueType> & React.RefAttributes<HTMLDivElement>>;
|
22
25
|
export default Tabs;
|
23
26
|
//# 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,
|
1
|
+
{"version":3,"file":"Tabs.d.ts","sourceRoot":"","sources":["../../../src/Tabs/Tabs.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACtC,OAAO,KAA8B,MAAM,OAAO,CAAA;AAGlD,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;AAoCxD,eAAO,MAAM,IAAI,6FAyDhB,CAAA;AAID,eAAe,IAAI,CAAA"}
|
@@ -9,22 +9,59 @@ 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
|
-
|
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
|
+
},
|
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
|
+
// eslint-disable-next-line react/display-name
|
48
|
+
export const Tabs = forwardRef(function Tabs(props, ref) {
|
49
|
+
const { children, orientation = 'horizontal', onChange, value, variant = 'scrollable', className } = props, rest = __rest(props, ["children", "orientation", "onChange", "value", "variant", "className"]);
|
50
|
+
const contextValue = useMemo(() => ({
|
51
|
+
orientation,
|
52
|
+
variant,
|
53
|
+
}), [orientation, variant]);
|
54
|
+
const isVertical = orientation === 'vertical';
|
55
|
+
return (React.createElement(TabsContext.Provider, { value: contextValue },
|
56
|
+
React.createElement(MUITabs, Object.assign({}, rest, { "data-component-type": 'tabs', slotProps: {
|
57
|
+
root: {
|
58
|
+
ref,
|
59
|
+
className: twMerge('relative min-h-0 flex overflow-hidden', classesByOrientation[orientation].root, classesByVariant[variant].root, className),
|
60
|
+
},
|
61
|
+
}, onChange: onChange, value: value, orientation: orientation }),
|
62
|
+
React.createElement("div", { className: twJoin(classesByVariant[variant].scroller, classesByOrientation[orientation].scroller, 'flex-auto inline-block relative whitespace-nowrap') },
|
63
|
+
React.createElement(TabsList, { className: twJoin('flex', isVertical && 'flex-col') }, children)))));
|
28
64
|
});
|
65
|
+
Tabs.displayName = 'Tabs';
|
29
66
|
export default Tabs;
|
30
67
|
//# 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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R,CAAC,EACF,CAAC,WAAW,EAAE,OAAO,CAAC,CACvB,CAAA;IAED,MAAM,UAAU,GAAG,WAAW,KAAK,UAAU,CAAA;IAE7C,OAAO,CACL,oBAAC,WAAW,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY;QACvC,oBAAC,OAAO,oBACF,IAAI,2BACY,MAAM,EAC1B,SAAS,EAAE;gBACT,IAAI,EAAE;oBACJ,GAAG;oBACH,SAAS,EAAE,OAAO,CAChB,uCAAuC,EACvC,oBAAoB,CAAC,WAAW,CAAC,CAAC,IAAI,EACtC,gBAAgB,CAAC,OAAO,CAAC,CAAC,IAAI,EAC9B,SAAS,CACV;iBACF;aACF,EACD,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,WAAW;YAExB,6BACE,SAAS,EAAE,MAAM,CACf,gBAAgB,CAAC,OAAO,CAAC,CAAC,QAAQ,EAClC,oBAAoB,CAAC,WAAW,CAAC,CAAC,QAAQ,EAC1C,mDAAmD,CACpD;gBAED,oBAAC,QAAQ,IAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,IAAI,UAAU,CAAC,IAC1D,QAAQ,CACA,CACP,CACE,CACW,CACxB,CAAA;AACH,CAAC,CACF,CAAA;AAED,IAAI,CAAC,WAAW,GAAG,MAAM,CAAA;AAEzB,eAAe,IAAI,CAAA"}
|
@@ -1,7 +1,5 @@
|
|
1
1
|
/// <reference types="react" />
|
2
|
-
export declare const TabsCompound: (<
|
3
|
-
|
4
|
-
}) => JSX.Element) & {
|
5
|
-
Tab: import("react").ForwardRefExoticComponent<import("../Tab/Tab").Props & import("react").RefAttributes<HTMLDivElement>>;
|
2
|
+
export declare const TabsCompound: import("react").ForwardRefExoticComponent<import("../Tabs/Tabs").Props<import("../Tabs").TabsValueType> & import("react").RefAttributes<HTMLDivElement>> & {
|
3
|
+
Tab: import("react").ForwardRefExoticComponent<import("../Tab/Tab").Props & import("react").RefAttributes<HTMLButtonElement>>;
|
6
4
|
};
|
7
5
|
//# 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": "5.0.15-alpha-
|
3
|
+
"version": "5.0.15-alpha-ff-7-tabs-19babbfd6.8+19babbfd6",
|
4
4
|
"description": "Toptal UI components library - Tabs",
|
5
5
|
"publishConfig": {
|
6
6
|
"access": "public"
|
@@ -22,13 +22,14 @@
|
|
22
22
|
},
|
23
23
|
"homepage": "https://github.com/toptal/picasso/tree/master/packages/picasso#readme",
|
24
24
|
"dependencies": {
|
25
|
-
"@
|
26
|
-
"@toptal/picasso-
|
27
|
-
"@toptal/picasso-
|
28
|
-
"@toptal/picasso-
|
29
|
-
"@toptal/picasso-typography
|
30
|
-
"@toptal/picasso-
|
31
|
-
"@toptal/picasso-
|
25
|
+
"@mui/base": "5.0.0-beta.58",
|
26
|
+
"@toptal/picasso-container": "3.1.3-alpha-ff-7-tabs-19babbfd6.8+19babbfd6",
|
27
|
+
"@toptal/picasso-icons": "1.12.2-alpha-ff-7-tabs-19babbfd6.8+19babbfd6",
|
28
|
+
"@toptal/picasso-shared": "15.0.1-alpha-ff-7-tabs-19babbfd6.354+19babbfd6",
|
29
|
+
"@toptal/picasso-typography": "4.0.4-alpha-ff-7-tabs-19babbfd6.8+19babbfd6",
|
30
|
+
"@toptal/picasso-typography-overflow": "4.0.4-alpha-ff-7-tabs-19babbfd6.8+19babbfd6",
|
31
|
+
"@toptal/picasso-user-badge": "5.1.12-alpha-ff-7-tabs-19babbfd6.8+19babbfd6",
|
32
|
+
"@toptal/picasso-utils": "3.1.1-alpha-ff-7-tabs-19babbfd6.8+19babbfd6",
|
32
33
|
"ap-style-title-case": "^1.1.2"
|
33
34
|
},
|
34
35
|
"sideEffects": [
|
@@ -36,8 +37,8 @@
|
|
36
37
|
"**/styles.js"
|
37
38
|
],
|
38
39
|
"peerDependencies": {
|
39
|
-
"@material-ui/core": "4.12.4",
|
40
40
|
"@toptal/picasso-provider": "*",
|
41
|
+
"@toptal/picasso-tailwind": ">=2.6",
|
41
42
|
"@toptal/picasso-tailwind-merge": "^2.0.0",
|
42
43
|
"react": ">=16.12.0 < 19.0.0"
|
43
44
|
},
|
@@ -45,14 +46,14 @@
|
|
45
46
|
".": "./dist-package/src/index.js"
|
46
47
|
},
|
47
48
|
"devDependencies": {
|
48
|
-
"@
|
49
|
-
"@toptal/picasso-
|
50
|
-
"@toptal/picasso-test-utils": "1.1.2-alpha-
|
49
|
+
"@toptal/picasso-provider": "5.0.1-alpha-ff-7-tabs-19babbfd6.275+19babbfd6",
|
50
|
+
"@toptal/picasso-tailwind-merge": "2.0.4-alpha-ff-7-tabs-19babbfd6.8+19babbfd6",
|
51
|
+
"@toptal/picasso-test-utils": "1.1.2-alpha-ff-7-tabs-19babbfd6.354+19babbfd6"
|
51
52
|
},
|
52
53
|
"files": [
|
53
54
|
"dist-package/**",
|
54
55
|
"!dist-package/tsconfig.tsbuildinfo",
|
55
56
|
"src"
|
56
57
|
],
|
57
|
-
"gitHead": "
|
58
|
+
"gitHead": "19babbfd627b4461663b6782aa7493f16f4181bc"
|
58
59
|
}
|
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
|
+
'text-black',
|
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,
|
@@ -81,18 +133,44 @@ export const Tab = forwardRef<HTMLDivElement, Props>(function Tab(props, ref) {
|
|
81
133
|
ref={ref}
|
82
134
|
tabIndex={0}
|
83
135
|
disabled={disabled}
|
84
|
-
label={labelComponent}
|
85
|
-
icon={icon}
|
86
136
|
value={value}
|
87
|
-
selected={selected}
|
88
137
|
onChange={onChange}
|
89
138
|
onClick={onClick}
|
90
|
-
|
91
|
-
root:
|
92
|
-
|
93
|
-
|
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
|
+
},
|
94
165
|
}}
|
95
|
-
|
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>
|
96
174
|
)
|
97
175
|
})
|
98
176
|
|