@mw-kit/mw-ui 1.7.77 → 1.7.78

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.
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import { TabProps, TabsProps } from '../../interfaces';
3
+ declare const Close: (props: Pick<TabsProps, 'onClose'> & {
4
+ index: number;
5
+ active: [number, React.Dispatch<React.SetStateAction<number>>];
6
+ options: [TabProps[], React.Dispatch<React.SetStateAction<TabProps[]>>];
7
+ }) => JSX.Element;
8
+ export default Close;
@@ -0,0 +1 @@
1
+ export declare const Close: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
@@ -0,0 +1 @@
1
+ export { default as Close } from './Close';
@@ -1,24 +1,33 @@
1
1
  /// <reference types="react" />
2
2
  import { SpacingOrZero, Spacings } from '../../interfaces';
3
+ export declare type TabComponent = React.FunctionComponent;
4
+ export declare type TabProvider = React.FunctionComponent<React.PropsWithChildren<{
5
+ active: boolean;
6
+ }>>;
3
7
  export declare type TabProps = {
4
8
  /**
5
9
  * Define the tab label.
6
10
  */
7
11
  label: string;
12
+ } & ({
8
13
  /**
9
- * Specifies which component will render when the tab is active.
14
+ * Specifies which component, will mount/unmount everytime the tab is ACTIVATED/INACTIVATED
10
15
  */
11
- component?: JSX.Element;
12
- };
16
+ component: TabComponent;
17
+ /**
18
+ * Specifies the component provider, will mount/unmount when the tab is CREATED/REMOVED
19
+ */
20
+ provider?: TabProvider;
21
+ } | {});
13
22
  export interface TabsProps extends React.HTMLAttributes<HTMLDivElement> {
14
23
  /**
15
24
  * Array with available tabs.
16
25
  */
17
- options: TabProps[];
26
+ options: TabProps[] | [TabProps[], React.Dispatch<React.SetStateAction<TabProps[]>>];
18
27
  /**
19
28
  * React state to control which tab is active.
20
29
  */
21
- activeState: [number, React.Dispatch<React.SetStateAction<number>>];
30
+ active: number | [number, React.Dispatch<React.SetStateAction<number>>];
22
31
  /**
23
32
  * Sets the style of the tabs to internal.
24
33
  */
@@ -6,5 +6,5 @@ declare type TabsContainerProps = {
6
6
  $spacing?: TabsProps['spacing'];
7
7
  };
8
8
  export declare const Tabs: import("styled-components").StyledComponent<"ul", import("styled-components").DefaultTheme, TabsContainerProps, never>;
9
- export declare const Tab: import("styled-components").StyledComponent<"li", import("styled-components").DefaultTheme, StyledTabsProps, never>;
9
+ export declare const Tab: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, StyledTabsProps, never>;
10
10
  export {};
package/dist/index.js CHANGED
@@ -19104,7 +19104,7 @@ var delimiters = {
19104
19104
  blue: ['blue'],
19105
19105
  grey: ['warningGray']
19106
19106
  };
19107
- var Tabs = styled__default.ul(_templateObject2$Q || (_templateObject2$Q = _taggedTemplateLiteralLoose(["\n user-select: none;\n list-style: none;\n display: inline-flex;\n width: 100%;\n\n ", "\n\n ", ";\n\n gap: ", ";\n"])), function (_ref) {
19107
+ var Tabs = styled__default.ul(_templateObject2$Q || (_templateObject2$Q = _taggedTemplateLiteralLoose(["\n user-select: none;\n list-style: none;\n display: inline-flex;\n width: 100%;\n\n ", "\n\n ", ";\n\n gap: ", ";\n\n > li {\n position: relative;\n }\n"])), function (_ref) {
19108
19108
  var spacing = _ref.$spacing;
19109
19109
 
19110
19110
  var _getSpacings$split = getSpacings(spacing || {}, {
@@ -19138,148 +19138,127 @@ var Tabs = styled__default.ul(_templateObject2$Q || (_templateObject2$Q = _tagge
19138
19138
  internal = _ref3.$internal;
19139
19139
  return internal ? theme.spacings.s6 : 0;
19140
19140
  });
19141
- var Tab = styled__default.li(_templateObject5$t || (_templateObject5$t = _taggedTemplateLiteralLoose(["\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: space-between;\n\n ", "\n"])), function (_ref4) {
19141
+ var Tab = styled__default.div(_templateObject5$t || (_templateObject5$t = _taggedTemplateLiteralLoose(["\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: space-between;\n\n ", "\n\n transition-property: padding-right, background-color, color;\n transition-duration: 0.25s;\n transition-timing-function: ease-in-out;\n"])), function (_ref4) {
19142
19142
  var theme = _ref4.theme,
19143
19143
  active = _ref4.$active,
19144
19144
  internal = _ref4.$internal;
19145
- return styled.css(_templateObject6$q || (_templateObject6$q = _taggedTemplateLiteralLoose(["\n background-color: ", ";\n padding: ", ";\n gap: ", ";\n\n ", "\n\n span {\n color: ", ";\n }\n "])), theme.colors[active ? 'blue' : 'white'], theme.spacings.s3, theme.spacings.s3, internal ? styled.css(_templateObject7$q || (_templateObject7$q = _taggedTemplateLiteralLoose(["\n border-radius: 4px 4px 0 0;\n\n > span {\n ", "\n line-height: 17px;\n }\n "])), function (_ref5) {
19145
+ return styled.css(_templateObject6$q || (_templateObject6$q = _taggedTemplateLiteralLoose(["\n background-color: ", ";\n padding: ", ";\n gap: ", ";\n\n ", "\n\n color: ", ";\n "])), theme.colors[active ? 'blue' : 'white'], theme.spacings.s3, theme.spacings.s3, internal ? styled.css(_templateObject7$q || (_templateObject7$q = _taggedTemplateLiteralLoose(["\n border-radius: 4px 4px 0 0;\n\n ", "\n line-height: 17px;\n "])), function (_ref5) {
19146
19146
  var theme = _ref5.theme;
19147
19147
  return theme.useTypography('h4');
19148
- }) : styled.css(_templateObject8$n || (_templateObject8$n = _taggedTemplateLiteralLoose(["\n box-shadow: 0px 3px 6px ", ";\n\n > span {\n ", "\n line-height: 19px;\n }\n "])), theme.getColor('black', 15), function (_ref6) {
19148
+ }) : styled.css(_templateObject8$n || (_templateObject8$n = _taggedTemplateLiteralLoose(["\n box-shadow: 0px 3px 6px ", ";\n\n ", "\n line-height: 19px;\n "])), theme.getColor('black', 15), function (_ref6) {
19149
19149
  var theme = _ref6.theme;
19150
19150
  return theme.useTypography('h2');
19151
19151
  }), theme.colors[active ? 'white' : 'darkBlue']);
19152
19152
  });
19153
19153
 
19154
- var initialStatus = function initialStatus(active, length) {
19155
- var status = Array(length).fill('open');
19156
- status[active] = 'active';
19157
- return status;
19158
- };
19159
-
19160
- var Tabs$1 = function Tabs$1(props) {
19161
- var options = props.options,
19162
- activeState = props.activeState;
19163
- var active = activeState[0],
19164
- setActive = activeState[1];
19154
+ var _templateObject$18;
19155
+ var Close = styled__default.div(_templateObject$18 || (_templateObject$18 = _taggedTemplateLiteralLoose(["\n position: absolute;\n top: calc(50% - ", " / 2);\n right: ", ";\n\n + ", " {\n /** icon width + tab gap + tab right padding */\n padding-right: ", ";\n }\n\n svg > * {\n transition-property: stroke;\n transition-duration: 0.25s;\n transition-timing-function: ease-in-out;\n }\n"])), function (_ref) {
19156
+ var theme = _ref.theme;
19157
+ return theme.spacings.s3;
19158
+ }, function (_ref2) {
19159
+ var theme = _ref2.theme;
19160
+ return theme.spacings.s3;
19161
+ }, Tab, function (_ref3) {
19162
+ var theme = _ref3.theme;
19163
+ return "calc(" + theme.spacings.s3 + " + " + theme.spacings.s3 + " + " + theme.spacings.s3 + ")";
19164
+ });
19165
19165
 
19166
- var _useState = React.useState(initialStatus(active, options.length)),
19167
- status = _useState[0],
19168
- setStatus = _useState[1];
19166
+ var Close$1 = function Close$1(props) {
19167
+ var index = props.index,
19168
+ _props$active = props.active,
19169
+ active = _props$active[0],
19170
+ setActive = _props$active[1],
19171
+ _props$options = props.options,
19172
+ options = _props$options[0],
19173
+ setOptions = _props$options[1];
19169
19174
 
19170
19175
  var onClose = props.onClose || function () {};
19171
19176
 
19172
- var activate = function activate(active, length) {
19173
- setStatus(function (prev) {
19174
- if (length !== undefined && length !== prev.length) {
19175
- return initialStatus(active, length);
19176
- }
19177
-
19178
- var current = prev.findIndex(function (e) {
19179
- return e === 'active';
19180
- });
19181
-
19182
- if (current !== active && current > -1 && active > -1 && active < prev.length) {
19183
- var _status = [].concat(prev);
19177
+ var onClickClose = React.useCallback(function (event) {
19178
+ if (options.length === 1) return;
19179
+ var newOptions = [].concat(options);
19180
+ newOptions.splice(index, 1);
19181
+ onClose(index, options[index], event);
19184
19182
 
19185
- _status[current] = 'open';
19186
- _status[active] = 'active';
19187
- return [].concat(_status);
19188
- }
19189
-
19190
- return prev;
19191
- });
19192
- };
19193
-
19194
- React.useEffect(function () {
19195
- activate(active, options.length);
19196
- }, [active, options.length]);
19197
- React.useEffect(function () {
19198
- var current = status.findIndex(function (e) {
19199
- return e === 'active';
19200
- });
19201
- setActive(current);
19202
- }, [status]);
19203
-
19204
- var onClickActivate = function onClickActivate(index, event) {
19205
- var element = event.target;
19206
-
19207
- while (element) {
19208
- if (element.tagName === 'svg') return;
19209
- element = element.parentElement;
19183
+ if (index < active || active === index && active > 0) {
19184
+ setActive(active - 1);
19210
19185
  }
19211
19186
 
19212
- activate(index);
19213
- };
19214
-
19215
- var onClickClose = function onClickClose(index, tab, event) {
19216
- var getActive = function getActive(removed, prev) {
19217
- for (var i = index - 1; i > -1; i--) {
19218
- if (removed[i] !== 'closed') {
19219
- return i;
19220
- }
19221
- }
19222
-
19223
- for (var _i = index + 1; _i < removed.length; _i++) {
19224
- if (removed[_i] !== 'closed') {
19225
- return _i;
19226
- }
19227
- }
19187
+ setOptions(newOptions);
19188
+ }, [options, active, index]);
19189
+ return React__default.createElement(Close, null, React__default.createElement(Icon, {
19190
+ type: 'feather',
19191
+ icon: 'x',
19192
+ onClick: onClickClose,
19193
+ width: '14px',
19194
+ height: '14px',
19195
+ strokeWidth: '3px',
19196
+ color: active === index ? 'white' : 'darkBlue'
19197
+ }));
19198
+ };
19228
19199
 
19229
- return prev;
19230
- };
19200
+ var VoidClose = function VoidClose() {
19201
+ return React__default.createElement(React__default.Fragment, null);
19202
+ };
19231
19203
 
19232
- setStatus(function (prev) {
19233
- if (prev[index] === 'closed') return prev;
19234
- var active = prev.findIndex(function (e) {
19235
- return e === 'active';
19236
- });
19237
- var status = [].concat(prev);
19238
- status[index] = 'closed';
19204
+ var VoidComponent = function VoidComponent() {
19205
+ return React__default.createElement(React__default.Fragment, null);
19206
+ };
19239
19207
 
19240
- if (active === index) {
19241
- var _active = getActive(status, index);
19208
+ var VoidProvider = function VoidProvider(props) {
19209
+ return React__default.createElement(React__default.Fragment, {
19210
+ children: props.children
19211
+ });
19212
+ };
19242
19213
 
19243
- status[_active] = 'active';
19244
- }
19214
+ var Tabs$1 = function Tabs$1(props) {
19215
+ var _ref = Array.isArray(props.active) ? props.active : React.useState(props.active),
19216
+ active = _ref[0],
19217
+ setActive = _ref[1];
19245
19218
 
19246
- return status;
19247
- });
19248
- onClose(index, tab, event);
19249
- };
19219
+ var _ref2 = typeof props.options[1] === 'function' ? props.options : React.useState(props.options),
19220
+ options = _ref2[0],
19221
+ setOptions = _ref2[1];
19250
19222
 
19251
- var divProps = filterObject(props, ['options', 'activeState', 'internal', 'maxTabs', 'onMaxTabsExceeded', 'onClose', 'alwaysOpen', 'delimiter', 'spacing']);
19223
+ var divProps = filterObject(props, ['options', 'active', 'internal', 'maxTabs', 'onMaxTabsExceeded', 'onClose', 'alwaysOpen', 'delimiter', 'spacing']);
19224
+ var CloseComponent = props.alwaysOpen || options.length < 2 ? VoidClose : Close$1;
19252
19225
  return React__default.createElement(Container$n, Object.assign({}, divProps), React__default.createElement(Tabs, {
19253
19226
  "$internal": props.internal,
19254
19227
  "$delimiter": props.delimiter,
19255
19228
  "$spacing": props.spacing
19256
- }, options.reduce(function (elements, tab, index) {
19257
- if (status[index] === 'closed') return elements;
19258
- return [].concat(elements, [React__default.createElement(Tab, {
19259
- key: index,
19260
- "$active": status[index] === 'active',
19229
+ }, options.map(function (tab, index) {
19230
+ return React__default.createElement("li", {
19231
+ key: index
19232
+ }, React__default.createElement(CloseComponent, {
19233
+ index: index,
19234
+ active: [active, setActive],
19235
+ options: [options, setOptions]
19236
+ }), React__default.createElement(Tab, {
19237
+ "$active": index === active,
19261
19238
  "$internal": props.internal,
19262
- onClick: function onClick(event) {
19263
- return onClickActivate(index, event);
19264
- }
19265
- }, React__default.createElement("span", null, tab.label), !props.alwaysOpen && React__default.createElement(Icon, {
19266
- type: 'feather',
19267
- icon: 'x',
19268
- onClick: function onClick(e) {
19269
- return onClickClose(index, tab, e);
19239
+ onClick: function onClick() {
19240
+ return setActive(index);
19270
19241
  },
19271
- width: '14px',
19272
- height: '14px',
19273
- strokeWidth: '3px',
19274
- color: status[index] === 'active' ? 'white' : 'darkBlue'
19275
- }))]);
19276
- }, [])), props.children && React__default.createElement("div", {
19277
- children: props.children
19242
+ children: tab.label
19243
+ }));
19244
+ })), options.map(function (tab, index) {
19245
+ var _ref3 = 'component' in tab ? tab : {},
19246
+ _ref3$component = _ref3.component,
19247
+ Component = _ref3$component === void 0 ? VoidComponent : _ref3$component,
19248
+ _ref3$provider = _ref3.provider,
19249
+ Provider = _ref3$provider === void 0 ? VoidProvider : _ref3$provider;
19250
+
19251
+ var isActive = index === active;
19252
+ return React__default.createElement(Provider, {
19253
+ key: index,
19254
+ active: isActive,
19255
+ children: isActive ? React__default.createElement("div", null, React__default.createElement(Component, null)) : undefined
19256
+ });
19278
19257
  }));
19279
19258
  };
19280
19259
 
19281
- var _templateObject$18;
19282
- var Container$o = styled__default.textarea(_templateObject$18 || (_templateObject$18 = _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) {
19260
+ var _templateObject$19;
19261
+ var Container$o = styled__default.textarea(_templateObject$19 || (_templateObject$19 = _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) {
19283
19262
  return "" + props.width;
19284
19263
  }, function (props) {
19285
19264
  return "" + props.height;
@@ -19289,8 +19268,8 @@ var TextArea = function TextArea(props) {
19289
19268
  return React__default.createElement(Container$o, Object.assign({}, props));
19290
19269
  };
19291
19270
 
19292
- var _templateObject$19, _templateObject2$R, _templateObject3$K, _templateObject4$x, _templateObject5$u, _templateObject6$r;
19293
- var Container$p = styled__default.div(_templateObject$19 || (_templateObject$19 = _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) {
19271
+ var _templateObject$1a, _templateObject2$R, _templateObject3$K, _templateObject4$x, _templateObject5$u, _templateObject6$r;
19272
+ var Container$p = styled__default.div(_templateObject$1a || (_templateObject$1a = _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) {
19294
19273
  return props.size === 'large' ? '837px' : '460px';
19295
19274
  }, function (props) {
19296
19275
  return props.color === 'success' && styled.css(_templateObject2$R || (_templateObject2$R = _taggedTemplateLiteralLoose(["\n background-color: #fcfff5;\n opacity: 1;\n border-color: #a8c599;\n h4 {\n color: #1e561f;\n }\n p {\n color: #1e561fcc;\n }\n "])));
@@ -19312,8 +19291,8 @@ var Toast = function Toast(props) {
19312
19291
  })), React__default.createElement(IconContent, null, React__default.createElement("h4", null, props.title), React__default.createElement("p", null, " ", props.description)));
19313
19292
  };
19314
19293
 
19315
- var _templateObject$1a, _templateObject2$S, _templateObject3$L, _templateObject4$y, _templateObject5$v;
19316
- var Image = styled__default.img(_templateObject$1a || (_templateObject$1a = _taggedTemplateLiteralLoose(["\n max-width: 100%;\n max-height: 100%;\n"])));
19294
+ var _templateObject$1b, _templateObject2$S, _templateObject3$L, _templateObject4$y, _templateObject5$v;
19295
+ var Image = styled__default.img(_templateObject$1b || (_templateObject$1b = _taggedTemplateLiteralLoose(["\n max-width: 100%;\n max-height: 100%;\n"])));
19317
19296
  var Container$q = styled__default.div(_templateObject2$S || (_templateObject2$S = _taggedTemplateLiteralLoose(["\n position: relative;\n display: inline-flex;\n\n &,\n ", " {\n width: ", ";\n\n height: ", ";\n }\n"])), Image, function (_ref) {
19318
19297
  var width = _ref.width;
19319
19298