Categories
Vue

Adding a Simple Calendar to Our Vue App with vue-simple-calendar

Adding a calendar widget by hand is very painful.

Therefore, many calendar component libraries are created.

vue-simple-calendar is one library.

In this article, we’ll look at how to add a calendar with the vue-simple-calendar library.

Getting Started

We add our library by installing it with NPM.

To do that, we run:

npm i vue-simple-calendar

Add a Simple Calendar

We can add a simple calendar with the calendar-view component.

To add it, we write:

<template>
  <div id="app">
    <calendar-view
      :show-date="showDate"
      class="theme-default holiday-us-traditional holiday-us-official"
    >
      <calendar-view-header
        slot="header"
        slot-scope="t"
        :header-props="t.headerProps"
        @input="setShowDate"
      />
    </calendar-view>
  </div>
</template>
<script>
import { CalendarView, CalendarViewHeader } from "vue-simple-calendar";
import "vue-simple-calendar/static/css/default.css";
import "vue-simple-calendar/static/css/holidays-us.css";

export default {
  name: "app",
  data() {
    return { showDate: new Date() };
  },
  components: {
    CalendarView,
    CalendarViewHeader
  },
  methods: {
    setShowDate(d) {
      this.showDate = d;
    }
  }
};
</script>

We import the CSS and register the components within our component.

The showDate prop has the date object which controls the month to be shown.

The calendar-view-header component has the header that lets us navigate through the months.

When we choose a month on the header, the input event is emitted.

Adding Calendar Events

We can set the events prop to populate the calendar with events.

For example, we can write:

<template>
  <div id="app">
    <calendar-view
      :show-date="showDate"
      :events="events"
      class="theme-default holiday-us-traditional holiday-us-official"
      @click-date="onClickDate"
    >
      <calendar-view-header
        slot="header"
        slot-scope="t"
        :header-props="t.headerProps"
        @input="setShowDate"
      />
    </calendar-view>
  </div>
</template>
<script>
import { CalendarView, CalendarViewHeader } from "vue-simple-calendar";
import "vue-simple-calendar/static/css/default.css";
import "vue-simple-calendar/static/css/holidays-us.css";

export default {
  name: "app",
  data() {
    return {
      showDate: new Date(),
      events: [
        {
          id: 1,
          startDate: "2020-10-19",
          endDate: "2020-10-19",
          title: "Sample event 1"
        },
        {
          id: 2,
          startDate: "2020-10-06",
          endDate: "2020-10-13",
          title: "Sample event 2"
        }
      ]
    };
  },
  components: {
    CalendarView,
    CalendarViewHeader
  },
  methods: {
    setShowDate(d) {
      this.showDate = d;
    },
    onClickDate(...params) {
      console.log(params);
    }
  }
};
</script>

We have the events array which we set as the value of the events prop.

Each entry has the id with the unique ID.

startDate has the start date of the event.

endDate has the end date of the event.

title has the title of the event.

id and startDate are required.

title defaults to 'untitled' .

It also emits events that we can listen to.

For example, we can listen to the click-date event which has the date that we clicked on and the mouse events as parameters.

The events will be shown on the calendar.

Slots

vue-simple-calendar can be customized by populating various slots.

periodStart lets us customize the first date of the display period.

periodEnd lets us customize the last date of the display period.

displayLocale lets us show the locale setting for the calendar.

monthNames sets the month names.

There’re many more slots listed at https://github.com/richardtallent/vue-simple-calendar#slots.

Conclusion

vue-simple-calendar is a simple library for adding a calendar to our Vue app.

Categories
Vue

Adding a Simple Calendar to Our Vue App with vue2-event-calendar

Adding a calendar widget by hand is very painful.

Therefore, many calendar component libraries are created.

vue-event-calendar is one library.

In this article, we’ll look at how to add a calendar with the vue-event-calendar library.

Getting Started

We add our library by installing it with NPM.

To do that, we run:

npm i vue-event-calendar

Adding the Calendar

We can use the component by registering the plugin.

First, we register it by writing:

import Vue from "vue";
import App from "./App.vue";
import "vue-event-calendar/dist/style.css";
import vueEventCalendar from "vue-event-calendar";

Vue.use(vueEventCalendar, { locale: "en" });
Vue.config.productionTip = false;

new Vue({
  render: (h) => h(App)
}).$mount("#app");

We import the CSS and then register the plugin to make it available throughout our Vue app.

Also, we set the locale with the options.

Then in our component, we add:

<template>
  <vue-event-calendar :events="events"></vue-event-calendar>
</template>

<script>
export default {
  data() {
    return {
      events: [
        {
          date: "2020/09/12",
          title: "special event"
        },
        {
          date: "2020/09/15",
          title: "party",
          desc: "go to a party",
          customClass: "highlight"
        }
      ]
    };
  }
};
</script>

to show the calendar component with the events.

vue-event-calendar has the calendar.

events has the events that we want to display.

Once we click on the day, we see the events displayed.

The event template can be changed by populating the default slot.

For example, we can write:

<template>
  <vue-event-calendar :events="events">
    <template scope="props">
      <div :key="index" v-for="(event, index) in props.showEvents" class="event-item">{{event}}</div>
    </template>
  </vue-event-calendar>
</template>

<script>
export default {
  data() {
    return {
      events: [
        {
          date: "2020/09/12",
          title: "special event"
        },
        {
          date: "2020/09/15",
          title: "party",
          desc: "go to a party",
          customClass: "highlight"
        }
      ]
    };
  }
};
</script>

We loop through the prop.showEvents array to render the events.

It has the whole event object.

Component Events

The vue-event-calendar emits the day-changed and month-changed events when we navigate through the calendar.

For example, we can write:

<template>
  <vue-event-calendar
    :events="events"
    @day-changed="handleDayChanged"
    @month-changed="handleMonthChanged"
  ></vue-event-calendar>
</template>

<script>
export default {
  data() {
    return {
      events: [
        {
          date: "2020/09/12",
          title: "special event"
        },
        {
          date: "2020/09/15",
          title: "party",
          desc: "go to a party",
          customClass: "highlight"
        }
      ]
    };
  },
  methods: {
    handleDayChanged(ev) {
      console.log(ev);
    },
    handleMonthChanged(ev) {
      console.log(ev);
    }
  }
};
</script>

We listen to the events with our own methods.

The event object parameter for the handleDayChanged method has the date and the events array with the events for the day.

The event object parameter for the handleMonthChanged method has the month string in MM/YYYY format.

We can also navigate the months programmatically with a few methods.

this.$EventCalendar.nextMonth() goes to the next month.

this.$EventCalendar.preMonth() goes to the previous month.

this.$EventCalendar.toDate(‘2020/11/12’) goes to the given date.

Conclusion

vue-event-calendar is a very useful library for displaying a calendar with events in a Vue app.

Categories
Vue

Adding a Simple Calendar to Our Vue App with vue2-simple-calendar

Adding a calendar widget by hand is very painful.

Therefore, many calendar component libraries are created.

vue2-simple-calendar is one library.

In this article, we’ll look at how to add a calendar with the vue2-simple-calendar library.

Getting Started

We add our library by installing it with NPM.

To do that, we run:

npm i vue2-simple-calendar

Using the Calendar Component

We can ad the calendar component by adding the CSS code.

Create a file called vue2-simple-calendar.css and add:

.vue-calendar {
  display: grid;
  grid-template-rows: 10% 90%;
  background: #fff;
  margin: 0 auto;
}
.calendar-header {
  align-items: center;
}
.header-left,
.header-right {
  flex: 1;
}
.header-center {
  flex: 3;
  text-align: center;
}
.title {
  margin: 0 5px;
}
.next-month,
.prev-month {
  cursor: pointer;
}
.calendar-body {
  display: grid;
  grid-template-rows: 5% 95%;
}
.days-header {
  display: grid;
  grid-auto-columns: 14.25%;
  grid-template-areas: "a a a a a a a";
  border-top: 1px solid #e0e0e0;
  border-left: 1px solid #e0e0e0;
  border-bottom: 1px solid #e0e0e0;
}
.days-body {
  display: grid;
  grid-template-rows: auto;
}
.day-number {
  text-align: right;
  margin-right: 10px;
}
.day-label {
  text-align: center;
  border-right: 1px solid #e0e0e0;
}
.week-row {
  display: grid;
  grid-template-areas: "a a a a a a a";
  grid-row-gap: 5px;
  grid-auto-columns: 14.25%;
  border-left: 1px solid #e0e0e0;
}
.week-day {
  padding: 4px;
  border-right: 1px solid #e0e0e0;
  border-bottom: 1px solid #e0e0e0;
}
.week-day.disabled {
  background-color: #f5f5f5;
}
.week-day.not-current > .day-number {
  color: #c3c3c3;
}
.week-day.today > .day-number {
  font-weight: 700;
  color: red;
}
.events {
  font-size: 12px;
  cursor: pointer;
  padding: 0 0 0 4px;
}
.events .event {
  height: 18px;
  line-height: 18px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  margin: 0 4px 2px 0;
  color: rgba(0, 0, 0, 0.87);
  background-color: #d4dcec;
}
.events .more-link {
  color: rgba(0, 0, 0, 0.38);
}

This is the same code like the example at https://codesandbox.io/s/93pjr734r4?file=/src/assets/vue2-simple-calendar.css:0-1549.

It doesn’t come with any styles, so we’ve to add them ourselves.

Then in main.js , we add:

import Vue from "vue";
import App from "./App.vue";
import vueCalendar from "vue2-simple-calendar";
import "./assets/vue2-simple-calendar.css";

Vue.use(vueCalendar, {});
Vue.config.productionTip = false;

new Vue({
  render: (h) => h(App)
}).$mount("#app");

to register the plugin.

Then in our component, we write:

<template>
  <vue-calendar
    :show-limit="3"
    :events="events"
    @show-all="showAll"
    @day-clicked="dayClicked"
    @event-clicked="eventClicked"
    @month-changed="monthChanged"
  ></vue-calendar>
</template>

<script>
export default {
  methods: {
    showAll(events) {
      console.log(events);
    },
    dayClicked(day) {
      console.log(day);
    },
    eventClicked(event) {
      console.log(event);
    },
    monthChanged(start, end) {
      console.log(start, end);
    },
    highlightDays(days) {
      console.log(days);
    }
  },
  created() {
    this.$calendar.eventBus.$on("show-all", events => this.showAll(events));
    this.$calendar.eventBus.$on("day-clicked", day => this.dayClicked(day));
    this.$calendar.eventBus.$on("event-clicked", event =>
      this.eventClicked(event)
    );
    this.$calendar.eventBus.$on("month-changed", (start, end) =>
      this.monthChanged(start, end)
    );
  }
};
</script>

The vue-calendar component renders the calendar.

It renders various events.

show-all is emitted when we show the days.

day-clicked is emitted when we click on a day.

event-clicked is emitted when we click on an event.

month-changed is emitted when we change the month on the calendar.

Conclusion

We can add a simple calendar component with the vue2-simple-calendar component.

Categories
Reviews

Why A2 Hosting is a Great Hosting Provider for Small Business?

A2 Hosting is another shared hosting provider that offers lots of values to their customers.

The benefits and pricing they offer are very suitable for small businesses.

They offer higher server speeds that other shared hosting providers.

Fastest Shared Hosting Speed

A2 Hosting loads sites faster than any other hosting provider. They can load a site usually in less than half a second.

This shows how fast they can load a site.

Customer Support

A2 Hosting offers a live chat for customer support.

It’s also available 24/7 so we can get support from them at any time.

Their support staff also replies very quickly so you’ll be sure to be able to reach them.

HackScan

The HackScan feature keeps your site safe by checking for any malware in your site and traffic patterns that may indicate an attack is going 24/7.

This prevents any chance of a denial of service attack breaking out on your site.

Free Site Migrations

A2 Hosting also offers free site migration.

You can get 1 to 25 websites migrated for free by them depending on your plan.

If you subscribe to the Lite, Swift, or Turbo plans, you’ll get a single site moved for free.

But if you subscribe to dedicated or managed VPS plans, you get 25 free site migrations.

Content Management Systems, Website Builders, and Developer Tools

They offer many tools for web a web hosts to help webmasters.

There’s an one-click installers for various CMSes like WordPress, Drupal, Joomla, and more.

And they offer their own website builder called SiteBuilder.

With that, you get a WYSIWYG interface for building your own site so that you don’t have to know how to code.

A2 Hosting also has free CloudFlare integration for caching to keep your site fast.

Money-Back Guarantee

A2 Hosting offers more than the 30-day money-back guarantee that most hosts offer.

They offer a refund even after 30 days with the ‘anytime’ money-back guarantee.

You can get a refund as far as 120 days.

Uptime of 99.93%

They have a high uptime percentage of 99.93%.

This means that your site is very unlikely to go down if you host it with A2 Hosting.

Many Hosting Plans

A2 Hosting offers many plans from the entry-level Startup plan all the way to the Turbo Max plan.

The Startup plan only allows one site to be hosting, but the rest can be used to host an unlimited number of sites.

Storage for the Startup plan is 100GB, which is generous. The rest are unlimited.

Bandwidth, databases, email addresses, are all unlimited.

The Drive, Turbo Boost, and Turbo Max plan all have automated backup capabilities in case anything goes wrong.

The Startup plans offers 0.7GB of RAM, and the higher-tier plans all offer at least 1GB of RAM.

Plans other than Startup also offer 2 or more cores for processing.

Caching is available on the Turbo Boost and Turbo Max plans.

There’re many add-ons that we can buy separately like SSL certificates, spam filtering, and CloudFlare.

Also, it’s one of a few hosting providers that offer Windows hosting if we want Windows servers.

The Startup plan starts at $3.95 a month.

With these features, it’s more than enough to host small to medium sites.

Conclusion

A2 Hosting offers many benefits that not all web hosts can offer.

The pricing and benefits they offer are great for small businesses.

Click Here to Sign Up for A2 Hosting

Categories
Buefy

Buefy — Radio Buttons and Star Rating

Buefy is a UI framework that’s based on Bulma.

In this article, we’ll look at how to use Buefy in our Vue app.

Radio Button

We can add radio buttons to let users select options from a set.

For example, we can write:

<template>  
  <section>  
    <div class="block">  
      <b-radio v-model="fruit" name="fruit" native-value="apple">apple</b-radio>  
      <b-radio v-model="fruit" name="fruit" native-value="orange">orange</b-radio>  
      <b-radio v-model="fruit" name="fruit" native-value="grape">grape</b-radio>  
    </div>  
    <p>{{fruit}}</p>  
  </section>  
</template>  
<script>  
export default {  
  data() {  
    return {  
      fruit: ""  
    };  
  }  
};  
</script>

to add the b-radio components to add the radio buttons.

name and v-model should be the same so we can only select one of them.

native-value has the value we set as the model value.

v-model binds the selected value to the model.

Sizes

We can change the size with the size prop:

<template>  
  <section>  
    <div class="block">  
      <b-radio size="is-large" v-model="fruit" name="fruit" native-value="apple">apple</b-radio>  
      <b-radio size="is-large" v-model="fruit" name="fruit" native-value="orange">orange</b-radio>  
      <b-radio size="is-large" v-model="fruit" name="fruit" native-value="grape">grape</b-radio>  
    </div>  
    <p>{{fruit}}</p>  
  </section>  
</template>  
<script>  
export default {  
  data() {  
    return {  
      fruit: ""  
    };  
  }  
};  
</script>

is-large made them large.

Type

We can change the styles with the type prop:

<template>  
  <section>  
    <div class="block">  
      <b-radio type="is-success" v-model="fruit" name="fruit" native-value="apple">apple</b-radio>  
      <b-radio type="is-success" v-model="fruit" name="fruit" native-value="orange">orange</b-radio>  
      <b-radio type="is-success" v-model="fruit" name="fruit" native-value="grape">grape</b-radio>  
    </div>  
    <p>{{fruit}}</p>  
  </section>  
</template>  
<script>  
export default {  
  data() {  
    return {  
      fruit: ""  
    };  
  }  
};  
</script>

is-success make the radio buttons green.

Radio Button

We can style the radio buttons as buttons.

For example, we can write:

<template>  
  <section>  
    <b-field>  
      <b-radio-button v-model="radioButton" native-value="foo" type="is-danger">  
        <span>foo</span>  
      </b-radio-button>  
      <b-radio-button v-model="radioButton" native-value="bar" type="is-success">  
        <span>bar</span>  
      </b-radio-button>  
      <b-radio-button v-model="radioButton" native-value="baz">baz</b-radio-button>  
      <b-radio-button v-model="radioButton" native-value="disabled" disabled>disabled</b-radio-button>  
    </b-field>  
    <p>{{fruit}}</p>  
  </section>  
</template>  
<script>  
export default {  
  data() {  
    return {  
      radioButton: ""  
    };  
  }  
};  
</script>

The type sets the styles.

b-radio-button render as buttons, but we can only choose one of them between the choices.

Rating Component

We can add a star rating input with the b-rate component.

For example, we can write:

<template>  
  <section>  
    <b-rate custom-text="rating" icon-pack="fa" icon="star"></b-rate>  
  </section>  
</template>  
<script>  
export default {};  
</script>

We set the icon-pack and icon to see the start icon.

It emits the change event:

<template>  
  <section>  
    <b-rate custom-text="rating" @change="success" icon-pack="fa" icon="star"></b-rate>  
  </section>  
</template>  
<script>  
export default {  
  methods: {  
    success() {  
      this.$buefy.toast.open({  
        message: "success",  
        type: "is-success"  
      });  
    }  
  }  
};  
</script>

We can bind the selected value with v-model :

<template>  
  <section>  
    <b-rate custom-text="rating" v-model="rating" icon-pack="fa" icon="star"></b-rate>  
  </section>  
</template>  
<script>  
export default {  
  data() {  
    return {  
      rating: 0  
    };  
  }  
};  
</script>

Conclusion

We can add a star rating and radio buttons with Buefy.