shinkansen-cogs 2.0.9 → 2.1.0
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 +1 -1
- package/eslint.config.mjs +4 -2
- package/index.d.mts +3 -5
- package/jest.after-each.mjs +10 -0
- package/jest.before-each.mjs +1 -0
- package/jest.config.mjs +27 -0
- package/package.json +21 -16
- package/src/js/cogs/checkbox/field/index.jsx +3 -3
- package/src/js/cogs/checkbox/index.jsx +1 -23
- package/src/js/cogs/email/field/index.jsx +3 -3
- package/src/js/cogs/email/index.jsx +1 -1
- package/src/js/cogs/index.jsx +9 -6
- package/src/js/cogs/number/field/index.jsx +3 -3
- package/src/js/cogs/number/index.jsx +1 -1
- package/src/js/cogs/password/field/index.jsx +3 -3
- package/src/js/cogs/password/index.jsx +1 -1
- package/src/js/cogs/radio/field/index.jsx +3 -3
- package/src/js/cogs/radio/index.jsx +1 -17
- package/src/js/cogs/select/field/index.d.mts +5 -1
- package/src/js/cogs/select/field/index.jsx +3 -3
- package/src/js/cogs/select/index.jsx +8 -2
- package/src/js/cogs/text/field/index.jsx +3 -3
- package/src/js/cogs/text/index.jsx +1 -1
- package/src/js/cogs/textarea/field/index.d.mts +5 -1
- package/src/js/cogs/textarea/field/index.jsx +3 -3
- package/src/js/cogs/textarea/index.jsx +1 -1
- package/src/js/components/field/index.d.mts +1 -5
- package/src/js/components/field/index.jsx +3 -30
- package/src/js/super/cogs/index.jsx +6 -2
- package/src/js/super/components/description/index.jsx +3 -0
- package/src/js/super/components/error-message/index.jsx +24 -13
- package/src/js/super/components/field/index.d.mts +5 -0
- package/src/js/super/components/field/index.jsx +33 -1
- package/src/js/super/components/title/index.d.mts +2 -0
- package/src/js/super/components/title/index.jsx +21 -4
package/babel.config.cjs
CHANGED
package/eslint.config.mjs
CHANGED
|
@@ -80,7 +80,8 @@ export default [
|
|
|
80
80
|
ignores: [
|
|
81
81
|
'src',
|
|
82
82
|
'stories',
|
|
83
|
-
'test'
|
|
83
|
+
'test',
|
|
84
|
+
'jest.*.mjs'
|
|
84
85
|
],
|
|
85
86
|
languageOptions: {
|
|
86
87
|
globals: {
|
|
@@ -145,7 +146,8 @@ export default [
|
|
|
145
146
|
standard({
|
|
146
147
|
files: [
|
|
147
148
|
'src/**/__tests__/**/*.jsx',
|
|
148
|
-
'stories/**/__tests__/**/*.jsx'
|
|
149
|
+
'stories/**/__tests__/**/*.jsx',
|
|
150
|
+
'jest.*.mjs'
|
|
149
151
|
],
|
|
150
152
|
languageOptions: {
|
|
151
153
|
parser: babelParser,
|
package/index.d.mts
CHANGED
|
@@ -25,6 +25,7 @@ declare global {
|
|
|
25
25
|
id?: string
|
|
26
26
|
name: string
|
|
27
27
|
title?: string
|
|
28
|
+
value?: string
|
|
28
29
|
description?: string
|
|
29
30
|
errorMessage?: ErrorDefinitionType
|
|
30
31
|
required?: boolean
|
|
@@ -59,6 +60,7 @@ declare global {
|
|
|
59
60
|
export interface FieldProps extends React.PropsWithChildren {
|
|
60
61
|
id?: string
|
|
61
62
|
name: string
|
|
63
|
+
value?: string
|
|
62
64
|
required?: boolean
|
|
63
65
|
disabled?: boolean
|
|
64
66
|
readOnly?: boolean
|
|
@@ -103,12 +105,10 @@ declare global {
|
|
|
103
105
|
|
|
104
106
|
export namespace Field {
|
|
105
107
|
export interface ValueProps extends Super.Components.Field.FieldProps {
|
|
106
|
-
value?: string
|
|
107
108
|
defaultValue?: string
|
|
108
109
|
}
|
|
109
110
|
|
|
110
111
|
export interface CheckProps extends Super.Components.Field.FieldProps {
|
|
111
|
-
value?: string
|
|
112
112
|
checked?: boolean
|
|
113
113
|
defaultChecked?: boolean
|
|
114
114
|
onClick: OnEventType
|
|
@@ -186,12 +186,10 @@ declare global {
|
|
|
186
186
|
|
|
187
187
|
export namespace Cogs {
|
|
188
188
|
export interface ValueProps extends Super.Cogs.CogProps {
|
|
189
|
-
value?: string
|
|
190
189
|
defaultValue?: string
|
|
191
190
|
}
|
|
192
191
|
|
|
193
192
|
export interface CheckProps extends Super.Cogs.CogProps {
|
|
194
|
-
value?: string
|
|
195
193
|
checked?: boolean
|
|
196
194
|
defaultChecked?: boolean
|
|
197
195
|
onClick: OnEventType
|
|
@@ -222,9 +220,9 @@ declare global {
|
|
|
222
220
|
|
|
223
221
|
export namespace Select {
|
|
224
222
|
export interface SelectProps extends Omit<Omit<ValueProps, 'value'>, 'defaultValue'>, React.PropsWithChildren {
|
|
225
|
-
multiple?: boolean
|
|
226
223
|
value?: string | string[]
|
|
227
224
|
defaultValue?: string | string[]
|
|
225
|
+
multiple?: boolean
|
|
228
226
|
}
|
|
229
227
|
}
|
|
230
228
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
beforeEach(() => {})
|
package/jest.config.mjs
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
bail: true,
|
|
3
|
+
verbose: true,
|
|
4
|
+
rootDir: '.',
|
|
5
|
+
roots: [
|
|
6
|
+
'./src'
|
|
7
|
+
],
|
|
8
|
+
clearMocks: true,
|
|
9
|
+
collectCoverage: true,
|
|
10
|
+
coverageDirectory: './coverage',
|
|
11
|
+
coverageProvider: 'v8',
|
|
12
|
+
testRegex: '(/__tests__/.*|(\\.|/))(test|spec)\\.(mjs?|jsx?)$',
|
|
13
|
+
transform: {
|
|
14
|
+
'^.+\\.jsx$': 'babel-jest',
|
|
15
|
+
'^.+\\.mjs$': 'babel-jest'
|
|
16
|
+
},
|
|
17
|
+
transformIgnorePatterns: [
|
|
18
|
+
'/node_modules\\/(?!react-component-instance)\\/',
|
|
19
|
+
'/node_modules\\/(?!react-component-snapshot)\\/'
|
|
20
|
+
],
|
|
21
|
+
moduleFileExtensions: ['js', 'jsx', 'mjs'],
|
|
22
|
+
testEnvironment: 'jsdom',
|
|
23
|
+
setupFilesAfterEnv: [
|
|
24
|
+
'<rootDir>/jest.before-each.mjs',
|
|
25
|
+
'<rootDir>/jest.after-each.mjs'
|
|
26
|
+
]
|
|
27
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shinkansen-cogs",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Shinkansen Cogs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Shinkansen",
|
|
@@ -63,21 +63,24 @@
|
|
|
63
63
|
"@modernpoacher/design-system": "2.0.2",
|
|
64
64
|
"@sequencemedia/eslint-config-standard": "^0.2.43",
|
|
65
65
|
"@sequencemedia/eslint-config-typescript": "^0.1.62",
|
|
66
|
-
"@storybook/addon-actions": "^8.6.
|
|
67
|
-
"@storybook/addon-essentials": "^8.6.
|
|
68
|
-
"@storybook/addon-links": "^8.6.
|
|
66
|
+
"@storybook/addon-actions": "^8.6.7",
|
|
67
|
+
"@storybook/addon-essentials": "^8.6.7",
|
|
68
|
+
"@storybook/addon-links": "^8.6.7",
|
|
69
69
|
"@storybook/addon-webpack5-compiler-babel": "^3.0.5",
|
|
70
|
-
"@storybook/manager-api": "^8.6.
|
|
71
|
-
"@storybook/react": "^8.6.
|
|
72
|
-
"@storybook/react-webpack5": "^8.6.
|
|
73
|
-
"@storybook/theming": "^8.6.
|
|
70
|
+
"@storybook/manager-api": "^8.6.7",
|
|
71
|
+
"@storybook/react": "^8.6.7",
|
|
72
|
+
"@storybook/react-webpack5": "^8.6.7",
|
|
73
|
+
"@storybook/theming": "^8.6.7",
|
|
74
|
+
"@testing-library/jest-dom": "^6.6.3",
|
|
75
|
+
"@testing-library/react": "^16.2.0",
|
|
74
76
|
"@types/babel__register": "^7.17.3",
|
|
75
77
|
"@types/chai": "^5.2.0",
|
|
76
78
|
"@types/debug": "^4.1.12",
|
|
77
79
|
"@types/jest": "^29.5.14",
|
|
78
80
|
"@types/mocha": "^10.0.10",
|
|
79
|
-
"@types/
|
|
80
|
-
"@types/react
|
|
81
|
+
"@types/prop-types": "^15.7.14",
|
|
82
|
+
"@types/react": "^19.0.11",
|
|
83
|
+
"@types/react-dom": "^19.0.4",
|
|
81
84
|
"@typescript-eslint/eslint-plugin": "^8.26.1",
|
|
82
85
|
"@typescript-eslint/parser": "^8.26.1",
|
|
83
86
|
"autoprefixer": "^10.4.21",
|
|
@@ -86,10 +89,11 @@
|
|
|
86
89
|
"cross-env": "^7.0.3",
|
|
87
90
|
"eslint": "^9.22.0",
|
|
88
91
|
"eslint-plugin-react": "^7.37.4",
|
|
89
|
-
"eslint-plugin-storybook": "^0.11.
|
|
92
|
+
"eslint-plugin-storybook": "^0.11.6",
|
|
90
93
|
"globals": "^16.0.0",
|
|
91
94
|
"husky": "^9.1.7",
|
|
92
95
|
"jest": "^29.7.0",
|
|
96
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
93
97
|
"mini-css-extract-plugin": "^2.9.2",
|
|
94
98
|
"mocha": "^11.1.0",
|
|
95
99
|
"perfectionist": "^2.4.0",
|
|
@@ -101,13 +105,14 @@
|
|
|
101
105
|
"postcss-map": "^0.11.0",
|
|
102
106
|
"prettier": "^3.5.3",
|
|
103
107
|
"prop-types": "^15.8.1",
|
|
104
|
-
"react": "
|
|
105
|
-
"react-
|
|
106
|
-
"react-
|
|
108
|
+
"react": "^19.0.0",
|
|
109
|
+
"react-component-instance": "^0.0.6",
|
|
110
|
+
"react-component-snapshot": "^0.0.1",
|
|
111
|
+
"react-dom": "^19.0.0",
|
|
107
112
|
"remove-files-webpack-plugin": "^1.5.0",
|
|
108
|
-
"sass": "^1.
|
|
113
|
+
"sass": "^1.86.0",
|
|
109
114
|
"sass-loader": "^16.0.5",
|
|
110
|
-
"storybook": "^8.6.
|
|
115
|
+
"storybook": "^8.6.7",
|
|
111
116
|
"stylelint": "^16.16.0",
|
|
112
117
|
"stylelint-config-recommended-scss": "^14.1.0",
|
|
113
118
|
"stylelint-scss": "^6.11.1",
|
|
@@ -25,8 +25,8 @@ export default class CheckboxField extends CheckField {
|
|
|
25
25
|
|
|
26
26
|
render () {
|
|
27
27
|
const {
|
|
28
|
-
id,
|
|
29
28
|
name,
|
|
29
|
+
id,
|
|
30
30
|
value,
|
|
31
31
|
checked,
|
|
32
32
|
required = false,
|
|
@@ -42,8 +42,8 @@ export default class CheckboxField extends CheckField {
|
|
|
42
42
|
if (typeof checked === 'boolean') {
|
|
43
43
|
return (
|
|
44
44
|
<input
|
|
45
|
-
id={id}
|
|
46
45
|
name={name}
|
|
46
|
+
id={id}
|
|
47
47
|
value={toInputValue(value)}
|
|
48
48
|
checked={checked}
|
|
49
49
|
required={required}
|
|
@@ -66,8 +66,8 @@ export default class CheckboxField extends CheckField {
|
|
|
66
66
|
|
|
67
67
|
return (
|
|
68
68
|
<input
|
|
69
|
-
id={id}
|
|
70
69
|
name={name}
|
|
70
|
+
id={id}
|
|
71
71
|
value={toInputValue(value)}
|
|
72
72
|
defaultChecked={defaultChecked}
|
|
73
73
|
required={required}
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
* CheckboxCog component
|
|
9
9
|
*/
|
|
10
10
|
import React from 'react'
|
|
11
|
-
import PropTypes from 'prop-types'
|
|
12
11
|
import classnames from 'classnames'
|
|
13
12
|
|
|
14
13
|
import {
|
|
@@ -35,22 +34,6 @@ export default class CheckboxCog extends CheckCog {
|
|
|
35
34
|
return classnames(super.getClassName(), 'checkbox')
|
|
36
35
|
}
|
|
37
36
|
|
|
38
|
-
/**
|
|
39
|
-
* @param {CheckProps} props
|
|
40
|
-
* @returns {boolean}
|
|
41
|
-
*/
|
|
42
|
-
shouldComponentUpdate (props) {
|
|
43
|
-
const {
|
|
44
|
-
value,
|
|
45
|
-
...superProps
|
|
46
|
-
} = props
|
|
47
|
-
|
|
48
|
-
return (
|
|
49
|
-
super.shouldComponentUpdate(superProps) ||
|
|
50
|
-
(value !== this.props.value)
|
|
51
|
-
)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
37
|
/**
|
|
55
38
|
* @param {string} name
|
|
56
39
|
* @param {string | string[]} [value]
|
|
@@ -141,8 +124,8 @@ export default class CheckboxCog extends CheckCog {
|
|
|
141
124
|
|
|
142
125
|
return (
|
|
143
126
|
<Field
|
|
144
|
-
id={id}
|
|
145
127
|
name={name}
|
|
128
|
+
id={id}
|
|
146
129
|
value={value}
|
|
147
130
|
checked={checked}
|
|
148
131
|
defaultChecked={defaultChecked}
|
|
@@ -172,8 +155,3 @@ export default class CheckboxCog extends CheckCog {
|
|
|
172
155
|
)
|
|
173
156
|
}
|
|
174
157
|
}
|
|
175
|
-
|
|
176
|
-
CheckboxCog.propTypes = {
|
|
177
|
-
...CheckCog.propTypes,
|
|
178
|
-
value: PropTypes.string.isRequired
|
|
179
|
-
}
|
|
@@ -24,8 +24,8 @@ export default class EmailField extends ValueField {
|
|
|
24
24
|
|
|
25
25
|
render () {
|
|
26
26
|
const {
|
|
27
|
-
id,
|
|
28
27
|
name,
|
|
28
|
+
id,
|
|
29
29
|
defaultValue,
|
|
30
30
|
required = false,
|
|
31
31
|
disabled = false,
|
|
@@ -45,8 +45,8 @@ export default class EmailField extends ValueField {
|
|
|
45
45
|
|
|
46
46
|
return (
|
|
47
47
|
<input
|
|
48
|
-
id={id}
|
|
49
48
|
name={name}
|
|
49
|
+
id={id}
|
|
50
50
|
value={toInputValue(value)}
|
|
51
51
|
required={required}
|
|
52
52
|
disabled={disabled}
|
|
@@ -64,8 +64,8 @@ export default class EmailField extends ValueField {
|
|
|
64
64
|
|
|
65
65
|
return (
|
|
66
66
|
<input
|
|
67
|
-
id={id}
|
|
68
67
|
name={name}
|
|
68
|
+
id={id}
|
|
69
69
|
defaultValue={String(defaultValue)}
|
|
70
70
|
required={required}
|
|
71
71
|
disabled={disabled}
|
package/src/js/cogs/index.jsx
CHANGED
|
@@ -46,9 +46,9 @@ export class ValueCog extends Cog {
|
|
|
46
46
|
} = props
|
|
47
47
|
|
|
48
48
|
return (
|
|
49
|
-
super.shouldComponentUpdate(superProps) ||
|
|
50
49
|
(value !== this.props.value) ||
|
|
51
|
-
(defaultValue !== this.props.defaultValue)
|
|
50
|
+
(defaultValue !== this.props.defaultValue) ||
|
|
51
|
+
super.shouldComponentUpdate(superProps)
|
|
52
52
|
)
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -57,6 +57,7 @@ export class ValueCog extends Cog {
|
|
|
57
57
|
|
|
58
58
|
const {
|
|
59
59
|
name,
|
|
60
|
+
value,
|
|
60
61
|
required = false,
|
|
61
62
|
disabled = false,
|
|
62
63
|
readOnly = false,
|
|
@@ -69,8 +70,9 @@ export class ValueCog extends Cog {
|
|
|
69
70
|
|
|
70
71
|
return (
|
|
71
72
|
<ValueField
|
|
72
|
-
id={id}
|
|
73
73
|
name={name}
|
|
74
|
+
id={id}
|
|
75
|
+
value={value}
|
|
74
76
|
required={required}
|
|
75
77
|
disabled={disabled}
|
|
76
78
|
readOnly={readOnly}
|
|
@@ -86,7 +88,6 @@ export class ValueCog extends Cog {
|
|
|
86
88
|
|
|
87
89
|
ValueCog.propTypes = {
|
|
88
90
|
...Cog.propTypes,
|
|
89
|
-
value: PropTypes.string,
|
|
90
91
|
defaultValue: PropTypes.string
|
|
91
92
|
}
|
|
92
93
|
|
|
@@ -107,9 +108,9 @@ export class CheckCog extends Cog {
|
|
|
107
108
|
} = props
|
|
108
109
|
|
|
109
110
|
return (
|
|
110
|
-
super.shouldComponentUpdate(superProps) ||
|
|
111
111
|
(checked !== this.props.checked) ||
|
|
112
112
|
(defaultChecked !== this.props.defaultChecked) ||
|
|
113
|
+
super.shouldComponentUpdate(superProps) ||
|
|
113
114
|
(onClick !== this.props.onClick)
|
|
114
115
|
)
|
|
115
116
|
}
|
|
@@ -119,6 +120,7 @@ export class CheckCog extends Cog {
|
|
|
119
120
|
|
|
120
121
|
const {
|
|
121
122
|
name,
|
|
123
|
+
value,
|
|
122
124
|
required = false,
|
|
123
125
|
disabled = false,
|
|
124
126
|
readOnly = false,
|
|
@@ -132,8 +134,9 @@ export class CheckCog extends Cog {
|
|
|
132
134
|
|
|
133
135
|
return (
|
|
134
136
|
<CheckField
|
|
135
|
-
id={id}
|
|
136
137
|
name={name}
|
|
138
|
+
id={id}
|
|
139
|
+
value={value}
|
|
137
140
|
required={required}
|
|
138
141
|
disabled={disabled}
|
|
139
142
|
readOnly={readOnly}
|
|
@@ -25,8 +25,8 @@ export default class NumberField extends ValueField {
|
|
|
25
25
|
|
|
26
26
|
render () {
|
|
27
27
|
const {
|
|
28
|
-
id,
|
|
29
28
|
name,
|
|
29
|
+
id,
|
|
30
30
|
defaultValue,
|
|
31
31
|
required = false,
|
|
32
32
|
disabled = false,
|
|
@@ -46,8 +46,8 @@ export default class NumberField extends ValueField {
|
|
|
46
46
|
|
|
47
47
|
return (
|
|
48
48
|
<input
|
|
49
|
-
id={id}
|
|
50
49
|
name={name}
|
|
50
|
+
id={id}
|
|
51
51
|
value={toInputValue(value)}
|
|
52
52
|
required={required}
|
|
53
53
|
disabled={disabled}
|
|
@@ -65,8 +65,8 @@ export default class NumberField extends ValueField {
|
|
|
65
65
|
|
|
66
66
|
return (
|
|
67
67
|
<input
|
|
68
|
-
id={id}
|
|
69
68
|
name={name}
|
|
69
|
+
id={id}
|
|
70
70
|
defaultValue={String(defaultValue)}
|
|
71
71
|
required={required}
|
|
72
72
|
disabled={disabled}
|
|
@@ -24,8 +24,8 @@ export default class PasswordField extends ValueField {
|
|
|
24
24
|
|
|
25
25
|
render () {
|
|
26
26
|
const {
|
|
27
|
-
id,
|
|
28
27
|
name,
|
|
28
|
+
id,
|
|
29
29
|
defaultValue,
|
|
30
30
|
required = false,
|
|
31
31
|
disabled = false,
|
|
@@ -45,8 +45,8 @@ export default class PasswordField extends ValueField {
|
|
|
45
45
|
|
|
46
46
|
return (
|
|
47
47
|
<input
|
|
48
|
-
id={id}
|
|
49
48
|
name={name}
|
|
49
|
+
id={id}
|
|
50
50
|
value={toInputValue(value)}
|
|
51
51
|
required={required}
|
|
52
52
|
disabled={disabled}
|
|
@@ -64,8 +64,8 @@ export default class PasswordField extends ValueField {
|
|
|
64
64
|
|
|
65
65
|
return (
|
|
66
66
|
<input
|
|
67
|
-
id={id}
|
|
68
67
|
name={name}
|
|
68
|
+
id={id}
|
|
69
69
|
defaultValue={String(defaultValue)}
|
|
70
70
|
required={required}
|
|
71
71
|
disabled={disabled}
|
|
@@ -26,8 +26,8 @@ export default class RadioField extends CheckField {
|
|
|
26
26
|
render () {
|
|
27
27
|
const {
|
|
28
28
|
checked,
|
|
29
|
-
id,
|
|
30
29
|
name,
|
|
30
|
+
id,
|
|
31
31
|
value,
|
|
32
32
|
required = false,
|
|
33
33
|
disabled = false,
|
|
@@ -42,8 +42,8 @@ export default class RadioField extends CheckField {
|
|
|
42
42
|
if (typeof checked === 'boolean') {
|
|
43
43
|
return (
|
|
44
44
|
<input
|
|
45
|
-
id={id}
|
|
46
45
|
name={name}
|
|
46
|
+
id={id}
|
|
47
47
|
value={toInputValue(value)}
|
|
48
48
|
checked={checked}
|
|
49
49
|
required={required}
|
|
@@ -66,8 +66,8 @@ export default class RadioField extends CheckField {
|
|
|
66
66
|
|
|
67
67
|
return (
|
|
68
68
|
<input
|
|
69
|
-
id={id}
|
|
70
69
|
name={name}
|
|
70
|
+
id={id}
|
|
71
71
|
value={toInputValue(value)}
|
|
72
72
|
defaultChecked={defaultChecked}
|
|
73
73
|
required={required}
|
|
@@ -35,22 +35,6 @@ export default class Radio extends CheckCog {
|
|
|
35
35
|
return classnames(super.getClassName(), 'radio')
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
/**
|
|
39
|
-
* @param {CheckProps} props
|
|
40
|
-
* @returns {boolean}
|
|
41
|
-
*/
|
|
42
|
-
shouldComponentUpdate (props) {
|
|
43
|
-
const {
|
|
44
|
-
value,
|
|
45
|
-
...superProps
|
|
46
|
-
} = props
|
|
47
|
-
|
|
48
|
-
return (
|
|
49
|
-
super.shouldComponentUpdate(superProps) || // , state) //
|
|
50
|
-
(value !== this.props.value)
|
|
51
|
-
)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
38
|
/**
|
|
55
39
|
* @param {string} name
|
|
56
40
|
* @param {string | string[]} [value]
|
|
@@ -141,8 +125,8 @@ export default class Radio extends CheckCog {
|
|
|
141
125
|
|
|
142
126
|
return (
|
|
143
127
|
<Field
|
|
144
|
-
id={id}
|
|
145
128
|
name={name}
|
|
129
|
+
id={id}
|
|
146
130
|
value={value}
|
|
147
131
|
checked={checked}
|
|
148
132
|
defaultChecked={defaultChecked}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
declare module '#cogs/cogs/select/field' {
|
|
2
|
+
import type { ChangeEvent } from 'react'
|
|
3
|
+
|
|
2
4
|
import {
|
|
3
5
|
ValueField
|
|
4
6
|
} from '#cogs/components/field'
|
|
5
7
|
|
|
6
8
|
export type SelectProps = CogsTypes.Components.Field.Select.SelectProps
|
|
7
9
|
|
|
8
|
-
export default class SelectField<P extends SelectProps> extends ValueField<P> {
|
|
10
|
+
export default class SelectField<P extends SelectProps> extends ValueField<P> {
|
|
11
|
+
handleChange (event: ChangeEvent<HTMLSelectElement>): void
|
|
12
|
+
}
|
|
9
13
|
}
|
|
10
14
|
|
|
11
15
|
declare module 'shinkansen-cogs/cogs/select/field' {
|
|
@@ -106,8 +106,8 @@ export default class SelectField extends ValueField {
|
|
|
106
106
|
|
|
107
107
|
render () {
|
|
108
108
|
const {
|
|
109
|
-
id,
|
|
110
109
|
name,
|
|
110
|
+
id,
|
|
111
111
|
defaultValue,
|
|
112
112
|
required = false,
|
|
113
113
|
disabled = false,
|
|
@@ -128,8 +128,8 @@ export default class SelectField extends ValueField {
|
|
|
128
128
|
|
|
129
129
|
return (
|
|
130
130
|
<select
|
|
131
|
-
id={id}
|
|
132
131
|
name={name}
|
|
132
|
+
id={id}
|
|
133
133
|
value={(
|
|
134
134
|
multiple
|
|
135
135
|
? Array.isArray(value)
|
|
@@ -153,8 +153,8 @@ export default class SelectField extends ValueField {
|
|
|
153
153
|
|
|
154
154
|
return (
|
|
155
155
|
<select
|
|
156
|
-
id={id}
|
|
157
156
|
name={name}
|
|
157
|
+
id={id}
|
|
158
158
|
defaultValue={(
|
|
159
159
|
multiple
|
|
160
160
|
? Array.isArray(defaultValue)
|
|
@@ -49,9 +49,15 @@ export default class SelectCog extends ValueCog {
|
|
|
49
49
|
} = props
|
|
50
50
|
|
|
51
51
|
return (
|
|
52
|
-
|
|
52
|
+
/**
|
|
53
|
+
* `value` may be `string` or `string[]`
|
|
54
|
+
*/
|
|
53
55
|
(value !== this.props.value) ||
|
|
56
|
+
/**
|
|
57
|
+
* `defaultValue` may be `string` or `string[]`
|
|
58
|
+
*/
|
|
54
59
|
(defaultValue !== this.props.defaultValue) ||
|
|
60
|
+
super.shouldComponentUpdate(superProps) ||
|
|
55
61
|
(multiple !== this.props.multiple) ||
|
|
56
62
|
(children !== this.props.children)
|
|
57
63
|
)
|
|
@@ -134,8 +140,8 @@ export default class SelectCog extends ValueCog {
|
|
|
134
140
|
|
|
135
141
|
return (
|
|
136
142
|
<Field
|
|
137
|
-
id={id}
|
|
138
143
|
name={name}
|
|
144
|
+
id={id}
|
|
139
145
|
value={value}
|
|
140
146
|
defaultValue={defaultValue}
|
|
141
147
|
required={required}
|
|
@@ -24,8 +24,8 @@ export default class TextField extends ValueField {
|
|
|
24
24
|
|
|
25
25
|
render () {
|
|
26
26
|
const {
|
|
27
|
-
id,
|
|
28
27
|
name,
|
|
28
|
+
id,
|
|
29
29
|
defaultValue,
|
|
30
30
|
required = false,
|
|
31
31
|
disabled = false,
|
|
@@ -45,8 +45,8 @@ export default class TextField extends ValueField {
|
|
|
45
45
|
|
|
46
46
|
return (
|
|
47
47
|
<input
|
|
48
|
-
id={id}
|
|
49
48
|
name={name}
|
|
49
|
+
id={id}
|
|
50
50
|
value={toInputValue(value)}
|
|
51
51
|
required={required}
|
|
52
52
|
disabled={disabled}
|
|
@@ -64,8 +64,8 @@ export default class TextField extends ValueField {
|
|
|
64
64
|
|
|
65
65
|
return (
|
|
66
66
|
<input
|
|
67
|
-
id={id}
|
|
68
67
|
name={name}
|
|
68
|
+
id={id}
|
|
69
69
|
defaultValue={String(defaultValue)}
|
|
70
70
|
required={required}
|
|
71
71
|
disabled={disabled}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
declare module '#cogs/cogs/textarea/field' {
|
|
2
|
+
import type { ChangeEvent } from 'react'
|
|
3
|
+
|
|
2
4
|
import {
|
|
3
5
|
ValueField
|
|
4
6
|
} from '#cogs/components/field'
|
|
5
7
|
|
|
6
8
|
export type TextareaProps = CogsTypes.Components.Field.Textarea.TextareaProps
|
|
7
9
|
|
|
8
|
-
export default class TextareaField<P extends TextareaProps> extends ValueField<P> {
|
|
10
|
+
export default class TextareaField<P extends TextareaProps> extends ValueField<P> {
|
|
11
|
+
handleChange (event: ChangeEvent<HTMLTextAreaElement>): void
|
|
12
|
+
}
|
|
9
13
|
}
|
|
10
14
|
|
|
11
15
|
declare module 'shinkansen-cogs/cogs/textarea/field' {
|
|
@@ -24,8 +24,8 @@ export default class TextareaField extends ValueField {
|
|
|
24
24
|
|
|
25
25
|
render () {
|
|
26
26
|
const {
|
|
27
|
-
id,
|
|
28
27
|
name,
|
|
28
|
+
id,
|
|
29
29
|
defaultValue,
|
|
30
30
|
required = false,
|
|
31
31
|
disabled = false,
|
|
@@ -45,8 +45,8 @@ export default class TextareaField extends ValueField {
|
|
|
45
45
|
|
|
46
46
|
return (
|
|
47
47
|
<textarea
|
|
48
|
-
id={id}
|
|
49
48
|
name={name}
|
|
49
|
+
id={id}
|
|
50
50
|
value={toInputValue(value)}
|
|
51
51
|
required={required}
|
|
52
52
|
disabled={disabled}
|
|
@@ -63,8 +63,8 @@ export default class TextareaField extends ValueField {
|
|
|
63
63
|
|
|
64
64
|
return (
|
|
65
65
|
<textarea
|
|
66
|
-
id={id}
|
|
67
66
|
name={name}
|
|
67
|
+
id={id}
|
|
68
68
|
defaultValue={String(defaultValue)}
|
|
69
69
|
required={required}
|
|
70
70
|
disabled={disabled}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare module '#cogs/components/field' {
|
|
2
|
-
import type {
|
|
2
|
+
import type { MouseEvent } from 'react'
|
|
3
3
|
|
|
4
4
|
import Field from '#cogs/super/components/field'
|
|
5
5
|
|
|
@@ -10,15 +10,11 @@ declare module '#cogs/components/field' {
|
|
|
10
10
|
|
|
11
11
|
export class ValueField<P extends ValueProps> extends Field<P> {
|
|
12
12
|
shouldComponentUpdate (props: ValueProps): boolean
|
|
13
|
-
|
|
14
|
-
handleChange (event: ChangeEvent<HTMLTextAreaElement> | ChangeEvent<HTMLInputElement>): void
|
|
15
13
|
}
|
|
16
14
|
|
|
17
15
|
export class CheckField<P extends CheckProps> extends Field<P> {
|
|
18
16
|
shouldComponentUpdate (props: CheckProps): boolean
|
|
19
17
|
|
|
20
|
-
handleChange (event: ChangeEvent<HTMLInputElement>): void
|
|
21
|
-
|
|
22
18
|
handleClick (event: MouseEvent<HTMLInputElement>): void
|
|
23
19
|
}
|
|
24
20
|
}
|
|
@@ -32,35 +32,10 @@ export function toInputValue (value) {
|
|
|
32
32
|
*
|
|
33
33
|
* @extends {Field<FieldProps & ValueProps>}
|
|
34
34
|
*/
|
|
35
|
-
export class ValueField extends Field {
|
|
36
|
-
/**
|
|
37
|
-
* @param {ValueProps} props
|
|
38
|
-
* @returns {boolean}
|
|
39
|
-
*/
|
|
40
|
-
shouldComponentUpdate (props) {
|
|
41
|
-
return (
|
|
42
|
-
super.shouldComponentUpdate(props) || // }, state) ||
|
|
43
|
-
(props.value !== this.props.value)
|
|
44
|
-
)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* @param {{ target: { value?: string } }} event
|
|
49
|
-
* @returns {void}
|
|
50
|
-
*/
|
|
51
|
-
handleChange = ({ target: { value } }) => {
|
|
52
|
-
const {
|
|
53
|
-
onChange = DEFAULT_HANDLE_EVENT,
|
|
54
|
-
name
|
|
55
|
-
} = this.props
|
|
56
|
-
|
|
57
|
-
onChange(name, value)
|
|
58
|
-
}
|
|
59
|
-
}
|
|
35
|
+
export class ValueField extends Field {}
|
|
60
36
|
|
|
61
37
|
ValueField.propTypes = {
|
|
62
38
|
...Field.propTypes,
|
|
63
|
-
value: PropTypes.string,
|
|
64
39
|
defaultValue: PropTypes.string
|
|
65
40
|
}
|
|
66
41
|
|
|
@@ -76,18 +51,16 @@ export class CheckField extends Field {
|
|
|
76
51
|
*/
|
|
77
52
|
shouldComponentUpdate (props) {
|
|
78
53
|
const {
|
|
79
|
-
value,
|
|
80
|
-
defaultChecked,
|
|
81
54
|
checked,
|
|
55
|
+
defaultChecked,
|
|
82
56
|
onClick,
|
|
83
57
|
...superProps
|
|
84
58
|
} = props
|
|
85
59
|
|
|
86
60
|
return (
|
|
87
|
-
super.shouldComponentUpdate(superProps) ||
|
|
88
|
-
(value !== this.props.value) ||
|
|
89
61
|
(checked !== this.props.checked) ||
|
|
90
62
|
(defaultChecked !== this.props.defaultChecked) ||
|
|
63
|
+
super.shouldComponentUpdate(superProps) ||
|
|
91
64
|
(onClick !== this.props.onClick)
|
|
92
65
|
)
|
|
93
66
|
}
|
|
@@ -52,6 +52,7 @@ export default class Cog extends Component {
|
|
|
52
52
|
(props.name !== this.props.name) ||
|
|
53
53
|
(props.id !== this.props.id) ||
|
|
54
54
|
(props.title !== this.props.title) ||
|
|
55
|
+
(props.value !== this.props.value) ||
|
|
55
56
|
(props.description !== this.props.description) ||
|
|
56
57
|
(props.errorMessage !== this.props.errorMessage) ||
|
|
57
58
|
(props.required !== this.props.required) ||
|
|
@@ -114,6 +115,7 @@ export default class Cog extends Component {
|
|
|
114
115
|
|
|
115
116
|
const {
|
|
116
117
|
name,
|
|
118
|
+
value,
|
|
117
119
|
required = false,
|
|
118
120
|
disabled = false,
|
|
119
121
|
readOnly = false,
|
|
@@ -126,8 +128,9 @@ export default class Cog extends Component {
|
|
|
126
128
|
|
|
127
129
|
return (
|
|
128
130
|
<Field
|
|
129
|
-
id={id}
|
|
130
131
|
name={name}
|
|
132
|
+
id={id}
|
|
133
|
+
value={value}
|
|
131
134
|
required={required}
|
|
132
135
|
disabled={disabled}
|
|
133
136
|
readOnly={readOnly}
|
|
@@ -155,9 +158,10 @@ export default class Cog extends Component {
|
|
|
155
158
|
}
|
|
156
159
|
|
|
157
160
|
Cog.propTypes = {
|
|
158
|
-
id: PropTypes.string,
|
|
159
161
|
name: PropTypes.string.isRequired,
|
|
162
|
+
id: PropTypes.string,
|
|
160
163
|
title: PropTypes.string,
|
|
164
|
+
value: PropTypes.string,
|
|
161
165
|
description: PropTypes.string,
|
|
162
166
|
errorMessage: PropTypes.shape({
|
|
163
167
|
type: PropTypes.string.isRequired,
|
|
@@ -10,6 +10,9 @@ import PropTypes from 'prop-types'
|
|
|
10
10
|
|
|
11
11
|
import TextContent from '#cogs/components/common/text-content'
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* @extends {Component<DescriptionProps>}
|
|
15
|
+
*/
|
|
13
16
|
export default class Description extends Component {
|
|
14
17
|
getClassName () {
|
|
15
18
|
return 'description'
|
|
@@ -15,6 +15,9 @@ import transform from '#cogs/transformers/error-message'
|
|
|
15
15
|
|
|
16
16
|
import TextContent from '#cogs/components/common/text-content'
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* @extends {Component<ErrorMessageProps, ErrorMessageState>}
|
|
20
|
+
*/
|
|
18
21
|
export default class ErrorMessage extends Component {
|
|
19
22
|
/**
|
|
20
23
|
* @type {ErrorMessageState}
|
|
@@ -26,11 +29,15 @@ export default class ErrorMessage extends Component {
|
|
|
26
29
|
errorMessage
|
|
27
30
|
} = this.props
|
|
28
31
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
if (errorMessage) {
|
|
33
|
+
const {
|
|
34
|
+
text
|
|
35
|
+
} = transform(errorMessage)
|
|
32
36
|
|
|
33
|
-
|
|
37
|
+
return !!text
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return false
|
|
34
41
|
}
|
|
35
42
|
|
|
36
43
|
getTextContent () {
|
|
@@ -38,11 +45,15 @@ export default class ErrorMessage extends Component {
|
|
|
38
45
|
errorMessage
|
|
39
46
|
} = this.props
|
|
40
47
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
48
|
+
if (errorMessage) {
|
|
49
|
+
const {
|
|
50
|
+
text
|
|
51
|
+
} = transform(errorMessage)
|
|
52
|
+
|
|
53
|
+
return text
|
|
54
|
+
}
|
|
44
55
|
|
|
45
|
-
return
|
|
56
|
+
return ''
|
|
46
57
|
}
|
|
47
58
|
|
|
48
59
|
getClassName () {
|
|
@@ -56,9 +67,9 @@ export default class ErrorMessage extends Component {
|
|
|
56
67
|
* @param {ErrorMessageState} state Current state
|
|
57
68
|
* @returns {ErrorMessageState}
|
|
58
69
|
*/
|
|
59
|
-
static getDerivedStateFromProps ({ errorMessage }, { errorMessage: E }) {
|
|
70
|
+
static getDerivedStateFromProps ({ errorMessage: e }, { errorMessage: E }) {
|
|
60
71
|
return {
|
|
61
|
-
errorMessage: equal(
|
|
72
|
+
errorMessage: (e === E || equal(e, E)) ? E : e
|
|
62
73
|
}
|
|
63
74
|
}
|
|
64
75
|
|
|
@@ -72,13 +83,13 @@ export default class ErrorMessage extends Component {
|
|
|
72
83
|
shouldComponentUpdate (props, state) {
|
|
73
84
|
const {
|
|
74
85
|
errorMessage: e
|
|
75
|
-
} = state
|
|
86
|
+
} = this.state
|
|
76
87
|
|
|
77
88
|
const {
|
|
78
89
|
errorMessage: E
|
|
79
|
-
} =
|
|
90
|
+
} = state
|
|
80
91
|
|
|
81
|
-
return !equal(
|
|
92
|
+
return !(e === E || equal(e, E))
|
|
82
93
|
}
|
|
83
94
|
|
|
84
95
|
renderTextContent () {
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
declare module '#cogs/super/components/field' {
|
|
2
2
|
import React from 'react'
|
|
3
|
+
import type {
|
|
4
|
+
ChangeEvent
|
|
5
|
+
} from 'react'
|
|
3
6
|
|
|
4
7
|
export type FieldProps = CogsTypes.Super.Components.Field.FieldProps
|
|
5
8
|
|
|
@@ -9,6 +12,8 @@ declare module '#cogs/super/components/field' {
|
|
|
9
12
|
getClassName (): string
|
|
10
13
|
|
|
11
14
|
shouldComponentUpdate (props: FieldProps): boolean
|
|
15
|
+
|
|
16
|
+
handleChange (event: ChangeEvent<HTMLInputElement> | ChangeEvent<HTMLTextAreaElement> | ChangeEvent<HTMLSelectElement>): void
|
|
12
17
|
}
|
|
13
18
|
}
|
|
14
19
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* @typedef {CogsTypes.OnEventType} OnEventType
|
|
2
3
|
* @typedef {CogsTypes.Super.Components.Field.FieldProps} FieldProps
|
|
3
4
|
*/
|
|
4
5
|
|
|
@@ -8,18 +9,43 @@
|
|
|
8
9
|
import React, { Component } from 'react'
|
|
9
10
|
import PropTypes from 'prop-types'
|
|
10
11
|
|
|
12
|
+
/**
|
|
13
|
+
* @type {OnEventType}
|
|
14
|
+
*/
|
|
15
|
+
function DEFAULT_HANDLE_EVENT () {
|
|
16
|
+
//
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @extends {Component<FieldProps>}
|
|
21
|
+
*/
|
|
11
22
|
export default class Field extends Component {
|
|
12
23
|
getClassName () {
|
|
13
24
|
return 'input'
|
|
14
25
|
}
|
|
15
26
|
|
|
27
|
+
/**
|
|
28
|
+
* @param {{ target: { value?: string } }} event
|
|
29
|
+
* @returns {void}
|
|
30
|
+
*/
|
|
31
|
+
handleChange = ({ target: { value } }) => {
|
|
32
|
+
const {
|
|
33
|
+
onChange = DEFAULT_HANDLE_EVENT,
|
|
34
|
+
name
|
|
35
|
+
} = this.props
|
|
36
|
+
|
|
37
|
+
onChange(name, value)
|
|
38
|
+
}
|
|
39
|
+
|
|
16
40
|
/**
|
|
17
41
|
* @param {FieldProps} props
|
|
18
42
|
* @returns {boolean}
|
|
19
43
|
*/
|
|
20
44
|
shouldComponentUpdate (props) {
|
|
21
45
|
return (
|
|
46
|
+
(props.name !== this.props.name) ||
|
|
22
47
|
(props.id !== this.props.id) ||
|
|
48
|
+
(props.value !== this.props.value) ||
|
|
23
49
|
(props.required !== this.props.required) ||
|
|
24
50
|
(props.disabled !== this.props.disabled) ||
|
|
25
51
|
(props.readOnly !== this.props.readOnly) ||
|
|
@@ -32,7 +58,9 @@ export default class Field extends Component {
|
|
|
32
58
|
|
|
33
59
|
render () {
|
|
34
60
|
const {
|
|
61
|
+
name,
|
|
35
62
|
id,
|
|
63
|
+
value,
|
|
36
64
|
required = false,
|
|
37
65
|
disabled = false,
|
|
38
66
|
readOnly = false,
|
|
@@ -44,13 +72,16 @@ export default class Field extends Component {
|
|
|
44
72
|
|
|
45
73
|
return (
|
|
46
74
|
<input
|
|
75
|
+
name={name}
|
|
47
76
|
id={id}
|
|
77
|
+
value={value}
|
|
48
78
|
required={required}
|
|
49
79
|
disabled={disabled}
|
|
50
80
|
readOnly={readOnly}
|
|
51
81
|
tabIndex={tabIndex}
|
|
52
82
|
accessKey={accessKey}
|
|
53
83
|
placeholder={placeholder}
|
|
84
|
+
onChange={this.handleChange}
|
|
54
85
|
className={this.getClassName()}
|
|
55
86
|
ref={fieldRef}
|
|
56
87
|
/>
|
|
@@ -59,8 +90,9 @@ export default class Field extends Component {
|
|
|
59
90
|
}
|
|
60
91
|
|
|
61
92
|
Field.propTypes = {
|
|
62
|
-
id: PropTypes.string,
|
|
63
93
|
name: PropTypes.string.isRequired,
|
|
94
|
+
id: PropTypes.string,
|
|
95
|
+
value: PropTypes.string,
|
|
64
96
|
required: PropTypes.bool,
|
|
65
97
|
disabled: PropTypes.bool,
|
|
66
98
|
readOnly: PropTypes.bool,
|
|
@@ -16,6 +16,8 @@ declare module '#cogs/super/components/title' {
|
|
|
16
16
|
|
|
17
17
|
shouldComponentUpdate (props: TitleProps): boolean
|
|
18
18
|
|
|
19
|
+
renderTextContent (textContent: string) : React.JSX.Element
|
|
20
|
+
|
|
19
21
|
renderIsRequired (): React.JSX.Element | null
|
|
20
22
|
|
|
21
23
|
renderIsDisabled (): React.JSX.Element | null
|
|
@@ -13,6 +13,9 @@ import Required from '#cogs/components/common/required'
|
|
|
13
13
|
import Disabled from '#cogs/components/common/disabled'
|
|
14
14
|
import ReadOnly from '#cogs/components/common/readonly'
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* @extends {Component<TitleProps>}
|
|
18
|
+
*/
|
|
16
19
|
export default class Title extends Component {
|
|
17
20
|
isRequired () {
|
|
18
21
|
const {
|
|
@@ -57,6 +60,18 @@ export default class Title extends Component {
|
|
|
57
60
|
)
|
|
58
61
|
}
|
|
59
62
|
|
|
63
|
+
/**
|
|
64
|
+
* @param {string} textContent
|
|
65
|
+
* @returns {React.JSX.Element}
|
|
66
|
+
*/
|
|
67
|
+
renderTextContent (textContent) {
|
|
68
|
+
return (
|
|
69
|
+
<TextContent
|
|
70
|
+
textContent={textContent}
|
|
71
|
+
/>
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
|
|
60
75
|
renderIsRequired () {
|
|
61
76
|
if (this.isRequired()) {
|
|
62
77
|
return (
|
|
@@ -89,15 +104,17 @@ export default class Title extends Component {
|
|
|
89
104
|
|
|
90
105
|
render () {
|
|
91
106
|
const {
|
|
107
|
+
id,
|
|
92
108
|
title
|
|
93
109
|
} = this.props
|
|
94
110
|
|
|
95
|
-
if (title) {
|
|
96
|
-
const { id } = this.props
|
|
97
|
-
|
|
111
|
+
if (id && title) {
|
|
98
112
|
return (
|
|
99
113
|
<label htmlFor={id} className={this.getClassName()}>
|
|
100
|
-
|
|
114
|
+
{this.renderTextContent(title)}
|
|
115
|
+
{this.renderIsRequired()}
|
|
116
|
+
{this.renderIsDisabled()}
|
|
117
|
+
{this.renderIsReadOnly()}
|
|
101
118
|
</label>
|
|
102
119
|
)
|
|
103
120
|
}
|