-
Notifications
You must be signed in to change notification settings - Fork 7
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
17 changed files
with
164 additions
and
40 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
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,65 @@ | ||
<script setup lang="ts" generic="T extends string | number"> | ||
import { match } from 'switch-pattern' | ||
import type { HTMLAttributes } from 'vue' | ||
interface Option { | ||
label: string | number | ||
value: T | ||
disabled?: boolean | ||
attrs?: HTMLAttributes | ||
} | ||
defineProps<{ | ||
options: Option[] | ||
size?: 'xs' | 'sm' | 'lg' | ||
}>() | ||
const modelValue = defineModel<T[]>('modelValue') | ||
function toggle(value: T, checked: boolean) { | ||
const _v = [modelValue.value!.includes(value), checked] as const | ||
const { exact, patterns: m } = match(_v) | ||
switch (m) { | ||
case (exact([true, true])): | ||
case (exact([false, false])): | ||
{ | ||
return | ||
} | ||
case (exact([false, true])): { | ||
modelValue.value?.push(value) | ||
return | ||
} | ||
case (exact([true, false])): { | ||
modelValue.value?.splice(modelValue.value.findIndex(i => i === value), 1) | ||
} | ||
} | ||
} | ||
// checkbox-xs checkbox-md checkbox-lg | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<div | ||
v-for="opt in options" | ||
:key="opt.value" | ||
class="form-control" | ||
> | ||
<label class="label cursor-pointer justify-start gap-4"> | ||
<input | ||
class="checkbox" | ||
:class="{ | ||
[`checkbox-${size}`]: size, | ||
}" | ||
type="checkbox" | ||
v-bind="opt.attrs" | ||
:checked="modelValue?.includes(opt.value)" | ||
@change="ev => toggle(opt.value, (ev.target as any).checked)" | ||
> | ||
<span class="label-text text-nowrap">{{ opt.label }}</span> | ||
</label> | ||
</div> | ||
</div> | ||
</template> |
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
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
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
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
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
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
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 |
---|---|---|
|
@@ -6,4 +6,5 @@ export { | |
rulesets, | ||
rankingSystems, | ||
leaderboardRankingSystems, | ||
userRoles, | ||
} from '$active' |
Oops, something went wrong.