shinkansen-cogs 1.5.24
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/.husky/pre-commit +4 -0
- package/README.md +11 -0
- package/babel.config.js +72 -0
- package/gulp.sh +42 -0
- package/index.js +7 -0
- package/lib/cogs/checkbox/index.js +1 -0
- package/lib/cogs/email/index.js +1 -0
- package/lib/cogs/index.js +1 -0
- package/lib/cogs/number/index.js +1 -0
- package/lib/cogs/password/index.js +1 -0
- package/lib/cogs/radio/index.js +1 -0
- package/lib/cogs/select/index.js +1 -0
- package/lib/cogs/text/index.js +1 -0
- package/lib/cogs/textarea/index.js +1 -0
- package/lib/components/common/disabled/index.js +1 -0
- package/lib/components/common/readonly/index.js +1 -0
- package/lib/components/common/required/index.js +1 -0
- package/lib/components/common/text-content/index.js +1 -0
- package/lib/components/description/checkbox/index.js +1 -0
- package/lib/components/description/email/index.js +1 -0
- package/lib/components/description/index.js +1 -0
- package/lib/components/description/number/index.js +1 -0
- package/lib/components/description/password/index.js +1 -0
- package/lib/components/description/radio/index.js +1 -0
- package/lib/components/description/select/index.js +1 -0
- package/lib/components/description/text/index.js +1 -0
- package/lib/components/description/textarea/index.js +1 -0
- package/lib/components/error-message/checkbox/index.js +1 -0
- package/lib/components/error-message/email/index.js +1 -0
- package/lib/components/error-message/index.js +1 -0
- package/lib/components/error-message/number/index.js +1 -0
- package/lib/components/error-message/password/index.js +1 -0
- package/lib/components/error-message/radio/index.js +1 -0
- package/lib/components/error-message/select/index.js +1 -0
- package/lib/components/error-message/text/index.js +1 -0
- package/lib/components/error-message/textarea/index.js +1 -0
- package/lib/components/field/checkbox/index.js +1 -0
- package/lib/components/field/email/index.js +1 -0
- package/lib/components/field/index.js +1 -0
- package/lib/components/field/number/index.js +1 -0
- package/lib/components/field/password/index.js +1 -0
- package/lib/components/field/radio/index.js +1 -0
- package/lib/components/field/select/index.js +1 -0
- package/lib/components/field/text/index.js +1 -0
- package/lib/components/field/textarea/index.js +1 -0
- package/lib/components/title/checkbox/index.js +1 -0
- package/lib/components/title/email/index.js +1 -0
- package/lib/components/title/index.js +1 -0
- package/lib/components/title/number/index.js +1 -0
- package/lib/components/title/password/index.js +1 -0
- package/lib/components/title/radio/index.js +1 -0
- package/lib/components/title/select/index.js +1 -0
- package/lib/components/title/text/index.js +1 -0
- package/lib/components/title/textarea/index.js +1 -0
- package/lib/index.js +1 -0
- package/lib/transformers/error-message/index.js +1 -0
- package/package.json +107 -0
- package/src/cogs/checkbox/index.js +138 -0
- package/src/cogs/email/index.js +115 -0
- package/src/cogs/index.js +225 -0
- package/src/cogs/number/index.js +124 -0
- package/src/cogs/password/index.js +115 -0
- package/src/cogs/radio/index.js +149 -0
- package/src/cogs/select/index.js +117 -0
- package/src/cogs/text/index.js +115 -0
- package/src/cogs/textarea/index.js +115 -0
- package/src/components/common/disabled/index.js +9 -0
- package/src/components/common/readonly/index.js +9 -0
- package/src/components/common/required/index.js +9 -0
- package/src/components/common/text-content/index.js +14 -0
- package/src/components/description/checkbox/index.js +19 -0
- package/src/components/description/email/index.js +19 -0
- package/src/components/description/index.js +61 -0
- package/src/components/description/number/index.js +19 -0
- package/src/components/description/password/index.js +19 -0
- package/src/components/description/radio/index.js +19 -0
- package/src/components/description/select/index.js +19 -0
- package/src/components/description/text/index.js +19 -0
- package/src/components/description/textarea/index.js +19 -0
- package/src/components/error-message/checkbox/index.js +19 -0
- package/src/components/error-message/email/index.js +19 -0
- package/src/components/error-message/index.js +103 -0
- package/src/components/error-message/number/index.js +19 -0
- package/src/components/error-message/password/index.js +19 -0
- package/src/components/error-message/radio/index.js +19 -0
- package/src/components/error-message/select/index.js +19 -0
- package/src/components/error-message/text/index.js +19 -0
- package/src/components/error-message/textarea/index.js +19 -0
- package/src/components/field/checkbox/index.js +55 -0
- package/src/components/field/email/index.js +56 -0
- package/src/components/field/index.js +165 -0
- package/src/components/field/number/index.js +65 -0
- package/src/components/field/password/index.js +56 -0
- package/src/components/field/radio/index.js +72 -0
- package/src/components/field/select/index.js +62 -0
- package/src/components/field/text/index.js +56 -0
- package/src/components/field/textarea/index.js +55 -0
- package/src/components/title/checkbox/index.js +19 -0
- package/src/components/title/email/index.js +19 -0
- package/src/components/title/index.js +134 -0
- package/src/components/title/number/index.js +19 -0
- package/src/components/title/password/index.js +19 -0
- package/src/components/title/radio/index.js +19 -0
- package/src/components/title/select/index.js +19 -0
- package/src/components/title/text/index.js +19 -0
- package/src/components/title/textarea/index.js +19 -0
- package/src/index.js +28 -0
- package/src/transformers/error-message/index.js +234 -0
package/package.json
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "shinkansen-cogs",
|
|
3
|
+
"version": "1.5.24",
|
|
4
|
+
"description": "Shinkansen Cogs",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"Shinkansen",
|
|
7
|
+
"Cogs",
|
|
8
|
+
"Zashiki Karakuri",
|
|
9
|
+
"Zashiki",
|
|
10
|
+
"Karakuri",
|
|
11
|
+
"React"
|
|
12
|
+
],
|
|
13
|
+
"main": "./index.js",
|
|
14
|
+
"author": "Jonathan Perry for Modern Poacher Limited <modernpoacher@modernpoacher.com>",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=12.19.0"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git@github.com/modernpoacher/shinkansen-cogs.git"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"prepublishOnly": "cross-env NODE_ENV=production npm run build",
|
|
25
|
+
"prebuild": "npm run clean",
|
|
26
|
+
"build": "cross-env DEBUG=shinkansen-cogs npm run babel -- --ignore \"**/__tests__/**\" && npm run gulp",
|
|
27
|
+
"build:watch": "npm run gulp -- build:watch",
|
|
28
|
+
"watch": "cross-env DEBUG=shinkansen-cogs concurrently -r \"npm run babel:watch\" \"npm run build:watch\"",
|
|
29
|
+
"clean": "rimraf lib",
|
|
30
|
+
"transform": "npm run gulp -- transform",
|
|
31
|
+
"transform:watch": "npm run gulp -- transform:watch",
|
|
32
|
+
"babel": "babel src -d lib",
|
|
33
|
+
"babel:watch": "npm run babel -- -w",
|
|
34
|
+
"gulp": "bash gulp.sh --color",
|
|
35
|
+
"lint": "eslint . .storybook",
|
|
36
|
+
"lint:fix": "npm run lint -- --fix",
|
|
37
|
+
"test": "cross-env NODE_ENV=test jest --collect-coverage false --verbose --run-in-band",
|
|
38
|
+
"storybook": "npm run build && npm run transform && start-storybook -p 6006",
|
|
39
|
+
"pre-commit": "npm run lint && npm test && npm run build && npm run transform && git add lib .storybook"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"classnames": "^2.3.1",
|
|
43
|
+
"debug": "^4.3.2",
|
|
44
|
+
"immutable": "3.8.2"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@babel/cli": "^7.15.4",
|
|
48
|
+
"@babel/core": "^7.15.5",
|
|
49
|
+
"@babel/eslint-parser": "^7.15.4",
|
|
50
|
+
"@babel/plugin-proposal-class-properties": "^7.14.5",
|
|
51
|
+
"@babel/plugin-proposal-export-default-from": "^7.14.5",
|
|
52
|
+
"@babel/plugin-proposal-export-namespace-from": "^7.14.5",
|
|
53
|
+
"@babel/plugin-transform-runtime": "^7.15.0",
|
|
54
|
+
"@babel/preset-env": "^7.15.6",
|
|
55
|
+
"@babel/preset-react": "^7.14.5",
|
|
56
|
+
"@babel/register": "^7.15.3",
|
|
57
|
+
"@modernpoacher/design-system": "0.0.383",
|
|
58
|
+
"@storybook/addon-actions": "^6.3.8",
|
|
59
|
+
"@storybook/addon-essentials": "^6.3.8",
|
|
60
|
+
"@storybook/addon-links": "^6.3.8",
|
|
61
|
+
"@storybook/react": "^6.3.8",
|
|
62
|
+
"autoprefixer": "^10.3.4",
|
|
63
|
+
"babel-jest": "^27.2.0",
|
|
64
|
+
"babel-loader": "^8.2.2",
|
|
65
|
+
"babel-plugin-module-resolver": "^4.1.0",
|
|
66
|
+
"concurrently": "^6.2.1",
|
|
67
|
+
"core-js": "^3.17.3",
|
|
68
|
+
"cross-env": "^7.0.3",
|
|
69
|
+
"cssnano": "^5.0.8",
|
|
70
|
+
"dart-sass": "^1.25.0",
|
|
71
|
+
"del": "^6.0.0",
|
|
72
|
+
"enzyme": "^3.11.0",
|
|
73
|
+
"enzyme-adapter-react-16": "^1.15.6",
|
|
74
|
+
"eslint": "^7.32.0",
|
|
75
|
+
"eslint-config-standard": "^16.0.3",
|
|
76
|
+
"eslint-import-resolver-babel-module": "^5.3.1",
|
|
77
|
+
"eslint-plugin-import": "^2.24.2",
|
|
78
|
+
"eslint-plugin-node": "^11.1.0",
|
|
79
|
+
"eslint-plugin-promise": "^5.1.0",
|
|
80
|
+
"eslint-plugin-react": "^7.25.2",
|
|
81
|
+
"glob-all": "^3.2.1",
|
|
82
|
+
"gulp": "^4.0.2",
|
|
83
|
+
"gulp-clean-css": "^4.3.0",
|
|
84
|
+
"gulp-css-purge": "^3.0.9",
|
|
85
|
+
"gulp-debug": "^4.0.0",
|
|
86
|
+
"gulp-postcss": "^9.0.1",
|
|
87
|
+
"gulp-rename": "^2.0.0",
|
|
88
|
+
"gulp-sass": "^5.0.0",
|
|
89
|
+
"gulp-sourcemaps": "^3.0.0",
|
|
90
|
+
"husky": "^7.0.2",
|
|
91
|
+
"jest": "^27.2.0",
|
|
92
|
+
"jsdom": "^17.0.0",
|
|
93
|
+
"jsdom-global": "^3.0.2",
|
|
94
|
+
"postcss": "^8.3.6",
|
|
95
|
+
"postcss-easy-import": "^3.0.0",
|
|
96
|
+
"postcss-map": "^0.11.0",
|
|
97
|
+
"postcss-normalize": "^10.0.1",
|
|
98
|
+
"postcss-scss": "^4.0.0",
|
|
99
|
+
"prop-types": "15.7.2",
|
|
100
|
+
"react": "16.14.0",
|
|
101
|
+
"react-dom": "16.14.0",
|
|
102
|
+
"react-test-renderer": "16.14.0",
|
|
103
|
+
"regenerator-runtime": "^0.13.9",
|
|
104
|
+
"rimraf": "^3.0.2",
|
|
105
|
+
"vinyl-paths": "3.0.1"
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CheckboxCog component
|
|
3
|
+
*/
|
|
4
|
+
import React from 'react'
|
|
5
|
+
import classnames from 'classnames'
|
|
6
|
+
|
|
7
|
+
import { CheckCog } from 'shinkansen-cogs/cogs'
|
|
8
|
+
import Title from 'shinkansen-cogs/components/title/checkbox'
|
|
9
|
+
import Description from 'shinkansen-cogs/components/description/checkbox'
|
|
10
|
+
import ErrorMessage from 'shinkansen-cogs/components/error-message/checkbox'
|
|
11
|
+
import Field from 'shinkansen-cogs/components/field/checkbox'
|
|
12
|
+
|
|
13
|
+
export default class CheckboxCog extends CheckCog {
|
|
14
|
+
getClassName () {
|
|
15
|
+
return classnames(super.getClassName(), 'checkbox')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
handleClick = (value) => {
|
|
19
|
+
const {
|
|
20
|
+
onClick,
|
|
21
|
+
name
|
|
22
|
+
} = this.props
|
|
23
|
+
|
|
24
|
+
onClick(name, value)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
handleChange = (value) => {
|
|
28
|
+
const {
|
|
29
|
+
onChange,
|
|
30
|
+
name
|
|
31
|
+
} = this.props
|
|
32
|
+
|
|
33
|
+
onChange(name, value)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
renderTitle () {
|
|
37
|
+
const id = this.getId()
|
|
38
|
+
|
|
39
|
+
const {
|
|
40
|
+
title,
|
|
41
|
+
required,
|
|
42
|
+
disabled,
|
|
43
|
+
readOnly
|
|
44
|
+
} = this.props
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<Title
|
|
48
|
+
id={id}
|
|
49
|
+
title={title}
|
|
50
|
+
required={required}
|
|
51
|
+
disabled={disabled}
|
|
52
|
+
readOnly={readOnly}
|
|
53
|
+
ref={this.setTitle}
|
|
54
|
+
/>
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
renderDescription () {
|
|
59
|
+
const {
|
|
60
|
+
description
|
|
61
|
+
} = this.props
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<Description
|
|
65
|
+
description={description}
|
|
66
|
+
ref={this.setDescription}
|
|
67
|
+
/>
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
renderErrorMessage () {
|
|
72
|
+
const {
|
|
73
|
+
errorMessage
|
|
74
|
+
} = this.props
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<ErrorMessage
|
|
78
|
+
errorMessage={errorMessage}
|
|
79
|
+
ref={this.setErrorMessage}
|
|
80
|
+
/>
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
renderField () {
|
|
85
|
+
const id = this.getId()
|
|
86
|
+
|
|
87
|
+
const {
|
|
88
|
+
name,
|
|
89
|
+
checked,
|
|
90
|
+
defaultChecked,
|
|
91
|
+
required,
|
|
92
|
+
disabled,
|
|
93
|
+
readOnly,
|
|
94
|
+
tabIndex,
|
|
95
|
+
accessKey,
|
|
96
|
+
placeholder
|
|
97
|
+
} = this.props
|
|
98
|
+
|
|
99
|
+
return (
|
|
100
|
+
<Field
|
|
101
|
+
id={id}
|
|
102
|
+
name={name}
|
|
103
|
+
checked={checked}
|
|
104
|
+
defaultChecked={defaultChecked}
|
|
105
|
+
required={required}
|
|
106
|
+
disabled={disabled}
|
|
107
|
+
readOnly={readOnly}
|
|
108
|
+
tabIndex={tabIndex}
|
|
109
|
+
accessKey={accessKey}
|
|
110
|
+
placeholder={placeholder}
|
|
111
|
+
onClick={this.handleClick}
|
|
112
|
+
onChange={this.handleChange}
|
|
113
|
+
ref={this.setField}
|
|
114
|
+
/>
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
render () {
|
|
119
|
+
const className = this.getClassName()
|
|
120
|
+
|
|
121
|
+
return (
|
|
122
|
+
<div className={className}>
|
|
123
|
+
{this.renderField()}
|
|
124
|
+
{this.renderTitle()}
|
|
125
|
+
{this.renderDescription()}
|
|
126
|
+
{this.renderErrorMessage()}
|
|
127
|
+
</div>
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
CheckboxCog.propTypes = {
|
|
133
|
+
...CheckCog.propTypes
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
CheckboxCog.defaultProps = {
|
|
137
|
+
...CheckCog.defaultProps
|
|
138
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EmailCog component
|
|
3
|
+
*/
|
|
4
|
+
import React from 'react'
|
|
5
|
+
import classnames from 'classnames'
|
|
6
|
+
|
|
7
|
+
import { ValueCog } from 'shinkansen-cogs/cogs'
|
|
8
|
+
import Title from 'shinkansen-cogs/components/title/email'
|
|
9
|
+
import Description from 'shinkansen-cogs/components/description/email'
|
|
10
|
+
import ErrorMessage from 'shinkansen-cogs/components/error-message/email'
|
|
11
|
+
import Field from 'shinkansen-cogs/components/field/email'
|
|
12
|
+
|
|
13
|
+
export default class EmailCog extends ValueCog {
|
|
14
|
+
getClassName () {
|
|
15
|
+
return classnames(super.getClassName(), 'email')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
handleChange = (value) => {
|
|
19
|
+
const {
|
|
20
|
+
onChange,
|
|
21
|
+
name
|
|
22
|
+
} = this.props
|
|
23
|
+
|
|
24
|
+
onChange(name, value)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
renderTitle () {
|
|
28
|
+
const id = this.getId()
|
|
29
|
+
|
|
30
|
+
const {
|
|
31
|
+
title,
|
|
32
|
+
required,
|
|
33
|
+
disabled,
|
|
34
|
+
readOnly
|
|
35
|
+
} = this.props
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<Title
|
|
39
|
+
id={id}
|
|
40
|
+
title={title}
|
|
41
|
+
required={required}
|
|
42
|
+
disabled={disabled}
|
|
43
|
+
readOnly={readOnly}
|
|
44
|
+
ref={this.setTitle}
|
|
45
|
+
/>
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
renderDescription () {
|
|
50
|
+
const {
|
|
51
|
+
description
|
|
52
|
+
} = this.props
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<Description
|
|
56
|
+
description={description}
|
|
57
|
+
ref={this.setDescription}
|
|
58
|
+
/>
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
renderErrorMessage () {
|
|
63
|
+
const {
|
|
64
|
+
errorMessage
|
|
65
|
+
} = this.props
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<ErrorMessage
|
|
69
|
+
errorMessage={errorMessage}
|
|
70
|
+
ref={this.setErrorMessage}
|
|
71
|
+
/>
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
renderField () {
|
|
76
|
+
const id = this.getId()
|
|
77
|
+
|
|
78
|
+
const {
|
|
79
|
+
name,
|
|
80
|
+
value,
|
|
81
|
+
defaultValue,
|
|
82
|
+
required,
|
|
83
|
+
disabled,
|
|
84
|
+
readOnly,
|
|
85
|
+
tabIndex,
|
|
86
|
+
accessKey,
|
|
87
|
+
placeholder
|
|
88
|
+
} = this.props
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<Field
|
|
92
|
+
id={id}
|
|
93
|
+
name={name}
|
|
94
|
+
value={value}
|
|
95
|
+
defaultValue={defaultValue}
|
|
96
|
+
required={required}
|
|
97
|
+
disabled={disabled}
|
|
98
|
+
readOnly={readOnly}
|
|
99
|
+
tabIndex={tabIndex}
|
|
100
|
+
accessKey={accessKey}
|
|
101
|
+
placeholder={placeholder}
|
|
102
|
+
onChange={this.handleChange}
|
|
103
|
+
ref={this.setField}
|
|
104
|
+
/>
|
|
105
|
+
)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
EmailCog.propTypes = {
|
|
110
|
+
...ValueCog.propTypes
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
EmailCog.defaultProps = {
|
|
114
|
+
...ValueCog.defaultProps
|
|
115
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cog component
|
|
3
|
+
*/
|
|
4
|
+
import React, { Component } from 'react'
|
|
5
|
+
import PropTypes from 'prop-types'
|
|
6
|
+
|
|
7
|
+
import classNames from 'classnames'
|
|
8
|
+
|
|
9
|
+
import Title from 'shinkansen-cogs/components/title'
|
|
10
|
+
import Description from 'shinkansen-cogs/components/description'
|
|
11
|
+
import ErrorMessage from 'shinkansen-cogs/components/error-message'
|
|
12
|
+
import Field from 'shinkansen-cogs/components/field'
|
|
13
|
+
|
|
14
|
+
function onChange () {
|
|
15
|
+
/* */
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function onClick () {
|
|
19
|
+
/* */
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default class Cog extends Component {
|
|
23
|
+
getTitle = () => this.title
|
|
24
|
+
getDescription = () => this.description
|
|
25
|
+
getErrorMessage = () => this.errorMessage
|
|
26
|
+
getField = () => this.input
|
|
27
|
+
|
|
28
|
+
setTitle = (title) => !!(this.title = title) || delete this.title
|
|
29
|
+
setDescription = (description) => !!(this.description = description) || delete this.description
|
|
30
|
+
setErrorMessage = (errorMessage) => !!(this.errorMessage = errorMessage) || delete this.errorMessage
|
|
31
|
+
setField = (input) => !!(this.input = input) || delete this.input
|
|
32
|
+
|
|
33
|
+
getClassName () {
|
|
34
|
+
const {
|
|
35
|
+
required,
|
|
36
|
+
disabled,
|
|
37
|
+
readOnly,
|
|
38
|
+
errorMessage
|
|
39
|
+
} = this.props
|
|
40
|
+
|
|
41
|
+
return classNames('cog', { required, disabled, readOnly, error: !!errorMessage })
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
getId () {
|
|
45
|
+
const {
|
|
46
|
+
id,
|
|
47
|
+
name
|
|
48
|
+
} = this.props
|
|
49
|
+
|
|
50
|
+
return id || name
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
shouldComponentUpdate (props) {
|
|
54
|
+
return (
|
|
55
|
+
(props.name !== this.props.name) ||
|
|
56
|
+
(props.id !== this.props.id) ||
|
|
57
|
+
(props.title !== this.props.title) ||
|
|
58
|
+
(props.description !== this.props.description) ||
|
|
59
|
+
(props.errorMessage !== this.props.errorMessage) ||
|
|
60
|
+
(props.required !== this.props.required) ||
|
|
61
|
+
(props.disabled !== this.props.disabled) ||
|
|
62
|
+
(props.readOnly !== this.props.readOnly) ||
|
|
63
|
+
(props.tabIndex !== this.props.tabIndex) ||
|
|
64
|
+
(props.accessKey !== this.props.accessKey) ||
|
|
65
|
+
(props.placeholder !== this.props.placeholder) ||
|
|
66
|
+
(props.onChange !== this.props.onChange)
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
renderTitle () {
|
|
71
|
+
const id = this.getId()
|
|
72
|
+
|
|
73
|
+
const {
|
|
74
|
+
title,
|
|
75
|
+
required,
|
|
76
|
+
disabled,
|
|
77
|
+
readOnly
|
|
78
|
+
} = this.props
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<Title
|
|
82
|
+
id={id}
|
|
83
|
+
title={title}
|
|
84
|
+
required={required}
|
|
85
|
+
disabled={disabled}
|
|
86
|
+
readOnly={readOnly}
|
|
87
|
+
ref={this.setTitle}
|
|
88
|
+
/>
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
renderDescription () {
|
|
93
|
+
const {
|
|
94
|
+
description
|
|
95
|
+
} = this.props
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<Description
|
|
99
|
+
description={description}
|
|
100
|
+
ref={this.setDescription}
|
|
101
|
+
/>
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
renderErrorMessage () {
|
|
106
|
+
const {
|
|
107
|
+
errorMessage
|
|
108
|
+
} = this.props
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<ErrorMessage
|
|
112
|
+
errorMessage={errorMessage}
|
|
113
|
+
ref={this.setErrorMessage}
|
|
114
|
+
/>
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
renderField () {
|
|
119
|
+
const id = this.getId()
|
|
120
|
+
|
|
121
|
+
const {
|
|
122
|
+
name,
|
|
123
|
+
required,
|
|
124
|
+
disabled,
|
|
125
|
+
readOnly,
|
|
126
|
+
tabIndex,
|
|
127
|
+
accessKey,
|
|
128
|
+
placeholder,
|
|
129
|
+
onChange
|
|
130
|
+
} = this.props
|
|
131
|
+
|
|
132
|
+
return (
|
|
133
|
+
<Field
|
|
134
|
+
id={id}
|
|
135
|
+
name={name}
|
|
136
|
+
required={required}
|
|
137
|
+
disabled={disabled}
|
|
138
|
+
readOnly={readOnly}
|
|
139
|
+
tabIndex={tabIndex}
|
|
140
|
+
accessKey={accessKey}
|
|
141
|
+
placeholder={placeholder}
|
|
142
|
+
onChange={onChange}
|
|
143
|
+
ref={this.setField}
|
|
144
|
+
/>
|
|
145
|
+
)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
render () {
|
|
149
|
+
const className = this.getClassName()
|
|
150
|
+
|
|
151
|
+
return (
|
|
152
|
+
<div className={className}>
|
|
153
|
+
{this.renderTitle()}
|
|
154
|
+
{this.renderDescription()}
|
|
155
|
+
{this.renderErrorMessage()}
|
|
156
|
+
{this.renderField()}
|
|
157
|
+
</div>
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
Cog.propTypes = {
|
|
163
|
+
id: PropTypes.string,
|
|
164
|
+
name: PropTypes.string.isRequired,
|
|
165
|
+
title: PropTypes.string,
|
|
166
|
+
description: PropTypes.string,
|
|
167
|
+
errorMessage: PropTypes.shape({
|
|
168
|
+
type: PropTypes.string.isRequired,
|
|
169
|
+
params: PropTypes.shape().isRequired,
|
|
170
|
+
uri: PropTypes.string.isRequired
|
|
171
|
+
}),
|
|
172
|
+
required: PropTypes.bool,
|
|
173
|
+
disabled: PropTypes.bool,
|
|
174
|
+
readOnly: PropTypes.bool,
|
|
175
|
+
placeholder: PropTypes.string,
|
|
176
|
+
onChange: PropTypes.func
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
Cog.defaultProps = {
|
|
180
|
+
required: false,
|
|
181
|
+
disabled: false,
|
|
182
|
+
readOnly: false,
|
|
183
|
+
onChange
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export class ValueCog extends Cog {
|
|
187
|
+
shouldComponentUpdate (props) {
|
|
188
|
+
return (
|
|
189
|
+
super.shouldComponentUpdate(props) ||
|
|
190
|
+
(props.value !== this.props.value)
|
|
191
|
+
)
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
ValueCog.propTypes = {
|
|
196
|
+
...Cog.propTypes,
|
|
197
|
+
value: PropTypes.string,
|
|
198
|
+
defaultValue: PropTypes.string
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
ValueCog.defaultProps = {
|
|
202
|
+
...Cog.defaultProps
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export class CheckCog extends Cog {
|
|
206
|
+
shouldComponentUpdate (props) {
|
|
207
|
+
return (
|
|
208
|
+
super.shouldComponentUpdate(props) ||
|
|
209
|
+
(props.checked !== this.props.checked) ||
|
|
210
|
+
(props.onClick !== this.props.onClick)
|
|
211
|
+
)
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
CheckCog.propTypes = {
|
|
216
|
+
...Cog.propTypes,
|
|
217
|
+
checked: PropTypes.bool,
|
|
218
|
+
defaultChecked: PropTypes.bool,
|
|
219
|
+
onClick: PropTypes.func
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
CheckCog.defaultProps = {
|
|
223
|
+
...Cog.defaultProps,
|
|
224
|
+
onClick
|
|
225
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NumberCog component
|
|
3
|
+
*/
|
|
4
|
+
import React from 'react'
|
|
5
|
+
import PropTypes from 'prop-types'
|
|
6
|
+
import classnames from 'classnames'
|
|
7
|
+
|
|
8
|
+
import { ValueCog } from 'shinkansen-cogs/cogs'
|
|
9
|
+
import Title from 'shinkansen-cogs/components/title/number'
|
|
10
|
+
import Description from 'shinkansen-cogs/components/description/number'
|
|
11
|
+
import ErrorMessage from 'shinkansen-cogs/components/error-message/number'
|
|
12
|
+
import Field from 'shinkansen-cogs/components/field/number'
|
|
13
|
+
|
|
14
|
+
export default class NumberCog extends ValueCog {
|
|
15
|
+
getClassName () {
|
|
16
|
+
return classnames(super.getClassName(), 'number')
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
handleChange = (value) => {
|
|
20
|
+
const {
|
|
21
|
+
onChange,
|
|
22
|
+
name
|
|
23
|
+
} = this.props
|
|
24
|
+
|
|
25
|
+
onChange(name, value)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
renderTitle () {
|
|
29
|
+
const id = this.getId()
|
|
30
|
+
|
|
31
|
+
const {
|
|
32
|
+
title,
|
|
33
|
+
required,
|
|
34
|
+
disabled,
|
|
35
|
+
readOnly
|
|
36
|
+
} = this.props
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<Title
|
|
40
|
+
id={id}
|
|
41
|
+
title={title}
|
|
42
|
+
required={required}
|
|
43
|
+
disabled={disabled}
|
|
44
|
+
readOnly={readOnly}
|
|
45
|
+
ref={this.setTitle}
|
|
46
|
+
/>
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
renderDescription () {
|
|
51
|
+
const {
|
|
52
|
+
description
|
|
53
|
+
} = this.props
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<Description
|
|
57
|
+
description={description}
|
|
58
|
+
ref={this.setDescription}
|
|
59
|
+
/>
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
renderErrorMessage () {
|
|
64
|
+
const {
|
|
65
|
+
errorMessage
|
|
66
|
+
} = this.props
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<ErrorMessage
|
|
70
|
+
errorMessage={errorMessage}
|
|
71
|
+
ref={this.setErrorMessage}
|
|
72
|
+
/>
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
renderField () {
|
|
77
|
+
const id = this.getId()
|
|
78
|
+
|
|
79
|
+
const {
|
|
80
|
+
name,
|
|
81
|
+
value,
|
|
82
|
+
defaultValue,
|
|
83
|
+
required,
|
|
84
|
+
disabled,
|
|
85
|
+
readOnly,
|
|
86
|
+
tabIndex,
|
|
87
|
+
accessKey,
|
|
88
|
+
placeholder
|
|
89
|
+
} = this.props
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<Field
|
|
93
|
+
id={id}
|
|
94
|
+
name={name}
|
|
95
|
+
value={value}
|
|
96
|
+
defaultValue={defaultValue}
|
|
97
|
+
required={required}
|
|
98
|
+
disabled={disabled}
|
|
99
|
+
readOnly={readOnly}
|
|
100
|
+
tabIndex={tabIndex}
|
|
101
|
+
accessKey={accessKey}
|
|
102
|
+
placeholder={placeholder}
|
|
103
|
+
onChange={this.handleChange}
|
|
104
|
+
ref={this.setField}
|
|
105
|
+
/>
|
|
106
|
+
)
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
NumberCog.propTypes = {
|
|
111
|
+
...ValueCog.propTypes,
|
|
112
|
+
value: PropTypes.oneOfType([
|
|
113
|
+
PropTypes.string,
|
|
114
|
+
PropTypes.number
|
|
115
|
+
]),
|
|
116
|
+
defaultValue: PropTypes.oneOfType([
|
|
117
|
+
PropTypes.string,
|
|
118
|
+
PropTypes.number
|
|
119
|
+
])
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
NumberCog.defaultProps = {
|
|
123
|
+
...ValueCog.defaultProps
|
|
124
|
+
}
|