Cristiano Magro
2025-01-07 23ff5f831a8ebe05a6e4a4884fdff25824706aac
add modal dialog

show message error
1 files added
2 files modified
115 ■■■■■ changed files
10 - course project/xno-prj-cmp-01-starting-setup/src/components/UI/BaseDialog.vue 86 ●●●●● patch | view | raw | blame | history
10 - course project/xno-prj-cmp-01-starting-setup/src/components/learning-resource/AddResource.vue 27 ●●●●● patch | view | raw | blame | history
10 - course project/xno-prj-cmp-01-starting-setup/src/main.js 2 ●●●●● patch | view | raw | blame | history
10 - course project/xno-prj-cmp-01-starting-setup/src/components/UI/BaseDialog.vue
New file
@@ -0,0 +1,86 @@
<template>
  <div @click="$emit('close')"></div>
  <dialog open>
    <header>
      <slot name="header">
        <h2>{{ title }}</h2>
      </slot>
    </header>
    <section>
      <slot></slot>
    </section>
    <menu>
      <slot name="action">
        <base-button @click="$emit('close')"></base-button>
      </slot>
    </menu>
  </dialog>
</template>
<script>
export default {
  //   props: ['title'],
  props: {
    title: {
      type: String,
      required: false,
    },
  },
  emits: ['close'],
};
</script>
<style scoped>
div {
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  width: 100%;
  background-color: rgba(0, 0, 0, 0.75);
  z-index: 10;
}
dialog {
  position: fixed;
  top: 20vh;
  left: 10%;
  width: 80%;
  z-index: 100;
  border-radius: 12px;
  border: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.26);
  padding: 0;
  margin: 0;
  overflow: hidden;
}
header {
  background-color: #3a0061;
  color: white;
  width: 100%;
  padding: 1rem;
}
header h2 {
  margin: 0;
}
section {
  padding: 1rem;
}
menu {
  padding: 1rem;
  display: flex;
  justify-content: flex-end;
  margin: 0;
}
@media (min-width: 768px) {
  dialog {
    left: calc(50% - 20rem);
    width: 40rem;
  }
}
</style>
10 - course project/xno-prj-cmp-01-starting-setup/src/components/learning-resource/AddResource.vue
@@ -1,5 +1,13 @@
<template>
  <h2>Add Resource</h2>
  <base-dialog v-if="inputIsInvalid" title="Invalid Input" @close="confirmError">
    <template #default>
      <p>Sfortunatamente un input รจ invalido</p>
      <p>Controlla che tutti gli input contengano qualche carattere valido.</p>
    </template>
    <template #action>
      <base-button @click="confirmError">Okay</base-button>
    </template>
  </base-dialog>
  <base-card>
    <form @submit.prevent="submitData">
      <div class="form-control">
@@ -30,14 +38,31 @@
<script>
export default {
  inject: ['addResource'],
  data() {
    return {
      inputIsInvalid: false,
    };
  },
  methods: {
    submitData() {
      const enteredTitle = this.$refs.titleInput.value;
      const enteredDescription = this.$refs.descInput.value;
      const enteredUrl = this.$refs.linkInput.value;
      if (
        enteredTitle.trim() === '' ||
        enteredDescription.trim() ||
        enteredUrl.trim()
      ) {
        this.inputIsInvalid = true;
        return;
      }
      this.addResource(enteredTitle, enteredDescription, enteredUrl);
    },
    confirmError() {
      this.inputIsInvalid = false;
    },
  },
};
</script>
10 - course project/xno-prj-cmp-01-starting-setup/src/main.js
@@ -3,11 +3,13 @@
import App from './App.vue';
import BaseCard from './components/UI/BaseCard.vue';
import BaseButton from './components/UI/BaseButton.vue';
import BaseDialog from './components/UI/BaseDialog.vue';
const app = createApp(App);
app.component('base-card', BaseCard);
app.component('base-button', BaseButton);
app.component('base-dialog', BaseDialog);
app.mount('#app');