react-tab-set 1.2.2 → 1.2.4

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": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "A React Tab Set component",
5
5
  "main": "./src/index.mjs",
6
6
  "type": "module",
@@ -10,6 +10,9 @@
10
10
  "url": "http://www.sequencemedia.net"
11
11
  },
12
12
  "license": "MIT",
13
+ "engines": {
14
+ "node": ">=18.17.0"
15
+ },
13
16
  "repository": {
14
17
  "type": "git",
15
18
  "url": "git://github.com/sequencemedia/react-tab-set.git"
@@ -26,9 +29,9 @@
26
29
  "uuid": "^9.0.1"
27
30
  },
28
31
  "devDependencies": {
29
- "@babel/cli": "^7.22.15",
30
32
  "@babel/core": "^7.22.20",
31
33
  "@babel/eslint-parser": "^7.22.15",
34
+ "@babel/plugin-syntax-jsx": "^7.22.5",
32
35
  "@babel/plugin-transform-typescript": "^7.22.15",
33
36
  "@babel/preset-env": "^7.22.20",
34
37
  "@babel/preset-react": "^7.22.15",
@@ -36,10 +39,6 @@
36
39
  "@babel/register": "^7.22.15",
37
40
  "@sequencemedia/hooks": "^1.0.454",
38
41
  "@storybook/addon-essentials": "^7.4.4",
39
- "@storybook/addon-interactions": "^7.4.4",
40
- "@storybook/addon-links": "^7.4.4",
41
- "@storybook/addon-onboarding": "^1.0.8",
42
- "@storybook/blocks": "^7.4.4",
43
42
  "@storybook/react": "^7.4.4",
44
43
  "@storybook/react-webpack5": "^7.4.4",
45
44
  "@types/debug": "^4.1.9",
@@ -56,8 +55,8 @@
56
55
  "eslint-plugin-storybook": "^0.6.14",
57
56
  "husky": "^8.0.3",
58
57
  "prop-types": "15.7.2",
59
- "react": "16.14.0",
60
- "react-dom": "16.14.0",
58
+ "react": "^18.2.0",
59
+ "react-dom": "^18.2.0",
61
60
  "storybook": "^7.4.4",
62
61
  "typescript": "^5.2.2"
63
62
  },
package/src/.babelrc CHANGED
@@ -21,6 +21,7 @@
21
21
  "@babel/react"
22
22
  ],
23
23
  "plugins": [
24
+ "@babel/syntax-jsx",
24
25
  "@babel/transform-typescript"
25
26
  ]
26
27
  }
package/src/index.mts CHANGED
@@ -1,23 +1 @@
1
- import isTabGroup from './tab-set/is-tab-group.mts'
2
- import isTab from './tab-set/tab-group/is-tab.mts'
3
- import isTabPanel from './tab-set/is-tab-panel.mts'
4
-
5
- import TabGroup from './tab-set/tab-group/index.tsx'
6
- import Tab from './tab-set/tab-group/tab/index.tsx'
7
- import TabPanel from './tab-set/tab-panel/index.tsx'
8
-
9
- import TabSet from './tab-set/index.tsx'
10
-
11
- export {
12
- isTabGroup,
13
- isTab,
14
- isTabPanel
15
- }
16
-
17
- export {
18
- TabGroup,
19
- Tab,
20
- TabPanel
21
- }
22
-
23
- export default TabSet
1
+ export { default } from './tab-set/index.tsx'
@@ -10,6 +10,7 @@ import isTabGroup from './is-tab-group.mts'
10
10
  const error = debug('react-tab-set/tab-set')
11
11
 
12
12
  export interface TabSetProps {
13
+ onClick: (selectedTab: string) => void
13
14
  onChange: (selectedTab: string) => void
14
15
  selectedTab: string
15
16
  children: JSX.Element | JSX.Element[]
@@ -20,16 +21,8 @@ export interface TabSetState {
20
21
  }
21
22
 
22
23
  export default class TabSet extends Component<TabSetProps, TabSetState> {
23
- constructor (props: TabSetProps) {
24
- super(props)
25
-
26
- const {
27
- selectedTab
28
- } = props
29
-
30
- this.state = {
31
- selectedTab
32
- }
24
+ state = {
25
+ selectedTab: this.props.selectedTab
33
26
  }
34
27
 
35
28
  /*
@@ -38,11 +31,18 @@ export default class TabSet extends Component<TabSetProps, TabSetState> {
38
31
  * an implemented tab
39
32
  */
40
33
  static defaultProps = {
41
- onChange: () => {},
34
+ onClick () {},
35
+ onChange () {},
42
36
  selectedTab: v4(),
43
37
  children: []
44
38
  }
45
39
 
40
+ static getDerivedStateFromProps ({ selectedTab }: TabSetState): TabSetState {
41
+ return {
42
+ selectedTab
43
+ }
44
+ }
45
+
46
46
  shouldComponentUpdate (props: TabSetProps, state: TabSetState): boolean {
47
47
  return (
48
48
  props.children !== this.props.children ||
@@ -51,10 +51,18 @@ export default class TabSet extends Component<TabSetProps, TabSetState> {
51
51
  }
52
52
 
53
53
  handleTabSelect = (selectedTab: string): void => {
54
- if (selectedTab !== this.state.selectedTab) {
55
- const { onChange } = this.props
54
+ const { onClick } = this.props
56
55
 
56
+ try {
57
+ onClick(selectedTab)
58
+ } catch {
59
+ error('Error `onClick`')
60
+ }
61
+
62
+ if (selectedTab !== this.state.selectedTab) {
57
63
  this.setState({ selectedTab }, () => {
64
+ const { onChange } = this.props
65
+
58
66
  try {
59
67
  onChange(selectedTab)
60
68
  } catch {
@@ -5,7 +5,7 @@ import {
5
5
 
6
6
  import isTab from './is-tab.mts'
7
7
 
8
- interface TabGroupProps {
8
+ export interface TabGroupProps {
9
9
  onTabSelect: (selectedTab: string) => void
10
10
  children: JSX.Element | JSX.Element[]
11
11
  selectedTab: string
@@ -18,7 +18,7 @@ export default class TabGroup extends Component<TabGroupProps> {
18
18
  * an implemented tab
19
19
  */
20
20
  static defaultProps = {
21
- onTabSelect: () => {},
21
+ onTabSelect () {},
22
22
  selectedTab: v4(),
23
23
  children: []
24
24
  }
@@ -17,7 +17,7 @@ export default class Tab extends Component<TabProps> {
17
17
  * an implemented tab
18
18
  */
19
19
  static defaultProps = {
20
- onTabClick: () => {},
20
+ onTabClick () {},
21
21
  tab: v4(),
22
22
  selectedTab: v4(),
23
23
  children: []
@@ -3,7 +3,7 @@ import {
3
3
  v4
4
4
  } from 'uuid'
5
5
 
6
- interface TabPanelProps {
6
+ export interface TabPanelProps {
7
7
  children: JSX.Element | JSX.Element[] | string | number | boolean | undefined | null
8
8
  tab: string
9
9
  selectedTab: string
package/index.mjs DELETED
@@ -1 +0,0 @@
1
- export * from './src/index.cjs'