r/learnprogramming • • 29d ago

Question How do web applications and the such make and style their date pickers and the sort?

I've seen countless web applications and sites use custom, flexible date pickers with modern UI that match their brand, but even after searching countlessly online I still have no answer as to how. Headless component libraries... DatePicker libraries... stick with native... I don't know any of it. I just want to know how to style the native date input to match my personal project's brand. Please can anyone help me understand how it is handled in the current era as I've heard that building my own picker is a nightmare and hell hole and nothing else...

3 Upvotes

13 comments sorted by

2

u/-Nocx- 29d ago

If I’m understanding your question properly, they hire an artist for any icons they might use, but for the most part they just replace the CSS. In my experience most people use bootstrap for these components, so you can edit the bootstrap CSS file directly.

The visual interface of your components is just CSS files. It isn’t magic. Either it’s loading an image or styling a selector. You don’t need an additional library, package, or framework to do that.

2

u/ToshiryuShadow 29d ago

But doesnt the date picker change across browsers and native styling is severely limited with -webkit prefixes and the such? I thought ppl used date picker libs for this which lead me into a library rabbit hole...

2

u/-Nocx- 29d ago

You can set different styles for each browser configuration. You can even set different styles for mobile, iPad, etc.

There might be some libraries that try to simplify it, but it’s a lot simpler to reduce your dependencies rather than rely on having to version a new tool / train people on it.

But even if you found a library to do it… it wouldn’t change what it’s doing underneath the hood.

Then again, I’m mostly a backend developer and a pretty mediocre front end developer, so maybe someone more knowledgeable can help you.

2

u/ToshiryuShadow 29d ago

different styles for all cases... will be a pretty big ordeal? As far as I know, headless libs and the such provide a good solution as u get full styling rights while it handles all the complex logic, but I might be missing something and from my search so far, there hasn't been similar questions brought up previously which prompted me to make this post. I was thinking of going native, but I'll wait and see what other people have in mind as I too am still in the process of learning all this. I appreciate taking the time to help me, thank you!

1

u/dmazzoni 29d ago

That's if you use <input type=date>. You don't have to use that.

Use something like this and style it to match your site:

https://mui.com/x/react-date-pickers/date-picker/

1

u/ToshiryuShadow 29d ago

Oh thanks, I'll be sure to check it out.

1

u/Quesadillamexicana77 29d ago

Native date inputs are pretty limited for styling, you can change the input box itself but not the calendar popup, which is drawn by the browser. That's why most apps use a headless library like React Aria, Radix or react-day-picker, where it handles the keyboard stuff, accessibility and date logic and you write all the markup and CSS yourself. I wouldn't build one from scratch, the pain is in edge cases like locales, time zones and screen readers. If you're not on React, flatpickr or Pikaday are simple and easy to theme with CSS variables.

1

u/ToshiryuShadow 29d ago

I was choosing between React Aria and React Day Picker and I've heard that React Aria is more easy/flexible to style your way and has superior accessibility according to online resources, but React Aria seems a bit too much for my personal project. Will React Day Picker suffice for handling Dates, Times and IANA Timezone Identifiers?

2

u/Mexicanito151551 28d ago

React Day Picker is plenty for dates and times. It handles locale formatting, ranges, disabled days and keyboard nav out of the box. For time zones it does not do the conversion itself though, it just gives you plain JS Date objects, so pair it with date-fns-tz or Luxon and store everything as UTC, then convert to the IANA zone only when you display it. React Aria is nicer if you want a fully custom look, but for a personal project I'd start with Day Picker and only switch if you hit a wall.

1

u/ToshiryuShadow 28d ago

That sounds perfect. Hearing the others suggestions have really improved my confidence in the choice. Ill go with React Day Picker. Thanks for the input!

1

u/kschang 29d ago

Using an existing toolkit / css framework. Lots to choose from.