@rjsf/shadcn 6.1.2 → 6.2.3

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rjsf/shadcn",
3
- "version": "6.1.2",
3
+ "version": "6.2.3",
4
4
  "main": "dist/index.js",
5
5
  "module": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -64,8 +64,8 @@
64
64
  ]
65
65
  },
66
66
  "peerDependencies": {
67
- "@rjsf/core": "^6.x",
68
- "@rjsf/utils": "^6.x",
67
+ "@rjsf/core": "^6.2.x",
68
+ "@rjsf/utils": "^6.2.x",
69
69
  "react": ">=18"
70
70
  },
71
71
  "engineStrict": false,
@@ -73,14 +73,14 @@
73
73
  "node": ">=20"
74
74
  },
75
75
  "devDependencies": {
76
- "@rjsf/core": "^6.x",
77
- "@rjsf/snapshot-tests": "^6.x",
78
- "@rjsf/utils": "^6.x",
79
- "@rjsf/validator-ajv8": "^6.x",
76
+ "@rjsf/core": "^6.2.0",
77
+ "@rjsf/snapshot-tests": "^6.2.0",
78
+ "@rjsf/utils": "^6.2.0",
79
+ "@rjsf/validator-ajv8": "^6.2.0",
80
80
  "@tailwindcss/cli": "^4.1.16",
81
81
  "eslint": "^8.57.1",
82
82
  "jsdom": "^27.0.1",
83
- "tailwindcss": "^4.1.12"
83
+ "tailwindcss": "^4.1.18"
84
84
  },
85
85
  "dependencies": {
86
86
  "@radix-ui/react-checkbox": "^1.3.3",
@@ -7,7 +7,7 @@ import {
7
7
  RJSFSchema,
8
8
  StrictRJSFSchema,
9
9
  } from '@rjsf/utils';
10
- import { ChangeEvent, FocusEvent } from 'react';
10
+ import { ChangeEvent, FocusEvent, MouseEvent, useCallback } from 'react';
11
11
 
12
12
  import { Input } from '../components/ui/input';
13
13
  import { cn } from '../lib/utils';
@@ -42,7 +42,9 @@ export default function BaseInputTemplate<
42
42
  children,
43
43
  extraProps,
44
44
  className,
45
+ registry,
45
46
  }: BaseInputTemplateProps<T, S, F>) {
47
+ const { ClearButton } = registry.templates.ButtonTemplates;
46
48
  const inputProps = {
47
49
  ...extraProps,
48
50
  ...getInputProps<T, S, F>(schema, type, options),
@@ -51,6 +53,14 @@ export default function BaseInputTemplate<
51
53
  onChange(value === '' ? options.emptyValue : value);
52
54
  const _onBlur = ({ target }: FocusEvent<HTMLInputElement>) => onBlur(id, target && target.value);
53
55
  const _onFocus = ({ target }: FocusEvent<HTMLInputElement>) => onFocus(id, target && target.value);
56
+ const _onClear = useCallback(
57
+ (e: MouseEvent) => {
58
+ e.preventDefault();
59
+ e.stopPropagation();
60
+ onChange(options.emptyValue ?? '');
61
+ },
62
+ [onChange, options.emptyValue],
63
+ );
54
64
 
55
65
  return (
56
66
  <div className='p-0.5'>
@@ -72,6 +82,9 @@ export default function BaseInputTemplate<
72
82
  onFocus={_onFocus}
73
83
  aria-describedby={ariaDescribedByIds(id, !!schema.examples)}
74
84
  />
85
+ {options.allowClearTextInputs && !readonly && !disabled && value && (
86
+ <ClearButton onClick={_onClear} registry={registry} />
87
+ )}
75
88
  {children}
76
89
  {Array.isArray(schema.examples) ? (
77
90
  <datalist id={examplesId(id)}>
@@ -1,5 +1,5 @@
1
1
  import { FormContextType, IconButtonProps, RJSFSchema, StrictRJSFSchema, TranslatableString } from '@rjsf/utils';
2
- import { ChevronDown, ChevronUp, Copy, Trash2 } from 'lucide-react';
2
+ import { ChevronDown, ChevronUp, Copy, Trash2, X } from 'lucide-react';
3
3
  import type { VariantProps } from 'class-variance-authority';
4
4
 
5
5
  import { Button, buttonVariants } from '../components/ui/button';
@@ -109,3 +109,12 @@ export function RemoveButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F
109
109
  />
110
110
  );
111
111
  }
112
+
113
+ export function ClearButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
114
+ props: ShadIconButtonProps<T, S, F>,
115
+ ) {
116
+ const {
117
+ registry: { translateString },
118
+ } = props;
119
+ return <IconButton title={translateString(TranslatableString.ClearButton)} {...props} icon={<X />} />;
120
+ }
@@ -9,7 +9,7 @@ import FieldErrorTemplate from '../FieldErrorTemplate';
9
9
  import FieldHelpTemplate from '../FieldHelpTemplate';
10
10
  import FieldTemplate from '../FieldTemplate';
11
11
  import GridTemplate from '../GridTemplate';
12
- import { CopyButton, MoveDownButton, MoveUpButton, RemoveButton } from '../IconButton';
12
+ import { CopyButton, MoveDownButton, MoveUpButton, RemoveButton, ClearButton } from '../IconButton';
13
13
  import MultiSchemaFieldTemplate from '../MultiSchemaFieldTemplate';
14
14
  import ObjectFieldTemplate from '../ObjectFieldTemplate';
15
15
  import OptionalDataControlsTemplate from '../OptionalDataControlsTemplate';
@@ -33,6 +33,7 @@ export function generateTemplates<
33
33
  MoveUpButton,
34
34
  RemoveButton,
35
35
  SubmitButton,
36
+ ClearButton,
36
37
  },
37
38
  DescriptionFieldTemplate: DescriptionField,
38
39
  ErrorListTemplate: ErrorList,
@@ -21,7 +21,7 @@ function Textarea({ className, ...props }: ComponentProps<'textarea'>) {
21
21
  <textarea
22
22
  data-slot='textarea'
23
23
  className={cn(
24
- 'border-input placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 flex field-sizing-content min-h-16 w-full rounded-md border bg-transparent px-3 py-2 text-base shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 md:text-sm',
24
+ 'border-input placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 flex min-h-16 w-full rounded-md border bg-transparent px-3 py-2 text-base shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 md:text-sm',
25
25
  className,
26
26
  )}
27
27
  {...props}