@modernpoacher/sprockets 0.0.288 → 1.0.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/.prettierignore +4 -0
- package/babel.config.cjs +6 -2
- package/eslint.config.mjs +33 -71
- package/index.d.mts +156 -6
- package/jest.after-each.mjs +10 -0
- package/jest.before-each.mjs +10 -0
- package/jest.config.mjs +11 -1
- package/package.json +93 -35
- package/src/js/components/common/text-content/index.cjs +20 -0
- package/src/js/components/common/text-content/index.d.cts +2 -0
- package/src/{components → js/components}/common/text-content/index.d.mts +1 -3
- package/src/{components → js/components}/common/text-content/index.jsx +7 -6
- package/src/{components → js/components}/common/visually-hidden-text/index.cjs +5 -2
- package/src/js/components/common/visually-hidden-text/index.d.cts +2 -0
- package/src/{components → js/components}/common/visually-hidden-text/index.d.mts +1 -3
- package/src/{components → js/components}/common/visually-hidden-text/index.jsx +7 -6
- package/src/{components → js/components}/description/index.cjs +5 -2
- package/src/js/components/description/index.d.cts +2 -0
- package/src/{components → js/components}/description/index.d.mts +2 -7
- package/src/js/components/description/index.jsx +5 -0
- package/src/{components → js/components}/error-message/index.cjs +5 -2
- package/src/js/components/error-message/index.d.cts +2 -0
- package/src/{components → js/components}/error-message/index.d.mts +2 -7
- package/src/js/components/error-message/index.jsx +5 -0
- package/src/{components → js/components}/group/index.cjs +5 -2
- package/src/js/components/group/index.d.cts +2 -0
- package/src/js/components/group/index.d.mts +9 -0
- package/src/js/components/group/index.jsx +5 -0
- package/src/js/components/index.cjs +32 -0
- package/src/js/components/index.d.cts +4 -0
- package/src/js/components/index.d.mts +4 -0
- package/src/js/components/index.mjs +10 -0
- package/src/{components → js/components}/title/index.cjs +5 -2
- package/src/js/components/title/index.d.cts +2 -0
- package/src/{components → js/components}/title/index.d.mts +2 -7
- package/src/js/components/title/index.jsx +5 -0
- package/src/js/index.d.cts +34 -0
- package/src/js/index.d.mts +34 -0
- package/src/js/sprockets/check-answers/group/answer-item.d.cts +1 -0
- package/src/js/sprockets/check-answers/group/answer-item.d.mts +11 -0
- package/src/{sprockets → js/sprockets}/check-answers/group/answer-item.jsx +9 -0
- package/src/{sprockets → js/sprockets}/check-answers/group/answer-title.cjs +1 -0
- package/src/js/sprockets/check-answers/group/answer-title.d.cts +1 -0
- package/src/js/sprockets/check-answers/group/answer-title.d.mts +9 -0
- package/src/{sprockets → js/sprockets}/check-answers/group/answer-title.jsx +2 -2
- package/src/{sprockets → js/sprockets}/check-answers/group/answer-value.cjs +1 -0
- package/src/js/sprockets/check-answers/group/answer-value.d.cts +1 -0
- package/src/js/sprockets/check-answers/group/answer-value.d.mts +9 -0
- package/src/js/sprockets/check-answers/group/answer-value.jsx +63 -0
- package/src/{sprockets → js/sprockets}/check-answers/group/change-answer.cjs +1 -0
- package/src/js/sprockets/check-answers/group/change-answer.d.cts +1 -0
- package/src/js/sprockets/check-answers/group/change-answer.d.mts +9 -0
- package/src/{sprockets → js/sprockets}/check-answers/group/change-answer.jsx +20 -12
- package/src/{sprockets → js/sprockets}/check-answers/group/index.cjs +5 -2
- package/src/js/sprockets/check-answers/group/index.d.cts +2 -0
- package/src/js/sprockets/check-answers/group/index.d.mts +13 -0
- package/src/js/sprockets/check-answers/group/index.jsx +134 -0
- package/src/{sprockets → js/sprockets}/check-answers/index.cjs +5 -2
- package/src/js/sprockets/check-answers/index.d.cts +2 -0
- package/src/js/sprockets/check-answers/index.d.mts +12 -0
- package/src/{sprockets → js/sprockets}/check-answers/index.jsx +25 -12
- package/src/{sprockets → js/sprockets}/check-answers/title/index.cjs +5 -2
- package/src/js/sprockets/check-answers/title/index.d.cts +2 -0
- package/src/js/sprockets/check-answers/title/index.d.mts +12 -0
- package/src/js/sprockets/check-answers/title/index.jsx +37 -0
- package/src/{sprockets → js/sprockets}/error-summary/group/index.cjs +5 -2
- package/src/js/sprockets/error-summary/group/index.d.cts +2 -0
- package/src/js/sprockets/error-summary/group/index.d.mts +13 -0
- package/src/js/sprockets/error-summary/group/index.jsx +124 -0
- package/src/{sprockets → js/sprockets}/error-summary/index.cjs +5 -2
- package/src/js/sprockets/error-summary/index.d.cts +2 -0
- package/src/js/sprockets/error-summary/index.d.mts +12 -0
- package/src/{sprockets → js/sprockets}/error-summary/index.jsx +26 -13
- package/src/{sprockets → js/sprockets}/error-summary/title/index.cjs +5 -2
- package/src/js/sprockets/error-summary/title/index.d.cts +2 -0
- package/src/js/sprockets/error-summary/title/index.d.mts +12 -0
- package/src/js/sprockets/error-summary/title/index.jsx +37 -0
- package/src/{sprockets → js/sprockets}/fieldset/description/index.cjs +5 -2
- package/src/js/sprockets/fieldset/description/index.d.cts +1 -0
- package/src/{sprockets → js/sprockets}/fieldset/description/index.jsx +2 -7
- package/src/{sprockets → js/sprockets}/fieldset/error-message/index.cjs +5 -2
- package/src/js/sprockets/fieldset/error-message/index.d.cts +1 -0
- package/src/{sprockets → js/sprockets}/fieldset/error-message/index.d.mts +1 -1
- package/src/{sprockets → js/sprockets}/fieldset/error-message/index.jsx +2 -7
- package/src/{sprockets → js/sprockets}/fieldset/group/index.cjs +5 -2
- package/src/js/sprockets/fieldset/group/index.d.cts +2 -0
- package/src/js/sprockets/fieldset/group/index.d.mts +13 -0
- package/src/js/sprockets/fieldset/group/index.jsx +21 -0
- package/src/{sprockets → js/sprockets}/fieldset/index.cjs +5 -2
- package/src/js/sprockets/fieldset/index.d.cts +2 -0
- package/src/js/sprockets/fieldset/index.d.mts +18 -0
- package/src/{sprockets → js/sprockets}/fieldset/index.jsx +26 -26
- package/src/{sprockets → js/sprockets}/fieldset/title/index.cjs +5 -2
- package/src/js/sprockets/fieldset/title/index.d.cts +2 -0
- package/src/js/sprockets/fieldset/title/index.d.mts +12 -0
- package/src/js/sprockets/fieldset/title/index.jsx +20 -0
- package/src/{sprockets → js/sprockets}/index.cjs +5 -5
- package/src/js/sprockets/index.d.cts +2 -0
- package/src/js/sprockets/index.d.mts +9 -0
- package/src/js/sprockets/index.jsx +5 -0
- package/src/js/super/components/description/index.cjs +20 -0
- package/src/js/super/components/description/index.d.cts +2 -0
- package/src/js/super/components/description/index.d.mts +18 -0
- package/src/{components → js/super/components}/description/index.jsx +15 -3
- package/src/js/super/components/error-message/index.cjs +20 -0
- package/src/js/super/components/error-message/index.d.cts +2 -0
- package/src/js/super/components/error-message/index.d.mts +27 -0
- package/src/{components → js/super/components}/error-message/index.jsx +8 -6
- package/src/js/super/components/group/index.cjs +20 -0
- package/src/js/super/components/group/index.d.cts +2 -0
- package/src/js/super/components/group/index.d.mts +19 -0
- package/src/js/super/components/group/index.jsx +59 -0
- package/src/js/super/components/index.cjs +32 -0
- package/src/js/super/components/index.d.cts +4 -0
- package/src/js/super/components/index.d.mts +4 -0
- package/src/js/super/components/index.mjs +10 -0
- package/src/js/super/components/title/index.cjs +20 -0
- package/src/js/super/components/title/index.d.cts +2 -0
- package/src/js/super/components/title/index.d.mts +20 -0
- package/src/js/super/components/title/index.jsx +62 -0
- package/src/{components/common/text-content → js/super/sprockets}/index.cjs +6 -3
- package/src/js/super/sprockets/index.d.cts +2 -0
- package/src/js/super/sprockets/index.d.mts +22 -0
- package/src/{sprockets → js/super/sprockets}/index.jsx +11 -18
- package/src/js/transformers/common/index.d.mts +1 -0
- package/src/{transformers → js/transformers}/common/index.mjs +5 -5
- package/src/js/transformers/index.d.mts +1 -0
- package/src/js/transformers/index.mjs +1 -0
- package/src/sass/.stylelintrc +14 -0
- package/src/sass/_sprockets.scss +77 -0
- package/src/sass/sprockets/_check-answers.scss +54 -0
- package/src/sass/sprockets/_error-summary.scss +57 -0
- package/src/sass/sprockets/_error.scss +47 -0
- package/jsconfig.json +0 -5
- package/src/common/index.d.mts +0 -9
- package/src/common/index.mjs +0 -7
- package/src/components/group/index.d.mts +0 -16
- package/src/components/group/index.jsx +0 -59
- package/src/components/title/index.jsx +0 -59
- package/src/index.d.mts +0 -9
- package/src/sprockets/check-answers/group/answer-value.jsx +0 -46
- package/src/sprockets/check-answers/group/index.d.mts +0 -9
- package/src/sprockets/check-answers/group/index.jsx +0 -125
- package/src/sprockets/check-answers/index.d.mts +0 -9
- package/src/sprockets/check-answers/title/index.d.mts +0 -9
- package/src/sprockets/check-answers/title/index.jsx +0 -29
- package/src/sprockets/error-summary/group/error-item.cjs +0 -13
- package/src/sprockets/error-summary/group/error-item.jsx +0 -22
- package/src/sprockets/error-summary/group/index.d.mts +0 -9
- package/src/sprockets/error-summary/group/index.jsx +0 -115
- package/src/sprockets/error-summary/index.d.mts +0 -9
- package/src/sprockets/error-summary/title/index.d.mts +0 -9
- package/src/sprockets/error-summary/title/index.jsx +0 -29
- package/src/sprockets/fieldset/group/index.d.mts +0 -9
- package/src/sprockets/fieldset/group/index.jsx +0 -16
- package/src/sprockets/fieldset/index.d.mts +0 -9
- package/src/sprockets/fieldset/title/index.d.mts +0 -9
- package/src/sprockets/fieldset/title/index.jsx +0 -15
- package/src/sprockets/index.d.mts +0 -17
- package/src/transformers/common/index.d.mts +0 -7
- package/tsconfig.json +0 -18
- /package/src/{index.cjs → js/index.cjs} +0 -0
- /package/src/{index.mjs → js/index.mjs} +0 -0
- /package/src/{sprockets → js/sprockets}/check-answers/group/answer-item.cjs +0 -0
- /package/src/{sprockets → js/sprockets}/fieldset/description/index.d.mts +0 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare module '#sprockets/sprockets/check-answers/group' {
|
|
2
|
+
import Group from '#sprockets/super/components/group'
|
|
3
|
+
|
|
4
|
+
export type CheckAnswersProps = SprocketsTypes.Sprockets.CheckAnswers.Group.CheckAnswersProps
|
|
5
|
+
export type CheckAnswersState = SprocketsTypes.Sprockets.CheckAnswers.Group.CheckAnswersState
|
|
6
|
+
|
|
7
|
+
export default class CheckAnswersGroup<P extends CheckAnswersProps, S extends CheckAnswersState> extends Group<P, S> {}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
declare module '@modernpoacher/sprockets/sprockets/check-answers/group' {
|
|
11
|
+
export { default } from '#sprockets/sprockets/check-answers/group'
|
|
12
|
+
export * from '#sprockets/sprockets/check-answers/group'
|
|
13
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {SprocketsTypes.AnswerDefinitionType} AnswerDefinitionType
|
|
3
|
+
* @typedef {SprocketsTypes.Super.Components.Group.GroupProps} GroupProps
|
|
4
|
+
* @typedef {SprocketsTypes.Super.Components.Group.GroupState} GroupState
|
|
5
|
+
* @typedef {SprocketsTypes.Sprockets.CheckAnswers.Group.CheckAnswersProps} CheckAnswersProps
|
|
6
|
+
* @typedef {SprocketsTypes.Sprockets.CheckAnswers.Group.CheckAnswersState} CheckAnswersState
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* CheckAnswersGroup component
|
|
11
|
+
*/
|
|
12
|
+
import React from 'react'
|
|
13
|
+
import PropTypes from 'prop-types'
|
|
14
|
+
import classnames from 'classnames'
|
|
15
|
+
import equal from 'fast-deep-equal'
|
|
16
|
+
|
|
17
|
+
import debug from 'debug'
|
|
18
|
+
|
|
19
|
+
import Group from '#sprockets/super/components/group'
|
|
20
|
+
|
|
21
|
+
import {
|
|
22
|
+
getKey
|
|
23
|
+
} from '#sprockets/transformers/common'
|
|
24
|
+
|
|
25
|
+
import AnswerTitle from '#sprockets/sprockets/check-answers/group/answer-title'
|
|
26
|
+
import AnswerValue from '#sprockets/sprockets/check-answers/group/answer-value'
|
|
27
|
+
import ChangeAnswer from '#sprockets/sprockets/check-answers/group/change-answer'
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @type {AnswerDefinitionType[]}
|
|
31
|
+
*/
|
|
32
|
+
const DEFAULT_CHECK_ANSWERS = []
|
|
33
|
+
|
|
34
|
+
const log = debug('@modernpoacher/sprockets/components/group/check-answers')
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @param {AnswerDefinitionType} answer
|
|
38
|
+
* @param {number} index
|
|
39
|
+
* @returns {React.JSX.Element}
|
|
40
|
+
*/
|
|
41
|
+
function render ({ answer: { title, value }, changeAnswer: { href, text, visuallyHiddenText } }, index) {
|
|
42
|
+
log('render')
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<div key={getKey(href, text, index)} className='answer'>
|
|
46
|
+
<AnswerTitle
|
|
47
|
+
title={title}
|
|
48
|
+
/>
|
|
49
|
+
|
|
50
|
+
<AnswerValue
|
|
51
|
+
value={value}
|
|
52
|
+
/>
|
|
53
|
+
|
|
54
|
+
<ChangeAnswer
|
|
55
|
+
href={href}
|
|
56
|
+
text={text}
|
|
57
|
+
visuallyHiddenText={visuallyHiddenText}
|
|
58
|
+
/>
|
|
59
|
+
</div>
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @extends {Group<GroupProps & CheckAnswersProps, GroupState & CheckAnswersState>}
|
|
65
|
+
*/
|
|
66
|
+
export default class CheckAnswersGroup extends Group {
|
|
67
|
+
/**
|
|
68
|
+
* @type {CheckAnswersState}
|
|
69
|
+
*/
|
|
70
|
+
state = {}
|
|
71
|
+
|
|
72
|
+
getClassName () {
|
|
73
|
+
return classnames(super.getClassName(), 'check-answers')
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Compare latest 'props' with 'state' for changes to 'checkAnswers'
|
|
78
|
+
*
|
|
79
|
+
* @param {CheckAnswersProps} props Latest props
|
|
80
|
+
* @param {CheckAnswersState} state Current state
|
|
81
|
+
* @returns {CheckAnswersState}
|
|
82
|
+
*/
|
|
83
|
+
static getDerivedStateFromProps ({ checkAnswers: c }, { checkAnswers: C }) {
|
|
84
|
+
return {
|
|
85
|
+
checkAnswers: (c === C || equal(c, C)) ? C : c
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Compare latest 'props' with 'state' for changes to 'checkAnswers'
|
|
91
|
+
*
|
|
92
|
+
* @param {CheckAnswersProps} props Latest props
|
|
93
|
+
* @param {CheckAnswersState} state Current state
|
|
94
|
+
* @returns {boolean}
|
|
95
|
+
*/
|
|
96
|
+
shouldComponentUpdate (props, state) {
|
|
97
|
+
const {
|
|
98
|
+
checkAnswers: c = DEFAULT_CHECK_ANSWERS
|
|
99
|
+
} = this.state
|
|
100
|
+
|
|
101
|
+
const {
|
|
102
|
+
checkAnswers: C = DEFAULT_CHECK_ANSWERS
|
|
103
|
+
} = state
|
|
104
|
+
|
|
105
|
+
return !(c === C || equal(c, C))
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
render () {
|
|
109
|
+
const {
|
|
110
|
+
checkAnswers = DEFAULT_CHECK_ANSWERS
|
|
111
|
+
} = this.props
|
|
112
|
+
|
|
113
|
+
if (checkAnswers.length) {
|
|
114
|
+
const {
|
|
115
|
+
groupRef
|
|
116
|
+
} = this.props
|
|
117
|
+
|
|
118
|
+
return (
|
|
119
|
+
<dl
|
|
120
|
+
className={this.getClassName()}
|
|
121
|
+
ref={groupRef}>
|
|
122
|
+
{checkAnswers.map(render)}
|
|
123
|
+
</dl>
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return null
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
CheckAnswersGroup.propTypes = {
|
|
132
|
+
...Group.propTypes,
|
|
133
|
+
checkAnswers: PropTypes.arrayOf(PropTypes.shape({}))
|
|
134
|
+
}
|
|
@@ -11,7 +11,10 @@ const log = debug('@modernpoacher/sprockets/sprockets/check-answers')
|
|
|
11
11
|
log('`sprockets` is awake')
|
|
12
12
|
|
|
13
13
|
const {
|
|
14
|
-
default:
|
|
14
|
+
default: CheckAnswers
|
|
15
15
|
} = require('./index.jsx')
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Exports only default
|
|
19
|
+
*/
|
|
20
|
+
module.exports = CheckAnswers
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare module '#sprockets/sprockets/check-answers' {
|
|
2
|
+
import Sprocket from '#sprockets/sprockets'
|
|
3
|
+
|
|
4
|
+
export type CheckAnswersProps = SprocketsTypes.Sprockets.CheckAnswers.CheckAnswersProps
|
|
5
|
+
|
|
6
|
+
export default class CheckAnswersSprocket<P extends CheckAnswersProps> extends Sprocket<P> {}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare module '@modernpoacher/sprockets/sprockets/check-answers' {
|
|
10
|
+
export { default } from '#sprockets/sprockets/check-answers'
|
|
11
|
+
export * from '#sprockets/sprockets/check-answers'
|
|
12
|
+
}
|
|
@@ -1,33 +1,46 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* @typedef {SprocketsTypes.AnswerDefinitionType} AnswerDefinitionType
|
|
3
|
+
* @typedef {SprocketsTypes.Sprockets.SprocketProps} SprocketProps
|
|
4
|
+
* @typedef {SprocketsTypes.Sprockets.CheckAnswers.CheckAnswersProps} CheckAnswersProps
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* CheckAnswersSprocket component
|
|
9
|
+
*/
|
|
7
10
|
import React from 'react'
|
|
8
11
|
import PropTypes from 'prop-types'
|
|
9
|
-
|
|
10
12
|
import classnames from 'classnames'
|
|
11
13
|
|
|
12
14
|
import Sprocket from '#sprockets/sprockets'
|
|
13
|
-
import Title from '
|
|
14
|
-
import Group from '
|
|
15
|
+
import Title from '#sprockets/sprockets/check-answers/title'
|
|
16
|
+
import Group from '#sprockets/sprockets/check-answers/group'
|
|
15
17
|
|
|
18
|
+
/**
|
|
19
|
+
* @type {AnswerDefinitionType[]}
|
|
20
|
+
*/
|
|
16
21
|
const DEFAULT_CHECK_ANSWERS = []
|
|
17
22
|
|
|
23
|
+
/**
|
|
24
|
+
* @extends {Sprocket<SprocketProps & CheckAnswersProps>}
|
|
25
|
+
*/
|
|
18
26
|
export default class CheckAnswersSprocket extends Sprocket {
|
|
19
27
|
getClassName () {
|
|
20
28
|
return classnames(super.getClassName(), 'check-answers')
|
|
21
29
|
}
|
|
22
30
|
|
|
23
31
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
32
|
+
* @param {CheckAnswersProps} props
|
|
33
|
+
* @returns {boolean}
|
|
26
34
|
*/
|
|
27
|
-
shouldComponentUpdate (props
|
|
35
|
+
shouldComponentUpdate (props) {
|
|
36
|
+
const {
|
|
37
|
+
checkAnswers,
|
|
38
|
+
...superProps
|
|
39
|
+
} = props
|
|
40
|
+
|
|
28
41
|
return (
|
|
29
|
-
super.shouldComponentUpdate(
|
|
30
|
-
(
|
|
42
|
+
super.shouldComponentUpdate(superProps) ||
|
|
43
|
+
(checkAnswers !== this.props.checkAnswers)
|
|
31
44
|
)
|
|
32
45
|
}
|
|
33
46
|
|
|
@@ -75,5 +88,5 @@ export default class CheckAnswersSprocket extends Sprocket {
|
|
|
75
88
|
|
|
76
89
|
CheckAnswersSprocket.propTypes = {
|
|
77
90
|
...Sprocket.propTypes,
|
|
78
|
-
checkAnswers: PropTypes.arrayOf(PropTypes.shape())
|
|
91
|
+
checkAnswers: PropTypes.arrayOf(PropTypes.shape({}))
|
|
79
92
|
}
|
|
@@ -11,7 +11,10 @@ const log = debug('@modernpoacher/sprockets/sprockets/check-answers/title')
|
|
|
11
11
|
log('`sprockets` is awake')
|
|
12
12
|
|
|
13
13
|
const {
|
|
14
|
-
default:
|
|
14
|
+
default: Title
|
|
15
15
|
} = require('./index.jsx')
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Exports only default
|
|
19
|
+
*/
|
|
20
|
+
module.exports = Title
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare module '#sprockets/sprockets/check-answers/title' {
|
|
2
|
+
import Title from '#sprockets/super/components/title'
|
|
3
|
+
|
|
4
|
+
export type CheckAnswersProps = SprocketsTypes.Sprockets.CheckAnswers.Title.CheckAnswersProps
|
|
5
|
+
|
|
6
|
+
export default class CheckAnswersTitle<P extends CheckAnswersProps> extends Title<P> {}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare module '@modernpoacher/sprockets/sprockets/check-answers/title' {
|
|
10
|
+
export { default } from '#sprockets/sprockets/check-answers/title'
|
|
11
|
+
export * from '#sprockets/sprockets/check-answers/title'
|
|
12
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {SprocketsTypes.Super.Components.Title.TitleProps} TitleProps
|
|
3
|
+
* @typedef {SprocketsTypes.Sprockets.CheckAnswers.Title.CheckAnswersProps} CheckAnswersProps
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* CheckAnswersTitle component
|
|
8
|
+
*/
|
|
9
|
+
import React from 'react'
|
|
10
|
+
import classnames from 'classnames'
|
|
11
|
+
|
|
12
|
+
import Title from '#sprockets/super/components/title'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @extends {Title<TitleProps & CheckAnswersProps>}
|
|
16
|
+
*/
|
|
17
|
+
export default class CheckAnswersTitle extends Title {
|
|
18
|
+
getClassName () {
|
|
19
|
+
return classnames(super.getClassName(), 'check-answers')
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
render () {
|
|
23
|
+
const {
|
|
24
|
+
title
|
|
25
|
+
} = this.props
|
|
26
|
+
|
|
27
|
+
if (title) {
|
|
28
|
+
return (
|
|
29
|
+
<h2 className={this.getClassName()}>
|
|
30
|
+
{this.renderTextContent(title)}
|
|
31
|
+
</h2>
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return null
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -11,7 +11,10 @@ const log = debug('@modernpoacher/sprockets/sprockets/error-summary/group')
|
|
|
11
11
|
log('`sprockets` is awake')
|
|
12
12
|
|
|
13
13
|
const {
|
|
14
|
-
default:
|
|
14
|
+
default: Group
|
|
15
15
|
} = require('./index.jsx')
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Exports only default
|
|
19
|
+
*/
|
|
20
|
+
module.exports = Group
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare module '#sprockets/sprockets/error-summary/group' {
|
|
2
|
+
import Group from '#sprockets/super/components/group'
|
|
3
|
+
|
|
4
|
+
export type ErrorSummaryProps = SprocketsTypes.Sprockets.ErrorSummary.Group.ErrorSummaryProps
|
|
5
|
+
export type ErrorSummaryState = SprocketsTypes.Sprockets.ErrorSummary.Group.ErrorSummaryState
|
|
6
|
+
|
|
7
|
+
export default class ErrorSummaryGroup<P extends ErrorSummaryProps, S extends ErrorSummaryState> extends Group<P, S> {}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
declare module '@modernpoacher/sprockets/sprockets/error-summary/group' {
|
|
11
|
+
export { default } from '#sprockets/sprockets/error-summary/group'
|
|
12
|
+
export * from '#sprockets/sprockets/error-summary/group'
|
|
13
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {SprocketsTypes.ErrorDefinitionType} ErrorDefinitionType
|
|
3
|
+
* @typedef {SprocketsTypes.Super.Components.Group.GroupProps} GroupProps
|
|
4
|
+
* @typedef {SprocketsTypes.Super.Components.Group.GroupState} GroupState
|
|
5
|
+
* @typedef {SprocketsTypes.Sprockets.ErrorSummary.Group.ErrorSummaryProps} ErrorSummaryProps
|
|
6
|
+
* @typedef {SprocketsTypes.Sprockets.ErrorSummary.Group.ErrorSummaryState} ErrorSummaryState
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* ErrorSummaryGroup component
|
|
11
|
+
*/
|
|
12
|
+
import React from 'react'
|
|
13
|
+
import PropTypes from 'prop-types'
|
|
14
|
+
import classnames from 'classnames'
|
|
15
|
+
import equal from 'fast-deep-equal'
|
|
16
|
+
|
|
17
|
+
import debug from 'debug'
|
|
18
|
+
|
|
19
|
+
import Group from '#sprockets/super/components/group'
|
|
20
|
+
|
|
21
|
+
import {
|
|
22
|
+
getKey
|
|
23
|
+
} from '#sprockets/transformers/common'
|
|
24
|
+
|
|
25
|
+
import TextContent from '#sprockets/components/common/text-content'
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @type {ErrorDefinitionType[]}
|
|
29
|
+
*/
|
|
30
|
+
const DEFAULT_ERROR_SUMMARY = []
|
|
31
|
+
|
|
32
|
+
const log = debug('@modernpoacher/sprockets/sprockets/error-summary/group')
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @param {ErrorDefinitionType} error
|
|
36
|
+
* @param {number} index
|
|
37
|
+
* @returns {React.JSX.Element}
|
|
38
|
+
*/
|
|
39
|
+
function render ({ href, text }, index) {
|
|
40
|
+
log('render')
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<li key={getKey(href, text, index)} className='error'>
|
|
44
|
+
<a href={href}>
|
|
45
|
+
<TextContent
|
|
46
|
+
textContent={text}
|
|
47
|
+
/>
|
|
48
|
+
</a>
|
|
49
|
+
</li>
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @extends {Group<GroupProps & ErrorSummaryProps, GroupState & ErrorSummaryState>}
|
|
55
|
+
*/
|
|
56
|
+
export default class ErrorSummaryGroup extends Group {
|
|
57
|
+
/**
|
|
58
|
+
* @type {ErrorSummaryState}
|
|
59
|
+
*/
|
|
60
|
+
state = {}
|
|
61
|
+
|
|
62
|
+
getClassName () {
|
|
63
|
+
return classnames(super.getClassName(), 'error-summary')
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Compare latest 'props' with 'state' for changes to 'errorSummary'
|
|
68
|
+
*
|
|
69
|
+
* @param {ErrorSummaryProps} props Latest props
|
|
70
|
+
* @param {ErrorSummaryState} state Current state
|
|
71
|
+
* @returns {ErrorSummaryState}
|
|
72
|
+
*/
|
|
73
|
+
static getDerivedStateFromProps ({ errorSummary: e }, { errorSummary: E }) {
|
|
74
|
+
return {
|
|
75
|
+
errorSummary: (e === E || equal(e, E)) ? E : e
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Compare latest 'props' with 'state' for changes to 'errorSummary'
|
|
81
|
+
*
|
|
82
|
+
* @param {ErrorSummaryProps} props Latest props
|
|
83
|
+
* @param {ErrorSummaryState} state Current state
|
|
84
|
+
* @returns {boolean}
|
|
85
|
+
*/
|
|
86
|
+
shouldComponentUpdate (props, state) {
|
|
87
|
+
const {
|
|
88
|
+
errorSummary: e = DEFAULT_ERROR_SUMMARY
|
|
89
|
+
} = this.state
|
|
90
|
+
|
|
91
|
+
const {
|
|
92
|
+
errorSummary: E = DEFAULT_ERROR_SUMMARY
|
|
93
|
+
} = state
|
|
94
|
+
|
|
95
|
+
return !(e === E || equal(e, E))
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
render () {
|
|
99
|
+
const {
|
|
100
|
+
errorSummary = DEFAULT_ERROR_SUMMARY
|
|
101
|
+
} = this.props
|
|
102
|
+
|
|
103
|
+
if (errorSummary.length) {
|
|
104
|
+
const {
|
|
105
|
+
groupRef
|
|
106
|
+
} = this.props
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<ul
|
|
110
|
+
className={this.getClassName()}
|
|
111
|
+
ref={groupRef}>
|
|
112
|
+
{errorSummary.map(render)}
|
|
113
|
+
</ul>
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return null
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
ErrorSummaryGroup.propTypes = {
|
|
122
|
+
...Group.propTypes,
|
|
123
|
+
errorSummary: PropTypes.arrayOf(PropTypes.shape({}))
|
|
124
|
+
}
|
|
@@ -11,7 +11,10 @@ const log = debug('@modernpoacher/sprockets/sprockets/error-summary')
|
|
|
11
11
|
log('`sprockets` is awake')
|
|
12
12
|
|
|
13
13
|
const {
|
|
14
|
-
default:
|
|
14
|
+
default: ErrorSummary
|
|
15
15
|
} = require('./index.jsx')
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Exports only default
|
|
19
|
+
*/
|
|
20
|
+
module.exports = ErrorSummary
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare module '#sprockets/sprockets/error-summary' {
|
|
2
|
+
import Sprocket from '#sprockets/sprockets'
|
|
3
|
+
|
|
4
|
+
export type ErrorSummaryProps = SprocketsTypes.Sprockets.ErrorSummary.ErrorSummaryProps
|
|
5
|
+
|
|
6
|
+
export default class ErrorSummarySprocket<P extends ErrorSummaryProps> extends Sprocket<P> {}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare module '@modernpoacher/sprockets/sprockets/error-summary' {
|
|
10
|
+
export { default } from '#sprockets/sprockets/error-summary'
|
|
11
|
+
export * from '#sprockets/sprockets/error-summary'
|
|
12
|
+
}
|
|
@@ -1,33 +1,46 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* @typedef {SprocketsTypes.ErrorDefinitionType} ErrorDefinitionType
|
|
3
|
+
* @typedef {SprocketsTypes.Sprockets.SprocketProps} SprocketProps
|
|
4
|
+
* @typedef {SprocketsTypes.Sprockets.ErrorSummary.ErrorSummaryProps} ErrorSummaryProps
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* ErrorSummarySprocket component
|
|
9
|
+
*/
|
|
7
10
|
import React from 'react'
|
|
8
11
|
import PropTypes from 'prop-types'
|
|
9
|
-
|
|
10
12
|
import classnames from 'classnames'
|
|
11
13
|
|
|
12
14
|
import Sprocket from '#sprockets/sprockets'
|
|
13
|
-
import Title from '
|
|
14
|
-
import Group from '
|
|
15
|
+
import Title from '#sprockets/sprockets/error-summary/title'
|
|
16
|
+
import Group from '#sprockets/sprockets/error-summary/group'
|
|
15
17
|
|
|
18
|
+
/**
|
|
19
|
+
* @type {ErrorDefinitionType[]}
|
|
20
|
+
*/
|
|
16
21
|
const DEFAULT_ERROR_SUMMARY = []
|
|
17
22
|
|
|
23
|
+
/**
|
|
24
|
+
* @extends {Sprocket<SprocketProps & ErrorSummaryProps>}
|
|
25
|
+
*/
|
|
18
26
|
export default class ErrorSummarySprocket extends Sprocket {
|
|
19
27
|
getClassName () {
|
|
20
28
|
return classnames(super.getClassName(), 'error-summary')
|
|
21
29
|
}
|
|
22
30
|
|
|
23
31
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
32
|
+
* @param {ErrorSummaryProps} props
|
|
33
|
+
* @returns {boolean}
|
|
26
34
|
*/
|
|
27
|
-
shouldComponentUpdate (props
|
|
35
|
+
shouldComponentUpdate (props) {
|
|
36
|
+
const {
|
|
37
|
+
errorSummary,
|
|
38
|
+
...superProps
|
|
39
|
+
} = props
|
|
40
|
+
|
|
28
41
|
return (
|
|
29
|
-
super.shouldComponentUpdate(
|
|
30
|
-
(
|
|
42
|
+
super.shouldComponentUpdate(superProps) ||
|
|
43
|
+
(errorSummary !== this.props.errorSummary)
|
|
31
44
|
)
|
|
32
45
|
}
|
|
33
46
|
|
|
@@ -64,7 +77,7 @@ export default class ErrorSummarySprocket extends Sprocket {
|
|
|
64
77
|
const className = this.getClassName()
|
|
65
78
|
|
|
66
79
|
return (
|
|
67
|
-
<div tabIndex=
|
|
80
|
+
<div tabIndex={-1} className={className}>
|
|
68
81
|
{this.renderTitle()}
|
|
69
82
|
{this.renderGroup()}
|
|
70
83
|
</div>
|
|
@@ -77,5 +90,5 @@ export default class ErrorSummarySprocket extends Sprocket {
|
|
|
77
90
|
|
|
78
91
|
ErrorSummarySprocket.propTypes = {
|
|
79
92
|
...Sprocket.propTypes,
|
|
80
|
-
errorSummary: PropTypes.arrayOf(PropTypes.shape())
|
|
93
|
+
errorSummary: PropTypes.arrayOf(PropTypes.shape({}))
|
|
81
94
|
}
|
|
@@ -11,7 +11,10 @@ const log = debug('@modernpoacher/sprockets/sprockets/error-summary/title')
|
|
|
11
11
|
log('`sprockets` is awake')
|
|
12
12
|
|
|
13
13
|
const {
|
|
14
|
-
default:
|
|
14
|
+
default: Title
|
|
15
15
|
} = require('./index.jsx')
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Exports only default
|
|
19
|
+
*/
|
|
20
|
+
module.exports = Title
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare module '#sprockets/sprockets/error-summary/title' {
|
|
2
|
+
import Title from '#sprockets/super/components/title'
|
|
3
|
+
|
|
4
|
+
export type ErrorSummaryProps = SprocketsTypes.Sprockets.ErrorSummary.Title.ErrorSummaryProps
|
|
5
|
+
|
|
6
|
+
export default class ErrorSummaryTitle<P extends ErrorSummaryProps> extends Title<P> {}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare module '@modernpoacher/sprockets/sprockets/error-summary/title' {
|
|
10
|
+
export { default } from '#sprockets/sprockets/error-summary/title'
|
|
11
|
+
export * from '#sprockets/sprockets/error-summary/title'
|
|
12
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {SprocketsTypes.Super.Components.Title.TitleProps} TitleProps
|
|
3
|
+
* @typedef {SprocketsTypes.Sprockets.ErrorSummary.Title.ErrorSummaryProps} ErrorSummaryProps
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* ErrorSummaryTitle component
|
|
8
|
+
*/
|
|
9
|
+
import React from 'react'
|
|
10
|
+
import classnames from 'classnames'
|
|
11
|
+
|
|
12
|
+
import Title from '#sprockets/super/components/title'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @extends {Title<TitleProps & ErrorSummaryProps>}
|
|
16
|
+
*/
|
|
17
|
+
export default class ErrorSummaryTitle extends Title {
|
|
18
|
+
getClassName () {
|
|
19
|
+
return classnames(super.getClassName(), 'error-summary')
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
render () {
|
|
23
|
+
const {
|
|
24
|
+
title
|
|
25
|
+
} = this.props
|
|
26
|
+
|
|
27
|
+
if (title) {
|
|
28
|
+
return (
|
|
29
|
+
<h2 className={this.getClassName()}>
|
|
30
|
+
{this.renderTextContent(title)}
|
|
31
|
+
</h2>
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return null
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -11,7 +11,10 @@ const log = debug('@modernpoacher/sprockets/sprockets/fieldset/description')
|
|
|
11
11
|
log('`sprockets` is awake')
|
|
12
12
|
|
|
13
13
|
const {
|
|
14
|
-
default:
|
|
14
|
+
default: Description
|
|
15
15
|
} = require('./index.jsx')
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Exports only default
|
|
19
|
+
*/
|
|
20
|
+
module.exports = Description
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from '#sprockets/sprockets/fieldset/description'
|