mirror of
https://github.com/dzeiocom/components.git
synced 2025-04-22 10:52:16 +00:00
Fixed Checkbox
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
parent
b13a40ef18
commit
3bde426325
@ -5,28 +5,33 @@ $backColor = #757575
|
|||||||
.label
|
.label
|
||||||
position relative
|
position relative
|
||||||
display flex
|
display flex
|
||||||
padding-left 8px
|
|
||||||
margin 8px
|
|
||||||
user-select none
|
user-select none
|
||||||
|
align-items center
|
||||||
|
|
||||||
|
+ .label
|
||||||
|
margin-top 8px
|
||||||
|
|
||||||
p
|
p
|
||||||
margin-left 18px
|
margin-left 8px
|
||||||
|
|
||||||
span
|
span
|
||||||
top 0
|
top 0
|
||||||
left 0
|
left 0
|
||||||
width 20px
|
width 20px
|
||||||
height @width
|
height @width
|
||||||
position absolute
|
position relative
|
||||||
box-shadow inset 0 0 0 2px $backColor
|
box-shadow inset 0 0 0 2px $grayDark
|
||||||
border-radius 2px
|
border-radius 2px
|
||||||
transition all $transition
|
transition all $transition
|
||||||
|
|
||||||
|
@media (prefers-color-scheme dark)
|
||||||
|
box-shadow inset 0 0 0 2px $grayLight
|
||||||
|
|
||||||
&::after
|
&::after
|
||||||
border-radius 20px
|
border-radius 20px
|
||||||
position absolute
|
position absolute
|
||||||
transition all $transition
|
transition all $transition
|
||||||
background $default
|
background $main
|
||||||
|
|
||||||
svg
|
svg
|
||||||
transition $transition
|
transition $transition
|
||||||
@ -41,19 +46,9 @@ $backColor = #757575
|
|||||||
left 0
|
left 0
|
||||||
opacity 0
|
opacity 0
|
||||||
|
|
||||||
&:focus + span
|
|
||||||
box-shadow inset 0 0 0 2px black, 0 0 0 2px rgba(black,.3)
|
|
||||||
@media (prefers-color-scheme dark)
|
|
||||||
box-shadow inset 0 0 0 2px white, 0 0 0 2px rgba(white,.3)
|
|
||||||
|
|
||||||
&:focus:checked + span
|
|
||||||
box-shadow inset 0 0 0 2px $default, 0 0 0 2px rgba($default,.3)
|
|
||||||
@media (prefers-color-scheme dark)
|
|
||||||
box-shadow inset 0 0 0 2px $default, 0 0 0 2px rgba($default,.3)
|
|
||||||
|
|
||||||
&:checked + span
|
&:checked + span
|
||||||
background rgba($default, .5)
|
background rgba($main, .5)
|
||||||
box-shadow inset 0 0 0 2px $default
|
box-shadow inset 0 0 0 2px $main
|
||||||
|
|
||||||
svg
|
svg
|
||||||
color white
|
color white
|
||||||
@ -67,7 +62,6 @@ $backColor = #757575
|
|||||||
box-shadow inset 0 0 0 2px white
|
box-shadow inset 0 0 0 2px white
|
||||||
|
|
||||||
.radio
|
.radio
|
||||||
margin-left 18px // Margin + margin for Circle
|
|
||||||
span
|
span
|
||||||
border-radius 20px
|
border-radius 20px
|
||||||
|
|
||||||
@ -86,20 +80,19 @@ $backColor = #757575
|
|||||||
.switch
|
.switch
|
||||||
padding 2px 0 2px 10px // 2px base padding 10px circle padding
|
padding 2px 0 2px 10px // 2px base padding 10px circle padding
|
||||||
|
|
||||||
&:hover span
|
&:hover span::after
|
||||||
box-shadow none
|
|
||||||
|
|
||||||
&::after
|
|
||||||
background black
|
background black
|
||||||
|
@media (prefers-color-scheme dark)
|
||||||
|
background white
|
||||||
|
|
||||||
span
|
span
|
||||||
width 28px
|
width 28px
|
||||||
height 14px
|
height 14px
|
||||||
border-radius 20px
|
border-radius 20px
|
||||||
top 50%
|
top 50%
|
||||||
|
margin-right 10px
|
||||||
box-shadow none
|
box-shadow none
|
||||||
background rgba($backColor, .5)
|
background rgba($backColor, .5)
|
||||||
transform translateY(-50%)
|
|
||||||
|
|
||||||
&::after
|
&::after
|
||||||
content " "
|
content " "
|
||||||
@ -115,93 +108,39 @@ $backColor = #757575
|
|||||||
width 20px
|
width 20px
|
||||||
|
|
||||||
&:checked + span
|
&:checked + span
|
||||||
box-shadow none
|
|
||||||
|
|
||||||
&::after
|
&::after
|
||||||
left 100%
|
left 100%
|
||||||
transform translate(-50%, -50%)
|
transform translate(-50%, -50%)
|
||||||
background $default
|
background $main
|
||||||
|
|
||||||
.primary
|
|
||||||
$color = $primary
|
|
||||||
|
|
||||||
|
checkBox($color)
|
||||||
input:checked + span
|
input:checked + span
|
||||||
background rgba($color, .5)
|
background rgba($color, .5)
|
||||||
box-shadow inset 0 0 0 2px $color
|
box-shadow inset 0 0 0 2px $color
|
||||||
|
|
||||||
&::after
|
&::after
|
||||||
background $color
|
background $color
|
||||||
|
input:focus:checked + span
|
||||||
|
box-shadow inset 0 0 0 2px $color, 0 0 0 2px rgba($color,.3)
|
||||||
&.switch
|
&.switch
|
||||||
input:checked + span
|
input:checked + span
|
||||||
box-shadow none
|
box-shadow none
|
||||||
|
|
||||||
.secondary
|
|
||||||
$color = $secondary
|
|
||||||
|
|
||||||
input:checked + span
|
|
||||||
background rgba($color, .5)
|
|
||||||
box-shadow inset 0 0 0 2px $color
|
|
||||||
|
|
||||||
&::after
|
|
||||||
background $color
|
|
||||||
|
|
||||||
&.switch
|
|
||||||
input:checked + span
|
|
||||||
box-shadow none
|
|
||||||
|
|
||||||
.info
|
.info
|
||||||
$color = $info
|
checkBox($infoLight)
|
||||||
|
@media (prefers-color-scheme dark)
|
||||||
input:checked + span
|
checkBox($infoDark)
|
||||||
background rgba($color, .5)
|
|
||||||
box-shadow inset 0 0 0 2px $color
|
|
||||||
|
|
||||||
&::after
|
|
||||||
background $color
|
|
||||||
|
|
||||||
&.switch
|
|
||||||
input:checked + span
|
|
||||||
box-shadow none
|
|
||||||
|
|
||||||
.success
|
.success
|
||||||
$color = $success
|
checkBox($successLight)
|
||||||
|
@media (prefers-color-scheme dark)
|
||||||
|
checkBox($successDark)
|
||||||
|
|
||||||
input:checked + span
|
.error
|
||||||
background rgba($color, .5)
|
checkBox($errorLight)
|
||||||
box-shadow inset 0 0 0 2px $color
|
@media (prefers-color-scheme dark)
|
||||||
|
checkBox($errorDark)
|
||||||
&::after
|
|
||||||
background $color
|
|
||||||
|
|
||||||
&.switch
|
|
||||||
input:checked + span
|
|
||||||
box-shadow none
|
|
||||||
|
|
||||||
.danger
|
|
||||||
$color = $danger
|
|
||||||
|
|
||||||
input:checked + span
|
|
||||||
background rgba($color, .5)
|
|
||||||
box-shadow inset 0 0 0 2px $color
|
|
||||||
|
|
||||||
&::after
|
|
||||||
background $color
|
|
||||||
|
|
||||||
&.switch
|
|
||||||
input:checked + span
|
|
||||||
box-shadow none
|
|
||||||
|
|
||||||
.warning
|
.warning
|
||||||
$color = $warning
|
checkBox($warningLight)
|
||||||
|
@media (prefers-color-scheme dark)
|
||||||
input:checked + span
|
checkBox($warningDark)
|
||||||
background rgba($color, .5)
|
|
||||||
box-shadow inset 0 0 0 2px $color
|
|
||||||
|
|
||||||
&::after
|
|
||||||
background $color
|
|
||||||
|
|
||||||
&.switch
|
|
||||||
input:checked + span
|
|
||||||
box-shadow none
|
|
||||||
|
@ -7,38 +7,32 @@ import css from './Checkbox.module.styl'
|
|||||||
import Text from '../Text'
|
import Text from '../Text'
|
||||||
|
|
||||||
interface Props extends React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> {
|
interface Props extends React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> {
|
||||||
label?: string
|
label: string
|
||||||
id: string
|
type?: 'checkbox' | 'radio' | 'switch'
|
||||||
type?: undefined
|
|
||||||
radio?: boolean
|
|
||||||
switch?: boolean
|
|
||||||
color?: ColorType
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Checkbox extends React.Component<Props> {
|
export default class Checkbox extends React.Component<Props> {
|
||||||
|
|
||||||
public render() {
|
public render() {
|
||||||
const props: Props = Object.assign({}, this.props)
|
const props: Partial<Props> = Object.assign({}, this.props)
|
||||||
delete props.label
|
delete props.label
|
||||||
delete props.type
|
delete props.type
|
||||||
delete props.color
|
|
||||||
delete props.switch
|
|
||||||
delete props.radio
|
|
||||||
|
|
||||||
const realType = this.props.radio ? 'radio' : 'checkbox'
|
const realType = this.props.type ?? 'checkbox'
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<label htmlFor={this.props.id} className={buildClassName(
|
<label htmlFor={this.props.id ?? this.props.label} className={buildClassName(
|
||||||
[css.label],
|
[css.label],
|
||||||
[css.radio, realType === 'radio'],
|
[css.radio, realType === 'radio'],
|
||||||
[css.switch, this.props.switch],
|
[css.switch, realType === 'switch'],
|
||||||
[css[this.props.color as string], this.props.color]
|
[css[this.props.color as string], this.props.color]
|
||||||
)}>
|
)}>
|
||||||
<input {...props}
|
<input {...props}
|
||||||
type={realType}
|
id={this.props.id ?? this.props.label}
|
||||||
|
type={realType === 'switch' ? 'checkbox' : realType}
|
||||||
/>
|
/>
|
||||||
<span>
|
<span>
|
||||||
{realType === 'checkbox' && ! this.props.switch && (
|
{realType === 'checkbox' && (
|
||||||
<Check strokeWidth={4} size={16}/>
|
<Check strokeWidth={4} size={16}/>
|
||||||
)}
|
)}
|
||||||
</span>
|
</span>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user