-
Notifications
You must be signed in to change notification settings - Fork 3
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
chore: button-migration #69
chore: button-migration #69
Conversation
WalkthroughThe changes update the button components and their styling across the project. In Changes
Possibly related PRs
Suggested reviewers
Poem
🪧 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/lib/button/KlerosSymbol.tsx (1)
10-12
: Consider simplifying variant logicThe current implementation works well, but you could make it more concise using a default value in the destructuring.
-const KlerosSymbol: React.FC<Pick<ButtonProps, "isDisabled" | "variant">> = ({ - isDisabled, - variant, -}) => { - const isPrimary = variant === "primary" || variant === undefined; - const isSecondary = variant === "secondary"; - const isTertiary = variant === "tertiary"; +const KlerosSymbol: React.FC<Pick<ButtonProps, "isDisabled" | "variant">> = ({ + isDisabled, + variant = "primary", +}) => { + const isPrimary = variant === "primary"; + const isSecondary = variant === "secondary"; + const isTertiary = variant === "tertiary";src/lib/button/ButtonIcon.tsx (1)
8-8
: Consider handling all variantsCurrently, you're only checking for the "secondary" variant. Consider also setting variables for "primary" and "tertiary" to make the code more consistent with KlerosSymbol.tsx.
const ButtonIcon: React.FC< Pick<ButtonProps, "Icon" | "icon" | "isDisabled" | "isLoading" | "variant"> > = ({ Icon, icon, isDisabled, isLoading, variant }) => { + const isPrimary = variant === "primary" || variant === undefined; const isSecondary = variant === "secondary"; + const isTertiary = variant === "tertiary";
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (12)
src/App.tsx
(1 hunks)src/examples/buttons.tsx
(1 hunks)src/lib/button/ButtonIcon.tsx
(1 hunks)src/lib/button/ButtonText.tsx
(1 hunks)src/lib/button/KlerosSymbol.tsx
(1 hunks)src/lib/button/base.tsx
(0 hunks)src/lib/button/index.tsx
(2 hunks)src/lib/button/primary.tsx
(0 hunks)src/lib/button/secondary.tsx
(0 hunks)src/lib/button/tertiary.tsx
(0 hunks)src/lib/dropdown/cascader/selector.tsx
(1 hunks)src/styles/global.css
(2 hunks)
💤 Files with no reviewable changes (4)
- src/lib/button/tertiary.tsx
- src/lib/button/secondary.tsx
- src/lib/button/primary.tsx
- src/lib/button/base.tsx
🔇 Additional comments (21)
src/lib/dropdown/cascader/selector.tsx (1)
36-36
: Consistent prop naming withisDisabled
Good change! Updating from
disabled
toisDisabled
improves the API consistency across components and follows React's common pattern of using the "is" prefix for boolean props.src/examples/buttons.tsx (2)
9-9
: Property renamed toisDisabled
Good update to use
isDisabled
instead ofdisabled
for consistency with the updated Button component API.
11-11
: Property renamed toisDisabled
Consistent update to use
isDisabled
instead ofdisabled
for the secondary button variant as well.src/App.tsx (1)
117-120
: Good migration to utility classesNice change from a styled component to using utility classes with
className="mt-16"
. This approach promotes consistency with the design system and makes the styling more maintainable.src/lib/button/ButtonText.tsx (1)
1-24
: Well-structured ButtonText component with proper state handlingThis new component is well-designed with:
- Clear separation of concerns by handling only text rendering
- Appropriate conditional styling based on button state (loading, disabled, variant)
- Proper use of the className utility for composing classes
- Good text styling with font weight, line height, and whitespace preservation
The implementation follows React best practices and will make the button structure more maintainable.
src/lib/button/KlerosSymbol.tsx (2)
6-9
: Good use of TypeScript's Pick utility typeUsing
Pick<ButtonProps, "isDisabled" | "variant">
is an excellent way to ensure type safety while limiting the props this component needs to handle.
14-23
: Well-structured conditional class namesThe use of the
cn
utility function for combining class names is clean and readable. The animation class "animate-breathing" suggests this component handles loading states visually.src/lib/button/ButtonIcon.tsx (2)
5-7
: Good component prop definitionThe component properly defines its props using TypeScript's Pick utility, ensuring it only receives the relevant props from ButtonProps.
10-23
:❓ Verification inconclusive
Verify the conditional rendering logic
The code uses the nullish coalescing operator (
??
) to conditionally render eithericon
orIcon
. This approach assumes thaticon
is not explicitly set to null or undefined when you want to useIcon
. Make sure this pattern works with your usage scenarios.
🏁 Script executed:
#!/bin/bash # Check for places where both icon and Icon are provided to Button components rg -p "Button.*icon.*Icon" --type=tsxLength of output: 67
Verify Conditional Rendering in ButtonIcon Component
- The code relies on the nullish coalescing operator (
??
) to determine whether to rendericon
or the fallback<Icon />
. This assumes that when you want to fallback to<Icon />
, theicon
prop is explicitlynull
orundefined
rather than any other falsy value.- Please ensure that in every usage scenario of the Button component,
icon
is either provided with a valid (non-null/undefined) value or omitted so that the fallback logic works as intended.- Note: The shell script originally used (
rg -p "Button.*icon.*Icon" --type=tsx
) returned an error due to an unrecognized file type. You might want to re-run your search using a glob pattern (e.g.,rg "Button.*icon.*Icon" -g "*.tsx"
) to verify that no other components inadvertently pass both props.src/styles/global.css (5)
36-36
: Good addition of base radius variableAdding
--klerosUIComponentsBaseRadius
as a CSS variable promotes consistency in UI components and makes it easier to update the border radius across the application.
158-158
: Good utilization of CSS variablesCreating a semantic alias
--radius-base
that references the technical variable--klerosUIComponentsBaseRadius
is a good practice. It creates an abstraction layer that makes the code more maintainable.
161-173
: Well-structured fadeIn animationThe fadeIn animation is properly defined with keyframes and a custom property for easy reuse. The transition through 50% opacity provides a smoother animation effect.
175-189
: Effective breathing animation for loading statesThe breathe animation provides a good visual cue for loading states. The scale transition from 1 to 1.3 and back creates a subtle pulsing effect.
190-190
: Good addition of easing function variableThe
--ease-ease
variable provides a reusable cubic-bezier curve, which ensures consistency in animations throughout the application.src/lib/button/index.tsx (7)
3-9
: Good component compositionImporting specialized sub-components (ButtonText, KlerosSymbol, ButtonIcon) promotes better separation of concerns and makes the codebase more maintainable.
11-15
: Good interface definition for base button propsThe BaseButtonProps interface clearly defines the common properties that all button variants share. Using optional properties with the
?
syntax is appropriate here.
17-25
: Good extension of AriaButtonPropsExtending AriaButtonProps ensures your buttons inherit all the accessibility features provided by react-aria-components. The use of Omit to avoid property conflicts is a good practice.
35-35
: Naming convention improvementChanging from
disabled
toisDisabled
follows the common React boolean prop naming convention, which improves code readability and consistency.
38-40
: Consistent variant handlingThe approach to determining the button variant matches the pattern used in the KlerosSymbol component, which is good for consistency.
42-66
: Good use of utility classes for stylingUsing the
cn
utility function with Tailwind CSS classes creates a clean, maintainable approach to styling that's easier to update than styled-components.
69-71
: Clean component compositionThe Button component is now cleanly composed of specialized sub-components, each receiving only the props they need. This approach improves maintainability and readability.
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: 1
🧹 Nitpick comments (3)
src/lib/button/index.tsx (3)
29-29
: Optional text property for icon-only buttons.
text
is mandatory, potentially disallowing icon-only usage. If an icon-only button variant is desired, consider makingtext?
optional.
38-48
: Destructure small for clarity.
You accessprops.small
within the body but destructureisDisabled
and others. Consistency improvements: explicitly destructuresmall
along with the other props to improve readability and avoid extraneous property passing to<AriaButton>
.Possible fix:
-function Button({ - text, - variant, - Icon, - icon, - onClick, - isLoading, - className, - isDisabled, - ...props -}: Readonly<ButtonProps>): React.ReactElement { - const isPrimary = variant === "primary" || variant === undefined; +function Button({ + text, + variant, + Icon, + icon, + onClick, + isLoading, + className, + isDisabled, + small, + ...props +}: Readonly<ButtonProps>): React.ReactElement { + const isPrimary = variant === "primary" || variant == null;
80-82
: Loading and icon combination logic.
The button showsKlerosSymbol
,ButtonIcon
, andButtonText
together while loading. If the design calls for disabling the icon or text while loading, consider conditional hiding for clarity of user feedback.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)
📒 Files selected for processing (1)
src/lib/button/index.tsx
(1 hunks)
🔇 Additional comments (3)
src/lib/button/index.tsx (3)
53-79
:❓ Verification inconclusive
Confirm Tailwind classes & theming approach.
The usage of"transition-[background]"
, custom durations & color tokens may depend on specialized Tailwind or PostCSS configuration. Ensure the classes are valid and consistent with the design system.
🏁 Script executed:
#!/bin/bash # Description: Search for the relevant tailwind.config.js or postcss config to confirm custom classes. fd "tailwind.config.js" --exec catLength of output: 34
Manual Verification of Tailwind/PostCSS Configuration
The automated search for a Tailwind configuration file (i.e.
tailwind.config.js
) did not return any files. This makes it unclear whether the custom Tailwind classes—such as"transition-[background]"
and the custom duration token"duration-(--klerosUIComponentsTransitionSpeed)"
—are defined or processed by a specialized PostCSS setup.• Next Steps:
- Please manually verify if your project includes a Tailwind configuration (e.g.
tailwind.config.js
ortailwind.config.ts
) or a PostCSS configuration (e.g.postcss.config.js
) that defines these custom classes and tokens.- Confirm that the classes are valid within your design system guidelines.
11-24
:❓ Verification inconclusive
Documentation vs. defaults mismatch.
While the doc comments declare default values (variant="primary"
,small=false
,isLoading=false
), there is no explicit assignment in the interface or the component. If consumers omit these props, the code logic must set them internally. Confirm that all defaults are honored at runtime.
🏁 Script executed:
#!/bin/bash # Description: Grep for usages of `Button` to ensure default props are handled or validated. rg -A 3 "Button\s*\("Length of output: 168
Attention: Verify Runtime Default Prop Handling for Button Component
The documented default values for
variant
("primary"
),small
(false
), andisLoading
(false
) aren’t clearly assigned in theButton
function. The grep output shows that the props are simply destructured (e.g.,function Button({ text, variant, Icon, … })
) with no default assignment at the parameter level. Please confirm that default values are properly applied via internal logic (or elsewhere) at runtime. If not, consider explicitly assigning default values (e.g., using destructuring defaults) to ensure consistency with the documentation.
- Location to review:
src/lib/button/index.tsx
(theButton
function parameters)- Action: Verify that the runtime assigns
variant: "primary"
,small: false
, andisLoading: false
when these props are omitted.
2-3
:❓ Verification inconclusive
Consider verifying the utility import path.
Please ensure"../../utils"
accurately points to thecn
function. Misconfigured or missing utilities often lead to runtime errors.
🏁 Script executed:
#!/bin/bash # Description: Validate that the `cn` function is indeed located in the resolved path. fd "utils" --exec rg -A 5 "export function cn"Length of output: 46
Below is a new shell script that digs deeper into the
src/utils
directory (which is what"../../utils"
resolves to fromsrc/lib/button/index.tsx
) to search for an export of thecn
function. This should help determine whether the import path is correct or if manual verification is needed:#!/bin/bash # Validate the presence of an export for the 'cn' function in the src/utils directory. echo "Listing all files in src/utils:" find src/utils -type f \( -name "*.ts" -o -name "*.tsx" -o -name "*.js" -o -name "*.jsx" \) echo -e "\nSearching for the export of 'cn'..." rg -n "export[[:space:]]+(function|const|let|var)[[:space:]]+cn" src/utilsAction Required:
- Run the above script to see if any file in
src/utils
exports thecn
function.- If the script still produces no output, please perform manual verification to confirm that
cn
is indeed available at the resolved path"../../utils"
(i.e. insrc/utils
).
|
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/lib/button/index.tsx (1)
51-77
: Well-structured dynamic class compositionThe use of the
cn
utility for class composition is excellent, creating a clean, maintainable approach to styling. The conditional classes based on button state provide consistent visual feedback.One minor optimization suggestion:
- {...{ variant, isLoading, isDisabled, ...props }} + {...props}Since
variant
,isLoading
, andisDisabled
are already destructured from props, no need to pass them again.src/lib/form/datepicker/dropdown.tsx (1)
88-88
: Updated event handler for compatibility with AriaButtonThe change from
onClick
toonPress
is appropriate and consistent with the migration toAriaButton
from React Aria Components.A minor syntax optimization:
- <Button small variant={"primary"} text={"Select"} onPress={onSelect} /> + <Button small variant="primary" text="Select" onPress={onSelect} />
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)
📒 Files selected for processing (4)
src/App.tsx
(1 hunks)src/lib/button/index.tsx
(1 hunks)src/lib/dropdown/cascader/selector.tsx
(1 hunks)src/lib/form/datepicker/dropdown.tsx
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- src/lib/dropdown/cascader/selector.tsx
- src/App.tsx
🔇 Additional comments (6)
src/lib/button/index.tsx (6)
2-9
: Great use of React Aria Components for enhanced accessibility!The migration to
AriaButton
from React Aria Components is an excellent choice for improving accessibility. The imports of the new button subcomponents (ButtonText
,KlerosSymbol
, andButtonIcon
) establish a clean composition pattern.
11-24
: Well-documented interface with appropriate defaultsThe
BaseButtonProps
interface is well structured with JSDoc comments providing clear descriptions and default values. The naming convention usingisLoading
instead ofloading
follows React's boolean prop naming convention for better readability.
26-28
: Unused property omission.
Omit<BaseButtonProps, "$loading">
is excluding a non-existent property$loading
. This might be a vestige of a previous implementation.Consider removing the
$loading
omission:-export interface ButtonProps - extends AriaButtonProps, - Omit<BaseButtonProps, "$loading"> { +export interface ButtonProps + extends AriaButtonProps, + BaseButtonProps {
30-35
: Improved props documentation and flexibilityGood addition of JSDoc comments for the icon props and the optional className for better styling flexibility.
37-50
: Clean component signature with proper TypeScript typingThe function signature uses
Readonly<ButtonProps>
for immutability and includes clear variant determination logic. Renamingdisabled
toisDisabled
is consistent with React boolean prop naming conventions.
78-81
: Excellent component composition patternUsing specialized sub-components (
KlerosSymbol
,ButtonIcon
,ButtonText
) creates a maintainable and clean button implementation. Passing the appropriate props to each component ensures consistent styling and behavior.
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.
lgtm
PR-Codex overview
This PR focuses on refactoring the
Button
component and its related files, updating event handlers, and improving accessibility. It also introduces new button variants and modifies styles for better usability.Detailed summary
base.tsx
,primary.tsx
,secondary.tsx
, andtertiary.tsx
.Button
component's event handler fromonClick
toonPress
.disabled
prop toisDisabled
in multiple components.ButtonIcon
,ButtonText
,KlerosSymbol
.global.css
for button animations.Button
component to useAriaButton
for accessibility.Summary by CodeRabbit
New Features
ButtonIcon
,ButtonText
, andKlerosSymbol
for enhanced functionality.Refactor
isDisabled
for uniform behavior across components.onClick
toonPress
for better alignment with interaction models.Style