What is the best way to customize the look of the v-calendar component in Vue.js?

I've recently started a project that involves Vue.js, and I needed to create a datepicker for it. After some research, I opted to utilize the v-calendar package.

The implementation of the component went smoothly and functioned as expected right out of the box. However, when I attempted to customize the styles according to the documentation, I encountered some issues in certain cases, and I'm struggling to identify the cause.

The goal is to achieve a design similar to this:

https://i.stack.imgur.com/LEJBW.png

While I managed to style the header using setupCalendar, applying the same style to the content has proven unsuccessful. Upon further inspection of the documentation, I noticed that they were passing the style as attributes. I tried replicating this method without success.

Additionally, I am curious if there is a way to automatically pass on the received $attrs from the parent-component to the input field? Currently, I am manually assigning each attribute using input-props. Is there a more efficient approach for this task?

Presently, my code structure looks like this:

https://i.stack.imgur.com/0G2zM.png

<template>
    <date-picker
        :attributes="attributes"
        v-model="date"
        :input-props="{
            id: $attrs.id,
            name: $attrs.name,
            class: 'input--default color--white',
            autocomplete: 'nope',
            readonly: true
        }"
    >
    </date-picker>
</template>

<script>
    // packages
    import { setupCalendar, DatePicker } from 'v-calendar'
    import 'v-calendar/lib/v-calendar.min.css';

    setupCalendar({
        locale: 'pt-PT',
        themeStyles: {
            wrapper: {
                fontSize: '17px',
                lineHeight: '21px',
                boxShadow: '5px 5px 10px 1px rgba( 0, 0, 0, .10 )',
            },
            header: {
                color: '#f7890b',
                textTransform: 'capitalize'
            },
            weekdays: {
                color: '#ededed'
            },
        },
         attributes: [{
            contentStyle: {
                color: '#ff4d4d', // Red
                fontWeight: 600,
                fontSize: '10px',
            },
            popover: { color: 'yellow', },
            highlight: {
                backgroundColor: 'purple',
            },
        }]

    });

    export default {
        inheritAttrs: false,
        components: {
            DatePicker
        },
        data () {
            return {
                date: null,
                attributes: [{
                    contentStyle: {
                        color: '#ff4d4d', // Red
                        fontWeight: 600,
                        fontSize: '10px',
                    },
                    popover: { color: 'yellow', },
                    highlight: {
                        backgroundColor: 'purple',
                    },
                }]
            }
        }
    }
</script>

<style>

</style>

Answer №1

To modify the CSS style in vue-datepicker, you can include these styles in your .css file or within your view using <style> ...</style>

Below is a example of how you can style the elements, such as changing the input to a Bootstrap style:

body {
  font-family: 'Helvetica Neue Light', Helvetica, sans-serif;
  padding: 1em 2em 2em;
}
input,
select {
  padding: 0.75em 0.5em;
  font-size: 100%;
  border: 1px solid #ccc;
  width: 100%;
}

select {
  height: 2.5em;
}

.example {
  background: #f2f2f2;
  border: 1px solid #ddd;
  padding: 0em 1em 1em;
  margin-bottom: 2em;
}

code,
pre {
  margin: 1em 0;
  padding: 1em;
  border: 1px solid #bbb;
  display: block;
  background: #ddd;
  border-radius: 3px;
}

.settings {
  margin: 2em 0;
  border-top: 1px solid #bbb;
  background: #eee;
}

h5 {
  font-size: 100%;
  padding: 0;
}

.form-group {
  margin-bottom: 1em;
}

.form-group label {
  font-size: 80%;
  display: block;
}

Answer №2

    attrs: [
        {
          highlight: {
            style: {
              borderRadius: "6px",
              // border: '1px solid #1982EF',
              backgroundColor: "#ccd6e0b3",
            },
            contentStyle: {
              fontWeight: "700",
            },
          },
          dates: new Date(),
        },
        {
          dot: {
            style: {
              backgroundColor: "#53af52",
              marginBottom: "3px",
            },
          },
          dates: [],
        },
        {
          dot: {
            style: {
              backgroundColor: "#f2a000",
              marginBottom: "3px",
            },
          },
          dates: [],
        },
      ],

//this type of styling is fully supported in v-calendar and can be implemented as shown.

Answer №3

Insert it within the template tag:

Include it inside the script tag:

import Calendar from "v-calendar/lib/components/calendar.umd";

When setting data variables:

attrs: [

    {
      highlight: {
        style: {
          borderRadius: '6px',
          border: '2px solid #1982EF'
        },
      },
      dates: new Date()
    },
    {
      dot: {
        style: {
          backgroundColor: '#53af52',
          marginBottom: '3px',
        },
      },
      dates: [],
    },
    {
      dot: {
        style: {
          backgroundColor: '#f2a000',
          marginBottom: '3px',
        },
      },
      excludeDates: null,
    },
    {
      content: {
        style: {
          display:'none !important'
        },
      },
      excludeDates: null,
    }
  ],

These attrs are provided to the v-calendar component as a prop to manage styles.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to wrap `useFetch` in order to leverage reactivity?

When I wrap useFetch() as a composable to customize the baseURL and automatically set an authentication token, I encounter reactivity issues when calling the composable within a component without using the await keyword. Typically, I would call const { dat ...

Whenever I nest my div tags within another div element in an HTML document

Whenever I try to position a div inside another div using float, I encounter problems. <div id="main"> <div id="anotherDiv"> <h1>Test</h1> </div> </div> Here is the corresponding style sheet: #main{ ba ...

Enhance accessibility: Improving screen reader and tab focus behavior with vue-router

It seems that focus resetting and screen readers detecting route changes are not integrated into vue-router. I understand why Vue might have omitted this feature, considering the varying use cases, but I am surprised by the lack of information on accessib ...

What can be done to stop the Datepicker from exiting the Dialog box and causing it to malfunction?

While creating a form inside a dialog box, I encountered an issue with the date picker functionality. Whenever I try to select a date, it disappears and breaks, rendering the last days of the calendar inaccessible. You can view an example of this problem i ...

Obtain and utilize the background color to easily implement the same color in another window

For my Chrome Extension project, I am looking to retrieve the background color of the current page and then set the background color of a window to match. Can someone guide me on how to accomplish this using JavaScript (with or without jQuery), and if ne ...

Tips for incorporating Material.io outlined icons within css pseudoelements (::before) usage

I'm attempting to incorporate the Material.io icon into a button using ::before, but it is appearing filled rather than outlined. Unfortunately, there are no available instructions on how to display the icon in an outlined style. This is the code I ...

Troubleshooting a Next.js background image problem when hosting on Netlify

I've encountered an issue while attempting to deploy a nextjs website on Netlify. Everything works perfectly on my local server, but once it's on Netlify, the background image URL changes and the image becomes invisible. Original CSS code: backg ...

The CSS scale property is not working as expected when used in a React.js application, specifically

working environment ・next.js ・react ・typescript https://www.youtube.com/watch?v=ujlpzTyJp-M A Toolchip was developed based on the referenced video. However, the --scale: 1; property is not being applied. import React, { FunctionComponent ...

Disable Button's Shadow when it is in an active state (clicked)

Check out the DEMO to see the button animation CSS in action. The CSS code for the button animations is as follows: .btnliner { /* CSS properties */ } /* More CSS properties */ .btnliner:hover { /* Hover effects */ } Here is the corresponding J ...

Issue arises when applying both overflow-x:scroll and justify-content:center

Encountering a problem with using overflow-x: scroll and justify-content: center on a flex parent container. Here is my code snippet: The issue: the first flex child item is not visible as it is cropped on the left side. Please refer to the screenshot and ...

Adding a line and text as a label to a rectangle in D3: A step-by-step guide

My current bar graph displays values for A, B, and C that fluctuate slightly in the data but follow a consistent trend, all being out of 100. https://i.stack.imgur.com/V8AWQ.png I'm facing issues adding lines with text to the center of each graph. A ...

The issue with the jQuery class change not being triggered in Internet Explorer seems to be isolated, as Chrome and

This little jQuery script I have is supposed to show a fixed navigation menu once the page has been scrolled below 200px, and then change the class on each menu list item to "current" when that section reaches the top of the viewport. The issue is that th ...

Preserve proportions while resizing the browser window

I needed my code to ensure that the images keep their aspect ratio regardless of the screen size or if the user resizes their browser instead of viewing it full screen. I have some code in place, but I'm unsure how to maintain the current effects of ...

Use JQuery to constantly monitor for any changes in HTML Div

I am dealing with a browser-based chat application where separate div elements are generated for each chat conversation. An external module oversees the entire chat process, and I do not have access to its underlying code. It is important to note that the ...

regarding unfamiliar functions in code and their mysterious purposes

My journey learning Vue.js has been going well, but I've hit a roadblock. Can someone explain the meaning of _. in the following code snippet? ...

Steps for shaping the dialog of Material-UI to fit an image

Is there a way to adjust the size of the dialog box to match that of the image? https://i.stack.imgur.com/pXtXg.png I've also tried changing the background color to transparent without success. https://i.stack.imgur.com/Hjx2x.png ...

Exploring ways to style font families for individual options within ng-options

I am looking to display a combobox where each option has a different font. While using the ng-options directive in AngularJS to populate the options for a <select> tag, I am struggling to set the font-family for individual options. $scope.reportFon ...

How can I switch the visibility of two A HREF elements by clicking on one of them?

Let me break it down for you in the simplest way possible. First off, there's this <a href="#" id="PAUSE" class="tubular-pause">Pause</a> and then we have a second one <a href="#" id="PLAY" class="tubular-play">Play</a> Al ...

Revamping Vue file with real-time updates using Laravel Echo Pusher Notifs

Over the last few days, I've been attempting to create a template that auto-reloads whenever there are new updates in the "Notifications" section. This could be due to a new entry being added or a notification being marked as read. Currently, I' ...

Looking for a way to exclude both parents and children from a list of relatives? Want to ensure that the

I've been struggling to align these list elements with their counterparts, but they seem to automatically create a margin for their child elements. It is essential for these list items to maintain the position:relative attribute so that the #dropdown ...