Skip to content

Commit

Permalink
feat: add disabled prop to switch & disable requires categories if fe…
Browse files Browse the repository at this point in the history
…ature disabled
  • Loading branch information
ArekChr committed Mar 18, 2024
1 parent a15c5a4 commit 7edf37f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/components/Switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ type SwitchProps = {

/** Accessibility label for the switch */
accessibilityLabel: string;

/** Whether the switch is disabled */
disabled?: boolean;
};

const OFFSET_X = {
OFF: 0,
ON: 20,
};

function Switch({isOn, onToggle, accessibilityLabel}: SwitchProps) {
function Switch({isOn, onToggle, accessibilityLabel, disabled}: SwitchProps) {
const styles = useThemeStyles();
const offsetX = useRef(new Animated.Value(isOn ? OFFSET_X.ON : OFFSET_X.OFF));

Expand All @@ -35,6 +38,7 @@ function Switch({isOn, onToggle, accessibilityLabel}: SwitchProps) {

return (
<PressableWithFeedback
disabled={disabled}
style={[styles.switchTrack, !isOn && styles.switchInactive]}
onPress={() => onToggle(!isOn)}
onLongPress={() => onToggle(!isOn)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function WorkspaceCategoriesSettingsPage({route}: WorkspaceCategoriesSettingsPag
isOn={policy?.requiresCategory ?? false}
accessibilityLabel={translate('workspace.categories.requiresCategory')}
onToggle={updateWorkspaceRequiresCategory}
disabled={!policy?.areCategoriesEnabled}
/>
</View>
</View>
Expand Down

0 comments on commit 7edf37f

Please sign in to comment.