Skip to content
This repository was archived by the owner on Sep 24, 2024. It is now read-only.

Commit 8761d5d

Browse files
SelemondevSelemondev
authored andcommitted
feat(app): #14 Checkbox
This pull request is intended to add a Checkbox component Closes: #14
1 parent 097aade commit 8761d5d

File tree

10 files changed

+196
-37
lines changed

10 files changed

+196
-37
lines changed
Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,12 @@
11
<script setup lang='ts'>
22
import { ref } from 'vue'
33
4-
const people = [{
5-
id: 'benjamincanac',
6-
label: 'benjamincanac',
7-
},
8-
{
9-
id: 'Atinux',
10-
label: 'Atinux',
11-
},
12-
{
13-
id: 'smarroufin',
14-
label: 'smarroufin',
15-
},
16-
{
17-
id: 'nobody',
18-
label: 'Nobody',
19-
}]
20-
21-
const selected = ref(people[3])
4+
const selected = ref(true)
225
</script>
236

247
<template>
258
<div class="grid place-items-center w-full min-h-screen">
26-
<USelectMenu
27-
v-slot="{ open }" v-model="selected" :variants="{
28-
'my-variant': {
29-
base: '!w-full',
30-
},
31-
}" :variant="['my-variant']" :options="people"
32-
>
33-
<UButton color="gray">
34-
{{ selected.label }}
35-
36-
<UIcon name="heroicons:chevron-right-20-solid" class="w-5 h-5 transition-transform" :class="[open && 'transform rotate-90']" />
37-
</UButton>
38-
</USelectMenu>
9+
<!-- <UInput color="red" v-model="value" /> -->
10+
<UCheckbox v-model="selected" name="notifications" label="Notifications" color="red" help="Please check this box" />
3911
</div>
4012
</template>

packages/nuxtlabs-ui-vue/src/Types/componentsTypes/components.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,19 @@ export interface UBadge extends UComponentRoot {
145145

146146
}
147147

148+
export interface UCheckbox extends UComponentRoot {
149+
base?: string
150+
rounded?: string
151+
color?: string
152+
background?: string
153+
border?: string
154+
ring?: string
155+
label?: string
156+
required?: string
157+
help?: string
158+
default?: objectProp
159+
}
160+
148161
export interface UDropdown extends UComponentRoot {
149162
container?: string
150163
height?: string
@@ -242,6 +255,7 @@ export type UAvatarGroupVariants = WithVariantProps<UAvatarGroup>
242255
export type UBadgeVariants = WithVariantProps<UBadge>
243256
export type UButtonVariants = WithVariantProps<UButton>
244257
export type UButtonGroupVariants = WithVariantProps<UButtonGroup>
258+
export type UCheckboxVariants = WithVariantProps<UCheckbox>
245259
export type UDropdownVariants = WithVariantProps<UDropdown>
246260
export type UIconVariants = WithVariantProps<UIcon>
247261
export type UInputVariants = WithVariantProps<UInput>

packages/nuxtlabs-ui-vue/src/Types/enums/Components.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export enum Components {
55
UAvatarGroup = 'UAvatarGroup',
66
UBadge = 'UBadge',
77
UButton = 'UButton',
8+
UCheckbox = 'UCheckbox',
89
ULink = 'ULink',
910
UButtonGroup = 'UButtonGroup',
1011
UDropdown = 'UDropdown',

packages/nuxtlabs-ui-vue/src/Types/variant.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Components } from './enums/Components'
2-
import type { UAccordionVariants, UAlertVariants, UAvatarVariants, UBadgeVariants, UButtonGroupVariants, UButtonVariants, UDropdownVariants, UIconVariants, UInputVariants, UKbdVariants, USelectVariants, UTextareaVariants } from './componentsTypes/components'
2+
import type { UAccordionVariants, UAlertVariants, UAvatarVariants, UBadgeVariants, UButtonGroupVariants, UButtonVariants, UCheckboxVariants, UDropdownVariants, UIconVariants, UInputVariants, UKbdVariants, USelectVariants, UTextareaVariants } from './componentsTypes/components'
33

44
export declare interface CSSClassKeyValuePair {
55
[key: string]: any
@@ -36,6 +36,7 @@ export interface NuxtLabsUIConfiguration {
3636
[Components.UBadge]?: UBadgeVariants
3737
[Components.UButton]?: UButtonVariants
3838
[Components.UButtonGroup]?: UButtonGroupVariants
39+
[Components.UCheckbox]?: UCheckboxVariants
3940
[Components.UDropdown]?: UDropdownVariants
4041
[Components.UIcon]?: UIconVariants
4142
[Components.UInput]?: UInputVariants

packages/nuxtlabs-ui-vue/src/assets/css/tailwind.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
@apply font-Roboto
99
}
1010

11-
select, option {
11+
select, option, input {
1212
@apply appearance-none
1313
}
1414
}
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<script setup lang="ts">
2+
import { computed, defineComponent } from 'vue'
3+
import classNames from 'classnames'
4+
import type { VariantJSWithClassesListProps } from '@/utils/getVariantProps'
5+
import { getVariantPropsWithClassesList } from '@/utils/getVariantProps'
6+
import type { UCheckbox } from '@/Types/componentsTypes/components'
7+
import { Components } from '@/Types/enums/Components'
8+
import { useFormEvents } from '@/composables/useFormEvents'
9+
import { useVariants } from '@/composables/useVariants'
10+
import nuxtLabsTheme from '@/theme/nuxtLabsTheme'
11+
12+
const props = defineProps({
13+
...getVariantPropsWithClassesList<UCheckbox>(),
14+
value: {
15+
type: [String, Number, Boolean, Object],
16+
default: null,
17+
},
18+
modelValue: {
19+
type: [Boolean, Array],
20+
default: null,
21+
},
22+
name: {
23+
type: String,
24+
default: null,
25+
},
26+
disabled: {
27+
type: Boolean,
28+
default: false,
29+
},
30+
checked: {
31+
type: Boolean,
32+
default: false,
33+
},
34+
indeterminate: {
35+
type: Boolean,
36+
default: false,
37+
},
38+
help: {
39+
type: String,
40+
default: null,
41+
},
42+
label: {
43+
type: String,
44+
default: null,
45+
},
46+
required: {
47+
type: Boolean,
48+
default: false,
49+
},
50+
color: {
51+
type: String,
52+
default: () => nuxtLabsTheme.UCheckbox.base.default.color,
53+
},
54+
})
55+
56+
const emits = defineEmits<{
57+
(event: 'update:modelValue', value: any): void
58+
(event: 'change', value: any): void
59+
}>()
60+
const variant = computed(() => {
61+
const customProps = {
62+
...props,
63+
variant: props.variant,
64+
}
65+
return useVariants<UCheckbox>(
66+
Components.UCheckbox,
67+
customProps as VariantJSWithClassesListProps<UCheckbox>,
68+
)
69+
})
70+
const { emitFormBlur } = useFormEvents()
71+
72+
const toggle = computed({
73+
get() {
74+
return props.modelValue
75+
},
76+
set(value) {
77+
emits('update:modelValue', value)
78+
},
79+
})
80+
81+
function onChange(event: Event) {
82+
emits('change', event)
83+
emitFormBlur()
84+
}
85+
86+
const inputClass = computed(() => {
87+
return classNames(
88+
variant.value.base,
89+
variant.value.rounded,
90+
variant.value.background,
91+
variant.value.border,
92+
nuxtLabsTheme.UCheckbox.base.ring.replaceAll('{color}', props.color),
93+
nuxtLabsTheme.UCheckbox.base.color.replaceAll('{color}', props.color),
94+
)
95+
})
96+
</script>
97+
98+
<script lang="ts">
99+
export default defineComponent({
100+
name: Components.UCheckbox,
101+
inheritAttrs: false,
102+
})
103+
</script>
104+
105+
<template>
106+
<div :class="variant.root">
107+
<div class="flex items-center h-5">
108+
<input
109+
:id="name"
110+
v-model="toggle"
111+
:name="name"
112+
:required="required"
113+
:value="value"
114+
:disabled="disabled"
115+
:checked="checked"
116+
:indeterminate="indeterminate"
117+
type="checkbox"
118+
class="form-checkbox"
119+
:class="inputClass"
120+
v-bind="$attrs"
121+
@change="onChange"
122+
>
123+
</div>
124+
<div v-if="label || $slots.label" class="ms-3 text-sm">
125+
<label :for="name" :class="variant.label">
126+
<slot name="label">{{ label }}</slot>
127+
<span v-if="required" :class="variant.required">*</span>
128+
</label>
129+
<p v-if="help" :class="variant.help">
130+
{{ help }}
131+
</p>
132+
</div>
133+
</div>
134+
</template>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Checkbox from './UCheckbox.vue'
2+
3+
export default {
4+
Checkbox,
5+
}

packages/nuxtlabs-ui-vue/src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export { default as UAvatarGroup } from './elements/Avatar/UAvatarGroup.vue'
55
export { default as UBadge } from './elements/Badge/UBadge.vue'
66
export { default as UButton } from './elements/Button/UButton.vue'
77
export { default as UButtonGroup } from './elements/Button/UButtonGroup.vue'
8+
export { default as UCheckbox } from './forms/Checkbox/UCheckbox.vue'
89
export { default as UDropdown } from './elements/Dropdown/UDropdown.vue'
910
export { default as UIcon } from './elements/Icon/UIcon.vue'
1011
export { default as UKbd } from './elements/Kbd/UKbd.vue'

packages/nuxtlabs-ui-vue/src/theme/nuxtLabsTheme.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,37 @@ export default {
323323
},
324324
},
325325
},
326+
327+
UCheckbox: {
328+
base: {
329+
root: 'relative flex items-start',
330+
base: 'h-4 w-4 dark:checked:bg-current dark:checked:border-transparent dark:indeterminate:bg-current dark:indeterminate:border-transparent disabled:opacity-50 disabled:cursor-not-allowed focus:ring-0 focus:ring-transparent focus:ring-offset-transparent',
331+
rounded: 'rounded',
332+
color: 'text-{color}-500 dark:text-{color}-400',
333+
background: 'bg-white dark:bg-gray-900',
334+
border: 'border border-gray-300 dark:border-gray-700',
335+
ring: 'focus-visible:ring-2 focus-visible:ring-{color}-500 dark:focus-visible:ring-{color}-400 focus-visible:ring-offset-2 focus-visible:ring-offset-white dark:focus-visible:ring-offset-gray-900',
336+
label: 'font-medium text-gray-700 dark:text-gray-200',
337+
required: 'text-red-500 dark:text-red-400',
338+
help: 'text-gray-500 dark:text-gray-400',
339+
default: {
340+
color: 'green',
341+
},
342+
},
343+
344+
variants: {
345+
default: {
346+
color: 'green',
347+
},
348+
color: 'text-{color}-500 dark:text-{color}-400',
349+
background: 'bg-white dark:bg-gray-900',
350+
border: 'border border-gray-300 dark:border-gray-700',
351+
ring: 'focus-visible:ring-2 focus-visible:ring-{color}-500 dark:focus-visible:ring-{color}-400 focus-visible:ring-offset-2 focus-visible:ring-offset-white dark:focus-visible:ring-offset-gray-900',
352+
label: 'font-medium text-gray-700 dark:text-gray-200',
353+
required: 'text-red-500 dark:text-red-400',
354+
help: 'text-gray-500 dark:text-gray-400',
355+
},
356+
},
326357
UDropdown: {
327358
base: {
328359
root: 'relative inline-flex text-left rtl:text-right',
@@ -404,7 +435,7 @@ export default {
404435
UInput: {
405436
base: {
406437
root: 'relative',
407-
base: 'relative block w-full disabled:cursor-not-allowed disabled:opacity-75 focus:outline-none border-0',
438+
base: 'appearance-none relative block w-full disabled:cursor-not-allowed disabled:opacity-75 focus:outline-none border-0',
408439
rounded: 'rounded-md',
409440
placeholder: 'placeholder-gray-400 dark:placeholder-gray-500',
410441
size: {

packages/nuxtlabs-ui-vue/tailwind.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ export const darkMode = 'class'
3636
export const theme = {
3737
extend: {
3838
colors: tailwindColors,
39-
backgroundColor: ['disabled', 'ring'],
40-
textColor: ['disabled', 'ring'],
39+
backgroundColor: ['disabled', 'ring', 'focus', 'border'],
40+
textColor: ['disabled', 'ring', 'focus', 'border'],
4141
fontFamily: {
4242
Roboto: 'Roboto',
4343
},
4444
},
4545
}
46-
export const plugins = []
46+
export const plugins = [require('@tailwindcss/forms')]

0 commit comments

Comments
 (0)