-
Notifications
You must be signed in to change notification settings - Fork 0
Custom icons #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom icons #4
Conversation
|
Warning Rate limit exceeded@matheusrocha89 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 9 minutes and 49 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (3)
WalkthroughThe pull request introduces enhancements to the Changes
Sequence DiagramsequenceDiagram
participant User
participant Component
participant Parent
User->>Component: Click Edit Button
Component->>Component: Enter Edit Mode
Component->>Parent: Trigger onEditButtonClick
User->>Component: Modify Input
Component->>Parent: Trigger onInputChange
User->>Component: Click Save Button
Component->>Component: Exit Edit Mode
Component->>Parent: Trigger onSaveButtonClick
Possibly related PRs
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/InputClickEdit/InputClickEdit.test.tsx (1)
1-146: Add edge case tests for better coverage.The test suite is well-structured and comprehensive. Consider adding these edge cases:
- Test behavior when switching isEditing prop rapidly
- Test with invalid input types
- Test with undefined/null icon components
describe("Edge Cases", () => { it("should handle rapid isEditing changes", async () => { const { rerender } = render(<InputClickEdit value="Test" />); // Rapidly toggle isEditing rerender(<InputClickEdit value="Test" isEditing={true} />); rerender(<InputClickEdit value="Test" isEditing={false} />); rerender(<InputClickEdit value="Test" isEditing={true} />); expect(screen.getByRole("textbox")).toBeInTheDocument(); }); it("should handle invalid input types gracefully", () => { render(<InputClickEdit isEditing inputType="invalid" />); const input = screen.getByRole("textbox"); expect(input).toHaveAttribute("type", "text"); // Should fallback to text }); it("should handle undefined icon components", () => { render(<InputClickEdit showIcons editIcon={undefined} />); expect(screen.getByTestId("edit-icon")).toBeInTheDocument(); // Should use fallback }); });README.md (1)
11-13: Enhance prop descriptions for better clarity.While the documentation is comprehensive, consider enhancing these prop descriptions:
editIcon/saveIcon: Specify that they accept component types (not instances)inputType: List supported HTML input typesisEditing: Explain controlled vs. uncontrolled behavior| Prop | Type | Default | Description | | -------------------- | ----------------------- | -------------------- | ------------------------------------------- | -| inputType | string | "text" | HTML input type (text, number, email, etc.) | +| inputType | string | "text" | HTML input type. Supported types: text, number, email, password, tel, url, search | -| isEditing | boolean | false | Initial editing state | +| isEditing | boolean | false | Controls edit mode. When provided, component acts in controlled mode | -| editIcon | React.ElementType | () => `<LuPencil />` | Custom edit icon component | +| editIcon | React.ElementType | () => `<LuPencil />` | Custom edit icon component type (not instance). Example: FiEdit, not <FiEdit /> | -| saveIcon | React.ElementType | () => `<LuCheck />` | Custom save icon component | +| saveIcon | React.ElementType | () => `<LuCheck />` | Custom save icon component type (not instance). Example: FiSave, not <FiSave /> |Also applies to: 35-54
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
README.md(2 hunks)src/InputClickEdit/InputClickEdit.test.tsx(1 hunks)src/InputClickEdit/InputClickEdit.tsx(6 hunks)
🔇 Additional comments (5)
src/InputClickEdit/InputClickEdit.tsx (4)
1-1: LGTM! Type changes enhance component flexibility.The changes to prop types improve the component's API:
- Making
isEditingoptional provides better DX- Changing icon types to
React.ElementTypeis more appropriate for component propsAlso applies to: 10-10, 21-22
42-43: LGTM! Props cleanup improves code organization.Moving the default icon assignments to the component body makes the code more maintainable.
50-52: LGTM! Effect ensures proper state synchronization.The
useEffecthook correctly synchronizes the internal editing state with theisEditingprop, enabling controlled component behavior.
78-79: LGTM! Icon handling is well-implemented.The changes provide:
- Clear fallback icons
- Proper test attributes for reliable testing
Also applies to: 94-94, 98-98, 106-106, 110-110
README.md (1)
61-126: LGTM! Examples are clear and comprehensive.The examples effectively demonstrate various use cases and component configurations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/InputClickEdit/InputClickEdit.tsx (1)
52-54: Consider using controlled state pattern instead of prop-state synchronization.While the current implementation works, consider refactoring to a fully controlled pattern to avoid potential prop-state synchronization issues. This would involve:
- Using the
isEditingprop directly instead of internal state- Making
setEditingoptional and only calling it when provided-const [editing, setEditing] = useState<boolean>(isEditing); -useEffect(() => { - setEditing(isEditing); -}, [isEditing]); +const editing = isEditing; const onEditClick = () => { - setEditing(true); + onEditButtonClick?.(); }; const handleSave = () => { - setEditing(false); onSaveButtonClick?.(); };README.md (1)
62-137: Consider adding TypeScript types to examples.While the examples are comprehensive, consider adding TypeScript types to demonstrate type safety:
function ControlledExample() { - const [isEditing, setIsEditing] = useState(false); - const [value, setValue] = useState("Control me"); + const [isEditing, setIsEditing] = useState<boolean>(false); + const [value, setValue] = useState<string>("Control me");
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
README.md(2 hunks)src/InputClickEdit/InputClickEdit.tsx(6 hunks)
🔇 Additional comments (7)
src/InputClickEdit/InputClickEdit.tsx (4)
10-10: LGTM! Good type improvements.
- Making
isEditingoptional maintains backward compatibility- Using
React.ElementTypefor icons is more appropriate as it ensures type safety for component propsAlso applies to: 21-22
43-44: LGTM! Good refactoring of default values.Moving default icon assignments to the component body improves type inference and makes the code more maintainable.
80-81: LGTM! Clean icon handling implementation.The OR operator pattern for default icons is clean and type-safe.
96-96: LGTM! Good test coverage support.Added data-testid attributes will help with component testing.
Also applies to: 101-101, 109-109, 114-114
README.md (3)
11-13: LGTM! Clear feature documentation.New features are well documented and match the implementation.
35-55: LGTM! Comprehensive props documentation.Props table is well-organized, accurate, and provides clear descriptions for all props.
141-157: LGTM! Clear styling documentation.The styling section provides clear guidance with practical examples using CSS modules.
|
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #4 +/- ##
==========================================
+ Coverage 0.00% 58.27% +58.27%
==========================================
Files 5 5
Lines 123 139 +16
Branches 5 21 +16
==========================================
+ Hits 0 81 +81
+ Misses 118 54 -64
+ Partials 5 4 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
This PR adds the feature of the user to pass custom icons to the buttons
Summary by CodeRabbit
Release Notes for @nobrainers/react-click-edit
New Features
Improvements
Changes
isEditingprop to be optionalThese updates provide developers with more customization options and a more robust input editing component.