@rjsf/chakra-ui 6.0.1 → 6.1.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.
@@ -273,12 +273,11 @@
273
273
  });
274
274
  }
275
275
  function FieldHelpTemplate(props) {
276
- const { fieldPathId, help } = props;
276
+ const { fieldPathId, help, uiSchema, registry } = props;
277
277
  if (!help) {
278
278
  return null;
279
279
  }
280
- const id = utils.helpId(fieldPathId);
281
- return /* @__PURE__ */ jsxRuntime.jsx(react$1.Text, { id, children: help });
280
+ return /* @__PURE__ */ jsxRuntime.jsx(react$1.Text, { as: "sup", fontSize: "md", id: utils.helpId(fieldPathId), children: /* @__PURE__ */ jsxRuntime.jsx(core.RichHelp, { help, registry, uiSchema }) });
282
281
  }
283
282
  function FieldTemplate(props) {
284
283
  const {
@@ -321,6 +320,8 @@
321
320
  disabled,
322
321
  id,
323
322
  label,
323
+ displayLabel,
324
+ rawDescription,
324
325
  onKeyRename,
325
326
  onKeyRenameBlur,
326
327
  onRemoveProperty,
@@ -484,10 +485,12 @@
484
485
  classNames,
485
486
  style,
486
487
  disabled,
488
+ displayLabel,
487
489
  id,
488
490
  label,
489
491
  onRemoveProperty,
490
492
  onKeyRenameBlur,
493
+ rawDescription,
491
494
  readonly,
492
495
  registry,
493
496
  required,
@@ -496,37 +499,50 @@
496
499
  } = props;
497
500
  const { templates, translateString } = registry;
498
501
  const { RemoveButton: RemoveButton2 } = templates.ButtonTemplates;
499
- const keyLabel = translateString(utils.TranslatableString.KeyLabel, [label]);
502
+ const keyLabel = displayLabel ? translateString(utils.TranslatableString.KeyLabel, [label]) : void 0;
500
503
  const additional = utils.ADDITIONAL_PROPERTY_FLAG in schema;
504
+ const hasDescription = !!rawDescription;
505
+ const margin = hasDescription ? 58 : 22;
501
506
  if (!additional) {
502
507
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: classNames, style, children });
503
508
  }
504
- return /* @__PURE__ */ jsxRuntime.jsxs(react$1.Grid, { className: classNames, style, alignItems: "center", gap: 2, children: [
505
- /* @__PURE__ */ jsxRuntime.jsx(react$1.GridItem, { children: /* @__PURE__ */ jsxRuntime.jsx(Field, { required, label: keyLabel, children: /* @__PURE__ */ jsxRuntime.jsx(
506
- react$1.Input,
507
- {
508
- defaultValue: label,
509
- disabled: disabled || readonly,
510
- id: `${id}-key`,
511
- name: `${id}-key`,
512
- onBlur: !readonly ? onKeyRenameBlur : void 0,
513
- type: "text",
514
- mb: 1
515
- }
516
- ) }) }),
517
- /* @__PURE__ */ jsxRuntime.jsx(react$1.GridItem, { children }),
518
- /* @__PURE__ */ jsxRuntime.jsx(react$1.GridItem, { children: /* @__PURE__ */ jsxRuntime.jsx(
519
- RemoveButton2,
520
- {
521
- id: utils.buttonId(id, "remove"),
522
- className: "rjsf-object-property-remove",
523
- disabled: disabled || readonly,
524
- onClick: onRemoveProperty,
525
- uiSchema,
526
- registry
527
- }
528
- ) })
529
- ] }, `${id}-key`);
509
+ return /* @__PURE__ */ jsxRuntime.jsxs(
510
+ react$1.Grid,
511
+ {
512
+ templateColumns: "repeat(11, 1fr)",
513
+ className: classNames,
514
+ style,
515
+ alignItems: "center",
516
+ gap: 2,
517
+ children: [
518
+ /* @__PURE__ */ jsxRuntime.jsx(react$1.GridItem, { colSpan: 5, style: { marginTop: hasDescription ? "36px" : void 0 }, children: /* @__PURE__ */ jsxRuntime.jsx(Field, { required, label: keyLabel, children: /* @__PURE__ */ jsxRuntime.jsx(
519
+ react$1.Input,
520
+ {
521
+ defaultValue: label,
522
+ disabled: disabled || readonly,
523
+ id: `${id}-key`,
524
+ name: `${id}-key`,
525
+ onBlur: !readonly ? onKeyRenameBlur : void 0,
526
+ type: "text",
527
+ mb: 1
528
+ }
529
+ ) }) }),
530
+ /* @__PURE__ */ jsxRuntime.jsx(react$1.GridItem, { colSpan: 5, children }),
531
+ /* @__PURE__ */ jsxRuntime.jsx(react$1.GridItem, { justifySelf: "flex-end", style: { marginTop: displayLabel ? `${margin}px` : void 0 }, children: /* @__PURE__ */ jsxRuntime.jsx(
532
+ RemoveButton2,
533
+ {
534
+ id: utils.buttonId(id, "remove"),
535
+ className: "rjsf-object-property-remove",
536
+ disabled: disabled || readonly,
537
+ onClick: onRemoveProperty,
538
+ uiSchema,
539
+ registry
540
+ }
541
+ ) })
542
+ ]
543
+ },
544
+ `${id}-key`
545
+ );
530
546
  }
531
547
 
532
548
  // src/Templates/Templates.ts
@@ -639,7 +655,9 @@
639
655
  registry,
640
656
  options
641
657
  );
642
- const description = options.description || schema.description;
658
+ const uiOptions = utils.getUiOptions(uiSchema);
659
+ const isCheckbox = uiOptions.widget === "checkbox";
660
+ const description = isCheckbox ? void 0 : options.description ?? schema.description;
643
661
  const _onChange = ({ checked }) => onChange(checked);
644
662
  const _onBlur = ({ target }) => onBlur(id, target && target.checked);
645
663
  const _onFocus = ({ target }) => onFocus(id, target && target.checked);
@@ -684,8 +702,8 @@
684
702
  onFocus,
685
703
  required,
686
704
  label,
687
- hideLabel,
688
705
  rawErrors = [],
706
+ hideLabel,
689
707
  uiSchema
690
708
  } = props;
691
709
  const { enumOptions, enumDisabled, emptyValue } = options;
@@ -694,40 +712,42 @@
694
712
  const row = options ? options.inline : false;
695
713
  const selectedIndexes = utils.enumOptionsIndexForValue(value, enumOptions, true);
696
714
  const chakraProps = getChakra({ });
697
- return /* @__PURE__ */ jsxRuntime.jsx(
715
+ return /* @__PURE__ */ jsxRuntime.jsxs(
698
716
  react$1.FieldsetRoot,
699
717
  {
700
718
  mb: 1,
701
719
  disabled: disabled || readonly,
702
720
  invalid: rawErrors && rawErrors.length > 0,
703
721
  ...chakraProps,
704
- children: /* @__PURE__ */ jsxRuntime.jsx(
705
- react$1.CheckboxGroup,
706
- {
707
- onValueChange: (option) => onChange(utils.enumOptionsValueForIndex(option, enumOptions, emptyValue)),
708
- value: selectedIndexes,
709
- "aria-describedby": utils.ariaDescribedByIds(id),
710
- readOnly: readonly,
711
- required,
712
- label: utils.labelValue(label, hideLabel || !label),
713
- children: /* @__PURE__ */ jsxRuntime.jsx(react$1.Stack, { direction: row ? "row" : "column", children: Array.isArray(enumOptions) && enumOptions.map((option, index) => {
714
- const itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1;
715
- return /* @__PURE__ */ jsxRuntime.jsx(
716
- Checkbox,
717
- {
718
- id: utils.optionId(id, index),
719
- name: htmlName || id,
720
- value: String(index),
721
- disabled: disabled || itemDisabled || readonly,
722
- onBlur: _onBlur,
723
- onFocus: _onFocus,
724
- children: option.label && /* @__PURE__ */ jsxRuntime.jsx(react$1.Text, { children: option.label })
725
- },
726
- index
727
- );
728
- }) })
729
- }
730
- )
722
+ children: [
723
+ !hideLabel && label && /* @__PURE__ */ jsxRuntime.jsx(react$1.FieldsetLegend, { children: utils.labelValue(label) }),
724
+ /* @__PURE__ */ jsxRuntime.jsx(
725
+ react$1.CheckboxGroup,
726
+ {
727
+ onValueChange: (option) => onChange(utils.enumOptionsValueForIndex(option, enumOptions, emptyValue)),
728
+ value: selectedIndexes,
729
+ "aria-describedby": utils.ariaDescribedByIds(id),
730
+ readOnly: readonly,
731
+ required,
732
+ children: /* @__PURE__ */ jsxRuntime.jsx(react$1.Stack, { direction: row ? "row" : "column", children: Array.isArray(enumOptions) && enumOptions.map((option, index) => {
733
+ const itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1;
734
+ return /* @__PURE__ */ jsxRuntime.jsx(
735
+ Checkbox,
736
+ {
737
+ id: utils.optionId(id, index),
738
+ name: htmlName || id,
739
+ value: String(index),
740
+ disabled: disabled || itemDisabled || readonly,
741
+ onBlur: _onBlur,
742
+ onFocus: _onFocus,
743
+ children: option.label && /* @__PURE__ */ jsxRuntime.jsx(react$1.Text, { children: option.label })
744
+ },
745
+ index
746
+ );
747
+ }) })
748
+ }
749
+ )
750
+ ]
731
751
  }
732
752
  );
733
753
  }
package/dist/index.cjs CHANGED
@@ -45,7 +45,7 @@ __export(index_exports, {
45
45
  module.exports = __toCommonJS(index_exports);
46
46
 
47
47
  // src/Form/Form.tsx
48
- var import_core2 = require("@rjsf/core");
48
+ var import_core3 = require("@rjsf/core");
49
49
 
50
50
  // src/AddButton/AddButton.tsx
51
51
  var import_utils = require("@rjsf/utils");
@@ -389,14 +389,14 @@ function FieldErrorTemplate(props) {
389
389
  // src/FieldHelpTemplate/FieldHelpTemplate.tsx
390
390
  var import_react17 = require("@chakra-ui/react");
391
391
  var import_utils9 = require("@rjsf/utils");
392
+ var import_core2 = require("@rjsf/core");
392
393
  var import_jsx_runtime13 = require("react/jsx-runtime");
393
394
  function FieldHelpTemplate(props) {
394
- const { fieldPathId, help } = props;
395
+ const { fieldPathId, help, uiSchema, registry } = props;
395
396
  if (!help) {
396
397
  return null;
397
398
  }
398
- const id = (0, import_utils9.helpId)(fieldPathId);
399
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_react17.Text, { id, children: help });
399
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_react17.Text, { as: "sup", fontSize: "md", id: (0, import_utils9.helpId)(fieldPathId), children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_core2.RichHelp, { help, registry, uiSchema }) });
400
400
  }
401
401
 
402
402
  // src/FieldTemplate/FieldTemplate.tsx
@@ -444,6 +444,8 @@ function FieldTemplate(props) {
444
444
  disabled,
445
445
  id,
446
446
  label,
447
+ displayLabel,
448
+ rawDescription,
447
449
  onKeyRename,
448
450
  onKeyRenameBlur,
449
451
  onRemoveProperty,
@@ -638,10 +640,12 @@ function WrapIfAdditionalTemplate(props) {
638
640
  classNames,
639
641
  style,
640
642
  disabled,
643
+ displayLabel,
641
644
  id,
642
645
  label,
643
646
  onRemoveProperty,
644
647
  onKeyRenameBlur,
648
+ rawDescription,
645
649
  readonly,
646
650
  registry,
647
651
  required,
@@ -650,37 +654,50 @@ function WrapIfAdditionalTemplate(props) {
650
654
  } = props;
651
655
  const { templates, translateString } = registry;
652
656
  const { RemoveButton: RemoveButton2 } = templates.ButtonTemplates;
653
- const keyLabel = translateString(import_utils13.TranslatableString.KeyLabel, [label]);
657
+ const keyLabel = displayLabel ? translateString(import_utils13.TranslatableString.KeyLabel, [label]) : void 0;
654
658
  const additional = import_utils13.ADDITIONAL_PROPERTY_FLAG in schema;
659
+ const hasDescription = !!rawDescription;
660
+ const margin = hasDescription ? 58 : 22;
655
661
  if (!additional) {
656
662
  return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: classNames, style, children });
657
663
  }
658
- return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(import_react24.Grid, { className: classNames, style, alignItems: "center", gap: 2, children: [
659
- /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_react24.GridItem, { children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Field, { required, label: keyLabel, children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
660
- import_react24.Input,
661
- {
662
- defaultValue: label,
663
- disabled: disabled || readonly,
664
- id: `${id}-key`,
665
- name: `${id}-key`,
666
- onBlur: !readonly ? onKeyRenameBlur : void 0,
667
- type: "text",
668
- mb: 1
669
- }
670
- ) }) }),
671
- /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_react24.GridItem, { children }),
672
- /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_react24.GridItem, { children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
673
- RemoveButton2,
674
- {
675
- id: (0, import_utils13.buttonId)(id, "remove"),
676
- className: "rjsf-object-property-remove",
677
- disabled: disabled || readonly,
678
- onClick: onRemoveProperty,
679
- uiSchema,
680
- registry
681
- }
682
- ) })
683
- ] }, `${id}-key`);
664
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(
665
+ import_react24.Grid,
666
+ {
667
+ templateColumns: "repeat(11, 1fr)",
668
+ className: classNames,
669
+ style,
670
+ alignItems: "center",
671
+ gap: 2,
672
+ children: [
673
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_react24.GridItem, { colSpan: 5, style: { marginTop: hasDescription ? "36px" : void 0 }, children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Field, { required, label: keyLabel, children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
674
+ import_react24.Input,
675
+ {
676
+ defaultValue: label,
677
+ disabled: disabled || readonly,
678
+ id: `${id}-key`,
679
+ name: `${id}-key`,
680
+ onBlur: !readonly ? onKeyRenameBlur : void 0,
681
+ type: "text",
682
+ mb: 1
683
+ }
684
+ ) }) }),
685
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_react24.GridItem, { colSpan: 5, children }),
686
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_react24.GridItem, { justifySelf: "flex-end", style: { marginTop: displayLabel ? `${margin}px` : void 0 }, children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
687
+ RemoveButton2,
688
+ {
689
+ id: (0, import_utils13.buttonId)(id, "remove"),
690
+ className: "rjsf-object-property-remove",
691
+ disabled: disabled || readonly,
692
+ onClick: onRemoveProperty,
693
+ uiSchema,
694
+ registry
695
+ }
696
+ ) })
697
+ ]
698
+ },
699
+ `${id}-key`
700
+ );
684
701
  }
685
702
 
686
703
  // src/Templates/Templates.ts
@@ -813,7 +830,9 @@ function CheckboxWidget(props) {
813
830
  registry,
814
831
  options
815
832
  );
816
- const description = options.description || schema.description;
833
+ const uiOptions = (0, import_utils16.getUiOptions)(uiSchema);
834
+ const isCheckbox = uiOptions.widget === "checkbox";
835
+ const description = isCheckbox ? void 0 : options.description ?? schema.description;
817
836
  const _onChange = ({ checked }) => onChange(checked);
818
837
  const _onBlur = ({ target }) => onBlur(id, target && target.checked);
819
838
  const _onFocus = ({ target }) => onFocus(id, target && target.checked);
@@ -863,8 +882,8 @@ function CheckboxesWidget(props) {
863
882
  onFocus,
864
883
  required,
865
884
  label,
866
- hideLabel,
867
885
  rawErrors = [],
886
+ hideLabel,
868
887
  uiSchema
869
888
  } = props;
870
889
  const { enumOptions, enumDisabled, emptyValue } = options;
@@ -873,40 +892,42 @@ function CheckboxesWidget(props) {
873
892
  const row = options ? options.inline : false;
874
893
  const selectedIndexes = (0, import_utils18.enumOptionsIndexForValue)(value, enumOptions, true);
875
894
  const chakraProps = getChakra({ uiSchema });
876
- return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
895
+ return /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(
877
896
  import_react29.FieldsetRoot,
878
897
  {
879
898
  mb: 1,
880
899
  disabled: disabled || readonly,
881
900
  invalid: rawErrors && rawErrors.length > 0,
882
901
  ...chakraProps,
883
- children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
884
- import_react29.CheckboxGroup,
885
- {
886
- onValueChange: (option) => onChange((0, import_utils18.enumOptionsValueForIndex)(option, enumOptions, emptyValue)),
887
- value: selectedIndexes,
888
- "aria-describedby": (0, import_utils18.ariaDescribedByIds)(id),
889
- readOnly: readonly,
890
- required,
891
- label: (0, import_utils18.labelValue)(label, hideLabel || !label),
892
- children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(import_react29.Stack, { direction: row ? "row" : "column", children: Array.isArray(enumOptions) && enumOptions.map((option, index) => {
893
- const itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1;
894
- return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
895
- Checkbox,
896
- {
897
- id: (0, import_utils18.optionId)(id, index),
898
- name: htmlName || id,
899
- value: String(index),
900
- disabled: disabled || itemDisabled || readonly,
901
- onBlur: _onBlur,
902
- onFocus: _onFocus,
903
- children: option.label && /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(import_react29.Text, { children: option.label })
904
- },
905
- index
906
- );
907
- }) })
908
- }
909
- )
902
+ children: [
903
+ !hideLabel && label && /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(import_react29.FieldsetLegend, { children: (0, import_utils18.labelValue)(label) }),
904
+ /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
905
+ import_react29.CheckboxGroup,
906
+ {
907
+ onValueChange: (option) => onChange((0, import_utils18.enumOptionsValueForIndex)(option, enumOptions, emptyValue)),
908
+ value: selectedIndexes,
909
+ "aria-describedby": (0, import_utils18.ariaDescribedByIds)(id),
910
+ readOnly: readonly,
911
+ required,
912
+ children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(import_react29.Stack, { direction: row ? "row" : "column", children: Array.isArray(enumOptions) && enumOptions.map((option, index) => {
913
+ const itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1;
914
+ return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
915
+ Checkbox,
916
+ {
917
+ id: (0, import_utils18.optionId)(id, index),
918
+ name: htmlName || id,
919
+ value: String(index),
920
+ disabled: disabled || itemDisabled || readonly,
921
+ onBlur: _onBlur,
922
+ onFocus: _onFocus,
923
+ children: option.label && /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(import_react29.Text, { children: option.label })
924
+ },
925
+ index
926
+ );
927
+ }) })
928
+ }
929
+ )
930
+ ]
910
931
  }
911
932
  );
912
933
  }
@@ -1484,7 +1505,7 @@ var Theme_default = generateTheme();
1484
1505
 
1485
1506
  // src/Form/Form.tsx
1486
1507
  function generateForm() {
1487
- return (0, import_core2.withTheme)(generateTheme());
1508
+ return (0, import_core3.withTheme)(generateTheme());
1488
1509
  }
1489
1510
  var Form_default = generateForm();
1490
1511