@modernpoacher/gremlins 0.0.311 → 1.0.1

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 (173) hide show
  1. package/.prettierignore +4 -0
  2. package/babel.config.cjs +4 -1
  3. package/eslint.config.mjs +33 -71
  4. package/index.d.mts +169 -2
  5. package/jest.after-each.mjs +10 -0
  6. package/jest.before-each.mjs +10 -0
  7. package/jest.config.mjs +11 -1
  8. package/package.json +84 -29
  9. package/src/{components → js/components}/common/disabled/index.cjs +5 -2
  10. package/src/js/components/common/disabled/index.d.cts +1 -0
  11. package/src/js/components/common/disabled/index.jsx +11 -0
  12. package/src/{components → js/components}/common/readonly/index.cjs +5 -2
  13. package/src/js/components/common/readonly/index.d.cts +1 -0
  14. package/src/js/components/common/readonly/index.jsx +11 -0
  15. package/src/{components → js/components}/common/required/index.cjs +5 -2
  16. package/src/js/components/common/required/index.d.cts +1 -0
  17. package/src/js/components/common/required/index.jsx +11 -0
  18. package/src/{components → js/components}/common/text-content/index.cjs +5 -2
  19. package/src/js/components/common/text-content/index.d.cts +2 -0
  20. package/src/{components → js/components}/common/text-content/index.d.mts +1 -3
  21. package/src/{components → js/components}/common/text-content/index.jsx +6 -5
  22. package/src/{components → js/components}/field/index.cjs +10 -2
  23. package/src/js/components/field/index.d.cts +1 -0
  24. package/src/js/components/field/index.d.mts +24 -0
  25. package/src/js/components/field/index.jsx +98 -0
  26. package/src/{components → js/components}/group/index.cjs +5 -2
  27. package/src/js/components/group/index.d.cts +2 -0
  28. package/src/js/components/group/index.d.mts +9 -0
  29. package/src/js/components/group/index.jsx +5 -0
  30. package/src/js/components/index.cjs +29 -0
  31. package/src/js/components/index.d.cts +2 -0
  32. package/src/js/components/index.d.mts +2 -0
  33. package/src/js/components/index.mjs +8 -0
  34. package/src/{gremlins → js/gremlins}/checkbox/field/index.cjs +5 -2
  35. package/src/js/gremlins/checkbox/field/index.d.cts +2 -0
  36. package/src/js/gremlins/checkbox/field/index.d.mts +14 -0
  37. package/src/{gremlins → js/gremlins}/checkbox/field/index.jsx +21 -10
  38. package/src/{gremlins → js/gremlins}/checkbox/index.cjs +5 -2
  39. package/src/js/gremlins/checkbox/index.d.cts +2 -0
  40. package/src/js/gremlins/checkbox/index.d.mts +24 -0
  41. package/src/{gremlins → js/gremlins}/checkbox/index.jsx +31 -23
  42. package/src/{gremlins → js/gremlins}/email/field/index.cjs +5 -2
  43. package/src/js/gremlins/email/field/index.d.cts +2 -0
  44. package/src/js/gremlins/email/field/index.d.mts +14 -0
  45. package/src/js/gremlins/email/field/index.jsx +83 -0
  46. package/src/{gremlins → js/gremlins}/email/index.cjs +5 -2
  47. package/src/js/gremlins/email/index.d.cts +2 -0
  48. package/src/js/gremlins/email/index.d.mts +18 -0
  49. package/src/{gremlins → js/gremlins}/email/index.jsx +25 -12
  50. package/src/{gremlins → js/gremlins}/fieldset/group/index.cjs +5 -2
  51. package/src/js/gremlins/fieldset/group/index.d.cts +2 -0
  52. package/src/js/gremlins/fieldset/group/index.d.mts +12 -0
  53. package/src/js/gremlins/fieldset/group/index.jsx +19 -0
  54. package/src/{gremlins → js/gremlins}/fieldset/index.cjs +5 -2
  55. package/src/js/gremlins/fieldset/index.d.cts +2 -0
  56. package/src/js/gremlins/fieldset/index.d.mts +14 -0
  57. package/src/js/gremlins/fieldset/index.jsx +37 -0
  58. package/src/{gremlins → js/gremlins}/index.cjs +9 -4
  59. package/src/js/gremlins/index.d.cts +5 -0
  60. package/src/js/gremlins/index.d.mts +27 -0
  61. package/src/js/gremlins/index.jsx +162 -0
  62. package/src/{gremlins → js/gremlins}/number/field/index.cjs +5 -2
  63. package/src/js/gremlins/number/field/index.d.cts +2 -0
  64. package/src/js/gremlins/number/field/index.d.mts +14 -0
  65. package/src/{gremlins → js/gremlins}/number/field/index.jsx +40 -7
  66. package/src/{gremlins → js/gremlins}/number/index.cjs +5 -2
  67. package/src/js/gremlins/number/index.d.cts +2 -0
  68. package/src/js/gremlins/number/index.d.mts +18 -0
  69. package/src/{gremlins → js/gremlins}/number/index.jsx +25 -8
  70. package/src/{gremlins → js/gremlins}/password/field/index.cjs +5 -2
  71. package/src/js/gremlins/password/field/index.d.cts +2 -0
  72. package/src/js/gremlins/password/field/index.d.mts +14 -0
  73. package/src/js/gremlins/password/field/index.jsx +83 -0
  74. package/src/{gremlins → js/gremlins}/password/index.cjs +5 -2
  75. package/src/js/gremlins/password/index.d.cts +2 -0
  76. package/src/js/gremlins/password/index.d.mts +18 -0
  77. package/src/{gremlins → js/gremlins}/password/index.jsx +25 -12
  78. package/src/{gremlins → js/gremlins}/radio/field/index.cjs +5 -2
  79. package/src/js/gremlins/radio/field/index.d.cts +2 -0
  80. package/src/js/gremlins/radio/field/index.d.mts +14 -0
  81. package/src/{gremlins → js/gremlins}/radio/field/index.jsx +20 -9
  82. package/src/{gremlins → js/gremlins}/radio/index.cjs +5 -2
  83. package/src/js/gremlins/radio/index.d.cts +2 -0
  84. package/src/js/gremlins/radio/index.d.mts +24 -0
  85. package/src/{gremlins → js/gremlins}/radio/index.jsx +33 -17
  86. package/src/{gremlins → js/gremlins}/select/field/index.cjs +5 -2
  87. package/src/js/gremlins/select/field/index.d.cts +2 -0
  88. package/src/js/gremlins/select/field/index.d.mts +18 -0
  89. package/src/js/gremlins/select/field/index.jsx +200 -0
  90. package/src/{gremlins → js/gremlins}/select/index.cjs +5 -2
  91. package/src/js/gremlins/select/index.d.cts +2 -0
  92. package/src/js/gremlins/select/index.d.mts +18 -0
  93. package/src/{gremlins → js/gremlins}/select/index.jsx +53 -16
  94. package/src/{gremlins → js/gremlins}/text/field/index.cjs +5 -2
  95. package/src/js/gremlins/text/field/index.d.cts +2 -0
  96. package/src/js/gremlins/text/field/index.d.mts +14 -0
  97. package/src/js/gremlins/text/field/index.jsx +83 -0
  98. package/src/{gremlins → js/gremlins}/text/index.cjs +5 -2
  99. package/src/js/gremlins/text/index.d.cts +2 -0
  100. package/src/js/gremlins/text/index.d.mts +18 -0
  101. package/src/{gremlins → js/gremlins}/text/index.jsx +25 -12
  102. package/src/{gremlins → js/gremlins}/textarea/field/index.cjs +5 -2
  103. package/src/js/gremlins/textarea/field/index.d.cts +2 -0
  104. package/src/js/gremlins/textarea/field/index.d.mts +18 -0
  105. package/src/js/gremlins/textarea/field/index.jsx +81 -0
  106. package/src/{gremlins → js/gremlins}/textarea/index.cjs +5 -2
  107. package/src/js/gremlins/textarea/index.d.cts +2 -0
  108. package/src/js/gremlins/textarea/index.d.mts +18 -0
  109. package/src/{gremlins → js/gremlins}/textarea/index.jsx +25 -12
  110. package/src/js/super/components/field/index.cjs +20 -0
  111. package/src/js/super/components/field/index.d.cts +2 -0
  112. package/src/js/super/components/field/index.d.mts +23 -0
  113. package/src/{components → js/super/components}/field/index.jsx +44 -87
  114. package/src/js/super/components/group/index.cjs +20 -0
  115. package/src/js/super/components/group/index.d.cts +2 -0
  116. package/src/js/super/components/group/index.d.mts +18 -0
  117. package/src/js/super/components/group/index.jsx +59 -0
  118. package/src/js/super/components/index.cjs +23 -0
  119. package/src/js/super/components/index.d.cts +2 -0
  120. package/src/js/super/components/index.d.mts +2 -0
  121. package/src/js/super/components/index.mjs +8 -0
  122. package/src/js/super/gremlins/index.cjs +22 -0
  123. package/src/js/super/gremlins/index.d.cts +4 -0
  124. package/src/js/super/gremlins/index.d.mts +36 -0
  125. package/src/js/super/gremlins/index.jsx +176 -0
  126. package/src/sass/.stylelintrc +14 -0
  127. package/src/sass/_gremlins.scss +59 -0
  128. package/src/sass/gremlins/_checkbox.scss +87 -0
  129. package/src/sass/gremlins/_disabled.scss +15 -0
  130. package/src/sass/gremlins/_error.scss +48 -0
  131. package/src/sass/gremlins/_radio.scss +93 -0
  132. package/.publish/README.md +0 -20
  133. package/src/common/index.d.mts +0 -9
  134. package/src/common/index.mjs +0 -7
  135. package/src/components/common/disabled/index.jsx +0 -9
  136. package/src/components/common/readonly/index.jsx +0 -9
  137. package/src/components/common/required/index.jsx +0 -9
  138. package/src/components/field/index.d.mts +0 -23
  139. package/src/components/group/index.d.mts +0 -16
  140. package/src/components/group/index.jsx +0 -59
  141. package/src/gremlins/checkbox/field/index.d.mts +0 -9
  142. package/src/gremlins/checkbox/index.d.mts +0 -9
  143. package/src/gremlins/email/field/index.d.mts +0 -9
  144. package/src/gremlins/email/field/index.jsx +0 -54
  145. package/src/gremlins/email/index.d.mts +0 -9
  146. package/src/gremlins/fieldset/group/index.d.mts +0 -9
  147. package/src/gremlins/fieldset/group/index.jsx +0 -16
  148. package/src/gremlins/fieldset/index.d.mts +0 -9
  149. package/src/gremlins/fieldset/index.jsx +0 -41
  150. package/src/gremlins/index.d.mts +0 -45
  151. package/src/gremlins/index.jsx +0 -291
  152. package/src/gremlins/number/field/index.d.mts +0 -9
  153. package/src/gremlins/number/index.d.mts +0 -9
  154. package/src/gremlins/password/field/index.d.mts +0 -9
  155. package/src/gremlins/password/field/index.jsx +0 -54
  156. package/src/gremlins/password/index.d.mts +0 -9
  157. package/src/gremlins/radio/field/index.d.mts +0 -9
  158. package/src/gremlins/radio/index.d.mts +0 -9
  159. package/src/gremlins/select/field/index.d.mts +0 -9
  160. package/src/gremlins/select/field/index.jsx +0 -111
  161. package/src/gremlins/select/index.d.mts +0 -9
  162. package/src/gremlins/text/field/index.d.mts +0 -9
  163. package/src/gremlins/text/field/index.jsx +0 -54
  164. package/src/gremlins/text/index.d.mts +0 -9
  165. package/src/gremlins/textarea/field/index.d.mts +0 -9
  166. package/src/gremlins/textarea/field/index.jsx +0 -53
  167. package/src/gremlins/textarea/index.d.mts +0 -9
  168. /package/src/{components → js/components}/common/disabled/index.d.mts +0 -0
  169. /package/src/{components → js/components}/common/readonly/index.d.mts +0 -0
  170. /package/src/{components → js/components}/common/required/index.d.mts +0 -0
  171. /package/src/{index.cjs → js/index.cjs} +0 -0
  172. /package/src/{index.d.mts → js/index.d.mts} +0 -0
  173. /package/src/{index.mjs → js/index.mjs} +0 -0
@@ -1,22 +1,50 @@
1
1
  /**
2
- * Field component
2
+ * @typedef {GremlinsTypes.OnEventType} OnEventType
3
+ * @typedef {GremlinsTypes.Super.Components.Field.FieldProps} FieldProps
4
+ */
5
+
6
+ /**
7
+ * Field component
3
8
  */
4
9
  import React, { Component } from 'react'
5
10
  import PropTypes from 'prop-types'
6
11
 
7
- import {
8
- DEFAULT_HANDLE_CHANGE,
9
- DEFAULT_HANDLE_CLICK
10
- } from '#gremlins/common'
12
+ /**
13
+ * @type {OnEventType}
14
+ */
15
+ function DEFAULT_HANDLE_EVENT () {
16
+ //
17
+ }
11
18
 
19
+ /**
20
+ * @extends {Component<FieldProps>}
21
+ */
12
22
  export default class Field extends Component {
13
23
  getClassName () {
14
24
  return 'input'
15
25
  }
16
26
 
17
- shouldComponentUpdate (props, state) {
27
+ /**
28
+ * @param {{ target: { value?: string } }} event
29
+ * @returns {void}
30
+ */
31
+ handleChange = ({ target: { value } }) => {
32
+ const {
33
+ onChange = DEFAULT_HANDLE_EVENT
34
+ } = this.props
35
+
36
+ onChange(value)
37
+ }
38
+
39
+ /**
40
+ * @param {FieldProps} props
41
+ * @returns {boolean}
42
+ */
43
+ shouldComponentUpdate (props) {
18
44
  return (
45
+ (props.name !== this.props.name) ||
19
46
  (props.id !== this.props.id) ||
47
+ (props.value !== this.props.value) ||
20
48
  (props.required !== this.props.required) ||
21
49
  (props.disabled !== this.props.disabled) ||
22
50
  (props.readOnly !== this.props.readOnly) ||
@@ -29,7 +57,9 @@ export default class Field extends Component {
29
57
 
30
58
  render () {
31
59
  const {
60
+ name,
32
61
  id,
62
+ value,
33
63
  required = false,
34
64
  disabled = false,
35
65
  readOnly = false,
@@ -41,13 +71,16 @@ export default class Field extends Component {
41
71
 
42
72
  return (
43
73
  <input
74
+ name={name}
44
75
  id={id}
76
+ value={value}
45
77
  required={required}
46
78
  disabled={disabled}
47
79
  readOnly={readOnly}
48
80
  tabIndex={tabIndex}
49
81
  accessKey={accessKey}
50
82
  placeholder={placeholder}
83
+ onChange={this.handleChange}
51
84
  className={this.getClassName()}
52
85
  ref={fieldRef}
53
86
  />
@@ -56,8 +89,9 @@ export default class Field extends Component {
56
89
  }
57
90
 
58
91
  Field.propTypes = {
59
- id: PropTypes.string,
60
92
  name: PropTypes.string.isRequired,
93
+ id: PropTypes.string,
94
+ value: PropTypes.string,
61
95
  required: PropTypes.bool,
62
96
  disabled: PropTypes.bool,
63
97
  readOnly: PropTypes.bool,
@@ -66,85 +100,8 @@ Field.propTypes = {
66
100
  placeholder: PropTypes.string,
67
101
  onChange: PropTypes.func,
68
102
  fieldRef: PropTypes.shape({
69
- current: PropTypes.shape().isRequired
103
+ current: PropTypes.shape({
104
+ value: PropTypes.string
105
+ })
70
106
  })
71
107
  }
72
-
73
- Field.defaultProps = {
74
- required: false,
75
- disabled: false,
76
- readOnly: false,
77
- onChange: DEFAULT_HANDLE_CHANGE
78
- }
79
-
80
- /**
81
- * ValueField component
82
- */
83
- export class ValueField extends Field {
84
- shouldComponentUpdate (props, state) {
85
- return (
86
- super.shouldComponentUpdate(props, state) ||
87
- (props.value !== this.props.value)
88
- )
89
- }
90
-
91
- handleChange = ({ target: { value } }) => {
92
- const {
93
- onChange = DEFAULT_HANDLE_CHANGE
94
- } = this.props
95
-
96
- onChange(value)
97
- }
98
- }
99
-
100
- ValueField.propTypes = {
101
- ...Field.propTypes,
102
- value: PropTypes.string,
103
- defaultValue: PropTypes.string
104
- }
105
-
106
- ValueField.defaultProps = {
107
- ...Field.defaultProps
108
- }
109
-
110
- /**
111
- * CheckField component
112
- */
113
- export class CheckField extends Field {
114
- shouldComponentUpdate (props, state) {
115
- return (
116
- super.shouldComponentUpdate(props, state) ||
117
- (props.value !== this.props.value) ||
118
- (props.checked !== this.props.checked) ||
119
- (props.onClick !== this.props.onClick)
120
- )
121
- }
122
-
123
- handleClick = ({ target: { value, checked } }) => {
124
- const {
125
- onClick = DEFAULT_HANDLE_CLICK
126
- } = this.props
127
-
128
- onClick(value, checked)
129
- }
130
-
131
- handleChange = ({ target: { value, checked } }) => {
132
- const {
133
- onChange = DEFAULT_HANDLE_CHANGE
134
- } = this.props
135
-
136
- onChange(value, checked)
137
- }
138
- }
139
-
140
- CheckField.propTypes = {
141
- ...Field.propTypes,
142
- checked: PropTypes.bool,
143
- defaultChecked: PropTypes.bool,
144
- onClick: PropTypes.func
145
- }
146
-
147
- CheckField.defaultProps = {
148
- ...Field.defaultProps,
149
- onClick: DEFAULT_HANDLE_CLICK
150
- }
@@ -0,0 +1,20 @@
1
+ require('@babel/register')({
2
+ ignore: [
3
+ /node_modules\/(?!@modernpoacher\/cogs|@modernpoacher\/sprockets|@modernpoacher\/gremlins)/
4
+ ]
5
+ })
6
+
7
+ const debug = require('debug')
8
+
9
+ const log = debug('@modernpoacher/gremlins/super/components/group')
10
+
11
+ log('`gremlins` is awake')
12
+
13
+ const {
14
+ default: Group
15
+ } = require('./index.jsx')
16
+
17
+ /**
18
+ * Exports only default
19
+ */
20
+ module.exports = Group
@@ -0,0 +1,2 @@
1
+ export { default } from '#gremlins/super/components/group'
2
+ export * from '#gremlins/super/components/group'
@@ -0,0 +1,18 @@
1
+ declare module '#gremlins/super/components/group' {
2
+ import React from 'react'
3
+
4
+ export type GroupProps = GremlinsTypes.Super.Components.Group.GroupProps
5
+
6
+ export default class Group<P extends GroupProps> extends React.Component<P> {
7
+ static propTypes: object
8
+
9
+ getClassName (): string
10
+
11
+ shouldComponentUpdate (props: GroupProps): boolean
12
+ }
13
+ }
14
+
15
+ declare module '@modernpoacher/gremlins/super/components/group' {
16
+ export { default } from '#gremlins/super/components/group'
17
+ export * from '#gremlins/super/components/group'
18
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * @typedef {GremlinsTypes.Super.Components.Group.GroupProps} GroupProps
3
+ */
4
+
5
+ /**
6
+ * Group component
7
+ */
8
+ import React, { Component } from 'react'
9
+ import PropTypes from 'prop-types'
10
+
11
+ export default class Group extends Component {
12
+ getClassName () {
13
+ return 'group'
14
+ }
15
+
16
+ /**
17
+ * @param {GroupProps} props
18
+ * @returns {boolean}
19
+ */
20
+ shouldComponentUpdate (props) {
21
+ return (
22
+ (props.children !== this.props.children)
23
+ )
24
+ }
25
+
26
+ render () {
27
+ const {
28
+ children
29
+ } = this.props
30
+
31
+ if (children) {
32
+ const {
33
+ groupRef
34
+ } = this.props
35
+
36
+ return (
37
+ <fieldset
38
+ className={this.getClassName()}
39
+ ref={groupRef}>
40
+ {children}
41
+ </fieldset>
42
+ )
43
+ }
44
+
45
+ return null
46
+ }
47
+ }
48
+
49
+ Group.propTypes = {
50
+ children: PropTypes.oneOfType([
51
+ PropTypes.node,
52
+ PropTypes.arrayOf(
53
+ PropTypes.node
54
+ )
55
+ ]),
56
+ groupRef: PropTypes.shape({
57
+ current: PropTypes.shape({})
58
+ })
59
+ }
@@ -0,0 +1,23 @@
1
+ require('@babel/register')({
2
+ ignore: [
3
+ /node_modules\/(?!@modernpoacher\/cogs|@modernpoacher\/sprockets|@modernpoacher\/gremlins)/
4
+ ]
5
+ })
6
+
7
+ const debug = require('debug')
8
+
9
+ const log = debug('@modernpoacher/gremlins/super/components')
10
+
11
+ log('`gremlins` is awake')
12
+
13
+ const {
14
+ default: Field
15
+ } = require('./field/index.jsx')
16
+
17
+ module.exports.Field = Field
18
+
19
+ const {
20
+ default: Group
21
+ } = require('./group/index.jsx')
22
+
23
+ module.exports.Group = Group
@@ -0,0 +1,2 @@
1
+ export { default as Field } from '#gremlins/super/components/field'
2
+ export { default as Group } from '#gremlins/super/components/group'
@@ -0,0 +1,2 @@
1
+ export { default as Field } from '#gremlins/super/components/field'
2
+ export { default as Group } from '#gremlins/super/components/group'
@@ -0,0 +1,8 @@
1
+ import debug from 'debug'
2
+
3
+ const log = debug('@modernpoacher/gremlins/super/components')
4
+
5
+ log('`gremlins` is awake')
6
+
7
+ export { default as Field } from './field/index.cjs'
8
+ export { default as Group } from './group/index.cjs'
@@ -0,0 +1,22 @@
1
+ require('@babel/register')({
2
+ ignore: [
3
+ /node_modules\/(?!@modernpoacher\/cogs|@modernpoacher\/sprockets|@modernpoacher\/gremlins)/
4
+ ]
5
+ })
6
+
7
+ const debug = require('debug')
8
+
9
+ const log = debug('@modernpoacher/gremlins/super/gremlins')
10
+
11
+ log('`gremlins` is awake')
12
+
13
+ const {
14
+ FieldGremlin,
15
+ GroupGremlin
16
+ } = require('./index.jsx')
17
+
18
+ /**
19
+ * Exports `FieldGremlin` and `GroupGremlin`
20
+ */
21
+ module.exports.FieldGremlin = FieldGremlin
22
+ module.exports.GroupGremlin = GroupGremlin
@@ -0,0 +1,4 @@
1
+ export {
2
+ FieldGremlin,
3
+ GroupGremlin
4
+ } from '#gremlins/super/gremlins'
@@ -0,0 +1,36 @@
1
+ declare module '#gremlins/super/gremlins' {
2
+ import React from 'react'
3
+
4
+ export type FieldGremlinProps = GremlinsTypes.Super.Gremlins.FieldGremlinProps
5
+
6
+ export class FieldGremlin<P extends FieldGremlinProps> extends React.Component<P> {
7
+ static propTypes: Record<PropertyKey, unknown>
8
+
9
+ getClassName (): string
10
+
11
+ getId (): string
12
+
13
+ shouldComponentUpdate (props: FieldGremlinProps): boolean
14
+
15
+ renderField (): React.JSX.Element | null
16
+ }
17
+
18
+ export type GroupGremlinProps = GremlinsTypes.Super.Gremlins.GroupGremlinProps
19
+
20
+ export class GroupGremlin<P extends GroupGremlinProps> extends React.Component<P> {
21
+ static propTypes: object
22
+
23
+ getClassName (): string
24
+
25
+ shouldComponentUpdate (props: GroupGremlinProps): boolean
26
+
27
+ renderGroup (): React.JSX.Element | null
28
+ }
29
+ }
30
+
31
+ declare module '@modernpoacher/gremlins/super/gremlins' {
32
+ export {
33
+ FieldGremlin,
34
+ GroupGremlin
35
+ } from '#gremlins/super/gremlins'
36
+ }
@@ -0,0 +1,176 @@
1
+ /**
2
+ * @typedef {GremlinsTypes.OnEventType} OnEventType
3
+ * @typedef {GremlinsTypes.Super.Gremlins.FieldGremlinProps} FieldGremlinProps
4
+ * @typedef {GremlinsTypes.Super.Gremlins.GroupGremlinProps} GroupGremlinProps
5
+ */
6
+
7
+ /**
8
+ * FieldGremlin component
9
+ * GroupGremlin component
10
+ */
11
+ import React, { Component } from 'react'
12
+ import PropTypes from 'prop-types'
13
+ import classnames from 'classnames'
14
+
15
+ import Field from '#gremlins/super/components/field'
16
+ import Group from '#gremlins/super/components/group'
17
+
18
+ /**
19
+ * @type {OnEventType}
20
+ */
21
+ function DEFAULT_HANDLE_EVENT () {
22
+ //
23
+ }
24
+
25
+ export class FieldGremlin extends Component {
26
+ getClassName () {
27
+ const {
28
+ required = false,
29
+ disabled = false,
30
+ readOnly = false
31
+ } = this.props
32
+
33
+ return classnames('gremlin', { required, disabled, readOnly })
34
+ }
35
+
36
+ getId () {
37
+ const {
38
+ id,
39
+ name
40
+ } = this.props
41
+
42
+ return id || name
43
+ }
44
+
45
+ /**
46
+ * @param {FieldGremlinProps} props
47
+ * @returns {boolean}
48
+ */
49
+ shouldComponentUpdate (props) {
50
+ return (
51
+ (props.name !== this.props.name) ||
52
+ (props.id !== this.props.id) ||
53
+ (props.value !== this.props.value) ||
54
+ (props.required !== this.props.required) ||
55
+ (props.disabled !== this.props.disabled) ||
56
+ (props.readOnly !== this.props.readOnly) ||
57
+ (props.tabIndex !== this.props.tabIndex) ||
58
+ (props.accessKey !== this.props.accessKey) ||
59
+ (props.placeholder !== this.props.placeholder) ||
60
+ (props.onChange !== this.props.onChange)
61
+ )
62
+ }
63
+
64
+ renderField () {
65
+ const id = this.getId()
66
+
67
+ const {
68
+ name,
69
+ value,
70
+ required = false,
71
+ disabled = false,
72
+ readOnly = false,
73
+ tabIndex,
74
+ accessKey,
75
+ placeholder,
76
+ onChange = DEFAULT_HANDLE_EVENT,
77
+ fieldRef
78
+ } = this.props
79
+
80
+ return (
81
+ <Field
82
+ name={name}
83
+ id={id}
84
+ value={value}
85
+ required={required}
86
+ disabled={disabled}
87
+ readOnly={readOnly}
88
+ tabIndex={tabIndex}
89
+ accessKey={accessKey}
90
+ placeholder={placeholder}
91
+ onChange={onChange}
92
+ fieldRef={fieldRef}
93
+ />
94
+ )
95
+ }
96
+
97
+ render () {
98
+ const className = this.getClassName()
99
+
100
+ return (
101
+ <div className={className}>
102
+ {this.renderField()}
103
+ </div>
104
+ )
105
+ }
106
+ }
107
+
108
+ FieldGremlin.propTypes = {
109
+ name: PropTypes.string.isRequired,
110
+ id: PropTypes.string,
111
+ value: PropTypes.string,
112
+ required: PropTypes.bool,
113
+ disabled: PropTypes.bool,
114
+ readOnly: PropTypes.bool,
115
+ tabIndex: PropTypes.number,
116
+ accessKey: PropTypes.string,
117
+ placeholder: PropTypes.string,
118
+ onChange: PropTypes.func,
119
+ fieldRef: PropTypes.shape({
120
+ current: PropTypes.shape({
121
+ value: PropTypes.string
122
+ })
123
+ })
124
+ }
125
+
126
+ export class GroupGremlin extends Component {
127
+ getClassName () {
128
+ return 'gremlin'
129
+ }
130
+
131
+ /**
132
+ * @param {GroupGremlinProps} props
133
+ * @returns {boolean}
134
+ */
135
+ shouldComponentUpdate (props) {
136
+ return (
137
+ (props.children !== this.props.children)
138
+ )
139
+ }
140
+
141
+ renderGroup () {
142
+ const {
143
+ groupRef,
144
+ children
145
+ } = this.props
146
+
147
+ return (
148
+ <Group
149
+ groupRef={groupRef}>
150
+ {children}
151
+ </Group>
152
+ )
153
+ }
154
+
155
+ render () {
156
+ const className = this.getClassName()
157
+
158
+ return (
159
+ <div className={className}>
160
+ {this.renderGroup()}
161
+ </div>
162
+ )
163
+ }
164
+ }
165
+
166
+ GroupGremlin.propTypes = {
167
+ children: PropTypes.oneOfType([
168
+ PropTypes.node,
169
+ PropTypes.arrayOf(
170
+ PropTypes.node
171
+ )
172
+ ]),
173
+ groupRef: PropTypes.shape({
174
+ current: PropTypes.shape({})
175
+ })
176
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "extends": "stylelint-config-recommended-scss",
3
+ "plugins": [
4
+ "stylelint-scss"
5
+ ],
6
+ "rules": {
7
+ "no-descending-specificity": [
8
+ true,
9
+ {
10
+ "severity": "warning"
11
+ }
12
+ ]
13
+ }
14
+ }
@@ -0,0 +1,59 @@
1
+ @use "design-system/palette";
2
+ @use "design-system/typography";
3
+
4
+ @use "gremlins/radio";
5
+ @use "gremlins/checkbox";
6
+ @use "gremlins/disabled";
7
+ @use "gremlins/error";
8
+
9
+ @mixin gremlins {
10
+ padding: 0;
11
+ margin: 1rem 0;
12
+
13
+ &:first-child {
14
+ margin-top: 0;
15
+ }
16
+
17
+ &:last-child {
18
+ margin-bottom: 0;
19
+ }
20
+
21
+ line-height: 1.375rem;
22
+
23
+ &.radio {
24
+ @include radio.gremlin-radio;
25
+ }
26
+
27
+ &.checkbox {
28
+ @include checkbox.gremlin-checkbox;
29
+ }
30
+
31
+ &.disabled {
32
+ @include disabled.gremlin-disabled;
33
+ }
34
+
35
+ &.error {
36
+ @include error.gremlin-error;
37
+ }
38
+
39
+ &.fieldset {
40
+ legend {
41
+ @include typography.heading-m;
42
+
43
+ & /* stylelint-disable-line no-duplicate-selectors */ {
44
+ padding: 0;
45
+ margin-top: 0;
46
+ }
47
+ }
48
+
49
+ &.error {
50
+ @include error.gremlin-error;
51
+
52
+ padding-left: 1rem;
53
+ }
54
+ }
55
+ }
56
+
57
+ %gremlins {
58
+ @include gremlins;
59
+ }