From bfd59883584aee4c1a0a88952f4277c52afdf2ca Mon Sep 17 00:00:00 2001 From: Romain Hamel Date: Wed, 27 Mar 2024 12:00:15 +0100 Subject: [PATCH] feat(Checkbox): new component (#67) Co-authored-by: Benjamin Canac --- playground/app.vue | 1 + playground/components/FormNestedExample.vue | 3 +- playground/pages/badge.vue | 2 +- playground/pages/button.vue | 8 +- playground/pages/checkbox.vue | 25 +++ playground/pages/chip.vue | 2 +- playground/pages/form-field.vue | 15 +- playground/pages/form.vue | 18 +- playground/pages/input.vue | 2 +- playground/pages/switch.vue | 6 +- playground/pages/tooltip.vue | 2 +- src/runtime/components/Accordion.vue | 3 +- src/runtime/components/Avatar.vue | 3 +- src/runtime/components/Checkbox.vue | 117 ++++++++++ src/runtime/components/Form.vue | 4 +- src/runtime/components/FormField.vue | 49 ++--- src/runtime/components/NavigationMenu.vue | 3 +- src/runtime/components/Switch.vue | 7 +- src/runtime/composables/useComponentIcons.ts | 9 +- src/runtime/composables/useFormField.ts | 2 +- src/runtime/utils/form.ts | 2 +- src/theme/avatar.ts | 27 +-- src/theme/checkbox.ts | 79 +++++++ src/theme/formField.ts | 2 +- src/theme/icons.ts | 9 +- src/theme/index.ts | 1 + src/theme/switch.ts | 14 +- test/components/Checkbox.spec.ts | 32 +++ test/components/Switch.spec.ts | 4 +- .../__snapshots__/Avatar.spec.ts.snap | 2 +- .../__snapshots__/Checkbox.spec.ts.snap | 207 ++++++++++++++++++ .../__snapshots__/Form.spec.ts.snap | 200 +++++++---------- .../__snapshots__/FormField.spec.ts.snap | 149 ++++++------- .../__snapshots__/Switch.spec.ts.snap | 12 +- 34 files changed, 718 insertions(+), 303 deletions(-) create mode 100644 playground/pages/checkbox.vue create mode 100644 src/runtime/components/Checkbox.vue create mode 100644 src/theme/checkbox.ts create mode 100644 test/components/Checkbox.spec.ts create mode 100644 test/components/__snapshots__/Checkbox.spec.ts.snap diff --git a/playground/app.vue b/playground/app.vue index 6a7119aa..a8db9412 100644 --- a/playground/app.vue +++ b/playground/app.vue @@ -13,6 +13,7 @@ const components = [ 'badge', 'button', 'card', + 'checkbox', 'chip', 'collapsible', 'form', diff --git a/playground/components/FormNestedExample.vue b/playground/components/FormNestedExample.vue index c677d6b0..76399d44 100644 --- a/playground/components/FormNestedExample.vue +++ b/playground/components/FormNestedExample.vue @@ -47,8 +47,7 @@ function onError (event: any) {
- - +
diff --git a/playground/pages/badge.vue b/playground/pages/badge.vue index e1bda8bc..2e54b9f6 100644 --- a/playground/pages/badge.vue +++ b/playground/pages/badge.vue @@ -26,7 +26,7 @@ const sizes = Object.keys(theme.variants.size)
-
+
diff --git a/playground/pages/button.vue b/playground/pages/button.vue index a4d1faac..1a8bd25a 100644 --- a/playground/pages/button.vue +++ b/playground/pages/button.vue @@ -59,13 +59,13 @@ const sizes = Object.keys(theme.variants.size) -
+
-
+
-
+
-
+
diff --git a/playground/pages/checkbox.vue b/playground/pages/checkbox.vue new file mode 100644 index 00000000..7e4f279d --- /dev/null +++ b/playground/pages/checkbox.vue @@ -0,0 +1,25 @@ + + + diff --git a/playground/pages/chip.vue b/playground/pages/chip.vue index dfaf7069..16223f96 100644 --- a/playground/pages/chip.vue +++ b/playground/pages/chip.vue @@ -29,7 +29,7 @@ const items = [{
-
+
diff --git a/playground/pages/form-field.vue b/playground/pages/form-field.vue index f0fde9a1..47f87349 100644 --- a/playground/pages/form-field.vue +++ b/playground/pages/form-field.vue @@ -13,7 +13,7 @@ const feedbacks = [ diff --git a/playground/pages/form.vue b/playground/pages/form.vue index eb95d3b3..16477892 100644 --- a/playground/pages/form.vue +++ b/playground/pages/form.vue @@ -5,15 +5,17 @@ import type { Form, FormSubmitEvent } from '#ui/types/form' type User = { email: string password: string + tos: boolean } -const state = ref({ email: '', password: '' }) -const state2 = ref({ email: '', password: '' }) -const state3 = ref({ email: '', password: '' }) +const state = reactive>({}) +const state2 = reactive>({}) +const state3 = reactive>({}) const schema = z.object({ email: z.string().email(), - password: z.string().min(8) + password: z.string().min(8), + tos: z.literal(true) }) const disabledForm = ref>() @@ -40,6 +42,10 @@ function onSubmit (event: FormSubmitEvent) { + + + +
Submit @@ -95,6 +101,10 @@ function onSubmit (event: FormSubmitEvent) { + + + +
Submit diff --git a/playground/pages/input.vue b/playground/pages/input.vue index b3f2036c..bb07ad11 100644 --- a/playground/pages/input.vue +++ b/playground/pages/input.vue @@ -6,7 +6,7 @@ const sizes = Object.keys(theme.variants.size)