@squiz/resource-browser 1.32.1-alpha.12
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/.storybook/main.ts +23 -0
- package/.storybook/preview-head.html +15 -0
- package/.storybook/preview.ts +16 -0
- package/build.js +21 -0
- package/jest.config.ts +18 -0
- package/lib/Icons/Generics/ArrowDown.d.ts +15 -0
- package/lib/Icons/Generics/ArrowDown.js +23 -0
- package/lib/Icons/Generics/ArrowRight.d.ts +15 -0
- package/lib/Icons/Generics/ArrowRight.js +23 -0
- package/lib/Icons/Generics/Close.d.ts +15 -0
- package/lib/Icons/Generics/Close.js +23 -0
- package/lib/Icons/Generics/GenericIconMap.d.ts +10 -0
- package/lib/Icons/Generics/GenericIconMap.js +14 -0
- package/lib/Icons/Generics/ResourceSelect.d.ts +15 -0
- package/lib/Icons/Generics/ResourceSelect.js +28 -0
- package/lib/Icons/Generics/Root.d.ts +15 -0
- package/lib/Icons/Generics/Root.js +23 -0
- package/lib/Icons/Generics/Selected.d.ts +15 -0
- package/lib/Icons/Generics/Selected.js +23 -0
- package/lib/Icons/Generics/index.d.ts +6 -0
- package/lib/Icons/Generics/index.js +19 -0
- package/lib/Icons/Icon.d.ts +47 -0
- package/lib/Icons/Icon.js +44 -0
- package/lib/Icons/MatrixResources/Audio.d.ts +15 -0
- package/lib/Icons/MatrixResources/Audio.js +28 -0
- package/lib/Icons/MatrixResources/Excel.d.ts +15 -0
- package/lib/Icons/MatrixResources/Excel.js +27 -0
- package/lib/Icons/MatrixResources/Folder.d.ts +15 -0
- package/lib/Icons/MatrixResources/Folder.js +24 -0
- package/lib/Icons/MatrixResources/GenericFile.d.ts +15 -0
- package/lib/Icons/MatrixResources/GenericFile.js +28 -0
- package/lib/Icons/MatrixResources/Image.d.ts +15 -0
- package/lib/Icons/MatrixResources/Image.js +26 -0
- package/lib/Icons/MatrixResources/MatrixResourceMap.d.ts +15 -0
- package/lib/Icons/MatrixResources/MatrixResourceMap.js +19 -0
- package/lib/Icons/MatrixResources/Page.d.ts +15 -0
- package/lib/Icons/MatrixResources/Page.js +30 -0
- package/lib/Icons/MatrixResources/Pdf.d.ts +15 -0
- package/lib/Icons/MatrixResources/Pdf.js +31 -0
- package/lib/Icons/MatrixResources/Powerpoint.d.ts +15 -0
- package/lib/Icons/MatrixResources/Powerpoint.js +28 -0
- package/lib/Icons/MatrixResources/Site.d.ts +15 -0
- package/lib/Icons/MatrixResources/Site.js +30 -0
- package/lib/Icons/MatrixResources/Video.d.ts +15 -0
- package/lib/Icons/MatrixResources/Video.js +24 -0
- package/lib/Icons/MatrixResources/Word.d.ts +17 -0
- package/lib/Icons/MatrixResources/Word.js +28 -0
- package/lib/Icons/MatrixResources/index.d.ts +11 -0
- package/lib/Icons/MatrixResources/index.js +29 -0
- package/lib/Modal/Modal.d.ts +11 -0
- package/lib/Modal/Modal.js +46 -0
- package/lib/Modal/ModalOpeningButton.d.ts +10 -0
- package/lib/Modal/ModalOpeningButton.js +13 -0
- package/lib/Modal/ModalTrigger.d.ts +9 -0
- package/lib/Modal/ModalTrigger.js +24 -0
- package/lib/PreviewPanel/PreviewModal.d.ts +11 -0
- package/lib/PreviewPanel/PreviewModal.js +81 -0
- package/lib/PreviewPanel/PreviewPanel.d.ts +16 -0
- package/lib/PreviewPanel/PreviewPanel.js +87 -0
- package/lib/PreviewPanel/details/MatrixResource.d.ts +12 -0
- package/lib/PreviewPanel/details/MatrixResource.js +41 -0
- package/lib/ResourceBreadcrumb/ResourceBreadcrumb.d.ts +9 -0
- package/lib/ResourceBreadcrumb/ResourceBreadcrumb.js +20 -0
- package/lib/ResourceItem/ResourceItem.d.ts +19 -0
- package/lib/ResourceItem/ResourceItem.js +26 -0
- package/lib/ResourceList/ResourceList.d.ts +14 -0
- package/lib/ResourceList/ResourceList.js +51 -0
- package/lib/ResourcePickerContainer/ResourcePickerContainer.d.ts +15 -0
- package/lib/ResourcePickerContainer/ResourcePickerContainer.js +145 -0
- package/lib/Skeleton/List/SkeletonList.d.ts +6 -0
- package/lib/Skeleton/List/SkeletonList.js +13 -0
- package/lib/Skeleton/ListItem/SkeletonListItem.d.ts +2 -0
- package/lib/Skeleton/ListItem/SkeletonListItem.js +15 -0
- package/lib/SourceDropdown/SourceDropdown.d.ts +9 -0
- package/lib/SourceDropdown/SourceDropdown.js +106 -0
- package/lib/SourceList/SourceList.d.ts +14 -0
- package/lib/SourceList/SourceList.js +58 -0
- package/lib/Spinner/Spinner.d.ts +8 -0
- package/lib/Spinner/Spinner.js +12 -0
- package/lib/index.css +968 -0
- package/lib/index.d.ts +37 -0
- package/lib/index.js +15 -0
- package/lib/uuid.d.ts +1 -0
- package/lib/uuid.js +8 -0
- package/package.json +74 -0
- package/postcss.config.js +11 -0
- package/src/Icons/Generics/ArrowDown.tsx +27 -0
- package/src/Icons/Generics/ArrowRight.tsx +27 -0
- package/src/Icons/Generics/Close.tsx +26 -0
- package/src/Icons/Generics/GenericIconMap.ts +14 -0
- package/src/Icons/Generics/ResourceSelect.tsx +40 -0
- package/src/Icons/Generics/Root.tsx +24 -0
- package/src/Icons/Generics/Selected.tsx +27 -0
- package/src/Icons/Generics/index.tsx +7 -0
- package/src/Icons/Icon.spec.tsx +62 -0
- package/src/Icons/Icon.stories.tsx +105 -0
- package/src/Icons/Icon.tsx +61 -0
- package/src/Icons/MatrixResources/Audio.tsx +30 -0
- package/src/Icons/MatrixResources/Excel.tsx +29 -0
- package/src/Icons/MatrixResources/Folder.tsx +29 -0
- package/src/Icons/MatrixResources/GenericFile.tsx +34 -0
- package/src/Icons/MatrixResources/Image.tsx +36 -0
- package/src/Icons/MatrixResources/MatrixResourceMap.ts +19 -0
- package/src/Icons/MatrixResources/Page.tsx +33 -0
- package/src/Icons/MatrixResources/Pdf.tsx +34 -0
- package/src/Icons/MatrixResources/Powerpoint.tsx +34 -0
- package/src/Icons/MatrixResources/Site.tsx +37 -0
- package/src/Icons/MatrixResources/Video.tsx +27 -0
- package/src/Icons/MatrixResources/Word.tsx +30 -0
- package/src/Icons/MatrixResources/index.tsx +12 -0
- package/src/Modal/Modal.spec.tsx +244 -0
- package/src/Modal/Modal.tsx +58 -0
- package/src/Modal/ModalContainer.stories.tsx +33 -0
- package/src/Modal/ModalOpeningButton.tsx +20 -0
- package/src/Modal/ModalTrigger.tsx +45 -0
- package/src/PreviewPanel/PreviewModal.spec.tsx +164 -0
- package/src/PreviewPanel/PreviewModal.tsx +92 -0
- package/src/PreviewPanel/PreviewPanel.spec.tsx +197 -0
- package/src/PreviewPanel/PreviewPanel.stories.tsx +61 -0
- package/src/PreviewPanel/PreviewPanel.tsx +123 -0
- package/src/PreviewPanel/details/MatrixResource.tsx +59 -0
- package/src/ResourceBreadcrumb/ResourceBreadcrumb.spec.tsx +76 -0
- package/src/ResourceBreadcrumb/ResourceBreadcrumb.stories.tsx +24 -0
- package/src/ResourceBreadcrumb/ResourceBreadcrumb.tsx +39 -0
- package/src/ResourceBreadcrumb/sample-hierarchy.json +23 -0
- package/src/ResourceItem/ResourceItem.spec.tsx +69 -0
- package/src/ResourceItem/ResourceItem.tsx +82 -0
- package/src/ResourceList/ResourceList.spec.tsx +196 -0
- package/src/ResourceList/ResourceList.stories.tsx +40 -0
- package/src/ResourceList/ResourceList.tsx +74 -0
- package/src/ResourceList/sample-resources.json +75 -0
- package/src/ResourcePickerContainer/ResourcePickerContainer.spec.tsx +706 -0
- package/src/ResourcePickerContainer/ResourcePickerContainer.stories.tsx +56 -0
- package/src/ResourcePickerContainer/ResourcePickerContainer.tsx +224 -0
- package/src/Skeleton/List/SkeletonList.spec.tsx +18 -0
- package/src/Skeleton/List/SkeletonList.stories.tsx +15 -0
- package/src/Skeleton/List/SkeletonList.tsx +16 -0
- package/src/Skeleton/ListItem/SkeletonListItem.stories.tsx +15 -0
- package/src/Skeleton/ListItem/SkeletonListItem.tsx +14 -0
- package/src/SourceDropdown/SourceDropdown.spec.tsx +263 -0
- package/src/SourceDropdown/SourceDropdown.stories.tsx +36 -0
- package/src/SourceDropdown/SourceDropdown.tsx +175 -0
- package/src/SourceDropdown/sample-sources.json +110 -0
- package/src/SourceList/SourceList.spec.tsx +224 -0
- package/src/SourceList/SourceList.stories.tsx +40 -0
- package/src/SourceList/SourceList.tsx +93 -0
- package/src/SourceList/sample-sources.json +110 -0
- package/src/Spinner/Spinner.spec.tsx +18 -0
- package/src/Spinner/Spinner.stories.tsx +26 -0
- package/src/Spinner/Spinner.tsx +18 -0
- package/src/Spinner/_spinner.scss +11 -0
- package/src/__mocks__/JestHelpers.ts +65 -0
- package/src/__mocks__/jestHelpers.spec.ts +38 -0
- package/src/__mocks__/styleMock.ts +1 -0
- package/src/index.scss +7 -0
- package/src/index.stories.tsx +70 -0
- package/src/index.tsx +71 -0
- package/src/uuid.ts +7 -0
- package/tailwind.config.cjs +84 -0
- package/tsconfig.json +22 -0
@@ -0,0 +1,110 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"id": "1",
|
4
|
+
"name": "Acme corporate system",
|
5
|
+
"nodes": [
|
6
|
+
{
|
7
|
+
"id": {
|
8
|
+
"id": "1",
|
9
|
+
"source": "1"
|
10
|
+
},
|
11
|
+
"type": "site",
|
12
|
+
"selected": true,
|
13
|
+
"label": "HandyHomes Website",
|
14
|
+
"childCount": 21
|
15
|
+
},
|
16
|
+
{
|
17
|
+
"id": {
|
18
|
+
"id": "2",
|
19
|
+
"source": "1"
|
20
|
+
},
|
21
|
+
"type": "site",
|
22
|
+
"selected": false,
|
23
|
+
"label": "Another Website very long title to make it wrap to multiple lines",
|
24
|
+
"childCount": 135877
|
25
|
+
}
|
26
|
+
]
|
27
|
+
},
|
28
|
+
{
|
29
|
+
"id": "2",
|
30
|
+
"name": "Acme internal system",
|
31
|
+
"nodes": [
|
32
|
+
{
|
33
|
+
"id": {
|
34
|
+
"id": "1",
|
35
|
+
"source": "2"
|
36
|
+
},
|
37
|
+
"type": "site",
|
38
|
+
"selected": false,
|
39
|
+
"label": "Intranet Website",
|
40
|
+
"childCount": 15
|
41
|
+
},
|
42
|
+
{
|
43
|
+
"id": {
|
44
|
+
"id": "2",
|
45
|
+
"source": "2"
|
46
|
+
},
|
47
|
+
"type": "site",
|
48
|
+
"selected": false,
|
49
|
+
"label": "Social Website",
|
50
|
+
"childCount": 10
|
51
|
+
}
|
52
|
+
]
|
53
|
+
},
|
54
|
+
{
|
55
|
+
"id": "3",
|
56
|
+
"name": "Other system",
|
57
|
+
"nodes": [
|
58
|
+
{
|
59
|
+
"id": {
|
60
|
+
"id": "1",
|
61
|
+
"source": "3"
|
62
|
+
},
|
63
|
+
"type": "folder",
|
64
|
+
"selected": false,
|
65
|
+
"label": "Digital asset manager",
|
66
|
+
"childCount": 0
|
67
|
+
},
|
68
|
+
{
|
69
|
+
"id": {
|
70
|
+
"id": "2",
|
71
|
+
"source": "3"
|
72
|
+
},
|
73
|
+
"type": "image",
|
74
|
+
"selected": false,
|
75
|
+
"label": "Unsplash image library",
|
76
|
+
"childCount": 0
|
77
|
+
},
|
78
|
+
{
|
79
|
+
"id": {
|
80
|
+
"id": "3",
|
81
|
+
"source": "3"
|
82
|
+
},
|
83
|
+
"type": "image",
|
84
|
+
"selected": false,
|
85
|
+
"label": "Unsplash image library",
|
86
|
+
"childCount": 0
|
87
|
+
},
|
88
|
+
{
|
89
|
+
"id": {
|
90
|
+
"id": "4",
|
91
|
+
"source": "3"
|
92
|
+
},
|
93
|
+
"type": "image",
|
94
|
+
"selected": false,
|
95
|
+
"label": "Unsplash image library",
|
96
|
+
"childCount": 0
|
97
|
+
},
|
98
|
+
{
|
99
|
+
"id": {
|
100
|
+
"id": "5",
|
101
|
+
"source": "3"
|
102
|
+
},
|
103
|
+
"type": "image",
|
104
|
+
"selected": false,
|
105
|
+
"label": "Unsplash image library",
|
106
|
+
"childCount": 0
|
107
|
+
}
|
108
|
+
]
|
109
|
+
}
|
110
|
+
]
|
@@ -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: 'lg',
|
20
|
+
};
|
21
|
+
|
22
|
+
export const Custom = Template.bind({});
|
23
|
+
Custom.args = {
|
24
|
+
...Default.args,
|
25
|
+
className: 'text-blue-300',
|
26
|
+
};
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import React, { ReactElement } from 'react';
|
2
|
+
import clsx from 'clsx';
|
3
|
+
|
4
|
+
export type SpinnerProps = {
|
5
|
+
size?: 'md' | 'lg';
|
6
|
+
className?: string;
|
7
|
+
label?: string;
|
8
|
+
};
|
9
|
+
|
10
|
+
const Spinner = ({ size = 'md', className, label = 'Loading' }: SpinnerProps): ReactElement => {
|
11
|
+
return (
|
12
|
+
<div className="spinner__wrapper" aria-label={label}>
|
13
|
+
<div className={clsx(`spinner`, size && `spinner--${size}`, className)} role="status" />
|
14
|
+
</div>
|
15
|
+
);
|
16
|
+
};
|
17
|
+
|
18
|
+
export default Spinner;
|
@@ -0,0 +1,11 @@
|
|
1
|
+
.spinner {
|
2
|
+
@apply inline-block rounded-full h-8 w-8;
|
3
|
+
@apply border-4 border-solid border-current border-r-transparent;
|
4
|
+
@apply animate-spin align-[-0.125em] motion-reduce:animate-[spin_1.5s_linear_infinite];
|
5
|
+
&__wrapper {
|
6
|
+
@apply flex items-center justify-center m-3 text-gray-300;
|
7
|
+
}
|
8
|
+
&--lg {
|
9
|
+
@apply h-12 w-12;
|
10
|
+
}
|
11
|
+
}
|
@@ -0,0 +1,65 @@
|
|
1
|
+
import fs from 'fs';
|
2
|
+
import path from 'path';
|
3
|
+
import sass from 'sass';
|
4
|
+
import postcss, { Root, AcceptedPlugin, Processor } from 'postcss';
|
5
|
+
import { fileURLToPath } from 'url';
|
6
|
+
|
7
|
+
const removeLayerDirectivePlugin = {
|
8
|
+
postcssPlugin: 'remove-layer-directive',
|
9
|
+
OnceExit(root: Root) {
|
10
|
+
// Remove the @layer directive while keeping the contents
|
11
|
+
root.walkAtRules('layer', (rule) => {
|
12
|
+
rule.replaceWith(rule.nodes);
|
13
|
+
});
|
14
|
+
},
|
15
|
+
} as AcceptedPlugin;
|
16
|
+
|
17
|
+
function removeLayerDirective(scss: string) {
|
18
|
+
const { css } = postcss({
|
19
|
+
plugins: [removeLayerDirectivePlugin],
|
20
|
+
} as Processor).process(scss, {
|
21
|
+
from: undefined,
|
22
|
+
});
|
23
|
+
|
24
|
+
return css;
|
25
|
+
}
|
26
|
+
|
27
|
+
function readAndParseScss({ relativePath, dirname }: { relativePath: string; dirname: string }) {
|
28
|
+
const cssFileContents = fs.readFileSync(path.resolve(dirname, relativePath), 'utf8');
|
29
|
+
const compiledCSS = sass.compileString(cssFileContents, {
|
30
|
+
importers: [
|
31
|
+
{
|
32
|
+
canonicalize(url) {
|
33
|
+
// This function converts the relative path to an absolute path
|
34
|
+
const filePath = path.resolve(dirname, url);
|
35
|
+
|
36
|
+
return new URL(`file://${filePath}`);
|
37
|
+
},
|
38
|
+
load(canonicalUrl) {
|
39
|
+
// This function loads the returns the file in the expected format
|
40
|
+
return {
|
41
|
+
contents: fs.readFileSync(fileURLToPath(`${canonicalUrl}.scss`), 'utf8'),
|
42
|
+
syntax: 'scss',
|
43
|
+
};
|
44
|
+
},
|
45
|
+
},
|
46
|
+
],
|
47
|
+
}).css;
|
48
|
+
|
49
|
+
return removeLayerDirective(compiledCSS);
|
50
|
+
}
|
51
|
+
|
52
|
+
function loadCss({ container, cssFileContents }: { container: HTMLElement; cssFileContents: string }) {
|
53
|
+
const style = window.document.createElement('style');
|
54
|
+
style.type = 'text/css';
|
55
|
+
style.innerHTML = cssFileContents;
|
56
|
+
container.append(style);
|
57
|
+
}
|
58
|
+
|
59
|
+
const resizeWindow = (x: number, y: number) => {
|
60
|
+
window.innerWidth = x;
|
61
|
+
window.innerHeight = y;
|
62
|
+
window.dispatchEvent(new Event('resize'));
|
63
|
+
};
|
64
|
+
|
65
|
+
export { readAndParseScss, loadCss, resizeWindow };
|
@@ -0,0 +1,38 @@
|
|
1
|
+
import { loadCss, resizeWindow } from './JestHelpers';
|
2
|
+
|
3
|
+
describe('loadCss', () => {
|
4
|
+
it('should load the css', () => {
|
5
|
+
const container = document.createElement('div');
|
6
|
+
container.setAttribute('id', 'test');
|
7
|
+
|
8
|
+
const cssFileContents = `
|
9
|
+
.test {
|
10
|
+
color: red;
|
11
|
+
}
|
12
|
+
`;
|
13
|
+
|
14
|
+
loadCss({ container, cssFileContents });
|
15
|
+
|
16
|
+
// Expect that the css is loaded into the container as a style tag
|
17
|
+
expect(container.innerHTML).toBe(`<style type="text/css">${cssFileContents}</style>`);
|
18
|
+
});
|
19
|
+
});
|
20
|
+
|
21
|
+
describe('resizeWindow', () => {
|
22
|
+
it('should resize the window', () => {
|
23
|
+
resizeWindow(100, 100);
|
24
|
+
|
25
|
+
// Expect that the window has been resized
|
26
|
+
expect(window.innerWidth).toBe(100);
|
27
|
+
expect(window.innerHeight).toBe(100);
|
28
|
+
});
|
29
|
+
|
30
|
+
it('should dispatch a resize event', () => {
|
31
|
+
const resizeSpy = jest.spyOn(window, 'dispatchEvent');
|
32
|
+
|
33
|
+
resizeWindow(100, 100);
|
34
|
+
|
35
|
+
// Expect that the window has been resized
|
36
|
+
expect(resizeSpy).toHaveBeenCalled();
|
37
|
+
});
|
38
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
export default {};
|
package/src/index.scss
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
import { StoryFn, Meta } from '@storybook/react';
|
2
|
+
|
3
|
+
import RelatedAssetPicker, { NodeIdentifier } from './index';
|
4
|
+
import sampleSources from './SourceList/sample-sources.json';
|
5
|
+
import sampleResources from './ResourceList/sample-resources.json';
|
6
|
+
|
7
|
+
export default {
|
8
|
+
title: 'RelatedAssetPicker',
|
9
|
+
component: RelatedAssetPicker,
|
10
|
+
} as Meta<typeof RelatedAssetPicker>;
|
11
|
+
|
12
|
+
const Template: StoryFn<typeof RelatedAssetPicker> = (props) => {
|
13
|
+
const { sourceIsLoading, resourceIsLoading, detailsIsLoading } = props;
|
14
|
+
return (
|
15
|
+
<RelatedAssetPicker
|
16
|
+
{...props}
|
17
|
+
onRequestSources={() => {
|
18
|
+
return new Promise((resolve) => {
|
19
|
+
if (!sourceIsLoading) {
|
20
|
+
setTimeout(resolve, 500, sampleSources);
|
21
|
+
}
|
22
|
+
});
|
23
|
+
}}
|
24
|
+
onRequestChildren={() => {
|
25
|
+
return new Promise((resolve) => {
|
26
|
+
if (!resourceIsLoading) {
|
27
|
+
setTimeout(resolve, 500, sampleResources);
|
28
|
+
}
|
29
|
+
});
|
30
|
+
}}
|
31
|
+
onRequestResource={() => {
|
32
|
+
return new Promise((resolve) => {
|
33
|
+
if (!detailsIsLoading) {
|
34
|
+
setTimeout(resolve, 500, {
|
35
|
+
type: 'page',
|
36
|
+
name: 'Products',
|
37
|
+
properties: new Map([
|
38
|
+
['assetId', '12345'],
|
39
|
+
['status', 'UnderConstruction'],
|
40
|
+
]),
|
41
|
+
});
|
42
|
+
}
|
43
|
+
});
|
44
|
+
}}
|
45
|
+
onChange={(nodeId: NodeIdentifier) => {
|
46
|
+
alert(`Resource Browser has selected ${nodeId.source} ${nodeId.id}`);
|
47
|
+
}}
|
48
|
+
/>
|
49
|
+
);
|
50
|
+
};
|
51
|
+
|
52
|
+
export const Primary = Template.bind({});
|
53
|
+
|
54
|
+
Primary.args = {
|
55
|
+
showButtonLabel: false,
|
56
|
+
buttonLabel: 'Open related asset picker',
|
57
|
+
buttonIcon: (
|
58
|
+
<svg width="30" height="30" viewBox="0 0 61 61" fill="none" xmlns="http://www.w3.org/2000/svg">
|
59
|
+
<path
|
60
|
+
d="M29.1 48C24.3 47.75 20.25 45.9 16.95 42.45C13.65 39 12 34.85 12 30C12 25 13.75 20.75 17.25 17.25C20.75 13.75 25 12 30 12C34.85 12 39 13.65 42.45 16.95C45.9 20.25 47.75 24.3 48 29.1L41.7 27.225C41.05 24.525 39.65 22.3125 37.5 20.5875C35.35 18.8625 32.85 18 30 18C26.7 18 23.875 19.175 21.525 21.525C19.175 23.875 18 26.7 18 30C18 32.85 18.8625 35.35 20.5875 37.5C22.3125 39.65 24.525 41.05 27.225 41.7L29.1 48ZM30 60C25.85 60 21.95 59.2125 18.3 57.6375C14.65 56.0625 11.475 53.925 8.775 51.225C6.075 48.525 3.9375 45.35 2.3625 41.7C0.7875 38.05 0 34.15 0 30C0 25.85 0.7875 21.95 2.3625 18.3C3.9375 14.65 6.075 11.475 8.775 8.775C11.475 6.075 14.65 3.9375 18.3 2.3625C21.95 0.7875 25.85 0 30 0C34.15 0 38.05 0.7875 41.7 2.3625C45.35 3.9375 48.525 6.075 51.225 8.775C53.925 11.475 56.0625 14.65 57.6375 18.3C59.2125 21.95 60 25.85 60 30V31.35C60 31.8 59.95 32.25 59.85 32.7L54 30.9V30C54 23.3 51.675 17.625 47.025 12.975C42.375 8.325 36.7 6 30 6C23.3 6 17.625 8.325 12.975 12.975C8.325 17.625 6 23.3 6 30C6 36.7 8.325 42.375 12.975 47.025C17.625 51.675 23.3 54 30 54H30.9L32.7 59.85C32.25 59.95 31.8 60 31.35 60H30ZM54.525 60.45L42.75 48.675L40.5 55.5C40.25 56.2 39.775 56.5375 39.075 56.5125C38.375 56.4875 37.9 56.125 37.65 55.425L30.825 32.7C30.625 32.15 30.75 31.65 31.2 31.2C31.65 30.75 32.15 30.625 32.7 30.825L55.425 37.65C56.125 37.9 56.4875 38.375 56.5125 39.075C56.5375 39.775 56.2 40.25 55.5 40.5L48.675 42.75L60.45 54.525C60.75 54.825 60.9 55.175 60.9 55.575C60.9 55.975 60.75 56.325 60.45 56.625L56.625 60.45C56.325 60.75 55.975 60.9 55.575 60.9C55.175 60.9 54.825 60.75 54.525 60.45Z"
|
61
|
+
fill="#BABABA"
|
62
|
+
/>
|
63
|
+
</svg>
|
64
|
+
),
|
65
|
+
modalTitle: 'Asset Picker',
|
66
|
+
sourceIsLoading: false,
|
67
|
+
resourceIsLoading: false,
|
68
|
+
detailsIsLoading: false,
|
69
|
+
allowedTypes: ['site', 'image'],
|
70
|
+
};
|
package/src/index.tsx
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
|
3
|
+
// import { ResourceBrowserInternalContext } from './InternalContext/InternalContext';
|
4
|
+
import ModalTrigger from './Modal/ModalTrigger';
|
5
|
+
import ResourcePickerContainer from './ResourcePickerContainer/ResourcePickerContainer';
|
6
|
+
|
7
|
+
export type NodeIdentifier = { source: string | null; id: string };
|
8
|
+
export type ResourceDetail = {
|
9
|
+
type: string;
|
10
|
+
name: string;
|
11
|
+
properties: Map<string, any>;
|
12
|
+
};
|
13
|
+
export type Resource = {
|
14
|
+
id: NodeIdentifier;
|
15
|
+
type: string;
|
16
|
+
selected: boolean;
|
17
|
+
label: string;
|
18
|
+
childCount: number;
|
19
|
+
};
|
20
|
+
export type Source = {
|
21
|
+
id: string;
|
22
|
+
name: string;
|
23
|
+
nodes: Array<Resource>;
|
24
|
+
};
|
25
|
+
export type Hierarchy = {
|
26
|
+
id: NodeIdentifier;
|
27
|
+
label: string;
|
28
|
+
};
|
29
|
+
|
30
|
+
export default function ComponentEditorContentBrowser({
|
31
|
+
showButtonLabel,
|
32
|
+
buttonLabel,
|
33
|
+
buttonIcon,
|
34
|
+
modalTitle,
|
35
|
+
allowedTypes,
|
36
|
+
onRequestSources,
|
37
|
+
onRequestChildren,
|
38
|
+
onRequestResource,
|
39
|
+
onChange,
|
40
|
+
}: {
|
41
|
+
showButtonLabel?: boolean;
|
42
|
+
buttonLabel: string;
|
43
|
+
buttonIcon: React.ReactNode;
|
44
|
+
modalTitle: string;
|
45
|
+
allowedTypes: string[] | undefined;
|
46
|
+
onRequestSources: () => Promise<Source[]>;
|
47
|
+
onRequestChildren(id: NodeIdentifier): Promise<Resource[]>;
|
48
|
+
onRequestResource(id: NodeIdentifier): Promise<ResourceDetail | null>;
|
49
|
+
onChange(resource: NodeIdentifier | null): void;
|
50
|
+
}) {
|
51
|
+
const showLabel = showButtonLabel || false;
|
52
|
+
|
53
|
+
return (
|
54
|
+
<div className="squiz-rb-scope">
|
55
|
+
<ModalTrigger showLabel={showLabel} label={buttonLabel} icon={buttonIcon}>
|
56
|
+
{(onClose, titleProps) => (
|
57
|
+
<ResourcePickerContainer
|
58
|
+
title={modalTitle}
|
59
|
+
titleAriaProps={titleProps}
|
60
|
+
allowedTypes={allowedTypes}
|
61
|
+
onClose={onClose}
|
62
|
+
onRequestSources={onRequestSources}
|
63
|
+
onRequestChildren={onRequestChildren}
|
64
|
+
onRequestResource={onRequestResource}
|
65
|
+
onChange={onChange}
|
66
|
+
/>
|
67
|
+
)}
|
68
|
+
</ModalTrigger>
|
69
|
+
</div>
|
70
|
+
);
|
71
|
+
}
|
package/src/uuid.ts
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
2
|
+
// @ts-nocheck
|
3
|
+
export default function uuid(): string {
|
4
|
+
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c) =>
|
5
|
+
(c ^ (window.crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16),
|
6
|
+
);
|
7
|
+
}
|
@@ -0,0 +1,84 @@
|
|
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
|
+
borderRadius: {
|
7
|
+
DEFAULT: '4px',
|
8
|
+
md: '6px',
|
9
|
+
},
|
10
|
+
fontFamily: {
|
11
|
+
base: 'Open Sans, Arial, sans-serif',
|
12
|
+
},
|
13
|
+
fontWeight: {
|
14
|
+
normal: '400',
|
15
|
+
medium: '500',
|
16
|
+
semibold: '600',
|
17
|
+
bold: '700',
|
18
|
+
},
|
19
|
+
fontSize: {
|
20
|
+
xlg: '1.125rem',
|
21
|
+
lg: '1rem',
|
22
|
+
md: '0.875rem',
|
23
|
+
sm: '0.8125rem',
|
24
|
+
base: '1rem',
|
25
|
+
'heading-1': ['1.625rem', '2rem'],
|
26
|
+
'heading-2': ['1.25rem', '1.5rem'],
|
27
|
+
'heading-3': ['1.125rem', '1.375rem'],
|
28
|
+
'heading-4': ['1rem', '1.25rem'],
|
29
|
+
},
|
30
|
+
fontFamily: {
|
31
|
+
base: 'Open Sans, Arial, sans-serif',
|
32
|
+
},
|
33
|
+
boxShadow: {
|
34
|
+
outline: '0 0 0 1px rgba(0,0,0,0.10)',
|
35
|
+
sm: '0 0 0 1px rgba(0,0,0,0.04), 0 1px 4px 2px rgba(0,0,0,0.08)',
|
36
|
+
DEFAULT: '0 0 0 1px rgba(0,0,0,0.04), 0 1px 12px 4px rgba(0,0,0,0.12)',
|
37
|
+
md: '0 0 0 1px rgba(0,0,0,0.04), 0 1px 12px 4px rgba(0,0,0,0.12)',
|
38
|
+
lg: '0 0 0 1px rgba(0,0,0,0.04), 0 1px 24px 12px rgba(0,0,0,0.12)',
|
39
|
+
inner: 'inset 0 2px 4px 0 rgb(0 0 0 / 0.05)',
|
40
|
+
none: 'none',
|
41
|
+
},
|
42
|
+
width: {
|
43
|
+
'modal-sm': '25rem',
|
44
|
+
'modal-md': '37.5rem',
|
45
|
+
'modal-lg': '50rem',
|
46
|
+
'modal-xl': '62.5rem',
|
47
|
+
},
|
48
|
+
spacing: {
|
49
|
+
1: '0.25rem', // 4px
|
50
|
+
2: '0.5rem', // 8px
|
51
|
+
3: '0.75rem', // 12px
|
52
|
+
4: '1rem', // 16px
|
53
|
+
5: '1.25rem', // 20px
|
54
|
+
6: '1.5rem', // 24px
|
55
|
+
7: '1.75rem', // 28px
|
56
|
+
8: '2rem', // 32px
|
57
|
+
169: '169px', // 169px
|
58
|
+
},
|
59
|
+
colors: {
|
60
|
+
gray: {
|
61
|
+
50: '#F7F7F7',
|
62
|
+
100: '#F5F5F5',
|
63
|
+
200: '#ededed',
|
64
|
+
300: '#e0e0e0',
|
65
|
+
400: '#BABABA',
|
66
|
+
500: '#949494',
|
67
|
+
600: '#707070',
|
68
|
+
700: '#4F4F4F',
|
69
|
+
800: '#3D3D3D',
|
70
|
+
900: '#2B2B2B',
|
71
|
+
},
|
72
|
+
blue: {
|
73
|
+
100: '#e6f1fa',
|
74
|
+
200: '#8FC0EB',
|
75
|
+
300: '#0774d2',
|
76
|
+
400: '#044985',
|
77
|
+
},
|
78
|
+
red: {
|
79
|
+
300: '#d72321',
|
80
|
+
},
|
81
|
+
},
|
82
|
+
},
|
83
|
+
},
|
84
|
+
};
|
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.tsx"]
|
22
|
+
}
|