Date formatting support in @mantine/dates should have the option not use dayjs #9104
ctalibard
started this conversation in
Feature requests
Replies: 1 comment 1 reply
|
Hi! Most of what you are asking for is already supported — the pieces just are not documented together, so it is easy to miss. All formatting hooks in import { createTheme, MantineProvider } from '@mantine/core';
import { DatesProvider } from '@mantine/dates';
const theme = createTheme({
components: {
DatePickerInput: {
defaultProps: {
valueFormatter: ({ date, locale }) =>
new Intl.DateTimeFormat(locale, { dateStyle: 'full' }).format(new Date(date)),
},
},
DateTimePicker: {
defaultProps: {
valueFormat: (date) =>
new Intl.DateTimeFormat('en-US', { dateStyle: 'medium', timeStyle: 'short' }).format(
new Date(date)
),
},
},
DatePicker: {
defaultProps: {
monthLabelFormat: (date) =>
new Intl.DateTimeFormat('en-US', { month: 'long', year: 'numeric' }).format(
new Date(date)
),
},
},
},
});
function App() {
return (
<MantineProvider theme={theme}>
<DatesProvider settings={{ locale: i18n.language }}>{/* ... */}</DatesProvider>
</MantineProvider>
);
}Note that Props that already accept a function
What is not covered yet
So points 1–3 above are the parts of your request that are genuinely missing, and they seem reasonable to add. |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
HI,
I was disappointed to discover that the date inputs, calendar and schedule components in the extensions do not use
Intl.DateTimeFormat. I'm using i18next to localise all my strings. Currently in order to get dates to format properly I have to:detectedLanguagefrom i18next into theDateProvider localeThis is a lot of error-prone heavy lifting, and bundle bloat for something that should be as simple as
new Intl.DateTimeFormat(locale, options).format(date). Am I missing something?I'm not expecting you to replace they way you currently do formatting, but it might be a good idea to provide some optional props to
<DatesProvider>to allow me to override the default formatters. I could just give you a function to format dates the way I want.All reactions