@fluentui/react-field 9.0.0-alpha.9 → 9.0.0-beta.1
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/.swcrc +30 -0
- package/CHANGELOG.json +633 -1
- package/CHANGELOG.md +230 -2
- package/README.md +66 -1
- package/dist/index.d.ts +153 -80
- package/lib/Field.js.map +1 -1
- package/lib/components/Field/Field.js +13 -0
- package/lib/components/Field/Field.js.map +1 -0
- package/lib/components/Field/Field.types.js +1 -1
- package/lib/components/Field/Field.types.js.map +1 -1
- package/lib/components/Field/index.js +1 -0
- package/lib/components/Field/index.js.map +1 -1
- package/lib/components/Field/renderField.js +11 -9
- package/lib/components/Field/renderField.js.map +1 -1
- package/lib/components/Field/useField.js +32 -98
- package/lib/components/Field/useField.js.map +1 -1
- package/lib/components/Field/useFieldStyles.js +61 -76
- package/lib/components/Field/useFieldStyles.js.map +1 -1
- package/lib/contexts/FieldContext.js +5 -0
- package/lib/contexts/FieldContext.js.map +1 -0
- package/lib/contexts/index.js +4 -0
- package/lib/contexts/index.js.map +1 -0
- package/lib/contexts/useFieldContextValues.js +33 -0
- package/lib/contexts/useFieldContextValues.js.map +1 -0
- package/lib/contexts/useFieldControlProps.js +65 -0
- package/lib/contexts/useFieldControlProps.js.map +1 -0
- package/lib/index.js +4 -1
- package/lib/index.js.map +1 -1
- package/lib/util/makeDeprecatedField.js +68 -0
- package/lib/util/makeDeprecatedField.js.map +1 -0
- package/lib-commonjs/Field.js +4 -5
- package/lib-commonjs/Field.js.map +1 -1
- package/lib-commonjs/components/Field/Field.js +23 -0
- package/lib-commonjs/components/Field/Field.js.map +1 -0
- package/lib-commonjs/components/Field/Field.types.js +5 -2
- package/lib-commonjs/components/Field/Field.types.js.map +1 -1
- package/lib-commonjs/components/Field/index.js +8 -11
- package/lib-commonjs/components/Field/index.js.map +1 -1
- package/lib-commonjs/components/Field/renderField.js +19 -26
- package/lib-commonjs/components/Field/renderField.js.map +1 -1
- package/lib-commonjs/components/Field/useField.js +71 -155
- package/lib-commonjs/components/Field/useField.js.map +1 -1
- package/lib-commonjs/components/Field/useFieldStyles.js +138 -118
- package/lib-commonjs/components/Field/useFieldStyles.js.map +1 -1
- package/lib-commonjs/contexts/FieldContext.js +21 -0
- package/lib-commonjs/contexts/FieldContext.js.map +1 -0
- package/lib-commonjs/contexts/index.js +11 -0
- package/lib-commonjs/contexts/index.js.map +1 -0
- package/lib-commonjs/contexts/useFieldContextValues.js +44 -0
- package/lib-commonjs/contexts/useFieldContextValues.js.map +1 -0
- package/lib-commonjs/contexts/useFieldControlProps.js +71 -0
- package/lib-commonjs/contexts/useFieldControlProps.js.map +1 -0
- package/lib-commonjs/index.js +24 -29
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/util/makeDeprecatedField.js +61 -0
- package/lib-commonjs/util/makeDeprecatedField.js.map +1 -0
- package/package.json +14 -11
- package/Spec.md +0 -354
- package/lib/components/Field/SlotComponent.types.js +0 -2
- package/lib/components/Field/SlotComponent.types.js.map +0 -1
- package/lib-amd/Field.js +0 -6
- package/lib-amd/Field.js.map +0 -1
- package/lib-amd/components/Field/Field.types.js +0 -5
- package/lib-amd/components/Field/Field.types.js.map +0 -1
- package/lib-amd/components/Field/SlotComponent.types.js +0 -5
- package/lib-amd/components/Field/SlotComponent.types.js.map +0 -1
- package/lib-amd/components/Field/index.js +0 -9
- package/lib-amd/components/Field/index.js.map +0 -1
- package/lib-amd/components/Field/renderField.js +0 -20
- package/lib-amd/components/Field/renderField.js.map +0 -1
- package/lib-amd/components/Field/useField.js +0 -121
- package/lib-amd/components/Field/useField.js.map +0 -1
- package/lib-amd/components/Field/useFieldStyles.js +0 -97
- package/lib-amd/components/Field/useFieldStyles.js.map +0 -1
- package/lib-amd/index.js +0 -10
- package/lib-amd/index.js.map +0 -1
- package/lib-commonjs/components/Field/SlotComponent.types.js +0 -6
- package/lib-commonjs/components/Field/SlotComponent.types.js.map +0 -1
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../lib/util/makeDeprecatedField.js"],"sourcesContent":["/* eslint-disable deprecation/deprecation */import * as React from 'react';\nimport { Field, fieldClassNames } from '../Field';\n/**\n * Partition the props used by the Field itself, from the props that are passed to the underlying field component.\n */\nfunction getPartitionedFieldProps(props) {\n const {\n className,\n control,\n hint,\n label,\n orientation,\n required,\n root,\n size,\n style,\n validationMessage,\n validationMessageIcon,\n validationState = 'none',\n ...restOfProps\n } = props;\n return [{\n className,\n hint,\n label,\n orientation,\n required,\n size,\n style,\n validationMessage,\n validationMessageIcon,\n validationState,\n ...root\n }, {\n required,\n size,\n ...restOfProps,\n ...control\n }];\n}\n/**\n * @deprecated Only for use to make deprecated [Control]Field shim components.\n * @internal\n */\nexport function makeDeprecatedField(Control, options = {}) {\n const {\n mapProps = props => props,\n displayName = `${Control.displayName}Field`\n } = options;\n const DeprecatedField = /*#__PURE__*/React.forwardRef((props, ref) => {\n const [fieldProps, controlProps] = getPartitionedFieldProps(mapProps(props));\n return /*#__PURE__*/React.createElement(Field, fieldProps, /*#__PURE__*/React.createElement(Control, {\n ...controlProps,\n ref: ref\n }));\n });\n DeprecatedField.displayName = displayName;\n return DeprecatedField;\n}\n/**\n * @deprecated Only for use to make deprecated [Control]Field shim components.\n * @internal\n */\nexport const getDeprecatedFieldClassNames = controlRootClassName => ({\n ...fieldClassNames,\n control: controlRootClassName\n});\n//# sourceMappingURL=makeDeprecatedField.js.map"],"names":["makeDeprecatedField","getDeprecatedFieldClassNames","getPartitionedFieldProps","props","className","control","hint","label","orientation","required","root","size","style","validationMessage","validationMessageIcon","validationState","restOfProps","Control","options","mapProps","displayName","DeprecatedField","React","forwardRef","ref","fieldProps","controlProps","createElement","Field","controlRootClassName","fieldClassNames"],"mappings":"AAAA,0CAA0C;;;;;;;;;;;IA4C1BA,mBAAmB,MAAnBA;IAmBHC,4BAA4B,MAA5BA;;;6DA/DsD;uBAC5B;AACvC;;CAEC,GACD,SAASC,yBAAyBC,KAAK,EAAE;IACvC,MAAM,EACJC,UAAS,EACTC,QAAO,EACPC,KAAI,EACJC,MAAK,EACLC,YAAW,EACXC,SAAQ,EACRC,KAAI,EACJC,KAAI,EACJC,MAAK,EACLC,kBAAiB,EACjBC,sBAAqB,EACrBC,iBAAkB,OAAM,EACxB,GAAGC,aACJ,GAAGb;IACJ,OAAO;QAAC;YACNC;YACAE;YACAC;YACAC;YACAC;YACAE;YACAC;YACAC;YACAC;YACAC;YACA,GAAGL,IAAI;QACT;QAAG;YACDD;YACAE;YACA,GAAGK,WAAW;YACd,GAAGX,OAAO;QACZ;KAAE;AACJ;AAKO,SAASL,oBAAoBiB,OAAO,EAAEC,UAAU,CAAC,CAAC,EAAE;IACzD,MAAM,EACJC,UAAWhB,CAAAA,QAASA,MAAK,EACzBiB,aAAc,CAAC,EAAEH,QAAQG,WAAW,CAAC,KAAK,CAAC,CAAA,EAC5C,GAAGF;IACJ,MAAMG,kBAAkB,WAAW,GAAEC,OAAMC,UAAU,CAAC,CAACpB,OAAOqB,MAAQ;QACpE,MAAM,CAACC,YAAYC,aAAa,GAAGxB,yBAAyBiB,SAAShB;QACrE,OAAO,WAAW,GAAEmB,OAAMK,aAAa,CAACC,YAAK,EAAEH,YAAY,WAAW,GAAEH,OAAMK,aAAa,CAACV,SAAS;YACnG,GAAGS,YAAY;YACfF,KAAKA;QACP;IACF;IACAH,gBAAgBD,WAAW,GAAGA;IAC9B,OAAOC;AACT;AAKO,MAAMpB,+BAA+B4B,CAAAA,uBAAyB,CAAA;QACnE,GAAGC,sBAAe;QAClBzB,SAASwB;IACX,CAAA,GACA,+CAA+C"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@fluentui/react-field",
|
3
|
-
"version": "9.0.0-
|
3
|
+
"version": "9.0.0-beta.1",
|
4
4
|
"description": "Fluent UI Field components",
|
5
5
|
"main": "lib-commonjs/index.js",
|
6
6
|
"module": "lib/index.js",
|
@@ -13,6 +13,7 @@
|
|
13
13
|
"license": "MIT",
|
14
14
|
"scripts": {
|
15
15
|
"build": "just-scripts build",
|
16
|
+
"bundle-size": "bundle-size measure",
|
16
17
|
"clean": "just-scripts clean",
|
17
18
|
"code-style": "just-scripts code-style",
|
18
19
|
"just": "just-scripts",
|
@@ -21,22 +22,23 @@
|
|
21
22
|
"storybook": "start-storybook",
|
22
23
|
"test": "jest --passWithNoTests",
|
23
24
|
"type-check": "tsc -b tsconfig.json",
|
24
|
-
"generate-api": "
|
25
|
+
"generate-api": "just-scripts generate-api"
|
25
26
|
},
|
26
27
|
"devDependencies": {
|
27
28
|
"@fluentui/eslint-plugin": "*",
|
28
29
|
"@fluentui/react-conformance": "*",
|
29
|
-
"@fluentui/react-conformance-griffel": "9.0.0-beta.
|
30
|
-
"@fluentui/scripts": "
|
30
|
+
"@fluentui/react-conformance-griffel": "9.0.0-beta.20",
|
31
|
+
"@fluentui/scripts-api-extractor": "*",
|
32
|
+
"@fluentui/scripts-tasks": "*"
|
31
33
|
},
|
32
34
|
"dependencies": {
|
33
|
-
"@fluentui/react-context-selector": "^9.1.
|
34
|
-
"@fluentui/react-icons": "^2.0.
|
35
|
-
"@fluentui/react-label": "^9.
|
36
|
-
"@fluentui/react-theme": "^9.1.
|
37
|
-
"@fluentui/react-utilities": "^9.
|
38
|
-
"@griffel/react": "^1.
|
39
|
-
"
|
35
|
+
"@fluentui/react-context-selector": "^9.1.16",
|
36
|
+
"@fluentui/react-icons": "^2.0.196",
|
37
|
+
"@fluentui/react-label": "^9.1.7",
|
38
|
+
"@fluentui/react-theme": "^9.1.7",
|
39
|
+
"@fluentui/react-utilities": "^9.7.3",
|
40
|
+
"@griffel/react": "^1.5.2",
|
41
|
+
"@swc/helpers": "^0.4.14"
|
40
42
|
},
|
41
43
|
"peerDependencies": {
|
42
44
|
"@types/react": ">=16.8.0 <19.0.0",
|
@@ -54,6 +56,7 @@
|
|
54
56
|
"exports": {
|
55
57
|
".": {
|
56
58
|
"types": "./dist/index.d.ts",
|
59
|
+
"node": "./lib-commonjs/index.js",
|
57
60
|
"import": "./lib/index.js",
|
58
61
|
"require": "./lib-commonjs/index.js"
|
59
62
|
},
|
package/Spec.md
DELETED
@@ -1,354 +0,0 @@
|
|
1
|
-
# @fluentui/react-field Spec
|
2
|
-
|
3
|
-
## Background
|
4
|
-
|
5
|
-
Field adds a label, validation text, and hint text to form input components. The existing input components (such as `Input` and `Combobox`) are wrapped to create field versions of them (such as `InputField` and `ComboboxField`).
|
6
|
-
|
7
|
-
Epic issue tracking implementation: https://github.com/microsoft/fluentui/issues/19627
|
8
|
-
|
9
|
-
## Prior Art
|
10
|
-
|
11
|
-
Existing libraries tend to take one of the following approaches to field.
|
12
|
-
|
13
|
-
1. Include support for label, error text, etc. in the base input component. Libraries using this approach include:
|
14
|
-
- **FluentUI v8** - [`TextField`](https://developer.microsoft.com/en-us/fluentui#/controls/web/textfield), [`Dropdown`](https://developer.microsoft.com/en-us/fluentui#/controls/web/dropdown), [`ChoiceGroup`](https://developer.microsoft.com/en-us/fluentui#/controls/web/choicegroup), etc.
|
15
|
-
- **Spectrum** - [`TextField`](https://react-spectrum.adobe.com/react-spectrum/TextField.html), [`Slider`](https://react-spectrum.adobe.com/react-spectrum/Slider.html), [`RadioGroup`](https://react-spectrum.adobe.com/react-spectrum/RadioGroup.html), etc.
|
16
|
-
2. Provide a set of components that are manually constructed into a field. This requires manually hooking up the components using props like `htmlFor` and `aria-describedby`. Libraries using this approach include:
|
17
|
-
- **FluentUI v0** - [`FormField`](https://fluentsite.z22.web.core.windows.net/0.64.0/components/form/props#form-field), [`FormLabel`](https://fluentsite.z22.web.core.windows.net/0.64.0/components/form/props#form-label), [`FormMessage`](https://fluentsite.z22.web.core.windows.net/0.64.0/components/form/props#form-message)
|
18
|
-
- **Ant** - [`Form.Item`](https://ant.design/components/form/#Form.Item) (uses context to do some of the hooking up between the item and the field component).
|
19
|
-
3. Provide base components without a label or descriptive text, and then Field versions of those controls. Libraries using this approach include:
|
20
|
-
- **FluentUI v0** - [`Input`](https://fluentsite.z22.web.core.windows.net/0.64.0/components/input/props) and [`FormInput`](https://fluentsite.z22.web.core.windows.net/0.64.0/components/form/props#form-input), for example.
|
21
|
-
- **Evergreen UI** - [`TextInput`](https://evergreen.segment.com/components/text-input) and [`TextInputField`](https://evergreen.segment.com/components/text-input#textinputfield), for example.
|
22
|
-
|
23
|
-
The Field implementation in this spec follows pattern (3). There are Field versions of all components that can be used as form inputs. There are several reasons, including:
|
24
|
-
|
25
|
-
- **Accessibility**: By combining a base component with the field props into a single component, all of the accessibility props like `htmlFor` and `aria-describedby` are set correctly for "free".
|
26
|
-
- **Simplicity**: All props related to the component (such as `label`, `id`, `validationState="error"`, etc.) are on the same component, rather than split between multiple components (like separate `Field` and `Input` components).
|
27
|
-
- **Consistency**: All of the Field components share a common set of props for the label, validationState, hint, etc.
|
28
|
-
- **Bundle size**: When the label and other field functionality is not needed, it is still possible to use the base components without pulling in unnecessary dependencies (like `Label` and the field styling).
|
29
|
-
|
30
|
-
## Sample Code
|
31
|
-
|
32
|
-
Each input component has a field version (such as `InputField`, `ComboboxField`, etc.) that includes the features of Field added to that component.
|
33
|
-
|
34
|
-
```jsx
|
35
|
-
<>
|
36
|
-
<InputField
|
37
|
-
// Field-specific props
|
38
|
-
label="This is the field label"
|
39
|
-
orientation="horizontal"
|
40
|
-
validationState="error"
|
41
|
-
validationMessage="This is error text"
|
42
|
-
// All props and slots of the underlying Input component are supported
|
43
|
-
required
|
44
|
-
size="small"
|
45
|
-
contentBefore="$"
|
46
|
-
contentAfter=".00"
|
47
|
-
/>
|
48
|
-
<RadioGroupField label="Radio group field">
|
49
|
-
<Radio value="one" label="Option one" />
|
50
|
-
<Radio value="two" label="Option two" />
|
51
|
-
<Radio value="three" label="Option three" />
|
52
|
-
</RadioGroupField>
|
53
|
-
<ComboboxField label="Combobox field" validationState="success" validationMessage="Success text">
|
54
|
-
<Option value="one">Option one</Option>
|
55
|
-
<Option value="two">Option two</Option>
|
56
|
-
<Option value="three">Option three</Option>
|
57
|
-
</ComboboxField>
|
58
|
-
<SliderField label="Slider field" validationState="warning" validationMessage="Warning text" />
|
59
|
-
<SpinButtonField label="Spin button field" hint="Hint text" />
|
60
|
-
</>
|
61
|
-
```
|
62
|
-
|
63
|
-
These field versions of the components use a common set of Field hooks, and can be defined using very little code.
|
64
|
-
|
65
|
-
```ts
|
66
|
-
export type InputFieldProps = FieldProps<typeof Input>;
|
67
|
-
|
68
|
-
export const InputField: ForwardRefComponent<InputFieldProps> = React.forwardRef((props, ref) => {
|
69
|
-
const state = useField_unstable(props, ref, Input);
|
70
|
-
useFieldStyles_unstable(state);
|
71
|
-
return renderField_unstable(state);
|
72
|
-
});
|
73
|
-
|
74
|
-
InputField.displayName = 'InputField';
|
75
|
-
```
|
76
|
-
|
77
|
-
## Components
|
78
|
-
|
79
|
-
The following field components will be defined. If more form components are added in the future, they should also include a Field version.
|
80
|
-
|
81
|
-
- `CheckboxField`
|
82
|
-
- `ComboboxField`
|
83
|
-
- `DropdownField`
|
84
|
-
- `InputField`
|
85
|
-
- `RadioGroupField`
|
86
|
-
- `SelectField`
|
87
|
-
- `SliderField`
|
88
|
-
- `SpinButtonField`
|
89
|
-
- `SwitchField`
|
90
|
-
- `TextareaField`
|
91
|
-
|
92
|
-
## Variants
|
93
|
-
|
94
|
-
- **Orientation**: The `orientation` prop affects the layout of the label and field component:
|
95
|
-
- `'vertical'` (default) - label is above the field component
|
96
|
-
- `'horizontal'` - label is to the left of the field component, and is 33% the width of the field (this allows multiple stacked fields to all align their labels)
|
97
|
-
- **Validation state**: The `validationState` prop affects the icon and color used by the `validationMessage`:
|
98
|
-
- `'error'` - Red x icon, red text color
|
99
|
-
- `'warning'` - Yellow exclamation icon, neutral color text
|
100
|
-
- `'success'` - Green check icon, neutral color text
|
101
|
-
- `undefined` (default): No validation message icon, neutral color text
|
102
|
-
- **Error**: Some control types (like `Input` and `Combobox`) have a prop that makes the border red. This prop will be set `validationState="error"`.
|
103
|
-
|
104
|
-
Field also forwards some props from the wrapped component to the label as well:
|
105
|
-
|
106
|
-
- **Size**: If the wrapped component supports a `size` prop, it will also be applied to the field's label.
|
107
|
-
- **Required**: If set, the Label will get a required asterisk: `*`
|
108
|
-
|
109
|
-
## API
|
110
|
-
|
111
|
-
### FieldComponent
|
112
|
-
|
113
|
-
The `FieldComponent` type defines the minimum set of props that the wrapped component must support. This is used for the generic types as the requirement for the type parameter: `FieldProps<T extends FieldComponent>`
|
114
|
-
|
115
|
-
```ts
|
116
|
-
/**
|
117
|
-
* The minimum requirement for a component used by Field.
|
118
|
-
*
|
119
|
-
* Note: the use of VoidFunctionComponent means that component is not *required* to have a children prop,
|
120
|
-
* but it is still allowed to have a children prop.
|
121
|
-
*/
|
122
|
-
export type FieldComponent = React.VoidFunctionComponent<
|
123
|
-
Pick<
|
124
|
-
React.HTMLAttributes<HTMLElement>,
|
125
|
-
'id' | 'className' | 'style' | 'aria-labelledby' | 'aria-describedby' | 'aria-invalid' | 'aria-errormessage'
|
126
|
-
>
|
127
|
-
>;
|
128
|
-
```
|
129
|
-
|
130
|
-
### Slots
|
131
|
-
|
132
|
-
_Note: TypeScript crashes if the `Slot` type is used with a template type parameter. The `SlotComponent` type is a simplified version of that type, which only supports `React.ComponentType`/`React.VoidFunctionComponent`._
|
133
|
-
|
134
|
-
```ts
|
135
|
-
export type FieldSlots<T extends FieldComponent> = {
|
136
|
-
root: NonNullable<Slot<'div'>>;
|
137
|
-
|
138
|
-
/**
|
139
|
-
* The underlying component wrapped by this field.
|
140
|
-
*
|
141
|
-
* This is the PRIMARY slot: all intrinsic HTML properties will be applied to this slot,
|
142
|
-
* except `className` and `style`, which remain on the root slot.
|
143
|
-
*/
|
144
|
-
control: SlotComponent<T>;
|
145
|
-
|
146
|
-
/**
|
147
|
-
* The label associated with the field.
|
148
|
-
*/
|
149
|
-
label?: Slot<typeof Label>;
|
150
|
-
|
151
|
-
/**
|
152
|
-
* A message about the validation state. The appearance of the `validationMessage` depends on `validationState`.
|
153
|
-
*/
|
154
|
-
validationMessage?: Slot<'span'>;
|
155
|
-
|
156
|
-
/**
|
157
|
-
* The icon associated with the `validationMessage`. If the `validationState` prop is set, this will default to an
|
158
|
-
* icon corresponding to that state.
|
159
|
-
*
|
160
|
-
* This will only be displayed if `validationMessage` is set.
|
161
|
-
*/
|
162
|
-
validationMessageIcon?: Slot<'span'>;
|
163
|
-
|
164
|
-
/**
|
165
|
-
* Additional hint text below the field.
|
166
|
-
*/
|
167
|
-
hint?: Slot<'span'>;
|
168
|
-
};
|
169
|
-
```
|
170
|
-
|
171
|
-
### Props
|
172
|
-
|
173
|
-
```ts
|
174
|
-
export type FieldProps<T extends FieldComponent> = ComponentProps<Partial<FieldSlots<T>>, 'control'> & {
|
175
|
-
/**
|
176
|
-
* The orientation of the label relative to the field component.
|
177
|
-
* This only affects the label, and not the validationMessage or hint (which always appear below the field component).
|
178
|
-
*
|
179
|
-
* @default vertical
|
180
|
-
*/
|
181
|
-
orientation?: 'vertical' | 'horizontal';
|
182
|
-
|
183
|
-
/**
|
184
|
-
* The `validationState` affects the color of the `validationMessage`, the `validationMessageIcon`, and for some
|
185
|
-
* field components, an `validationState="error"` causes the border to become red.
|
186
|
-
*
|
187
|
-
* @default undefined
|
188
|
-
*/
|
189
|
-
validationState?: 'error' | 'warning' | 'success';
|
190
|
-
};
|
191
|
-
```
|
192
|
-
|
193
|
-
Field also reads some props from the underlying component. These are not part of `FieldProps` because they are not added to the components that don't support them. However, they are accepted by `useField`:
|
194
|
-
|
195
|
-
```ts
|
196
|
-
/**
|
197
|
-
* Props that are supported by Field, but not required to be supported by the component that implements field.
|
198
|
-
*/
|
199
|
-
export type OptionalFieldComponentProps = {
|
200
|
-
/**
|
201
|
-
* Whether the field label should be marked as required.
|
202
|
-
*/
|
203
|
-
required?: boolean;
|
204
|
-
|
205
|
-
/**
|
206
|
-
* Size of the field label.
|
207
|
-
*
|
208
|
-
* Number sizes will be ignored, but are allowed because the HTML <input> element has a `size` prop of type `number`.
|
209
|
-
*/
|
210
|
-
size?: 'small' | 'medium' | 'large' | number;
|
211
|
-
};
|
212
|
-
```
|
213
|
-
|
214
|
-
### State
|
215
|
-
|
216
|
-
```ts
|
217
|
-
export type FieldState<T extends FieldComponent> = ComponentState<Required<FieldSlots<T>>> &
|
218
|
-
Pick<FieldProps<T>, 'orientation' | 'validationState'> & {
|
219
|
-
classNames: SlotClassNames<FieldSlots<T>>;
|
220
|
-
};
|
221
|
-
```
|
222
|
-
|
223
|
-
### Label for Checkbox and Switch
|
224
|
-
|
225
|
-
The Checkbox and Switch components already have a `label` prop, which conflicts with the Field's `label`.
|
226
|
-
|
227
|
-
#### `CheckboxField`
|
228
|
-
|
229
|
-
- The `label` prop will go to the Checkbox and NOT the Field
|
230
|
-
- New `fieldLabel` prop for the label of the Field
|
231
|
-
|
232
|
-
#### `SwitchField`
|
233
|
-
|
234
|
-
- The `label` prop will go to the Field and NOT the Switch
|
235
|
-
- The Switch's `labelPosition` prop is therefore not supported, and is omitted from SwitchField.
|
236
|
-
|
237
|
-
## Structure
|
238
|
-
|
239
|
-
### Public API
|
240
|
-
|
241
|
-
```jsx
|
242
|
-
<InputField
|
243
|
-
label="This is the field label"
|
244
|
-
orientation="horizontal"
|
245
|
-
validationState="error"
|
246
|
-
validationMessage="This is a validation message"
|
247
|
-
hint="This is a hint message"
|
248
|
-
/>
|
249
|
-
```
|
250
|
-
|
251
|
-
(similar API for other Field components)
|
252
|
-
|
253
|
-
### Slot structure
|
254
|
-
|
255
|
-
```jsx
|
256
|
-
<slots.root>
|
257
|
-
<slots.label {...slotProps.label} />
|
258
|
-
<slots.control {...slotProps.control} />
|
259
|
-
<slots.validationMessage {...slotProps.validationMessage}>
|
260
|
-
<slots.validationMessageIcon {...slotProps.validationMessageIcon} />
|
261
|
-
{slotProps.validationMessage.children}
|
262
|
-
</slots.validationMessage>
|
263
|
-
<slots.hint {...slotProps.hint} />
|
264
|
-
</slots.root>
|
265
|
-
```
|
266
|
-
|
267
|
-
### DOM structure
|
268
|
-
|
269
|
-
```html
|
270
|
-
<div className="fui-Field">
|
271
|
-
<label className="fui-Field__label fui-Label">This is the field label</label>
|
272
|
-
<!-- wrapped field component goes here -->
|
273
|
-
<span className="fui-Field__validationMessage">
|
274
|
-
<span className="fui-Field__validationMessageIcon"><svg>...</svg></span>
|
275
|
-
This is a validation message
|
276
|
-
</span>
|
277
|
-
<span className="fui-Field__hint">This is a hint message</span>
|
278
|
-
</div>
|
279
|
-
```
|
280
|
-
|
281
|
-
## Migration
|
282
|
-
|
283
|
-
### Migration from v8
|
284
|
-
|
285
|
-
Migration from v8 will require picking between the normal and `Field` version of an input control, depending on whether the field-specific features are required: (`label`, `validationState="error"`, `validationMessage`, `hint`)
|
286
|
-
|
287
|
-
See individual input components for more detailed migration guides.
|
288
|
-
|
289
|
-
| v8 Control | v9 Base control | v9 Field control | Notes |
|
290
|
-
| ------------- | --------------------- | ------------------------------- | -------------------------------------------------------------------------------------------- |
|
291
|
-
| `Checkbox` | `Checkbox` | `CheckboxField` | Only use `CheckboxField` if an error message is needed, or if required for layout in a form. |
|
292
|
-
| `ChoiceGroup` | `RadioGroup` | `RadioGroupField` | |
|
293
|
-
| `ComboBox` | `Combobox` | `ComboboxField` | `errorMessage="..."` is replaced by `validationState="error" validationMessage="..."` |
|
294
|
-
| `Dropdown` | `Dropdown` | `DropdownField` | `errorMessage="..."` is replaced by `validationState="error" validationMessage="..."` |
|
295
|
-
| `Slider` | `Slider` | `SliderField` | |
|
296
|
-
| `SpinButton` | `SpinButton` | `SpinButtonField` | |
|
297
|
-
| `TextField` | `Input` OR `Textarea` | `InputField` OR `TextareaField` | `errorMessage="..."` is replaced by `validationState="error" validationMessage="..."` |
|
298
|
-
| `Toggle` | `Switch` | `SwitchField` | |
|
299
|
-
|
300
|
-
### Migration from v0
|
301
|
-
|
302
|
-
Many components in v0 have `Form___` versions (such as `FormInput`). Those are replaced by the `___Field` equivalent. See the underlying component's migration guides for more detailed migration information.
|
303
|
-
|
304
|
-
Component mapping:
|
305
|
-
|
306
|
-
- `FormButton` => Not supported
|
307
|
-
- `FormCheckbox` => `CheckboxField` OR `SwitchField`
|
308
|
-
- `FormDatepicker` => _(Not yet implemented)_
|
309
|
-
- `FormDropdown` => `DropdownField`
|
310
|
-
- `FormField` => Not supported
|
311
|
-
- `FormFieldCustom` => Not supported
|
312
|
-
- `FormLabel` => The `label` prop of the field component
|
313
|
-
- `FormMessage` => Either the `validationMessage` or `hint` prop of the field component
|
314
|
-
- `FormRadioGroup` => `RadioGroupField`
|
315
|
-
- `FormSlider` => `SliderField`
|
316
|
-
- `FormTextArea` => `TextareaField`
|
317
|
-
|
318
|
-
The following props are common to each of the `Form___` components:
|
319
|
-
|
320
|
-
- `label` => `label`
|
321
|
-
- `message` => either `validationMessage` or `hint`
|
322
|
-
- `errorMessage` => `validationMessage` with `validationState="error"`
|
323
|
-
|
324
|
-
## Behaviors
|
325
|
-
|
326
|
-
### Form validation
|
327
|
-
|
328
|
-
Field has no logic to perform input validation. It is expected that the validation will be done externally (possibly using a third party form validation library like Formik).
|
329
|
-
|
330
|
-
### Interaction
|
331
|
-
|
332
|
-
The Field itself is not interactive. The wrapped component has the same interactions as it does outside of a field.
|
333
|
-
|
334
|
-
## Accessibility
|
335
|
-
|
336
|
-
- **ARIA pattern**
|
337
|
-
- Field itself does not implement a defined ARIA pattern. It has no role applied to the root element.
|
338
|
-
- **Attributes**
|
339
|
-
- The following are applied on the wrapped component:
|
340
|
-
- `aria-labelledby={label.id}`, if the label is present.
|
341
|
-
- `aria-describedby` is set to one of:
|
342
|
-
- `aria-describedby={validationMessage.id}`, if validationMessage is present, and _only if_ `validationState !== 'error'`
|
343
|
-
- `aria-describedby={hint.id}`, if hint is present
|
344
|
-
- `aria-describedby={validationMessage.id + ' ' + hint.id}`, if both conditions above apply
|
345
|
-
- `aria-errormessage={validationMessage.id}`, if validationMessage is present, and _only if_ `validationState === 'error'`
|
346
|
-
- `aria-invalid={true}`, _only if_ `validationState === 'error'`
|
347
|
-
- On the `label` slot:
|
348
|
-
- `htmlFor={control.id}` - the wrapped component's `id` (an ID is generated if not supplied via props).
|
349
|
-
- **Live regions** (state change announcements)
|
350
|
-
- TBD: Need to determine if the validation message should be an aria live region.
|
351
|
-
- **UI parts appearing on hover or focus**
|
352
|
-
- None.
|
353
|
-
- **Focus behavior**
|
354
|
-
- No special focus behavior: no focus trapping or programmatic focus moving.
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"SlotComponent.types.js","sourceRoot":"../src/","sources":["packages/react-components/react-field/src/components/Field/SlotComponent.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport type { SlotShorthandValue, SlotRenderFunction } from '@fluentui/react-utilities';\n\n//\n// TEMPORARY definition of the SlotComponent type, until it is available from react-utilities\n//\n\nexport type SlotComponent<Type extends React.ComponentType | React.VoidFunctionComponent> = WithSlotShorthandValue<\n Type extends React.ComponentType<infer Props>\n ? // If this is a VoidFunctionComponent that doesn't allow children, add { children?: never }\n WithSlotRenderFunction<Props extends { children?: unknown } ? Props : Props & { children?: never }>\n : never\n>;\n\n//\n// TEMPORARY copied versions of the non-exported helper types from react-utilities\n//\n\ntype WithSlotShorthandValue<Props extends { children?: unknown }> =\n | Props\n | Extract<SlotShorthandValue, Props['children']>;\n\ntype WithSlotRenderFunction<Props extends { children?: unknown }> = Props & {\n children?: Props['children'] | SlotRenderFunction<Props>;\n};\n"]}
|
package/lib-amd/Field.js
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
define(["require", "exports", "tslib", "./components/Field/index"], function (require, exports, tslib_1, index_1) {
|
2
|
-
"use strict";
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
-
tslib_1.__exportStar(index_1, exports);
|
5
|
-
});
|
6
|
-
//# sourceMappingURL=Field.js.map
|
package/lib-amd/Field.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"Field.js","sourceRoot":"","sources":["../../../../../../../packages/react-components/react-field/src/Field.ts"],"names":[],"mappings":";;;IAAA,uCAAyC","sourcesContent":["export * from './components/Field/index';\n"]}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"Field.types.js","sourceRoot":"","sources":["../../../../../../../../../packages/react-components/react-field/src/components/Field/Field.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport { Label } from '@fluentui/react-label';\nimport type { ComponentProps, ComponentState, Slot, SlotClassNames } from '@fluentui/react-utilities';\nimport type { SlotComponent } from './SlotComponent.types';\n\n/**\n * The minimum requirement for a component used by Field.\n *\n * Note: the use of VoidFunctionComponent means that component is not *required* to have a children prop,\n * but it is still allowed to have a children prop.\n */\nexport type FieldControl = React.VoidFunctionComponent<\n Pick<\n React.HTMLAttributes<HTMLElement>,\n 'id' | 'className' | 'style' | 'aria-labelledby' | 'aria-describedby' | 'aria-invalid' | 'aria-errormessage'\n >\n>;\n\n/**\n * Slots added by Field\n */\nexport type FieldSlots<T extends FieldControl> = {\n root: NonNullable<Slot<'div'>>;\n\n /**\n * The underlying component wrapped by this field.\n */\n control: SlotComponent<T>;\n\n /**\n * The label associated with the field.\n */\n label?: Slot<typeof Label>;\n\n /**\n * A message about the validation state. The appearance of the `validationMessage` depends on `validationState`.\n */\n validationMessage?: Slot<'div'>;\n\n /**\n * The icon associated with the `validationMessage`. If the `validationState` prop is set, this will default to an\n * icon corresponding to that state.\n *\n * This will only be displayed if `validationMessage` is set.\n */\n validationMessageIcon?: Slot<'span'>;\n\n /**\n * Additional hint text below the field.\n */\n hint?: Slot<'div'>;\n};\n\n/**\n * Field Props\n */\nexport type FieldProps<T extends FieldControl> = ComponentProps<Partial<FieldSlots<T>>, 'control'> & {\n /**\n * The orientation of the label relative to the field component.\n * This only affects the label, and not the validationMessage or hint (which always appear below the field component).\n *\n * @default vertical\n */\n orientation?: 'vertical' | 'horizontal';\n\n /**\n * The `validationState` affects the color of the `validationMessage`, the `validationMessageIcon`, and for some\n * field components, an `validationState=\"error\"` causes the border to become red.\n *\n * @default undefined\n */\n validationState?: 'error' | 'warning' | 'success';\n};\n\n/**\n * FieldProps plus extra optional props that are supported by useField_unstable, but not required to be part of the\n * API of every Field component.\n *\n * This allows Field to forward the required and size props to the label if the underlying component supports them,\n * but doesn't add them to the public API of fields that don't support them.\n */\nexport type FieldPropsWithOptionalComponentProps<T extends FieldControl> = FieldProps<T> & {\n /**\n * Whether the field label should be marked as required.\n */\n required?: boolean;\n\n /**\n * Size of the field label.\n *\n * Number sizes will be ignored, but are allowed because the HTML `<input>` element has a prop `size?: number`.\n */\n size?: 'small' | 'medium' | 'large' | number;\n};\n\n/**\n * Configuration parameters for a Field class, passed to useField_unstable\n */\nexport type FieldConfig<T extends FieldControl> = {\n /**\n * The underlying input component that this field is wrapping.\n */\n component: T;\n\n /**\n * Class names for this component, created by `getFieldClassNames`.\n */\n classNames: SlotClassNames<FieldSlots<T>>;\n\n /**\n * How the label be connected to the control.\n * * htmlFor - Set the Label's htmlFor prop to the component's ID (and generate an ID if not provided).\n * This is the preferred method for components that use the underlying <input> tag.\n * * aria-labelledby - Set the component's aria-labelledby prop to the Label's ID. Use this for components\n * that are not directly <input> elements (such as RadioGroup).\n *\n * @default htmlFor\n */\n labelConnection?: 'htmlFor' | 'aria-labelledby';\n\n /**\n * Should the aria-invalid and aria-errormessage attributes be set when validationState=\"error\".\n *\n * @default true\n */\n ariaInvalidOnError?: boolean;\n};\n\n/**\n * State used in rendering Field\n */\nexport type FieldState<T extends FieldControl> = ComponentState<Required<FieldSlots<T>>> &\n Pick<FieldProps<T>, 'orientation' | 'validationState'> & {\n classNames: SlotClassNames<FieldSlots<T>>;\n };\n"]}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"SlotComponent.types.js","sourceRoot":"","sources":["../../../../../../../../../packages/react-components/react-field/src/components/Field/SlotComponent.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport type { SlotShorthandValue, SlotRenderFunction } from '@fluentui/react-utilities';\n\n//\n// TEMPORARY definition of the SlotComponent type, until it is available from react-utilities\n//\n\nexport type SlotComponent<Type extends React.ComponentType | React.VoidFunctionComponent> = WithSlotShorthandValue<\n Type extends React.ComponentType<infer Props>\n ? // If this is a VoidFunctionComponent that doesn't allow children, add { children?: never }\n WithSlotRenderFunction<Props extends { children?: unknown } ? Props : Props & { children?: never }>\n : never\n>;\n\n//\n// TEMPORARY copied versions of the non-exported helper types from react-utilities\n//\n\ntype WithSlotShorthandValue<Props extends { children?: unknown }> =\n | Props\n | Extract<SlotShorthandValue, Props['children']>;\n\ntype WithSlotRenderFunction<Props extends { children?: unknown }> = Props & {\n children?: Props['children'] | SlotRenderFunction<Props>;\n};\n"]}
|
@@ -1,9 +0,0 @@
|
|
1
|
-
define(["require", "exports", "tslib", "./Field.types", "./renderField", "./useField", "./useFieldStyles"], function (require, exports, tslib_1, Field_types_1, renderField_1, useField_1, useFieldStyles_1) {
|
2
|
-
"use strict";
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
-
tslib_1.__exportStar(Field_types_1, exports);
|
5
|
-
tslib_1.__exportStar(renderField_1, exports);
|
6
|
-
tslib_1.__exportStar(useField_1, exports);
|
7
|
-
tslib_1.__exportStar(useFieldStyles_1, exports);
|
8
|
-
});
|
9
|
-
//# sourceMappingURL=index.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../../../packages/react-components/react-field/src/components/Field/index.ts"],"names":[],"mappings":";;;IAAA,6CAA8B;IAC9B,6CAA8B;IAC9B,0CAA2B;IAC3B,gDAAiC","sourcesContent":["export * from './Field.types';\nexport * from './renderField';\nexport * from './useField';\nexport * from './useFieldStyles';\n"]}
|
@@ -1,20 +0,0 @@
|
|
1
|
-
define(["require", "exports", "tslib", "react", "@fluentui/react-utilities"], function (require, exports, tslib_1, React, react_utilities_1) {
|
2
|
-
"use strict";
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
-
exports.renderField_unstable = void 0;
|
5
|
-
/**
|
6
|
-
* Render the final JSX of Field
|
7
|
-
*/
|
8
|
-
var renderField_unstable = function (state) {
|
9
|
-
var _a = react_utilities_1.getSlots(state), slots = _a.slots, slotProps = _a.slotProps;
|
10
|
-
return (React.createElement(slots.root, tslib_1.__assign({}, slotProps.root),
|
11
|
-
slots.label && React.createElement(slots.label, tslib_1.__assign({}, slotProps.label)),
|
12
|
-
slots.control && React.createElement(slots.control, tslib_1.__assign({}, slotProps.control)),
|
13
|
-
slots.validationMessage && (React.createElement(slots.validationMessage, tslib_1.__assign({}, slotProps.validationMessage),
|
14
|
-
slots.validationMessageIcon && React.createElement(slots.validationMessageIcon, tslib_1.__assign({}, slotProps.validationMessageIcon)),
|
15
|
-
slotProps.validationMessage.children)),
|
16
|
-
slots.hint && React.createElement(slots.hint, tslib_1.__assign({}, slotProps.hint))));
|
17
|
-
};
|
18
|
-
exports.renderField_unstable = renderField_unstable;
|
19
|
-
});
|
20
|
-
//# sourceMappingURL=renderField.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"renderField.js","sourceRoot":"","sources":["../../../../../../../../../packages/react-components/react-field/src/components/Field/renderField.tsx"],"names":[],"mappings":";;;;IAIA;;OAEG;IACI,IAAM,oBAAoB,GAAG,UAAyB,KAAoB;QACzE,IAAA,KAAuB,0BAAQ,CAA2B,KAAiC,CAAC,EAA1F,KAAK,WAAA,EAAE,SAAS,eAA0E,CAAC;QAEnG,OAAO,CACL,oBAAC,KAAK,CAAC,IAAI,uBAAK,SAAS,CAAC,IAAI;YAC3B,KAAK,CAAC,KAAK,IAAI,oBAAC,KAAK,CAAC,KAAK,uBAAK,SAAS,CAAC,KAAK,EAAI;YAEnD,KAAK,CAAC,OAAO,IAAI,oBAAC,KAAK,CAAC,OAAO,uBAAM,SAAS,CAAC,OAAe,EAAI;YAClE,KAAK,CAAC,iBAAiB,IAAI,CAC1B,oBAAC,KAAK,CAAC,iBAAiB,uBAAK,SAAS,CAAC,iBAAiB;gBACrD,KAAK,CAAC,qBAAqB,IAAI,oBAAC,KAAK,CAAC,qBAAqB,uBAAK,SAAS,CAAC,qBAAqB,EAAI;gBACnG,SAAS,CAAC,iBAAiB,CAAC,QAAQ,CACb,CAC3B;YACA,KAAK,CAAC,IAAI,IAAI,oBAAC,KAAK,CAAC,IAAI,uBAAK,SAAS,CAAC,IAAI,EAAI,CACtC,CACd,CAAC;IACJ,CAAC,CAAC;IAjBW,QAAA,oBAAoB,wBAiB/B","sourcesContent":["import * as React from 'react';\nimport { getSlots } from '@fluentui/react-utilities';\nimport type { FieldControl, FieldSlots, FieldState } from './Field.types';\n\n/**\n * Render the final JSX of Field\n */\nexport const renderField_unstable = <T extends FieldControl>(state: FieldState<T>) => {\n const { slots, slotProps } = getSlots<FieldSlots<FieldControl>>(state as FieldState<FieldControl>);\n\n return (\n <slots.root {...slotProps.root}>\n {slots.label && <slots.label {...slotProps.label} />}\n {/* eslint-disable-next-line @typescript-eslint/no-explicit-any */}\n {slots.control && <slots.control {...(slotProps.control as any)} />}\n {slots.validationMessage && (\n <slots.validationMessage {...slotProps.validationMessage}>\n {slots.validationMessageIcon && <slots.validationMessageIcon {...slotProps.validationMessageIcon} />}\n {slotProps.validationMessage.children}\n </slots.validationMessage>\n )}\n {slots.hint && <slots.hint {...slotProps.hint} />}\n </slots.root>\n );\n};\n"]}
|
@@ -1,121 +0,0 @@
|
|
1
|
-
define(["require", "exports", "tslib", "react", "@fluentui/react-icons", "@fluentui/react-label", "@fluentui/react-utilities"], function (require, exports, tslib_1, React, react_icons_1, react_label_1, react_utilities_1) {
|
2
|
-
"use strict";
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
-
exports.useField_unstable = exports.getPartitionedFieldProps = void 0;
|
5
|
-
var validationMessageIcons = {
|
6
|
-
error: React.createElement(react_icons_1.ErrorCircle12Filled, null),
|
7
|
-
warning: React.createElement(react_icons_1.Warning12Filled, null),
|
8
|
-
success: React.createElement(react_icons_1.CheckmarkCircle12Filled, null),
|
9
|
-
};
|
10
|
-
/**
|
11
|
-
* Partition the props used by the Field itself, from the props that are passed to the underlying field component.
|
12
|
-
*/
|
13
|
-
var getPartitionedFieldProps = function (props) {
|
14
|
-
var className = props.className, control = props.control, hint = props.hint, label = props.label, orientation = props.orientation, root = props.root, style = props.style, validationMessage = props.validationMessage, validationMessageIcon = props.validationMessageIcon, validationState = props.validationState, restOfProps = tslib_1.__rest(props, ["className", "control", "hint", "label", "orientation", "root", "style", "validationMessage", "validationMessageIcon", "validationState"]);
|
15
|
-
var fieldProps = {
|
16
|
-
className: className,
|
17
|
-
control: control,
|
18
|
-
hint: hint,
|
19
|
-
label: label,
|
20
|
-
orientation: orientation,
|
21
|
-
root: root,
|
22
|
-
style: style,
|
23
|
-
validationMessage: validationMessage,
|
24
|
-
validationMessageIcon: validationMessageIcon,
|
25
|
-
validationState: validationState,
|
26
|
-
};
|
27
|
-
return [fieldProps, restOfProps];
|
28
|
-
};
|
29
|
-
exports.getPartitionedFieldProps = getPartitionedFieldProps;
|
30
|
-
/**
|
31
|
-
* Create the state required to render Field.
|
32
|
-
*
|
33
|
-
* The returned state can be modified with hooks such as useFieldStyles_unstable,
|
34
|
-
* before being passed to renderField_unstable.
|
35
|
-
*
|
36
|
-
* @param props - Props passed to this field
|
37
|
-
* @param ref - Ref to the control slot (primary slot)
|
38
|
-
* @param params - Configuration parameters for this Field
|
39
|
-
*/
|
40
|
-
var useField_unstable = function (props, ref, params) {
|
41
|
-
var _a, _b, _c, _d, _e;
|
42
|
-
var _f = exports.getPartitionedFieldProps(props), fieldProps = _f[0], controlProps = _f[1];
|
43
|
-
var _g = fieldProps.orientation, orientation = _g === void 0 ? 'vertical' : _g, validationState = fieldProps.validationState;
|
44
|
-
var _h = params.labelConnection, labelConnection = _h === void 0 ? 'htmlFor' : _h, _j = params.ariaInvalidOnError, ariaInvalidOnError = _j === void 0 ? true : _j;
|
45
|
-
var baseId = react_utilities_1.useId('field-');
|
46
|
-
var root = react_utilities_1.resolveShorthand(fieldProps.root, {
|
47
|
-
required: true,
|
48
|
-
defaultProps: react_utilities_1.getNativeElementProps('div', fieldProps),
|
49
|
-
});
|
50
|
-
var control = react_utilities_1.resolveShorthand(fieldProps.control, {
|
51
|
-
required: true,
|
52
|
-
defaultProps: tslib_1.__assign({ ref: ref, id: baseId + '__control' }, controlProps),
|
53
|
-
});
|
54
|
-
var label = react_utilities_1.resolveShorthand(fieldProps.label, {
|
55
|
-
defaultProps: {
|
56
|
-
id: baseId + '__label',
|
57
|
-
required: controlProps.required,
|
58
|
-
size: typeof controlProps.size === 'string' ? controlProps.size : undefined,
|
59
|
-
htmlFor: labelConnection === 'htmlFor' ? control.id : undefined,
|
60
|
-
},
|
61
|
-
});
|
62
|
-
var validationMessage = react_utilities_1.resolveShorthand(fieldProps.validationMessage, {
|
63
|
-
defaultProps: {
|
64
|
-
id: baseId + '__validationMessage',
|
65
|
-
},
|
66
|
-
});
|
67
|
-
var hint = react_utilities_1.resolveShorthand(fieldProps.hint, {
|
68
|
-
defaultProps: {
|
69
|
-
id: baseId + '__hint',
|
70
|
-
},
|
71
|
-
});
|
72
|
-
var validationMessageIcon = react_utilities_1.resolveShorthand(fieldProps.validationMessageIcon, {
|
73
|
-
required: !!validationState,
|
74
|
-
defaultProps: {
|
75
|
-
children: validationState ? validationMessageIcons[validationState] : undefined,
|
76
|
-
},
|
77
|
-
});
|
78
|
-
// Hook up aria props on the control
|
79
|
-
if (label && labelConnection === 'aria-labelledby') {
|
80
|
-
(_a = control['aria-labelledby']) !== null && _a !== void 0 ? _a : (control['aria-labelledby'] = label.id);
|
81
|
-
}
|
82
|
-
if (validationState === 'error' && ariaInvalidOnError) {
|
83
|
-
(_b = control['aria-invalid']) !== null && _b !== void 0 ? _b : (control['aria-invalid'] = true);
|
84
|
-
if (validationMessage) {
|
85
|
-
(_c = control['aria-errormessage']) !== null && _c !== void 0 ? _c : (control['aria-errormessage'] = validationMessage.id);
|
86
|
-
}
|
87
|
-
if (hint) {
|
88
|
-
(_d = control['aria-describedby']) !== null && _d !== void 0 ? _d : (control['aria-describedby'] = hint.id);
|
89
|
-
}
|
90
|
-
}
|
91
|
-
else {
|
92
|
-
// If the state is not an error, then the control is described by the validation message, or hint, or both
|
93
|
-
var describedby = validationMessage || hint;
|
94
|
-
if (describedby) {
|
95
|
-
(_e = control['aria-describedby']) !== null && _e !== void 0 ? _e : (control['aria-describedby'] = validationMessage && hint ? validationMessage.id + " " + hint.id : describedby.id);
|
96
|
-
}
|
97
|
-
}
|
98
|
-
var state = {
|
99
|
-
orientation: orientation,
|
100
|
-
validationState: validationState,
|
101
|
-
classNames: params.classNames,
|
102
|
-
components: {
|
103
|
-
root: 'div',
|
104
|
-
control: params.component,
|
105
|
-
label: react_label_1.Label,
|
106
|
-
validationMessage: 'div',
|
107
|
-
validationMessageIcon: 'span',
|
108
|
-
hint: 'div',
|
109
|
-
},
|
110
|
-
root: root,
|
111
|
-
control: control,
|
112
|
-
label: label,
|
113
|
-
validationMessageIcon: validationMessageIcon,
|
114
|
-
validationMessage: validationMessage,
|
115
|
-
hint: hint,
|
116
|
-
};
|
117
|
-
return state;
|
118
|
-
};
|
119
|
-
exports.useField_unstable = useField_unstable;
|
120
|
-
});
|
121
|
-
//# sourceMappingURL=useField.js.map
|