@planningcenter/tapestry-react 2.1.2 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Badge/Badge.js +5 -1
- package/dist/cjs/Button/Button.js +6 -3
- package/dist/cjs/Card/Card.js +5 -2
- package/dist/cjs/Combobox/Combobox.js +16 -43
- package/dist/cjs/Combobox/ComboboxInput.js +112 -146
- package/dist/cjs/Combobox/ComboboxItem.js +38 -53
- package/dist/cjs/Combobox/ComboboxItems.js +41 -58
- package/dist/cjs/Combobox/index.js +12 -0
- package/dist/cjs/DateField/DateField.js +109 -128
- package/dist/cjs/Field/Field.js +80 -106
- package/dist/cjs/Menu/Item.js +1 -0
- package/dist/cjs/Popover/utils.js +1 -0
- package/dist/cjs/SegmentedControl/SegmentedControl.js +89 -111
- package/dist/cjs/SegmentedTabs/SegmentedTabs.js +54 -84
- package/dist/cjs/Tabs/Tab.js +9 -6
- package/dist/cjs/Tabs/TabList.js +49 -64
- package/dist/cjs/Tabs/TabPanel.js +6 -2
- package/dist/cjs/Tabs/TabPanels.js +14 -27
- package/dist/cjs/Tabs/Tabs.js +72 -106
- package/dist/cjs/Tabs/index.js +12 -0
- package/dist/cjs/ThemeProvider/ThemeProvider.js +1 -1
- package/dist/cjs/Tooltip/Tooltip.js +158 -182
- package/dist/cjs/Wizard/Wizard.js +143 -193
- package/dist/cjs/Wizard/index.js +3 -0
- package/dist/esm/Badge/Badge.js +5 -1
- package/dist/esm/Button/Button.js +6 -3
- package/dist/esm/Card/Card.js +5 -2
- package/dist/esm/Combobox/Combobox.js +18 -43
- package/dist/esm/Combobox/ComboboxInput.js +111 -149
- package/dist/esm/Combobox/ComboboxItem.js +38 -52
- package/dist/esm/Combobox/ComboboxItems.js +38 -56
- package/dist/esm/Combobox/index.js +8 -0
- package/dist/esm/DateField/DateField.js +106 -133
- package/dist/esm/Field/Field.js +76 -103
- package/dist/esm/Menu/Item.js +1 -0
- package/dist/esm/Popover/utils.js +1 -0
- package/dist/esm/SegmentedControl/SegmentedControl.js +90 -114
- package/dist/esm/SegmentedTabs/SegmentedTabs.js +51 -83
- package/dist/esm/Tabs/Tab.js +8 -6
- package/dist/esm/Tabs/TabList.js +49 -66
- package/dist/esm/Tabs/TabPanel.js +4 -2
- package/dist/esm/Tabs/TabPanels.js +14 -28
- package/dist/esm/Tabs/Tabs.js +76 -120
- package/dist/esm/Tabs/index.js +8 -0
- package/dist/esm/ThemeProvider/ThemeProvider.js +1 -1
- package/dist/esm/Tooltip/Tooltip.js +154 -195
- package/dist/esm/Wizard/Wizard.js +144 -201
- package/dist/esm/Wizard/index.js +2 -0
- package/dist/types/Popover/utils.d.ts +3 -0
- package/package.json +1 -1
- package/src/.DS_Store +0 -0
- package/src/Badge/Badge.js +5 -0
- package/src/Button/Button.tsx +6 -3
- package/src/Card/Card.tsx +22 -1
- package/src/Combobox/Combobox.js +18 -32
- package/src/Combobox/Combobox.mdx +1 -0
- package/src/Combobox/Combobox.test.js +1 -1
- package/src/Combobox/ComboboxInput.js +111 -105
- package/src/Combobox/ComboboxItem.js +27 -27
- package/src/Combobox/ComboboxItems.js +38 -60
- package/src/Combobox/index.js +8 -0
- package/src/DateField/DateField.js +109 -105
- package/src/DateField/DateField.mdx +1 -0
- package/src/Field/Field.js +85 -93
- package/src/Field/Field.mdx +1 -0
- package/src/Menu/Heading.js +5 -1
- package/src/Menu/Heading.mdx +20 -0
- package/src/Menu/Item.js +13 -1
- package/src/Menu/Item.mdx +18 -0
- package/src/Menu/Menu.mdx +1 -0
- package/src/Popover/utils.ts +1 -0
- package/src/SegmentedControl/SegmentedControl.js +88 -92
- package/src/SegmentedControl/SegmentedControl.mdx +1 -0
- package/src/SegmentedTabs/SegmentedTabs.js +51 -71
- package/src/SegmentedTabs/SegmentedTabs.mdx +1 -0
- package/src/Tabs/Tab.js +3 -1
- package/src/Tabs/TabList.js +56 -62
- package/src/Tabs/TabPanel.js +2 -1
- package/src/Tabs/TabPanels.js +14 -15
- package/src/Tabs/Tabs.js +63 -84
- package/src/Tabs/Tabs.mdx +16 -17
- package/src/Tabs/index.js +8 -0
- package/src/ThemeProvider/ThemeProvider.tsx +1 -1
- package/src/Tooltip/Tooltip.js +142 -160
- package/src/Tooltip/Tooltip.mdx +1 -0
- package/src/Wizard/Wizard.js +141 -170
- package/src/Wizard/Wizard.mdx +3 -2
- package/src/Wizard/index.js +2 -0
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import React, {
|
|
2
|
+
import React, { useCallback, useState, useEffect } from 'react'
|
|
3
3
|
|
|
4
4
|
import Text from '../Text'
|
|
5
5
|
import StackView from '../StackView'
|
|
6
|
+
import { useThemeProps } from '../system'
|
|
6
7
|
|
|
7
8
|
function Tab({ isSelected, selectedColor, onSelect, ...restProps }) {
|
|
8
9
|
return (
|
|
@@ -37,33 +38,17 @@ type Props = {
|
|
|
37
38
|
tabProps: object,
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
componentDidUpdate(lastProps) {
|
|
54
|
-
if (this.props.activeTab) {
|
|
55
|
-
const lastActiveIndex = this.getActiveIndex(lastProps)
|
|
56
|
-
const nextActiveIndex = this.getActiveIndex(this.props)
|
|
57
|
-
if (
|
|
58
|
-
lastActiveIndex !== nextActiveIndex ||
|
|
59
|
-
this.state.activeIndex !== nextActiveIndex
|
|
60
|
-
) {
|
|
61
|
-
this.setState({ activeIndex: nextActiveIndex })
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
getActiveIndex({ activeTab, tabs }) {
|
|
41
|
+
function SegmentedTabs(props: Props) {
|
|
42
|
+
const {
|
|
43
|
+
activeTab,
|
|
44
|
+
color = 'primary',
|
|
45
|
+
getTabLabel = (tab) => tab,
|
|
46
|
+
onChange,
|
|
47
|
+
tabs,
|
|
48
|
+
tabProps,
|
|
49
|
+
...restProps
|
|
50
|
+
} = useThemeProps('segmentedTabs', props)
|
|
51
|
+
const getActiveIndex = useCallback(({ activeTab, tabs }) => {
|
|
67
52
|
let index
|
|
68
53
|
if (typeof activeTab === 'function') {
|
|
69
54
|
index = tabs.reduce((searchIndex, tab, index) => {
|
|
@@ -76,53 +61,48 @@ class SegmentedTabs extends Component<Props> {
|
|
|
76
61
|
index = activeTab === undefined ? 0 : tabs.indexOf(activeTab)
|
|
77
62
|
}
|
|
78
63
|
return index
|
|
79
|
-
}
|
|
64
|
+
})
|
|
65
|
+
const [activeIndex, setActiveIndex] = useState(getActiveIndex(props))
|
|
80
66
|
|
|
81
|
-
setIndex = (index) => {
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
67
|
+
const setIndex = useCallback((index) => {
|
|
68
|
+
if (activeTab === undefined) {
|
|
69
|
+
setActiveIndex(index)
|
|
70
|
+
}
|
|
71
|
+
if (onChange) {
|
|
72
|
+
onChange(tabs[index])
|
|
86
73
|
}
|
|
87
|
-
|
|
88
|
-
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
const newActiveIndex = getActiveIndex(props)
|
|
78
|
+
|
|
79
|
+
if (activeIndex !== newActiveIndex) {
|
|
80
|
+
setActiveIndex(newActiveIndex)
|
|
89
81
|
}
|
|
90
|
-
}
|
|
82
|
+
}, [activeTab])
|
|
91
83
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
index={index}
|
|
115
|
-
isSelected={index === activeIndex}
|
|
116
|
-
selectedColor={color}
|
|
117
|
-
onSelect={() => this.setIndex(index)}
|
|
118
|
-
{...tabProps}
|
|
119
|
-
>
|
|
120
|
-
{getTabLabel(tab)}
|
|
121
|
-
</Tab>
|
|
122
|
-
))}
|
|
123
|
-
</StackView>
|
|
124
|
-
)
|
|
125
|
-
}
|
|
84
|
+
return (
|
|
85
|
+
<StackView
|
|
86
|
+
role="group"
|
|
87
|
+
axis="horizontal"
|
|
88
|
+
distribution="fill"
|
|
89
|
+
position="relative"
|
|
90
|
+
{...restProps}
|
|
91
|
+
>
|
|
92
|
+
{tabs.map((tab, index) => (
|
|
93
|
+
<Tab
|
|
94
|
+
key={index}
|
|
95
|
+
index={index}
|
|
96
|
+
isSelected={index === activeIndex}
|
|
97
|
+
selectedColor={color}
|
|
98
|
+
onSelect={() => setIndex(index)}
|
|
99
|
+
{...tabProps}
|
|
100
|
+
>
|
|
101
|
+
{getTabLabel(tab)}
|
|
102
|
+
</Tab>
|
|
103
|
+
))}
|
|
104
|
+
</StackView>
|
|
105
|
+
)
|
|
126
106
|
}
|
|
127
107
|
|
|
128
108
|
export default SegmentedTabs
|
package/src/Tabs/Tab.js
CHANGED
|
@@ -3,11 +3,13 @@ import React from 'react'
|
|
|
3
3
|
|
|
4
4
|
import StackView from '../StackView'
|
|
5
5
|
import { useHover } from '../hooks'
|
|
6
|
+
import { useThemeProps } from '../system'
|
|
6
7
|
|
|
7
8
|
export type Props = { isActive?: boolean }
|
|
8
9
|
|
|
9
10
|
function Tab(props: Props) {
|
|
10
|
-
const { axis, children, disabled, id, isActive, ...restProps } =
|
|
11
|
+
const { axis, children, disabled, id, isActive, ...restProps } =
|
|
12
|
+
useThemeProps('tabs.tab', props)
|
|
11
13
|
const { hover, hoverProps } = useHover()
|
|
12
14
|
const hovered = !disabled && hover
|
|
13
15
|
const borderSize = 2
|
package/src/Tabs/TabList.js
CHANGED
|
@@ -1,73 +1,67 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import React, {
|
|
2
|
+
import React, { Children, cloneElement } from 'react'
|
|
3
3
|
|
|
4
4
|
import StackView from '../StackView'
|
|
5
|
+
import { useThemeProps } from '../system'
|
|
5
6
|
|
|
6
7
|
export const TABLIST_DISPLAY_NAME = 'TabList'
|
|
7
8
|
|
|
8
9
|
type Props = { activeIndex?: number }
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
moveTabFocus(Children.count(children) - 1)
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
})
|
|
67
|
-
)}
|
|
68
|
-
</StackView>
|
|
69
|
-
)
|
|
70
|
-
}
|
|
11
|
+
function TabList(props: Props) {
|
|
12
|
+
const {
|
|
13
|
+
activeIndex,
|
|
14
|
+
axis = 'horizontal',
|
|
15
|
+
children,
|
|
16
|
+
id,
|
|
17
|
+
moveTabFocus,
|
|
18
|
+
setActiveIndex,
|
|
19
|
+
...restProps
|
|
20
|
+
} = useThemeProps('tabs.tabList', props)
|
|
21
|
+
const backwardKey = axis === 'horizontal' ? 'ArrowLeft' : 'ArrowUp'
|
|
22
|
+
const forwardKey = axis === 'horizontal' ? 'ArrowRight' : 'ArrowDown'
|
|
23
|
+
return (
|
|
24
|
+
<StackView
|
|
25
|
+
role="tablist"
|
|
26
|
+
aria-orientation={axis}
|
|
27
|
+
axis={axis}
|
|
28
|
+
distribution="fill"
|
|
29
|
+
{...restProps}
|
|
30
|
+
>
|
|
31
|
+
{Children.map(children, (child, index) =>
|
|
32
|
+
cloneElement(child, {
|
|
33
|
+
axis,
|
|
34
|
+
id: `${id}-${index}`,
|
|
35
|
+
isActive: index === activeIndex,
|
|
36
|
+
tabIndex: child.props.disabled
|
|
37
|
+
? undefined
|
|
38
|
+
: index !== activeIndex
|
|
39
|
+
? -1
|
|
40
|
+
: 0,
|
|
41
|
+
onFocus: () => setActiveIndex(index),
|
|
42
|
+
onKeyDown: (event) => {
|
|
43
|
+
if (event.key === backwardKey) {
|
|
44
|
+
event.preventDefault()
|
|
45
|
+
moveTabFocus(-1)
|
|
46
|
+
}
|
|
47
|
+
if (event.key === forwardKey) {
|
|
48
|
+
event.preventDefault()
|
|
49
|
+
moveTabFocus(1)
|
|
50
|
+
}
|
|
51
|
+
if (event.key === 'Home') {
|
|
52
|
+
event.preventDefault()
|
|
53
|
+
moveTabFocus(0)
|
|
54
|
+
}
|
|
55
|
+
if (event.key === 'End') {
|
|
56
|
+
event.preventDefault()
|
|
57
|
+
moveTabFocus(Children.count(children) - 1)
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
})
|
|
61
|
+
)}
|
|
62
|
+
</StackView>
|
|
63
|
+
)
|
|
71
64
|
}
|
|
72
65
|
|
|
66
|
+
TabList.displayName = TABLIST_DISPLAY_NAME
|
|
73
67
|
export default TabList
|
package/src/Tabs/TabPanel.js
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
import React from 'react'
|
|
3
3
|
|
|
4
4
|
import Box from '../Box'
|
|
5
|
+
import { useThemeProps } from '../system'
|
|
5
6
|
|
|
6
7
|
export type Props = { activeId?: any }
|
|
7
8
|
|
|
8
9
|
function TabPanel(props: Props) {
|
|
9
|
-
const { activeId, ...restProps } = props
|
|
10
|
+
const { activeId, ...restProps } = useThemeProps('tabs.tabPanel', props)
|
|
10
11
|
return (
|
|
11
12
|
<Box
|
|
12
13
|
role="tabpanel"
|
package/src/Tabs/TabPanels.js
CHANGED
|
@@ -1,26 +1,25 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import React, {
|
|
2
|
+
import React, { cloneElement } from 'react'
|
|
3
3
|
|
|
4
4
|
import Box from '../Box'
|
|
5
|
+
import { useThemeProps } from '../system'
|
|
5
6
|
|
|
6
7
|
export const TABPANELS_DISPLAY_NAME = 'TabPanels'
|
|
7
8
|
|
|
8
9
|
type Props = { activeIndex?: number }
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
</Box>
|
|
22
|
-
)
|
|
23
|
-
}
|
|
11
|
+
function TabPanels(props: Props) {
|
|
12
|
+
const { activeIndex, children, id, ...restProps } = useThemeProps(
|
|
13
|
+
'tabs.tabPanels',
|
|
14
|
+
props
|
|
15
|
+
)
|
|
16
|
+
const child = children[activeIndex]
|
|
17
|
+
return (
|
|
18
|
+
<Box {...restProps}>
|
|
19
|
+
{child ? cloneElement(child, { activeId: `${id}-${activeIndex}` }) : null}
|
|
20
|
+
</Box>
|
|
21
|
+
)
|
|
24
22
|
}
|
|
25
23
|
|
|
24
|
+
TabPanels.displayName = TABPANELS_DISPLAY_NAME
|
|
26
25
|
export default TabPanels
|
package/src/Tabs/Tabs.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import React, {
|
|
2
|
+
import React, { useState, useRef, useCallback, Children } from 'react'
|
|
3
3
|
|
|
4
4
|
import StackView from '../StackView'
|
|
5
5
|
import { generateId } from '../utils'
|
|
6
|
+
import { useThemeProps } from '../system'
|
|
6
7
|
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import TabPanel from './TabPanel'
|
|
10
|
-
import TabPanels, { TABPANELS_DISPLAY_NAME } from './TabPanels'
|
|
8
|
+
import { TABLIST_DISPLAY_NAME } from './TabList'
|
|
9
|
+
import { TABPANELS_DISPLAY_NAME } from './TabPanels'
|
|
11
10
|
|
|
12
11
|
type Props = {
|
|
13
12
|
/**
|
|
@@ -31,103 +30,83 @@ type Props = {
|
|
|
31
30
|
onChange?: Function,
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
state = {
|
|
51
|
-
activeIndex: this.props.defaultActiveIndex,
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
setTabList = (node) => {
|
|
55
|
-
if (node) {
|
|
56
|
-
this.tabList = node.querySelector('[role="tablist"]')
|
|
33
|
+
function Tabs(props: Props) {
|
|
34
|
+
const {
|
|
35
|
+
activeIndex = null,
|
|
36
|
+
children,
|
|
37
|
+
defaultActiveIndex = 0,
|
|
38
|
+
onChange,
|
|
39
|
+
...restProps
|
|
40
|
+
} = useThemeProps('tabs', props)
|
|
41
|
+
|
|
42
|
+
const id = generateId('tabs')
|
|
43
|
+
const [localActiveIndex, setLocalActiveIndex] = useState(defaultActiveIndex)
|
|
44
|
+
const tabListRef = useRef(null)
|
|
45
|
+
|
|
46
|
+
const setActiveIndex = useCallback((index) => {
|
|
47
|
+
if (onChange) {
|
|
48
|
+
onChange(index)
|
|
57
49
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
setActiveIndex = (activeIndex) => {
|
|
61
|
-
if (this.props.onChange) {
|
|
62
|
-
this.props.onChange(activeIndex)
|
|
50
|
+
if (activeIndex === null) {
|
|
51
|
+
setLocalActiveIndex(index)
|
|
63
52
|
}
|
|
64
|
-
|
|
65
|
-
this.setState({ activeIndex })
|
|
66
|
-
}
|
|
67
|
-
}
|
|
53
|
+
})
|
|
68
54
|
|
|
69
|
-
getActiveIndex = () => {
|
|
70
|
-
return
|
|
71
|
-
|
|
72
|
-
: this.props.activeIndex
|
|
73
|
-
}
|
|
55
|
+
const getActiveIndex = useCallback(() => {
|
|
56
|
+
return activeIndex === null ? localActiveIndex : activeIndex
|
|
57
|
+
})
|
|
74
58
|
|
|
75
|
-
getNextTab = (startIndex, direction) => {
|
|
76
|
-
const tabCount =
|
|
59
|
+
const getNextTab = useCallback((startIndex, direction) => {
|
|
60
|
+
const tabCount = tabListRef.current.children.length
|
|
77
61
|
let nextIndex = startIndex + direction
|
|
78
62
|
if (nextIndex < 0) {
|
|
79
63
|
nextIndex = tabCount - 1
|
|
80
64
|
} else if (nextIndex >= tabCount) {
|
|
81
65
|
nextIndex = 0
|
|
82
66
|
}
|
|
83
|
-
const nextTab =
|
|
67
|
+
const nextTab = tabListRef.current.children[nextIndex]
|
|
84
68
|
if (nextTab.getAttribute('aria-disabled') === 'true') {
|
|
85
|
-
return
|
|
69
|
+
return getNextTab(nextIndex, direction)
|
|
86
70
|
} else {
|
|
87
71
|
return nextTab
|
|
88
72
|
}
|
|
89
|
-
}
|
|
73
|
+
})
|
|
90
74
|
|
|
91
|
-
moveTabFocus = (direction) => {
|
|
92
|
-
const nextTab =
|
|
75
|
+
const moveTabFocus = useCallback((direction) => {
|
|
76
|
+
const nextTab = getNextTab(getActiveIndex(), direction)
|
|
93
77
|
if (nextTab) {
|
|
94
78
|
nextTab.focus()
|
|
95
79
|
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
)
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
})}
|
|
128
|
-
</StackView>
|
|
129
|
-
)
|
|
130
|
-
}
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<StackView
|
|
84
|
+
innerRef={(node) => {
|
|
85
|
+
if (node) {
|
|
86
|
+
tabListRef.current = node.querySelector('[role="tablist"]')
|
|
87
|
+
}
|
|
88
|
+
}}
|
|
89
|
+
{...restProps}
|
|
90
|
+
>
|
|
91
|
+
{Children.map(children, (child, index) => {
|
|
92
|
+
if (child && child.type.displayName === TABLIST_DISPLAY_NAME) {
|
|
93
|
+
return React.cloneElement(child, {
|
|
94
|
+
id,
|
|
95
|
+
activeIndex: getActiveIndex(),
|
|
96
|
+
moveTabFocus,
|
|
97
|
+
setActiveIndex,
|
|
98
|
+
})
|
|
99
|
+
} else if (child && child.type.displayName === TABPANELS_DISPLAY_NAME) {
|
|
100
|
+
return React.cloneElement(child, {
|
|
101
|
+
id,
|
|
102
|
+
activeIndex: getActiveIndex(),
|
|
103
|
+
})
|
|
104
|
+
} else {
|
|
105
|
+
return child
|
|
106
|
+
}
|
|
107
|
+
})}
|
|
108
|
+
</StackView>
|
|
109
|
+
)
|
|
131
110
|
}
|
|
132
111
|
|
|
133
112
|
export default Tabs
|
package/src/Tabs/Tabs.mdx
CHANGED
|
@@ -3,48 +3,47 @@ title: Tabs
|
|
|
3
3
|
category: General
|
|
4
4
|
summary: A single content area with multiple panels, each associated with a header in a list.
|
|
5
5
|
propsSummary: Accepts [StackView](/stackview) props.
|
|
6
|
+
themeKey: tabs
|
|
6
7
|
---
|
|
7
8
|
|
|
8
9
|
```jsx live
|
|
9
|
-
const { Tab, TabList, TabPanel, TabPanels } = Tabs
|
|
10
10
|
const tabs = [1, 2, 3, 4]
|
|
11
11
|
render(
|
|
12
12
|
<Tabs>
|
|
13
|
-
<TabList minWidth={60}>
|
|
13
|
+
<Tabs.TabList minWidth={60}>
|
|
14
14
|
{tabs.map((tab, index) => (
|
|
15
|
-
<Tab key={tab} disabled={index === 2}>
|
|
15
|
+
<Tabs.Tab key={tab} disabled={index === 2}>
|
|
16
16
|
Tab {tab}
|
|
17
|
-
</Tab>
|
|
17
|
+
</Tabs.Tab>
|
|
18
18
|
))}
|
|
19
|
-
</TabList>
|
|
20
|
-
<TabPanels>
|
|
19
|
+
</Tabs.TabList>
|
|
20
|
+
<Tabs.TabPanels>
|
|
21
21
|
{tabs.map((tab) => (
|
|
22
|
-
<TabPanel key={tab} padding={2}>
|
|
22
|
+
<Tabs.TabPanel key={tab} padding={2}>
|
|
23
23
|
Content for tab {tab}
|
|
24
|
-
</TabPanel>
|
|
24
|
+
</Tabs.TabPanel>
|
|
25
25
|
))}
|
|
26
|
-
</TabPanels>
|
|
26
|
+
</Tabs.TabPanels>
|
|
27
27
|
</Tabs>
|
|
28
28
|
)
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
```jsx live
|
|
32
|
-
const { Tab, TabList, TabPanel, TabPanels } = Tabs
|
|
33
32
|
const tabs = [1, 2, 3, 4]
|
|
34
33
|
render(
|
|
35
34
|
<Card as={Tabs} axis="horizontal">
|
|
36
|
-
<TabList axis="vertical" distribution="start" minWidth={20}>
|
|
35
|
+
<Tabs.TabList axis="vertical" distribution="start" minWidth={20}>
|
|
37
36
|
{tabs.map((tab) => (
|
|
38
|
-
<Tab key={tab}>Tab {tab}</Tab>
|
|
37
|
+
<Tabs.Tab key={tab}>Tab {tab}</Tabs.Tab>
|
|
39
38
|
))}
|
|
40
|
-
</TabList>
|
|
41
|
-
<TabPanels>
|
|
39
|
+
</Tabs.TabList>
|
|
40
|
+
<Tabs.TabPanels>
|
|
42
41
|
{tabs.map((tab) => (
|
|
43
|
-
<TabPanel key={tab} padding={2}>
|
|
42
|
+
<Tabs.TabPanel key={tab} padding={2}>
|
|
44
43
|
Content for tab {tab}
|
|
45
|
-
</TabPanel>
|
|
44
|
+
</Tabs.TabPanel>
|
|
46
45
|
))}
|
|
47
|
-
</TabPanels>
|
|
46
|
+
</Tabs.TabPanels>
|
|
48
47
|
</Card>
|
|
49
48
|
)
|
|
50
49
|
```
|
package/src/Tabs/index.js
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
1
1
|
import Tabs from './Tabs'
|
|
2
|
+
import Tab from './Tab'
|
|
3
|
+
import TabList from './TabList'
|
|
4
|
+
import TabPanel from './TabPanel'
|
|
5
|
+
import TabPanels from './TabPanels'
|
|
6
|
+
Tabs.Tab = Tab
|
|
7
|
+
Tabs.TabList = TabList
|
|
8
|
+
Tabs.TabPanel = TabPanel
|
|
9
|
+
Tabs.TabPanels = TabPanels
|
|
2
10
|
export default Tabs
|