shinkansen-sprockets 2.0.6 → 2.1.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/babel.config.cjs CHANGED
@@ -52,7 +52,7 @@ module.exports = (api) => {
52
52
  presets,
53
53
  plugins,
54
54
  ignore: [
55
- /node_modules\/(?!shinkansen|@modernpoacher)/
55
+ /node_modules\/(?!shinkansen|@modernpoacher|react-component-instance|react-component-snapshot)/
56
56
  ]
57
57
  }
58
58
  }
package/eslint.config.mjs CHANGED
@@ -80,7 +80,8 @@ export default [
80
80
  ignores: [
81
81
  'src',
82
82
  'stories',
83
- 'test'
83
+ 'test',
84
+ 'jest.*.mjs'
84
85
  ],
85
86
  languageOptions: {
86
87
  globals: {
@@ -145,7 +146,8 @@ export default [
145
146
  standard({
146
147
  files: [
147
148
  'src/**/__tests__/**/*.jsx',
148
- 'stories/**/__tests__/**/*.jsx'
149
+ 'stories/**/__tests__/**/*.jsx',
150
+ 'jest.*.mjs'
149
151
  ],
150
152
  languageOptions: {
151
153
  parser: babelParser,
package/index.d.mts CHANGED
@@ -51,11 +51,11 @@ declare global {
51
51
 
52
52
  export namespace ErrorMessage {
53
53
  export interface ErrorMessageProps {
54
- errorMessage?: ErrorDefinitionType[]
54
+ errorMessage?: ErrorDefinitionType
55
55
  }
56
56
 
57
57
  export interface ErrorMessageState {
58
- errorMessage?: ErrorDefinitionType[]
58
+ errorMessage?: ErrorDefinitionType
59
59
  }
60
60
  }
61
61
 
@@ -157,7 +157,7 @@ declare global {
157
157
  export namespace Fieldset {
158
158
  export interface FieldsetProps extends Super.Sprockets.SprocketProps {
159
159
  description?: string
160
- errorMessage?: ErrorDefinitionType[]
160
+ errorMessage?: ErrorDefinitionType
161
161
  }
162
162
 
163
163
  export namespace Group {
@@ -0,0 +1,10 @@
1
+ afterEach(() => {
2
+ const {
3
+ body
4
+ } = document
5
+
6
+ Array.from(body.children)
7
+ .forEach((child) => {
8
+ body.removeChild(child)
9
+ })
10
+ })
@@ -0,0 +1 @@
1
+ beforeEach(() => {})
@@ -0,0 +1,26 @@
1
+ export default {
2
+ bail: true,
3
+ verbose: true,
4
+ rootDir: '.',
5
+ roots: [
6
+ './src'
7
+ ],
8
+ clearMocks: true,
9
+ collectCoverage: true,
10
+ coverageDirectory: './coverage',
11
+ coverageProvider: 'v8',
12
+ testRegex: '(/__tests__/.*|(\\.|/))(test|spec)\\.(mjs?|jsx?)$',
13
+ transform: {
14
+ '^.+\\.jsx$': 'babel-jest',
15
+ '^.+\\.mjs$': 'babel-jest'
16
+ },
17
+ transformIgnorePatterns: [
18
+ '/node_modules\\/(?!react-component-instance)\\/'
19
+ ],
20
+ moduleFileExtensions: ['js', 'jsx', 'mjs'],
21
+ testEnvironment: 'jsdom',
22
+ setupFilesAfterEnv: [
23
+ '<rootDir>/jest.before-each.mjs',
24
+ '<rootDir>/jest.after-each.mjs'
25
+ ]
26
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shinkansen-sprockets",
3
- "version": "2.0.6",
3
+ "version": "2.1.0",
4
4
  "description": "Shinkansen Sprockets",
5
5
  "keywords": [
6
6
  "Shinkansen",
@@ -64,21 +64,24 @@
64
64
  "@modernpoacher/design-system": "2.0.2",
65
65
  "@sequencemedia/eslint-config-standard": "^0.2.43",
66
66
  "@sequencemedia/eslint-config-typescript": "^0.1.62",
67
- "@storybook/addon-actions": "^8.6.6",
68
- "@storybook/addon-essentials": "^8.6.6",
69
- "@storybook/addon-links": "^8.6.6",
67
+ "@storybook/addon-actions": "^8.6.7",
68
+ "@storybook/addon-essentials": "^8.6.7",
69
+ "@storybook/addon-links": "^8.6.7",
70
70
  "@storybook/addon-webpack5-compiler-babel": "^3.0.5",
71
- "@storybook/manager-api": "^8.6.6",
72
- "@storybook/react": "^8.6.6",
73
- "@storybook/react-webpack5": "^8.6.6",
74
- "@storybook/theming": "^8.6.6",
71
+ "@storybook/manager-api": "^8.6.7",
72
+ "@storybook/react": "^8.6.7",
73
+ "@storybook/react-webpack5": "^8.6.7",
74
+ "@storybook/theming": "^8.6.7",
75
+ "@testing-library/jest-dom": "^6.6.3",
76
+ "@testing-library/react": "^16.2.0",
75
77
  "@types/babel__register": "^7.17.3",
76
78
  "@types/chai": "^5.2.0",
77
79
  "@types/debug": "^4.1.12",
78
80
  "@types/jest": "^29.5.14",
79
81
  "@types/mocha": "^10.0.10",
80
- "@types/react": "18.3.13",
81
- "@types/react-test-renderer": "^19.0.0",
82
+ "@types/prop-types": "^15.7.14",
83
+ "@types/react": "^19.0.11",
84
+ "@types/react-dom": "^19.0.4",
82
85
  "@typescript-eslint/eslint-plugin": "^8.26.1",
83
86
  "@typescript-eslint/parser": "^8.26.1",
84
87
  "autoprefixer": "^10.4.21",
@@ -87,10 +90,11 @@
87
90
  "cross-env": "^7.0.3",
88
91
  "eslint": "^9.22.0",
89
92
  "eslint-plugin-react": "^7.37.4",
90
- "eslint-plugin-storybook": "^0.11.4",
93
+ "eslint-plugin-storybook": "^0.11.6",
91
94
  "globals": "^16.0.0",
92
95
  "husky": "^9.1.7",
93
96
  "jest": "^29.7.0",
97
+ "jest-environment-jsdom": "^29.7.0",
94
98
  "mini-css-extract-plugin": "^2.9.2",
95
99
  "mocha": "^11.1.0",
96
100
  "perfectionist": "^2.4.0",
@@ -102,14 +106,15 @@
102
106
  "postcss-map": "^0.11.0",
103
107
  "prettier": "^3.5.3",
104
108
  "prop-types": "^15.8.1",
105
- "react": "18.3.1",
106
- "react-dom": "18.3.1",
109
+ "react": "^19.0.0",
110
+ "react-component-instance": "^0.0.6",
111
+ "react-component-snapshot": "^0.0.1",
112
+ "react-dom": "^19.0.0",
107
113
  "react-router": "^7.3.0",
108
- "react-test-renderer": "18.3.1",
109
114
  "remove-files-webpack-plugin": "^1.5.0",
110
- "sass": "^1.85.1",
115
+ "sass": "^1.86.0",
111
116
  "sass-loader": "^16.0.5",
112
- "storybook": "^8.6.6",
117
+ "storybook": "^8.6.7",
113
118
  "stylelint": "^16.16.0",
114
119
  "stylelint-config-recommended-scss": "^14.1.0",
115
120
  "stylelint-scss": "^6.11.1",
@@ -11,8 +11,8 @@
11
11
  */
12
12
  import React from 'react'
13
13
  import PropTypes from 'prop-types'
14
- import equal from 'fast-deep-equal'
15
14
  import classnames from 'classnames'
15
+ import equal from 'fast-deep-equal'
16
16
 
17
17
  import debug from 'debug'
18
18
 
@@ -78,14 +78,14 @@ export default class CheckAnswersGroup extends Group {
78
78
  * @param {CheckAnswersState} state Current state
79
79
  * @returns {CheckAnswersState}
80
80
  */
81
- static getDerivedStateFromProps ({ checkAnswers }, { checkAnswers: C }) {
81
+ static getDerivedStateFromProps ({ checkAnswers: c }, { checkAnswers: C }) {
82
82
  return {
83
- checkAnswers: equal(checkAnswers, C) ? C : checkAnswers
83
+ checkAnswers: (c === C || equal(c, C)) ? C : c
84
84
  }
85
85
  }
86
86
 
87
87
  /**
88
- * Compare latest 'props' with 'state' for changes to 'checkAnswers'
88
+ * Compare latest 'props' with 'state' for changes to 'checkAnswers'
89
89
  *
90
90
  * @param {CheckAnswersProps} props Latest props
91
91
  * @param {CheckAnswersState} state Current state
@@ -94,13 +94,13 @@ export default class CheckAnswersGroup extends Group {
94
94
  shouldComponentUpdate (props, state) {
95
95
  const {
96
96
  checkAnswers: c = DEFAULT_CHECK_ANSWERS
97
- } = state
97
+ } = this.state
98
98
 
99
99
  const {
100
100
  checkAnswers: C = DEFAULT_CHECK_ANSWERS
101
- } = this.state
101
+ } = state
102
102
 
103
- return (c !== C)
103
+ return !(c === C || equal(c, C))
104
104
  }
105
105
 
106
106
  render () {
@@ -9,7 +9,6 @@
9
9
  */
10
10
  import React from 'react'
11
11
  import PropTypes from 'prop-types'
12
-
13
12
  import classnames from 'classnames'
14
13
 
15
14
  import Sprocket from '#sprockets/sprockets'
@@ -20,10 +20,14 @@ export default class CheckAnswersTitle extends Title {
20
20
  }
21
21
 
22
22
  render () {
23
- if (this.hasTextContent()) {
23
+ const {
24
+ title
25
+ } = this.props
26
+
27
+ if (title) {
24
28
  return (
25
29
  <h2 className={this.getClassName()}>
26
- {this.renderTextContent()}
30
+ {this.renderTextContent(title)}
27
31
  </h2>
28
32
  )
29
33
  }
@@ -11,9 +11,8 @@
11
11
  */
12
12
  import React from 'react'
13
13
  import PropTypes from 'prop-types'
14
-
15
- import equal from 'fast-deep-equal'
16
14
  import classnames from 'classnames'
15
+ import equal from 'fast-deep-equal'
17
16
 
18
17
  import debug from 'debug'
19
18
 
@@ -75,9 +74,9 @@ export default class ErrorSummaryGroup extends Group {
75
74
  * @param {ErrorSummaryState} state Current state
76
75
  * @returns {ErrorSummaryState}
77
76
  */
78
- static getDerivedStateFromProps ({ errorSummary }, { errorSummary: E }) {
77
+ static getDerivedStateFromProps ({ errorSummary: e }, { errorSummary: E }) {
79
78
  return {
80
- errorSummary: equal(errorSummary, E) ? E : errorSummary
79
+ errorSummary: (e === E || equal(e, E)) ? E : e
81
80
  }
82
81
  }
83
82
 
@@ -91,13 +90,13 @@ export default class ErrorSummaryGroup extends Group {
91
90
  shouldComponentUpdate (props, state) {
92
91
  const {
93
92
  errorSummary: e = DEFAULT_ERROR_SUMMARY
94
- } = state
93
+ } = this.state
95
94
 
96
95
  const {
97
96
  errorSummary: E = DEFAULT_ERROR_SUMMARY
98
- } = this.state
97
+ } = state
99
98
 
100
- return !equal(e, E)
99
+ return !(e === E || equal(e, E))
101
100
  }
102
101
 
103
102
  render () {
@@ -9,7 +9,6 @@
9
9
  */
10
10
  import React from 'react'
11
11
  import PropTypes from 'prop-types'
12
-
13
12
  import classnames from 'classnames'
14
13
 
15
14
  import Sprocket from '#sprockets/sprockets'
@@ -20,10 +20,14 @@ export default class ErrorSummaryTitle extends Title {
20
20
  }
21
21
 
22
22
  render () {
23
- if (this.hasTextContent()) {
23
+ const {
24
+ title
25
+ } = this.props
26
+
27
+ if (title) {
24
28
  return (
25
29
  <h2 className={this.getClassName()}>
26
- {this.renderTextContent()}
30
+ {this.renderTextContent(title)}
27
31
  </h2>
28
32
  )
29
33
  }
@@ -8,7 +8,6 @@
8
8
  */
9
9
  import React from 'react'
10
10
  import PropTypes from 'prop-types'
11
-
12
11
  import classnames from 'classnames'
13
12
 
14
13
  import Sprocket from '#sprockets/sprockets'
@@ -10,6 +10,9 @@ import PropTypes from 'prop-types'
10
10
 
11
11
  import TextContent from '#sprockets/components/common/text-content'
12
12
 
13
+ /**
14
+ * @extends {Component<DescriptionProps>}
15
+ */
13
16
  export default class Description extends Component {
14
17
  getClassName () {
15
18
  return 'description'
@@ -15,6 +15,9 @@ import transform from '#sprockets/transformers/error-message'
15
15
 
16
16
  import TextContent from '#sprockets/components/common/text-content'
17
17
 
18
+ /**
19
+ * @extends {Component<ErrorMessageProps, ErrorMessageState>}
20
+ */
18
21
  export default class ErrorMessage extends Component {
19
22
  /**
20
23
  * @type {ErrorMessageState}
@@ -26,11 +29,15 @@ export default class ErrorMessage extends Component {
26
29
  errorMessage
27
30
  } = this.props
28
31
 
29
- const {
30
- text
31
- } = transform(errorMessage)
32
+ if (errorMessage) {
33
+ const {
34
+ text
35
+ } = transform(errorMessage)
32
36
 
33
- return !!text
37
+ return !!text
38
+ }
39
+
40
+ return false
34
41
  }
35
42
 
36
43
  getTextContent () {
@@ -38,11 +45,15 @@ export default class ErrorMessage extends Component {
38
45
  errorMessage
39
46
  } = this.props
40
47
 
41
- const {
42
- text
43
- } = transform(errorMessage)
48
+ if (errorMessage) {
49
+ const {
50
+ text
51
+ } = transform(errorMessage)
52
+
53
+ return text
54
+ }
44
55
 
45
- return text
56
+ return ''
46
57
  }
47
58
 
48
59
  getClassName () {
@@ -56,9 +67,9 @@ export default class ErrorMessage extends Component {
56
67
  * @param {ErrorMessageState} state Current state
57
68
  * @returns {ErrorMessageState}
58
69
  */
59
- static getDerivedStateFromProps ({ errorMessage }, { errorMessage: E }) {
70
+ static getDerivedStateFromProps ({ errorMessage: e }, { errorMessage: E }) {
60
71
  return {
61
- errorMessage: equal(errorMessage, E) ? E : errorMessage
72
+ errorMessage: (e === E || equal(e, E)) ? E : e
62
73
  }
63
74
  }
64
75
 
@@ -72,13 +83,13 @@ export default class ErrorMessage extends Component {
72
83
  shouldComponentUpdate (props, state) {
73
84
  const {
74
85
  errorMessage: e
75
- } = state
86
+ } = this.state
76
87
 
77
88
  const {
78
89
  errorMessage: E
79
- } = this.state
90
+ } = state
80
91
 
81
- return !equal(E, e)
92
+ return !(e === E || equal(e, E))
82
93
  }
83
94
 
84
95
  renderTextContent () {
@@ -25,17 +25,24 @@ export default class Group extends Component {
25
25
 
26
26
  render () {
27
27
  const {
28
- groupRef,
29
28
  children
30
29
  } = this.props
31
30
 
32
- return (
33
- <fieldset
34
- className={this.getClassName()}
35
- ref={groupRef}>
36
- {children}
37
- </fieldset>
38
- )
31
+ if (children) {
32
+ const {
33
+ groupRef
34
+ } = this.props
35
+
36
+ return (
37
+ <fieldset
38
+ className={this.getClassName()}
39
+ ref={groupRef}>
40
+ {children}
41
+ </fieldset>
42
+ )
43
+ }
44
+
45
+ return null
39
46
  }
40
47
  }
41
48
 
@@ -47,6 +54,6 @@ Group.propTypes = {
47
54
  )
48
55
  ]),
49
56
  groupRef: PropTypes.shape({
50
- current: PropTypes.shape({}).isRequired
57
+ current: PropTypes.shape({})
51
58
  })
52
59
  }
@@ -6,15 +6,11 @@ declare module '#sprockets/super/components/title' {
6
6
  export default class Title<P extends TitleProps> extends React.Component<P> {
7
7
  static propTypes: object
8
8
 
9
- hasTextContent (): boolean
10
-
11
- getTextContent (): string
12
-
13
9
  getClassName (): string
14
10
 
15
11
  shouldComponentUpdate (props: TitleProps): boolean
16
12
 
17
- renderTextContent (): React.JSX.Element | null
13
+ renderTextContent (textContent: string): React.JSX.Element
18
14
  }
19
15
  }
20
16
 
@@ -10,23 +10,10 @@ import PropTypes from 'prop-types'
10
10
 
11
11
  import TextContent from '#sprockets/components/common/text-content'
12
12
 
13
+ /**
14
+ * @extends {Component<TitleProps>}
15
+ */
13
16
  export default class Title extends Component {
14
- hasTextContent () {
15
- const {
16
- title
17
- } = this.props
18
-
19
- return !!title
20
- }
21
-
22
- getTextContent () {
23
- const {
24
- title
25
- } = this.props
26
-
27
- return title
28
- }
29
-
30
17
  getClassName () {
31
18
  return 'title'
32
19
  }
@@ -41,25 +28,27 @@ export default class Title extends Component {
41
28
  )
42
29
  }
43
30
 
44
- renderTextContent () {
45
- if (this.hasTextContent()) {
46
- const textContent = this.getTextContent()
47
-
48
- return (
49
- <TextContent
50
- textContent={textContent}
51
- />
52
- )
53
- }
54
-
55
- return null
31
+ /**
32
+ * @param {string} textContent
33
+ * @returns {React.JSX.Element}
34
+ */
35
+ renderTextContent (textContent) {
36
+ return (
37
+ <TextContent
38
+ textContent={textContent}
39
+ />
40
+ )
56
41
  }
57
42
 
58
43
  render () {
59
- if (this.hasTextContent()) {
44
+ const {
45
+ title
46
+ } = this.props
47
+
48
+ if (title) {
60
49
  return (
61
50
  <legend className={this.getClassName()}>
62
- {this.renderTextContent()}
51
+ {this.renderTextContent(title)}
63
52
  </legend>
64
53
  )
65
54
  }
@@ -74,6 +74,6 @@ Sprocket.propTypes = {
74
74
  )
75
75
  ]),
76
76
  groupRef: PropTypes.shape({
77
- current: PropTypes.shape({}).isRequired
77
+ current: PropTypes.shape({})
78
78
  })
79
79
  }