@fluentui/react-field 0.0.0-nightly-20230125-0418.1 → 0.0.0-nightly-20230126-0420.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. package/CHANGELOG.json +13 -13
  2. package/CHANGELOG.md +9 -9
  3. package/dist/index.d.ts +60 -86
  4. package/lib/components/Field/Field.js +11 -0
  5. package/lib/components/Field/Field.js.map +1 -0
  6. package/lib/components/Field/Field.types.js.map +1 -1
  7. package/lib/components/Field/index.js +1 -0
  8. package/lib/components/Field/index.js.map +1 -1
  9. package/lib/components/Field/renderField.js +1 -3
  10. package/lib/components/Field/renderField.js.map +1 -1
  11. package/lib/components/Field/useField.js +37 -71
  12. package/lib/components/Field/useField.js.map +1 -1
  13. package/lib/components/Field/useFieldStyles.js +15 -18
  14. package/lib/components/Field/useFieldStyles.js.map +1 -1
  15. package/lib/index.js +3 -1
  16. package/lib/index.js.map +1 -1
  17. package/lib/util/makeDeprecatedField.js +71 -0
  18. package/lib/util/makeDeprecatedField.js.map +1 -0
  19. package/lib-commonjs/components/Field/Field.js +17 -0
  20. package/lib-commonjs/components/Field/Field.js.map +1 -0
  21. package/lib-commonjs/components/Field/index.js +1 -0
  22. package/lib-commonjs/components/Field/index.js.map +1 -1
  23. package/lib-commonjs/components/Field/renderField.js +1 -3
  24. package/lib-commonjs/components/Field/renderField.js.map +1 -1
  25. package/lib-commonjs/components/Field/useField.js +38 -73
  26. package/lib-commonjs/components/Field/useField.js.map +1 -1
  27. package/lib-commonjs/components/Field/useFieldStyles.js +16 -20
  28. package/lib-commonjs/components/Field/useFieldStyles.js.map +1 -1
  29. package/lib-commonjs/index.js +23 -3
  30. package/lib-commonjs/index.js.map +1 -1
  31. package/lib-commonjs/util/makeDeprecatedField.js +79 -0
  32. package/lib-commonjs/util/makeDeprecatedField.js.map +1 -0
  33. package/package.json +7 -6
  34. package/lib/components/Field/SlotComponent.types.js +0 -2
  35. package/lib/components/Field/SlotComponent.types.js.map +0 -1
  36. package/lib-commonjs/components/Field/SlotComponent.types.js +0 -6
  37. package/lib-commonjs/components/Field/SlotComponent.types.js.map +0 -1
package/CHANGELOG.json CHANGED
@@ -2,9 +2,9 @@
2
2
  "name": "@fluentui/react-field",
3
3
  "entries": [
4
4
  {
5
- "date": "Wed, 25 Jan 2023 04:25:37 GMT",
6
- "tag": "@fluentui/react-field_v0.0.0-nightly-20230125-0418.1",
7
- "version": "0.0.0-nightly-20230125-0418.1",
5
+ "date": "Thu, 26 Jan 2023 04:27:47 GMT",
6
+ "tag": "@fluentui/react-field_v0.0.0-nightly-20230126-0420.1",
7
+ "version": "0.0.0-nightly-20230126-0420.1",
8
8
  "comments": {
9
9
  "prerelease": [
10
10
  {
@@ -16,32 +16,32 @@
16
16
  {
17
17
  "author": "beachball",
18
18
  "package": "@fluentui/react-field",
19
- "comment": "Bump @fluentui/react-context-selector to v0.0.0-nightly-20230125-0418.1",
20
- "commit": "9ae3c86be8e1491c190d1b0c746d9ff238c36f75"
19
+ "comment": "Bump @fluentui/react-context-selector to v0.0.0-nightly-20230126-0420.1",
20
+ "commit": "3428a8c744066a319dc9afcce72c948f1a96f0b2"
21
21
  },
22
22
  {
23
23
  "author": "beachball",
24
24
  "package": "@fluentui/react-field",
25
- "comment": "Bump @fluentui/react-label to v0.0.0-nightly-20230125-0418.1",
26
- "commit": "9ae3c86be8e1491c190d1b0c746d9ff238c36f75"
25
+ "comment": "Bump @fluentui/react-label to v0.0.0-nightly-20230126-0420.1",
26
+ "commit": "3428a8c744066a319dc9afcce72c948f1a96f0b2"
27
27
  },
28
28
  {
29
29
  "author": "beachball",
30
30
  "package": "@fluentui/react-field",
31
- "comment": "Bump @fluentui/react-theme to v0.0.0-nightly-20230125-0418.1",
32
- "commit": "9ae3c86be8e1491c190d1b0c746d9ff238c36f75"
31
+ "comment": "Bump @fluentui/react-theme to v0.0.0-nightly-20230126-0420.1",
32
+ "commit": "3428a8c744066a319dc9afcce72c948f1a96f0b2"
33
33
  },
34
34
  {
35
35
  "author": "beachball",
36
36
  "package": "@fluentui/react-field",
37
- "comment": "Bump @fluentui/react-utilities to v0.0.0-nightly-20230125-0418.1",
38
- "commit": "9ae3c86be8e1491c190d1b0c746d9ff238c36f75"
37
+ "comment": "Bump @fluentui/react-utilities to v0.0.0-nightly-20230126-0420.1",
38
+ "commit": "3428a8c744066a319dc9afcce72c948f1a96f0b2"
39
39
  },
40
40
  {
41
41
  "author": "beachball",
42
42
  "package": "@fluentui/react-field",
43
- "comment": "Bump @fluentui/react-conformance-griffel to v0.0.0-nightly-20230125-0418.1",
44
- "commit": "9ae3c86be8e1491c190d1b0c746d9ff238c36f75"
43
+ "comment": "Bump @fluentui/react-conformance-griffel to v0.0.0-nightly-20230126-0420.1",
44
+ "commit": "3428a8c744066a319dc9afcce72c948f1a96f0b2"
45
45
  }
46
46
  ]
47
47
  }
package/CHANGELOG.md CHANGED
@@ -1,22 +1,22 @@
1
1
  # Change Log - @fluentui/react-field
2
2
 
3
- This log was last generated on Wed, 25 Jan 2023 04:25:37 GMT and should not be manually modified.
3
+ This log was last generated on Thu, 26 Jan 2023 04:27:47 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
- ## [0.0.0-nightly-20230125-0418.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-field_v0.0.0-nightly-20230125-0418.1)
7
+ ## [0.0.0-nightly-20230126-0420.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-field_v0.0.0-nightly-20230126-0420.1)
8
8
 
9
- Wed, 25 Jan 2023 04:25:37 GMT
10
- [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-field_v9.0.0-alpha.16..@fluentui/react-field_v0.0.0-nightly-20230125-0418.1)
9
+ Thu, 26 Jan 2023 04:27:47 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-field_v9.0.0-alpha.16..@fluentui/react-field_v0.0.0-nightly-20230126-0420.1)
11
11
 
12
12
  ### Changes
13
13
 
14
14
  - Release nightly v9 ([commit](https://github.com/microsoft/fluentui/commit/not available) by fluentui-internal@service.microsoft.com)
15
- - Bump @fluentui/react-context-selector to v0.0.0-nightly-20230125-0418.1 ([commit](https://github.com/microsoft/fluentui/commit/9ae3c86be8e1491c190d1b0c746d9ff238c36f75) by beachball)
16
- - Bump @fluentui/react-label to v0.0.0-nightly-20230125-0418.1 ([commit](https://github.com/microsoft/fluentui/commit/9ae3c86be8e1491c190d1b0c746d9ff238c36f75) by beachball)
17
- - Bump @fluentui/react-theme to v0.0.0-nightly-20230125-0418.1 ([commit](https://github.com/microsoft/fluentui/commit/9ae3c86be8e1491c190d1b0c746d9ff238c36f75) by beachball)
18
- - Bump @fluentui/react-utilities to v0.0.0-nightly-20230125-0418.1 ([commit](https://github.com/microsoft/fluentui/commit/9ae3c86be8e1491c190d1b0c746d9ff238c36f75) by beachball)
19
- - Bump @fluentui/react-conformance-griffel to v0.0.0-nightly-20230125-0418.1 ([commit](https://github.com/microsoft/fluentui/commit/9ae3c86be8e1491c190d1b0c746d9ff238c36f75) by beachball)
15
+ - Bump @fluentui/react-context-selector to v0.0.0-nightly-20230126-0420.1 ([commit](https://github.com/microsoft/fluentui/commit/3428a8c744066a319dc9afcce72c948f1a96f0b2) by beachball)
16
+ - Bump @fluentui/react-label to v0.0.0-nightly-20230126-0420.1 ([commit](https://github.com/microsoft/fluentui/commit/3428a8c744066a319dc9afcce72c948f1a96f0b2) by beachball)
17
+ - Bump @fluentui/react-theme to v0.0.0-nightly-20230126-0420.1 ([commit](https://github.com/microsoft/fluentui/commit/3428a8c744066a319dc9afcce72c948f1a96f0b2) by beachball)
18
+ - Bump @fluentui/react-utilities to v0.0.0-nightly-20230126-0420.1 ([commit](https://github.com/microsoft/fluentui/commit/3428a8c744066a319dc9afcce72c948f1a96f0b2) by beachball)
19
+ - Bump @fluentui/react-conformance-griffel to v0.0.0-nightly-20230126-0420.1 ([commit](https://github.com/microsoft/fluentui/commit/3428a8c744066a319dc9afcce72c948f1a96f0b2) by beachball)
20
20
 
21
21
  ## [9.0.0-alpha.16](https://github.com/microsoft/fluentui/tree/@fluentui/react-field_v9.0.0-alpha.16)
22
22
 
package/dist/index.d.ts CHANGED
@@ -2,55 +2,45 @@
2
2
 
3
3
  import type { ComponentProps } from '@fluentui/react-utilities';
4
4
  import type { ComponentState } from '@fluentui/react-utilities';
5
+ import { ForwardRefComponent } from '@fluentui/react-utilities';
5
6
  import { Label } from '@fluentui/react-label';
6
7
  import * as React_2 from 'react';
7
8
  import type { Slot } from '@fluentui/react-utilities';
8
9
  import type { SlotClassNames } from '@fluentui/react-utilities';
9
- import type { SlotRenderFunction } from '@fluentui/react-utilities';
10
- import type { SlotShorthandValue } from '@fluentui/react-utilities';
11
10
 
12
11
  /**
13
- * Configuration parameters for a Field class, passed to useField_unstable
12
+ * @deprecated Only for use to make deprecated [Control]Field shim components.
13
+ * @internal
14
14
  */
15
- export declare type FieldConfig<T extends FieldControl> = {
16
- /**
17
- * The underlying input component that this field is wrapping.
18
- */
19
- component: T;
20
- /**
21
- * Class names for this component, created by `getFieldClassNames`.
22
- */
23
- classNames: SlotClassNames<FieldSlots<T>>;
24
- /**
25
- * How the label be connected to the control.
26
- * * htmlFor - Set the Label's htmlFor prop to the component's ID (and generate an ID if not provided).
27
- * This is the preferred method for components that use the underlying <input> tag.
28
- * * aria-labelledby - Set the component's aria-labelledby prop to the Label's ID. Use this for components
29
- * that are not directly <input> elements (such as RadioGroup).
30
- *
31
- * @default htmlFor
32
- */
33
- labelConnection?: 'htmlFor' | 'aria-labelledby';
34
- /**
35
- * Should the aria-invalid attribute be set when validationState="error".
36
- *
37
- * @default true
38
- */
39
- ariaInvalidOnError?: boolean;
40
- };
15
+ export declare type DeprecatedFieldProps<ControlProps> = ControlProps & {
16
+ root?: FieldProps;
17
+ control?: ControlProps;
18
+ } & Pick<FieldProps, 'className' | 'hint' | 'label' | 'orientation' | 'style' | 'validationMessage' | 'validationMessageIcon' | 'validationState'>;
19
+
20
+ export declare const Field: ForwardRefComponent<FieldProps>;
41
21
 
42
22
  /**
43
- * The minimum requirement for a component used by Field.
44
- *
45
- * Note: the use of VoidFunctionComponent means that component is not *required* to have a children prop,
46
- * but it is still allowed to have a children prop.
23
+ * The props added to the Field's child element.
47
24
  */
48
- export declare type FieldControl = React_2.VoidFunctionComponent<Pick<React_2.HTMLAttributes<HTMLElement>, 'id' | 'className' | 'style' | 'aria-labelledby' | 'aria-describedby' | 'aria-invalid'>>;
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>;
49
28
 
50
29
  /**
51
30
  * Field Props
52
31
  */
53
- export declare type FieldProps<T extends FieldControl> = ComponentProps<Partial<FieldSlots<T>>, 'control'> & {
32
+ export declare type FieldProps = Omit<ComponentProps<FieldSlots>, 'children'> & {
33
+ /**
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.
36
+ *
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.
42
+ */
43
+ children?: React_2.ReactElement<FieldChildProps> | null | ((props: FieldChildProps) => React_2.ReactNode);
54
44
  /**
55
45
  * The orientation of the label relative to the field component.
56
46
  * This only affects the label, and not the validationMessage or hint (which always appear below the field component).
@@ -59,47 +49,30 @@ export declare type FieldProps<T extends FieldControl> = ComponentProps<Partial<
59
49
  */
60
50
  orientation?: 'vertical' | 'horizontal';
61
51
  /**
62
- * The `validationState` affects the color of the `validationMessage`, the `validationMessageIcon`, and for some
63
- * field components, an `validationState="error"` causes the border to become red.
52
+ * The `validationState` affects the color of the `validationMessage`, the `validationMessageIcon`
64
53
  *
65
- * @default undefined
54
+ * Setting `validationState` to `error` will also set `aria-invalid` to `true` on the Field's child,
55
+ * `role="alert"` on the `validationMessage`, and for some field components, causes the border to become red.
66
56
  */
67
57
  validationState?: 'error' | 'warning' | 'success';
68
- };
69
-
70
- /**
71
- * FieldProps plus extra optional props that are supported by useField_unstable, but not required to be part of the
72
- * API of every Field component.
73
- *
74
- * This allows Field to forward the required and size props to the label if the underlying component supports them,
75
- * but doesn't add them to the public API of fields that don't support them.
76
- */
77
- declare type FieldPropsWithOptionalComponentProps<T extends FieldControl> = FieldProps<T> & {
78
58
  /**
79
- * A ref to the underlying control.
80
- */
81
- ref?: React_2.Ref<HTMLElement>;
82
- /**
83
- * Whether the field label should be marked as required.
59
+ * Marks the Field as required. If `true`, an asterisk will be appended to the label, and `aria-required` will be set
60
+ * on the Field's child.
84
61
  */
85
62
  required?: boolean;
86
63
  /**
87
- * Size of the field label.
64
+ * The size of the Field's label.
88
65
  *
89
- * Number sizes will be ignored, but are allowed because the HTML `<input>` element has a prop `size?: number`.
66
+ * @default medium
90
67
  */
91
- size?: 'small' | 'medium' | 'large' | number;
68
+ size?: 'small' | 'medium' | 'large';
92
69
  };
93
70
 
94
71
  /**
95
- * Slots added by Field
72
+ * Slots of the Field component
96
73
  */
97
- export declare type FieldSlots<T extends FieldControl> = {
74
+ export declare type FieldSlots = {
98
75
  root: NonNullable<Slot<'div'>>;
99
- /**
100
- * The underlying component wrapped by this field.
101
- */
102
- control: SlotComponent<T>;
103
76
  /**
104
77
  * The label associated with the field.
105
78
  */
@@ -124,22 +97,34 @@ export declare type FieldSlots<T extends FieldControl> = {
124
97
  /**
125
98
  * State used in rendering Field
126
99
  */
127
- export declare type FieldState<T extends FieldControl> = ComponentState<Required<FieldSlots<T>>> & Pick<FieldProps<T>, 'orientation' | 'validationState'> & {
128
- classNames: SlotClassNames<FieldSlots<T>>;
100
+ export declare type FieldState = ComponentState<Required<FieldSlots>> & Pick<FieldProps, 'orientation' | 'validationState'>;
101
+
102
+ /**
103
+ * @deprecated Only for use to make deprecated [Control]Field shim components.
104
+ * @internal
105
+ */
106
+ export declare const getDeprecatedFieldClassNames: (controlRootClassName: string) => {
107
+ control: string;
108
+ root: string;
109
+ label: string;
110
+ validationMessage: string;
111
+ validationMessageIcon: string;
112
+ hint: string;
129
113
  };
130
114
 
131
- export declare const getFieldClassNames: (name: string) => SlotClassNames<FieldSlots<FieldControl>>;
115
+ /**
116
+ * @deprecated Only for use to make deprecated [Control]Field shim components.
117
+ * @internal
118
+ */
119
+ export declare function makeDeprecatedField<ControlProps>(Control: React_2.ComponentType<ControlProps>, options?: {
120
+ mapProps?: (props: DeprecatedFieldProps<ControlProps>) => DeprecatedFieldProps<ControlProps>;
121
+ displayName?: string;
122
+ }): ForwardRefComponent<DeprecatedFieldProps<ControlProps>>;
132
123
 
133
124
  /**
134
125
  * Render the final JSX of Field
135
126
  */
136
- export declare const renderField_unstable: <T extends FieldControl>(state: FieldState<T>) => JSX.Element;
137
-
138
- declare type SlotComponent<Type extends React_2.ComponentType | React_2.VoidFunctionComponent> = WithSlotShorthandValue<Type extends React_2.ComponentType<infer Props> ? WithSlotRenderFunction<Props extends {
139
- children?: unknown;
140
- } ? Props : Props & {
141
- children?: never;
142
- }> : never>;
127
+ export declare const renderField_unstable: (state: FieldState) => JSX.Element;
143
128
 
144
129
  /**
145
130
  * Create the state required to render Field.
@@ -148,24 +133,13 @@ declare type SlotComponent<Type extends React_2.ComponentType | React_2.VoidFunc
148
133
  * before being passed to renderField_unstable.
149
134
  *
150
135
  * @param props - Props passed to this field
151
- * @param ref - Ref to the control slot (primary slot)
152
- * @param params - Configuration parameters for this Field
136
+ * @param ref - Ref to the root
153
137
  */
154
- export declare const useField_unstable: <T extends FieldControl>(props: FieldPropsWithOptionalComponentProps<T>, ref: React_2.Ref<HTMLElement>, params: FieldConfig<T>) => FieldState<T>;
138
+ export declare const useField_unstable: (props: FieldProps, ref: React_2.Ref<HTMLDivElement>) => FieldState;
155
139
 
156
140
  /**
157
141
  * Apply styling to the Field slots based on the state
158
142
  */
159
- export declare const useFieldStyles_unstable: <T extends FieldControl>(state: FieldState<T>) => void;
160
-
161
- declare type WithSlotRenderFunction<Props extends {
162
- children?: unknown;
163
- }> = Props & {
164
- children?: Props['children'] | SlotRenderFunction<Props>;
165
- };
166
-
167
- declare type WithSlotShorthandValue<Props extends {
168
- children?: unknown;
169
- }> = Props | Extract<SlotShorthandValue, Props['children']>;
143
+ export declare const useFieldStyles_unstable: (state: FieldState) => void;
170
144
 
171
145
  export { }
@@ -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":"","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":"","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'\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 * A ref to the underlying control.\n */\n ref?: React.Ref<HTMLElement>;\n\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 attribute 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
+ {"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 } 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. 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 = 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 color of the `validationMessage`, the `validationMessageIcon`\n *\n * Setting `validationState` to `error` will also set `aria-invalid` to `true` on the Field's child,\n * `role=\"alert\"` on the `validationMessage`, and for some field components, causes the border to become red.\n */\n validationState?: 'error' | 'warning' | 'success';\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>> & 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":"","sources":["../../../../../../../../../packages/react-components/react-field/src/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":"","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"]}
@@ -12,9 +12,7 @@ export const renderField_unstable = state => {
12
12
  ...slotProps.root
13
13
  }, slots.label && /*#__PURE__*/React.createElement(slots.label, {
14
14
  ...slotProps.label
15
- }), slots.control && /*#__PURE__*/React.createElement(slots.control, {
16
- ...slotProps.control
17
- }), slots.validationMessage && /*#__PURE__*/React.createElement(slots.validationMessage, {
15
+ }), slotProps.root.children, slots.validationMessage && /*#__PURE__*/React.createElement(slots.validationMessage, {
18
16
  ...slotProps.validationMessage
19
17
  }, slots.validationMessageIcon && /*#__PURE__*/React.createElement(slots.validationMessageIcon, {
20
18
  ...slotProps.validationMessageIcon
@@ -1 +1 @@
1
- {"version":3,"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,QAAQ,QAAQ,2BAA2B;AAGpD;;;AAGA,OAAO,MAAMC,oBAAoB,GAA4BC,KAAoB,IAAI;EACnF,MAAM;IAAEC,KAAK;IAAEC;EAAS,CAAE,GAAGJ,QAAQ,CAA2BE,KAAiC,CAAC;EAElG,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,EAEnDH,KAAK,CAACI,OAAO,iBAAIR,oBAACI,KAAK,CAACI,OAAO;IAAA,GAAMH,SAAS,CAACG;EAAe,EAAI,EAClEJ,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,CAACE,QAAQ,CAExC,EACAP,KAAK,CAACQ,IAAI,iBAAIZ,oBAACI,KAAK,CAACQ,IAAI;IAAA,GAAKP,SAAS,CAACO;EAAI,EAAI,CACtC;AAEjB,CAAC","names":["React","getSlots","renderField_unstable","state","slots","slotProps","root","label","control","validationMessage","validationMessageIcon","children","hint"],"sourceRoot":"","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 { 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
+ {"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":"","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"]}
@@ -7,37 +7,6 @@ const validationMessageIcons = {
7
7
  warning: /*#__PURE__*/React.createElement(Warning12Filled, null),
8
8
  success: /*#__PURE__*/React.createElement(CheckmarkCircle12Filled, null)
9
9
  };
10
- /**
11
- * Partition the props used by the Field itself, from the props that are passed to the underlying field component.
12
- */
13
- export const getPartitionedFieldProps = props => {
14
- const {
15
- className,
16
- control,
17
- hint,
18
- label,
19
- orientation,
20
- root,
21
- style,
22
- validationMessage,
23
- validationMessageIcon,
24
- validationState,
25
- ...restOfProps
26
- } = props;
27
- const fieldProps = {
28
- className,
29
- control,
30
- hint,
31
- label,
32
- orientation,
33
- root,
34
- style,
35
- validationMessage,
36
- validationMessageIcon,
37
- validationState
38
- };
39
- return [fieldProps, restOfProps];
40
- };
41
10
  /**
42
11
  * Create the state required to render Field.
43
12
  *
@@ -45,54 +14,58 @@ export const getPartitionedFieldProps = props => {
45
14
  * before being passed to renderField_unstable.
46
15
  *
47
16
  * @param props - Props passed to this field
48
- * @param ref - Ref to the control slot (primary slot)
49
- * @param params - Configuration parameters for this Field
17
+ * @param ref - Ref to the root
50
18
  */
51
- export const useField_unstable = (props, ref, params) => {
52
- var _a, _b, _c;
53
- const [fieldProps, controlProps] = getPartitionedFieldProps(props);
19
+ export const useField_unstable = (props, ref) => {
20
+ var _a, _b, _c, _d;
54
21
  const {
22
+ children,
55
23
  orientation = 'vertical',
56
- validationState
57
- } = fieldProps;
58
- const {
59
- labelConnection = 'htmlFor',
60
- ariaInvalidOnError = true
61
- } = params;
24
+ required,
25
+ validationState,
26
+ size
27
+ } = props;
62
28
  const baseId = useId('field-');
63
- const root = resolveShorthand(fieldProps.root, {
64
- required: true,
65
- defaultProps: getNativeElementProps('div', fieldProps)
66
- });
67
- const label = resolveShorthand(fieldProps.label, {
29
+ const root = getNativeElementProps('div', {
30
+ ...props,
31
+ ref
32
+ }, /*excludedPropNames:*/['children']);
33
+ const label = resolveShorthand(props.label, {
68
34
  defaultProps: {
69
35
  id: baseId + '__label',
70
- required: controlProps.required,
71
- size: typeof controlProps.size === 'string' ? controlProps.size : undefined
36
+ required,
37
+ size
72
38
  // htmlFor is handled below
73
39
  }
74
40
  });
75
41
 
76
- const validationMessage = resolveShorthand(fieldProps.validationMessage, {
42
+ const validationMessage = resolveShorthand(props.validationMessage, {
77
43
  defaultProps: {
78
44
  id: baseId + '__validationMessage',
79
45
  role: validationState === 'error' ? 'alert' : undefined
80
46
  }
81
47
  });
82
- const hint = resolveShorthand(fieldProps.hint, {
48
+ const hint = resolveShorthand(props.hint, {
83
49
  defaultProps: {
84
50
  id: baseId + '__hint'
85
51
  }
86
52
  });
87
- const validationMessageIcon = resolveShorthand(fieldProps.validationMessageIcon, {
53
+ const validationMessageIcon = resolveShorthand(props.validationMessageIcon, {
88
54
  required: !!validationState,
89
55
  defaultProps: {
90
56
  children: validationState ? validationMessageIcons[validationState] : undefined
91
57
  }
92
58
  });
93
- // Hook up aria props on the control
94
- if (label && labelConnection === 'aria-labelledby') {
59
+ const controlProps = /*#__PURE__*/React.isValidElement(children) ? {
60
+ ...children.props
61
+ } : {};
62
+ if (label) {
95
63
  (_a = controlProps['aria-labelledby']) !== null && _a !== void 0 ? _a : controlProps['aria-labelledby'] = label.id;
64
+ if (!label.htmlFor) {
65
+ // Assign the child a generated ID if doesn't already have an ID
66
+ (_b = controlProps.id) !== null && _b !== void 0 ? _b : controlProps.id = baseId + '__control';
67
+ label.htmlFor = controlProps.id;
68
+ }
96
69
  }
97
70
  if (validationMessage || hint) {
98
71
  // The control is described by the validation message, or hint, or both
@@ -100,39 +73,32 @@ export const useField_unstable = (props, ref, params) => {
100
73
  // For reference: https://github.com/microsoft/fluentui/pull/25580#discussion_r1017259933
101
74
  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(' ');
102
75
  }
103
- if (validationState === 'error' && ariaInvalidOnError) {
104
- (_b = controlProps['aria-invalid']) !== null && _b !== void 0 ? _b : controlProps['aria-invalid'] = true;
76
+ if (validationState === 'error') {
77
+ (_c = controlProps['aria-invalid']) !== null && _c !== void 0 ? _c : controlProps['aria-invalid'] = true;
105
78
  }
106
- const control = resolveShorthand(fieldProps.control, {
107
- required: true,
108
- defaultProps: {
109
- ref,
110
- id: baseId + '__control',
111
- ...controlProps
112
- }
113
- });
114
- if (label && labelConnection === 'htmlFor') {
115
- (_c = label.htmlFor) !== null && _c !== void 0 ? _c : label.htmlFor = control.id;
79
+ if (required) {
80
+ (_d = controlProps['aria-required']) !== null && _d !== void 0 ? _d : controlProps['aria-required'] = true;
81
+ }
82
+ if ( /*#__PURE__*/React.isValidElement(children)) {
83
+ root.children = /*#__PURE__*/React.cloneElement(children, controlProps);
84
+ } else if (typeof children === 'function') {
85
+ root.children = children(controlProps);
116
86
  }
117
- const state = {
87
+ return {
118
88
  orientation,
119
89
  validationState,
120
- classNames: params.classNames,
121
90
  components: {
122
91
  root: 'div',
123
- control: params.component,
124
92
  label: Label,
125
93
  validationMessage: 'div',
126
94
  validationMessageIcon: 'span',
127
95
  hint: 'div'
128
96
  },
129
97
  root,
130
- control,
131
98
  label,
132
99
  validationMessageIcon,
133
100
  validationMessage,
134
101
  hint
135
102
  };
136
- return state;
137
103
  };
138
104
  //# sourceMappingURL=useField.js.map
@@ -1 +1 @@
1
- {"version":3,"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,uBAAuB,EAAEC,mBAAmB,EAAEC,eAAe,QAAQ,uBAAuB;AACrG,SAASC,KAAK,QAAQ,uBAAuB;AAC7C,SAASC,qBAAqB,EAAEC,gBAAgB,EAAEC,KAAK,QAAQ,2BAA2B;AAG1F,MAAMC,sBAAsB,GAAG;EAC7BC,KAAK,eAAET,oBAACE,mBAAmB,OAAG;EAC9BQ,OAAO,eAAEV,oBAACG,eAAe,OAAG;EAC5BQ,OAAO,eAAEX,oBAACC,uBAAuB;CACzB;AAEV;;;AAGA,OAAO,MAAMW,wBAAwB,GAAIC,KAAyD,IAAI;EACpG,MAAM;IACJC,SAAS;IACTC,OAAO;IACPC,IAAI;IACJC,KAAK;IACLC,WAAW;IACXC,IAAI;IACJC,KAAK;IACLC,iBAAiB;IACjBC,qBAAqB;IACrBC,eAAe;IACf,GAAGC;EAAW,CACf,GAAGX,KAAK;EAET,MAAMY,UAAU,GAAG;IACjBX,SAAS;IACTC,OAAO;IACPC,IAAI;IACJC,KAAK;IACLC,WAAW;IACXC,IAAI;IACJC,KAAK;IACLC,iBAAiB;IACjBC,qBAAqB;IACrBC;GACD;EAED,OAAO,CAACE,UAAU,EAAED,WAAW,CAAU;AAC3C,CAAC;AAED;;;;;;;;;;AAUA,OAAO,MAAME,iBAAiB,GAAG,CAC/Bb,KAA8C,EAC9Cc,GAA2B,EAC3BC,MAAsB,KACL;;EACjB,MAAM,CAACH,UAAU,EAAEI,YAAY,CAAC,GAAGjB,wBAAwB,CAACC,KAAK,CAAC;EAClE,MAAM;IAAEK,WAAW,GAAG,UAAU;IAAEK;EAAe,CAAE,GAAGE,UAAU;EAChE,MAA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orCircle12Filled","Warning12Filled","Label","getNativeElementProps","resolveShorthand","useId","validationMessageIcons","error","warning","success","getPartitionedFieldProps","props","className","control","hint","label","orientation","root","style","validationMessage","validationMessageIcon","validationState","restOfProps","fieldProps","useField_unstable","ref","params","controlProps","labelConnection","ariaInvalidOnError","baseId","required","defaultProps","id","size","undefined","role","children","filter","Boolean","join","htmlFor","state","classNames","components","component"],"sourceRoot":"","sources":["../../../../../../../../../packages/react-components/react-field/src/components/Field/useField.tsx"],"sourcesContent":["import * as React from 'react';\nimport { CheckmarkCircle12Filled, ErrorCircle12Filled, Warning12Filled } from '@fluentui/react-icons';\nimport { Label } from '@fluentui/react-label';\nimport { getNativeElementProps, resolveShorthand, useId } from '@fluentui/react-utilities';\nimport type { FieldConfig, FieldControl, FieldPropsWithOptionalComponentProps, FieldState } from './Field.types';\n\nconst validationMessageIcons = {\n error: <ErrorCircle12Filled />,\n warning: <Warning12Filled />,\n success: <CheckmarkCircle12Filled />,\n} as const;\n\n/**\n * Partition the props used by the Field itself, from the props that are passed to the underlying field component.\n */\nexport const getPartitionedFieldProps = (props: FieldPropsWithOptionalComponentProps<FieldControl>) => {\n const {\n className,\n control,\n hint,\n label,\n orientation,\n root,\n style,\n validationMessage,\n validationMessageIcon,\n validationState,\n ...restOfProps\n } = props;\n\n const fieldProps = {\n className,\n control,\n hint,\n label,\n orientation,\n root,\n style,\n validationMessage,\n validationMessageIcon,\n validationState,\n };\n\n return [fieldProps, restOfProps] as const;\n};\n\n/**\n * Create the state required to render Field.\n *\n * The returned state can be modified with hooks such as useFieldStyles_unstable,\n * before being passed to renderField_unstable.\n *\n * @param props - Props passed to this field\n * @param ref - Ref to the control slot (primary slot)\n * @param params - Configuration parameters for this Field\n */\nexport const useField_unstable = <T extends FieldControl>(\n props: FieldPropsWithOptionalComponentProps<T>,\n ref: React.Ref<HTMLElement>,\n params: FieldConfig<T>,\n): FieldState<T> => {\n const [fieldProps, controlProps] = getPartitionedFieldProps(props);\n const { orientation = 'vertical', validationState } = fieldProps;\n const { labelConnection = 'htmlFor', ariaInvalidOnError = true } = params;\n\n const baseId = useId('field-');\n\n const root = resolveShorthand(fieldProps.root, {\n required: true,\n defaultProps: getNativeElementProps('div', fieldProps),\n });\n\n const label = resolveShorthand(fieldProps.label, {\n defaultProps: {\n id: baseId + '__label',\n required: controlProps.required,\n size: typeof controlProps.size === 'string' ? controlProps.size : undefined,\n // htmlFor is handled below\n },\n });\n\n const validationMessage = resolveShorthand(fieldProps.validationMessage, {\n defaultProps: {\n id: baseId + '__validationMessage',\n role: validationState === 'error' ? 'alert' : undefined,\n },\n });\n\n const hint = resolveShorthand(fieldProps.hint, {\n defaultProps: {\n id: baseId + '__hint',\n },\n });\n\n const validationMessageIcon = resolveShorthand(fieldProps.validationMessageIcon, {\n required: !!validationState,\n defaultProps: {\n children: validationState ? validationMessageIcons[validationState] : undefined,\n },\n });\n\n // Hook up aria props on the control\n if (label && labelConnection === 'aria-labelledby') {\n controlProps['aria-labelledby'] ??= label.id;\n }\n\n if (validationMessage || hint) {\n // The control is described by the validation message, or hint, or both\n // We also preserve and append any aria-describedby supplied by the user\n // For reference: https://github.com/microsoft/fluentui/pull/25580#discussion_r1017259933\n controlProps['aria-describedby'] = [validationMessage?.id, hint?.id, controlProps['aria-describedby']]\n .filter(Boolean)\n .join(' ');\n }\n\n if (validationState === 'error' && ariaInvalidOnError) {\n controlProps['aria-invalid'] ??= true;\n }\n\n const control = resolveShorthand(fieldProps.control, {\n required: true,\n defaultProps: {\n ref,\n id: baseId + '__control',\n ...controlProps,\n },\n });\n\n if (label && labelConnection === 'htmlFor') {\n label.htmlFor ??= control.id;\n }\n\n const state: FieldState<FieldControl> = {\n orientation,\n validationState,\n classNames: params.classNames,\n components: {\n root: 'div',\n control: params.component,\n label: Label,\n validationMessage: 'div',\n validationMessageIcon: 'span',\n hint: 'div',\n },\n root,\n control,\n label,\n validationMessageIcon,\n validationMessage,\n hint,\n };\n\n return state as FieldState<T>;\n};\n"]}
1
+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;IAClCM,IAAI,CAACN,QAAQ,gBAAGf,KAAK,CAACoC,YAAY,CAACrB,QAAQ,EAAEe,YAAY,CAAC;GAC3D,MAAM,IAAI,OAAOf,QAAQ,KAAK,UAAU,EAAE;IACzCM,IAAI,CAACN,QAAQ,GAAGA,QAAQ,CAACe,YAAY,CAAC;;EAGxC,OAAO;IACLd,WAAW;IACXE,eAAe;IACfmB,UAAU,EAAE;MACVhB,IAAI,EAAE,KAAK;MACXC,KAAK,EAAElB,KAAK;MACZqB,iBAAiB,EAAE,KAAK;MACxBI,qBAAqB,EAAE,MAAM;MAC7BD,IAAI,EAAE;KACP;IACDP,IAAI;IACJC,KAAK;IACLO,qBAAqB;IACrBJ,iBAAiB;IACjBG;GACD;AACH,CAAC","names":["React","CheckmarkCircle12Filled","ErrorCircle12Filled","Warning12Filled","Label","getNativeElementProps","resolveShorthand","useId","validationMessageIcons","error","warning","success","useField_unstable","props","ref","children","orientation","required","validationState","size","baseId","root","label","defaultProps","id","validationMessage","role","undefined","hint","validationMessageIcon","controlProps","isValidElement","htmlFor","filter","Boolean","join","cloneElement","components"],"sourceRoot":"","sources":["../../../../../../../../../packages/react-components/react-field/src/components/Field/useField.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { CheckmarkCircle12Filled, ErrorCircle12Filled, Warning12Filled } from '@fluentui/react-icons';\nimport { Label } from '@fluentui/react-label';\nimport { getNativeElementProps, resolveShorthand, useId } from '@fluentui/react-utilities';\nimport type { FieldChildProps, FieldProps, FieldState } from './Field.types';\n\nconst validationMessageIcons = {\n error: <ErrorCircle12Filled />,\n warning: <Warning12Filled />,\n success: <CheckmarkCircle12Filled />,\n} as const;\n\n/**\n * Create the state required to render Field.\n *\n * The returned state can be modified with hooks such as useFieldStyles_unstable,\n * before being passed to renderField_unstable.\n *\n * @param props - Props passed to this field\n * @param ref - Ref to the root\n */\nexport const useField_unstable = (props: FieldProps, ref: React.Ref<HTMLDivElement>): FieldState => {\n const { children, orientation = 'vertical', required, validationState, size } = props;\n\n const baseId = useId('field-');\n\n const root = getNativeElementProps('div', { ...props, ref }, /*excludedPropNames:*/ ['children']);\n\n const label = resolveShorthand(props.label, {\n defaultProps: {\n id: baseId + '__label',\n required,\n size,\n // htmlFor is handled below\n },\n });\n\n const validationMessage = resolveShorthand(props.validationMessage, {\n defaultProps: {\n id: baseId + '__validationMessage',\n role: validationState === 'error' ? 'alert' : undefined,\n },\n });\n\n const hint = resolveShorthand(props.hint, {\n defaultProps: {\n id: baseId + '__hint',\n },\n });\n\n const validationMessageIcon = resolveShorthand(props.validationMessageIcon, {\n required: !!validationState,\n defaultProps: {\n children: validationState ? validationMessageIcons[validationState] : undefined,\n },\n });\n\n const controlProps: FieldChildProps = React.isValidElement(children) ? { ...children.props } : {};\n\n if (label) {\n controlProps['aria-labelledby'] ??= label.id;\n\n if (!label.htmlFor) {\n // Assign the child a generated ID if doesn't already have an ID\n controlProps.id ??= baseId + '__control';\n label.htmlFor = controlProps.id;\n }\n }\n\n if (validationMessage || hint) {\n // The control is described by the validation message, or hint, or both\n // We also preserve and append any aria-describedby supplied by the user\n // For reference: https://github.com/microsoft/fluentui/pull/25580#discussion_r1017259933\n controlProps['aria-describedby'] = [validationMessage?.id, hint?.id, controlProps['aria-describedby']]\n .filter(Boolean)\n .join(' ');\n }\n\n if (validationState === 'error') {\n controlProps['aria-invalid'] ??= true;\n }\n\n if (required) {\n controlProps['aria-required'] ??= true;\n }\n\n if (React.isValidElement(children)) {\n root.children = React.cloneElement(children, controlProps);\n } else if (typeof children === 'function') {\n root.children = children(controlProps);\n }\n\n return {\n orientation,\n validationState,\n components: {\n root: 'div',\n label: Label,\n validationMessage: 'div',\n validationMessageIcon: 'span',\n hint: 'div',\n },\n root,\n label,\n validationMessageIcon,\n validationMessage,\n hint,\n };\n};\n"]}