Skip to content

Commit

Permalink
Add hover and disabled styles to background of toggle component
Browse files Browse the repository at this point in the history
  • Loading branch information
juliewongbandue committed Aug 15, 2023
1 parent c4d80cb commit c8f16de
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/components/inputs/Input/Input.style.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import styled, { css, StyledComponent } from 'styled-components';
import { rgba } from 'polished';
import { rgba, darken } from 'polished';
import { grayscale, slate } from '../../../color';

import {
FauxMark,
Expand Down Expand Up @@ -84,19 +85,40 @@ export const ToggleIcon = styled.div`
`;

function fauxToggleChecked({ toggle, theme }) {
const unCheckedColor =
theme.name === 'light' ? slate(300) : grayscale(300);
const checkedColor = theme.formats.primary;

return (
toggle &&
css`
~ ${Faux} {
background: ${unCheckedColor};
border: 1px solid ${unCheckedColor};
}
&:checked ~ ${Faux} {
background: ${theme.formats.primary};
border: 1px solid ${theme.formats.primary};
background: ${checkedColor};
border: 1px solid ${checkedColor};
${ToggleIcon} {
transform: scale(1) translateX(calc(100% + 4px));
}
&::after {
transform: scale(1) translateX(calc(100% + 4px));
}
}
:hover:checked ~ ${Faux} {
background: ${darken(0.1, checkedColor)};
border-color: ${darken(0.1, checkedColor)};
}
:hover ~ ${Faux} {
background: ${darken(0.1, unCheckedColor)};
border-color: transparent;
}
:disabled ~ ${Faux} {
opacity: 50%;
}
`
);
}
Expand Down

0 comments on commit c8f16de

Please sign in to comment.