@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,90 @@
1
+ /**
2
+ * Sprocket component
3
+ *
4
+ * @typedef {import('@modernpoacher/sprockets/sprockets').SprocketProps} SprocketProps
5
+ */
6
+
7
+ import React, { Component } from 'react'
8
+ import PropTypes from 'prop-types'
9
+
10
+ import Title from '@modernpoacher/sprockets/components/title'
11
+ import Group from '@modernpoacher/sprockets/components/group'
12
+
13
+ function onChange () {
14
+ /* */
15
+ }
16
+
17
+ export default class Sprocket extends Component {
18
+ getClassName () {
19
+ return 'sprocket'
20
+ }
21
+
22
+ /**
23
+ * @param {SprocketProps} props
24
+ * @returns {boolean}
25
+ */
26
+ shouldComponentUpdate (props) {
27
+ return (
28
+ (props.children !== this.props.children) ||
29
+ (props.title !== this.props.title) ||
30
+ (props.onChange !== this.props.onChange)
31
+ )
32
+ }
33
+
34
+ renderTitle () {
35
+ const {
36
+ title
37
+ } = this.props
38
+
39
+ return (
40
+ <Title
41
+ title={title}
42
+ />
43
+ )
44
+ }
45
+
46
+ renderGroup () {
47
+ const {
48
+ onChange,
49
+ groupRef,
50
+ children
51
+ } = this.props
52
+
53
+ return (
54
+ <Group
55
+ onChange={onChange}
56
+ groupRef={groupRef}>
57
+ {this.renderTitle()}
58
+ {children}
59
+ </Group>
60
+ )
61
+ }
62
+
63
+ render () {
64
+ const className = this.getClassName()
65
+
66
+ return (
67
+ <div className={className}>
68
+ {this.renderGroup()}
69
+ </div>
70
+ )
71
+ }
72
+ }
73
+
74
+ Sprocket.propTypes = {
75
+ title: PropTypes.string,
76
+ onChange: PropTypes.func,
77
+ children: PropTypes.oneOfType([
78
+ PropTypes.node,
79
+ PropTypes.arrayOf(
80
+ PropTypes.node
81
+ )
82
+ ]),
83
+ groupRef: PropTypes.shape({
84
+ current: PropTypes.shape().isRequired
85
+ })
86
+ }
87
+
88
+ Sprocket.defaultProps = {
89
+ onChange
90
+ }
@@ -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/table/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,163 @@
1
+ /**
2
+ * TableGroup 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, { isValidElement } from 'react'
13
+ import PropTypes from 'prop-types'
14
+
15
+ import classnames from 'classnames'
16
+
17
+ import Group from '@modernpoacher/sprockets/components/group'
18
+ import Title from '@modernpoacher/sprockets/sprockets/table/title'
19
+
20
+ function getText ({ text }) {
21
+ return text
22
+ }
23
+
24
+ export default class TableGroup extends Group {
25
+ /**
26
+ * @type {GroupState}
27
+ */
28
+ state = {}
29
+
30
+ getClassName () {
31
+ return classnames(super.getClassName(), 'table')
32
+ }
33
+
34
+ /**
35
+ * Compare latest 'props' with 'state' for changes to 'children'
36
+ *
37
+ * @param {GroupProps} props Latest props
38
+ * @param {GroupState} state Current state
39
+ * @returns {{children: {}}}
40
+ */
41
+ static getDerivedStateFromProps ({ children: c }, { children: C }) {
42
+ return {
43
+ children: (c !== C) ? c : C
44
+ }
45
+ }
46
+
47
+ /**
48
+ * Compare latest 'props' with 'state' for changes to 'children'
49
+ *
50
+ * @param {GroupProps} props Latest props
51
+ * @param {GroupState} state Current state
52
+ * @returns {boolean}
53
+ */
54
+ shouldComponentUpdate (props, state) {
55
+ const {
56
+ head: h,
57
+ body: b
58
+ } = state
59
+
60
+ const {
61
+ head: H,
62
+ body: B
63
+ } = this.state
64
+
65
+ return (h !== H) || (b !== B)
66
+ }
67
+
68
+ render () {
69
+ const {
70
+ groupRef,
71
+ title,
72
+ head,
73
+ body
74
+ } = this.props
75
+
76
+ if (head.length || body.length) {
77
+ return (
78
+ <table
79
+ className={this.getClassName()}
80
+ ref={groupRef}>
81
+ <Title
82
+ title={title}
83
+ />
84
+ {head.length && (
85
+ <thead>
86
+ <tr>
87
+ {head.map(({ text }, i) => (
88
+ <th key={i}>
89
+ {text}
90
+ </th>
91
+ ))}
92
+ </tr>
93
+ </thead>
94
+ )}
95
+ {body.length && (
96
+ <tbody>
97
+ {body.map((row, i) => (
98
+ <tr key={i}>
99
+ {row.map((item, i) => {
100
+ if (i) {
101
+ if (isValidElement(item)) {
102
+ return (
103
+ <td key={i}>
104
+ {item}
105
+ </td>
106
+ )
107
+ }
108
+
109
+ return (
110
+ <td key={i}>
111
+ {getText(item)}
112
+ </td>
113
+ )
114
+ }
115
+
116
+ if (isValidElement(item)) {
117
+ return (
118
+ <th key={i}>
119
+ {item}
120
+ </th>
121
+ )
122
+ }
123
+
124
+ return (
125
+ <th key={i}>
126
+ {getText(item)}
127
+ </th>
128
+ )
129
+ })}
130
+ </tr>
131
+ ))}
132
+ </tbody>
133
+ )}
134
+ </table>
135
+ )
136
+ }
137
+
138
+ return null
139
+ }
140
+ }
141
+
142
+ TableGroup.propTypes = {
143
+ title: PropTypes.string,
144
+ head: PropTypes.arrayOf(
145
+ PropTypes.shape({
146
+ text: PropTypes.string.isRequired
147
+ })
148
+ ),
149
+ body: PropTypes.arrayOf(
150
+ PropTypes.arrayOf(
151
+ PropTypes.shape({
152
+ text: PropTypes.string.isRequired
153
+ })
154
+ )
155
+ ),
156
+ groupRef: PropTypes.shape({
157
+ current: PropTypes.shape().isRequired
158
+ })
159
+ }
160
+
161
+ TableGroup.defaultProps = {
162
+ ...Group.defaultProps
163
+ }
@@ -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/table')
10
+
11
+ log('`sprockets` is awake')
12
+
13
+ const {
14
+ default: component
15
+ } = require('./index.jsx')
16
+
17
+ module.exports = component
@@ -0,0 +1,91 @@
1
+ /**
2
+ * TableSprocket 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 Group from './group/index.jsx'
14
+
15
+ export default class TableSprocket extends Sprocket {
16
+ getClassName () {
17
+ return classnames(super.getClassName(), 'table')
18
+ }
19
+
20
+ /**
21
+ * @param {SprocketProps} props
22
+ * @returns {boolean}
23
+ */
24
+ shouldComponentUpdate (props) {
25
+ return (
26
+ (props.title !== this.props.title) ||
27
+ (props.head !== this.props.head) ||
28
+ (props.body !== this.props.body)
29
+ )
30
+ }
31
+
32
+ renderGroup () {
33
+ const {
34
+ groupRef,
35
+ title,
36
+ head,
37
+ body
38
+ } = this.props
39
+
40
+ return (
41
+ <Group
42
+ groupRef={groupRef}
43
+ title={title}
44
+ head={head}
45
+ body={body}
46
+ />
47
+ )
48
+ }
49
+
50
+ render () {
51
+ const {
52
+ head,
53
+ body
54
+ } = this.props
55
+
56
+ if (head.length || body.length) {
57
+ return (
58
+ <div className={this.getClassName()}>
59
+ {this.renderGroup()}
60
+ </div>
61
+ )
62
+ }
63
+
64
+ return null
65
+ }
66
+ }
67
+
68
+ TableSprocket.propTypes = {
69
+ title: PropTypes.string,
70
+ head: PropTypes.arrayOf(
71
+ PropTypes.shape({
72
+ text: PropTypes.string.isRequired
73
+ })
74
+ ),
75
+ body: PropTypes.arrayOf(
76
+ PropTypes.arrayOf(
77
+ PropTypes.shape({
78
+ text: PropTypes.string.isRequired
79
+ })
80
+ )
81
+ ),
82
+ groupRef: PropTypes.shape({
83
+ current: PropTypes.shape().isRequired
84
+ })
85
+ }
86
+
87
+ TableSprocket.defaultProps = {
88
+ ...Sprocket.defaultProps,
89
+ head: [],
90
+ body: []
91
+ }
@@ -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/table/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
+ * TableTitle 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 TableTitle extends Title {
10
+ getClassName () {
11
+ return classnames(super.getClassName(), 'table')
12
+ }
13
+
14
+ render () {
15
+ if (this.hasTextContent()) {
16
+ return (
17
+ <caption className={this.getClassName()}>
18
+ {this.renderTextContent()}
19
+ </caption>
20
+ )
21
+ }
22
+
23
+ return null
24
+ }
25
+ }
26
+
27
+ TableTitle.propTypes = {
28
+ ...Title.propTypes
29
+ }
30
+
31
+ TableTitle.defaultProps = {
32
+ ...Title.defaultProps
33
+ }