@zendeskgarden/react-tabs 9.0.0-next.2 → 9.0.0-next.21
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/README.md +10 -10
- package/dist/esm/elements/Tab.js +50 -0
- package/dist/esm/elements/TabList.js +30 -0
- package/dist/esm/elements/TabPanel.js +41 -0
- package/dist/esm/elements/Tabs.js +72 -0
- package/dist/esm/index.js +10 -0
- package/dist/esm/styled/StyledTab.js +80 -0
- package/dist/esm/styled/StyledTabList.js +47 -0
- package/dist/esm/styled/StyledTabPanel.js +30 -0
- package/dist/esm/styled/StyledTabs.js +22 -0
- package/dist/esm/utils/toTabs.js +26 -0
- package/dist/esm/utils/useTabsContext.js +14 -0
- package/dist/index.cjs.js +121 -66
- package/dist/typings/elements/Tab.d.ts +2 -0
- package/dist/typings/elements/TabList.d.ts +2 -0
- package/dist/typings/elements/TabPanel.d.ts +2 -0
- package/dist/typings/elements/Tabs.d.ts +9 -1
- package/dist/typings/styled/StyledTab.d.ts +6 -7
- package/dist/typings/styled/StyledTabList.d.ts +7 -5
- package/dist/typings/styled/StyledTabPanel.d.ts +7 -5
- package/dist/typings/styled/StyledTabs.d.ts +2 -6
- package/dist/typings/utils/useTabsContext.d.ts +6 -2
- package/package.json +8 -8
- package/dist/index.esm.js +0 -249
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ npm install react react-dom styled-components @zendeskgarden/react-theming
|
|
|
17
17
|
```jsx
|
|
18
18
|
import React, { useState } from 'react';
|
|
19
19
|
import { ThemeProvider } from '@zendeskgarden/react-theming';
|
|
20
|
-
import { Tabs
|
|
20
|
+
import { Tabs } from '@zendeskgarden/react-tabs';
|
|
21
21
|
|
|
22
22
|
const Example = () => {
|
|
23
23
|
const [selectedTab, setSelectedTab] = useState('tab-1');
|
|
@@ -28,15 +28,15 @@ const Example = () => {
|
|
|
28
28
|
return (
|
|
29
29
|
<ThemeProvider>
|
|
30
30
|
<Tabs selectedItem={selectedTab} onChange={setSelectedTab}>
|
|
31
|
-
<TabList>
|
|
32
|
-
<Tab item="tab-1">Tab 1</Tab>
|
|
33
|
-
<Tab item="tab-2">Tab 2</Tab>
|
|
34
|
-
<Tab disabled>Disabled Tab</Tab>
|
|
35
|
-
<Tab item="tab-3">Tab 3</Tab>
|
|
36
|
-
</TabList>
|
|
37
|
-
<TabPanel item="tab-1">Tab 1 content</TabPanel>
|
|
38
|
-
<TabPanel item="tab-2">Tab 2 content</TabPanel>
|
|
39
|
-
<TabPanel item="tab-3">Tab 3 content</TabPanel>
|
|
31
|
+
<Tabs.TabList>
|
|
32
|
+
<Tabs.Tab item="tab-1">Tab 1</Tabs.Tab>
|
|
33
|
+
<Tabs.Tab item="tab-2">Tab 2</Tabs.Tab>
|
|
34
|
+
<Tabs.Tab disabled>Disabled Tab</Tabs.Tab>
|
|
35
|
+
<Tabs.Tab item="tab-3">Tab 3</Tabs.Tab>
|
|
36
|
+
</Tabs.TabList>
|
|
37
|
+
<Tabs.TabPanel item="tab-1">Tab 1 content</Tabs.TabPanel>
|
|
38
|
+
<Tabs.TabPanel item="tab-2">Tab 2 content</Tabs.TabPanel>
|
|
39
|
+
<Tabs.TabPanel item="tab-3">Tab 3 content</Tabs.TabPanel>
|
|
40
40
|
</Tabs>
|
|
41
41
|
</ThemeProvider>
|
|
42
42
|
);
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
$isVertical: tabsPropGetters?.isVertical
|
|
29
|
+
}, otherProps));
|
|
30
|
+
}
|
|
31
|
+
const {
|
|
32
|
+
ref: tabRef,
|
|
33
|
+
...tabProps
|
|
34
|
+
} = tabsPropGetters.getTabProps({
|
|
35
|
+
value: item
|
|
36
|
+
});
|
|
37
|
+
return React.createElement(StyledTab, Object.assign({
|
|
38
|
+
$isSelected: item === tabsPropGetters.selectedValue,
|
|
39
|
+
$isVertical: tabsPropGetters.isVertical
|
|
40
|
+
}, tabProps, otherProps, {
|
|
41
|
+
ref: mergeRefs([tabRef, ref])
|
|
42
|
+
}));
|
|
43
|
+
});
|
|
44
|
+
Tab.displayName = 'Tabs.Tab';
|
|
45
|
+
Tab.propTypes = {
|
|
46
|
+
disabled: PropTypes.bool,
|
|
47
|
+
item: PropTypes.any
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export { Tab };
|
|
@@ -0,0 +1,30 @@
|
|
|
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({
|
|
23
|
+
$isVertical: tabsPropGetters.isVertical
|
|
24
|
+
}, tabListProps, props, {
|
|
25
|
+
ref: ref
|
|
26
|
+
}));
|
|
27
|
+
});
|
|
28
|
+
TabList.displayName = 'Tabs.TabList';
|
|
29
|
+
|
|
30
|
+
export { TabList };
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
$isVertical: tabsPropGetters.isVertical
|
|
32
|
+
}, tabPanelProps, otherProps, {
|
|
33
|
+
ref: ref
|
|
34
|
+
}));
|
|
35
|
+
});
|
|
36
|
+
TabPanel.displayName = 'Tabs.TabPanel';
|
|
37
|
+
TabPanel.propTypes = {
|
|
38
|
+
item: PropTypes.any
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export { TabPanel };
|
|
@@ -0,0 +1,72 @@
|
|
|
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
|
+
const contextValue = useMemo(() => ({
|
|
47
|
+
isVertical,
|
|
48
|
+
...tabsContextValue
|
|
49
|
+
}), [isVertical, tabsContextValue]);
|
|
50
|
+
return React.createElement(TabsContext.Provider, {
|
|
51
|
+
value: contextValue
|
|
52
|
+
}, React.createElement(StyledTabs, Object.assign({
|
|
53
|
+
$isVertical: isVertical
|
|
54
|
+
}, otherProps, {
|
|
55
|
+
ref: ref
|
|
56
|
+
}), children));
|
|
57
|
+
});
|
|
58
|
+
TabsComponent.propTypes = {
|
|
59
|
+
isVertical: PropTypes.bool,
|
|
60
|
+
selectedItem: PropTypes.any,
|
|
61
|
+
onChange: PropTypes.func
|
|
62
|
+
};
|
|
63
|
+
TabsComponent.defaultProps = {
|
|
64
|
+
isVertical: false
|
|
65
|
+
};
|
|
66
|
+
TabsComponent.displayName = 'Tabs';
|
|
67
|
+
const Tabs = TabsComponent;
|
|
68
|
+
Tabs.Tab = Tab;
|
|
69
|
+
Tabs.TabList = TabList;
|
|
70
|
+
Tabs.TabPanel = TabPanel;
|
|
71
|
+
|
|
72
|
+
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,80 @@
|
|
|
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, getColor, 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
|
+
$isVertical
|
|
17
|
+
} = _ref;
|
|
18
|
+
const borderColor = $isSelected ? getColor({
|
|
19
|
+
theme,
|
|
20
|
+
variable: 'border.primaryEmphasis'
|
|
21
|
+
}) : 'transparent';
|
|
22
|
+
const borderBlockEndColor = $isVertical ? undefined : borderColor;
|
|
23
|
+
const borderInlineColor = $isVertical ? borderColor : undefined;
|
|
24
|
+
const selectedColor = getColor({
|
|
25
|
+
theme,
|
|
26
|
+
variable: 'foreground.primary'
|
|
27
|
+
});
|
|
28
|
+
const foregroundColor = $isSelected ? selectedColor : 'inherit';
|
|
29
|
+
const disabledColor = getColor({
|
|
30
|
+
theme,
|
|
31
|
+
variable: 'foreground.disabled'
|
|
32
|
+
});
|
|
33
|
+
return css(["border-bottom-color:", ";border-", "-color:", ";color:", ";&:hover{color:", ";}", " &:active{border-color:currentcolor;color:", ";}&[aria-disabled='true']{border-color:transparent;color:", ";}"], borderBlockEndColor, theme.rtl ? 'right' : 'left', borderInlineColor, foregroundColor, selectedColor, focusStyles({
|
|
34
|
+
theme,
|
|
35
|
+
inset: true,
|
|
36
|
+
spacerWidth: null,
|
|
37
|
+
shadowWidth: 'sm',
|
|
38
|
+
selector: '&:focus-visible::before',
|
|
39
|
+
styles: {
|
|
40
|
+
color: selectedColor
|
|
41
|
+
}
|
|
42
|
+
}), selectedColor, disabledColor);
|
|
43
|
+
};
|
|
44
|
+
const sizeStyles = _ref2 => {
|
|
45
|
+
let {
|
|
46
|
+
theme,
|
|
47
|
+
$isVertical
|
|
48
|
+
} = _ref2;
|
|
49
|
+
const borderWidth = theme.borderWidths.md;
|
|
50
|
+
const focusHeight = `${theme.space.base * 5}px`;
|
|
51
|
+
let marginBottom;
|
|
52
|
+
let padding;
|
|
53
|
+
if ($isVertical) {
|
|
54
|
+
marginBottom = `${theme.space.base * 5}px`;
|
|
55
|
+
padding = `${theme.space.base}px ${theme.space.base * 2}px`;
|
|
56
|
+
} else {
|
|
57
|
+
const paddingTop = theme.space.base * 2.5;
|
|
58
|
+
const paddingHorizontal = theme.space.base * 7;
|
|
59
|
+
const paddingBottom = paddingTop - stripUnit(theme.borderWidths.md) - stripUnit(theme.borderWidths.sm);
|
|
60
|
+
padding = `${paddingTop}px ${paddingHorizontal}px ${paddingBottom}px`;
|
|
61
|
+
}
|
|
62
|
+
return css(["margin-bottom:", ";border-width:", ";padding:", ";&:focus-visible::before,&[data-garden-focus-visible]::before{height:", ";}&:last-of-type{margin-bottom:0;}"], marginBottom, borderWidth, padding, focusHeight);
|
|
63
|
+
};
|
|
64
|
+
const StyledTab = styled.div.attrs({
|
|
65
|
+
'data-garden-id': COMPONENT_ID,
|
|
66
|
+
'data-garden-version': '9.0.0-next.21'
|
|
67
|
+
}).withConfig({
|
|
68
|
+
displayName: "StyledTab",
|
|
69
|
+
componentId: "sc-x2pbow-0"
|
|
70
|
+
})(["display:", ";position:relative;transition:color 0.25s ease-in-out;border-bottom:", ";border-", ":", ";cursor:pointer;overflow:hidden;vertical-align:top;user-select:none;text-align:", ";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:", ";pointer-events:none;}&:active::before{box-shadow:none;}&[aria-disabled='true']{cursor:default;}", ";"], props => props.$isVertical ? 'block' : 'inline-block', props => props.$isVertical ? undefined : props.theme.borderStyles.solid, props => props.theme.rtl ? 'right' : 'left', props => props.$isVertical ? props.theme.borderStyles.solid : undefined, props => {
|
|
71
|
+
if (props.$isVertical) {
|
|
72
|
+
return props.theme.rtl ? 'right' : 'left';
|
|
73
|
+
}
|
|
74
|
+
return 'center';
|
|
75
|
+
}, sizeStyles, colorStyles, props => props.theme.space.base * (props.$isVertical ? 1 : 2.5), props => props.theme.space.base * (props.$isVertical ? 1 : 6), props => props.theme.space.base * (props.$isVertical ? 1 : 6), props => props.theme.borderRadii.md, props => retrieveComponentStyles(COMPONENT_ID, props));
|
|
76
|
+
StyledTab.defaultProps = {
|
|
77
|
+
theme: DEFAULT_THEME
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export { StyledTab };
|
|
@@ -0,0 +1,47 @@
|
|
|
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, getColor, getLineHeight } from '@zendeskgarden/react-theming';
|
|
9
|
+
|
|
10
|
+
const COMPONENT_ID = 'tabs.tablist';
|
|
11
|
+
const colorStyles = _ref => {
|
|
12
|
+
let {
|
|
13
|
+
theme
|
|
14
|
+
} = _ref;
|
|
15
|
+
const borderColor = getColor({
|
|
16
|
+
theme,
|
|
17
|
+
variable: 'border.default'
|
|
18
|
+
});
|
|
19
|
+
const foregroundColor = getColor({
|
|
20
|
+
theme,
|
|
21
|
+
variable: 'foreground.default'
|
|
22
|
+
});
|
|
23
|
+
return css(["color-scheme:only ", ";border-bottom-color:", ";color:", ";"], p => p.theme.colors.base, borderColor, foregroundColor);
|
|
24
|
+
};
|
|
25
|
+
const sizeStyles = _ref2 => {
|
|
26
|
+
let {
|
|
27
|
+
theme,
|
|
28
|
+
$isVertical
|
|
29
|
+
} = _ref2;
|
|
30
|
+
const marginBottom = $isVertical ? 0 : `${theme.space.base * 5}px`;
|
|
31
|
+
const borderBottom = $isVertical ? undefined : theme.borderWidths.sm;
|
|
32
|
+
const fontSize = theme.fontSizes.md;
|
|
33
|
+
const lineHeight = getLineHeight(theme.space.base * 5, fontSize);
|
|
34
|
+
return css(["margin-top:0;margin-bottom:", ";border-bottom-width:", ";padding:0;line-height:", ";font-size:", ";"], marginBottom, borderBottom, lineHeight, fontSize);
|
|
35
|
+
};
|
|
36
|
+
const StyledTabList = styled.div.attrs({
|
|
37
|
+
'data-garden-id': COMPONENT_ID,
|
|
38
|
+
'data-garden-version': '9.0.0-next.21'
|
|
39
|
+
}).withConfig({
|
|
40
|
+
displayName: "StyledTabList",
|
|
41
|
+
componentId: "sc-wa5aaj-0"
|
|
42
|
+
})(["display:", ";border-bottom:", ";vertical-align:", ";white-space:nowrap;", ";", ";", ";"], props => props.$isVertical ? 'table-cell' : 'block', props => props.$isVertical ? 'none' : props.theme.borderStyles.solid, props => props.$isVertical ? 'top' : undefined, sizeStyles, colorStyles, props => retrieveComponentStyles(COMPONENT_ID, props));
|
|
43
|
+
StyledTabList.defaultProps = {
|
|
44
|
+
theme: DEFAULT_THEME
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export { StyledTabList };
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
|
|
10
|
+
const COMPONENT_ID = 'tabs.tabpanel';
|
|
11
|
+
const sizeStyles = _ref => {
|
|
12
|
+
let {
|
|
13
|
+
theme,
|
|
14
|
+
$isVertical
|
|
15
|
+
} = _ref;
|
|
16
|
+
const margin = $isVertical ? `${theme.space.base * 8}px` : undefined;
|
|
17
|
+
return css(["margin-", ":", ";"], theme.rtl ? 'right' : 'left', margin);
|
|
18
|
+
};
|
|
19
|
+
const StyledTabPanel = styled.div.attrs({
|
|
20
|
+
'data-garden-id': COMPONENT_ID,
|
|
21
|
+
'data-garden-version': '9.0.0-next.21'
|
|
22
|
+
}).withConfig({
|
|
23
|
+
displayName: "StyledTabPanel",
|
|
24
|
+
componentId: "sc-7lhrmp-0"
|
|
25
|
+
})(["display:block;vertical-align:", ";color-scheme:only ", ";", ";&[aria-hidden='true']{display:none;}", ";"], props => props.$isVertical && 'top', p => p.theme.colors.base, sizeStyles, props => retrieveComponentStyles(COMPONENT_ID, props));
|
|
26
|
+
StyledTabPanel.defaultProps = {
|
|
27
|
+
theme: DEFAULT_THEME
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export { StyledTabPanel };
|
|
@@ -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.tabs';
|
|
11
|
+
const StyledTabs = styled.div.attrs({
|
|
12
|
+
'data-garden-id': COMPONENT_ID,
|
|
13
|
+
'data-garden-version': '9.0.0-next.21'
|
|
14
|
+
}).withConfig({
|
|
15
|
+
displayName: "StyledTabs",
|
|
16
|
+
componentId: "sc-1qaor65-0"
|
|
17
|
+
})(["display:", ";overflow:hidden;direction:", ";", ";"], props => props.$isVertical ? 'table' : 'block', props => props.theme.rtl && 'rtl', props => retrieveComponentStyles(COMPONENT_ID, props));
|
|
18
|
+
StyledTabs.defaultProps = {
|
|
19
|
+
theme: DEFAULT_THEME
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
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,97 +21,140 @@ 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
|
-
const colorStyles = _ref => {
|
|
25
|
+
const colorStyles$1 = _ref => {
|
|
42
26
|
let {
|
|
43
27
|
theme,
|
|
44
|
-
isSelected
|
|
28
|
+
$isSelected,
|
|
29
|
+
$isVertical
|
|
45
30
|
} = _ref;
|
|
46
|
-
const
|
|
47
|
-
|
|
31
|
+
const borderColor = $isSelected ? reactTheming.getColor({
|
|
32
|
+
theme,
|
|
33
|
+
variable: 'border.primaryEmphasis'
|
|
34
|
+
}) : 'transparent';
|
|
35
|
+
const borderBlockEndColor = $isVertical ? undefined : borderColor;
|
|
36
|
+
const borderInlineColor = $isVertical ? borderColor : undefined;
|
|
37
|
+
const selectedColor = reactTheming.getColor({
|
|
38
|
+
theme,
|
|
39
|
+
variable: 'foreground.primary'
|
|
40
|
+
});
|
|
41
|
+
const foregroundColor = $isSelected ? selectedColor : 'inherit';
|
|
42
|
+
const disabledColor = reactTheming.getColor({
|
|
43
|
+
theme,
|
|
44
|
+
variable: 'foreground.disabled'
|
|
45
|
+
});
|
|
46
|
+
return styled.css(["border-bottom-color:", ";border-", "-color:", ";color:", ";&:hover{color:", ";}", " &:active{border-color:currentcolor;color:", ";}&[aria-disabled='true']{border-color:transparent;color:", ";}"], borderBlockEndColor, theme.rtl ? 'right' : 'left', borderInlineColor, foregroundColor, selectedColor, reactTheming.focusStyles({
|
|
48
47
|
theme,
|
|
49
48
|
inset: true,
|
|
50
49
|
spacerWidth: null,
|
|
51
50
|
shadowWidth: 'sm',
|
|
52
|
-
selector: '&:focus-visible::before
|
|
51
|
+
selector: '&:focus-visible::before',
|
|
53
52
|
styles: {
|
|
54
53
|
color: selectedColor
|
|
55
54
|
}
|
|
56
|
-
}), selectedColor,
|
|
55
|
+
}), selectedColor, disabledColor);
|
|
57
56
|
};
|
|
58
|
-
const sizeStyles = _ref2 => {
|
|
57
|
+
const sizeStyles$2 = _ref2 => {
|
|
59
58
|
let {
|
|
60
|
-
theme
|
|
59
|
+
theme,
|
|
60
|
+
$isVertical
|
|
61
61
|
} = _ref2;
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
const borderWidth = theme.borderWidths.md;
|
|
63
|
+
const focusHeight = `${theme.space.base * 5}px`;
|
|
64
|
+
let marginBottom;
|
|
65
|
+
let padding;
|
|
66
|
+
if ($isVertical) {
|
|
67
|
+
marginBottom = `${theme.space.base * 5}px`;
|
|
68
|
+
padding = `${theme.space.base}px ${theme.space.base * 2}px`;
|
|
69
|
+
} else {
|
|
70
|
+
const paddingTop = theme.space.base * 2.5;
|
|
71
|
+
const paddingHorizontal = theme.space.base * 7;
|
|
72
|
+
const paddingBottom = paddingTop - polished.stripUnit(theme.borderWidths.md) - polished.stripUnit(theme.borderWidths.sm);
|
|
73
|
+
padding = `${paddingTop}px ${paddingHorizontal}px ${paddingBottom}px`;
|
|
74
|
+
}
|
|
75
|
+
return styled.css(["margin-bottom:", ";border-width:", ";padding:", ";&:focus-visible::before,&[data-garden-focus-visible]::before{height:", ";}&:last-of-type{margin-bottom:0;}"], marginBottom, borderWidth, padding, focusHeight);
|
|
66
76
|
};
|
|
67
77
|
const StyledTab = styled__default.default.div.attrs({
|
|
68
78
|
'data-garden-id': COMPONENT_ID$3,
|
|
69
|
-
'data-garden-version': '9.0.0-next.
|
|
79
|
+
'data-garden-version': '9.0.0-next.21'
|
|
70
80
|
}).withConfig({
|
|
71
81
|
displayName: "StyledTab",
|
|
72
82
|
componentId: "sc-x2pbow-0"
|
|
73
|
-
})(["display:
|
|
83
|
+
})(["display:", ";position:relative;transition:color 0.25s ease-in-out;border-bottom:", ";border-", ":", ";cursor:pointer;overflow:hidden;vertical-align:top;user-select:none;text-align:", ";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:", ";pointer-events:none;}&:active::before{box-shadow:none;}&[aria-disabled='true']{cursor:default;}", ";"], props => props.$isVertical ? 'block' : 'inline-block', props => props.$isVertical ? undefined : props.theme.borderStyles.solid, props => props.theme.rtl ? 'right' : 'left', props => props.$isVertical ? props.theme.borderStyles.solid : undefined, props => {
|
|
84
|
+
if (props.$isVertical) {
|
|
85
|
+
return props.theme.rtl ? 'right' : 'left';
|
|
86
|
+
}
|
|
87
|
+
return 'center';
|
|
88
|
+
}, sizeStyles$2, colorStyles$1, props => props.theme.space.base * (props.$isVertical ? 1 : 2.5), props => props.theme.space.base * (props.$isVertical ? 1 : 6), props => props.theme.space.base * (props.$isVertical ? 1 : 6), props => props.theme.borderRadii.md, props => reactTheming.retrieveComponentStyles(COMPONENT_ID$3, props));
|
|
74
89
|
StyledTab.defaultProps = {
|
|
75
90
|
theme: reactTheming.DEFAULT_THEME
|
|
76
91
|
};
|
|
77
92
|
|
|
78
93
|
const COMPONENT_ID$2 = 'tabs.tablist';
|
|
94
|
+
const colorStyles = _ref => {
|
|
95
|
+
let {
|
|
96
|
+
theme
|
|
97
|
+
} = _ref;
|
|
98
|
+
const borderColor = reactTheming.getColor({
|
|
99
|
+
theme,
|
|
100
|
+
variable: 'border.default'
|
|
101
|
+
});
|
|
102
|
+
const foregroundColor = reactTheming.getColor({
|
|
103
|
+
theme,
|
|
104
|
+
variable: 'foreground.default'
|
|
105
|
+
});
|
|
106
|
+
return styled.css(["color-scheme:only ", ";border-bottom-color:", ";color:", ";"], p => p.theme.colors.base, borderColor, foregroundColor);
|
|
107
|
+
};
|
|
108
|
+
const sizeStyles$1 = _ref2 => {
|
|
109
|
+
let {
|
|
110
|
+
theme,
|
|
111
|
+
$isVertical
|
|
112
|
+
} = _ref2;
|
|
113
|
+
const marginBottom = $isVertical ? 0 : `${theme.space.base * 5}px`;
|
|
114
|
+
const borderBottom = $isVertical ? undefined : theme.borderWidths.sm;
|
|
115
|
+
const fontSize = theme.fontSizes.md;
|
|
116
|
+
const lineHeight = reactTheming.getLineHeight(theme.space.base * 5, fontSize);
|
|
117
|
+
return styled.css(["margin-top:0;margin-bottom:", ";border-bottom-width:", ";padding:0;line-height:", ";font-size:", ";"], marginBottom, borderBottom, lineHeight, fontSize);
|
|
118
|
+
};
|
|
79
119
|
const StyledTabList = styled__default.default.div.attrs({
|
|
80
120
|
'data-garden-id': COMPONENT_ID$2,
|
|
81
|
-
'data-garden-version': '9.0.0-next.
|
|
121
|
+
'data-garden-version': '9.0.0-next.21'
|
|
82
122
|
}).withConfig({
|
|
83
123
|
displayName: "StyledTabList",
|
|
84
124
|
componentId: "sc-wa5aaj-0"
|
|
85
|
-
})(["display:
|
|
125
|
+
})(["display:", ";border-bottom:", ";vertical-align:", ";white-space:nowrap;", ";", ";", ";"], props => props.$isVertical ? 'table-cell' : 'block', props => props.$isVertical ? 'none' : props.theme.borderStyles.solid, props => props.$isVertical ? 'top' : undefined, sizeStyles$1, colorStyles, props => reactTheming.retrieveComponentStyles(COMPONENT_ID$2, props));
|
|
86
126
|
StyledTabList.defaultProps = {
|
|
87
127
|
theme: reactTheming.DEFAULT_THEME
|
|
88
128
|
};
|
|
89
129
|
|
|
90
130
|
const COMPONENT_ID$1 = 'tabs.tabpanel';
|
|
131
|
+
const sizeStyles = _ref => {
|
|
132
|
+
let {
|
|
133
|
+
theme,
|
|
134
|
+
$isVertical
|
|
135
|
+
} = _ref;
|
|
136
|
+
const margin = $isVertical ? `${theme.space.base * 8}px` : undefined;
|
|
137
|
+
return styled.css(["margin-", ":", ";"], theme.rtl ? 'right' : 'left', margin);
|
|
138
|
+
};
|
|
91
139
|
const StyledTabPanel = styled__default.default.div.attrs({
|
|
92
140
|
'data-garden-id': COMPONENT_ID$1,
|
|
93
|
-
'data-garden-version': '9.0.0-next.
|
|
141
|
+
'data-garden-version': '9.0.0-next.21'
|
|
94
142
|
}).withConfig({
|
|
95
143
|
displayName: "StyledTabPanel",
|
|
96
144
|
componentId: "sc-7lhrmp-0"
|
|
97
|
-
})(["display:block;&[aria-hidden='true']{display:none;}", ";"], props => reactTheming.retrieveComponentStyles(COMPONENT_ID$1, props));
|
|
145
|
+
})(["display:block;vertical-align:", ";color-scheme:only ", ";", ";&[aria-hidden='true']{display:none;}", ";"], props => props.$isVertical && 'top', p => p.theme.colors.base, sizeStyles, props => reactTheming.retrieveComponentStyles(COMPONENT_ID$1, props));
|
|
98
146
|
StyledTabPanel.defaultProps = {
|
|
99
147
|
theme: reactTheming.DEFAULT_THEME
|
|
100
148
|
};
|
|
101
149
|
|
|
102
150
|
const COMPONENT_ID = 'tabs.tabs';
|
|
103
|
-
const verticalStyling = _ref => {
|
|
104
|
-
let {
|
|
105
|
-
theme
|
|
106
|
-
} = _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,&[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);
|
|
108
|
-
};
|
|
109
151
|
const StyledTabs = styled__default.default.div.attrs({
|
|
110
152
|
'data-garden-id': COMPONENT_ID,
|
|
111
|
-
'data-garden-version': '9.0.0-next.
|
|
153
|
+
'data-garden-version': '9.0.0-next.21'
|
|
112
154
|
}).withConfig({
|
|
113
155
|
displayName: "StyledTabs",
|
|
114
156
|
componentId: "sc-1qaor65-0"
|
|
115
|
-
})(["display:
|
|
157
|
+
})(["display:", ";overflow:hidden;direction:", ";", ";"], props => props.$isVertical ? 'table' : 'block', props => props.theme.rtl && 'rtl', props => reactTheming.retrieveComponentStyles(COMPONENT_ID, props));
|
|
116
158
|
StyledTabs.defaultProps = {
|
|
117
159
|
theme: reactTheming.DEFAULT_THEME
|
|
118
160
|
};
|
|
@@ -130,10 +172,11 @@ const Tab = React__default.default.forwardRef((_ref, ref) => {
|
|
|
130
172
|
} = _ref;
|
|
131
173
|
const tabsPropGetters = useTabsContext();
|
|
132
174
|
if (disabled || !tabsPropGetters) {
|
|
133
|
-
return React__default.default.createElement(StyledTab,
|
|
175
|
+
return React__default.default.createElement(StyledTab, Object.assign({
|
|
134
176
|
role: "tab",
|
|
135
177
|
"aria-disabled": disabled,
|
|
136
|
-
ref: ref
|
|
178
|
+
ref: ref,
|
|
179
|
+
$isVertical: tabsPropGetters?.isVertical
|
|
137
180
|
}, otherProps));
|
|
138
181
|
}
|
|
139
182
|
const {
|
|
@@ -142,13 +185,14 @@ const Tab = React__default.default.forwardRef((_ref, ref) => {
|
|
|
142
185
|
} = tabsPropGetters.getTabProps({
|
|
143
186
|
value: item
|
|
144
187
|
});
|
|
145
|
-
return React__default.default.createElement(StyledTab,
|
|
146
|
-
isSelected: item === tabsPropGetters.selectedValue
|
|
188
|
+
return React__default.default.createElement(StyledTab, Object.assign({
|
|
189
|
+
$isSelected: item === tabsPropGetters.selectedValue,
|
|
190
|
+
$isVertical: tabsPropGetters.isVertical
|
|
147
191
|
}, tabProps, otherProps, {
|
|
148
192
|
ref: reactMergeRefs.mergeRefs([tabRef, ref])
|
|
149
193
|
}));
|
|
150
194
|
});
|
|
151
|
-
Tab.displayName = 'Tab';
|
|
195
|
+
Tab.displayName = 'Tabs.Tab';
|
|
152
196
|
Tab.propTypes = {
|
|
153
197
|
disabled: PropTypes__default.default.bool,
|
|
154
198
|
item: PropTypes__default.default.any
|
|
@@ -157,16 +201,18 @@ Tab.propTypes = {
|
|
|
157
201
|
const TabList = React__default.default.forwardRef((props, ref) => {
|
|
158
202
|
const tabsPropGetters = useTabsContext();
|
|
159
203
|
if (!tabsPropGetters) {
|
|
160
|
-
return React__default.default.createElement(StyledTabList,
|
|
204
|
+
return React__default.default.createElement(StyledTabList, Object.assign({
|
|
161
205
|
ref: ref
|
|
162
206
|
}, props));
|
|
163
207
|
}
|
|
164
208
|
const tabListProps = tabsPropGetters.getTabListProps();
|
|
165
|
-
return React__default.default.createElement(StyledTabList,
|
|
209
|
+
return React__default.default.createElement(StyledTabList, Object.assign({
|
|
210
|
+
$isVertical: tabsPropGetters.isVertical
|
|
211
|
+
}, tabListProps, props, {
|
|
166
212
|
ref: ref
|
|
167
213
|
}));
|
|
168
214
|
});
|
|
169
|
-
TabList.displayName = 'TabList';
|
|
215
|
+
TabList.displayName = 'Tabs.TabList';
|
|
170
216
|
|
|
171
217
|
const TabPanel = React__default.default.forwardRef((_ref, ref) => {
|
|
172
218
|
let {
|
|
@@ -175,20 +221,21 @@ const TabPanel = React__default.default.forwardRef((_ref, ref) => {
|
|
|
175
221
|
} = _ref;
|
|
176
222
|
const tabsPropGetters = useTabsContext();
|
|
177
223
|
if (!tabsPropGetters) {
|
|
178
|
-
return React__default.default.createElement(StyledTabPanel,
|
|
224
|
+
return React__default.default.createElement(StyledTabPanel, Object.assign({
|
|
179
225
|
ref: ref
|
|
180
226
|
}, otherProps));
|
|
181
227
|
}
|
|
182
228
|
const tabPanelProps = tabsPropGetters.getTabPanelProps({
|
|
183
229
|
value: item
|
|
184
230
|
});
|
|
185
|
-
return React__default.default.createElement(StyledTabPanel,
|
|
186
|
-
"aria-hidden": tabsPropGetters.selectedValue !== item
|
|
231
|
+
return React__default.default.createElement(StyledTabPanel, Object.assign({
|
|
232
|
+
"aria-hidden": tabsPropGetters.selectedValue !== item,
|
|
233
|
+
$isVertical: tabsPropGetters.isVertical
|
|
187
234
|
}, tabPanelProps, otherProps, {
|
|
188
235
|
ref: ref
|
|
189
236
|
}));
|
|
190
237
|
});
|
|
191
|
-
TabPanel.displayName = 'TabPanel';
|
|
238
|
+
TabPanel.displayName = 'Tabs.TabPanel';
|
|
192
239
|
TabPanel.propTypes = {
|
|
193
240
|
item: PropTypes__default.default.any
|
|
194
241
|
};
|
|
@@ -210,7 +257,7 @@ const toTabs = children => React.Children.toArray(children).reduce((_items, chil
|
|
|
210
257
|
return retVal;
|
|
211
258
|
}, []);
|
|
212
259
|
|
|
213
|
-
const
|
|
260
|
+
const TabsComponent = React.forwardRef((_ref, ref) => {
|
|
214
261
|
let {
|
|
215
262
|
isVertical,
|
|
216
263
|
children,
|
|
@@ -236,23 +283,31 @@ const Tabs = React.forwardRef((_ref, ref) => {
|
|
|
236
283
|
}
|
|
237
284
|
}
|
|
238
285
|
});
|
|
286
|
+
const contextValue = React.useMemo(() => ({
|
|
287
|
+
isVertical,
|
|
288
|
+
...tabsContextValue
|
|
289
|
+
}), [isVertical, tabsContextValue]);
|
|
239
290
|
return React__default.default.createElement(TabsContext.Provider, {
|
|
240
|
-
value:
|
|
241
|
-
}, React__default.default.createElement(StyledTabs,
|
|
242
|
-
isVertical: isVertical
|
|
291
|
+
value: contextValue
|
|
292
|
+
}, React__default.default.createElement(StyledTabs, Object.assign({
|
|
293
|
+
$isVertical: isVertical
|
|
243
294
|
}, otherProps, {
|
|
244
295
|
ref: ref
|
|
245
296
|
}), children));
|
|
246
297
|
});
|
|
247
|
-
|
|
298
|
+
TabsComponent.propTypes = {
|
|
248
299
|
isVertical: PropTypes__default.default.bool,
|
|
249
300
|
selectedItem: PropTypes__default.default.any,
|
|
250
301
|
onChange: PropTypes__default.default.func
|
|
251
302
|
};
|
|
252
|
-
|
|
303
|
+
TabsComponent.defaultProps = {
|
|
253
304
|
isVertical: false
|
|
254
305
|
};
|
|
255
|
-
|
|
306
|
+
TabsComponent.displayName = 'Tabs';
|
|
307
|
+
const Tabs = TabsComponent;
|
|
308
|
+
Tabs.Tab = Tab;
|
|
309
|
+
Tabs.TabList = TabList;
|
|
310
|
+
Tabs.TabPanel = TabPanel;
|
|
256
311
|
|
|
257
312
|
exports.Tab = Tab;
|
|
258
313
|
exports.TabList = TabList;
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
import React from 'react';
|
|
8
8
|
import { ITabProps } from '../types';
|
|
9
9
|
/**
|
|
10
|
+
* @deprecated use `Tabs.Tab` instead
|
|
11
|
+
*
|
|
10
12
|
* @extends HTMLAttributes<HTMLDivElement>
|
|
11
13
|
*/
|
|
12
14
|
export declare const Tab: React.ForwardRefExoticComponent<ITabProps & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import React from 'react';
|
|
8
8
|
/**
|
|
9
|
+
* @deprecated use `Tabs.TabList` instead
|
|
10
|
+
*
|
|
9
11
|
* @extends HTMLAttributes<HTMLDivElement>
|
|
10
12
|
*/
|
|
11
13
|
export declare const TabList: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
import React from 'react';
|
|
8
8
|
import { ITabPanelProps } from '../types';
|
|
9
9
|
/**
|
|
10
|
+
* @deprecated use `Tabs.TabPanel` instead
|
|
11
|
+
*
|
|
10
12
|
* @extends HTMLAttributes<HTMLDivElement>
|
|
11
13
|
*/
|
|
12
14
|
export declare const TabPanel: React.ForwardRefExoticComponent<ITabPanelProps & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -6,7 +6,15 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import React from 'react';
|
|
8
8
|
import { ITabsProps } from '../types';
|
|
9
|
+
import { Tab } from './Tab';
|
|
10
|
+
import { TabList } from './TabList';
|
|
11
|
+
import { TabPanel } from './TabPanel';
|
|
12
|
+
export declare const TabsComponent: React.ForwardRefExoticComponent<ITabsProps & React.RefAttributes<HTMLDivElement>>;
|
|
9
13
|
/**
|
|
10
14
|
* @extends HTMLAttributes<HTMLDivElement>
|
|
11
15
|
*/
|
|
12
|
-
export declare const Tabs: React.ForwardRefExoticComponent<ITabsProps & React.RefAttributes<HTMLDivElement
|
|
16
|
+
export declare const Tabs: React.ForwardRefExoticComponent<ITabsProps & React.RefAttributes<HTMLDivElement>> & {
|
|
17
|
+
Tab: typeof Tab;
|
|
18
|
+
TabList: typeof TabList;
|
|
19
|
+
TabPanel: typeof TabPanel;
|
|
20
|
+
};
|
|
@@ -6,12 +6,11 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { DefaultTheme } from 'styled-components';
|
|
8
8
|
interface IStyledTabProps {
|
|
9
|
-
isSelected?: boolean;
|
|
9
|
+
$isSelected?: boolean;
|
|
10
|
+
$isVertical?: boolean;
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*/
|
|
16
|
-
export declare const StyledTab: import("styled-components").StyledComponent<"div", DefaultTheme, IStyledTabProps, never>;
|
|
12
|
+
export declare const StyledTab: import("styled-components").StyledComponent<"div", DefaultTheme, {
|
|
13
|
+
'data-garden-id': string;
|
|
14
|
+
'data-garden-version': string;
|
|
15
|
+
} & IStyledTabProps, "data-garden-id" | "data-garden-version">;
|
|
17
16
|
export {};
|
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
5
|
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
import { DefaultTheme } from 'styled-components';
|
|
8
|
+
interface IStyledTabListProps {
|
|
9
|
+
$isVertical?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare const StyledTabList: import("styled-components").StyledComponent<"div", DefaultTheme, {
|
|
11
12
|
'data-garden-id': string;
|
|
12
13
|
'data-garden-version': string;
|
|
13
|
-
}, "data-garden-id" | "data-garden-version">;
|
|
14
|
+
} & IStyledTabListProps, "data-garden-id" | "data-garden-version">;
|
|
15
|
+
export {};
|
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
5
|
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
import { DefaultTheme } from 'styled-components';
|
|
8
|
+
interface IStyledTabPanelProps {
|
|
9
|
+
$isVertical?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare const StyledTabPanel: import("styled-components").StyledComponent<"div", DefaultTheme, {
|
|
11
12
|
'data-garden-id': string;
|
|
12
13
|
'data-garden-version': string;
|
|
13
|
-
}, "data-garden-id" | "data-garden-version">;
|
|
14
|
+
} & IStyledTabPanelProps, "data-garden-id" | "data-garden-version">;
|
|
15
|
+
export {};
|
|
@@ -4,15 +4,11 @@
|
|
|
4
4
|
* Use of this source code is governed under the Apache License, Version 2.0
|
|
5
5
|
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
6
|
*/
|
|
7
|
-
import { DefaultTheme } from 'styled-components';
|
|
8
7
|
interface IStyledTabsProps {
|
|
9
|
-
|
|
10
|
-
* Displays vertical TabList styling
|
|
11
|
-
*/
|
|
12
|
-
isVertical?: boolean;
|
|
8
|
+
$isVertical?: boolean;
|
|
13
9
|
}
|
|
14
10
|
/**
|
|
15
11
|
* Accepts all `<div>` props
|
|
16
12
|
*/
|
|
17
|
-
export declare const StyledTabs: import("styled-components").StyledComponent<"div", DefaultTheme, IStyledTabsProps, never>;
|
|
13
|
+
export declare const StyledTabs: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, IStyledTabsProps, never>;
|
|
18
14
|
export {};
|
|
@@ -6,5 +6,9 @@
|
|
|
6
6
|
*/
|
|
7
7
|
/// <reference types="react" />
|
|
8
8
|
import { IUseTabsReturnValue } from '@zendeskgarden/container-tabs';
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
interface ITabsContext extends IUseTabsReturnValue<any> {
|
|
10
|
+
isVertical?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare const TabsContext: import("react").Context<ITabsContext | undefined>;
|
|
13
|
+
export declare const useTabsContext: () => ITabsContext | undefined;
|
|
14
|
+
export {};
|
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.21",
|
|
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
|
],
|
|
@@ -21,20 +21,20 @@
|
|
|
21
21
|
"sideEffects": false,
|
|
22
22
|
"types": "dist/typings/index.d.ts",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@zendeskgarden/container-tabs": "^2.0.
|
|
24
|
+
"@zendeskgarden/container-tabs": "^2.0.10",
|
|
25
25
|
"@zendeskgarden/container-utilities": "^2.0.0",
|
|
26
|
-
"polished": "^4.
|
|
26
|
+
"polished": "^4.3.1",
|
|
27
27
|
"prop-types": "^15.5.7",
|
|
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
|
-
"styled-components": "^5.1
|
|
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.21"
|
|
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": "a245ce2b794ea65142174a6a1f855a111b2677a2"
|
|
50
50
|
}
|
package/dist/index.esm.js
DELETED
|
@@ -1,249 +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, getColor, 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 = getColor('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 => getColor('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.2'
|
|
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.2'
|
|
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 => getColor('neutralHue', 300, props.theme), props => props.theme.space.base * 5, props => getColor('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.2'
|
|
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.2'
|
|
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 Tabs = 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
|
-
Tabs.propTypes = {
|
|
240
|
-
isVertical: PropTypes.bool,
|
|
241
|
-
selectedItem: PropTypes.any,
|
|
242
|
-
onChange: PropTypes.func
|
|
243
|
-
};
|
|
244
|
-
Tabs.defaultProps = {
|
|
245
|
-
isVertical: false
|
|
246
|
-
};
|
|
247
|
-
Tabs.displayName = 'Tabs';
|
|
248
|
-
|
|
249
|
-
export { Tab, TabList, TabPanel, Tabs };
|