44
55https://github.com/user-attachments/assets/58c8cca5-878a-4e64-aa06-a8e202318f2a
66
7-
87> A lightweight, easy-to-use React component that makes any text editable with a click!
98
109## ✨ Features
@@ -39,33 +38,32 @@ import { InputClickEdit } from "@nobrainers/react-click-edit";
3938function App() {
4039 const [name, setName] = useState (" John Doe" );
4140
42- return <InputClickEdit value = { name } onInputChange = { setName } />;
41+ return <InputClickEdit value = { name } onChange = { setName } />;
4342}
4443```
4544
4645## 🔧 Props
4746
48- | Prop | Type | Default | Description |
49- | -------------------- | ----------------------- | -------- | ------------------------------------------- |
50- | value | string | "" | Text to display and edit |
51- | isEditing | boolean | false | Initial editing state |
52- | inputType | string | "text" | HTML input type (text, number, email, etc.) |
53- | label | string | "" | Label for the input field |
54- | className | string | "" | Container class name |
55- | inputClassName | string | "" | Input field class name |
56- | editButtonClassName | string | "" | Edit button class name |
57- | saveButtonClassName | string | "" | Save button class name |
58- | editWrapperClassName | string | "" | Edit mode wrapper class name |
59- | saveButtonLabel | React.ReactNode | "Save" | Custom save button label |
60- | editButtonLabel | React.ReactNode | "Edit" | Custom edit button label |
61- | showIcons | boolean | false | Toggle button icons visibility |
62- | iconsOnly | boolean | false | Show only icons without text labels |
63- | editIcon | React.ElementType | LuPencil | Custom edit icon component |
64- | saveIcon | React.ElementType | LuCheck | Custom save icon component |
65- | iconPosition | "left" \| "right" | "left" | Position of icons in buttons |
66- | onEditButtonClick | () => void | () => {} | Callback when edit button is clicked |
67- | onInputChange | (value: string) => void | () => {} | Callback when input value changes |
68- | onSaveButtonClick | () => void | () => {} | Callback when save button is clicked |
47+ | Prop | Type | Required | Default | Description |
48+ | ----------------- | -------------------------------------- | -------- | -------- | ----------------------------------------- |
49+ | value | string | Yes\* | - | Controlled text value to display and edit |
50+ | defaultValue | string | No | - | Initial uncontrolled value |
51+ | type | string | No | "text" | HTML input type attribute |
52+ | onChange | ` ChangeEventHandler<HTMLInputElement> ` | Yes\* | - | HTML input onChange handler |
53+ | isEditing | boolean | No | false | Control the editing state |
54+ | label | string | No | "" | Label for the input field |
55+ | className | string | No | "" | Container class name |
56+ | editButtonLabel | React.ReactNode | No | "Edit" | Custom edit button label |
57+ | saveButtonLabel | React.ReactNode | No | "Save" | Custom save button label |
58+ | showIcons | boolean | No | false | Toggle button icons visibility |
59+ | iconsOnly | boolean | No | false | Show only icons without text labels |
60+ | editIcon | React.ElementType | No | LuPencil | Custom edit icon component |
61+ | saveIcon | React.ElementType | No | LuCheck | Custom save icon component |
62+ | iconPosition | "left" \| "right" | No | "left" | Position of icons in buttons |
63+ | onEditButtonClick | () => void | No | () => {} | Callback when edit button is clicked |
64+ | onSaveButtonClick | () => void | No | () => {} | Callback when save button is clicked |
65+
66+ \* Either ` value ` + ` onChange ` (controlled) or ` defaultValue ` (uncontrolled) must be provided.
6967
7068## 💡 Examples
7169
@@ -74,7 +72,7 @@ function App() {
7472``` tsx
7573function BasicExample() {
7674 const [name, setName] = useState (" John Doe" );
77- return <InputClickEdit value = { name } onInputChange = { setName } />;
75+ return <InputClickEdit value = { name } onChange = { setName } />;
7876}
7977```
8078
@@ -83,9 +81,9 @@ function BasicExample() {
8381``` tsx
8482<InputClickEdit
8583 label = " Age"
86- inputType = " number"
84+ type = " number"
8785 value = " 25"
88- onInputChange = { (value ) => console .log (value )}
86+ onChange = { (value ) => console .log (value )}
8987/>
9088```
9189
@@ -133,7 +131,7 @@ function ControlledExample() {
133131 isEditing = { isEditing }
134132 onEditButtonClick = { () => setIsEditing (true )}
135133 onSaveButtonClick = { () => setIsEditing (false )}
136- onInputChange = { setValue }
134+ onChange = { setValue }
137135 />
138136 );
139137}
@@ -151,6 +149,51 @@ function ControlledExample() {
151149/>
152150```
153151
152+ ### React Hook Form Integration
153+
154+ ``` tsx
155+ import { useForm , Controller } from " react-hook-form" ;
156+ import { InputClickEdit } from " @nobrainers/react-click-edit" ;
157+
158+ function FormExample() {
159+ const { control, handleSubmit } = useForm ();
160+ const onSubmit = (data ) => console .log (data );
161+
162+ return (
163+ <form onSubmit = { handleSubmit (onSubmit )} >
164+ <Controller
165+ name = " editableText"
166+ control = { control }
167+ defaultValue = " Edit me"
168+ render = { ({ field }) => (
169+ <InputClickEdit { ... field } onChange = { field .onChange } />
170+ )}
171+ />
172+ <button type = " submit" >Submit</button >
173+ </form >
174+ );
175+ }
176+ ```
177+
178+ ### Register Example
179+
180+ ``` tsx
181+ import { useForm } from " react-hook-form" ;
182+ import { InputClickEdit } from " @nobrainers/react-click-edit" ;
183+
184+ function RegisterExample() {
185+ const { register, handleSubmit } = useForm ();
186+ const onSubmit = (data ) => console .log (data );
187+
188+ return (
189+ <form onSubmit = { handleSubmit (onSubmit )} >
190+ <InputClickEdit { ... register (" editableText" )} />
191+ <button type = " submit" >Submit</button >
192+ </form >
193+ );
194+ }
195+ ```
196+
154197## 🎨 Styling
155198
156199The component comes with minimal default styling through its base CSS file. You can override these styles or add additional styling using CSS classes. All main elements accept custom class names through props.
0 commit comments