-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
90 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React, { useState } from 'react' | ||
import { SwitchInput } from './index.js' | ||
|
||
export default { | ||
title: 'Components/SwitchInput', | ||
component: SwitchInput, | ||
} | ||
|
||
export const Default = () => { | ||
const [value, setValue] = useState(false) | ||
return <SwitchInput value={value} onChange={setValue} /> | ||
} | ||
|
||
export const Error = () => { | ||
const [value, setValue] = useState(true) | ||
return <SwitchInput error value={value} onChange={setValue} /> | ||
} | ||
|
||
export const Disabled = () => { | ||
const [value, setValue] = useState(true) | ||
return <SwitchInput value={value} onChange={setValue} disabled /> | ||
} |
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,67 @@ | ||
import { borderRadius } from '../../utils/border.js' | ||
import { color } from '../../utils/colors.js' | ||
|
||
type SwitchInputProps = { | ||
value: boolean | ||
onChange: (value: boolean) => void | ||
disabled?: boolean | ||
error?: boolean | ||
} | ||
|
||
function SwitchInput({ value, onChange, disabled, error }: SwitchInputProps) { | ||
return ( | ||
<div | ||
style={{ | ||
width: 24, | ||
height: 16, | ||
borderRadius: borderRadius('full'), | ||
border: `1px solid ${color('neutral-20-adjusted')}`, | ||
background: color('neutral-10-adjusted'), | ||
...(value && { | ||
border: `1px solid ${color('neutral-100')}`, | ||
background: color('neutral-100'), | ||
}), | ||
...(error && { | ||
border: `1px solid ${color('destructive-100')}`, | ||
background: color('neutral-10-adjusted'), | ||
...(value && { | ||
border: `1px solid ${color('destructive-100')}`, | ||
background: color('destructive-100'), | ||
}), | ||
}), | ||
...(disabled && { | ||
border: `1px solid transparent`, | ||
background: color('neutral-20'), | ||
}), | ||
}} | ||
tabIndex={0} | ||
onClick={() => { | ||
if (disabled) return | ||
|
||
onChange(!value) | ||
}} | ||
> | ||
<div | ||
style={{ | ||
width: 14, | ||
height: 14, | ||
borderRadius: borderRadius('full'), | ||
background: color('neutral-100'), | ||
...(value && { | ||
marginLeft: 'auto', | ||
background: color('neutral-inverted-100'), | ||
}), | ||
...(error && { | ||
background: color('neutral-100'), | ||
}), | ||
...(disabled && { | ||
background: color('neutral-inverted-80'), | ||
}), | ||
}} | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
export type { SwitchInputProps } | ||
export { SwitchInput } |
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