-
-
Notifications
You must be signed in to change notification settings - Fork 356
/
Copy pathDatetimeFormat.ts
90 lines (84 loc) · 2.64 KB
/
DatetimeFormat.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { defineComponent } from 'vue'
import { assign } from '@intlify/shared'
import { DATETIME_FORMAT_OPTIONS_KEYS } from '@intlify/core-base'
import { useI18n } from '../i18n'
import { DatetimePartsSymbol } from '../symbols'
import { renderFormatter } from './formatRenderer'
import { baseFormatProps } from './base'
import type { VNodeProps } from 'vue'
import type { DateTimeOptions } from '@intlify/core-base'
import type { Composer, ComposerInternal } from '../composer'
import type { FormattableProps } from './formatRenderer'
import type { BaseFormatProps } from './base'
/**
* DatetimeFormat Component Props
*
* @VueI18nComponent
*/
export type DatetimeFormatProps = FormattableProps<
number | Date,
Intl.DateTimeFormatOptions
>
export const DatetimeFormatImpl = /* #__PURE__*/ defineComponent({
/* eslint-disable */
name: 'i18n-d',
props: assign(
{
value: {
type: [Number, Date],
required: true
},
format: {
type: [String, Object]
}
},
baseFormatProps
),
/* eslint-enable */
// eslint-disable-next-line @typescript-eslint/no-explicit-any
setup(props: any, context: any): any {
const i18n =
props.i18n ||
(useI18n({
useScope: props.scope as 'global' | 'parent',
__useComponent: true
}) as unknown as Composer & ComposerInternal)
return renderFormatter<
FormattableProps<number | Date, Intl.DateTimeFormatOptions>,
number | Date,
Intl.DateTimeFormatOptions,
DateTimeOptions,
Intl.DateTimeFormatPart
>(
props as DatetimeFormatProps,
context,
DATETIME_FORMAT_OPTIONS_KEYS,
(...args: unknown[]) =>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(i18n as any)[DatetimePartsSymbol](...args)
)
}
})
/**
* Datetime Format Component
*
* @remarks
* See the following items for property about details
*
* @VueI18nSee [FormattableProps](component#formattableprops)
* @VueI18nSee [BaseFormatProps](component#baseformatprops)
* @VueI18nSee [Custom Formatting](../guide/essentials/datetime#custom-formatting)
*
* @VueI18nDanger
* Not supported IE, due to no support `Intl.DateTimeFormat#formatToParts` in [IE](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatToParts)
*
* If you want to use it, you need to use [polyfill](https://github.com/formatjs/formatjs/tree/main/packages/intl-datetimeformat)
*
* @VueI18nComponent
*/
export const DatetimeFormat = DatetimeFormatImpl as unknown as {
new (): {
$props: VNodeProps & DatetimeFormatProps & BaseFormatProps
}
}
export const I18nD = DatetimeFormat