Skip to content

Commit

Permalink
feat: add asterisk on required fields
Browse files Browse the repository at this point in the history
  • Loading branch information
favna committed Jul 23, 2024
1 parent fea28a5 commit a2d131e
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 20 deletions.
4 changes: 2 additions & 2 deletions components/forms/input.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div class="form-control w-full">
<label class="label">
<span class="label-text">{{ label }}</span>
<span class="label-text">{{ label }}<FormsRequiredStar :required="required" /></span>
</label>
<input v-model="value" type="text" class="input input-bordered w-full shadow-md" :class="{ 'input-error': !!errorMessage }" />
<label class="label">
Expand All @@ -11,7 +11,7 @@
</template>

<script setup lang="ts">
const props = defineProps<{ name: string; label: string }>();
const props = defineProps<{ name: string; label: string; required?: boolean }>();
const { value, errorMessage } = useField<string>(toRef(props, 'name'));
</script>
7 changes: 7 additions & 0 deletions components/forms/required-star.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<template>
<span v-if="required" class="ml-1 font-bold text-red-600">*</span>
</template>

<script lang="ts" setup>
defineProps<{ required?: boolean }>();
</script>
2 changes: 1 addition & 1 deletion components/forms/select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="form-control mb-4 w-full">
<label class="label">
<span class="label-text">
{{ label }}
{{ label }}<FormsRequiredStar :required="required" />
<span v-if="options.length === 0">
<span class="font-bold text-error">
<NuxtLink :aria-label="`Go to configuration page for ${label}`" class="link link-secondary" :to="addNewOptionHref"
Expand Down
4 changes: 2 additions & 2 deletions components/forms/textarea.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div class="form-control h-1/2">
<label class="label">
<span class="label-text">{{ label }}</span>
<span class="label-text">{{ label }}<FormsRequiredStar :required="required" /></span>
<span v-if="lengthCount.length" class="label-text text-slate-600 dark:text-gray-400">Length per part: {{ lengthCount.join(', ') }}</span>
</label>
<textarea
Expand All @@ -17,7 +17,7 @@
</template>

<script setup lang="ts">
const props = defineProps<{ name: string; label: string }>();
const props = defineProps<{ name: string; label: string; required?: boolean }>();
const { value, errorMessage } = useField<string>(toRef(props, 'name'));
Expand Down
6 changes: 3 additions & 3 deletions components/modals/role.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<template>
<div class="modal">
<form class="modal-box relative" @submit="onSubmit">
<form class="modal-box relative max-w-[40rem]" @submit="onSubmit">
<button aria-label="Close popup" class="btn btn-circle btn-sm absolute right-2 top-2" @click="handleClose(resetForm)">
<XCircleIcon />
</button>
<h3 class="text-lg font-bold">{{ action === 'add' ? 'Add a new role' : 'Update role' }}</h3>
<FormsInput name="label" label="Role name" />
<FormsInput name="value" label="Role Snowflake" />
<FormsInput name="label" label="Role name" :required="true" />
<FormsInput name="value" label="Role Snowflake" :required="true" />
<div class="mt-5 grid w-full grid-cols-1 gap-2 lg:grid-cols-2 lg:gap-4">
<button aria-label="Reset inputs" type="button" class="btn btn-accent" @click="resetForm()">Reset form</button>
<button aria-label="Add role" type="submit" class="btn btn-primary" :disabled="isSubmitting || !meta.valid">
Expand Down
6 changes: 3 additions & 3 deletions components/modals/webhook.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<template>
<div class="modal">
<form class="modal-box relative" @submit="onSubmit">
<form class="modal-box relative max-w-[40rem]" @submit="onSubmit">
<button aria-label="Close popup" class="btn btn-circle btn-sm absolute right-2 top-2" @click="handleClose(resetForm)">
<XCircleIcon />
</button>
<h3 class="text-lg font-bold">{{ action === 'add' ? 'Add a new Webhook URL' : 'Update Webhook URL' }}</h3>
<FormsInput name="label" label="Label" />
<FormsInput name="value" label="Webhook URL" />
<FormsInput name="label" label="Label" :required="true" />
<FormsInput name="value" label="Webhook URL" :required="true" />
<div class="mt-5 grid w-full grid-cols-1 gap-2 lg:grid-cols-2 lg:gap-4">
<button aria-label="Reset inputs" type="button" class="btn btn-accent" @click="resetForm()">Reset form</button>
<button aria-label="Add webhook" type="submit" class="btn btn-primary" :disabled="isSubmitting || !meta.valid">
Expand Down
8 changes: 4 additions & 4 deletions pages/post.vue
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<template>
<div class="mt-5 grid h-full w-full grid-cols-1 px-5">
<form class="flex flex-col" @submit="onSubmit">
<modals-review
<ModalsReview
v-if="modalStorage.identifier === ''"
:values="values"
:is-editing="false"
@close-modal="modalStorage.resetModal()"
@reset-form="resetForm()"
/>
<forms-textarea name="text" label="Message Text" />
<forms-select
<FormsTextarea name="text" label="Message Text" :required="true" />
<FormsSelect
name="webhookUrl"
label="Choose the webhook URL to post to"
add-new-option-href="/configure/webhooks"
class="py-2 lg:py-6"
:options="webhookStorage.webhooks"
:required="true"
/>
<forms-select
<FormsSelect
name="role"
label="Optionally choose a role to mention"
add-new-option-href="/configure/roles"
Expand Down
10 changes: 5 additions & 5 deletions pages/update.vue
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<template>
<div class="mt-5 grid h-full w-full grid-cols-1 px-5">
<form class="flex flex-col" @submit="onSubmit">
<modals-review
<ModalsReview
v-if="modalStorage.identifier === ''"
:values="values"
:is-editing="true"
@close-modal="modalStorage.resetModal()"
@reset-form="resetForm()"
/>
<forms-textarea name="text" label="Message Text" />
<forms-select
<FormsTextarea name="text" label="Message Text" :required="true" />
<FormsSelect
name="webhookUrl"
label="Choose the webhook URL to post to"
add-new-option-href="/configure/webhooks"
class="pt-2 lg:pt-3"
:options="webhookStorage.webhooks"
:required="true"
/>
<forms-input name="messageId" label="Message id to update" />
<FormsInput name="messageId" label="Message id to update" :required="true" />
<button
type="button"
class="btn-shadow btn btn-primary w-full"
Expand All @@ -26,7 +26,7 @@
>
Fetch webhook message content from Discord
</button>
<forms-select
<FormsSelect
name="role"
label="Optionally choose a role to mention"
add-new-option-href="/configure/roles"
Expand Down

0 comments on commit a2d131e

Please sign in to comment.