@fluentui/react-field 9.0.0-alpha.8 → 9.0.0-beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. package/.swcrc +30 -0
  2. package/CHANGELOG.json +668 -1
  3. package/CHANGELOG.md +241 -2
  4. package/README.md +66 -1
  5. package/dist/index.d.ts +153 -80
  6. package/lib/Field.js.map +1 -1
  7. package/lib/components/Field/Field.js +13 -0
  8. package/lib/components/Field/Field.js.map +1 -0
  9. package/lib/components/Field/Field.types.js +1 -1
  10. package/lib/components/Field/Field.types.js.map +1 -1
  11. package/lib/components/Field/index.js +1 -0
  12. package/lib/components/Field/index.js.map +1 -1
  13. package/lib/components/Field/renderField.js +11 -9
  14. package/lib/components/Field/renderField.js.map +1 -1
  15. package/lib/components/Field/useField.js +32 -98
  16. package/lib/components/Field/useField.js.map +1 -1
  17. package/lib/components/Field/useFieldStyles.js +61 -76
  18. package/lib/components/Field/useFieldStyles.js.map +1 -1
  19. package/lib/contexts/FieldContext.js +5 -0
  20. package/lib/contexts/FieldContext.js.map +1 -0
  21. package/lib/contexts/index.js +4 -0
  22. package/lib/contexts/index.js.map +1 -0
  23. package/lib/contexts/useFieldContextValues.js +33 -0
  24. package/lib/contexts/useFieldContextValues.js.map +1 -0
  25. package/lib/contexts/useFieldControlProps.js +65 -0
  26. package/lib/contexts/useFieldControlProps.js.map +1 -0
  27. package/lib/index.js +4 -1
  28. package/lib/index.js.map +1 -1
  29. package/lib/util/makeDeprecatedField.js +68 -0
  30. package/lib/util/makeDeprecatedField.js.map +1 -0
  31. package/lib-commonjs/Field.js +4 -5
  32. package/lib-commonjs/Field.js.map +1 -1
  33. package/lib-commonjs/components/Field/Field.js +23 -0
  34. package/lib-commonjs/components/Field/Field.js.map +1 -0
  35. package/lib-commonjs/components/Field/Field.types.js +5 -2
  36. package/lib-commonjs/components/Field/Field.types.js.map +1 -1
  37. package/lib-commonjs/components/Field/index.js +8 -11
  38. package/lib-commonjs/components/Field/index.js.map +1 -1
  39. package/lib-commonjs/components/Field/renderField.js +19 -26
  40. package/lib-commonjs/components/Field/renderField.js.map +1 -1
  41. package/lib-commonjs/components/Field/useField.js +71 -155
  42. package/lib-commonjs/components/Field/useField.js.map +1 -1
  43. package/lib-commonjs/components/Field/useFieldStyles.js +138 -118
  44. package/lib-commonjs/components/Field/useFieldStyles.js.map +1 -1
  45. package/lib-commonjs/contexts/FieldContext.js +21 -0
  46. package/lib-commonjs/contexts/FieldContext.js.map +1 -0
  47. package/lib-commonjs/contexts/index.js +11 -0
  48. package/lib-commonjs/contexts/index.js.map +1 -0
  49. package/lib-commonjs/contexts/useFieldContextValues.js +44 -0
  50. package/lib-commonjs/contexts/useFieldContextValues.js.map +1 -0
  51. package/lib-commonjs/contexts/useFieldControlProps.js +71 -0
  52. package/lib-commonjs/contexts/useFieldControlProps.js.map +1 -0
  53. package/lib-commonjs/index.js +24 -29
  54. package/lib-commonjs/index.js.map +1 -1
  55. package/lib-commonjs/util/makeDeprecatedField.js +61 -0
  56. package/lib-commonjs/util/makeDeprecatedField.js.map +1 -0
  57. package/package.json +15 -13
  58. package/Spec.md +0 -354
  59. package/lib/components/Field/SlotComponent.types.js +0 -2
  60. package/lib/components/Field/SlotComponent.types.js.map +0 -1
  61. package/lib-commonjs/components/Field/SlotComponent.types.js +0 -6
  62. package/lib-commonjs/components/Field/SlotComponent.types.js.map +0 -1
@@ -0,0 +1,61 @@
1
+ /* eslint-disable deprecation/deprecation */ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ makeDeprecatedField: ()=>makeDeprecatedField,
13
+ getDeprecatedFieldClassNames: ()=>getDeprecatedFieldClassNames
14
+ });
15
+ const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default;
16
+ const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
17
+ const _field = require("../Field");
18
+ /**
19
+ * Partition the props used by the Field itself, from the props that are passed to the underlying field component.
20
+ */ function getPartitionedFieldProps(props) {
21
+ const { className , control , hint , label , orientation , required , root , size , style , validationMessage , validationMessageIcon , validationState ='none' , ...restOfProps } = props;
22
+ return [
23
+ {
24
+ className,
25
+ hint,
26
+ label,
27
+ orientation,
28
+ required,
29
+ size,
30
+ style,
31
+ validationMessage,
32
+ validationMessageIcon,
33
+ validationState,
34
+ ...root
35
+ },
36
+ {
37
+ required,
38
+ size,
39
+ ...restOfProps,
40
+ ...control
41
+ }
42
+ ];
43
+ }
44
+ function makeDeprecatedField(Control, options = {}) {
45
+ const { mapProps =(props)=>props , displayName =`${Control.displayName}Field` } = options;
46
+ const DeprecatedField = /*#__PURE__*/ _react.forwardRef((props, ref)=>{
47
+ const [fieldProps, controlProps] = getPartitionedFieldProps(mapProps(props));
48
+ return /*#__PURE__*/ _react.createElement(_field.Field, fieldProps, /*#__PURE__*/ _react.createElement(Control, {
49
+ ...controlProps,
50
+ ref: ref
51
+ }));
52
+ });
53
+ DeprecatedField.displayName = displayName;
54
+ return DeprecatedField;
55
+ }
56
+ const getDeprecatedFieldClassNames = (controlRootClassName)=>({
57
+ ..._field.fieldClassNames,
58
+ control: controlRootClassName
59
+ }); //# sourceMappingURL=makeDeprecatedField.js.map
60
+
61
+ //# sourceMappingURL=makeDeprecatedField.js.map
@@ -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-alpha.8",
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",
@@ -20,24 +21,24 @@
20
21
  "start": "yarn storybook",
21
22
  "storybook": "start-storybook",
22
23
  "test": "jest --passWithNoTests",
23
- "docs": "api-extractor run --config=config/api-extractor.local.json --local",
24
- "build:local": "tsc -p ./tsconfig.lib.json --module esnext --emitDeclarationOnly && node ../../../scripts/typescript/normalize-import --output ./dist/types/packages/react-components/react-field/src && yarn docs",
25
- "type-check": "tsc -b tsconfig.json"
24
+ "type-check": "tsc -b tsconfig.json",
25
+ "generate-api": "just-scripts generate-api"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@fluentui/eslint-plugin": "*",
29
29
  "@fluentui/react-conformance": "*",
30
- "@fluentui/react-conformance-griffel": "9.0.0-beta.18",
31
- "@fluentui/scripts": "^1.0.0"
30
+ "@fluentui/react-conformance-griffel": "9.0.0-beta.20",
31
+ "@fluentui/scripts-api-extractor": "*",
32
+ "@fluentui/scripts-tasks": "*"
32
33
  },
33
34
  "dependencies": {
34
- "@fluentui/react-context-selector": "^9.1.1",
35
- "@fluentui/react-icons": "^2.0.175",
36
- "@fluentui/react-label": "^9.0.10",
37
- "@fluentui/react-theme": "^9.1.2",
38
- "@fluentui/react-utilities": "^9.2.1",
39
- "@griffel/react": "^1.4.2",
40
- "tslib": "^2.1.0"
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"
41
42
  },
42
43
  "peerDependencies": {
43
44
  "@types/react": ">=16.8.0 <19.0.0",
@@ -55,6 +56,7 @@
55
56
  "exports": {
56
57
  ".": {
57
58
  "types": "./dist/index.d.ts",
59
+ "node": "./lib-commonjs/index.js",
58
60
  "import": "./lib/index.js",
59
61
  "require": "./lib-commonjs/index.js"
60
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,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=SlotComponent.types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SlotComponent.types.js","sourceRoot":"../src/","sources":["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,6 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- //# sourceMappingURL=SlotComponent.types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","sourceRoot":"../src/"}