Switch
Key Changes:
- Component Renaming & Import Path: The component
SwitchButton
from@ohif/ui
has been replaced bySwitch
in@ohif/ui-next
. You will need to update your import statements accordingly. - Removal of
label
Prop: The integratedlabel
prop 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 theSwitch
needs to be handled explicitly, typically using Flexbox utility classes. - Event Handler Prop Renamed: The
onChange
event handler prop has been replaced withonCheckedChange
. The new prop provides the updated booleanchecked
state directly as its argument. - Styling and Layout: The new
Switch
component relies on standardclassName
prop 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/ui
to@ohif/ui-next
and 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 thelabel
prop 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
label
prop is gone. A<div>
withflex
is used to arrange the new<Switch>
and an associated<Label>
. ThehtmlFor
attribute on the<Label>
links it to the<Switch>
via itsid
for accessibility. -
Update Event Handler Prop: Rename the
onChange
prop 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
onChange
toonCheckedChange
. The callback function signature, receiving the booleanchecked
state, remains a common pattern and is directly supported byonCheckedChange
. If your previousonChange
did not receive the checked state directly (e.g., it just toggled existing state), you might need to adjust your handler logic slightly, butonCheckedChange
directly provides the new state.