@zendeskgarden/react-tabs 9.0.0-next.6 → 9.0.0-next.8
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/esm/elements/Tab.js +48 -0
- package/dist/esm/elements/TabList.js +28 -0
- package/dist/esm/elements/TabPanel.js +40 -0
- package/dist/esm/elements/Tabs.js +68 -0
- package/dist/esm/index.js +10 -0
- package/dist/esm/styled/StyledTab.js +49 -0
- package/dist/esm/styled/StyledTabList.js +22 -0
- package/dist/esm/styled/StyledTabPanel.js +22 -0
- package/dist/esm/styled/StyledTabs.js +31 -0
- package/dist/esm/utils/toTabs.js +26 -0
- package/dist/esm/utils/useTabsContext.js +14 -0
- package/dist/index.cjs.js +19 -35
- package/package.json +5 -5
- package/dist/index.esm.js +0 -253
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Zendesk, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
+
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
*/
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import PropTypes from 'prop-types';
|
|
9
|
+
import { mergeRefs } from 'react-merge-refs';
|
|
10
|
+
import { StyledTab } from '../styled/StyledTab.js';
|
|
11
|
+
import '../styled/StyledTabList.js';
|
|
12
|
+
import '../styled/StyledTabPanel.js';
|
|
13
|
+
import '../styled/StyledTabs.js';
|
|
14
|
+
import { useTabsContext } from '../utils/useTabsContext.js';
|
|
15
|
+
|
|
16
|
+
const Tab = React.forwardRef((_ref, ref) => {
|
|
17
|
+
let {
|
|
18
|
+
disabled,
|
|
19
|
+
item,
|
|
20
|
+
...otherProps
|
|
21
|
+
} = _ref;
|
|
22
|
+
const tabsPropGetters = useTabsContext();
|
|
23
|
+
if (disabled || !tabsPropGetters) {
|
|
24
|
+
return React.createElement(StyledTab, Object.assign({
|
|
25
|
+
role: "tab",
|
|
26
|
+
"aria-disabled": disabled,
|
|
27
|
+
ref: ref
|
|
28
|
+
}, otherProps));
|
|
29
|
+
}
|
|
30
|
+
const {
|
|
31
|
+
ref: tabRef,
|
|
32
|
+
...tabProps
|
|
33
|
+
} = tabsPropGetters.getTabProps({
|
|
34
|
+
value: item
|
|
35
|
+
});
|
|
36
|
+
return React.createElement(StyledTab, Object.assign({
|
|
37
|
+
isSelected: item === tabsPropGetters.selectedValue
|
|
38
|
+
}, tabProps, otherProps, {
|
|
39
|
+
ref: mergeRefs([tabRef, ref])
|
|
40
|
+
}));
|
|
41
|
+
});
|
|
42
|
+
Tab.displayName = 'Tab';
|
|
43
|
+
Tab.propTypes = {
|
|
44
|
+
disabled: PropTypes.bool,
|
|
45
|
+
item: PropTypes.any
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export { Tab };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Zendesk, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
+
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
*/
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import '../styled/StyledTab.js';
|
|
9
|
+
import { StyledTabList } from '../styled/StyledTabList.js';
|
|
10
|
+
import '../styled/StyledTabPanel.js';
|
|
11
|
+
import '../styled/StyledTabs.js';
|
|
12
|
+
import { useTabsContext } from '../utils/useTabsContext.js';
|
|
13
|
+
|
|
14
|
+
const TabList = React.forwardRef((props, ref) => {
|
|
15
|
+
const tabsPropGetters = useTabsContext();
|
|
16
|
+
if (!tabsPropGetters) {
|
|
17
|
+
return React.createElement(StyledTabList, Object.assign({
|
|
18
|
+
ref: ref
|
|
19
|
+
}, props));
|
|
20
|
+
}
|
|
21
|
+
const tabListProps = tabsPropGetters.getTabListProps();
|
|
22
|
+
return React.createElement(StyledTabList, Object.assign({}, tabListProps, props, {
|
|
23
|
+
ref: ref
|
|
24
|
+
}));
|
|
25
|
+
});
|
|
26
|
+
TabList.displayName = 'TabList';
|
|
27
|
+
|
|
28
|
+
export { TabList };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Zendesk, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
+
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
*/
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import PropTypes from 'prop-types';
|
|
9
|
+
import '../styled/StyledTab.js';
|
|
10
|
+
import '../styled/StyledTabList.js';
|
|
11
|
+
import { StyledTabPanel } from '../styled/StyledTabPanel.js';
|
|
12
|
+
import '../styled/StyledTabs.js';
|
|
13
|
+
import { useTabsContext } from '../utils/useTabsContext.js';
|
|
14
|
+
|
|
15
|
+
const TabPanel = React.forwardRef((_ref, ref) => {
|
|
16
|
+
let {
|
|
17
|
+
item,
|
|
18
|
+
...otherProps
|
|
19
|
+
} = _ref;
|
|
20
|
+
const tabsPropGetters = useTabsContext();
|
|
21
|
+
if (!tabsPropGetters) {
|
|
22
|
+
return React.createElement(StyledTabPanel, Object.assign({
|
|
23
|
+
ref: ref
|
|
24
|
+
}, otherProps));
|
|
25
|
+
}
|
|
26
|
+
const tabPanelProps = tabsPropGetters.getTabPanelProps({
|
|
27
|
+
value: item
|
|
28
|
+
});
|
|
29
|
+
return React.createElement(StyledTabPanel, Object.assign({
|
|
30
|
+
"aria-hidden": tabsPropGetters.selectedValue !== item
|
|
31
|
+
}, tabPanelProps, otherProps, {
|
|
32
|
+
ref: ref
|
|
33
|
+
}));
|
|
34
|
+
});
|
|
35
|
+
TabPanel.displayName = 'TabPanel';
|
|
36
|
+
TabPanel.propTypes = {
|
|
37
|
+
item: PropTypes.any
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export { TabPanel };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Zendesk, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
+
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
*/
|
|
7
|
+
import React, { forwardRef, useContext, useState, useMemo } from 'react';
|
|
8
|
+
import PropTypes from 'prop-types';
|
|
9
|
+
import { ThemeContext } from 'styled-components';
|
|
10
|
+
import { DEFAULT_THEME } from '@zendeskgarden/react-theming';
|
|
11
|
+
import { useTabs } from '@zendeskgarden/container-tabs';
|
|
12
|
+
import { getControlledValue } from '@zendeskgarden/container-utilities';
|
|
13
|
+
import { toTabs } from '../utils/toTabs.js';
|
|
14
|
+
import { TabsContext } from '../utils/useTabsContext.js';
|
|
15
|
+
import { StyledTabs } from '../styled/StyledTabs.js';
|
|
16
|
+
import { Tab } from './Tab.js';
|
|
17
|
+
import { TabList } from './TabList.js';
|
|
18
|
+
import { TabPanel } from './TabPanel.js';
|
|
19
|
+
|
|
20
|
+
const TabsComponent = forwardRef((_ref, ref) => {
|
|
21
|
+
let {
|
|
22
|
+
isVertical,
|
|
23
|
+
children,
|
|
24
|
+
onChange,
|
|
25
|
+
selectedItem: controlledSelectedItem,
|
|
26
|
+
...otherProps
|
|
27
|
+
} = _ref;
|
|
28
|
+
const theme = useContext(ThemeContext) || DEFAULT_THEME;
|
|
29
|
+
const [internalSelectedItem, setInternalSelectedItem] = useState();
|
|
30
|
+
const selectedItem = getControlledValue(controlledSelectedItem, internalSelectedItem);
|
|
31
|
+
const tabs = useMemo(() => toTabs(children), [children]);
|
|
32
|
+
const tabsContextValue = useTabs({
|
|
33
|
+
tabs,
|
|
34
|
+
rtl: theme.rtl,
|
|
35
|
+
orientation: isVertical ? 'vertical' : 'horizontal',
|
|
36
|
+
selectedValue: selectedItem,
|
|
37
|
+
defaultSelectedValue: tabs.find(tab => !tab.disabled)?.value,
|
|
38
|
+
onSelect: item => {
|
|
39
|
+
if (onChange) {
|
|
40
|
+
onChange(item);
|
|
41
|
+
} else {
|
|
42
|
+
setInternalSelectedItem(item);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
return React.createElement(TabsContext.Provider, {
|
|
47
|
+
value: tabsContextValue
|
|
48
|
+
}, React.createElement(StyledTabs, Object.assign({
|
|
49
|
+
isVertical: isVertical
|
|
50
|
+
}, otherProps, {
|
|
51
|
+
ref: ref
|
|
52
|
+
}), children));
|
|
53
|
+
});
|
|
54
|
+
TabsComponent.propTypes = {
|
|
55
|
+
isVertical: PropTypes.bool,
|
|
56
|
+
selectedItem: PropTypes.any,
|
|
57
|
+
onChange: PropTypes.func
|
|
58
|
+
};
|
|
59
|
+
TabsComponent.defaultProps = {
|
|
60
|
+
isVertical: false
|
|
61
|
+
};
|
|
62
|
+
TabsComponent.displayName = 'Tabs';
|
|
63
|
+
const Tabs = TabsComponent;
|
|
64
|
+
Tabs.Tab = Tab;
|
|
65
|
+
Tabs.TabList = TabList;
|
|
66
|
+
Tabs.TabPanel = TabPanel;
|
|
67
|
+
|
|
68
|
+
export { Tabs, TabsComponent };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Zendesk, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
+
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
*/
|
|
7
|
+
export { Tab } from './elements/Tab.js';
|
|
8
|
+
export { TabList } from './elements/TabList.js';
|
|
9
|
+
export { TabPanel } from './elements/TabPanel.js';
|
|
10
|
+
export { Tabs } from './elements/Tabs.js';
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Zendesk, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
+
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
*/
|
|
7
|
+
import styled, { css } from 'styled-components';
|
|
8
|
+
import { retrieveComponentStyles, DEFAULT_THEME, getColorV8, focusStyles } from '@zendeskgarden/react-theming';
|
|
9
|
+
import { stripUnit } from 'polished';
|
|
10
|
+
|
|
11
|
+
const COMPONENT_ID = 'tabs.tab';
|
|
12
|
+
const colorStyles = _ref => {
|
|
13
|
+
let {
|
|
14
|
+
theme,
|
|
15
|
+
isSelected
|
|
16
|
+
} = _ref;
|
|
17
|
+
const selectedColor = getColorV8('primaryHue', 600, theme);
|
|
18
|
+
return css(["border-color:", ";color:", ";&:hover{color:", ";}", " &:active{border-color:currentcolor;color:", ";}&[aria-disabled='true']{border-color:transparent;color:", ";}"], isSelected && 'currentcolor !important', isSelected ? selectedColor : 'inherit', selectedColor, focusStyles({
|
|
19
|
+
theme,
|
|
20
|
+
inset: true,
|
|
21
|
+
spacerWidth: null,
|
|
22
|
+
shadowWidth: 'sm',
|
|
23
|
+
selector: '&:focus-visible::before',
|
|
24
|
+
styles: {
|
|
25
|
+
color: selectedColor
|
|
26
|
+
}
|
|
27
|
+
}), selectedColor, props => getColorV8('neutralHue', 400, props.theme));
|
|
28
|
+
};
|
|
29
|
+
const sizeStyles = _ref2 => {
|
|
30
|
+
let {
|
|
31
|
+
theme
|
|
32
|
+
} = _ref2;
|
|
33
|
+
const paddingTop = theme.space.base * 2.5;
|
|
34
|
+
const paddingHorizontal = theme.space.base * 7;
|
|
35
|
+
const paddingBottom = paddingTop - stripUnit(theme.borderWidths.md) - stripUnit(theme.borderWidths.sm);
|
|
36
|
+
return css(["padding:", "px ", "px ", "px;"], paddingTop, paddingHorizontal, paddingBottom);
|
|
37
|
+
};
|
|
38
|
+
const StyledTab = styled.div.attrs({
|
|
39
|
+
'data-garden-id': COMPONENT_ID,
|
|
40
|
+
'data-garden-version': '9.0.0-next.8'
|
|
41
|
+
}).withConfig({
|
|
42
|
+
displayName: "StyledTab",
|
|
43
|
+
componentId: "sc-x2pbow-0"
|
|
44
|
+
})(["display:inline-block;position:relative;transition:color 0.25s ease-in-out;border-bottom:", " transparent;border-width:", ";cursor:pointer;overflow:hidden;vertical-align:top;user-select:none;text-align:center;text-decoration:none;text-overflow:ellipsis;", " ", " &:focus{text-decoration:none;}&::before{transition:box-shadow 0.1s ease-in-out;content:'';}&:focus-visible::before{position:absolute;top:", "px;right:", "px;left:", "px;border-radius:", ";height:", "px;pointer-events:none;}&:active::before{box-shadow:none;}&[aria-disabled='true']{cursor:default;}", ";"], props => props.theme.borderStyles.solid, props => props.theme.borderWidths.md, sizeStyles, colorStyles, props => props.theme.space.base * 2.5, props => props.theme.space.base * 6, props => props.theme.space.base * 6, props => props.theme.borderRadii.md, props => props.theme.space.base * 5, props => retrieveComponentStyles(COMPONENT_ID, props));
|
|
45
|
+
StyledTab.defaultProps = {
|
|
46
|
+
theme: DEFAULT_THEME
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export { StyledTab };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Zendesk, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
+
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
*/
|
|
7
|
+
import styled from 'styled-components';
|
|
8
|
+
import { getColorV8, retrieveComponentStyles, DEFAULT_THEME } from '@zendeskgarden/react-theming';
|
|
9
|
+
|
|
10
|
+
const COMPONENT_ID = 'tabs.tablist';
|
|
11
|
+
const StyledTabList = styled.div.attrs({
|
|
12
|
+
'data-garden-id': COMPONENT_ID,
|
|
13
|
+
'data-garden-version': '9.0.0-next.8'
|
|
14
|
+
}).withConfig({
|
|
15
|
+
displayName: "StyledTabList",
|
|
16
|
+
componentId: "sc-wa5aaj-0"
|
|
17
|
+
})(["display:block;margin-top:0;margin-bottom:", "px;border-bottom:", " ", " ", ";padding:0;line-height:", "px;white-space:nowrap;color:", ";font-size:", ";", ";"], props => props.theme.space.base * 5, props => props.theme.borderWidths.sm, props => props.theme.borderStyles.solid, props => getColorV8('neutralHue', 300, props.theme), props => props.theme.space.base * 5, props => getColorV8('neutralHue', 600, props.theme), props => props.theme.fontSizes.md, props => retrieveComponentStyles(COMPONENT_ID, props));
|
|
18
|
+
StyledTabList.defaultProps = {
|
|
19
|
+
theme: DEFAULT_THEME
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { StyledTabList };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Zendesk, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
+
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
*/
|
|
7
|
+
import styled from 'styled-components';
|
|
8
|
+
import { retrieveComponentStyles, DEFAULT_THEME } from '@zendeskgarden/react-theming';
|
|
9
|
+
|
|
10
|
+
const COMPONENT_ID = 'tabs.tabpanel';
|
|
11
|
+
const StyledTabPanel = styled.div.attrs({
|
|
12
|
+
'data-garden-id': COMPONENT_ID,
|
|
13
|
+
'data-garden-version': '9.0.0-next.8'
|
|
14
|
+
}).withConfig({
|
|
15
|
+
displayName: "StyledTabPanel",
|
|
16
|
+
componentId: "sc-7lhrmp-0"
|
|
17
|
+
})(["display:block;&[aria-hidden='true']{display:none;}", ";"], props => retrieveComponentStyles(COMPONENT_ID, props));
|
|
18
|
+
StyledTabPanel.defaultProps = {
|
|
19
|
+
theme: DEFAULT_THEME
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { StyledTabPanel };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Zendesk, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
+
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
*/
|
|
7
|
+
import styled, { css } from 'styled-components';
|
|
8
|
+
import { retrieveComponentStyles, DEFAULT_THEME } from '@zendeskgarden/react-theming';
|
|
9
|
+
import { StyledTab } from './StyledTab.js';
|
|
10
|
+
import { StyledTabPanel } from './StyledTabPanel.js';
|
|
11
|
+
import { StyledTabList } from './StyledTabList.js';
|
|
12
|
+
|
|
13
|
+
const COMPONENT_ID = 'tabs.tabs';
|
|
14
|
+
const verticalStyling = _ref => {
|
|
15
|
+
let {
|
|
16
|
+
theme
|
|
17
|
+
} = _ref;
|
|
18
|
+
return css(["display:table;", "{display:table-cell;margin-bottom:0;border-bottom:none;vertical-align:top;}", "{display:block;margin-bottom:", "px;margin-left:", ";border-left:", ";border-bottom-style:none;border-", "-style:", ";border-", "-color:transparent;padding:", "px ", "px;text-align:", ";&:last-of-type{margin-bottom:0;}&:focus-visible::before{top:", "px;right:", "px;left:", "px;}}", "{margin-", ":", "px;vertical-align:top;}"], StyledTabList, StyledTab, theme.space.base * 5, theme.rtl && '0', theme.rtl && '0', theme.rtl ? 'right' : 'left', theme.borderStyles.solid, theme.rtl ? 'right' : 'left', theme.space.base, theme.space.base * 2, theme.rtl ? 'right' : 'left', theme.space.base, theme.space.base, theme.space.base, StyledTabPanel, theme.rtl ? 'right' : 'left', theme.space.base * 8);
|
|
19
|
+
};
|
|
20
|
+
const StyledTabs = styled.div.attrs({
|
|
21
|
+
'data-garden-id': COMPONENT_ID,
|
|
22
|
+
'data-garden-version': '9.0.0-next.8'
|
|
23
|
+
}).withConfig({
|
|
24
|
+
displayName: "StyledTabs",
|
|
25
|
+
componentId: "sc-1qaor65-0"
|
|
26
|
+
})(["display:block;overflow:hidden;direction:", ";", ";", ";"], props => props.theme.rtl && 'rtl', props => props.isVertical && verticalStyling(props), props => retrieveComponentStyles(COMPONENT_ID, props));
|
|
27
|
+
StyledTabs.defaultProps = {
|
|
28
|
+
theme: DEFAULT_THEME
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export { StyledTabs };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Zendesk, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
+
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
*/
|
|
7
|
+
import { Children, isValidElement } from 'react';
|
|
8
|
+
|
|
9
|
+
const toTabs = children => Children.toArray(children).reduce((_items, child) => {
|
|
10
|
+
const retVal = _items;
|
|
11
|
+
if ( isValidElement(child)) {
|
|
12
|
+
if ('item' in child.props) {
|
|
13
|
+
const props = child.props;
|
|
14
|
+
retVal.push({
|
|
15
|
+
value: props.item,
|
|
16
|
+
disabled: props.disabled
|
|
17
|
+
});
|
|
18
|
+
} else {
|
|
19
|
+
const childItems = toTabs(child.props.children);
|
|
20
|
+
retVal.push(...childItems);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return retVal;
|
|
24
|
+
}, []);
|
|
25
|
+
|
|
26
|
+
export { toTabs };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Zendesk, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
+
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
*/
|
|
7
|
+
import { createContext, useContext } from 'react';
|
|
8
|
+
|
|
9
|
+
const TabsContext = createContext(undefined);
|
|
10
|
+
const useTabsContext = () => {
|
|
11
|
+
return useContext(TabsContext);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { TabsContext, useTabsContext };
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
* Copyright Zendesk, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
+
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
*/
|
|
8
7
|
'use strict';
|
|
9
8
|
|
|
10
9
|
var React = require('react');
|
|
@@ -22,21 +21,6 @@ var React__default = /*#__PURE__*/_interopDefault(React);
|
|
|
22
21
|
var PropTypes__default = /*#__PURE__*/_interopDefault(PropTypes);
|
|
23
22
|
var styled__default = /*#__PURE__*/_interopDefault(styled);
|
|
24
23
|
|
|
25
|
-
function _extends() {
|
|
26
|
-
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
27
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
28
|
-
var source = arguments[i];
|
|
29
|
-
for (var key in source) {
|
|
30
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
31
|
-
target[key] = source[key];
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return target;
|
|
36
|
-
};
|
|
37
|
-
return _extends.apply(this, arguments);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
24
|
const COMPONENT_ID$3 = 'tabs.tab';
|
|
41
25
|
const colorStyles = _ref => {
|
|
42
26
|
let {
|
|
@@ -49,7 +33,7 @@ const colorStyles = _ref => {
|
|
|
49
33
|
inset: true,
|
|
50
34
|
spacerWidth: null,
|
|
51
35
|
shadowWidth: 'sm',
|
|
52
|
-
selector: '&:focus-visible::before
|
|
36
|
+
selector: '&:focus-visible::before',
|
|
53
37
|
styles: {
|
|
54
38
|
color: selectedColor
|
|
55
39
|
}
|
|
@@ -66,11 +50,11 @@ const sizeStyles = _ref2 => {
|
|
|
66
50
|
};
|
|
67
51
|
const StyledTab = styled__default.default.div.attrs({
|
|
68
52
|
'data-garden-id': COMPONENT_ID$3,
|
|
69
|
-
'data-garden-version': '9.0.0-next.
|
|
53
|
+
'data-garden-version': '9.0.0-next.8'
|
|
70
54
|
}).withConfig({
|
|
71
55
|
displayName: "StyledTab",
|
|
72
56
|
componentId: "sc-x2pbow-0"
|
|
73
|
-
})(["display:inline-block;position:relative;transition:color 0.25s ease-in-out;border-bottom:", " transparent;border-width:", ";cursor:pointer;overflow:hidden;vertical-align:top;user-select:none;text-align:center;text-decoration:none;text-overflow:ellipsis;", " ", " &:focus{text-decoration:none;}&::before{transition:box-shadow 0.1s ease-in-out;content:'';}&:focus-visible::before
|
|
57
|
+
})(["display:inline-block;position:relative;transition:color 0.25s ease-in-out;border-bottom:", " transparent;border-width:", ";cursor:pointer;overflow:hidden;vertical-align:top;user-select:none;text-align:center;text-decoration:none;text-overflow:ellipsis;", " ", " &:focus{text-decoration:none;}&::before{transition:box-shadow 0.1s ease-in-out;content:'';}&:focus-visible::before{position:absolute;top:", "px;right:", "px;left:", "px;border-radius:", ";height:", "px;pointer-events:none;}&:active::before{box-shadow:none;}&[aria-disabled='true']{cursor:default;}", ";"], props => props.theme.borderStyles.solid, props => props.theme.borderWidths.md, sizeStyles, colorStyles, props => props.theme.space.base * 2.5, props => props.theme.space.base * 6, props => props.theme.space.base * 6, props => props.theme.borderRadii.md, props => props.theme.space.base * 5, props => reactTheming.retrieveComponentStyles(COMPONENT_ID$3, props));
|
|
74
58
|
StyledTab.defaultProps = {
|
|
75
59
|
theme: reactTheming.DEFAULT_THEME
|
|
76
60
|
};
|
|
@@ -78,7 +62,7 @@ StyledTab.defaultProps = {
|
|
|
78
62
|
const COMPONENT_ID$2 = 'tabs.tablist';
|
|
79
63
|
const StyledTabList = styled__default.default.div.attrs({
|
|
80
64
|
'data-garden-id': COMPONENT_ID$2,
|
|
81
|
-
'data-garden-version': '9.0.0-next.
|
|
65
|
+
'data-garden-version': '9.0.0-next.8'
|
|
82
66
|
}).withConfig({
|
|
83
67
|
displayName: "StyledTabList",
|
|
84
68
|
componentId: "sc-wa5aaj-0"
|
|
@@ -90,7 +74,7 @@ StyledTabList.defaultProps = {
|
|
|
90
74
|
const COMPONENT_ID$1 = 'tabs.tabpanel';
|
|
91
75
|
const StyledTabPanel = styled__default.default.div.attrs({
|
|
92
76
|
'data-garden-id': COMPONENT_ID$1,
|
|
93
|
-
'data-garden-version': '9.0.0-next.
|
|
77
|
+
'data-garden-version': '9.0.0-next.8'
|
|
94
78
|
}).withConfig({
|
|
95
79
|
displayName: "StyledTabPanel",
|
|
96
80
|
componentId: "sc-7lhrmp-0"
|
|
@@ -104,11 +88,11 @@ const verticalStyling = _ref => {
|
|
|
104
88
|
let {
|
|
105
89
|
theme
|
|
106
90
|
} = _ref;
|
|
107
|
-
return styled.css(["display:table;", "{display:table-cell;margin-bottom:0;border-bottom:none;vertical-align:top;}", "{display:block;margin-bottom:", "px;margin-left:", ";border-left:", ";border-bottom-style:none;border-", "-style:", ";border-", "-color:transparent;padding:", "px ", "px;text-align:", ";&:last-of-type{margin-bottom:0;}&:focus-visible::before
|
|
91
|
+
return styled.css(["display:table;", "{display:table-cell;margin-bottom:0;border-bottom:none;vertical-align:top;}", "{display:block;margin-bottom:", "px;margin-left:", ";border-left:", ";border-bottom-style:none;border-", "-style:", ";border-", "-color:transparent;padding:", "px ", "px;text-align:", ";&:last-of-type{margin-bottom:0;}&:focus-visible::before{top:", "px;right:", "px;left:", "px;}}", "{margin-", ":", "px;vertical-align:top;}"], StyledTabList, StyledTab, theme.space.base * 5, theme.rtl && '0', theme.rtl && '0', theme.rtl ? 'right' : 'left', theme.borderStyles.solid, theme.rtl ? 'right' : 'left', theme.space.base, theme.space.base * 2, theme.rtl ? 'right' : 'left', theme.space.base, theme.space.base, theme.space.base, StyledTabPanel, theme.rtl ? 'right' : 'left', theme.space.base * 8);
|
|
108
92
|
};
|
|
109
93
|
const StyledTabs = styled__default.default.div.attrs({
|
|
110
94
|
'data-garden-id': COMPONENT_ID,
|
|
111
|
-
'data-garden-version': '9.0.0-next.
|
|
95
|
+
'data-garden-version': '9.0.0-next.8'
|
|
112
96
|
}).withConfig({
|
|
113
97
|
displayName: "StyledTabs",
|
|
114
98
|
componentId: "sc-1qaor65-0"
|
|
@@ -130,7 +114,7 @@ const Tab = React__default.default.forwardRef((_ref, ref) => {
|
|
|
130
114
|
} = _ref;
|
|
131
115
|
const tabsPropGetters = useTabsContext();
|
|
132
116
|
if (disabled || !tabsPropGetters) {
|
|
133
|
-
return React__default.default.createElement(StyledTab,
|
|
117
|
+
return React__default.default.createElement(StyledTab, Object.assign({
|
|
134
118
|
role: "tab",
|
|
135
119
|
"aria-disabled": disabled,
|
|
136
120
|
ref: ref
|
|
@@ -142,7 +126,7 @@ const Tab = React__default.default.forwardRef((_ref, ref) => {
|
|
|
142
126
|
} = tabsPropGetters.getTabProps({
|
|
143
127
|
value: item
|
|
144
128
|
});
|
|
145
|
-
return React__default.default.createElement(StyledTab,
|
|
129
|
+
return React__default.default.createElement(StyledTab, Object.assign({
|
|
146
130
|
isSelected: item === tabsPropGetters.selectedValue
|
|
147
131
|
}, tabProps, otherProps, {
|
|
148
132
|
ref: reactMergeRefs.mergeRefs([tabRef, ref])
|
|
@@ -157,12 +141,12 @@ Tab.propTypes = {
|
|
|
157
141
|
const TabList = React__default.default.forwardRef((props, ref) => {
|
|
158
142
|
const tabsPropGetters = useTabsContext();
|
|
159
143
|
if (!tabsPropGetters) {
|
|
160
|
-
return React__default.default.createElement(StyledTabList,
|
|
144
|
+
return React__default.default.createElement(StyledTabList, Object.assign({
|
|
161
145
|
ref: ref
|
|
162
146
|
}, props));
|
|
163
147
|
}
|
|
164
148
|
const tabListProps = tabsPropGetters.getTabListProps();
|
|
165
|
-
return React__default.default.createElement(StyledTabList,
|
|
149
|
+
return React__default.default.createElement(StyledTabList, Object.assign({}, tabListProps, props, {
|
|
166
150
|
ref: ref
|
|
167
151
|
}));
|
|
168
152
|
});
|
|
@@ -175,14 +159,14 @@ const TabPanel = React__default.default.forwardRef((_ref, ref) => {
|
|
|
175
159
|
} = _ref;
|
|
176
160
|
const tabsPropGetters = useTabsContext();
|
|
177
161
|
if (!tabsPropGetters) {
|
|
178
|
-
return React__default.default.createElement(StyledTabPanel,
|
|
162
|
+
return React__default.default.createElement(StyledTabPanel, Object.assign({
|
|
179
163
|
ref: ref
|
|
180
164
|
}, otherProps));
|
|
181
165
|
}
|
|
182
166
|
const tabPanelProps = tabsPropGetters.getTabPanelProps({
|
|
183
167
|
value: item
|
|
184
168
|
});
|
|
185
|
-
return React__default.default.createElement(StyledTabPanel,
|
|
169
|
+
return React__default.default.createElement(StyledTabPanel, Object.assign({
|
|
186
170
|
"aria-hidden": tabsPropGetters.selectedValue !== item
|
|
187
171
|
}, tabPanelProps, otherProps, {
|
|
188
172
|
ref: ref
|
|
@@ -238,7 +222,7 @@ const TabsComponent = React.forwardRef((_ref, ref) => {
|
|
|
238
222
|
});
|
|
239
223
|
return React__default.default.createElement(TabsContext.Provider, {
|
|
240
224
|
value: tabsContextValue
|
|
241
|
-
}, React__default.default.createElement(StyledTabs,
|
|
225
|
+
}, React__default.default.createElement(StyledTabs, Object.assign({
|
|
242
226
|
isVertical: isVertical
|
|
243
227
|
}, otherProps, {
|
|
244
228
|
ref: ref
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zendeskgarden/react-tabs",
|
|
3
|
-
"version": "9.0.0-next.
|
|
3
|
+
"version": "9.0.0-next.8",
|
|
4
4
|
"description": "Components and render prop containers relating to the Garden Design System.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Zendesk Garden <garden@zendesk.com>",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"url": "https://github.com/zendeskgarden/react-components/issues"
|
|
11
11
|
},
|
|
12
12
|
"main": "dist/index.cjs.js",
|
|
13
|
-
"module": "dist/index.
|
|
13
|
+
"module": "dist/esm/index.js",
|
|
14
14
|
"files": [
|
|
15
15
|
"dist"
|
|
16
16
|
],
|
|
@@ -28,13 +28,13 @@
|
|
|
28
28
|
"react-merge-refs": "^2.0.0"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@zendeskgarden/react-theming": "
|
|
31
|
+
"@zendeskgarden/react-theming": ">=9.0.0-next",
|
|
32
32
|
"react": ">=16.8.0",
|
|
33
33
|
"react-dom": ">=16.8.0",
|
|
34
34
|
"styled-components": "^5.3.1"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@zendeskgarden/react-theming": "^9.0.0-next.
|
|
37
|
+
"@zendeskgarden/react-theming": "^9.0.0-next.8"
|
|
38
38
|
},
|
|
39
39
|
"keywords": [
|
|
40
40
|
"components",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
48
|
"zendeskgarden:src": "src/index.ts",
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "a3d6534843d5a4f5cb60b52bc67264f3230f2da0"
|
|
50
50
|
}
|
package/dist/index.esm.js
DELETED
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright Zendesk, Inc.
|
|
3
|
-
*
|
|
4
|
-
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
|
-
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import React, { createContext, useContext, Children, isValidElement, forwardRef, useState, useMemo } from 'react';
|
|
9
|
-
import PropTypes from 'prop-types';
|
|
10
|
-
import { mergeRefs } from 'react-merge-refs';
|
|
11
|
-
import styled, { css, ThemeContext } from 'styled-components';
|
|
12
|
-
import { retrieveComponentStyles, DEFAULT_THEME, getColorV8, focusStyles } from '@zendeskgarden/react-theming';
|
|
13
|
-
import { stripUnit } from 'polished';
|
|
14
|
-
import { useTabs } from '@zendeskgarden/container-tabs';
|
|
15
|
-
import { getControlledValue } from '@zendeskgarden/container-utilities';
|
|
16
|
-
|
|
17
|
-
function _extends() {
|
|
18
|
-
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
19
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
20
|
-
var source = arguments[i];
|
|
21
|
-
for (var key in source) {
|
|
22
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
23
|
-
target[key] = source[key];
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return target;
|
|
28
|
-
};
|
|
29
|
-
return _extends.apply(this, arguments);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const COMPONENT_ID$3 = 'tabs.tab';
|
|
33
|
-
const colorStyles = _ref => {
|
|
34
|
-
let {
|
|
35
|
-
theme,
|
|
36
|
-
isSelected
|
|
37
|
-
} = _ref;
|
|
38
|
-
const selectedColor = getColorV8('primaryHue', 600, theme);
|
|
39
|
-
return css(["border-color:", ";color:", ";&:hover{color:", ";}", " &:active{border-color:currentcolor;color:", ";}&[aria-disabled='true']{border-color:transparent;color:", ";}"], isSelected && 'currentcolor !important', isSelected ? selectedColor : 'inherit', selectedColor, focusStyles({
|
|
40
|
-
theme,
|
|
41
|
-
inset: true,
|
|
42
|
-
spacerWidth: null,
|
|
43
|
-
shadowWidth: 'sm',
|
|
44
|
-
selector: '&:focus-visible::before, &[data-garden-focus-visible="true"]::before',
|
|
45
|
-
styles: {
|
|
46
|
-
color: selectedColor
|
|
47
|
-
}
|
|
48
|
-
}), selectedColor, props => getColorV8('neutralHue', 400, props.theme));
|
|
49
|
-
};
|
|
50
|
-
const sizeStyles = _ref2 => {
|
|
51
|
-
let {
|
|
52
|
-
theme
|
|
53
|
-
} = _ref2;
|
|
54
|
-
const paddingTop = theme.space.base * 2.5;
|
|
55
|
-
const paddingHorizontal = theme.space.base * 7;
|
|
56
|
-
const paddingBottom = paddingTop - stripUnit(theme.borderWidths.md) - stripUnit(theme.borderWidths.sm);
|
|
57
|
-
return css(["padding:", "px ", "px ", "px;"], paddingTop, paddingHorizontal, paddingBottom);
|
|
58
|
-
};
|
|
59
|
-
const StyledTab = styled.div.attrs({
|
|
60
|
-
'data-garden-id': COMPONENT_ID$3,
|
|
61
|
-
'data-garden-version': '9.0.0-next.6'
|
|
62
|
-
}).withConfig({
|
|
63
|
-
displayName: "StyledTab",
|
|
64
|
-
componentId: "sc-x2pbow-0"
|
|
65
|
-
})(["display:inline-block;position:relative;transition:color 0.25s ease-in-out;border-bottom:", " transparent;border-width:", ";cursor:pointer;overflow:hidden;vertical-align:top;user-select:none;text-align:center;text-decoration:none;text-overflow:ellipsis;", " ", " &:focus{text-decoration:none;}&::before{transition:box-shadow 0.1s ease-in-out;content:'';}&:focus-visible::before,&[data-garden-focus-visible]::before{position:absolute;top:", "px;right:", "px;left:", "px;border-radius:", ";height:", "px;pointer-events:none;}&:active::before{box-shadow:none;}&[aria-disabled='true']{cursor:default;}", ";"], props => props.theme.borderStyles.solid, props => props.theme.borderWidths.md, sizeStyles, colorStyles, props => props.theme.space.base * 2.5, props => props.theme.space.base * 6, props => props.theme.space.base * 6, props => props.theme.borderRadii.md, props => props.theme.space.base * 5, props => retrieveComponentStyles(COMPONENT_ID$3, props));
|
|
66
|
-
StyledTab.defaultProps = {
|
|
67
|
-
theme: DEFAULT_THEME
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const COMPONENT_ID$2 = 'tabs.tablist';
|
|
71
|
-
const StyledTabList = styled.div.attrs({
|
|
72
|
-
'data-garden-id': COMPONENT_ID$2,
|
|
73
|
-
'data-garden-version': '9.0.0-next.6'
|
|
74
|
-
}).withConfig({
|
|
75
|
-
displayName: "StyledTabList",
|
|
76
|
-
componentId: "sc-wa5aaj-0"
|
|
77
|
-
})(["display:block;margin-top:0;margin-bottom:", "px;border-bottom:", " ", " ", ";padding:0;line-height:", "px;white-space:nowrap;color:", ";font-size:", ";", ";"], props => props.theme.space.base * 5, props => props.theme.borderWidths.sm, props => props.theme.borderStyles.solid, props => getColorV8('neutralHue', 300, props.theme), props => props.theme.space.base * 5, props => getColorV8('neutralHue', 600, props.theme), props => props.theme.fontSizes.md, props => retrieveComponentStyles(COMPONENT_ID$2, props));
|
|
78
|
-
StyledTabList.defaultProps = {
|
|
79
|
-
theme: DEFAULT_THEME
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const COMPONENT_ID$1 = 'tabs.tabpanel';
|
|
83
|
-
const StyledTabPanel = styled.div.attrs({
|
|
84
|
-
'data-garden-id': COMPONENT_ID$1,
|
|
85
|
-
'data-garden-version': '9.0.0-next.6'
|
|
86
|
-
}).withConfig({
|
|
87
|
-
displayName: "StyledTabPanel",
|
|
88
|
-
componentId: "sc-7lhrmp-0"
|
|
89
|
-
})(["display:block;&[aria-hidden='true']{display:none;}", ";"], props => retrieveComponentStyles(COMPONENT_ID$1, props));
|
|
90
|
-
StyledTabPanel.defaultProps = {
|
|
91
|
-
theme: DEFAULT_THEME
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
const COMPONENT_ID = 'tabs.tabs';
|
|
95
|
-
const verticalStyling = _ref => {
|
|
96
|
-
let {
|
|
97
|
-
theme
|
|
98
|
-
} = _ref;
|
|
99
|
-
return css(["display:table;", "{display:table-cell;margin-bottom:0;border-bottom:none;vertical-align:top;}", "{display:block;margin-bottom:", "px;margin-left:", ";border-left:", ";border-bottom-style:none;border-", "-style:", ";border-", "-color:transparent;padding:", "px ", "px;text-align:", ";&:last-of-type{margin-bottom:0;}&:focus-visible::before,&[data-garden-focus-visible]::before{top:", "px;right:", "px;left:", "px;}}", "{margin-", ":", "px;vertical-align:top;}"], StyledTabList, StyledTab, theme.space.base * 5, theme.rtl && '0', theme.rtl && '0', theme.rtl ? 'right' : 'left', theme.borderStyles.solid, theme.rtl ? 'right' : 'left', theme.space.base, theme.space.base * 2, theme.rtl ? 'right' : 'left', theme.space.base, theme.space.base, theme.space.base, StyledTabPanel, theme.rtl ? 'right' : 'left', theme.space.base * 8);
|
|
100
|
-
};
|
|
101
|
-
const StyledTabs = styled.div.attrs({
|
|
102
|
-
'data-garden-id': COMPONENT_ID,
|
|
103
|
-
'data-garden-version': '9.0.0-next.6'
|
|
104
|
-
}).withConfig({
|
|
105
|
-
displayName: "StyledTabs",
|
|
106
|
-
componentId: "sc-1qaor65-0"
|
|
107
|
-
})(["display:block;overflow:hidden;direction:", ";", ";", ";"], props => props.theme.rtl && 'rtl', props => props.isVertical && verticalStyling(props), props => retrieveComponentStyles(COMPONENT_ID, props));
|
|
108
|
-
StyledTabs.defaultProps = {
|
|
109
|
-
theme: DEFAULT_THEME
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
const TabsContext = createContext(undefined);
|
|
113
|
-
const useTabsContext = () => {
|
|
114
|
-
return useContext(TabsContext);
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
const Tab = React.forwardRef((_ref, ref) => {
|
|
118
|
-
let {
|
|
119
|
-
disabled,
|
|
120
|
-
item,
|
|
121
|
-
...otherProps
|
|
122
|
-
} = _ref;
|
|
123
|
-
const tabsPropGetters = useTabsContext();
|
|
124
|
-
if (disabled || !tabsPropGetters) {
|
|
125
|
-
return React.createElement(StyledTab, _extends({
|
|
126
|
-
role: "tab",
|
|
127
|
-
"aria-disabled": disabled,
|
|
128
|
-
ref: ref
|
|
129
|
-
}, otherProps));
|
|
130
|
-
}
|
|
131
|
-
const {
|
|
132
|
-
ref: tabRef,
|
|
133
|
-
...tabProps
|
|
134
|
-
} = tabsPropGetters.getTabProps({
|
|
135
|
-
value: item
|
|
136
|
-
});
|
|
137
|
-
return React.createElement(StyledTab, _extends({
|
|
138
|
-
isSelected: item === tabsPropGetters.selectedValue
|
|
139
|
-
}, tabProps, otherProps, {
|
|
140
|
-
ref: mergeRefs([tabRef, ref])
|
|
141
|
-
}));
|
|
142
|
-
});
|
|
143
|
-
Tab.displayName = 'Tab';
|
|
144
|
-
Tab.propTypes = {
|
|
145
|
-
disabled: PropTypes.bool,
|
|
146
|
-
item: PropTypes.any
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
const TabList = React.forwardRef((props, ref) => {
|
|
150
|
-
const tabsPropGetters = useTabsContext();
|
|
151
|
-
if (!tabsPropGetters) {
|
|
152
|
-
return React.createElement(StyledTabList, _extends({
|
|
153
|
-
ref: ref
|
|
154
|
-
}, props));
|
|
155
|
-
}
|
|
156
|
-
const tabListProps = tabsPropGetters.getTabListProps();
|
|
157
|
-
return React.createElement(StyledTabList, _extends({}, tabListProps, props, {
|
|
158
|
-
ref: ref
|
|
159
|
-
}));
|
|
160
|
-
});
|
|
161
|
-
TabList.displayName = 'TabList';
|
|
162
|
-
|
|
163
|
-
const TabPanel = React.forwardRef((_ref, ref) => {
|
|
164
|
-
let {
|
|
165
|
-
item,
|
|
166
|
-
...otherProps
|
|
167
|
-
} = _ref;
|
|
168
|
-
const tabsPropGetters = useTabsContext();
|
|
169
|
-
if (!tabsPropGetters) {
|
|
170
|
-
return React.createElement(StyledTabPanel, _extends({
|
|
171
|
-
ref: ref
|
|
172
|
-
}, otherProps));
|
|
173
|
-
}
|
|
174
|
-
const tabPanelProps = tabsPropGetters.getTabPanelProps({
|
|
175
|
-
value: item
|
|
176
|
-
});
|
|
177
|
-
return React.createElement(StyledTabPanel, _extends({
|
|
178
|
-
"aria-hidden": tabsPropGetters.selectedValue !== item
|
|
179
|
-
}, tabPanelProps, otherProps, {
|
|
180
|
-
ref: ref
|
|
181
|
-
}));
|
|
182
|
-
});
|
|
183
|
-
TabPanel.displayName = 'TabPanel';
|
|
184
|
-
TabPanel.propTypes = {
|
|
185
|
-
item: PropTypes.any
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
const toTabs = children => Children.toArray(children).reduce((_items, child) => {
|
|
189
|
-
const retVal = _items;
|
|
190
|
-
if ( isValidElement(child)) {
|
|
191
|
-
if ('item' in child.props) {
|
|
192
|
-
const props = child.props;
|
|
193
|
-
retVal.push({
|
|
194
|
-
value: props.item,
|
|
195
|
-
disabled: props.disabled
|
|
196
|
-
});
|
|
197
|
-
} else {
|
|
198
|
-
const childItems = toTabs(child.props.children);
|
|
199
|
-
retVal.push(...childItems);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
return retVal;
|
|
203
|
-
}, []);
|
|
204
|
-
|
|
205
|
-
const TabsComponent = forwardRef((_ref, ref) => {
|
|
206
|
-
let {
|
|
207
|
-
isVertical,
|
|
208
|
-
children,
|
|
209
|
-
onChange,
|
|
210
|
-
selectedItem: controlledSelectedItem,
|
|
211
|
-
...otherProps
|
|
212
|
-
} = _ref;
|
|
213
|
-
const theme = useContext(ThemeContext) || DEFAULT_THEME;
|
|
214
|
-
const [internalSelectedItem, setInternalSelectedItem] = useState();
|
|
215
|
-
const selectedItem = getControlledValue(controlledSelectedItem, internalSelectedItem);
|
|
216
|
-
const tabs = useMemo(() => toTabs(children), [children]);
|
|
217
|
-
const tabsContextValue = useTabs({
|
|
218
|
-
tabs,
|
|
219
|
-
rtl: theme.rtl,
|
|
220
|
-
orientation: isVertical ? 'vertical' : 'horizontal',
|
|
221
|
-
selectedValue: selectedItem,
|
|
222
|
-
defaultSelectedValue: tabs.find(tab => !tab.disabled)?.value,
|
|
223
|
-
onSelect: item => {
|
|
224
|
-
if (onChange) {
|
|
225
|
-
onChange(item);
|
|
226
|
-
} else {
|
|
227
|
-
setInternalSelectedItem(item);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
return React.createElement(TabsContext.Provider, {
|
|
232
|
-
value: tabsContextValue
|
|
233
|
-
}, React.createElement(StyledTabs, _extends({
|
|
234
|
-
isVertical: isVertical
|
|
235
|
-
}, otherProps, {
|
|
236
|
-
ref: ref
|
|
237
|
-
}), children));
|
|
238
|
-
});
|
|
239
|
-
TabsComponent.propTypes = {
|
|
240
|
-
isVertical: PropTypes.bool,
|
|
241
|
-
selectedItem: PropTypes.any,
|
|
242
|
-
onChange: PropTypes.func
|
|
243
|
-
};
|
|
244
|
-
TabsComponent.defaultProps = {
|
|
245
|
-
isVertical: false
|
|
246
|
-
};
|
|
247
|
-
TabsComponent.displayName = 'Tabs';
|
|
248
|
-
const Tabs = TabsComponent;
|
|
249
|
-
Tabs.Tab = Tab;
|
|
250
|
-
Tabs.TabList = TabList;
|
|
251
|
-
Tabs.TabPanel = TabPanel;
|
|
252
|
-
|
|
253
|
-
export { Tab, TabList, TabPanel, Tabs };
|