Skip to content

Commit

Permalink
Updated: Checkbox component and its default variant code.
Browse files Browse the repository at this point in the history
  • Loading branch information
moshiur01 committed Dec 20, 2024
1 parent 214f49f commit 5c400ad
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 39 deletions.
6 changes: 3 additions & 3 deletions components/content/docs/components/checkbox/CheckboxApi.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ const CheckBoxApiData = [
},
{
id: 3,
propsName: "checked",
propsType: "v-model",
propsDescription: "Checked state of the checkbox",
propsName: "default-checked",
propsType: "boolean",
propsDescription: "Default Checked state of the checkbox",
},
];
</script>
Expand Down
14 changes: 2 additions & 12 deletions components/content/docs/components/checkbox/DefaultCheckbox.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
<script lang="ts" setup>
import { ref } from "vue";
import CodeHighlightWithPreview from "~/components/content/CodeHighlightWithPreview.vue";
import { Checkbox, Label } from "~/src";
import { defaultCheckboxCode } from "./checkboxCode";
const statusOne = ref(true);
const statusTwo = ref(false);
</script>
<template>
<CodeHighlightWithPreview :code="defaultCheckboxCode">
Expand All @@ -15,17 +11,11 @@ const statusTwo = ref(false);
Keep Design System License
</p>
<fieldset class="flex items-center gap-2">
<Checkbox
id="single"
:checked="statusOne"
@update:checked="(value) => (statusOne = value)" />
<Checkbox id="single" default-checked />
<Label for="single">Single License</Label>
</fieldset>
<fieldset class="flex items-center gap-2">
<Checkbox
id="team"
:checked="statusTwo"
@update:checked="(value) => (statusTwo = value)" />
<Checkbox id="team" />
<Label for="team">Team License</Label>
</fieldset>
</div>
Expand Down
19 changes: 5 additions & 14 deletions components/content/docs/components/checkbox/checkboxCode.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,24 @@
const defaultCheckboxCode = {
"CheckboxComponent.vue": `<script setup>
import { Checkbox, Label } from 'keep-vue'
import { ref } from 'vue'
const statusOne = ref(true);
const statusTwo = ref(false);
console.log(statusOne.value, statusTwo.value)
</script>
<template>
<div class="space-y-3 p-3">
<div class="flex items-center justify-center">
<div class="space-y-3 p-3">
<p class="text-body-3 font-normal dark:text-metal-300">
Keep Design System License
</p>
<fieldset class="flex items-center gap-2">
<Checkbox
id="single"
:checked="statusOne"
@update:checked="(value) => (statusOne = value)" />
<Checkbox id="single" default-checked />
<Label for="single">Single License</Label>
</fieldset>
<fieldset class="flex items-center gap-2">
<Checkbox
id="team"
:checked="statusTwo"
@update:checked="(value) => (statusTwo = value)" />
<Checkbox id="team" />
<Label for="team">Team License</Label>
</fieldset>
</div>
</div>
</template>`,
};

Expand Down
17 changes: 7 additions & 10 deletions src/components/Checkbox/Checkbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import {
CheckboxIndicator,
CheckboxRoot,
useForwardPropsEmits,
type CheckboxRootEmits,
type CheckboxRootProps,
} from "radix-vue";
import { computed } from "vue";
Expand All @@ -20,25 +22,21 @@ const props = withDefaults(
class: "",
iconClass: "",
variant: "default",
checked: false,
},
);
// Define emits
const emit = defineEmits<{
"update:checked": [value: boolean];
}>();
const emits = defineEmits<CheckboxRootEmits>();
const restProps = computed(() => {
const { class: _, iconClass, checked, variant, ...rest } = props;
const { class: _, iconClass, variant, ...rest } = props;
return rest;
});
const forwarded = useForwardPropsEmits(restProps, emits);
</script>

<template>
<CheckboxRoot
v-bind="restProps"
:checked="checked"
v-bind="forwarded"
:class="
cn(
'peer relative h-4 w-4 shrink-0 border border-metal-200 ring-offset-primary-100 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary-100 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:border-primary-500 data-[state=checked]:text-primary-500 dark:border-metal-100 dark:ring-offset-primary-500 dark:focus-visible:ring-primary-500 dark:data-[state=checked]:text-primary-500',
Expand All @@ -52,8 +50,7 @@ const restProps = computed(() => {
'rounded data-[state=checked]:before:rounded-sm',
props.class,
)
"
@update:checked="(value) => emit('update:checked', value)">
">
<!-- indicator -->
<CheckboxIndicator
v-if="props.variant === 'default'"
Expand Down

0 comments on commit 5c400ad

Please sign in to comment.