-
Notifications
You must be signed in to change notification settings - Fork 536
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
Pass props through to ToggleSwitch wrapper #3520
Changes from 3 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@primer/react': patch | ||
--- | ||
|
||
passthrough dom props on toggleswitch | ||
|
||
<!-- Changed components: ToggleSwitch --> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,11 +13,7 @@ import {CellAlignment} from '../DataTable/column' | |
const TRANSITION_DURATION = '80ms' | ||
const EASE_OUT_QUAD_CURVE = 'cubic-bezier(0.5, 1, 0.89, 1)' | ||
|
||
export type ToggleSwitchProps = { | ||
/** The id of the DOM node that describes the switch */ | ||
['aria-describedby']?: string | ||
/** The id of the DOM node that labels the switch */ | ||
['aria-labelledby']: string | ||
export interface ToggleSwitchProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'>, SxProp { | ||
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. this could be narrowed a bit more, but I don't think we need to do that (and i kind of wish we used the dom onchange event type too, but oh well). We could also use 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. From a TS perspective, is there a convention we could use to decide when to use 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. I don't think there's any clear guidance, and there aren't many cases where it matters. I think it's a bit clearer to read as an interface extension here instead of |
||
/** Uncontrolled - whether the switch is turned on */ | ||
defaultChecked?: boolean | ||
/** Whether the switch is ready for user input */ | ||
|
@@ -36,7 +32,7 @@ export type ToggleSwitchProps = { | |
* **This should only be changed when the switch's alignment needs to be adjusted.** For example: It needs to be left-aligned because the label appears above it and the caption appears below it. | ||
*/ | ||
statusLabelPosition?: CellAlignment | ||
} & SxProp | ||
} | ||
|
||
const sizeVariants = variant({ | ||
prop: 'size', | ||
|
@@ -221,6 +217,7 @@ const ToggleSwitch: React.FC<React.PropsWithChildren<ToggleSwitchProps>> = ({ | |
size = 'medium', | ||
statusLabelPosition = 'start', | ||
sx: sxProp, | ||
...props | ||
}) => { | ||
const isControlled = typeof checked !== 'undefined' | ||
const [isOn, setIsOn] = useProvidedStateOrCreate<boolean>(checked, onChange, Boolean(defaultChecked)) | ||
|
@@ -247,6 +244,7 @@ const ToggleSwitch: React.FC<React.PropsWithChildren<ToggleSwitchProps>> = ({ | |
alignItems="center" | ||
flexDirection={statusLabelPosition === 'start' ? 'row' : 'row-reverse'} | ||
sx={sxProp} | ||
{...props} | ||
> | ||
{loading ? <Spinner size="small" /> : null} | ||
<Text | ||
|
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.
these are included in
html attributes