@fluentui/react-field 0.0.0-nightly-20230124-0417.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.
- package/CHANGELOG.json +13 -13
- package/CHANGELOG.md +9 -9
- package/dist/index.d.ts +60 -86
- package/lib/components/Field/Field.js +11 -0
- package/lib/components/Field/Field.js.map +1 -0
- package/lib/components/Field/Field.types.js.map +1 -1
- package/lib/components/Field/index.js +1 -0
- package/lib/components/Field/index.js.map +1 -1
- package/lib/components/Field/renderField.js +1 -3
- package/lib/components/Field/renderField.js.map +1 -1
- package/lib/components/Field/useField.js +37 -71
- package/lib/components/Field/useField.js.map +1 -1
- package/lib/components/Field/useFieldStyles.js +15 -18
- package/lib/components/Field/useFieldStyles.js.map +1 -1
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/util/makeDeprecatedField.js +71 -0
- package/lib/util/makeDeprecatedField.js.map +1 -0
- package/lib-commonjs/components/Field/Field.js +17 -0
- package/lib-commonjs/components/Field/Field.js.map +1 -0
- package/lib-commonjs/components/Field/index.js +1 -0
- package/lib-commonjs/components/Field/index.js.map +1 -1
- package/lib-commonjs/components/Field/renderField.js +1 -3
- package/lib-commonjs/components/Field/renderField.js.map +1 -1
- package/lib-commonjs/components/Field/useField.js +38 -73
- package/lib-commonjs/components/Field/useField.js.map +1 -1
- package/lib-commonjs/components/Field/useFieldStyles.js +16 -20
- package/lib-commonjs/components/Field/useFieldStyles.js.map +1 -1
- package/lib-commonjs/index.js +23 -3
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/util/makeDeprecatedField.js +79 -0
- package/lib-commonjs/util/makeDeprecatedField.js.map +1 -0
- package/package.json +7 -6
- package/lib/components/Field/SlotComponent.types.js +0 -2
- package/lib/components/Field/SlotComponent.types.js.map +0 -1
- package/lib-commonjs/components/Field/SlotComponent.types.js +0 -6
- package/lib-commonjs/components/Field/SlotComponent.types.js.map +0 -1
@@ -1,13 +1,12 @@
|
|
1
1
|
import { tokens, typographyStyles } from '@fluentui/react-theme';
|
2
2
|
import { __resetStyles, __styles, mergeClasses } from '@griffel/react';
|
3
|
-
export const
|
4
|
-
root: `fui
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
});
|
3
|
+
export const fieldClassNames = {
|
4
|
+
root: `fui-Field`,
|
5
|
+
label: `fui-Field__label`,
|
6
|
+
validationMessage: `fui-Field__validationMessage`,
|
7
|
+
validationMessageIcon: `fui-Field__validationMessageIcon`,
|
8
|
+
hint: `fui-Field__hint`
|
9
|
+
};
|
11
10
|
// Size of the icon in the validation message
|
12
11
|
const iconSize = '12px';
|
13
12
|
/**
|
@@ -80,30 +79,28 @@ const useValidationMessageIconStyles = /*#__PURE__*/__styles({
|
|
80
79
|
* Apply styling to the Field slots based on the state
|
81
80
|
*/
|
82
81
|
export const useFieldStyles_unstable = state => {
|
83
|
-
const
|
84
|
-
|
82
|
+
const {
|
83
|
+
validationState
|
84
|
+
} = state;
|
85
85
|
const horizontal = state.orientation === 'horizontal';
|
86
86
|
const rootStyles = useRootStyles();
|
87
|
-
state.root.className = mergeClasses(
|
88
|
-
if (state.control) {
|
89
|
-
state.control.className = mergeClasses(classNames.control, state.control.className);
|
90
|
-
}
|
87
|
+
state.root.className = mergeClasses(fieldClassNames.root, rootStyles.base, horizontal && rootStyles.horizontal, horizontal && !state.label && rootStyles.horizontalNoLabel, state.root.className);
|
91
88
|
const labelStyles = useLabelStyles();
|
92
89
|
if (state.label) {
|
93
|
-
state.label.className = mergeClasses(
|
90
|
+
state.label.className = mergeClasses(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);
|
94
91
|
}
|
95
92
|
const validationMessageIconBaseClassName = useValidationMessageIconBaseClassName();
|
96
93
|
const validationMessageIconStyles = useValidationMessageIconStyles();
|
97
94
|
if (state.validationMessageIcon) {
|
98
|
-
state.validationMessageIcon.className = mergeClasses(
|
95
|
+
state.validationMessageIcon.className = mergeClasses(fieldClassNames.validationMessageIcon, validationMessageIconBaseClassName, !!validationState && validationMessageIconStyles[validationState], state.validationMessageIcon.className);
|
99
96
|
}
|
100
97
|
const secondaryTextBaseClassName = useSecondaryTextBaseClassName();
|
101
98
|
const secondaryTextStyles = useSecondaryTextStyles();
|
102
99
|
if (state.validationMessage) {
|
103
|
-
state.validationMessage.className = mergeClasses(
|
100
|
+
state.validationMessage.className = mergeClasses(fieldClassNames.validationMessage, secondaryTextBaseClassName, validationState === 'error' && secondaryTextStyles.error, !!state.validationMessageIcon && secondaryTextStyles.withIcon, state.validationMessage.className);
|
104
101
|
}
|
105
102
|
if (state.hint) {
|
106
|
-
state.hint.className = mergeClasses(
|
103
|
+
state.hint.className = mergeClasses(fieldClassNames.hint, secondaryTextBaseClassName, state.hint.className);
|
107
104
|
}
|
108
105
|
};
|
109
106
|
//# sourceMappingURL=useFieldStyles.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"mappings":"AAAA,SAASA,MAAM,EAAEC,gBAAgB,QAAQ,uBAAuB;AAEhE,kCAAsCC,YAAY,QAAQ,gBAAgB;AAG1E,OAAO,MAAMC,
|
1
|
+
{"version":3,"mappings":"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","names":["tokens","typographyStyles","mergeClasses","fieldClassNames","root","label","validationMessage","validationMessageIcon","hint","iconSize","useRootStyles","useLabelStyles","useSecondaryTextBaseClassName","useSecondaryTextStyles","useValidationMessageIconBaseClassName","useValidationMessageIconStyles","useFieldStyles_unstable","state","validationState","horizontal","orientation","rootStyles","className","base","horizontalNoLabel","labelStyles","vertical","size","large","verticalLarge","validationMessageIconBaseClassName","validationMessageIconStyles","secondaryTextBaseClassName","secondaryTextStyles","error","withIcon"],"sourceRoot":"","sources":["../../../../../../../../../packages/react-components/react-field/src/components/Field/useFieldStyles.ts"],"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 && 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"]}
|
package/lib/index.js
CHANGED
@@ -1,2 +1,4 @@
|
|
1
|
-
export {
|
1
|
+
export { Field, fieldClassNames, renderField_unstable, useFieldStyles_unstable, useField_unstable } from './Field';
|
2
|
+
// eslint-disable-next-line deprecation/deprecation
|
3
|
+
export { getDeprecatedFieldClassNames, makeDeprecatedField } from './util/makeDeprecatedField';
|
2
4
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/react-components/react-field/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/react-components/react-field/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAGnH,mDAAmD;AACnD,OAAO,EAAE,4BAA4B,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC","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,71 @@
|
|
1
|
+
/* eslint-disable deprecation/deprecation */
|
2
|
+
import * as React from 'react';
|
3
|
+
import { Field, fieldClassNames } from '../Field';
|
4
|
+
/**
|
5
|
+
* Partition the props used by the Field itself, from the props that are passed to the underlying field component.
|
6
|
+
*/
|
7
|
+
function getPartitionedFieldProps(props) {
|
8
|
+
const {
|
9
|
+
className,
|
10
|
+
control,
|
11
|
+
hint,
|
12
|
+
label,
|
13
|
+
orientation,
|
14
|
+
required,
|
15
|
+
root,
|
16
|
+
size,
|
17
|
+
style,
|
18
|
+
validationMessage,
|
19
|
+
validationMessageIcon,
|
20
|
+
validationState,
|
21
|
+
...restOfProps
|
22
|
+
} = props;
|
23
|
+
return [{
|
24
|
+
className,
|
25
|
+
hint,
|
26
|
+
label,
|
27
|
+
orientation,
|
28
|
+
required,
|
29
|
+
size,
|
30
|
+
style,
|
31
|
+
validationMessage,
|
32
|
+
validationMessageIcon,
|
33
|
+
validationState,
|
34
|
+
...root
|
35
|
+
}, {
|
36
|
+
required,
|
37
|
+
size,
|
38
|
+
...restOfProps,
|
39
|
+
...control
|
40
|
+
}];
|
41
|
+
}
|
42
|
+
/**
|
43
|
+
* @deprecated Only for use to make deprecated [Control]Field shim components.
|
44
|
+
* @internal
|
45
|
+
*/
|
46
|
+
export function makeDeprecatedField(Control, options = {}) {
|
47
|
+
const {
|
48
|
+
mapProps = props => props,
|
49
|
+
displayName = `${Control.displayName}Field`
|
50
|
+
} = options;
|
51
|
+
const DeprecatedField = /*#__PURE__*/React.forwardRef((props, ref) => {
|
52
|
+
const [fieldProps, controlProps] = getPartitionedFieldProps(mapProps(props));
|
53
|
+
return /*#__PURE__*/React.createElement(Field, {
|
54
|
+
...fieldProps
|
55
|
+
}, /*#__PURE__*/React.createElement(Control, {
|
56
|
+
...controlProps,
|
57
|
+
ref: ref
|
58
|
+
}));
|
59
|
+
});
|
60
|
+
DeprecatedField.displayName = displayName;
|
61
|
+
return DeprecatedField;
|
62
|
+
}
|
63
|
+
/**
|
64
|
+
* @deprecated Only for use to make deprecated [Control]Field shim components.
|
65
|
+
* @internal
|
66
|
+
*/
|
67
|
+
export const getDeprecatedFieldClassNames = controlRootClassName => ({
|
68
|
+
...fieldClassNames,
|
69
|
+
control: controlRootClassName
|
70
|
+
});
|
71
|
+
//# sourceMappingURL=makeDeprecatedField.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"mappings":"AAAA;AACA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAG9B,SAASC,KAAK,EAAEC,eAAe,QAAQ,UAAU;AAqBjD;;;AAGA,SAASC,wBAAwB,CAC/BC,KAAiF;EAEjF,MAAM;IACJC,SAAS;IACTC,OAAO;IACPC,IAAI;IACJC,KAAK;IACLC,WAAW;IACXC,QAAQ;IACRC,IAAI;IACJC,IAAI;IACJC,KAAK;IACLC,iBAAiB;IACjBC,qBAAqB;IACrBC,eAAe;IACf,GAAGC;EAAW,CACf,GAAGb,KAAK;EAET,OAAO,CACL;IACEC,SAAS;IACTE,IAAI;IACJC,KAAK;IACLC,WAAW;IACXC,QAAQ;IACRE,IAAI;IACJC,KAAK;IACLC,iBAAiB;IACjBC,qBAAqB;IACrBC,eAAe;IACf,GAAGL;GACJ,EACD;IACED,QAAQ;IACRE,IAAI;IACJ,GAAGK,WAAW;IACd,GAAGX;GACJ,CACF;AACH;AAEA;;;;AAIA,OAAM,SAAUY,mBAAmB,CACjCC,OAA0C,EAC1CC,UAGI,EAAE;EAEN,MAAM;IAAEC,QAAQ,GAAGjB,KAAK,IAAIA,KAAK;IAAEkB,WAAW,GAAG,GAAGH,OAAO,CAACG,WAAW;EAAO,CAAE,GAAGF,OAAO;EAE1F,MAAMG,eAAe,gBAAGvB,KAAK,CAACwB,UAAU,CAAC,CAACpB,KAAK,EAAEqB,GAAG,KAAI;IACtD,MAAM,CAACC,UAAU,EAAEC,YAAY,CAAC,GAAGxB,wBAAwB,CAACkB,QAAQ,CAACjB,KAAK,CAAC,CAAC;IAC5E,oBACEJ,oBAACC,KAAK;MAAA,GAAKyB;IAAU,gBAEnB1B,oBAACmB,OAAO;MAAA,GAAMQ,YAAoB;MAAEF,GAAG,EAAEA;IAAU,EAAI,CACjD;EAEZ,CAAC,CAA4D;EAE7DF,eAAe,CAACD,WAAW,GAAGA,WAAW;EAEzC,OAAOC,eAAe;AACxB;AAEA;;;;AAIA,OAAO,MAAMK,4BAA4B,GAAIC,oBAA4B,KAAM;EAC7E,GAAG3B,eAAe;EAClBI,OAAO,EAAEuB;CACV,CAAC","names":["React","Field","fieldClassNames","getPartitionedFieldProps","props","className","control","hint","label","orientation","required","root","size","style","validationMessage","validationMessageIcon","validationState","restOfProps","makeDeprecatedField","Control","options","mapProps","displayName","DeprecatedField","forwardRef","ref","fieldProps","controlProps","getDeprecatedFieldClassNames","controlRootClassName"],"sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-field/src/util/makeDeprecatedField.tsx"],"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,\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"]}
|
@@ -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":"","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"]}
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
const tslib_1 = /*#__PURE__*/require("tslib");
|
7
7
|
tslib_1.__exportStar(require("./Field.types"), exports);
|
8
|
+
tslib_1.__exportStar(require("./Field"), exports);
|
8
9
|
tslib_1.__exportStar(require("./renderField"), exports);
|
9
10
|
tslib_1.__exportStar(require("./useField"), exports);
|
10
11
|
tslib_1.__exportStar(require("./useFieldStyles"), exports);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"mappings":";;;;;;AAAAA;AACAA;AACAA;AACAA","names":["tslib_1"],"sourceRoot":"","sources":["../../../../../../../../../packages/react-components/react-field/src/components/Field/index.ts"],"sourcesContent":["export * from './Field.types';\nexport * from './renderField';\nexport * from './useField';\nexport * from './useFieldStyles';\n"]}
|
1
|
+
{"version":3,"mappings":";;;;;;AAAAA;AACAA;AACAA;AACAA;AACAA","names":["tslib_1"],"sourceRoot":"","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"]}
|
@@ -18,9 +18,7 @@ const renderField_unstable = state => {
|
|
18
18
|
...slotProps.root
|
19
19
|
}, slots.label && React.createElement(slots.label, {
|
20
20
|
...slotProps.label
|
21
|
-
}), slots.
|
22
|
-
...slotProps.control
|
23
|
-
}), slots.validationMessage && React.createElement(slots.validationMessage, {
|
21
|
+
}), slotProps.root.children, slots.validationMessage && React.createElement(slots.validationMessage, {
|
24
22
|
...slotProps.validationMessage
|
25
23
|
}, slots.validationMessageIcon && React.createElement(slots.validationMessageIcon, {
|
26
24
|
...slotProps.validationMessageIcon
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"mappings":";;;;;;AAAA;AACA;AAGA;;;AAGO,MAAMA,oBAAoB,
|
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":"","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,7 +3,7 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.useField_unstable =
|
6
|
+
exports.useField_unstable = void 0;
|
7
7
|
const React = /*#__PURE__*/require("react");
|
8
8
|
const react_icons_1 = /*#__PURE__*/require("@fluentui/react-icons");
|
9
9
|
const react_label_1 = /*#__PURE__*/require("@fluentui/react-label");
|
@@ -13,38 +13,6 @@ const validationMessageIcons = {
|
|
13
13
|
warning: /*#__PURE__*/React.createElement(react_icons_1.Warning12Filled, null),
|
14
14
|
success: /*#__PURE__*/React.createElement(react_icons_1.CheckmarkCircle12Filled, null)
|
15
15
|
};
|
16
|
-
/**
|
17
|
-
* Partition the props used by the Field itself, from the props that are passed to the underlying field component.
|
18
|
-
*/
|
19
|
-
const getPartitionedFieldProps = props => {
|
20
|
-
const {
|
21
|
-
className,
|
22
|
-
control,
|
23
|
-
hint,
|
24
|
-
label,
|
25
|
-
orientation,
|
26
|
-
root,
|
27
|
-
style,
|
28
|
-
validationMessage,
|
29
|
-
validationMessageIcon,
|
30
|
-
validationState,
|
31
|
-
...restOfProps
|
32
|
-
} = props;
|
33
|
-
const fieldProps = {
|
34
|
-
className,
|
35
|
-
control,
|
36
|
-
hint,
|
37
|
-
label,
|
38
|
-
orientation,
|
39
|
-
root,
|
40
|
-
style,
|
41
|
-
validationMessage,
|
42
|
-
validationMessageIcon,
|
43
|
-
validationState
|
44
|
-
};
|
45
|
-
return [fieldProps, restOfProps];
|
46
|
-
};
|
47
|
-
exports.getPartitionedFieldProps = getPartitionedFieldProps;
|
48
16
|
/**
|
49
17
|
* Create the state required to render Field.
|
50
18
|
*
|
@@ -52,54 +20,58 @@ exports.getPartitionedFieldProps = getPartitionedFieldProps;
|
|
52
20
|
* before being passed to renderField_unstable.
|
53
21
|
*
|
54
22
|
* @param props - Props passed to this field
|
55
|
-
* @param ref - Ref to the
|
56
|
-
* @param params - Configuration parameters for this Field
|
23
|
+
* @param ref - Ref to the root
|
57
24
|
*/
|
58
|
-
const useField_unstable = (props, ref
|
59
|
-
var _a, _b, _c;
|
60
|
-
const [fieldProps, controlProps] = exports.getPartitionedFieldProps(props);
|
25
|
+
const useField_unstable = (props, ref) => {
|
26
|
+
var _a, _b, _c, _d;
|
61
27
|
const {
|
28
|
+
children,
|
62
29
|
orientation = 'vertical',
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
ariaInvalidOnError = true
|
68
|
-
} = params;
|
30
|
+
required,
|
31
|
+
validationState,
|
32
|
+
size
|
33
|
+
} = props;
|
69
34
|
const baseId = react_utilities_1.useId('field-');
|
70
|
-
const root = react_utilities_1.
|
71
|
-
|
72
|
-
|
73
|
-
});
|
74
|
-
const label = react_utilities_1.resolveShorthand(
|
35
|
+
const root = react_utilities_1.getNativeElementProps('div', {
|
36
|
+
...props,
|
37
|
+
ref
|
38
|
+
}, /*excludedPropNames:*/['children']);
|
39
|
+
const label = react_utilities_1.resolveShorthand(props.label, {
|
75
40
|
defaultProps: {
|
76
41
|
id: baseId + '__label',
|
77
|
-
required
|
78
|
-
size
|
42
|
+
required,
|
43
|
+
size
|
79
44
|
// htmlFor is handled below
|
80
45
|
}
|
81
46
|
});
|
82
47
|
|
83
|
-
const validationMessage = react_utilities_1.resolveShorthand(
|
48
|
+
const validationMessage = react_utilities_1.resolveShorthand(props.validationMessage, {
|
84
49
|
defaultProps: {
|
85
50
|
id: baseId + '__validationMessage',
|
86
51
|
role: validationState === 'error' ? 'alert' : undefined
|
87
52
|
}
|
88
53
|
});
|
89
|
-
const hint = react_utilities_1.resolveShorthand(
|
54
|
+
const hint = react_utilities_1.resolveShorthand(props.hint, {
|
90
55
|
defaultProps: {
|
91
56
|
id: baseId + '__hint'
|
92
57
|
}
|
93
58
|
});
|
94
|
-
const validationMessageIcon = react_utilities_1.resolveShorthand(
|
59
|
+
const validationMessageIcon = react_utilities_1.resolveShorthand(props.validationMessageIcon, {
|
95
60
|
required: !!validationState,
|
96
61
|
defaultProps: {
|
97
62
|
children: validationState ? validationMessageIcons[validationState] : undefined
|
98
63
|
}
|
99
64
|
});
|
100
|
-
|
101
|
-
|
65
|
+
const controlProps = React.isValidElement(children) ? {
|
66
|
+
...children.props
|
67
|
+
} : {};
|
68
|
+
if (label) {
|
102
69
|
(_a = controlProps['aria-labelledby']) !== null && _a !== void 0 ? _a : controlProps['aria-labelledby'] = label.id;
|
70
|
+
if (!label.htmlFor) {
|
71
|
+
// Assign the child a generated ID if doesn't already have an ID
|
72
|
+
(_b = controlProps.id) !== null && _b !== void 0 ? _b : controlProps.id = baseId + '__control';
|
73
|
+
label.htmlFor = controlProps.id;
|
74
|
+
}
|
103
75
|
}
|
104
76
|
if (validationMessage || hint) {
|
105
77
|
// The control is described by the validation message, or hint, or both
|
@@ -107,40 +79,33 @@ const useField_unstable = (props, ref, params) => {
|
|
107
79
|
// For reference: https://github.com/microsoft/fluentui/pull/25580#discussion_r1017259933
|
108
80
|
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(' ');
|
109
81
|
}
|
110
|
-
if (validationState === 'error'
|
111
|
-
(
|
82
|
+
if (validationState === 'error') {
|
83
|
+
(_c = controlProps['aria-invalid']) !== null && _c !== void 0 ? _c : controlProps['aria-invalid'] = true;
|
112
84
|
}
|
113
|
-
|
114
|
-
required: true
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
});
|
121
|
-
if (label && labelConnection === 'htmlFor') {
|
122
|
-
(_c = label.htmlFor) !== null && _c !== void 0 ? _c : label.htmlFor = control.id;
|
85
|
+
if (required) {
|
86
|
+
(_d = controlProps['aria-required']) !== null && _d !== void 0 ? _d : controlProps['aria-required'] = true;
|
87
|
+
}
|
88
|
+
if (React.isValidElement(children)) {
|
89
|
+
root.children = React.cloneElement(children, controlProps);
|
90
|
+
} else if (typeof children === 'function') {
|
91
|
+
root.children = children(controlProps);
|
123
92
|
}
|
124
|
-
|
93
|
+
return {
|
125
94
|
orientation,
|
126
95
|
validationState,
|
127
|
-
classNames: params.classNames,
|
128
96
|
components: {
|
129
97
|
root: 'div',
|
130
|
-
control: params.component,
|
131
98
|
label: react_label_1.Label,
|
132
99
|
validationMessage: 'div',
|
133
100
|
validationMessageIcon: 'span',
|
134
101
|
hint: 'div'
|
135
102
|
},
|
136
103
|
root,
|
137
|
-
control,
|
138
104
|
label,
|
139
105
|
validationMessageIcon,
|
140
106
|
validationMessage,
|
141
107
|
hint
|
142
108
|
};
|
143
|
-
return state;
|
144
109
|
};
|
145
110
|
exports.useField_unstable = useField_unstable;
|
146
111
|
//# sourceMappingURL=useField.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"mappings":";;;;;;AAAA;
|
1
|
+
{"version":3,"mappings":"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","names":["validationMessageIcons","error","React","react_icons_1","warning","success","useField_unstable","props","ref","children","orientation","required","validationState","size","baseId","react_utilities_1","root","label","defaultProps","id","validationMessage","role","undefined","hint","validationMessageIcon","controlProps","isValidElement","htmlFor","filter","Boolean","join","cloneElement","components","react_label_1","exports"],"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"]}
|
@@ -3,18 +3,16 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.useFieldStyles_unstable = exports.
|
6
|
+
exports.useFieldStyles_unstable = exports.fieldClassNames = void 0;
|
7
7
|
const react_theme_1 = /*#__PURE__*/require("@fluentui/react-theme");
|
8
8
|
const react_1 = /*#__PURE__*/require("@griffel/react");
|
9
|
-
|
10
|
-
root: `fui
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
});
|
17
|
-
exports.getFieldClassNames = getFieldClassNames;
|
9
|
+
exports.fieldClassNames = {
|
10
|
+
root: `fui-Field`,
|
11
|
+
label: `fui-Field__label`,
|
12
|
+
validationMessage: `fui-Field__validationMessage`,
|
13
|
+
validationMessageIcon: `fui-Field__validationMessageIcon`,
|
14
|
+
hint: `fui-Field__hint`
|
15
|
+
};
|
18
16
|
// Size of the icon in the validation message
|
19
17
|
const iconSize = '12px';
|
20
18
|
/**
|
@@ -87,30 +85,28 @@ const useValidationMessageIconStyles = /*#__PURE__*/react_1.__styles({
|
|
87
85
|
* Apply styling to the Field slots based on the state
|
88
86
|
*/
|
89
87
|
const useFieldStyles_unstable = state => {
|
90
|
-
const
|
91
|
-
|
88
|
+
const {
|
89
|
+
validationState
|
90
|
+
} = state;
|
92
91
|
const horizontal = state.orientation === 'horizontal';
|
93
92
|
const rootStyles = useRootStyles();
|
94
|
-
state.root.className = react_1.mergeClasses(
|
95
|
-
if (state.control) {
|
96
|
-
state.control.className = react_1.mergeClasses(classNames.control, state.control.className);
|
97
|
-
}
|
93
|
+
state.root.className = react_1.mergeClasses(exports.fieldClassNames.root, rootStyles.base, horizontal && rootStyles.horizontal, horizontal && !state.label && rootStyles.horizontalNoLabel, state.root.className);
|
98
94
|
const labelStyles = useLabelStyles();
|
99
95
|
if (state.label) {
|
100
|
-
state.label.className = react_1.mergeClasses(
|
96
|
+
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);
|
101
97
|
}
|
102
98
|
const validationMessageIconBaseClassName = useValidationMessageIconBaseClassName();
|
103
99
|
const validationMessageIconStyles = useValidationMessageIconStyles();
|
104
100
|
if (state.validationMessageIcon) {
|
105
|
-
state.validationMessageIcon.className = react_1.mergeClasses(
|
101
|
+
state.validationMessageIcon.className = react_1.mergeClasses(exports.fieldClassNames.validationMessageIcon, validationMessageIconBaseClassName, !!validationState && validationMessageIconStyles[validationState], state.validationMessageIcon.className);
|
106
102
|
}
|
107
103
|
const secondaryTextBaseClassName = useSecondaryTextBaseClassName();
|
108
104
|
const secondaryTextStyles = useSecondaryTextStyles();
|
109
105
|
if (state.validationMessage) {
|
110
|
-
state.validationMessage.className = react_1.mergeClasses(
|
106
|
+
state.validationMessage.className = react_1.mergeClasses(exports.fieldClassNames.validationMessage, secondaryTextBaseClassName, validationState === 'error' && secondaryTextStyles.error, !!state.validationMessageIcon && secondaryTextStyles.withIcon, state.validationMessage.className);
|
111
107
|
}
|
112
108
|
if (state.hint) {
|
113
|
-
state.hint.className = react_1.mergeClasses(
|
109
|
+
state.hint.className = react_1.mergeClasses(exports.fieldClassNames.hint, secondaryTextBaseClassName, state.hint.className);
|
114
110
|
}
|
115
111
|
};
|
116
112
|
exports.useFieldStyles_unstable = useFieldStyles_unstable;
|