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

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useField.js","sourceRoot":"","sources":["../../../../../../../../../packages/react-components/react-field/src/components/Field/useField.tsx"],"names":[],"mappings":";;;;IAOA,IAAM,sBAAsB,GAAG;QAC7B,KAAK,EAAE,oBAAC,iCAAmB,OAAG;QAC9B,OAAO,EAAE,oBAAC,6BAAe,OAAG;QAC5B,OAAO,EAAE,oBAAC,qCAAuB,OAAG;QACpC,IAAI,EAAE,SAAS;KACP,CAAC;IAEX;;;;;;;;OAQG;IACI,IAAM,iBAAiB,GAAG,UAAC,KAAiB,EAAE,GAA8B;;QAE/E,IAAA,QAAQ,GAKN,KAAK,SALC,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,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAC;SACxC;QAED,OAAO;YACL,WAAW,aAAA;YACX,eAAe,iBAAA;YACf,UAAU,EAAE;gBACV,IAAI,EAAE,KAAK;gBACX,KAAK,EAAE,mBAAK;gBACZ,iBAAiB,EAAE,KAAK;gBACxB,qBAAqB,EAAE,MAAM;gBAC7B,IAAI,EAAE,KAAK;aACZ;YACD,IAAI,MAAA;YACJ,KAAK,OAAA;YACL,qBAAqB,uBAAA;YACrB,iBAAiB,mBAAA;YACjB,IAAI,MAAA;SACL,CAAC;IACJ,CAAC,CAAC;IA9FW,QAAA,iBAAiB,qBA8F5B","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 none: undefined,\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 {\n children,\n orientation = 'vertical',\n required,\n validationState = props.validationMessage ? 'error' : 'none',\n size,\n } = 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 defaultIcon = validationMessageIcons[validationState];\n const validationMessageIcon = resolveShorthand(props.validationMessageIcon, {\n required: !!defaultIcon,\n defaultProps: {\n children: defaultIcon,\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"]}
@@ -0,0 +1,115 @@
1
+ define(["require", "exports", "tslib", "@fluentui/react-theme", "@griffel/react"], function (require, exports, tslib_1, react_theme_1, react_1) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.useFieldStyles_unstable = exports.fieldClassNames = void 0;
5
+ exports.fieldClassNames = {
6
+ root: "fui-Field",
7
+ label: "fui-Field__label",
8
+ validationMessage: "fui-Field__validationMessage",
9
+ validationMessageIcon: "fui-Field__validationMessageIcon",
10
+ hint: "fui-Field__hint",
11
+ };
12
+ // Size of the icon in the validation message
13
+ var iconSize = '12px';
14
+ /**
15
+ * Styles for the root slot
16
+ */
17
+ var useRootStyles = react_1.makeStyles({
18
+ base: {
19
+ display: 'grid',
20
+ },
21
+ // In horizontal layout, the field is a grid with the label taking up the entire first column.
22
+ // The last row is slack space in case the label is taller than the rest of the content.
23
+ horizontal: {
24
+ gridTemplateColumns: '33% 1fr',
25
+ gridTemplateRows: 'auto auto auto 1fr',
26
+ },
27
+ // In horizontal layout without a label, replace the label's column with padding.
28
+ // This lets grid auto-flow properly place the other children, and keeps fields with and without labels aligned.
29
+ horizontalNoLabel: {
30
+ paddingLeft: '33%',
31
+ gridTemplateColumns: '1fr',
32
+ },
33
+ });
34
+ var useLabelStyles = react_1.makeStyles({
35
+ base: {
36
+ paddingTop: react_theme_1.tokens.spacingVerticalXXS,
37
+ paddingBottom: react_theme_1.tokens.spacingVerticalXXS,
38
+ },
39
+ large: {
40
+ paddingTop: '1px',
41
+ paddingBottom: '1px',
42
+ },
43
+ vertical: {
44
+ marginBottom: react_theme_1.tokens.spacingVerticalXXS,
45
+ },
46
+ verticalLarge: {
47
+ marginBottom: react_theme_1.tokens.spacingVerticalXS,
48
+ },
49
+ horizontal: {
50
+ marginRight: react_theme_1.tokens.spacingHorizontalM,
51
+ gridRowStart: '1',
52
+ gridRowEnd: '-1',
53
+ },
54
+ });
55
+ var useSecondaryTextBaseClassName = react_1.makeResetStyles(tslib_1.__assign({ marginTop: react_theme_1.tokens.spacingVerticalXXS, color: react_theme_1.tokens.colorNeutralForeground3 }, react_theme_1.typographyStyles.caption1));
56
+ var useSecondaryTextStyles = react_1.makeStyles({
57
+ error: {
58
+ color: react_theme_1.tokens.colorPaletteRedForeground1,
59
+ },
60
+ withIcon: {
61
+ // Add a gutter for the icon, to allow multiple lines of text to line up to the right of the icon.
62
+ paddingLeft: "calc(" + iconSize + " + " + react_theme_1.tokens.spacingHorizontalXS + ")",
63
+ },
64
+ });
65
+ var useValidationMessageIconBaseClassName = react_1.makeResetStyles({
66
+ display: 'inline-block',
67
+ fontSize: iconSize,
68
+ // Negative left margin puts the icon in the gutter of the validation message div's withIcon style.
69
+ marginLeft: "calc(-" + iconSize + " - " + react_theme_1.tokens.spacingHorizontalXS + ")",
70
+ marginRight: react_theme_1.tokens.spacingHorizontalXS,
71
+ // Line height of 0 prevents the verticalAlign from affecting the line height of the text.
72
+ lineHeight: '0',
73
+ // Negative verticalAlign shifts the inline icon down to align with the text (effectively top padding).
74
+ verticalAlign: '-1px',
75
+ });
76
+ var useValidationMessageIconStyles = react_1.makeStyles({
77
+ error: {
78
+ color: react_theme_1.tokens.colorPaletteRedForeground1,
79
+ },
80
+ warning: {
81
+ color: react_theme_1.tokens.colorPaletteDarkOrangeForeground1,
82
+ },
83
+ success: {
84
+ color: react_theme_1.tokens.colorPaletteGreenForeground1,
85
+ },
86
+ });
87
+ /**
88
+ * Apply styling to the Field slots based on the state
89
+ */
90
+ var useFieldStyles_unstable = function (state) {
91
+ var validationState = state.validationState;
92
+ var horizontal = state.orientation === 'horizontal';
93
+ var rootStyles = useRootStyles();
94
+ state.root.className = react_1.mergeClasses(exports.fieldClassNames.root, rootStyles.base, horizontal && rootStyles.horizontal, horizontal && !state.label && rootStyles.horizontalNoLabel, state.root.className);
95
+ var labelStyles = useLabelStyles();
96
+ if (state.label) {
97
+ state.label.className = react_1.mergeClasses(exports.fieldClassNames.label, labelStyles.base, horizontal && labelStyles.horizontal, !horizontal && labelStyles.vertical, state.label.size === 'large' && labelStyles.large, !horizontal && state.label.size === 'large' && labelStyles.verticalLarge, state.label.className);
98
+ }
99
+ var validationMessageIconBaseClassName = useValidationMessageIconBaseClassName();
100
+ var validationMessageIconStyles = useValidationMessageIconStyles();
101
+ if (state.validationMessageIcon) {
102
+ state.validationMessageIcon.className = react_1.mergeClasses(exports.fieldClassNames.validationMessageIcon, validationMessageIconBaseClassName, validationState !== 'none' && validationMessageIconStyles[validationState], state.validationMessageIcon.className);
103
+ }
104
+ var secondaryTextBaseClassName = useSecondaryTextBaseClassName();
105
+ var secondaryTextStyles = useSecondaryTextStyles();
106
+ if (state.validationMessage) {
107
+ state.validationMessage.className = react_1.mergeClasses(exports.fieldClassNames.validationMessage, secondaryTextBaseClassName, validationState === 'error' && secondaryTextStyles.error, !!state.validationMessageIcon && secondaryTextStyles.withIcon, state.validationMessage.className);
108
+ }
109
+ if (state.hint) {
110
+ state.hint.className = react_1.mergeClasses(exports.fieldClassNames.hint, secondaryTextBaseClassName, state.hint.className);
111
+ }
112
+ };
113
+ exports.useFieldStyles_unstable = useFieldStyles_unstable;
114
+ });
115
+ //# sourceMappingURL=useFieldStyles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFieldStyles.js","sourceRoot":"","sources":["../../../../../../../../../packages/react-components/react-field/src/components/Field/useFieldStyles.ts"],"names":[],"mappings":";;;;IAKa,QAAA,eAAe,GAA+B;QACzD,IAAI,EAAE,WAAW;QACjB,KAAK,EAAE,kBAAkB;QACzB,iBAAiB,EAAE,8BAA8B;QACjD,qBAAqB,EAAE,kCAAkC;QACzD,IAAI,EAAE,iBAAiB;KACxB,CAAC;IAEF,6CAA6C;IAC7C,IAAM,QAAQ,GAAG,MAAM,CAAC;IAExB;;OAEG;IACH,IAAM,aAAa,GAAG,kBAAU,CAAC;QAC/B,IAAI,EAAE;YACJ,OAAO,EAAE,MAAM;SAChB;QAED,8FAA8F;QAC9F,wFAAwF;QACxF,UAAU,EAAE;YACV,mBAAmB,EAAE,SAAS;YAC9B,gBAAgB,EAAE,oBAAoB;SACvC;QAED,iFAAiF;QACjF,gHAAgH;QAChH,iBAAiB,EAAE;YACjB,WAAW,EAAE,KAAK;YAClB,mBAAmB,EAAE,KAAK;SAC3B;KACF,CAAC,CAAC;IAEH,IAAM,cAAc,GAAG,kBAAU,CAAC;QAChC,IAAI,EAAE;YACJ,UAAU,EAAE,oBAAM,CAAC,kBAAkB;YACrC,aAAa,EAAE,oBAAM,CAAC,kBAAkB;SACzC;QAED,KAAK,EAAE;YACL,UAAU,EAAE,KAAK;YACjB,aAAa,EAAE,KAAK;SACrB;QAED,Q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,EAAE,CAAC;QACnE,IAAM,mBAAmB,GAAG,sBAAsB,EAAE,CAAC;QACrD,IAAI,KAAK,CAAC,iBAAiB,EAAE;YAC3B,KAAK,CAAC,iBAAiB,CAAC,SAAS,GAAG,oBAAY,CAC9C,uBAAe,CAAC,iBAAiB,EACjC,0BAA0B,EAC1B,eAAe,KAAK,OAAO,IAAI,mBAAmB,CAAC,KAAK,EACxD,CAAC,CAAC,KAAK,CAAC,qBAAqB,IAAI,mBAAmB,CAAC,QAAQ,EAC7D,KAAK,CAAC,iBAAiB,CAAC,SAAS,CAClC,CAAC;SACH;QAED,IAAI,KAAK,CAAC,IAAI,EAAE;YACd,KAAK,CAAC,IAAI,CAAC,SAAS,GAAG,oBAAY,CAAC,uBAAe,CAAC,IAAI,EAAE,0BAA0B,EAAE,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;SAC7G;IACH,CAAC,CAAC;IApDW,QAAA,uBAAuB,2BAoDlC","sourcesContent":["import { tokens, typographyStyles } from '@fluentui/react-theme';\nimport type { SlotClassNames } from '@fluentui/react-utilities';\nimport { makeResetStyles, makeStyles, mergeClasses } from '@griffel/react';\nimport type { FieldSlots, FieldState } from './Field.types';\n\nexport const fieldClassNames: SlotClassNames<FieldSlots> = {\n root: `fui-Field`,\n label: `fui-Field__label`,\n validationMessage: `fui-Field__validationMessage`,\n validationMessageIcon: `fui-Field__validationMessageIcon`,\n hint: `fui-Field__hint`,\n};\n\n// Size of the icon in the validation message\nconst iconSize = '12px';\n\n/**\n * Styles for the root slot\n */\nconst useRootStyles = makeStyles({\n base: {\n display: 'grid',\n },\n\n // In horizontal layout, the field is a grid with the label taking up the entire first column.\n // The last row is slack space in case the label is taller than the rest of the content.\n horizontal: {\n gridTemplateColumns: '33% 1fr',\n gridTemplateRows: 'auto auto auto 1fr',\n },\n\n // In horizontal layout without a label, replace the label's column with padding.\n // This lets grid auto-flow properly place the other children, and keeps fields with and without labels aligned.\n horizontalNoLabel: {\n paddingLeft: '33%',\n gridTemplateColumns: '1fr',\n },\n});\n\nconst useLabelStyles = makeStyles({\n base: {\n paddingTop: tokens.spacingVerticalXXS,\n paddingBottom: tokens.spacingVerticalXXS,\n },\n\n large: {\n paddingTop: '1px',\n paddingBottom: '1px',\n },\n\n vertical: {\n marginBottom: tokens.spacingVerticalXXS,\n },\n\n verticalLarge: {\n marginBottom: tokens.spacingVerticalXS,\n },\n\n horizontal: {\n marginRight: tokens.spacingHorizontalM,\n gridRowStart: '1',\n gridRowEnd: '-1',\n },\n});\n\nconst useSecondaryTextBaseClassName = makeResetStyles({\n marginTop: tokens.spacingVerticalXXS,\n color: tokens.colorNeutralForeground3,\n ...typographyStyles.caption1,\n});\n\nconst useSecondaryTextStyles = makeStyles({\n error: {\n color: tokens.colorPaletteRedForeground1,\n },\n\n withIcon: {\n // Add a gutter for the icon, to allow multiple lines of text to line up to the right of the icon.\n paddingLeft: `calc(${iconSize} + ${tokens.spacingHorizontalXS})`,\n },\n});\n\nconst useValidationMessageIconBaseClassName = makeResetStyles({\n display: 'inline-block',\n fontSize: iconSize,\n // Negative left margin puts the icon in the gutter of the validation message div's withIcon style.\n marginLeft: `calc(-${iconSize} - ${tokens.spacingHorizontalXS})`,\n marginRight: tokens.spacingHorizontalXS,\n // Line height of 0 prevents the verticalAlign from affecting the line height of the text.\n lineHeight: '0',\n // Negative verticalAlign shifts the inline icon down to align with the text (effectively top padding).\n verticalAlign: '-1px',\n});\n\nconst useValidationMessageIconStyles = makeStyles({\n error: {\n color: tokens.colorPaletteRedForeground1,\n },\n warning: {\n color: tokens.colorPaletteDarkOrangeForeground1,\n },\n success: {\n color: tokens.colorPaletteGreenForeground1,\n },\n});\n\n/**\n * Apply styling to the Field slots based on the state\n */\nexport const useFieldStyles_unstable = (state: FieldState) => {\n const { validationState } = state;\n const horizontal = state.orientation === 'horizontal';\n\n const rootStyles = useRootStyles();\n state.root.className = mergeClasses(\n fieldClassNames.root,\n rootStyles.base,\n horizontal && rootStyles.horizontal,\n horizontal && !state.label && rootStyles.horizontalNoLabel,\n state.root.className,\n );\n\n const labelStyles = useLabelStyles();\n if (state.label) {\n state.label.className = mergeClasses(\n fieldClassNames.label,\n labelStyles.base,\n horizontal && labelStyles.horizontal,\n !horizontal && labelStyles.vertical,\n state.label.size === 'large' && labelStyles.large,\n !horizontal && state.label.size === 'large' && labelStyles.verticalLarge,\n state.label.className,\n );\n }\n\n const validationMessageIconBaseClassName = useValidationMessageIconBaseClassName();\n const validationMessageIconStyles = useValidationMessageIconStyles();\n if (state.validationMessageIcon) {\n state.validationMessageIcon.className = mergeClasses(\n fieldClassNames.validationMessageIcon,\n validationMessageIconBaseClassName,\n validationState !== 'none' && validationMessageIconStyles[validationState],\n state.validationMessageIcon.className,\n );\n }\n\n const secondaryTextBaseClassName = useSecondaryTextBaseClassName();\n const secondaryTextStyles = useSecondaryTextStyles();\n if (state.validationMessage) {\n state.validationMessage.className = mergeClasses(\n fieldClassNames.validationMessage,\n secondaryTextBaseClassName,\n validationState === 'error' && secondaryTextStyles.error,\n !!state.validationMessageIcon && secondaryTextStyles.withIcon,\n state.validationMessage.className,\n );\n }\n\n if (state.hint) {\n state.hint.className = mergeClasses(fieldClassNames.hint, secondaryTextBaseClassName, state.hint.className);\n }\n};\n"]}
@@ -0,0 +1,13 @@
1
+ define(["require", "exports", "./Field", "./util/makeDeprecatedField"], function (require, exports, Field_1, makeDeprecatedField_1) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.makeDeprecatedField = exports.getDeprecatedFieldClassNames = exports.useField_unstable = exports.useFieldStyles_unstable = exports.renderField_unstable = exports.fieldClassNames = exports.Field = void 0;
5
+ Object.defineProperty(exports, "Field", { enumerable: true, get: function () { return Field_1.Field; } });
6
+ Object.defineProperty(exports, "fieldClassNames", { enumerable: true, get: function () { return Field_1.fieldClassNames; } });
7
+ Object.defineProperty(exports, "renderField_unstable", { enumerable: true, get: function () { return Field_1.renderField_unstable; } });
8
+ Object.defineProperty(exports, "useFieldStyles_unstable", { enumerable: true, get: function () { return Field_1.useFieldStyles_unstable; } });
9
+ Object.defineProperty(exports, "useField_unstable", { enumerable: true, get: function () { return Field_1.useField_unstable; } });
10
+ Object.defineProperty(exports, "getDeprecatedFieldClassNames", { enumerable: true, get: function () { return makeDeprecatedField_1.getDeprecatedFieldClassNames; } });
11
+ Object.defineProperty(exports, "makeDeprecatedField", { enumerable: true, get: function () { return makeDeprecatedField_1.makeDeprecatedField; } });
12
+ });
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/react-components/react-field/src/index.ts"],"names":[],"mappings":";;;;IAAS,8FAAA,KAAK,OAAA;IAAE,wGAAA,eAAe,OAAA;IAAE,6GAAA,oBAAoB,OAAA;IAAE,gHAAA,uBAAuB,OAAA;IAAE,0GAAA,iBAAiB,OAAA;IAIxF,mIAAA,4BAA4B,OAAA;IAAE,0HAAA,mBAAmB,OAAA","sourcesContent":["export { Field, fieldClassNames, renderField_unstable, useFieldStyles_unstable, useField_unstable } from './Field';\nexport type { FieldProps, FieldSlots, FieldState } from './Field';\n\n// eslint-disable-next-line deprecation/deprecation\nexport { getDeprecatedFieldClassNames, makeDeprecatedField } from './util/makeDeprecatedField';\n// eslint-disable-next-line deprecation/deprecation\nexport type { DeprecatedFieldProps } from './util/makeDeprecatedField';\n"]}
@@ -0,0 +1,38 @@
1
+ define(["require", "exports", "tslib", "react", "../Field"], function (require, exports, tslib_1, React, Field_1) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.getDeprecatedFieldClassNames = exports.makeDeprecatedField = void 0;
5
+ /**
6
+ * Partition the props used by the Field itself, from the props that are passed to the underlying field component.
7
+ */
8
+ function getPartitionedFieldProps(props) {
9
+ var className = props.className, control = props.control, hint = props.hint, label = props.label, orientation = props.orientation, required = props.required, root = props.root, size = props.size, style = props.style, validationMessage = props.validationMessage, validationMessageIcon = props.validationMessageIcon, _a = props.validationState, validationState = _a === void 0 ? 'none' : _a, restOfProps = tslib_1.__rest(props, ["className", "control", "hint", "label", "orientation", "required", "root", "size", "style", "validationMessage", "validationMessageIcon", "validationState"]);
10
+ return [
11
+ tslib_1.__assign({ className: className, hint: hint, label: label, orientation: orientation, required: required, size: size, style: style, validationMessage: validationMessage, validationMessageIcon: validationMessageIcon, validationState: validationState }, root),
12
+ tslib_1.__assign(tslib_1.__assign({ required: required, size: size }, restOfProps), control),
13
+ ];
14
+ }
15
+ /**
16
+ * @deprecated Only for use to make deprecated [Control]Field shim components.
17
+ * @internal
18
+ */
19
+ function makeDeprecatedField(Control, options) {
20
+ if (options === void 0) { options = {}; }
21
+ var _a = options.mapProps, mapProps = _a === void 0 ? function (props) { return props; } : _a, _b = options.displayName, displayName = _b === void 0 ? Control.displayName + "Field" : _b;
22
+ var DeprecatedField = React.forwardRef(function (props, ref) {
23
+ var _a = getPartitionedFieldProps(mapProps(props)), fieldProps = _a[0], controlProps = _a[1];
24
+ return (React.createElement(Field_1.Field, tslib_1.__assign({}, fieldProps),
25
+ React.createElement(Control, tslib_1.__assign({}, controlProps, { ref: ref }))));
26
+ });
27
+ DeprecatedField.displayName = displayName;
28
+ return DeprecatedField;
29
+ }
30
+ exports.makeDeprecatedField = makeDeprecatedField;
31
+ /**
32
+ * @deprecated Only for use to make deprecated [Control]Field shim components.
33
+ * @internal
34
+ */
35
+ var getDeprecatedFieldClassNames = function (controlRootClassName) { return (tslib_1.__assign(tslib_1.__assign({}, Field_1.fieldClassNames), { control: controlRootClassName })); };
36
+ exports.getDeprecatedFieldClassNames = getDeprecatedFieldClassNames;
37
+ });
38
+ //# sourceMappingURL=makeDeprecatedField.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"makeDeprecatedField.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-field/src/util/makeDeprecatedField.tsx"],"names":[],"mappings":";;;;IAyBA;;OAEG;IACH,SAAS,wBAAwB,CAC/B,K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UAAU;gBAEnB,oBAAC,OAAO,uBAAM,YAAoB,IAAE,GAAG,EAAE,GAAU,IAAI,CACjD,CACT,CAAC;QACJ,CAAC,CAA4D,CAAC;QAE9D,eAAe,CAAC,WAAW,GAAG,WAAW,CAAC;QAE1C,OAAO,eAAe,CAAC;IACzB,CAAC;IAtBD,kDAsBC;IAED;;;OAGG;IACI,IAAM,4BAA4B,GAAG,UAAC,oBAA4B,IAAK,OAAA,uCACzE,uBAAe,KAClB,OAAO,EAAE,oBAAoB,IAC7B,EAH4E,CAG5E,CAAC;IAHU,QAAA,4BAA4B,gCAGtC","sourcesContent":["/* eslint-disable deprecation/deprecation */\nimport * as React from 'react';\nimport { ForwardRefComponent } from '@fluentui/react-utilities';\nimport type { FieldProps } from '../Field';\nimport { Field, fieldClassNames } from '../Field';\n\n/**\n * @deprecated Only for use to make deprecated [Control]Field shim components.\n * @internal\n */\nexport type DeprecatedFieldProps<ControlProps> = ControlProps & {\n root?: FieldProps;\n control?: ControlProps;\n} & Pick<\n FieldProps,\n | 'className'\n | 'hint'\n | 'label'\n | 'orientation'\n | 'style'\n | 'validationMessage'\n | 'validationMessageIcon'\n | 'validationState'\n >;\n\n/**\n * Partition the props used by the Field itself, from the props that are passed to the underlying field component.\n */\nfunction getPartitionedFieldProps<ControlProps>(\n props: DeprecatedFieldProps<ControlProps> & Pick<FieldProps, 'required' | 'size'>,\n) {\n const {\n className,\n control,\n hint,\n label,\n orientation,\n required,\n root,\n size,\n style,\n validationMessage,\n validationMessageIcon,\n validationState = 'none',\n ...restOfProps\n } = props;\n\n return [\n {\n className,\n hint,\n label,\n orientation,\n required,\n size,\n style,\n validationMessage,\n validationMessageIcon,\n validationState,\n ...root,\n },\n {\n required,\n size,\n ...restOfProps,\n ...control,\n },\n ];\n}\n\n/**\n * @deprecated Only for use to make deprecated [Control]Field shim components.\n * @internal\n */\nexport function makeDeprecatedField<ControlProps>(\n Control: React.ComponentType<ControlProps>,\n options: {\n mapProps?: (props: DeprecatedFieldProps<ControlProps>) => DeprecatedFieldProps<ControlProps>;\n displayName?: string;\n } = {},\n) {\n const { mapProps = props => props, displayName = `${Control.displayName}Field` } = options;\n\n const DeprecatedField = React.forwardRef((props, ref) => {\n const [fieldProps, controlProps] = getPartitionedFieldProps(mapProps(props));\n return (\n <Field {...fieldProps}>\n {/* eslint-disable-next-line @typescript-eslint/no-explicit-any */}\n <Control {...(controlProps as any)} ref={ref as any} />\n </Field>\n );\n }) as ForwardRefComponent<DeprecatedFieldProps<ControlProps>>;\n\n DeprecatedField.displayName = displayName;\n\n return DeprecatedField;\n}\n\n/**\n * @deprecated Only for use to make deprecated [Control]Field shim components.\n * @internal\n */\nexport const getDeprecatedFieldClassNames = (controlRootClassName: string) => ({\n ...fieldClassNames,\n control: controlRootClassName,\n});\n"]}
@@ -3,8 +3,6 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
-
7
6
  const tslib_1 = /*#__PURE__*/require("tslib");
8
-
9
7
  tslib_1.__exportStar(require("./components/Field/index"), exports);
10
8
  //# sourceMappingURL=Field.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["Field.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,0BAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './components/Field/index';\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":";;;;;;AAAAA","names":["tslib_1"],"sourceRoot":"../src/","sources":["packages/react-components/react-field/src/Field.ts"],"sourcesContent":["export * from './components/Field/index';\n"]}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Field = void 0;
7
+ const React = /*#__PURE__*/require("react");
8
+ const renderField_1 = /*#__PURE__*/require("./renderField");
9
+ const useField_1 = /*#__PURE__*/require("./useField");
10
+ const useFieldStyles_1 = /*#__PURE__*/require("./useFieldStyles");
11
+ exports.Field = /*#__PURE__*/React.forwardRef((props, ref) => {
12
+ const state = useField_1.useField_unstable(props, ref);
13
+ useFieldStyles_1.useFieldStyles_unstable(state);
14
+ return renderField_1.renderField_unstable(state);
15
+ });
16
+ exports.Field.displayName = 'Field';
17
+ //# sourceMappingURL=Field.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"mappings":";;;;;;AAAA;AAGA;AACA;AACA;AAEaA,aAAK,gBAAoCC,KAAK,CAACC,UAAU,CAAC,CAACC,KAAK,EAAEC,GAAG,KAAI;EACpF,MAAMC,KAAK,GAAGC,4BAAiB,CAACH,KAAK,EAAEC,GAAG,CAAC;EAC3CG,wCAAuB,CAACF,KAAK,CAAC;EAC9B,OAAOG,kCAAoB,CAACH,KAAK,CAAC;AACpC,CAAC,CAAC;AAEFL,aAAK,CAACS,WAAW,GAAG,OAAO","names":["exports","React","forwardRef","props","ref","state","useField_1","useFieldStyles_1","renderField_1","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,"sources":[],"names":[],"mappings":"","sourceRoot":"../src/"}
1
+ {"version":3,"mappings":"","names":[],"sourceRoot":"../src/","sources":[],"sourcesContent":[]}
@@ -3,14 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
-
7
6
  const tslib_1 = /*#__PURE__*/require("tslib");
8
-
9
7
  tslib_1.__exportStar(require("./Field.types"), exports);
10
-
8
+ tslib_1.__exportStar(require("./Field"), exports);
11
9
  tslib_1.__exportStar(require("./renderField"), exports);
12
-
13
10
  tslib_1.__exportStar(require("./useField"), exports);
14
-
15
11
  tslib_1.__exportStar(require("./useFieldStyles"), exports);
16
12
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["components/Field/index.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,eAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,eAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,YAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,kBAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './Field.types';\nexport * from './renderField';\nexport * from './useField';\nexport * from './useFieldStyles';\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":";;;;;;AAAAA;AACAA;AACAA;AACAA;AACAA","names":["tslib_1"],"sourceRoot":"../src/","sources":["packages/react-components/react-field/src/components/Field/index.ts"],"sourcesContent":["export * from './Field.types';\nexport * from './Field';\nexport * from './renderField';\nexport * from './useField';\nexport * from './useFieldStyles';\n"]}
@@ -4,28 +4,27 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.renderField_unstable = void 0;
7
-
8
7
  const React = /*#__PURE__*/require("react");
9
-
10
8
  const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
11
9
  /**
12
10
  * Render the final JSX of Field
13
11
  */
14
-
15
-
16
12
  const renderField_unstable = state => {
17
13
  const {
18
14
  slots,
19
15
  slotProps
20
16
  } = react_utilities_1.getSlots(state);
21
- return React.createElement(slots.root, { ...slotProps.root
22
- }, slots.label && React.createElement(slots.label, { ...slotProps.label
23
- }), slots.control && React.createElement(slots.control, { ...slotProps.control
24
- }), slots.validationMessage && React.createElement(slots.validationMessage, { ...slotProps.validationMessage
25
- }, slots.validationMessageIcon && React.createElement(slots.validationMessageIcon, { ...slotProps.validationMessageIcon
26
- }), slotProps.validationMessage.children), slots.hint && React.createElement(slots.hint, { ...slotProps.hint
17
+ return React.createElement(slots.root, {
18
+ ...slotProps.root
19
+ }, slots.label && React.createElement(slots.label, {
20
+ ...slotProps.label
21
+ }), slotProps.root.children, slots.validationMessage && React.createElement(slots.validationMessage, {
22
+ ...slotProps.validationMessage
23
+ }, slots.validationMessageIcon && React.createElement(slots.validationMessageIcon, {
24
+ ...slotProps.validationMessageIcon
25
+ }), slotProps.validationMessage.children), slots.hint && React.createElement(slots.hint, {
26
+ ...slotProps.hint
27
27
  }));
28
28
  };
29
-
30
29
  exports.renderField_unstable = renderField_unstable;
31
30
  //# sourceMappingURL=renderField.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["components/Field/renderField.tsx"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;AAGA;;AAEG;;;AACI,MAAM,oBAAoB,GAA8B,KAA3B,IAAmD;EACrF,MAAM;IAAE,KAAF;IAAS;EAAT,IAAuB,iBAAA,CAAA,QAAA,CAAqC,KAArC,CAA7B;EAEA,OACE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,IAAP,EAAW,EAAA,GAAK,SAAS,CAAC;EAAf,CAAX,EACG,KAAK,CAAC,KAAN,IAAe,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,KAAP,EAAY,EAAA,GAAK,SAAS,CAAC;EAAf,CAAZ,CADlB,EAGG,KAAK,CAAC,OAAN,IAAiB,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,OAAP,EAAc,EAAA,GAAM,SAAS,CAAC;EAAhB,CAAd,CAHpB,EAIG,KAAK,CAAC,iBAAN,IACC,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,iBAAP,EAAwB,EAAA,GAAK,SAAS,CAAC;EAAf,CAAxB,EACG,KAAK,CAAC,qBAAN,IAA+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,IAAc,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,IAAP,EAAW,EAAA,GAAK,SAAS,CAAC;EAAf,CAAX,CAVjB,CADF;AAcD,CAjBM;;AAAM,OAAA,CAAA,oBAAA,GAAoB,oBAApB","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;AACA;AAGA;;;AAGO,MAAMA,oBAAoB,GAAIC,KAAiB,IAAI;EACxD,MAAM;IAAEC,KAAK;IAAEC;EAAS,CAAE,GAAGC,0BAAQ,CAAaH,KAAK,CAAC;EAExD,OACEI,oBAACH,KAAK,CAACI,IAAI;IAAA,GAAKH,SAAS,CAACG;EAAI,GAC3BJ,KAAK,CAACK,KAAK,IAAIF,oBAACH,KAAK,CAACK,KAAK;IAAA,GAAKJ,SAAS,CAACI;EAAK,EAAI,EACnDJ,SAAS,CAACG,IAAI,CAACE,QAAQ,EACvBN,KAAK,CAACO,iBAAiB,IACtBJ,oBAACH,KAAK,CAACO,iBAAiB;IAAA,GAAKN,SAAS,CAACM;EAAiB,GACrDP,KAAK,CAACQ,qBAAqB,IAAIL,oBAACH,KAAK,CAACQ,qBAAqB;IAAA,GAAKP,SAAS,CAACO;EAAqB,EAAI,EACnGP,SAAS,CAACM,iBAAiB,CAACD,QAAQ,CAExC,EACAN,KAAK,CAACS,IAAI,IAAIN,oBAACH,KAAK,CAACS,IAAI;IAAA,GAAKR,SAAS,CAACQ;EAAI,EAAI,CACtC;AAEjB,CAAC;AAhBYC,4BAAoB","names":["renderField_unstable","state","slots","slotProps","react_utilities_1","React","root","label","children","validationMessage","validationMessageIcon","hint","exports"],"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"]}
@@ -3,62 +3,17 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.useField_unstable = exports.getPartitionedFieldProps = void 0;
7
-
6
+ exports.useField_unstable = void 0;
8
7
  const React = /*#__PURE__*/require("react");
9
-
10
8
  const react_icons_1 = /*#__PURE__*/require("@fluentui/react-icons");
11
-
12
9
  const react_label_1 = /*#__PURE__*/require("@fluentui/react-label");
13
-
14
10
  const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
15
-
16
11
  const validationMessageIcons = {
17
12
  error: /*#__PURE__*/React.createElement(react_icons_1.ErrorCircle12Filled, null),
18
13
  warning: /*#__PURE__*/React.createElement(react_icons_1.Warning12Filled, null),
19
- success: /*#__PURE__*/React.createElement(react_icons_1.CheckmarkCircle12Filled, null)
14
+ success: /*#__PURE__*/React.createElement(react_icons_1.CheckmarkCircle12Filled, null),
15
+ none: undefined
20
16
  };
21
- /**
22
- * Merge two possibly-undefined IDs for aria-describedby. If both IDs are defined, combines
23
- * them into a string separated by a space. Otherwise, returns just the defined ID (if any).
24
- */
25
-
26
- const mergeAriaDescribedBy = (a, b) => a && b ? `${a} ${b}` : a || b;
27
- /**
28
- * Partition the props used by the Field itself, from the props that are passed to the underlying field component.
29
- */
30
-
31
-
32
- const getPartitionedFieldProps = props => {
33
- const {
34
- className,
35
- control,
36
- hint,
37
- label,
38
- orientation,
39
- root,
40
- style,
41
- validationMessage,
42
- validationMessageIcon,
43
- validationState,
44
- ...restOfProps
45
- } = props;
46
- const fieldProps = {
47
- className,
48
- control,
49
- hint,
50
- label,
51
- orientation,
52
- root,
53
- style,
54
- validationMessage,
55
- validationMessageIcon,
56
- validationState
57
- };
58
- return [fieldProps, restOfProps];
59
- };
60
-
61
- exports.getPartitionedFieldProps = getPartitionedFieldProps;
62
17
  /**
63
18
  * Create the state required to render Field.
64
19
  *
@@ -66,89 +21,93 @@ exports.getPartitionedFieldProps = getPartitionedFieldProps;
66
21
  * before being passed to renderField_unstable.
67
22
  *
68
23
  * @param props - Props passed to this field
69
- * @param ref - Ref to the control slot (primary slot)
70
- * @param params - Configuration parameters for this Field
24
+ * @param ref - Ref to the root
71
25
  */
72
-
73
- const useField_unstable = (props, ref, params) => {
74
- const [fieldProps, controlProps] = exports.getPartitionedFieldProps(props);
75
- const baseId = react_utilities_1.useId('field-');
26
+ const useField_unstable = (props, ref) => {
27
+ var _a, _b, _c, _d;
76
28
  const {
29
+ children,
77
30
  orientation = 'vertical',
78
- validationState
79
- } = fieldProps;
80
- const root = react_utilities_1.resolveShorthand(fieldProps.root, {
81
- required: true,
82
- defaultProps: react_utilities_1.getNativeElementProps('div', fieldProps)
83
- });
84
- const label = react_utilities_1.resolveShorthand(fieldProps.label, {
31
+ required,
32
+ validationState = props.validationMessage ? 'error' : 'none',
33
+ size
34
+ } = props;
35
+ const baseId = react_utilities_1.useId('field-');
36
+ const root = react_utilities_1.getNativeElementProps('div', {
37
+ ...props,
38
+ ref
39
+ }, /*excludedPropNames:*/['children']);
40
+ const label = react_utilities_1.resolveShorthand(props.label, {
85
41
  defaultProps: {
86
42
  id: baseId + '__label',
87
- required: controlProps.required,
88
- size: typeof controlProps.size === 'string' ? controlProps.size : undefined // htmlFor is set below
89
-
43
+ required,
44
+ size
45
+ // htmlFor is handled below
90
46
  }
91
47
  });
92
- const validationMessage = react_utilities_1.resolveShorthand(fieldProps.validationMessage, {
48
+
49
+ const validationMessage = react_utilities_1.resolveShorthand(props.validationMessage, {
93
50
  defaultProps: {
94
- id: baseId + '__validationMessage'
51
+ id: baseId + '__validationMessage',
52
+ role: validationState === 'error' ? 'alert' : undefined
95
53
  }
96
54
  });
97
- const hint = react_utilities_1.resolveShorthand(fieldProps.hint, {
55
+ const hint = react_utilities_1.resolveShorthand(props.hint, {
98
56
  defaultProps: {
99
57
  id: baseId + '__hint'
100
58
  }
101
59
  });
102
- const validationMessageIcon = react_utilities_1.resolveShorthand(fieldProps.validationMessageIcon, {
103
- required: !!validationState,
60
+ const defaultIcon = validationMessageIcons[validationState];
61
+ const validationMessageIcon = react_utilities_1.resolveShorthand(props.validationMessageIcon, {
62
+ required: !!defaultIcon,
104
63
  defaultProps: {
105
- children: validationState ? validationMessageIcons[validationState] : undefined
64
+ children: defaultIcon
106
65
  }
107
66
  });
108
- const {
109
- labelConnection = 'htmlFor'
110
- } = params;
111
- const hasError = validationState === 'error';
112
- const control = react_utilities_1.resolveShorthand(fieldProps.control, {
113
- required: true,
114
- defaultProps: {
115
- ref,
116
- // Add a default ID only if required for label's htmlFor prop
117
- id: label && labelConnection === 'htmlFor' ? baseId + '__control' : undefined,
118
- // Add aria-labelledby only if not using the label's htmlFor
119
- 'aria-labelledby': labelConnection !== 'htmlFor' ? label === null || label === void 0 ? void 0 : label.id : undefined,
120
- '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),
121
- 'aria-errormessage': hasError ? validationMessage === null || validationMessage === void 0 ? void 0 : validationMessage.id : undefined,
122
- 'aria-invalid': hasError ? true : undefined,
123
- ...controlProps
67
+ const controlProps = React.isValidElement(children) ? {
68
+ ...children.props
69
+ } : {};
70
+ if (label) {
71
+ (_a = controlProps['aria-labelledby']) !== null && _a !== void 0 ? _a : controlProps['aria-labelledby'] = label.id;
72
+ if (!label.htmlFor) {
73
+ // Assign the child a generated ID if doesn't already have an ID
74
+ (_b = controlProps.id) !== null && _b !== void 0 ? _b : controlProps.id = baseId + '__control';
75
+ label.htmlFor = controlProps.id;
124
76
  }
125
- });
126
-
127
- if (labelConnection === 'htmlFor' && label && !label.htmlFor) {
128
- label.htmlFor = control.id;
129
77
  }
130
-
131
- const state = {
78
+ if (validationMessage || hint) {
79
+ // The control is described by the validation message, or hint, or both
80
+ // We also preserve and append any aria-describedby supplied by the user
81
+ // For reference: https://github.com/microsoft/fluentui/pull/25580#discussion_r1017259933
82
+ 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(' ');
83
+ }
84
+ if (validationState === 'error') {
85
+ (_c = controlProps['aria-invalid']) !== null && _c !== void 0 ? _c : controlProps['aria-invalid'] = true;
86
+ }
87
+ if (required) {
88
+ (_d = controlProps['aria-required']) !== null && _d !== void 0 ? _d : controlProps['aria-required'] = true;
89
+ }
90
+ if (React.isValidElement(children)) {
91
+ root.children = React.cloneElement(children, controlProps);
92
+ } else if (typeof children === 'function') {
93
+ root.children = children(controlProps);
94
+ }
95
+ return {
132
96
  orientation,
133
97
  validationState,
134
- classNames: params.classNames,
135
98
  components: {
136
99
  root: 'div',
137
- control: params.component,
138
100
  label: react_label_1.Label,
139
- validationMessage: 'span',
101
+ validationMessage: 'div',
140
102
  validationMessageIcon: 'span',
141
- hint: 'span'
103
+ hint: 'div'
142
104
  },
143
105
  root,
144
- control,
145
106
  label,
146
107
  validationMessageIcon,
147
108
  validationMessage,
148
109
  hint
149
110
  };
150
- return state;
151
111
  };
152
-
153
112
  exports.useField_unstable = useField_unstable;
154
113
  //# sourceMappingURL=useField.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["components/Field/useField.tsx"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,aAAA,gBAAA,OAAA,CAAA,uBAAA,CAAA;;AACA,MAAA,aAAA,gBAAA,OAAA,CAAA,uBAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;;AASA,MAAM,sBAAsB,GAAG;EAC7B,KAAK,eAAE,KAAA,CAAA,aAAA,CAAC,aAAA,CAAA,mBAAD,EAAoB,IAApB,CADsB;EAE7B,OAAO,eAAE,KAAA,CAAA,aAAA,CAAC,aAAA,CAAA,eAAD,EAAgB,IAAhB,CAFoB;EAG7B,OAAO,eAAE,KAAA,CAAA,aAAA,CAAC,aAAA,CAAA,uBAAD,EAAwB,IAAxB;AAHoB,CAA/B;AAMA;;;AAGG;;AACH,MAAM,oBAAoB,GAAG,CAAC,CAAD,EAAa,CAAb,KAA6B,CAAC,IAAI,CAAL,GAAS,GAAG,CAAC,IAAI,CAAC,EAAlB,GAAuB,CAAC,IAAI,CAAtF;AAEA;;AAEG;;;AACI,M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AiB,KAAA,KAAA,CAAjB,GAAiB,KAAA,CAAjB,GAAA,iBAAiB,CAAE,EAApB,EAAwB,IAAI,KAAA,IAAJ,IAAA,IAAI,KAAA,KAAA,CAAJ,GAAI,KAAA,CAAJ,GAAA,IAAI,CAAE,EAA9B,CANlD;MAOZ,qBAAqB,QAAQ,GAAG,iBAAiB,KAAA,IAAjB,IAAA,iBAAiB,KAAA,KAAA,CAAjB,GAAiB,KAAA,CAAjB,GAAA,iBAAiB,CAAE,EAAtB,GAA2B,SAP5C;MAQZ,gBAAgB,QAAQ,GAAG,IAAH,GAAU,SARtB;MASZ,GAAG;IATS;EAFqC,CAArC,CAAhB;;EAeA,IAAI,eAAe,KAAK,SAApB,IAAiC,KAAjC,IAA0C,CAAC,KAAK,CAAC,OAArD,EAA8D;IAC5D,KAAK,CAAC,OAAN,GAAgB,OAAO,CAAC,EAAxB;EACD;;EAED,MAAM,KAAK,GAA+B;IACxC,WADwC;IAExC,eAFwC;IAGxC,UAAU,EAAE,MAAM,CAAC,UAHqB;IAIxC,UAAU,EAAE;MACV,IAAI,EAAE,KADI;MAEV,OAAO,EAAE,MAAM,CAAC,SAFN;MAGV,KAAK,EAAE,aAAA,CAAA,KAHG;MAIV,iBAAiB,EAAE,MAJT;MAKV,qBAAqB,EAAE,MALb;MAMV,IAAI,EAAE;IANI,CAJ4B;IAYxC,IAZwC;IAaxC,OAbwC;IAcxC,KAdwC;IAexC,qBAfwC;IAgBxC,iBAhBwC;IAiBxC;EAjBwC,CAA1C;EAoBA,OAAO,KAAP;AACD,CAvFM;;AAAM,OAAA,CAAA,iBAAA,GAAiB,iBAAjB","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 {\n FieldComponent,\n FieldConfig,\n FieldProps,\n FieldPropsWithOptionalComponentProps,\n FieldState,\n} from './Field.types';\n\nconst validationMessageIcons = {\n error: <ErrorCircle12Filled />,\n warning: <Warning12Filled />,\n success: <CheckmarkCircle12Filled />,\n} as const;\n\n/**\n * Merge two possibly-undefined IDs for aria-describedby. If both IDs are defined, combines\n * them into a string separated by a space. Otherwise, returns just the defined ID (if any).\n */\nconst mergeAriaDescribedBy = (a?: string, b?: string) => (a && b ? `${a} ${b}` : a || b);\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 extends FieldProps<FieldComponent>>(props: Props) => {\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 FieldComponent>(\n props: FieldPropsWithOptionalComponentProps<T>,\n ref: React.Ref<HTMLElement>,\n params: FieldConfig<T>,\n): FieldState<T> => {\n const [fieldProps, controlProps] = getPartitionedFieldProps(props);\n\n const baseId = useId('field-');\n\n const { orientation = 'vertical', validationState } = fieldProps;\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 set below\n },\n });\n\n const validationMessage = resolveShorthand(fieldProps.validationMessage, {\n defaultProps: {\n id: baseId + '__validationMessage',\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 const { labelConnection = 'htmlFor' } = params;\n const hasError = validationState === 'error';\n\n const control = resolveShorthand(fieldProps.control, {\n required: true,\n defaultProps: {\n ref,\n // Add a default ID only if required for label's htmlFor prop\n id: label && labelConnection === 'htmlFor' ? baseId + '__control' : undefined,\n // Add aria-labelledby only if not using the label's htmlFor\n 'aria-labelledby': labelConnection !== 'htmlFor' ? label?.id : undefined,\n 'aria-describedby': hasError ? hint?.id : mergeAriaDescribedBy(validationMessage?.id, hint?.id),\n 'aria-errormessage': hasError ? validationMessage?.id : undefined,\n 'aria-invalid': hasError ? true : undefined,\n ...controlProps,\n },\n });\n\n if (labelConnection === 'htmlFor' && label && !label.htmlFor) {\n label.htmlFor = control.id;\n }\n\n const state: FieldState<FieldComponent> = {\n orientation,\n validationState,\n classNames: params.classNames,\n components: {\n root: 'div',\n control: params.component,\n label: Label,\n validationMessage: 'span',\n validationMessageIcon: 'span',\n hint: 'span',\n },\n root,\n control,\n label,\n validationMessageIcon,\n validationMessage,\n hint,\n };\n\n return state as FieldState<T>;\n};\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":";;;;;;AAAA;AAEA;AACA;AACA;AAGA,MAAMA,sBAAsB,GAAG;EAC7BC,KAAK,eAAEC,oBAACC,iCAAmB,OAAG;EAC9BC,OAAO,eAAEF,oBAACC,6BAAe,OAAG;EAC5BE,OAAO,eAAEH,oBAACC,qCAAuB,OAAG;EACpCG,IAAI,EAAEC;CACE;AAEV;;;;;;;;;AASO,MAAMC,iBAAiB,GAAG,CAACC,KAAiB,EAAEC,GAA8B,KAAgB;;EACjG,MAAM;IACJC,QAAQ;IACRC,WAAW,GAAG,UAAU;IACxBC,QAAQ;IACRC,eAAe,GAAGL,KAAK,CAACM,iBAAiB,GAAG,OAAO,GAAG,MAAM;IA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,EAAE,mCAAfK,YAAY,CAACL,EAAE,GAAKL,MAAM,GAAG,WAAW;MACxCG,KAAK,CAACS,OAAO,GAAGF,YAAY,CAACL,EAAE;;;EAInC,IAAIP,iBAAiB,IAAIS,IAAI,EAAE;IAC7B;IACA;IACA;IACAG,YAAY,CAAC,kBAAkB,CAAC,GAAG,CAACZ,iBAAiB,aAAjBA,iBAAiB,uBAAjBA,iBAAiB,CAAEO,EAAE,EAAEE,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAEF,EAAE,EAAEK,YAAY,CAAC,kBAAkB,CAAC,CAAC,CACnGG,MAAM,CAACC,OAAO,CAAC,CACfC,IAAI,CAAC,GAAG,CAAC;;EAGd,IAAIlB,eAAe,KAAK,OAAO,EAAE;IAC/B,kBAAY,CAAC,cAAc,oCAA3Ba,YAAY,CAAC,cAAc,IAAM,IAAI;;EAGvC,IAAId,QAAQ,EAAE;IACZ,kBAAY,CAAC,eAAe,oCAA5Bc,YAAY,CAAC,eAAe,IAAM,IAAI;;EAGxC,IAAIzB,KAAK,CAAC0B,cAAc,CAACjB,QAAQ,CAAC,EAAE;IAClCQ,IAAI,CAACR,QAAQ,GAAGT,KAAK,CAAC+B,YAAY,CAACtB,QAAQ,EAAEgB,YAAY,CAAC;GAC3D,MAAM,IAAI,OAAOhB,QAAQ,KAAK,UAAU,EAAE;IACzCQ,IAAI,CAACR,QAAQ,GAAGA,QAAQ,CAACgB,YAAY,CAAC;;EAGxC,OAAO;IACLf,WAAW;IACXE,eAAe;IACfoB,UAAU,EAAE;MACVf,IAAI,EAAE,KAAK;MACXC,KAAK,EAAEe,mBAAK;MACZpB,iBAAiB,EAAE,KAAK;MACxBW,qBAAqB,EAAE,MAAM;MAC7BF,IAAI,EAAE;KACP;IACDL,IAAI;IACJC,KAAK;IACLM,qBAAqB;IACrBX,iBAAiB;IACjBS;GACD;AACH,CAAC;AA9FYY,yBAAiB","names":["validationMessageIcons","error","React","react_icons_1","warning","success","none","undefined","useField_unstable","props","ref","children","orientation","required","validationState","validationMessage","size","baseId","react_utilities_1","root","label","defaultProps","id","role","hint","defaultIcon","validationMessageIcon","controlProps","isValidElement","htmlFor","filter","Boolean","join","cloneElement","components","react_label_1","exports"],"sourceRoot":"../src/","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 none: undefined,\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 {\n children,\n orientation = 'vertical',\n required,\n validationState = props.validationMessage ? 'error' : 'none',\n size,\n } = 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 defaultIcon = validationMessageIcons[validationState];\n const validationMessageIcon = resolveShorthand(props.validationMessageIcon, {\n required: !!defaultIcon,\n defaultProps: {\n children: defaultIcon,\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"]}