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.
Files changed (108) hide show
  1. package/.husky/pre-commit +4 -0
  2. package/README.md +11 -0
  3. package/babel.config.js +72 -0
  4. package/gulp.sh +42 -0
  5. package/index.js +7 -0
  6. package/lib/cogs/checkbox/index.js +1 -0
  7. package/lib/cogs/email/index.js +1 -0
  8. package/lib/cogs/index.js +1 -0
  9. package/lib/cogs/number/index.js +1 -0
  10. package/lib/cogs/password/index.js +1 -0
  11. package/lib/cogs/radio/index.js +1 -0
  12. package/lib/cogs/select/index.js +1 -0
  13. package/lib/cogs/text/index.js +1 -0
  14. package/lib/cogs/textarea/index.js +1 -0
  15. package/lib/components/common/disabled/index.js +1 -0
  16. package/lib/components/common/readonly/index.js +1 -0
  17. package/lib/components/common/required/index.js +1 -0
  18. package/lib/components/common/text-content/index.js +1 -0
  19. package/lib/components/description/checkbox/index.js +1 -0
  20. package/lib/components/description/email/index.js +1 -0
  21. package/lib/components/description/index.js +1 -0
  22. package/lib/components/description/number/index.js +1 -0
  23. package/lib/components/description/password/index.js +1 -0
  24. package/lib/components/description/radio/index.js +1 -0
  25. package/lib/components/description/select/index.js +1 -0
  26. package/lib/components/description/text/index.js +1 -0
  27. package/lib/components/description/textarea/index.js +1 -0
  28. package/lib/components/error-message/checkbox/index.js +1 -0
  29. package/lib/components/error-message/email/index.js +1 -0
  30. package/lib/components/error-message/index.js +1 -0
  31. package/lib/components/error-message/number/index.js +1 -0
  32. package/lib/components/error-message/password/index.js +1 -0
  33. package/lib/components/error-message/radio/index.js +1 -0
  34. package/lib/components/error-message/select/index.js +1 -0
  35. package/lib/components/error-message/text/index.js +1 -0
  36. package/lib/components/error-message/textarea/index.js +1 -0
  37. package/lib/components/field/checkbox/index.js +1 -0
  38. package/lib/components/field/email/index.js +1 -0
  39. package/lib/components/field/index.js +1 -0
  40. package/lib/components/field/number/index.js +1 -0
  41. package/lib/components/field/password/index.js +1 -0
  42. package/lib/components/field/radio/index.js +1 -0
  43. package/lib/components/field/select/index.js +1 -0
  44. package/lib/components/field/text/index.js +1 -0
  45. package/lib/components/field/textarea/index.js +1 -0
  46. package/lib/components/title/checkbox/index.js +1 -0
  47. package/lib/components/title/email/index.js +1 -0
  48. package/lib/components/title/index.js +1 -0
  49. package/lib/components/title/number/index.js +1 -0
  50. package/lib/components/title/password/index.js +1 -0
  51. package/lib/components/title/radio/index.js +1 -0
  52. package/lib/components/title/select/index.js +1 -0
  53. package/lib/components/title/text/index.js +1 -0
  54. package/lib/components/title/textarea/index.js +1 -0
  55. package/lib/index.js +1 -0
  56. package/lib/transformers/error-message/index.js +1 -0
  57. package/package.json +107 -0
  58. package/src/cogs/checkbox/index.js +138 -0
  59. package/src/cogs/email/index.js +115 -0
  60. package/src/cogs/index.js +225 -0
  61. package/src/cogs/number/index.js +124 -0
  62. package/src/cogs/password/index.js +115 -0
  63. package/src/cogs/radio/index.js +149 -0
  64. package/src/cogs/select/index.js +117 -0
  65. package/src/cogs/text/index.js +115 -0
  66. package/src/cogs/textarea/index.js +115 -0
  67. package/src/components/common/disabled/index.js +9 -0
  68. package/src/components/common/readonly/index.js +9 -0
  69. package/src/components/common/required/index.js +9 -0
  70. package/src/components/common/text-content/index.js +14 -0
  71. package/src/components/description/checkbox/index.js +19 -0
  72. package/src/components/description/email/index.js +19 -0
  73. package/src/components/description/index.js +61 -0
  74. package/src/components/description/number/index.js +19 -0
  75. package/src/components/description/password/index.js +19 -0
  76. package/src/components/description/radio/index.js +19 -0
  77. package/src/components/description/select/index.js +19 -0
  78. package/src/components/description/text/index.js +19 -0
  79. package/src/components/description/textarea/index.js +19 -0
  80. package/src/components/error-message/checkbox/index.js +19 -0
  81. package/src/components/error-message/email/index.js +19 -0
  82. package/src/components/error-message/index.js +103 -0
  83. package/src/components/error-message/number/index.js +19 -0
  84. package/src/components/error-message/password/index.js +19 -0
  85. package/src/components/error-message/radio/index.js +19 -0
  86. package/src/components/error-message/select/index.js +19 -0
  87. package/src/components/error-message/text/index.js +19 -0
  88. package/src/components/error-message/textarea/index.js +19 -0
  89. package/src/components/field/checkbox/index.js +55 -0
  90. package/src/components/field/email/index.js +56 -0
  91. package/src/components/field/index.js +165 -0
  92. package/src/components/field/number/index.js +65 -0
  93. package/src/components/field/password/index.js +56 -0
  94. package/src/components/field/radio/index.js +72 -0
  95. package/src/components/field/select/index.js +62 -0
  96. package/src/components/field/text/index.js +56 -0
  97. package/src/components/field/textarea/index.js +55 -0
  98. package/src/components/title/checkbox/index.js +19 -0
  99. package/src/components/title/email/index.js +19 -0
  100. package/src/components/title/index.js +134 -0
  101. package/src/components/title/number/index.js +19 -0
  102. package/src/components/title/password/index.js +19 -0
  103. package/src/components/title/radio/index.js +19 -0
  104. package/src/components/title/select/index.js +19 -0
  105. package/src/components/title/text/index.js +19 -0
  106. package/src/components/title/textarea/index.js +19 -0
  107. package/src/index.js +28 -0
  108. package/src/transformers/error-message/index.js +234 -0
@@ -0,0 +1,115 @@
1
+ /**
2
+ * PasswordCog 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/password'
9
+ import Description from 'shinkansen-cogs/components/description/password'
10
+ import ErrorMessage from 'shinkansen-cogs/components/error-message/password'
11
+ import Field from 'shinkansen-cogs/components/field/password'
12
+
13
+ export default class PasswordCog extends ValueCog {
14
+ getClassName () {
15
+ return classnames(super.getClassName(), 'password')
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
+ PasswordCog.propTypes = {
110
+ ...ValueCog.propTypes
111
+ }
112
+
113
+ PasswordCog.defaultProps = {
114
+ ...ValueCog.defaultProps
115
+ }
@@ -0,0 +1,149 @@
1
+ /**
2
+ * Radio component
3
+ */
4
+ import React from 'react'
5
+ import PropTypes from 'prop-types'
6
+ import classnames from 'classnames'
7
+
8
+ import { CheckCog } from 'shinkansen-cogs/cogs'
9
+ import Title from 'shinkansen-cogs/components/title/radio'
10
+ import Description from 'shinkansen-cogs/components/description/radio'
11
+ import ErrorMessage from 'shinkansen-cogs/components/error-message/radio'
12
+ import Field from 'shinkansen-cogs/components/field/radio'
13
+
14
+ export default class Radio extends CheckCog {
15
+ getClassName () {
16
+ return classnames(super.getClassName(), 'radio')
17
+ }
18
+
19
+ handleClick = (value) => {
20
+ const {
21
+ onClick,
22
+ name
23
+ } = this.props
24
+
25
+ onClick(name, value)
26
+ }
27
+
28
+ handleChange = (value) => {
29
+ const {
30
+ onChange,
31
+ name
32
+ } = this.props
33
+
34
+ onChange(name, value)
35
+ }
36
+
37
+ shouldComponentUpdate (props) {
38
+ return (
39
+ super.shouldComponentUpdate(props) ||
40
+ (props.value !== this.props.value)
41
+ )
42
+ }
43
+
44
+ renderTitle () {
45
+ const id = this.getId()
46
+
47
+ const {
48
+ title,
49
+ required,
50
+ disabled,
51
+ readOnly
52
+ } = this.props
53
+
54
+ return (
55
+ <Title
56
+ id={id}
57
+ title={title}
58
+ required={required}
59
+ disabled={disabled}
60
+ readOnly={readOnly}
61
+ ref={this.setTitle}
62
+ />
63
+ )
64
+ }
65
+
66
+ renderDescription () {
67
+ const {
68
+ description
69
+ } = this.props
70
+
71
+ return (
72
+ <Description
73
+ description={description}
74
+ ref={this.setDescription}
75
+ />
76
+ )
77
+ }
78
+
79
+ renderErrorMessage () {
80
+ const {
81
+ errorMessage
82
+ } = this.props
83
+
84
+ return (
85
+ <ErrorMessage
86
+ errorMessage={errorMessage}
87
+ ref={this.setErrorMessage}
88
+ />
89
+ )
90
+ }
91
+
92
+ renderField () {
93
+ const id = this.getId()
94
+
95
+ const {
96
+ name,
97
+ value,
98
+ checked,
99
+ defaultChecked,
100
+ required,
101
+ disabled,
102
+ readOnly,
103
+ tabIndex,
104
+ accessKey,
105
+ placeholder
106
+ } = this.props
107
+
108
+ return (
109
+ <Field
110
+ id={id}
111
+ name={name}
112
+ value={value}
113
+ checked={checked}
114
+ defaultChecked={defaultChecked}
115
+ required={required}
116
+ disabled={disabled}
117
+ readOnly={readOnly}
118
+ tabIndex={tabIndex}
119
+ accessKey={accessKey}
120
+ placeholder={placeholder}
121
+ onClick={this.handleClick}
122
+ onChange={this.handleChange}
123
+ ref={this.setField}
124
+ />
125
+ )
126
+ }
127
+
128
+ render () {
129
+ const className = this.getClassName()
130
+
131
+ return (
132
+ <div className={className}>
133
+ {this.renderField()}
134
+ {this.renderTitle()}
135
+ {this.renderDescription()}
136
+ {this.renderErrorMessage()}
137
+ </div>
138
+ )
139
+ }
140
+ }
141
+
142
+ Radio.propTypes = {
143
+ ...CheckCog.propTypes,
144
+ value: PropTypes.string.isRequired
145
+ }
146
+
147
+ Radio.defaultProps = {
148
+ ...CheckCog.defaultProps
149
+ }
@@ -0,0 +1,117 @@
1
+ /**
2
+ * SelectCog 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/select'
9
+ import Description from 'shinkansen-cogs/components/description/select'
10
+ import ErrorMessage from 'shinkansen-cogs/components/error-message/select'
11
+ import Field from 'shinkansen-cogs/components/field/select'
12
+
13
+ export default class SelectCog extends ValueCog {
14
+ getClassName () {
15
+ return classnames(super.getClassName(), 'select')
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
+ children
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
+ {children}
106
+ </Field>
107
+ )
108
+ }
109
+ }
110
+
111
+ SelectCog.propTypes = {
112
+ ...ValueCog.propTypes
113
+ }
114
+
115
+ SelectCog.defaultProps = {
116
+ ...ValueCog.defaultProps
117
+ }
@@ -0,0 +1,115 @@
1
+ /**
2
+ * TextCog 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/text'
9
+ import Description from 'shinkansen-cogs/components/description/text'
10
+ import ErrorMessage from 'shinkansen-cogs/components/error-message/text'
11
+ import Field from 'shinkansen-cogs/components/field/text'
12
+
13
+ export default class TextCog extends ValueCog {
14
+ getClassName () {
15
+ return classnames(super.getClassName(), 'text')
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
+ TextCog.propTypes = {
110
+ ...ValueCog.propTypes
111
+ }
112
+
113
+ TextCog.defaultProps = {
114
+ ...ValueCog.defaultProps
115
+ }
@@ -0,0 +1,115 @@
1
+ /**
2
+ * TextareaCog 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/textarea'
9
+ import Description from 'shinkansen-cogs/components/description/textarea'
10
+ import ErrorMessage from 'shinkansen-cogs/components/error-message/textarea'
11
+ import Field from 'shinkansen-cogs/components/field/textarea'
12
+
13
+ export default class TextareaCog extends ValueCog {
14
+ getClassName () {
15
+ return classnames(super.getClassName(), 'textarea')
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
+ TextareaCog.propTypes = {
110
+ ...ValueCog.propTypes
111
+ }
112
+
113
+ TextareaCog.defaultProps = {
114
+ ...ValueCog.defaultProps
115
+ }
@@ -0,0 +1,9 @@
1
+ import React from 'react'
2
+
3
+ const DISABLED = String.fromCharCode(42)
4
+
5
+ export default () => (
6
+ <span className='is-disabled'>
7
+ {DISABLED}
8
+ </span>
9
+ )
@@ -0,0 +1,9 @@
1
+ import React from 'react'
2
+
3
+ const READONLY = String.fromCharCode(42)
4
+
5
+ export default () => (
6
+ <span className='is-readonly'>
7
+ {READONLY}
8
+ </span>
9
+ )
@@ -0,0 +1,9 @@
1
+ import React from 'react'
2
+
3
+ const REQUIRED = String.fromCharCode(42)
4
+
5
+ export default () => (
6
+ <span className='is-required'>
7
+ {REQUIRED}
8
+ </span>
9
+ )
@@ -0,0 +1,14 @@
1
+ import React from 'react'
2
+ import PropTypes from 'prop-types'
3
+
4
+ const TextContent = ({ textContent }) => (
5
+ <span className='text-content'>
6
+ {textContent}
7
+ </span>
8
+ )
9
+
10
+ TextContent.propTypes = {
11
+ textContent: PropTypes.string.isRequired
12
+ }
13
+
14
+ export default TextContent
@@ -0,0 +1,19 @@
1
+ /**
2
+ * CheckboxDescription component
3
+ */
4
+ import classnames from 'classnames'
5
+ import Description from 'shinkansen-cogs/components/description'
6
+
7
+ export default class CheckboxDescription extends Description {
8
+ getClassName () {
9
+ return classnames(super.getClassName(), 'checkbox')
10
+ }
11
+ }
12
+
13
+ CheckboxDescription.propTypes = {
14
+ ...Description.propTypes
15
+ }
16
+
17
+ CheckboxDescription.defaultProps = {
18
+ ...Description.defaultProps
19
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * EmailDescription component
3
+ */
4
+ import classnames from 'classnames'
5
+ import Description from 'shinkansen-cogs/components/description'
6
+
7
+ export default class EmailDescription extends Description {
8
+ getClassName () {
9
+ return classnames(super.getClassName(), 'email')
10
+ }
11
+ }
12
+
13
+ EmailDescription.propTypes = {
14
+ ...Description.propTypes
15
+ }
16
+
17
+ EmailDescription.defaultProps = {
18
+ ...Description.defaultProps
19
+ }