@instructure/ui-form-field 8.8.1-snapshot.3 → 8.9.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/CHANGELOG.md +6 -0
- package/es/FormField/index.js +4 -31
- package/es/FormField/props.js +51 -0
- package/es/FormFieldGroup/index.js +3 -39
- package/es/FormFieldGroup/props.js +55 -0
- package/es/FormFieldLabel/index.js +3 -10
- package/{src/FormFieldMessage/types.ts → es/FormFieldLabel/props.js} +7 -8
- package/es/FormFieldLayout/index.js +4 -45
- package/es/FormFieldLayout/props.js +59 -0
- package/es/FormFieldMessage/index.js +3 -10
- package/{src/FormFieldLabel/types.ts → es/FormFieldMessage/props.js} +7 -9
- package/es/FormFieldMessages/index.js +4 -20
- package/{src/FormField/types.ts → es/FormFieldMessages/props.js} +13 -16
- package/lib/FormField/index.js +5 -35
- package/lib/FormField/props.js +63 -0
- package/lib/FormFieldGroup/index.js +4 -41
- package/lib/FormFieldGroup/props.js +67 -0
- package/lib/FormFieldLabel/index.js +4 -11
- package/{src/FormFieldLayout/types.ts → lib/FormFieldLabel/props.js} +18 -18
- package/lib/FormFieldLayout/index.js +5 -47
- package/lib/FormFieldLayout/props.js +71 -0
- package/lib/FormFieldMessage/index.js +4 -11
- package/lib/FormFieldMessage/props.js +41 -0
- package/lib/FormFieldMessages/index.js +5 -22
- package/lib/FormFieldMessages/props.js +48 -0
- package/package.json +15 -16
- package/src/FormField/index.tsx +6 -31
- package/src/FormField/props.ts +91 -0
- package/src/FormFieldGroup/index.tsx +6 -38
- package/src/FormFieldGroup/props.ts +98 -0
- package/src/FormFieldGroup/styles.ts +1 -1
- package/src/FormFieldLabel/index.tsx +7 -13
- package/src/{FormFieldGroup/types.ts → FormFieldLabel/props.ts} +20 -16
- package/src/FormFieldLabel/styles.ts +1 -1
- package/src/FormFieldLayout/index.tsx +8 -44
- package/src/FormFieldLayout/props.ts +97 -0
- package/src/FormFieldLayout/styles.ts +1 -1
- package/src/FormFieldMessage/index.tsx +6 -12
- package/src/FormFieldMessage/props.ts +50 -0
- package/src/FormFieldMessage/styles.ts +1 -1
- package/src/FormFieldMessages/index.tsx +8 -22
- package/src/FormFieldMessages/{types.ts → props.ts} +29 -4
- package/src/index.ts +6 -6
- package/types/FormField/index.d.ts +28 -32
- package/types/FormField/index.d.ts.map +1 -1
- package/types/FormField/props.d.ts +24 -0
- package/types/FormField/props.d.ts.map +1 -0
- package/types/FormFieldGroup/index.d.ts +27 -36
- package/types/FormFieldGroup/index.d.ts.map +1 -1
- package/types/FormFieldGroup/props.d.ts +28 -0
- package/types/FormFieldGroup/props.d.ts.map +1 -0
- package/types/FormFieldGroup/styles.d.ts +1 -1
- package/types/FormFieldLabel/index.d.ts +10 -9
- package/types/FormFieldLabel/index.d.ts.map +1 -1
- package/types/FormFieldLabel/props.d.ts +15 -0
- package/types/FormFieldLabel/props.d.ts.map +1 -0
- package/types/FormFieldLabel/styles.d.ts +1 -1
- package/types/FormFieldLayout/index.d.ts +33 -46
- package/types/FormFieldLayout/index.d.ts.map +1 -1
- package/types/FormFieldLayout/props.d.ts +25 -0
- package/types/FormFieldLayout/props.d.ts.map +1 -0
- package/types/FormFieldLayout/styles.d.ts +1 -1
- package/types/FormFieldMessage/index.d.ts +9 -8
- package/types/FormFieldMessage/index.d.ts.map +1 -1
- package/types/FormFieldMessage/props.d.ts +16 -0
- package/types/FormFieldMessage/props.d.ts.map +1 -0
- package/types/FormFieldMessage/styles.d.ts +1 -1
- package/types/FormFieldMessages/index.d.ts +4 -19
- package/types/FormFieldMessages/index.d.ts.map +1 -1
- package/types/FormFieldMessages/props.d.ts +14 -0
- package/types/FormFieldMessages/props.d.ts.map +1 -0
- package/types/index.d.ts +6 -6
- package/LICENSE.md +0 -27
- package/es/FormField/types.js +0 -1
- package/es/FormFieldGroup/types.js +0 -1
- package/es/FormFieldLabel/types.js +0 -1
- package/es/FormFieldLayout/types.js +0 -1
- package/es/FormFieldMessage/types.js +0 -1
- package/es/FormFieldMessages/types.js +0 -1
- package/lib/FormField/types.js +0 -1
- package/lib/FormFieldGroup/types.js +0 -1
- package/lib/FormFieldLabel/types.js +0 -1
- package/lib/FormFieldLayout/types.js +0 -1
- package/lib/FormFieldMessage/types.js +0 -1
- package/lib/FormFieldMessages/types.js +0 -1
- package/types/FormField/types.d.ts +0 -15
- package/types/FormField/types.d.ts.map +0 -1
- package/types/FormFieldGroup/types.d.ts +0 -21
- package/types/FormFieldGroup/types.d.ts.map +0 -1
- package/types/FormFieldLabel/types.d.ts +0 -8
- package/types/FormFieldLabel/types.d.ts.map +0 -1
- package/types/FormFieldLayout/types.d.ts +0 -18
- package/types/FormFieldLayout/types.d.ts.map +0 -1
- package/types/FormFieldMessage/types.d.ts +0 -7
- package/types/FormFieldMessage/types.d.ts.map +0 -1
- package/types/FormFieldMessages/types.d.ts +0 -7
- package/types/FormFieldMessages/types.d.ts.map +0 -1
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import React from 'react'
|
|
26
|
+
import PropTypes from 'prop-types'
|
|
27
|
+
|
|
28
|
+
import { FormPropTypes } from '../FormPropTypes'
|
|
29
|
+
|
|
30
|
+
import type { PropValidators } from '@instructure/shared-types'
|
|
31
|
+
import type { FormMessage } from '../FormPropTypes'
|
|
32
|
+
|
|
33
|
+
type FormFieldOwnProps = {
|
|
34
|
+
label: React.ReactNode
|
|
35
|
+
id: string
|
|
36
|
+
messages?: FormMessage[]
|
|
37
|
+
messagesId?: string
|
|
38
|
+
children?: React.ReactNode
|
|
39
|
+
inline?: boolean
|
|
40
|
+
layout?: 'stacked' | 'inline'
|
|
41
|
+
labelAlign?: 'start' | 'end'
|
|
42
|
+
vAlign?: 'top' | 'middle' | 'bottom'
|
|
43
|
+
width?: string
|
|
44
|
+
inputContainerRef?: (...args: any[]) => any
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
type PropKeys = keyof FormFieldOwnProps
|
|
48
|
+
|
|
49
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
50
|
+
|
|
51
|
+
type FormFieldProps = FormFieldOwnProps
|
|
52
|
+
|
|
53
|
+
const propTypes: PropValidators<PropKeys> = {
|
|
54
|
+
label: PropTypes.node.isRequired,
|
|
55
|
+
/**
|
|
56
|
+
* the id of the input (to link it to its label for a11y)
|
|
57
|
+
*/
|
|
58
|
+
id: PropTypes.string.isRequired,
|
|
59
|
+
/**
|
|
60
|
+
* object with shape: `{
|
|
61
|
+
* text: PropTypes.string,
|
|
62
|
+
* type: PropTypes.oneOf(['error', 'hint', 'success', 'screenreader-only'])
|
|
63
|
+
* }`
|
|
64
|
+
*/
|
|
65
|
+
messages: PropTypes.arrayOf(FormPropTypes.message),
|
|
66
|
+
messagesId: PropTypes.string,
|
|
67
|
+
children: PropTypes.node,
|
|
68
|
+
inline: PropTypes.bool,
|
|
69
|
+
layout: PropTypes.oneOf(['stacked', 'inline']),
|
|
70
|
+
labelAlign: PropTypes.oneOf(['start', 'end']),
|
|
71
|
+
vAlign: PropTypes.oneOf(['top', 'middle', 'bottom']),
|
|
72
|
+
width: PropTypes.string,
|
|
73
|
+
inputContainerRef: PropTypes.func
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const allowedProps: AllowedPropKeys = [
|
|
77
|
+
'label',
|
|
78
|
+
'id',
|
|
79
|
+
'messages',
|
|
80
|
+
'messagesId',
|
|
81
|
+
'children',
|
|
82
|
+
'inline',
|
|
83
|
+
'layout',
|
|
84
|
+
'labelAlign',
|
|
85
|
+
'vAlign',
|
|
86
|
+
'width',
|
|
87
|
+
'inputContainerRef'
|
|
88
|
+
]
|
|
89
|
+
|
|
90
|
+
export type { FormFieldProps }
|
|
91
|
+
export { propTypes, allowedProps }
|
|
@@ -24,18 +24,18 @@
|
|
|
24
24
|
|
|
25
25
|
/** @jsx jsx */
|
|
26
26
|
import { Component, Children } from 'react'
|
|
27
|
-
import PropTypes from 'prop-types'
|
|
28
27
|
|
|
29
28
|
import { Grid } from '@instructure/ui-grid'
|
|
30
29
|
import { pickProps, omitProps } from '@instructure/ui-react-utils'
|
|
31
30
|
import { withStyle, jsx } from '@instructure/emotion'
|
|
32
31
|
|
|
33
32
|
import { FormFieldLayout } from '../FormFieldLayout'
|
|
34
|
-
import { FormPropTypes } from '../FormPropTypes'
|
|
35
33
|
|
|
36
34
|
import generateStyle from './styles'
|
|
37
35
|
import generateComponentTheme from './theme'
|
|
38
|
-
|
|
36
|
+
|
|
37
|
+
import { propTypes, allowedProps } from './props'
|
|
38
|
+
import type { FormFieldGroupProps, FormFieldGroupStyleProps } from './props'
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
41
|
---
|
|
@@ -46,42 +46,10 @@ category: components
|
|
|
46
46
|
class FormFieldGroup extends Component<FormFieldGroupProps> {
|
|
47
47
|
static readonly componentId = 'FormFieldGroup'
|
|
48
48
|
|
|
49
|
-
static propTypes =
|
|
50
|
-
|
|
51
|
-
makeStyles: PropTypes.func,
|
|
52
|
-
// eslint-disable-next-line react/require-default-props
|
|
53
|
-
styles: PropTypes.object,
|
|
54
|
-
description: PropTypes.node.isRequired,
|
|
55
|
-
/**
|
|
56
|
-
* the element type to render as
|
|
57
|
-
*/
|
|
58
|
-
as: PropTypes.elementType,
|
|
59
|
-
/**
|
|
60
|
-
* object with shape: `{
|
|
61
|
-
* text: PropTypes.string,
|
|
62
|
-
* type: PropTypes.oneOf(['error', 'hint', 'success', 'screenreader-only'])
|
|
63
|
-
* }`
|
|
64
|
-
*/
|
|
65
|
-
messages: PropTypes.arrayOf(FormPropTypes.message),
|
|
66
|
-
/**
|
|
67
|
-
* id for the form field messages
|
|
68
|
-
*/
|
|
69
|
-
messagesId: PropTypes.string,
|
|
70
|
-
disabled: PropTypes.bool,
|
|
71
|
-
children: PropTypes.node,
|
|
72
|
-
layout: PropTypes.oneOf(['stacked', 'columns', 'inline']),
|
|
73
|
-
rowSpacing: PropTypes.oneOf(['none', 'small', 'medium', 'large']),
|
|
74
|
-
colSpacing: PropTypes.oneOf(['none', 'small', 'medium', 'large']),
|
|
75
|
-
vAlign: PropTypes.oneOf(['top', 'middle', 'bottom']),
|
|
76
|
-
startAt: PropTypes.oneOf(['small', 'medium', 'large', 'x-large', null])
|
|
77
|
-
}
|
|
78
|
-
|
|
49
|
+
static propTypes = propTypes
|
|
50
|
+
static allowedProps = allowedProps
|
|
79
51
|
static defaultProps = {
|
|
80
52
|
children: null,
|
|
81
|
-
layout: undefined,
|
|
82
|
-
startAt: undefined,
|
|
83
|
-
messages: undefined,
|
|
84
|
-
messagesId: undefined,
|
|
85
53
|
as: 'fieldset',
|
|
86
54
|
disabled: false,
|
|
87
55
|
rowSpacing: 'medium',
|
|
@@ -147,7 +115,7 @@ class FormFieldGroup extends Component<FormFieldGroupProps> {
|
|
|
147
115
|
const { styles } = this.props
|
|
148
116
|
|
|
149
117
|
return (
|
|
150
|
-
<span key="fields" css={styles
|
|
118
|
+
<span key="fields" css={styles?.formFieldGroup}>
|
|
151
119
|
{this.renderChildren()}
|
|
152
120
|
</span>
|
|
153
121
|
)
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import PropTypes from 'prop-types'
|
|
26
|
+
|
|
27
|
+
import { FormPropTypes } from '../FormPropTypes'
|
|
28
|
+
|
|
29
|
+
import type { AsElementType, PropValidators } from '@instructure/shared-types'
|
|
30
|
+
import type { WithStyleProps } from '@instructure/emotion'
|
|
31
|
+
import type { FormMessage } from '../FormPropTypes'
|
|
32
|
+
|
|
33
|
+
type FormFieldGroupOwnProps = {
|
|
34
|
+
description: React.ReactNode
|
|
35
|
+
as?: AsElementType
|
|
36
|
+
messages?: FormMessage[]
|
|
37
|
+
messagesId?: string
|
|
38
|
+
disabled?: boolean
|
|
39
|
+
children?: React.ReactNode
|
|
40
|
+
layout?: 'stacked' | 'columns' | 'inline'
|
|
41
|
+
rowSpacing?: 'none' | 'small' | 'medium' | 'large'
|
|
42
|
+
colSpacing?: 'none' | 'small' | 'medium' | 'large'
|
|
43
|
+
vAlign?: 'top' | 'middle' | 'bottom'
|
|
44
|
+
startAt?: any // TODO: PropTypes.oneOf(['small', 'medium', 'large', 'x-large', null])
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
type FormFieldGroupStyleProps = {
|
|
48
|
+
invalid: boolean
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type PropKeys = keyof FormFieldGroupOwnProps
|
|
52
|
+
|
|
53
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
54
|
+
|
|
55
|
+
type FormFieldGroupProps = FormFieldGroupOwnProps & WithStyleProps
|
|
56
|
+
|
|
57
|
+
const propTypes: PropValidators<PropKeys> = {
|
|
58
|
+
description: PropTypes.node.isRequired,
|
|
59
|
+
/**
|
|
60
|
+
* the element type to render as
|
|
61
|
+
*/
|
|
62
|
+
as: PropTypes.elementType,
|
|
63
|
+
/**
|
|
64
|
+
* object with shape: `{
|
|
65
|
+
* text: PropTypes.string,
|
|
66
|
+
* type: PropTypes.oneOf(['error', 'hint', 'success', 'screenreader-only'])
|
|
67
|
+
* }`
|
|
68
|
+
*/
|
|
69
|
+
messages: PropTypes.arrayOf(FormPropTypes.message),
|
|
70
|
+
/**
|
|
71
|
+
* id for the form field messages
|
|
72
|
+
*/
|
|
73
|
+
messagesId: PropTypes.string,
|
|
74
|
+
disabled: PropTypes.bool,
|
|
75
|
+
children: PropTypes.node,
|
|
76
|
+
layout: PropTypes.oneOf(['stacked', 'columns', 'inline']),
|
|
77
|
+
rowSpacing: PropTypes.oneOf(['none', 'small', 'medium', 'large']),
|
|
78
|
+
colSpacing: PropTypes.oneOf(['none', 'small', 'medium', 'large']),
|
|
79
|
+
vAlign: PropTypes.oneOf(['top', 'middle', 'bottom']),
|
|
80
|
+
startAt: PropTypes.oneOf(['small', 'medium', 'large', 'x-large', null])
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const allowedProps: AllowedPropKeys = [
|
|
84
|
+
'description',
|
|
85
|
+
'as',
|
|
86
|
+
'messages',
|
|
87
|
+
'messagesId',
|
|
88
|
+
'disabled',
|
|
89
|
+
'children',
|
|
90
|
+
'layout',
|
|
91
|
+
'rowSpacing',
|
|
92
|
+
'colSpacing',
|
|
93
|
+
'vAlign',
|
|
94
|
+
'startAt'
|
|
95
|
+
]
|
|
96
|
+
|
|
97
|
+
export type { FormFieldGroupProps, FormFieldGroupStyleProps }
|
|
98
|
+
export { propTypes, allowedProps }
|
|
@@ -24,14 +24,15 @@
|
|
|
24
24
|
|
|
25
25
|
/** @jsx jsx */
|
|
26
26
|
import { Component } from 'react'
|
|
27
|
-
import PropTypes from 'prop-types'
|
|
28
27
|
|
|
29
28
|
import { omitProps, getElementType } from '@instructure/ui-react-utils'
|
|
30
29
|
import { withStyle, jsx } from '@instructure/emotion'
|
|
31
30
|
|
|
32
31
|
import generateStyle from './styles'
|
|
33
32
|
import generateComponentTheme from './theme'
|
|
34
|
-
|
|
33
|
+
|
|
34
|
+
import { propTypes, allowedProps } from './props'
|
|
35
|
+
import type { FormFieldLabelProps } from './props'
|
|
35
36
|
|
|
36
37
|
/**
|
|
37
38
|
---
|
|
@@ -53,18 +54,11 @@ example: true
|
|
|
53
54
|
class FormFieldLabel extends Component<FormFieldLabelProps> {
|
|
54
55
|
static readonly componentId = 'FormFieldLabel'
|
|
55
56
|
|
|
56
|
-
static propTypes =
|
|
57
|
-
|
|
58
|
-
makeStyles: PropTypes.func,
|
|
59
|
-
// eslint-disable-next-line react/require-default-props
|
|
60
|
-
styles: PropTypes.object,
|
|
61
|
-
as: PropTypes.elementType,
|
|
62
|
-
children: PropTypes.node.isRequired
|
|
63
|
-
}
|
|
64
|
-
|
|
57
|
+
static propTypes = propTypes
|
|
58
|
+
static allowedProps = allowedProps
|
|
65
59
|
static defaultProps = {
|
|
66
60
|
as: 'span'
|
|
67
|
-
}
|
|
61
|
+
} as const
|
|
68
62
|
|
|
69
63
|
componentDidMount() {
|
|
70
64
|
// @ts-expect-error ts-migrate(2722) FIXME: Cannot invoke an object which is possibly 'undefin... Remove this comment to see the full error message
|
|
@@ -85,7 +79,7 @@ class FormFieldLabel extends Component<FormFieldLabelProps> {
|
|
|
85
79
|
return (
|
|
86
80
|
<ElementType
|
|
87
81
|
{...omitProps(this.props, FormFieldLabel.propTypes)}
|
|
88
|
-
css={styles
|
|
82
|
+
css={styles?.formFieldLabel}
|
|
89
83
|
>
|
|
90
84
|
{children}
|
|
91
85
|
</ElementType>
|
|
@@ -22,24 +22,28 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
import
|
|
26
|
-
import { FormMessage } from '../FormPropTypes'
|
|
25
|
+
import PropTypes from 'prop-types'
|
|
27
26
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
import type { AsElementType, PropValidators } from '@instructure/shared-types'
|
|
28
|
+
import type { WithStyleProps } from '@instructure/emotion'
|
|
29
|
+
|
|
30
|
+
type FormFieldLabelOwnProps = {
|
|
32
31
|
as?: AsElementType
|
|
33
|
-
|
|
34
|
-
messagesId?: string
|
|
35
|
-
disabled?: boolean
|
|
36
|
-
layout?: 'stacked' | 'columns' | 'inline'
|
|
37
|
-
rowSpacing?: 'none' | 'small' | 'medium' | 'large'
|
|
38
|
-
colSpacing?: 'none' | 'small' | 'medium' | 'large'
|
|
39
|
-
vAlign?: 'top' | 'middle' | 'bottom'
|
|
40
|
-
startAt?: any // TODO: PropTypes.oneOf(['small', 'medium', 'large', 'x-large', null])
|
|
32
|
+
children: React.ReactNode
|
|
41
33
|
}
|
|
42
34
|
|
|
43
|
-
|
|
44
|
-
|
|
35
|
+
type PropKeys = keyof FormFieldLabelOwnProps
|
|
36
|
+
|
|
37
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
38
|
+
|
|
39
|
+
type FormFieldLabelProps = FormFieldLabelOwnProps & WithStyleProps
|
|
40
|
+
|
|
41
|
+
const propTypes: PropValidators<PropKeys> = {
|
|
42
|
+
as: PropTypes.elementType,
|
|
43
|
+
children: PropTypes.node.isRequired
|
|
45
44
|
}
|
|
45
|
+
|
|
46
|
+
const allowedProps: AllowedPropKeys = ['as', 'children']
|
|
47
|
+
|
|
48
|
+
export type { FormFieldLabelProps }
|
|
49
|
+
export { propTypes, allowedProps }
|
|
@@ -24,7 +24,6 @@
|
|
|
24
24
|
|
|
25
25
|
/** @jsx jsx */
|
|
26
26
|
import { Component } from 'react'
|
|
27
|
-
import PropTypes from 'prop-types'
|
|
28
27
|
|
|
29
28
|
import { hasVisibleChildren } from '@instructure/ui-a11y-utils'
|
|
30
29
|
import { ScreenReaderContent } from '@instructure/ui-a11y-content'
|
|
@@ -41,10 +40,11 @@ import { withStyle, jsx } from '@instructure/emotion'
|
|
|
41
40
|
|
|
42
41
|
import { FormFieldLabel } from '../FormFieldLabel'
|
|
43
42
|
import { FormFieldMessages } from '../FormFieldMessages'
|
|
44
|
-
import { FormPropTypes } from '../FormPropTypes'
|
|
45
43
|
|
|
46
44
|
import generateStyle from './styles'
|
|
47
|
-
|
|
45
|
+
|
|
46
|
+
import { propTypes, allowedProps } from './props'
|
|
47
|
+
import type { FormFieldLayoutProps } from './props'
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
50
|
---
|
|
@@ -55,51 +55,15 @@ parent: FormField
|
|
|
55
55
|
class FormFieldLayout extends Component<FormFieldLayoutProps> {
|
|
56
56
|
static readonly componentId = 'FormFieldLayout'
|
|
57
57
|
|
|
58
|
-
static propTypes =
|
|
59
|
-
|
|
60
|
-
makeStyles: PropTypes.func,
|
|
61
|
-
// eslint-disable-next-line react/require-default-props
|
|
62
|
-
styles: PropTypes.object,
|
|
63
|
-
label: PropTypes.node.isRequired,
|
|
64
|
-
/**
|
|
65
|
-
* the id of the input (to link it to its label for a11y)
|
|
66
|
-
*/
|
|
67
|
-
id: PropTypes.string,
|
|
68
|
-
/**
|
|
69
|
-
* the element type to render as
|
|
70
|
-
*/
|
|
71
|
-
as: PropTypes.elementType,
|
|
72
|
-
/**
|
|
73
|
-
* object with shape: `{
|
|
74
|
-
* text: PropTypes.string,
|
|
75
|
-
* type: PropTypes.oneOf(['error', 'hint', 'success', 'screenreader-only'])
|
|
76
|
-
* }`
|
|
77
|
-
*/
|
|
78
|
-
messages: PropTypes.arrayOf(FormPropTypes.message),
|
|
79
|
-
/**
|
|
80
|
-
* id for the form field messages
|
|
81
|
-
*/
|
|
82
|
-
messagesId: PropTypes.string,
|
|
83
|
-
children: PropTypes.node,
|
|
84
|
-
inline: PropTypes.bool,
|
|
85
|
-
layout: PropTypes.oneOf(['stacked', 'inline']),
|
|
86
|
-
labelAlign: PropTypes.oneOf(['start', 'end']),
|
|
87
|
-
width: PropTypes.string,
|
|
88
|
-
inputContainerRef: PropTypes.func
|
|
89
|
-
}
|
|
90
|
-
|
|
58
|
+
static propTypes = propTypes
|
|
59
|
+
static allowedProps = allowedProps
|
|
91
60
|
static defaultProps = {
|
|
92
|
-
id: undefined,
|
|
93
|
-
width: undefined,
|
|
94
|
-
messages: undefined,
|
|
95
|
-
messagesId: undefined,
|
|
96
61
|
children: null,
|
|
97
62
|
inline: false,
|
|
98
63
|
layout: 'stacked',
|
|
99
64
|
as: 'label',
|
|
100
|
-
labelAlign: 'end'
|
|
101
|
-
|
|
102
|
-
}
|
|
65
|
+
labelAlign: 'end'
|
|
66
|
+
} as const
|
|
103
67
|
|
|
104
68
|
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'props' implicitly has an 'any' type.
|
|
105
69
|
constructor(props) {
|
|
@@ -218,7 +182,7 @@ class FormFieldLayout extends Component<FormFieldLayoutProps> {
|
|
|
218
182
|
...FormFieldLayout.propTypes,
|
|
219
183
|
...Grid.propTypes
|
|
220
184
|
})}
|
|
221
|
-
css={styles
|
|
185
|
+
css={styles?.formFieldLayout}
|
|
222
186
|
style={{ width }}
|
|
223
187
|
// @ts-expect-error ts-migrate(2339) FIXME: Property '_messagesId' does not exist on type 'For... Remove this comment to see the full error message
|
|
224
188
|
aria-describedby={this.hasMessages ? this._messagesId : null}
|