@rjsf/chakra-ui 6.1.2 → 6.2.4

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.
@@ -120,6 +120,7 @@ function ArrayFieldTemplate(props) {
120
120
  }
121
121
 
122
122
  // src/BaseInputTemplate/BaseInputTemplate.tsx
123
+ import { useCallback } from "react";
123
124
  import { Input } from "@chakra-ui/react";
124
125
  import {
125
126
  ariaDescribedByIds,
@@ -181,12 +182,22 @@ function BaseInputTemplate(props) {
181
182
  autofocus,
182
183
  placeholder,
183
184
  disabled,
184
- uiSchema
185
+ uiSchema,
186
+ registry
185
187
  } = props;
186
188
  const inputProps = getInputProps(schema, type, options);
189
+ const { ClearButton: ClearButton2 } = registry.templates.ButtonTemplates;
187
190
  const _onChange = ({ target: { value: value2 } }) => onChange(value2 === "" ? options.emptyValue : value2);
188
191
  const _onBlur = ({ target }) => onBlur(id, target && target.value);
189
192
  const _onFocus = ({ target }) => onFocus(id, target && target.value);
193
+ const onClear = useCallback(
194
+ (e) => {
195
+ e.preventDefault();
196
+ e.stopPropagation();
197
+ onChange(options.emptyValue ?? "");
198
+ },
199
+ [onChange, options.emptyValue]
200
+ );
190
201
  const chakraProps = getChakra({ uiSchema });
191
202
  return /* @__PURE__ */ jsxs5(
192
203
  Field,
@@ -215,6 +226,7 @@ function BaseInputTemplate(props) {
215
226
  "aria-describedby": ariaDescribedByIds(id, !!schema.examples)
216
227
  }
217
228
  ),
229
+ options.allowClearTextInputs && !readonly && !disabled && value && /* @__PURE__ */ jsx5(ClearButton2, { registry, onClick: onClear }),
218
230
  Array.isArray(schema.examples) ? /* @__PURE__ */ jsx5("datalist", { id: examplesId(id), children: schema.examples.concat(schema.default && !schema.examples.includes(schema.default) ? [schema.default] : []).map((example) => {
219
231
  return /* @__PURE__ */ jsx5("option", { value: example }, example);
220
232
  }) }) : null
@@ -289,7 +301,7 @@ var ChakraIconButton_default = memo(ChakraIconButton2);
289
301
 
290
302
  // src/IconButton/IconButton.tsx
291
303
  import { TranslatableString as TranslatableString3 } from "@rjsf/utils";
292
- import { ArrowUpIcon, ArrowDownIcon, CopyIcon, DeleteIcon } from "lucide-react";
304
+ import { ArrowUpIcon, ArrowDownIcon, CopyIcon, DeleteIcon, X } from "lucide-react";
293
305
  import { jsx as jsx11 } from "react/jsx-runtime";
294
306
  function CopyButton(props) {
295
307
  const {
@@ -336,6 +348,12 @@ function RemoveButton(props) {
336
348
  }
337
349
  );
338
350
  }
351
+ function ClearButton(props) {
352
+ const {
353
+ registry: { translateString }
354
+ } = props;
355
+ return /* @__PURE__ */ jsx11(ChakraIconButton_default, { title: translateString(TranslatableString3.ClearButton), ...props, icon: /* @__PURE__ */ jsx11(X, {}) });
356
+ }
339
357
 
340
358
  // src/FieldErrorTemplate/FieldErrorTemplate.tsx
341
359
  import { errorId } from "@rjsf/utils";
@@ -692,7 +710,8 @@ function generateTemplates() {
692
710
  MoveDownButton,
693
711
  MoveUpButton,
694
712
  RemoveButton,
695
- SubmitButton
713
+ SubmitButton,
714
+ ClearButton
696
715
  },
697
716
  DescriptionFieldTemplate: DescriptionField,
698
717
  ErrorListTemplate: ErrorList,
@@ -709,6 +728,17 @@ function generateTemplates() {
709
728
  }
710
729
  var Templates_default = generateTemplates();
711
730
 
731
+ // src/AltDateTimeWidget/AltDateTimeWidget.tsx
732
+ import { jsx as jsx22 } from "react/jsx-runtime";
733
+ function AltDateTimeWidget({
734
+ time = true,
735
+ ...props
736
+ }) {
737
+ const { AltDateWidget: AltDateWidget2 } = props.registry.widgets;
738
+ return /* @__PURE__ */ jsx22(AltDateWidget2, { ...props, time });
739
+ }
740
+ var AltDateTimeWidget_default = AltDateTimeWidget;
741
+
712
742
  // src/AltDateWidget/AltDateWidget.tsx
713
743
  import { Box as Box6, Button as Button3, FieldsetRoot } from "@chakra-ui/react";
714
744
  import {
@@ -716,16 +746,27 @@ import {
716
746
  TranslatableString as TranslatableString5,
717
747
  useAltDateWidgetProps
718
748
  } from "@rjsf/utils";
719
- import { jsx as jsx22, jsxs as jsxs12 } from "react/jsx-runtime";
720
- function AltDateWidget(props) {
721
- const { autofocus, disabled, id, onBlur, onFocus, options, readonly, registry } = props;
749
+ import { jsx as jsx23, jsxs as jsxs12 } from "react/jsx-runtime";
750
+ function AltDateWidget({
751
+ autofocus = false,
752
+ disabled = false,
753
+ readonly = false,
754
+ time = false,
755
+ options,
756
+ ...props
757
+ }) {
758
+ const { id, onBlur, onFocus, registry } = props;
722
759
  const { translateString } = registry;
723
- const { elements, handleChange, handleClear, handleSetNow } = useAltDateWidgetProps(props);
760
+ const realOptions = { yearsRange: [1900, (/* @__PURE__ */ new Date()).getFullYear() + 2], ...options };
761
+ const { elements, handleChange, handleClear, handleSetNow } = useAltDateWidgetProps({
762
+ ...props,
763
+ options: realOptions
764
+ });
724
765
  const chakraProps = getChakra({ uiSchema: props.uiSchema });
725
766
  return /* @__PURE__ */ jsxs12(FieldsetRoot, { ...chakraProps, children: [
726
- /* @__PURE__ */ jsx22(Box6, { display: "flex", flexWrap: "wrap", alignItems: "center", children: elements.map((elemProps, i) => {
767
+ /* @__PURE__ */ jsx23(Box6, { display: "flex", flexWrap: "wrap", alignItems: "center", children: elements.map((elemProps, i) => {
727
768
  const elemId = `${id}_${elemProps.type}`;
728
- return /* @__PURE__ */ jsx22(Box6, { mr: "2", mb: "2", width: "20", children: /* @__PURE__ */ jsx22(
769
+ return /* @__PURE__ */ jsx23(Box6, { mr: "2", mb: "2", width: "20", children: /* @__PURE__ */ jsx23(
729
770
  DateElement,
730
771
  {
731
772
  ...props,
@@ -744,34 +785,13 @@ function AltDateWidget(props) {
744
785
  ) }, elemId);
745
786
  }) }),
746
787
  /* @__PURE__ */ jsxs12(Box6, { display: "flex", children: [
747
- !options.hideNowButton && /* @__PURE__ */ jsx22(Button3, { onClick: handleSetNow, mr: "2", children: translateString(TranslatableString5.NowLabel) }),
748
- !options.hideClearButton && /* @__PURE__ */ jsx22(Button3, { onClick: handleClear, children: translateString(TranslatableString5.ClearLabel) })
788
+ !options.hideNowButton && /* @__PURE__ */ jsx23(Button3, { onClick: handleSetNow, mr: "2", children: translateString(TranslatableString5.NowLabel) }),
789
+ !options.hideClearButton && /* @__PURE__ */ jsx23(Button3, { onClick: handleClear, children: translateString(TranslatableString5.ClearLabel) })
749
790
  ] })
750
791
  ] });
751
792
  }
752
- AltDateWidget.defaultProps = {
753
- autofocus: false,
754
- disabled: false,
755
- readonly: false,
756
- time: false,
757
- options: {
758
- yearsRange: [1900, (/* @__PURE__ */ new Date()).getFullYear() + 2]
759
- }
760
- };
761
793
  var AltDateWidget_default = AltDateWidget;
762
794
 
763
- // src/AltDateTimeWidget/AltDateTimeWidget.tsx
764
- import { jsx as jsx23 } from "react/jsx-runtime";
765
- function AltDateTimeWidget(props) {
766
- const { AltDateWidget: AltDateWidget2 } = props.registry.widgets;
767
- return /* @__PURE__ */ jsx23(AltDateWidget2, { ...props, time: true });
768
- }
769
- AltDateTimeWidget.defaultProps = {
770
- ...AltDateWidget_default.defaultProps,
771
- time: true
772
- };
773
- var AltDateTimeWidget_default = AltDateTimeWidget;
774
-
775
795
  // src/CheckboxWidget/CheckboxWidget.tsx
776
796
  import { Text as Text3 } from "@chakra-ui/react";
777
797
  import {