@squiz/generic-browser-lib 1.35.1-alpha.34

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 (153) hide show
  1. package/.storybook/main.ts +23 -0
  2. package/.storybook/preview-head.html +15 -0
  3. package/.storybook/preview.ts +16 -0
  4. package/README.md +10 -0
  5. package/build.js +21 -0
  6. package/jest.config.ts +29 -0
  7. package/lib/Hooks/useAsync.d.ts +21 -0
  8. package/lib/Hooks/useAsync.js +53 -0
  9. package/lib/Icons/Generics/ArrowDown.d.ts +15 -0
  10. package/lib/Icons/Generics/ArrowDown.js +23 -0
  11. package/lib/Icons/Generics/ArrowRight.d.ts +15 -0
  12. package/lib/Icons/Generics/ArrowRight.js +23 -0
  13. package/lib/Icons/Generics/Back.d.ts +4 -0
  14. package/lib/Icons/Generics/Back.js +12 -0
  15. package/lib/Icons/Generics/Close.d.ts +15 -0
  16. package/lib/Icons/Generics/Close.js +23 -0
  17. package/lib/Icons/Generics/Empty.d.ts +4 -0
  18. package/lib/Icons/Generics/Empty.js +12 -0
  19. package/lib/Icons/Generics/Error.d.ts +4 -0
  20. package/lib/Icons/Generics/Error.js +12 -0
  21. package/lib/Icons/Generics/GenericIconMap.d.ts +14 -0
  22. package/lib/Icons/Generics/GenericIconMap.js +18 -0
  23. package/lib/Icons/Generics/ResourceSelect.d.ts +15 -0
  24. package/lib/Icons/Generics/ResourceSelect.js +28 -0
  25. package/lib/Icons/Generics/Retry.d.ts +4 -0
  26. package/lib/Icons/Generics/Retry.js +12 -0
  27. package/lib/Icons/Generics/Root.d.ts +15 -0
  28. package/lib/Icons/Generics/Root.js +23 -0
  29. package/lib/Icons/Generics/Selected.d.ts +15 -0
  30. package/lib/Icons/Generics/Selected.js +23 -0
  31. package/lib/Icons/Generics/index.d.ts +10 -0
  32. package/lib/Icons/Generics/index.js +27 -0
  33. package/lib/Icons/Icon.d.ts +50 -0
  34. package/lib/Icons/Icon.js +42 -0
  35. package/lib/Icons/MatrixResources/Audio.d.ts +15 -0
  36. package/lib/Icons/MatrixResources/Audio.js +28 -0
  37. package/lib/Icons/MatrixResources/Excel.d.ts +15 -0
  38. package/lib/Icons/MatrixResources/Excel.js +27 -0
  39. package/lib/Icons/MatrixResources/Folder.d.ts +15 -0
  40. package/lib/Icons/MatrixResources/Folder.js +24 -0
  41. package/lib/Icons/MatrixResources/GenericFile.d.ts +15 -0
  42. package/lib/Icons/MatrixResources/GenericFile.js +28 -0
  43. package/lib/Icons/MatrixResources/Image.d.ts +15 -0
  44. package/lib/Icons/MatrixResources/Image.js +26 -0
  45. package/lib/Icons/MatrixResources/MatrixResourceMap.d.ts +15 -0
  46. package/lib/Icons/MatrixResources/MatrixResourceMap.js +19 -0
  47. package/lib/Icons/MatrixResources/Page.d.ts +15 -0
  48. package/lib/Icons/MatrixResources/Page.js +30 -0
  49. package/lib/Icons/MatrixResources/Pdf.d.ts +15 -0
  50. package/lib/Icons/MatrixResources/Pdf.js +31 -0
  51. package/lib/Icons/MatrixResources/Powerpoint.d.ts +15 -0
  52. package/lib/Icons/MatrixResources/Powerpoint.js +28 -0
  53. package/lib/Icons/MatrixResources/Site.d.ts +15 -0
  54. package/lib/Icons/MatrixResources/Site.js +30 -0
  55. package/lib/Icons/MatrixResources/Video.d.ts +15 -0
  56. package/lib/Icons/MatrixResources/Video.js +24 -0
  57. package/lib/Icons/MatrixResources/Word.d.ts +17 -0
  58. package/lib/Icons/MatrixResources/Word.js +28 -0
  59. package/lib/Icons/MatrixResources/index.d.ts +11 -0
  60. package/lib/Icons/MatrixResources/index.js +29 -0
  61. package/lib/Modal/Modal.d.ts +10 -0
  62. package/lib/Modal/Modal.js +47 -0
  63. package/lib/Modal/ModalOpeningButton.d.ts +10 -0
  64. package/lib/Modal/ModalOpeningButton.js +14 -0
  65. package/lib/Modal/ModalTrigger.d.ts +9 -0
  66. package/lib/Modal/ModalTrigger.js +26 -0
  67. package/lib/PreviewPanel/PreviewModal.d.ts +11 -0
  68. package/lib/PreviewPanel/PreviewModal.js +79 -0
  69. package/lib/PreviewPanel/PreviewPanel.d.ts +13 -0
  70. package/lib/PreviewPanel/PreviewPanel.js +58 -0
  71. package/lib/PreviewPanel/PreviewPanelHOC.d.ts +6 -0
  72. package/lib/PreviewPanel/PreviewPanelHOC.js +16 -0
  73. package/lib/ResetButton/ResetButton.d.ts +5 -0
  74. package/lib/ResetButton/ResetButton.js +12 -0
  75. package/lib/ResourceItem/ResourceItem.d.ts +19 -0
  76. package/lib/ResourceItem/ResourceItem.js +29 -0
  77. package/lib/ResourceState/ResourceState.d.ts +7 -0
  78. package/lib/ResourceState/ResourceState.js +17 -0
  79. package/lib/Skeleton/List/SkeletonList.d.ts +6 -0
  80. package/lib/Skeleton/List/SkeletonList.js +13 -0
  81. package/lib/Skeleton/ListItem/SkeletonListItem.d.ts +1 -0
  82. package/lib/Skeleton/ListItem/SkeletonListItem.js +15 -0
  83. package/lib/Spinner/Spinner.d.ts +7 -0
  84. package/lib/Spinner/Spinner.js +13 -0
  85. package/lib/index.css +885 -0
  86. package/lib/index.d.ts +12 -0
  87. package/lib/index.js +28 -0
  88. package/package.json +76 -0
  89. package/postcss.config.js +11 -0
  90. package/src/Hooks/useAsync.spec.ts +106 -0
  91. package/src/Hooks/useAsync.ts +62 -0
  92. package/src/Icons/Generics/ArrowDown.tsx +27 -0
  93. package/src/Icons/Generics/ArrowRight.tsx +27 -0
  94. package/src/Icons/Generics/Back.tsx +13 -0
  95. package/src/Icons/Generics/Close.tsx +26 -0
  96. package/src/Icons/Generics/Empty.tsx +13 -0
  97. package/src/Icons/Generics/Error.tsx +13 -0
  98. package/src/Icons/Generics/GenericIconMap.ts +18 -0
  99. package/src/Icons/Generics/ResourceSelect.tsx +40 -0
  100. package/src/Icons/Generics/Retry.tsx +13 -0
  101. package/src/Icons/Generics/Root.tsx +24 -0
  102. package/src/Icons/Generics/Selected.tsx +27 -0
  103. package/src/Icons/Generics/index.tsx +11 -0
  104. package/src/Icons/Icon.spec.tsx +62 -0
  105. package/src/Icons/Icon.stories.tsx +110 -0
  106. package/src/Icons/Icon.tsx +54 -0
  107. package/src/Icons/MatrixResources/Audio.tsx +30 -0
  108. package/src/Icons/MatrixResources/Excel.tsx +29 -0
  109. package/src/Icons/MatrixResources/Folder.tsx +29 -0
  110. package/src/Icons/MatrixResources/GenericFile.tsx +34 -0
  111. package/src/Icons/MatrixResources/Image.tsx +36 -0
  112. package/src/Icons/MatrixResources/MatrixResourceMap.ts +19 -0
  113. package/src/Icons/MatrixResources/Page.tsx +33 -0
  114. package/src/Icons/MatrixResources/Pdf.tsx +34 -0
  115. package/src/Icons/MatrixResources/Powerpoint.tsx +34 -0
  116. package/src/Icons/MatrixResources/Site.tsx +37 -0
  117. package/src/Icons/MatrixResources/Video.tsx +27 -0
  118. package/src/Icons/MatrixResources/Word.tsx +30 -0
  119. package/src/Icons/MatrixResources/index.tsx +12 -0
  120. package/src/Modal/Modal.spec.tsx +269 -0
  121. package/src/Modal/Modal.tsx +55 -0
  122. package/src/Modal/ModalContainer.stories.tsx +33 -0
  123. package/src/Modal/ModalOpeningButton.tsx +20 -0
  124. package/src/Modal/ModalTrigger.tsx +54 -0
  125. package/src/PreviewPanel/PreviewModal.spec.tsx +164 -0
  126. package/src/PreviewPanel/PreviewModal.tsx +94 -0
  127. package/src/PreviewPanel/PreviewPanel.spec.tsx +162 -0
  128. package/src/PreviewPanel/PreviewPanel.stories.tsx +66 -0
  129. package/src/PreviewPanel/PreviewPanel.tsx +83 -0
  130. package/src/PreviewPanel/PreviewPanelHOC.spec.tsx +45 -0
  131. package/src/PreviewPanel/PreviewPanelHOC.tsx +17 -0
  132. package/src/ResetButton/ResetButton.spec.tsx +42 -0
  133. package/src/ResetButton/ResetButton.tsx +22 -0
  134. package/src/ResourceItem/ResourceItem.spec.tsx +65 -0
  135. package/src/ResourceItem/ResourceItem.tsx +90 -0
  136. package/src/ResourceState/ResourceState.spec.tsx +26 -0
  137. package/src/ResourceState/ResourceState.stories.tsx +24 -0
  138. package/src/ResourceState/ResourceState.tsx +31 -0
  139. package/src/Skeleton/List/SkeletonList.spec.tsx +18 -0
  140. package/src/Skeleton/List/SkeletonList.stories.tsx +15 -0
  141. package/src/Skeleton/List/SkeletonList.tsx +20 -0
  142. package/src/Skeleton/ListItem/SkeletonListItem.stories.tsx +15 -0
  143. package/src/Skeleton/ListItem/SkeletonListItem.tsx +14 -0
  144. package/src/Skeleton/_skeleton.scss +15 -0
  145. package/src/Spinner/Spinner.spec.tsx +18 -0
  146. package/src/Spinner/Spinner.stories.tsx +26 -0
  147. package/src/Spinner/Spinner.tsx +16 -0
  148. package/src/Spinner/_spinner.scss +14 -0
  149. package/src/index.scss +22 -0
  150. package/src/index.stories.tsx +26 -0
  151. package/src/index.ts +20 -0
  152. package/tailwind.config.cjs +89 -0
  153. package/tsconfig.json +22 -0
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import { screen, render } from '@testing-library/react';
3
+
4
+ import { SkeletonList } from './SkeletonList';
5
+
6
+ describe('SkeletonList', () => {
7
+ it('Should render the skeleton list', async () => {
8
+ render(<SkeletonList itemCount={17} />);
9
+
10
+ expect(screen.getByLabelText('Skeleton loader list')).toBeInTheDocument();
11
+ });
12
+
13
+ it('Should list out the amount of items we set as the count', async () => {
14
+ render(<SkeletonList itemCount={5} />);
15
+
16
+ expect(screen.getAllByRole('listitem')).toHaveLength(5);
17
+ });
18
+ });
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ import { StoryFn, Meta } from '@storybook/react';
3
+
4
+ import { SkeletonList, SkeletonListProps } from './SkeletonList';
5
+
6
+ export default {
7
+ title: 'Global/Skeleton/List',
8
+ component: SkeletonList,
9
+ } as Meta<typeof SkeletonList>;
10
+
11
+ const Template: StoryFn<SkeletonListProps> = (args: SkeletonListProps) => <SkeletonList {...args} />;
12
+
13
+ export const Default = Template.bind({});
14
+
15
+ Default.args = {};
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+ import { SkeletonListItem } from '../ListItem/SkeletonListItem';
3
+ import clsx from 'clsx';
4
+
5
+ export type SkeletonListProps = {
6
+ itemCount: number;
7
+ className?: string;
8
+ ariaLabel?: string;
9
+ };
10
+
11
+ export const SkeletonList = ({ itemCount = 8, className, ariaLabel }: SkeletonListProps) => (
12
+ <ul
13
+ className={clsx(`flex flex-col px-7 my-4 focus-visible:outline-0`, className)}
14
+ aria-label={`${ariaLabel || 'Skeleton loader list'}`}
15
+ >
16
+ {[...Array(itemCount)].map((_item, index: number) => {
17
+ return <SkeletonListItem key={index} />;
18
+ })}
19
+ </ul>
20
+ );
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ import { StoryFn, Meta } from '@storybook/react';
3
+
4
+ import { SkeletonListItem } from './SkeletonListItem';
5
+
6
+ export default {
7
+ title: 'Global/Skeleton/List item',
8
+ component: SkeletonListItem,
9
+ } as Meta<typeof SkeletonListItem>;
10
+
11
+ const Template: StoryFn<typeof SkeletonListItem> = () => <SkeletonListItem />;
12
+
13
+ export const Default = Template.bind({});
14
+
15
+ Default.args = {};
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+
3
+ export const SkeletonListItem = () => (
4
+ <li className="flex items-center p-1 first:mt-0 bg-white border-1 border-b-0 border-grey-200 first:rounded-t-lg last:rounded-b-lg last:border-b">
5
+ <div className="animate-skeleton-pulse grid grid-cols-[24px_1fr_45px] w-full flex items-center p-4 rounded">
6
+ <span className="w-6 h-6 bg-gray-200 rounded-full" />
7
+ <div className="w-full d-flex flex-col mx-4">
8
+ <div className="mb-1 w-3/4 h-2 bg-gray-200 rounded" />
9
+ <div className="w-1/2 h-2 bg-gray-200 rounded" />
10
+ </div>
11
+ <div className="ml-auto mx-4 w-12 h-2 bg-gray-200 rounded" />
12
+ </div>
13
+ </li>
14
+ );
@@ -0,0 +1,15 @@
1
+ .animate-skeleton-pulse {
2
+ animation: pulse 2s linear infinite;
3
+
4
+ @keyframes pulse {
5
+ 0% {
6
+ opacity: 1;
7
+ }
8
+ 50% {
9
+ opacity: 0.45;
10
+ }
11
+ 100% {
12
+ opacity: 1;
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import { screen, render } from '@testing-library/react';
3
+
4
+ import { Spinner } from './Spinner';
5
+
6
+ describe('Spinner', () => {
7
+ it('Should render the spinner', async () => {
8
+ render(<Spinner />);
9
+
10
+ expect(screen.getByLabelText('Loading')).toBeInTheDocument();
11
+ });
12
+
13
+ it('Should render the loading spinner with the custom aria label', async () => {
14
+ render(<Spinner label="Loading sources" />);
15
+
16
+ expect(screen.getByLabelText('Loading sources')).toBeInTheDocument();
17
+ });
18
+ });
@@ -0,0 +1,26 @@
1
+ import React from 'react';
2
+ import { StoryFn, Meta } from '@storybook/react';
3
+
4
+ import { Spinner, SpinnerProps } from './Spinner';
5
+
6
+ export default {
7
+ title: 'Global/Spinner',
8
+ component: Spinner,
9
+ } as Meta<typeof Spinner>;
10
+
11
+ const Template: StoryFn<SpinnerProps> = (args: SpinnerProps) => <Spinner {...args} />;
12
+
13
+ export const Default = Template.bind({});
14
+ Default.args = {};
15
+
16
+ export const Large = Template.bind({});
17
+ Large.args = {
18
+ ...Default.args,
19
+ size: 'md',
20
+ };
21
+
22
+ export const Custom = Template.bind({});
23
+ Custom.args = {
24
+ ...Default.args,
25
+ className: 'text-blue-300 m-3',
26
+ };
@@ -0,0 +1,16 @@
1
+ import React, { ReactElement } from 'react';
2
+ import clsx from 'clsx';
3
+
4
+ export type SpinnerProps = {
5
+ size?: 'sm' | 'md';
6
+ className?: string;
7
+ label?: string;
8
+ };
9
+
10
+ export const Spinner = ({ size = 'sm', className, label = 'Loading' }: SpinnerProps): ReactElement => {
11
+ return (
12
+ <div className="spinner__wrapper text-gray-600" aria-label={label}>
13
+ <div className={clsx('spinner', size && `spinner--${size}`, className)} role="status" />
14
+ </div>
15
+ );
16
+ };
@@ -0,0 +1,14 @@
1
+ .spinner {
2
+ @apply inline-block rounded-full;
3
+ @apply border-2 border-solid border-current border-r-transparent;
4
+ @apply animate-spin align-[-0.125em] motion-reduce:animate-[spin_1.5s_linear_infinite];
5
+ height: 20px;
6
+ width: 20px;
7
+ &__wrapper {
8
+ @apply flex items-center justify-center;
9
+ }
10
+ &--md {
11
+ height: 32px;
12
+ width: 32px;
13
+ }
14
+ }
package/src/index.scss ADDED
@@ -0,0 +1,22 @@
1
+ /* Tailwind base styles, but scoped to the editor */
2
+ @import 'tailwindcss/base';
3
+ @import 'tailwindcss/components';
4
+ @import 'tailwindcss/utilities';
5
+
6
+ // Components
7
+ @import './Spinner/spinner';
8
+ @import './Skeleton/skeleton';
9
+
10
+ *,
11
+ button {
12
+ @apply antialiased;
13
+ letter-spacing: -0.02em;
14
+ }
15
+
16
+ svg {
17
+ @apply text-gray-600;
18
+ }
19
+
20
+ .p-4\.5 {
21
+ padding: 18px;
22
+ }
@@ -0,0 +1,26 @@
1
+ import { StoryFn } from '@storybook/react';
2
+ import { ResourceItem } from '../src/ResourceItem/ResourceItem';
3
+ export default {
4
+ title: 'Resource Item',
5
+ };
6
+ const Template: StoryFn<any> = (props) => {
7
+ return <ResourceItem {...props}></ResourceItem>;
8
+ };
9
+ export const Primary = Template.bind({});
10
+
11
+ Primary.args = {
12
+ item: {},
13
+ selected: true,
14
+ label: 'Test',
15
+ type: 'Folder',
16
+ childCount: 3,
17
+ previewModalState: () => {
18
+ return;
19
+ },
20
+ onSelect: () => {
21
+ return;
22
+ },
23
+ onDrillDown: () => {
24
+ return;
25
+ },
26
+ };
package/src/index.ts ADDED
@@ -0,0 +1,20 @@
1
+ export * from './Icons/Icon';
2
+
3
+ export * from './Spinner/Spinner';
4
+
5
+ export * from './Modal/Modal';
6
+ export * from './Modal/ModalTrigger';
7
+ export * from './Modal/ModalOpeningButton';
8
+
9
+ export * from './Skeleton/List/SkeletonList';
10
+
11
+ export * from './ResourceItem/ResourceItem';
12
+
13
+ export * from './ResourceState/ResourceState';
14
+
15
+ export * from './PreviewPanel/PreviewPanel';
16
+ export * from './PreviewPanel/PreviewPanelHOC';
17
+
18
+ export * from './Hooks/useAsync';
19
+
20
+ export * from './ResetButton/ResetButton';
@@ -0,0 +1,89 @@
1
+ /** @type {import('tailwindcss').Config} */
2
+ module.exports = {
3
+ content: ['./index.html', './src/**/*.{js,ts,jsx,tsx}', './node_modules/flowbite/**/*.js'],
4
+ theme: {
5
+ extend: {
6
+ borderWidth: {
7
+ // We shouldn't use ".border" class and instead use ".border-1".
8
+ // ".border" has !important styling defined in Matrix so overrides anything various border styling if used.
9
+ 1: '1px',
10
+ },
11
+ borderRadius: {
12
+ DEFAULT: '4px',
13
+ md: '6px',
14
+ },
15
+ fontFamily: {
16
+ base: 'Open Sans, Arial, sans-serif',
17
+ },
18
+ fontWeight: {
19
+ normal: '400',
20
+ medium: '500',
21
+ semibold: '600',
22
+ bold: '700',
23
+ },
24
+ fontSize: {
25
+ xlg: '1.125rem',
26
+ lg: '1rem',
27
+ md: '0.875rem',
28
+ sm: '0.8125rem',
29
+ base: '1rem',
30
+ 'heading-1': ['1.625rem', '2rem'],
31
+ 'heading-2': ['1.25rem', '1.5rem'],
32
+ 'heading-3': ['1.125rem', '1.375rem'],
33
+ 'heading-4': ['1rem', '1.25rem'],
34
+ },
35
+ fontFamily: {
36
+ base: 'Open Sans, Arial, sans-serif',
37
+ },
38
+ boxShadow: {
39
+ outline: '0 0 0 1px rgba(0,0,0,0.10)',
40
+ sm: '0 0 0 1px rgba(0,0,0,0.04), 0 1px 4px 2px rgba(0,0,0,0.08)',
41
+ DEFAULT: '0 0 0 1px rgba(0,0,0,0.04), 0 1px 12px 4px rgba(0,0,0,0.12)',
42
+ md: '0 0 0 1px rgba(0,0,0,0.04), 0 1px 12px 4px rgba(0,0,0,0.12)',
43
+ lg: '0 0 0 1px rgba(0,0,0,0.04), 0 1px 24px 12px rgba(0,0,0,0.12)',
44
+ inner: 'inset 0 2px 4px 0 rgb(0 0 0 / 0.05)',
45
+ none: 'none',
46
+ },
47
+ width: {
48
+ 'modal-sm': '25rem',
49
+ 'modal-md': '37.5rem',
50
+ 'modal-lg': '50rem',
51
+ 'modal-xl': '62.5rem',
52
+ },
53
+ spacing: {
54
+ 1: '0.25rem', // 4px
55
+ 2: '0.5rem', // 8px
56
+ 3: '0.75rem', // 12px
57
+ 4: '1rem', // 16px
58
+ 5: '1.25rem', // 20px
59
+ 6: '1.5rem', // 24px
60
+ 7: '1.75rem', // 28px
61
+ 8: '2rem', // 32px
62
+ 169: '169px', // 169px
63
+ },
64
+ colors: {
65
+ gray: {
66
+ 50: '#F7F7F7',
67
+ 100: '#F5F5F5',
68
+ 200: '#ededed',
69
+ 300: '#e0e0e0',
70
+ 400: '#BABABA',
71
+ 500: '#949494',
72
+ 600: '#707070',
73
+ 700: '#4F4F4F',
74
+ 800: '#3D3D3D',
75
+ 900: '#2B2B2B',
76
+ },
77
+ blue: {
78
+ 100: '#e6f1fa',
79
+ 200: '#8FC0EB',
80
+ 300: '#0774d2',
81
+ 400: '#044985',
82
+ },
83
+ red: {
84
+ 300: '#d72321',
85
+ },
86
+ },
87
+ },
88
+ },
89
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "useDefineForClassFields": true,
5
+ "experimentalDecorators": true,
6
+ "lib": ["DOM", "DOM.Iterable", "ESNext"],
7
+ "allowJs": false,
8
+ "skipLibCheck": true,
9
+ "esModuleInterop": true,
10
+ "allowSyntheticDefaultImports": true,
11
+ "strict": true,
12
+ "forceConsistentCasingInFileNames": true,
13
+ "module": "CommonJS",
14
+ "moduleResolution": "node",
15
+ "resolveJsonModule": true,
16
+ "isolatedModules": true,
17
+ "jsx": "react",
18
+ "declaration": true,
19
+ "outDir": "./lib"
20
+ },
21
+ "files": ["./src/index.ts"]
22
+ }