@fluentui/react-field 9.0.0-alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.json +119 -0
- package/CHANGELOG.md +36 -0
- package/LICENSE +15 -0
- package/README.md +5 -0
- package/Spec.md +354 -0
- package/dist/index.d.ts +236 -0
- package/lib/CheckboxField.js +2 -0
- package/lib/CheckboxField.js.map +1 -0
- package/lib/ComboboxField.js +2 -0
- package/lib/ComboboxField.js.map +1 -0
- package/lib/Field.js +2 -0
- package/lib/Field.js.map +1 -0
- package/lib/InputField.js +2 -0
- package/lib/InputField.js.map +1 -0
- package/lib/RadioGroupField.js +2 -0
- package/lib/RadioGroupField.js.map +1 -0
- package/lib/SelectField.js +2 -0
- package/lib/SelectField.js.map +1 -0
- package/lib/SliderField.js +2 -0
- package/lib/SliderField.js.map +1 -0
- package/lib/SpinButtonField.js +2 -0
- package/lib/SpinButtonField.js.map +1 -0
- package/lib/SwitchField.js +2 -0
- package/lib/SwitchField.js.map +1 -0
- package/lib/TextareaField.js +2 -0
- package/lib/TextareaField.js.map +1 -0
- package/lib/components/CheckboxField/CheckboxField.js +32 -0
- package/lib/components/CheckboxField/CheckboxField.js.map +1 -0
- package/lib/components/CheckboxField/index.js +2 -0
- package/lib/components/CheckboxField/index.js.map +1 -0
- package/lib/components/ComboboxField/ComboboxField.js +14 -0
- package/lib/components/ComboboxField/ComboboxField.js.map +1 -0
- package/lib/components/ComboboxField/index.js +2 -0
- package/lib/components/ComboboxField/index.js.map +1 -0
- package/lib/components/Field/Field.types.js +2 -0
- package/lib/components/Field/Field.types.js.map +1 -0
- package/lib/components/Field/SlotComponent.types.js +2 -0
- package/lib/components/Field/SlotComponent.types.js.map +1 -0
- package/lib/components/Field/index.js +5 -0
- package/lib/components/Field/index.js.map +1 -0
- package/lib/components/Field/renderField.js +20 -0
- package/lib/components/Field/renderField.js.map +1 -0
- package/lib/components/Field/useField.js +139 -0
- package/lib/components/Field/useField.js.map +1 -0
- package/lib/components/Field/useFieldStyles.js +121 -0
- package/lib/components/Field/useFieldStyles.js.map +1 -0
- package/lib/components/InputField/InputField.js +14 -0
- package/lib/components/InputField/InputField.js.map +1 -0
- package/lib/components/InputField/index.js +2 -0
- package/lib/components/InputField/index.js.map +1 -0
- package/lib/components/RadioGroupField/RadioGroupField.js +15 -0
- package/lib/components/RadioGroupField/RadioGroupField.js.map +1 -0
- package/lib/components/RadioGroupField/index.js +2 -0
- package/lib/components/RadioGroupField/index.js.map +1 -0
- package/lib/components/SelectField/SelectField.js +14 -0
- package/lib/components/SelectField/SelectField.js.map +1 -0
- package/lib/components/SelectField/index.js +2 -0
- package/lib/components/SelectField/index.js.map +1 -0
- package/lib/components/SliderField/SliderField.js +14 -0
- package/lib/components/SliderField/SliderField.js.map +1 -0
- package/lib/components/SliderField/index.js +2 -0
- package/lib/components/SliderField/index.js.map +1 -0
- package/lib/components/SpinButtonField/SpinButtonField.js +14 -0
- package/lib/components/SpinButtonField/SpinButtonField.js.map +1 -0
- package/lib/components/SpinButtonField/index.js +2 -0
- package/lib/components/SpinButtonField/index.js.map +1 -0
- package/lib/components/SwitchField/SwitchField.js +14 -0
- package/lib/components/SwitchField/SwitchField.js.map +1 -0
- package/lib/components/SwitchField/index.js +2 -0
- package/lib/components/SwitchField/index.js.map +1 -0
- package/lib/components/TextareaField/TextareaField.js +14 -0
- package/lib/components/TextareaField/TextareaField.js.map +1 -0
- package/lib/components/TextareaField/index.js +2 -0
- package/lib/components/TextareaField/index.js.map +1 -0
- package/lib/index.js +11 -0
- package/lib/index.js.map +1 -0
- package/lib-commonjs/CheckboxField.js +10 -0
- package/lib-commonjs/CheckboxField.js.map +1 -0
- package/lib-commonjs/ComboboxField.js +10 -0
- package/lib-commonjs/ComboboxField.js.map +1 -0
- package/lib-commonjs/Field.js +10 -0
- package/lib-commonjs/Field.js.map +1 -0
- package/lib-commonjs/InputField.js +10 -0
- package/lib-commonjs/InputField.js.map +1 -0
- package/lib-commonjs/RadioGroupField.js +10 -0
- package/lib-commonjs/RadioGroupField.js.map +1 -0
- package/lib-commonjs/SelectField.js +10 -0
- package/lib-commonjs/SelectField.js.map +1 -0
- package/lib-commonjs/SliderField.js +10 -0
- package/lib-commonjs/SliderField.js.map +1 -0
- package/lib-commonjs/SpinButtonField.js +10 -0
- package/lib-commonjs/SpinButtonField.js.map +1 -0
- package/lib-commonjs/SwitchField.js +10 -0
- package/lib-commonjs/SwitchField.js.map +1 -0
- package/lib-commonjs/TextareaField.js +10 -0
- package/lib-commonjs/TextareaField.js.map +1 -0
- package/lib-commonjs/components/CheckboxField/CheckboxField.js +42 -0
- package/lib-commonjs/components/CheckboxField/CheckboxField.js.map +1 -0
- package/lib-commonjs/components/CheckboxField/index.js +10 -0
- package/lib-commonjs/components/CheckboxField/index.js.map +1 -0
- package/lib-commonjs/components/ComboboxField/ComboboxField.js +24 -0
- package/lib-commonjs/components/ComboboxField/ComboboxField.js.map +1 -0
- package/lib-commonjs/components/ComboboxField/index.js +10 -0
- package/lib-commonjs/components/ComboboxField/index.js.map +1 -0
- package/lib-commonjs/components/Field/Field.types.js +6 -0
- package/lib-commonjs/components/Field/Field.types.js.map +1 -0
- package/lib-commonjs/components/Field/SlotComponent.types.js +6 -0
- package/lib-commonjs/components/Field/SlotComponent.types.js.map +1 -0
- package/lib-commonjs/components/Field/index.js +16 -0
- package/lib-commonjs/components/Field/index.js.map +1 -0
- package/lib-commonjs/components/Field/renderField.js +31 -0
- package/lib-commonjs/components/Field/renderField.js.map +1 -0
- package/lib-commonjs/components/Field/useField.js +154 -0
- package/lib-commonjs/components/Field/useField.js.map +1 -0
- package/lib-commonjs/components/Field/useFieldStyles.js +134 -0
- package/lib-commonjs/components/Field/useFieldStyles.js.map +1 -0
- package/lib-commonjs/components/InputField/InputField.js +24 -0
- package/lib-commonjs/components/InputField/InputField.js.map +1 -0
- package/lib-commonjs/components/InputField/index.js +10 -0
- package/lib-commonjs/components/InputField/index.js.map +1 -0
- package/lib-commonjs/components/RadioGroupField/RadioGroupField.js +25 -0
- package/lib-commonjs/components/RadioGroupField/RadioGroupField.js.map +1 -0
- package/lib-commonjs/components/RadioGroupField/index.js +10 -0
- package/lib-commonjs/components/RadioGroupField/index.js.map +1 -0
- package/lib-commonjs/components/SelectField/SelectField.js +24 -0
- package/lib-commonjs/components/SelectField/SelectField.js.map +1 -0
- package/lib-commonjs/components/SelectField/index.js +10 -0
- package/lib-commonjs/components/SelectField/index.js.map +1 -0
- package/lib-commonjs/components/SliderField/SliderField.js +24 -0
- package/lib-commonjs/components/SliderField/SliderField.js.map +1 -0
- package/lib-commonjs/components/SliderField/index.js +10 -0
- package/lib-commonjs/components/SliderField/index.js.map +1 -0
- package/lib-commonjs/components/SpinButtonField/SpinButtonField.js +24 -0
- package/lib-commonjs/components/SpinButtonField/SpinButtonField.js.map +1 -0
- package/lib-commonjs/components/SpinButtonField/index.js +10 -0
- package/lib-commonjs/components/SpinButtonField/index.js.map +1 -0
- package/lib-commonjs/components/SwitchField/SwitchField.js +24 -0
- package/lib-commonjs/components/SwitchField/SwitchField.js.map +1 -0
- package/lib-commonjs/components/SwitchField/index.js +10 -0
- package/lib-commonjs/components/SwitchField/index.js.map +1 -0
- package/lib-commonjs/components/TextareaField/TextareaField.js +24 -0
- package/lib-commonjs/components/TextareaField/TextareaField.js.map +1 -0
- package/lib-commonjs/components/TextareaField/index.js +10 -0
- package/lib-commonjs/components/TextareaField/index.js.map +1 -0
- package/lib-commonjs/index.js +169 -0
- package/lib-commonjs/index.js.map +1 -0
- package/package.json +64 -0
package/dist/index.d.ts
ADDED
@@ -0,0 +1,236 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
|
3
|
+
import { Checkbox } from '@fluentui/react-checkbox';
|
4
|
+
import type { CheckboxProps } from '@fluentui/react-checkbox';
|
5
|
+
import { Combobox } from '@fluentui/react-combobox';
|
6
|
+
import type { ComponentProps } from '@fluentui/react-utilities';
|
7
|
+
import type { ComponentState } from '@fluentui/react-utilities';
|
8
|
+
import { ForwardRefComponent } from '@fluentui/react-utilities';
|
9
|
+
import { Input } from '@fluentui/react-input';
|
10
|
+
import { Label } from '@fluentui/react-label';
|
11
|
+
import { RadioGroup } from '@fluentui/react-radio';
|
12
|
+
import * as React_2 from 'react';
|
13
|
+
import { Select } from '@fluentui/react-select';
|
14
|
+
import { Slider } from '@fluentui/react-slider';
|
15
|
+
import type { Slot } from '@fluentui/react-utilities';
|
16
|
+
import { SlotClassNames } from '@fluentui/react-utilities';
|
17
|
+
import type { SlotRenderFunction } from '@fluentui/react-utilities';
|
18
|
+
import type { SlotShorthandValue } from '@fluentui/react-utilities';
|
19
|
+
import { SpinButton } from '@fluentui/react-spinbutton';
|
20
|
+
import { Switch } from '@fluentui/react-switch';
|
21
|
+
import { Textarea } from '@fluentui/react-textarea';
|
22
|
+
|
23
|
+
export declare const CheckboxField: ForwardRefComponent<CheckboxFieldProps>;
|
24
|
+
|
25
|
+
export declare const checkboxFieldClassNames: SlotClassNames<FieldSlots<FieldComponent>>;
|
26
|
+
|
27
|
+
export declare type CheckboxFieldProps = Omit<FieldProps<typeof Checkbox>, 'label'> & {
|
28
|
+
/**
|
29
|
+
* The Checkbox's label.
|
30
|
+
*/
|
31
|
+
label?: CheckboxProps['label'];
|
32
|
+
/**
|
33
|
+
* The label for the CheckboxField, which appears above or before the Checkbox, depending on the `orientation` prop.
|
34
|
+
* It is recommended to only set the `label` prop, and not `fieldLabel`.
|
35
|
+
*/
|
36
|
+
fieldLabel?: FieldProps<typeof Checkbox>['label'];
|
37
|
+
};
|
38
|
+
|
39
|
+
export declare const ComboboxField: ForwardRefComponent<ComboboxFieldProps>;
|
40
|
+
|
41
|
+
export declare const comboboxFieldClassNames: SlotClassNames<FieldSlots<FieldComponent>>;
|
42
|
+
|
43
|
+
export declare type ComboboxFieldProps = FieldProps<typeof Combobox>;
|
44
|
+
|
45
|
+
/**
|
46
|
+
* The minimum requirement for a component used by Field.
|
47
|
+
*
|
48
|
+
* Note: the use of VoidFunctionComponent means that component is not *required* to have a children prop,
|
49
|
+
* but it is still allowed to have a children prop.
|
50
|
+
*/
|
51
|
+
declare type FieldComponent = React_2.VoidFunctionComponent<Pick<React_2.HTMLAttributes<HTMLElement>, 'id' | 'className' | 'style' | 'aria-labelledby' | 'aria-describedby' | 'aria-invalid' | 'aria-errormessage'>>;
|
52
|
+
|
53
|
+
/**
|
54
|
+
* Configuration parameters for a Field class, passed to useField_unstable
|
55
|
+
*/
|
56
|
+
export declare type FieldConfig<T extends FieldComponent> = {
|
57
|
+
/**
|
58
|
+
* The underlying input component that this field is wrapping.
|
59
|
+
*/
|
60
|
+
component: T;
|
61
|
+
/**
|
62
|
+
* Class names for this component, created by `getFieldClassNames`.
|
63
|
+
*/
|
64
|
+
classNames: SlotClassNames<FieldSlots<T>>;
|
65
|
+
/**
|
66
|
+
* How the label be connected to the control.
|
67
|
+
* * htmlFor - Set the Label's htmlFor prop to the component's ID (and generate an ID if not provided).
|
68
|
+
* This is the preferred method for components that use the underlying <input> tag.
|
69
|
+
* * aria-labelledby - Set the component's aria-labelledby prop to the Label's ID. Use this for components
|
70
|
+
* that are not directly <input> elements (such as RadioGroup).
|
71
|
+
*
|
72
|
+
* @default htmlFor
|
73
|
+
*/
|
74
|
+
labelConnection?: 'htmlFor' | 'aria-labelledby';
|
75
|
+
};
|
76
|
+
|
77
|
+
/**
|
78
|
+
* Field Props
|
79
|
+
*/
|
80
|
+
export declare type FieldProps<T extends FieldComponent> = ComponentProps<Partial<FieldSlots<T>>, 'control'> & {
|
81
|
+
/**
|
82
|
+
* The orientation of the label relative to the field component.
|
83
|
+
* This only affects the label, and not the validationMessage or hint (which always appear below the field component).
|
84
|
+
*
|
85
|
+
* @default vertical
|
86
|
+
*/
|
87
|
+
orientation?: 'vertical' | 'horizontal';
|
88
|
+
/**
|
89
|
+
* The `validationState` affects the color of the `validationMessage`, the `validationMessageIcon`, and for some
|
90
|
+
* field components, an `validationState="error"` causes the border to become red.
|
91
|
+
*
|
92
|
+
* @default undefined
|
93
|
+
*/
|
94
|
+
validationState?: 'error' | 'warning' | 'success';
|
95
|
+
};
|
96
|
+
|
97
|
+
/**
|
98
|
+
* FieldProps plus extra optional props that are supported by useField_unstable, but not required to be part of the
|
99
|
+
* API of every Field component.
|
100
|
+
*
|
101
|
+
* This allows Field to forward the required and size props to the label if the underlying component supports them,
|
102
|
+
* but doesn't add them to the public API of fields that don't support them.
|
103
|
+
*/
|
104
|
+
declare type FieldPropsWithOptionalComponentProps<T extends FieldComponent> = FieldProps<T> & {
|
105
|
+
/**
|
106
|
+
* Whether the field label should be marked as required.
|
107
|
+
*/
|
108
|
+
required?: boolean;
|
109
|
+
/**
|
110
|
+
* Size of the field label.
|
111
|
+
*
|
112
|
+
* Number sizes will be ignored, but are allowed because the HTML `<input>` element has a prop `size?: number`.
|
113
|
+
*/
|
114
|
+
size?: 'small' | 'medium' | 'large' | number;
|
115
|
+
};
|
116
|
+
|
117
|
+
/**
|
118
|
+
* Slots added by Field
|
119
|
+
*/
|
120
|
+
export declare type FieldSlots<T extends FieldComponent> = {
|
121
|
+
root: NonNullable<Slot<'div'>>;
|
122
|
+
/**
|
123
|
+
* The underlying component wrapped by this field.
|
124
|
+
*/
|
125
|
+
control: SlotComponent<T>;
|
126
|
+
/**
|
127
|
+
* The label associated with the field.
|
128
|
+
*/
|
129
|
+
label?: Slot<typeof Label>;
|
130
|
+
/**
|
131
|
+
* A message about the validation state. The appearance of the `validationMessage` depends on `validationState`.
|
132
|
+
*/
|
133
|
+
validationMessage?: Slot<'span'>;
|
134
|
+
/**
|
135
|
+
* The icon associated with the `validationMessage`. If the `validationState` prop is set, this will default to an
|
136
|
+
* icon corresponding to that state.
|
137
|
+
*
|
138
|
+
* This will only be displayed if `validationMessage` is set.
|
139
|
+
*/
|
140
|
+
validationMessageIcon?: Slot<'span'>;
|
141
|
+
/**
|
142
|
+
* Additional hint text below the field.
|
143
|
+
*/
|
144
|
+
hint?: Slot<'span'>;
|
145
|
+
};
|
146
|
+
|
147
|
+
/**
|
148
|
+
* State used in rendering Field
|
149
|
+
*/
|
150
|
+
export declare type FieldState<T extends FieldComponent> = ComponentState<Required<FieldSlots<T>>> & Pick<FieldProps<T>, 'orientation' | 'validationState'> & {
|
151
|
+
classNames: SlotClassNames<FieldSlots<T>>;
|
152
|
+
};
|
153
|
+
|
154
|
+
export declare const getFieldClassNames: (name: string) => SlotClassNames<FieldSlots<FieldComponent>>;
|
155
|
+
|
156
|
+
export declare const InputField: ForwardRefComponent<InputFieldProps>;
|
157
|
+
|
158
|
+
export declare const inputFieldClassNames: SlotClassNames<FieldSlots<FieldComponent>>;
|
159
|
+
|
160
|
+
export declare type InputFieldProps = FieldProps<typeof Input>;
|
161
|
+
|
162
|
+
export declare const RadioGroupField: ForwardRefComponent<RadioGroupFieldProps>;
|
163
|
+
|
164
|
+
export declare const radioGroupFieldClassNames: SlotClassNames<FieldSlots<FieldComponent>>;
|
165
|
+
|
166
|
+
export declare type RadioGroupFieldProps = FieldProps<typeof RadioGroup>;
|
167
|
+
|
168
|
+
/**
|
169
|
+
* Render the final JSX of Field
|
170
|
+
*/
|
171
|
+
export declare const renderField_unstable: <T extends FieldComponent>(state: FieldState<T>) => JSX.Element;
|
172
|
+
|
173
|
+
export declare const SelectField: ForwardRefComponent<SelectFieldProps>;
|
174
|
+
|
175
|
+
export declare const selectFieldClassNames: SlotClassNames<FieldSlots<FieldComponent>>;
|
176
|
+
|
177
|
+
export declare type SelectFieldProps = FieldProps<typeof Select>;
|
178
|
+
|
179
|
+
export declare const SliderField: ForwardRefComponent<SliderFieldProps>;
|
180
|
+
|
181
|
+
export declare const sliderFieldClassNames: SlotClassNames<FieldSlots<FieldComponent>>;
|
182
|
+
|
183
|
+
export declare type SliderFieldProps = FieldProps<typeof Slider>;
|
184
|
+
|
185
|
+
declare type SlotComponent<Type extends React_2.ComponentType | React_2.VoidFunctionComponent> = WithSlotShorthandValue<Type extends React_2.ComponentType<infer Props> ? WithSlotRenderFunction<Props extends {
|
186
|
+
children?: unknown;
|
187
|
+
} ? Props : Props & {
|
188
|
+
children?: never;
|
189
|
+
}> : never>;
|
190
|
+
|
191
|
+
export declare const SpinButtonField: ForwardRefComponent<SpinButtonFieldProps>;
|
192
|
+
|
193
|
+
export declare const spinButtonFieldClassNames: SlotClassNames<FieldSlots<FieldComponent>>;
|
194
|
+
|
195
|
+
export declare type SpinButtonFieldProps = FieldProps<typeof SpinButton>;
|
196
|
+
|
197
|
+
export declare const SwitchField: ForwardRefComponent<SwitchFieldProps>;
|
198
|
+
|
199
|
+
export declare const switchFieldClassNames: SlotClassNames<FieldSlots<FieldComponent>>;
|
200
|
+
|
201
|
+
export declare type SwitchFieldProps = FieldProps<typeof Switch>;
|
202
|
+
|
203
|
+
export declare const TextareaField: ForwardRefComponent<TextareaFieldProps>;
|
204
|
+
|
205
|
+
export declare const textareaFieldClassNames: SlotClassNames<FieldSlots<FieldComponent>>;
|
206
|
+
|
207
|
+
export declare type TextareaFieldProps = FieldProps<typeof Textarea>;
|
208
|
+
|
209
|
+
/**
|
210
|
+
* Create the state required to render Field.
|
211
|
+
*
|
212
|
+
* The returned state can be modified with hooks such as useFieldStyles_unstable,
|
213
|
+
* before being passed to renderField_unstable.
|
214
|
+
*
|
215
|
+
* @param props - Props passed to this field
|
216
|
+
* @param ref - Ref to the control slot (primary slot)
|
217
|
+
* @param params - Configuration parameters for this Field
|
218
|
+
*/
|
219
|
+
export declare const useField_unstable: <T extends FieldComponent>(props: FieldPropsWithOptionalComponentProps<T>, ref: React_2.Ref<HTMLElement>, params: FieldConfig<T>) => FieldState<T>;
|
220
|
+
|
221
|
+
/**
|
222
|
+
* Apply styling to the Field slots based on the state
|
223
|
+
*/
|
224
|
+
export declare const useFieldStyles_unstable: <T extends FieldComponent>(state: FieldState<T>) => void;
|
225
|
+
|
226
|
+
declare type WithSlotRenderFunction<Props extends {
|
227
|
+
children?: unknown;
|
228
|
+
}> = Props & {
|
229
|
+
children?: Props['children'] | SlotRenderFunction<Props>;
|
230
|
+
};
|
231
|
+
|
232
|
+
declare type WithSlotShorthandValue<Props extends {
|
233
|
+
children?: unknown;
|
234
|
+
}> = Props | Extract<SlotShorthandValue, Props['children']>;
|
235
|
+
|
236
|
+
export { }
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"CheckboxField.js","sourceRoot":"../src/","sources":["CheckboxField.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC","sourcesContent":["export * from './components/CheckboxField/index';\n"]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"ComboboxField.js","sourceRoot":"../src/","sources":["ComboboxField.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC","sourcesContent":["export * from './components/ComboboxField/index';\n"]}
|
package/lib/Field.js
ADDED
package/lib/Field.js.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"Field.js","sourceRoot":"../src/","sources":["Field.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC","sourcesContent":["export * from './components/Field/index';\n"]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"InputField.js","sourceRoot":"../src/","sources":["InputField.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC","sourcesContent":["export * from './components/InputField/index';\n"]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"RadioGroupField.js","sourceRoot":"../src/","sources":["RadioGroupField.ts"],"names":[],"mappings":"AAAA,cAAc,oCAAoC,CAAC","sourcesContent":["export * from './components/RadioGroupField/index';\n"]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"SelectField.js","sourceRoot":"../src/","sources":["SelectField.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC","sourcesContent":["export * from './components/SelectField/index';\n"]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"SliderField.js","sourceRoot":"../src/","sources":["SliderField.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC","sourcesContent":["export * from './components/SliderField/index';\n"]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"SpinButtonField.js","sourceRoot":"../src/","sources":["SpinButtonField.ts"],"names":[],"mappings":"AAAA,cAAc,oCAAoC,CAAC","sourcesContent":["export * from './components/SpinButtonField/index';\n"]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"SwitchField.js","sourceRoot":"../src/","sources":["SwitchField.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC","sourcesContent":["export * from './components/SwitchField/index';\n"]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"TextareaField.js","sourceRoot":"../src/","sources":["TextareaField.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC","sourcesContent":["export * from './components/TextareaField/index';\n"]}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import * as React from 'react';
|
2
|
+
import { Checkbox } from '@fluentui/react-checkbox';
|
3
|
+
import { getFieldClassNames, renderField_unstable, useFieldStyles_unstable, useField_unstable } from '../../Field';
|
4
|
+
export const checkboxFieldClassNames = /*#__PURE__*/getFieldClassNames('CheckboxField');
|
5
|
+
export const CheckboxField = /*#__PURE__*/React.forwardRef((props, ref) => {
|
6
|
+
const {
|
7
|
+
fieldLabel,
|
8
|
+
required,
|
9
|
+
label,
|
10
|
+
control,
|
11
|
+
...restOfProps
|
12
|
+
} = props;
|
13
|
+
props = {
|
14
|
+
// Use the fieldLabel prop as the Field's label
|
15
|
+
label: fieldLabel,
|
16
|
+
// Use the label prop as the Checkbox's label
|
17
|
+
control: {
|
18
|
+
label,
|
19
|
+
required,
|
20
|
+
...control
|
21
|
+
},
|
22
|
+
...restOfProps
|
23
|
+
};
|
24
|
+
const state = useField_unstable(props, ref, {
|
25
|
+
component: Checkbox,
|
26
|
+
classNames: checkboxFieldClassNames
|
27
|
+
});
|
28
|
+
useFieldStyles_unstable(state);
|
29
|
+
return renderField_unstable(state);
|
30
|
+
});
|
31
|
+
CheckboxField.displayName = 'CheckboxField';
|
32
|
+
//# sourceMappingURL=CheckboxField.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["components/CheckboxField/CheckboxField.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAEA,SAAS,QAAT,QAAyB,0BAAzB;AAGA,SAAS,kBAAT,EAA6B,oBAA7B,EAAmD,uBAAnD,EAA4E,iBAA5E,QAAqG,aAArG;AAeA,OAAO,MAAM,uBAAuB,gBAAG,kBAAkB,CAAC,eAAD,CAAlD;AAEP,OAAO,MAAM,aAAa,gBAA4C,KAAK,CAAC,UAAN,CAAiB,CAAC,KAAD,EAAQ,GAAR,KAAe;EACpG,MAAM;IAAE,UAAF;IAAc,QAAd;IAAwB,KAAxB;IAA+B,OAA/B;IAAwC,GAAG;EAA3C,IAA2D,KAAjE;EAEA,KAAK,GAAG;IACN;IACA,KAAK,EAAE,UAFD;IAGN;IACA,OAAO,EAAE;MAAE,KAAF;MAAS,QAAT;MAAmB,GAAG;IAAtB,CAJH;IAKN,GAAG;EALG,CAAR;EAQA,MAAM,KAAK,GAAG,iBAAiB,CAAC,KAAD,EAAQ,GAAR,EAAa;IAAE,SAAS,EAAE,QAAb;IAAuB,UAAU,EAAE;EAAnC,CAAb,CAA/B;EACA,uBAAuB,CAAC,KAAD,CAAvB;EACA,OAAO,oBAAoB,CAAC,KAAD,CAA3B;AACD,CAdqE,CAA/D;AAgBP,aAAa,CAAC,WAAd,GAA4B,eAA5B","sourcesContent":["import * as React from 'react';\nimport type { CheckboxProps } from '@fluentui/react-checkbox';\nimport { Checkbox } from '@fluentui/react-checkbox';\nimport { ForwardRefComponent } from '@fluentui/react-utilities';\nimport type { FieldProps } from '../../Field';\nimport { getFieldClassNames, renderField_unstable, useFieldStyles_unstable, useField_unstable } from '../../Field';\n\nexport type CheckboxFieldProps = Omit<FieldProps<typeof Checkbox>, 'label'> & {\n /**\n * The Checkbox's label.\n */\n label?: CheckboxProps['label'];\n\n /**\n * The label for the CheckboxField, which appears above or before the Checkbox, depending on the `orientation` prop.\n * It is recommended to only set the `label` prop, and not `fieldLabel`.\n */\n fieldLabel?: FieldProps<typeof Checkbox>['label'];\n};\n\nexport const checkboxFieldClassNames = getFieldClassNames('CheckboxField');\n\nexport const CheckboxField: ForwardRefComponent<CheckboxFieldProps> = React.forwardRef((props, ref) => {\n const { fieldLabel, required, label, control, ...restOfProps } = props;\n\n props = {\n // Use the fieldLabel prop as the Field's label\n label: fieldLabel,\n // Use the label prop as the Checkbox's label\n control: { label, required, ...control },\n ...restOfProps,\n };\n\n const state = useField_unstable(props, ref, { component: Checkbox, classNames: checkboxFieldClassNames });\n useFieldStyles_unstable(state);\n return renderField_unstable(state);\n});\n\nCheckboxField.displayName = 'CheckboxField';\n"],"sourceRoot":"../src/"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["components/CheckboxField/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC","sourcesContent":["export * from './CheckboxField';\n"]}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import * as React from 'react';
|
2
|
+
import { Combobox } from '@fluentui/react-combobox';
|
3
|
+
import { getFieldClassNames, renderField_unstable, useFieldStyles_unstable, useField_unstable } from '../../Field';
|
4
|
+
export const comboboxFieldClassNames = /*#__PURE__*/getFieldClassNames('ComboboxField');
|
5
|
+
export const ComboboxField = /*#__PURE__*/React.forwardRef((props, ref) => {
|
6
|
+
const state = useField_unstable(props, ref, {
|
7
|
+
component: Combobox,
|
8
|
+
classNames: comboboxFieldClassNames
|
9
|
+
});
|
10
|
+
useFieldStyles_unstable(state);
|
11
|
+
return renderField_unstable(state);
|
12
|
+
});
|
13
|
+
ComboboxField.displayName = 'ComboboxField';
|
14
|
+
//# sourceMappingURL=ComboboxField.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["components/ComboboxField/ComboboxField.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,QAAT,QAAyB,0BAAzB;AAGA,SAAS,kBAAT,EAA6B,oBAA7B,EAAmD,uBAAnD,EAA4E,iBAA5E,QAAqG,aAArG;AAIA,OAAO,MAAM,uBAAuB,gBAAG,kBAAkB,CAAC,eAAD,CAAlD;AAEP,OAAO,MAAM,aAAa,gBAA4C,KAAK,CAAC,UAAN,CAAiB,CAAC,KAAD,EAAQ,GAAR,KAAe;EACpG,MAAM,KAAK,GAAG,iBAAiB,CAAC,KAAD,EAAQ,GAAR,EAAa;IAAE,SAAS,EAAE,QAAb;IAAuB,UAAU,EAAE;EAAnC,CAAb,CAA/B;EACA,uBAAuB,CAAC,KAAD,CAAvB;EACA,OAAO,oBAAoB,CAAC,KAAD,CAA3B;AACD,CAJqE,CAA/D;AAMP,aAAa,CAAC,WAAd,GAA4B,eAA5B","sourcesContent":["import * as React from 'react';\nimport { Combobox } from '@fluentui/react-combobox';\nimport type { ForwardRefComponent } from '@fluentui/react-utilities';\nimport type { FieldProps } from '../../Field';\nimport { getFieldClassNames, renderField_unstable, useFieldStyles_unstable, useField_unstable } from '../../Field';\n\nexport type ComboboxFieldProps = FieldProps<typeof Combobox>;\n\nexport const comboboxFieldClassNames = getFieldClassNames('ComboboxField');\n\nexport const ComboboxField: ForwardRefComponent<ComboboxFieldProps> = React.forwardRef((props, ref) => {\n const state = useField_unstable(props, ref, { component: Combobox, classNames: comboboxFieldClassNames });\n useFieldStyles_unstable(state);\n return renderField_unstable(state);\n});\n\nComboboxField.displayName = 'ComboboxField';\n"],"sourceRoot":"../src/"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["components/ComboboxField/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC","sourcesContent":["export * from './ComboboxField';\n"]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"Field.types.js","sourceRoot":"../src/","sources":["components/Field/Field.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport { Label } from '@fluentui/react-label';\nimport type { ComponentProps, ComponentState, Slot, SlotClassNames } from '@fluentui/react-utilities';\nimport type { SlotComponent } from './SlotComponent.types';\n\n/**\n * The minimum requirement for a component used by Field.\n *\n * Note: the use of VoidFunctionComponent means that component is not *required* to have a children prop,\n * but it is still allowed to have a children prop.\n */\nexport type FieldComponent = React.VoidFunctionComponent<\n Pick<\n React.HTMLAttributes<HTMLElement>,\n 'id' | 'className' | 'style' | 'aria-labelledby' | 'aria-describedby' | 'aria-invalid' | 'aria-errormessage'\n >\n>;\n\n/**\n * Slots added by Field\n */\nexport type FieldSlots<T extends FieldComponent> = {\n root: NonNullable<Slot<'div'>>;\n\n /**\n * The underlying component wrapped by this field.\n */\n control: SlotComponent<T>;\n\n /**\n * The label associated with the field.\n */\n label?: Slot<typeof Label>;\n\n /**\n * A message about the validation state. The appearance of the `validationMessage` depends on `validationState`.\n */\n validationMessage?: Slot<'span'>;\n\n /**\n * The icon associated with the `validationMessage`. If the `validationState` prop is set, this will default to an\n * icon corresponding to that state.\n *\n * This will only be displayed if `validationMessage` is set.\n */\n validationMessageIcon?: Slot<'span'>;\n\n /**\n * Additional hint text below the field.\n */\n hint?: Slot<'span'>;\n};\n\n/**\n * Field Props\n */\nexport type FieldProps<T extends FieldComponent> = ComponentProps<Partial<FieldSlots<T>>, 'control'> & {\n /**\n * The orientation of the label relative to the field component.\n * This only affects the label, and not the validationMessage or hint (which always appear below the field component).\n *\n * @default vertical\n */\n orientation?: 'vertical' | 'horizontal';\n\n /**\n * The `validationState` affects the color of the `validationMessage`, the `validationMessageIcon`, and for some\n * field components, an `validationState=\"error\"` causes the border to become red.\n *\n * @default undefined\n */\n validationState?: 'error' | 'warning' | 'success';\n};\n\n/**\n * FieldProps plus extra optional props that are supported by useField_unstable, but not required to be part of the\n * API of every Field component.\n *\n * This allows Field to forward the required and size props to the label if the underlying component supports them,\n * but doesn't add them to the public API of fields that don't support them.\n */\nexport type FieldPropsWithOptionalComponentProps<T extends FieldComponent> = FieldProps<T> & {\n /**\n * Whether the field label should be marked as required.\n */\n required?: boolean;\n\n /**\n * Size of the field label.\n *\n * Number sizes will be ignored, but are allowed because the HTML `<input>` element has a prop `size?: number`.\n */\n size?: 'small' | 'medium' | 'large' | number;\n};\n\n/**\n * Configuration parameters for a Field class, passed to useField_unstable\n */\nexport type FieldConfig<T extends FieldComponent> = {\n /**\n * The underlying input component that this field is wrapping.\n */\n component: T;\n\n /**\n * Class names for this component, created by `getFieldClassNames`.\n */\n classNames: SlotClassNames<FieldSlots<T>>;\n\n /**\n * How the label be connected to the control.\n * * htmlFor - Set the Label's htmlFor prop to the component's ID (and generate an ID if not provided).\n * This is the preferred method for components that use the underlying <input> tag.\n * * aria-labelledby - Set the component's aria-labelledby prop to the Label's ID. Use this for components\n * that are not directly <input> elements (such as RadioGroup).\n *\n * @default htmlFor\n */\n labelConnection?: 'htmlFor' | 'aria-labelledby';\n};\n\n/**\n * State used in rendering Field\n */\nexport type FieldState<T extends FieldComponent> = ComponentState<Required<FieldSlots<T>>> &\n Pick<FieldProps<T>, 'orientation' | 'validationState'> & {\n classNames: SlotClassNames<FieldSlots<T>>;\n };\n"]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"SlotComponent.types.js","sourceRoot":"../src/","sources":["components/Field/SlotComponent.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport type { SlotShorthandValue, SlotRenderFunction } from '@fluentui/react-utilities';\n\n//\n// TEMPORARY definition of the SlotComponent type, until it is available from react-utilities\n//\n\nexport type SlotComponent<Type extends React.ComponentType | React.VoidFunctionComponent> = WithSlotShorthandValue<\n Type extends React.ComponentType<infer Props>\n ? // If this is a VoidFunctionComponent that doesn't allow children, add { children?: never }\n WithSlotRenderFunction<Props extends { children?: unknown } ? Props : Props & { children?: never }>\n : never\n>;\n\n//\n// TEMPORARY copied versions of the non-exported helper types from react-utilities\n//\n\ntype WithSlotShorthandValue<Props extends { children?: unknown }> =\n | Props\n | Extract<SlotShorthandValue, Props['children']>;\n\ntype WithSlotRenderFunction<Props extends { children?: unknown }> = Props & {\n children?: Props['children'] | SlotRenderFunction<Props>;\n};\n"]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["components/Field/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC","sourcesContent":["export * from './Field.types';\nexport * from './renderField';\nexport * from './useField';\nexport * from './useFieldStyles';\n"]}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import * as React from 'react';
|
2
|
+
import { getSlots } from '@fluentui/react-utilities';
|
3
|
+
/**
|
4
|
+
* Render the final JSX of Field
|
5
|
+
*/
|
6
|
+
|
7
|
+
export const renderField_unstable = state => {
|
8
|
+
const {
|
9
|
+
slots,
|
10
|
+
slotProps
|
11
|
+
} = getSlots(state);
|
12
|
+
return /*#__PURE__*/React.createElement(slots.root, { ...slotProps.root
|
13
|
+
}, slots.label && /*#__PURE__*/React.createElement(slots.label, { ...slotProps.label
|
14
|
+
}), slots.control && /*#__PURE__*/React.createElement(slots.control, { ...slotProps.control
|
15
|
+
}), slots.validationMessage && /*#__PURE__*/React.createElement(slots.validationMessage, { ...slotProps.validationMessage
|
16
|
+
}, slots.validationMessageIcon && /*#__PURE__*/React.createElement(slots.validationMessageIcon, { ...slotProps.validationMessageIcon
|
17
|
+
}), slotProps.validationMessage.children), slots.hint && /*#__PURE__*/React.createElement(slots.hint, { ...slotProps.hint
|
18
|
+
}));
|
19
|
+
};
|
20
|
+
//# sourceMappingURL=renderField.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["components/Field/renderField.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,QAAT,QAAyB,2BAAzB;AAGA;;AAEG;;AACH,OAAO,MAAM,oBAAoB,GAA8B,KAA3B,IAAmD;EACrF,MAAM;IAAE,KAAF;IAAS;EAAT,IAAuB,QAAQ,CAA6B,KAA7B,CAArC;EAEA,oBACE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,IAAP,EAAW,EAAA,GAAK,SAAS,CAAC;EAAf,CAAX,EACG,KAAK,CAAC,KAAN,iBAAe,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,KAAP,EAAY,EAAA,GAAK,SAAS,CAAC;EAAf,CAAZ,CADlB,EAGG,KAAK,CAAC,OAAN,iBAAiB,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,OAAP,EAAc,EAAA,GAAM,SAAS,CAAC;EAAhB,CAAd,CAHpB,EAIG,KAAK,CAAC,iBAAN,iBACC,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,iBAAP,EAAwB,EAAA,GAAK,SAAS,CAAC;EAAf,CAAxB,EACG,KAAK,CAAC,qBAAN,iBAA+B,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,qBAAP,EAA4B,EAAA,GAAK,SAAS,CAAC;EAAf,CAA5B,CADlC,EAEG,SAAS,CAAC,iBAAV,CAA4B,QAF/B,CALJ,EAUG,KAAK,CAAC,IAAN,iBAAc,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,IAAP,EAAW,EAAA,GAAK,SAAS,CAAC;EAAf,CAAX,CAVjB,CADF;AAcD,CAjBM","sourcesContent":["import * as React from 'react';\nimport { getSlots } from '@fluentui/react-utilities';\nimport type { FieldComponent, FieldSlots, FieldState } from './Field.types';\n\n/**\n * Render the final JSX of Field\n */\nexport const renderField_unstable = <T extends FieldComponent>(state: FieldState<T>) => {\n const { slots, slotProps } = getSlots<FieldSlots<FieldComponent>>(state as FieldState<FieldComponent>);\n\n return (\n <slots.root {...slotProps.root}>\n {slots.label && <slots.label {...slotProps.label} />}\n {/* eslint-disable-next-line @typescript-eslint/no-explicit-any */}\n {slots.control && <slots.control {...(slotProps.control as any)} />}\n {slots.validationMessage && (\n <slots.validationMessage {...slotProps.validationMessage}>\n {slots.validationMessageIcon && <slots.validationMessageIcon {...slotProps.validationMessageIcon} />}\n {slotProps.validationMessage.children}\n </slots.validationMessage>\n )}\n {slots.hint && <slots.hint {...slotProps.hint} />}\n </slots.root>\n );\n};\n"],"sourceRoot":"../src/"}
|
@@ -0,0 +1,139 @@
|
|
1
|
+
import * as React from 'react';
|
2
|
+
import { CheckmarkCircle12Filled, ErrorCircle12Filled, Warning12Filled } from '@fluentui/react-icons';
|
3
|
+
import { Label } from '@fluentui/react-label';
|
4
|
+
import { getNativeElementProps, resolveShorthand, useId } from '@fluentui/react-utilities';
|
5
|
+
const validationMessageIcons = {
|
6
|
+
error: /*#__PURE__*/React.createElement(ErrorCircle12Filled, null),
|
7
|
+
warning: /*#__PURE__*/React.createElement(Warning12Filled, null),
|
8
|
+
success: /*#__PURE__*/React.createElement(CheckmarkCircle12Filled, null)
|
9
|
+
};
|
10
|
+
/**
|
11
|
+
* Merge two possibly-undefined IDs for aria-describedby. If both IDs are defined, combines
|
12
|
+
* them into a string separated by a space. Otherwise, returns just the defined ID (if any).
|
13
|
+
*/
|
14
|
+
|
15
|
+
const mergeAriaDescribedBy = (a, b) => a && b ? `${a} ${b}` : a || b;
|
16
|
+
/**
|
17
|
+
* Partition the props used by the Field itself, from the props that are passed to the underlying field component.
|
18
|
+
*/
|
19
|
+
|
20
|
+
|
21
|
+
export const getPartitionedFieldProps = props => {
|
22
|
+
const {
|
23
|
+
className,
|
24
|
+
control,
|
25
|
+
hint,
|
26
|
+
label,
|
27
|
+
orientation,
|
28
|
+
root,
|
29
|
+
style,
|
30
|
+
validationMessage,
|
31
|
+
validationMessageIcon,
|
32
|
+
validationState,
|
33
|
+
...restOfProps
|
34
|
+
} = props;
|
35
|
+
const fieldProps = {
|
36
|
+
className,
|
37
|
+
control,
|
38
|
+
hint,
|
39
|
+
label,
|
40
|
+
orientation,
|
41
|
+
root,
|
42
|
+
style,
|
43
|
+
validationMessage,
|
44
|
+
validationMessageIcon,
|
45
|
+
validationState
|
46
|
+
};
|
47
|
+
return [fieldProps, restOfProps];
|
48
|
+
};
|
49
|
+
/**
|
50
|
+
* Create the state required to render Field.
|
51
|
+
*
|
52
|
+
* The returned state can be modified with hooks such as useFieldStyles_unstable,
|
53
|
+
* before being passed to renderField_unstable.
|
54
|
+
*
|
55
|
+
* @param props - Props passed to this field
|
56
|
+
* @param ref - Ref to the control slot (primary slot)
|
57
|
+
* @param params - Configuration parameters for this Field
|
58
|
+
*/
|
59
|
+
|
60
|
+
export const useField_unstable = (props, ref, params) => {
|
61
|
+
const [fieldProps, controlProps] = getPartitionedFieldProps(props);
|
62
|
+
const baseId = useId('field-');
|
63
|
+
const {
|
64
|
+
orientation = 'vertical',
|
65
|
+
validationState
|
66
|
+
} = fieldProps;
|
67
|
+
const root = resolveShorthand(fieldProps.root, {
|
68
|
+
required: true,
|
69
|
+
defaultProps: getNativeElementProps('div', fieldProps)
|
70
|
+
});
|
71
|
+
const label = resolveShorthand(fieldProps.label, {
|
72
|
+
defaultProps: {
|
73
|
+
id: baseId + '__label',
|
74
|
+
required: controlProps.required,
|
75
|
+
size: typeof controlProps.size === 'string' ? controlProps.size : undefined // htmlFor is set below
|
76
|
+
|
77
|
+
}
|
78
|
+
});
|
79
|
+
const validationMessage = resolveShorthand(fieldProps.validationMessage, {
|
80
|
+
defaultProps: {
|
81
|
+
id: baseId + '__validationMessage'
|
82
|
+
}
|
83
|
+
});
|
84
|
+
const hint = resolveShorthand(fieldProps.hint, {
|
85
|
+
defaultProps: {
|
86
|
+
id: baseId + '__hint'
|
87
|
+
}
|
88
|
+
});
|
89
|
+
const validationMessageIcon = resolveShorthand(fieldProps.validationMessageIcon, {
|
90
|
+
required: !!validationState,
|
91
|
+
defaultProps: {
|
92
|
+
children: validationState ? validationMessageIcons[validationState] : undefined
|
93
|
+
}
|
94
|
+
});
|
95
|
+
const {
|
96
|
+
labelConnection = 'htmlFor'
|
97
|
+
} = params;
|
98
|
+
const hasError = validationState === 'error';
|
99
|
+
const control = resolveShorthand(fieldProps.control, {
|
100
|
+
required: true,
|
101
|
+
defaultProps: {
|
102
|
+
ref,
|
103
|
+
// Add a default ID only if required for label's htmlFor prop
|
104
|
+
id: label && labelConnection === 'htmlFor' ? baseId + '__control' : undefined,
|
105
|
+
// Add aria-labelledby only if not using the label's htmlFor
|
106
|
+
'aria-labelledby': labelConnection !== 'htmlFor' ? label === null || label === void 0 ? void 0 : label.id : undefined,
|
107
|
+
'aria-describedby': hasError ? hint === null || hint === void 0 ? void 0 : hint.id : mergeAriaDescribedBy(validationMessage === null || validationMessage === void 0 ? void 0 : validationMessage.id, hint === null || hint === void 0 ? void 0 : hint.id),
|
108
|
+
'aria-errormessage': hasError ? validationMessage === null || validationMessage === void 0 ? void 0 : validationMessage.id : undefined,
|
109
|
+
'aria-invalid': hasError ? true : undefined,
|
110
|
+
...controlProps
|
111
|
+
}
|
112
|
+
});
|
113
|
+
|
114
|
+
if (labelConnection === 'htmlFor' && label && !label.htmlFor) {
|
115
|
+
label.htmlFor = control.id;
|
116
|
+
}
|
117
|
+
|
118
|
+
const state = {
|
119
|
+
orientation,
|
120
|
+
validationState,
|
121
|
+
classNames: params.classNames,
|
122
|
+
components: {
|
123
|
+
root: 'div',
|
124
|
+
control: params.component,
|
125
|
+
label: Label,
|
126
|
+
validationMessage: 'span',
|
127
|
+
validationMessageIcon: 'span',
|
128
|
+
hint: 'span'
|
129
|
+
},
|
130
|
+
root,
|
131
|
+
control,
|
132
|
+
label,
|
133
|
+
validationMessageIcon,
|
134
|
+
validationMessage,
|
135
|
+
hint
|
136
|
+
};
|
137
|
+
return state;
|
138
|
+
};
|
139
|
+
//# sourceMappingURL=useField.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["components/Field/useField.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAC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,EAAE;IANI,CAJ4B;IAYxC,IAZwC;IAaxC,OAbwC;IAcxC,KAdwC;IAexC,qBAfwC;IAgBxC,iBAhBwC;IAiBxC;EAjBwC,CAA1C;EAoBA,OAAO,KAAP;AACD,CAvFM","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/"}
|