@modernpoacher/sprockets 0.0.5
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/README.md +11 -0
- package/babel.config.cjs +99 -0
- package/jsconfig.json +11 -0
- package/package.json +138 -0
- package/src/components/common/text-content/index.cjs +17 -0
- package/src/components/common/text-content/index.jsx +24 -0
- package/src/components/description/index.cjs +17 -0
- package/src/components/description/index.jsx +38 -0
- package/src/components/error-message/index.cjs +17 -0
- package/src/components/error-message/index.jsx +42 -0
- package/src/components/group/index.cjs +17 -0
- package/src/components/group/index.jsx +55 -0
- package/src/components/title/index.cjs +17 -0
- package/src/components/title/index.jsx +59 -0
- package/src/index.cjs +19 -0
- package/src/index.d.cts +172 -0
- package/src/index.mjs +19 -0
- package/src/sprockets/check-answers/group/answer-item.cjs +13 -0
- package/src/sprockets/check-answers/group/answer-item.jsx +37 -0
- package/src/sprockets/check-answers/group/answer-title.cjs +13 -0
- package/src/sprockets/check-answers/group/answer-title.jsx +23 -0
- package/src/sprockets/check-answers/group/answer-value.cjs +13 -0
- package/src/sprockets/check-answers/group/answer-value.jsx +51 -0
- package/src/sprockets/check-answers/group/change-answer.cjs +13 -0
- package/src/sprockets/check-answers/group/change-answer.jsx +37 -0
- package/src/sprockets/check-answers/group/index.cjs +17 -0
- package/src/sprockets/check-answers/group/index.jsx +93 -0
- package/src/sprockets/check-answers/group/visually-hidden-text.cjs +13 -0
- package/src/sprockets/check-answers/group/visually-hidden-text.jsx +27 -0
- package/src/sprockets/check-answers/index.cjs +17 -0
- package/src/sprockets/check-answers/index.jsx +86 -0
- package/src/sprockets/check-answers/title/index.cjs +17 -0
- package/src/sprockets/check-answers/title/index.jsx +33 -0
- package/src/sprockets/error-summary/group/error-item.cjs +13 -0
- package/src/sprockets/error-summary/group/error-item.jsx +22 -0
- package/src/sprockets/error-summary/group/index.cjs +17 -0
- package/src/sprockets/error-summary/group/index.jsx +93 -0
- package/src/sprockets/error-summary/index.cjs +17 -0
- package/src/sprockets/error-summary/index.jsx +88 -0
- package/src/sprockets/error-summary/title/index.cjs +17 -0
- package/src/sprockets/error-summary/title/index.jsx +33 -0
- package/src/sprockets/fieldset/description/index.cjs +17 -0
- package/src/sprockets/fieldset/description/index.jsx +20 -0
- package/src/sprockets/fieldset/error-message/index.cjs +17 -0
- package/src/sprockets/fieldset/error-message/index.jsx +20 -0
- package/src/sprockets/fieldset/group/index.cjs +17 -0
- package/src/sprockets/fieldset/group/index.jsx +20 -0
- package/src/sprockets/fieldset/index.cjs +17 -0
- package/src/sprockets/fieldset/index.jsx +105 -0
- package/src/sprockets/fieldset/title/index.cjs +17 -0
- package/src/sprockets/fieldset/title/index.jsx +19 -0
- package/src/sprockets/index.cjs +20 -0
- package/src/sprockets/index.jsx +90 -0
- package/src/sprockets/table/group/index.cjs +17 -0
- package/src/sprockets/table/group/index.jsx +163 -0
- package/src/sprockets/table/index.cjs +17 -0
- package/src/sprockets/table/index.jsx +91 -0
- package/src/sprockets/table/title/index.cjs +17 -0
- package/src/sprockets/table/title/index.jsx +33 -0
package/src/index.d.cts
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
declare namespace SprocketsTypes {
|
|
2
|
+
export type OnChangeType = () => void
|
|
3
|
+
|
|
4
|
+
export type AnswerDefinitionType = {
|
|
5
|
+
answer: {
|
|
6
|
+
title: string
|
|
7
|
+
value: string | string[]
|
|
8
|
+
}
|
|
9
|
+
changeAnswer: {
|
|
10
|
+
text: string
|
|
11
|
+
href: string
|
|
12
|
+
visuallyHiddenText?: string
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type ErrorDefinitionType = {
|
|
17
|
+
type: string,
|
|
18
|
+
uri: string,
|
|
19
|
+
params: {
|
|
20
|
+
expectedType: string
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type ComponentsType = {}
|
|
25
|
+
|
|
26
|
+
export type FieldChangeType = {
|
|
27
|
+
text: string,
|
|
28
|
+
href: string
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type FieldErrorType = {
|
|
32
|
+
text: string,
|
|
33
|
+
href: string
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
declare module '@modernpoacher/sprockets/components/common/text-content' {
|
|
38
|
+
import React from 'react'
|
|
39
|
+
|
|
40
|
+
export type TextContentProps = {
|
|
41
|
+
textContent: string
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export default function TextContent(props: TextContentProps): React.JSX.Element
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
declare module '@modernpoacher/sprockets/components/description' {
|
|
48
|
+
import React from 'react'
|
|
49
|
+
|
|
50
|
+
export type DescriptionProps = {
|
|
51
|
+
description: string
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export default class Description extends React.Component<DescriptionProps> {}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
declare module '@modernpoacher/sprockets/components/error-message' {
|
|
58
|
+
import React from 'react'
|
|
59
|
+
|
|
60
|
+
export type ErrorMessageProps = {
|
|
61
|
+
errorMessage: string
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export default class ErrorMessage extends React.Component<ErrorMessageProps> {}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
declare module '@modernpoacher/sprockets/components/title' {
|
|
68
|
+
import React from 'react'
|
|
69
|
+
|
|
70
|
+
export type TitleProps = {
|
|
71
|
+
title: string
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export default class Title extends React.Component<TitleProps> {}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
declare module '@modernpoacher/sprockets/components/group' {
|
|
78
|
+
import React from 'react'
|
|
79
|
+
|
|
80
|
+
export type GroupProps = {
|
|
81
|
+
onChange: SprocketsTypes.OnChangeType,
|
|
82
|
+
groupRef: object,
|
|
83
|
+
children: React.JSX.Element | React.JSX.Element[]
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export default class Group extends React.Component<GroupProps> {}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
declare module '@modernpoacher/sprockets/sprockets/check-answers/title' {
|
|
90
|
+
import Title from '@modernpoacher/sprockets/components/title'
|
|
91
|
+
|
|
92
|
+
export default class CheckAnswersTitle extends Title {}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
declare module '@modernpoacher/sprockets/sprockets/check-answers/group' {
|
|
96
|
+
import Group from '@modernpoacher/sprockets/components/group'
|
|
97
|
+
|
|
98
|
+
export default class CheckAnswersGroup extends Group {}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
declare module '@modernpoacher/sprockets/sprockets/check-answers' {
|
|
102
|
+
import Sprocket from '@modernpoacher/sprockets/sprockets'
|
|
103
|
+
|
|
104
|
+
export default class ErrorSummarySprocket extends Sprocket {}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
declare module '@modernpoacher/sprockets/sprockets/error-summary/title' {
|
|
108
|
+
import Title from '@modernpoacher/sprockets/components/title'
|
|
109
|
+
|
|
110
|
+
export default class ErrorSummaryTitle extends Title {}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
declare module '@modernpoacher/sprockets/sprockets/error-summary/group' {
|
|
114
|
+
import Group from '@modernpoacher/sprockets/components/group'
|
|
115
|
+
|
|
116
|
+
export default class ErrorSummaryGroup extends Group {}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
declare module '@modernpoacher/sprockets/sprockets/error-summary' {
|
|
120
|
+
import Sprocket from '@modernpoacher/sprockets/sprockets'
|
|
121
|
+
|
|
122
|
+
export default class CheckAnswersSprocket extends Sprocket {}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
declare module '@modernpoacher/sprockets/sprockets/fieldset/description' {
|
|
126
|
+
import Description from '@modernpoacher/sprockets/components/description'
|
|
127
|
+
|
|
128
|
+
export default class FieldsetDescription extends Description {}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
declare module '@modernpoacher/sprockets/sprockets/fieldset/error-message' {
|
|
132
|
+
import ErrorMessage from '@modernpoacher/sprockets/components/error-message'
|
|
133
|
+
|
|
134
|
+
export default class FieldsetErrorMessage extends ErrorMessage {}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
declare module '@modernpoacher/sprockets/sprockets/fieldset/title' {
|
|
138
|
+
import Title from '@modernpoacher/sprockets/components/title'
|
|
139
|
+
|
|
140
|
+
export default class FieldsetTitle extends Title {}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
declare module '@modernpoacher/sprockets/sprockets/fieldset/group' {
|
|
144
|
+
import Group from '@modernpoacher/sprockets/components/group'
|
|
145
|
+
|
|
146
|
+
export default class FieldsetGroup extends Group {}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
declare module '@modernpoacher/sprockets/sprockets/fieldset' {
|
|
150
|
+
import Sprocket from '@modernpoacher/sprockets/sprockets'
|
|
151
|
+
|
|
152
|
+
export default class FieldsetSprocket extends Sprocket {}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
declare module '@modernpoacher/sprockets/sprockets' {
|
|
156
|
+
import React from 'react'
|
|
157
|
+
|
|
158
|
+
export type SprocketProps = {
|
|
159
|
+
title: string,
|
|
160
|
+
onChange: SprocketsTypes.OnChangeType,
|
|
161
|
+
groupRef: object,
|
|
162
|
+
children: React.JSX.Element | React.JSX.Element[]
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export default class Sprocket extends React.Component<SprocketProps> {}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
declare module '@modernpoacher/sprockets' {
|
|
169
|
+
export { default as CheckAnswersSprocket } from '@modernpoacher/sprockets/sprockets/check-answers'
|
|
170
|
+
export { default as ErrorSummarySprocket } from '@modernpoacher/sprockets/sprockets/error-summary'
|
|
171
|
+
export { default as FieldsetSprocket } from '@modernpoacher/sprockets/sprockets/fieldset'
|
|
172
|
+
}
|
package/src/index.mjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import debug from 'debug'
|
|
2
|
+
|
|
3
|
+
import CheckAnswersSprocket from './sprockets/check-answers/index.cjs'
|
|
4
|
+
import ErrorSummarySprocket from './sprockets/error-summary/index.cjs'
|
|
5
|
+
import FieldsetSprocket from './sprockets/fieldset/index.cjs'
|
|
6
|
+
|
|
7
|
+
const log = debug('@modernpoacher/sprockets')
|
|
8
|
+
|
|
9
|
+
log('`sprockets` is awake')
|
|
10
|
+
|
|
11
|
+
export { default as CheckAnswersSprocket } from './sprockets/check-answers/index.cjs'
|
|
12
|
+
export { default as ErrorSummarySprocket } from './sprockets/error-summary/index.cjs'
|
|
13
|
+
export { default as FieldsetSprocket } from './sprockets/fieldset/index.cjs'
|
|
14
|
+
|
|
15
|
+
export default {
|
|
16
|
+
CheckAnswersSprocket,
|
|
17
|
+
ErrorSummarySprocket,
|
|
18
|
+
FieldsetSprocket
|
|
19
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require('@babel/register')({
|
|
2
|
+
ignore: [
|
|
3
|
+
/node_modules\/(?!@modernpoacher\/cogs|@modernpoacher\/sprockets)/
|
|
4
|
+
]
|
|
5
|
+
})
|
|
6
|
+
|
|
7
|
+
const debug = require('debug')
|
|
8
|
+
|
|
9
|
+
const log = debug('@modernpoacher/sprockets/sprockets/check-answers/group/answer-item')
|
|
10
|
+
|
|
11
|
+
log('`sprockets` is awake')
|
|
12
|
+
|
|
13
|
+
module.exports = require('./answer-item.jsx')
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
|
|
4
|
+
import AnswerTitle from './answer-title.cjs'
|
|
5
|
+
import AnswerValue from './answer-value.cjs'
|
|
6
|
+
import ChangeAnswer from './change-answer.cjs'
|
|
7
|
+
|
|
8
|
+
export default function AnswerItem ({ answer: { title, value }, changeAnswer: { href, text, visuallyHiddenText } }) {
|
|
9
|
+
return (
|
|
10
|
+
<div className='answer'>
|
|
11
|
+
<AnswerTitle title={title} />
|
|
12
|
+
<AnswerValue value={value} />
|
|
13
|
+
<ChangeAnswer
|
|
14
|
+
href={href}
|
|
15
|
+
text={text}
|
|
16
|
+
visuallyHiddenText={visuallyHiddenText}
|
|
17
|
+
/>
|
|
18
|
+
</div>
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
AnswerItem.propTypes = {
|
|
23
|
+
answer: PropTypes.shape({
|
|
24
|
+
title: PropTypes.string.isRequired,
|
|
25
|
+
value: PropTypes.oneOfType([
|
|
26
|
+
PropTypes.string,
|
|
27
|
+
PropTypes.arrayOf(
|
|
28
|
+
PropTypes.string
|
|
29
|
+
)
|
|
30
|
+
]).isRequired
|
|
31
|
+
}),
|
|
32
|
+
changeAnswer: PropTypes.shape({
|
|
33
|
+
text: PropTypes.string.isRequired,
|
|
34
|
+
href: PropTypes.string.isRequired,
|
|
35
|
+
visuallyHiddenText: PropTypes.string.isRequired
|
|
36
|
+
})
|
|
37
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require('@babel/register')({
|
|
2
|
+
ignore: [
|
|
3
|
+
/node_modules\/(?!@modernpoacher\/cogs|@modernpoacher\/sprockets)/
|
|
4
|
+
]
|
|
5
|
+
})
|
|
6
|
+
|
|
7
|
+
const debug = require('debug')
|
|
8
|
+
|
|
9
|
+
const log = debug('@modernpoacher/sprockets/sprockets/check-answers/group/answer-title')
|
|
10
|
+
|
|
11
|
+
log('`sprockets` is awake')
|
|
12
|
+
|
|
13
|
+
module.exports = require('./answer-title.jsx')
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
import debug from 'debug'
|
|
4
|
+
|
|
5
|
+
const log = debug('@modernpoacher/sprockets/sprockets/check-answers/group')
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @param {SprocketsTypes.AnswerDefinitionType}
|
|
9
|
+
* @returns {React.JSX.Element}
|
|
10
|
+
*/
|
|
11
|
+
export default function AnswerTitle ({ title }) {
|
|
12
|
+
log('AnswerTitle')
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<dt className='answer-title'>
|
|
16
|
+
{title}
|
|
17
|
+
</dt>
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
AnswerTitle.propTypes = {
|
|
22
|
+
title: PropTypes.string.isRequired
|
|
23
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require('@babel/register')({
|
|
2
|
+
ignore: [
|
|
3
|
+
/node_modules\/(?!@modernpoacher\/cogs|@modernpoacher\/sprockets)/
|
|
4
|
+
]
|
|
5
|
+
})
|
|
6
|
+
|
|
7
|
+
const debug = require('debug')
|
|
8
|
+
|
|
9
|
+
const log = debug('@modernpoacher/sprockets/sprockets/check-answers/group/answer-value')
|
|
10
|
+
|
|
11
|
+
log('`sprockets` is awake')
|
|
12
|
+
|
|
13
|
+
module.exports = require('./answer-value.jsx')
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
import debug from 'debug'
|
|
4
|
+
|
|
5
|
+
const log = debug('@modernpoacher/sprockets/sprockets/check-answers/group')
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @param {string | string[]}
|
|
9
|
+
* @returns {string | string[]}
|
|
10
|
+
*/
|
|
11
|
+
function getAnswerValue (value) {
|
|
12
|
+
if (Array.isArray(value)) {
|
|
13
|
+
const n = value.length - 1
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
value
|
|
17
|
+
.reduce((a, v, i) => {
|
|
18
|
+
const s = String(v)
|
|
19
|
+
|
|
20
|
+
return (i !== n)
|
|
21
|
+
? a.concat(s).concat(<br key={i} />)
|
|
22
|
+
: a.concat(s)
|
|
23
|
+
}, [])
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return String(value)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param {SprocketsTypes.AnswerDefinitionType}
|
|
32
|
+
* @returns {React.JSX.Element}
|
|
33
|
+
*/
|
|
34
|
+
export default function AnswerValue ({ value }) {
|
|
35
|
+
log('AnswerValue')
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<dd className='answer-value'>
|
|
39
|
+
{getAnswerValue(value)}
|
|
40
|
+
</dd>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
AnswerValue.propTypes = {
|
|
45
|
+
value: PropTypes.oneOfType([
|
|
46
|
+
PropTypes.string,
|
|
47
|
+
PropTypes.arrayOf(
|
|
48
|
+
PropTypes.string
|
|
49
|
+
)
|
|
50
|
+
]).isRequired
|
|
51
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require('@babel/register')({
|
|
2
|
+
ignore: [
|
|
3
|
+
/node_modules\/(?!@modernpoacher\/cogs|@modernpoacher\/sprockets)/
|
|
4
|
+
]
|
|
5
|
+
})
|
|
6
|
+
|
|
7
|
+
const debug = require('debug')
|
|
8
|
+
|
|
9
|
+
const log = debug('@modernpoacher/sprockets/sprockets/check-answers/group/change-answer')
|
|
10
|
+
|
|
11
|
+
log('`sprockets` is awake')
|
|
12
|
+
|
|
13
|
+
module.exports = require('./change-answer.jsx')
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
import debug from 'debug'
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
Link
|
|
7
|
+
} from 'react-router-dom'
|
|
8
|
+
|
|
9
|
+
import TextContent from '@modernpoacher/sprockets/components/common/text-content'
|
|
10
|
+
|
|
11
|
+
import VisuallyHiddenText from './visually-hidden-text.cjs'
|
|
12
|
+
|
|
13
|
+
const log = debug('@modernpoacher/sprockets/sprockets/check-answers/group/change-answer')
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param {SprocketsTypes.AnswerDefinitionType}
|
|
17
|
+
* @returns {React.JSX.Element}
|
|
18
|
+
*/
|
|
19
|
+
export default function ChangeAnswer ({ href, text, visuallyHiddenText }) {
|
|
20
|
+
log('ChangeAnswer')
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<dd className='change-answer'>
|
|
24
|
+
<Link to={href}>
|
|
25
|
+
<TextContent textContent={text} />
|
|
26
|
+
{String.fromCharCode(32)}
|
|
27
|
+
<VisuallyHiddenText visuallyHiddenText={visuallyHiddenText} />
|
|
28
|
+
</Link>
|
|
29
|
+
</dd>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
ChangeAnswer.propTypes = {
|
|
34
|
+
href: PropTypes.string.isRequired,
|
|
35
|
+
text: PropTypes.string.isRequired,
|
|
36
|
+
visuallyHiddenText: PropTypes.string.isRequired
|
|
37
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require('@babel/register')({
|
|
2
|
+
ignore: [
|
|
3
|
+
/node_modules\/(?!@modernpoacher\/cogs|@modernpoacher\/sprockets)/
|
|
4
|
+
]
|
|
5
|
+
})
|
|
6
|
+
|
|
7
|
+
const debug = require('debug')
|
|
8
|
+
|
|
9
|
+
const log = debug('@modernpoacher/sprockets/sprockets/check-answers/group')
|
|
10
|
+
|
|
11
|
+
log('`sprockets` is awake')
|
|
12
|
+
|
|
13
|
+
const {
|
|
14
|
+
default: component
|
|
15
|
+
} = require('./index.jsx')
|
|
16
|
+
|
|
17
|
+
module.exports = component
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CheckAnswersGroup component
|
|
3
|
+
*
|
|
4
|
+
* @typedef {import('@modernpoacher/sprockets/components/group').GroupProps} GroupProps
|
|
5
|
+
*
|
|
6
|
+
* Group state
|
|
7
|
+
*
|
|
8
|
+
* @typedef {Object} GroupState
|
|
9
|
+
* @property {{}} [children]
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import React from 'react'
|
|
13
|
+
import PropTypes from 'prop-types'
|
|
14
|
+
|
|
15
|
+
import classnames from 'classnames'
|
|
16
|
+
|
|
17
|
+
import Group from '@modernpoacher/sprockets/components/group'
|
|
18
|
+
|
|
19
|
+
export default class CheckAnswersGroup extends Group {
|
|
20
|
+
/**
|
|
21
|
+
* @type {GroupState}
|
|
22
|
+
*/
|
|
23
|
+
state = {}
|
|
24
|
+
|
|
25
|
+
getClassName () {
|
|
26
|
+
return classnames(super.getClassName(), 'check-answers')
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Compare latest 'props' with 'state' for changes to 'children'
|
|
31
|
+
*
|
|
32
|
+
* @param {GroupProps} props Latest props
|
|
33
|
+
* @param {GroupState} state Current state
|
|
34
|
+
* @returns {{children: {}}}
|
|
35
|
+
*/
|
|
36
|
+
static getDerivedStateFromProps ({ children: c }, { children: C }) {
|
|
37
|
+
return {
|
|
38
|
+
children: (c !== C) ? c : C
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Compare latest 'props' with 'state' for changes to 'children'
|
|
44
|
+
*
|
|
45
|
+
* @param {GroupProps} props Latest props
|
|
46
|
+
* @param {GroupState} state Current state
|
|
47
|
+
* @returns {boolean}
|
|
48
|
+
*/
|
|
49
|
+
shouldComponentUpdate (props, state) {
|
|
50
|
+
const {
|
|
51
|
+
children: c
|
|
52
|
+
} = state
|
|
53
|
+
|
|
54
|
+
const {
|
|
55
|
+
children: C
|
|
56
|
+
} = this.state
|
|
57
|
+
|
|
58
|
+
return (c !== C)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
render () {
|
|
62
|
+
const {
|
|
63
|
+
groupRef,
|
|
64
|
+
children
|
|
65
|
+
} = this.props
|
|
66
|
+
|
|
67
|
+
if (children) {
|
|
68
|
+
return (
|
|
69
|
+
<dl
|
|
70
|
+
className={this.getClassName()}
|
|
71
|
+
ref={groupRef}>
|
|
72
|
+
{children}
|
|
73
|
+
</dl>
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return null
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
CheckAnswersGroup.propTypes = {
|
|
82
|
+
...Group.propTypes,
|
|
83
|
+
children: PropTypes.oneOfType([
|
|
84
|
+
PropTypes.node,
|
|
85
|
+
PropTypes.arrayOf(
|
|
86
|
+
PropTypes.node
|
|
87
|
+
)
|
|
88
|
+
])
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
CheckAnswersGroup.defaultProps = {
|
|
92
|
+
...Group.defaultProps
|
|
93
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require('@babel/register')({
|
|
2
|
+
ignore: [
|
|
3
|
+
/node_modules\/(?!@modernpoacher\/cogs|@modernpoacher\/sprockets)/
|
|
4
|
+
]
|
|
5
|
+
})
|
|
6
|
+
|
|
7
|
+
const debug = require('debug')
|
|
8
|
+
|
|
9
|
+
const log = debug('@modernpoacher/sprockets/sprockets/check-answers/group/visually-hidden-text')
|
|
10
|
+
|
|
11
|
+
log('`sprockets` is awake')
|
|
12
|
+
|
|
13
|
+
module.exports = require('./visually-hidden-text.jsx')
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
import debug from 'debug'
|
|
4
|
+
|
|
5
|
+
const log = debug('@modernpoacher/sprockets/sprockets/check-answers/group')
|
|
6
|
+
|
|
7
|
+
export default function VisuallyHiddenText ({ visuallyHiddenText }) {
|
|
8
|
+
log('VisuallyHiddenText')
|
|
9
|
+
|
|
10
|
+
if (visuallyHiddenText) {
|
|
11
|
+
return (
|
|
12
|
+
<span className='visually-hidden-text'>
|
|
13
|
+
{visuallyHiddenText.toLowerCase()}
|
|
14
|
+
</span>
|
|
15
|
+
)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return null
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
VisuallyHiddenText.propTypes = {
|
|
22
|
+
visuallyHiddenText: PropTypes.string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
VisuallyHiddenText.defaultProps = {
|
|
26
|
+
visuallyHiddenText: ''
|
|
27
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require('@babel/register')({
|
|
2
|
+
ignore: [
|
|
3
|
+
/node_modules\/(?!@modernpoacher\/cogs|@modernpoacher\/sprockets)/
|
|
4
|
+
]
|
|
5
|
+
})
|
|
6
|
+
|
|
7
|
+
const debug = require('debug')
|
|
8
|
+
|
|
9
|
+
const log = debug('@modernpoacher/sprockets/sprockets/check-answers')
|
|
10
|
+
|
|
11
|
+
log('`sprockets` is awake')
|
|
12
|
+
|
|
13
|
+
const {
|
|
14
|
+
default: component
|
|
15
|
+
} = require('./index.jsx')
|
|
16
|
+
|
|
17
|
+
module.exports = component
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CheckAnswersSprocket component
|
|
3
|
+
*
|
|
4
|
+
* @typedef {import('@modernpoacher/sprockets/sprockets').SprocketProps} SprocketProps
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import React from 'react'
|
|
8
|
+
import PropTypes from 'prop-types'
|
|
9
|
+
|
|
10
|
+
import classnames from 'classnames'
|
|
11
|
+
|
|
12
|
+
import Sprocket from '@modernpoacher/sprockets/sprockets'
|
|
13
|
+
import Title from './title/index.jsx'
|
|
14
|
+
import Group from './group/index.jsx'
|
|
15
|
+
|
|
16
|
+
export default class CheckAnswersSprocket extends Sprocket {
|
|
17
|
+
getClassName () {
|
|
18
|
+
return classnames(super.getClassName(), 'check-answers')
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {SprocketProps} props
|
|
23
|
+
* @returns {boolean}
|
|
24
|
+
*/
|
|
25
|
+
shouldComponentUpdate (props) {
|
|
26
|
+
return (
|
|
27
|
+
super.shouldComponentUpdate(props) ||
|
|
28
|
+
(props.children !== this.props.children)
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
renderTitle () {
|
|
33
|
+
const {
|
|
34
|
+
title
|
|
35
|
+
} = this.props
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<Title
|
|
39
|
+
title={title}
|
|
40
|
+
/>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
renderGroup () {
|
|
45
|
+
const {
|
|
46
|
+
children
|
|
47
|
+
} = this.props
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<Group>
|
|
51
|
+
{children}
|
|
52
|
+
</Group>
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
render () {
|
|
57
|
+
const {
|
|
58
|
+
children
|
|
59
|
+
} = this.props
|
|
60
|
+
|
|
61
|
+
if (children) {
|
|
62
|
+
return (
|
|
63
|
+
<div className={this.getClassName()}>
|
|
64
|
+
{this.renderTitle()}
|
|
65
|
+
{this.renderGroup()}
|
|
66
|
+
</div>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return null
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
CheckAnswersSprocket.propTypes = {
|
|
75
|
+
...Sprocket.propTypes,
|
|
76
|
+
children: PropTypes.oneOfType([
|
|
77
|
+
PropTypes.node,
|
|
78
|
+
PropTypes.arrayOf(
|
|
79
|
+
PropTypes.node
|
|
80
|
+
)
|
|
81
|
+
])
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
CheckAnswersSprocket.defaultProps = {
|
|
85
|
+
...Sprocket.defaultProps
|
|
86
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require('@babel/register')({
|
|
2
|
+
ignore: [
|
|
3
|
+
/node_modules\/(?!@modernpoacher\/cogs|@modernpoacher\/sprockets)/
|
|
4
|
+
]
|
|
5
|
+
})
|
|
6
|
+
|
|
7
|
+
const debug = require('debug')
|
|
8
|
+
|
|
9
|
+
const log = debug('@modernpoacher/sprockets/sprockets/check-answers/title')
|
|
10
|
+
|
|
11
|
+
log('`sprockets` is awake')
|
|
12
|
+
|
|
13
|
+
const {
|
|
14
|
+
default: component
|
|
15
|
+
} = require('./index.jsx')
|
|
16
|
+
|
|
17
|
+
module.exports = component
|