shinkansen-cogs 1.7.301 → 1.8.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 -0
- package/eslint.config.mjs +11 -56
- package/index.d.mts +214 -4
- package/package.json +6 -2
- package/src/cogs/checkbox/description/index.cjs +1 -1
- package/src/cogs/checkbox/description/index.jsx +0 -4
- package/src/cogs/checkbox/error-message/index.cjs +1 -1
- package/src/cogs/checkbox/error-message/index.jsx +0 -4
- package/src/cogs/checkbox/field/index.cjs +1 -1
- package/src/cogs/checkbox/field/index.d.mts +8 -2
- package/src/cogs/checkbox/field/index.jsx +11 -1
- package/src/cogs/checkbox/index.cjs +1 -1
- package/src/cogs/checkbox/index.d.mts +20 -2
- package/src/cogs/checkbox/index.jsx +41 -14
- package/src/cogs/checkbox/title/index.cjs +1 -1
- package/src/cogs/checkbox/title/index.d.mts +5 -1
- package/src/cogs/checkbox/title/index.jsx +8 -4
- package/src/cogs/email/description/index.cjs +1 -1
- package/src/cogs/email/description/index.jsx +0 -4
- package/src/cogs/email/error-message/index.cjs +1 -1
- package/src/cogs/email/error-message/index.jsx +0 -4
- package/src/cogs/email/field/index.cjs +1 -1
- package/src/cogs/email/field/index.d.mts +8 -2
- package/src/cogs/email/field/index.jsx +11 -5
- package/src/cogs/email/index.cjs +1 -1
- package/src/cogs/email/index.d.mts +13 -2
- package/src/cogs/email/index.jsx +17 -8
- package/src/cogs/email/title/index.cjs +1 -1
- package/src/cogs/email/title/index.d.mts +5 -1
- package/src/cogs/email/title/index.jsx +8 -4
- package/src/cogs/index.cjs +1 -0
- package/src/cogs/index.d.mts +31 -13
- package/src/cogs/index.jsx +43 -14
- package/src/cogs/number/description/index.cjs +1 -1
- package/src/cogs/number/description/index.jsx +0 -4
- package/src/cogs/number/error-message/index.cjs +1 -1
- package/src/cogs/number/error-message/index.jsx +0 -4
- package/src/cogs/number/field/index.cjs +1 -1
- package/src/cogs/number/field/index.d.mts +8 -2
- package/src/cogs/number/field/index.jsx +11 -1
- package/src/cogs/number/index.cjs +1 -1
- package/src/cogs/number/index.d.mts +13 -2
- package/src/cogs/number/index.jsx +17 -4
- package/src/cogs/number/title/index.cjs +1 -1
- package/src/cogs/number/title/index.d.mts +5 -1
- package/src/cogs/number/title/index.jsx +8 -4
- package/src/cogs/password/description/index.cjs +1 -1
- package/src/cogs/password/description/index.jsx +0 -4
- package/src/cogs/password/error-message/index.cjs +1 -1
- package/src/cogs/password/error-message/index.jsx +0 -4
- package/src/cogs/password/field/index.cjs +1 -1
- package/src/cogs/password/field/index.d.mts +8 -2
- package/src/cogs/password/field/index.jsx +11 -5
- package/src/cogs/password/index.cjs +1 -1
- package/src/cogs/password/index.d.mts +13 -2
- package/src/cogs/password/index.jsx +17 -8
- package/src/cogs/password/title/index.cjs +1 -1
- package/src/cogs/password/title/index.d.mts +5 -1
- package/src/cogs/password/title/index.jsx +8 -4
- package/src/cogs/radio/description/index.cjs +1 -1
- package/src/cogs/radio/description/index.jsx +0 -4
- package/src/cogs/radio/error-message/index.cjs +1 -1
- package/src/cogs/radio/error-message/index.jsx +0 -4
- package/src/cogs/radio/field/index.cjs +1 -1
- package/src/cogs/radio/field/index.d.mts +8 -2
- package/src/cogs/radio/field/index.jsx +11 -1
- package/src/cogs/radio/index.cjs +1 -1
- package/src/cogs/radio/index.d.mts +20 -2
- package/src/cogs/radio/index.jsx +41 -14
- package/src/cogs/radio/title/index.cjs +1 -1
- package/src/cogs/radio/title/index.d.mts +5 -1
- package/src/cogs/radio/title/index.jsx +8 -4
- package/src/cogs/select/description/index.cjs +1 -1
- package/src/cogs/select/description/index.jsx +0 -4
- package/src/cogs/select/error-message/index.cjs +1 -1
- package/src/cogs/select/error-message/index.jsx +0 -4
- package/src/cogs/select/field/index.cjs +1 -1
- package/src/cogs/select/field/index.d.mts +8 -2
- package/src/cogs/select/field/index.jsx +56 -15
- package/src/cogs/select/index.cjs +1 -1
- package/src/cogs/select/index.d.mts +13 -2
- package/src/cogs/select/index.jsx +39 -12
- package/src/cogs/select/title/index.cjs +1 -1
- package/src/cogs/select/title/index.d.mts +5 -1
- package/src/cogs/select/title/index.jsx +8 -4
- package/src/cogs/text/description/index.cjs +1 -1
- package/src/cogs/text/description/index.jsx +0 -4
- package/src/cogs/text/error-message/index.cjs +1 -1
- package/src/cogs/text/error-message/index.jsx +0 -4
- package/src/cogs/text/field/index.cjs +1 -1
- package/src/cogs/text/field/index.d.mts +8 -2
- package/src/cogs/text/field/index.jsx +11 -5
- package/src/cogs/text/index.cjs +1 -1
- package/src/cogs/text/index.d.mts +13 -2
- package/src/cogs/text/index.jsx +17 -8
- package/src/cogs/text/title/index.cjs +1 -1
- package/src/cogs/text/title/index.d.mts +5 -1
- package/src/cogs/text/title/index.jsx +8 -4
- package/src/cogs/textarea/description/index.cjs +1 -1
- package/src/cogs/textarea/description/index.jsx +0 -4
- package/src/cogs/textarea/error-message/index.cjs +1 -1
- package/src/cogs/textarea/error-message/index.jsx +0 -4
- package/src/cogs/textarea/field/index.cjs +1 -1
- package/src/cogs/textarea/field/index.d.mts +8 -2
- package/src/cogs/textarea/field/index.jsx +11 -5
- package/src/cogs/textarea/index.cjs +1 -1
- package/src/cogs/textarea/index.d.mts +13 -2
- package/src/cogs/textarea/index.jsx +17 -8
- package/src/cogs/textarea/title/index.cjs +1 -1
- package/src/cogs/textarea/title/index.d.mts +5 -1
- package/src/cogs/textarea/title/index.jsx +8 -4
- package/src/common/index.d.mts +10 -2
- package/src/components/common/disabled/index.cjs +1 -1
- package/src/components/common/disabled/index.jsx +7 -5
- package/src/components/common/readonly/index.cjs +1 -1
- package/src/components/common/readonly/index.jsx +7 -5
- package/src/components/common/required/index.cjs +1 -1
- package/src/components/common/required/index.jsx +7 -5
- package/src/components/common/text-content/index.cjs +1 -1
- package/src/components/common/text-content/index.d.mts +3 -4
- package/src/components/common/text-content/index.jsx +6 -5
- package/src/components/description/index.cjs +1 -1
- package/src/components/description/index.d.mts +10 -5
- package/src/components/description/index.jsx +12 -2
- package/src/components/error-message/index.cjs +1 -1
- package/src/components/error-message/index.d.mts +22 -3
- package/src/components/error-message/index.jsx +28 -11
- package/src/components/field/index.cjs +1 -1
- package/src/components/field/index.d.mts +29 -14
- package/src/components/field/index.jsx +57 -17
- package/src/components/title/index.cjs +1 -1
- package/src/components/title/index.d.mts +22 -10
- package/src/components/title/index.jsx +12 -2
- package/src/index.d.mts +3 -0
- package/src/transformers/error-message/index.d.mts +8 -0
- package/src/transformers/error-message/index.mjs +12 -4
|
@@ -1,11 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {CogsTypes.Components.Field.ValueProps} ValueProps
|
|
3
|
+
* @typedef {CogsTypes.Components.Field.Password.PasswordProps} PasswordProps
|
|
4
|
+
*/
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
7
|
* PasswordField component
|
|
3
8
|
*/
|
|
4
9
|
import React from 'react'
|
|
5
10
|
import classnames from 'classnames'
|
|
6
11
|
|
|
7
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
ValueField
|
|
14
|
+
} from '#cogs/components/field'
|
|
8
15
|
|
|
16
|
+
/**
|
|
17
|
+
* @extends {ValueField<ValueProps & PasswordProps>}
|
|
18
|
+
*/
|
|
9
19
|
export default class PasswordField extends ValueField {
|
|
10
20
|
getClassName () {
|
|
11
21
|
return classnames(super.getClassName(), 'password')
|
|
@@ -48,7 +58,3 @@ export default class PasswordField extends ValueField {
|
|
|
48
58
|
)
|
|
49
59
|
}
|
|
50
60
|
}
|
|
51
|
-
|
|
52
|
-
PasswordField.propTypes = {
|
|
53
|
-
...ValueField.propTypes
|
|
54
|
-
}
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
declare module '#cogs/cogs/password' {
|
|
2
|
-
import
|
|
2
|
+
import {
|
|
3
|
+
ValueCog
|
|
4
|
+
} from '#cogs/cogs'
|
|
3
5
|
|
|
4
|
-
|
|
6
|
+
type PasswordProps = CogsTypes.Cogs.Cog.Password.PasswordProps
|
|
7
|
+
|
|
8
|
+
export default class PasswordCog<P extends PasswordProps> extends ValueCog<P> {
|
|
9
|
+
handleChange (
|
|
10
|
+
name: string,
|
|
11
|
+
value?: string | string[]
|
|
12
|
+
): void
|
|
13
|
+
}
|
|
5
14
|
}
|
|
6
15
|
|
|
7
16
|
declare module 'shinkansen-cogs/cogs/password' {
|
|
17
|
+
export type PasswordProps = CogsTypes.Cogs.Cog.Password.PasswordProps
|
|
18
|
+
|
|
8
19
|
export { default } from '#cogs/cogs/password'
|
|
9
20
|
}
|
|
@@ -1,10 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {CogsTypes.Cogs.Cog.ValueProps} ValueProps
|
|
3
|
+
* @typedef {CogsTypes.Cogs.Cog.Password.PasswordProps} PasswordProps
|
|
4
|
+
*/
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
7
|
* PasswordCog component
|
|
3
8
|
*/
|
|
4
9
|
import React from 'react'
|
|
5
10
|
import classnames from 'classnames'
|
|
6
11
|
|
|
7
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
ValueCog
|
|
14
|
+
} from '#cogs/cogs'
|
|
8
15
|
|
|
9
16
|
import {
|
|
10
17
|
DEFAULT_HANDLE_CHANGE
|
|
@@ -15,15 +22,21 @@ import Description from './description/index.jsx'
|
|
|
15
22
|
import ErrorMessage from './error-message/index.jsx'
|
|
16
23
|
import Field from './field/index.jsx'
|
|
17
24
|
|
|
25
|
+
/**
|
|
26
|
+
* @extends {ValueCog<ValueProps & PasswordProps>}
|
|
27
|
+
*/
|
|
18
28
|
export default class PasswordCog extends ValueCog {
|
|
19
29
|
getClassName () {
|
|
20
30
|
return classnames(super.getClassName(), 'password')
|
|
21
31
|
}
|
|
22
32
|
|
|
23
|
-
|
|
33
|
+
/**
|
|
34
|
+
* @param {string} name
|
|
35
|
+
* @param {string | string[]} [value]
|
|
36
|
+
*/
|
|
37
|
+
handleChange = (name, value) => {
|
|
24
38
|
const {
|
|
25
|
-
onChange = DEFAULT_HANDLE_CHANGE
|
|
26
|
-
name
|
|
39
|
+
onChange = DEFAULT_HANDLE_CHANGE
|
|
27
40
|
} = this.props
|
|
28
41
|
|
|
29
42
|
onChange(name, value)
|
|
@@ -108,7 +121,3 @@ export default class PasswordCog extends ValueCog {
|
|
|
108
121
|
)
|
|
109
122
|
}
|
|
110
123
|
}
|
|
111
|
-
|
|
112
|
-
PasswordCog.propTypes = {
|
|
113
|
-
...ValueCog.propTypes
|
|
114
|
-
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
declare module '#cogs/cogs/password/title' {
|
|
2
2
|
import Title from '#cogs/components/title'
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
type PasswordProps = CogsTypes.Components.Title.Password.PasswordProps
|
|
5
|
+
|
|
6
|
+
export default class PasswordTitle<P extends PasswordProps> extends Title<P> {}
|
|
5
7
|
}
|
|
6
8
|
|
|
7
9
|
declare module 'shinkansen-cogs/cogs/password/title' {
|
|
10
|
+
export type PasswordProps = CogsTypes.Components.Title.Password.PasswordProps
|
|
11
|
+
|
|
8
12
|
export { default } from '#cogs/cogs/password/title'
|
|
9
13
|
}
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {CogsTypes.Components.Title.TitleProps} TitleProps
|
|
3
|
+
* @typedef {CogsTypes.Components.Title.Password.PasswordProps} PasswordProps
|
|
4
|
+
*/
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
7
|
* PasswordTitle component
|
|
3
8
|
*/
|
|
4
9
|
import classnames from 'classnames'
|
|
5
10
|
import Title from '#cogs/components/title'
|
|
6
11
|
|
|
12
|
+
/**
|
|
13
|
+
* @extends {Title<TitleProps & PasswordProps>}
|
|
14
|
+
*/
|
|
7
15
|
export default class PasswordTitle extends Title {
|
|
8
16
|
getClassName () {
|
|
9
17
|
return classnames(super.getClassName(), 'password')
|
|
10
18
|
}
|
|
11
19
|
}
|
|
12
|
-
|
|
13
|
-
PasswordTitle.propTypes = {
|
|
14
|
-
...Title.propTypes
|
|
15
|
-
}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
declare module '#cogs/cogs/radio/field' {
|
|
2
|
-
import
|
|
2
|
+
import {
|
|
3
|
+
CheckField
|
|
4
|
+
} from '#cogs/components/field'
|
|
3
5
|
|
|
4
|
-
|
|
6
|
+
type RadioProps = CogsTypes.Components.Field.Radio.RadioProps
|
|
7
|
+
|
|
8
|
+
export default class RadioField<P extends RadioProps> extends CheckField<P> {}
|
|
5
9
|
}
|
|
6
10
|
|
|
7
11
|
declare module 'shinkansen-cogs/cogs/radio/field' {
|
|
12
|
+
export type RadioProps = CogsTypes.Components.Field.Radio.RadioProps
|
|
13
|
+
|
|
8
14
|
export { default } from '#cogs/cogs/radio/field'
|
|
9
15
|
}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {CogsTypes.Components.Field.CheckProps} CheckProps
|
|
3
|
+
* @typedef {CogsTypes.Components.Field.Radio.RadioProps} RadioProps
|
|
4
|
+
*/
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
7
|
* RadioField component
|
|
3
8
|
*/
|
|
@@ -5,8 +10,13 @@ import React from 'react'
|
|
|
5
10
|
import PropTypes from 'prop-types'
|
|
6
11
|
import classnames from 'classnames'
|
|
7
12
|
|
|
8
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
CheckField
|
|
15
|
+
} from '#cogs/components/field'
|
|
9
16
|
|
|
17
|
+
/**
|
|
18
|
+
* @extends {CheckField<CheckProps & RadioProps>}
|
|
19
|
+
*/
|
|
10
20
|
export default class RadioField extends CheckField {
|
|
11
21
|
getClassName () {
|
|
12
22
|
return classnames(super.getClassName(), 'radio')
|
package/src/cogs/radio/index.cjs
CHANGED
|
@@ -1,9 +1,27 @@
|
|
|
1
1
|
declare module '#cogs/cogs/radio' {
|
|
2
|
-
import
|
|
2
|
+
import {
|
|
3
|
+
CheckCog
|
|
4
|
+
} from '#cogs/cogs'
|
|
3
5
|
|
|
4
|
-
|
|
6
|
+
type RadioProps = CogsTypes.Cogs.Cog.Radio.RadioProps
|
|
7
|
+
|
|
8
|
+
export default class RadioCog<P extends RadioProps> extends CheckCog<P> {
|
|
9
|
+
handleChange (
|
|
10
|
+
name: string,
|
|
11
|
+
value?: string | string[],
|
|
12
|
+
checked?: boolean
|
|
13
|
+
): void
|
|
14
|
+
|
|
15
|
+
handleClick (
|
|
16
|
+
name: string,
|
|
17
|
+
value?: string | string[],
|
|
18
|
+
checked?: boolean
|
|
19
|
+
): void
|
|
20
|
+
}
|
|
5
21
|
}
|
|
6
22
|
|
|
7
23
|
declare module 'shinkansen-cogs/cogs/radio' {
|
|
24
|
+
export type RadioProps = CogsTypes.Cogs.Cog.Radio.RadioProps
|
|
25
|
+
|
|
8
26
|
export { default } from '#cogs/cogs/radio'
|
|
9
27
|
}
|
package/src/cogs/radio/index.jsx
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {CogsTypes.Cogs.Cog.CheckProps} CheckProps
|
|
3
|
+
* @typedef {CogsTypes.Cogs.Cog.Radio.RadioProps} RadioProps
|
|
4
|
+
*/
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
7
|
* Radio component
|
|
3
8
|
*/
|
|
@@ -5,7 +10,9 @@ import React from 'react'
|
|
|
5
10
|
import PropTypes from 'prop-types'
|
|
6
11
|
import classnames from 'classnames'
|
|
7
12
|
|
|
8
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
CheckCog
|
|
15
|
+
} from '#cogs/cogs'
|
|
9
16
|
|
|
10
17
|
import {
|
|
11
18
|
DEFAULT_HANDLE_CHANGE,
|
|
@@ -17,36 +24,56 @@ import Description from './description/index.jsx'
|
|
|
17
24
|
import ErrorMessage from './error-message/index.jsx'
|
|
18
25
|
import Field from './field/index.jsx'
|
|
19
26
|
|
|
27
|
+
/**
|
|
28
|
+
* @extends {CheckCog<CheckProps & RadioProps>}
|
|
29
|
+
*/
|
|
20
30
|
export default class Radio extends CheckCog {
|
|
21
31
|
getClassName () {
|
|
22
32
|
return classnames(super.getClassName(), 'radio')
|
|
23
33
|
}
|
|
24
34
|
|
|
25
|
-
|
|
35
|
+
/**
|
|
36
|
+
* @param {CheckProps} props
|
|
37
|
+
* @returns {boolean}
|
|
38
|
+
*/
|
|
39
|
+
shouldComponentUpdate (props) {
|
|
26
40
|
const {
|
|
27
|
-
|
|
28
|
-
|
|
41
|
+
value,
|
|
42
|
+
...superProps
|
|
43
|
+
} = props
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
super.shouldComponentUpdate(superProps) || // , state) //
|
|
47
|
+
(value !== this.props.value)
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @param {string} name
|
|
53
|
+
* @param {string | string[]} [value]
|
|
54
|
+
* @param {boolean} [checked]
|
|
55
|
+
*/
|
|
56
|
+
handleChange = (name, value, checked) => {
|
|
57
|
+
const {
|
|
58
|
+
onChange = DEFAULT_HANDLE_CHANGE
|
|
29
59
|
} = this.props
|
|
30
60
|
|
|
31
61
|
onChange(name, value, checked)
|
|
32
62
|
}
|
|
33
63
|
|
|
34
|
-
|
|
64
|
+
/**
|
|
65
|
+
* @param {string} name
|
|
66
|
+
* @param {string | string[]} [value]
|
|
67
|
+
* @param {boolean} [checked]
|
|
68
|
+
*/
|
|
69
|
+
handleClick = (name, value, checked) => {
|
|
35
70
|
const {
|
|
36
|
-
onClick = DEFAULT_HANDLE_CLICK
|
|
37
|
-
name
|
|
71
|
+
onClick = DEFAULT_HANDLE_CLICK
|
|
38
72
|
} = this.props
|
|
39
73
|
|
|
40
74
|
onClick(name, value, checked)
|
|
41
75
|
}
|
|
42
76
|
|
|
43
|
-
shouldComponentUpdate (props, state) {
|
|
44
|
-
return (
|
|
45
|
-
super.shouldComponentUpdate(props) ||
|
|
46
|
-
(props.value !== this.props.value)
|
|
47
|
-
)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
77
|
renderTitle () {
|
|
51
78
|
const id = this.getId()
|
|
52
79
|
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
declare module '#cogs/cogs/radio/title' {
|
|
2
2
|
import Title from '#cogs/components/title'
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
type RadioProps = CogsTypes.Components.Title.Radio.RadioProps
|
|
5
|
+
|
|
6
|
+
export default class RadioTitle<P extends RadioProps> extends Title<P> {}
|
|
5
7
|
}
|
|
6
8
|
|
|
7
9
|
declare module 'shinkansen-cogs/cogs/radio/title' {
|
|
10
|
+
export type RadioProps = CogsTypes.Components.Title.Radio.RadioProps
|
|
11
|
+
|
|
8
12
|
export { default } from '#cogs/cogs/radio/title'
|
|
9
13
|
}
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {CogsTypes.Components.Title.TitleProps} TitleProps
|
|
3
|
+
* @typedef {CogsTypes.Components.Title.Radio.RadioProps} RadioProps
|
|
4
|
+
*/
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
7
|
* RadioTitle component
|
|
3
8
|
*/
|
|
4
9
|
import classnames from 'classnames'
|
|
5
10
|
import Title from '#cogs/components/title'
|
|
6
11
|
|
|
12
|
+
/**
|
|
13
|
+
* @extends {Title<TitleProps & RadioProps>}
|
|
14
|
+
*/
|
|
7
15
|
export default class RadioTitle extends Title {
|
|
8
16
|
getClassName () {
|
|
9
17
|
return classnames(super.getClassName(), 'radio')
|
|
10
18
|
}
|
|
11
19
|
}
|
|
12
|
-
|
|
13
|
-
RadioTitle.propTypes = {
|
|
14
|
-
...Title.propTypes
|
|
15
|
-
}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
declare module '#cogs/cogs/select/field' {
|
|
2
|
-
import
|
|
2
|
+
import {
|
|
3
|
+
ValueField
|
|
4
|
+
} from '#cogs/components/field'
|
|
3
5
|
|
|
4
|
-
|
|
6
|
+
type SelectProps = CogsTypes.Components.Field.Select.SelectProps
|
|
7
|
+
|
|
8
|
+
export default class SelectField<P extends SelectProps> extends ValueField<P> {}
|
|
5
9
|
}
|
|
6
10
|
|
|
7
11
|
declare module 'shinkansen-cogs/cogs/select/field' {
|
|
12
|
+
export type SelectProps = CogsTypes.Components.Field.Select.SelectProps
|
|
13
|
+
|
|
8
14
|
export { default } from '#cogs/cogs/select/field'
|
|
9
15
|
}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {CogsTypes.Components.Field.ValueProps} ValueProps
|
|
3
|
+
* @typedef {CogsTypes.Components.Field.Select.SelectProps} SelectProps
|
|
4
|
+
*/
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
7
|
* SelectField component
|
|
3
8
|
*/
|
|
@@ -5,46 +10,82 @@ import React from 'react'
|
|
|
5
10
|
import PropTypes from 'prop-types'
|
|
6
11
|
import classnames from 'classnames'
|
|
7
12
|
|
|
8
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
ValueField
|
|
15
|
+
} from '#cogs/components/field'
|
|
9
16
|
|
|
10
17
|
import {
|
|
11
18
|
DEFAULT_HANDLE_CHANGE
|
|
12
19
|
} from '#cogs/common'
|
|
13
20
|
|
|
21
|
+
/**
|
|
22
|
+
* @param {{ target: { selectedOptions: { value?: string, text?: string }[] } }} event
|
|
23
|
+
* @returns {string[]}
|
|
24
|
+
*/
|
|
14
25
|
function getSelectedValues ({ target: { selectedOptions } }) {
|
|
15
26
|
return (
|
|
16
27
|
Array.from(selectedOptions)
|
|
17
|
-
.map(({ value, text }) => value || text)
|
|
28
|
+
.map(({ value, text }) => (value || text) ?? '')
|
|
18
29
|
)
|
|
19
30
|
}
|
|
20
31
|
|
|
32
|
+
/**
|
|
33
|
+
* @param {{ target: { value?: string } }} event
|
|
34
|
+
* @returns {string}
|
|
35
|
+
*/
|
|
21
36
|
function getSelectedValue ({ target: { value } }) {
|
|
22
|
-
return value
|
|
37
|
+
return value ?? ''
|
|
23
38
|
}
|
|
24
39
|
|
|
40
|
+
/**
|
|
41
|
+
* @extends {ValueField<ValueProps & SelectProps>}
|
|
42
|
+
*/
|
|
25
43
|
export default class SelectField extends ValueField {
|
|
26
|
-
shouldComponentUpdate (props, state) {
|
|
27
|
-
return (
|
|
28
|
-
super.shouldComponentUpdate(props) ||
|
|
29
|
-
(props.multiple !== this.props.multiple) ||
|
|
30
|
-
(props.children !== this.props.children)
|
|
31
|
-
)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
44
|
getClassName () {
|
|
35
45
|
return classnames(super.getClassName(), 'select')
|
|
36
46
|
}
|
|
37
47
|
|
|
48
|
+
/**
|
|
49
|
+
* @param {SelectProps} props
|
|
50
|
+
* @returns {boolean}
|
|
51
|
+
*/
|
|
52
|
+
shouldComponentUpdate (props) {
|
|
53
|
+
const {
|
|
54
|
+
multiple,
|
|
55
|
+
children,
|
|
56
|
+
...superProps
|
|
57
|
+
} = props
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
super.shouldComponentUpdate(superProps) || // , state ||
|
|
61
|
+
(multiple !== this.props.multiple) ||
|
|
62
|
+
(children !== this.props.children)
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @overload
|
|
68
|
+
* @param {{ target: { selectedOptions: { value?: string, text?: string }[] } }} event
|
|
69
|
+
* @returns {void}
|
|
70
|
+
*
|
|
71
|
+
* @overload
|
|
72
|
+
* @param {{ target: { value?: string } }} event
|
|
73
|
+
* @returns {void}
|
|
74
|
+
*
|
|
75
|
+
* @param {any} event
|
|
76
|
+
* @returns {void}
|
|
77
|
+
*/
|
|
38
78
|
handleChange = (event) => {
|
|
39
79
|
const {
|
|
40
80
|
multiple = false,
|
|
41
|
-
onChange = DEFAULT_HANDLE_CHANGE
|
|
81
|
+
onChange = DEFAULT_HANDLE_CHANGE,
|
|
82
|
+
name
|
|
42
83
|
} = this.props
|
|
43
84
|
|
|
44
85
|
if (multiple) {
|
|
45
|
-
onChange(getSelectedValues(event))
|
|
86
|
+
onChange(name, getSelectedValues(event))
|
|
46
87
|
} else {
|
|
47
|
-
onChange(getSelectedValue(event))
|
|
88
|
+
onChange(name, getSelectedValue(event))
|
|
48
89
|
}
|
|
49
90
|
}
|
|
50
91
|
|
|
@@ -73,7 +114,7 @@ export default class SelectField extends ValueField {
|
|
|
73
114
|
value={value}
|
|
74
115
|
defaultValue={defaultValue}
|
|
75
116
|
required={required}
|
|
76
|
-
disabled={disabled}
|
|
117
|
+
disabled={disabled} // @ts-ignore
|
|
77
118
|
readOnly={readOnly}
|
|
78
119
|
tabIndex={tabIndex}
|
|
79
120
|
accessKey={accessKey}
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
declare module '#cogs/cogs/select' {
|
|
2
|
-
import
|
|
2
|
+
import {
|
|
3
|
+
ValueCog
|
|
4
|
+
} from '#cogs/cogs'
|
|
3
5
|
|
|
4
|
-
|
|
6
|
+
type SelectProps = CogsTypes.Cogs.Cog.Select.SelectProps
|
|
7
|
+
|
|
8
|
+
export default class SelectCog<P extends SelectProps> extends ValueCog<Omit<Omit<P, 'value'>, 'defaultValue'>> {
|
|
9
|
+
handleChange (
|
|
10
|
+
name: string,
|
|
11
|
+
value?: string | string[]
|
|
12
|
+
): void
|
|
13
|
+
}
|
|
5
14
|
}
|
|
6
15
|
|
|
7
16
|
declare module 'shinkansen-cogs/cogs/select' {
|
|
17
|
+
export type SelectProps = CogsTypes.Cogs.Cog.Select.SelectProps
|
|
18
|
+
|
|
8
19
|
export { default } from '#cogs/cogs/select'
|
|
9
20
|
}
|