@dnanpm/styleguide 3.5.1 → 3.6.0

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.
@@ -1 +1 @@
1
- import 'jest-styled-components';
1
+ export {};
@@ -1 +1 @@
1
- import 'jest-styled-components';
1
+ export {};
@@ -1,10 +1,10 @@
1
- import type { ReactNode } from 'react';
1
+ import type { MouseEvent, ReactNode } from 'react';
2
2
  import React from 'react';
3
- type Type = 'default' | 'underlined';
3
+ type Type = 'box' | 'panel' | 'underlined';
4
4
  /**
5
- * @deprecated Use `default` or `underlined` types
5
+ * @deprecated Use `box`, `panel` or `underlined` types
6
6
  */
7
- type TypeDeprecated = 'gray';
7
+ type TypeDeprecated = 'default' | 'gray';
8
8
  export interface Props {
9
9
  /**
10
10
  * Unique ID for the component
@@ -15,14 +15,16 @@ export interface Props {
15
15
  */
16
16
  label: string;
17
17
  /**
18
- * Style of the tab
18
+ * Allows to change the styling of component
19
19
  *
20
- * @param {Type} default Default style
21
- * @param {Type} underlined Visually similar to anchor
20
+ * @param {Type} box Uses Box component as wrapper for content container
21
+ * @param {Type} panel Content container remains unstyled
22
+ * @param {Type} underlined Tab label is visually similar to anchor, with content container unstyled
22
23
  *
23
- * @param {TypeDeprecated} gray DEPRECATED Use `default` or `underlined` types
24
+ * @param {TypeDeprecated} default DEPRECATED Use `box` type
25
+ * @param {TypeDeprecated} gray DEPRECATED Use `box`, `panel` or `underlined` types
24
26
  *
25
- * @default 'default'
27
+ * @default 'box'
26
28
  */
27
29
  type?: Type | TypeDeprecated;
28
30
  /**
@@ -45,10 +47,19 @@ export interface Props {
45
47
  * Allows to set tab as active
46
48
  */
47
49
  isActive?: boolean;
50
+ /**
51
+ * Allows to enable updated internal state management.
52
+ * Note: In updated internal state management, this component acts as truly stateless and can be controlled with `isActive` property.
53
+ *
54
+ * @deprecated Will be removed in next major release
55
+ */
56
+ isStateless?: boolean;
48
57
  /**
49
58
  * On tab label click callback
59
+ *
60
+ * @deprecated Parameter `tab` has been deprecated. Use `e` parameter instead
50
61
  */
51
- onClick?: (tab: string) => void;
62
+ onClick?: (tab: string, e?: MouseEvent<HTMLElement>) => void;
52
63
  /**
53
64
  * Allows to pass testid string for testing purposes
54
65
  */
@@ -7,6 +7,8 @@ var React = require('react');
7
7
  var styled = require('../../themes/styled.js');
8
8
  var theme = require('../../themes/theme.js');
9
9
  var styledUtils = require('../../utils/styledUtils.js');
10
+ var Box = require('../Box/Box.js');
11
+ var Divider = require('../Divider/Divider.js');
10
12
 
11
13
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
12
14
 
@@ -18,26 +20,13 @@ const TabLabel = styled["default"].li `
18
20
  list-style: none;
19
21
  font-size: ${theme["default"].fontSize.default};
20
22
  line-height: ${theme["default"].lineHeight.default};
21
- font-weight: ${theme["default"].fontWeight.book};
23
+ font-weight: ${({ isActive }) => (isActive ? theme["default"].fontWeight.bold : theme["default"].fontWeight.book)};
22
24
  background-color: ${({ isActive }) => isActive ? theme["default"].color.background.white.default : theme["default"].color.background.sand.E01};
25
+ border-radius: ${theme["default"].radius.default} ${theme["default"].radius.default} 0 0;
23
26
  border: 1px solid ${theme["default"].color.line.L03};
24
27
  border-bottom: 0 none;
25
28
  padding: 0.625rem 1.25rem;
26
29
  cursor: pointer;
27
-
28
- && + * {
29
- border-right: 0 none;
30
- }
31
-
32
- &:first-child {
33
- border-right: 0 none;
34
- border-radius: ${theme["default"].radius.default} 0 0 0;
35
- }
36
-
37
- &&:last-child {
38
- border-right: 1px solid ${theme["default"].color.line.L03};
39
- border-radius: 0 ${theme["default"].radius.default} 0 0;
40
- }
41
30
  `;
42
31
  const TabStyle = styled["default"].li `
43
32
  display: inline-block;
@@ -49,11 +38,6 @@ const TabStyle = styled["default"].li `
49
38
  font-size: ${theme["default"].fontSize.default};
50
39
  line-height: ${theme["default"].lineHeight.default};
51
40
  font-weight: ${theme["default"].fontWeight.book};
52
- margin-right: ${styledUtils.getMultipliedSize(theme["default"].base.baseHeight, 2)};
53
-
54
- &:last-child {
55
- margin-right: 0;
56
- }
57
41
 
58
42
  ${({ isActive }) => isActive &&
59
43
  `
@@ -64,7 +48,6 @@ const TabStyle = styled["default"].li `
64
48
  ${({ $type }) => $type === 'underlined' &&
65
49
  `
66
50
  padding: ${styledUtils.getMultipliedSize(theme["default"].base.baseHeight, 1.6)} 0;
67
- margin-right: ${styledUtils.getMultipliedSize(theme["default"].base.baseHeight, 3)};
68
51
  `}
69
52
 
70
53
  ${({ isActive, $type }) => isActive &&
@@ -74,15 +57,44 @@ const TabStyle = styled["default"].li `
74
57
  background-color: transparent;
75
58
  `}
76
59
  `;
60
+ const ContentContainer = styled["default"].div `
61
+ ${({ $type }) => {
62
+ if ($type === 'box' || $type === 'default') {
63
+ return `
64
+ border-top-left-radius: 0;
65
+ `;
66
+ }
67
+ if ($type === 'panel') {
68
+ return `
69
+ border-top: 1px solid ${theme["default"].color.line.L03};
70
+ `;
71
+ }
72
+ if ($type === 'underlined' || $type === 'gray') {
73
+ return `
74
+ margin-top: ${theme["default"].grid.gutter};
75
+ `;
76
+ }
77
+ return '';
78
+ }}
79
+ `;
77
80
  /** @visibleName Tab */
78
81
  const Tab = (_a) => {
79
- var { type = 'default', 'data-testid': dataTestId } = _a, props = tslib.__rest(_a, ["type", 'data-testid']);
80
- const onClickHandler = () => {
82
+ var { type = 'box', 'data-testid': dataTestId } = _a, props = tslib.__rest(_a, ["type", 'data-testid']);
83
+ const onClickHandler = (e) => {
81
84
  if (props.onClick) {
82
- props.onClick(props.label);
85
+ props.onClick(props.label, e);
83
86
  }
84
87
  };
85
- return type === 'default' ? (React__default["default"].createElement(TabLabel, { role: "tab", "$type": type, "aria-selected": props.activeTab ? props.activeTab === props.label : props.isActive, isActive: props.activeTab ? props.activeTab === props.label : props.isActive, onClick: onClickHandler }, props.label)) : (React__default["default"].createElement(TabStyle, { role: "tab", "aria-selected": props.activeTab ? props.activeTab === props.label : props.isActive, isActive: props.activeTab ? props.activeTab === props.label : props.isActive, "$type": props.tabStyle || type, onClick: onClickHandler }, props.label));
88
+ return type === 'box' || type === 'default' || type === 'panel' ? (React__default["default"].createElement(React__default["default"].Fragment, null,
89
+ React__default["default"].createElement(TabLabel, { role: "tab", id: props.id, "$type": type, "aria-selected": props.activeTab ? props.activeTab === props.label : props.isActive, isActive: props.activeTab ? props.activeTab === props.label : props.isActive, onClick: onClickHandler }, props.label),
90
+ props.isStateless &&
91
+ (props.children && (props.activeTab === props.label || props.isActive) ? (React__default["default"].createElement(ContentContainer, { role: "tabpanel", "$type": props.tabStyle || type, as: (type === 'box' || type === 'default') && !props.tabStyle
92
+ ? Box["default"]
93
+ : undefined }, props.children)) : (React__default["default"].createElement(Divider["default"], { margin: "0" }))))) : (React__default["default"].createElement(React__default["default"].Fragment, null,
94
+ React__default["default"].createElement(TabStyle, { role: "tab", id: props.id, "$type": props.tabStyle || type, "aria-selected": props.activeTab ? props.activeTab === props.label : props.isActive, isActive: props.activeTab ? props.activeTab === props.label : props.isActive, onClick: onClickHandler }, props.label),
95
+ props.isStateless &&
96
+ props.children &&
97
+ (props.activeTab === props.label || props.isActive) && (React__default["default"].createElement(ContentContainer, { role: "tabpanel", "$type": props.tabStyle || type }, props.children))));
86
98
  };
87
99
 
88
100
  exports["default"] = Tab;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,6 +1,13 @@
1
+ import type { MouseEvent, ReactNode } from 'react';
1
2
  import React from 'react';
2
3
  import type { Props as TabProps } from '../Tab/Tab';
3
- interface Props extends Omit<TabProps, 'label' | 'activeTab' | 'onClick'> {
4
+ interface Props extends Omit<TabProps, 'label' | 'children' | 'activeTab' | 'onClick'> {
5
+ /**
6
+ * Content of the component
7
+ *
8
+ * @type Tab
9
+ */
10
+ children: ReactNode;
4
11
  /**
5
12
  * Allows to pass default tab explicitly
6
13
  *
@@ -11,10 +18,26 @@ interface Props extends Omit<TabProps, 'label' | 'activeTab' | 'onClick'> {
11
18
  * Allows to stretch tabs list to full container width
12
19
  */
13
20
  isFullWidth?: boolean;
21
+ /**
22
+ * Allows to reduce gap between tabs in `underlined` type
23
+ */
24
+ isNarrowUnderlined?: boolean;
14
25
  /**
15
26
  * On tab change callback
27
+ *
28
+ * @deprecated Use `onClick` property
16
29
  */
17
30
  onChange?: (tab: string) => void;
31
+ /**
32
+ * Allows to pass common mouse click callback to all children
33
+ */
34
+ onClick?: (e: MouseEvent<HTMLElement>) => void;
35
+ /**
36
+ * Allows to pass a custom className
37
+ *
38
+ * @deprecated Prefix 'tabs' is deprecated and will be removed in next major version
39
+ */
40
+ className?: string;
18
41
  }
19
42
  /** @visibleName Tabs */
20
43
  declare const Tabs: ({ type, "data-testid": dataTestId, ...props }: Props) => React.JSX.Element | null;
@@ -28,31 +28,76 @@ const Tablist = styled["default"].ul `
28
28
  }
29
29
  `}
30
30
 
31
- ${({ $type }) => {
32
- if ($type === 'default') {
33
- return `margin: 0;`;
31
+ ${({ $type, isNarrowUnderlined }) => {
32
+ if ($type === 'box' || $type === 'default' || $type === 'panel') {
33
+ return `
34
+ margin: 0;
35
+
36
+ & > li {
37
+ border-right: 0 none;
38
+ border-radius: 0;
39
+ }
40
+
41
+ & > li:first-of-type {
42
+ border-right: 0 none;
43
+ border-top-left-radius: ${theme["default"].radius.default};
44
+ }
45
+
46
+ & > li:last-of-type {
47
+ border-right: 1px solid ${theme["default"].color.line.L03};
48
+ border-top-right-radius: ${theme["default"].radius.default};
49
+ }
50
+ `;
34
51
  }
35
52
  if ($type === 'underlined') {
36
- return `border-bottom: 1px solid ${theme["default"].color.line.L02};`;
53
+ return `
54
+ gap: ${isNarrowUnderlined ? '1.25rem' : '2.5rem'};
55
+ border-bottom: 1px solid ${theme["default"].color.line.L02};
56
+ `;
57
+ }
58
+ if ($type === 'gray') {
59
+ return `
60
+ gap: 1.25rem;
61
+ `;
37
62
  }
38
63
  return '';
39
64
  }}
40
65
  `;
41
- const StyledBox = styled["default"](Box["default"]) `
42
- border-top-left-radius: 0;
43
- `;
44
- const TabContent = styled["default"].div `
45
- margin-top: ${theme["default"].grid.gutter};
66
+ const ContentContainer = styled["default"].div `
67
+ ${({ $type, isFullWidth }) => {
68
+ if ($type === 'box' || $type === 'default') {
69
+ return `
70
+ border-top-left-radius: 0;
71
+ ${isFullWidth ? 'border-top-right-radius: 0;' : ''}
72
+ `;
73
+ }
74
+ if ($type === 'panel') {
75
+ return `
76
+ border-top: 1px solid ${theme["default"].color.line.L03};
77
+ `;
78
+ }
79
+ if ($type === 'underlined' || $type === 'gray') {
80
+ return `
81
+ margin-top: ${theme["default"].grid.gutter};
82
+ `;
83
+ }
84
+ return '';
85
+ }}
46
86
  `;
47
87
  /** @visibleName Tabs */
48
88
  const Tabs = (_a) => {
49
- var { type = 'default', 'data-testid': dataTestId } = _a, props = tslib.__rest(_a, ["type", 'data-testid']);
89
+ var { type = 'box', 'data-testid': dataTestId } = _a, props = tslib.__rest(_a, ["type", 'data-testid']);
50
90
  const [activeTab, setActiveTab] = React.useState(props.defaultTab);
51
91
  const tabs = React.Children.map(props.children, child => React.isValidElement(child) && child.type === Tab["default"] ? child : null);
52
- const onClickTabItem = (tab) => {
92
+ const onClickTabItem = (tab, e) => {
53
93
  setActiveTab(tab);
54
- if (tab !== activeTab && props.onChange) {
55
- props.onChange(tab);
94
+ if (tab !== activeTab) {
95
+ if (props.onChange) {
96
+ props.onChange(tab);
97
+ }
98
+ if (props.onClick && e) {
99
+ props.onClick(e);
100
+ }
56
101
  }
57
102
  };
58
103
  if (!tabs) {
@@ -63,8 +108,14 @@ const Tabs = (_a) => {
63
108
  setActiveTab((outerActiveTab === null || outerActiveTab === void 0 ? void 0 : outerActiveTab.props.label) || tabs[0].props.label);
64
109
  }
65
110
  return (React__default["default"].createElement("div", { className: props.className ? `tabs ${props.className}` : 'tabs', "data-testid": dataTestId },
66
- React__default["default"].createElement(Tablist, { role: "tablist", "$type": props.tabStyle || type, isFullWidth: props.isFullWidth }, tabs.map(tab => (React__default["default"].createElement(Tab["default"], { key: tab.props.label, label: tab.props.label, type: props.tabStyle || type, isActive: tab.props.isActive ? tab.props.isActive : activeTab === tab.props.label, activeTab: tab.props.activeTab, onClick: onClickTabItem, className: tab.props.className, "data-testid": tab.props['data-testid'] })))),
67
- type === 'default' && !props.tabStyle ? (React__default["default"].createElement(StyledBox, { role: "tabpanel" }, tabs.map(tab => tab.props.label !== activeTab ? undefined : tab.props.children))) : (React__default["default"].createElement(TabContent, { role: "tabpanel" }, tabs.map(tab => tab.props.label !== activeTab ? undefined : tab.props.children)))));
111
+ React__default["default"].createElement(Tablist, { role: "tablist", "$type": props.tabStyle || type, isFullWidth: props.isFullWidth, isNarrowUnderlined: props.isNarrowUnderlined }, React.Children.map(props.children, tab => React.isValidElement(tab) &&
112
+ tab.type === Tab["default"] && (React__default["default"].createElement(Tab["default"], { id: tab.props.id, key: tab.props.label, label: tab.props.label, type: props.tabStyle || type, isActive: tab.props.isActive
113
+ ? tab.props.isActive
114
+ : activeTab === tab.props.label, activeTab: tab.props.activeTab, onClick: onClickTabItem, className: tab.props.className, "data-testid": tab.props['data-testid'] })))),
115
+ React__default["default"].createElement(ContentContainer, { role: "tabpanel", "$type": props.tabStyle || type, isFullWidth: props.isFullWidth, as: (type === 'box' || type === 'default') && !props.tabStyle ? Box["default"] : undefined }, React.Children.map(props.children, tab => React.isValidElement(tab) &&
116
+ tab.type === Tab["default"] &&
117
+ (tab.props.isActive || tab.props.label === activeTab) &&
118
+ tab.props.children))));
68
119
  };
69
120
 
70
121
  exports["default"] = Tabs;
@@ -0,0 +1 @@
1
+ export {};
@@ -1 +1 @@
1
- import 'jest-styled-components';
1
+ export {};
@@ -1 +1 @@
1
- import 'jest-styled-components';
1
+ export {};
@@ -1,10 +1,10 @@
1
- import type { ReactNode } from 'react';
1
+ import type { MouseEvent, ReactNode } from 'react';
2
2
  import React from 'react';
3
- type Type = 'default' | 'underlined';
3
+ type Type = 'box' | 'panel' | 'underlined';
4
4
  /**
5
- * @deprecated Use `default` or `underlined` types
5
+ * @deprecated Use `box`, `panel` or `underlined` types
6
6
  */
7
- type TypeDeprecated = 'gray';
7
+ type TypeDeprecated = 'default' | 'gray';
8
8
  export interface Props {
9
9
  /**
10
10
  * Unique ID for the component
@@ -15,14 +15,16 @@ export interface Props {
15
15
  */
16
16
  label: string;
17
17
  /**
18
- * Style of the tab
18
+ * Allows to change the styling of component
19
19
  *
20
- * @param {Type} default Default style
21
- * @param {Type} underlined Visually similar to anchor
20
+ * @param {Type} box Uses Box component as wrapper for content container
21
+ * @param {Type} panel Content container remains unstyled
22
+ * @param {Type} underlined Tab label is visually similar to anchor, with content container unstyled
22
23
  *
23
- * @param {TypeDeprecated} gray DEPRECATED Use `default` or `underlined` types
24
+ * @param {TypeDeprecated} default DEPRECATED Use `box` type
25
+ * @param {TypeDeprecated} gray DEPRECATED Use `box`, `panel` or `underlined` types
24
26
  *
25
- * @default 'default'
27
+ * @default 'box'
26
28
  */
27
29
  type?: Type | TypeDeprecated;
28
30
  /**
@@ -45,10 +47,19 @@ export interface Props {
45
47
  * Allows to set tab as active
46
48
  */
47
49
  isActive?: boolean;
50
+ /**
51
+ * Allows to enable updated internal state management.
52
+ * Note: In updated internal state management, this component acts as truly stateless and can be controlled with `isActive` property.
53
+ *
54
+ * @deprecated Will be removed in next major release
55
+ */
56
+ isStateless?: boolean;
48
57
  /**
49
58
  * On tab label click callback
59
+ *
60
+ * @deprecated Parameter `tab` has been deprecated. Use `e` parameter instead
50
61
  */
51
- onClick?: (tab: string) => void;
62
+ onClick?: (tab: string, e?: MouseEvent<HTMLElement>) => void;
52
63
  /**
53
64
  * Allows to pass testid string for testing purposes
54
65
  */
@@ -3,6 +3,8 @@ import React__default from 'react';
3
3
  import styled from '../../themes/styled.js';
4
4
  import theme from '../../themes/theme.js';
5
5
  import { getMultipliedSize } from '../../utils/styledUtils.js';
6
+ import Box from '../Box/Box.js';
7
+ import Divider from '../Divider/Divider.js';
6
8
 
7
9
  // TODO: Change to button HTML element as a part of https://jira.dna.fi/browse/STYLE-622
8
10
  const TabLabel = styled.li `
@@ -10,26 +12,13 @@ const TabLabel = styled.li `
10
12
  list-style: none;
11
13
  font-size: ${theme.fontSize.default};
12
14
  line-height: ${theme.lineHeight.default};
13
- font-weight: ${theme.fontWeight.book};
15
+ font-weight: ${({ isActive }) => (isActive ? theme.fontWeight.bold : theme.fontWeight.book)};
14
16
  background-color: ${({ isActive }) => isActive ? theme.color.background.white.default : theme.color.background.sand.E01};
17
+ border-radius: ${theme.radius.default} ${theme.radius.default} 0 0;
15
18
  border: 1px solid ${theme.color.line.L03};
16
19
  border-bottom: 0 none;
17
20
  padding: 0.625rem 1.25rem;
18
21
  cursor: pointer;
19
-
20
- && + * {
21
- border-right: 0 none;
22
- }
23
-
24
- &:first-child {
25
- border-right: 0 none;
26
- border-radius: ${theme.radius.default} 0 0 0;
27
- }
28
-
29
- &&:last-child {
30
- border-right: 1px solid ${theme.color.line.L03};
31
- border-radius: 0 ${theme.radius.default} 0 0;
32
- }
33
22
  `;
34
23
  const TabStyle = styled.li `
35
24
  display: inline-block;
@@ -41,11 +30,6 @@ const TabStyle = styled.li `
41
30
  font-size: ${theme.fontSize.default};
42
31
  line-height: ${theme.lineHeight.default};
43
32
  font-weight: ${theme.fontWeight.book};
44
- margin-right: ${getMultipliedSize(theme.base.baseHeight, 2)};
45
-
46
- &:last-child {
47
- margin-right: 0;
48
- }
49
33
 
50
34
  ${({ isActive }) => isActive &&
51
35
  `
@@ -56,7 +40,6 @@ const TabStyle = styled.li `
56
40
  ${({ $type }) => $type === 'underlined' &&
57
41
  `
58
42
  padding: ${getMultipliedSize(theme.base.baseHeight, 1.6)} 0;
59
- margin-right: ${getMultipliedSize(theme.base.baseHeight, 3)};
60
43
  `}
61
44
 
62
45
  ${({ isActive, $type }) => isActive &&
@@ -66,15 +49,44 @@ const TabStyle = styled.li `
66
49
  background-color: transparent;
67
50
  `}
68
51
  `;
52
+ const ContentContainer = styled.div `
53
+ ${({ $type }) => {
54
+ if ($type === 'box' || $type === 'default') {
55
+ return `
56
+ border-top-left-radius: 0;
57
+ `;
58
+ }
59
+ if ($type === 'panel') {
60
+ return `
61
+ border-top: 1px solid ${theme.color.line.L03};
62
+ `;
63
+ }
64
+ if ($type === 'underlined' || $type === 'gray') {
65
+ return `
66
+ margin-top: ${theme.grid.gutter};
67
+ `;
68
+ }
69
+ return '';
70
+ }}
71
+ `;
69
72
  /** @visibleName Tab */
70
73
  const Tab = (_a) => {
71
- var { type = 'default', 'data-testid': dataTestId } = _a, props = __rest(_a, ["type", 'data-testid']);
72
- const onClickHandler = () => {
74
+ var { type = 'box', 'data-testid': dataTestId } = _a, props = __rest(_a, ["type", 'data-testid']);
75
+ const onClickHandler = (e) => {
73
76
  if (props.onClick) {
74
- props.onClick(props.label);
77
+ props.onClick(props.label, e);
75
78
  }
76
79
  };
77
- return type === 'default' ? (React__default.createElement(TabLabel, { role: "tab", "$type": type, "aria-selected": props.activeTab ? props.activeTab === props.label : props.isActive, isActive: props.activeTab ? props.activeTab === props.label : props.isActive, onClick: onClickHandler }, props.label)) : (React__default.createElement(TabStyle, { role: "tab", "aria-selected": props.activeTab ? props.activeTab === props.label : props.isActive, isActive: props.activeTab ? props.activeTab === props.label : props.isActive, "$type": props.tabStyle || type, onClick: onClickHandler }, props.label));
80
+ return type === 'box' || type === 'default' || type === 'panel' ? (React__default.createElement(React__default.Fragment, null,
81
+ React__default.createElement(TabLabel, { role: "tab", id: props.id, "$type": type, "aria-selected": props.activeTab ? props.activeTab === props.label : props.isActive, isActive: props.activeTab ? props.activeTab === props.label : props.isActive, onClick: onClickHandler }, props.label),
82
+ props.isStateless &&
83
+ (props.children && (props.activeTab === props.label || props.isActive) ? (React__default.createElement(ContentContainer, { role: "tabpanel", "$type": props.tabStyle || type, as: (type === 'box' || type === 'default') && !props.tabStyle
84
+ ? Box
85
+ : undefined }, props.children)) : (React__default.createElement(Divider, { margin: "0" }))))) : (React__default.createElement(React__default.Fragment, null,
86
+ React__default.createElement(TabStyle, { role: "tab", id: props.id, "$type": props.tabStyle || type, "aria-selected": props.activeTab ? props.activeTab === props.label : props.isActive, isActive: props.activeTab ? props.activeTab === props.label : props.isActive, onClick: onClickHandler }, props.label),
87
+ props.isStateless &&
88
+ props.children &&
89
+ (props.activeTab === props.label || props.isActive) && (React__default.createElement(ContentContainer, { role: "tabpanel", "$type": props.tabStyle || type }, props.children))));
78
90
  };
79
91
 
80
92
  export { Tab as default };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,6 +1,13 @@
1
+ import type { MouseEvent, ReactNode } from 'react';
1
2
  import React from 'react';
2
3
  import type { Props as TabProps } from '../Tab/Tab';
3
- interface Props extends Omit<TabProps, 'label' | 'activeTab' | 'onClick'> {
4
+ interface Props extends Omit<TabProps, 'label' | 'children' | 'activeTab' | 'onClick'> {
5
+ /**
6
+ * Content of the component
7
+ *
8
+ * @type Tab
9
+ */
10
+ children: ReactNode;
4
11
  /**
5
12
  * Allows to pass default tab explicitly
6
13
  *
@@ -11,10 +18,26 @@ interface Props extends Omit<TabProps, 'label' | 'activeTab' | 'onClick'> {
11
18
  * Allows to stretch tabs list to full container width
12
19
  */
13
20
  isFullWidth?: boolean;
21
+ /**
22
+ * Allows to reduce gap between tabs in `underlined` type
23
+ */
24
+ isNarrowUnderlined?: boolean;
14
25
  /**
15
26
  * On tab change callback
27
+ *
28
+ * @deprecated Use `onClick` property
16
29
  */
17
30
  onChange?: (tab: string) => void;
31
+ /**
32
+ * Allows to pass common mouse click callback to all children
33
+ */
34
+ onClick?: (e: MouseEvent<HTMLElement>) => void;
35
+ /**
36
+ * Allows to pass a custom className
37
+ *
38
+ * @deprecated Prefix 'tabs' is deprecated and will be removed in next major version
39
+ */
40
+ className?: string;
18
41
  }
19
42
  /** @visibleName Tabs */
20
43
  declare const Tabs: ({ type, "data-testid": dataTestId, ...props }: Props) => React.JSX.Element | null;
@@ -20,31 +20,76 @@ const Tablist = styled.ul `
20
20
  }
21
21
  `}
22
22
 
23
- ${({ $type }) => {
24
- if ($type === 'default') {
25
- return `margin: 0;`;
23
+ ${({ $type, isNarrowUnderlined }) => {
24
+ if ($type === 'box' || $type === 'default' || $type === 'panel') {
25
+ return `
26
+ margin: 0;
27
+
28
+ & > li {
29
+ border-right: 0 none;
30
+ border-radius: 0;
31
+ }
32
+
33
+ & > li:first-of-type {
34
+ border-right: 0 none;
35
+ border-top-left-radius: ${theme.radius.default};
36
+ }
37
+
38
+ & > li:last-of-type {
39
+ border-right: 1px solid ${theme.color.line.L03};
40
+ border-top-right-radius: ${theme.radius.default};
41
+ }
42
+ `;
26
43
  }
27
44
  if ($type === 'underlined') {
28
- return `border-bottom: 1px solid ${theme.color.line.L02};`;
45
+ return `
46
+ gap: ${isNarrowUnderlined ? '1.25rem' : '2.5rem'};
47
+ border-bottom: 1px solid ${theme.color.line.L02};
48
+ `;
49
+ }
50
+ if ($type === 'gray') {
51
+ return `
52
+ gap: 1.25rem;
53
+ `;
29
54
  }
30
55
  return '';
31
56
  }}
32
57
  `;
33
- const StyledBox = styled(Box) `
34
- border-top-left-radius: 0;
35
- `;
36
- const TabContent = styled.div `
37
- margin-top: ${theme.grid.gutter};
58
+ const ContentContainer = styled.div `
59
+ ${({ $type, isFullWidth }) => {
60
+ if ($type === 'box' || $type === 'default') {
61
+ return `
62
+ border-top-left-radius: 0;
63
+ ${isFullWidth ? 'border-top-right-radius: 0;' : ''}
64
+ `;
65
+ }
66
+ if ($type === 'panel') {
67
+ return `
68
+ border-top: 1px solid ${theme.color.line.L03};
69
+ `;
70
+ }
71
+ if ($type === 'underlined' || $type === 'gray') {
72
+ return `
73
+ margin-top: ${theme.grid.gutter};
74
+ `;
75
+ }
76
+ return '';
77
+ }}
38
78
  `;
39
79
  /** @visibleName Tabs */
40
80
  const Tabs = (_a) => {
41
- var { type = 'default', 'data-testid': dataTestId } = _a, props = __rest(_a, ["type", 'data-testid']);
81
+ var { type = 'box', 'data-testid': dataTestId } = _a, props = __rest(_a, ["type", 'data-testid']);
42
82
  const [activeTab, setActiveTab] = useState(props.defaultTab);
43
83
  const tabs = Children.map(props.children, child => isValidElement(child) && child.type === Tab ? child : null);
44
- const onClickTabItem = (tab) => {
84
+ const onClickTabItem = (tab, e) => {
45
85
  setActiveTab(tab);
46
- if (tab !== activeTab && props.onChange) {
47
- props.onChange(tab);
86
+ if (tab !== activeTab) {
87
+ if (props.onChange) {
88
+ props.onChange(tab);
89
+ }
90
+ if (props.onClick && e) {
91
+ props.onClick(e);
92
+ }
48
93
  }
49
94
  };
50
95
  if (!tabs) {
@@ -55,8 +100,14 @@ const Tabs = (_a) => {
55
100
  setActiveTab((outerActiveTab === null || outerActiveTab === void 0 ? void 0 : outerActiveTab.props.label) || tabs[0].props.label);
56
101
  }
57
102
  return (React__default.createElement("div", { className: props.className ? `tabs ${props.className}` : 'tabs', "data-testid": dataTestId },
58
- React__default.createElement(Tablist, { role: "tablist", "$type": props.tabStyle || type, isFullWidth: props.isFullWidth }, tabs.map(tab => (React__default.createElement(Tab, { key: tab.props.label, label: tab.props.label, type: props.tabStyle || type, isActive: tab.props.isActive ? tab.props.isActive : activeTab === tab.props.label, activeTab: tab.props.activeTab, onClick: onClickTabItem, className: tab.props.className, "data-testid": tab.props['data-testid'] })))),
59
- type === 'default' && !props.tabStyle ? (React__default.createElement(StyledBox, { role: "tabpanel" }, tabs.map(tab => tab.props.label !== activeTab ? undefined : tab.props.children))) : (React__default.createElement(TabContent, { role: "tabpanel" }, tabs.map(tab => tab.props.label !== activeTab ? undefined : tab.props.children)))));
103
+ React__default.createElement(Tablist, { role: "tablist", "$type": props.tabStyle || type, isFullWidth: props.isFullWidth, isNarrowUnderlined: props.isNarrowUnderlined }, Children.map(props.children, tab => isValidElement(tab) &&
104
+ tab.type === Tab && (React__default.createElement(Tab, { id: tab.props.id, key: tab.props.label, label: tab.props.label, type: props.tabStyle || type, isActive: tab.props.isActive
105
+ ? tab.props.isActive
106
+ : activeTab === tab.props.label, activeTab: tab.props.activeTab, onClick: onClickTabItem, className: tab.props.className, "data-testid": tab.props['data-testid'] })))),
107
+ React__default.createElement(ContentContainer, { role: "tabpanel", "$type": props.tabStyle || type, isFullWidth: props.isFullWidth, as: (type === 'box' || type === 'default') && !props.tabStyle ? Box : undefined }, Children.map(props.children, tab => isValidElement(tab) &&
108
+ tab.type === Tab &&
109
+ (tab.props.isActive || tab.props.label === activeTab) &&
110
+ tab.props.children))));
60
111
  };
61
112
 
62
113
  export { Tabs as default };
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dnanpm/styleguide",
3
3
  "sideEffects": false,
4
- "version": "3.5.1",
4
+ "version": "3.6.0",
5
5
  "main": "build/cjs/index.js",
6
6
  "module": "build/es/index.js",
7
7
  "jsnext:main": "build/es/index.js",