@modernpoacher/cogs 0.0.60 → 0.1.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modernpoacher/cogs",
3
- "version": "0.0.60",
3
+ "version": "0.1.1",
4
4
  "description": "Cogs",
5
5
  "keywords": [
6
6
  "Cogs",
@@ -57,9 +57,9 @@
57
57
  "@storybook/addon-links": "^7.5.3",
58
58
  "@storybook/react": "^7.5.3",
59
59
  "@storybook/react-webpack5": "^7.5.3",
60
- "@types/react": "^18.2.38",
61
- "@typescript-eslint/eslint-plugin": "^6.12.0",
62
- "@typescript-eslint/parser": "^6.12.0",
60
+ "@types/react": "^18.2.39",
61
+ "@typescript-eslint/eslint-plugin": "^6.13.0",
62
+ "@typescript-eslint/parser": "^6.13.0",
63
63
  "babel-plugin-module-resolver": "^5.0.0",
64
64
  "clean-webpack-plugin": "^4.0.0",
65
65
  "core-js": "^3.33.3",
@@ -2,6 +2,7 @@
2
2
  * CheckboxField component
3
3
  */
4
4
  import React from 'react'
5
+ import PropTypes from 'prop-types'
5
6
  import classnames from 'classnames'
6
7
 
7
8
  import { CheckField } from '@modernpoacher/cogs/components/field'
@@ -15,6 +16,7 @@ export default class CheckboxField extends CheckField {
15
16
  const {
16
17
  id,
17
18
  name,
19
+ value,
18
20
  checked,
19
21
  defaultChecked,
20
22
  required,
@@ -31,6 +33,7 @@ export default class CheckboxField extends CheckField {
31
33
  <input
32
34
  id={id}
33
35
  name={name}
36
+ value={value}
34
37
  checked={checked}
35
38
  defaultChecked={defaultChecked}
36
39
  required={required}
@@ -49,7 +52,8 @@ export default class CheckboxField extends CheckField {
49
52
  }
50
53
 
51
54
  CheckboxField.propTypes = {
52
- ...CheckField.propTypes
55
+ ...CheckField.propTypes,
56
+ value: PropTypes.string.isRequired
53
57
  }
54
58
 
55
59
  CheckboxField.defaultProps = {
@@ -2,6 +2,7 @@
2
2
  * CheckboxCog component
3
3
  */
4
4
  import React from 'react'
5
+ import PropTypes from 'prop-types'
5
6
  import classnames from 'classnames'
6
7
 
7
8
  import { CheckCog } from '@modernpoacher/cogs/cogs'
@@ -16,20 +17,27 @@ export default class CheckboxCog extends CheckCog {
16
17
  return classnames(super.getClassName(), 'checkbox')
17
18
  }
18
19
 
19
- handleClick = (value) => {
20
+ handleClick = (value, checked) => {
20
21
  const {
21
22
  onClick
22
23
  } = this.props
23
24
 
24
- onClick(value)
25
+ onClick(value, checked)
25
26
  }
26
27
 
27
- handleChange = (value) => {
28
+ handleChange = (value, checked) => {
28
29
  const {
29
30
  onChange
30
31
  } = this.props
31
32
 
32
- onChange(value)
33
+ onChange(value, checked)
34
+ }
35
+
36
+ shouldComponentUpdate (props) {
37
+ return (
38
+ super.shouldComponentUpdate(props) ||
39
+ (props.value !== this.props.value)
40
+ )
33
41
  }
34
42
 
35
43
  renderTitle () {
@@ -82,6 +90,7 @@ export default class CheckboxCog extends CheckCog {
82
90
 
83
91
  const {
84
92
  name,
93
+ value,
85
94
  checked,
86
95
  defaultChecked,
87
96
  required,
@@ -97,6 +106,7 @@ export default class CheckboxCog extends CheckCog {
97
106
  <Field
98
107
  id={id}
99
108
  name={name}
109
+ value={value}
100
110
  checked={checked}
101
111
  defaultChecked={defaultChecked}
102
112
  required={required}
@@ -127,7 +137,8 @@ export default class CheckboxCog extends CheckCog {
127
137
  }
128
138
 
129
139
  CheckboxCog.propTypes = {
130
- ...CheckCog.propTypes
140
+ ...CheckCog.propTypes,
141
+ value: PropTypes.string.isRequired
131
142
  }
132
143
 
133
144
  CheckboxCog.defaultProps = {
@@ -12,18 +12,6 @@ export default class RadioField extends CheckField {
12
12
  return classnames(super.getClassName(), 'radio')
13
13
  }
14
14
 
15
- handleClick = ({ target: { value } }) => {
16
- const { onClick } = this.props
17
-
18
- onClick(value)
19
- }
20
-
21
- handleChange = ({ target: { value } }) => {
22
- const { onChange } = this.props
23
-
24
- onChange(value)
25
- }
26
-
27
15
  render () {
28
16
  const {
29
17
  id,
@@ -17,20 +17,20 @@ export default class Radio extends CheckCog {
17
17
  return classnames(super.getClassName(), 'radio')
18
18
  }
19
19
 
20
- handleClick = (value) => {
20
+ handleClick = (value, checked) => {
21
21
  const {
22
22
  onClick
23
23
  } = this.props
24
24
 
25
- onClick(value)
25
+ onClick(value, checked)
26
26
  }
27
27
 
28
- handleChange = (value) => {
28
+ handleChange = (value, checked) => {
29
29
  const {
30
30
  onChange
31
31
  } = this.props
32
32
 
33
- onChange(value)
33
+ onChange(value, checked)
34
34
  }
35
35
 
36
36
  shouldComponentUpdate (props) {
@@ -115,21 +115,22 @@ export class CheckField extends Field {
115
115
  shouldComponentUpdate (props) {
116
116
  return (
117
117
  super.shouldComponentUpdate(props) ||
118
+ (props.value !== this.props.value) ||
118
119
  (props.checked !== this.props.checked) ||
119
120
  (props.onClick !== this.props.onClick)
120
121
  )
121
122
  }
122
123
 
123
- handleClick = ({ target: { checked } }) => {
124
+ handleClick = ({ target: { value, checked } }) => {
124
125
  const { onClick } = this.props
125
126
 
126
- onClick(checked)
127
+ onClick(value, checked)
127
128
  }
128
129
 
129
- handleChange = ({ target: { checked } }) => {
130
+ handleChange = ({ target: { value, checked } }) => {
130
131
  const { onChange } = this.props
131
132
 
132
- onChange(checked)
133
+ onChange(value, checked)
133
134
  }
134
135
  }
135
136