Tips on personalizing chosen date formats within the Mantine DatePicker?

I've integrated the Mantine DatePicker into my web application and now I want to customize the default style for when a user selects a date.

Here's the current style:

https://i.sstatic.net/hjQOi.png

This is what I'm aiming for:

https://i.sstatic.net/kroSY.png

After reading through the documentation of Mantine DatePicker here, I discovered getDayProps which can help me add styles to the dates. However, I'm unsure about how to implement it.

So far, I have tried this code which changes the color on hovering over a date:


        <DatePicker
          value={value}
          onChange={setValue}   
          getDayProps={() => {
            return {
              sx: (theme) => ({
                backgroundColor: theme.colors.red[6],
                color: theme.black,
                ...theme.fn.hover({
                  backgroundColor: theme.colors.violet[7],
                  color: theme.white,
                }),
              }),
            };
          }}
        />

Answer №1

After some experimenting, I figured it out:

If you're using just the Date Picker:

<DatePicker
  date={date}
  onDateChange={setDate}
  value={value}
  onChange={handleChange}
  styles={{
    day: {
      "&[data-selected], &[data-selected]:hover": {
        backgroundColor: `${accentColor}`,
        color: "white",
      },
    },
  }}
/>

And for the DatePicker with type="range":

<DatePickerInput
  type="range"
  valueFormat="DD MMM, YY"
  value={value}
  onChange={setValue}
  numberOfColumns={2}
  placeholder="Pick dates range"
  styles={{
    day: {
      "&[data-selected], &[data-selected]:hover": {
        backgroundColor: `${accentColor}`,
        color: "white",
      },

      "&[data-in-range], &[data-in-range]:hover": {
        backgroundColor: `${accentColor}`,
        color: "white",
        opacity: "0.5",
      },

      "&[data-first-in-range], &[data-first-in-range]:hover": {
        backgroundColor: `${accentColor}`,
        color: "white",
        opacity: "1",
      },

      "&[data-last-in-range], &[data-last-in-range]:hover": {
        backgroundColor: `${accentColor}`,
        color: "white",
        opacity: "1",
      },
    },
    input: {
      "&:focus": {
        borderColor: accentColor,
      },
    },
  }}
/>

To learn more, check out DatePicker Styles API. You can also find guidance on utilizing Mantine Styles API in How to use Mantine Styles API.

Answer №2

To modify the color of the chosen date, apply custom styling with the following CSS class: .mantine-DatePicker-day[data-selected]

Simply insert the code snippet below into your stylesheet:

.mantine-DatePicker-day[data-selected]{
  background-color: #7048E8 !important;
}

We trust this solution will meet your needs.

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

The page is constantly updating on its own

In my React app, the App component checks for a token in local storage upon loading. If a token is found, it is verified. If the token is valid, the user is directed to the dashboard; otherwise, they are taken to the login page. The issue I am facing is ...

The efficient method of storing application activity logs using one schema and minimal details in MongoDB within a Node.js environment

Looking for a way to efficiently log application actions in a Node.js project with MongoDB database. We aim to include limited information such as success, action name, user id, time, etc. Any suggestions or best practices for achieving this in Node.js w ...

Tips for connecting an input tag within a popover to a Vue Model

I've got an input nested inside a popover content as shown below: JSFiddle Link HTML code snippet: <div id="vue-app"> <div class="btn btn-primary" data-toggle="popover" data-placement="bottom" title="Hello World!" data-html="true" data ...

The inner workings of v8's fast object storage method

After exploring the answer to whether v8 rehashes when an object grows, I am intrigued by how v8 manages to store "fast" objects. According to the response: Fast mode for property access is significantly faster, but it requires knowledge of the object&ap ...

Is there a way to showcase a Bootstrap popover using HTML content sourced from a GridView?

I've spent the last couple of hours experimenting with this, trying different things. I can successfully display a popover with basic title and content, but I'm struggling to make it work with HTML and Eval() as the content. Here's my curren ...

What is the process for incorporating a compiled JavaScript library into a TypeScript project?

In my Typescript project (ProjectA), I am utilizing several node packages. Additionally, I have a babel project (ProjectB) with a build configuration that supports output for multiple module definition standards such as amd, common.js, and esm. My questio ...

"Is it possible to use a Twitter widget with Mootools

I have been attempting to create a marquee for my twitter Account on my website. After some trial and error, I was able to achieve this using jQuery. Here is the code I used: <div id="twitter"> <p> Loading.....</p> <n ...

Using the onClick event to dynamically alter the class name within a mapped array by leveraging Hooks

I'm currently working on developing an answer sheet, commonly known as a "Bubble sheet", where the user has the ability to select either "A,B,C, or D" and see the bubble transition from light mode to dark mode just like when marking with a physical pe ...

Storing values globally in NodeJS from request headers

What is the most effective way to store and access the value from a request header in multiple parts of my application? One approach could be as shown in the following example from app.js: app.get('*', (req, res) => { global.exampleHeader ...

The changes made in the CSS file are not reflected in the browser

Recently, I encountered a strange issue with my new server where the CSS changes were not reflecting in the browser. Despite trying to refresh and clear the cache, the problem persisted. To investigate further, I used FileZilla to check if the updated CSS ...

What could be causing this error message to appear during my Storybook build process?

Recently, I made the leap of upgrading Storybook from V6.5.9 to V7.1.0 within a dynamic Next.js project. Surprisingly, everything seemed to be working fine until I attempted to build my storybook and encountered this perplexing error: ERR! => Failed to ...

Using JSON to update the state data of the App component in React

I am currently working on loading Json data in a react component. Within my two components ProjectCardContainer and ProjectDetailPage, I am trying to display the data from the App state when clicking on a link within an <h6> element. However, I disco ...

Pairing a removal request with a JSON entity

I am currently working on a project where I need to delete a specific JSON object from a JSON file once its values are displayed in a form using the AJAX Delete function. In order to achieve this, I have set up a route in Express for the JSON file as shown ...

Error Alert: Redux unable to retrieve data from Django API due to CORS issue

Currently, I am working on a project with a frontend application running on http://localhost:3000 and a backend API on http://localhost:8000. However, I am facing a CORS issue when trying to make requests from the frontend to the backend API. The error me ...

Does Material UI have a collapsible component that includes a "showmore" feature?

After observing the frequent use of the showmore feature in Google design, I began to wonder if there is a similar component available in Material UI. Can anyone confirm? If my description is inaccurate, it appears like this: https://i.stack.imgur.com/Jpy ...

Having trouble retrieving a response when using axios.put(...) even though the document is being successfully updated in the MongoDB database

In my React project, I am utilizing axios to update the database in MongoDB. const handleEditFormSubmit = async (editdata) =>{ try{ const id = tabledata[editCategory-1]._id; let body ={} body = {...body, ["Category"]:editdata[ ...

Looking to create a GitHub example in Fiddle but running into issues with getting the result?

I've been working on an example on Fiddle, but it's not functioning as expected. I want to implement i18next so that the text changes when the user switches languages. After searching for a solution, I came across this GitHub repository: https:// ...

Identify HTML elements within a textarea or text input using JavaScript while also accommodating the common special characters ">" and "<"

Is there a way to accurately detect HTML tags in textarea or text input fields before submitting a form? While it may seem straightforward to use regular expressions like /<\/?[^>]*>/gi.test(str) for this purpose, the challenge arises when de ...

Understanding how to use the 'this' variable in Vue components is essential for efficiently modifying DOM elements. Let's dive into a clarification on the usage of 'this'

Within my vue component, the structure is as follows: export default{ name: '', data: function () { return { var1 :{}, var2 : {}, ... } }, created: function () { this.methodName1() }, methods: { me ...

The layout created with Tailwind did not meet our expectations in terms of the value obtained

Choose the shape you desire. Click here to view image The current shape looks like this... Click here to view image bar : h-14 nav : h-full content : h-full footer : h-14 I am trying to create a layout similar to this using tailwind CSS, but it's no ...