-
Notifications
You must be signed in to change notification settings - Fork 22
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
#167 Allow classnames for switch #171
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -21,25 +21,27 @@ const sizes = { | |
}, | ||
}; | ||
|
||
// TODO: Native checkbox input `checked` and `disabled` properties are not prefixed with `is`. | ||
// Decide on the naming convention. | ||
export const Switch = ({ isChecked = false, size = "medium", ...rest }) => { | ||
export const Switch = ({ isChecked = false, size = "medium", classNames = { parent: "", inner: "" }, ...rest }) => { | ||
return ( | ||
<HeadlessSwitch | ||
checked={isChecked} | ||
className={clsx( | ||
"ui-switch", | ||
isChecked ? "bg-primary disabled:bg-gray-light" : "bg-gray disabled:bg-gray-light", | ||
"relative inline-flex flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none", | ||
"relative inline-flex flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent", | ||
Comment on lines
-33
to
+31
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. Split into two lines |
||
"transition-colors duration-200 ease-in-out focus:outline-none", | ||
sizes[size].parent, | ||
classNames.parent, | ||
)} | ||
{...rest} | ||
> | ||
<span | ||
className={clsx( | ||
"ui-switch-inner pointer-events-none inline-block transform rounded-full bg-white shadow ring-0", | ||
isChecked ? sizes[size].translate : "translate-x-0", | ||
"ui-switch-inner pointer-events-none inline-block transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out", | ||
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. Moved above |
||
"transition duration-200 ease-in-out", | ||
sizes[size].inner, | ||
classNames.inner, | ||
)} | ||
/> | ||
</HeadlessSwitch> | ||
|
@@ -49,6 +51,7 @@ export const Switch = ({ isChecked = false, size = "medium", ...rest }) => { | |
Switch.propTypes = { | ||
isChecked: PropTypes.bool, | ||
size: PropTypes.string, | ||
classNames: PropTypes.shape({ switch: PropTypes.string, content: PropTypes.string }), | ||
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. Does not match the props |
||
}; | ||
|
||
Switch.Group = ({ className, children }) => { | ||
|
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.
parent
andinner
match what we 8 lines about insizes
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.
How about
container
andinput
(orswitch
)? That is what we used for some other components