@targetprocess/tabs 12.20.1-alpha.2 → 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/CHANGELOG.md CHANGED
@@ -1,45 +1,45 @@
1
- #### v7.5.0
2
-
3
- - `activeTabId` property behavior fixed
4
- - Open first tab in controlled mode if there are no tabs with provided `activeTabId`
5
- - Open first tab in controlled mode if `activeTabId` is not provided
6
-
7
- #### v7.4.3
8
-
9
- - `ShowMore` component uses button for now
10
-
11
- #### v7.3.6
12
-
13
- - Make `ShowMore` button bigger
14
-
15
- #### v7.2.0
16
-
17
- - Add support long list of tabs without horizontal scroll
18
- - Line animation: to and from right
19
- - Support `role`, `aria-selected`, `aria-controls`, `aria-labeledby`
20
- - Support keyboard navigation via `tab`, `shift-tab`, `enter`
21
- - `resizeThrottle` can be set via props
22
-
23
- #### v7.1.0
24
-
25
- - (breaking change) Now uses automatic style injection - no style import/`@global-import` is needed
26
-
27
- #### v2.0.1
28
-
29
- - Fix `propTypes` assignment for `Tab` component.
30
-
31
- #### v2.0.0
32
-
33
- - Removed dependency on `lodash-es`.
34
-
35
- #### v1.3.0
36
-
37
- - `Tabs.Tab` component `header` prop now accepts a function with `{onResize}` as argument. This way, header renderer can notify tabs list that current active tab slider should be adjusted:
38
-
39
- ```jsx
40
- <Tabs>
41
- <Tabs.Tab header={({onResize}) => <SomeComplexTabHeaderComponent onContentChanged={onResize} />}>
42
- {/* tab content here */}
43
- </Tabs.Tab>
44
- </Tabs>
45
- ```
1
+ #### v7.5.0
2
+
3
+ - `activeTabId` property behavior fixed
4
+ - Open first tab in controlled mode if there are no tabs with provided `activeTabId`
5
+ - Open first tab in controlled mode if `activeTabId` is not provided
6
+
7
+ #### v7.4.3
8
+
9
+ - `ShowMore` component uses button for now
10
+
11
+ #### v7.3.6
12
+
13
+ - Make `ShowMore` button bigger
14
+
15
+ #### v7.2.0
16
+
17
+ - Add support long list of tabs without horizontal scroll
18
+ - Line animation: to and from right
19
+ - Support `role`, `aria-selected`, `aria-controls`, `aria-labeledby`
20
+ - Support keyboard navigation via `tab`, `shift-tab`, `enter`
21
+ - `resizeThrottle` can be set via props
22
+
23
+ #### v7.1.0
24
+
25
+ - (breaking change) Now uses automatic style injection - no style import/`@global-import` is needed
26
+
27
+ #### v2.0.1
28
+
29
+ - Fix `propTypes` assignment for `Tab` component.
30
+
31
+ #### v2.0.0
32
+
33
+ - Removed dependency on `lodash-es`.
34
+
35
+ #### v1.3.0
36
+
37
+ - `Tabs.Tab` component `header` prop now accepts a function with `{onResize}` as argument. This way, header renderer can notify tabs list that current active tab slider should be adjusted:
38
+
39
+ ```jsx
40
+ <Tabs>
41
+ <Tabs.Tab header={({onResize}) => <SomeComplexTabHeaderComponent onContentChanged={onResize} />}>
42
+ {/* tab content here */}
43
+ </Tabs.Tab>
44
+ </Tabs>
45
+ ```
package/README.md CHANGED
@@ -1,15 +1,15 @@
1
- # `@targetprocess/tabs`
2
-
3
- ### Testing
4
-
5
- If your test environment is based on JSDOM, you will need to manually mock `ResizeObserver` for tests that render tabs component:
6
-
7
- ```js
8
- // this can be in your jest.setup.js/beforeAll/other test env init script where JSDOM is available
9
-
10
- window.ResizeObserver = class ResizeObserver {
11
- observe() {}
12
- unobserve() {}
13
- disconnect() {}
14
- }
15
- ```
1
+ # `@targetprocess/tabs`
2
+
3
+ ### Testing
4
+
5
+ If your test environment is based on JSDOM, you will need to manually mock `ResizeObserver` for tests that render tabs component:
6
+
7
+ ```js
8
+ // this can be in your jest.setup.js/beforeAll/other test env init script where JSDOM is available
9
+
10
+ window.ResizeObserver = class ResizeObserver {
11
+ observe() {}
12
+ unobserve() {}
13
+ disconnect() {}
14
+ }
15
+ ```
package/ShowMore.jsx CHANGED
@@ -1,152 +1,152 @@
1
- import React from 'react'
2
- import classNames from 'classnames'
3
- import PropTypes from 'prop-types'
4
- import {ChevronIcon} from '@targetprocess/icons'
5
- import {Button} from '@targetprocess/button'
6
- import styles from './style/index.css'
7
- import Popover from '@targetprocess/popover'
8
- import {showMorePopoverProps} from './shared-proptype'
9
-
10
- export default class ShowMore extends React.Component {
11
- static propTypes = {
12
- children: PropTypes.node,
13
- hasChildSelected: PropTypes.bool,
14
- onShowMoreChanged: PropTypes.func,
15
- showMorePopoverClassName: PropTypes.string,
16
- showMorePopoverProps: showMorePopoverProps
17
- }
18
-
19
- static defaultProps = {
20
- children: null,
21
- hasChildSelected: false,
22
- onShowMoreChanged: () => null
23
- }
24
-
25
- state = {
26
- isFocused: false,
27
- isHidden: true
28
- }
29
-
30
- componentWillMount() {
31
- if (typeof window !== 'undefined') {
32
- window.addEventListener('click', this.close)
33
- window.addEventListener('keydown', this.onKeyDown)
34
- }
35
- }
36
-
37
- shouldComponentUpdate(nextProps, nextState) {
38
- const {children, hasChildSelected} = this.props
39
- return (
40
- children.length !== nextProps.children.length ||
41
- hasChildSelected !== nextProps.hasChildSelected ||
42
- this.state !== nextState
43
- )
44
- }
45
-
46
- componentWillUnmount() {
47
- if (typeof window !== 'undefined') {
48
- window.removeEventListener('click', this.close)
49
- window.removeEventListener('keydown', this.onKeyDown)
50
- }
51
- }
52
-
53
- onFocus = () => this.setState({isFocused: true})
54
-
55
- onBlur = () => this.setState({isFocused: false})
56
-
57
- onKeyDown = event => {
58
- const {isFocused, isHidden} = this.state
59
- if (event.key === 'Enter') {
60
- if (isFocused) {
61
- this.setState({isHidden: !isHidden})
62
- } else if (!isHidden) {
63
- this.setState({isHidden: true})
64
- }
65
- }
66
- }
67
-
68
- close = () => {
69
- const {isHidden} = this.state
70
- if (!isHidden) {
71
- this.setState({isHidden: true})
72
- }
73
- }
74
-
75
- toggleVisibility = event => {
76
- event.stopPropagation()
77
- this.setState(({isHidden}) => ({isHidden: !isHidden}))
78
- }
79
-
80
- getShowMorePopoverProps = () => {
81
- const popoverProps = {
82
- ...this.props.showMorePopoverProps
83
- }
84
-
85
- if (this.props.showMorePopoverProps && this.props.showMorePopoverProps.getContainerElement) {
86
- showMorePopoverProps.trackScroll = false
87
- }
88
-
89
- return popoverProps
90
- }
91
-
92
- render() {
93
- const {children, onShowMoreChanged, hasChildSelected} = this.props
94
- const {isHidden} = this.state
95
-
96
- if (!children || !children.length) {
97
- return null
98
- }
99
-
100
- const isListHidden = isHidden
101
-
102
- const listStyles = classNames(
103
- styles['tabs__header__tabs__showmore-menu'],
104
- !isListHidden && styles['tabs__header__tabs__showmore-menu--opened'],
105
- this.props.showMorePopoverClassName
106
- )
107
-
108
- const showMoreLabelStyles = classNames(
109
- styles['tabs__header__tabs__showmore__label'],
110
- hasChildSelected && styles['tabs__header__tabs__showmore__label--selected'],
111
- !isListHidden && styles['tabs__header__tabs__showmore__label--selected']
112
- )
113
-
114
- return (
115
- <Popover
116
- {...this.getShowMorePopoverProps()}
117
- className={styles['tabs__header']}
118
- getPopoverPosition="bottomRight"
119
- preferPlace="below"
120
- isOpen={!isListHidden}
121
- onOuterAction={this.close}
122
- body={
123
- <div className={listStyles} aria-hidden={isListHidden} role="tablist">
124
- {children}
125
- </div>
126
- }
127
- >
128
- <div
129
- className={styles.tabs__header__tabs__showmore__wrapper}
130
- role="tab"
131
- aria-label="More tabs"
132
- >
133
- <Button
134
- ref={onShowMoreChanged}
135
- onFocus={this.onFocus}
136
- role="navigation"
137
- onBlur={this.onBlur}
138
- onClick={this.toggleVisibility}
139
- checked={!isListHidden}
140
- className={showMoreLabelStyles}
141
- icon={<ChevronIcon />}
142
- kind="default"
143
- size="L"
144
- data-title="More tabs"
145
- noBackground
146
- isWide
147
- />
148
- </div>
149
- </Popover>
150
- )
151
- }
152
- }
1
+ import React from 'react'
2
+ import classNames from 'classnames'
3
+ import PropTypes from 'prop-types'
4
+ import {ChevronIcon} from '@targetprocess/icons'
5
+ import {Button} from '@targetprocess/button'
6
+ import styles from './style/index.css'
7
+ import Popover from '@targetprocess/popover'
8
+ import {showMorePopoverProps} from './shared-proptype'
9
+
10
+ export default class ShowMore extends React.Component {
11
+ static propTypes = {
12
+ children: PropTypes.node,
13
+ hasChildSelected: PropTypes.bool,
14
+ onShowMoreChanged: PropTypes.func,
15
+ showMorePopoverClassName: PropTypes.string,
16
+ showMorePopoverProps: showMorePopoverProps
17
+ }
18
+
19
+ static defaultProps = {
20
+ children: null,
21
+ hasChildSelected: false,
22
+ onShowMoreChanged: () => null
23
+ }
24
+
25
+ state = {
26
+ isFocused: false,
27
+ isHidden: true
28
+ }
29
+
30
+ componentWillMount() {
31
+ if (typeof window !== 'undefined') {
32
+ window.addEventListener('click', this.close)
33
+ window.addEventListener('keydown', this.onKeyDown)
34
+ }
35
+ }
36
+
37
+ shouldComponentUpdate(nextProps, nextState) {
38
+ const {children, hasChildSelected} = this.props
39
+ return (
40
+ children.length !== nextProps.children.length ||
41
+ hasChildSelected !== nextProps.hasChildSelected ||
42
+ this.state !== nextState
43
+ )
44
+ }
45
+
46
+ componentWillUnmount() {
47
+ if (typeof window !== 'undefined') {
48
+ window.removeEventListener('click', this.close)
49
+ window.removeEventListener('keydown', this.onKeyDown)
50
+ }
51
+ }
52
+
53
+ onFocus = () => this.setState({isFocused: true})
54
+
55
+ onBlur = () => this.setState({isFocused: false})
56
+
57
+ onKeyDown = event => {
58
+ const {isFocused, isHidden} = this.state
59
+ if (event.key === 'Enter') {
60
+ if (isFocused) {
61
+ this.setState({isHidden: !isHidden})
62
+ } else if (!isHidden) {
63
+ this.setState({isHidden: true})
64
+ }
65
+ }
66
+ }
67
+
68
+ close = () => {
69
+ const {isHidden} = this.state
70
+ if (!isHidden) {
71
+ this.setState({isHidden: true})
72
+ }
73
+ }
74
+
75
+ toggleVisibility = event => {
76
+ event.stopPropagation()
77
+ this.setState(({isHidden}) => ({isHidden: !isHidden}))
78
+ }
79
+
80
+ getShowMorePopoverProps = () => {
81
+ const popoverProps = {
82
+ ...this.props.showMorePopoverProps
83
+ }
84
+
85
+ if (this.props.showMorePopoverProps && this.props.showMorePopoverProps.getContainerElement) {
86
+ showMorePopoverProps.trackScroll = false
87
+ }
88
+
89
+ return popoverProps
90
+ }
91
+
92
+ render() {
93
+ const {children, onShowMoreChanged, hasChildSelected} = this.props
94
+ const {isHidden} = this.state
95
+
96
+ if (!children || !children.length) {
97
+ return null
98
+ }
99
+
100
+ const isListHidden = isHidden
101
+
102
+ const listStyles = classNames(
103
+ styles['tabs__header__tabs__showmore-menu'],
104
+ !isListHidden && styles['tabs__header__tabs__showmore-menu--opened'],
105
+ this.props.showMorePopoverClassName
106
+ )
107
+
108
+ const showMoreLabelStyles = classNames(
109
+ styles['tabs__header__tabs__showmore__label'],
110
+ hasChildSelected && styles['tabs__header__tabs__showmore__label--selected'],
111
+ !isListHidden && styles['tabs__header__tabs__showmore__label--selected']
112
+ )
113
+
114
+ return (
115
+ <Popover
116
+ {...this.getShowMorePopoverProps()}
117
+ className={styles['tabs__header']}
118
+ getPopoverPosition="bottomRight"
119
+ preferPlace="below"
120
+ isOpen={!isListHidden}
121
+ onOuterAction={this.close}
122
+ body={
123
+ <div className={listStyles} aria-hidden={isListHidden} role="tablist">
124
+ {children}
125
+ </div>
126
+ }
127
+ >
128
+ <div
129
+ className={styles.tabs__header__tabs__showmore__wrapper}
130
+ role="tab"
131
+ aria-label="More tabs"
132
+ >
133
+ <Button
134
+ ref={onShowMoreChanged}
135
+ onFocus={this.onFocus}
136
+ role="navigation"
137
+ onBlur={this.onBlur}
138
+ onClick={this.toggleVisibility}
139
+ checked={!isListHidden}
140
+ className={showMoreLabelStyles}
141
+ icon={<ChevronIcon />}
142
+ kind="default"
143
+ size="L"
144
+ data-title="More tabs"
145
+ noBackground
146
+ isWide
147
+ />
148
+ </div>
149
+ </Popover>
150
+ )
151
+ }
152
+ }
package/TabInner.jsx CHANGED
@@ -1,90 +1,90 @@
1
- import React from 'react'
2
- import PropTypes from 'prop-types'
3
-
4
- function onTabClick(selected, onClick, originalKey) {
5
- return () => !selected && onClick(originalKey)
6
- }
7
-
8
- export default class TabInner extends React.Component {
9
- static propTypes = {
10
- children: PropTypes.node,
11
- disabled: PropTypes.bool,
12
-
13
- // generic props
14
- panelId: PropTypes.string.isRequired,
15
- selected: PropTypes.bool.isRequired,
16
- onClick: PropTypes.func.isRequired,
17
- getOnFocusCallback: PropTypes.func.isRequired,
18
- onBlur: PropTypes.func.isRequired,
19
- id: PropTypes.string.isRequired,
20
- originalKey: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
21
- classNames: PropTypes.string.isRequired
22
- }
23
-
24
- static defaultProps = {
25
- children: null,
26
- disabled: false
27
- }
28
-
29
- shouldComponentUpdate(nextProps) {
30
- return (
31
- this.props.children !== nextProps.children ||
32
- this.props.selected !== nextProps.selected ||
33
- this.props.classNames !== nextProps.classNames
34
- )
35
- }
36
- componentDidMount() {
37
- if (this.props.firstElement) {
38
- this.tab.focus()
39
- }
40
- }
41
-
42
- blurHandler = () => {
43
- window.requestAnimationFrame(() => {
44
- if (this.tab) {
45
- this.tab.blur()
46
- }
47
- })
48
- }
49
-
50
- renderTab = () => {
51
- const {children} = this.props
52
-
53
- return children
54
- }
55
-
56
- render() {
57
- const {
58
- id,
59
- selected,
60
- disabled,
61
- panelId,
62
- onClick,
63
- getOnFocusCallback,
64
- onBlur,
65
- originalKey,
66
- classNames
67
- } = this.props
68
-
69
- return (
70
- <div
71
- ref={tab => (this.tab = tab)}
72
- role="tab"
73
- id={id}
74
- className={classNames}
75
- aria-selected={selected}
76
- aria-expanded={selected}
77
- aria-disabled={disabled}
78
- aria-controls={panelId}
79
- tabIndex="0"
80
- onClick={onTabClick(selected, onClick, originalKey)}
81
- onFocus={getOnFocusCallback(originalKey)}
82
- onBlur={onBlur}
83
- onMouseLeave={this.blurHandler}
84
- onMouseUp={this.blurHandler}
85
- >
86
- <div>{this.renderTab()}</div>
87
- </div>
88
- )
89
- }
90
- }
1
+ import React from 'react'
2
+ import PropTypes from 'prop-types'
3
+
4
+ function onTabClick(selected, onClick, originalKey) {
5
+ return () => !selected && onClick(originalKey)
6
+ }
7
+
8
+ export default class TabInner extends React.Component {
9
+ static propTypes = {
10
+ children: PropTypes.node,
11
+ disabled: PropTypes.bool,
12
+
13
+ // generic props
14
+ panelId: PropTypes.string.isRequired,
15
+ selected: PropTypes.bool.isRequired,
16
+ onClick: PropTypes.func.isRequired,
17
+ getOnFocusCallback: PropTypes.func.isRequired,
18
+ onBlur: PropTypes.func.isRequired,
19
+ id: PropTypes.string.isRequired,
20
+ originalKey: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
21
+ classNames: PropTypes.string.isRequired
22
+ }
23
+
24
+ static defaultProps = {
25
+ children: null,
26
+ disabled: false
27
+ }
28
+
29
+ shouldComponentUpdate(nextProps) {
30
+ return (
31
+ this.props.children !== nextProps.children ||
32
+ this.props.selected !== nextProps.selected ||
33
+ this.props.classNames !== nextProps.classNames
34
+ )
35
+ }
36
+ componentDidMount() {
37
+ if (this.props.firstElement) {
38
+ this.tab.focus()
39
+ }
40
+ }
41
+
42
+ blurHandler = () => {
43
+ window.requestAnimationFrame(() => {
44
+ if (this.tab) {
45
+ this.tab.blur()
46
+ }
47
+ })
48
+ }
49
+
50
+ renderTab = () => {
51
+ const {children} = this.props
52
+
53
+ return children
54
+ }
55
+
56
+ render() {
57
+ const {
58
+ id,
59
+ selected,
60
+ disabled,
61
+ panelId,
62
+ onClick,
63
+ getOnFocusCallback,
64
+ onBlur,
65
+ originalKey,
66
+ classNames
67
+ } = this.props
68
+
69
+ return (
70
+ <div
71
+ ref={tab => (this.tab = tab)}
72
+ role="tab"
73
+ id={id}
74
+ className={classNames}
75
+ aria-selected={selected}
76
+ aria-expanded={selected}
77
+ aria-disabled={disabled}
78
+ aria-controls={panelId}
79
+ tabIndex="0"
80
+ onClick={onTabClick(selected, onClick, originalKey)}
81
+ onFocus={getOnFocusCallback(originalKey)}
82
+ onBlur={onBlur}
83
+ onMouseLeave={this.blurHandler}
84
+ onMouseUp={this.blurHandler}
85
+ >
86
+ <div>{this.renderTab()}</div>
87
+ </div>
88
+ )
89
+ }
90
+ }
package/TabPanel.jsx CHANGED
@@ -1,27 +1,27 @@
1
- import React from 'react'
2
- import PropTypes from 'prop-types'
3
-
4
- export const TabPanel = props => {
5
- const {id, tabId, children, hidden = false} = props
6
-
7
- return (
8
- <div
9
- role="tabpanel"
10
- id={id}
11
- aria-labelledby={tabId}
12
- aria-hidden={hidden}
13
- style={hidden ? {display: 'none'} : {}}
14
- >
15
- {children}
16
- </div>
17
- )
18
- }
19
-
20
- TabPanel.propTypes = {
21
- children: PropTypes.node,
22
- id: PropTypes.string.isRequired,
23
-
24
- // generic props
25
- tabId: PropTypes.string.isRequired,
26
- hidden: PropTypes.bool
27
- }
1
+ import React from 'react'
2
+ import PropTypes from 'prop-types'
3
+
4
+ export const TabPanel = props => {
5
+ const {id, tabId, children, hidden = false} = props
6
+
7
+ return (
8
+ <div
9
+ role="tabpanel"
10
+ id={id}
11
+ aria-labelledby={tabId}
12
+ aria-hidden={hidden}
13
+ style={hidden ? {display: 'none'} : {}}
14
+ >
15
+ {children}
16
+ </div>
17
+ )
18
+ }
19
+
20
+ TabPanel.propTypes = {
21
+ children: PropTypes.node,
22
+ id: PropTypes.string.isRequired,
23
+
24
+ // generic props
25
+ tabId: PropTypes.string.isRequired,
26
+ hidden: PropTypes.bool
27
+ }