@mw-kit/mw-ui 1.7.76 → 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
@@ -656,14 +656,18 @@ var AbsoluteContainer = React__default.forwardRef(function (props, fowardedRef)
656
656
  setRef = _useState[1];
657
657
 
658
658
  var getPosition = React.useCallback(function () {
659
+ if (props.position) return props.position;
659
660
  if (!ref) return null;
660
661
 
661
- var _ref = boundRef ? {
662
- offsetTop: boundRef.offsetTop,
663
- offsetLeft: boundRef.offsetLeft,
664
- width: boundRef.offsetWidth,
665
- height: boundRef.offsetHeight
666
- } : {
662
+ var _ref = boundRef ? function () {
663
+ var rect = boundRef.getBoundingClientRect();
664
+ return {
665
+ offsetTop: rect.top,
666
+ offsetLeft: rect.left,
667
+ width: boundRef.offsetWidth,
668
+ height: boundRef.offsetHeight
669
+ };
670
+ }() : {
667
671
  offsetTop: 0,
668
672
  offsetLeft: 0,
669
673
  width: window.innerWidth,
@@ -694,9 +698,9 @@ var AbsoluteContainer = React__default.forwardRef(function (props, fowardedRef)
694
698
 
695
699
  return _newPosition;
696
700
  }
697
- }, [ref, boundRef]);
701
+ }, [ref, boundRef, props.position]);
698
702
 
699
- var _useState2 = React.useState(props.position || getPosition),
703
+ var _useState2 = React.useState(getPosition),
700
704
  position = _useState2[0],
701
705
  setPosition = _useState2[1];
702
706
 
@@ -704,7 +708,6 @@ var AbsoluteContainer = React__default.forwardRef(function (props, fowardedRef)
704
708
  return ref;
705
709
  });
706
710
  React.useEffect(function () {
707
- if (props.position) return;
708
711
  setPosition(getPosition);
709
712
  }, [getPosition]);
710
713
  var htmlProps = filterObject(props, ['center', 'position', 'children', 'content']);
@@ -19101,7 +19104,7 @@ var delimiters = {
19101
19104
  blue: ['blue'],
19102
19105
  grey: ['warningGray']
19103
19106
  };
19104
- 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) {
19105
19108
  var spacing = _ref.$spacing;
19106
19109
 
19107
19110
  var _getSpacings$split = getSpacings(spacing || {}, {
@@ -19135,148 +19138,127 @@ var Tabs = styled__default.ul(_templateObject2$Q || (_templateObject2$Q = _tagge
19135
19138
  internal = _ref3.$internal;
19136
19139
  return internal ? theme.spacings.s6 : 0;
19137
19140
  });
19138
- 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) {
19139
19142
  var theme = _ref4.theme,
19140
19143
  active = _ref4.$active,
19141
19144
  internal = _ref4.$internal;
19142
- 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) {
19143
19146
  var theme = _ref5.theme;
19144
19147
  return theme.useTypography('h4');
19145
- }) : 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) {
19146
19149
  var theme = _ref6.theme;
19147
19150
  return theme.useTypography('h2');
19148
19151
  }), theme.colors[active ? 'white' : 'darkBlue']);
19149
19152
  });
19150
19153
 
19151
- var initialStatus = function initialStatus(active, length) {
19152
- var status = Array(length).fill('open');
19153
- status[active] = 'active';
19154
- return status;
19155
- };
19156
-
19157
- var Tabs$1 = function Tabs$1(props) {
19158
- var options = props.options,
19159
- activeState = props.activeState;
19160
- var active = activeState[0],
19161
- 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
+ });
19162
19165
 
19163
- var _useState = React.useState(initialStatus(active, options.length)),
19164
- status = _useState[0],
19165
- 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];
19166
19174
 
19167
19175
  var onClose = props.onClose || function () {};
19168
19176
 
19169
- var activate = function activate(active, length) {
19170
- setStatus(function (prev) {
19171
- if (length !== undefined && length !== prev.length) {
19172
- return initialStatus(active, length);
19173
- }
19174
-
19175
- var current = prev.findIndex(function (e) {
19176
- return e === 'active';
19177
- });
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);
19178
19182
 
19179
- if (current !== active && current > -1 && active > -1 && active < prev.length) {
19180
- var _status = [].concat(prev);
19181
-
19182
- _status[current] = 'open';
19183
- _status[active] = 'active';
19184
- return [].concat(_status);
19185
- }
19186
-
19187
- return prev;
19188
- });
19189
- };
19190
-
19191
- React.useEffect(function () {
19192
- activate(active, options.length);
19193
- }, [active, options.length]);
19194
- React.useEffect(function () {
19195
- var current = status.findIndex(function (e) {
19196
- return e === 'active';
19197
- });
19198
- setActive(current);
19199
- }, [status]);
19200
-
19201
- var onClickActivate = function onClickActivate(index, event) {
19202
- var element = event.target;
19203
-
19204
- while (element) {
19205
- if (element.tagName === 'svg') return;
19206
- element = element.parentElement;
19183
+ if (index < active || active === index && active > 0) {
19184
+ setActive(active - 1);
19207
19185
  }
19208
19186
 
19209
- activate(index);
19210
- };
19211
-
19212
- var onClickClose = function onClickClose(index, tab, event) {
19213
- var getActive = function getActive(removed, prev) {
19214
- for (var i = index - 1; i > -1; i--) {
19215
- if (removed[i] !== 'closed') {
19216
- return i;
19217
- }
19218
- }
19219
-
19220
- for (var _i = index + 1; _i < removed.length; _i++) {
19221
- if (removed[_i] !== 'closed') {
19222
- return _i;
19223
- }
19224
- }
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
+ };
19225
19199
 
19226
- return prev;
19227
- };
19200
+ var VoidClose = function VoidClose() {
19201
+ return React__default.createElement(React__default.Fragment, null);
19202
+ };
19228
19203
 
19229
- setStatus(function (prev) {
19230
- if (prev[index] === 'closed') return prev;
19231
- var active = prev.findIndex(function (e) {
19232
- return e === 'active';
19233
- });
19234
- var status = [].concat(prev);
19235
- status[index] = 'closed';
19204
+ var VoidComponent = function VoidComponent() {
19205
+ return React__default.createElement(React__default.Fragment, null);
19206
+ };
19236
19207
 
19237
- if (active === index) {
19238
- 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
+ };
19239
19213
 
19240
- status[_active] = 'active';
19241
- }
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];
19242
19218
 
19243
- return status;
19244
- });
19245
- onClose(index, tab, event);
19246
- };
19219
+ var _ref2 = typeof props.options[1] === 'function' ? props.options : React.useState(props.options),
19220
+ options = _ref2[0],
19221
+ setOptions = _ref2[1];
19247
19222
 
19248
- 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;
19249
19225
  return React__default.createElement(Container$n, Object.assign({}, divProps), React__default.createElement(Tabs, {
19250
19226
  "$internal": props.internal,
19251
19227
  "$delimiter": props.delimiter,
19252
19228
  "$spacing": props.spacing
19253
- }, options.reduce(function (elements, tab, index) {
19254
- if (status[index] === 'closed') return elements;
19255
- return [].concat(elements, [React__default.createElement(Tab, {
19256
- key: index,
19257
- "$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,
19258
19238
  "$internal": props.internal,
19259
- onClick: function onClick(event) {
19260
- return onClickActivate(index, event);
19261
- }
19262
- }, React__default.createElement("span", null, tab.label), !props.alwaysOpen && React__default.createElement(Icon, {
19263
- type: 'feather',
19264
- icon: 'x',
19265
- onClick: function onClick(e) {
19266
- return onClickClose(index, tab, e);
19239
+ onClick: function onClick() {
19240
+ return setActive(index);
19267
19241
  },
19268
- width: '14px',
19269
- height: '14px',
19270
- strokeWidth: '3px',
19271
- color: status[index] === 'active' ? 'white' : 'darkBlue'
19272
- }))]);
19273
- }, [])), props.children && React__default.createElement("div", {
19274
- 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
+ });
19275
19257
  }));
19276
19258
  };
19277
19259
 
19278
- var _templateObject$18;
19279
- 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) {
19280
19262
  return "" + props.width;
19281
19263
  }, function (props) {
19282
19264
  return "" + props.height;
@@ -19286,8 +19268,8 @@ var TextArea = function TextArea(props) {
19286
19268
  return React__default.createElement(Container$o, Object.assign({}, props));
19287
19269
  };
19288
19270
 
19289
- var _templateObject$19, _templateObject2$R, _templateObject3$K, _templateObject4$x, _templateObject5$u, _templateObject6$r;
19290
- 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) {
19291
19273
  return props.size === 'large' ? '837px' : '460px';
19292
19274
  }, function (props) {
19293
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 "])));
@@ -19309,8 +19291,8 @@ var Toast = function Toast(props) {
19309
19291
  })), React__default.createElement(IconContent, null, React__default.createElement("h4", null, props.title), React__default.createElement("p", null, " ", props.description)));
19310
19292
  };
19311
19293
 
19312
- var _templateObject$1a, _templateObject2$S, _templateObject3$L, _templateObject4$y, _templateObject5$v;
19313
- 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"])));
19314
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) {
19315
19297
  var width = _ref.width;
19316
19298