Skip to content

Commit

Permalink
fix: make toggle button non-layout
Browse files Browse the repository at this point in the history
  • Loading branch information
haideralsh committed Dec 22, 2023
1 parent fb0dc07 commit 1e34640
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
3 changes: 1 addition & 2 deletions src/Toggle/Toggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { Box } from "../Box";
import { HelpText, RequirementText } from "../FieldLabel";
import { Field } from "../Form";
import { Text } from "../Type";
import { ComponentSize, useComponentSize } from "../NDSProvider/ComponentSizeContext";
import { ClickInputLabel } from "../utils";
import { DefaultNDSThemeType } from "../theme.type";
import { getSubset, omitSubset } from "../utils/subset";
import ToggleButton from "./ToggleButton";
import { ComponentSize, useComponentSize } from "../NDSProvider/ComponentSizeContext";

const labelTextStyles = (theme: DefaultNDSThemeType) => ({
fontSize: theme.fontSizes.small,
Expand All @@ -25,7 +25,6 @@ type MaybeToggleTitleProps = React.ComponentPropsWithRef<"div"> & {
helpText?: string;
children?: any;
};

const MaybeToggleTitle: React.FC<MaybeToggleTitleProps> = ({
labelText,
requirementText,
Expand Down
23 changes: 12 additions & 11 deletions src/Toggle/ToggleButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,15 @@ const animationConfig: AnimationConfig = {
const Switch: React.FC<SwitchProps> = ({ children, disabled, toggled, onClick }) => (
<AnimatedBox
position="relative"
display="flex"
alignItems="center"
justifyContent={toggled ? "flex-end" : "flex-start"}
height="24px"
width="48px"
bg={disabled ? "grey" : getSwitchBackground(toggled)}
borderRadius="20px"
padding="2px"
boxShadow="small"
whileHover="hover"
animate={toggled ? "toggled" : "initial"}
whileHover="active"
whileFocus="active"
onClick={onClick}
>
{children}
Expand All @@ -70,18 +69,20 @@ const Switch: React.FC<SwitchProps> = ({ children, disabled, toggled, onClick })
const Slider: React.FC<SliderProps> = ({ disabled, children }) => (
<motion.div
className="slider"
layout
initial={false}
variants={{
hover: {
active: {
boxShadow: disabled ? undefined : theme.shadows.focus,
scale: disabled ? undefined : animationConfig.scale,
},
toggled: {
marginLeft: theme.space.x3,
},
initial: {
marginLeft: theme.space.none,
},
}}
transition={animationConfig.transition}
whileFocus={{
boxShadow: disabled ? undefined : theme.shadows.focus,
scale: disabled ? undefined : animationConfig.scale,
}}
style={{
height: "20px",
width: "20px",
Expand All @@ -106,7 +107,7 @@ const ToggleInput = styled.input(
transform: disabled ? null : `scale(${animationConfig.scale})`,
boxShadow: disabled ? undefined : theme.shadows.focus,
},
})
}),
);

const ToggleButton: React.FC<ToggleButtonProps> = React.forwardRef((props, ref) => {
Expand Down

0 comments on commit 1e34640

Please sign in to comment.