UNPKG

@rjsf/fluent-ui

Version:

Fluent UI theme, fields and widgets for react-jsonschema-form

1,396 lines (1,363 loc) 37.6 kB
// src/index.ts import { initializeIcons } from "@fluentui/react"; // src/FuiForm/FuiForm.ts import { withTheme } from "@rjsf/core"; // src/ArrayFieldItemTemplate/ArrayFieldItemTemplate.tsx import { jsx, jsxs } from "react/jsx-runtime"; function ArrayFieldItemTemplate(props) { const { children, disabled, hasToolbar, hasCopy, hasMoveDown, hasMoveUp, hasRemove, index, onCopyIndexClick, onDropIndexClick, onReorderClick, readonly, uiSchema, registry } = props; const { CopyButton: CopyButton2, MoveDownButton: MoveDownButton2, MoveUpButton: MoveUpButton2, RemoveButton: RemoveButton2 } = registry.templates.ButtonTemplates; return /* @__PURE__ */ jsx("div", { className: "ms-Grid", dir: "ltr", children: /* @__PURE__ */ jsxs("div", { className: "ms-Grid-row", children: [ /* @__PURE__ */ jsx("div", { className: "ms-Grid-col ms-sm6 ms-md8 ms-lg9", children: /* @__PURE__ */ jsx("div", { className: "ms-Grid-row", children }) }), hasToolbar && /* @__PURE__ */ jsxs("div", { className: "ms-Grid-col ms-sm6 ms-md4 ms-lg3", style: { textAlign: "right" }, children: [ (hasMoveUp || hasMoveDown) && /* @__PURE__ */ jsx( MoveUpButton2, { disabled: disabled || readonly || !hasMoveUp, onClick: onReorderClick(index, index - 1), uiSchema, registry } ), (hasMoveUp || hasMoveDown) && /* @__PURE__ */ jsx( MoveDownButton2, { disabled: disabled || readonly || !hasMoveDown, onClick: onReorderClick(index, index + 1), uiSchema, registry } ), hasCopy && /* @__PURE__ */ jsx( CopyButton2, { disabled: disabled || readonly, onClick: onCopyIndexClick(index), uiSchema, registry } ), hasRemove && /* @__PURE__ */ jsx( RemoveButton2, { disabled: disabled || readonly, onClick: onDropIndexClick(index), uiSchema, registry } ) ] }) ] }) }); } // src/AddButton/AddButton.tsx import { TranslatableString } from "@rjsf/utils"; import { CommandBarButton } from "@fluentui/react"; import { jsx as jsx2 } from "react/jsx-runtime"; var addIcon = { iconName: "Add" }; function AddButton(props) { const { registry: { translateString } } = props; return /* @__PURE__ */ jsx2( CommandBarButton, { style: { height: "32px" }, iconProps: addIcon, text: translateString(TranslatableString.AddItemButton), className: props.className, onClick: props.onClick, disabled: props.disabled } ); } // src/ArrayFieldTemplate/ArrayFieldTemplate.tsx import { getTemplate, getUiOptions } from "@rjsf/utils"; import { Fragment, jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime"; var rightJustify = { float: "right" }; function ArrayFieldTemplate(props) { const { canAdd, disabled, idSchema, uiSchema, items, onAddClick, readonly, registry, required, schema, title } = props; const uiOptions = getUiOptions(uiSchema); const ArrayFieldDescriptionTemplate = getTemplate( "ArrayFieldDescriptionTemplate", registry, uiOptions ); const ArrayFieldItemTemplate2 = getTemplate( "ArrayFieldItemTemplate", registry, uiOptions ); const ArrayFieldTitleTemplate = getTemplate( "ArrayFieldTitleTemplate", registry, uiOptions ); const { ButtonTemplates: { AddButton: AddButton2 } } = registry.templates; return /* @__PURE__ */ jsxs2(Fragment, { children: [ /* @__PURE__ */ jsx3( ArrayFieldTitleTemplate, { idSchema, title: uiOptions.title || title, schema, uiSchema, required, registry } ), /* @__PURE__ */ jsx3( ArrayFieldDescriptionTemplate, { idSchema, description: uiOptions.description || schema.description, schema, uiSchema, registry } ), items.length > 0 && items.map(({ key, ...itemProps }) => /* @__PURE__ */ jsx3(ArrayFieldItemTemplate2, { ...itemProps }, key)), canAdd && /* @__PURE__ */ jsx3("span", { style: rightJustify, children: /* @__PURE__ */ jsx3( AddButton2, { className: "array-item-add", onClick: onAddClick, disabled: disabled || readonly, uiSchema, registry } ) }) ] }); } // src/BaseInputTemplate/BaseInputTemplate.tsx import { TextField } from "@fluentui/react"; import { ariaDescribedByIds, examplesId, labelValue, getInputProps } from "@rjsf/utils"; import _pick from "lodash/pick"; import { Fragment as Fragment2, jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime"; var allowedProps = [ "multiline", "resizable", "autoAdjustHeight", "underlined", "borderless", "label", "onRenderLabel", "description", "onRenderDescription", "prefix", "suffix", "onRenderPrefix", "onRenderSuffix", "iconProps", "defaultValue", "value", "disabled", "readOnly", "errorMessage", "onChange", "onNotifyValidationResult", "onGetErrorMessage", "deferredValidationTime", "className", "inputClassName", "ariaLabel", "validateOnFocusIn", "validateOnFocusOut", "validateOnLoad", "theme", "styles", "autoComplete", "mask", "maskChar", "maskFormat", "type", "list" ]; function BaseInputTemplate({ id, placeholder, required, readonly, disabled, label, hideLabel, value, onChange, onChangeOverride, onBlur, onFocus, autofocus, options, schema, type, rawErrors, multiline }) { const inputProps = getInputProps(schema, type, options); const _onChange = ({ target: { value: value2 } }) => onChange(value2 === "" ? options.emptyValue : value2); const _onBlur = ({ target }) => onBlur(id, target && target.value); const _onFocus = ({ target }) => onFocus(id, target && target.value); const uiProps = _pick(options.props || {}, allowedProps); return /* @__PURE__ */ jsxs3(Fragment2, { children: [ /* @__PURE__ */ jsx4( TextField, { id, name: id, placeholder, label: labelValue(label, hideLabel), autoFocus: autofocus, required, disabled, readOnly: readonly, multiline, ...inputProps, value: value || value === 0 ? value : "", onChange: onChangeOverride || _onChange, onBlur: _onBlur, onFocus: _onFocus, errorMessage: (rawErrors || []).join("\n"), list: schema.examples ? examplesId(id) : void 0, ...uiProps, "aria-describedby": ariaDescribedByIds(id, !!schema.examples) } ), Array.isArray(schema.examples) && /* @__PURE__ */ jsx4("datalist", { id: examplesId(id), children: schema.examples.concat(schema.default && !schema.examples.includes(schema.default) ? [schema.default] : []).map((example) => { return /* @__PURE__ */ jsx4("option", { value: example }, example); }) }) ] }); } // src/DescriptionField/DescriptionField.tsx import { Text } from "@fluentui/react"; import { jsx as jsx5 } from "react/jsx-runtime"; function DescriptionField({ description, id }) { if (description) { return /* @__PURE__ */ jsx5(Text, { id, children: description }); } return null; } // src/ErrorList/ErrorList.tsx import { MessageBar, MessageBarType } from "@fluentui/react"; import { TranslatableString as TranslatableString2 } from "@rjsf/utils"; import { Fragment as Fragment3, jsx as jsx6 } from "react/jsx-runtime"; function ErrorList({ errors, registry }) { const { translateString } = registry; return /* @__PURE__ */ jsx6(Fragment3, { children: errors.map((error, i) => { return /* @__PURE__ */ jsx6( MessageBar, { messageBarType: MessageBarType.error, isMultiline: false, dismissButtonAriaLabel: translateString(TranslatableString2.CloseLabel), children: error.stack }, i ); }) }); } // src/IconButton/IconButton.tsx import { IconButton } from "@fluentui/react"; import { TranslatableString as TranslatableString3 } from "@rjsf/utils"; import { jsx as jsx7 } from "react/jsx-runtime"; function FluentIconButton(props) { const iconProps = { iconName: props.icon }; return /* @__PURE__ */ jsx7(IconButton, { disabled: props.disabled, onClick: props.onClick, iconProps, color: "secondary" }); } function CopyButton(props) { const { registry: { translateString } } = props; return /* @__PURE__ */ jsx7(FluentIconButton, { title: translateString(TranslatableString3.CopyButton), ...props, icon: "Copy" }); } function MoveDownButton(props) { const { registry: { translateString } } = props; return /* @__PURE__ */ jsx7(FluentIconButton, { title: translateString(TranslatableString3.MoveDownButton), ...props, icon: "Down" }); } function MoveUpButton(props) { const { registry: { translateString } } = props; return /* @__PURE__ */ jsx7(FluentIconButton, { title: translateString(TranslatableString3.MoveUpButton), ...props, icon: "Up" }); } function RemoveButton(props) { const { registry: { translateString } } = props; return /* @__PURE__ */ jsx7(FluentIconButton, { title: translateString(TranslatableString3.RemoveButton), ...props, icon: "Delete" }); } // src/FieldErrorTemplate/FieldErrorTemplate.tsx import { errorId } from "@rjsf/utils"; import { List } from "@fluentui/react"; import { jsx as jsx8 } from "react/jsx-runtime"; function FieldErrorTemplate(props) { const { errors = [], idSchema } = props; if (errors.length === 0) { return null; } const id = errorId(idSchema); return /* @__PURE__ */ jsx8(List, { id, items: errors }); } // src/FieldHelpTemplate/FieldHelpTemplate.tsx import { helpId } from "@rjsf/utils"; import { Text as Text2 } from "@fluentui/react"; import { jsx as jsx9 } from "react/jsx-runtime"; function FieldHelpTemplate(props) { const { idSchema, help } = props; if (!help) { return null; } const id = helpId(idSchema); return /* @__PURE__ */ jsx9(Text2, { id, children: help }); } // src/FieldTemplate/FieldTemplate.tsx import { getTemplate as getTemplate2, getUiOptions as getUiOptions2 } from "@rjsf/utils"; import { Text as Text3 } from "@fluentui/react"; import { jsx as jsx10, jsxs as jsxs4 } from "react/jsx-runtime"; function FieldTemplate(props) { const { children, errors, help, displayLabel, description, rawDescription, hidden, uiSchema, registry } = props; const uiOptions = getUiOptions2(uiSchema); const WrapIfAdditionalTemplate2 = getTemplate2( "WrapIfAdditionalTemplate", registry, uiOptions ); if (hidden) { return /* @__PURE__ */ jsx10("div", { style: { display: "none" }, children }); } return /* @__PURE__ */ jsxs4(WrapIfAdditionalTemplate2, { ...props, children: [ children, displayLabel && rawDescription && /* @__PURE__ */ jsx10(Text3, { children: description }), errors, help ] }); } // src/ObjectFieldTemplate/ObjectFieldTemplate.tsx import { canExpand, descriptionId, getTemplate as getTemplate3, getUiOptions as getUiOptions3, titleId } from "@rjsf/utils"; import { Fragment as Fragment4, jsx as jsx11, jsxs as jsxs5 } from "react/jsx-runtime"; var rightJustify2 = { float: "right" }; function ObjectFieldTemplate({ description, title, properties, required, disabled, readonly, schema, uiSchema, idSchema, formData, onAddClick, registry }) { const uiOptions = getUiOptions3(uiSchema); const TitleFieldTemplate = getTemplate3("TitleFieldTemplate", registry, uiOptions); const DescriptionFieldTemplate = getTemplate3( "DescriptionFieldTemplate", registry, uiOptions ); const { ButtonTemplates: { AddButton: AddButton2 } } = registry.templates; return /* @__PURE__ */ jsxs5(Fragment4, { children: [ title && /* @__PURE__ */ jsx11( TitleFieldTemplate, { id: titleId(idSchema), title, required, schema, uiSchema, registry } ), description && /* @__PURE__ */ jsx11( DescriptionFieldTemplate, { id: descriptionId(idSchema), schema, uiSchema, description, registry } ), /* @__PURE__ */ jsxs5("div", { className: "ms-Grid", dir: "ltr", children: [ /* @__PURE__ */ jsx11("div", { className: "ms-Grid-row", children: properties.map((element) => element.content) }), canExpand(schema, uiSchema, formData) && /* @__PURE__ */ jsx11("span", { style: rightJustify2, children: /* @__PURE__ */ jsx11( AddButton2, { className: "object-property-expand", onClick: onAddClick(schema), disabled: disabled || readonly, uiSchema, registry } ) }) ] }) ] }); } // src/SubmitButton/SubmitButton.tsx import { getSubmitButtonOptions } from "@rjsf/utils"; import { PrimaryButton } from "@fluentui/react"; import { jsx as jsx12, jsxs as jsxs6 } from "react/jsx-runtime"; function SubmitButton({ uiSchema }) { const { submitText, norender, props: submitButtonProps } = getSubmitButtonOptions(uiSchema); if (norender) { return null; } return /* @__PURE__ */ jsxs6("div", { children: [ /* @__PURE__ */ jsx12("br", {}), /* @__PURE__ */ jsx12("div", { className: "ms-Grid-col ms-sm12", children: /* @__PURE__ */ jsx12(PrimaryButton, { text: submitText, type: "submit", ...submitButtonProps }) }) ] }); } // src/TitleField/TitleField.tsx import { Label } from "@fluentui/react"; import { jsx as jsx13 } from "react/jsx-runtime"; var styles = { root: [ { fontSize: 24, marginBottom: 20, paddingBottom: 0 } ] }; function TitleField({ id, title }) { return /* @__PURE__ */ jsx13(Label, { id, styles, children: title }); } // src/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.tsx import { TextField as TextField2 } from "@fluentui/react"; import { ADDITIONAL_PROPERTY_FLAG, TranslatableString as TranslatableString4 } from "@rjsf/utils"; import { jsx as jsx14, jsxs as jsxs7 } from "react/jsx-runtime"; function WrapIfAdditionalTemplate(props) { const { children, disabled, id, label, onDropPropertyClick, onKeyChange, readonly, registry, required, schema, style, uiSchema } = props; const { templates, translateString } = registry; let { classNames = "" } = props; classNames = "ms-Grid-col ms-sm12 " + classNames.replace("form-group", ""); const { RemoveButton: RemoveButton2 } = templates.ButtonTemplates; const keyLabel = translateString(TranslatableString4.KeyLabel, [label]); const additional = ADDITIONAL_PROPERTY_FLAG in schema; if (!additional) { return /* @__PURE__ */ jsx14("div", { className: classNames, style: { ...style, marginBottom: 15 }, children }); } const handleBlur = ({ target }) => onKeyChange(target.value); return /* @__PURE__ */ jsx14("div", { className: classNames, style: { ...style, marginBottom: 15 }, dir: "ltr", children: /* @__PURE__ */ jsxs7("div", { className: "ms-Grid-row", children: [ /* @__PURE__ */ jsx14("div", { className: "ms-Grid-col ms-sm4 ms-md4 ms-lg5", children: /* @__PURE__ */ jsx14( TextField2, { required, label: keyLabel, defaultValue: label, disabled: disabled || readonly, id: `${id}-key`, name: `${id}-key`, onBlur: !readonly ? handleBlur : void 0, type: "text" } ) }), /* @__PURE__ */ jsx14("div", { className: "ms-Grid-col ms-sm4 ms-md4 ms-lg5", children }), /* @__PURE__ */ jsx14("div", { className: "ms-Grid-col ms-sm4 ms-md4 ms-lg2", style: { textAlign: "right" }, children: /* @__PURE__ */ jsx14( RemoveButton2, { disabled: disabled || readonly, onClick: onDropPropertyClick(label), uiSchema, registry } ) }) ] }, `${id}-key`) }); } // src/Templates/Templates.ts function generateTemplates() { return { ArrayFieldItemTemplate, ArrayFieldTemplate, BaseInputTemplate, ButtonTemplates: { CopyButton, AddButton, MoveDownButton, MoveUpButton, RemoveButton, SubmitButton }, DescriptionFieldTemplate: DescriptionField, ErrorListTemplate: ErrorList, FieldErrorTemplate, FieldHelpTemplate, FieldTemplate, ObjectFieldTemplate, TitleFieldTemplate: TitleField, WrapIfAdditionalTemplate }; } var Templates_default = generateTemplates(); // src/CheckboxWidget/CheckboxWidget.tsx import { useCallback } from "react"; import { Checkbox } from "@fluentui/react"; import { ariaDescribedByIds as ariaDescribedByIds2, descriptionId as descriptionId2, getTemplate as getTemplate4, labelValue as labelValue2 } from "@rjsf/utils"; import _pick2 from "lodash/pick"; import { Fragment as Fragment5, jsx as jsx15, jsxs as jsxs8 } from "react/jsx-runtime"; var allowedProps2 = [ "ariaDescribedBy", "ariaLabel", "ariaPositionInSet", "ariaSetSize", "boxSide", "checked", "checkmarkIconProps", "className", "componentRef", "defaultChecked", "defaultIndeterminate", "disabled", "indeterminate", "inputProps", /* Backward compatibility with fluentui v7 */ "keytipProps", "label", "onChange", "onRenderLabel", "styles", "theme" ]; function CheckboxWidget(props) { const { id, value, // required, disabled, readonly, label, hideLabel, schema, autofocus, onChange, onBlur, onFocus, options, registry, uiSchema } = props; const DescriptionFieldTemplate = getTemplate4( "DescriptionFieldTemplate", registry, options ); const _onChange = useCallback( (_, checked) => { onChange(checked); }, [onChange] ); const _onBlur = ({ target }) => onBlur(id, target && target.value); const _onFocus = ({ target }) => onFocus(id, target && target.value); const uiProps = _pick2(options.props || {}, allowedProps2); const description = options.description ?? schema.description; return /* @__PURE__ */ jsxs8(Fragment5, { children: [ !hideLabel && !!description && /* @__PURE__ */ jsx15( DescriptionFieldTemplate, { id: descriptionId2(id), description, schema, uiSchema, registry } ), /* @__PURE__ */ jsx15( Checkbox, { id, name: id, label: labelValue2(label || void 0, hideLabel), disabled: disabled || readonly, inputProps: { autoFocus: autofocus, onBlur: _onBlur, onFocus: _onFocus }, checked: typeof value === "undefined" ? false : value, onChange: _onChange, ...uiProps, "aria-describedby": ariaDescribedByIds2(id), ...{ autoFocus: autofocus, onBlur: _onBlur, onFocus: _onFocus } } ) ] }); } // src/CheckboxesWidget/CheckboxesWidget.tsx import { Checkbox as Checkbox2 } from "@fluentui/react"; import { ariaDescribedByIds as ariaDescribedByIds3, enumOptionsDeselectValue, enumOptionsIsSelected, enumOptionsSelectValue, enumOptionsValueForIndex, labelValue as labelValue3, optionId } from "@rjsf/utils"; import _pick3 from "lodash/pick"; // src/FluentLabel/FluentLabel.tsx import { Label as Label2 } from "@fluentui/react"; import { jsx as jsx16, jsxs as jsxs9 } from "react/jsx-runtime"; var styles_red = { // TODO: get this color from theme. color: "rgb(164, 38, 44)", fontSize: 12, fontWeight: "normal", fontFamily: `"Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif` }; function FluentLabel({ label, required, id }) { return /* @__PURE__ */ jsxs9(Label2, { htmlFor: id, children: [ label, required && /* @__PURE__ */ jsx16("span", { style: styles_red, children: "\xA0*" }) ] }); } // src/CheckboxesWidget/CheckboxesWidget.tsx import { Fragment as Fragment6, jsx as jsx17, jsxs as jsxs10 } from "react/jsx-runtime"; function CheckboxesWidget({ label, hideLabel, id, disabled, options, value, autofocus, readonly, required, onChange, onBlur, onFocus, rawErrors = [] }) { const { enumOptions, enumDisabled, emptyValue } = options; const checkboxesValues = Array.isArray(value) ? value : [value]; const _onChange = (index) => (_ev, checked) => { if (checked) { onChange(enumOptionsSelectValue(index, checkboxesValues, enumOptions)); } else { onChange(enumOptionsDeselectValue(index, checkboxesValues, enumOptions)); } }; const _onBlur = ({ target }) => onBlur(id, enumOptionsValueForIndex(target && target.value, enumOptions, emptyValue)); const _onFocus = ({ target }) => onFocus(id, enumOptionsValueForIndex(target && target.value, enumOptions, emptyValue)); const uiProps = _pick3(options.props || {}, allowedProps2); return /* @__PURE__ */ jsxs10(Fragment6, { children: [ labelValue3(/* @__PURE__ */ jsx17(FluentLabel, { label: label || void 0, required }), hideLabel), Array.isArray(enumOptions) && enumOptions.map((option, index) => { const checked = enumOptionsIsSelected(option.value, checkboxesValues); const itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1; return /* @__PURE__ */ jsx17( Checkbox2, { id: optionId(id, index), name: id, checked, label: option.label, disabled: disabled || itemDisabled || readonly, inputProps: { autoFocus: autofocus && index === 0, onBlur: _onBlur, onFocus: _onFocus }, onChange: _onChange(index), ...uiProps, "aria-describedby": ariaDescribedByIds3(id), ...{ autoFocus: autofocus && index === 0, onBlur: _onBlur, onFocus: _onFocus } }, index ); }), /* @__PURE__ */ jsx17("span", { style: styles_red, children: (rawErrors || []).join("\n") }) ] }); } // src/ColorWidget/ColorWidget.tsx import { ColorPicker, getColorFromString } from "@fluentui/react"; import { ariaDescribedByIds as ariaDescribedByIds4, labelValue as labelValue4 } from "@rjsf/utils"; import _pick4 from "lodash/pick"; import { Fragment as Fragment7, jsx as jsx18, jsxs as jsxs11 } from "react/jsx-runtime"; var allowedProps3 = [ "componentRef", "color", "strings", "onChange", "alphaType", "alphaSliderHidden", "hexLabel", "redLabel", "greenLabel", "blueLabel", "alphaLabel", "className", "theme", "styles", "showPreview" ]; function ColorWidget({ id, options, value, required, label, hideLabel, onChange }) { const updateColor = (_ev, colorObj) => { onChange(colorObj.hex); }; const uiProps = { id, ..._pick4(options.props || {}, allowedProps3) }; return /* @__PURE__ */ jsxs11(Fragment7, { children: [ labelValue4(/* @__PURE__ */ jsx18(FluentLabel, { label: label || void 0, required, id }), hideLabel), /* @__PURE__ */ jsx18( ColorPicker, { color: getColorFromString(value), onChange: updateColor, alphaType: "alpha", showPreview: true, ...uiProps, "aria-describedby": ariaDescribedByIds4(id) } ) ] }); } // src/DateWidget/DateWidget.tsx import { ariaDescribedByIds as ariaDescribedByIds5, labelValue as labelValue5, pad, TranslatableString as TranslatableString5 } from "@rjsf/utils"; import { DatePicker, DayOfWeek, mergeStyleSets } from "@fluentui/react"; import _pick5 from "lodash/pick"; import { jsx as jsx19 } from "react/jsx-runtime"; var allowedProps4 = [ "componentRef", "styles", "theme", "calloutProps", "calendarProps", "textField", "calendarAs", "onSelectDate", "label", "isRequired", "disabled", "ariaLabel", "underlined", "pickerAriaLabel", "isMonthPickerVisible", "showMonthPickerAsOverlay", "allowTextInput", "disableAutoFocus", "placeholder", "today", "value", "formatDate", "parseDateFromString", "firstDayOfWeek", "strings", "highlightCurrentMonth", "highlightSelectedMonth", "showWeekNumbers", "firstWeekOfYear", "showGoToToday", "borderless", "className", "dateTimeFormatter", "minDate", "maxDate", "initialPickerDate", "allFocusable", "onAfterMenuDismiss", "showCloseButton", "tabIndex" ]; var controlClass = mergeStyleSets({ control: { margin: "0 0 15px 0" } }); var formatDate = (date) => { if (!date) { return ""; } const yyyy = pad(date.getFullYear(), 4); const MM = pad(date.getMonth() + 1, 2); const dd = pad(date.getDate(), 2); return `${yyyy}-${MM}-${dd}`; }; var parseDate = (dateStr) => { if (!dateStr) { return void 0; } const [year, month, day] = dateStr.split("-").map((e) => parseInt(e)); const dt = new Date(year, month - 1, day); return dt; }; function DateWidget({ id, required, label, hideLabel, value, onChange, onBlur, onFocus, options, placeholder, registry }) { const { translateString } = registry; const _onSelectDate = (date) => { if (date) { const formatted = formatDate(date); formatted && onChange(formatted); } }; const _onBlur = ({ target }) => onBlur(id, target && target.value); const _onFocus = ({ target }) => onFocus(id, target && target.value); const uiProps = _pick5(options.props || {}, allowedProps4); return /* @__PURE__ */ jsx19( DatePicker, { id, className: controlClass.control, firstDayOfWeek: DayOfWeek.Sunday, placeholder, ariaLabel: translateString(TranslatableString5.AriaDateLabel), isRequired: required, label: labelValue5(label, hideLabel), onSelectDate: _onSelectDate, onBlur: _onBlur, onFocus: _onFocus, value: parseDate(value), ...uiProps, "aria-describedby": ariaDescribedByIds5(id) } ); } // src/DateTimeWidget/DateTimeWidget.tsx import { getTemplate as getTemplate5, localToUTC, utcToLocal } from "@rjsf/utils"; import { jsx as jsx20 } from "react/jsx-runtime"; function DateTimeWidget(props) { const { registry } = props; const uiProps = props.options["props"] || {}; const options = { ...props.options, props: { type: "datetime-local", ...uiProps } }; const BaseInputTemplate2 = getTemplate5("BaseInputTemplate", registry, options); const value = utcToLocal(props.value); const onChange = (value2) => { props.onChange(localToUTC(value2)); }; return /* @__PURE__ */ jsx20(BaseInputTemplate2, { ...props, options, value, onChange }); } // src/RadioWidget/RadioWidget.tsx import { ChoiceGroup } from "@fluentui/react"; import { ariaDescribedByIds as ariaDescribedByIds6, enumOptionsIndexForValue, enumOptionsValueForIndex as enumOptionsValueForIndex2, labelValue as labelValue6, optionId as optionId2 } from "@rjsf/utils"; import _pick6 from "lodash/pick"; import { jsx as jsx21 } from "react/jsx-runtime"; var allowedProps5 = [ "componentRef", "options", "defaultSelectedKey", "selectedKey", "onChange", "label", /* Backward compatibility with fluentui v7 */ "onChanged", "theme", "styles", "ariaLabelledBy" ]; function RadioWidget({ id, options, value, required, label, hideLabel, onChange, onBlur, onFocus, disabled, readonly }) { const { enumOptions, enumDisabled, emptyValue } = options; function _onChange(_ev, option) { if (option) { onChange(enumOptionsValueForIndex2(option.key, enumOptions, emptyValue)); } } const _onBlur = ({ target }) => onBlur(id, enumOptionsValueForIndex2(target && target.value, enumOptions, emptyValue)); const _onFocus = ({ target }) => onFocus(id, enumOptionsValueForIndex2(target && target.value, enumOptions, emptyValue)); const newOptions = Array.isArray(enumOptions) ? enumOptions.map((option, index) => ({ key: String(index), name: id, id: optionId2(id, index), text: option.label, disabled: Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1, "aria-describedby": ariaDescribedByIds6(id) })) : []; const selectedIndex = enumOptionsIndexForValue(value, enumOptions); const uiProps = _pick6(options.props || {}, allowedProps5); return /* @__PURE__ */ jsx21( ChoiceGroup, { id, name: id, options: newOptions, disabled: disabled || readonly, onChange: _onChange, onFocus: _onFocus, onBlur: _onBlur, label: labelValue6(label, hideLabel || !label), required, selectedKey: selectedIndex, ...uiProps } ); } // src/RangeWidget/RangeWidget.tsx import { Slider } from "@fluentui/react"; import { ariaDescribedByIds as ariaDescribedByIds7, labelValue as labelValue7, rangeSpec } from "@rjsf/utils"; import _pick7 from "lodash/pick"; import { Fragment as Fragment8, jsx as jsx22, jsxs as jsxs12 } from "react/jsx-runtime"; var allowedProps6 = [ "componentRef", "styles?", "theme", "label", "defaultValue", "value", "min", "max", "step", "showValue", "onChange", "ariaLabel", "ariaValueText", "vertical", "disabled", "snapToStep", "className", "buttonProps", "valueFormat", "originFromZero" ]; function RangeWidget({ value, readonly, disabled, options, schema, onChange, required, label, hideLabel, id }) { const sliderProps = { value, label, id, ...rangeSpec(schema) }; const _onChange = (value2) => onChange(value2); const uiProps = { id, ..._pick7(options.props || {}, allowedProps6) }; return /* @__PURE__ */ jsxs12(Fragment8, { children: [ labelValue7(/* @__PURE__ */ jsx22(FluentLabel, { label: label || void 0, required, id }), hideLabel), /* @__PURE__ */ jsx22( Slider, { disabled: disabled || readonly, min: sliderProps.min, max: sliderProps.max, step: sliderProps.step, onChange: _onChange, snapToStep: true, ...uiProps, "aria-describedby": ariaDescribedByIds7(id) } ) ] }); } // src/SelectWidget/SelectWidget.tsx import { Dropdown } from "@fluentui/react"; import { ariaDescribedByIds as ariaDescribedByIds8, enumOptionsDeselectValue as enumOptionsDeselectValue2, enumOptionsIndexForValue as enumOptionsIndexForValue2, enumOptionsSelectValue as enumOptionsSelectValue2, enumOptionsValueForIndex as enumOptionsValueForIndex3, labelValue as labelValue8 } from "@rjsf/utils"; import _pick8 from "lodash/pick"; import { jsx as jsx23 } from "react/jsx-runtime"; var allowedProps7 = [ "placeHolder", "options", "onChange", "onChanged", "onRenderLabel", "onRenderPlaceholder", "onRenderPlaceHolder", "onRenderTitle", "onRenderCaretDown", "dropdownWidth", "responsiveMode", "defaultSelectedKeys", "selectedKeys", "multiselectDelimiter", "notifyOnReselect", "isDisabled", "keytipProps", "theme", "styles", // ISelectableDroppableTextProps "componentRef", "label", "ariaLabel", "id", "className", "defaultSelectedKey", "selectedKey", "multiSelect", "options", "onRenderContainer", "onRenderList", "onRenderItem", "onRenderOption", "onDismiss", "disabled", "required", "calloutProps", "panelProps", "errorMessage", "placeholder", "openOnKeyboardFocus" ]; function SelectWidget({ id, options, label, hideLabel, required, disabled, readonly, value, multiple, onChange, onBlur, onFocus }) { const { enumOptions, enumDisabled, emptyValue } = options; const _onChange = (_ev, item) => { if (!item) { return; } if (multiple) { const valueOrDefault = value || []; if (item.selected) { onChange(enumOptionsSelectValue2(item.key, valueOrDefault, enumOptions)); } else { onChange(enumOptionsDeselectValue2(item.key, valueOrDefault, enumOptions)); } } else { onChange(enumOptionsValueForIndex3(item.key, enumOptions, emptyValue)); } }; const _onBlur = (e) => onBlur(id, enumOptionsValueForIndex3(e.target.value, enumOptions, emptyValue)); const _onFocus = (e) => onFocus(id, enumOptionsValueForIndex3(e.target.value, enumOptions, emptyValue)); const newOptions = Array.isArray(enumOptions) ? enumOptions.map((option, index) => ({ key: String(index), text: option.label, disabled: Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1 })) : []; const uiProps = _pick8(options.props || {}, allowedProps7); const selectedIndexes = enumOptionsIndexForValue2(value, enumOptions, multiple); return /* @__PURE__ */ jsx23( Dropdown, { id, label: labelValue8(label, hideLabel), multiSelect: multiple, defaultSelectedKey: multiple ? void 0 : selectedIndexes, defaultSelectedKeys: multiple ? selectedIndexes : void 0, required, options: newOptions, disabled: disabled || readonly, onChange: _onChange, onBlur: _onBlur, onFocus: _onFocus, ...uiProps, "aria-describedby": ariaDescribedByIds8(id) } ); } // src/TextareaWidget/TextareaWidget.tsx import { getTemplate as getTemplate6, getUiOptions as getUiOptions4 } from "@rjsf/utils"; import { jsx as jsx24 } from "react/jsx-runtime"; function TextareaWidget(props) { const { uiSchema, registry } = props; const options = getUiOptions4(uiSchema); const BaseInputTemplate2 = getTemplate6("BaseInputTemplate", registry, options); return /* @__PURE__ */ jsx24(BaseInputTemplate2, { ...props, multiline: true }); } // src/UpDownWidget/UpDownWidget.tsx import { SpinButton } from "@fluentui/react"; import { ariaDescribedByIds as ariaDescribedByIds9, labelValue as labelValue9, rangeSpec as rangeSpec2, TranslatableString as TranslatableString6 } from "@rjsf/utils"; import _pick9 from "lodash/pick"; import { Fragment as Fragment9, jsx as jsx25, jsxs as jsxs13 } from "react/jsx-runtime"; var allowedProps8 = [ "ariaDescribedBy", "ariaLabel", "ariaPositionInSet", "ariaSetSize", "ariaValueNow", "ariaValueText", "className", "componentRef", "decrementButtonAriaLabel", "decrementButtonIcon", "defaultValue", "disabled", "downArrowButtonStyles", /* Backward compatibility with fluentui v7 */ "getClassNames", "iconButtonProps", "iconProps", "incrementButtonAriaLabel", "incrementButtonIcon", "inputProps", "keytipProps", "label", "labelPosition", "max", "min", "onBlur", "onDecrement", "onFocus", "onIncrement", "onValidate", "precision", "step", "styles", "theme", "title", "upArrowButtonStyles", "value" ]; function UpDownWidget({ id, required, readonly, disabled, label, hideLabel, value, onChange, onBlur, onFocus, options, schema, registry }) { const { translateString } = registry; const _onChange = (ev, newValue) => { if (newValue) { onChange(Number(newValue)); } else if ("value" in ev.target) { onChange(Number(ev.target.value)); } }; let { min, max, step } = rangeSpec2(schema); if (min === void 0) { min = -1 * Infinity; } if (max === void 0) { max = Infinity; } if (step === void 0) { step = 1; } const _onIncrement = (value2) => { if (Number(value2) + step <= max) { onChange(Number(value2) + step); } }; const _onDecrement = (value2) => { if (Number(value2) - step >= min) { onChange(Number(value2) - step); } }; const _onBlur = ({ target }) => onBlur(id, target && target.value); const _onFocus = ({ target }) => onFocus(id, target && target.value); const uiProps = _pick9(options.props || {}, allowedProps8); return /* @__PURE__ */ jsxs13(Fragment9, { children: [ labelValue9(/* @__PURE__ */ jsx25(FluentLabel, { label: label || void 0, required, id }), hideLabel), /* @__PURE__ */ jsx25( SpinButton, { id, min, max, step, incrementButtonAriaLabel: translateString(TranslatableString6.IncrementAriaLabel), decrementButtonAriaLabel: translateString(TranslatableString6.DecrementAriaLabel), disabled: disabled || readonly, value: value || value === 0 ? value : "", onBlur: _onBlur, onFocus: _onFocus, onChange: _onChange, onIncrement: _onIncrement, onDecrement: _onDecrement, ...uiProps, "aria-describedby": ariaDescribedByIds9(id) } ) ] }); } // src/Widgets/Widgets.ts function generateWidgets() { return { CheckboxWidget, CheckboxesWidget, ColorWidget, DateWidget, DateTimeWidget, RadioWidget, RangeWidget, SelectWidget, TextareaWidget, UpDownWidget }; } var Widgets_default = generateWidgets(); // src/Theme/Theme.ts function generateTheme() { return { templates: generateTemplates(), widgets: generateWidgets() }; } var Theme_default = generateTheme(); // src/FuiForm/FuiForm.ts function generateForm() { return withTheme(generateTheme()); } var FuiForm_default = generateForm(); // src/index.ts initializeIcons(); var src_default = FuiForm_default; export { FuiForm_default as Form, Templates_default as Templates, Theme_default as Theme, Widgets_default as Widgets, src_default as default, generateForm, generateTemplates, generateTheme, generateWidgets }; //# sourceMappingURL=fluent-ui.esm.js.map