1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.createFormattedComponent = exports.createFormattedDateTimePartsComponent = exports.FormattedListParts = exports.FormattedNumberParts = void 0;
|
4 | var tslib_1 = require("tslib");
|
5 | var React = (0, tslib_1.__importStar)(require("react"));
|
6 | var useIntl_1 = (0, tslib_1.__importDefault)(require("./useIntl"));
|
7 | var DisplayName;
|
8 | (function (DisplayName) {
|
9 | DisplayName["formatDate"] = "FormattedDate";
|
10 | DisplayName["formatTime"] = "FormattedTime";
|
11 | DisplayName["formatNumber"] = "FormattedNumber";
|
12 | DisplayName["formatList"] = "FormattedList";
|
13 |
|
14 |
|
15 | DisplayName["formatDisplayName"] = "FormattedDisplayName";
|
16 | })(DisplayName || (DisplayName = {}));
|
17 | var DisplayNameParts;
|
18 | (function (DisplayNameParts) {
|
19 | DisplayNameParts["formatDate"] = "FormattedDateParts";
|
20 | DisplayNameParts["formatTime"] = "FormattedTimeParts";
|
21 | DisplayNameParts["formatNumber"] = "FormattedNumberParts";
|
22 | DisplayNameParts["formatList"] = "FormattedListParts";
|
23 | })(DisplayNameParts || (DisplayNameParts = {}));
|
24 | var FormattedNumberParts = function (props) {
|
25 | var intl = (0, useIntl_1.default)();
|
26 | var value = props.value, children = props.children, formatProps = (0, tslib_1.__rest)(props, ["value", "children"]);
|
27 | return children(intl.formatNumberToParts(value, formatProps));
|
28 | };
|
29 | exports.FormattedNumberParts = FormattedNumberParts;
|
30 | exports.FormattedNumberParts.displayName = 'FormattedNumberParts';
|
31 | var FormattedListParts = function (props) {
|
32 | var intl = (0, useIntl_1.default)();
|
33 | var value = props.value, children = props.children, formatProps = (0, tslib_1.__rest)(props, ["value", "children"]);
|
34 | return children(intl.formatListToParts(value, formatProps));
|
35 | };
|
36 | exports.FormattedListParts = FormattedListParts;
|
37 | exports.FormattedNumberParts.displayName = 'FormattedNumberParts';
|
38 | function createFormattedDateTimePartsComponent(name) {
|
39 | var ComponentParts = function (props) {
|
40 | var intl = (0, useIntl_1.default)();
|
41 | var value = props.value, children = props.children, formatProps = (0, tslib_1.__rest)(props, ["value", "children"]);
|
42 | var date = typeof value === 'string' ? new Date(value || 0) : value;
|
43 | var formattedParts = name === 'formatDate'
|
44 | ? intl.formatDateToParts(date, formatProps)
|
45 | : intl.formatTimeToParts(date, formatProps);
|
46 | return children(formattedParts);
|
47 | };
|
48 | ComponentParts.displayName = DisplayNameParts[name];
|
49 | return ComponentParts;
|
50 | }
|
51 | exports.createFormattedDateTimePartsComponent = createFormattedDateTimePartsComponent;
|
52 | function createFormattedComponent(name) {
|
53 | var Component = function (props) {
|
54 | var intl = (0, useIntl_1.default)();
|
55 | var value = props.value, children = props.children, formatProps = (0, tslib_1.__rest)(props
|
56 |
|
57 | , ["value", "children"]);
|
58 |
|
59 | var formattedValue = intl[name](value, formatProps);
|
60 | if (typeof children === 'function') {
|
61 | return children(formattedValue);
|
62 | }
|
63 | var Text = intl.textComponent || React.Fragment;
|
64 | return React.createElement(Text, null, formattedValue);
|
65 | };
|
66 | Component.displayName = DisplayName[name];
|
67 | return Component;
|
68 | }
|
69 | exports.createFormattedComponent = createFormattedComponent;
|