Skip to content

Commit

Permalink
Add switch component
Browse files Browse the repository at this point in the history
  • Loading branch information
barshathakuri committed Apr 12, 2024
1 parent 4885f9f commit b1547d0
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/components/Switch/SwitchIcon/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { _cs } from '@togglecorp/fujs';

import styles from './styles.module.css';

export interface SwitchIconProps {
className?: string;
value?: boolean | null;
}

function SwitchIcon(props: SwitchIconProps) {
const {
className,
value,
} = props;

return (
<div
className={_cs(
styles.switchIcon,
className,
value ? styles.on : styles.off,
)}
aria-hidden="true"
>
<div className={styles.knob} />
</div>
);
}

export default SwitchIcon;
34 changes: 34 additions & 0 deletions src/components/Switch/SwitchIcon/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
.switch-icon {
--gap: .05em;
--border-width: var(--go-ui-width-separator-sm);
--knob-diameter: calc(1em - 2 * var(--gap) - 2 * var(--border-width));
--background-color: var(--go-ui-color-gray-50);
--border-color: var(--go-ui-color-gray-30);
--knob-color: var(--go-ui-color-white);

display: flex;
align-items: center;
transition: var(--go-ui-duration-transition-medium) background-color ease-in-out;
border: var(--border-width) solid var(--border-color);
border-radius: .5em;
background-color: var(--background-color);
padding: var(--gap);
width: calc(1em + var(--knob-diameter));
height: 1em;

.knob {
transition: var(--go-ui-duration-transition-medium) transform ease-in-out, var(--go-ui-duration-transition-medium) background-color ease-in-out;
border-radius: calc(calc(1em - var(--gap) * 2) / 2);
background-color: var(--knob-color);
width: var(--knob-diameter);
height: var(--knob-diameter);
}

&.on {
background-color: var(--go-ui-color-primary-red);

.knob {
transform: translateX(100%);
}
}
}
11 changes: 11 additions & 0 deletions src/components/Switch/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import styles from './styles.module.css';

function Switch() {
return (
<div
className={styles.container}
/>
);
}

export default Switch;
3 changes: 3 additions & 0 deletions src/components/Switch/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.container {
--width: var(--go-ui-font-size-4xl);
}

0 comments on commit b1547d0

Please sign in to comment.