@sproutsocial/racine 24.0.0 → 24.1.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/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Change Log
2
2
 
3
+ ## 24.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 25d94a2: Racine now includes a new Duration component. It is a primitive component used to format durations of time according to our date & time formatting guidelines Additionally, the package includes a formatDuration helper, which can be used to get a stringified version of a duration.
8
+ - bd3fc39: ### Deprecation Notice: Flow Type System
9
+
10
+ We are officially deprecating the use of the Flow type system in `@sproutsocial/racine`. This change affects all Flow types used in this library. Flow support will be discontinued entirely on **October 24th**.
11
+
12
+ To ensure a smooth transition, please migrate your projects away from Flow types and start using TypeScript as soon as possible.
13
+
14
+ If you have any questions or need assistance, feel free to reach out to the team.
15
+
16
+ Thank you for your understanding and cooperation as we work towards improving our codebase.
17
+
3
18
  ## 24.0.0
4
19
 
5
20
  ### Major Changes
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.formatDuration = exports.default = void 0;
8
+ var React = _interopRequireWildcard(require("react"));
9
+ var _lruMemoize = _interopRequireDefault(require("lru-memoize"));
10
+ var _constants = require("../utils/constants");
11
+ var _VisuallyHidden = require("../VisuallyHidden");
12
+ var _constants2 = require("./constants");
13
+ var _styles = require("./styles");
14
+ var _jsxRuntime = require("react/jsx-runtime");
15
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
17
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
18
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
19
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
20
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
21
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
22
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
23
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
24
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
25
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
26
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
27
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
28
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
29
+ var getDivisionAndRemainder = function getDivisionAndRemainder(numerator, denominator) {
30
+ return [Math.floor(numerator / denominator), numerator % denominator];
31
+ };
32
+ var _createDurationFormatter = function _createDurationFormatter(locale, unitDisplay) {
33
+ var timeUnitFormatter = function timeUnitFormatter(locale, unit, unitDisplay) {
34
+ return Intl.NumberFormat(locale, {
35
+ style: "unit",
36
+ unit: unit,
37
+ unitDisplay: unitDisplay
38
+ }).format;
39
+ };
40
+ var formatDays = timeUnitFormatter(locale, "day", unitDisplay);
41
+ var formatHours = timeUnitFormatter(locale, "hour", unitDisplay);
42
+ var formatMinutes = timeUnitFormatter(locale, "minute", unitDisplay);
43
+ var formatSeconds = timeUnitFormatter(locale, "second", unitDisplay);
44
+ var formatMilliseconds = timeUnitFormatter(locale, "millisecond", unitDisplay);
45
+ var formatList = new Intl.ListFormat(locale, {
46
+ style: "narrow",
47
+ type: "unit"
48
+ });
49
+ return function (milliseconds) {
50
+ if (milliseconds <= 0) {
51
+ return formatMilliseconds(0);
52
+ }
53
+ var days;
54
+ var hours;
55
+ var minutes;
56
+ var seconds;
57
+ var _getDivisionAndRemain = getDivisionAndRemainder(milliseconds, 86400000);
58
+ var _getDivisionAndRemain2 = _slicedToArray(_getDivisionAndRemain, 2);
59
+ days = _getDivisionAndRemain2[0];
60
+ milliseconds = _getDivisionAndRemain2[1];
61
+ var _getDivisionAndRemain3 = getDivisionAndRemainder(milliseconds, 3600000);
62
+ var _getDivisionAndRemain4 = _slicedToArray(_getDivisionAndRemain3, 2);
63
+ hours = _getDivisionAndRemain4[0];
64
+ milliseconds = _getDivisionAndRemain4[1];
65
+ var _getDivisionAndRemain5 = getDivisionAndRemainder(milliseconds, 60000);
66
+ var _getDivisionAndRemain6 = _slicedToArray(_getDivisionAndRemain5, 2);
67
+ minutes = _getDivisionAndRemain6[0];
68
+ milliseconds = _getDivisionAndRemain6[1];
69
+ var _getDivisionAndRemain7 = getDivisionAndRemainder(milliseconds, 1000);
70
+ var _getDivisionAndRemain8 = _slicedToArray(_getDivisionAndRemain7, 2);
71
+ seconds = _getDivisionAndRemain8[0];
72
+ milliseconds = _getDivisionAndRemain8[1];
73
+ var list = [days ? formatDays(days) : null, hours ? formatHours(hours) : null, minutes ? formatMinutes(minutes) : null, seconds ? formatSeconds(seconds) : null, milliseconds ? formatMilliseconds(milliseconds) : null].filter(function (listItem) {
74
+ return listItem !== null;
75
+ });
76
+ return formatList.format(list);
77
+ };
78
+ };
79
+
80
+ // Memoize to reduce the energy of creating new instances of Intl.NumberFormat
81
+ var memoizer = (0, _lruMemoize.default)(_constants2.MEMO_CACHE_SIZE, _constants2.COMPARE_OBJECTS);
82
+ var createDurationFormatter = memoizer(_createDurationFormatter);
83
+ var isValidNumber = function isValidNumber(value) {
84
+ return typeof value === "number" && isFinite(value);
85
+ };
86
+ var getDuration = function getDuration(_ref) {
87
+ var returnType = _ref.returnType,
88
+ props = _ref.props;
89
+ var _props$display = props.display,
90
+ display = _props$display === void 0 ? "long" : _props$display,
91
+ invalidMillisecondsLabel = props.invalidMillisecondsLabel,
92
+ _props$locale = props.locale,
93
+ locale = _props$locale === void 0 ? "en-US" : _props$locale,
94
+ _props$milliseconds = props.milliseconds,
95
+ milliseconds = _props$milliseconds === void 0 ? null : _props$milliseconds,
96
+ qa = props.qa;
97
+ var isReturnTypeString = returnType === "string";
98
+ if (!isValidNumber(milliseconds)) {
99
+ return isReturnTypeString ? _constants.EM_DASH : /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
100
+ children: [invalidMillisecondsLabel ?
101
+ /*#__PURE__*/
102
+ // Give screen readers something useful to read off + hide the em dash
103
+ (0, _jsxRuntime.jsx)(_VisuallyHidden.VisuallyHidden, {
104
+ children: invalidMillisecondsLabel
105
+ }) : null, /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.Container, _objectSpread(_objectSpread({
106
+ "aria-hidden": true
107
+ }, qa), {}, {
108
+ children: _constants.EM_DASH
109
+ }))]
110
+ });
111
+ }
112
+ var fullText = createDurationFormatter(locale, display)(milliseconds);
113
+ return isReturnTypeString ? fullText : /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.Container, _objectSpread(_objectSpread({}, qa), {}, {
114
+ children: fullText
115
+ }));
116
+ };
117
+ var formatDuration = exports.formatDuration = function formatDuration(props) {
118
+ return getDuration({
119
+ returnType: "string",
120
+ props: props
121
+ });
122
+ };
123
+ var Duration = function Duration(props) {
124
+ return getDuration({
125
+ returnType: "component",
126
+ props: props
127
+ });
128
+ };
129
+ var _default = exports.default = Duration;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.MEMO_CACHE_SIZE = exports.COMPARE_OBJECTS = void 0;
7
+ var MEMO_CACHE_SIZE = exports.MEMO_CACHE_SIZE = 10;
8
+ var COMPARE_OBJECTS = exports.COMPARE_OBJECTS = true;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ var _exportNames = {
8
+ Duration: true,
9
+ formatDuration: true
10
+ };
11
+ Object.defineProperty(exports, "Duration", {
12
+ enumerable: true,
13
+ get: function get() {
14
+ return _Duration.default;
15
+ }
16
+ });
17
+ exports.default = void 0;
18
+ Object.defineProperty(exports, "formatDuration", {
19
+ enumerable: true,
20
+ get: function get() {
21
+ return _Duration.formatDuration;
22
+ }
23
+ });
24
+ var _Duration = _interopRequireWildcard(require("./Duration"));
25
+ var _DurationTypes = require("./DurationTypes");
26
+ Object.keys(_DurationTypes).forEach(function (key) {
27
+ if (key === "default" || key === "__esModule") return;
28
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
29
+ if (key in exports && exports[key] === _DurationTypes[key]) return;
30
+ Object.defineProperty(exports, key, {
31
+ enumerable: true,
32
+ get: function get() {
33
+ return _DurationTypes[key];
34
+ }
35
+ });
36
+ });
37
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
38
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
39
+ var _default = exports.default = _Duration.default;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Container = void 0;
7
+ var _styledComponents = _interopRequireDefault(require("styled-components"));
8
+ var _seedsReactText = _interopRequireDefault(require("@sproutsocial/seeds-react-text"));
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ var Container = exports.Container = (0, _styledComponents.default)(_seedsReactText.default).withConfig({
11
+ displayName: "styles__Container",
12
+ componentId: "sc-6o8ar7-0"
13
+ })(["font-variant-numeric:tabular-nums;"]);
package/commonjs/index.js CHANGED
@@ -264,6 +264,18 @@ Object.keys(_Drawer).forEach(function (key) {
264
264
  }
265
265
  });
266
266
  });
267
+ var _Duration = require("./Duration");
268
+ Object.keys(_Duration).forEach(function (key) {
269
+ if (key === "default" || key === "__esModule") return;
270
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
271
+ if (key in exports && exports[key] === _Duration[key]) return;
272
+ Object.defineProperty(exports, key, {
273
+ enumerable: true,
274
+ get: function get() {
275
+ return _Duration[key];
276
+ }
277
+ });
278
+ });
267
279
  var _EmptyState = require("./EmptyState");
268
280
  Object.keys(_EmptyState).forEach(function (key) {
269
281
  if (key === "default" || key === "__esModule") return;
@@ -0,0 +1,6 @@
1
+ import * as React from "react";
2
+ import type { TypeDurationProps } from "./DurationTypes";
3
+ export declare const formatDuration: (props: TypeDurationProps) => string;
4
+ declare const Duration: (props: TypeDurationProps) => React.ReactNode;
5
+ export default Duration;
6
+ //# sourceMappingURL=Duration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Duration.d.ts","sourceRoot":"","sources":["../../../src/Duration/Duration.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAO/B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AA+GzD,eAAO,MAAM,cAAc,UAAW,iBAAiB,KAAG,MAEzD,CAAC;AAEF,QAAA,MAAM,QAAQ,UAAW,iBAAiB,oBAEzC,CAAC;AAEF,eAAe,QAAQ,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { TypeTextProps } from "@sproutsocial/seeds-react-text";
2
+ import { TypeQaProps } from "../types/shared";
3
+ export interface TypeDurationProps extends Omit<TypeTextProps, "children"> {
4
+ /** The style of the formatted milliseconds */
5
+ milliseconds: number | null;
6
+ /** Locale to format. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument */
7
+ locale?: Intl.LocalesArgument;
8
+ /** The style of the formatted duration */
9
+ display?: "long" | "narrow";
10
+ /** Text to be read off by screen readers for invalid values (i.e., any value rendered as '—' (em dash)) */
11
+ invalidMillisecondsLabel?: string;
12
+ qa?: TypeQaProps;
13
+ }
14
+ //# sourceMappingURL=DurationTypes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DurationTypes.d.ts","sourceRoot":"","sources":["../../../src/Duration/DurationTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,WAAW,iBAAkB,SAAQ,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC;IACxE,8CAA8C;IAC9C,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAE5B,mIAAmI;IACnI,MAAM,CAAC,EAAE,IAAI,CAAC,eAAe,CAAC;IAE9B,0CAA0C;IAC1C,OAAO,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC;IAE5B,2GAA2G;IAC3G,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAElC,EAAE,CAAC,EAAE,WAAW,CAAC;CAClB"}
@@ -0,0 +1,2 @@
1
+ export declare const DurationTypeTest: () => import("react/jsx-runtime").JSX.Element;
2
+ //# sourceMappingURL=Duration.typetest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Duration.typetest.d.ts","sourceRoot":"","sources":["../../../../src/Duration/__tests__/Duration.typetest.tsx"],"names":[],"mappings":"AAQA,eAAO,MAAM,gBAAgB,+CAoB5B,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const testDuration: (milliseconds: any, options: {} | undefined, texts: any) => void;
2
+ export default testDuration;
3
+ //# sourceMappingURL=testDuration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testDuration.d.ts","sourceRoot":"","sources":["../../../../../src/Duration/__tests__/features/testDuration.tsx"],"names":[],"mappings":"AAWA,QAAA,MAAM,YAAY,kEAsBjB,CAAC;AAEF,eAAe,YAAY,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare const MEMO_CACHE_SIZE = 10;
2
+ export declare const COMPARE_OBJECTS = true;
3
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/Duration/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,KAAK,CAAC;AAClC,eAAO,MAAM,eAAe,OAAO,CAAC"}
@@ -0,0 +1,6 @@
1
+ import Duration, { formatDuration } from "./Duration";
2
+ export default Duration;
3
+ export { Duration };
4
+ export { formatDuration };
5
+ export * from "./DurationTypes";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Duration/index.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,EAAE,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEtD,eAAe,QAAQ,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,CAAC;AACpB,OAAO,EAAE,cAAc,EAAE,CAAC;AAC1B,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,11 @@
1
+ export declare const Container: import("styled-components").StyledComponent<{
2
+ ({ fontSize, children, qa, color, ...rest }: import("@sproutsocial/seeds-react-text").TypeTextProps): import("react/jsx-runtime").JSX.Element;
3
+ Headline: import("styled-components").StyledComponent<"span", any, import("@sproutsocial/seeds-react-text").TypeTextProps, never>;
4
+ SubHeadline: import("styled-components").StyledComponent<"span", any, import("@sproutsocial/seeds-react-text").TypeTextProps, never>;
5
+ SmallSubHeadline: import("styled-components").StyledComponent<"span", any, import("@sproutsocial/seeds-react-text").TypeTextProps, never>;
6
+ Byline: import("styled-components").StyledComponent<"span", any, import("@sproutsocial/seeds-react-text").TypeTextProps, never>;
7
+ SmallByline: import("styled-components").StyledComponent<"span", any, import("@sproutsocial/seeds-react-text").TypeTextProps, never>;
8
+ BodyCopy: import("styled-components").StyledComponent<"span", any, import("@sproutsocial/seeds-react-text").TypeTextProps, never>;
9
+ SmallBodyCopy: import("styled-components").StyledComponent<"span", any, import("@sproutsocial/seeds-react-text").TypeTextProps, never>;
10
+ }, import("styled-components").DefaultTheme, {}, never>;
11
+ //# sourceMappingURL=styles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../src/Duration/styles.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,SAAS;;;;;;;;;uDAErB,CAAC"}
@@ -21,6 +21,7 @@ export * from "@sproutsocial/seeds-react-checkbox";
21
21
  export * from "./Collapsible";
22
22
  export * from "./DatePicker";
23
23
  export * from "./Drawer";
24
+ export * from "./Duration";
24
25
  export * from "./EmptyState";
25
26
  export * from "./Fieldset";
26
27
  export * from "./FormField";
@@ -1 +1 @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C;AACjD,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,QAAQ,CAAC;AACvB,cAAc,gCAAgC,CAAC;AAC/C,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AAEjC;;GAEG;AACH,OAAO,EAAE,MAAM,IAAI,KAAK,EAAE,MAAM,UAAU,CAAC"}
@@ -0,0 +1,122 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
10
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
11
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
12
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
13
+ import * as React from "react";
14
+ import memoize from "lru-memoize";
15
+ import { EM_DASH } from "../utils/constants";
16
+ import { VisuallyHidden } from "../VisuallyHidden";
17
+ import { MEMO_CACHE_SIZE, COMPARE_OBJECTS } from "./constants";
18
+ import { Container } from "./styles";
19
+ import { jsx as _jsx } from "react/jsx-runtime";
20
+ import { Fragment as _Fragment } from "react/jsx-runtime";
21
+ import { jsxs as _jsxs } from "react/jsx-runtime";
22
+ var getDivisionAndRemainder = function getDivisionAndRemainder(numerator, denominator) {
23
+ return [Math.floor(numerator / denominator), numerator % denominator];
24
+ };
25
+ var _createDurationFormatter = function _createDurationFormatter(locale, unitDisplay) {
26
+ var timeUnitFormatter = function timeUnitFormatter(locale, unit, unitDisplay) {
27
+ return Intl.NumberFormat(locale, {
28
+ style: "unit",
29
+ unit: unit,
30
+ unitDisplay: unitDisplay
31
+ }).format;
32
+ };
33
+ var formatDays = timeUnitFormatter(locale, "day", unitDisplay);
34
+ var formatHours = timeUnitFormatter(locale, "hour", unitDisplay);
35
+ var formatMinutes = timeUnitFormatter(locale, "minute", unitDisplay);
36
+ var formatSeconds = timeUnitFormatter(locale, "second", unitDisplay);
37
+ var formatMilliseconds = timeUnitFormatter(locale, "millisecond", unitDisplay);
38
+ var formatList = new Intl.ListFormat(locale, {
39
+ style: "narrow",
40
+ type: "unit"
41
+ });
42
+ return function (milliseconds) {
43
+ if (milliseconds <= 0) {
44
+ return formatMilliseconds(0);
45
+ }
46
+ var days;
47
+ var hours;
48
+ var minutes;
49
+ var seconds;
50
+ var _getDivisionAndRemain = getDivisionAndRemainder(milliseconds, 86400000);
51
+ var _getDivisionAndRemain2 = _slicedToArray(_getDivisionAndRemain, 2);
52
+ days = _getDivisionAndRemain2[0];
53
+ milliseconds = _getDivisionAndRemain2[1];
54
+ var _getDivisionAndRemain3 = getDivisionAndRemainder(milliseconds, 3600000);
55
+ var _getDivisionAndRemain4 = _slicedToArray(_getDivisionAndRemain3, 2);
56
+ hours = _getDivisionAndRemain4[0];
57
+ milliseconds = _getDivisionAndRemain4[1];
58
+ var _getDivisionAndRemain5 = getDivisionAndRemainder(milliseconds, 60000);
59
+ var _getDivisionAndRemain6 = _slicedToArray(_getDivisionAndRemain5, 2);
60
+ minutes = _getDivisionAndRemain6[0];
61
+ milliseconds = _getDivisionAndRemain6[1];
62
+ var _getDivisionAndRemain7 = getDivisionAndRemainder(milliseconds, 1000);
63
+ var _getDivisionAndRemain8 = _slicedToArray(_getDivisionAndRemain7, 2);
64
+ seconds = _getDivisionAndRemain8[0];
65
+ milliseconds = _getDivisionAndRemain8[1];
66
+ var list = [days ? formatDays(days) : null, hours ? formatHours(hours) : null, minutes ? formatMinutes(minutes) : null, seconds ? formatSeconds(seconds) : null, milliseconds ? formatMilliseconds(milliseconds) : null].filter(function (listItem) {
67
+ return listItem !== null;
68
+ });
69
+ return formatList.format(list);
70
+ };
71
+ };
72
+
73
+ // Memoize to reduce the energy of creating new instances of Intl.NumberFormat
74
+ var memoizer = memoize(MEMO_CACHE_SIZE, COMPARE_OBJECTS);
75
+ var createDurationFormatter = memoizer(_createDurationFormatter);
76
+ var isValidNumber = function isValidNumber(value) {
77
+ return typeof value === "number" && isFinite(value);
78
+ };
79
+ var getDuration = function getDuration(_ref) {
80
+ var returnType = _ref.returnType,
81
+ props = _ref.props;
82
+ var _props$display = props.display,
83
+ display = _props$display === void 0 ? "long" : _props$display,
84
+ invalidMillisecondsLabel = props.invalidMillisecondsLabel,
85
+ _props$locale = props.locale,
86
+ locale = _props$locale === void 0 ? "en-US" : _props$locale,
87
+ _props$milliseconds = props.milliseconds,
88
+ milliseconds = _props$milliseconds === void 0 ? null : _props$milliseconds,
89
+ qa = props.qa;
90
+ var isReturnTypeString = returnType === "string";
91
+ if (!isValidNumber(milliseconds)) {
92
+ return isReturnTypeString ? EM_DASH : /*#__PURE__*/_jsxs(_Fragment, {
93
+ children: [invalidMillisecondsLabel ?
94
+ /*#__PURE__*/
95
+ // Give screen readers something useful to read off + hide the em dash
96
+ _jsx(VisuallyHidden, {
97
+ children: invalidMillisecondsLabel
98
+ }) : null, /*#__PURE__*/_jsx(Container, _objectSpread(_objectSpread({
99
+ "aria-hidden": true
100
+ }, qa), {}, {
101
+ children: EM_DASH
102
+ }))]
103
+ });
104
+ }
105
+ var fullText = createDurationFormatter(locale, display)(milliseconds);
106
+ return isReturnTypeString ? fullText : /*#__PURE__*/_jsx(Container, _objectSpread(_objectSpread({}, qa), {}, {
107
+ children: fullText
108
+ }));
109
+ };
110
+ export var formatDuration = function formatDuration(props) {
111
+ return getDuration({
112
+ returnType: "string",
113
+ props: props
114
+ });
115
+ };
116
+ var Duration = function Duration(props) {
117
+ return getDuration({
118
+ returnType: "component",
119
+ props: props
120
+ });
121
+ };
122
+ export default Duration;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export var MEMO_CACHE_SIZE = 10;
2
+ export var COMPARE_OBJECTS = true;
@@ -0,0 +1,5 @@
1
+ import Duration, { formatDuration } from "./Duration";
2
+ export default Duration;
3
+ export { Duration };
4
+ export { formatDuration };
5
+ export * from "./DurationTypes";
@@ -0,0 +1,6 @@
1
+ import styled from "styled-components";
2
+ import Text from "@sproutsocial/seeds-react-text";
3
+ export var Container = styled(Text).withConfig({
4
+ displayName: "styles__Container",
5
+ componentId: "sc-6o8ar7-0"
6
+ })(["font-variant-numeric:tabular-nums;"]);
package/lib/index.js CHANGED
@@ -26,6 +26,7 @@ export * from "@sproutsocial/seeds-react-checkbox";
26
26
  export * from "./Collapsible";
27
27
  export * from "./DatePicker";
28
28
  export * from "./Drawer";
29
+ export * from "./Duration";
29
30
  export * from "./EmptyState";
30
31
  export * from "./Fieldset";
31
32
  export * from "./FormField";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sproutsocial/racine",
3
- "version": "24.0.0",
3
+ "version": "24.1.0",
4
4
  "license": "MIT",
5
5
  "engines": {
6
6
  "node": ">=18"