@commercelayer/app-elements 0.0.1

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 (88) hide show
  1. package/LICENSE +21 -0
  2. package/dist/@types/Elements.d.ts +1 -0
  3. package/dist/Async-ba6be658.js +80 -0
  4. package/dist/InputDateComponent-89d2ab03.js +8923 -0
  5. package/dist/Select-72746d2c.js +34 -0
  6. package/dist/helpers/date.d.ts +8 -0
  7. package/dist/helpers/downloadJsonAsFile.d.ts +9 -0
  8. package/dist/hooks/useClickAway.d.ts +2 -0
  9. package/dist/main-dc0e3952.js +5009 -0
  10. package/dist/main.d.ts +55 -0
  11. package/dist/main.js +67 -0
  12. package/dist/overrides-52d8822b.js +4253 -0
  13. package/dist/providers/CoreSdkProvider/index.d.ts +20 -0
  14. package/dist/providers/CoreSdkProvider/makeSdkClient.d.ts +7 -0
  15. package/dist/providers/ErrorBoundary.d.ts +19 -0
  16. package/dist/providers/TokenProvider/getAccessTokenFromUrl.d.ts +1 -0
  17. package/dist/providers/TokenProvider/getInfoFromJwt.d.ts +7 -0
  18. package/dist/providers/TokenProvider/index.d.ts +62 -0
  19. package/dist/providers/TokenProvider/reducer.d.ts +21 -0
  20. package/dist/providers/TokenProvider/storage.d.ts +14 -0
  21. package/dist/providers/TokenProvider/types.d.ts +44 -0
  22. package/dist/providers/TokenProvider/url.d.ts +7 -0
  23. package/dist/providers/TokenProvider/validateToken.d.ts +24 -0
  24. package/dist/style.css +1 -0
  25. package/dist/ui/atoms/A.d.ts +8 -0
  26. package/dist/ui/atoms/Badge.d.ts +11 -0
  27. package/dist/ui/atoms/BlockCode.d.ts +11 -0
  28. package/dist/ui/atoms/Button.d.ts +23 -0
  29. package/dist/ui/atoms/Card.d.ts +8 -0
  30. package/dist/ui/atoms/Container.d.ts +20 -0
  31. package/dist/ui/atoms/CopyToClipboard.d.ts +19 -0
  32. package/dist/ui/atoms/DelayShow.d.ts +10 -0
  33. package/dist/ui/atoms/EmptyState.d.ts +13 -0
  34. package/dist/ui/atoms/FormFooter.d.ts +10 -0
  35. package/dist/ui/atoms/Hint.d.ts +11 -0
  36. package/dist/ui/atoms/Icon.d.ts +37 -0
  37. package/dist/ui/atoms/Legend.d.ts +20 -0
  38. package/dist/ui/atoms/PageHeading.d.ts +39 -0
  39. package/dist/ui/atoms/Pagination.d.ts +27 -0
  40. package/dist/ui/atoms/Skeleton.d.ts +41 -0
  41. package/dist/ui/atoms/Spacer.d.ts +28 -0
  42. package/dist/ui/atoms/StatusDot.d.ts +9 -0
  43. package/dist/ui/atoms/StatusIcon.d.ts +16 -0
  44. package/dist/ui/atoms/Tabs.d.ts +46 -0
  45. package/dist/ui/atoms/Text.d.ts +21 -0
  46. package/dist/ui/atoms/dropdown/DropdownMenu.d.ts +10 -0
  47. package/dist/ui/atoms/dropdown/DropdownMenuDivider.d.ts +9 -0
  48. package/dist/ui/atoms/dropdown/DropdownMenuItem.d.ts +10 -0
  49. package/dist/ui/atoms/dropdown/index.d.ts +3 -0
  50. package/dist/ui/atoms/tables/Td.d.ts +9 -0
  51. package/dist/ui/atoms/tables/Th.d.ts +9 -0
  52. package/dist/ui/atoms/tables/Tr.d.ts +9 -0
  53. package/dist/ui/atoms/tables/index.d.ts +3 -0
  54. package/dist/ui/composite/ContextMenu.d.ts +10 -0
  55. package/dist/ui/composite/PageError.d.ts +30 -0
  56. package/dist/ui/composite/PageLayout.d.ts +17 -0
  57. package/dist/ui/composite/PageSkeleton.d.ts +10 -0
  58. package/dist/ui/composite/Report.d.ts +19 -0
  59. package/dist/ui/forms/Input.d.ts +14 -0
  60. package/dist/ui/forms/InputDate/InputDateComponent.d.ts +45 -0
  61. package/dist/ui/forms/InputDate/index.d.ts +5 -0
  62. package/dist/ui/forms/InputDateRange.d.ts +23 -0
  63. package/dist/ui/forms/InputFeedback.d.ts +11 -0
  64. package/dist/ui/forms/InputFile.d.ts +10 -0
  65. package/dist/ui/forms/InputJson.d.ts +14 -0
  66. package/dist/ui/forms/InputReadonly.d.ts +24 -0
  67. package/dist/ui/forms/InputSelect/Async.d.ts +11 -0
  68. package/dist/ui/forms/InputSelect/Select.d.ts +10 -0
  69. package/dist/ui/forms/InputSelect/index.d.ts +59 -0
  70. package/dist/ui/forms/InputSelect/overrides.d.ts +10 -0
  71. package/dist/ui/forms/InputSelect/styles.d.ts +4 -0
  72. package/dist/ui/forms/InputTextArea.d.ts +6 -0
  73. package/dist/ui/forms/InputToggleBox.d.ts +9 -0
  74. package/dist/ui/forms/InputToggleListBox.d.ts +15 -0
  75. package/dist/ui/forms/InputWrapper.d.ts +34 -0
  76. package/dist/ui/forms/Label.d.ts +9 -0
  77. package/dist/ui/forms/RadioButtons.d.ts +18 -0
  78. package/dist/ui/lists/List.d.ts +37 -0
  79. package/dist/ui/lists/ListDetails.d.ts +32 -0
  80. package/dist/ui/lists/ListDetailsItem.d.ts +22 -0
  81. package/dist/ui/lists/ListItem.d.ts +12 -0
  82. package/dist/ui/lists/ListItemTask.d.ts +33 -0
  83. package/dist/ui/tables/Table.d.ts +10 -0
  84. package/dist/ui/tables/TableData.d.ts +13 -0
  85. package/dist/utils/children.d.ts +15 -0
  86. package/dist/utils/extractHeaders.d.ts +6 -0
  87. package/dist/utils/pagination.d.ts +43 -0
  88. package/package.json +70 -0
@@ -0,0 +1,34 @@
1
+ import { HintProps } from '../atoms/Hint';
2
+ import { InputFeedbackProps } from '../forms/InputFeedback';
3
+ export interface InputWrapperBaseProps {
4
+ /**
5
+ * optional input label
6
+ */
7
+ label?: string;
8
+ /**
9
+ * optional hint to be rendered below
10
+ */
11
+ hint?: {
12
+ icon?: HintProps['icon'];
13
+ text: HintProps['children'];
14
+ };
15
+ /**
16
+ * optional hint to be rendered below
17
+ */
18
+ feedback?: Omit<InputFeedbackProps, 'className'>;
19
+ }
20
+ export interface InputWrapperProps extends InputWrapperBaseProps {
21
+ /**
22
+ * optional css class names used for the input element
23
+ */
24
+ className?: string;
25
+ name?: string;
26
+ children: JSX.Element | JSX.Element[];
27
+ }
28
+ declare function InputWrapper({ label, children, className, hint, feedback, name, ...rest }: InputWrapperProps): JSX.Element;
29
+ declare namespace InputWrapper {
30
+ var displayName: string;
31
+ }
32
+ export { InputWrapper };
33
+ export declare function getFeedbackStyle(feedback?: Omit<InputFeedbackProps, 'className'>): Record<string, boolean>;
34
+ export declare function getFeedbackCssInJs(variant?: InputFeedbackProps['variant']): Pick<CSSStyleDeclaration, 'borderColor' | 'borderWidth'>;
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ interface Props extends React.LabelHTMLAttributes<HTMLLabelElement> {
3
+ gap?: boolean;
4
+ }
5
+ declare function Label({ gap, children, className, ...rest }: Props): JSX.Element;
6
+ declare namespace Label {
7
+ var displayName: string;
8
+ }
9
+ export { Label };
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import { InputHTMLAttributes } from 'react';
3
+ import { InputWrapperBaseProps } from '../forms/InputWrapper';
4
+ export declare type RadioOptionValue = string | number | boolean;
5
+ export interface RadioOption {
6
+ value: RadioOptionValue;
7
+ label: string;
8
+ }
9
+ export interface RadioButtonsProps extends InputWrapperBaseProps {
10
+ id: string;
11
+ options: RadioOption[];
12
+ value?: RadioOptionValue;
13
+ onChange: (value: RadioOptionValue) => void;
14
+ className?: string;
15
+ onBlur?: InputHTMLAttributes<HTMLInputElement>['onBlur'];
16
+ }
17
+ declare const RadioButtons: React.ForwardRefExoticComponent<RadioButtonsProps & React.RefAttributes<HTMLInputElement>>;
18
+ export { RadioButtons };
@@ -0,0 +1,37 @@
1
+ import { ReactNode } from 'react';
2
+ import { PaginationProps } from '../atoms/Pagination';
3
+ export declare type ListPagination = {
4
+ recordsPerPage: number;
5
+ recordCount: number;
6
+ } & Omit<PaginationProps, 'className' | 'isDisabled'>;
7
+ export interface ListProps {
8
+ /**
9
+ * List name displayed in the heading
10
+ */
11
+ title?: string;
12
+ /**
13
+ * Element to be displayed on the right side of the heading
14
+ */
15
+ actionButton?: ReactNode;
16
+ /**
17
+ * Set an opacity on the list, usefull when changing page and new page data is not ready yet.
18
+ */
19
+ isDisabled?: boolean;
20
+ /**
21
+ * Show Skeleton UI
22
+ */
23
+ isLoading?: boolean;
24
+ /**
25
+ * It should only accept or ListItem or ListItemTask
26
+ */
27
+ children?: ReactNode;
28
+ /**
29
+ * When a `ListPagination` is passed, a pagination nav is added at the bottom of the list
30
+ */
31
+ pagination?: ListPagination;
32
+ }
33
+ declare function List({ title, actionButton, isDisabled, children, pagination, isLoading, ...rest }: ListProps): JSX.Element;
34
+ declare namespace List {
35
+ var displayName: string;
36
+ }
37
+ export { List };
@@ -0,0 +1,32 @@
1
+ import { ReactNode } from 'react';
2
+ export interface DetailsListProps {
3
+ /**
4
+ * Optional title to show on top of the list
5
+ */
6
+ title?: string;
7
+ /**
8
+ * Use <ListDetailsItem> component as children
9
+ */
10
+ children?: ReactNode;
11
+ /**
12
+ * css class name
13
+ */
14
+ className?: string;
15
+ /**
16
+ * font size
17
+ */
18
+ fontSize?: 'normal' | 'small';
19
+ /**
20
+ * Show skeleton when this is `true`
21
+ */
22
+ isLoading?: boolean;
23
+ /**
24
+ * Number of items to show as skeleton rows. Default is `3`.
25
+ */
26
+ loadingLines?: number;
27
+ }
28
+ declare function ListDetails({ title, children, fontSize, isLoading, loadingLines, ...rest }: DetailsListProps): JSX.Element;
29
+ declare namespace ListDetails {
30
+ var displayName: string;
31
+ }
32
+ export { ListDetails };
@@ -0,0 +1,22 @@
1
+ import { ReactNode } from 'react';
2
+ interface ListDetailsItemProps {
3
+ /**
4
+ * label to show on the left side. In a key/value pair, this is the `key`
5
+ */
6
+ label: string;
7
+ /**
8
+ * content to show on the right side.
9
+ * It represent the value.
10
+ * Most of the type it should be a `<CopyToClipboard>` component
11
+ */
12
+ children: ReactNode;
13
+ /**
14
+ * To show the skeleton item while `children` ar not yet. Label is always rendered
15
+ */
16
+ isLoading?: boolean;
17
+ }
18
+ declare function ListDetailsItem({ label, children, isLoading, ...rest }: ListDetailsItemProps): JSX.Element;
19
+ declare namespace ListDetailsItem {
20
+ var displayName: string;
21
+ }
22
+ export { ListDetailsItem };
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ export interface ListItemProps extends React.HTMLAttributes<HTMLDivElement> {
3
+ label: string;
4
+ description?: React.ReactNode;
5
+ icon?: React.ReactNode;
6
+ noHover?: boolean;
7
+ }
8
+ declare function ListItem({ label, description, icon, className, noHover, ...rest }: ListItemProps): JSX.Element;
9
+ declare namespace ListItem {
10
+ var displayName: string;
11
+ }
12
+ export { ListItem };
@@ -0,0 +1,33 @@
1
+ import React from 'react';
2
+ import { StatusUI } from '../atoms/StatusIcon';
3
+ export interface ListItemTaskProps extends React.HTMLAttributes<HTMLDivElement> {
4
+ /**
5
+ * define the status to show the proper icon
6
+ */
7
+ status: StatusUI;
8
+ /**
9
+ * Only accepted if status is `progress'
10
+ */
11
+ progressPercentage?: number;
12
+ /**
13
+ * Main text to show
14
+ */
15
+ title: string;
16
+ /**
17
+ * Optional text to display below the title
18
+ */
19
+ description?: React.ReactNode;
20
+ /**
21
+ * When set, this will render a `Cancel` button to cancel the current task
22
+ */
23
+ onCancelRequest?: () => void;
24
+ /**
25
+ * Disable hover effect
26
+ */
27
+ noHover?: boolean;
28
+ }
29
+ declare function ListItemTask({ status, progressPercentage, title, onCancelRequest, description, className, noHover, ...rest }: ListItemTaskProps): JSX.Element;
30
+ declare namespace ListItemTask {
31
+ var displayName: string;
32
+ }
33
+ export { ListItemTask };
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ interface Props extends React.TableHTMLAttributes<HTMLTableElement> {
3
+ thead?: React.ReactNode;
4
+ tbody?: React.ReactNode;
5
+ }
6
+ declare function Table({ thead, tbody, className, ...rest }: Props): JSX.Element;
7
+ declare namespace Table {
8
+ var displayName: string;
9
+ }
10
+ export { Table };
@@ -0,0 +1,13 @@
1
+ export interface TableDataProps {
2
+ data: Array<Record<string, string | Object>>;
3
+ className?: string;
4
+ limit?: number;
5
+ title?: string;
6
+ showTotal?: boolean;
7
+ showOthers?: boolean;
8
+ }
9
+ declare function TableData({ data, className, limit, title, showTotal, showOthers, ...rest }: TableDataProps): JSX.Element;
10
+ declare namespace TableData {
11
+ var displayName: string;
12
+ }
13
+ export { TableData };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Checks if a ReactNode matches a specific component display name.
3
+ * @param child - a ReactNode single child
4
+ * @param displayName - the name of the component we would like to match
5
+ * @returns a boolean values indicating argument match the passed displayName
6
+ *
7
+ * * Example:
8
+ * ```jsx
9
+ * React.Children.map(children, (child) =>
10
+ * isSpecificReactComponent(child, 'Button')
11
+ * )
12
+ * // will return an array of true/false values depending if some child is a button
13
+ * ```
14
+ */
15
+ export declare function isSpecificReactComponent(child: string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | React.ReactFragment | React.ReactPortal | null | undefined, displayName: string): boolean;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Extract all keys from an array of objects of different shapes,
3
+ * @param data - array of objects of different shapes
4
+ * @returns an array of string values
5
+ */
6
+ export declare function extractHeaders(data: Array<Record<string, any>>): string[];
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Helper function to retrieve the first and last index of the current page
3
+ * Example: To show `1-50 of 148` or `51-100 of 148` or `100-148 of 148` we can do `${firstOfPage}-${lastOfPage} of ${recordCount}`
4
+ * @param currentPage - The current active page (Int)
5
+ * @param recordsPerPage - Number of items listed in a single page (Int)
6
+ * @param recordCount - Number of the total items from all pages (Int)
7
+ * @returns an object containing `firstOfPage` which is the first index of the current page (on page 2 with 30 items per page will be 31)
8
+ * and `lastOfPage` which is the last index of the current page (on page 2 with 30 items per page will be 60)
9
+ */
10
+ export declare function makeCurrentPageOffsets({ currentPage, recordsPerPage, recordCount }: {
11
+ currentPage: number;
12
+ recordsPerPage: number;
13
+ recordCount: number;
14
+ }): {
15
+ firstOfPage: number;
16
+ lastOfPage: number;
17
+ };
18
+ /**
19
+ * Helper function to make a list of adjacent pages.
20
+ * It will consider the final and first page to avoid generating not existing pages.
21
+ * Example: If current page is 3 and we want to generate 5 adjacents it could return
22
+ * [3,4,5,6,7] or [1,2,3] depending on the direction we are looking for.
23
+ * @param currentPage - The current active page (Int)
24
+ * @param pageCount - The total number of pages (Int)
25
+ * @param adjacentPagesCount - How many adjacent pages we need to generate (Int)
26
+ * @param direction - The direction we need to look for. It could be `forward` or `backward`
27
+ * @param excludeCurrentPage - Boolean flag, in case we don't need the current page to be in the array
28
+ * @returns an array of adjacent page numbers
29
+ */
30
+ export declare function makeSomeAdjacentPages({ currentPage, pageCount, adjacentPagesCount, direction, excludeCurrentPage }: {
31
+ currentPage: number;
32
+ pageCount: number;
33
+ adjacentPagesCount: number;
34
+ direction?: 'backward' | 'forward';
35
+ excludeCurrentPage?: boolean;
36
+ }): number[];
37
+ export declare function computeTitleWithPagination({ title, firstOfPage, lastOfPage, recordCount, currentPage }: {
38
+ title: string;
39
+ firstOfPage: number;
40
+ lastOfPage: number;
41
+ recordCount: number;
42
+ currentPage: number;
43
+ }): string;
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@commercelayer/app-elements",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "module": "./dist/main.js",
9
+ "types": "./dist/main.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "import": "./dist/main.js"
13
+ },
14
+ "./style.css": {
15
+ "import": "./dist/style.css"
16
+ }
17
+ },
18
+ "engines": {
19
+ "node": ">=18",
20
+ "pnpm": ">=7"
21
+ },
22
+ "dependencies": {
23
+ "@commercelayer/sdk": "^4.20.0",
24
+ "@tailwindcss/forms": "^0.5.3",
25
+ "@testing-library/jest-dom": "^5.16.5",
26
+ "@testing-library/react": "^13.4.0",
27
+ "@types/lodash": "^4.14.191",
28
+ "@types/react": "^18.0.26",
29
+ "@types/react-datepicker": "^4.8.0",
30
+ "@types/react-dom": "^18.0.9",
31
+ "@types/testing-library__jest-dom": "^5.14.5",
32
+ "@vitejs/plugin-react": "^3.0.0",
33
+ "autoprefixer": "^10.4.13",
34
+ "classnames": "^2.3.2",
35
+ "jsdom": "^20.0.3",
36
+ "jwt-decode": "^3.1.2",
37
+ "lodash": "^4.17.21",
38
+ "phosphor-react": "^1.4.1",
39
+ "polished": "^4.2.2",
40
+ "postcss": "^8.4.20",
41
+ "react": "^18.2.0",
42
+ "react-datepicker": "^4.8.0",
43
+ "react-dom": "^18.2.0",
44
+ "react-select": "^5.7.0",
45
+ "tailwindcss": "^3.2.4",
46
+ "ts-invariant": "^0.10.3",
47
+ "typescript": "^4.9.4",
48
+ "vite": "^4.0.3",
49
+ "vite-plugin-dts": "^1.7.1",
50
+ "vitest": "^0.26.2"
51
+ },
52
+ "devDependencies": {
53
+ "@commercelayer/eslint-config-ts-react": "^0.1.3",
54
+ "@types/node": "^18.11.17",
55
+ "cross-fetch": "^3.1.5",
56
+ "eslint": "^8.30.0",
57
+ "msw": "^1.0.0",
58
+ "type-fest": "^3.5.4"
59
+ },
60
+ "peerDependencies": {
61
+ "@commercelayer/sdk": "^4.x"
62
+ },
63
+ "scripts": {
64
+ "build": "tsc && vite build",
65
+ "lint": "eslint src",
66
+ "lint:fix": "eslint src --fix",
67
+ "test": "vitest run",
68
+ "test:watch": "vitest"
69
+ }
70
+ }