@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.
Files changed (59) hide show
  1. package/README.md +11 -0
  2. package/babel.config.cjs +99 -0
  3. package/jsconfig.json +11 -0
  4. package/package.json +138 -0
  5. package/src/components/common/text-content/index.cjs +17 -0
  6. package/src/components/common/text-content/index.jsx +24 -0
  7. package/src/components/description/index.cjs +17 -0
  8. package/src/components/description/index.jsx +38 -0
  9. package/src/components/error-message/index.cjs +17 -0
  10. package/src/components/error-message/index.jsx +42 -0
  11. package/src/components/group/index.cjs +17 -0
  12. package/src/components/group/index.jsx +55 -0
  13. package/src/components/title/index.cjs +17 -0
  14. package/src/components/title/index.jsx +59 -0
  15. package/src/index.cjs +19 -0
  16. package/src/index.d.cts +172 -0
  17. package/src/index.mjs +19 -0
  18. package/src/sprockets/check-answers/group/answer-item.cjs +13 -0
  19. package/src/sprockets/check-answers/group/answer-item.jsx +37 -0
  20. package/src/sprockets/check-answers/group/answer-title.cjs +13 -0
  21. package/src/sprockets/check-answers/group/answer-title.jsx +23 -0
  22. package/src/sprockets/check-answers/group/answer-value.cjs +13 -0
  23. package/src/sprockets/check-answers/group/answer-value.jsx +51 -0
  24. package/src/sprockets/check-answers/group/change-answer.cjs +13 -0
  25. package/src/sprockets/check-answers/group/change-answer.jsx +37 -0
  26. package/src/sprockets/check-answers/group/index.cjs +17 -0
  27. package/src/sprockets/check-answers/group/index.jsx +93 -0
  28. package/src/sprockets/check-answers/group/visually-hidden-text.cjs +13 -0
  29. package/src/sprockets/check-answers/group/visually-hidden-text.jsx +27 -0
  30. package/src/sprockets/check-answers/index.cjs +17 -0
  31. package/src/sprockets/check-answers/index.jsx +86 -0
  32. package/src/sprockets/check-answers/title/index.cjs +17 -0
  33. package/src/sprockets/check-answers/title/index.jsx +33 -0
  34. package/src/sprockets/error-summary/group/error-item.cjs +13 -0
  35. package/src/sprockets/error-summary/group/error-item.jsx +22 -0
  36. package/src/sprockets/error-summary/group/index.cjs +17 -0
  37. package/src/sprockets/error-summary/group/index.jsx +93 -0
  38. package/src/sprockets/error-summary/index.cjs +17 -0
  39. package/src/sprockets/error-summary/index.jsx +88 -0
  40. package/src/sprockets/error-summary/title/index.cjs +17 -0
  41. package/src/sprockets/error-summary/title/index.jsx +33 -0
  42. package/src/sprockets/fieldset/description/index.cjs +17 -0
  43. package/src/sprockets/fieldset/description/index.jsx +20 -0
  44. package/src/sprockets/fieldset/error-message/index.cjs +17 -0
  45. package/src/sprockets/fieldset/error-message/index.jsx +20 -0
  46. package/src/sprockets/fieldset/group/index.cjs +17 -0
  47. package/src/sprockets/fieldset/group/index.jsx +20 -0
  48. package/src/sprockets/fieldset/index.cjs +17 -0
  49. package/src/sprockets/fieldset/index.jsx +105 -0
  50. package/src/sprockets/fieldset/title/index.cjs +17 -0
  51. package/src/sprockets/fieldset/title/index.jsx +19 -0
  52. package/src/sprockets/index.cjs +20 -0
  53. package/src/sprockets/index.jsx +90 -0
  54. package/src/sprockets/table/group/index.cjs +17 -0
  55. package/src/sprockets/table/group/index.jsx +163 -0
  56. package/src/sprockets/table/index.cjs +17 -0
  57. package/src/sprockets/table/index.jsx +91 -0
  58. package/src/sprockets/table/title/index.cjs +17 -0
  59. package/src/sprockets/table/title/index.jsx +33 -0
@@ -0,0 +1,33 @@
1
+ /**
2
+ * CheckAnswersTitle component
3
+ */
4
+
5
+ import React from 'react'
6
+ import classnames from 'classnames'
7
+ import Title from '@modernpoacher/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,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/error-summary/group/error-item')
10
+
11
+ log('`sprockets` is awake')
12
+
13
+ module.exports = require('./error-item.jsx')
@@ -0,0 +1,22 @@
1
+ import React from 'react'
2
+ import PropTypes from 'prop-types'
3
+
4
+ import TextContent from '@modernpoacher/sprockets/components/common/text-content'
5
+
6
+ export default function ErrorItem ({
7
+ href,
8
+ text
9
+ }) {
10
+ return (
11
+ <li className='error'>
12
+ <a href={href}>
13
+ <TextContent textContent={text} />
14
+ </a>
15
+ </li>
16
+ )
17
+ }
18
+
19
+ ErrorItem.propTypes = {
20
+ href: PropTypes.string.isRequired,
21
+ text: PropTypes.string.isRequired
22
+ }
@@ -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/error-summary/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
+ * ErrorSummaryGroup 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 ErrorSummaryGroup extends Group {
20
+ /**
21
+ * @type {GroupState}
22
+ */
23
+ state = {}
24
+
25
+ getClassName () {
26
+ return classnames(super.getClassName(), 'error-summary')
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 {GroupState}
35
+ */
36
+ static getDerivedStateFromProps ({ children: e }, { children: E }) {
37
+ return {
38
+ children: (e !== E) ? e : E
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: e
52
+ } = state
53
+
54
+ const {
55
+ children: E
56
+ } = this.state
57
+
58
+ return (e !== E)
59
+ }
60
+
61
+ render () {
62
+ const {
63
+ groupRef,
64
+ children
65
+ } = this.props
66
+
67
+ if (children) {
68
+ return (
69
+ <ul
70
+ className={this.getClassName()}
71
+ ref={groupRef}>
72
+ {children}
73
+ </ul>
74
+ )
75
+ }
76
+
77
+ return null
78
+ }
79
+ }
80
+
81
+ ErrorSummaryGroup.propTypes = {
82
+ ...Group.propTypes,
83
+ children: PropTypes.oneOfType([
84
+ PropTypes.node,
85
+ PropTypes.arrayOf(
86
+ PropTypes.node
87
+ )
88
+ ])
89
+ }
90
+
91
+ ErrorSummaryGroup.defaultProps = {
92
+ ...Group.defaultProps
93
+ }
@@ -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/error-summary')
10
+
11
+ log('`sprockets` is awake')
12
+
13
+ const {
14
+ default: component
15
+ } = require('./index.jsx')
16
+
17
+ module.exports = component
@@ -0,0 +1,88 @@
1
+ /**
2
+ * ErrorSummarySprocket 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 ErrorSummarySprocket extends Sprocket {
17
+ getClassName () {
18
+ return classnames(super.getClassName(), 'error-summary')
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
+ const className = this.getClassName()
63
+
64
+ return (
65
+ <div tabIndex='-1' className={className}>
66
+ {this.renderTitle()}
67
+ {this.renderGroup()}
68
+ </div>
69
+ )
70
+ }
71
+
72
+ return null
73
+ }
74
+ }
75
+
76
+ ErrorSummarySprocket.propTypes = {
77
+ ...Sprocket.propTypes,
78
+ children: PropTypes.oneOfType([
79
+ PropTypes.node,
80
+ PropTypes.arrayOf(
81
+ PropTypes.node
82
+ )
83
+ ])
84
+ }
85
+
86
+ ErrorSummarySprocket.defaultProps = {
87
+ ...Sprocket.defaultProps
88
+ }
@@ -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/error-summary/title')
10
+
11
+ log('`sprockets` is awake')
12
+
13
+ const {
14
+ default: component
15
+ } = require('./index.jsx')
16
+
17
+ module.exports = component
@@ -0,0 +1,33 @@
1
+ /**
2
+ * ErrorSummaryTitle component
3
+ */
4
+
5
+ import React from 'react'
6
+ import classnames from 'classnames'
7
+ import Title from '@modernpoacher/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,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/fieldset/description')
10
+
11
+ log('`sprockets` is awake')
12
+
13
+ const {
14
+ default: component
15
+ } = require('./index.jsx')
16
+
17
+ module.exports = component
@@ -0,0 +1,20 @@
1
+ /**
2
+ * FieldsetDescription component
3
+ */
4
+
5
+ import classnames from 'classnames'
6
+ import Description from '@modernpoacher/sprockets/components/description'
7
+
8
+ export default class FieldsetDescription extends Description {
9
+ getClassName () {
10
+ return classnames(super.getClassName(), 'fieldset')
11
+ }
12
+ }
13
+
14
+ FieldsetDescription.propTypes = {
15
+ ...Description.propTypes
16
+ }
17
+
18
+ FieldsetDescription.defaultProps = {
19
+ ...Description.defaultProps
20
+ }
@@ -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/fieldset/error-message')
10
+
11
+ log('`sprockets` is awake')
12
+
13
+ const {
14
+ default: component
15
+ } = require('./index.jsx')
16
+
17
+ module.exports = component
@@ -0,0 +1,20 @@
1
+ /**
2
+ * FieldsetErrorMessage component
3
+ */
4
+
5
+ import classnames from 'classnames'
6
+ import ErrorMessage from '@modernpoacher/sprockets/components/error-message'
7
+
8
+ export default class FieldsetErrorMessage extends ErrorMessage {
9
+ getClassName () {
10
+ return classnames(super.getClassName(), 'fieldset')
11
+ }
12
+ }
13
+
14
+ FieldsetErrorMessage.propTypes = {
15
+ ...ErrorMessage.propTypes
16
+ }
17
+
18
+ FieldsetErrorMessage.defaultProps = {
19
+ ...ErrorMessage.defaultProps
20
+ }
@@ -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/fieldset/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,20 @@
1
+ /**
2
+ * FieldsetGroup component
3
+ */
4
+
5
+ import classnames from 'classnames'
6
+ import Group from '@modernpoacher/sprockets/components/group'
7
+
8
+ export default class FieldsetGroup extends Group {
9
+ getClassName () {
10
+ return classnames(super.getClassName(), 'fieldset')
11
+ }
12
+ }
13
+
14
+ FieldsetGroup.propTypes = {
15
+ ...Group.propTypes
16
+ }
17
+
18
+ FieldsetGroup.defaultProps = {
19
+ ...Group.defaultProps
20
+ }
@@ -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/fieldset')
10
+
11
+ log('`sprockets` is awake')
12
+
13
+ const {
14
+ default: component
15
+ } = require('./index.jsx')
16
+
17
+ module.exports = component
@@ -0,0 +1,105 @@
1
+ /**
2
+ * FieldsetSprocket 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 Description from './description/index.jsx'
15
+ import ErrorMessage from './error-message/index.jsx'
16
+ import Group from './group/index.jsx'
17
+
18
+ export default class FieldsetSprocket extends Sprocket {
19
+ getClassName () {
20
+ const {
21
+ errorMessage
22
+ } = this.props
23
+
24
+ return classnames(super.getClassName(), { error: !!errorMessage }, 'fieldset')
25
+ }
26
+
27
+ /**
28
+ * @param {SprocketProps} props
29
+ * @returns {boolean}
30
+ */
31
+ shouldComponentUpdate (props) {
32
+ return (
33
+ super.shouldComponentUpdate(props) ||
34
+ (props.description !== this.props.description) ||
35
+ (props.errorMessage !== this.props.errorMessage)
36
+ )
37
+ }
38
+
39
+ renderTitle () {
40
+ const {
41
+ title
42
+ } = this.props
43
+
44
+ return (
45
+ <Title
46
+ title={title}
47
+ />
48
+ )
49
+ }
50
+
51
+ renderDescription () {
52
+ const {
53
+ description
54
+ } = this.props
55
+
56
+ return (
57
+ <Description
58
+ description={description}
59
+ />
60
+ )
61
+ }
62
+
63
+ renderErrorMessage () {
64
+ const {
65
+ errorMessage
66
+ } = this.props
67
+
68
+ return (
69
+ <ErrorMessage
70
+ errorMessage={errorMessage}
71
+ />
72
+ )
73
+ }
74
+
75
+ renderGroup () {
76
+ const {
77
+ onChange,
78
+ children
79
+ } = this.props
80
+
81
+ return (
82
+ <Group
83
+ onChange={onChange}>
84
+ {this.renderTitle()}
85
+ {this.renderDescription()}
86
+ {this.renderErrorMessage()}
87
+ {children}
88
+ </Group>
89
+ )
90
+ }
91
+ }
92
+
93
+ FieldsetSprocket.propTypes = {
94
+ ...Sprocket.propTypes,
95
+ description: PropTypes.string,
96
+ errorMessage: PropTypes.shape({
97
+ type: PropTypes.string.isRequired,
98
+ params: PropTypes.shape().isRequired,
99
+ uri: PropTypes.string.isRequired
100
+ })
101
+ }
102
+
103
+ FieldsetSprocket.defaultProps = {
104
+ ...Sprocket.defaultProps
105
+ }
@@ -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/fieldset/title')
10
+
11
+ log('`sprockets` is awake')
12
+
13
+ const {
14
+ default: component
15
+ } = require('./index.jsx')
16
+
17
+ module.exports = component
@@ -0,0 +1,19 @@
1
+ /**
2
+ * FieldsetTitle component
3
+ */
4
+ import classnames from 'classnames'
5
+ import Title from '@modernpoacher/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,20 @@
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')
10
+
11
+ log('`sprockets` is awake')
12
+
13
+ /**
14
+ * Has only default export
15
+ */
16
+ const {
17
+ default: component
18
+ } = require('./index.jsx')
19
+
20
+ module.exports = component