entria-components
entria-components copied to clipboard
Date totally reusable component using moment library
<Date />
Why we not haves a Date component where him it's working nicely with dates where on javascript it's so hard works?
What u think about guys?
This point makes sense?
Is it just for rendering a date, or does it do more?
I think that a component will only make sense when we're rendering something... We have this one that's a wrapper for date-fns
with a custom parser... Maybe we could improve it. 😄
Not, the real intention here it's to works with date through props. But, with that, We'll gonna need a parser where we could export too. Like bellow:
import Date from '@entria/components/Date';
// we can too export a helper for works with date ;) but this, would be only a abstraction from moment
// for example, this helper could named `parseDate`, whatever
import { parseDate } from '@entria/components/Date';
// for date rendering
<Date date={date} />
// or with children (because we can take the children like string and work it)
<Date>{date}</Date>
<Date>{new Date()}</Date> // could be rendering too
// this way, the full prop would be default
<Date>26/10</Date> // could be rendering too
<Date month>26/10</Date> // like that, would render only 10
// but on my think this will gonna helps with examples bellow
// rendering only month in date
<Date month date={date} />
<Date year date={date} />
<Date full date={date} />
There's a lot of possibilities! :tada:
@felippepuhle we can reuse this like a helper and haves a component for that! Of course, we need first improve this helper.
@felippepuhle moment it's better than date-fns
hahaha https://momentjs.com/
But I'm thinking that date-fns
and moment
haves different objectives and we could work with both!
Feel free to send a PR implementing this guy on @entria/utils
... I keep my assertion that it will only be used to render something, but that's awesome too... 🎉
I don't think that's a good idea use both of them(date-fns
and moment
) at the same project... I never used moment
, date-fns
always solved my problems... So, I can't say which one is better \o/
If this it's solving your issues, so this seems be a good idea. But, take a look so on moment project, because I really believe that you'll gonna see than moment lib can safe better the javascript using dates, for a lot of reasons, but take your own, reading it hahaha
With a React component for that we can grow up our possibilities. Think it! @alexandref93 @felippepuhle