ag-common 0.0.317 → 0.0.320

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.
Files changed (48) hide show
  1. package/dist/api/helpers/dynamo.d.ts +2 -2
  2. package/dist/api/helpers/dynamo.js +6 -6
  3. package/dist/api/helpers/s3.d.ts +2 -2
  4. package/dist/api/helpers/s3.js +3 -3
  5. package/dist/api/helpers/ses.d.ts +2 -2
  6. package/dist/api/helpers/ses.js +3 -3
  7. package/dist/api/helpers/sqs.d.ts +2 -2
  8. package/dist/api/helpers/sqs.js +3 -3
  9. package/dist/common/helpers/date.d.ts +15 -1
  10. package/dist/common/helpers/date.js +19 -8
  11. package/dist/common/helpers/string.d.ts +1 -0
  12. package/dist/common/helpers/string.js +12 -1
  13. package/dist/ui/components/Chevron/index.d.ts +7 -6
  14. package/dist/ui/components/Close/index.d.ts +5 -4
  15. package/dist/ui/components/Confirm/Dialog.d.ts +7 -5
  16. package/dist/ui/components/Confirm/Dialog.js +5 -0
  17. package/dist/ui/components/Confirm/Modal.d.ts +2 -7
  18. package/dist/ui/components/Confirm/index.d.ts +1 -0
  19. package/dist/ui/components/Confirm/index.js +1 -0
  20. package/dist/ui/components/Confirm/types.d.ts +15 -0
  21. package/dist/ui/components/Confirm/types.js +2 -0
  22. package/dist/ui/components/FlexColumn/index.d.ts +2 -2
  23. package/dist/ui/components/FlexRow/index.d.ts +2 -2
  24. package/dist/ui/components/Icon/index.d.ts +2 -2
  25. package/dist/ui/components/KebabDots/index.d.ts +4 -3
  26. package/dist/ui/components/Loader/index.d.ts +5 -4
  27. package/dist/ui/components/Loader/index.js +1 -1
  28. package/dist/ui/components/Modal/types.d.ts +0 -6
  29. package/dist/ui/components/ProgressBar/index.d.ts +12 -0
  30. package/dist/ui/components/ProgressBar/index.js +50 -0
  31. package/dist/ui/components/Prompt/Dialog.d.ts +2 -2
  32. package/dist/ui/components/Prompt/Modal.d.ts +11 -8
  33. package/dist/ui/components/Prompt/Modal.js +4 -2
  34. package/dist/ui/components/RowOrColumn/index.d.ts +2 -0
  35. package/dist/ui/components/Search/Inline.d.ts +2 -2
  36. package/dist/ui/components/Search/Modal.d.ts +2 -2
  37. package/dist/ui/components/Search/types.d.ts +2 -0
  38. package/dist/ui/components/Sidebar/index.d.ts +7 -6
  39. package/dist/ui/components/Table/index.d.ts +5 -4
  40. package/dist/ui/components/Table/index.js +1 -1
  41. package/dist/ui/components/UserImage/index.d.ts +12 -9
  42. package/dist/ui/components/UserImage/index.js +1 -1
  43. package/dist/ui/components/index.d.ts +4 -3
  44. package/dist/ui/components/index.js +4 -3
  45. package/dist/ui/helpers/date.d.ts +7 -1
  46. package/dist/ui/helpers/date.js +17 -16
  47. package/dist/ui/helpers/useLocalStorage.js +3 -3
  48. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  import { DYNAMOKEYS, IQueryDynamo, Key } from '../types';
2
- import AWS from 'aws-sdk';
3
- export declare let dynamoDb: AWS.DynamoDB.DocumentClient;
2
+ import DynamoDB from 'aws-sdk/clients/dynamodb';
3
+ export declare let dynamoDb: DynamoDB.DocumentClient;
4
4
  export declare const setDynamo: (region: string) => void;
5
5
  export declare const putDynamo: <T>(item: T, tableName: string) => Promise<{
6
6
  error?: string | undefined;
@@ -17,11 +17,11 @@ const log_1 = require("../../common/helpers/log");
17
17
  const array_1 = require("../../common/helpers/array");
18
18
  const sleep_1 = require("../../common/helpers/sleep");
19
19
  const async_1 = require("../../common/helpers/async");
20
- const aws_sdk_1 = __importDefault(require("aws-sdk"));
20
+ const dynamodb_1 = __importDefault(require("aws-sdk/clients/dynamodb"));
21
21
  // eslint-disable-next-line import/no-mutable-exports
22
- exports.dynamoDb = new aws_sdk_1.default.DynamoDB.DocumentClient();
22
+ exports.dynamoDb = new dynamodb_1.default.DocumentClient();
23
23
  const setDynamo = (region) => {
24
- exports.dynamoDb = new aws_sdk_1.default.DynamoDB.DocumentClient({ region });
24
+ exports.dynamoDb = new dynamodb_1.default.DocumentClient({ region });
25
25
  };
26
26
  exports.setDynamo = setDynamo;
27
27
  const putDynamo = (item, tableName) => __awaiter(void 0, void 0, void 0, function* () {
@@ -194,11 +194,11 @@ const getItemsDynamo = ({ tableName, items, }) => __awaiter(void 0, void 0, void
194
194
  },
195
195
  },
196
196
  };
197
- const dbRaw = new aws_sdk_1.default.DynamoDB({ apiVersion: '2012-10-08' });
197
+ const dbRaw = new dynamodb_1.default({ apiVersion: '2012-10-08' });
198
198
  try {
199
199
  const res = yield dbRaw.batchGetItem(params).promise();
200
200
  (0, log_1.debug)(`got dynamo getitems=${JSON.stringify(res, null, 2)}`);
201
- let ret = ((_f = (_e = res.Responses) === null || _e === void 0 ? void 0 : _e[tableName]) === null || _f === void 0 ? void 0 : _f.map((s) => aws_sdk_1.default.DynamoDB.Converter.unmarshall(s))) || [];
201
+ let ret = ((_f = (_e = res.Responses) === null || _e === void 0 ? void 0 : _e[tableName]) === null || _f === void 0 ? void 0 : _f.map((s) => dynamodb_1.default.Converter.unmarshall(s))) || [];
202
202
  return ret;
203
203
  }
204
204
  catch (e) {
@@ -312,7 +312,7 @@ const getDynamoTtl = (days) => Math.ceil(new Date().getTime() / 1000) + days * 8
312
312
  exports.getDynamoTtl = getDynamoTtl;
313
313
  const wipeTable = (tableName) => __awaiter(void 0, void 0, void 0, function* () {
314
314
  var _j;
315
- const dbRaw = new aws_sdk_1.default.DynamoDB({ apiVersion: '2012-10-08' });
315
+ const dbRaw = new dynamodb_1.default({ apiVersion: '2012-10-08' });
316
316
  let infoV = yield dbRaw
317
317
  .describeTable({
318
318
  TableName: tableName,
@@ -1,13 +1,13 @@
1
1
  /// <reference types="node" />
2
2
  import { Blob } from 'aws-sdk/lib/dynamodb/document_client';
3
- import AWS from 'aws-sdk';
3
+ import S3 from 'aws-sdk/clients/s3';
4
4
  export declare const setS3: (region: string) => void;
5
5
  export declare const getS3Object: ({ fileurl, }: {
6
6
  fileurl: {
7
7
  Bucket: string;
8
8
  Key: string;
9
9
  };
10
- }) => Promise<import("aws-sdk/lib/request").PromiseResult<AWS.S3.GetObjectOutput, AWS.AWSError>>;
10
+ }) => Promise<import("aws-sdk/lib/request").PromiseResult<S3.GetObjectOutput, import("aws-sdk/lib/error").AWSError>>;
11
11
  export declare const putS3Object: ({ Body, Bucket, Key, ContentType, }: {
12
12
  ContentType?: string | undefined;
13
13
  Body: string | Blob;
@@ -13,10 +13,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.deleteFile = exports.uploadFile = exports.putS3Object = exports.getS3Object = exports.setS3 = void 0;
16
- const aws_sdk_1 = __importDefault(require("aws-sdk"));
17
- let s3 = new aws_sdk_1.default.S3();
16
+ const s3_1 = __importDefault(require("aws-sdk/clients/s3"));
17
+ let s3 = new s3_1.default();
18
18
  const setS3 = (region) => {
19
- s3 = new aws_sdk_1.default.S3({ region });
19
+ s3 = new s3_1.default({ region });
20
20
  };
21
21
  exports.setS3 = setS3;
22
22
  const getS3Object = ({ fileurl, }) => __awaiter(void 0, void 0, void 0, function* () {
@@ -1,5 +1,5 @@
1
- import AWS from 'aws-sdk';
2
- export declare let ses: AWS.SES;
1
+ import SES from 'aws-sdk/clients/ses';
2
+ export declare let ses: SES;
3
3
  export declare const setSes: (region: string) => void;
4
4
  export interface ISendEmail {
5
5
  to: string;
@@ -13,10 +13,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.sendEmails = exports.sendEmail = exports.setSes = exports.ses = void 0;
16
- const aws_sdk_1 = __importDefault(require("aws-sdk"));
17
- exports.ses = new aws_sdk_1.default.SES();
16
+ const ses_1 = __importDefault(require("aws-sdk/clients/ses"));
17
+ exports.ses = new ses_1.default();
18
18
  const setSes = (region) => {
19
- exports.ses = new aws_sdk_1.default.SES({ region });
19
+ exports.ses = new ses_1.default({ region });
20
20
  };
21
21
  exports.setSes = setSes;
22
22
  const sendEmail = ({ to, message, subject, sourceArn, from, }) => __awaiter(void 0, void 0, void 0, function* () {
@@ -1,4 +1,4 @@
1
- import AWS from 'aws-sdk';
2
- export declare let sqs: AWS.SQS;
1
+ import SQS from 'aws-sdk/clients/sqs';
2
+ export declare let sqs: SQS;
3
3
  export declare const setSqs: (region: string) => void;
4
4
  export declare const sendMessages: <T>(items: T[], queueUrl: string) => Promise<void>;
@@ -14,11 +14,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.sendMessages = exports.setSqs = exports.sqs = void 0;
16
16
  const common_1 = require("../../common");
17
- const aws_sdk_1 = __importDefault(require("aws-sdk"));
17
+ const sqs_1 = __importDefault(require("aws-sdk/clients/sqs"));
18
18
  // eslint-disable-next-line import/no-mutable-exports
19
- exports.sqs = new aws_sdk_1.default.SQS();
19
+ exports.sqs = new sqs_1.default();
20
20
  const setSqs = (region) => {
21
- exports.sqs = new aws_sdk_1.default.SQS({ region });
21
+ exports.sqs = new sqs_1.default({ region });
22
22
  };
23
23
  exports.setSqs = setSqs;
24
24
  const sendMessages = (items, queueUrl) => __awaiter(void 0, void 0, void 0, function* () {
@@ -3,7 +3,21 @@ export declare const addHours: (d: number, h: number) => Date;
3
3
  export declare const addDays: (dIn: Date, count: number) => Date;
4
4
  export declare const addMinutes: (date: Date, minutes: number) => Date;
5
5
  export declare const lastDayInMonth: (date: Date) => Date;
6
- export declare const dateDiffDays: (date1: Date, date2: Date) => number;
6
+ /**
7
+ * breaks ticks into time diffs
8
+ * @param lowDate
9
+ * @param highDate defaults to Date.Now
10
+ * @returns
11
+ */
12
+ export declare const dateDiff: (lowDate: Date, highDate?: Date) => {
13
+ totalMinutes: number;
14
+ totalHours: number;
15
+ totalDays: number;
16
+ totalYears: number;
17
+ };
18
+ /**
19
+ * convert csharp datetime to js datetime
20
+ */
7
21
  export declare const CSharpToJs: (charpTicks: number) => Date;
8
22
  /**
9
23
  *
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.dateTimeToNearestMinute = exports.CSharpToJs = exports.dateDiffDays = exports.lastDayInMonth = exports.addMinutes = exports.addDays = exports.addHours = exports.getTimeSeconds = void 0;
3
+ exports.dateTimeToNearestMinute = exports.CSharpToJs = exports.dateDiff = exports.lastDayInMonth = exports.addMinutes = exports.addDays = exports.addHours = exports.getTimeSeconds = void 0;
4
+ const math_1 = require("./math");
4
5
  const getTimeSeconds = () => Math.ceil(new Date().getTime() / 1000);
5
6
  exports.getTimeSeconds = getTimeSeconds;
6
7
  const addHours = (d, h) => {
@@ -17,14 +18,24 @@ const addMinutes = (date, minutes) => new Date(date.getTime() + minutes * 60000)
17
18
  exports.addMinutes = addMinutes;
18
19
  const lastDayInMonth = (date) => new Date(date.getFullYear(), date.getMonth() + 1, 0);
19
20
  exports.lastDayInMonth = lastDayInMonth;
20
- const dateDiffDays = (date1, date2) => {
21
- const dt1 = new Date(date1);
22
- const dt2 = new Date(date2);
23
- return Math.floor((Date.UTC(dt2.getFullYear(), dt2.getMonth(), dt2.getDate()) -
24
- Date.UTC(dt1.getFullYear(), dt1.getMonth(), dt1.getDate())) /
25
- 1000);
21
+ /**
22
+ * breaks ticks into time diffs
23
+ * @param lowDate
24
+ * @param highDate defaults to Date.Now
25
+ * @returns
26
+ */
27
+ const dateDiff = (lowDate, highDate) => {
28
+ const ticksSince = (highDate !== null && highDate !== void 0 ? highDate : new Date()).getTime() - lowDate.getTime();
29
+ const totalMinutes = (0, math_1.toFixedDown)(ticksSince / 1000 / 60, 0);
30
+ const totalHours = (0, math_1.toFixedDown)(totalMinutes / 60, 0);
31
+ const totalDays = (0, math_1.toFixedDown)(totalHours / 24, 0);
32
+ const totalYears = (0, math_1.toFixedDown)(totalDays / 365, 0);
33
+ return { totalMinutes, totalHours, totalDays, totalYears };
26
34
  };
27
- exports.dateDiffDays = dateDiffDays;
35
+ exports.dateDiff = dateDiff;
36
+ /**
37
+ * convert csharp datetime to js datetime
38
+ */
28
39
  const CSharpToJs = (charpTicks) => {
29
40
  // ticks are in nanotime; convert to microtime
30
41
  const ticks = charpTicks / 10000;
@@ -61,3 +61,4 @@ export declare const chunkString: (str: string, length: number) => string[];
61
61
  */
62
62
  export declare function stringToObject(raw: string, splitKeyValue: string, splitKeys: string): Record<string, string>;
63
63
  export declare const indexOfNumber: (str: string, char: string, num?: number) => number | undefined;
64
+ export declare function isValidUrl(raw: string): boolean;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.indexOfNumber = exports.stringToObject = exports.chunkString = exports.safeStringify = exports.containsInsensitive = exports.containsInsensitiveIndex = exports.replaceRemove = exports.toTitleCase = exports.niceUrl = exports.truncate = exports.trim = exports.trimSide = exports.csvJSON = exports.fromBase64 = exports.toBase64 = void 0;
3
+ exports.isValidUrl = exports.indexOfNumber = exports.stringToObject = exports.chunkString = exports.safeStringify = exports.containsInsensitive = exports.containsInsensitiveIndex = exports.replaceRemove = exports.toTitleCase = exports.niceUrl = exports.truncate = exports.trim = exports.trimSide = exports.csvJSON = exports.fromBase64 = exports.toBase64 = void 0;
4
4
  const toBase64 = (str) => Buffer.from(str).toString('base64');
5
5
  exports.toBase64 = toBase64;
6
6
  const fromBase64 = (str) => Buffer.from(decodeURIComponent(str), 'base64').toString();
@@ -197,3 +197,14 @@ const indexOfNumber = (str, char, num = 0) => {
197
197
  return ret;
198
198
  };
199
199
  exports.indexOfNumber = indexOfNumber;
200
+ function isValidUrl(raw) {
201
+ let url;
202
+ try {
203
+ url = new URL(raw);
204
+ }
205
+ catch (_) {
206
+ return false;
207
+ }
208
+ return url.protocol === 'http:' || url.protocol === 'https:';
209
+ }
210
+ exports.isValidUrl = isValidUrl;
@@ -1,11 +1,12 @@
1
1
  /// <reference types="react" />
2
- export declare const Chevron: ({ width, className, colour, onToggle, point, }: {
2
+ export interface IChevron {
3
3
  /**
4
4
  * default right
5
5
  */
6
6
  point: 'up' | 'down' | 'left' | 'right';
7
- colour?: string | undefined;
8
- className?: string | undefined;
9
- width?: string | undefined;
10
- onToggle?: (() => void) | undefined;
11
- }) => JSX.Element;
7
+ colour?: string;
8
+ className?: string;
9
+ width?: string;
10
+ onToggle?: () => void;
11
+ }
12
+ export declare const Chevron: ({ width, className, colour, onToggle, point, }: IChevron) => JSX.Element;
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
- export declare const Close: (p: {
3
- onClick?: ((ev: React.MouseEvent<HTMLDivElement, MouseEvent>) => void) | undefined;
4
- className?: string | undefined;
5
- }) => JSX.Element;
2
+ export interface IClose {
3
+ onClick?: (ev: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
4
+ className?: string;
5
+ }
6
+ export declare const Close: (p: IClose) => JSX.Element;
@@ -1,5 +1,7 @@
1
- export interface IConfirmAction {
2
- topText?: string;
3
- bottomText: string;
4
- }
5
- export declare const ConfirmDialog: ({ bottomText, topText, }: IConfirmAction) => Promise<boolean>;
1
+ import { IConfirmDialog } from './types';
2
+ /**
3
+ * opens a dialog programatically
4
+ * @param param0
5
+ * @returns
6
+ */
7
+ export declare const ConfirmDialog: ({ bottomText, topText, }: IConfirmDialog) => Promise<boolean>;
@@ -17,6 +17,11 @@ const Modal_1 = require("./Modal");
17
17
  const log_1 = require("../../../common/helpers/log");
18
18
  const react_dom_1 = __importDefault(require("react-dom"));
19
19
  const react_1 = __importDefault(require("react"));
20
+ /**
21
+ * opens a dialog programatically
22
+ * @param param0
23
+ * @returns
24
+ */
20
25
  const ConfirmDialog = ({ bottomText, topText, }) => __awaiter(void 0, void 0, void 0, function* () {
21
26
  return new Promise((res) => {
22
27
  const idName = 'ag-confirm-dialog';
@@ -1,8 +1,3 @@
1
1
  /// <reference types="react" />
2
- export declare const ConfirmModal: ({ onSubmit, bottomText, topText, okText, cancelText, }: {
3
- onSubmit: (v: boolean) => void;
4
- topText?: string | undefined;
5
- bottomText: string;
6
- okText?: string | undefined;
7
- cancelText?: string | undefined;
8
- }) => JSX.Element;
2
+ import { IConfirmModal } from './types';
3
+ export declare const ConfirmModal: ({ onSubmit, bottomText, topText, okText, cancelText, }: IConfirmModal) => JSX.Element;
@@ -1,2 +1,3 @@
1
+ export * from './types';
1
2
  export * from './Dialog';
2
3
  export * from './Modal';
@@ -14,5 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./types"), exports);
17
18
  __exportStar(require("./Dialog"), exports);
18
19
  __exportStar(require("./Modal"), exports);
@@ -0,0 +1,15 @@
1
+ export interface IConfirmDialog {
2
+ /** default (undefined) */
3
+ topText?: string;
4
+ bottomText: string;
5
+ }
6
+ export interface IConfirmModal {
7
+ onSubmit: (v: boolean) => void;
8
+ /** default (undefined) */
9
+ topText?: string;
10
+ bottomText: string;
11
+ /** default OK */
12
+ okText?: string;
13
+ /** default Cancel */
14
+ cancelText?: string;
15
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +1,3 @@
1
1
  /// <reference types="react" />
2
- import { IRowOrColumn } from '../RowOrColumn';
3
- export declare const FlexColumn: (props: IRowOrColumn) => JSX.Element;
2
+ import { IFlexColumn } from '../RowOrColumn';
3
+ export declare const FlexColumn: (props: IFlexColumn) => JSX.Element;
@@ -1,3 +1,3 @@
1
1
  /// <reference types="react" />
2
- import { IRowOrColumn } from '../RowOrColumn';
3
- export declare const FlexRow: (props: IRowOrColumn) => JSX.Element;
2
+ import { IFlexRow } from '../RowOrColumn';
3
+ export declare const FlexRow: (props: IFlexRow) => JSX.Element;
@@ -1,5 +1,5 @@
1
1
  import React, { ReactNode } from 'react';
2
- export interface IIconProps {
2
+ export interface IIcon {
3
3
  disabled?: boolean;
4
4
  fill?: string;
5
5
  outline?: string;
@@ -21,4 +21,4 @@ export interface IIconProps {
21
21
  className?: string;
22
22
  }
23
23
  export declare const IconF: import("styled-components").StyledComponent<"span", any, {}, never>;
24
- export declare const Icon: (pr: IIconProps) => JSX.Element;
24
+ export declare const Icon: (pr: IIcon) => JSX.Element;
@@ -1,4 +1,5 @@
1
1
  /// <reference types="react" />
2
- export declare const KebabDots: ({ onClick }: {
3
- onClick?: (() => Promise<void>) | undefined;
4
- }) => JSX.Element;
2
+ export interface IKebabDots {
3
+ onClick?: () => Promise<void>;
4
+ }
5
+ export declare const KebabDots: ({ onClick }: IKebabDots) => JSX.Element;
@@ -1,12 +1,13 @@
1
1
  /// <reference types="react" />
2
- export declare const Loader: ({ name, height, width, }: {
2
+ export interface ILoader {
3
3
  /**
4
4
  * default 2rem
5
5
  */
6
- width?: string | null | undefined;
6
+ width?: string | null;
7
7
  /**
8
8
  * default 2rem
9
9
  */
10
- height?: string | null | undefined;
10
+ height?: string | null;
11
11
  name: string;
12
- }) => JSX.Element;
12
+ }
13
+ export declare const Loader: ({ name, height, width }: ILoader) => JSX.Element;
@@ -63,7 +63,7 @@ const LoadingBack = styled_components_1.default.div `
63
63
  }
64
64
  transition: opacity 5s;
65
65
  `;
66
- const Loader = ({ name, height = '2rem', width = '2rem', }) => {
66
+ const Loader = ({ name, height = '2rem', width = '2rem' }) => {
67
67
  const [trans, setTrans] = (0, react_1.useState)(true);
68
68
  (0, react_1.useEffect)(() => {
69
69
  setTrans(false);
@@ -10,9 +10,3 @@ export interface IModal {
10
10
  className?: string;
11
11
  closeOnClickOutside?: boolean;
12
12
  }
13
- export interface IPromptAction {
14
- topText?: string;
15
- bottomText: string;
16
- defaultValue?: string;
17
- placeholder?: string;
18
- }
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ export interface IProgressBar {
3
+ min: number;
4
+ max: number;
5
+ /** default #4d76ff */
6
+ frontColour?: string;
7
+ /** default #eee */
8
+ backColour?: string;
9
+ /** default 25,50,75 */
10
+ dotPercentages?: number[] | null;
11
+ }
12
+ export declare const ProgressBar: (p: IProgressBar) => JSX.Element;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ProgressBar = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const styled_components_1 = __importDefault(require("styled-components"));
9
+ const styles_1 = require("../../styles");
10
+ const Base = styled_components_1.default.div `
11
+ position: relative;
12
+ min-width: 5rem;
13
+ width: 100%;
14
+ height: 2rem;
15
+ border-radius: 1rem;
16
+ overflow: hidden;
17
+ `;
18
+ const Bar = styled_components_1.default.div `
19
+ position: absolute;
20
+ top: 0;
21
+ bottom: 0;
22
+ left: 0;
23
+ transition: width 0.2s ease;
24
+ `;
25
+ const Dot = styled_components_1.default.div `
26
+ position: absolute;
27
+ top: calc(50% - 0.25rem);
28
+ width: 0.5rem;
29
+ height: 0.5rem;
30
+ background-color: #aaa;
31
+ z-index: 1;
32
+ border-radius: 50%;
33
+ &[data-invert='true'] {
34
+ background-color: #333;
35
+ }
36
+ `;
37
+ const ProgressBar = (p) => {
38
+ const { min, max, frontColour = styles_1.colours.notificationBlue, backColour = '#eee', dotPercentages = [25, 50, 75], } = p;
39
+ const barWidth = (min / max) * 100;
40
+ return (react_1.default.createElement(Base, { style: { backgroundColor: backColour } },
41
+ react_1.default.createElement(Bar, { style: {
42
+ width: `${barWidth}%`,
43
+ backgroundColor: frontColour,
44
+ } }),
45
+ (dotPercentages === null || dotPercentages === void 0 ? void 0 : dotPercentages.map) &&
46
+ dotPercentages.map((v) => {
47
+ return (react_1.default.createElement(Dot, { key: v, style: { left: `calc(${v}% - 0.25rem)` }, "data-invert": v > barWidth }));
48
+ })));
49
+ };
50
+ exports.ProgressBar = ProgressBar;
@@ -1,7 +1,7 @@
1
- export interface IPromptAction {
1
+ export interface IPromptDialog {
2
2
  topText?: string;
3
3
  bottomText: string;
4
4
  defaultValue?: string;
5
5
  placeholder?: string;
6
6
  }
7
- export declare const PromptDialog: (p: IPromptAction) => Promise<string | undefined>;
7
+ export declare const PromptDialog: (p: IPromptDialog) => Promise<string | undefined>;
@@ -1,11 +1,14 @@
1
1
  /// <reference types="react" />
2
- export declare const PromptModal: ({ wrapper, res, bottomText, topText, okText, cancelText, defaultValue, placeholder, }: {
3
- defaultValue?: string | undefined;
4
- placeholder?: string | undefined;
2
+ export interface IPromptModal {
3
+ defaultValue?: string;
4
+ placeholder?: string;
5
5
  res: (v: string | undefined) => void;
6
- wrapper: HTMLDivElement;
7
- topText?: string | undefined;
6
+ wrapper?: HTMLDivElement;
7
+ topText?: string;
8
8
  bottomText: string;
9
- okText?: string | undefined;
10
- cancelText?: string | undefined;
11
- }) => JSX.Element;
9
+ /** default 'OK' */
10
+ okText?: string;
11
+ /** default "cancel" */
12
+ cancelText?: string;
13
+ }
14
+ export declare const PromptModal: ({ wrapper, res, bottomText, topText, okText, cancelText, defaultValue, placeholder, }: IPromptModal) => JSX.Element;
@@ -70,8 +70,10 @@ const PromptModal = ({ wrapper, res, bottomText, topText, okText = 'OK', cancelT
70
70
  res(v);
71
71
  }
72
72
  finally {
73
- react_dom_1.default.unmountComponentAtNode(wrapper);
74
- wrapper.remove();
73
+ if (wrapper) {
74
+ react_dom_1.default.unmountComponentAtNode(wrapper);
75
+ wrapper.remove();
76
+ }
75
77
  }
76
78
  };
77
79
  return (react_1.default.createElement(Modal_1.Modal, { position: "center", topPosition: "center", open: true, setOpen: () => ret(undefined), showCloseButton: false, closeOnClickOutside: false },
@@ -8,4 +8,6 @@ export interface IRowOrColumn {
8
8
  title?: string;
9
9
  enableOverflow?: boolean;
10
10
  }
11
+ export declare type IFlexColumn = IRowOrColumn;
12
+ export declare type IFlexRow = IRowOrColumn;
11
13
  export declare const RowOrColumn: (props: IRowOrColumn) => JSX.Element;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
- import { ISearchDialog, TSearchModalRes } from './types';
3
- export declare const SearchInline: <T>(p: ISearchDialog<T> & {
2
+ import { ISearchInline, TSearchModalRes } from './types';
3
+ export declare const SearchInline: <T>(p: ISearchInline<T> & {
4
4
  onSelectItem?: ((v: TSearchModalRes<T>) => void) | undefined;
5
5
  onSearchTextChange?: ((v: string) => void) | undefined;
6
6
  }) => JSX.Element;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { ISearchDialog, TSearchModalRes } from './types';
3
- export declare const SearchModal: <T>(p: ISearchDialog<T> & {
2
+ import { ISearchModal, TSearchModalRes } from './types';
3
+ export declare const SearchModal: <T>(p: ISearchModal<T> & {
4
4
  onSelectItem: (v: TSearchModalRes<T>) => void;
5
5
  }) => JSX.Element;
@@ -29,3 +29,5 @@ export declare type TSearchModalRes<T> = undefined | {
29
29
  foundItem: T;
30
30
  searchText: string;
31
31
  };
32
+ export declare type ISearchModal<T> = ISearchDialog<T>;
33
+ export declare type ISearchInline<T> = ISearchDialog<T>;
@@ -1,17 +1,18 @@
1
1
  /// <reference types="react" />
2
- export declare const Sidebar: ({ children, className, key, cookieDocument, width, }: {
2
+ export interface ISidebar {
3
3
  children: any;
4
- className?: string | undefined;
4
+ className?: string;
5
5
  /**
6
6
  * used for localstorage. default 'sidebar'
7
7
  */
8
- key?: string | undefined;
8
+ key?: string;
9
9
  /**
10
10
  * optionally pass in SSR cookiedocument
11
11
  */
12
- cookieDocument?: string | undefined;
12
+ cookieDocument?: string;
13
13
  /**
14
14
  * default 15rem
15
15
  */
16
- width?: string | undefined;
17
- }) => JSX.Element;
16
+ width?: string;
17
+ }
18
+ export declare const Sidebar: ({ children, className, key, cookieDocument, width, }: ISidebar) => JSX.Element;
@@ -3,8 +3,9 @@ export interface TableItem {
3
3
  content: JSX.Element;
4
4
  groupTitle: string;
5
5
  }
6
- export declare const Table: ({ children, className, headerRow, }: {
6
+ export interface ITable {
7
7
  children: TableItem[];
8
- className?: string | undefined;
9
- headerRow?: JSX.Element | undefined;
10
- }) => JSX.Element;
8
+ className?: string;
9
+ headerRow?: JSX.Element;
10
+ }
11
+ export declare const Table: ({ children, className, headerRow }: ITable) => JSX.Element;
@@ -34,7 +34,7 @@ const GroupWrap = styled_components_1.default.div `
34
34
  display: flex;
35
35
  flex-flow: column;
36
36
  `;
37
- const Table = ({ children, className, headerRow, }) => {
37
+ const Table = ({ children, className, headerRow }) => {
38
38
  const grouped = (0, groupBy_1.groupByList)(children, (s) => s.groupTitle);
39
39
  return (react_1.default.createElement(Base, { className: className }, grouped.map((group) => (react_1.default.createElement(GroupWrap, { key: 'gk' + group.key },
40
40
  group.key && (react_1.default.createElement(GroupTitle, { key: `gt${group.key}` }, group.key)),
@@ -1,11 +1,14 @@
1
1
  /// <reference types="react" />
2
2
  import { User } from '../../helpers/jwt';
3
- export declare const UserImage: ({ image, className, title, }: {
4
- image?: string | undefined;
5
- className?: string | undefined;
6
- title?: string | undefined;
7
- }) => JSX.Element;
8
- export declare const UserProfileImage: ({ className, user, }: {
9
- className?: string | undefined;
10
- user?: User | undefined;
11
- }) => JSX.Element;
3
+ export interface IUserImage {
4
+ image?: string;
5
+ className?: string;
6
+ /** default "user image" */
7
+ title?: string;
8
+ }
9
+ export declare const UserImage: ({ image, className, title, }: IUserImage) => JSX.Element;
10
+ export interface IUserProfileImage {
11
+ className?: string;
12
+ user?: Pick<User, 'picture' | 'fullname' | 'userId'>;
13
+ }
14
+ export declare const UserProfileImage: ({ className, user }: IUserProfileImage) => JSX.Element;
@@ -54,7 +54,7 @@ const UserImage = ({ image, className, title = 'user image', }) => {
54
54
  (!image || fallback) && UserOutline_1.UserOutline));
55
55
  };
56
56
  exports.UserImage = UserImage;
57
- const UserProfileImage = ({ className, user, }) => {
57
+ const UserProfileImage = ({ className, user }) => {
58
58
  const image = user === null || user === void 0 ? void 0 : user.picture;
59
59
  if (image) {
60
60
  if (!images.domains.find((i) => image.includes(i))) {
@@ -2,8 +2,7 @@ export * from './BorderGradient';
2
2
  export * from './Button';
3
3
  export * from './Chevron';
4
4
  export * from './Close';
5
- export * from './OpenApiCodeBlock';
6
- export * from './Confirm/Dialog';
5
+ export * from './Confirm';
7
6
  export * from './DropdownList';
8
7
  export * from './FlexColumn';
9
8
  export * from './FlexRow';
@@ -11,7 +10,9 @@ export * from './HeadersRaw';
11
10
  export * from './Icon';
12
11
  export * from './KebabDots';
13
12
  export * from './Loader';
14
- export * from './Modal/Modal';
13
+ export * from './Modal';
14
+ export * from './OpenApiCodeBlock';
15
+ export * from './ProgressBar';
15
16
  export * from './Prompt';
16
17
  export * from './RowOrColumn';
17
18
  export * from './Search';
@@ -18,8 +18,7 @@ __exportStar(require("./BorderGradient"), exports);
18
18
  __exportStar(require("./Button"), exports);
19
19
  __exportStar(require("./Chevron"), exports);
20
20
  __exportStar(require("./Close"), exports);
21
- __exportStar(require("./OpenApiCodeBlock"), exports);
22
- __exportStar(require("./Confirm/Dialog"), exports);
21
+ __exportStar(require("./Confirm"), exports);
23
22
  __exportStar(require("./DropdownList"), exports);
24
23
  __exportStar(require("./FlexColumn"), exports);
25
24
  __exportStar(require("./FlexRow"), exports);
@@ -27,7 +26,9 @@ __exportStar(require("./HeadersRaw"), exports);
27
26
  __exportStar(require("./Icon"), exports);
28
27
  __exportStar(require("./KebabDots"), exports);
29
28
  __exportStar(require("./Loader"), exports);
30
- __exportStar(require("./Modal/Modal"), exports);
29
+ __exportStar(require("./Modal"), exports);
30
+ __exportStar(require("./OpenApiCodeBlock"), exports);
31
+ __exportStar(require("./ProgressBar"), exports);
31
32
  __exportStar(require("./Prompt"), exports);
32
33
  __exportStar(require("./RowOrColumn"), exports);
33
34
  __exportStar(require("./Search"), exports);
@@ -1,2 +1,8 @@
1
- export declare const daydiffstr: (dayticks: number) => string;
1
+ /**
2
+ * returns appropriate time diff string
3
+ * @param lowDate
4
+ * @param highDate defaults to Date.Now
5
+ * @returns
6
+ */
7
+ export declare const dateDiffToString: (lowDate: Date, highDate?: Date) => string;
2
8
  export declare const getDMY: (date: Date, dayOffset?: number) => string;
@@ -1,28 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDMY = exports.daydiffstr = void 0;
3
+ exports.getDMY = exports.dateDiffToString = void 0;
4
4
  const plural_1 = require("./plural");
5
5
  const date_1 = require("../../common/helpers/date");
6
- const math_1 = require("../../common/helpers/math");
7
- const daydiffstr = (dayticks) => {
8
- const ticksSince = new Date().getTime() - dayticks;
9
- const totalMinutes = (0, math_1.toFixedDown)(ticksSince / 1000 / 60, 0);
10
- const totalHours = (0, math_1.toFixedDown)(totalMinutes / 60, 0);
11
- const totalDays = (0, math_1.toFixedDown)(totalHours / 24, 0);
12
- const totalYears = (0, math_1.toFixedDown)(totalDays / 365, 0);
13
- let ts = `${totalYears} ${(0, plural_1.plural)('yr', totalYears)} ago `;
14
- if (totalMinutes < 60) {
15
- ts = `${totalMinutes} ${(0, plural_1.plural)('min', totalMinutes)} ago `;
6
+ /**
7
+ * returns appropriate time diff string
8
+ * @param lowDate
9
+ * @param highDate defaults to Date.Now
10
+ * @returns
11
+ */
12
+ const dateDiffToString = (lowDate, highDate) => {
13
+ const d = (0, date_1.dateDiff)(lowDate, highDate !== null && highDate !== void 0 ? highDate : new Date());
14
+ let ts = `${d.totalYears} ${(0, plural_1.plural)('yr', d.totalYears)} ago `;
15
+ if (d.totalMinutes < 60) {
16
+ ts = `${d.totalMinutes} ${(0, plural_1.plural)('min', d.totalMinutes)} ago `;
16
17
  }
17
- else if (totalHours < 24) {
18
- ts = `${totalHours} ${(0, plural_1.plural)('hr', totalHours)} ago `;
18
+ else if (d.totalHours < 24) {
19
+ ts = `${d.totalHours} ${(0, plural_1.plural)('hr', d.totalHours)} ago `;
19
20
  }
20
- else if (totalDays < 365) {
21
- ts = `${totalDays} ${(0, plural_1.plural)('day', totalDays)} ago `;
21
+ else if (d.totalDays < 365) {
22
+ ts = `${d.totalDays} ${(0, plural_1.plural)('day', d.totalDays)} ago `;
22
23
  }
23
24
  return ts;
24
25
  };
25
- exports.daydiffstr = daydiffstr;
26
+ exports.dateDiffToString = dateDiffToString;
26
27
  const getDMY = (date, dayOffset) => {
27
28
  const date1 = (0, date_1.addDays)(date, dayOffset || 0);
28
29
  const d = String(date1.getDate()).padStart(2, '0');
@@ -4,7 +4,7 @@ exports.UseLocalStorage = exports.getLocalStorageItem = exports.setLocalStorageI
4
4
  const log_1 = require("../../common/helpers/log");
5
5
  const object_1 = require("../../common/helpers/object");
6
6
  const react_1 = require("react");
7
- const getTimeSeconds = () => Math.ceil(new Date().getTime() / 1000);
7
+ const date_1 = require("../../common/helpers/date");
8
8
  const clearLocalStorageItem = (key) => {
9
9
  if (typeof window === 'undefined') {
10
10
  return;
@@ -41,7 +41,7 @@ const setLocalStorageItem = (key, value, ttl) => {
41
41
  return;
42
42
  }
43
43
  const set = {
44
- expiry: !ttl ? undefined : getTimeSeconds() + ttl,
44
+ expiry: !ttl ? undefined : (0, date_1.getTimeSeconds)() + ttl,
45
45
  val: JSON.stringify(value),
46
46
  };
47
47
  window.localStorage.setItem(key, JSON.stringify(set));
@@ -58,7 +58,7 @@ const getLocalStorageItem = (key, initialValue, ttl) => {
58
58
  }
59
59
  const itemraw = window.localStorage.getItem(key);
60
60
  const item = (0, object_1.tryJsonParse)(itemraw, undefined);
61
- if (!item || (item.expiry && getTimeSeconds() > item.expiry)) {
61
+ if (!item || (item.expiry && (0, date_1.getTimeSeconds)() > item.expiry)) {
62
62
  (0, exports.setLocalStorageItem)(key, initialValue, ttl);
63
63
  return initialValue;
64
64
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ag-common",
3
- "version": "0.0.317",
3
+ "version": "0.0.320",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Andrei Gec <@andreigec> (https://gec.dev/)",