@mw-kit/mw-ui 1.7.107 → 1.7.109

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.
@@ -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: [(Tab & {
5
+ tabs: [Tab[], React.Dispatch<React.SetStateAction<TabProps[]>>];
6
+ sortedTabs: (Tab & {
6
7
  index: number;
7
- })[], React.Dispatch<React.SetStateAction<TabProps[]>>];
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 TabProps<T = {}> = Tab<T> & ({
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: TabComponent<T>;
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
- * Specifies the component provider, will mount/unmount when the tab is CREATED/REMOVED
42
+ * list of components
35
43
  */
36
- provider?: TabProvider<T>;
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;
@@ -4,5 +4,6 @@ declare type TabsContainerProps = {
4
4
  $delimiter?: TabsProps['delimiter'];
5
5
  $spacing?: TabsProps['spacing'];
6
6
  };
7
+ export declare const ComponentContainer: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
7
8
  export declare const Tabs: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, TabsContainerProps, never>;
8
9
  export {};
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
- if (index < active) {
19539
- setActive(active - 1, newOptions[active - 1].data);
19540
- } else if (active === index) {
19541
- var newactive = active > 0 ? active - 1 : active;
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, tabs.map(function (_ref) {
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
 
@@ -19650,12 +19658,13 @@ var TabItem = function TabItem(props) {
19650
19658
  }));
19651
19659
  };
19652
19660
 
19653
- var _templateObject$1c, _templateObject2$S, _templateObject3$J;
19661
+ var _templateObject$1c, _templateObject2$S, _templateObject3$J, _templateObject4$x;
19654
19662
  var delimiters = {
19655
19663
  blue: ['blue'],
19656
19664
  grey: ['warningGray']
19657
19665
  };
19658
- var Tabs = styled__default.div(_templateObject$1c || (_templateObject$1c = _taggedTemplateLiteralLoose(["\n position: relative;\n overflow: hidden;\n\n display: flex;\n width: 100%;\n white-space: nowrap;\n\n ", "\n\n ", "\n\n\n /* exibe as setas de navega\xE7\xE3o vis\xEDveis ao passar o mouse sobre o container */\n &:hover .scroll-arrow.visible:nth-child(1) {\n left: 0;\n }\n & .scroll-arrow:nth-child(1) {\n left: -16px;\n }\n\n &:hover .scroll-arrow.visible:nth-last-child(1) {\n right: 0;\n }\n & .scroll-arrow:nth-last-child(1) {\n right: -16px;\n }\n"])), function (_ref) {
19666
+ var ComponentContainer = styled__default.div(_templateObject$1c || (_templateObject$1c = _taggedTemplateLiteralLoose([""])));
19667
+ var Tabs = styled__default.div(_templateObject2$S || (_templateObject2$S = _taggedTemplateLiteralLoose(["\n position: relative;\n overflow: hidden;\n\n display: flex;\n width: 100%;\n white-space: nowrap;\n\n ", "\n\n ", "\n\n\n /* exibe as setas de navega\xE7\xE3o vis\xEDveis ao passar o mouse sobre o container */\n &:hover .scroll-arrow.visible:nth-child(1) {\n left: 0;\n }\n & .scroll-arrow:nth-child(1) {\n left: -16px;\n }\n\n &:hover .scroll-arrow.visible:nth-last-child(1) {\n right: 0;\n }\n & .scroll-arrow:nth-last-child(1) {\n right: -16px;\n }\n"])), function (_ref) {
19659
19668
  var spacing = _ref.$spacing;
19660
19669
 
19661
19670
  var _getSpacings$split = getSpacings(spacing || {}, {
@@ -19669,13 +19678,13 @@ var Tabs = styled__default.div(_templateObject$1c || (_templateObject$1c = _tagg
19669
19678
  bottom = _getSpacings$split[2],
19670
19679
  left = _getSpacings$split[3];
19671
19680
 
19672
- return styled.css(_templateObject2$S || (_templateObject2$S = _taggedTemplateLiteralLoose(["\n margin: ", " 0 ", " 0;\n padding: 0 ", " 0 ", ";\n "])), top, bottom, right, left);
19681
+ return styled.css(_templateObject3$J || (_templateObject3$J = _taggedTemplateLiteralLoose(["\n margin: ", " 0 ", " 0;\n padding: 0 ", " 0 ", ";\n "])), top, bottom, right, left);
19673
19682
  }, function (_ref2) {
19674
19683
  var theme = _ref2.theme,
19675
19684
  internal = _ref2.$internal,
19676
19685
  delimiter = _ref2.$delimiter;
19677
19686
  var border = delimiter === 'none' ? 'none' : internal ? "1px solid " + theme.getColor.apply(theme, delimiters[delimiter || 'grey']) : "2px solid " + theme.getColor.apply(theme, delimiters[delimiter || 'blue']);
19678
- return styled.css(_templateObject3$J || (_templateObject3$J = _taggedTemplateLiteralLoose(["\n border-bottom: ", ";\n + div {\n border: 1px solid ", ";\n border-top-width: 0px;\n border-radius: 0px 0px 2px 2px;\n padding: ", ";\n }\n "])), border, theme.getColor.apply(theme, delimiters.grey), theme.spacings.s3);
19687
+ return styled.css(_templateObject4$x || (_templateObject4$x = _taggedTemplateLiteralLoose(["\n border-bottom: ", ";\n + ", " {\n border: 1px solid ", ";\n border-top-width: 0px;\n border-radius: 0px 0px 2px 2px;\n padding: ", ";\n }\n "])), border, ComponentContainer, theme.getColor.apply(theme, delimiters.grey), theme.spacings.s3);
19679
19688
  });
19680
19689
 
19681
19690
  var VoidProvider = function VoidProvider(props) {
@@ -19684,7 +19693,9 @@ var VoidProvider = function VoidProvider(props) {
19684
19693
  });
19685
19694
  };
19686
19695
 
19687
- var Tabs$1 = function Tabs$1(props) {
19696
+ var Component$3 = function Component(props) {
19697
+ var components = props.components || {};
19698
+
19688
19699
  var _ref = typeof props.options[1] === 'function' ? props.options : React.useState(props.options),
19689
19700
  options = _ref[0],
19690
19701
  setOptions = _ref[1];
@@ -19712,17 +19723,20 @@ var Tabs$1 = function Tabs$1(props) {
19712
19723
  internal: props.internal
19713
19724
  }), React__default.createElement(TabItem, {
19714
19725
  active: [active, setActive],
19715
- tabs: [sortedTabs, setOptions],
19726
+ tabs: [options, setOptions],
19727
+ sortedTabs: sortedTabs,
19716
19728
  onClose: props.onClose,
19717
19729
  alwaysOpen: props.alwaysOpen,
19718
19730
  internal: props.internal
19719
19731
  }))), options.map(function (tab, index) {
19720
- if (!('component' in tab)) return React__default.createElement(React__default.Fragment, {
19721
- key: index
19722
- });
19723
- var _tab$provider = tab.provider,
19724
- Provider = _tab$provider === void 0 ? VoidProvider : _tab$provider,
19725
- Component = tab.component;
19732
+ if (tab.component === undefined) {
19733
+ return React__default.createElement(React__default.Fragment, {
19734
+ key: index
19735
+ });
19736
+ }
19737
+
19738
+ var Component = components[tab.component];
19739
+ var Provider = Component.provider || VoidProvider;
19726
19740
 
19727
19741
  var setTab = function setTab(s) {
19728
19742
  setOptions(function (prev) {
@@ -19752,8 +19766,9 @@ var Tabs$1 = function Tabs$1(props) {
19752
19766
  setLabel: setLabel
19753
19767
  }, index === active ? {
19754
19768
  active: true,
19755
- children: React__default.createElement("div", null, React__default.createElement(Component, {
19769
+ children: React__default.createElement(ComponentContainer, null, React__default.createElement(Component, {
19756
19770
  data: tab.data,
19771
+ label: tab.label,
19757
19772
  setLabel: setLabel
19758
19773
  }))
19759
19774
  } : {
@@ -19762,6 +19777,11 @@ var Tabs$1 = function Tabs$1(props) {
19762
19777
  }));
19763
19778
  };
19764
19779
 
19780
+ var Tabs$1 = Object.assign(Component$3, {
19781
+ mapComponents: mapComponents,
19782
+ buildComponent: buildComponent
19783
+ });
19784
+
19765
19785
  var _templateObject$1d;
19766
19786
  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
19787
  return "" + props.width;
@@ -19773,7 +19793,7 @@ var TextArea = function TextArea(props) {
19773
19793
  return React__default.createElement(Container$q, Object.assign({}, props));
19774
19794
  };
19775
19795
 
19776
- var _templateObject$1e, _templateObject2$T, _templateObject3$K, _templateObject4$x, _templateObject5$t, _templateObject6$q;
19796
+ var _templateObject$1e, _templateObject2$T, _templateObject3$K, _templateObject4$y, _templateObject5$t, _templateObject6$q;
19777
19797
  var Container$r = styled__default.div(_templateObject$1e || (_templateObject$1e = _taggedTemplateLiteralLoose(["\n border-radius: 4px;\n width: ", ";\n height: 88px;\n border: 1px solid transparent;\n position: relative;\n\n ", "\n\n ", "\n\n ", "\n\n svg {\n cursor: pointer;\n position: absolute;\n top: 14px;\n right: 14px;\n width: 13px;\n height: 13px;\n }\n"])), function (props) {
19778
19798
  return props.size === 'large' ? '837px' : '460px';
19779
19799
  }, function (props) {
@@ -19781,7 +19801,7 @@ var Container$r = styled__default.div(_templateObject$1e || (_templateObject$1e
19781
19801
  }, function (props) {
19782
19802
  return props.color === 'error' && styled.css(_templateObject3$K || (_templateObject3$K = _taggedTemplateLiteralLoose(["\n background-color: #fff6f6;\n opacity: 1;\n border-color: #973937;\n h4 {\n color: #973937;\n }\n p {\n color: #973937;\n }\n "])));
19783
19803
  }, function (props) {
19784
- return props.color === 'warning' && styled.css(_templateObject4$x || (_templateObject4$x = _taggedTemplateLiteralLoose(["\n background-color: #fffaf3;\n opacity: 1;\n border-color: #ccbea0;\n h4 {\n color: #7a4d05;\n }\n p {\n color: #7a4d05cc;\n }\n "])));
19804
+ return props.color === 'warning' && styled.css(_templateObject4$y || (_templateObject4$y = _taggedTemplateLiteralLoose(["\n background-color: #fffaf3;\n opacity: 1;\n border-color: #ccbea0;\n h4 {\n color: #7a4d05;\n }\n p {\n color: #7a4d05cc;\n }\n "])));
19785
19805
  });
19786
19806
  var IconContainer$2 = styled__default.div(_templateObject5$t || (_templateObject5$t = _taggedTemplateLiteralLoose(["\n width: 100%;\n display: flex;\n align-items: center;\n justify-content: flex-end;\n padding: 14px 14px 0 0;\n margin: 0;\n"])));
19787
19807
  var IconContent = styled__default.div(_templateObject6$q || (_templateObject6$q = _taggedTemplateLiteralLoose(["\n width: 100%;\n padding: 13px 0 21px 28px;\n display: flex;\n flex: 1;\n flex-direction: column;\n\n h4 {\n margin-bottom: 7px;\n font-size: 18p;\n }\n p {\n margin: 0;\n font-size: 14px;\n max-width: 380px;\n }\n"])));
@@ -19796,7 +19816,7 @@ var Toast = function Toast(props) {
19796
19816
  })), React__default.createElement(IconContent, null, React__default.createElement("h4", null, props.title), React__default.createElement("p", null, " ", props.description)));
19797
19817
  };
19798
19818
 
19799
- var _templateObject$1f, _templateObject2$U, _templateObject3$L, _templateObject4$y, _templateObject5$u;
19819
+ var _templateObject$1f, _templateObject2$U, _templateObject3$L, _templateObject4$z, _templateObject5$u;
19800
19820
  var Image = styled__default.img(_templateObject$1f || (_templateObject$1f = _taggedTemplateLiteralLoose(["\n max-width: 100%;\n max-height: 100%;\n"])));
19801
19821
  var Container$s = styled__default.div(_templateObject2$U || (_templateObject2$U = _taggedTemplateLiteralLoose(["\n position: relative;\n display: inline-flex;\n\n &,\n ", " {\n width: ", ";\n\n height: ", ";\n }\n"])), Image, function (_ref) {
19802
19822
  var width = _ref.width;
@@ -19829,7 +19849,7 @@ var Dimmer = styled__default.div(_templateObject3$L || (_templateObject3$L = _ta
19829
19849
  var theme = _ref3.theme;
19830
19850
  return theme.getColor('greyishBlue', 50);
19831
19851
  });
19832
- var Button$6 = styled__default(Button$1)(_templateObject4$y || (_templateObject4$y = _taggedTemplateLiteralLoose(["\n background-color: ", ";\n"])), function (_ref4) {
19852
+ var Button$6 = styled__default(Button$1)(_templateObject4$z || (_templateObject4$z = _taggedTemplateLiteralLoose(["\n background-color: ", ";\n"])), function (_ref4) {
19833
19853
  var theme = _ref4.theme;
19834
19854
  return theme.getColor('white', 50);
19835
19855
  });