initial
This commit is contained in:
74
layers/ui/components/checkbox/index.vue
Normal file
74
layers/ui/components/checkbox/index.vue
Normal file
@@ -0,0 +1,74 @@
|
||||
<template>
|
||||
<div
|
||||
:class="[
|
||||
cn.b(),
|
||||
cn.is('checked', checked),
|
||||
cn.is('invalid', invalid),
|
||||
cn.is('disabled', disabled),
|
||||
cn.is('focused', focused),
|
||||
cn.has('label', hasLabel),
|
||||
]"
|
||||
>
|
||||
<label :class="[cn.e('wrapper')]">
|
||||
<input
|
||||
:name="id"
|
||||
:class="[cn.e('input')]"
|
||||
type="checkbox"
|
||||
:disabled="disabled"
|
||||
:checked="checked"
|
||||
@focus="focused = true"
|
||||
@blur="focused = false"
|
||||
@change="handleChange"
|
||||
>
|
||||
|
||||
<UiIconSCheck :class="[cn.e('checkmark')]" />
|
||||
|
||||
<p :class="[cn.e('label')]">
|
||||
<slot>{{ label }}</slot>
|
||||
</p>
|
||||
</label>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useSlots } from 'vue'
|
||||
import useClassname from '../../composables/use-classname'
|
||||
|
||||
export interface Props {
|
||||
id: string
|
||||
label?: string
|
||||
disabled?: boolean
|
||||
modelValue?: boolean | string | number
|
||||
trueValue?: boolean | string | number
|
||||
falseValue?: boolean | string | number
|
||||
required?: boolean
|
||||
}
|
||||
|
||||
defineOptions({
|
||||
name: 'UiCheckbox',
|
||||
})
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
disabled: false,
|
||||
trueValue: true,
|
||||
falseValue: false,
|
||||
required: false,
|
||||
modelValue: undefined,
|
||||
})
|
||||
|
||||
defineEmits<{
|
||||
'update:modelValue': [state: boolean | string | number]
|
||||
focus: []
|
||||
blur: []
|
||||
}>()
|
||||
|
||||
const slots = useSlots()
|
||||
|
||||
const cn = useClassname('ui-checkbox')
|
||||
|
||||
const { checked, invalid, focused, hasLabel, handleChange } = useCheckbox(props, slots)
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
@use 'styles';
|
||||
</style>
|
||||
98
layers/ui/components/checkbox/styles.scss
Normal file
98
layers/ui/components/checkbox/styles.scss
Normal file
@@ -0,0 +1,98 @@
|
||||
@use '../../styles/variables' as *;
|
||||
@use '../../styles/mixins' as *;
|
||||
|
||||
.ui-checkbox {
|
||||
$self: &;
|
||||
|
||||
--size: 16px;
|
||||
|
||||
display: flex;
|
||||
|
||||
&__wrapper {
|
||||
display: inline-flex;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
&__input {
|
||||
width: 0;
|
||||
height: 0;
|
||||
opacity: 0;
|
||||
cursor: pointer;
|
||||
z-index: -1;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
&__checkmark {
|
||||
--border-color: var(--checkbox-border-color);
|
||||
--border-width: 1px;
|
||||
|
||||
width: var(--size);
|
||||
height: var(--size);
|
||||
border-radius: 4px;
|
||||
outline: var(--border-width) solid var(--border-color);
|
||||
outline-offset: calc(var(--border-width) * -1);
|
||||
color: transparent;
|
||||
cursor: pointer;
|
||||
transition: .2s ease-out;
|
||||
transition-property: outline-color, background-color, color;
|
||||
|
||||
#{$self}.has-label & {
|
||||
margin-top: 1px;
|
||||
}
|
||||
|
||||
#{$self}__input:focus-visible + &,
|
||||
#{$self}:not(.is-disabled):not(.is-checked) &:hover {
|
||||
--border-width: 2px;
|
||||
}
|
||||
|
||||
#{$self}.is-checked & {
|
||||
--border-width: 0px;
|
||||
|
||||
color: var(--checkbox-checked-color);
|
||||
background-color: var(--checkbox-checked-background);
|
||||
}
|
||||
|
||||
#{$self}.is-checked #{$self}__input:focus-visible + &,
|
||||
#{$self}:not(.is-disabled).is-checked &:hover {
|
||||
color: var(--checkbox-checked-hover-color);
|
||||
}
|
||||
|
||||
#{$self}.is-invalid & {
|
||||
--border-color: var(--checkbox-invalid-border-color);
|
||||
}
|
||||
|
||||
#{$self}.is-disabled & {
|
||||
--border-color: var(--checkbox-disabled-border-color);
|
||||
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
#{$self}.is-disabled.is-checked & {
|
||||
color: var(--checkbox-disabled-checked-color);
|
||||
}
|
||||
}
|
||||
|
||||
&__label {
|
||||
@include txt-i-m;
|
||||
|
||||
margin-left: 8px;
|
||||
color: var(--checkbox-label-color);
|
||||
|
||||
#{$self}.is-disabled & {
|
||||
color: var(--checkbox-label-disabled-color);
|
||||
cursor: not-allowed;
|
||||
}
|
||||
}
|
||||
|
||||
@include element-variant('checkbox', '', (
|
||||
'border-color': $clr-grey-400,
|
||||
'checked-color': $clr-grey-600,
|
||||
'checked-background': $clr-grey-300,
|
||||
'checked-hover-color': $clr-grey-500,
|
||||
'invalid-border-color': $clr-red-500,
|
||||
'disabled-border-color': $clr-grey-300,
|
||||
'disabled-checked-color': $clr-grey-400,
|
||||
'label-color': $clr-black,
|
||||
'label-disabled-color': $clr-grey-400
|
||||
))
|
||||
}
|
||||
Reference in New Issue
Block a user