Skip to content
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

Add [x]Props to ToggleSwitch #2010

Merged
merged 22 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
391ad3e
test
AdamMeza-Bentley Mar 1, 2024
eedd534
test
AdamMeza-Bentley Mar 1, 2024
e16b2b2
remove test file
AdamMeza-Bentley Mar 1, 2024
5a2b8b3
Merge branch 'main' of https://github.com/iTwin/iTwinUI
AdamMeza-Bentley Mar 8, 2024
cea8776
Merge branch 'main' of https://github.com/iTwin/iTwinUI
AdamMeza-Bentley Mar 19, 2024
fd99847
Merge branch 'main' of https://github.com/iTwin/iTwinUI
AdamMeza-Bentley Mar 21, 2024
8761614
Merge branch 'main' of https://github.com/iTwin/iTwinUI
AdamMeza-Bentley Mar 22, 2024
5db6cb2
fix merge errors
AdamMeza-Bentley Apr 1, 2024
044d813
Merge branch 'main' of https://github.com/iTwin/iTwinUI
AdamMeza-Bentley Apr 5, 2024
c310e1f
Merge branch 'main' of https://github.com/iTwin/iTwinUI
AdamMeza-Bentley Apr 11, 2024
46e7521
Merge branch 'main' of https://github.com/iTwin/iTwinUI
AdamMeza-Bentley Apr 15, 2024
31d105d
Merge branch 'main' of https://github.com/iTwin/iTwinUI
AdamMeza-Bentley Apr 17, 2024
3dff0d7
Merge branch 'main' of https://github.com/iTwin/iTwinUI
AdamMeza-Bentley Apr 18, 2024
96ebe7d
add label props to ToggleSwitch
AdamMeza-Bentley Apr 18, 2024
32c701e
remove unneeded import
AdamMeza-Bentley Apr 18, 2024
f52a85e
revert playground;
AdamMeza-Bentley Apr 18, 2024
25820dd
revert playground;
AdamMeza-Bentley Apr 18, 2024
5e42218
make more specific testing
AdamMeza-Bentley Apr 19, 2024
b9b8242
add changeset
AdamMeza-Bentley Apr 19, 2024
d54e782
doc changes
AdamMeza-Bentley Apr 19, 2024
2c2db63
small changes
AdamMeza-Bentley Apr 24, 2024
2e952fd
remove labelClassName
AdamMeza-Bentley Apr 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/brave-terms-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@itwin/itwinui-react": minor
---

ToggleSwitch: Added new `labelProps` to allow for customization of label element.
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,25 @@ it('should not render an icon if it is set to null', () => {
const { container } = render(<ToggleSwitch icon={null} />);
expect(container.querySelector('.iui-toggle-switch-icon')).toBeNull();
});

it('should correctly pass labelProps', () => {
const { container } = render(
<ToggleSwitch
className='switch-class'
style={{ color: 'blue' }}
label='some-label'
labelProps={{
className: 'some-class',
style: { color: 'red' },
}}
/>,
);

const label = container.querySelector('.some-class') as HTMLElement;

expect(label.style.color).toBe('red');

expect(
(container.querySelector('.switch-class') as HTMLElement).style.color,
).toBe('blue');
});
11 changes: 10 additions & 1 deletion packages/itwinui-react/src/core/ToggleSwitch/ToggleSwitch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ type ToggleSwitchProps = {
* Label for the toggle switch.
*/
label?: React.ReactNode;
/**
* Passes properties for ToggleSwitch label.
*/
labelProps?: React.ComponentProps<'span'>;
/**
* Position of the label.
* @default 'right'
Expand Down Expand Up @@ -63,6 +67,7 @@ export const ToggleSwitch = React.forwardRef((props, ref) => {
className,
style,
size = 'default',
labelProps = {},
icon: iconProp,
...rest
} = props;
Expand Down Expand Up @@ -101,7 +106,11 @@ export const ToggleSwitch = React.forwardRef((props, ref) => {
</Box>
)}
{label && (
<Box as='span' className='iui-toggle-switch-label'>
<Box
as='span'
{...labelProps}
className={cx('iui-toggle-switch-label', labelProps?.className)}
>
{label}
</Box>
)}
Expand Down
Loading