@rjsf/chakra-ui 5.3.1 → 5.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import { withTheme } from '@rjsf/core';
2
2
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
3
- import { TranslatableString, getUiOptions, getTemplate, getInputProps, examplesId, ariaDescribedByIds, errorId, helpId, titleId, descriptionId, canExpand, getSubmitButtonOptions, ADDITIONAL_PROPERTY_FLAG, parseDateString, toDateString, pad, schemaRequiresTrueValue, enumOptionsIndexForValue, enumOptionsValueForIndex, enumOptionsIsSelected, optionId, rangeSpec } from '@rjsf/utils';
3
+ import { TranslatableString, getUiOptions, getTemplate, getInputProps, labelValue, examplesId, ariaDescribedByIds, errorId, helpId, titleId, descriptionId, canExpand, getSubmitButtonOptions, ADDITIONAL_PROPERTY_FLAG, parseDateString, toDateString, pad, schemaRequiresTrueValue, enumOptionsIndexForValue, enumOptionsValueForIndex, enumOptionsIsSelected, optionId, rangeSpec } from '@rjsf/utils';
4
4
  import { Button, HStack, Box, ButtonGroup, Grid, GridItem, shouldForwardProp, FormControl, FormLabel, Input, Text, Alert, AlertTitle, List, ListItem, ListIcon, IconButton, FormErrorMessage, FormHelperText, Heading, Divider, Checkbox, CheckboxGroup, Stack, RadioGroup, Radio, Slider, SliderTrack, SliderFilledTrack, SliderThumb, Textarea, NumberInput, NumberInputField, NumberInputStepper, NumberIncrementStepper, NumberDecrementStepper, ChakraProvider } from '@chakra-ui/react';
5
5
  import { AddIcon, WarningIcon, CopyIcon, ArrowDownIcon, ArrowUpIcon, DeleteIcon } from '@chakra-ui/icons';
6
6
  import { useMemo, memo, useState, useEffect } from 'react';
@@ -197,6 +197,7 @@ function BaseInputTemplate(props) {
197
197
  type = props.type,
198
198
  value = props.value,
199
199
  label = props.label,
200
+ hideLabel = props.hideLabel,
200
201
  schema = props.schema,
201
202
  uiSchema = props.uiSchema,
202
203
  onChange = props.onChange,
@@ -209,13 +210,11 @@ function BaseInputTemplate(props) {
209
210
  rawErrors = props.rawErrors,
210
211
  autofocus = props.autofocus,
211
212
  placeholder = props.placeholder,
212
- disabled = props.disabled,
213
- registry = props.registry;
213
+ disabled = props.disabled;
214
214
  var inputProps = getInputProps(schema, type, options);
215
215
  var chakraProps = getChakra({
216
216
  uiSchema: uiSchema
217
217
  });
218
- var schemaUtils = registry.schemaUtils;
219
218
  var _onChange = function _onChange(_ref) {
220
219
  var value = _ref.target.value;
221
220
  return onChange(value === '' ? options.emptyValue : value);
@@ -228,7 +227,6 @@ function BaseInputTemplate(props) {
228
227
  var value = _ref3.target.value;
229
228
  return onFocus(id, value);
230
229
  };
231
- var displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema) && (!!label || !!schema.title);
232
230
  return jsxs(FormControl, _extends({
233
231
  mb: 1
234
232
  }, chakraProps, {
@@ -236,11 +234,11 @@ function BaseInputTemplate(props) {
236
234
  isRequired: required,
237
235
  isReadOnly: readonly,
238
236
  isInvalid: rawErrors && rawErrors.length > 0,
239
- children: [displayLabel ? jsx(FormLabel, {
237
+ children: [labelValue(jsx(FormLabel, {
240
238
  htmlFor: id,
241
239
  id: id + "-label",
242
- children: label || schema.title
243
- }) : null, jsx(Input, _extends({
240
+ children: label
241
+ }), hideLabel || !label), jsx(Input, _extends({
244
242
  id: id,
245
243
  name: id,
246
244
  value: value || value === 0 ? value : '',
@@ -467,16 +465,16 @@ function ObjectFieldTemplate(props) {
467
465
  // Button templates are not overridden in the uiSchema
468
466
  var AddButton = registry.templates.ButtonTemplates.AddButton;
469
467
  return jsxs(Fragment, {
470
- children: [(uiOptions.title || title) && jsx(TitleFieldTemplate, {
468
+ children: [title && jsx(TitleFieldTemplate, {
471
469
  id: titleId(idSchema),
472
- title: uiOptions.title || title,
470
+ title: title,
473
471
  required: required,
474
472
  schema: schema,
475
473
  uiSchema: uiSchema,
476
474
  registry: registry
477
- }), (uiOptions.description || description) && jsx(DescriptionFieldTemplate, {
475
+ }), description && jsx(DescriptionFieldTemplate, {
478
476
  id: descriptionId(idSchema),
479
- description: uiOptions.description || description,
477
+ description: description,
480
478
  schema: schema,
481
479
  uiSchema: uiSchema,
482
480
  registry: registry
@@ -812,6 +810,9 @@ function CheckboxWidget(props) {
812
810
  onBlur = props.onBlur,
813
811
  onFocus = props.onFocus,
814
812
  label = props.label,
813
+ hideLabel = props.hideLabel,
814
+ registry = props.registry,
815
+ options = props.options,
815
816
  uiSchema = props.uiSchema,
816
817
  schema = props.schema;
817
818
  var chakraProps = getChakra({
@@ -821,6 +822,8 @@ function CheckboxWidget(props) {
821
822
  // the "required" attribute if the field value must be "true", due to the
822
823
  // "const" or "enum" keywords
823
824
  var required = schemaRequiresTrueValue(schema);
825
+ var DescriptionFieldTemplate = getTemplate('DescriptionFieldTemplate', registry, options);
826
+ var description = options.description || schema.description;
824
827
  var _onChange = function _onChange(_ref) {
825
828
  var checked = _ref.target.checked;
826
829
  return onChange(checked);
@@ -833,11 +836,17 @@ function CheckboxWidget(props) {
833
836
  var value = _ref3.target.value;
834
837
  return onFocus(id, value);
835
838
  };
836
- return jsx(FormControl, _extends({
839
+ return jsxs(FormControl, _extends({
837
840
  mb: 1
838
841
  }, chakraProps, {
839
842
  isRequired: required,
840
- children: jsx(Checkbox, {
843
+ children: [!hideLabel && !!description && jsx(DescriptionFieldTemplate, {
844
+ id: descriptionId(id),
845
+ description: description,
846
+ schema: schema,
847
+ uiSchema: uiSchema,
848
+ registry: registry
849
+ }), jsx(Checkbox, {
841
850
  id: id,
842
851
  name: id,
843
852
  isChecked: typeof value === 'undefined' ? false : value,
@@ -846,10 +855,10 @@ function CheckboxWidget(props) {
846
855
  onBlur: _onBlur,
847
856
  onFocus: _onFocus,
848
857
  "aria-describedby": ariaDescribedByIds(id),
849
- children: label && jsx(Text, {
858
+ children: labelValue(jsx(Text, {
850
859
  children: label
851
- })
852
- })
860
+ }), hideLabel || !label)
861
+ })]
853
862
  }));
854
863
  }
855
864
 
@@ -864,10 +873,10 @@ function CheckboxesWidget(props) {
864
873
  onFocus = props.onFocus,
865
874
  required = props.required,
866
875
  label = props.label,
876
+ hideLabel = props.hideLabel,
867
877
  uiSchema = props.uiSchema,
868
878
  _props$rawErrors = props.rawErrors,
869
- rawErrors = _props$rawErrors === void 0 ? [] : _props$rawErrors,
870
- schema = props.schema;
879
+ rawErrors = _props$rawErrors === void 0 ? [] : _props$rawErrors;
871
880
  var enumOptions = options.enumOptions,
872
881
  enumDisabled = options.enumDisabled,
873
882
  emptyValue = options.emptyValue;
@@ -892,11 +901,11 @@ function CheckboxesWidget(props) {
892
901
  isRequired: required,
893
902
  isReadOnly: readonly,
894
903
  isInvalid: rawErrors && rawErrors.length > 0,
895
- children: [jsx(FormLabel, {
904
+ children: [labelValue(jsx(FormLabel, {
896
905
  htmlFor: id,
897
906
  id: id + "-label",
898
- children: label || schema.title
899
- }), jsx(CheckboxGroup, {
907
+ children: label
908
+ }), hideLabel || !label), jsx(CheckboxGroup, {
900
909
  onChange: function onChange(option) {
901
910
  return _onChange(enumOptionsValueForIndex(option, enumOptions, emptyValue));
902
911
  },
@@ -926,14 +935,15 @@ function CheckboxesWidget(props) {
926
935
  }
927
936
 
928
937
  function RadioWidget(_ref) {
938
+ var _enumOptionsIndexForV;
929
939
  var id = _ref.id,
930
- schema = _ref.schema,
931
940
  options = _ref.options,
932
941
  value = _ref.value,
933
942
  required = _ref.required,
934
943
  disabled = _ref.disabled,
935
944
  readonly = _ref.readonly,
936
945
  label = _ref.label,
946
+ hideLabel = _ref.hideLabel,
937
947
  onChange = _ref.onChange,
938
948
  onBlur = _ref.onBlur,
939
949
  onFocus = _ref.onFocus,
@@ -956,18 +966,18 @@ function RadioWidget(_ref) {
956
966
  return onFocus(id, enumOptionsValueForIndex(value, enumOptions, emptyValue));
957
967
  };
958
968
  var row = options ? options.inline : false;
959
- var selectedIndex = enumOptionsIndexForValue(value, enumOptions);
969
+ var selectedIndex = (_enumOptionsIndexForV = enumOptionsIndexForValue(value, enumOptions)) != null ? _enumOptionsIndexForV : null;
960
970
  return jsxs(FormControl, _extends({
961
971
  mb: 1
962
972
  }, chakraProps, {
963
973
  isDisabled: disabled || readonly,
964
974
  isRequired: required,
965
975
  isReadOnly: readonly,
966
- children: [jsx(FormLabel, {
976
+ children: [labelValue(jsx(FormLabel, {
967
977
  htmlFor: id,
968
978
  id: id + "-label",
969
- children: label || schema.title
970
- }), jsx(RadioGroup, {
979
+ children: label
980
+ }), hideLabel || !label), jsx(RadioGroup, {
971
981
  onChange: _onChange,
972
982
  onBlur: _onBlur,
973
983
  onFocus: _onFocus,
@@ -1001,9 +1011,8 @@ function RangeWidget(_ref) {
1001
1011
  uiSchema = _ref.uiSchema,
1002
1012
  onChange = _ref.onChange,
1003
1013
  label = _ref.label,
1004
- id = _ref.id,
1005
- registry = _ref.registry;
1006
- var schemaUtils = registry.schemaUtils;
1014
+ hideLabel = _ref.hideLabel,
1015
+ id = _ref.id;
1007
1016
  var chakraProps = getChakra({
1008
1017
  uiSchema: uiSchema
1009
1018
  });
@@ -1012,7 +1021,6 @@ function RangeWidget(_ref) {
1012
1021
  label: label,
1013
1022
  id: id
1014
1023
  }, rangeSpec(schema));
1015
- var displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema) && (!!label || !!schema.title);
1016
1024
  var _onChange = function _onChange(value) {
1017
1025
  return onChange(value === undefined ? options.emptyValue : value);
1018
1026
  };
@@ -1027,10 +1035,10 @@ function RangeWidget(_ref) {
1027
1035
  return jsxs(FormControl, _extends({
1028
1036
  mb: 1
1029
1037
  }, chakraProps, {
1030
- children: [displayLabel ? jsx(FormLabel, {
1038
+ children: [labelValue(jsx(FormLabel, {
1031
1039
  htmlFor: id,
1032
- children: label || schema.title
1033
- }) : null, jsxs(Slider, _extends({}, sliderWidgetProps, {
1040
+ children: label
1041
+ }), hideLabel || !label), jsxs(Slider, _extends({}, sliderWidgetProps, {
1034
1042
  id: id,
1035
1043
  name: id,
1036
1044
  isDisabled: disabled || readonly,
@@ -1046,10 +1054,10 @@ function RangeWidget(_ref) {
1046
1054
  }
1047
1055
 
1048
1056
  function SelectWidget(props) {
1049
- var schema = props.schema,
1050
- id = props.id,
1057
+ var id = props.id,
1051
1058
  options = props.options,
1052
1059
  label = props.label,
1060
+ hideLabel = props.hideLabel,
1053
1061
  placeholder = props.placeholder,
1054
1062
  multiple = props.multiple,
1055
1063
  required = props.required,
@@ -1114,10 +1122,10 @@ function SelectWidget(props) {
1114
1122
  isRequired: required,
1115
1123
  isReadOnly: readonly,
1116
1124
  isInvalid: rawErrors && rawErrors.length > 0,
1117
- children: [(label || schema.title) && jsx(FormLabel, {
1125
+ children: [labelValue(jsx(FormLabel, {
1118
1126
  htmlFor: isMultiple ? undefined : id,
1119
- children: label || schema.title
1120
- }), jsx(Select, {
1127
+ children: label
1128
+ }), hideLabel || !label), jsx(Select, {
1121
1129
  inputId: id,
1122
1130
  name: id,
1123
1131
  isMulti: isMultiple,
@@ -1139,6 +1147,7 @@ function TextareaWidget(_ref) {
1139
1147
  placeholder = _ref.placeholder,
1140
1148
  value = _ref.value,
1141
1149
  label = _ref.label,
1150
+ hideLabel = _ref.hideLabel,
1142
1151
  disabled = _ref.disabled,
1143
1152
  autofocus = _ref.autofocus,
1144
1153
  readonly = _ref.readonly,
@@ -1146,16 +1155,12 @@ function TextareaWidget(_ref) {
1146
1155
  onFocus = _ref.onFocus,
1147
1156
  onChange = _ref.onChange,
1148
1157
  options = _ref.options,
1149
- schema = _ref.schema,
1150
1158
  uiSchema = _ref.uiSchema,
1151
1159
  required = _ref.required,
1152
- rawErrors = _ref.rawErrors,
1153
- registry = _ref.registry;
1160
+ rawErrors = _ref.rawErrors;
1154
1161
  var chakraProps = getChakra({
1155
1162
  uiSchema: uiSchema
1156
1163
  });
1157
- var schemaUtils = registry.schemaUtils;
1158
- var displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema) && (!!label || !!schema.title);
1159
1164
  var _onChange = function _onChange(_ref2) {
1160
1165
  var value = _ref2.target.value;
1161
1166
  return onChange(value === '' ? options.emptyValue : value);
@@ -1175,10 +1180,10 @@ function TextareaWidget(_ref) {
1175
1180
  isRequired: required,
1176
1181
  isReadOnly: readonly,
1177
1182
  isInvalid: rawErrors && rawErrors.length > 0,
1178
- children: [displayLabel ? jsx(FormLabel, {
1183
+ children: [labelValue(jsx(FormLabel, {
1179
1184
  htmlFor: id,
1180
- children: label || schema.title
1181
- }) : null, jsx(Textarea, {
1185
+ children: label
1186
+ }), hideLabel || !label), jsx(Textarea, {
1182
1187
  id: id,
1183
1188
  name: id,
1184
1189
  value: value != null ? value : '',
@@ -1194,20 +1199,17 @@ function TextareaWidget(_ref) {
1194
1199
 
1195
1200
  function UpDownWidget(props) {
1196
1201
  var id = props.id,
1197
- schema = props.schema,
1198
1202
  uiSchema = props.uiSchema,
1199
1203
  readonly = props.readonly,
1200
1204
  disabled = props.disabled,
1201
1205
  label = props.label,
1206
+ hideLabel = props.hideLabel,
1202
1207
  value = props.value,
1203
1208
  onChange = props.onChange,
1204
1209
  onBlur = props.onBlur,
1205
1210
  onFocus = props.onFocus,
1206
1211
  rawErrors = props.rawErrors,
1207
- required = props.required,
1208
- registry = props.registry;
1209
- var schemaUtils = registry.schemaUtils;
1210
- var displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema) && (!!label || !!schema.title);
1212
+ required = props.required;
1211
1213
  var chakraProps = getChakra({
1212
1214
  uiSchema: uiSchema
1213
1215
  });
@@ -1229,10 +1231,10 @@ function UpDownWidget(props) {
1229
1231
  isRequired: required,
1230
1232
  isReadOnly: readonly,
1231
1233
  isInvalid: rawErrors && rawErrors.length > 0,
1232
- children: [displayLabel ? jsx(FormLabel, {
1234
+ children: [labelValue(jsx(FormLabel, {
1233
1235
  htmlFor: id,
1234
- children: label || schema.title
1235
- }) : null, jsxs(NumberInput, {
1236
+ children: label
1237
+ }), hideLabel || !label), jsxs(NumberInput, {
1236
1238
  value: value != null ? value : '',
1237
1239
  onChange: _onChange,
1238
1240
  onBlur: _onBlur,