@mw-kit/mw-ui 1.7.107 → 1.7.108
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/components/Tabs/components/TabItem/index.d.ts +3 -2
- package/dist/components/Tabs/functions.d.ts +3 -1
- package/dist/components/Tabs/index.d.ts +5 -2
- package/dist/components/Tabs/interfaces.d.ts +18 -12
- package/dist/index.js +34 -15
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +34 -15
- package/dist/index.modern.js.map +1 -1
- package/dist/interfaces.d.ts +1 -1
- package/package.json +1 -1
|
@@ -2,9 +2,10 @@ import React from 'react';
|
|
|
2
2
|
import { Tab, TabProps, TabsProps } from '../../interfaces';
|
|
3
3
|
declare type TabItemProps = {
|
|
4
4
|
active: Exclude<TabsProps['active'], number>;
|
|
5
|
-
tabs: [
|
|
5
|
+
tabs: [Tab[], React.Dispatch<React.SetStateAction<TabProps[]>>];
|
|
6
|
+
sortedTabs: (Tab & {
|
|
6
7
|
index: number;
|
|
7
|
-
})[]
|
|
8
|
+
})[];
|
|
8
9
|
} & Pick<TabsProps, 'onClose' | 'alwaysOpen' | 'internal'>;
|
|
9
10
|
declare const TabItem: (props: TabItemProps) => JSX.Element;
|
|
10
11
|
export default TabItem;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Tab } from './interfaces';
|
|
1
|
+
import { Tab, TabComponent, TabComponents, TabProvider } from './interfaces';
|
|
2
2
|
export declare const sortTabs: (tabs: (Tab & {
|
|
3
3
|
index: number;
|
|
4
4
|
})[], sorted?: (Tab & {
|
|
@@ -7,3 +7,5 @@ export declare const sortTabs: (tabs: (Tab & {
|
|
|
7
7
|
index: number;
|
|
8
8
|
})[];
|
|
9
9
|
export declare const hasChildren: (tabs: Tab[], group: string | undefined) => boolean;
|
|
10
|
+
export declare const mapComponents: <C extends string, T = {}>(obj: { [K in C]: TabComponent<T>; }) => TabComponents<T, C>;
|
|
11
|
+
export declare const buildComponent: <T = {}>(component: TabComponent<T>, provider?: TabProvider<T> | undefined) => TabComponent<T>;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import { TabsComponent } from './interfaces';
|
|
2
|
-
declare const Tabs: TabsComponent
|
|
1
|
+
import { TabComponent, TabComponents, TabProvider, TabsComponent } from './interfaces';
|
|
2
|
+
declare const Tabs: TabsComponent & {
|
|
3
|
+
mapComponents: <C extends string, T = {}>(obj: { [K in C]: TabComponent<T>; }) => TabComponents<T, C>;
|
|
4
|
+
buildComponent: <T_1 = {}>(component: TabComponent<T_1>, provider?: TabProvider<T_1> | undefined) => TabComponent<T_1>;
|
|
5
|
+
};
|
|
3
6
|
export default Tabs;
|
|
@@ -16,30 +16,36 @@ export declare type Tab<T = {}> = {
|
|
|
16
16
|
group?: string;
|
|
17
17
|
primary?: boolean;
|
|
18
18
|
};
|
|
19
|
-
export declare type TabComponent<T = {}> = React.FunctionComponent<{
|
|
20
|
-
data: T;
|
|
21
|
-
setLabel: React.Dispatch<React.SetStateAction<string>>;
|
|
22
|
-
}>;
|
|
23
19
|
export declare type TabProvider<T = {}> = React.FunctionComponent<React.PropsWithChildren<{
|
|
24
20
|
active: boolean;
|
|
25
21
|
setTab: React.Dispatch<React.SetStateAction<Tab<T>>>;
|
|
26
22
|
setLabel: React.Dispatch<React.SetStateAction<string>>;
|
|
27
23
|
} & Tab<T>>>;
|
|
28
|
-
export declare type
|
|
24
|
+
export declare type TabComponent<T = {}> = React.FunctionComponent<{
|
|
25
|
+
data: T;
|
|
26
|
+
label: string;
|
|
27
|
+
setLabel: React.Dispatch<React.SetStateAction<string>>;
|
|
28
|
+
}> & {
|
|
29
|
+
provider?: TabProvider<T>;
|
|
30
|
+
};
|
|
31
|
+
export declare type TabProps<T = {}, C extends string = string> = Tab<T> & {
|
|
29
32
|
/**
|
|
30
33
|
* Specifies which component, will mount/unmount everytime the tab is ACTIVATED/INACTIVATED
|
|
31
34
|
*/
|
|
32
|
-
component
|
|
35
|
+
component?: C;
|
|
36
|
+
};
|
|
37
|
+
export declare type TabComponents<T = {}, C extends string = string> = {
|
|
38
|
+
[K in C]: TabComponent<T>;
|
|
39
|
+
};
|
|
40
|
+
export interface TabsProps<T = {}, C extends string = string> extends Omit<React.HTMLAttributes<HTMLDivElement>, 'children'> {
|
|
33
41
|
/**
|
|
34
|
-
*
|
|
42
|
+
* list of components
|
|
35
43
|
*/
|
|
36
|
-
|
|
37
|
-
} | {});
|
|
38
|
-
export interface TabsProps<T = {}> extends Omit<React.HTMLAttributes<HTMLDivElement>, 'children'> {
|
|
44
|
+
components?: TabComponents<T, C>;
|
|
39
45
|
/**
|
|
40
46
|
* Array with available tabs.
|
|
41
47
|
*/
|
|
42
|
-
options: TabProps<T>[] | [TabProps<T>[], React.Dispatch<React.SetStateAction<TabProps<T>[]>>];
|
|
48
|
+
options: TabProps<T, C>[] | [TabProps<T, C>[], React.Dispatch<React.SetStateAction<TabProps<T, C>[]>>];
|
|
43
49
|
/**
|
|
44
50
|
* React state to control which tab is active.
|
|
45
51
|
*/
|
|
@@ -73,4 +79,4 @@ export interface TabsProps<T = {}> extends Omit<React.HTMLAttributes<HTMLDivElem
|
|
|
73
79
|
*/
|
|
74
80
|
onClose?: (index: number, tab: TabProps<T>, event: React.MouseEvent) => boolean | Promise<boolean>;
|
|
75
81
|
}
|
|
76
|
-
export declare type TabsComponent = <T = {}>(props: TabsProps<T>) => JSX.Element;
|
|
82
|
+
export declare type TabsComponent = <T = {}, C extends string = string>(props: TabsProps<T, C>) => JSX.Element;
|
package/dist/index.js
CHANGED
|
@@ -19506,6 +19506,14 @@ var hasChildren = function hasChildren(tabs, group) {
|
|
|
19506
19506
|
return tab.group === group && !tab.primary;
|
|
19507
19507
|
}) : false;
|
|
19508
19508
|
};
|
|
19509
|
+
var mapComponents = function mapComponents(obj) {
|
|
19510
|
+
return obj;
|
|
19511
|
+
};
|
|
19512
|
+
var buildComponent = function buildComponent(component, provider) {
|
|
19513
|
+
return provider ? Object.assign(component, {
|
|
19514
|
+
provider: provider
|
|
19515
|
+
}) : component;
|
|
19516
|
+
};
|
|
19509
19517
|
|
|
19510
19518
|
var _templateObject$19;
|
|
19511
19519
|
var Close = styled__default.div(_templateObject$19 || (_templateObject$19 = _taggedTemplateLiteralLoose(["\n position: relative;\n z-index: 2;\n display: flex;\n align-items: center;\n justify-content: center;\n cursor: pointer;\n\n background-color: var(--bgColor);\n color: var(--color);\n padding: 4px 8px;\n\n transition: --color 0.5s, --bgColor 0.5s;\n\n svg {\n width: 14px;\n height: 14px;\n\n * {\n transition: --color 0.5s;\n stroke: var(--color);\n }\n }\n"])));
|
|
@@ -19535,13 +19543,12 @@ var Close$1 = function Close$1(props) {
|
|
|
19535
19543
|
return;
|
|
19536
19544
|
}
|
|
19537
19545
|
|
|
19538
|
-
|
|
19539
|
-
|
|
19540
|
-
|
|
19541
|
-
|
|
19542
|
-
setActive(newactive, newOptions[newactive].data);
|
|
19543
|
-
}
|
|
19546
|
+
var newactive = function () {
|
|
19547
|
+
if (index < active) return active - 1;
|
|
19548
|
+
return active > 0 ? active - 1 : active;
|
|
19549
|
+
}();
|
|
19544
19550
|
|
|
19551
|
+
setActive(newactive, newOptions[newactive].data);
|
|
19545
19552
|
setOptions(newOptions);
|
|
19546
19553
|
});
|
|
19547
19554
|
} catch (e) {
|
|
@@ -19619,10 +19626,11 @@ var TabItem = function TabItem(props) {
|
|
|
19619
19626
|
_props$tabs = props.tabs,
|
|
19620
19627
|
tabs = _props$tabs[0],
|
|
19621
19628
|
setTabs = _props$tabs[1],
|
|
19629
|
+
sortedTabs = props.sortedTabs,
|
|
19622
19630
|
onClose = props.onClose,
|
|
19623
19631
|
alwaysOpen = props.alwaysOpen;
|
|
19624
19632
|
var CloseComponent = alwaysOpen || tabs.length < 2 ? VoidClose : Close$1;
|
|
19625
|
-
return React__default.createElement(React__default.Fragment, null,
|
|
19633
|
+
return React__default.createElement(React__default.Fragment, null, sortedTabs.map(function (_ref) {
|
|
19626
19634
|
var index = _ref.index,
|
|
19627
19635
|
tab = _objectWithoutPropertiesLoose(_ref, _excluded$3);
|
|
19628
19636
|
|
|
@@ -19684,7 +19692,9 @@ var VoidProvider = function VoidProvider(props) {
|
|
|
19684
19692
|
});
|
|
19685
19693
|
};
|
|
19686
19694
|
|
|
19687
|
-
var
|
|
19695
|
+
var Component$3 = function Component(props) {
|
|
19696
|
+
var components = props.components || {};
|
|
19697
|
+
|
|
19688
19698
|
var _ref = typeof props.options[1] === 'function' ? props.options : React.useState(props.options),
|
|
19689
19699
|
options = _ref[0],
|
|
19690
19700
|
setOptions = _ref[1];
|
|
@@ -19712,17 +19722,20 @@ var Tabs$1 = function Tabs$1(props) {
|
|
|
19712
19722
|
internal: props.internal
|
|
19713
19723
|
}), React__default.createElement(TabItem, {
|
|
19714
19724
|
active: [active, setActive],
|
|
19715
|
-
tabs: [
|
|
19725
|
+
tabs: [options, setOptions],
|
|
19726
|
+
sortedTabs: sortedTabs,
|
|
19716
19727
|
onClose: props.onClose,
|
|
19717
19728
|
alwaysOpen: props.alwaysOpen,
|
|
19718
19729
|
internal: props.internal
|
|
19719
19730
|
}))), options.map(function (tab, index) {
|
|
19720
|
-
if (
|
|
19721
|
-
|
|
19722
|
-
|
|
19723
|
-
|
|
19724
|
-
|
|
19725
|
-
|
|
19731
|
+
if (tab.component === undefined) {
|
|
19732
|
+
return React__default.createElement(React__default.Fragment, {
|
|
19733
|
+
key: index
|
|
19734
|
+
});
|
|
19735
|
+
}
|
|
19736
|
+
|
|
19737
|
+
var Component = components[tab.component];
|
|
19738
|
+
var Provider = Component.provider || VoidProvider;
|
|
19726
19739
|
|
|
19727
19740
|
var setTab = function setTab(s) {
|
|
19728
19741
|
setOptions(function (prev) {
|
|
@@ -19754,6 +19767,7 @@ var Tabs$1 = function Tabs$1(props) {
|
|
|
19754
19767
|
active: true,
|
|
19755
19768
|
children: React__default.createElement("div", null, React__default.createElement(Component, {
|
|
19756
19769
|
data: tab.data,
|
|
19770
|
+
label: tab.label,
|
|
19757
19771
|
setLabel: setLabel
|
|
19758
19772
|
}))
|
|
19759
19773
|
} : {
|
|
@@ -19762,6 +19776,11 @@ var Tabs$1 = function Tabs$1(props) {
|
|
|
19762
19776
|
}));
|
|
19763
19777
|
};
|
|
19764
19778
|
|
|
19779
|
+
var Tabs$1 = Object.assign(Component$3, {
|
|
19780
|
+
mapComponents: mapComponents,
|
|
19781
|
+
buildComponent: buildComponent
|
|
19782
|
+
});
|
|
19783
|
+
|
|
19765
19784
|
var _templateObject$1d;
|
|
19766
19785
|
var Container$q = styled__default.textarea(_templateObject$1d || (_templateObject$1d = _taggedTemplateLiteralLoose(["\n width: ", ";\n height: ", ";\n resize: none;\n outline: 0;\n border: 1px solid #c8c8c8;\n padding: 14px;\n border-radius: 4px;\n color: #192338;\n"])), function (props) {
|
|
19767
19786
|
return "" + props.width;
|