react-tab-set 2.0.120 → 2.0.122

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-tab-set",
3
- "version": "2.0.120",
3
+ "version": "2.0.122",
4
4
  "description": "A React Tab Set component",
5
5
  "main": "./src/index.mjs",
6
6
  "type": "module",
@@ -50,8 +50,8 @@
50
50
  "core-js": "^3.37.1",
51
51
  "cross-env": "^7.0.3",
52
52
  "eslint": "8.57.0",
53
+ "eslint-config-love": "47.0.0",
53
54
  "eslint-config-standard": "^17.1.0",
54
- "eslint-config-standard-with-typescript": "^43.0.1",
55
55
  "eslint-plugin-react": "^7.34.2",
56
56
  "eslint-plugin-storybook": "^0.8.0",
57
57
  "husky": "^9.0.11",
@@ -1,3 +1,6 @@
1
+ import type {
2
+ JSX
3
+ } from 'react'
1
4
  import React, {
2
5
  Children,
3
6
  cloneElement,
@@ -12,7 +15,8 @@ import debug from 'debug'
12
15
  import isTabPanel from './is-tab-panel.mts'
13
16
  import isTabGroup from './is-tab-group.mts'
14
17
 
15
- const error = debug('react-tab-set/tab-set')
18
+ const log = debug('react-tab-set/tab-set')
19
+ const error = debug('react-tab-set/tab-set:error')
16
20
 
17
21
  export interface TabSetProps {
18
22
  children: JSX.Element | JSX.Element[]
@@ -71,23 +75,35 @@ function mapChildren (
71
75
  })
72
76
  }
73
77
 
78
+ function DEFAULT_HANDLE_CHANGE (selectedTab: string): void {
79
+ log(selectedTab)
80
+ }
81
+
74
82
  export default function TabSet (props: TabSetProps): JSX.Element {
75
83
  const {
76
84
  children,
77
- selectedTab: tab
85
+ selectedTab: tab = v4()
78
86
  } = props
79
87
 
80
88
  const [selectedTab, setSelectedTab] = useState(tab)
81
89
 
82
- useEffect(() => { setSelectedTab(tab) }, [tab])
90
+ useEffect(() => {
91
+ if (selectedTab !== tab) {
92
+ setSelectedTab(tab)
93
+ }
94
+ }, [tab])
83
95
 
84
96
  useEffect(() => {
85
- const { onChange } = props
97
+ if (selectedTab !== tab) {
98
+ const {
99
+ onChange = DEFAULT_HANDLE_CHANGE
100
+ } = props
86
101
 
87
- try {
88
- onChange(selectedTab)
89
- } catch {
90
- error('Error `onChange`')
102
+ try {
103
+ onChange(selectedTab)
104
+ } catch {
105
+ error('Error `onChange`')
106
+ }
91
107
  }
92
108
  }, [selectedTab])
93
109
 
@@ -97,7 +113,3 @@ export default function TabSet (props: TabSetProps): JSX.Element {
97
113
  </div>
98
114
  )
99
115
  }
100
-
101
- TabSet.defaultProps = {
102
- selectedTab: v4()
103
- }
@@ -1,3 +1,6 @@
1
+ import type {
2
+ JSX
3
+ } from 'react'
1
4
  import React, {
2
5
  Children,
3
6
  cloneElement
@@ -5,9 +8,12 @@ import React, {
5
8
  import {
6
9
  v4
7
10
  } from 'uuid'
11
+ import debug from 'debug'
8
12
 
9
13
  import isTab from './is-tab.mts'
10
14
 
15
+ const log = debug('react-tab-set/tab-set/tab-group')
16
+
11
17
  export interface TabGroupProps {
12
18
  children: JSX.Element | JSX.Element[]
13
19
  selectedTab: string
@@ -55,11 +61,15 @@ function mapChildren (
55
61
  })
56
62
  }
57
63
 
64
+ function DEFAULT_HANDLE_TAB_SELECT (value: React.SetStateAction<string>): void {
65
+ log(value)
66
+ }
67
+
58
68
  export default function TabGroup (props: TabGroupProps): JSX.Element {
59
69
  const {
60
70
  children,
61
- selectedTab,
62
- onTabSelect
71
+ selectedTab = v4(),
72
+ onTabSelect = DEFAULT_HANDLE_TAB_SELECT
63
73
  } = props
64
74
 
65
75
  return (
@@ -68,8 +78,3 @@ export default function TabGroup (props: TabGroupProps): JSX.Element {
68
78
  </ul>
69
79
  )
70
80
  }
71
-
72
- TabGroup.defaultProps = {
73
- selectedTab: v4(),
74
- onTabSelect () { }
75
- }
@@ -1,7 +1,15 @@
1
- import React from 'react'
1
+ import type {
2
+ JSX
3
+ } from 'react'
4
+ import React, {
5
+ useCallback
6
+ } from 'react'
2
7
  import {
3
8
  v4
4
9
  } from 'uuid'
10
+ import debug from 'debug'
11
+
12
+ const log = debug('react-tab-set/tab-set/tab-group/tab')
5
13
 
6
14
  export interface TabProps {
7
15
  children: JSX.Element | JSX.Element[] | string | number | boolean
@@ -10,30 +18,31 @@ export interface TabProps {
10
18
  onTabSelect: (value: React.SetStateAction<string>) => void
11
19
  }
12
20
 
21
+ function DEFAULT_HANDLE_TAB_SELECT (value: React.SetStateAction<string>): void {
22
+ log(value)
23
+ }
24
+
13
25
  export default function Tab (props: TabProps): JSX.Element {
14
26
  const {
15
27
  children,
16
28
  tab,
17
- selectedTab,
18
- onTabSelect
29
+ selectedTab = v4(),
30
+ onTabSelect = DEFAULT_HANDLE_TAB_SELECT
19
31
  } = props
20
32
 
21
33
  const className = (tab === selectedTab)
22
34
  ? 'tab selected'
23
35
  : 'tab'
24
36
 
37
+ const handleClick = useCallback(function onClick (): void {
38
+ onTabSelect(tab)
39
+ }, [tab])
40
+
25
41
  return (
26
42
  <li
27
43
  className={className}
28
- onClick={(): void => {
29
- onTabSelect(tab)
30
- }}>
44
+ onClick={handleClick}>
31
45
  {children}
32
46
  </li>
33
47
  )
34
48
  }
35
-
36
- Tab.defaultProps = {
37
- selectedTab: v4(),
38
- onTabSelect () { }
39
- }
@@ -1,3 +1,6 @@
1
+ import type {
2
+ JSX
3
+ } from 'react'
1
4
  import React from 'react'
2
5
  import {
3
6
  v4
@@ -10,15 +13,19 @@ export interface TabPanelProps {
10
13
  render?: () => JSX.Element | JSX.Element[] | string | number | boolean | undefined | null
11
14
  }
12
15
 
16
+ function DEFAULT_RENDER (): null {
17
+ return null
18
+ }
19
+
13
20
  export default function TabPanel (props: TabPanelProps): JSX.Element | null {
14
21
  const {
15
22
  tab,
16
- selectedTab
23
+ selectedTab = v4()
17
24
  } = props
18
25
 
19
26
  if (tab === selectedTab) {
20
27
  const {
21
- render = () => null,
28
+ render = DEFAULT_RENDER,
22
29
  children = render()
23
30
  } = props
24
31
 
@@ -33,7 +40,3 @@ export default function TabPanel (props: TabPanelProps): JSX.Element | null {
33
40
 
34
41
  return null
35
42
  }
36
-
37
- TabPanel.defaultProps = {
38
- selectedTab: v4()
39
- }