Switch
Key Changes:
- Component Renaming & Import Path: The component
SwitchButtonfrom@ohif/uihas been replaced bySwitchin@ohif/ui-next. You will need to update your import statements accordingly. - Removal of
labelProp: The integratedlabelprop has been removed. Labels should now be implemented externally using standard HTML elements (like<span>or<label>) or the<Label>component from@ohif/ui-next. Layout between the label and theSwitchneeds to be handled explicitly, typically using Flexbox utility classes. - Event Handler Prop Renamed: The
onChangeevent handler prop has been replaced withonCheckedChange. The new prop provides the updated booleancheckedstate directly as its argument. - Styling and Layout: The new
Switchcomponent relies on standardclassNameprop and Tailwind utility classes for styling and layout adjustments, rather than internal props or structures.
Migration Steps:
-
Update Import Statement: Change the import from
@ohif/uito@ohif/ui-nextand rename the component.- import { SwitchButton } from '@ohif/ui';
+ import { Switch } from '@ohif/ui-next';
+ import { Label } from '@ohif/ui-next'; // Optional: If using the Label component -
Replace Component Usage and Handle Label Externally: Replace the
<SwitchButton>tag with<Switch>. Remove thelabelprop and add an external element for the label. Use layout utilities (likeflex) to position the label relative to the switch.Example Diff:
- <SwitchButton
- label="Enable Feature"
- checked={isFeatureEnabled}
- onChange={handleToggle}
- />
+ <div className="flex items-center space-x-2">
+ <Switch
+ id="feature-toggle" // It's good practice to add an id
+ checked={isFeatureEnabled}
+ onCheckedChange={handleToggle}
+ />
+ <Label htmlFor="feature-toggle">Enable Feature</Label> {/* Or use a <span> */}
+ </div>Explanation: The
labelprop is gone. A<div>withflexis used to arrange the new<Switch>and an associated<Label>. ThehtmlForattribute on the<Label>links it to the<Switch>via itsidfor accessibility. -
Update Event Handler Prop: Rename the
onChangeprop toonCheckedChange. Ensure your handler function correctly receives the new boolean state as its argument.Example Diff (within the component usage):
- onChange={checked => setIsEnabled(checked)}
+ onCheckedChange={checked => setIsEnabled(checked)}Explanation: The prop name changes from
onChangetoonCheckedChange. The callback function signature, receiving the booleancheckedstate, remains a common pattern and is directly supported byonCheckedChange. If your previousonChangedid not receive the checked state directly (e.g., it just toggled existing state), you might need to adjust your handler logic slightly, butonCheckedChangedirectly provides the new state.