shinkansen-sprockets 1.0.28
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/.husky/pre-commit +4 -0
- package/README.md +11 -0
- package/babel.config.js +72 -0
- package/gulp.sh +42 -0
- package/index.js +7 -0
- package/lib/components/common/text-content/index.js +1 -0
- package/lib/components/description/fieldset/index.js +1 -0
- package/lib/components/description/index.js +1 -0
- package/lib/components/error-message/fieldset/index.js +1 -0
- package/lib/components/error-message/index.js +1 -0
- package/lib/components/group/check-answers/answer-title.js +1 -0
- package/lib/components/group/check-answers/answer-value.js +1 -0
- package/lib/components/group/check-answers/change-answer.js +1 -0
- package/lib/components/group/check-answers/index.js +1 -0
- package/lib/components/group/check-answers/visually-hidden-text.js +1 -0
- package/lib/components/group/error-summary/index.js +1 -0
- package/lib/components/group/fieldset/index.js +1 -0
- package/lib/components/group/index.js +1 -0
- package/lib/components/title/check-answers/index.js +1 -0
- package/lib/components/title/error-summary/index.js +1 -0
- package/lib/components/title/fieldset/index.js +1 -0
- package/lib/components/title/index.js +1 -0
- package/lib/index.js +1 -0
- package/lib/sprockets/check-answers/index.js +1 -0
- package/lib/sprockets/error-summary/index.js +1 -0
- package/lib/sprockets/fieldset/index.js +1 -0
- package/lib/sprockets/index.js +1 -0
- package/lib/transformers/check-answers/index.js +1 -0
- package/lib/transformers/common/index.js +1 -0
- package/lib/transformers/error-message/index.js +1 -0
- package/lib/transformers/error-summary/index.js +1 -0
- package/package.json +107 -0
- package/src/components/common/text-content/index.js +14 -0
- package/src/components/description/fieldset/index.js +19 -0
- package/src/components/description/index.js +61 -0
- package/src/components/error-message/fieldset/index.js +19 -0
- package/src/components/error-message/index.js +103 -0
- package/src/components/group/check-answers/answer-title.js +21 -0
- package/src/components/group/check-answers/answer-value.js +45 -0
- package/src/components/group/check-answers/change-answer.js +35 -0
- package/src/components/group/check-answers/index.js +104 -0
- package/src/components/group/check-answers/visually-hidden-text.js +25 -0
- package/src/components/group/error-summary/index.js +106 -0
- package/src/components/group/fieldset/index.js +19 -0
- package/src/components/group/index.js +42 -0
- package/src/components/title/check-answers/index.js +33 -0
- package/src/components/title/error-summary/index.js +33 -0
- package/src/components/title/fieldset/index.js +19 -0
- package/src/components/title/index.js +59 -0
- package/src/index.js +13 -0
- package/src/sprockets/check-answers/index.js +74 -0
- package/src/sprockets/error-summary/index.js +79 -0
- package/src/sprockets/fieldset/index.js +108 -0
- package/src/sprockets/index.js +86 -0
- package/src/transformers/check-answers/index.js +12 -0
- package/src/transformers/common/index.js +14 -0
- package/src/transformers/error-message/index.js +234 -0
- package/src/transformers/error-summary/index.js +234 -0
@@ -0,0 +1,42 @@
|
|
1
|
+
/**
|
2
|
+
* Group component
|
3
|
+
*/
|
4
|
+
import React, { Component } from 'react'
|
5
|
+
import PropTypes from 'prop-types'
|
6
|
+
|
7
|
+
export default class Group extends Component {
|
8
|
+
getDOMNode = () => this.domNode
|
9
|
+
setDOMNode = (domNode) => !!(this.domNode = domNode) || delete this.domNode
|
10
|
+
|
11
|
+
getClassName () {
|
12
|
+
return 'group'
|
13
|
+
}
|
14
|
+
|
15
|
+
shouldComponentUpdate (props) {
|
16
|
+
return (
|
17
|
+
(props.onChange !== this.props.onChange) ||
|
18
|
+
(props.children !== this.props.children)
|
19
|
+
)
|
20
|
+
}
|
21
|
+
|
22
|
+
render () {
|
23
|
+
const {
|
24
|
+
onChange,
|
25
|
+
children
|
26
|
+
} = this.props
|
27
|
+
|
28
|
+
return (
|
29
|
+
<fieldset
|
30
|
+
onChange={onChange}
|
31
|
+
className={this.getClassName()}
|
32
|
+
ref={this.setDOMNode}>
|
33
|
+
{children}
|
34
|
+
</fieldset>
|
35
|
+
)
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
Group.propTypes = {
|
40
|
+
onChange: PropTypes.func,
|
41
|
+
children: PropTypes.any
|
42
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
/**
|
2
|
+
* CheckAnswersTitle component
|
3
|
+
*/
|
4
|
+
|
5
|
+
import React from 'react'
|
6
|
+
import classnames from 'classnames'
|
7
|
+
import Title from 'shinkansen-sprockets/components/title'
|
8
|
+
|
9
|
+
export default class CheckAnswersTitle extends Title {
|
10
|
+
getClassName () {
|
11
|
+
return classnames(super.getClassName(), 'check-answers')
|
12
|
+
}
|
13
|
+
|
14
|
+
render () {
|
15
|
+
if (this.hasTextContent()) {
|
16
|
+
return (
|
17
|
+
<h2 className={this.getClassName()}>
|
18
|
+
{this.renderTextContent()}
|
19
|
+
</h2>
|
20
|
+
)
|
21
|
+
}
|
22
|
+
|
23
|
+
return null
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
CheckAnswersTitle.propTypes = {
|
28
|
+
...Title.propTypes
|
29
|
+
}
|
30
|
+
|
31
|
+
CheckAnswersTitle.defaultProps = {
|
32
|
+
...Title.defaultProps
|
33
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
/**
|
2
|
+
* ErrorSummaryTitle component
|
3
|
+
*/
|
4
|
+
|
5
|
+
import React from 'react'
|
6
|
+
import classnames from 'classnames'
|
7
|
+
import Title from 'shinkansen-sprockets/components/title'
|
8
|
+
|
9
|
+
export default class ErrorSummaryTitle extends Title {
|
10
|
+
getClassName () {
|
11
|
+
return classnames(super.getClassName(), 'error-summary')
|
12
|
+
}
|
13
|
+
|
14
|
+
render () {
|
15
|
+
if (this.hasTextContent()) {
|
16
|
+
return (
|
17
|
+
<h2 className={this.getClassName()}>
|
18
|
+
{this.renderTextContent()}
|
19
|
+
</h2>
|
20
|
+
)
|
21
|
+
}
|
22
|
+
|
23
|
+
return null
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
ErrorSummaryTitle.propTypes = {
|
28
|
+
...Title.propTypes
|
29
|
+
}
|
30
|
+
|
31
|
+
ErrorSummaryTitle.defaultProps = {
|
32
|
+
...Title.defaultProps
|
33
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
/**
|
2
|
+
* FieldsetTitle component
|
3
|
+
*/
|
4
|
+
import classnames from 'classnames'
|
5
|
+
import Title from 'shinkansen-sprockets/components/title'
|
6
|
+
|
7
|
+
export default class FieldsetTitle extends Title {
|
8
|
+
getClassName () {
|
9
|
+
return classnames(super.getClassName(), 'fieldset')
|
10
|
+
}
|
11
|
+
}
|
12
|
+
|
13
|
+
FieldsetTitle.propTypes = {
|
14
|
+
...Title.propTypes
|
15
|
+
}
|
16
|
+
|
17
|
+
FieldsetTitle.defaultProps = {
|
18
|
+
...Title.defaultProps
|
19
|
+
}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
/**
|
2
|
+
* Title component
|
3
|
+
*/
|
4
|
+
import React, { Component } from 'react'
|
5
|
+
import PropTypes from 'prop-types'
|
6
|
+
|
7
|
+
import TextContent from 'shinkansen-sprockets/components/common/text-content'
|
8
|
+
|
9
|
+
export default class Title extends Component {
|
10
|
+
hasTextContent () {
|
11
|
+
const { title } = this.props
|
12
|
+
|
13
|
+
return !!title
|
14
|
+
}
|
15
|
+
|
16
|
+
getTextContent () {
|
17
|
+
const { title } = this.props
|
18
|
+
|
19
|
+
return title
|
20
|
+
}
|
21
|
+
|
22
|
+
getClassName () {
|
23
|
+
return 'title'
|
24
|
+
}
|
25
|
+
|
26
|
+
shouldComponentUpdate (props) {
|
27
|
+
return (
|
28
|
+
(props.title !== this.props.title)
|
29
|
+
)
|
30
|
+
}
|
31
|
+
|
32
|
+
renderTextContent () {
|
33
|
+
if (this.hasTextContent()) {
|
34
|
+
const textContent = this.getTextContent()
|
35
|
+
|
36
|
+
return (
|
37
|
+
<TextContent textContent={textContent} />
|
38
|
+
)
|
39
|
+
}
|
40
|
+
|
41
|
+
return null
|
42
|
+
}
|
43
|
+
|
44
|
+
render () {
|
45
|
+
if (this.hasTextContent()) {
|
46
|
+
return (
|
47
|
+
<legend className={this.getClassName()}>
|
48
|
+
{this.renderTextContent()}
|
49
|
+
</legend>
|
50
|
+
)
|
51
|
+
}
|
52
|
+
|
53
|
+
return null
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
Title.propTypes = {
|
58
|
+
title: PropTypes.string
|
59
|
+
}
|
package/src/index.js
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
import CheckAnswersSprocket from './sprockets/check-answers'
|
2
|
+
import ErrorSummarySprocket from './sprockets/error-summary'
|
3
|
+
import FieldsetSprocket from './sprockets/fieldset'
|
4
|
+
|
5
|
+
export CheckAnswersSprocket from './sprockets/check-answers'
|
6
|
+
export ErrorSummarySprocket from './sprockets/error-summary'
|
7
|
+
export FieldsetSprocket from './sprockets/fieldset'
|
8
|
+
|
9
|
+
export default {
|
10
|
+
CheckAnswersSprocket,
|
11
|
+
ErrorSummarySprocket,
|
12
|
+
FieldsetSprocket
|
13
|
+
}
|
@@ -0,0 +1,74 @@
|
|
1
|
+
import React from 'react'
|
2
|
+
import PropTypes from 'prop-types'
|
3
|
+
|
4
|
+
import classnames from 'classnames'
|
5
|
+
|
6
|
+
import Sprocket from 'shinkansen-sprockets/sprockets'
|
7
|
+
import Title from 'shinkansen-sprockets/components/title/check-answers'
|
8
|
+
import Group from 'shinkansen-sprockets/components/group/check-answers'
|
9
|
+
|
10
|
+
export default class CheckAnswersSprocket extends Sprocket {
|
11
|
+
getClassName () {
|
12
|
+
return classnames(super.getClassName(), 'check-answers')
|
13
|
+
}
|
14
|
+
|
15
|
+
shouldComponentUpdate (props) {
|
16
|
+
return (
|
17
|
+
super.shouldComponentUpdate(props) ||
|
18
|
+
(props.checkAnswers !== this.props.checkAnswers)
|
19
|
+
)
|
20
|
+
}
|
21
|
+
|
22
|
+
renderTitle () {
|
23
|
+
const {
|
24
|
+
title
|
25
|
+
} = this.props
|
26
|
+
|
27
|
+
return (
|
28
|
+
<Title
|
29
|
+
title={title}
|
30
|
+
ref={this.setTitle}
|
31
|
+
/>
|
32
|
+
)
|
33
|
+
}
|
34
|
+
|
35
|
+
renderGroup () {
|
36
|
+
const {
|
37
|
+
checkAnswers
|
38
|
+
} = this.props
|
39
|
+
|
40
|
+
return (
|
41
|
+
<Group
|
42
|
+
checkAnswers={checkAnswers}
|
43
|
+
ref={this.setGroup}
|
44
|
+
/>
|
45
|
+
)
|
46
|
+
}
|
47
|
+
|
48
|
+
render () {
|
49
|
+
const {
|
50
|
+
checkAnswers
|
51
|
+
} = this.props
|
52
|
+
|
53
|
+
if (checkAnswers.length) {
|
54
|
+
return (
|
55
|
+
<div className={this.getClassName()}>
|
56
|
+
{this.renderTitle()}
|
57
|
+
{this.renderGroup()}
|
58
|
+
</div>
|
59
|
+
)
|
60
|
+
}
|
61
|
+
|
62
|
+
return null
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
CheckAnswersSprocket.propTypes = {
|
67
|
+
...Sprocket.propTypes,
|
68
|
+
checkAnswers: PropTypes.array
|
69
|
+
}
|
70
|
+
|
71
|
+
CheckAnswersSprocket.defaultProps = {
|
72
|
+
...Sprocket.defaultProps,
|
73
|
+
checkAnswers: []
|
74
|
+
}
|
@@ -0,0 +1,79 @@
|
|
1
|
+
/**
|
2
|
+
* ErrorSummarySprocket component
|
3
|
+
*/
|
4
|
+
import React from 'react'
|
5
|
+
import PropTypes from 'prop-types'
|
6
|
+
|
7
|
+
import classnames from 'classnames'
|
8
|
+
|
9
|
+
import Sprocket from 'shinkansen-sprockets/sprockets'
|
10
|
+
import Title from 'shinkansen-sprockets/components/title/error-summary'
|
11
|
+
import Group from 'shinkansen-sprockets/components/group/error-summary'
|
12
|
+
|
13
|
+
export default class ErrorSummarySprocket extends Sprocket {
|
14
|
+
getClassName () {
|
15
|
+
return classnames(super.getClassName(), 'error-summary')
|
16
|
+
}
|
17
|
+
|
18
|
+
shouldComponentUpdate (props) {
|
19
|
+
return (
|
20
|
+
super.shouldComponentUpdate(props) ||
|
21
|
+
(props.errorSummary !== this.props.errorSummary)
|
22
|
+
)
|
23
|
+
}
|
24
|
+
|
25
|
+
renderTitle () {
|
26
|
+
const {
|
27
|
+
title
|
28
|
+
} = this.props
|
29
|
+
|
30
|
+
return (
|
31
|
+
<Title
|
32
|
+
title={title}
|
33
|
+
ref={this.setTitle}
|
34
|
+
/>
|
35
|
+
)
|
36
|
+
}
|
37
|
+
|
38
|
+
renderGroup () {
|
39
|
+
const {
|
40
|
+
errorSummary
|
41
|
+
} = this.props
|
42
|
+
|
43
|
+
return (
|
44
|
+
<Group
|
45
|
+
errorSummary={errorSummary}
|
46
|
+
ref={this.setGroup}>
|
47
|
+
</Group>
|
48
|
+
)
|
49
|
+
}
|
50
|
+
|
51
|
+
render () {
|
52
|
+
const {
|
53
|
+
errorSummary
|
54
|
+
} = this.props
|
55
|
+
|
56
|
+
if (errorSummary.length) {
|
57
|
+
const className = this.getClassName()
|
58
|
+
|
59
|
+
return (
|
60
|
+
<div tabIndex='-1' className={className}>
|
61
|
+
{this.renderTitle()}
|
62
|
+
{this.renderGroup()}
|
63
|
+
</div>
|
64
|
+
)
|
65
|
+
}
|
66
|
+
|
67
|
+
return null
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
ErrorSummarySprocket.propTypes = {
|
72
|
+
...Sprocket.propTypes,
|
73
|
+
errorSummary: PropTypes.array
|
74
|
+
}
|
75
|
+
|
76
|
+
ErrorSummarySprocket.defaultProps = {
|
77
|
+
...Sprocket.defaultProps,
|
78
|
+
errorSummary: []
|
79
|
+
}
|
@@ -0,0 +1,108 @@
|
|
1
|
+
/**
|
2
|
+
* FieldsetSprocket component
|
3
|
+
*/
|
4
|
+
import React from 'react'
|
5
|
+
import PropTypes from 'prop-types'
|
6
|
+
|
7
|
+
import classnames from 'classnames'
|
8
|
+
|
9
|
+
import Sprocket from 'shinkansen-sprockets/sprockets'
|
10
|
+
import Title from 'shinkansen-sprockets/components/title/fieldset'
|
11
|
+
import Description from 'shinkansen-sprockets/components/description/fieldset'
|
12
|
+
import ErrorMessage from 'shinkansen-sprockets/components/error-message/fieldset'
|
13
|
+
import Group from 'shinkansen-sprockets/components/group/fieldset'
|
14
|
+
|
15
|
+
export default class FieldsetSprocket extends Sprocket {
|
16
|
+
getDescription = () => this.description
|
17
|
+
getErrorMessage = () => this.errorMessage
|
18
|
+
|
19
|
+
setDescription = (description) => !!(this.description = description) || delete this.description
|
20
|
+
setErrorMessage = (errorMessage) => !!(this.errorMessage = errorMessage) || delete this.errorMessage
|
21
|
+
|
22
|
+
getClassName () {
|
23
|
+
const {
|
24
|
+
errorMessage
|
25
|
+
} = this.props
|
26
|
+
|
27
|
+
return classnames(super.getClassName(), { error: !!errorMessage }, 'fieldset')
|
28
|
+
}
|
29
|
+
|
30
|
+
shouldComponentUpdate (props) {
|
31
|
+
return (
|
32
|
+
super.shouldComponentUpdate(props) ||
|
33
|
+
(props.description !== this.props.description) ||
|
34
|
+
(props.errorMessage !== this.props.errorMessage)
|
35
|
+
)
|
36
|
+
}
|
37
|
+
|
38
|
+
renderTitle () {
|
39
|
+
const {
|
40
|
+
title
|
41
|
+
} = this.props
|
42
|
+
|
43
|
+
return (
|
44
|
+
<Title
|
45
|
+
title={title}
|
46
|
+
ref={this.setTitle}
|
47
|
+
/>
|
48
|
+
)
|
49
|
+
}
|
50
|
+
|
51
|
+
renderDescription () {
|
52
|
+
const {
|
53
|
+
description
|
54
|
+
} = this.props
|
55
|
+
|
56
|
+
return (
|
57
|
+
<Description
|
58
|
+
description={description}
|
59
|
+
ref={this.setDescription}
|
60
|
+
/>
|
61
|
+
)
|
62
|
+
}
|
63
|
+
|
64
|
+
renderErrorMessage () {
|
65
|
+
const {
|
66
|
+
errorMessage
|
67
|
+
} = this.props
|
68
|
+
|
69
|
+
return (
|
70
|
+
<ErrorMessage
|
71
|
+
errorMessage={errorMessage}
|
72
|
+
ref={this.setErrorMessage}
|
73
|
+
/>
|
74
|
+
)
|
75
|
+
}
|
76
|
+
|
77
|
+
renderGroup () {
|
78
|
+
const {
|
79
|
+
onChange,
|
80
|
+
children
|
81
|
+
} = this.props
|
82
|
+
|
83
|
+
return (
|
84
|
+
<Group
|
85
|
+
onChange={onChange}
|
86
|
+
ref={this.setGroup}>
|
87
|
+
{this.renderTitle()}
|
88
|
+
{this.renderDescription()}
|
89
|
+
{this.renderErrorMessage()}
|
90
|
+
{children}
|
91
|
+
</Group>
|
92
|
+
)
|
93
|
+
}
|
94
|
+
}
|
95
|
+
|
96
|
+
FieldsetSprocket.propTypes = {
|
97
|
+
...Sprocket.propTypes,
|
98
|
+
description: PropTypes.string,
|
99
|
+
errorMessage: PropTypes.shape({
|
100
|
+
type: PropTypes.string.isRequired,
|
101
|
+
params: PropTypes.shape().isRequired,
|
102
|
+
uri: PropTypes.string.isRequired
|
103
|
+
})
|
104
|
+
}
|
105
|
+
|
106
|
+
FieldsetSprocket.defaultProps = {
|
107
|
+
...Sprocket.defaultProps
|
108
|
+
}
|
@@ -0,0 +1,86 @@
|
|
1
|
+
/**
|
2
|
+
* Sprocket component
|
3
|
+
*/
|
4
|
+
import React, { Component } from 'react'
|
5
|
+
import PropTypes from 'prop-types'
|
6
|
+
|
7
|
+
import Title from 'shinkansen-sprockets/components/title'
|
8
|
+
import Group from 'shinkansen-sprockets/components/group'
|
9
|
+
|
10
|
+
function onChange () {
|
11
|
+
/* */
|
12
|
+
}
|
13
|
+
|
14
|
+
export default class Sprocket extends Component {
|
15
|
+
getTitle = () => this.title
|
16
|
+
getGroup = () => this.group
|
17
|
+
|
18
|
+
setTitle = (title) => !!(this.title = title) || delete this.title
|
19
|
+
setGroup = (group) => !!(this.group = group) || delete this.group
|
20
|
+
|
21
|
+
getClassName () {
|
22
|
+
return 'sprocket'
|
23
|
+
}
|
24
|
+
|
25
|
+
shouldComponentUpdate (props) {
|
26
|
+
return (
|
27
|
+
(props.children !== this.props.children) ||
|
28
|
+
(props.title !== this.props.title) ||
|
29
|
+
(props.onChange !== this.props.onChange)
|
30
|
+
)
|
31
|
+
}
|
32
|
+
|
33
|
+
renderTitle () {
|
34
|
+
const {
|
35
|
+
title
|
36
|
+
} = this.props
|
37
|
+
|
38
|
+
return (
|
39
|
+
<Title
|
40
|
+
title={title}
|
41
|
+
ref={this.setTitle}
|
42
|
+
/>
|
43
|
+
)
|
44
|
+
}
|
45
|
+
|
46
|
+
renderGroup () {
|
47
|
+
const {
|
48
|
+
onChange,
|
49
|
+
children
|
50
|
+
} = this.props
|
51
|
+
|
52
|
+
return (
|
53
|
+
<Group
|
54
|
+
onChange={onChange}
|
55
|
+
ref={this.setGroup}>
|
56
|
+
{this.renderTitle()}
|
57
|
+
{children}
|
58
|
+
</Group>
|
59
|
+
)
|
60
|
+
}
|
61
|
+
|
62
|
+
render () {
|
63
|
+
const className = this.getClassName()
|
64
|
+
|
65
|
+
return (
|
66
|
+
<div className={className}>
|
67
|
+
{this.renderGroup()}
|
68
|
+
</div>
|
69
|
+
)
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
Sprocket.propTypes = {
|
74
|
+
title: PropTypes.string,
|
75
|
+
onChange: PropTypes.func,
|
76
|
+
children: PropTypes.oneOfType([
|
77
|
+
PropTypes.element,
|
78
|
+
PropTypes.arrayOf(
|
79
|
+
PropTypes.element
|
80
|
+
)
|
81
|
+
])
|
82
|
+
}
|
83
|
+
|
84
|
+
Sprocket.defaultProps = {
|
85
|
+
onChange
|
86
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
const CHAR32 = String.fromCharCode(32)
|
2
|
+
const CHAR45 = String.fromCharCode(45)
|
3
|
+
|
4
|
+
export function getKey (href, text, index) {
|
5
|
+
return (
|
6
|
+
`${href}-${text}-${index}`
|
7
|
+
.toLowerCase()
|
8
|
+
.replace(/^#/, 'error-')
|
9
|
+
.replace(/[^\w\-\d]/g, CHAR32).trim()
|
10
|
+
.replace(/\s\s+/g, CHAR32)
|
11
|
+
.replace(/\-\-+/g, CHAR45) // eslint-disable-line
|
12
|
+
.replace(/[\s\s|\-\-|\s\-|\-\s]+/g, CHAR45) // eslint-disable-line
|
13
|
+
)
|
14
|
+
}
|