@targetprocess/tabs 12.20.1-alpha.4 → 12.20.2-alpha.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/TabsPrint.jsx CHANGED
@@ -1,95 +1,95 @@
1
- import React from 'react'
2
- import classNames from 'classnames'
3
- import {TabPanel} from './TabPanel'
4
- import TabInner from './TabInner'
5
- import styles from './style/index.css'
6
- import {Tab} from './Tabs'
7
-
8
- const tabPrefix = 'tab-'
9
- const panelPrefix = 'panel-'
10
-
11
- const getTabs = allTabs =>
12
- allTabs.reduce(
13
- (result, item) => {
14
- const {id, header, children, disabled} = item.props
15
- const payload = {tabIndex: result.tabIndex, disabled, id}
16
- const tabPayload = {
17
- ...payload,
18
- header
19
- }
20
-
21
- const panelPayload = {
22
- ...payload,
23
- children
24
- }
25
-
26
- result.headers.push(tabPayload)
27
- result.panels.set(id, panelPayload)
28
- result.tabIndex += 1
29
-
30
- return result
31
- },
32
- {
33
- headers: [],
34
- panels: new Map(),
35
- tabIndex: 0
36
- }
37
- )
38
-
39
- const renderTabHeader = headerProp => {
40
- const isRenderProp = typeof headerProp === 'function'
41
- if (!isRenderProp) {
42
- return headerProp
43
- }
44
-
45
- return headerProp({
46
- onResize: () => {}
47
- })
48
- }
49
-
50
- const getTabProps = ({header, id, selected, tabIndex, disabled}) => ({
51
- selected,
52
- tabIndex,
53
- children: renderTabHeader(header),
54
- key: tabPrefix + id,
55
- id: tabPrefix + id,
56
- originalKey: id,
57
- onClick: () => {},
58
- getOnFocusCallback: () => {},
59
- onBlur: () => {},
60
- panelId: panelPrefix + id,
61
- classNames: classNames(
62
- styles['tabs__header__tab-item'],
63
- selected && styles['tabs__header__tab-item--active'],
64
- disabled && styles['tabs__header__tab-item--disabled']
65
- )
66
- })
67
-
68
- const getPanelProps = ({id, children}) => ({
69
- children,
70
- key: panelPrefix + id,
71
- id: panelPrefix + id,
72
- tabId: tabPrefix + id
73
- })
74
-
75
- export const TabsPrint = props => {
76
- const allTabs = React.Children.toArray(props.children).filter(child => child.type === Tab)
77
- const {headers, panels} = getTabs(allTabs)
78
-
79
- return (
80
- <div className={classNames(styles['tabs'], props.className)}>
81
- {Array.from(panels.values()).map(tab => (
82
- <div key={tab.id} className={styles.tab_content_page}>
83
- <div className={styles.tabs__header}>
84
- <div className={styles.tabs__header__container}>
85
- <TabInner {...getTabProps(headers.find(header => tab.id === header.id))} />
86
- </div>
87
- </div>
88
- <div className={styles.tabs__body}>
89
- <TabPanel {...getPanelProps(tab)} />
90
- </div>
91
- </div>
92
- ))}
93
- </div>
94
- )
95
- }
1
+ import React from 'react'
2
+ import classNames from 'classnames'
3
+ import {TabPanel} from './TabPanel'
4
+ import TabInner from './TabInner'
5
+ import styles from './style/index.css'
6
+ import {Tab} from './Tabs'
7
+
8
+ const tabPrefix = 'tab-'
9
+ const panelPrefix = 'panel-'
10
+
11
+ const getTabs = allTabs =>
12
+ allTabs.reduce(
13
+ (result, item) => {
14
+ const {id, header, children, disabled} = item.props
15
+ const payload = {tabIndex: result.tabIndex, disabled, id}
16
+ const tabPayload = {
17
+ ...payload,
18
+ header
19
+ }
20
+
21
+ const panelPayload = {
22
+ ...payload,
23
+ children
24
+ }
25
+
26
+ result.headers.push(tabPayload)
27
+ result.panels.set(id, panelPayload)
28
+ result.tabIndex += 1
29
+
30
+ return result
31
+ },
32
+ {
33
+ headers: [],
34
+ panels: new Map(),
35
+ tabIndex: 0
36
+ }
37
+ )
38
+
39
+ const renderTabHeader = headerProp => {
40
+ const isRenderProp = typeof headerProp === 'function'
41
+ if (!isRenderProp) {
42
+ return headerProp
43
+ }
44
+
45
+ return headerProp({
46
+ onResize: () => {}
47
+ })
48
+ }
49
+
50
+ const getTabProps = ({header, id, selected, tabIndex, disabled}) => ({
51
+ selected,
52
+ tabIndex,
53
+ children: renderTabHeader(header),
54
+ key: tabPrefix + id,
55
+ id: tabPrefix + id,
56
+ originalKey: id,
57
+ onClick: () => {},
58
+ getOnFocusCallback: () => {},
59
+ onBlur: () => {},
60
+ panelId: panelPrefix + id,
61
+ classNames: classNames(
62
+ styles['tabs__header__tab-item'],
63
+ selected && styles['tabs__header__tab-item--active'],
64
+ disabled && styles['tabs__header__tab-item--disabled']
65
+ )
66
+ })
67
+
68
+ const getPanelProps = ({id, children}) => ({
69
+ children,
70
+ key: panelPrefix + id,
71
+ id: panelPrefix + id,
72
+ tabId: tabPrefix + id
73
+ })
74
+
75
+ export const TabsPrint = props => {
76
+ const allTabs = React.Children.toArray(props.children).filter(child => child.type === Tab)
77
+ const {headers, panels} = getTabs(allTabs)
78
+
79
+ return (
80
+ <div className={classNames(styles['tabs'], props.className)}>
81
+ {Array.from(panels.values()).map(tab => (
82
+ <div key={tab.id} className={styles.tab_content_page}>
83
+ <div className={styles.tabs__header}>
84
+ <div className={styles.tabs__header__container}>
85
+ <TabInner {...getTabProps(headers.find(header => tab.id === header.id))} />
86
+ </div>
87
+ </div>
88
+ <div className={styles.tabs__body}>
89
+ <TabPanel {...getPanelProps(tab)} />
90
+ </div>
91
+ </div>
92
+ ))}
93
+ </div>
94
+ )
95
+ }