Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 32 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,27 @@ function App() {

## 🔧 Props

| Prop | Type | Default | Description |
| -------------------- | ----------------------- | -------------- | ------------------------------------ |
| value | string | "" | Text to display and edit |
| isEditing | boolean | false | Initial editing state |
| inputType | string | "text" | Type of input field |
| label | string | "" | Label for the input |
| className | string | "" | Container class name |
| inputClassName | string | "" | Input field class name |
| editButtonClassName | string | "" | Edit button class name |
| saveButtonClassName | string | "" | Save button class name |
| editWrapperClassName | string | "" | Edit mode wrapper class name |
| saveButtonLabel | React.ReactNode | "Save" | Custom save button label |
| editButtonLabel | React.ReactNode | "Edit" | Custom edit button label |
| showIcons | boolean | false | Show icons in buttons |
| editIcon | React.ReactNode | `<LuPencil />` | Custom edit icon |
| saveIcon | React.ReactNode | `<LuCheck />` | Custom save icon |
| iconPosition | "left" \| "right" | "left" | Position of icons in buttons |
| onEditButtonClick | () => void | () => {} | Callback when edit button is clicked |
| onInputChange | (value: string) => void | () => {} | Callback when input value changes |
| onSaveButtonClick | () => void | () => {} | Callback when save button is clicked |
| Prop | Type | Default | Description |
| -------------------- | ----------------------- | -------------- | ------------------------------------- |
| value | string | "" | Text to display and edit |
| isEditing | boolean | false | Initial editing state |
| inputType | string | "text" | Type of input field |
| label | string | "" | Label for the input |
| className | string | "" | Container class name |
| inputClassName | string | "" | Input field class name |
| editButtonClassName | string | "" | Edit button class name |
| saveButtonClassName | string | "" | Save button class name |
| editWrapperClassName | string | "" | Edit mode wrapper class name |
| saveButtonLabel | React.ReactNode | "Save" | Custom save button label |
| editButtonLabel | React.ReactNode | "Edit" | Custom edit button label |
| showIcons | boolean | false | Show icons in buttons |
| editIcon | React.ReactNode | `<LuPencil />` | Custom edit icon |
| saveIcon | React.ReactNode | `<LuCheck />` | Custom save icon |
| iconPosition | "left" \| "right" | "left" | Position of icons in buttons |
| onEditButtonClick | () => void | () => {} | Callback when edit button is clicked |
| onInputChange | (value: string) => void | () => {} | Callback when input value changes |
| onSaveButtonClick | () => void | () => {} | Callback when save button is clicked |
| iconsOnly | boolean | false | Show only icons without button labels |

## 💡 Examples

Expand Down Expand Up @@ -81,6 +82,17 @@ function App() {
/>
```

### Icons Only (No Text Labels)

```tsx
<InputClickEdit
value="Icons only buttons"
iconsOnly
editIcon={<span>✎</span>}
saveIcon={<span>✓</span>}
/>
```

## 📄 License

MIT
2 changes: 2 additions & 0 deletions playground/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ function App() {
<h1>Vite + React</h1>
<div className="card">
<InputClickEdit onInputChange={handleChange} value={value} showIcons />
<br />
<InputClickEdit onInputChange={handleChange} value={value} iconsOnly />
<p>
Edit <code>src/App.tsx</code> and save to test HMR
</p>
Expand Down
11 changes: 7 additions & 4 deletions src/InputClickEdit/InputClickEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type InputClickEditProps = {
editIcon?: React.ReactNode;
saveIcon?: React.ReactNode;
iconPosition?: "left" | "right";
iconsOnly?: boolean;
onEditButtonClick?: () => void;
onInputChange?: (value: string) => void;
onSaveButtonClick?: () => void;
Expand All @@ -41,6 +42,7 @@ const InputClickEdit = ({
showIcons = false,
saveIcon = <LuCheck />,
editIcon = <LuPencil />,
iconsOnly = false,
iconPosition = "left",
onEditButtonClick = () => {},
onInputChange = () => {},
Expand Down Expand Up @@ -71,6 +73,7 @@ const InputClickEdit = ({
[styles.button]: true,
[styles.buttonReverse]: iconPosition === "right",
};
const displayIcons = showIcons || iconsOnly;

return (
<div className={cn(styles.wrapper, className)}>
Expand All @@ -88,8 +91,8 @@ const InputClickEdit = ({
className={cn(buttonBaseClassName, saveButtonClassName)}
onClick={handleSave}
>
{showIcons && saveIcon}
{saveButtonLabel}
{displayIcons && saveIcon}
{!iconsOnly && saveButtonLabel}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add ARIA labels for icon-only buttons.

When iconsOnly is true, the buttons will lack text labels which could impact accessibility. Consider adding appropriate ARIA labels to maintain accessibility.

           <button
             className={cn(buttonBaseClassName, saveButtonClassName)}
             onClick={handleSave}
+            aria-label={iconsOnly ? saveButtonLabel?.toString() : undefined}
           >
             {displayIcons && saveIcon}
             {!iconsOnly && saveButtonLabel}
           </button>
           
           // ... and similarly for the edit button ...
           
           <button
             className={cn(buttonBaseClassName, editButtonClassName)}
             onClick={onEditClick}
+            aria-label={iconsOnly ? editButtonLabel?.toString() : undefined}
           >
             {displayIcons && editIcon}
             {!iconsOnly && editButtonLabel}
           </button>

Also applies to: 105-106

</button>
</div>
) : (
Expand All @@ -99,8 +102,8 @@ const InputClickEdit = ({
className={cn(buttonBaseClassName, editButtonClassName)}
onClick={onEditClick}
>
{showIcons && editIcon}
{editButtonLabel}
{displayIcons && editIcon}
{!iconsOnly && editButtonLabel}
</button>
</div>
)}
Expand Down