@symply.io/basic-components 1.4.4-beta.1 → 1.4.4-beta.3
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/README.md +8 -7
- package/TabGroup/index.d.ts +1 -2
- package/TabGroup/index.js +30 -21
- package/TabGroup/types.d.ts +8 -5
- package/package.json +1 -1
package/README.md
CHANGED
@@ -812,6 +812,8 @@ import SocialInput from '@symply.io/basic-components/SocialInput';
|
|
812
812
|
|
813
813
|
Tabs group.
|
814
814
|
|
815
|
+
It is extended from `@mui/material/Tabs`, so it includes all properties of `@mui/material/Tabs`.
|
816
|
+
|
815
817
|
<h5>Import</h5>
|
816
818
|
|
817
819
|
```typescript
|
@@ -822,13 +824,12 @@ import TabGroup from '@symply.io/basic-components/TabGroup';
|
|
822
824
|
|
823
825
|
<h5>Props</h5>
|
824
826
|
|
825
|
-
| Name | Type
|
826
|
-
| --------------- |
|
827
|
-
| currentTabIndex | number
|
828
|
-
|
|
829
|
-
| tabs | Array\<{ text: string; disabled?: boolean }\> |
|
830
|
-
|
|
831
|
-
| variant | 'standard' \| 'scrollable' \| 'fullWidth' | 'scrollable' | false | Determines additional display behavior of the tabs |
|
827
|
+
| Name | Type | Default | Required | Description |
|
828
|
+
| --------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | -------- | ------------------------------------------------------------ |
|
829
|
+
| currentTabIndex | number | 0 | true | the tab index from the higher component |
|
830
|
+
| onChange | func | If `onChange` is undefined and the `url` of tab is defined, we will navigate to that url when the tab changed | false | Callback fired when the `Tab` is changed.<br />**Signature:**<br/>`function(args: {tabIndex: number; url?: string}) => void`<br/>*tabIndex:* The selected index of the `Tab` element.<br/>*url*: The url for navigating. |
|
831
|
+
| tabs | Array\<{ key: string; text: string; url?: string; disabled?: boolean }\> | | true | All tab items. |
|
832
|
+
| variant | 'standard' \| 'scrollable' \| 'fullWidth' | 'scrollable' | false | Determines additional display behavior of the tabs |
|
832
833
|
|
833
834
|
|
834
835
|
|
package/TabGroup/index.d.ts
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
/// <reference types="react" />
|
2
1
|
import type { TabGroupProps } from "./types";
|
3
|
-
declare
|
2
|
+
declare function TabGroup(props: TabGroupProps): JSX.Element;
|
4
3
|
export default TabGroup;
|
5
4
|
export type { TabGroupProps };
|
package/TabGroup/index.js
CHANGED
@@ -9,34 +9,43 @@ var __assign = (this && this.__assign) || function () {
|
|
9
9
|
};
|
10
10
|
return __assign.apply(this, arguments);
|
11
11
|
};
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
13
|
+
var t = {};
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
15
|
+
t[p] = s[p];
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
19
|
+
t[p[i]] = s[p[i]];
|
20
|
+
}
|
21
|
+
return t;
|
22
|
+
};
|
12
23
|
import { jsx as _jsx } from "react/jsx-runtime";
|
13
|
-
import {
|
24
|
+
import { useCallback } from "react";
|
25
|
+
import { navigate } from "@reach/router";
|
14
26
|
import Tab from "@mui/material/Tab";
|
15
27
|
import Tabs from "@mui/material/Tabs";
|
16
28
|
import useMediaQuery from "@mui/material/useMediaQuery";
|
17
29
|
import ThemeProvider from "@mui/material/styles/ThemeProvider";
|
18
30
|
import useCustomTheme from "../useCustomTheme";
|
19
|
-
|
20
|
-
var tabs = props.tabs, _a = props.textColor, textColor = _a === void 0 ? "primary" : _a, _b = props.variant, variant = _b === void 0 ? "scrollable" : _b, primaryColor = props.primaryColor, secondaryColor = props.secondaryColor,
|
31
|
+
function TabGroup(props) {
|
32
|
+
var tabs = props.tabs, _a = props.textColor, textColor = _a === void 0 ? "primary" : _a, _b = props.variant, variant = _b === void 0 ? "scrollable" : _b, primaryColor = props.primaryColor, secondaryColor = props.secondaryColor, currentTabIndex = props.currentTabIndex, onChange = props.onChange, rest = __rest(props, ["tabs", "textColor", "variant", "primaryColor", "secondaryColor", "currentTabIndex", "onChange"]);
|
21
33
|
var theme = useCustomTheme({ primaryColor: primaryColor, secondaryColor: secondaryColor });
|
22
34
|
var mobileViewport = useMediaQuery(theme.breakpoints.down("md"));
|
23
|
-
var
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
35
|
+
var onTabClick = useCallback(function (_, val) {
|
36
|
+
var tab = tabs[val];
|
37
|
+
if (tab) {
|
38
|
+
var url = tab.url;
|
39
|
+
if (onChange) {
|
40
|
+
onChange({ tabIndex: val, url: url });
|
41
|
+
}
|
42
|
+
else if (url) {
|
43
|
+
navigate(url);
|
44
|
+
}
|
33
45
|
}
|
34
|
-
}, [
|
35
|
-
return (_jsx(ThemeProvider, __assign({ theme: theme }, { children: _jsx(Tabs, __assign({ value: currentTabIndex, TabIndicatorProps: { hidden: true }, variant: mobileViewport ? "scrollable" : variant, textColor: textColor, onChange: function (
|
36
|
-
|
37
|
-
onTabChange(val);
|
38
|
-
} }, { children: tabs.map(function (tab, index) {
|
39
|
-
var text = tab.text, _a = tab.disabled, disabled = _a === void 0 ? false : _a;
|
46
|
+
}, [tabs]);
|
47
|
+
return (_jsx(ThemeProvider, __assign({ theme: theme }, { children: _jsx(Tabs, __assign({ value: currentTabIndex, TabIndicatorProps: { hidden: true }, variant: mobileViewport ? "scrollable" : variant, textColor: textColor, onChange: onTabClick }, rest, { children: tabs.map(function (tab, index) {
|
48
|
+
var key = tab.key, text = tab.text, _a = tab.disabled, disabled = _a === void 0 ? false : _a;
|
40
49
|
var active = currentTabIndex === index;
|
41
50
|
return (_jsx(Tab, { disableFocusRipple: true, disableRipple: true, label: text, disabled: disabled, sx: {
|
42
51
|
cursor: disabled ? "not-allowed" : "pointer",
|
@@ -44,7 +53,7 @@ var TabGroup = forwardRef(function (props, ref) {
|
|
44
53
|
background: active ? "#fff" : undefined,
|
45
54
|
borderRadius: active ? theme.spacing(0.5) : undefined,
|
46
55
|
boxShadow: active ? "0px 4px 6px #acc1c2" : undefined
|
47
|
-
} }, index));
|
56
|
+
} }, key || index));
|
48
57
|
}) })) })));
|
49
|
-
}
|
58
|
+
}
|
50
59
|
export default TabGroup;
|
package/TabGroup/types.d.ts
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
import { CSSProperties } from "react";
|
2
2
|
import { TabsProps } from "@mui/material/Tabs";
|
3
|
-
export interface TabGroupProps {
|
4
|
-
textColor?: TabsProps["textColor"];
|
3
|
+
export interface TabGroupProps extends Omit<TabsProps, "onChange"> {
|
5
4
|
tabs: Array<{
|
5
|
+
key: string;
|
6
6
|
text: string;
|
7
7
|
disabled?: boolean;
|
8
|
+
url?: string;
|
8
9
|
}>;
|
9
|
-
|
10
|
-
currentTabIndex?: number;
|
10
|
+
currentTabIndex: number;
|
11
11
|
primaryColor?: CSSProperties["color"];
|
12
12
|
secondaryColor?: CSSProperties["color"];
|
13
|
-
|
13
|
+
onChange?: (args: {
|
14
|
+
tabIndex: number;
|
15
|
+
url?: string;
|
16
|
+
}) => unknown;
|
14
17
|
}
|