ISSUE-005 - Added indicator "I" and "O", emulating an accessibility option found in iOS.
Added a subtle background color transition. Gave up on the idea of giving the toggle circle a shadow (not worth the hassle). But if I did decide to do that, I'd be able to animate the toggle circle fairly easily, I think.
This commit is contained in:
1 parent
3151c58d9d
commit
dd4df61fec
3 files changed
+31
-9
No files matched your search
@@ -13,13 +13,17 @@ export type ToggleProps = {
|
|||||||
label: string,
|
label: string,
|
||||||
toggled: boolean,
|
toggled: boolean,
|
||||||
onToggle: (value: AnimatedBG) => void,
|
onToggle: (value: AnimatedBG) => void,
|
||||||
|
showIndicators?: boolean,
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* This is my attempt at making a iOS-style toggle switch.
|
* This is my attempt at making a iOS-style toggle switch.
|
||||||
* @param param0
|
|
||||||
* @returns
|
|
||||||
*/
|
*/
|
||||||
export const Toggle = ({ label, toggled, onToggle }: ToggleProps) => {
|
export const Toggle = ({
|
||||||
|
label,
|
||||||
|
toggled,
|
||||||
|
onToggle,
|
||||||
|
showIndicators = false,
|
||||||
|
}: ToggleProps) => {
|
||||||
const [hovered, setHovered] = useState(false);
|
const [hovered, setHovered] = useState(false);
|
||||||
return (
|
return (
|
||||||
<ToggleContainer>
|
<ToggleContainer>
|
||||||
@@ -37,8 +41,9 @@ export const Toggle = ({ label, toggled, onToggle }: ToggleProps) => {
|
|||||||
onMouseDown={() => setHovered(true)}
|
onMouseDown={() => setHovered(true)}
|
||||||
onMouseUp={() => setHovered(false)}
|
onMouseUp={() => setHovered(false)}
|
||||||
>
|
>
|
||||||
<ToggleBackground toggled={toggled} />
|
<ToggleBackground toggled={toggled} showIndicators={showIndicators}>
|
||||||
<ToggleCircle toggled={toggled} stretched={hovered} />
|
<ToggleCircle toggled={toggled} stretched={hovered} />
|
||||||
|
</ToggleBackground>
|
||||||
</ToggleLabel>
|
</ToggleLabel>
|
||||||
</ToggleBody>
|
</ToggleBody>
|
||||||
</ToggleContainer>
|
</ToggleContainer>
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ ToggleLabel.displayName = "ToggleLabel";
|
|||||||
type ToggleBackgroundProps = {
|
type ToggleBackgroundProps = {
|
||||||
toggled: boolean,
|
toggled: boolean,
|
||||||
toggledColor?: string,
|
toggledColor?: string,
|
||||||
|
showIndicators?: boolean,
|
||||||
};
|
};
|
||||||
export const ToggleBackground = styled.div<ToggleBackgroundProps>`
|
export const ToggleBackground = styled.div<ToggleBackgroundProps>`
|
||||||
background-color: ${({
|
background-color: ${({
|
||||||
@@ -47,10 +48,31 @@ export const ToggleBackground = styled.div<ToggleBackgroundProps>`
|
|||||||
)};
|
)};
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
transition: background-color 300ms;
|
||||||
|
|
||||||
${({ toggled }) => toggled && css`
|
${({ toggled }) => toggled && css`
|
||||||
box-shadow: inset 0 0 24px -16px black;
|
box-shadow: inset 0 0 24px -16px black;
|
||||||
`}
|
`}
|
||||||
|
|
||||||
|
${({ toggled, showIndicators }) => showIndicators && (toggled ?
|
||||||
|
css`
|
||||||
|
div:before {
|
||||||
|
position: absolute;
|
||||||
|
right: 26px;
|
||||||
|
bottom: -2px;
|
||||||
|
content: "I";
|
||||||
|
color: ${p => p.theme.colors.darkGrey};
|
||||||
|
}
|
||||||
|
` :
|
||||||
|
css`
|
||||||
|
div:after {
|
||||||
|
position: absolute;
|
||||||
|
left: 23px;
|
||||||
|
bottom: -2px;
|
||||||
|
content: "O";
|
||||||
|
color: ${p => p.theme.colors.grey};
|
||||||
|
}
|
||||||
|
`)}
|
||||||
`;
|
`;
|
||||||
ToggleBackground.displayName = "ToggleBackground";
|
ToggleBackground.displayName = "ToggleBackground";
|
||||||
|
|
||||||
|
|||||||
@@ -48,9 +48,4 @@ export const GlobalStyle = createGlobalStyle<MainThemeProps>`
|
|||||||
button {
|
button {
|
||||||
font-family: ${p => p.theme.fonts.basic};
|
font-family: ${p => p.theme.fonts.basic};
|
||||||
}
|
}
|
||||||
|
|
||||||
.main {
|
|
||||||
padding: 70px 0 20px;
|
|
||||||
min-height: calc(100vh - 50px);
|
|
||||||
}
|
|
||||||
`;
|
`;
|
||||||
Reference in new issue
Block a user