shinkansen-sprockets 1.1.462 → 1.2.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 +1 -0
- package/eslint.config.mjs +11 -56
- package/index.d.mts +122 -13
- package/package.json +8 -3
- package/src/common/index.d.mts +1 -3
- package/src/common/index.mjs +1 -7
- package/src/components/common/text-content/index.cjs +1 -1
- package/src/components/common/text-content/index.d.mts +3 -4
- package/src/components/common/text-content/index.jsx +7 -6
- package/src/components/common/visually-hidden-text/index.cjs +1 -1
- package/src/components/common/visually-hidden-text/index.d.mts +3 -4
- package/src/components/common/visually-hidden-text/index.jsx +7 -6
- package/src/components/description/index.cjs +1 -1
- package/src/components/description/index.d.mts +10 -5
- package/src/components/description/index.jsx +12 -3
- package/src/components/error-message/index.cjs +1 -1
- package/src/components/error-message/index.d.mts +20 -5
- package/src/components/error-message/index.jsx +30 -15
- package/src/components/group/index.cjs +1 -1
- package/src/components/group/index.d.mts +12 -7
- package/src/components/group/index.jsx +8 -15
- package/src/components/title/index.cjs +1 -1
- package/src/components/title/index.d.mts +16 -5
- package/src/components/title/index.jsx +18 -4
- package/src/index.d.mts +8 -0
- package/src/sprockets/check-answers/group/answer-title.cjs +1 -0
- package/src/sprockets/check-answers/group/answer-title.jsx +2 -2
- package/src/sprockets/check-answers/group/answer-value.cjs +1 -0
- package/src/sprockets/check-answers/group/answer-value.jsx +29 -12
- package/src/sprockets/check-answers/group/change-answer.cjs +1 -0
- package/src/sprockets/check-answers/group/change-answer.jsx +17 -7
- package/src/sprockets/check-answers/group/index.cjs +1 -1
- package/src/sprockets/check-answers/group/index.d.mts +7 -1
- package/src/sprockets/check-answers/group/index.jsx +43 -28
- package/src/sprockets/check-answers/index.cjs +1 -1
- package/src/sprockets/check-answers/index.d.mts +5 -1
- package/src/sprockets/check-answers/index.jsx +25 -9
- package/src/sprockets/check-answers/title/index.cjs +1 -1
- package/src/sprockets/check-answers/title/index.d.mts +5 -1
- package/src/sprockets/check-answers/title/index.jsx +8 -5
- package/src/sprockets/error-summary/group/index.cjs +1 -1
- package/src/sprockets/error-summary/group/index.d.mts +7 -1
- package/src/sprockets/error-summary/group/index.jsx +31 -23
- package/src/sprockets/error-summary/index.cjs +1 -1
- package/src/sprockets/error-summary/index.d.mts +5 -1
- package/src/sprockets/error-summary/index.jsx +19 -9
- package/src/sprockets/error-summary/title/index.cjs +1 -1
- package/src/sprockets/error-summary/title/index.d.mts +5 -1
- package/src/sprockets/error-summary/title/index.jsx +8 -5
- package/src/sprockets/fieldset/description/index.cjs +1 -1
- package/src/sprockets/fieldset/description/index.jsx +0 -5
- package/src/sprockets/fieldset/error-message/index.cjs +1 -1
- package/src/sprockets/fieldset/error-message/index.jsx +0 -5
- package/src/sprockets/fieldset/group/index.cjs +1 -1
- package/src/sprockets/fieldset/group/index.d.mts +7 -1
- package/src/sprockets/fieldset/group/index.jsx +10 -5
- package/src/sprockets/fieldset/index.cjs +1 -1
- package/src/sprockets/fieldset/index.d.mts +11 -1
- package/src/sprockets/fieldset/index.jsx +22 -17
- package/src/sprockets/fieldset/title/index.cjs +1 -1
- package/src/sprockets/fieldset/title/index.d.mts +5 -1
- package/src/sprockets/fieldset/title/index.jsx +8 -4
- package/src/sprockets/index.cjs +1 -4
- package/src/sprockets/index.d.mts +14 -8
- package/src/sprockets/index.jsx +9 -16
- package/src/transformers/check-answers/index.d.mts +8 -0
- package/src/transformers/check-answers/index.mjs +2 -2
- package/src/transformers/common/index.mjs +4 -4
- package/src/transformers/error-message/index.d.mts +8 -0
- package/src/transformers/error-message/index.mjs +12 -4
- package/src/transformers/error-summary/index.d.mts +8 -0
- package/src/transformers/error-summary/index.mjs +10 -6
@@ -1,7 +1,12 @@
|
|
1
1
|
/**
|
2
|
-
*
|
2
|
+
* @typedef {SprocketsTypes.ErrorDefinitionType} ErrorDefinitionType
|
3
|
+
* @typedef {SprocketsTypes.Components.ErrorMessage.ErrorMessageProps} ErrorMessageProps
|
4
|
+
* @typedef {SprocketsTypes.Components.ErrorMessage.ErrorMessageState} ErrorMessageState
|
3
5
|
*/
|
4
6
|
|
7
|
+
/**
|
8
|
+
* ErrorMessage component
|
9
|
+
*/
|
5
10
|
import React, { Component } from 'react'
|
6
11
|
import PropTypes from 'prop-types'
|
7
12
|
import equal from 'fast-deep-equal'
|
@@ -11,12 +16,15 @@ import transform from '#sprockets/transformers/error-message'
|
|
11
16
|
import TextContent from '#sprockets/components/common/text-content'
|
12
17
|
|
13
18
|
export default class ErrorMessage extends Component {
|
14
|
-
|
15
|
-
|
16
|
-
|
19
|
+
/**
|
20
|
+
* @type {ErrorMessageState}
|
21
|
+
*/
|
22
|
+
state = {}
|
17
23
|
|
18
24
|
hasTextContent () {
|
19
|
-
const {
|
25
|
+
const {
|
26
|
+
errorMessage
|
27
|
+
} = this.props
|
20
28
|
|
21
29
|
const {
|
22
30
|
text
|
@@ -26,7 +34,10 @@ export default class ErrorMessage extends Component {
|
|
26
34
|
}
|
27
35
|
|
28
36
|
getTextContent () {
|
29
|
-
const {
|
37
|
+
const {
|
38
|
+
errorMessage
|
39
|
+
} = this.props
|
40
|
+
|
30
41
|
const {
|
31
42
|
text
|
32
43
|
} = transform(errorMessage)
|
@@ -41,9 +52,9 @@ export default class ErrorMessage extends Component {
|
|
41
52
|
/**
|
42
53
|
* Merge latest `props` to `state`
|
43
54
|
*
|
44
|
-
* @param {
|
45
|
-
* @param {
|
46
|
-
* @returns {
|
55
|
+
* @param {ErrorMessageProps} props Latest props
|
56
|
+
* @param {ErrorMessageState} state Current state
|
57
|
+
* @returns {ErrorMessageState}
|
47
58
|
*/
|
48
59
|
static getDerivedStateFromProps ({ errorMessage }, { errorMessage: E }) {
|
49
60
|
return {
|
@@ -54,8 +65,8 @@ export default class ErrorMessage extends Component {
|
|
54
65
|
/**
|
55
66
|
* Compare current and latest `state` for changes to `errorMessage`
|
56
67
|
*
|
57
|
-
* @param {
|
58
|
-
* @param {
|
68
|
+
* @param {ErrorMessageProps} props Latest props
|
69
|
+
* @param {ErrorMessageState} state Latest state
|
59
70
|
* @returns {boolean}
|
60
71
|
*/
|
61
72
|
shouldComponentUpdate (props, state) {
|
@@ -67,7 +78,7 @@ export default class ErrorMessage extends Component {
|
|
67
78
|
errorMessage: E
|
68
79
|
} = this.state
|
69
80
|
|
70
|
-
return (e
|
81
|
+
return !equal(E, e)
|
71
82
|
}
|
72
83
|
|
73
84
|
renderTextContent () {
|
@@ -75,7 +86,9 @@ export default class ErrorMessage extends Component {
|
|
75
86
|
const textContent = this.getTextContent()
|
76
87
|
|
77
88
|
return (
|
78
|
-
<TextContent
|
89
|
+
<TextContent
|
90
|
+
textContent={textContent}
|
91
|
+
/>
|
79
92
|
)
|
80
93
|
}
|
81
94
|
|
@@ -83,7 +96,9 @@ export default class ErrorMessage extends Component {
|
|
83
96
|
}
|
84
97
|
|
85
98
|
render () {
|
86
|
-
const {
|
99
|
+
const {
|
100
|
+
errorMessage
|
101
|
+
} = this.props
|
87
102
|
|
88
103
|
if (errorMessage) {
|
89
104
|
return (
|
@@ -100,7 +115,7 @@ export default class ErrorMessage extends Component {
|
|
100
115
|
ErrorMessage.propTypes = {
|
101
116
|
errorMessage: PropTypes.shape({
|
102
117
|
type: PropTypes.string.isRequired,
|
103
|
-
params: PropTypes.shape().isRequired,
|
118
|
+
params: PropTypes.shape({}).isRequired,
|
104
119
|
uri: PropTypes.string.isRequired
|
105
120
|
})
|
106
121
|
}
|
@@ -1,16 +1,21 @@
|
|
1
1
|
declare module '#sprockets/components/group' {
|
2
2
|
import React from 'react'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
type GroupProps = SprocketsTypes.Components.Group.GroupProps
|
5
|
+
type GroupState = SprocketsTypes.Components.Group.GroupState
|
6
|
+
|
7
|
+
export default class Group<P extends GroupProps, S extends GroupState> extends React.Component<P, S> {
|
8
|
+
static propTypes: object
|
9
|
+
|
10
|
+
getClassName (): string
|
9
11
|
|
10
|
-
|
12
|
+
shouldComponentUpdate (props: GroupProps, state: GroupState): boolean
|
13
|
+
}
|
11
14
|
}
|
12
15
|
|
13
16
|
declare module 'shinkansen-sprockets/components/group' {
|
17
|
+
export type GroupProps = SprocketsTypes.Components.Group.GroupProps
|
18
|
+
export type GroupState = SprocketsTypes.Components.Group.GroupState
|
19
|
+
|
14
20
|
export { default } from '#sprockets/components/group'
|
15
|
-
export * from '#sprockets/components/group'
|
16
21
|
}
|
@@ -1,42 +1,36 @@
|
|
1
1
|
/**
|
2
|
-
* Group
|
3
|
-
*
|
4
|
-
* @typedef {import('shinkansen-sprockets/components/group').GroupProps} GroupProps
|
2
|
+
* @typedef {SprocketsTypes.Components.Group.GroupProps} GroupProps
|
5
3
|
*/
|
6
4
|
|
5
|
+
/**
|
6
|
+
* Group component
|
7
|
+
*/
|
7
8
|
import React, { Component } from 'react'
|
8
9
|
import PropTypes from 'prop-types'
|
9
10
|
|
10
|
-
import {
|
11
|
-
DEFAULT_HANDLE_CHANGE
|
12
|
-
} from '#sprockets/common'
|
13
|
-
|
14
11
|
export default class Group extends Component {
|
15
12
|
getClassName () {
|
16
13
|
return 'group'
|
17
14
|
}
|
18
15
|
|
19
16
|
/**
|
20
|
-
*
|
21
|
-
*
|
17
|
+
* @param {GroupProps} props
|
18
|
+
* @returns {boolean}
|
22
19
|
*/
|
23
|
-
shouldComponentUpdate (props
|
20
|
+
shouldComponentUpdate (props) {
|
24
21
|
return (
|
25
|
-
(props.onChange !== this.props.onChange) ||
|
26
22
|
(props.children !== this.props.children)
|
27
23
|
)
|
28
24
|
}
|
29
25
|
|
30
26
|
render () {
|
31
27
|
const {
|
32
|
-
onChange = DEFAULT_HANDLE_CHANGE,
|
33
28
|
groupRef,
|
34
29
|
children
|
35
30
|
} = this.props
|
36
31
|
|
37
32
|
return (
|
38
33
|
<fieldset
|
39
|
-
onChange={onChange}
|
40
34
|
className={this.getClassName()}
|
41
35
|
ref={groupRef}>
|
42
36
|
{children}
|
@@ -46,7 +40,6 @@ export default class Group extends Component {
|
|
46
40
|
}
|
47
41
|
|
48
42
|
Group.propTypes = {
|
49
|
-
onChange: PropTypes.func,
|
50
43
|
children: PropTypes.oneOfType([
|
51
44
|
PropTypes.node,
|
52
45
|
PropTypes.arrayOf(
|
@@ -54,6 +47,6 @@ Group.propTypes = {
|
|
54
47
|
)
|
55
48
|
]),
|
56
49
|
groupRef: PropTypes.shape({
|
57
|
-
current: PropTypes.shape().isRequired
|
50
|
+
current: PropTypes.shape({}).isRequired
|
58
51
|
})
|
59
52
|
}
|
@@ -1,14 +1,25 @@
|
|
1
1
|
declare module '#sprockets/components/title' {
|
2
2
|
import React from 'react'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
type TitleProps = SprocketsTypes.Components.Title.TitleProps
|
5
|
+
|
6
|
+
export default class Title<P extends TitleProps> extends React.Component<P> {
|
7
|
+
static propTypes: object
|
8
|
+
|
9
|
+
hasTextContent (): boolean
|
10
|
+
|
11
|
+
getTextContent (): string
|
7
12
|
|
8
|
-
|
13
|
+
getClassName (): string
|
14
|
+
|
15
|
+
shouldComponentUpdate (props: TitleProps): boolean
|
16
|
+
|
17
|
+
renderTextContent (): React.JSX.Element | null
|
18
|
+
}
|
9
19
|
}
|
10
20
|
|
11
21
|
declare module 'shinkansen-sprockets/components/title' {
|
22
|
+
export type TitleProps = SprocketsTypes.Components.Title.TitleProps
|
23
|
+
|
12
24
|
export { default } from '#sprockets/components/title'
|
13
|
-
export * from '#sprockets/components/title'
|
14
25
|
}
|
@@ -1,3 +1,7 @@
|
|
1
|
+
/**
|
2
|
+
* @typedef {SprocketsTypes.Components.Title.TitleProps} TitleProps
|
3
|
+
*/
|
4
|
+
|
1
5
|
/**
|
2
6
|
* Title component
|
3
7
|
*/
|
@@ -8,13 +12,17 @@ import TextContent from '#sprockets/components/common/text-content'
|
|
8
12
|
|
9
13
|
export default class Title extends Component {
|
10
14
|
hasTextContent () {
|
11
|
-
const {
|
15
|
+
const {
|
16
|
+
title
|
17
|
+
} = this.props
|
12
18
|
|
13
19
|
return !!title
|
14
20
|
}
|
15
21
|
|
16
22
|
getTextContent () {
|
17
|
-
const {
|
23
|
+
const {
|
24
|
+
title
|
25
|
+
} = this.props
|
18
26
|
|
19
27
|
return title
|
20
28
|
}
|
@@ -23,7 +31,11 @@ export default class Title extends Component {
|
|
23
31
|
return 'title'
|
24
32
|
}
|
25
33
|
|
26
|
-
|
34
|
+
/**
|
35
|
+
* @param {TitleProps} props
|
36
|
+
* @returns {boolean}
|
37
|
+
*/
|
38
|
+
shouldComponentUpdate (props) {
|
27
39
|
return (
|
28
40
|
(props.title !== this.props.title)
|
29
41
|
)
|
@@ -34,7 +46,9 @@ export default class Title extends Component {
|
|
34
46
|
const textContent = this.getTextContent()
|
35
47
|
|
36
48
|
return (
|
37
|
-
<TextContent
|
49
|
+
<TextContent
|
50
|
+
textContent={textContent}
|
51
|
+
/>
|
38
52
|
)
|
39
53
|
}
|
40
54
|
|
package/src/index.d.mts
CHANGED
@@ -5,5 +5,13 @@ declare module '#sprockets' {
|
|
5
5
|
}
|
6
6
|
|
7
7
|
declare module 'shinkansen-sprockets' {
|
8
|
+
export type AnswerDefinitionType = SprocketsTypes.AnswerDefinitionType
|
9
|
+
|
10
|
+
export type FieldChangeType = SprocketsTypes.FieldChangeType
|
11
|
+
|
12
|
+
export type ErrorDefinitionType = SprocketsTypes.ErrorDefinitionType
|
13
|
+
|
14
|
+
export type FieldErrorType = SprocketsTypes.FieldErrorType
|
15
|
+
|
8
16
|
export * from '#sprockets'
|
9
17
|
}
|
@@ -2,8 +2,8 @@ import React from 'react'
|
|
2
2
|
import PropTypes from 'prop-types'
|
3
3
|
|
4
4
|
/**
|
5
|
-
*
|
6
|
-
*
|
5
|
+
* @param {{ answer: { title: string } }} answer
|
6
|
+
* @returns {React.JSX.Element}
|
7
7
|
*/
|
8
8
|
export default function AnswerTitle ({ answer: { title } }) {
|
9
9
|
return (
|
@@ -2,22 +2,39 @@ import React from 'react'
|
|
2
2
|
import PropTypes from 'prop-types'
|
3
3
|
|
4
4
|
/**
|
5
|
-
*
|
6
|
-
*
|
5
|
+
* @param {number} n
|
6
|
+
* @returns {(
|
7
|
+
* a: Array<string | React.JSX.Element>,
|
8
|
+
* v: string,
|
9
|
+
* i: number
|
10
|
+
* ) => Array<string | React.JSX.Element>}
|
11
|
+
*/
|
12
|
+
function getReduce (n) {
|
13
|
+
/**
|
14
|
+
* @param {Array<string | React.JSX.Element>} a
|
15
|
+
* @param {string} v
|
16
|
+
* @param {number} i
|
17
|
+
* @returns {Array<string | React.JSX.Element>}
|
18
|
+
*/
|
19
|
+
return function reduce (a, v, i) {
|
20
|
+
const s = String(v)
|
21
|
+
|
22
|
+
return (i !== n)
|
23
|
+
? a.concat(s).concat(<br key={i} />)
|
24
|
+
: a.concat(s)
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
/**
|
29
|
+
* @param {string | string[]} value
|
30
|
+
* @returns {string | Array<string | React.JSX.Element>}
|
7
31
|
*/
|
8
32
|
function getAnswerValue (value) {
|
9
33
|
if (Array.isArray(value)) {
|
10
34
|
const n = value.length - 1
|
11
35
|
|
12
36
|
return (
|
13
|
-
value
|
14
|
-
.reduce((a, v, i) => {
|
15
|
-
const s = String(v)
|
16
|
-
|
17
|
-
return (i !== n)
|
18
|
-
? a.concat(s).concat(<br key={i} />)
|
19
|
-
: a.concat(s)
|
20
|
-
}, [])
|
37
|
+
value.reduce(getReduce(n), [])
|
21
38
|
)
|
22
39
|
}
|
23
40
|
|
@@ -25,8 +42,8 @@ function getAnswerValue (value) {
|
|
25
42
|
}
|
26
43
|
|
27
44
|
/**
|
28
|
-
*
|
29
|
-
*
|
45
|
+
* @param {{ answer: { value: string | string[] } }} answer
|
46
|
+
* @returns {React.JSX.Element}
|
30
47
|
*/
|
31
48
|
export default function AnswerValue ({ answer: { value } }) {
|
32
49
|
return (
|
@@ -12,6 +12,10 @@ import VisuallyHiddenText from '#sprockets/components/common/visually-hidden-tex
|
|
12
12
|
|
13
13
|
const log = debug('shinkansen-sprockets/sprockets/check-answers/group/change-answer')
|
14
14
|
|
15
|
+
/**
|
16
|
+
* @param {{ textContent?: string, visuallyHiddenText: string }} props
|
17
|
+
* @returns {React.JSX.Element | null}
|
18
|
+
*/
|
15
19
|
function TextContentWithVisuallyHiddenText ({ textContent, visuallyHiddenText }) {
|
16
20
|
return (
|
17
21
|
<>
|
@@ -23,10 +27,14 @@ function TextContentWithVisuallyHiddenText ({ textContent, visuallyHiddenText })
|
|
23
27
|
}
|
24
28
|
|
25
29
|
TextContentWithVisuallyHiddenText.propTypes = {
|
26
|
-
textContent: PropTypes.string
|
27
|
-
visuallyHiddenText: PropTypes.string
|
30
|
+
textContent: PropTypes.string,
|
31
|
+
visuallyHiddenText: PropTypes.string
|
28
32
|
}
|
29
33
|
|
34
|
+
/**
|
35
|
+
* @param {{ textContent?: string, visuallyHiddenText?: string }} props
|
36
|
+
* @returns {React.JSX.Element | null}
|
37
|
+
*/
|
30
38
|
function LinkText ({ textContent, visuallyHiddenText }) {
|
31
39
|
if (textContent) {
|
32
40
|
return (
|
@@ -35,16 +43,18 @@ function LinkText ({ textContent, visuallyHiddenText }) {
|
|
35
43
|
: <TextContent textContent={textContent} />
|
36
44
|
)
|
37
45
|
}
|
46
|
+
|
47
|
+
return null
|
38
48
|
}
|
39
49
|
|
40
50
|
LinkText.propTypes = {
|
41
|
-
textContent: PropTypes.string
|
42
|
-
visuallyHiddenText: PropTypes.string
|
51
|
+
textContent: PropTypes.string,
|
52
|
+
visuallyHiddenText: PropTypes.string
|
43
53
|
}
|
44
54
|
|
45
55
|
/**
|
46
|
-
*
|
47
|
-
*
|
56
|
+
* @param {{ changeAnswer: { href: string, text: string, visuallyHiddenText?: string } }} answer
|
57
|
+
* @returns {React.JSX.Element}
|
48
58
|
*/
|
49
59
|
export default function ChangeAnswer ({ changeAnswer: { href, text, visuallyHiddenText } }) {
|
50
60
|
log('ChangeAnswer')
|
@@ -62,6 +72,6 @@ ChangeAnswer.propTypes = {
|
|
62
72
|
changeAnswer: PropTypes.shape({
|
63
73
|
href: PropTypes.string.isRequired,
|
64
74
|
text: PropTypes.string.isRequired,
|
65
|
-
visuallyHiddenText: PropTypes.string
|
75
|
+
visuallyHiddenText: PropTypes.string
|
66
76
|
}).isRequired
|
67
77
|
}
|
@@ -1,9 +1,15 @@
|
|
1
1
|
declare module '#sprockets/sprockets/check-answers/group' {
|
2
2
|
import Group from '#sprockets/components/group'
|
3
3
|
|
4
|
-
|
4
|
+
type CheckAnswersProps = SprocketsTypes.Components.Group.CheckAnswers.CheckAnswersProps
|
5
|
+
type CheckAnswersState = SprocketsTypes.Components.Group.CheckAnswers.CheckAnswersState
|
6
|
+
|
7
|
+
export default class CheckAnswersGroup<P extends CheckAnswersProps, S extends CheckAnswersState> extends Group<P, S> {}
|
5
8
|
}
|
6
9
|
|
7
10
|
declare module 'shinkansen-sprockets/sprockets/check-answers/group' {
|
11
|
+
export type CheckAnswersProps = SprocketsTypes.Components.Group.CheckAnswers.CheckAnswersProps
|
12
|
+
export type CheckAnswersState = SprocketsTypes.Components.Group.CheckAnswers.CheckAnswersState
|
13
|
+
|
8
14
|
export { default } from '#sprockets/sprockets/check-answers/group'
|
9
15
|
}
|
@@ -1,44 +1,56 @@
|
|
1
1
|
/**
|
2
|
-
*
|
3
|
-
*
|
4
|
-
*
|
5
|
-
*
|
6
|
-
* Group
|
7
|
-
*
|
8
|
-
* @typedef {Object} GroupState
|
9
|
-
* @property {{}} [checkAnswers]
|
2
|
+
* @typedef {SprocketsTypes.AnswerDefinitionType} AnswerDefinitionType
|
3
|
+
* @typedef {SprocketsTypes.Components.Group.GroupProps} GroupProps
|
4
|
+
* @typedef {SprocketsTypes.Components.Group.GroupState} GroupState
|
5
|
+
* @typedef {SprocketsTypes.Components.Group.CheckAnswers.CheckAnswersProps} CheckAnswersProps
|
6
|
+
* @typedef {SprocketsTypes.Components.Group.CheckAnswers.CheckAnswersState} CheckAnswersState
|
10
7
|
*/
|
11
8
|
|
9
|
+
/**
|
10
|
+
* CheckAnswersGroup component
|
11
|
+
*/
|
12
12
|
import React from 'react'
|
13
13
|
import PropTypes from 'prop-types'
|
14
|
-
|
15
|
-
import debug from 'debug'
|
16
|
-
|
17
14
|
import equal from 'fast-deep-equal'
|
18
15
|
import classnames from 'classnames'
|
19
16
|
|
17
|
+
import debug from 'debug'
|
18
|
+
|
20
19
|
import Group from '#sprockets/components/group'
|
21
20
|
|
22
21
|
import {
|
23
22
|
getKey
|
24
23
|
} from '#sprockets/transformers/common'
|
25
24
|
|
26
|
-
import AnswerTitle from './answer-title.
|
27
|
-
import AnswerValue from './answer-value.
|
28
|
-
import ChangeAnswer from './change-answer.
|
25
|
+
import AnswerTitle from './answer-title.jsx'
|
26
|
+
import AnswerValue from './answer-value.jsx'
|
27
|
+
import ChangeAnswer from './change-answer.jsx'
|
29
28
|
|
29
|
+
/**
|
30
|
+
* @type {AnswerDefinitionType[]}
|
31
|
+
*/
|
30
32
|
const DEFAULT_CHECK_ANSWERS = []
|
31
33
|
|
32
34
|
const log = debug('shinkansen-sprockets/components/group/check-answers')
|
33
35
|
|
34
|
-
|
36
|
+
/**
|
37
|
+
* @param {AnswerDefinitionType} answer
|
38
|
+
* @param {number} index
|
39
|
+
* @returns {React.JSX.Element}
|
40
|
+
*/
|
35
41
|
function render ({ params: { answer, changeAnswer: { href, text, ...changeAnswer } } }, index) {
|
36
42
|
log('render')
|
37
43
|
|
38
44
|
return (
|
39
45
|
<div key={getKey(href, text, index)} className='answer'>
|
40
|
-
<AnswerTitle
|
41
|
-
|
46
|
+
<AnswerTitle
|
47
|
+
answer={answer}
|
48
|
+
/>
|
49
|
+
|
50
|
+
<AnswerValue
|
51
|
+
answer={answer}
|
52
|
+
/>
|
53
|
+
|
42
54
|
<ChangeAnswer
|
43
55
|
changeAnswer={{ ...changeAnswer, href, text }}
|
44
56
|
/>
|
@@ -46,13 +58,14 @@ function render ({ params: { answer, changeAnswer: { href, text, ...changeAnswer
|
|
46
58
|
)
|
47
59
|
}
|
48
60
|
|
61
|
+
/**
|
62
|
+
* @extends {Group<GroupProps & CheckAnswersProps, GroupState & CheckAnswersState>}
|
63
|
+
*/
|
49
64
|
export default class CheckAnswersGroup extends Group {
|
50
65
|
/**
|
51
|
-
*
|
66
|
+
* @type {CheckAnswersState}
|
52
67
|
*/
|
53
|
-
state = {
|
54
|
-
checkAnswers: DEFAULT_CHECK_ANSWERS
|
55
|
-
}
|
68
|
+
state = {}
|
56
69
|
|
57
70
|
getClassName () {
|
58
71
|
return classnames(super.getClassName(), 'check-answers')
|
@@ -61,9 +74,9 @@ export default class CheckAnswersGroup extends Group {
|
|
61
74
|
/**
|
62
75
|
* Compare latest 'props' with 'state' for changes to 'checkAnswers'
|
63
76
|
*
|
64
|
-
*
|
65
|
-
*
|
66
|
-
*
|
77
|
+
* @param {CheckAnswersProps} props Latest props
|
78
|
+
* @param {CheckAnswersState} state Current state
|
79
|
+
* @returns {CheckAnswersState}
|
67
80
|
*/
|
68
81
|
static getDerivedStateFromProps ({ checkAnswers }, { checkAnswers: C }) {
|
69
82
|
return {
|
@@ -74,9 +87,9 @@ export default class CheckAnswersGroup extends Group {
|
|
74
87
|
/**
|
75
88
|
* Compare latest 'props' with 'state' for changes to 'checkAnswers'
|
76
89
|
*
|
77
|
-
*
|
78
|
-
*
|
79
|
-
*
|
90
|
+
* @param {CheckAnswersProps} props Latest props
|
91
|
+
* @param {CheckAnswersState} state Current state
|
92
|
+
* @returns {boolean}
|
80
93
|
*/
|
81
94
|
shouldComponentUpdate (props, state) {
|
82
95
|
const {
|
@@ -95,6 +108,8 @@ export default class CheckAnswersGroup extends Group {
|
|
95
108
|
checkAnswers = DEFAULT_CHECK_ANSWERS
|
96
109
|
} = this.props
|
97
110
|
|
111
|
+
console.log('checkAnswers', checkAnswers)
|
112
|
+
|
98
113
|
if (checkAnswers.length) {
|
99
114
|
const {
|
100
115
|
groupRef
|
@@ -115,5 +130,5 @@ export default class CheckAnswersGroup extends Group {
|
|
115
130
|
|
116
131
|
CheckAnswersGroup.propTypes = {
|
117
132
|
...Group.propTypes,
|
118
|
-
checkAnswers: PropTypes.arrayOf(PropTypes.shape())
|
133
|
+
checkAnswers: PropTypes.arrayOf(PropTypes.shape({}))
|
119
134
|
}
|
@@ -1,9 +1,13 @@
|
|
1
1
|
declare module '#sprockets/sprockets/check-answers' {
|
2
2
|
import Sprocket from '#sprockets/sprockets'
|
3
3
|
|
4
|
-
|
4
|
+
type CheckAnswersProps = SprocketsTypes.Sprockets.Sprocket.CheckAnswers.CheckAnswersProps
|
5
|
+
|
6
|
+
export default class CheckAnswersSprocket<P extends CheckAnswersProps> extends Sprocket<P> {}
|
5
7
|
}
|
6
8
|
|
7
9
|
declare module 'shinkansen-sprockets/sprockets/check-answers' {
|
10
|
+
export type CheckAnswersProps = SprocketsTypes.Sprockets.Sprocket.CheckAnswers.CheckAnswersProps
|
11
|
+
|
8
12
|
export { default } from '#sprockets/sprockets/check-answers'
|
9
13
|
}
|