@rjsf/fluent-ui
Version:
Fluent UI theme, fields and widgets for react-jsonschema-form
1,205 lines (1,195 loc) • 35.6 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@fluentui/react'), require('@rjsf/core'), require('react/jsx-runtime'), require('@rjsf/utils'), require('lodash/pick'), require('react')) :
typeof define === 'function' && define.amd ? define(['exports', '@fluentui/react', '@rjsf/core', 'react/jsx-runtime', '@rjsf/utils', 'lodash/pick', 'react'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@rjsf/fluent-ui"] = {}, global.react, global.core, global.jsxRuntime, global.utils, global._pick, global.react$1));
})(this, (function (exports, react, core, jsxRuntime, utils, _pick, react$1) { 'use strict';
// src/index.ts
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__ */ jsxRuntime.jsx("div", { className: "ms-Grid", dir: "ltr", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "ms-Grid-row", children: [
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "ms-Grid-col ms-sm6 ms-md8 ms-lg9", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "ms-Grid-row", children }) }),
hasToolbar && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "ms-Grid-col ms-sm6 ms-md4 ms-lg3", style: { textAlign: "right" }, children: [
(hasMoveUp || hasMoveDown) && /* @__PURE__ */ jsxRuntime.jsx(
MoveUpButton2,
{
disabled: disabled || readonly || !hasMoveUp,
onClick: onReorderClick(index, index - 1),
uiSchema,
registry
}
),
(hasMoveUp || hasMoveDown) && /* @__PURE__ */ jsxRuntime.jsx(
MoveDownButton2,
{
disabled: disabled || readonly || !hasMoveDown,
onClick: onReorderClick(index, index + 1),
uiSchema,
registry
}
),
hasCopy && /* @__PURE__ */ jsxRuntime.jsx(
CopyButton2,
{
disabled: disabled || readonly,
onClick: onCopyIndexClick(index),
uiSchema,
registry
}
),
hasRemove && /* @__PURE__ */ jsxRuntime.jsx(
RemoveButton2,
{
disabled: disabled || readonly,
onClick: onDropIndexClick(index),
uiSchema,
registry
}
)
] })
] }) });
}
var addIcon = { iconName: "Add" };
function AddButton(props) {
const {
registry: { translateString }
} = props;
return /* @__PURE__ */ jsxRuntime.jsx(
react.CommandBarButton,
{
style: { height: "32px" },
iconProps: addIcon,
text: translateString(utils.TranslatableString.AddItemButton),
className: props.className,
onClick: props.onClick,
disabled: props.disabled
}
);
}
var rightJustify = {
float: "right"
};
function ArrayFieldTemplate(props) {
const { canAdd, disabled, idSchema, uiSchema, items, onAddClick, readonly, registry, required, schema, title } = props;
const uiOptions = utils.getUiOptions(uiSchema);
const ArrayFieldDescriptionTemplate = utils.getTemplate(
"ArrayFieldDescriptionTemplate",
registry,
uiOptions
);
const ArrayFieldItemTemplate2 = utils.getTemplate(
"ArrayFieldItemTemplate",
registry,
uiOptions
);
const ArrayFieldTitleTemplate = utils.getTemplate(
"ArrayFieldTitleTemplate",
registry,
uiOptions
);
const {
ButtonTemplates: { AddButton: AddButton2 }
} = registry.templates;
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
/* @__PURE__ */ jsxRuntime.jsx(
ArrayFieldTitleTemplate,
{
idSchema,
title: uiOptions.title || title,
schema,
uiSchema,
required,
registry
}
),
/* @__PURE__ */ jsxRuntime.jsx(
ArrayFieldDescriptionTemplate,
{
idSchema,
description: uiOptions.description || schema.description,
schema,
uiSchema,
registry
}
),
items.length > 0 && items.map(({ key, ...itemProps }) => /* @__PURE__ */ jsxRuntime.jsx(ArrayFieldItemTemplate2, { ...itemProps }, key)),
canAdd && /* @__PURE__ */ jsxRuntime.jsx("span", { style: rightJustify, children: /* @__PURE__ */ jsxRuntime.jsx(
AddButton2,
{
className: "array-item-add",
onClick: onAddClick,
disabled: disabled || readonly,
uiSchema,
registry
}
) })
] });
}
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 = utils.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__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
/* @__PURE__ */ jsxRuntime.jsx(
react.TextField,
{
id,
name: id,
placeholder,
label: utils.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 ? utils.examplesId(id) : void 0,
...uiProps,
"aria-describedby": utils.ariaDescribedByIds(id, !!schema.examples)
}
),
Array.isArray(schema.examples) && /* @__PURE__ */ jsxRuntime.jsx("datalist", { id: utils.examplesId(id), children: schema.examples.concat(schema.default && !schema.examples.includes(schema.default) ? [schema.default] : []).map((example) => {
return /* @__PURE__ */ jsxRuntime.jsx("option", { value: example }, example);
}) })
] });
}
function DescriptionField({ description, id }) {
if (description) {
return /* @__PURE__ */ jsxRuntime.jsx(react.Text, { id, children: description });
}
return null;
}
function ErrorList({
errors,
registry
}) {
const { translateString } = registry;
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: errors.map((error, i) => {
return /* @__PURE__ */ jsxRuntime.jsx(
react.MessageBar,
{
messageBarType: react.MessageBarType.error,
isMultiline: false,
dismissButtonAriaLabel: translateString(utils.TranslatableString.CloseLabel),
children: error.stack
},
i
);
}) });
}
function FluentIconButton(props) {
const iconProps = {
iconName: props.icon
};
return /* @__PURE__ */ jsxRuntime.jsx(react.IconButton, { disabled: props.disabled, onClick: props.onClick, iconProps, color: "secondary" });
}
function CopyButton(props) {
const {
registry: { translateString }
} = props;
return /* @__PURE__ */ jsxRuntime.jsx(FluentIconButton, { title: translateString(utils.TranslatableString.CopyButton), ...props, icon: "Copy" });
}
function MoveDownButton(props) {
const {
registry: { translateString }
} = props;
return /* @__PURE__ */ jsxRuntime.jsx(FluentIconButton, { title: translateString(utils.TranslatableString.MoveDownButton), ...props, icon: "Down" });
}
function MoveUpButton(props) {
const {
registry: { translateString }
} = props;
return /* @__PURE__ */ jsxRuntime.jsx(FluentIconButton, { title: translateString(utils.TranslatableString.MoveUpButton), ...props, icon: "Up" });
}
function RemoveButton(props) {
const {
registry: { translateString }
} = props;
return /* @__PURE__ */ jsxRuntime.jsx(FluentIconButton, { title: translateString(utils.TranslatableString.RemoveButton), ...props, icon: "Delete" });
}
function FieldErrorTemplate(props) {
const { errors = [], idSchema } = props;
if (errors.length === 0) {
return null;
}
const id = utils.errorId(idSchema);
return /* @__PURE__ */ jsxRuntime.jsx(react.List, { id, items: errors });
}
function FieldHelpTemplate(props) {
const { idSchema, help } = props;
if (!help) {
return null;
}
const id = utils.helpId(idSchema);
return /* @__PURE__ */ jsxRuntime.jsx(react.Text, { id, children: help });
}
function FieldTemplate(props) {
const { children, errors, help, displayLabel, description, rawDescription, hidden, uiSchema, registry } = props;
const uiOptions = utils.getUiOptions(uiSchema);
const WrapIfAdditionalTemplate2 = utils.getTemplate(
"WrapIfAdditionalTemplate",
registry,
uiOptions
);
if (hidden) {
return /* @__PURE__ */ jsxRuntime.jsx("div", { style: { display: "none" }, children });
}
return /* @__PURE__ */ jsxRuntime.jsxs(WrapIfAdditionalTemplate2, { ...props, children: [
children,
displayLabel && rawDescription && /* @__PURE__ */ jsxRuntime.jsx(react.Text, { children: description }),
errors,
help
] });
}
var rightJustify2 = {
float: "right"
};
function ObjectFieldTemplate({
description,
title,
properties,
required,
disabled,
readonly,
schema,
uiSchema,
idSchema,
formData,
onAddClick,
registry
}) {
const uiOptions = utils.getUiOptions(uiSchema);
const TitleFieldTemplate = utils.getTemplate("TitleFieldTemplate", registry, uiOptions);
const DescriptionFieldTemplate = utils.getTemplate(
"DescriptionFieldTemplate",
registry,
uiOptions
);
const {
ButtonTemplates: { AddButton: AddButton2 }
} = registry.templates;
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
title && /* @__PURE__ */ jsxRuntime.jsx(
TitleFieldTemplate,
{
id: utils.titleId(idSchema),
title,
required,
schema,
uiSchema,
registry
}
),
description && /* @__PURE__ */ jsxRuntime.jsx(
DescriptionFieldTemplate,
{
id: utils.descriptionId(idSchema),
schema,
uiSchema,
description,
registry
}
),
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "ms-Grid", dir: "ltr", children: [
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "ms-Grid-row", children: properties.map((element) => element.content) }),
utils.canExpand(schema, uiSchema, formData) && /* @__PURE__ */ jsxRuntime.jsx("span", { style: rightJustify2, children: /* @__PURE__ */ jsxRuntime.jsx(
AddButton2,
{
className: "object-property-expand",
onClick: onAddClick(schema),
disabled: disabled || readonly,
uiSchema,
registry
}
) })
] })
] });
}
function SubmitButton({ uiSchema }) {
const { submitText, norender, props: submitButtonProps } = utils.getSubmitButtonOptions(uiSchema);
if (norender) {
return null;
}
return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
/* @__PURE__ */ jsxRuntime.jsx("br", {}),
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "ms-Grid-col ms-sm12", children: /* @__PURE__ */ jsxRuntime.jsx(react.PrimaryButton, { text: submitText, type: "submit", ...submitButtonProps }) })
] });
}
var styles = {
root: [
{
fontSize: 24,
marginBottom: 20,
paddingBottom: 0
}
]
};
function TitleField({
id,
title
}) {
return /* @__PURE__ */ jsxRuntime.jsx(react.Label, { id, styles, children: title });
}
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(utils.TranslatableString.KeyLabel, [label]);
const additional = utils.ADDITIONAL_PROPERTY_FLAG in schema;
if (!additional) {
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: classNames, style: { ...style, marginBottom: 15 }, children });
}
const handleBlur = ({ target }) => onKeyChange(target.value);
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: classNames, style: { ...style, marginBottom: 15 }, dir: "ltr", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "ms-Grid-row", children: [
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "ms-Grid-col ms-sm4 ms-md4 ms-lg5", children: /* @__PURE__ */ jsxRuntime.jsx(
react.TextField,
{
required,
label: keyLabel,
defaultValue: label,
disabled: disabled || readonly,
id: `${id}-key`,
name: `${id}-key`,
onBlur: !readonly ? handleBlur : void 0,
type: "text"
}
) }),
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "ms-Grid-col ms-sm4 ms-md4 ms-lg5", children }),
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "ms-Grid-col ms-sm4 ms-md4 ms-lg2", style: { textAlign: "right" }, children: /* @__PURE__ */ jsxRuntime.jsx(
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();
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 = utils.getTemplate(
"DescriptionFieldTemplate",
registry,
options
);
const _onChange = react$1.useCallback(
(_, checked) => {
onChange(checked);
},
[onChange]
);
const _onBlur = ({ target }) => onBlur(id, target && target.value);
const _onFocus = ({ target }) => onFocus(id, target && target.value);
const uiProps = _pick(options.props || {}, allowedProps2);
const description = options.description ?? schema.description;
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
!hideLabel && !!description && /* @__PURE__ */ jsxRuntime.jsx(
DescriptionFieldTemplate,
{
id: utils.descriptionId(id),
description,
schema,
uiSchema,
registry
}
),
/* @__PURE__ */ jsxRuntime.jsx(
react.Checkbox,
{
id,
name: id,
label: utils.labelValue(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": utils.ariaDescribedByIds(id),
...{
autoFocus: autofocus,
onBlur: _onBlur,
onFocus: _onFocus
}
}
)
] });
}
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__ */ jsxRuntime.jsxs(react.Label, { htmlFor: id, children: [
label,
required && /* @__PURE__ */ jsxRuntime.jsx("span", { style: styles_red, children: "\xA0*" })
] });
}
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(utils.enumOptionsSelectValue(index, checkboxesValues, enumOptions));
} else {
onChange(utils.enumOptionsDeselectValue(index, checkboxesValues, enumOptions));
}
};
const _onBlur = ({ target }) => onBlur(id, utils.enumOptionsValueForIndex(target && target.value, enumOptions, emptyValue));
const _onFocus = ({ target }) => onFocus(id, utils.enumOptionsValueForIndex(target && target.value, enumOptions, emptyValue));
const uiProps = _pick(options.props || {}, allowedProps2);
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
utils.labelValue(/* @__PURE__ */ jsxRuntime.jsx(FluentLabel, { label: label || void 0, required }), hideLabel),
Array.isArray(enumOptions) && enumOptions.map((option, index) => {
const checked = utils.enumOptionsIsSelected(option.value, checkboxesValues);
const itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1;
return /* @__PURE__ */ jsxRuntime.jsx(
react.Checkbox,
{
id: utils.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": utils.ariaDescribedByIds(id),
...{
autoFocus: autofocus && index === 0,
onBlur: _onBlur,
onFocus: _onFocus
}
},
index
);
}),
/* @__PURE__ */ jsxRuntime.jsx("span", { style: styles_red, children: (rawErrors || []).join("\n") })
] });
}
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, ..._pick(options.props || {}, allowedProps3) };
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
utils.labelValue(/* @__PURE__ */ jsxRuntime.jsx(FluentLabel, { label: label || void 0, required, id }), hideLabel),
/* @__PURE__ */ jsxRuntime.jsx(
react.ColorPicker,
{
color: react.getColorFromString(value),
onChange: updateColor,
alphaType: "alpha",
showPreview: true,
...uiProps,
"aria-describedby": utils.ariaDescribedByIds(id)
}
)
] });
}
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 = react.mergeStyleSets({
control: {
margin: "0 0 15px 0"
}
});
var formatDate = (date) => {
if (!date) {
return "";
}
const yyyy = utils.pad(date.getFullYear(), 4);
const MM = utils.pad(date.getMonth() + 1, 2);
const dd = utils.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 = _pick(options.props || {}, allowedProps4);
return /* @__PURE__ */ jsxRuntime.jsx(
react.DatePicker,
{
id,
className: controlClass.control,
firstDayOfWeek: react.DayOfWeek.Sunday,
placeholder,
ariaLabel: translateString(utils.TranslatableString.AriaDateLabel),
isRequired: required,
label: utils.labelValue(label, hideLabel),
onSelectDate: _onSelectDate,
onBlur: _onBlur,
onFocus: _onFocus,
value: parseDate(value),
...uiProps,
"aria-describedby": utils.ariaDescribedByIds(id)
}
);
}
function DateTimeWidget(props) {
const { registry } = props;
const uiProps = props.options["props"] || {};
const options = {
...props.options,
props: {
type: "datetime-local",
...uiProps
}
};
const BaseInputTemplate2 = utils.getTemplate("BaseInputTemplate", registry, options);
const value = utils.utcToLocal(props.value);
const onChange = (value2) => {
props.onChange(utils.localToUTC(value2));
};
return /* @__PURE__ */ jsxRuntime.jsx(BaseInputTemplate2, { ...props, options, value, onChange });
}
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(utils.enumOptionsValueForIndex(option.key, enumOptions, emptyValue));
}
}
const _onBlur = ({ target }) => onBlur(id, utils.enumOptionsValueForIndex(target && target.value, enumOptions, emptyValue));
const _onFocus = ({ target }) => onFocus(id, utils.enumOptionsValueForIndex(target && target.value, enumOptions, emptyValue));
const newOptions = Array.isArray(enumOptions) ? enumOptions.map((option, index) => ({
key: String(index),
name: id,
id: utils.optionId(id, index),
text: option.label,
disabled: Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1,
"aria-describedby": utils.ariaDescribedByIds(id)
})) : [];
const selectedIndex = utils.enumOptionsIndexForValue(value, enumOptions);
const uiProps = _pick(options.props || {}, allowedProps5);
return /* @__PURE__ */ jsxRuntime.jsx(
react.ChoiceGroup,
{
id,
name: id,
options: newOptions,
disabled: disabled || readonly,
onChange: _onChange,
onFocus: _onFocus,
onBlur: _onBlur,
label: utils.labelValue(label, hideLabel || !label),
required,
selectedKey: selectedIndex,
...uiProps
}
);
}
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, ...utils.rangeSpec(schema) };
const _onChange = (value2) => onChange(value2);
const uiProps = { id, ..._pick(options.props || {}, allowedProps6) };
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
utils.labelValue(/* @__PURE__ */ jsxRuntime.jsx(FluentLabel, { label: label || void 0, required, id }), hideLabel),
/* @__PURE__ */ jsxRuntime.jsx(
react.Slider,
{
disabled: disabled || readonly,
min: sliderProps.min,
max: sliderProps.max,
step: sliderProps.step,
onChange: _onChange,
snapToStep: true,
...uiProps,
"aria-describedby": utils.ariaDescribedByIds(id)
}
)
] });
}
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(utils.enumOptionsSelectValue(item.key, valueOrDefault, enumOptions));
} else {
onChange(utils.enumOptionsDeselectValue(item.key, valueOrDefault, enumOptions));
}
} else {
onChange(utils.enumOptionsValueForIndex(item.key, enumOptions, emptyValue));
}
};
const _onBlur = (e) => onBlur(id, utils.enumOptionsValueForIndex(e.target.value, enumOptions, emptyValue));
const _onFocus = (e) => onFocus(id, utils.enumOptionsValueForIndex(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 = _pick(options.props || {}, allowedProps7);
const selectedIndexes = utils.enumOptionsIndexForValue(value, enumOptions, multiple);
return /* @__PURE__ */ jsxRuntime.jsx(
react.Dropdown,
{
id,
label: utils.labelValue(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": utils.ariaDescribedByIds(id)
}
);
}
function TextareaWidget(props) {
const { uiSchema, registry } = props;
const options = utils.getUiOptions(uiSchema);
const BaseInputTemplate2 = utils.getTemplate("BaseInputTemplate", registry, options);
return /* @__PURE__ */ jsxRuntime.jsx(BaseInputTemplate2, { ...props, multiline: true });
}
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 } = utils.rangeSpec(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 = _pick(options.props || {}, allowedProps8);
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
utils.labelValue(/* @__PURE__ */ jsxRuntime.jsx(FluentLabel, { label: label || void 0, required, id }), hideLabel),
/* @__PURE__ */ jsxRuntime.jsx(
react.SpinButton,
{
id,
min,
max,
step,
incrementButtonAriaLabel: translateString(utils.TranslatableString.IncrementAriaLabel),
decrementButtonAriaLabel: translateString(utils.TranslatableString.DecrementAriaLabel),
disabled: disabled || readonly,
value: value || value === 0 ? value : "",
onBlur: _onBlur,
onFocus: _onFocus,
onChange: _onChange,
onIncrement: _onIncrement,
onDecrement: _onDecrement,
...uiProps,
"aria-describedby": utils.ariaDescribedByIds(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 core.withTheme(generateTheme());
}
var FuiForm_default = generateForm();
// src/index.ts
react.initializeIcons();
var src_default = FuiForm_default;
exports.Form = FuiForm_default;
exports.Templates = Templates_default;
exports.Theme = Theme_default;
exports.Widgets = Widgets_default;
exports.default = src_default;
exports.generateForm = generateForm;
exports.generateTemplates = generateTemplates;
exports.generateTheme = generateTheme;
exports.generateWidgets = generateWidgets;
Object.defineProperty(exports, '__esModule', { value: true });
}));