@zendeskgarden/react-tabs 8.69.3 → 8.69.5
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/index.cjs.js +36 -25
- package/dist/index.esm.js +37 -26
- package/dist/typings/utils/toTabs.d.ts +15 -0
- package/dist/typings/utils/useTabsContext.d.ts +3 -8
- package/package.json +4 -4
package/dist/index.cjs.js
CHANGED
|
@@ -45,7 +45,7 @@ const colorStyles = _ref => {
|
|
|
45
45
|
isSelected
|
|
46
46
|
} = _ref;
|
|
47
47
|
const selectedColor = reactTheming.getColor('primaryHue', 600, theme);
|
|
48
|
-
return styled.css(["border-color:", ";color:", ";&:hover{color:", ";}", " &:active{border-color:
|
|
48
|
+
return styled.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, reactTheming.focusStyles({
|
|
49
49
|
theme,
|
|
50
50
|
inset: true,
|
|
51
51
|
spacerWidth: null,
|
|
@@ -67,7 +67,7 @@ const sizeStyles = _ref2 => {
|
|
|
67
67
|
};
|
|
68
68
|
const StyledTab = styled__default.default.div.attrs({
|
|
69
69
|
'data-garden-id': COMPONENT_ID$3,
|
|
70
|
-
'data-garden-version': '8.69.
|
|
70
|
+
'data-garden-version': '8.69.5'
|
|
71
71
|
}).withConfig({
|
|
72
72
|
displayName: "StyledTab",
|
|
73
73
|
componentId: "sc-x2pbow-0"
|
|
@@ -79,7 +79,7 @@ StyledTab.defaultProps = {
|
|
|
79
79
|
const COMPONENT_ID$2 = 'tabs.tablist';
|
|
80
80
|
const StyledTabList = styled__default.default.div.attrs({
|
|
81
81
|
'data-garden-id': COMPONENT_ID$2,
|
|
82
|
-
'data-garden-version': '8.69.
|
|
82
|
+
'data-garden-version': '8.69.5'
|
|
83
83
|
}).withConfig({
|
|
84
84
|
displayName: "StyledTabList",
|
|
85
85
|
componentId: "sc-wa5aaj-0"
|
|
@@ -91,7 +91,7 @@ StyledTabList.defaultProps = {
|
|
|
91
91
|
const COMPONENT_ID$1 = 'tabs.tabpanel';
|
|
92
92
|
const StyledTabPanel = styled__default.default.div.attrs({
|
|
93
93
|
'data-garden-id': COMPONENT_ID$1,
|
|
94
|
-
'data-garden-version': '8.69.
|
|
94
|
+
'data-garden-version': '8.69.5'
|
|
95
95
|
}).withConfig({
|
|
96
96
|
displayName: "StyledTabPanel",
|
|
97
97
|
componentId: "sc-7lhrmp-0"
|
|
@@ -109,7 +109,7 @@ const verticalStyling = _ref => {
|
|
|
109
109
|
};
|
|
110
110
|
const StyledTabs = styled__default.default.div.attrs({
|
|
111
111
|
'data-garden-id': COMPONENT_ID,
|
|
112
|
-
'data-garden-version': '8.69.
|
|
112
|
+
'data-garden-version': '8.69.5'
|
|
113
113
|
}).withConfig({
|
|
114
114
|
displayName: "StyledTabs",
|
|
115
115
|
componentId: "sc-1qaor65-0"
|
|
@@ -130,21 +130,21 @@ const Tab = React__default.default.forwardRef((_ref, ref) => {
|
|
|
130
130
|
...otherProps
|
|
131
131
|
} = _ref;
|
|
132
132
|
const tabsPropGetters = useTabsContext();
|
|
133
|
-
const tabRef = React__default.default.createRef();
|
|
134
133
|
if (disabled || !tabsPropGetters) {
|
|
135
134
|
return React__default.default.createElement(StyledTab, _extends({
|
|
136
135
|
role: "tab",
|
|
137
136
|
"aria-disabled": disabled,
|
|
138
|
-
ref:
|
|
137
|
+
ref: ref
|
|
139
138
|
}, otherProps));
|
|
140
139
|
}
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
140
|
+
const {
|
|
141
|
+
ref: tabRef,
|
|
142
|
+
...tabProps
|
|
143
|
+
} = tabsPropGetters.getTabProps({
|
|
144
|
+
value: item
|
|
145
145
|
});
|
|
146
146
|
return React__default.default.createElement(StyledTab, _extends({
|
|
147
|
-
isSelected: item === tabsPropGetters.
|
|
147
|
+
isSelected: item === tabsPropGetters.selectedValue
|
|
148
148
|
}, tabProps, otherProps, {
|
|
149
149
|
ref: mergeRefs__default.default([tabRef, ref])
|
|
150
150
|
}));
|
|
@@ -181,11 +181,10 @@ const TabPanel = React__default.default.forwardRef((_ref, ref) => {
|
|
|
181
181
|
}, otherProps));
|
|
182
182
|
}
|
|
183
183
|
const tabPanelProps = tabsPropGetters.getTabPanelProps({
|
|
184
|
-
item
|
|
185
|
-
index: tabsPropGetters.tabPanelIndexRef.current++
|
|
184
|
+
value: item
|
|
186
185
|
});
|
|
187
186
|
return React__default.default.createElement(StyledTabPanel, _extends({
|
|
188
|
-
"aria-hidden": tabsPropGetters.
|
|
187
|
+
"aria-hidden": tabsPropGetters.selectedValue !== item
|
|
189
188
|
}, tabPanelProps, otherProps, {
|
|
190
189
|
ref: ref
|
|
191
190
|
}));
|
|
@@ -195,6 +194,23 @@ TabPanel.propTypes = {
|
|
|
195
194
|
item: PropTypes__default.default.any
|
|
196
195
|
};
|
|
197
196
|
|
|
197
|
+
const toTabs = children => React.Children.toArray(children).reduce((_items, child) => {
|
|
198
|
+
const retVal = _items;
|
|
199
|
+
if ( React.isValidElement(child) && child.type !== 'string') {
|
|
200
|
+
if (Tab === child.type && 'item' in child.props) {
|
|
201
|
+
const props = child.props;
|
|
202
|
+
retVal.push({
|
|
203
|
+
value: props.item,
|
|
204
|
+
disabled: props.disabled
|
|
205
|
+
});
|
|
206
|
+
} else {
|
|
207
|
+
const childItems = toTabs(child.props.children);
|
|
208
|
+
retVal.push(...childItems);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return retVal;
|
|
212
|
+
}, []);
|
|
213
|
+
|
|
198
214
|
const Tabs = React.forwardRef((_ref, ref) => {
|
|
199
215
|
let {
|
|
200
216
|
isVertical,
|
|
@@ -205,14 +221,14 @@ const Tabs = React.forwardRef((_ref, ref) => {
|
|
|
205
221
|
} = _ref;
|
|
206
222
|
const theme = React.useContext(styled.ThemeContext) || reactTheming.DEFAULT_THEME;
|
|
207
223
|
const [internalSelectedItem, setInternalSelectedItem] = React.useState();
|
|
208
|
-
const tabIndexRef = React.useRef(0);
|
|
209
|
-
const tabPanelIndexRef = React.useRef(0);
|
|
210
224
|
const selectedItem = containerUtilities.getControlledValue(controlledSelectedItem, internalSelectedItem);
|
|
211
|
-
const
|
|
225
|
+
const tabs = React.useMemo(() => toTabs(children), [children]);
|
|
226
|
+
const tabsContextValue = containerTabs.useTabs({
|
|
227
|
+
tabs,
|
|
212
228
|
rtl: theme.rtl,
|
|
213
229
|
orientation: isVertical ? 'vertical' : 'horizontal',
|
|
214
|
-
selectedItem,
|
|
215
|
-
|
|
230
|
+
selectedValue: selectedItem,
|
|
231
|
+
defaultSelectedValue: tabs.find(tab => !tab.disabled)?.value,
|
|
216
232
|
onSelect: item => {
|
|
217
233
|
if (onChange) {
|
|
218
234
|
onChange(item);
|
|
@@ -221,11 +237,6 @@ const Tabs = React.forwardRef((_ref, ref) => {
|
|
|
221
237
|
}
|
|
222
238
|
}
|
|
223
239
|
});
|
|
224
|
-
const tabsContextValue = React.useMemo(() => ({
|
|
225
|
-
...tabPropGetters,
|
|
226
|
-
tabIndexRef,
|
|
227
|
-
tabPanelIndexRef
|
|
228
|
-
}), [tabPropGetters]);
|
|
229
240
|
return React__default.default.createElement(TabsContext.Provider, {
|
|
230
241
|
value: tabsContextValue
|
|
231
242
|
}, React__default.default.createElement(StyledTabs, _extends({
|
package/dist/index.esm.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* found at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import React, { createContext, useContext, forwardRef, useState,
|
|
8
|
+
import React, { createContext, useContext, Children, isValidElement, forwardRef, useState, useMemo } from 'react';
|
|
9
9
|
import PropTypes from 'prop-types';
|
|
10
10
|
import mergeRefs from 'react-merge-refs';
|
|
11
11
|
import styled, { css, ThemeContext } from 'styled-components';
|
|
@@ -36,7 +36,7 @@ const colorStyles = _ref => {
|
|
|
36
36
|
isSelected
|
|
37
37
|
} = _ref;
|
|
38
38
|
const selectedColor = getColor('primaryHue', 600, theme);
|
|
39
|
-
return css(["border-color:", ";color:", ";&:hover{color:", ";}", " &:active{border-color:
|
|
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
40
|
theme,
|
|
41
41
|
inset: true,
|
|
42
42
|
spacerWidth: null,
|
|
@@ -58,7 +58,7 @@ const sizeStyles = _ref2 => {
|
|
|
58
58
|
};
|
|
59
59
|
const StyledTab = styled.div.attrs({
|
|
60
60
|
'data-garden-id': COMPONENT_ID$3,
|
|
61
|
-
'data-garden-version': '8.69.
|
|
61
|
+
'data-garden-version': '8.69.5'
|
|
62
62
|
}).withConfig({
|
|
63
63
|
displayName: "StyledTab",
|
|
64
64
|
componentId: "sc-x2pbow-0"
|
|
@@ -70,7 +70,7 @@ StyledTab.defaultProps = {
|
|
|
70
70
|
const COMPONENT_ID$2 = 'tabs.tablist';
|
|
71
71
|
const StyledTabList = styled.div.attrs({
|
|
72
72
|
'data-garden-id': COMPONENT_ID$2,
|
|
73
|
-
'data-garden-version': '8.69.
|
|
73
|
+
'data-garden-version': '8.69.5'
|
|
74
74
|
}).withConfig({
|
|
75
75
|
displayName: "StyledTabList",
|
|
76
76
|
componentId: "sc-wa5aaj-0"
|
|
@@ -82,7 +82,7 @@ StyledTabList.defaultProps = {
|
|
|
82
82
|
const COMPONENT_ID$1 = 'tabs.tabpanel';
|
|
83
83
|
const StyledTabPanel = styled.div.attrs({
|
|
84
84
|
'data-garden-id': COMPONENT_ID$1,
|
|
85
|
-
'data-garden-version': '8.69.
|
|
85
|
+
'data-garden-version': '8.69.5'
|
|
86
86
|
}).withConfig({
|
|
87
87
|
displayName: "StyledTabPanel",
|
|
88
88
|
componentId: "sc-7lhrmp-0"
|
|
@@ -100,7 +100,7 @@ const verticalStyling = _ref => {
|
|
|
100
100
|
};
|
|
101
101
|
const StyledTabs = styled.div.attrs({
|
|
102
102
|
'data-garden-id': COMPONENT_ID,
|
|
103
|
-
'data-garden-version': '8.69.
|
|
103
|
+
'data-garden-version': '8.69.5'
|
|
104
104
|
}).withConfig({
|
|
105
105
|
displayName: "StyledTabs",
|
|
106
106
|
componentId: "sc-1qaor65-0"
|
|
@@ -121,21 +121,21 @@ const Tab = React.forwardRef((_ref, ref) => {
|
|
|
121
121
|
...otherProps
|
|
122
122
|
} = _ref;
|
|
123
123
|
const tabsPropGetters = useTabsContext();
|
|
124
|
-
const tabRef = React.createRef();
|
|
125
124
|
if (disabled || !tabsPropGetters) {
|
|
126
125
|
return React.createElement(StyledTab, _extends({
|
|
127
126
|
role: "tab",
|
|
128
127
|
"aria-disabled": disabled,
|
|
129
|
-
ref:
|
|
128
|
+
ref: ref
|
|
130
129
|
}, otherProps));
|
|
131
130
|
}
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
131
|
+
const {
|
|
132
|
+
ref: tabRef,
|
|
133
|
+
...tabProps
|
|
134
|
+
} = tabsPropGetters.getTabProps({
|
|
135
|
+
value: item
|
|
136
136
|
});
|
|
137
137
|
return React.createElement(StyledTab, _extends({
|
|
138
|
-
isSelected: item === tabsPropGetters.
|
|
138
|
+
isSelected: item === tabsPropGetters.selectedValue
|
|
139
139
|
}, tabProps, otherProps, {
|
|
140
140
|
ref: mergeRefs([tabRef, ref])
|
|
141
141
|
}));
|
|
@@ -172,11 +172,10 @@ const TabPanel = React.forwardRef((_ref, ref) => {
|
|
|
172
172
|
}, otherProps));
|
|
173
173
|
}
|
|
174
174
|
const tabPanelProps = tabsPropGetters.getTabPanelProps({
|
|
175
|
-
item
|
|
176
|
-
index: tabsPropGetters.tabPanelIndexRef.current++
|
|
175
|
+
value: item
|
|
177
176
|
});
|
|
178
177
|
return React.createElement(StyledTabPanel, _extends({
|
|
179
|
-
"aria-hidden": tabsPropGetters.
|
|
178
|
+
"aria-hidden": tabsPropGetters.selectedValue !== item
|
|
180
179
|
}, tabPanelProps, otherProps, {
|
|
181
180
|
ref: ref
|
|
182
181
|
}));
|
|
@@ -186,6 +185,23 @@ TabPanel.propTypes = {
|
|
|
186
185
|
item: PropTypes.any
|
|
187
186
|
};
|
|
188
187
|
|
|
188
|
+
const toTabs = children => Children.toArray(children).reduce((_items, child) => {
|
|
189
|
+
const retVal = _items;
|
|
190
|
+
if ( isValidElement(child) && child.type !== 'string') {
|
|
191
|
+
if (Tab === child.type && '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
|
+
|
|
189
205
|
const Tabs = forwardRef((_ref, ref) => {
|
|
190
206
|
let {
|
|
191
207
|
isVertical,
|
|
@@ -196,14 +212,14 @@ const Tabs = forwardRef((_ref, ref) => {
|
|
|
196
212
|
} = _ref;
|
|
197
213
|
const theme = useContext(ThemeContext) || DEFAULT_THEME;
|
|
198
214
|
const [internalSelectedItem, setInternalSelectedItem] = useState();
|
|
199
|
-
const tabIndexRef = useRef(0);
|
|
200
|
-
const tabPanelIndexRef = useRef(0);
|
|
201
215
|
const selectedItem = getControlledValue(controlledSelectedItem, internalSelectedItem);
|
|
202
|
-
const
|
|
216
|
+
const tabs = useMemo(() => toTabs(children), [children]);
|
|
217
|
+
const tabsContextValue = useTabs({
|
|
218
|
+
tabs,
|
|
203
219
|
rtl: theme.rtl,
|
|
204
220
|
orientation: isVertical ? 'vertical' : 'horizontal',
|
|
205
|
-
selectedItem,
|
|
206
|
-
|
|
221
|
+
selectedValue: selectedItem,
|
|
222
|
+
defaultSelectedValue: tabs.find(tab => !tab.disabled)?.value,
|
|
207
223
|
onSelect: item => {
|
|
208
224
|
if (onChange) {
|
|
209
225
|
onChange(item);
|
|
@@ -212,11 +228,6 @@ const Tabs = forwardRef((_ref, ref) => {
|
|
|
212
228
|
}
|
|
213
229
|
}
|
|
214
230
|
});
|
|
215
|
-
const tabsContextValue = useMemo(() => ({
|
|
216
|
-
...tabPropGetters,
|
|
217
|
-
tabIndexRef,
|
|
218
|
-
tabPanelIndexRef
|
|
219
|
-
}), [tabPropGetters]);
|
|
220
231
|
return React.createElement(TabsContext.Provider, {
|
|
221
232
|
value: tabsContextValue
|
|
222
233
|
}, React.createElement(StyledTabs, _extends({
|
|
@@ -0,0 +1,15 @@
|
|
|
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 { ReactNode } from 'react';
|
|
8
|
+
/**
|
|
9
|
+
* Converts an array of `Tab` children to a valid `tabs` data structure for `useTabs`.
|
|
10
|
+
*
|
|
11
|
+
* @param children The `children` prop from `Tabs`.
|
|
12
|
+
*
|
|
13
|
+
* @returns A valid `IUseTabsProps['tabs']` data structure.
|
|
14
|
+
*/
|
|
15
|
+
export declare const toTabs: (children: ReactNode) => import("@zendeskgarden/container-tabs").ITab<any>[];
|
|
@@ -4,12 +4,7 @@
|
|
|
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
|
-
|
|
7
|
+
/// <reference types="react" />
|
|
8
8
|
import { IUseTabsReturnValue } from '@zendeskgarden/container-tabs';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
tabPanelIndexRef: MutableRefObject<number>;
|
|
12
|
-
}
|
|
13
|
-
export declare const TabsContext: import("react").Context<ITabsContext | undefined>;
|
|
14
|
-
export declare const useTabsContext: () => ITabsContext | undefined;
|
|
15
|
-
export {};
|
|
9
|
+
export declare const TabsContext: import("react").Context<IUseTabsReturnValue<any> | undefined>;
|
|
10
|
+
export declare const useTabsContext: () => IUseTabsReturnValue<any> | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zendeskgarden/react-tabs",
|
|
3
|
-
"version": "8.69.
|
|
3
|
+
"version": "8.69.5",
|
|
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>",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"sideEffects": false,
|
|
22
22
|
"types": "dist/typings/index.d.ts",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@zendeskgarden/container-tabs": "^
|
|
24
|
+
"@zendeskgarden/container-tabs": "^2.0.1",
|
|
25
25
|
"@zendeskgarden/container-utilities": "^1.0.0",
|
|
26
26
|
"polished": "^4.0.0",
|
|
27
27
|
"prop-types": "^15.5.7",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"styled-components": "^4.2.0 || ^5.0.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@zendeskgarden/react-theming": "^8.69.
|
|
37
|
+
"@zendeskgarden/react-theming": "^8.69.5"
|
|
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": "610a2e79728debaa8ea03de256d81b83cf4e595f"
|
|
50
50
|
}
|