@fluentui/react-field 9.0.0-alpha.2 → 9.0.0-alpha.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. package/CHANGELOG.json +904 -12
  2. package/CHANGELOG.md +270 -13
  3. package/README.md +66 -1
  4. package/dist/index.d.ts +76 -157
  5. package/lib/Field.js.map +1 -1
  6. package/lib/components/Field/Field.js +11 -0
  7. package/lib/components/Field/Field.js.map +1 -0
  8. package/lib/components/Field/Field.types.js.map +1 -1
  9. package/lib/components/Field/index.js +1 -0
  10. package/lib/components/Field/index.js.map +1 -1
  11. package/lib/components/Field/renderField.js +10 -7
  12. package/lib/components/Field/renderField.js.map +1 -1
  13. package/lib/components/Field/useField.js +57 -90
  14. package/lib/components/Field/useField.js.map +1 -1
  15. package/lib/components/Field/useFieldStyles.js +61 -76
  16. package/lib/components/Field/useFieldStyles.js.map +1 -1
  17. package/lib/index.js +3 -10
  18. package/lib/index.js.map +1 -1
  19. package/lib/util/makeDeprecatedField.js +71 -0
  20. package/lib/util/makeDeprecatedField.js.map +1 -0
  21. package/lib-amd/Field.js +6 -0
  22. package/lib-amd/Field.js.map +1 -0
  23. package/lib-amd/components/Field/Field.js +12 -0
  24. package/lib-amd/components/Field/Field.js.map +1 -0
  25. package/lib-amd/components/Field/Field.types.js +5 -0
  26. package/lib-amd/components/Field/Field.types.js.map +1 -0
  27. package/lib-amd/components/Field/index.js +10 -0
  28. package/lib-amd/components/Field/index.js.map +1 -0
  29. package/lib-amd/components/Field/renderField.js +20 -0
  30. package/lib-amd/components/Field/renderField.js.map +1 -0
  31. package/lib-amd/components/Field/useField.js +99 -0
  32. package/lib-amd/components/Field/useField.js.map +1 -0
  33. package/lib-amd/components/Field/useFieldStyles.js +115 -0
  34. package/lib-amd/components/Field/useFieldStyles.js.map +1 -0
  35. package/lib-amd/index.js +13 -0
  36. package/lib-amd/index.js.map +1 -0
  37. package/lib-amd/util/makeDeprecatedField.js +38 -0
  38. package/lib-amd/util/makeDeprecatedField.js.map +1 -0
  39. package/lib-commonjs/Field.js +0 -2
  40. package/lib-commonjs/Field.js.map +1 -1
  41. package/lib-commonjs/components/Field/Field.js +17 -0
  42. package/lib-commonjs/components/Field/Field.js.map +1 -0
  43. package/lib-commonjs/components/Field/Field.types.js.map +1 -1
  44. package/lib-commonjs/components/Field/index.js +1 -5
  45. package/lib-commonjs/components/Field/index.js.map +1 -1
  46. package/lib-commonjs/components/Field/renderField.js +10 -11
  47. package/lib-commonjs/components/Field/renderField.js.map +1 -1
  48. package/lib-commonjs/components/Field/useField.js +58 -99
  49. package/lib-commonjs/components/Field/useField.js.map +1 -1
  50. package/lib-commonjs/components/Field/useFieldStyles.js +62 -83
  51. package/lib-commonjs/components/Field/useFieldStyles.js.map +1 -1
  52. package/lib-commonjs/index.js +15 -132
  53. package/lib-commonjs/index.js.map +1 -1
  54. package/lib-commonjs/util/makeDeprecatedField.js +79 -0
  55. package/lib-commonjs/util/makeDeprecatedField.js.map +1 -0
  56. package/package.json +25 -25
  57. package/Spec.md +0 -354
  58. package/lib/CheckboxField.js +0 -2
  59. package/lib/CheckboxField.js.map +0 -1
  60. package/lib/ComboboxField.js +0 -2
  61. package/lib/ComboboxField.js.map +0 -1
  62. package/lib/InputField.js +0 -2
  63. package/lib/InputField.js.map +0 -1
  64. package/lib/RadioGroupField.js +0 -2
  65. package/lib/RadioGroupField.js.map +0 -1
  66. package/lib/SelectField.js +0 -2
  67. package/lib/SelectField.js.map +0 -1
  68. package/lib/SliderField.js +0 -2
  69. package/lib/SliderField.js.map +0 -1
  70. package/lib/SpinButtonField.js +0 -2
  71. package/lib/SpinButtonField.js.map +0 -1
  72. package/lib/SwitchField.js +0 -2
  73. package/lib/SwitchField.js.map +0 -1
  74. package/lib/TextareaField.js +0 -2
  75. package/lib/TextareaField.js.map +0 -1
  76. package/lib/components/CheckboxField/CheckboxField.js +0 -32
  77. package/lib/components/CheckboxField/CheckboxField.js.map +0 -1
  78. package/lib/components/CheckboxField/index.js +0 -2
  79. package/lib/components/CheckboxField/index.js.map +0 -1
  80. package/lib/components/ComboboxField/ComboboxField.js +0 -14
  81. package/lib/components/ComboboxField/ComboboxField.js.map +0 -1
  82. package/lib/components/ComboboxField/index.js +0 -2
  83. package/lib/components/ComboboxField/index.js.map +0 -1
  84. package/lib/components/Field/SlotComponent.types.js +0 -2
  85. package/lib/components/Field/SlotComponent.types.js.map +0 -1
  86. package/lib/components/InputField/InputField.js +0 -14
  87. package/lib/components/InputField/InputField.js.map +0 -1
  88. package/lib/components/InputField/index.js +0 -2
  89. package/lib/components/InputField/index.js.map +0 -1
  90. package/lib/components/RadioGroupField/RadioGroupField.js +0 -15
  91. package/lib/components/RadioGroupField/RadioGroupField.js.map +0 -1
  92. package/lib/components/RadioGroupField/index.js +0 -2
  93. package/lib/components/RadioGroupField/index.js.map +0 -1
  94. package/lib/components/SelectField/SelectField.js +0 -14
  95. package/lib/components/SelectField/SelectField.js.map +0 -1
  96. package/lib/components/SelectField/index.js +0 -2
  97. package/lib/components/SelectField/index.js.map +0 -1
  98. package/lib/components/SliderField/SliderField.js +0 -14
  99. package/lib/components/SliderField/SliderField.js.map +0 -1
  100. package/lib/components/SliderField/index.js +0 -2
  101. package/lib/components/SliderField/index.js.map +0 -1
  102. package/lib/components/SpinButtonField/SpinButtonField.js +0 -14
  103. package/lib/components/SpinButtonField/SpinButtonField.js.map +0 -1
  104. package/lib/components/SpinButtonField/index.js +0 -2
  105. package/lib/components/SpinButtonField/index.js.map +0 -1
  106. package/lib/components/SwitchField/SwitchField.js +0 -14
  107. package/lib/components/SwitchField/SwitchField.js.map +0 -1
  108. package/lib/components/SwitchField/index.js +0 -2
  109. package/lib/components/SwitchField/index.js.map +0 -1
  110. package/lib/components/TextareaField/TextareaField.js +0 -14
  111. package/lib/components/TextareaField/TextareaField.js.map +0 -1
  112. package/lib/components/TextareaField/index.js +0 -2
  113. package/lib/components/TextareaField/index.js.map +0 -1
  114. package/lib-commonjs/CheckboxField.js +0 -10
  115. package/lib-commonjs/CheckboxField.js.map +0 -1
  116. package/lib-commonjs/ComboboxField.js +0 -10
  117. package/lib-commonjs/ComboboxField.js.map +0 -1
  118. package/lib-commonjs/InputField.js +0 -10
  119. package/lib-commonjs/InputField.js.map +0 -1
  120. package/lib-commonjs/RadioGroupField.js +0 -10
  121. package/lib-commonjs/RadioGroupField.js.map +0 -1
  122. package/lib-commonjs/SelectField.js +0 -10
  123. package/lib-commonjs/SelectField.js.map +0 -1
  124. package/lib-commonjs/SliderField.js +0 -10
  125. package/lib-commonjs/SliderField.js.map +0 -1
  126. package/lib-commonjs/SpinButtonField.js +0 -10
  127. package/lib-commonjs/SpinButtonField.js.map +0 -1
  128. package/lib-commonjs/SwitchField.js +0 -10
  129. package/lib-commonjs/SwitchField.js.map +0 -1
  130. package/lib-commonjs/TextareaField.js +0 -10
  131. package/lib-commonjs/TextareaField.js.map +0 -1
  132. package/lib-commonjs/components/CheckboxField/CheckboxField.js +0 -42
  133. package/lib-commonjs/components/CheckboxField/CheckboxField.js.map +0 -1
  134. package/lib-commonjs/components/CheckboxField/index.js +0 -10
  135. package/lib-commonjs/components/CheckboxField/index.js.map +0 -1
  136. package/lib-commonjs/components/ComboboxField/ComboboxField.js +0 -24
  137. package/lib-commonjs/components/ComboboxField/ComboboxField.js.map +0 -1
  138. package/lib-commonjs/components/ComboboxField/index.js +0 -10
  139. package/lib-commonjs/components/ComboboxField/index.js.map +0 -1
  140. package/lib-commonjs/components/Field/SlotComponent.types.js +0 -6
  141. package/lib-commonjs/components/Field/SlotComponent.types.js.map +0 -1
  142. package/lib-commonjs/components/InputField/InputField.js +0 -24
  143. package/lib-commonjs/components/InputField/InputField.js.map +0 -1
  144. package/lib-commonjs/components/InputField/index.js +0 -10
  145. package/lib-commonjs/components/InputField/index.js.map +0 -1
  146. package/lib-commonjs/components/RadioGroupField/RadioGroupField.js +0 -25
  147. package/lib-commonjs/components/RadioGroupField/RadioGroupField.js.map +0 -1
  148. package/lib-commonjs/components/RadioGroupField/index.js +0 -10
  149. package/lib-commonjs/components/RadioGroupField/index.js.map +0 -1
  150. package/lib-commonjs/components/SelectField/SelectField.js +0 -24
  151. package/lib-commonjs/components/SelectField/SelectField.js.map +0 -1
  152. package/lib-commonjs/components/SelectField/index.js +0 -10
  153. package/lib-commonjs/components/SelectField/index.js.map +0 -1
  154. package/lib-commonjs/components/SliderField/SliderField.js +0 -24
  155. package/lib-commonjs/components/SliderField/SliderField.js.map +0 -1
  156. package/lib-commonjs/components/SliderField/index.js +0 -10
  157. package/lib-commonjs/components/SliderField/index.js.map +0 -1
  158. package/lib-commonjs/components/SpinButtonField/SpinButtonField.js +0 -24
  159. package/lib-commonjs/components/SpinButtonField/SpinButtonField.js.map +0 -1
  160. package/lib-commonjs/components/SpinButtonField/index.js +0 -10
  161. package/lib-commonjs/components/SpinButtonField/index.js.map +0 -1
  162. package/lib-commonjs/components/SwitchField/SwitchField.js +0 -24
  163. package/lib-commonjs/components/SwitchField/SwitchField.js.map +0 -1
  164. package/lib-commonjs/components/SwitchField/index.js +0 -10
  165. package/lib-commonjs/components/SwitchField/index.js.map +0 -1
  166. package/lib-commonjs/components/TextareaField/TextareaField.js +0 -24
  167. package/lib-commonjs/components/TextareaField/TextareaField.js.map +0 -1
  168. package/lib-commonjs/components/TextareaField/index.js +0 -10
  169. package/lib-commonjs/components/TextareaField/index.js.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,83 +1,46 @@
1
1
  /// <reference types="react" />
2
2
 
3
- import { Checkbox } from '@fluentui/react-checkbox';
4
- import type { CheckboxProps } from '@fluentui/react-checkbox';
5
- import { Combobox } from '@fluentui/react-combobox';
6
3
  import type { ComponentProps } from '@fluentui/react-utilities';
7
4
  import type { ComponentState } from '@fluentui/react-utilities';
8
5
  import { ForwardRefComponent } from '@fluentui/react-utilities';
9
- import { Input } from '@fluentui/react-input';
10
6
  import { Label } from '@fluentui/react-label';
11
- import { RadioGroup } from '@fluentui/react-radio';
12
7
  import * as React_2 from 'react';
13
- import { Select } from '@fluentui/react-select';
14
- import { Slider } from '@fluentui/react-slider';
15
8
  import type { Slot } from '@fluentui/react-utilities';
16
- import { SlotClassNames } from '@fluentui/react-utilities';
17
- import type { SlotRenderFunction } from '@fluentui/react-utilities';
18
- import type { SlotShorthandValue } from '@fluentui/react-utilities';
19
- import { SpinButton } from '@fluentui/react-spinbutton';
20
- import { Switch } from '@fluentui/react-switch';
21
- import { Textarea } from '@fluentui/react-textarea';
9
+ import type { SlotClassNames } from '@fluentui/react-utilities';
22
10
 
23
- export declare const CheckboxField: ForwardRefComponent<CheckboxFieldProps>;
24
-
25
- export declare const checkboxFieldClassNames: SlotClassNames<FieldSlots<FieldComponent>>;
26
-
27
- export declare type CheckboxFieldProps = Omit<FieldProps<typeof Checkbox>, 'label'> & {
28
- /**
29
- * The Checkbox's label.
30
- */
31
- label?: CheckboxProps['label'];
32
- /**
33
- * The label for the CheckboxField, which appears above or before the Checkbox, depending on the `orientation` prop.
34
- * It is recommended to only set the `label` prop, and not `fieldLabel`.
35
- */
36
- fieldLabel?: FieldProps<typeof Checkbox>['label'];
37
- };
38
-
39
- export declare const ComboboxField: ForwardRefComponent<ComboboxFieldProps>;
40
-
41
- export declare const comboboxFieldClassNames: SlotClassNames<FieldSlots<FieldComponent>>;
11
+ /**
12
+ * @deprecated Only for use to make deprecated [Control]Field shim components.
13
+ * @internal
14
+ */
15
+ export declare type DeprecatedFieldProps<ControlProps> = ControlProps & {
16
+ root?: FieldProps;
17
+ control?: ControlProps;
18
+ } & Pick<FieldProps, 'className' | 'hint' | 'label' | 'orientation' | 'style' | 'validationMessage' | 'validationMessageIcon' | 'validationState'>;
42
19
 
43
- export declare type ComboboxFieldProps = FieldProps<typeof Combobox>;
20
+ export declare const Field: ForwardRefComponent<FieldProps>;
44
21
 
45
22
  /**
46
- * The minimum requirement for a component used by Field.
47
- *
48
- * Note: the use of VoidFunctionComponent means that component is not *required* to have a children prop,
49
- * but it is still allowed to have a children prop.
23
+ * The props added to the Field's child element.
50
24
  */
51
- declare type FieldComponent = React_2.VoidFunctionComponent<Pick<React_2.HTMLAttributes<HTMLElement>, 'id' | 'className' | 'style' | 'aria-labelledby' | 'aria-describedby' | 'aria-invalid' | 'aria-errormessage'>>;
25
+ declare type FieldChildProps = Pick<React_2.HTMLAttributes<HTMLElement>, 'id' | 'aria-labelledby' | 'aria-describedby' | 'aria-invalid' | 'aria-required'>;
26
+
27
+ export declare const fieldClassNames: SlotClassNames<FieldSlots>;
52
28
 
53
29
  /**
54
- * Configuration parameters for a Field class, passed to useField_unstable
30
+ * Field Props
55
31
  */
56
- export declare type FieldConfig<T extends FieldComponent> = {
57
- /**
58
- * The underlying input component that this field is wrapping.
59
- */
60
- component: T;
32
+ export declare type FieldProps = Omit<ComponentProps<FieldSlots>, 'children'> & {
61
33
  /**
62
- * Class names for this component, created by `getFieldClassNames`.
63
- */
64
- classNames: SlotClassNames<FieldSlots<T>>;
65
- /**
66
- * How the label be connected to the control.
67
- * * htmlFor - Set the Label's htmlFor prop to the component's ID (and generate an ID if not provided).
68
- * This is the preferred method for components that use the underlying <input> tag.
69
- * * aria-labelledby - Set the component's aria-labelledby prop to the Label's ID. Use this for components
70
- * that are not directly <input> elements (such as RadioGroup).
34
+ * The Field's child can be a single form control, or a render function that takes the props that should be spread on
35
+ * a form control.
71
36
  *
72
- * @default htmlFor
37
+ * All form controls in this library can be used directly as children (such as `<Input>` or `<RadioGroup>`), as well
38
+ * as intrinsic form controls like `<input>` or `<textarea>`. Custom controls can also be used as long as they
39
+ * accept FieldChildProps and spread them on the appropriate element.
40
+ *
41
+ * For more complex scenarios, a render function can be used to pass the FieldChildProps to the appropriate control.
73
42
  */
74
- labelConnection?: 'htmlFor' | 'aria-labelledby';
75
- };
76
-
77
- /**
78
- * Field Props
79
- */
80
- export declare type FieldProps<T extends FieldComponent> = ComponentProps<Partial<FieldSlots<T>>, 'control'> & {
43
+ children?: React_2.ReactElement<FieldChildProps> | null | ((props: FieldChildProps) => React_2.ReactNode);
81
44
  /**
82
45
  * The orientation of the label relative to the field component.
83
46
  * This only affects the label, and not the validationMessage or hint (which always appear below the field component).
@@ -86,125 +49,92 @@ export declare type FieldProps<T extends FieldComponent> = ComponentProps<Partia
86
49
  */
87
50
  orientation?: 'vertical' | 'horizontal';
88
51
  /**
89
- * The `validationState` affects the color of the `validationMessage`, the `validationMessageIcon`, and for some
90
- * field components, an `validationState="error"` causes the border to become red.
52
+ * The `validationState` affects the display of the `validationMessage` and `validationMessageIcon`.
91
53
  *
92
- * @default undefined
54
+ * * error: (default) The validation message has a red error icon and red text, with `role="alert"` so it is
55
+ * announced by screen readers. Additionally, the control inside the field has `aria-invalid` set, which adds a
56
+ * red border to some field components (such as `Input`).
57
+ * * success: The validation message has a green checkmark icon and gray text.
58
+ * * warning: The validation message has a yellow exclamation icon and gray text.
59
+ * * none: The validation message has no icon and gray text.
60
+ *
61
+ * @default error when validationMessage is set; none otherwise.
93
62
  */
94
- validationState?: 'error' | 'warning' | 'success';
95
- };
96
-
97
- /**
98
- * FieldProps plus extra optional props that are supported by useField_unstable, but not required to be part of the
99
- * API of every Field component.
100
- *
101
- * This allows Field to forward the required and size props to the label if the underlying component supports them,
102
- * but doesn't add them to the public API of fields that don't support them.
103
- */
104
- declare type FieldPropsWithOptionalComponentProps<T extends FieldComponent> = FieldProps<T> & {
63
+ validationState?: 'error' | 'warning' | 'success' | 'none';
105
64
  /**
106
- * Whether the field label should be marked as required.
65
+ * Marks the Field as required. If `true`, an asterisk will be appended to the label, and `aria-required` will be set
66
+ * on the Field's child.
107
67
  */
108
68
  required?: boolean;
109
69
  /**
110
- * Size of the field label.
70
+ * The size of the Field's label.
111
71
  *
112
- * Number sizes will be ignored, but are allowed because the HTML `<input>` element has a prop `size?: number`.
72
+ * @default medium
113
73
  */
114
- size?: 'small' | 'medium' | 'large' | number;
74
+ size?: 'small' | 'medium' | 'large';
115
75
  };
116
76
 
117
77
  /**
118
- * Slots added by Field
78
+ * Slots of the Field component
119
79
  */
120
- export declare type FieldSlots<T extends FieldComponent> = {
80
+ export declare type FieldSlots = {
121
81
  root: NonNullable<Slot<'div'>>;
122
- /**
123
- * The underlying component wrapped by this field.
124
- */
125
- control: SlotComponent<T>;
126
82
  /**
127
83
  * The label associated with the field.
128
84
  */
129
85
  label?: Slot<typeof Label>;
130
86
  /**
131
- * A message about the validation state. The appearance of the `validationMessage` depends on `validationState`.
87
+ * A message about the validation state. By default, this is an error message, but it can be a success, warning,
88
+ * or custom message by setting `validationState`.
132
89
  */
133
- validationMessage?: Slot<'span'>;
90
+ validationMessage?: Slot<'div'>;
134
91
  /**
135
- * The icon associated with the `validationMessage`. If the `validationState` prop is set, this will default to an
136
- * icon corresponding to that state.
92
+ * The icon associated with the `validationMessage`. This will only be displayed if `validationMessage` is set.
137
93
  *
138
- * This will only be displayed if `validationMessage` is set.
94
+ * The default depends on `validationState`:
95
+ * * error: `<ErrorCircle12Filled />`
96
+ * * warning: `<Warning12Filled />`
97
+ * * success: `<CheckmarkCircle12Filled />`
98
+ * * none: `null`
139
99
  */
140
100
  validationMessageIcon?: Slot<'span'>;
141
101
  /**
142
102
  * Additional hint text below the field.
143
103
  */
144
- hint?: Slot<'span'>;
104
+ hint?: Slot<'div'>;
145
105
  };
146
106
 
147
107
  /**
148
108
  * State used in rendering Field
149
109
  */
150
- export declare type FieldState<T extends FieldComponent> = ComponentState<Required<FieldSlots<T>>> & Pick<FieldProps<T>, 'orientation' | 'validationState'> & {
151
- classNames: SlotClassNames<FieldSlots<T>>;
152
- };
153
-
154
- export declare const getFieldClassNames: (name: string) => SlotClassNames<FieldSlots<FieldComponent>>;
155
-
156
- export declare const InputField: ForwardRefComponent<InputFieldProps>;
110
+ export declare type FieldState = ComponentState<Required<FieldSlots>> & Required<Pick<FieldProps, 'orientation' | 'validationState'>>;
157
111
 
158
- export declare const inputFieldClassNames: SlotClassNames<FieldSlots<FieldComponent>>;
159
-
160
- export declare type InputFieldProps = FieldProps<typeof Input>;
161
-
162
- export declare const RadioGroupField: ForwardRefComponent<RadioGroupFieldProps>;
163
-
164
- export declare const radioGroupFieldClassNames: SlotClassNames<FieldSlots<FieldComponent>>;
112
+ /**
113
+ * @deprecated Only for use to make deprecated [Control]Field shim components.
114
+ * @internal
115
+ */
116
+ export declare const getDeprecatedFieldClassNames: (controlRootClassName: string) => {
117
+ control: string;
118
+ root: string;
119
+ label: string;
120
+ validationMessage: string;
121
+ validationMessageIcon: string;
122
+ hint: string;
123
+ };
165
124
 
166
- export declare type RadioGroupFieldProps = FieldProps<typeof RadioGroup>;
125
+ /**
126
+ * @deprecated Only for use to make deprecated [Control]Field shim components.
127
+ * @internal
128
+ */
129
+ export declare function makeDeprecatedField<ControlProps>(Control: React_2.ComponentType<ControlProps>, options?: {
130
+ mapProps?: (props: DeprecatedFieldProps<ControlProps>) => DeprecatedFieldProps<ControlProps>;
131
+ displayName?: string;
132
+ }): ForwardRefComponent<DeprecatedFieldProps<ControlProps>>;
167
133
 
168
134
  /**
169
135
  * Render the final JSX of Field
170
136
  */
171
- export declare const renderField_unstable: <T extends FieldComponent>(state: FieldState<T>) => JSX.Element;
172
-
173
- export declare const SelectField: ForwardRefComponent<SelectFieldProps>;
174
-
175
- export declare const selectFieldClassNames: SlotClassNames<FieldSlots<FieldComponent>>;
176
-
177
- export declare type SelectFieldProps = FieldProps<typeof Select>;
178
-
179
- export declare const SliderField: ForwardRefComponent<SliderFieldProps>;
180
-
181
- export declare const sliderFieldClassNames: SlotClassNames<FieldSlots<FieldComponent>>;
182
-
183
- export declare type SliderFieldProps = FieldProps<typeof Slider>;
184
-
185
- declare type SlotComponent<Type extends React_2.ComponentType | React_2.VoidFunctionComponent> = WithSlotShorthandValue<Type extends React_2.ComponentType<infer Props> ? WithSlotRenderFunction<Props extends {
186
- children?: unknown;
187
- } ? Props : Props & {
188
- children?: never;
189
- }> : never>;
190
-
191
- export declare const SpinButtonField: ForwardRefComponent<SpinButtonFieldProps>;
192
-
193
- export declare const spinButtonFieldClassNames: SlotClassNames<FieldSlots<FieldComponent>>;
194
-
195
- export declare type SpinButtonFieldProps = FieldProps<typeof SpinButton>;
196
-
197
- export declare const SwitchField: ForwardRefComponent<SwitchFieldProps>;
198
-
199
- export declare const switchFieldClassNames: SlotClassNames<FieldSlots<FieldComponent>>;
200
-
201
- export declare type SwitchFieldProps = FieldProps<typeof Switch>;
202
-
203
- export declare const TextareaField: ForwardRefComponent<TextareaFieldProps>;
204
-
205
- export declare const textareaFieldClassNames: SlotClassNames<FieldSlots<FieldComponent>>;
206
-
207
- export declare type TextareaFieldProps = FieldProps<typeof Textarea>;
137
+ export declare const renderField_unstable: (state: FieldState) => JSX.Element;
208
138
 
209
139
  /**
210
140
  * Create the state required to render Field.
@@ -213,24 +143,13 @@ export declare type TextareaFieldProps = FieldProps<typeof Textarea>;
213
143
  * before being passed to renderField_unstable.
214
144
  *
215
145
  * @param props - Props passed to this field
216
- * @param ref - Ref to the control slot (primary slot)
217
- * @param params - Configuration parameters for this Field
146
+ * @param ref - Ref to the root
218
147
  */
219
- export declare const useField_unstable: <T extends FieldComponent>(props: FieldPropsWithOptionalComponentProps<T>, ref: React_2.Ref<HTMLElement>, params: FieldConfig<T>) => FieldState<T>;
148
+ export declare const useField_unstable: (props: FieldProps, ref: React_2.Ref<HTMLDivElement>) => FieldState;
220
149
 
221
150
  /**
222
151
  * Apply styling to the Field slots based on the state
223
152
  */
224
- export declare const useFieldStyles_unstable: <T extends FieldComponent>(state: FieldState<T>) => void;
225
-
226
- declare type WithSlotRenderFunction<Props extends {
227
- children?: unknown;
228
- }> = Props & {
229
- children?: Props['children'] | SlotRenderFunction<Props>;
230
- };
231
-
232
- declare type WithSlotShorthandValue<Props extends {
233
- children?: unknown;
234
- }> = Props | Extract<SlotShorthandValue, Props['children']>;
153
+ export declare const useFieldStyles_unstable: (state: FieldState) => void;
235
154
 
236
155
  export { }
package/lib/Field.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Field.js","sourceRoot":"../src/","sources":["Field.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC","sourcesContent":["export * from './components/Field/index';\n"]}
1
+ {"version":3,"file":"Field.js","sourceRoot":"../src/","sources":["packages/react-components/react-field/src/Field.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC","sourcesContent":["export * from './components/Field/index';\n"]}
@@ -0,0 +1,11 @@
1
+ import * as React from 'react';
2
+ import { renderField_unstable } from './renderField';
3
+ import { useField_unstable } from './useField';
4
+ import { useFieldStyles_unstable } from './useFieldStyles';
5
+ export const Field = /*#__PURE__*/React.forwardRef((props, ref) => {
6
+ const state = useField_unstable(props, ref);
7
+ useFieldStyles_unstable(state);
8
+ return renderField_unstable(state);
9
+ });
10
+ Field.displayName = 'Field';
11
+ //# sourceMappingURL=Field.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAG9B,SAASC,oBAAoB,QAAQ,eAAe;AACpD,SAASC,iBAAiB,QAAQ,YAAY;AAC9C,SAASC,uBAAuB,QAAQ,kBAAkB;AAE1D,OAAO,MAAMC,KAAK,gBAAoCJ,KAAK,CAACK,UAAU,CAAC,CAACC,KAAK,EAAEC,GAAG,KAAI;EACpF,MAAMC,KAAK,GAAGN,iBAAiB,CAACI,KAAK,EAAEC,GAAG,CAAC;EAC3CJ,uBAAuB,CAACK,KAAK,CAAC;EAC9B,OAAOP,oBAAoB,CAACO,KAAK,CAAC;AACpC,CAAC,CAAC;AAEFJ,KAAK,CAACK,WAAW,GAAG,OAAO","names":["React","renderField_unstable","useField_unstable","useFieldStyles_unstable","Field","forwardRef","props","ref","state","displayName"],"sourceRoot":"../src/","sources":["packages/react-components/react-field/src/components/Field/Field.tsx"],"sourcesContent":["import * as React from 'react';\nimport type { ForwardRefComponent } from '@fluentui/react-utilities';\nimport type { FieldProps } from './Field.types';\nimport { renderField_unstable } from './renderField';\nimport { useField_unstable } from './useField';\nimport { useFieldStyles_unstable } from './useFieldStyles';\n\nexport const Field: ForwardRefComponent<FieldProps> = React.forwardRef((props, ref) => {\n const state = useField_unstable(props, ref);\n useFieldStyles_unstable(state);\n return renderField_unstable(state);\n});\n\nField.displayName = 'Field';\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"Field.types.js","sourceRoot":"../src/","sources":["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 FieldComponent = 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 FieldComponent> = {\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<'span'>;\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<'span'>;\n};\n\n/**\n * Field Props\n */\nexport type FieldProps<T extends FieldComponent> = 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 FieldComponent> = 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 FieldComponent> = {\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/**\n * State used in rendering Field\n */\nexport type FieldState<T extends FieldComponent> = ComponentState<Required<FieldSlots<T>>> &\n Pick<FieldProps<T>, 'orientation' | 'validationState'> & {\n classNames: SlotClassNames<FieldSlots<T>>;\n };\n"]}
1
+ {"version":3,"file":"Field.types.js","sourceRoot":"../src/","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 } from '@fluentui/react-utilities';\n\n/**\n * The props added to the Field's child element.\n */\nexport type FieldChildProps = Pick<\n React.HTMLAttributes<HTMLElement>,\n 'id' | 'aria-labelledby' | 'aria-describedby' | 'aria-invalid' | 'aria-required'\n>;\n\n/**\n * Slots of the Field component\n */\nexport type FieldSlots = {\n root: NonNullable<Slot<'div'>>;\n\n /**\n * The label associated with the field.\n */\n label?: Slot<typeof Label>;\n\n /**\n * A message about the validation state. By default, this is an error message, but it can be a success, warning,\n * or custom message by setting `validationState`.\n */\n validationMessage?: Slot<'div'>;\n\n /**\n * The icon associated with the `validationMessage`. This will only be displayed if `validationMessage` is set.\n *\n * The default depends on `validationState`:\n * * error: `<ErrorCircle12Filled />`\n * * warning: `<Warning12Filled />`\n * * success: `<CheckmarkCircle12Filled />`\n * * none: `null`\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 = Omit<ComponentProps<FieldSlots>, 'children'> & {\n /**\n * The Field's child can be a single form control, or a render function that takes the props that should be spread on\n * a form control.\n *\n * All form controls in this library can be used directly as children (such as `<Input>` or `<RadioGroup>`), as well\n * as intrinsic form controls like `<input>` or `<textarea>`. Custom controls can also be used as long as they\n * accept FieldChildProps and spread them on the appropriate element.\n *\n * For more complex scenarios, a render function can be used to pass the FieldChildProps to the appropriate control.\n */\n children?: React.ReactElement<FieldChildProps> | null | ((props: FieldChildProps) => React.ReactNode);\n\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 display of the `validationMessage` and `validationMessageIcon`.\n *\n * * error: (default) The validation message has a red error icon and red text, with `role=\"alert\"` so it is\n * announced by screen readers. Additionally, the control inside the field has `aria-invalid` set, which adds a\n * red border to some field components (such as `Input`).\n * * success: The validation message has a green checkmark icon and gray text.\n * * warning: The validation message has a yellow exclamation icon and gray text.\n * * none: The validation message has no icon and gray text.\n *\n * @default error when validationMessage is set; none otherwise.\n */\n validationState?: 'error' | 'warning' | 'success' | 'none';\n\n /**\n * Marks the Field as required. If `true`, an asterisk will be appended to the label, and `aria-required` will be set\n * on the Field's child.\n */\n required?: boolean;\n\n /**\n * The size of the Field's label.\n *\n * @default medium\n */\n size?: 'small' | 'medium' | 'large';\n};\n\n/**\n * State used in rendering Field\n */\nexport type FieldState = ComponentState<Required<FieldSlots>> &\n Required<Pick<FieldProps, 'orientation' | 'validationState'>>;\n"]}
@@ -1,4 +1,5 @@
1
1
  export * from './Field.types';
2
+ export * from './Field';
2
3
  export * from './renderField';
3
4
  export * from './useField';
4
5
  export * from './useFieldStyles';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["components/Field/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC","sourcesContent":["export * from './Field.types';\nexport * from './renderField';\nexport * from './useField';\nexport * from './useFieldStyles';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["packages/react-components/react-field/src/components/Field/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC","sourcesContent":["export * from './Field.types';\nexport * from './Field';\nexport * from './renderField';\nexport * from './useField';\nexport * from './useFieldStyles';\n"]}
@@ -3,18 +3,21 @@ import { getSlots } from '@fluentui/react-utilities';
3
3
  /**
4
4
  * Render the final JSX of Field
5
5
  */
6
-
7
6
  export const renderField_unstable = state => {
8
7
  const {
9
8
  slots,
10
9
  slotProps
11
10
  } = getSlots(state);
12
- return /*#__PURE__*/React.createElement(slots.root, { ...slotProps.root
13
- }, slots.label && /*#__PURE__*/React.createElement(slots.label, { ...slotProps.label
14
- }), slots.control && /*#__PURE__*/React.createElement(slots.control, { ...slotProps.control
15
- }), slots.validationMessage && /*#__PURE__*/React.createElement(slots.validationMessage, { ...slotProps.validationMessage
16
- }, slots.validationMessageIcon && /*#__PURE__*/React.createElement(slots.validationMessageIcon, { ...slotProps.validationMessageIcon
17
- }), slotProps.validationMessage.children), slots.hint && /*#__PURE__*/React.createElement(slots.hint, { ...slotProps.hint
11
+ return /*#__PURE__*/React.createElement(slots.root, {
12
+ ...slotProps.root
13
+ }, slots.label && /*#__PURE__*/React.createElement(slots.label, {
14
+ ...slotProps.label
15
+ }), slotProps.root.children, slots.validationMessage && /*#__PURE__*/React.createElement(slots.validationMessage, {
16
+ ...slotProps.validationMessage
17
+ }, slots.validationMessageIcon && /*#__PURE__*/React.createElement(slots.validationMessageIcon, {
18
+ ...slotProps.validationMessageIcon
19
+ }), slotProps.validationMessage.children), slots.hint && /*#__PURE__*/React.createElement(slots.hint, {
20
+ ...slotProps.hint
18
21
  }));
19
22
  };
20
23
  //# sourceMappingURL=renderField.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["components/Field/renderField.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,QAAT,QAAyB,2BAAzB;AAGA;;AAEG;;AACH,OAAO,MAAM,oBAAoB,GAA8B,KAA3B,IAAmD;EACrF,MAAM;IAAE,KAAF;IAAS;EAAT,IAAuB,QAAQ,CAA6B,KAA7B,CAArC;EAEA,oBACE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,IAAP,EAAW,EAAA,GAAK,SAAS,CAAC;EAAf,CAAX,EACG,KAAK,CAAC,KAAN,iBAAe,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,KAAP,EAAY,EAAA,GAAK,SAAS,CAAC;EAAf,CAAZ,CADlB,EAGG,KAAK,CAAC,OAAN,iBAAiB,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,OAAP,EAAc,EAAA,GAAM,SAAS,CAAC;EAAhB,CAAd,CAHpB,EAIG,KAAK,CAAC,iBAAN,iBACC,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,iBAAP,EAAwB,EAAA,GAAK,SAAS,CAAC;EAAf,CAAxB,EACG,KAAK,CAAC,qBAAN,iBAA+B,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,qBAAP,EAA4B,EAAA,GAAK,SAAS,CAAC;EAAf,CAA5B,CADlC,EAEG,SAAS,CAAC,iBAAV,CAA4B,QAF/B,CALJ,EAUG,KAAK,CAAC,IAAN,iBAAc,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,IAAP,EAAW,EAAA,GAAK,SAAS,CAAC;EAAf,CAAX,CAVjB,CADF;AAcD,CAjBM","sourcesContent":["import * as React from 'react';\nimport { getSlots } from '@fluentui/react-utilities';\nimport type { FieldComponent, FieldSlots, FieldState } from './Field.types';\n\n/**\n * Render the final JSX of Field\n */\nexport const renderField_unstable = <T extends FieldComponent>(state: FieldState<T>) => {\n const { slots, slotProps } = getSlots<FieldSlots<FieldComponent>>(state as FieldState<FieldComponent>);\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"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,QAAQ,QAAQ,2BAA2B;AAGpD;;;AAGA,OAAO,MAAMC,oBAAoB,GAAIC,KAAiB,IAAI;EACxD,MAAM;IAAEC,KAAK;IAAEC;EAAS,CAAE,GAAGJ,QAAQ,CAAaE,KAAK,CAAC;EAExD,oBACEH,oBAACI,KAAK,CAACE,IAAI;IAAA,GAAKD,SAAS,CAACC;EAAI,GAC3BF,KAAK,CAACG,KAAK,iBAAIP,oBAACI,KAAK,CAACG,KAAK;IAAA,GAAKF,SAAS,CAACE;EAAK,EAAI,EACnDF,SAAS,CAACC,IAAI,CAACE,QAAQ,EACvBJ,KAAK,CAACK,iBAAiB,iBACtBT,oBAACI,KAAK,CAACK,iBAAiB;IAAA,GAAKJ,SAAS,CAACI;EAAiB,GACrDL,KAAK,CAACM,qBAAqB,iBAAIV,oBAACI,KAAK,CAACM,qBAAqB;IAAA,GAAKL,SAAS,CAACK;EAAqB,EAAI,EACnGL,SAAS,CAACI,iBAAiB,CAACD,QAAQ,CAExC,EACAJ,KAAK,CAACO,IAAI,iBAAIX,oBAACI,KAAK,CAACO,IAAI;IAAA,GAAKN,SAAS,CAACM;EAAI,EAAI,CACtC;AAEjB,CAAC","names":["React","getSlots","renderField_unstable","state","slots","slotProps","root","label","children","validationMessage","validationMessageIcon","hint"],"sourceRoot":"../src/","sources":["packages/react-components/react-field/src/components/Field/renderField.tsx"],"sourcesContent":["import * as React from 'react';\nimport { getSlots } from '@fluentui/react-utilities';\nimport type { FieldSlots, FieldState } from './Field.types';\n\n/**\n * Render the final JSX of Field\n */\nexport const renderField_unstable = (state: FieldState) => {\n const { slots, slotProps } = getSlots<FieldSlots>(state);\n\n return (\n <slots.root {...slotProps.root}>\n {slots.label && <slots.label {...slotProps.label} />}\n {slotProps.root.children}\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"]}
@@ -5,46 +5,8 @@ import { getNativeElementProps, resolveShorthand, useId } from '@fluentui/react-
5
5
  const validationMessageIcons = {
6
6
  error: /*#__PURE__*/React.createElement(ErrorCircle12Filled, null),
7
7
  warning: /*#__PURE__*/React.createElement(Warning12Filled, null),
8
- success: /*#__PURE__*/React.createElement(CheckmarkCircle12Filled, null)
9
- };
10
- /**
11
- * Merge two possibly-undefined IDs for aria-describedby. If both IDs are defined, combines
12
- * them into a string separated by a space. Otherwise, returns just the defined ID (if any).
13
- */
14
-
15
- const mergeAriaDescribedBy = (a, b) => a && b ? `${a} ${b}` : a || b;
16
- /**
17
- * Partition the props used by the Field itself, from the props that are passed to the underlying field component.
18
- */
19
-
20
-
21
- export const getPartitionedFieldProps = props => {
22
- const {
23
- className,
24
- control,
25
- hint,
26
- label,
27
- orientation,
28
- root,
29
- style,
30
- validationMessage,
31
- validationMessageIcon,
32
- validationState,
33
- ...restOfProps
34
- } = props;
35
- const fieldProps = {
36
- className,
37
- control,
38
- hint,
39
- label,
40
- orientation,
41
- root,
42
- style,
43
- validationMessage,
44
- validationMessageIcon,
45
- validationState
46
- };
47
- return [fieldProps, restOfProps];
8
+ success: /*#__PURE__*/React.createElement(CheckmarkCircle12Filled, null),
9
+ none: undefined
48
10
  };
49
11
  /**
50
12
  * Create the state required to render Field.
@@ -53,87 +15,92 @@ export const getPartitionedFieldProps = props => {
53
15
  * before being passed to renderField_unstable.
54
16
  *
55
17
  * @param props - Props passed to this field
56
- * @param ref - Ref to the control slot (primary slot)
57
- * @param params - Configuration parameters for this Field
18
+ * @param ref - Ref to the root
58
19
  */
59
-
60
- export const useField_unstable = (props, ref, params) => {
61
- const [fieldProps, controlProps] = getPartitionedFieldProps(props);
62
- const baseId = useId('field-');
20
+ export const useField_unstable = (props, ref) => {
21
+ var _a, _b, _c, _d;
63
22
  const {
23
+ children,
64
24
  orientation = 'vertical',
65
- validationState
66
- } = fieldProps;
67
- const root = resolveShorthand(fieldProps.root, {
68
- required: true,
69
- defaultProps: getNativeElementProps('div', fieldProps)
70
- });
71
- const label = resolveShorthand(fieldProps.label, {
25
+ required,
26
+ validationState = props.validationMessage ? 'error' : 'none',
27
+ size
28
+ } = props;
29
+ const baseId = useId('field-');
30
+ const root = getNativeElementProps('div', {
31
+ ...props,
32
+ ref
33
+ }, /*excludedPropNames:*/['children']);
34
+ const label = resolveShorthand(props.label, {
72
35
  defaultProps: {
73
36
  id: baseId + '__label',
74
- required: controlProps.required,
75
- size: typeof controlProps.size === 'string' ? controlProps.size : undefined // htmlFor is set below
76
-
37
+ required,
38
+ size
39
+ // htmlFor is handled below
77
40
  }
78
41
  });
79
- const validationMessage = resolveShorthand(fieldProps.validationMessage, {
42
+
43
+ const validationMessage = resolveShorthand(props.validationMessage, {
80
44
  defaultProps: {
81
- id: baseId + '__validationMessage'
45
+ id: baseId + '__validationMessage',
46
+ role: validationState === 'error' ? 'alert' : undefined
82
47
  }
83
48
  });
84
- const hint = resolveShorthand(fieldProps.hint, {
49
+ const hint = resolveShorthand(props.hint, {
85
50
  defaultProps: {
86
51
  id: baseId + '__hint'
87
52
  }
88
53
  });
89
- const validationMessageIcon = resolveShorthand(fieldProps.validationMessageIcon, {
90
- required: !!validationState,
54
+ const defaultIcon = validationMessageIcons[validationState];
55
+ const validationMessageIcon = resolveShorthand(props.validationMessageIcon, {
56
+ required: !!defaultIcon,
91
57
  defaultProps: {
92
- children: validationState ? validationMessageIcons[validationState] : undefined
58
+ children: defaultIcon
93
59
  }
94
60
  });
95
- const {
96
- labelConnection = 'htmlFor'
97
- } = params;
98
- const hasError = validationState === 'error';
99
- const control = resolveShorthand(fieldProps.control, {
100
- required: true,
101
- defaultProps: {
102
- ref,
103
- // Add a default ID only if required for label's htmlFor prop
104
- id: label && labelConnection === 'htmlFor' ? baseId + '__control' : undefined,
105
- // Add aria-labelledby only if not using the label's htmlFor
106
- 'aria-labelledby': labelConnection !== 'htmlFor' ? label === null || label === void 0 ? void 0 : label.id : undefined,
107
- 'aria-describedby': hasError ? hint === null || hint === void 0 ? void 0 : hint.id : mergeAriaDescribedBy(validationMessage === null || validationMessage === void 0 ? void 0 : validationMessage.id, hint === null || hint === void 0 ? void 0 : hint.id),
108
- 'aria-errormessage': hasError ? validationMessage === null || validationMessage === void 0 ? void 0 : validationMessage.id : undefined,
109
- 'aria-invalid': hasError ? true : undefined,
110
- ...controlProps
61
+ const controlProps = /*#__PURE__*/React.isValidElement(children) ? {
62
+ ...children.props
63
+ } : {};
64
+ if (label) {
65
+ (_a = controlProps['aria-labelledby']) !== null && _a !== void 0 ? _a : controlProps['aria-labelledby'] = label.id;
66
+ if (!label.htmlFor) {
67
+ // Assign the child a generated ID if doesn't already have an ID
68
+ (_b = controlProps.id) !== null && _b !== void 0 ? _b : controlProps.id = baseId + '__control';
69
+ label.htmlFor = controlProps.id;
111
70
  }
112
- });
113
-
114
- if (labelConnection === 'htmlFor' && label && !label.htmlFor) {
115
- label.htmlFor = control.id;
116
71
  }
117
-
118
- const state = {
72
+ if (validationMessage || hint) {
73
+ // The control is described by the validation message, or hint, or both
74
+ // We also preserve and append any aria-describedby supplied by the user
75
+ // For reference: https://github.com/microsoft/fluentui/pull/25580#discussion_r1017259933
76
+ controlProps['aria-describedby'] = [validationMessage === null || validationMessage === void 0 ? void 0 : validationMessage.id, hint === null || hint === void 0 ? void 0 : hint.id, controlProps['aria-describedby']].filter(Boolean).join(' ');
77
+ }
78
+ if (validationState === 'error') {
79
+ (_c = controlProps['aria-invalid']) !== null && _c !== void 0 ? _c : controlProps['aria-invalid'] = true;
80
+ }
81
+ if (required) {
82
+ (_d = controlProps['aria-required']) !== null && _d !== void 0 ? _d : controlProps['aria-required'] = true;
83
+ }
84
+ if ( /*#__PURE__*/React.isValidElement(children)) {
85
+ root.children = /*#__PURE__*/React.cloneElement(children, controlProps);
86
+ } else if (typeof children === 'function') {
87
+ root.children = children(controlProps);
88
+ }
89
+ return {
119
90
  orientation,
120
91
  validationState,
121
- classNames: params.classNames,
122
92
  components: {
123
93
  root: 'div',
124
- control: params.component,
125
94
  label: Label,
126
- validationMessage: 'span',
95
+ validationMessage: 'div',
127
96
  validationMessageIcon: 'span',
128
- hint: 'span'
97
+ hint: 'div'
129
98
  },
130
99
  root,
131
- control,
132
100
  label,
133
101
  validationMessageIcon,
134
102
  validationMessage,
135
103
  hint
136
104
  };
137
- return state;
138
105
  };
139
106
  //# sourceMappingURL=useField.js.map