@longline/aqua-ui 1.0.229 → 1.0.231

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.
@@ -1,12 +1,11 @@
1
1
  import * as React from 'react';
2
- type TType = 'longdate' | 'shortdate' | 'longdatetime' | 'shortdatetime' | 'longtime' | 'shorttime' | 'distance' | 'month';
3
2
  interface IDateTimeFormatterProps {
4
3
  /**
5
- * Input date. This can either be a `Date` or a `string`.
4
+ * Input date. This can either be a `Date` or a `string`, e.g. `2025-09-22T10:05:41.074Z`.
6
5
  */
7
6
  value: string | Date;
8
7
  /**
9
- * Optional `Locale`.
8
+ * Optional `Locale`, e.g. `es`
10
9
  */
11
10
  locale?: string;
12
11
  }
@@ -19,10 +18,11 @@ interface IDateTimeFormatterAnimateProps {
19
18
  }
20
19
  interface IProps extends IDateTimeFormatterProps, IDateTimeFormatterAnimateProps {
21
20
  /**
22
- * Preset format.
21
+ * Preset format _or_ a `Intl.DateTimeFormatOptions` object for
22
+ * custom formatting.
23
23
  * @default longdate
24
24
  */
25
- type?: TType;
25
+ type?: 'longdate' | 'shortdate' | 'longdatetime' | 'shortdatetime' | 'longtime' | 'shorttime' | 'distance' | 'month' | Intl.DateTimeFormatOptions;
26
26
  }
27
27
  /**
28
28
  * `DateTimeFormatter` formats a date or time to a string.
@@ -45,7 +45,6 @@ interface IProps extends IDateTimeFormatterProps, IDateTimeFormatterAnimateProps
45
45
  */
46
46
  declare const DateTimeFormatter: {
47
47
  ({ type, ...props }: IProps): React.JSX.Element;
48
- displayName: string;
49
48
  LongDate: React.MemoExoticComponent<({ value, locale }: IDateTimeFormatterProps) => React.JSX.Element>;
50
49
  ShortDate: React.MemoExoticComponent<({ value, locale }: IDateTimeFormatterProps) => React.JSX.Element>;
51
50
  LongDateTime: React.MemoExoticComponent<({ value, locale }: IDateTimeFormatterProps) => React.JSX.Element>;
@@ -21,7 +21,7 @@ var __rest = (this && this.__rest) || function (s, e) {
21
21
  return t;
22
22
  };
23
23
  import * as React from 'react';
24
- import { DistanceDate, LongDate, LongDateTime, LongTime, ShortDate, ShortDateTime, ShortTime, Month } from './elements';
24
+ import { DistanceDate, LongDate, LongDateTime, LongTime, ShortDate, ShortDateTime, ShortTime, Month, Custom, } from './elements';
25
25
  /**
26
26
  * `DateTimeFormatter` formats a date or time to a string.
27
27
  *
@@ -53,10 +53,9 @@ var DateTimeFormatter = function (_a) {
53
53
  case 'distance': return React.createElement(DistanceDate, __assign({}, props));
54
54
  case 'month': return React.createElement(Month, __assign({}, props));
55
55
  default:
56
- return null;
56
+ return React.createElement(Custom, __assign({}, props, { format: type }));
57
57
  }
58
58
  };
59
- DateTimeFormatter.displayName = "DateTime";
60
59
  // Bonus: users can either use the `type` prop, or import the individual
61
60
  // components directly:
62
61
  DateTimeFormatter.LongDate = LongDate;
@@ -0,0 +1,36 @@
1
+ import * as React from 'react';
2
+ import { IDateTimeFormatterProps } from '../DateTimeFormatter';
3
+ interface IProps {
4
+ format: Intl.DateTimeFormatOptions;
5
+ }
6
+ /**
7
+ * `CustomDateTime` formats a date/time value into a string, according to
8
+ * a custom format (as an `Intl.DateTimeFormatOptions` object, see
9
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat).
10
+ *
11
+ * It also sets the full date/time as the `title` attribute for accessibility
12
+ * and UX, so users can see the full timestamp on hover.
13
+ *
14
+ * Accepts a `Date` object or a date string as `value`. If `value` is `null`
15
+ * or invalid, the component returns `null` and renders nothing.
16
+ *
17
+ * Optionally, a `locale` prop can be provided to format the date/time string
18
+ * accordingto locale-specific rules.
19
+ *
20
+ * The formatted output is wrapped in a `<time>` element with a machine-readable
21
+ * `dateTime` attribute to improve semantics and SEO.
22
+ *
23
+ * @example
24
+ * ```tsx
25
+ * <DateTimeFormatter.Custom value={new Date()} format={{
26
+ * day: 'numeric', // e.g. 28
27
+ * month: 'short', // e.g. Sep
28
+ * year: 'numeric', // e.g. 2024
29
+ * hour: '2-digit', // e.g. 14 (24-hour format)
30
+ * minute: '2-digit', // e.g. 30
31
+ * hour12: false // 24-hour time, remove if you want 12-hour time
32
+ * }}/>
33
+ * ```
34
+ */
35
+ declare const Custom: React.MemoExoticComponent<({ value, locale, format }: IDateTimeFormatterProps & IProps) => React.JSX.Element>;
36
+ export { Custom };
@@ -0,0 +1,43 @@
1
+ import * as React from 'react';
2
+ import { toDate } from './toDate';
3
+ /**
4
+ * `CustomDateTime` formats a date/time value into a string, according to
5
+ * a custom format (as an `Intl.DateTimeFormatOptions` object, see
6
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat).
7
+ *
8
+ * It also sets the full date/time as the `title` attribute for accessibility
9
+ * and UX, so users can see the full timestamp on hover.
10
+ *
11
+ * Accepts a `Date` object or a date string as `value`. If `value` is `null`
12
+ * or invalid, the component returns `null` and renders nothing.
13
+ *
14
+ * Optionally, a `locale` prop can be provided to format the date/time string
15
+ * accordingto locale-specific rules.
16
+ *
17
+ * The formatted output is wrapped in a `<time>` element with a machine-readable
18
+ * `dateTime` attribute to improve semantics and SEO.
19
+ *
20
+ * @example
21
+ * ```tsx
22
+ * <DateTimeFormatter.Custom value={new Date()} format={{
23
+ * day: 'numeric', // e.g. 28
24
+ * month: 'short', // e.g. Sep
25
+ * year: 'numeric', // e.g. 2024
26
+ * hour: '2-digit', // e.g. 14 (24-hour format)
27
+ * minute: '2-digit', // e.g. 30
28
+ * hour12: false // 24-hour time, remove if you want 12-hour time
29
+ * }}/>
30
+ * ```
31
+ */
32
+ var Custom = React.memo(function (_a) {
33
+ var value = _a.value, locale = _a.locale, format = _a.format;
34
+ if (value == null)
35
+ return null;
36
+ var date = toDate(value);
37
+ if (isNaN(date.getTime()))
38
+ return null; // Extra check for invalid dates
39
+ var display = React.useMemo(function () { return new Intl.DateTimeFormat(locale || undefined, format).format(date); }, [date, locale]);
40
+ return (React.createElement("time", { dateTime: date.toISOString(), title: display }, display));
41
+ });
42
+ Custom.displayName = "DateTimeFormatter.Custom";
43
+ export { Custom };
@@ -2,7 +2,7 @@ import * as React from 'react';
2
2
  import { IDateTimeFormatterProps } from '../DateTimeFormatter';
3
3
  /**
4
4
  * `LongDate` formats a date value into a long date string, such as
5
- * "Mon, 1 January 2023". It also sets a full date description as the
5
+ * "Monday, 1 January 2023". It also sets a full date description as the
6
6
  * title attribute for better accessibility.
7
7
  *
8
8
  * The component accepts either a `Date` object or a date string as `value`.
@@ -2,7 +2,7 @@ import * as React from 'react';
2
2
  import { toDate } from './toDate';
3
3
  /**
4
4
  * `LongDate` formats a date value into a long date string, such as
5
- * "Mon, 1 January 2023". It also sets a full date description as the
5
+ * "Monday, 1 January 2023". It also sets a full date description as the
6
6
  * title attribute for better accessibility.
7
7
  *
8
8
  * The component accepts either a `Date` object or a date string as `value`.
@@ -6,3 +6,4 @@ export * from './ShortDateTime';
6
6
  export * from './LongDateTime';
7
7
  export * from './DistanceDate';
8
8
  export * from './Month';
9
+ export * from './Custom';
@@ -6,3 +6,4 @@ export * from './ShortDateTime';
6
6
  export * from './LongDateTime';
7
7
  export * from './DistanceDate';
8
8
  export * from './Month';
9
+ export * from './Custom';
@@ -55,7 +55,7 @@ function useOutsideClose(_a) {
55
55
  // If component isn't open, then do nothing:
56
56
  if (!open)
57
57
  return undefined;
58
- // When the HTML document gets clicked, see if the click in side one of
58
+ // When the HTML document gets clicked, see if the click is inside one of
59
59
  // the HTML elements that were passed in. If so, do nothing. It outside
60
60
  // these elements, close the component.
61
61
  var handleClick = function (e) {
@@ -40,7 +40,7 @@ var FilterBase = function (props) {
40
40
  refs: [paneRef, buttonRef],
41
41
  onClose: function () { return setOpen(false); },
42
42
  escapeToClose: true,
43
- blurToClose: true
43
+ blurToClose: false
44
44
  });
45
45
  var _b = usePopper(buttonRef.current, paneRef.current, {
46
46
  placement: 'bottom-end',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longline/aqua-ui",
3
- "version": "1.0.229",
3
+ "version": "1.0.231",
4
4
  "description": "AquaUI",
5
5
  "author": "Alexander van Oostenrijk / Longline Environment",
6
6
  "license": "Commercial",