-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ⚡ add new Switch component to ui-kit
- Loading branch information
1 parent
b17f46a
commit 63d59a0
Showing
8 changed files
with
159 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { Switch, FormRow } from '../src/ui'; | ||
|
||
# Switch | ||
|
||
<FormRow variety> | ||
<h3>Default</h3> | ||
<Switch /> | ||
</FormRow> | ||
|
||
<FormRow variety> | ||
<h3>Disabled</h3> | ||
<Switch disabled /> | ||
</FormRow> | ||
|
||
<FormRow variety> | ||
<h3>Error</h3> | ||
<Switch error>Some label</Switch> | ||
</FormRow> | ||
|
||
<FormRow variety> | ||
<h3>With handler</h3> | ||
<Switch onChange={() => alert('Value is change')} /> | ||
</FormRow> | ||
|
||
<FormRow variety> | ||
<h3>With Label</h3> | ||
<Switch>change settings</Switch> | ||
</FormRow> | ||
|
||
``` | ||
<FormRow variety> | ||
<h3>Default</h3> | ||
<Switch /> | ||
</FormRow> | ||
<FormRow variety> | ||
<h3>Disabled</h3> | ||
<Switch disabled /> | ||
</FormRow> | ||
<FormRow variety> | ||
<h3>Error</h3> | ||
<Switch error /> | ||
</FormRow> | ||
<FormRow variety> | ||
<h3>With handler</h3> | ||
<Switch onChange={() => alert('Value is change')} /> | ||
</FormRow> | ||
<FormRow variety> | ||
<h3>With Label</h3> | ||
<Switch>change settings</Switch> | ||
</FormRow> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
.switch { | ||
display: inline-flex; | ||
position: relative; | ||
user-select: none; | ||
align-items: center; | ||
|
||
&.-error { | ||
color: var(--color-error); | ||
|
||
.switch-track { | ||
box-shadow: 0 0 0 2px var(--color-error); | ||
} | ||
} | ||
|
||
input { | ||
position: absolute; | ||
opacity: 0; | ||
z-index: 1; | ||
cursor: pointer; | ||
width: 106%; | ||
height: 106%; | ||
margin: 0; | ||
left: -3%; | ||
top: -3%; | ||
|
||
&:checked + .switch-track { | ||
background-color: var(--color-primary); | ||
} | ||
|
||
&:checked + .switch-track .switch-thumb { | ||
transform: translateX(16px); | ||
} | ||
|
||
&:focus + .switch-track { | ||
border-color: var(--color-secondary); | ||
box-shadow: 0 0 0 3px var(--color-outline); | ||
} | ||
|
||
&[disabled] { | ||
cursor: not-allowed; | ||
} | ||
|
||
&[disabled] + .switch-track { | ||
background-color: var(--color-black-16); | ||
} | ||
} | ||
|
||
.switch-track { | ||
width: 32px; | ||
height: 16px; | ||
border-radius: 10px; | ||
background-color: var(--color-black-16); | ||
position: relative; | ||
display: inline-flex; | ||
transition: 0.1s background-color ease-in-out; | ||
|
||
& + * { | ||
margin-left: 8px; | ||
} | ||
} | ||
|
||
.switch-thumb { | ||
width: 12px; | ||
height: 12px; | ||
border-radius: 50%; | ||
background-color: var(--color-white); | ||
display: inline-flex; | ||
margin: 2px; | ||
transform: translateX(0); | ||
transition: 0.1s transform ease-in-out; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React, { FC, InputHTMLAttributes, PropsWithChildren } from 'react'; | ||
import cx from 'clsx'; | ||
|
||
export interface SwitchProps extends InputHTMLAttributes<HTMLInputElement> { | ||
error?: boolean; | ||
} | ||
|
||
const Switch: FC<PropsWithChildren<SwitchProps>> = (props) => { | ||
const { className, style, children, error, ...other } = props; | ||
|
||
return ( | ||
<span className={cx('switch', className, error && '-error')} style={style}> | ||
<input type="checkbox" {...other} /> | ||
<span className="switch-track"> | ||
<span className="switch-thumb" /> | ||
</span> | ||
{!!children && <span>{children}</span>} | ||
</span> | ||
); | ||
}; | ||
|
||
export default Switch; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters