Skip to content

Commit

Permalink
feat: add form error component (#4802)
Browse files Browse the repository at this point in the history
  • Loading branch information
connoratrug authored Mar 6, 2025
1 parent bfd0512 commit c3a83af
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
34 changes: 34 additions & 0 deletions apps/tailwind-components/components/form/Error.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<template>
<div class="flex flex-row bg-invalid p-2 justify-between">
<div></div>
<div class="flex flex-row gap-1">
<BaseIcon name="info" class="text-invalid stroke-2 min-h-6 min-w-6" />
<span class="my-auto text-invalid font-bold px-1">{{ message }}</span>
</div>

<ButtonBar>
<Button
:icon-only="true"
type="tertiary"
icon="caret-up"
label="Go to previous error"
@click="$emit('error-prev')"
/>
<Button
:icon-only="true"
type="tertiary"
icon="caret-down"
label="Go to next error"
@click="$emit('error-next')"
/>
</ButtonBar>
</div>
</template>

<script setup lang="ts">
defineProps<{
message: string;
}>();
defineEmits(["error-prev", "error-next"]);
</script>
17 changes: 17 additions & 0 deletions apps/tailwind-components/pages/form/Error.story.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<template>
<FormError
message="3 fields require your attention before you can save this cohort"
@error-prev="errorPrev"
@error-next="errorNext"
/>
</template>

<script setup lang="ts">
function errorPrev() {
alert("Previous error");
}
function errorNext() {
alert("Next error");
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { mount } from "@vue/test-utils";
import { expect, it } from "vitest";
import Error from "~/components/form/Error.vue";
import FloatingVue from "floating-vue";
import "floating-vue/dist/style.css"; // Ensure styles are loaded

const wrapper = mount(Error, {
props: {
message: "this is an error message",
},
global: {
plugins: [FloatingVue], // Register the plugin
},
});

it("should show the message", async () => {
expect(wrapper.html()).toContain("this is an error message");
expect(wrapper.findAll("button")[0].text()).toContain("Go to previous error");
expect(wrapper.findAll("button")[1].text()).toContain("Go to next error");
});

0 comments on commit c3a83af

Please sign in to comment.