@react-spectrum/labeledvalue 3.1.18 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/LabeledValue.main.js +9 -6
- package/dist/LabeledValue.main.js.map +1 -1
- package/dist/LabeledValue.mjs +10 -7
- package/dist/LabeledValue.module.js +10 -7
- package/dist/LabeledValue.module.js.map +1 -1
- package/dist/types.d.ts +10 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/{vars.b904ab57.css → vars.6c953d9a.css} +3 -3
- package/dist/{vars.b904ab57.css.map → vars.6c953d9a.css.map} +1 -1
- package/package.json +10 -9
- package/src/LabeledValue.tsx +30 -10
@@ -1,4 +1,4 @@
|
|
1
|
-
require("./vars.
|
1
|
+
require("./vars.6c953d9a.css");
|
2
2
|
var $eb2fc0ee655eff6b$exports = require("./fieldlabel_vars_css.main.js");
|
3
3
|
var $lcZyr$internationalizeddate = require("@internationalized/date");
|
4
4
|
var $lcZyr$reactspectrumutils = require("@react-spectrum/utils");
|
@@ -34,9 +34,14 @@ $parcel$export(module.exports, "LabeledValue", () => $2a7417c2df2197f7$export$d1
|
|
34
34
|
|
35
35
|
|
36
36
|
|
37
|
-
|
37
|
+
const $2a7417c2df2197f7$export$d1328f67a56fa517 = /*#__PURE__*/ (0, ($parcel$interopDefault($lcZyr$react))).forwardRef(function LabeledValue(props, ref) {
|
38
38
|
let { value: value, formatOptions: formatOptions } = props;
|
39
39
|
let domRef = (0, $lcZyr$reactspectrumutils.useDOMRef)(ref);
|
40
|
+
(0, $lcZyr$react.useEffect)(()=>{
|
41
|
+
if ((domRef === null || domRef === void 0 ? void 0 : domRef.current) && domRef.current.querySelectorAll('input, [contenteditable], textarea').length > 0) throw new Error('LabeledValue cannot contain an editable value.');
|
42
|
+
}, [
|
43
|
+
domRef
|
44
|
+
]);
|
40
45
|
let children;
|
41
46
|
if (Array.isArray(value)) children = /*#__PURE__*/ (0, ($parcel$interopDefault($lcZyr$react))).createElement($2a7417c2df2197f7$var$FormattedStringList, {
|
42
47
|
value: value,
|
@@ -59,6 +64,7 @@ function $2a7417c2df2197f7$var$LabeledValue(props, ref) {
|
|
59
64
|
formatOptions: formatOptions
|
60
65
|
});
|
61
66
|
if (typeof value === 'string') children = value;
|
67
|
+
if (/*#__PURE__*/ (0, ($parcel$interopDefault($lcZyr$react))).isValidElement(value)) children = value;
|
62
68
|
return /*#__PURE__*/ (0, ($parcel$interopDefault($lcZyr$react))).createElement((0, $lcZyr$reactspectrumlabel.Field), {
|
63
69
|
...props,
|
64
70
|
wrapperProps: (0, $lcZyr$reactariautils.filterDOMProps)(props),
|
@@ -66,7 +72,7 @@ function $2a7417c2df2197f7$var$LabeledValue(props, ref) {
|
|
66
72
|
elementType: "span",
|
67
73
|
wrapperClassName: (0, $lcZyr$reactspectrumutils.classNames)((0, ($parcel$interopDefault($eb2fc0ee655eff6b$exports))), 'spectrum-LabeledValue')
|
68
74
|
}, /*#__PURE__*/ (0, ($parcel$interopDefault($lcZyr$react))).createElement("span", null, children));
|
69
|
-
}
|
75
|
+
});
|
70
76
|
function $2a7417c2df2197f7$var$FormattedStringList(props) {
|
71
77
|
let stringFormatter = (0, $lcZyr$reactariai18n.useListFormatter)(props.formatOptions);
|
72
78
|
return /*#__PURE__*/ (0, ($parcel$interopDefault($lcZyr$react))).createElement((0, ($parcel$interopDefault($lcZyr$react))).Fragment, null, stringFormatter.format(props.value));
|
@@ -128,9 +134,6 @@ function $2a7417c2df2197f7$var$convertValue(value) {
|
|
128
134
|
let date = (0, $lcZyr$internationalizeddate.today)((0, $lcZyr$internationalizeddate.getLocalTimeZone)());
|
129
135
|
return (0, $lcZyr$internationalizeddate.toCalendarDateTime)(date, value);
|
130
136
|
}
|
131
|
-
/**
|
132
|
-
* A LabeledValue displays a non-editable value with a label. It formats numbers, dates, times, and lists according to the user's locale.
|
133
|
-
*/ let $2a7417c2df2197f7$export$d1328f67a56fa517 = /*#__PURE__*/ (0, ($parcel$interopDef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QAAC,MAAM;QAAW,OAAO;QAAQ,KAAK;QAAW,MAAM;QAAW,QAAQ;QAAW,UAAU,MAAM,QAAQ;QAAE,cAAc;IAAO;SACtI,IAAI,UAAU,SAAS,UAAU,OACtC,OAAO;QAAC,WAAW;QAAQ,WAAW;IAAO;SACxC,IAAI,UAAU,OACnB,OAAO;QAAC,WAAW;IAAO;SAE1B,OAAO;QAAC,WAAW;IAAM;AAE7B;AAEA,SAAS,mCAAa,KAAW;IAC/B,IAAI,OAAO,CAAA,GAAA,kCAAI,EAAE,CAAA,GAAA,6CAAe;IAEhC,OAAO,CAAA,GAAA,+CAAiB,EAAE,MAAM;AAClC;AAEA;;CAEC,GACD,IAAI,0DAAgB,CAAA,GAAA,sCAAI,EAAE,UAAU,CAAC","sources":["packages/@react-spectrum/labeledvalue/src/LabeledValue.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {CalendarDate, CalendarDateTime, getLocalTimeZone, Time, toCalendarDateTime, today, ZonedDateTime} from '@internationalized/date';\nimport {classNames, useDOMRef} from '@react-spectrum/utils';\nimport type {DOMProps, DOMRef, RangeValue, SpectrumLabelableProps, StyleProps} from '@react-types/shared';\nimport {Field} from '@react-spectrum/label';\nimport {filterDOMProps} from '@react-aria/utils';\nimport labelStyles from '@adobe/spectrum-css-temp/components/fieldlabel/vars.css';\nimport React, {ReactNode} from 'react';\nimport {useDateFormatter, useListFormatter, useNumberFormatter} from '@react-aria/i18n';\n\n// NOTE: the types here need to be synchronized with the ones in docs/types.ts, which are simpler so the documentation generator can handle them.\n\nexport interface LabeledValueBaseProps extends DOMProps, StyleProps, Omit<SpectrumLabelableProps, 'necessityIndicator' | 'isRequired'>, DOMProps {\n /** The content to display as the label. */\n label: ReactNode\n}\n\ntype NumberValue = number | RangeValue<number>;\ninterface NumberProps<T extends NumberValue> {\n /** The value to display. */\n value: T,\n /** Formatting options for the value. */\n formatOptions?: Intl.NumberFormatOptions\n}\n\nexport type DateTime = Date | CalendarDate | CalendarDateTime | ZonedDateTime | Time;\ntype RangeDateTime = RangeValue<DateTime>;\ntype DateTimeValue = DateTime | RangeDateTime;\ninterface DateProps<T extends DateTimeValue> {\n /** The value to display. */\n value: T,\n /** Formatting options for the value. */\n formatOptions?: Intl.DateTimeFormatOptions\n}\n\ninterface StringProps<T extends string> {\n /** The value to display. */\n value: T,\n /** Formatting options for the value. */\n formatOptions?: never\n}\n\ninterface StringListProps<T extends string[]> {\n /** The value to display. */\n value: T,\n /** Formatting options for the value. */\n formatOptions?: Intl.ListFormatOptions\n}\n\ntype LabeledValueProps<T> =\n T extends NumberValue ? NumberProps<T> :\n T extends DateTimeValue ? DateProps<T> :\n T extends string[] ? StringListProps<T> :\n T extends string ? StringProps<T> :\n never;\n\ntype SpectrumLabeledValueTypes = string[] | string | Date | CalendarDate | CalendarDateTime | ZonedDateTime | Time | number | RangeValue<number> | RangeValue<DateTime>;\nexport type SpectrumLabeledValueProps<T> = LabeledValueProps<T> & LabeledValueBaseProps;\n\nfunction LabeledValue<T extends SpectrumLabeledValueTypes>(props: SpectrumLabeledValueProps<T>, ref: DOMRef<HTMLElement>) {\n let {\n value,\n formatOptions\n } = props;\n let domRef = useDOMRef(ref);\n\n let children;\n if (Array.isArray(value)) {\n children = <FormattedStringList value={value} formatOptions={formatOptions as Intl.ListFormatOptions} />;\n }\n\n if (typeof value === 'object' && 'start' in value && typeof value.start === 'number' && typeof value.end === 'number') {\n children = <FormattedNumber value={value as NumberValue} formatOptions={formatOptions as Intl.NumberFormatOptions} />;\n }\n\n if (typeof value === 'object' && 'start' in value && typeof value.start !== 'number' && typeof value.end !== 'number') {\n children = <FormattedDate value={value as DateTimeValue} formatOptions={formatOptions as Intl.DateTimeFormatOptions} />;\n }\n\n if (typeof value === 'number') {\n children = <FormattedNumber value={value} formatOptions={formatOptions as Intl.NumberFormatOptions} />;\n }\n\n if (typeof value === 'object' && ('calendar' in value || 'hour' in value) || (value instanceof Date)) {\n children = <FormattedDate value={value} formatOptions={formatOptions as Intl.DateTimeFormatOptions} />;\n }\n\n if (typeof value === 'string') {\n children = value;\n }\n\n return (\n <Field {...props as any} wrapperProps={filterDOMProps(props as any)} ref={domRef} elementType=\"span\" wrapperClassName={classNames(labelStyles, 'spectrum-LabeledValue')}>\n <span>{children}</span>\n </Field>\n );\n}\n\nfunction FormattedStringList<T extends string[]>(props: StringListProps<T>) {\n let stringFormatter = useListFormatter(props.formatOptions);\n\n return (\n <>{stringFormatter.format(props.value)}</>\n );\n}\n\nfunction FormattedNumber<T extends NumberValue>(props: NumberProps<T>) {\n let numberFormatter = useNumberFormatter(props.formatOptions);\n let value = props.value;\n\n if (typeof value === 'object') {\n return <>{numberFormatter.formatRange(value.start, value.end)}</>;\n }\n\n return <>{numberFormatter.format(value)}</>;\n}\n\nfunction FormattedDate<T extends DateTimeValue>(props: DateProps<T>) {\n let {value, formatOptions} = props;\n if (!formatOptions) {\n formatOptions = getDefaultFormatOptions('start' in value ? value.start : value);\n }\n\n let dateFormatter = useDateFormatter(formatOptions);\n let timeZone = dateFormatter.resolvedOptions().timeZone || getLocalTimeZone();\n let final: Date;\n\n if ('start' in value && 'end' in value) {\n let start = value.start;\n let end = value.end;\n\n start = convertDateTime(start, timeZone);\n end = convertDateTime(end, timeZone);\n\n return <>{dateFormatter.formatRange(start, end)}</>;\n }\n\n final = convertDateTime(value, timeZone);\n return <>{dateFormatter.format(final)}</>;\n}\n\nfunction convertDateTime(value: DateTime, timeZone: any) {\n if ('timeZone' in value) {\n return value.toDate();\n } else if ('calendar' in value) {\n return value.toDate(timeZone);\n } else if (!(value instanceof Date)) {\n return convertValue(value).toDate(timeZone);\n }\n\n return value;\n}\n\nfunction getDefaultFormatOptions(value: DateTime): Intl.DateTimeFormatOptions {\n if (value instanceof Date) {\n return {dateStyle: 'long', timeStyle: 'short'};\n } else if ('timeZone' in value) {\n return {year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric', timeZone: value.timeZone, timeZoneName: 'short'};\n } else if ('hour' in value && 'year' in value) {\n return {dateStyle: 'long', timeStyle: 'short'};\n } else if ('hour' in value) {\n return {timeStyle: 'short'};\n } else {\n return {dateStyle: 'long'};\n }\n}\n\nfunction convertValue(value: Time) {\n let date = today(getLocalTimeZone());\n\n return toCalendarDateTime(date, value);\n}\n\n/**\n * A LabeledValue displays a non-editable value with a label. It formats numbers, dates, times, and lists according to the user's locale.\n */\nlet _LabeledValue = React.forwardRef(LabeledValue);\nexport {_LabeledValue as LabeledValue};\n"],"names":[],"version":3,"file":"LabeledValue.main.js.map"}
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AAuEM,MAAM,0DAAe,CAAA,GAAA,sCAAI,EAAE,UAAU,CAAC,SAAS,aAAkD,KAAmC,EAAE,GAAwB;IACnK,IAAI,SACF,KAAK,iBACL,aAAa,EACd,GAAG;IACJ,IAAI,SAAS,CAAA,GAAA,mCAAQ,EAAE;IAEvB,CAAA,GAAA,sBAAQ,EAAE;QACR,IACE,CAAA,mBAAA,6BAAA,OAAQ,OAAO,KACf,OAAO,OAAO,CAAC,gBAAgB,CAAC,sCAC7B,MAAM,GAAG,GAEZ,MAAM,IAAI,MAAM;IAEpB,GAAG;QAAC;KAAO;IAGX,IAAI;IACJ,IAAI,MAAM,OAAO,CAAC,QAChB,yBAAW,0DAAC;QAAoB,OAAO;QAAO,eAAe;;IAG/D,IAAI,OAAO,UAAU,YAAY,WAAW,SAAS,OAAO,MAAM,KAAK,KAAK,YAAY,OAAO,MAAM,GAAG,KAAK,UAC3G,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":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {CalendarDate, CalendarDateTime, getLocalTimeZone, Time, toCalendarDateTime, today, ZonedDateTime} from '@internationalized/date';\nimport {classNames, useDOMRef} from '@react-spectrum/utils';\nimport type {DOMProps, DOMRef, RangeValue, SpectrumLabelableProps, StyleProps} from '@react-types/shared';\nimport {Field} from '@react-spectrum/label';\nimport {filterDOMProps} from '@react-aria/utils';\nimport labelStyles from '@adobe/spectrum-css-temp/components/fieldlabel/vars.css';\nimport React, {ReactElement, ReactNode, useEffect} from 'react';\nimport {useDateFormatter, useListFormatter, useNumberFormatter} from '@react-aria/i18n';\n\n// NOTE: the types here need to be synchronized with the ones in docs/types.ts, which are simpler so the documentation generator can handle them.\n\nexport interface LabeledValueBaseProps extends DOMProps, StyleProps, Omit<SpectrumLabelableProps, 'necessityIndicator' | 'isRequired'>, DOMProps {\n /** The content to display as the label. */\n label: ReactNode\n}\n\ntype NumberValue = number | RangeValue<number>;\ninterface NumberProps<T extends NumberValue> {\n /** The value to display. */\n value: T,\n /** Formatting options for the value. */\n formatOptions?: Intl.NumberFormatOptions\n}\n\nexport type DateTime = Date | CalendarDate | CalendarDateTime | ZonedDateTime | Time;\ntype RangeDateTime = RangeValue<DateTime>;\ntype DateTimeValue = DateTime | RangeDateTime;\ninterface DateProps<T extends DateTimeValue> {\n /** The value to display. */\n value: T,\n /** Formatting options for the value. */\n formatOptions?: Intl.DateTimeFormatOptions\n}\n\ninterface StringProps<T extends string> {\n /** The value to display. */\n value: T,\n /** Formatting options for the value. */\n formatOptions?: never\n}\n\ninterface StringListProps<T extends string[]> {\n /** The value to display. */\n value: T,\n /** Formatting options for the value. */\n formatOptions?: Intl.ListFormatOptions\n}\n\ninterface ReactElementProps<T extends ReactElement> {\n /** The value to display. */\n value: T,\n /** Formatting options for the value. */\n formatOptions?: never\n}\n\ntype LabeledValueProps<T> =\n T extends NumberValue ? NumberProps<T> :\n T extends DateTimeValue ? DateProps<T> :\n T extends string[] ? StringListProps<T> :\n T extends string ? StringProps<T> :\n T extends ReactElement ? ReactElementProps<T> :\n never;\n\ntype SpectrumLabeledValueTypes = string[] | string | Date | CalendarDate | CalendarDateTime | ZonedDateTime | Time | number | RangeValue<number> | RangeValue<DateTime> | ReactElement;\nexport type SpectrumLabeledValueProps<T> = LabeledValueProps<T> & LabeledValueBaseProps;\n\n/**\n * A LabeledValue displays a non-editable value with a label. It formats numbers, dates, times, and lists according to the user's locale.\n */\nexport const LabeledValue = React.forwardRef(function LabeledValue<T extends SpectrumLabeledValueTypes>(props: SpectrumLabeledValueProps<T>, ref: DOMRef<HTMLElement>) {\n let {\n value,\n formatOptions\n } = props;\n let domRef = useDOMRef(ref);\n\n useEffect(() => {\n if (\n domRef?.current &&\n domRef.current.querySelectorAll('input, [contenteditable], textarea')\n .length > 0\n ) {\n throw new Error('LabeledValue cannot contain an editable value.');\n }\n }, [domRef]);\n \n\n let children;\n if (Array.isArray(value)) {\n children = <FormattedStringList value={value} formatOptions={formatOptions as Intl.ListFormatOptions} />;\n }\n\n if (typeof value === 'object' && 'start' in value && typeof value.start === 'number' && typeof value.end === 'number') {\n children = <FormattedNumber value={value as NumberValue} formatOptions={formatOptions as Intl.NumberFormatOptions} />;\n }\n\n if (typeof value === 'object' && 'start' in value && typeof value.start !== 'number' && typeof value.end !== 'number') {\n children = <FormattedDate value={value as DateTimeValue} formatOptions={formatOptions as Intl.DateTimeFormatOptions} />;\n }\n\n if (typeof value === 'number') {\n children = <FormattedNumber value={value} formatOptions={formatOptions as Intl.NumberFormatOptions} />;\n }\n\n if (typeof value === 'object' && ('calendar' in value || 'hour' in value) || (value instanceof Date)) {\n children = <FormattedDate value={value} formatOptions={formatOptions as Intl.DateTimeFormatOptions} />;\n }\n\n if (typeof value === 'string') {\n children = value;\n }\n\n if (React.isValidElement(value)) {\n children = value;\n }\n\n return (\n <Field {...props as any} wrapperProps={filterDOMProps(props as any)} ref={domRef} elementType=\"span\" wrapperClassName={classNames(labelStyles, 'spectrum-LabeledValue')}>\n <span>{children}</span>\n </Field>\n );\n});\n\nfunction FormattedStringList<T extends string[]>(props: StringListProps<T>) {\n let stringFormatter = useListFormatter(props.formatOptions);\n\n return (\n <>{stringFormatter.format(props.value)}</>\n );\n}\n\nfunction FormattedNumber<T extends NumberValue>(props: NumberProps<T>) {\n let numberFormatter = useNumberFormatter(props.formatOptions);\n let value = props.value;\n\n if (typeof value === 'object') {\n return <>{numberFormatter.formatRange(value.start, value.end)}</>;\n }\n\n return <>{numberFormatter.format(value)}</>;\n}\n\nfunction FormattedDate<T extends DateTimeValue>(props: DateProps<T>) {\n let {value, formatOptions} = props;\n if (!formatOptions) {\n formatOptions = getDefaultFormatOptions('start' in value ? value.start : value);\n }\n\n let dateFormatter = useDateFormatter(formatOptions);\n let timeZone = dateFormatter.resolvedOptions().timeZone || getLocalTimeZone();\n let final: Date;\n\n if ('start' in value && 'end' in value) {\n let start = value.start;\n let end = value.end;\n\n start = convertDateTime(start, timeZone);\n end = convertDateTime(end, timeZone);\n\n return <>{dateFormatter.formatRange(start, end)}</>;\n }\n\n final = convertDateTime(value, timeZone);\n return <>{dateFormatter.format(final)}</>;\n}\n\nfunction convertDateTime(value: DateTime, timeZone: any) {\n if ('timeZone' in value) {\n return value.toDate();\n } else if ('calendar' in value) {\n return value.toDate(timeZone);\n } else if (!(value instanceof Date)) {\n return convertValue(value).toDate(timeZone);\n }\n\n return value;\n}\n\nfunction getDefaultFormatOptions(value: DateTime): Intl.DateTimeFormatOptions {\n if (value instanceof Date) {\n return {dateStyle: 'long', timeStyle: 'short'};\n } else if ('timeZone' in value) {\n return {year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric', timeZone: value.timeZone, timeZoneName: 'short'};\n } else if ('hour' in value && 'year' in value) {\n return {dateStyle: 'long', timeStyle: 'short'};\n } else if ('hour' in value) {\n return {timeStyle: 'short'};\n } else {\n return {dateStyle: 'long'};\n }\n}\n\nfunction convertValue(value: Time) {\n let date = today(getLocalTimeZone());\n\n return toCalendarDateTime(date, value);\n}\n"],"names":[],"version":3,"file":"LabeledValue.main.js.map"}
|
package/dist/LabeledValue.mjs
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
import "./vars.
|
1
|
+
import "./vars.6c953d9a.css";
|
2
2
|
import $fhlTD$fieldlabel_vars_cssmodulejs from "./fieldlabel_vars_css.mjs";
|
3
3
|
import {getLocalTimeZone as $fhlTD$getLocalTimeZone, today as $fhlTD$today, toCalendarDateTime as $fhlTD$toCalendarDateTime} from "@internationalized/date";
|
4
4
|
import {useDOMRef as $fhlTD$useDOMRef, classNames as $fhlTD$classNames} from "@react-spectrum/utils";
|
5
5
|
import {Field as $fhlTD$Field} from "@react-spectrum/label";
|
6
6
|
import {filterDOMProps as $fhlTD$filterDOMProps} from "@react-aria/utils";
|
7
|
-
import $fhlTD$react from "react";
|
7
|
+
import $fhlTD$react, {useEffect as $fhlTD$useEffect} from "react";
|
8
8
|
import {useListFormatter as $fhlTD$useListFormatter, useNumberFormatter as $fhlTD$useNumberFormatter, useDateFormatter as $fhlTD$useDateFormatter} from "@react-aria/i18n";
|
9
9
|
|
10
10
|
|
@@ -28,9 +28,14 @@ function $parcel$interopDefault(a) {
|
|
28
28
|
|
29
29
|
|
30
30
|
|
31
|
-
|
31
|
+
const $3e9971be431adb24$export$d1328f67a56fa517 = /*#__PURE__*/ (0, $fhlTD$react).forwardRef(function LabeledValue(props, ref) {
|
32
32
|
let { value: value, formatOptions: formatOptions } = props;
|
33
33
|
let domRef = (0, $fhlTD$useDOMRef)(ref);
|
34
|
+
(0, $fhlTD$useEffect)(()=>{
|
35
|
+
if ((domRef === null || domRef === void 0 ? void 0 : domRef.current) && domRef.current.querySelectorAll('input, [contenteditable], textarea').length > 0) throw new Error('LabeledValue cannot contain an editable value.');
|
36
|
+
}, [
|
37
|
+
domRef
|
38
|
+
]);
|
34
39
|
let children;
|
35
40
|
if (Array.isArray(value)) children = /*#__PURE__*/ (0, $fhlTD$react).createElement($3e9971be431adb24$var$FormattedStringList, {
|
36
41
|
value: value,
|
@@ -53,6 +58,7 @@ function $3e9971be431adb24$var$LabeledValue(props, ref) {
|
|
53
58
|
formatOptions: formatOptions
|
54
59
|
});
|
55
60
|
if (typeof value === 'string') children = value;
|
61
|
+
if (/*#__PURE__*/ (0, $fhlTD$react).isValidElement(value)) children = value;
|
56
62
|
return /*#__PURE__*/ (0, $fhlTD$react).createElement((0, $fhlTD$Field), {
|
57
63
|
...props,
|
58
64
|
wrapperProps: (0, $fhlTD$filterDOMProps)(props),
|
@@ -60,7 +66,7 @@ function $3e9971be431adb24$var$LabeledValue(props, ref) {
|
|
60
66
|
elementType: "span",
|
61
67
|
wrapperClassName: (0, $fhlTD$classNames)((0, ($parcel$interopDefault($fhlTD$fieldlabel_vars_cssmodulejs))), 'spectrum-LabeledValue')
|
62
68
|
}, /*#__PURE__*/ (0, $fhlTD$react).createElement("span", null, children));
|
63
|
-
}
|
69
|
+
});
|
64
70
|
function $3e9971be431adb24$var$FormattedStringList(props) {
|
65
71
|
let stringFormatter = (0, $fhlTD$useListFormatter)(props.formatOptions);
|
66
72
|
return /*#__PURE__*/ (0, $fhlTD$react).createElement((0, $fhlTD$react).Fragment, null, stringFormatter.format(props.value));
|
@@ -122,9 +128,6 @@ function $3e9971be431adb24$var$convertValue(value) {
|
|
122
128
|
let date = (0, $fhlTD$today)((0, $fhlTD$getLocalTimeZone)());
|
123
129
|
return (0, $fhlTD$toCalendarDateTime)(date, value);
|
124
130
|
}
|
125
|
-
/**
|
126
|
-
* A LabeledValue displays a non-editable value with a label. It formats numbers, dates, times, and lists according to the user's locale.
|
127
|
-
*/ let $3e9971be431adb24$export$d1328f67a56fa517 = /*#__PURE__*/ (0, $fhlTD$react).forwardRef($3e9971be431adb24$var$LabeledValue);
|
128
131
|
|
129
132
|
|
130
133
|
export {$3e9971be431adb24$export$d1328f67a56fa517 as LabeledValue};
|
@@ -1,10 +1,10 @@
|
|
1
|
-
import "./vars.
|
1
|
+
import "./vars.6c953d9a.css";
|
2
2
|
import $fhlTD$fieldlabel_vars_cssmodulejs from "./fieldlabel_vars_css.module.js";
|
3
3
|
import {getLocalTimeZone as $fhlTD$getLocalTimeZone, today as $fhlTD$today, toCalendarDateTime as $fhlTD$toCalendarDateTime} from "@internationalized/date";
|
4
4
|
import {useDOMRef as $fhlTD$useDOMRef, classNames as $fhlTD$classNames} from "@react-spectrum/utils";
|
5
5
|
import {Field as $fhlTD$Field} from "@react-spectrum/label";
|
6
6
|
import {filterDOMProps as $fhlTD$filterDOMProps} from "@react-aria/utils";
|
7
|
-
import $fhlTD$react from "react";
|
7
|
+
import $fhlTD$react, {useEffect as $fhlTD$useEffect} from "react";
|
8
8
|
import {useListFormatter as $fhlTD$useListFormatter, useNumberFormatter as $fhlTD$useNumberFormatter, useDateFormatter as $fhlTD$useDateFormatter} from "@react-aria/i18n";
|
9
9
|
|
10
10
|
|
@@ -28,9 +28,14 @@ function $parcel$interopDefault(a) {
|
|
28
28
|
|
29
29
|
|
30
30
|
|
31
|
-
|
31
|
+
const $3e9971be431adb24$export$d1328f67a56fa517 = /*#__PURE__*/ (0, $fhlTD$react).forwardRef(function LabeledValue(props, ref) {
|
32
32
|
let { value: value, formatOptions: formatOptions } = props;
|
33
33
|
let domRef = (0, $fhlTD$useDOMRef)(ref);
|
34
|
+
(0, $fhlTD$useEffect)(()=>{
|
35
|
+
if ((domRef === null || domRef === void 0 ? void 0 : domRef.current) && domRef.current.querySelectorAll('input, [contenteditable], textarea').length > 0) throw new Error('LabeledValue cannot contain an editable value.');
|
36
|
+
}, [
|
37
|
+
domRef
|
38
|
+
]);
|
34
39
|
let children;
|
35
40
|
if (Array.isArray(value)) children = /*#__PURE__*/ (0, $fhlTD$react).createElement($3e9971be431adb24$var$FormattedStringList, {
|
36
41
|
value: value,
|
@@ -53,6 +58,7 @@ function $3e9971be431adb24$var$LabeledValue(props, ref) {
|
|
53
58
|
formatOptions: formatOptions
|
54
59
|
});
|
55
60
|
if (typeof value === 'string') children = value;
|
61
|
+
if (/*#__PURE__*/ (0, $fhlTD$react).isValidElement(value)) children = value;
|
56
62
|
return /*#__PURE__*/ (0, $fhlTD$react).createElement((0, $fhlTD$Field), {
|
57
63
|
...props,
|
58
64
|
wrapperProps: (0, $fhlTD$filterDOMProps)(props),
|
@@ -60,7 +66,7 @@ function $3e9971be431adb24$var$LabeledValue(props, ref) {
|
|
60
66
|
elementType: "span",
|
61
67
|
wrapperClassName: (0, $fhlTD$classNames)((0, ($parcel$interopDefault($fhlTD$fieldlabel_vars_cssmodulejs))), 'spectrum-LabeledValue')
|
62
68
|
}, /*#__PURE__*/ (0, $fhlTD$react).createElement("span", null, children));
|
63
|
-
}
|
69
|
+
});
|
64
70
|
function $3e9971be431adb24$var$FormattedStringList(props) {
|
65
71
|
let stringFormatter = (0, $fhlTD$useListFormatter)(props.formatOptions);
|
66
72
|
return /*#__PURE__*/ (0, $fhlTD$react).createElement((0, $fhlTD$react).Fragment, null, stringFormatter.format(props.value));
|
@@ -122,9 +128,6 @@ function $3e9971be431adb24$var$convertValue(value) {
|
|
122
128
|
let date = (0, $fhlTD$today)((0, $fhlTD$getLocalTimeZone)());
|
123
129
|
return (0, $fhlTD$toCalendarDateTime)(date, value);
|
124
130
|
}
|
125
|
-
/**
|
126
|
-
* A LabeledValue displays a non-editable value with a label. It formats numbers, dates, times, and lists according to the user's locale.
|
127
|
-
*/ let $3e9971be431adb24$export$d1328f67a56fa517 = /*#__PURE__*/ (0, $fhlTD$react).forwardRef($3e9971be431adb24$var$LabeledValue);
|
128
131
|
|
129
132
|
|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QAAW,UAAU,MAAM,QAAQ;QAAE,cAAc;IAAO;SACtI,IAAI,UAAU,SAAS,UAAU,OACtC,OAAO;QAAC,WAAW;QAAQ,WAAW;IAAO;SACxC,IAAI,UAAU,OACnB,OAAO;QAAC,WAAW;IAAO;SAE1B,OAAO;QAAC,WAAW;IAAM;AAE7B;AAEA,SAAS,mCAAa,KAAW;IAC/B,IAAI,OAAO,CAAA,GAAA,YAAI,EAAE,CAAA,GAAA,uBAAe;IAEhC,OAAO,CAAA,GAAA,yBAAiB,EAAE,MAAM;AAClC;AAEA;;CAEC,GACD,IAAI,0DAAgB,CAAA,GAAA,YAAI,EAAE,UAAU,CAAC","sources":["packages/@react-spectrum/labeledvalue/src/LabeledValue.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {CalendarDate, CalendarDateTime, getLocalTimeZone, Time, toCalendarDateTime, today, ZonedDateTime} from '@internationalized/date';\nimport {classNames, useDOMRef} from '@react-spectrum/utils';\nimport type {DOMProps, DOMRef, RangeValue, SpectrumLabelableProps, StyleProps} from '@react-types/shared';\nimport {Field} from '@react-spectrum/label';\nimport {filterDOMProps} from '@react-aria/utils';\nimport labelStyles from '@adobe/spectrum-css-temp/components/fieldlabel/vars.css';\nimport React, {ReactNode} from 'react';\nimport {useDateFormatter, useListFormatter, useNumberFormatter} from '@react-aria/i18n';\n\n// NOTE: the types here need to be synchronized with the ones in docs/types.ts, which are simpler so the documentation generator can handle them.\n\nexport interface LabeledValueBaseProps extends DOMProps, StyleProps, Omit<SpectrumLabelableProps, 'necessityIndicator' | 'isRequired'>, DOMProps {\n /** The content to display as the label. */\n label: ReactNode\n}\n\ntype NumberValue = number | RangeValue<number>;\ninterface NumberProps<T extends NumberValue> {\n /** The value to display. */\n value: T,\n /** Formatting options for the value. */\n formatOptions?: Intl.NumberFormatOptions\n}\n\nexport type DateTime = Date | CalendarDate | CalendarDateTime | ZonedDateTime | Time;\ntype RangeDateTime = RangeValue<DateTime>;\ntype DateTimeValue = DateTime | RangeDateTime;\ninterface DateProps<T extends DateTimeValue> {\n /** The value to display. */\n value: T,\n /** Formatting options for the value. */\n formatOptions?: Intl.DateTimeFormatOptions\n}\n\ninterface StringProps<T extends string> {\n /** The value to display. */\n value: T,\n /** Formatting options for the value. */\n formatOptions?: never\n}\n\ninterface StringListProps<T extends string[]> {\n /** The value to display. */\n value: T,\n /** Formatting options for the value. */\n formatOptions?: Intl.ListFormatOptions\n}\n\ntype LabeledValueProps<T> =\n T extends NumberValue ? NumberProps<T> :\n T extends DateTimeValue ? DateProps<T> :\n T extends string[] ? StringListProps<T> :\n T extends string ? StringProps<T> :\n never;\n\ntype SpectrumLabeledValueTypes = string[] | string | Date | CalendarDate | CalendarDateTime | ZonedDateTime | Time | number | RangeValue<number> | RangeValue<DateTime>;\nexport type SpectrumLabeledValueProps<T> = LabeledValueProps<T> & LabeledValueBaseProps;\n\nfunction LabeledValue<T extends SpectrumLabeledValueTypes>(props: SpectrumLabeledValueProps<T>, ref: DOMRef<HTMLElement>) {\n let {\n value,\n formatOptions\n } = props;\n let domRef = useDOMRef(ref);\n\n let children;\n if (Array.isArray(value)) {\n children = <FormattedStringList value={value} formatOptions={formatOptions as Intl.ListFormatOptions} />;\n }\n\n if (typeof value === 'object' && 'start' in value && typeof value.start === 'number' && typeof value.end === 'number') {\n children = <FormattedNumber value={value as NumberValue} formatOptions={formatOptions as Intl.NumberFormatOptions} />;\n }\n\n if (typeof value === 'object' && 'start' in value && typeof value.start !== 'number' && typeof value.end !== 'number') {\n children = <FormattedDate value={value as DateTimeValue} formatOptions={formatOptions as Intl.DateTimeFormatOptions} />;\n }\n\n if (typeof value === 'number') {\n children = <FormattedNumber value={value} formatOptions={formatOptions as Intl.NumberFormatOptions} />;\n }\n\n if (typeof value === 'object' && ('calendar' in value || 'hour' in value) || (value instanceof Date)) {\n children = <FormattedDate value={value} formatOptions={formatOptions as Intl.DateTimeFormatOptions} />;\n }\n\n if (typeof value === 'string') {\n children = value;\n }\n\n return (\n <Field {...props as any} wrapperProps={filterDOMProps(props as any)} ref={domRef} elementType=\"span\" wrapperClassName={classNames(labelStyles, 'spectrum-LabeledValue')}>\n <span>{children}</span>\n </Field>\n );\n}\n\nfunction FormattedStringList<T extends string[]>(props: StringListProps<T>) {\n let stringFormatter = useListFormatter(props.formatOptions);\n\n return (\n <>{stringFormatter.format(props.value)}</>\n );\n}\n\nfunction FormattedNumber<T extends NumberValue>(props: NumberProps<T>) {\n let numberFormatter = useNumberFormatter(props.formatOptions);\n let value = props.value;\n\n if (typeof value === 'object') {\n return <>{numberFormatter.formatRange(value.start, value.end)}</>;\n }\n\n return <>{numberFormatter.format(value)}</>;\n}\n\nfunction FormattedDate<T extends DateTimeValue>(props: DateProps<T>) {\n let {value, formatOptions} = props;\n if (!formatOptions) {\n formatOptions = getDefaultFormatOptions('start' in value ? value.start : value);\n }\n\n let dateFormatter = useDateFormatter(formatOptions);\n let timeZone = dateFormatter.resolvedOptions().timeZone || getLocalTimeZone();\n let final: Date;\n\n if ('start' in value && 'end' in value) {\n let start = value.start;\n let end = value.end;\n\n start = convertDateTime(start, timeZone);\n end = convertDateTime(end, timeZone);\n\n return <>{dateFormatter.formatRange(start, end)}</>;\n }\n\n final = convertDateTime(value, timeZone);\n return <>{dateFormatter.format(final)}</>;\n}\n\nfunction convertDateTime(value: DateTime, timeZone: any) {\n if ('timeZone' in value) {\n return value.toDate();\n } else if ('calendar' in value) {\n return value.toDate(timeZone);\n } else if (!(value instanceof Date)) {\n return convertValue(value).toDate(timeZone);\n }\n\n return value;\n}\n\nfunction getDefaultFormatOptions(value: DateTime): Intl.DateTimeFormatOptions {\n if (value instanceof Date) {\n return {dateStyle: 'long', timeStyle: 'short'};\n } else if ('timeZone' in value) {\n return {year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric', timeZone: value.timeZone, timeZoneName: 'short'};\n } else if ('hour' in value && 'year' in value) {\n return {dateStyle: 'long', timeStyle: 'short'};\n } else if ('hour' in value) {\n return {timeStyle: 'short'};\n } else {\n return {dateStyle: 'long'};\n }\n}\n\nfunction convertValue(value: Time) {\n let date = today(getLocalTimeZone());\n\n return toCalendarDateTime(date, value);\n}\n\n/**\n * A LabeledValue displays a non-editable value with a label. It formats numbers, dates, times, and lists according to the user's locale.\n */\nlet _LabeledValue = React.forwardRef(LabeledValue);\nexport {_LabeledValue as LabeledValue};\n"],"names":[],"version":3,"file":"LabeledValue.module.js.map"}
|
1
|
+
{"mappings":";;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AAuEM,MAAM,0DAAe,CAAA,GAAA,YAAI,EAAE,UAAU,CAAC,SAAS,aAAkD,KAAmC,EAAE,GAAwB;IACnK,IAAI,SACF,KAAK,iBACL,aAAa,EACd,GAAG;IACJ,IAAI,SAAS,CAAA,GAAA,gBAAQ,EAAE;IAEvB,CAAA,GAAA,gBAAQ,EAAE;QACR,IACE,CAAA,mBAAA,6BAAA,OAAQ,OAAO,KACf,OAAO,OAAO,CAAC,gBAAgB,CAAC,sCAC7B,MAAM,GAAG,GAEZ,MAAM,IAAI,MAAM;IAEpB,GAAG;QAAC;KAAO;IAGX,IAAI;IACJ,IAAI,MAAM,OAAO,CAAC,QAChB,yBAAW,gCAAC;QAAoB,OAAO;QAAO,eAAe;;IAG/D,IAAI,OAAO,UAAU,YAAY,WAAW,SAAS,OAAO,MAAM,KAAK,KAAK,YAAY,OAAO,MAAM,GAAG,KAAK,UAC3G,yBAAW,gCAAC;QAAgB,OAAO;QAAsB,eAAe;;IAG1E,IAAI,OAAO,UAAU,YAAY,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AI,WAAW,cAAc,eAAe,GAAG,QAAQ,IAAI,CAAA,GAAA,uBAAe;IAC1E,IAAI;IAEJ,IAAI,WAAW,SAAS,SAAS,OAAO;QACtC,IAAI,QAAQ,MAAM,KAAK;QACvB,IAAI,MAAM,MAAM,GAAG;QAEnB,QAAQ,sCAAgB,OAAO;QAC/B,MAAM,sCAAgB,KAAK;QAE3B,qBAAO,kEAAG,cAAc,WAAW,CAAC,OAAO;IAC7C;IAEA,QAAQ,sCAAgB,OAAO;IAC/B,qBAAO,kEAAG,cAAc,MAAM,CAAC;AACjC;AAEA,SAAS,sCAAgB,KAAe,EAAE,QAAa;IACrD,IAAI,cAAc,OAChB,OAAO,MAAM,MAAM;SACd,IAAI,cAAc,OACvB,OAAO,MAAM,MAAM,CAAC;SACf,IAAI,CAAE,CAAA,iBAAiB,IAAG,GAC/B,OAAO,mCAAa,OAAO,MAAM,CAAC;IAGpC,OAAO;AACT;AAEA,SAAS,8CAAwB,KAAe;IAC9C,IAAI,iBAAiB,MACnB,OAAO;QAAC,WAAW;QAAQ,WAAW;IAAO;SACxC,IAAI,cAAc,OACvB,OAAO;QAAC,MAAM;QAAW,OAAO;QAAQ,KAAK;QAAW,MAAM;QAAW,QAAQ;QAAW,UAAU,MAAM,QAAQ;QAAE,cAAc;IAAO;SACtI,IAAI,UAAU,SAAS,UAAU,OACtC,OAAO;QAAC,WAAW;QAAQ,WAAW;IAAO;SACxC,IAAI,UAAU,OACnB,OAAO;QAAC,WAAW;IAAO;SAE1B,OAAO;QAAC,WAAW;IAAM;AAE7B;AAEA,SAAS,mCAAa,KAAW;IAC/B,IAAI,OAAO,CAAA,GAAA,YAAI,EAAE,CAAA,GAAA,uBAAe;IAEhC,OAAO,CAAA,GAAA,yBAAiB,EAAE,MAAM;AAClC","sources":["packages/@react-spectrum/labeledvalue/src/LabeledValue.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {CalendarDate, CalendarDateTime, getLocalTimeZone, Time, toCalendarDateTime, today, ZonedDateTime} from '@internationalized/date';\nimport {classNames, useDOMRef} from '@react-spectrum/utils';\nimport type {DOMProps, DOMRef, RangeValue, SpectrumLabelableProps, StyleProps} from '@react-types/shared';\nimport {Field} from '@react-spectrum/label';\nimport {filterDOMProps} from '@react-aria/utils';\nimport labelStyles from '@adobe/spectrum-css-temp/components/fieldlabel/vars.css';\nimport React, {ReactElement, ReactNode, useEffect} from 'react';\nimport {useDateFormatter, useListFormatter, useNumberFormatter} from '@react-aria/i18n';\n\n// NOTE: the types here need to be synchronized with the ones in docs/types.ts, which are simpler so the documentation generator can handle them.\n\nexport interface LabeledValueBaseProps extends DOMProps, StyleProps, Omit<SpectrumLabelableProps, 'necessityIndicator' | 'isRequired'>, DOMProps {\n /** The content to display as the label. */\n label: ReactNode\n}\n\ntype NumberValue = number | RangeValue<number>;\ninterface NumberProps<T extends NumberValue> {\n /** The value to display. */\n value: T,\n /** Formatting options for the value. */\n formatOptions?: Intl.NumberFormatOptions\n}\n\nexport type DateTime = Date | CalendarDate | CalendarDateTime | ZonedDateTime | Time;\ntype RangeDateTime = RangeValue<DateTime>;\ntype DateTimeValue = DateTime | RangeDateTime;\ninterface DateProps<T extends DateTimeValue> {\n /** The value to display. */\n value: T,\n /** Formatting options for the value. */\n formatOptions?: Intl.DateTimeFormatOptions\n}\n\ninterface StringProps<T extends string> {\n /** The value to display. */\n value: T,\n /** Formatting options for the value. */\n formatOptions?: never\n}\n\ninterface StringListProps<T extends string[]> {\n /** The value to display. */\n value: T,\n /** Formatting options for the value. */\n formatOptions?: Intl.ListFormatOptions\n}\n\ninterface ReactElementProps<T extends ReactElement> {\n /** The value to display. */\n value: T,\n /** Formatting options for the value. */\n formatOptions?: never\n}\n\ntype LabeledValueProps<T> =\n T extends NumberValue ? NumberProps<T> :\n T extends DateTimeValue ? DateProps<T> :\n T extends string[] ? StringListProps<T> :\n T extends string ? StringProps<T> :\n T extends ReactElement ? ReactElementProps<T> :\n never;\n\ntype SpectrumLabeledValueTypes = string[] | string | Date | CalendarDate | CalendarDateTime | ZonedDateTime | Time | number | RangeValue<number> | RangeValue<DateTime> | ReactElement;\nexport type SpectrumLabeledValueProps<T> = LabeledValueProps<T> & LabeledValueBaseProps;\n\n/**\n * A LabeledValue displays a non-editable value with a label. It formats numbers, dates, times, and lists according to the user's locale.\n */\nexport const LabeledValue = React.forwardRef(function LabeledValue<T extends SpectrumLabeledValueTypes>(props: SpectrumLabeledValueProps<T>, ref: DOMRef<HTMLElement>) {\n let {\n value,\n formatOptions\n } = props;\n let domRef = useDOMRef(ref);\n\n useEffect(() => {\n if (\n domRef?.current &&\n domRef.current.querySelectorAll('input, [contenteditable], textarea')\n .length > 0\n ) {\n throw new Error('LabeledValue cannot contain an editable value.');\n }\n }, [domRef]);\n \n\n let children;\n if (Array.isArray(value)) {\n children = <FormattedStringList value={value} formatOptions={formatOptions as Intl.ListFormatOptions} />;\n }\n\n if (typeof value === 'object' && 'start' in value && typeof value.start === 'number' && typeof value.end === 'number') {\n children = <FormattedNumber value={value as NumberValue} formatOptions={formatOptions as Intl.NumberFormatOptions} />;\n }\n\n if (typeof value === 'object' && 'start' in value && typeof value.start !== 'number' && typeof value.end !== 'number') {\n children = <FormattedDate value={value as DateTimeValue} formatOptions={formatOptions as Intl.DateTimeFormatOptions} />;\n }\n\n if (typeof value === 'number') {\n children = <FormattedNumber value={value} formatOptions={formatOptions as Intl.NumberFormatOptions} />;\n }\n\n if (typeof value === 'object' && ('calendar' in value || 'hour' in value) || (value instanceof Date)) {\n children = <FormattedDate value={value} formatOptions={formatOptions as Intl.DateTimeFormatOptions} />;\n }\n\n if (typeof value === 'string') {\n children = value;\n }\n\n if (React.isValidElement(value)) {\n children = value;\n }\n\n return (\n <Field {...props as any} wrapperProps={filterDOMProps(props as any)} ref={domRef} elementType=\"span\" wrapperClassName={classNames(labelStyles, 'spectrum-LabeledValue')}>\n <span>{children}</span>\n </Field>\n );\n});\n\nfunction FormattedStringList<T extends string[]>(props: StringListProps<T>) {\n let stringFormatter = useListFormatter(props.formatOptions);\n\n return (\n <>{stringFormatter.format(props.value)}</>\n );\n}\n\nfunction FormattedNumber<T extends NumberValue>(props: NumberProps<T>) {\n let numberFormatter = useNumberFormatter(props.formatOptions);\n let value = props.value;\n\n if (typeof value === 'object') {\n return <>{numberFormatter.formatRange(value.start, value.end)}</>;\n }\n\n return <>{numberFormatter.format(value)}</>;\n}\n\nfunction FormattedDate<T extends DateTimeValue>(props: DateProps<T>) {\n let {value, formatOptions} = props;\n if (!formatOptions) {\n formatOptions = getDefaultFormatOptions('start' in value ? value.start : value);\n }\n\n let dateFormatter = useDateFormatter(formatOptions);\n let timeZone = dateFormatter.resolvedOptions().timeZone || getLocalTimeZone();\n let final: Date;\n\n if ('start' in value && 'end' in value) {\n let start = value.start;\n let end = value.end;\n\n start = convertDateTime(start, timeZone);\n end = convertDateTime(end, timeZone);\n\n return <>{dateFormatter.formatRange(start, end)}</>;\n }\n\n final = convertDateTime(value, timeZone);\n return <>{dateFormatter.format(final)}</>;\n}\n\nfunction convertDateTime(value: DateTime, timeZone: any) {\n if ('timeZone' in value) {\n return value.toDate();\n } else if ('calendar' in value) {\n return value.toDate(timeZone);\n } else if (!(value instanceof Date)) {\n return convertValue(value).toDate(timeZone);\n }\n\n return value;\n}\n\nfunction getDefaultFormatOptions(value: DateTime): Intl.DateTimeFormatOptions {\n if (value instanceof Date) {\n return {dateStyle: 'long', timeStyle: 'short'};\n } else if ('timeZone' in value) {\n return {year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric', timeZone: value.timeZone, timeZoneName: 'short'};\n } else if ('hour' in value && 'year' in value) {\n return {dateStyle: 'long', timeStyle: 'short'};\n } else if ('hour' in value) {\n return {timeStyle: 'short'};\n } else {\n return {dateStyle: 'long'};\n }\n}\n\nfunction convertValue(value: Time) {\n let date = today(getLocalTimeZone());\n\n return toCalendarDateTime(date, value);\n}\n"],"names":[],"version":3,"file":"LabeledValue.module.js.map"}
|
package/dist/types.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { CalendarDate, CalendarDateTime, Time, ZonedDateTime } from "@internationalized/date";
|
2
2
|
import { DOMProps, RangeValue, SpectrumLabelableProps, StyleProps, DOMRefValue } from "@react-types/shared";
|
3
|
-
import React, { ReactNode } from "react";
|
3
|
+
import React, { ReactElement, ReactNode } from "react";
|
4
4
|
interface LabeledValueBaseProps extends DOMProps, StyleProps, Omit<SpectrumLabelableProps, 'necessityIndicator' | 'isRequired'>, DOMProps {
|
5
5
|
/** The content to display as the label. */
|
6
6
|
label: ReactNode;
|
@@ -33,12 +33,18 @@ interface StringListProps<T extends string[]> {
|
|
33
33
|
/** Formatting options for the value. */
|
34
34
|
formatOptions?: Intl.ListFormatOptions;
|
35
35
|
}
|
36
|
-
|
37
|
-
|
36
|
+
interface ReactElementProps<T extends ReactElement> {
|
37
|
+
/** The value to display. */
|
38
|
+
value: T;
|
39
|
+
/** Formatting options for the value. */
|
40
|
+
formatOptions?: never;
|
41
|
+
}
|
42
|
+
type LabeledValueProps<T> = T extends NumberValue ? NumberProps<T> : T extends DateTimeValue ? DateProps<T> : T extends string[] ? StringListProps<T> : T extends string ? StringProps<T> : T extends ReactElement ? ReactElementProps<T> : never;
|
43
|
+
type SpectrumLabeledValueTypes = string[] | string | Date | CalendarDate | CalendarDateTime | ZonedDateTime | Time | number | RangeValue<number> | RangeValue<DateTime> | ReactElement;
|
38
44
|
export type SpectrumLabeledValueProps<T> = LabeledValueProps<T> & LabeledValueBaseProps;
|
39
45
|
/**
|
40
46
|
* A LabeledValue displays a non-editable value with a label. It formats numbers, dates, times, and lists according to the user's locale.
|
41
47
|
*/
|
42
|
-
export
|
48
|
+
export const LabeledValue: React.ForwardRefExoticComponent<SpectrumLabeledValueProps<SpectrumLabeledValueTypes> & React.RefAttributes<DOMRefValue<HTMLElement>>>;
|
43
49
|
|
44
50
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"mappings":";;;AAuBA,+BAAuC,SAAQ,QAAQ,EAAE,UAAU,EAAE,IAAI,CAAC,sBAAsB,EAAE,oBAAoB,GAAG,YAAY,CAAC,EAAE,QAAQ;IAC9I,2CAA2C;IAC3C,KAAK,EAAE,SAAS,CAAA;CACjB;AAED,mBAAmB,MAAM,GAAG,WAAW,MAAM,CAAC,CAAC;AAC/C,sBAAsB,CAAC,SAAS,WAAW;IACzC,4BAA4B;IAC5B,KAAK,EAAE,CAAC,CAAC;IACT,wCAAwC;IACxC,aAAa,CAAC,EAAE,KAAK,mBAAmB,CAAA;CACzC;AAED,gBAAuB,IAAI,GAAG,YAAY,GAAG,gBAAgB,GAAG,aAAa,GAAG,IAAI,CAAC;AACrF,qBAAqB,WAAW,QAAQ,CAAC,CAAC;AAC1C,qBAAqB,QAAQ,GAAG,aAAa,CAAC;AAC9C,oBAAoB,CAAC,SAAS,aAAa;IACzC,4BAA4B;IAC5B,KAAK,EAAE,CAAC,CAAC;IACT,wCAAwC;IACxC,aAAa,CAAC,EAAE,KAAK,qBAAqB,CAAA;CAC3C;AAED,sBAAsB,CAAC,SAAS,MAAM;IACpC,4BAA4B;IAC5B,KAAK,EAAE,CAAC,CAAC;IACT,wCAAwC;IACxC,aAAa,CAAC,EAAE,KAAK,CAAA;CACtB;AAED,0BAA0B,CAAC,SAAS,MAAM,EAAE;IAC1C,4BAA4B;IAC5B,KAAK,EAAE,CAAC,CAAC;IACT,wCAAwC;IACxC,aAAa,CAAC,EAAE,KAAK,iBAAiB,CAAA;CACvC;AAED,u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,SAAS,MAAM,EAAE;IAC1C,4BAA4B;IAC5B,KAAK,EAAE,CAAC,CAAC;IACT,wCAAwC;IACxC,aAAa,CAAC,EAAE,KAAK,iBAAiB,CAAA;CACvC;AAED,4BAA4B,CAAC,SAAS,YAAY;IAChD,4BAA4B;IAC5B,KAAK,EAAE,CAAC,CAAC;IACT,wCAAwC;IACxC,aAAa,CAAC,EAAE,KAAK,CAAA;CACtB;AAED,uBAAuB,CAAC,IACtB,CAAC,SAAS,WAAW,GAAG,YAAY,CAAC,CAAC,GACtC,CAAC,SAAS,aAAa,GAAG,UAAU,CAAC,CAAC,GACtC,CAAC,SAAS,MAAM,EAAE,GAAG,gBAAgB,CAAC,CAAC,GACvC,CAAC,SAAS,MAAM,GAAG,YAAY,CAAC,CAAC,GACjC,CAAC,SAAS,YAAY,GAAG,kBAAkB,CAAC,CAAC,GAC7C,KAAK,CAAC;AAER,iCAAiC,MAAM,EAAE,GAAG,MAAM,GAAG,IAAI,GAAG,YAAY,GAAG,gBAAgB,GAAG,aAAa,GAAG,IAAI,GAAG,MAAM,GAAG,WAAW,MAAM,CAAC,GAAG,WAAW,QAAQ,CAAC,GAAG,YAAY,CAAC;AACvL,sCAAsC,CAAC,IAAI,kBAAkB,CAAC,CAAC,GAAG,qBAAqB,CAAC;AAExF;;GAEG;AACH,OAAO,MAAM,mJAoDX,CAAC","sources":["packages/@react-spectrum/labeledvalue/src/packages/@react-spectrum/labeledvalue/src/LabeledValue.tsx","packages/@react-spectrum/labeledvalue/src/packages/@react-spectrum/labeledvalue/src/index.ts","packages/@react-spectrum/labeledvalue/src/index.ts"],"sourcesContent":[null,null,"/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n/// <reference types=\"css-module-types\" />\n\nexport type {SpectrumLabeledValueProps} from './LabeledValue';\nexport {LabeledValue} from './LabeledValue';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
@@ -152,9 +152,9 @@
|
|
152
152
|
}
|
153
153
|
|
154
154
|
.jIQVGq_spectrum-Field:where(.jIQVGq_spectrum-Field--positionSide) .jIQVGq_spectrum-Field-wrapper {
|
155
|
+
min-width: 0;
|
155
156
|
width: var(--spectrum-field-default-width);
|
156
157
|
flex: 1;
|
157
|
-
min-width: 0;
|
158
158
|
height: 100%;
|
159
159
|
}
|
160
160
|
|
@@ -214,8 +214,8 @@
|
|
214
214
|
}
|
215
215
|
|
216
216
|
.jIQVGq_spectrum-Form.jIQVGq_spectrum-Form--positionSide .jIQVGq_spectrum-Field-field {
|
217
|
-
min-width: var(--spectrum-alias-single-line-width, var(--spectrum-global-dimension-size-2400));
|
218
217
|
width: auto;
|
218
|
+
min-width: var(--spectrum-alias-single-line-width, var(--spectrum-global-dimension-size-2400));
|
219
219
|
}
|
220
220
|
|
221
221
|
.jIQVGq_spectrum-Form.jIQVGq_spectrum-Form--positionTop {
|
@@ -268,4 +268,4 @@
|
|
268
268
|
:is(.jIQVGq_spectrum-FieldLabel, .jIQVGq_spectrum-Form-itemLabel).jIQVGq_is-disabled {
|
269
269
|
color: var(--spectrum-fieldlabel-text-color-disabled, var(--spectrum-alias-text-color-disabled));
|
270
270
|
}
|
271
|
-
/*# sourceMappingURL=vars.
|
271
|
+
/*# sourceMappingURL=vars.6c953d9a.css.map */
|
@@ -1 +1 @@
|
|
1
|
-
{"mappings":"AA4DA;;;;;AAIE;;;;AAIA;;;;AAIA;;;;AAIA;;;;AAIA;;;;AAIA;;;;AAQA;;;;AAIA;;;;AAKF;;;;;;;;AAOE;;;;;;;;;;;AAqBE;;;;;AAQF;;;;AAKE;;;;;AAOJ;EACE;;;;EAIE;;;;;AAMJ;;;;;;;;;;;;;;;;AAsBA;;;;;;AAMA;;;;;;;AAOA;;;;;AAUA;;;;;AAIE;;;;;;AAMA;;;;;;;;;;AAUE;;;;;AAMA;;;;AAIA;;;;AAOF;;;;;AAKE;;;;;;;AAaE;;;;AAMF;;;;;AAKA;;;;;AAOA;;;;AAaF;;;;;;;;AAOE;;;;;AAME;;;;AAKA;;;;AAKA;;;;AAKA;;;;AAGE;;;;AAMJ;;;;AAIA;;;;;AAOF;;;;;;;AASE;;;;;AASF;;;;AAGE;;;;;;AAOF;;;;AAIA;;;;AAIA;;;;AAIA;;;;;AAKA;;;;AAkBF;;;;AAIE","sources":["packages/@adobe/spectrum-css-temp/components/fieldlabel/vars.css"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n@import './index.css';\n@import './skin.css';\n"],"names":[],"version":3,"file":"vars.
|
1
|
+
{"mappings":"AA4DA;;;;;AAIE;;;;AAIA;;;;AAIA;;;;AAIA;;;;AAIA;;;;AAIA;;;;AAQA;;;;AAIA;;;;AAKF;;;;;;;;AAOE;;;;;;;;;;;AAqBE;;;;;AAQF;;;;AAKE;;;;;AAOJ;EACE;;;;EAIE;;;;;AAMJ;;;;;;;;;;;;;;;;AAsBA;;;;;;AAMA;;;;;;;AAOA;;;;;AAUA;;;;;AAIE;;;;;;AAMA;;;;;;;;;;AAUE;;;;;AAMA;;;;AAIA;;;;AAOF;;;;;AAKE;;;;;;;AAaE;;;;AAMF;;;;;AAKA;;;;;AAOA;;;;AAaF;;;;;;;;AAOE;;;;;AAME;;;;AAKA;;;;AAKA;;;;AAKA;;;;AAGE;;;;AAMJ;;;;AAIA;;;;;AAOF;;;;;;;AASE;;;;;AASF;;;;AAGE;;;;;;AAOF;;;;AAIA;;;;AAIA;;;;AAIA;;;;;AAKA;;;;AAkBF;;;;AAIE","sources":["packages/@adobe/spectrum-css-temp/components/fieldlabel/vars.css"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n@import './index.css';\n@import './skin.css';\n"],"names":[],"version":3,"file":"vars.6c953d9a.css.map"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@react-spectrum/labeledvalue",
|
3
|
-
"version": "3.
|
3
|
+
"version": "3.2.0",
|
4
4
|
"description": "Spectrum UI components in React",
|
5
5
|
"license": "Apache-2.0",
|
6
6
|
"main": "dist/main.js",
|
@@ -36,12 +36,12 @@
|
|
36
36
|
"url": "https://github.com/adobe/react-spectrum"
|
37
37
|
},
|
38
38
|
"dependencies": {
|
39
|
-
"@internationalized/date": "^3.
|
40
|
-
"@react-aria/i18n": "^3.12.
|
41
|
-
"@react-aria/utils": "^3.
|
42
|
-
"@react-spectrum/label": "^3.16.
|
43
|
-
"@react-spectrum/utils": "^3.12.
|
44
|
-
"@react-types/shared": "^3.
|
39
|
+
"@internationalized/date": "^3.7.0",
|
40
|
+
"@react-aria/i18n": "^3.12.6",
|
41
|
+
"@react-aria/utils": "^3.28.0",
|
42
|
+
"@react-spectrum/label": "^3.16.12",
|
43
|
+
"@react-spectrum/utils": "^3.12.2",
|
44
|
+
"@react-types/shared": "^3.28.0",
|
45
45
|
"@swc/helpers": "^0.5.0"
|
46
46
|
},
|
47
47
|
"devDependencies": {
|
@@ -49,10 +49,11 @@
|
|
49
49
|
},
|
50
50
|
"peerDependencies": {
|
51
51
|
"@react-spectrum/provider": "^3.0.0",
|
52
|
-
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
|
52
|
+
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1",
|
53
|
+
"react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
|
53
54
|
},
|
54
55
|
"publishConfig": {
|
55
56
|
"access": "public"
|
56
57
|
},
|
57
|
-
"gitHead": "
|
58
|
+
"gitHead": "4d3c72c94eea2d72eb3a0e7d56000c6ef7e39726"
|
58
59
|
}
|
package/src/LabeledValue.tsx
CHANGED
@@ -16,7 +16,7 @@ import type {DOMProps, DOMRef, RangeValue, SpectrumLabelableProps, StyleProps} f
|
|
16
16
|
import {Field} from '@react-spectrum/label';
|
17
17
|
import {filterDOMProps} from '@react-aria/utils';
|
18
18
|
import labelStyles from '@adobe/spectrum-css-temp/components/fieldlabel/vars.css';
|
19
|
-
import React, {ReactNode} from 'react';
|
19
|
+
import React, {ReactElement, ReactNode, useEffect} from 'react';
|
20
20
|
import {useDateFormatter, useListFormatter, useNumberFormatter} from '@react-aria/i18n';
|
21
21
|
|
22
22
|
// NOTE: the types here need to be synchronized with the ones in docs/types.ts, which are simpler so the documentation generator can handle them.
|
@@ -58,23 +58,45 @@ interface StringListProps<T extends string[]> {
|
|
58
58
|
formatOptions?: Intl.ListFormatOptions
|
59
59
|
}
|
60
60
|
|
61
|
+
interface ReactElementProps<T extends ReactElement> {
|
62
|
+
/** The value to display. */
|
63
|
+
value: T,
|
64
|
+
/** Formatting options for the value. */
|
65
|
+
formatOptions?: never
|
66
|
+
}
|
67
|
+
|
61
68
|
type LabeledValueProps<T> =
|
62
69
|
T extends NumberValue ? NumberProps<T> :
|
63
70
|
T extends DateTimeValue ? DateProps<T> :
|
64
71
|
T extends string[] ? StringListProps<T> :
|
65
72
|
T extends string ? StringProps<T> :
|
73
|
+
T extends ReactElement ? ReactElementProps<T> :
|
66
74
|
never;
|
67
75
|
|
68
|
-
type SpectrumLabeledValueTypes = string[] | string | Date | CalendarDate | CalendarDateTime | ZonedDateTime | Time | number | RangeValue<number> | RangeValue<DateTime
|
76
|
+
type SpectrumLabeledValueTypes = string[] | string | Date | CalendarDate | CalendarDateTime | ZonedDateTime | Time | number | RangeValue<number> | RangeValue<DateTime> | ReactElement;
|
69
77
|
export type SpectrumLabeledValueProps<T> = LabeledValueProps<T> & LabeledValueBaseProps;
|
70
78
|
|
71
|
-
|
79
|
+
/**
|
80
|
+
* A LabeledValue displays a non-editable value with a label. It formats numbers, dates, times, and lists according to the user's locale.
|
81
|
+
*/
|
82
|
+
export const LabeledValue = React.forwardRef(function LabeledValue<T extends SpectrumLabeledValueTypes>(props: SpectrumLabeledValueProps<T>, ref: DOMRef<HTMLElement>) {
|
72
83
|
let {
|
73
84
|
value,
|
74
85
|
formatOptions
|
75
86
|
} = props;
|
76
87
|
let domRef = useDOMRef(ref);
|
77
88
|
|
89
|
+
useEffect(() => {
|
90
|
+
if (
|
91
|
+
domRef?.current &&
|
92
|
+
domRef.current.querySelectorAll('input, [contenteditable], textarea')
|
93
|
+
.length > 0
|
94
|
+
) {
|
95
|
+
throw new Error('LabeledValue cannot contain an editable value.');
|
96
|
+
}
|
97
|
+
}, [domRef]);
|
98
|
+
|
99
|
+
|
78
100
|
let children;
|
79
101
|
if (Array.isArray(value)) {
|
80
102
|
children = <FormattedStringList value={value} formatOptions={formatOptions as Intl.ListFormatOptions} />;
|
@@ -100,12 +122,16 @@ function LabeledValue<T extends SpectrumLabeledValueTypes>(props: SpectrumLabele
|
|
100
122
|
children = value;
|
101
123
|
}
|
102
124
|
|
125
|
+
if (React.isValidElement(value)) {
|
126
|
+
children = value;
|
127
|
+
}
|
128
|
+
|
103
129
|
return (
|
104
130
|
<Field {...props as any} wrapperProps={filterDOMProps(props as any)} ref={domRef} elementType="span" wrapperClassName={classNames(labelStyles, 'spectrum-LabeledValue')}>
|
105
131
|
<span>{children}</span>
|
106
132
|
</Field>
|
107
133
|
);
|
108
|
-
}
|
134
|
+
});
|
109
135
|
|
110
136
|
function FormattedStringList<T extends string[]>(props: StringListProps<T>) {
|
111
137
|
let stringFormatter = useListFormatter(props.formatOptions);
|
@@ -181,9 +207,3 @@ function convertValue(value: Time) {
|
|
181
207
|
|
182
208
|
return toCalendarDateTime(date, value);
|
183
209
|
}
|
184
|
-
|
185
|
-
/**
|
186
|
-
* A LabeledValue displays a non-editable value with a label. It formats numbers, dates, times, and lists according to the user's locale.
|
187
|
-
*/
|
188
|
-
let _LabeledValue = React.forwardRef(LabeledValue);
|
189
|
-
export {_LabeledValue as LabeledValue};
|