@rjsf/daisyui 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.
@@ -199,8 +199,10 @@
199
199
  schema,
200
200
  type,
201
201
  label,
202
- placeholder
202
+ placeholder,
203
+ registry
203
204
  } = props;
205
+ const { ClearButton: ClearButton2 } = registry.templates.ButtonTemplates;
204
206
  const inputProps = utils.getInputProps(schema, type, options);
205
207
  let className = "input input-bordered w-full";
206
208
  let isMulti = multiple;
@@ -222,29 +224,40 @@
222
224
  ({ target }) => onFocus && onFocus(id, target.value),
223
225
  [onFocus, id]
224
226
  );
227
+ const _onClear = react.useCallback(
228
+ (e) => {
229
+ e.preventDefault();
230
+ e.stopPropagation();
231
+ onChange(options.emptyValue ?? "");
232
+ },
233
+ [onChange, options.emptyValue]
234
+ );
225
235
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
226
236
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "form-control", children: [
227
237
  /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: id, className: "label hidden", style: { display: "none" }, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "label-text", children: label }) }),
228
- /* @__PURE__ */ jsxRuntime.jsx(
229
- "input",
230
- {
231
- id,
232
- name: htmlName || id,
233
- value: value || value === 0 ? value : "",
234
- placeholder,
235
- required,
236
- disabled: disabled || readonly,
237
- autoFocus: autofocus,
238
- className,
239
- multiple: isMulti,
240
- ...rest,
241
- ...htmlInputProps,
242
- onChange: onChangeOverride || _onChange,
243
- onBlur: _onBlur,
244
- onFocus: _onFocus,
245
- "aria-describedby": utils.ariaDescribedByIds(id, !!schema.examples)
246
- }
247
- )
238
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { position: "relative" }, children: [
239
+ /* @__PURE__ */ jsxRuntime.jsx(
240
+ "input",
241
+ {
242
+ id,
243
+ name: htmlName || id,
244
+ value: value || value === 0 ? value : "",
245
+ placeholder,
246
+ required,
247
+ disabled: disabled || readonly,
248
+ autoFocus: autofocus,
249
+ className,
250
+ multiple: isMulti,
251
+ ...rest,
252
+ ...htmlInputProps,
253
+ onChange: onChangeOverride || _onChange,
254
+ onBlur: _onBlur,
255
+ onFocus: _onFocus,
256
+ "aria-describedby": utils.ariaDescribedByIds(id, !!schema.examples)
257
+ }
258
+ ),
259
+ options.allowClearTextInputs && !readonly && !disabled && value && /* @__PURE__ */ jsxRuntime.jsx(ClearButton2, { registry, onClick: _onClear })
260
+ ] })
248
261
  ] }),
249
262
  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) => {
250
263
  return /* @__PURE__ */ jsxRuntime.jsx("option", { value: example }, example);
@@ -341,6 +354,20 @@
341
354
  }
342
355
  );
343
356
  }
357
+ function ClearButton(props) {
358
+ const {
359
+ registry: { translateString }
360
+ } = props;
361
+ return /* @__PURE__ */ jsxRuntime.jsx(
362
+ DaisyUIButton_default,
363
+ {
364
+ title: translateString(utils.TranslatableString.ClearButton),
365
+ ...props,
366
+ iconType: "default",
367
+ icon: freeSolidSvgIcons.faXmark
368
+ }
369
+ );
370
+ }
344
371
  function DescriptionField(props) {
345
372
  const { id, description, registry, uiSchema } = props;
346
373
  if (!description) {
@@ -389,6 +416,7 @@
389
416
  rawDescription,
390
417
  hidden,
391
418
  onChange,
419
+ fieldPathId,
392
420
  ...divProps
393
421
  } = props;
394
422
  const isCheckbox = schema.type === "boolean";
@@ -633,7 +661,8 @@
633
661
  CopyButton,
634
662
  MoveDownButton,
635
663
  MoveUpButton,
636
- RemoveButton
664
+ RemoveButton,
665
+ ClearButton
637
666
  },
638
667
  DescriptionFieldTemplate: DescriptionField,
639
668
  ErrorListTemplate: ErrorList,
package/dist/index.cjs CHANGED
@@ -248,8 +248,10 @@ function BaseInputTemplate(props) {
248
248
  schema,
249
249
  type,
250
250
  label,
251
- placeholder
251
+ placeholder,
252
+ registry
252
253
  } = props;
254
+ const { ClearButton: ClearButton2 } = registry.templates.ButtonTemplates;
253
255
  const inputProps = (0, import_utils4.getInputProps)(schema, type, options);
254
256
  let className = "input input-bordered w-full";
255
257
  let isMulti = multiple;
@@ -271,29 +273,40 @@ function BaseInputTemplate(props) {
271
273
  ({ target }) => onFocus && onFocus(id, target.value),
272
274
  [onFocus, id]
273
275
  );
276
+ const _onClear = (0, import_react2.useCallback)(
277
+ (e) => {
278
+ e.preventDefault();
279
+ e.stopPropagation();
280
+ onChange(options.emptyValue ?? "");
281
+ },
282
+ [onChange, options.emptyValue]
283
+ );
274
284
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
275
285
  /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "form-control", children: [
276
286
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("label", { htmlFor: id, className: "label hidden", style: { display: "none" }, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "label-text", children: label }) }),
277
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
278
- "input",
279
- {
280
- id,
281
- name: htmlName || id,
282
- value: value || value === 0 ? value : "",
283
- placeholder,
284
- required,
285
- disabled: disabled || readonly,
286
- autoFocus: autofocus,
287
- className,
288
- multiple: isMulti,
289
- ...rest,
290
- ...htmlInputProps,
291
- onChange: onChangeOverride || _onChange,
292
- onBlur: _onBlur,
293
- onFocus: _onFocus,
294
- "aria-describedby": (0, import_utils4.ariaDescribedByIds)(id, !!schema.examples)
295
- }
296
- )
287
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { position: "relative" }, children: [
288
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
289
+ "input",
290
+ {
291
+ id,
292
+ name: htmlName || id,
293
+ value: value || value === 0 ? value : "",
294
+ placeholder,
295
+ required,
296
+ disabled: disabled || readonly,
297
+ autoFocus: autofocus,
298
+ className,
299
+ multiple: isMulti,
300
+ ...rest,
301
+ ...htmlInputProps,
302
+ onChange: onChangeOverride || _onChange,
303
+ onBlur: _onBlur,
304
+ onFocus: _onFocus,
305
+ "aria-describedby": (0, import_utils4.ariaDescribedByIds)(id, !!schema.examples)
306
+ }
307
+ ),
308
+ options.allowClearTextInputs && !readonly && !disabled && value && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ClearButton2, { registry, onClick: _onClear })
309
+ ] })
297
310
  ] }),
298
311
  Array.isArray(schema.examples) && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("datalist", { id: (0, import_utils4.examplesId)(id), children: schema.examples.concat(schema.default && !schema.examples.includes(schema.default) ? [schema.default] : []).map((example) => {
299
312
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("option", { value: example }, example);
@@ -412,6 +425,20 @@ function RemoveButton(props) {
412
425
  }
413
426
  );
414
427
  }
428
+ function ClearButton(props) {
429
+ const {
430
+ registry: { translateString }
431
+ } = props;
432
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
433
+ DaisyUIButton_default,
434
+ {
435
+ title: translateString(import_utils7.TranslatableString.ClearButton),
436
+ ...props,
437
+ iconType: "default",
438
+ icon: import_free_solid_svg_icons2.faXmark
439
+ }
440
+ );
441
+ }
415
442
 
416
443
  // src/templates/DescriptionField/DescriptionField.tsx
417
444
  var import_core = require("@rjsf/core");
@@ -479,6 +506,7 @@ function FieldTemplate(props) {
479
506
  rawDescription,
480
507
  hidden,
481
508
  onChange,
509
+ fieldPathId,
482
510
  ...divProps
483
511
  } = props;
484
512
  const isCheckbox = schema.type === "boolean";
@@ -745,7 +773,8 @@ function generateTemplates() {
745
773
  CopyButton,
746
774
  MoveDownButton,
747
775
  MoveUpButton,
748
- RemoveButton
776
+ RemoveButton,
777
+ ClearButton
749
778
  },
750
779
  DescriptionFieldTemplate: DescriptionField,
751
780
  ErrorListTemplate: ErrorList,