@modernpoacher/cogs 0.1.122 → 0.1.124

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/babel.config.cjs CHANGED
@@ -47,6 +47,7 @@ const plugins = [
47
47
  /**
48
48
  * Storybook
49
49
  */
50
+ '@modernpoacher/cogs/common/': './src/common/index.mjs',
50
51
  '@modernpoacher/cogs/cogs/checkbox/error-message': './src/cogs/checkbox/error-message/index.jsx',
51
52
  '@modernpoacher/cogs/cogs/checkbox/description': './src/cogs/checkbox/description/index.jsx',
52
53
  '@modernpoacher/cogs/cogs/checkbox/field': './src/cogs/checkbox/field/index.jsx',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modernpoacher/cogs",
3
- "version": "0.1.122",
3
+ "version": "0.1.124",
4
4
  "description": "Cogs",
5
5
  "keywords": [
6
6
  "Cogs",
@@ -52,11 +52,11 @@
52
52
  "@babel/register": "^7.24.6",
53
53
  "@modernpoacher/design-system": "1.0.113",
54
54
  "@modernpoacher/hooks": "^1.0.479",
55
- "@storybook/addon-actions": "^8.1.11",
56
- "@storybook/addon-essentials": "^8.1.11",
57
- "@storybook/addon-links": "^8.1.11",
58
- "@storybook/react": "^8.1.11",
59
- "@storybook/react-webpack5": "^8.1.11",
55
+ "@storybook/addon-actions": "7.6.20",
56
+ "@storybook/addon-essentials": "7.6.20",
57
+ "@storybook/addon-links": "7.6.20",
58
+ "@storybook/react": "7.6.20",
59
+ "@storybook/react-webpack5": "7.6.20",
60
60
  "@types/react": "^18.3.3",
61
61
  "@typescript-eslint/eslint-plugin": "^7.14.1",
62
62
  "@typescript-eslint/parser": "^7.14.1",
@@ -72,7 +72,7 @@
72
72
  "husky": "^9.0.11",
73
73
  "jest": "^29.7.0",
74
74
  "mini-css-extract-plugin": "^2.9.0",
75
- "postcss": "^8.4.38",
75
+ "postcss": "^8.4.39",
76
76
  "postcss-import": "^16.1.0",
77
77
  "postcss-loader": "^8.1.1",
78
78
  "postcss-map": "^0.11.0",
@@ -83,7 +83,7 @@
83
83
  "remove-files-webpack-plugin": "^1.5.0",
84
84
  "sass": "^1.77.6",
85
85
  "sass-loader": "^14.2.1",
86
- "storybook": "^8.1.11",
86
+ "storybook": "7.6.20",
87
87
  "webpack": "^5.92.1",
88
88
  "webpack-cli": "^5.1.4"
89
89
  },
@@ -136,6 +136,7 @@
136
136
  "./cogs/textarea/error-message": "./src/cogs/textarea/error-message/index.cjs",
137
137
  "./cogs/textarea/field": "./src/cogs/textarea/field/index.cjs",
138
138
  "./cogs/textarea/title": "./src/cogs/textarea/title/index.cjs",
139
+ "./common": "./src/common/index.mjs",
139
140
  "./components/common/disabled": "./src/components/common/disabled/index.cjs",
140
141
  "./components/common/readonly": "./src/components/common/readonly/index.cjs",
141
142
  "./components/common/required": "./src/components/common/required/index.cjs",
@@ -18,9 +18,9 @@ export default class CheckboxField extends CheckField {
18
18
  id,
19
19
  name,
20
20
  value,
21
- required,
22
- disabled,
23
- readOnly,
21
+ required = false,
22
+ disabled = false,
23
+ readOnly = false,
24
24
  tabIndex,
25
25
  accessKey,
26
26
  fieldRef
@@ -40,8 +40,8 @@ export default class CheckboxField extends CheckField {
40
40
  readOnly={readOnly}
41
41
  tabIndex={tabIndex}
42
42
  accessKey={accessKey}
43
- onClick={this.handleClick}
44
43
  onChange={this.handleChange}
44
+ onClick={this.handleClick}
45
45
  className={className}
46
46
  type='checkbox'
47
47
  ref={fieldRef}
@@ -64,8 +64,8 @@ export default class CheckboxField extends CheckField {
64
64
  readOnly={readOnly}
65
65
  tabIndex={tabIndex}
66
66
  accessKey={accessKey}
67
- onClick={this.handleClick}
68
67
  onChange={this.handleChange}
68
+ onClick={this.handleClick}
69
69
  className={className}
70
70
  type='checkbox'
71
71
  ref={fieldRef}
@@ -7,6 +7,11 @@ import classnames from 'classnames'
7
7
 
8
8
  import { CheckCog } from '@modernpoacher/cogs/cogs'
9
9
 
10
+ import {
11
+ DEFAULT_HANDLE_CHANGE,
12
+ DEFAULT_HANDLE_CLICK
13
+ } from '@modernpoacher/cogs/common'
14
+
10
15
  import Title from './title/index.jsx'
11
16
  import Description from './description/index.jsx'
12
17
  import ErrorMessage from './error-message/index.jsx'
@@ -17,20 +22,20 @@ export default class CheckboxCog extends CheckCog {
17
22
  return classnames(super.getClassName(), 'checkbox')
18
23
  }
19
24
 
20
- handleClick = (value, checked) => {
25
+ handleChange = (value, checked) => {
21
26
  const {
22
- onClick
27
+ onChange = DEFAULT_HANDLE_CHANGE
23
28
  } = this.props
24
29
 
25
- onClick(value, checked)
30
+ onChange(value, checked)
26
31
  }
27
32
 
28
- handleChange = (value, checked) => {
33
+ handleClick = (value, checked) => {
29
34
  const {
30
- onChange
35
+ onClick = DEFAULT_HANDLE_CLICK
31
36
  } = this.props
32
37
 
33
- onChange(value, checked)
38
+ onClick(value, checked)
34
39
  }
35
40
 
36
41
  shouldComponentUpdate (props) {
@@ -45,9 +50,9 @@ export default class CheckboxCog extends CheckCog {
45
50
 
46
51
  const {
47
52
  title,
48
- required,
49
- disabled,
50
- readOnly
53
+ required = false,
54
+ disabled = false,
55
+ readOnly = false
51
56
  } = this.props
52
57
 
53
58
  return (
@@ -93,9 +98,9 @@ export default class CheckboxCog extends CheckCog {
93
98
  value,
94
99
  checked,
95
100
  defaultChecked,
96
- required,
97
- disabled,
98
- readOnly,
101
+ required = false,
102
+ disabled = false,
103
+ readOnly = false,
99
104
  tabIndex,
100
105
  accessKey,
101
106
  placeholder,
@@ -115,8 +120,8 @@ export default class CheckboxCog extends CheckCog {
115
120
  tabIndex={tabIndex}
116
121
  accessKey={accessKey}
117
122
  placeholder={placeholder}
118
- onClick={this.handleClick}
119
123
  onChange={this.handleChange}
124
+ onClick={this.handleClick}
120
125
  fieldRef={fieldRef}
121
126
  />
122
127
  )
@@ -17,9 +17,9 @@ export default class EmailField extends ValueField {
17
17
  name,
18
18
  value,
19
19
  defaultValue,
20
- required,
21
- disabled,
22
- readOnly,
20
+ required = false,
21
+ disabled = false,
22
+ readOnly = false,
23
23
  tabIndex,
24
24
  accessKey,
25
25
  placeholder,
@@ -6,6 +6,10 @@ import classnames from 'classnames'
6
6
 
7
7
  import { ValueCog } from '@modernpoacher/cogs/cogs'
8
8
 
9
+ import {
10
+ DEFAULT_HANDLE_CHANGE
11
+ } from '@modernpoacher/cogs/common'
12
+
9
13
  import Title from './title/index.jsx'
10
14
  import Description from './description/index.jsx'
11
15
  import ErrorMessage from './error-message/index.jsx'
@@ -18,7 +22,7 @@ export default class EmailCog extends ValueCog {
18
22
 
19
23
  handleChange = (value) => {
20
24
  const {
21
- onChange
25
+ onChange = DEFAULT_HANDLE_CHANGE
22
26
  } = this.props
23
27
 
24
28
  onChange(value)
@@ -29,9 +33,9 @@ export default class EmailCog extends ValueCog {
29
33
 
30
34
  const {
31
35
  title,
32
- required,
33
- disabled,
34
- readOnly
36
+ required = false,
37
+ disabled = false,
38
+ readOnly = false
35
39
  } = this.props
36
40
 
37
41
  return (
@@ -76,9 +80,9 @@ export default class EmailCog extends ValueCog {
76
80
  name,
77
81
  value,
78
82
  defaultValue,
79
- required,
80
- disabled,
81
- readOnly,
83
+ required = false,
84
+ disabled = false,
85
+ readOnly = false,
82
86
  tabIndex,
83
87
  accessKey,
84
88
  placeholder,
@@ -7,25 +7,25 @@ import React, { Component } from 'react'
7
7
  import PropTypes from 'prop-types'
8
8
  import classnames from 'classnames'
9
9
 
10
+ import {
11
+ DEFAULT_HANDLE_CHANGE,
12
+ DEFAULT_HANDLE_CLICK
13
+ } from '@modernpoacher/cogs/common'
14
+
10
15
  import Title from '@modernpoacher/cogs/components/title'
11
16
  import Description from '@modernpoacher/cogs/components/description'
12
17
  import ErrorMessage from '@modernpoacher/cogs/components/error-message'
13
- import Field from '@modernpoacher/cogs/components/field'
14
-
15
- function onChange () {
16
- /* */
17
- }
18
-
19
- function onClick () {
20
- /* */
21
- }
18
+ import Field, {
19
+ ValueField,
20
+ CheckField
21
+ } from '@modernpoacher/cogs/components/field'
22
22
 
23
23
  export default class Cog extends Component {
24
24
  getClassName () {
25
25
  const {
26
- required,
27
- disabled,
28
- readOnly,
26
+ required = false,
27
+ disabled = false,
28
+ readOnly = false,
29
29
  errorMessage
30
30
  } = this.props
31
31
 
@@ -67,9 +67,9 @@ export default class Cog extends Component {
67
67
 
68
68
  const {
69
69
  title,
70
- required,
71
- disabled,
72
- readOnly
70
+ required = false,
71
+ disabled = false,
72
+ readOnly = false
73
73
  } = this.props
74
74
 
75
75
  return (
@@ -112,13 +112,13 @@ export default class Cog extends Component {
112
112
 
113
113
  const {
114
114
  name,
115
- required,
116
- disabled,
117
- readOnly,
115
+ required = false,
116
+ disabled = false,
117
+ readOnly = false,
118
118
  tabIndex,
119
119
  accessKey,
120
120
  placeholder,
121
- onChange,
121
+ onChange = DEFAULT_HANDLE_CHANGE,
122
122
  fieldRef
123
123
  } = this.props
124
124
 
@@ -172,7 +172,7 @@ Cog.defaultProps = {
172
172
  required: false,
173
173
  disabled: false,
174
174
  readOnly: false,
175
- onChange
175
+ onChange: DEFAULT_HANDLE_CHANGE
176
176
  }
177
177
 
178
178
  export class ValueCog extends Cog {
@@ -182,6 +182,37 @@ export class ValueCog extends Cog {
182
182
  (props.value !== this.props.value)
183
183
  )
184
184
  }
185
+
186
+ renderField () {
187
+ const id = this.getId()
188
+
189
+ const {
190
+ name,
191
+ required = false,
192
+ disabled = false,
193
+ readOnly = false,
194
+ tabIndex,
195
+ accessKey,
196
+ placeholder,
197
+ onChange = DEFAULT_HANDLE_CHANGE,
198
+ fieldRef
199
+ } = this.props
200
+
201
+ return (
202
+ <ValueField
203
+ id={id}
204
+ name={name}
205
+ required={required}
206
+ disabled={disabled}
207
+ readOnly={readOnly}
208
+ tabIndex={tabIndex}
209
+ accessKey={accessKey}
210
+ placeholder={placeholder}
211
+ onChange={onChange}
212
+ fieldRef={fieldRef}
213
+ />
214
+ )
215
+ }
185
216
  }
186
217
 
187
218
  ValueCog.propTypes = {
@@ -202,6 +233,39 @@ export class CheckCog extends Cog {
202
233
  (props.onClick !== this.props.onClick)
203
234
  )
204
235
  }
236
+
237
+ renderField () {
238
+ const id = this.getId()
239
+
240
+ const {
241
+ name,
242
+ required = false,
243
+ disabled = false,
244
+ readOnly = false,
245
+ tabIndex,
246
+ accessKey,
247
+ placeholder,
248
+ onChange = DEFAULT_HANDLE_CHANGE,
249
+ onClick = DEFAULT_HANDLE_CLICK,
250
+ fieldRef
251
+ } = this.props
252
+
253
+ return (
254
+ <CheckField
255
+ id={id}
256
+ name={name}
257
+ required={required}
258
+ disabled={disabled}
259
+ readOnly={readOnly}
260
+ tabIndex={tabIndex}
261
+ accessKey={accessKey}
262
+ placeholder={placeholder}
263
+ onChange={onChange}
264
+ onClick={onClick}
265
+ fieldRef={fieldRef}
266
+ />
267
+ )
268
+ }
205
269
  }
206
270
 
207
271
  CheckCog.propTypes = {
@@ -213,5 +277,5 @@ CheckCog.propTypes = {
213
277
 
214
278
  CheckCog.defaultProps = {
215
279
  ...Cog.defaultProps,
216
- onClick
280
+ onClick: DEFAULT_HANDLE_CLICK
217
281
  }
@@ -18,9 +18,9 @@ export default class NumberField extends ValueField {
18
18
  name,
19
19
  value,
20
20
  defaultValue,
21
- required,
22
- disabled,
23
- readOnly,
21
+ required = false,
22
+ disabled = false,
23
+ readOnly = false,
24
24
  tabIndex,
25
25
  accessKey,
26
26
  placeholder,
@@ -7,6 +7,10 @@ import classnames from 'classnames'
7
7
 
8
8
  import { ValueCog } from '@modernpoacher/cogs/cogs'
9
9
 
10
+ import {
11
+ DEFAULT_HANDLE_CHANGE
12
+ } from '@modernpoacher/cogs/common'
13
+
10
14
  import Title from './title/index.jsx'
11
15
  import Description from './description/index.jsx'
12
16
  import ErrorMessage from './error-message/index.jsx'
@@ -19,7 +23,7 @@ export default class NumberCog extends ValueCog {
19
23
 
20
24
  handleChange = (value) => {
21
25
  const {
22
- onChange
26
+ onChange = DEFAULT_HANDLE_CHANGE
23
27
  } = this.props
24
28
 
25
29
  onChange(value)
@@ -30,9 +34,9 @@ export default class NumberCog extends ValueCog {
30
34
 
31
35
  const {
32
36
  title,
33
- required,
34
- disabled,
35
- readOnly
37
+ required = false,
38
+ disabled = false,
39
+ readOnly = false
36
40
  } = this.props
37
41
 
38
42
  return (
@@ -77,9 +81,9 @@ export default class NumberCog extends ValueCog {
77
81
  name,
78
82
  value,
79
83
  defaultValue,
80
- required,
81
- disabled,
82
- readOnly,
84
+ required = false,
85
+ disabled = false,
86
+ readOnly = false,
83
87
  tabIndex,
84
88
  accessKey,
85
89
  placeholder,
@@ -17,9 +17,9 @@ export default class PasswordField extends ValueField {
17
17
  name,
18
18
  value,
19
19
  defaultValue,
20
- required,
21
- disabled,
22
- readOnly,
20
+ required = false,
21
+ disabled = false,
22
+ readOnly = false,
23
23
  tabIndex,
24
24
  accessKey,
25
25
  placeholder,
@@ -6,6 +6,10 @@ import classnames from 'classnames'
6
6
 
7
7
  import { ValueCog } from '@modernpoacher/cogs/cogs'
8
8
 
9
+ import {
10
+ DEFAULT_HANDLE_CHANGE
11
+ } from '@modernpoacher/cogs/common'
12
+
9
13
  import Title from './title/index.jsx'
10
14
  import Description from './description/index.jsx'
11
15
  import ErrorMessage from './error-message/index.jsx'
@@ -18,7 +22,7 @@ export default class PasswordCog extends ValueCog {
18
22
 
19
23
  handleChange = (value) => {
20
24
  const {
21
- onChange
25
+ onChange = DEFAULT_HANDLE_CHANGE
22
26
  } = this.props
23
27
 
24
28
  onChange(value)
@@ -29,9 +33,9 @@ export default class PasswordCog extends ValueCog {
29
33
 
30
34
  const {
31
35
  title,
32
- required,
33
- disabled,
34
- readOnly
36
+ required = false,
37
+ disabled = false,
38
+ readOnly = false
35
39
  } = this.props
36
40
 
37
41
  return (
@@ -76,9 +80,9 @@ export default class PasswordCog extends ValueCog {
76
80
  name,
77
81
  value,
78
82
  defaultValue,
79
- required,
80
- disabled,
81
- readOnly,
83
+ required = false,
84
+ disabled = false,
85
+ readOnly = false,
82
86
  tabIndex,
83
87
  accessKey,
84
88
  placeholder,
@@ -18,9 +18,9 @@ export default class RadioField extends CheckField {
18
18
  id,
19
19
  name,
20
20
  value,
21
- required,
22
- disabled,
23
- readOnly,
21
+ required = false,
22
+ disabled = false,
23
+ readOnly = false,
24
24
  tabIndex,
25
25
  accessKey,
26
26
  fieldRef
@@ -40,8 +40,8 @@ export default class RadioField extends CheckField {
40
40
  readOnly={readOnly}
41
41
  tabIndex={tabIndex}
42
42
  accessKey={accessKey}
43
- onClick={this.handleClick}
44
43
  onChange={this.handleChange}
44
+ onClick={this.handleClick}
45
45
  className={className}
46
46
  type='radio'
47
47
  ref={fieldRef}
@@ -64,8 +64,8 @@ export default class RadioField extends CheckField {
64
64
  readOnly={readOnly}
65
65
  tabIndex={tabIndex}
66
66
  accessKey={accessKey}
67
- onClick={this.handleClick}
68
67
  onChange={this.handleChange}
68
+ onClick={this.handleClick}
69
69
  className={className}
70
70
  type='radio'
71
71
  ref={fieldRef}
@@ -7,6 +7,11 @@ import classnames from 'classnames'
7
7
 
8
8
  import { CheckCog } from '@modernpoacher/cogs/cogs'
9
9
 
10
+ import {
11
+ DEFAULT_HANDLE_CHANGE,
12
+ DEFAULT_HANDLE_CLICK
13
+ } from '@modernpoacher/cogs/common'
14
+
10
15
  import Title from './title/index.jsx'
11
16
  import Description from './description/index.jsx'
12
17
  import ErrorMessage from './error-message/index.jsx'
@@ -17,20 +22,20 @@ export default class Radio extends CheckCog {
17
22
  return classnames(super.getClassName(), 'radio')
18
23
  }
19
24
 
20
- handleClick = (value, checked) => {
25
+ handleChange = (value, checked) => {
21
26
  const {
22
- onClick
27
+ onChange = DEFAULT_HANDLE_CHANGE
23
28
  } = this.props
24
29
 
25
- onClick(value, checked)
30
+ onChange(value, checked)
26
31
  }
27
32
 
28
- handleChange = (value, checked) => {
33
+ handleClick = (value, checked) => {
29
34
  const {
30
- onChange
35
+ onClick = DEFAULT_HANDLE_CLICK
31
36
  } = this.props
32
37
 
33
- onChange(value, checked)
38
+ onClick(value, checked)
34
39
  }
35
40
 
36
41
  shouldComponentUpdate (props) {
@@ -45,9 +50,9 @@ export default class Radio extends CheckCog {
45
50
 
46
51
  const {
47
52
  title,
48
- required,
49
- disabled,
50
- readOnly
53
+ required = false,
54
+ disabled = false,
55
+ readOnly = false
51
56
  } = this.props
52
57
 
53
58
  return (
@@ -93,9 +98,9 @@ export default class Radio extends CheckCog {
93
98
  value,
94
99
  checked,
95
100
  defaultChecked,
96
- required,
97
- disabled,
98
- readOnly,
101
+ required = false,
102
+ disabled = false,
103
+ readOnly = false,
99
104
  tabIndex,
100
105
  accessKey,
101
106
  placeholder,
@@ -115,8 +120,8 @@ export default class Radio extends CheckCog {
115
120
  tabIndex={tabIndex}
116
121
  accessKey={accessKey}
117
122
  placeholder={placeholder}
118
- onClick={this.handleClick}
119
123
  onChange={this.handleChange}
124
+ onClick={this.handleClick}
120
125
  fieldRef={fieldRef}
121
126
  />
122
127
  )
@@ -5,6 +5,10 @@ import React from 'react'
5
5
  import PropTypes from 'prop-types'
6
6
  import classnames from 'classnames'
7
7
 
8
+ import {
9
+ DEFAULT_HANDLE_CHANGE
10
+ } from '@modernpoacher/cogs/common'
11
+
8
12
  import { ValueField } from '@modernpoacher/cogs/components/field'
9
13
 
10
14
  function getSelectedValues ({ target: { selectedOptions } }) {
@@ -33,8 +37,8 @@ export default class SelectField extends ValueField {
33
37
 
34
38
  handleChange = (event) => {
35
39
  const {
36
- multiple,
37
- onChange
40
+ multiple = false,
41
+ onChange = DEFAULT_HANDLE_CHANGE
38
42
  } = this.props
39
43
 
40
44
  if (multiple) {
@@ -50,12 +54,12 @@ export default class SelectField extends ValueField {
50
54
  name,
51
55
  value,
52
56
  defaultValue,
53
- required,
54
- disabled,
55
- readOnly,
57
+ required = false,
58
+ disabled = false,
59
+ readOnly = false,
56
60
  tabIndex,
57
61
  accessKey,
58
- multiple,
62
+ multiple = false,
59
63
  children,
60
64
  fieldRef
61
65
  } = this.props
@@ -7,6 +7,10 @@ import classnames from 'classnames'
7
7
 
8
8
  import { ValueCog } from '@modernpoacher/cogs/cogs'
9
9
 
10
+ import {
11
+ DEFAULT_HANDLE_CHANGE
12
+ } from '@modernpoacher/cogs/common'
13
+
10
14
  import Title from './title/index.jsx'
11
15
  import Description from './description/index.jsx'
12
16
  import ErrorMessage from './error-message/index.jsx'
@@ -27,7 +31,7 @@ export default class SelectCog extends ValueCog {
27
31
 
28
32
  handleChange = (value) => {
29
33
  const {
30
- onChange
34
+ onChange = DEFAULT_HANDLE_CHANGE
31
35
  } = this.props
32
36
 
33
37
  onChange(value)
@@ -38,9 +42,9 @@ export default class SelectCog extends ValueCog {
38
42
 
39
43
  const {
40
44
  title,
41
- required,
42
- disabled,
43
- readOnly
45
+ required = false,
46
+ disabled = false,
47
+ readOnly = false
44
48
  } = this.props
45
49
 
46
50
  return (
@@ -85,13 +89,13 @@ export default class SelectCog extends ValueCog {
85
89
  name,
86
90
  value,
87
91
  defaultValue,
88
- required,
89
- disabled,
90
- readOnly,
92
+ required = false,
93
+ disabled = false,
94
+ readOnly = false,
91
95
  tabIndex,
92
96
  accessKey,
93
97
  placeholder,
94
- multiple,
98
+ multiple = false,
95
99
  fieldRef,
96
100
  children
97
101
  } = this.props
@@ -17,9 +17,9 @@ export default class TextField extends ValueField {
17
17
  name,
18
18
  value,
19
19
  defaultValue,
20
- required,
21
- disabled,
22
- readOnly,
20
+ required = false,
21
+ disabled = false,
22
+ readOnly = false,
23
23
  tabIndex,
24
24
  accessKey,
25
25
  placeholder,
@@ -6,6 +6,10 @@ import classnames from 'classnames'
6
6
 
7
7
  import { ValueCog } from '@modernpoacher/cogs/cogs'
8
8
 
9
+ import {
10
+ DEFAULT_HANDLE_CHANGE
11
+ } from '@modernpoacher/cogs/common'
12
+
9
13
  import Title from './title/index.jsx'
10
14
  import Description from './description/index.jsx'
11
15
  import ErrorMessage from './error-message/index.jsx'
@@ -18,7 +22,7 @@ export default class TextCog extends ValueCog {
18
22
 
19
23
  handleChange = (value) => {
20
24
  const {
21
- onChange
25
+ onChange = DEFAULT_HANDLE_CHANGE
22
26
  } = this.props
23
27
 
24
28
  onChange(value)
@@ -29,9 +33,9 @@ export default class TextCog extends ValueCog {
29
33
 
30
34
  const {
31
35
  title,
32
- required,
33
- disabled,
34
- readOnly
36
+ required = false,
37
+ disabled = false,
38
+ readOnly = false
35
39
  } = this.props
36
40
 
37
41
  return (
@@ -76,9 +80,9 @@ export default class TextCog extends ValueCog {
76
80
  name,
77
81
  value,
78
82
  defaultValue,
79
- required,
80
- disabled,
81
- readOnly,
83
+ required = false,
84
+ disabled = false,
85
+ readOnly = false,
82
86
  tabIndex,
83
87
  accessKey,
84
88
  placeholder,
@@ -17,9 +17,9 @@ export default class TextareaField extends ValueField {
17
17
  name,
18
18
  value,
19
19
  defaultValue,
20
- required,
21
- disabled,
22
- readOnly,
20
+ required = false,
21
+ disabled = false,
22
+ readOnly = false,
23
23
  tabIndex,
24
24
  accessKey,
25
25
  placeholder,
@@ -6,6 +6,10 @@ import classnames from 'classnames'
6
6
 
7
7
  import { ValueCog } from '@modernpoacher/cogs/cogs'
8
8
 
9
+ import {
10
+ DEFAULT_HANDLE_CHANGE
11
+ } from '@modernpoacher/cogs/common'
12
+
9
13
  import Title from './title/index.jsx'
10
14
  import Description from './description/index.jsx'
11
15
  import ErrorMessage from './error-message/index.jsx'
@@ -18,7 +22,7 @@ export default class TextareaCog extends ValueCog {
18
22
 
19
23
  handleChange = (value) => {
20
24
  const {
21
- onChange
25
+ onChange = DEFAULT_HANDLE_CHANGE
22
26
  } = this.props
23
27
 
24
28
  onChange(value)
@@ -29,9 +33,9 @@ export default class TextareaCog extends ValueCog {
29
33
 
30
34
  const {
31
35
  title,
32
- required,
33
- disabled,
34
- readOnly
36
+ required = false,
37
+ disabled = false,
38
+ readOnly = false
35
39
  } = this.props
36
40
 
37
41
  return (
@@ -76,9 +80,9 @@ export default class TextareaCog extends ValueCog {
76
80
  name,
77
81
  value,
78
82
  defaultValue,
79
- required,
80
- disabled,
81
- readOnly,
83
+ required = false,
84
+ disabled = false,
85
+ readOnly = false,
82
86
  tabIndex,
83
87
  accessKey,
84
88
  placeholder,
@@ -0,0 +1,7 @@
1
+ export function DEFAULT_HANDLE_CHANGE () {
2
+ /* */
3
+ }
4
+
5
+ export function DEFAULT_HANDLE_CLICK () {
6
+ /* */
7
+ }
@@ -26,3 +26,5 @@ export default function TextContent ({ textContent }) {
26
26
  TextContent.propTypes = {
27
27
  textContent: PropTypes.string.isRequired
28
28
  }
29
+
30
+ TextContent.defaultProps = {}
@@ -35,3 +35,5 @@ export default class Description extends Component {
35
35
  Description.propTypes = {
36
36
  description: PropTypes.string
37
37
  }
38
+
39
+ Description.defaultProps = {}
@@ -0,0 +1,7 @@
1
+ declare module '@modernpoacher/cogs/components/error-message' {
2
+ import React from 'react'
3
+
4
+ export type ErrorMessageProps = CogsTypes.ErrorDefinitionType
5
+
6
+ export default class ErrorMessage extends React.Component<ErrorMessageProps> {}
7
+ }
@@ -39,3 +39,5 @@ export default class ErrorMessage extends Component {
39
39
  ErrorMessage.propTypes = {
40
40
  errorMessage: PropTypes.string
41
41
  }
42
+
43
+ ErrorMessage.defaultProps = {}
@@ -4,13 +4,10 @@
4
4
  import React, { Component } from 'react'
5
5
  import PropTypes from 'prop-types'
6
6
 
7
- function onChange () {
8
- /* */
9
- }
10
-
11
- function onClick () {
12
- /* */
13
- }
7
+ import {
8
+ DEFAULT_HANDLE_CHANGE,
9
+ DEFAULT_HANDLE_CLICK
10
+ } from '@modernpoacher/cogs/common'
14
11
 
15
12
  export default class Field extends Component {
16
13
  getClassName () {
@@ -33,9 +30,9 @@ export default class Field extends Component {
33
30
  render () {
34
31
  const {
35
32
  id,
36
- required,
37
- disabled,
38
- readOnly,
33
+ required = false,
34
+ disabled = false,
35
+ readOnly = false,
39
36
  tabIndex,
40
37
  accessKey,
41
38
  placeholder,
@@ -77,22 +74,24 @@ Field.defaultProps = {
77
74
  required: false,
78
75
  disabled: false,
79
76
  readOnly: false,
80
- onChange
77
+ onChange: DEFAULT_HANDLE_CHANGE
81
78
  }
82
79
 
83
80
  /**
84
81
  * ValueField component
85
82
  */
86
83
  export class ValueField extends Field {
87
- shouldComponentUpdate (props) {
84
+ shouldComponentUpdate (props, state) {
88
85
  return (
89
- super.shouldComponentUpdate(props) ||
86
+ super.shouldComponentUpdate(props, state) ||
90
87
  (props.value !== this.props.value)
91
88
  )
92
89
  }
93
90
 
94
91
  handleChange = ({ target: { value } }) => {
95
- const { onChange } = this.props
92
+ const {
93
+ onChange = DEFAULT_HANDLE_CHANGE
94
+ } = this.props
96
95
 
97
96
  onChange(value)
98
97
  }
@@ -112,9 +111,9 @@ ValueField.defaultProps = {
112
111
  * CheckField component
113
112
  */
114
113
  export class CheckField extends Field {
115
- shouldComponentUpdate (props) {
114
+ shouldComponentUpdate (props, state) {
116
115
  return (
117
- super.shouldComponentUpdate(props) ||
116
+ super.shouldComponentUpdate(props, state) ||
118
117
  (props.value !== this.props.value) ||
119
118
  (props.checked !== this.props.checked) ||
120
119
  (props.onClick !== this.props.onClick)
@@ -122,13 +121,17 @@ export class CheckField extends Field {
122
121
  }
123
122
 
124
123
  handleClick = ({ target: { value, checked } }) => {
125
- const { onClick } = this.props
124
+ const {
125
+ onClick = DEFAULT_HANDLE_CLICK
126
+ } = this.props
126
127
 
127
128
  onClick(value, checked)
128
129
  }
129
130
 
130
131
  handleChange = ({ target: { value, checked } }) => {
131
- const { onChange } = this.props
132
+ const {
133
+ onChange = DEFAULT_HANDLE_CHANGE
134
+ } = this.props
132
135
 
133
136
  onChange(value, checked)
134
137
  }
@@ -143,5 +146,5 @@ CheckField.propTypes = {
143
146
 
144
147
  CheckField.defaultProps = {
145
148
  ...Field.defaultProps,
146
- onClick
149
+ onClick: DEFAULT_HANDLE_CLICK
147
150
  }