跳到主要内容

IToggleButton

View source on GitHub

Custom toggle button input for binary state controls.

toggle-buttontoggle-button

Examples

Theme switcher with custom margin

const darkModeToggle: IToggleButton = {
label: "Dark Mode",
isChecked: false,
onChange: () => {
return {
actions: [Actions.updateProps, Actions.updateTheme],
newProps: {
isChecked: true
},
theme: "dark"
};
},
style: {
marginLeft: "16px"
}
}

Permission-aware notification settings

const notificationsToggle: IToggleButton = {
label: "Enable Notifications",
isChecked: true,
isDisabled: !hasNotificationPermission,
onChange: () => {
return {
actions: [Actions.updateProps, Actions.showToast],
newProps: {
isChecked: false
},
toastProps: [{
type: ToastType.info,
title: "Notifications disabled",
timeout: 3000
}]
};
}
}

Styled auto-save control with custom background

const autoSaveToggle: IToggleButton = {
label: "Auto-save",
isChecked: true,
onChange: () => {
return {
actions: [Actions.updateProps],
newProps: {
isChecked: false
}
};
},
style: {
backgroundColor: "#f5f5f5",
padding: "8px",
borderRadius: "4px"
}
}

Properties

PropertyTypeDescription
label?stringDefines the toggle button label
isCheckedbooleanSpecifies whether the toggle button is enabled
onChange() => void | IMessageSets a function which is triggered whenever the toggle button is clicked
isDisabled?booleanSpecifies whether the toggle button is disabled
style?anyDefines the toggle button CSS style
className?stringDefines the CSS class for styling the component. Can be used to override or extend the default component styles.