-
-
Notifications
You must be signed in to change notification settings - Fork 32
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
Util classname 3 #632
Util classname 3 #632
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,6 +1,7 @@ | ||||||||||||||||||||||||||||
'use client'; | ||||||||||||||||||||||||||||
import React, { useState } from 'react'; | ||||||||||||||||||||||||||||
import { customClassSwitcher } from '~/core'; | ||||||||||||||||||||||||||||
import { clsx } from 'clsx'; | ||||||||||||||||||||||||||||
const COMPONENT_NAME = 'Switch'; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
export type SwitchProps = { | ||||||||||||||||||||||||||||
|
@@ -26,7 +27,7 @@ const Switch = ({ children, customRootClass = '', className = '', color = '', de | |||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||
return ( | ||||||||||||||||||||||||||||
<> | ||||||||||||||||||||||||||||
<input type='checkbox' className={`${rootClass}`} {...props} checked= {isChecked}/> | ||||||||||||||||||||||||||||
<input type='checkbox' className={clsx(rootClass)} {...props} checked= {isChecked}/> | ||||||||||||||||||||||||||||
<button type="button" onClick={handleChecked} role="switch"></button> | ||||||||||||||||||||||||||||
</> | ||||||||||||||||||||||||||||
Comment on lines
+30
to
32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider improving accessibility The current implementation using separate checkbox and button elements might cause accessibility issues. Consider using ARIA attributes and combining the elements. - <input type='checkbox' className={clsx(rootClass)} {...props} checked= {isChecked}/>
- <button type="button" onClick={handleChecked} role="switch"></button>
+ <button
+ type="button"
+ role="switch"
+ aria-checked={isChecked}
+ className={clsx(rootClass, color && `${rootClass}--${color}`)}
+ onClick={handleChecked}
+ {...props}
+ >
+ <span className="sr-only">Toggle switch</span>
+ </button> 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,7 +1,8 @@ | ||||||||||||||||
import React from 'react'; | ||||||||||||||||
import { clsx } from 'clsx'; | ||||||||||||||||
|
||||||||||||||||
const TableHead = ({ children, className = 'header', ...props }:any) => { | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add proper TypeScript types instead of using Using -const TableHead = ({ children, className = 'header', ...props }:any) => {
+type TableHeadProps = React.ComponentPropsWithoutRef<'thead'> & {
+ children: React.ReactNode;
+ className?: string;
+};
+
+const TableHead = ({ children, className = 'thead-header', ...props }: TableHeadProps) => { 📝 Committable suggestion
Suggested change
|
||||||||||||||||
return <thead className={className} {...props} > | ||||||||||||||||
return <thead className={clsx(className)} {...props} > | ||||||||||||||||
{children} | ||||||||||||||||
</thead>; | ||||||||||||||||
}; | ||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
'use client'; | ||
import React from 'react'; | ||
|
||
import { clsx } from 'clsx'; | ||
import TextAreaRoot from './fragments/TextAreaRoot'; | ||
import TextAreaInput from './fragments/TextAreaInput'; | ||
|
||
|
@@ -11,7 +11,7 @@ export type TextAreaProps = { | |
} | ||
|
||
const TextArea = ({ customRootClass = '', className = '', children, ...props }: TextAreaProps) => { | ||
return <TextAreaRoot customRootClass={customRootClass} className={`${className}`}> | ||
return <TextAreaRoot customRootClass={customRootClass} className={clsx(className)}> | ||
<TextAreaInput placeholder="enter text"> | ||
{children} | ||
</TextAreaInput> | ||
Comment on lines
15
to
17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Make placeholder configurable. The hardcoded placeholder "enter text" limits the component's reusability. Consider making it a prop. - <TextAreaInput placeholder="enter text">
+ <TextAreaInput placeholder={props.placeholder ?? "enter text"}> And update the TextAreaProps interface: export type TextAreaProps = {
children: React.ReactNode;
customRootClass?: string;
className?: string;
+ placeholder?: string;
}
|
||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,5 +1,5 @@ | ||||||
import React, { useState } from 'react'; | ||||||
|
||||||
import { clsx } from 'clsx'; | ||||||
import { customClassSwitcher } from '~/core'; | ||||||
|
||||||
import TogglePrimitive from '~/core/primitives/Toggle'; | ||||||
|
@@ -43,7 +43,7 @@ const Toggle: React.FC<ToggleProps> = ({ | |||||
return ( | ||||||
|
||||||
<TogglePrimitive | ||||||
className={`${rootClass}`} | ||||||
className={clsx(rootClass)} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Include the className prop in clsx call The Update the className composition: -className={clsx(rootClass)}
+className={clsx(rootClass, className)} 📝 Committable suggestion
Suggested change
|
||||||
pressed={isPressed} | ||||||
onPressedChange={handlePressed} | ||||||
data-state={isPressed ? 'on' : 'off'} | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import React, { useContext, useId, useRef, useState } from 'react'; | ||
import ButtonPrimitive from '~/core/primitives/Button'; | ||
import { TreeContext } from '../contexts/TreeContext'; | ||
import { clsx } from 'clsx'; | ||
|
||
type TreeItemProps = { | ||
children: React.ReactNode; | ||
|
@@ -60,7 +61,7 @@ const TreeItem = ({ children, item, level = 0, className = '', ...props }: TreeI | |
return <> | ||
|
||
<ButtonPrimitive | ||
className={className} | ||
className={clsx(className)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Unnecessary use of clsx The current implementation
-className={clsx(className)}
+className={className} Additionally, consider moving inline styles to className-based styling for better maintainability: -style={{ display: 'block', alignItems: 'center', gap: '0.5rem' }}
+className={clsx(className, 'tree-item-button')} -style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}
+className="tree-item-content" This would require adding corresponding CSS classes but would improve maintainability and consistency.
|
||
ref={buttonRef} | ||
onClick={handleClick} | ||
data-rad-ui-batch-element | ||
|
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.
🛠️ Refactor suggestion
Replace 'any' type with proper component props interface.
Using 'any' type reduces type safety. Consider defining a proper interface for the component props.