@squiz/resource-browser 3.3.6 → 3.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/lib/ResourceBrowserInlineButton/ResourceBrowserInlineButton.js +37 -4
- package/lib/index.css +4 -0
- package/lib/types.d.ts +1 -1
- package/package.json +1 -1
- package/src/ResourceBrowserInlineButton/ResourceBrowserInlineButton.scss +5 -0
- package/src/ResourceBrowserInlineButton/ResourceBrowserInlineButton.spec.tsx +10 -1
- package/src/ResourceBrowserInlineButton/ResourceBrowserInlineButton.stories.tsx +7 -0
- package/src/ResourceBrowserInlineButton/ResourceBrowserInlineButton.tsx +20 -4
- package/src/types.ts +1 -1
package/CHANGELOG.md
CHANGED
@@ -1,26 +1,59 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
27
|
};
|
5
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
29
|
exports.ResourceBrowserInlineButton = void 0;
|
7
|
-
const react_1 =
|
30
|
+
const react_1 = __importStar(require("react"));
|
8
31
|
const MainContainer_1 = __importDefault(require("../MainContainer/MainContainer"));
|
9
32
|
const resource_browser_ui_lib_1 = require("@squiz/resource-browser-ui-lib");
|
10
33
|
const InlineLoadingErrorState_1 = require("./InlineLoadingErrorState/InlineLoadingErrorState");
|
11
34
|
const ImageInline_1 = require("../Icons/ImageInline");
|
12
35
|
const LinkInline_1 = require("../Icons/LinkInline");
|
36
|
+
const AdsClickIcon_1 = require("../Icons/AdsClickIcon");
|
13
37
|
const ResourceBrowserInlineButton = ({ inlineType, modalTitle, allowedTypes, onChange, onRetry, value, useResource, isDisabled, plugin, pluginMode, searchEnabled, source, sources, isLoading, error, setSource, isModalOpen, onModalStateChange, }) => {
|
14
38
|
// If an error happens loading the resource the inline browser just opens without it as if no preselectedResource is provided
|
15
39
|
const { data: resource, isLoading: isResourceLoading } = useResource(value || null, source);
|
16
|
-
const
|
40
|
+
const inlineTypePickerLabels = (0, react_1.useMemo)(() => ({
|
41
|
+
image: 'Change image',
|
42
|
+
link: 'Change link',
|
43
|
+
resource: 'Change resource',
|
44
|
+
}), [inlineType]);
|
45
|
+
const inlineTypePickerIcons = (0, react_1.useMemo)(() => ({
|
46
|
+
image: react_1.default.createElement(ImageInline_1.ImageInline, { "aria-label": "change image" }),
|
47
|
+
link: react_1.default.createElement(LinkInline_1.LinkInline, { "aria-label": "change link" }),
|
48
|
+
resource: react_1.default.createElement(AdsClickIcon_1.AdsClickIcon, { "aria-label": "change resource" }),
|
49
|
+
}), [inlineType]);
|
17
50
|
return (react_1.default.createElement("div", { className: "inline-launch-button" },
|
18
51
|
react_1.default.createElement(resource_browser_ui_lib_1.ModalTrigger, { overlayTriggerState: {
|
19
52
|
isOpen: isModalOpen,
|
20
53
|
onOpenChange: onModalStateChange,
|
21
|
-
}, showLabel: false, label: "", icon:
|
54
|
+
}, showLabel: false, label: "", icon: inlineTypePickerIcons[inlineType], isDisabled: isDisabled, scope: "squiz-rb-scope", containerClasses: "inline-launch-button__button" }, (onClose, titleProps) => (react_1.default.createElement(react_1.default.Fragment, null,
|
22
55
|
(isLoading || isResourceLoading || error) && (react_1.default.createElement(InlineLoadingErrorState_1.InlineLoadingErrorState, { title: modalTitle, titleAriaProps: titleProps, onClose: onClose, onRetry: onRetry, isLoading: isLoading || isResourceLoading, error: error })),
|
23
56
|
!(isLoading || isResourceLoading) && !error && (react_1.default.createElement(MainContainer_1.default, { selectedSource: source, sources: sources, preselectedResource: resource, plugin: plugin, pluginMode: pluginMode, searchEnabled: searchEnabled, title: modalTitle, titleAriaProps: titleProps, allowedTypes: allowedTypes, onSourceSelect: setSource, onClose: onClose, onChange: onChange }))))),
|
24
|
-
react_1.default.createElement("div", { className: "inline-launch-button__label" },
|
57
|
+
react_1.default.createElement("div", { className: "inline-launch-button__label" }, inlineTypePickerLabels[inlineType])));
|
25
58
|
};
|
26
59
|
exports.ResourceBrowserInlineButton = ResourceBrowserInlineButton;
|
package/lib/index.css
CHANGED
@@ -6402,6 +6402,10 @@
|
|
6402
6402
|
padding: 2px;
|
6403
6403
|
cursor: pointer;
|
6404
6404
|
}
|
6405
|
+
.squiz-rb-scope .inline-launch-button__button svg:not(.squiz-rb-plugin *) {
|
6406
|
+
width: 18px;
|
6407
|
+
height: 18px;
|
6408
|
+
}
|
6405
6409
|
.squiz-rb-scope .inline-launch-button__label:not(.squiz-rb-plugin *) {
|
6406
6410
|
display: none;
|
6407
6411
|
position: absolute;
|
package/lib/types.d.ts
CHANGED
@@ -2,7 +2,7 @@ import React, { ReactElement } from 'react';
|
|
2
2
|
import { SquizImageType } from '@squiz/dx-json-schema-lib';
|
3
3
|
export type OnRequestSources = () => Promise<ResourceBrowserSource[]>;
|
4
4
|
export type ResourceBrowserPluginType = 'dam' | 'matrix';
|
5
|
-
export type InlineType = 'image' | 'link';
|
5
|
+
export type InlineType = 'image' | 'link' | 'resource';
|
6
6
|
export type AuthenticationConfiguration = {
|
7
7
|
authUrl: string;
|
8
8
|
redirectUrl: string;
|
package/package.json
CHANGED
@@ -27,7 +27,7 @@ describe('ResourceBrowserInlineButton', () => {
|
|
27
27
|
});
|
28
28
|
});
|
29
29
|
|
30
|
-
it('Render
|
30
|
+
it('Render link icon if inline type is "link"', async () => {
|
31
31
|
//@ts-ignore
|
32
32
|
render(<ResourceBrowserInlineButton {...defaultProps} inlineType={'link'} />);
|
33
33
|
|
@@ -36,6 +36,15 @@ describe('ResourceBrowserInlineButton', () => {
|
|
36
36
|
});
|
37
37
|
});
|
38
38
|
|
39
|
+
it('Render resource icon if inline type is "resource"', async () => {
|
40
|
+
//@ts-ignore
|
41
|
+
render(<ResourceBrowserInlineButton {...defaultProps} inlineType={'resource'} />);
|
42
|
+
|
43
|
+
await waitFor(() => {
|
44
|
+
expect(screen.getByLabelText('change resource')).toBeTruthy();
|
45
|
+
});
|
46
|
+
});
|
47
|
+
|
39
48
|
it('On trigger press render loading if still awaiting external data', async () => {
|
40
49
|
//@ts-ignore
|
41
50
|
render(<ResourceBrowserInlineButton {...defaultProps} inlineType={'image'} isLoading={true} />);
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import React from 'react';
|
1
|
+
import React, { useMemo } from 'react';
|
2
2
|
import MainContainer from '../MainContainer/MainContainer';
|
3
3
|
import { ResourceBrowserInputProps } from '../ResourceBrowserInput/ResourceBrowserInput';
|
4
4
|
import { ModalTrigger } from '@squiz/resource-browser-ui-lib';
|
@@ -6,6 +6,7 @@ import { InlineLoadingErrorState } from './InlineLoadingErrorState/InlineLoading
|
|
6
6
|
import { ImageInline } from '../Icons/ImageInline';
|
7
7
|
import { LinkInline } from '../Icons/LinkInline';
|
8
8
|
import { InlineType } from '../types';
|
9
|
+
import { AdsClickIcon } from '../Icons/AdsClickIcon';
|
9
10
|
|
10
11
|
export type ResourceBrowserInlineButtonProps = ResourceBrowserInputProps & {
|
11
12
|
inlineType: InlineType;
|
@@ -35,7 +36,22 @@ export const ResourceBrowserInlineButton = ({
|
|
35
36
|
// If an error happens loading the resource the inline browser just opens without it as if no preselectedResource is provided
|
36
37
|
const { data: resource, isLoading: isResourceLoading } = useResource(value || null, source);
|
37
38
|
|
38
|
-
const
|
39
|
+
const inlineTypePickerLabels = useMemo(
|
40
|
+
() => ({
|
41
|
+
image: 'Change image',
|
42
|
+
link: 'Change link',
|
43
|
+
resource: 'Change resource',
|
44
|
+
}),
|
45
|
+
[inlineType],
|
46
|
+
);
|
47
|
+
const inlineTypePickerIcons = useMemo(
|
48
|
+
() => ({
|
49
|
+
image: <ImageInline aria-label="change image" />,
|
50
|
+
link: <LinkInline aria-label="change link" />,
|
51
|
+
resource: <AdsClickIcon aria-label="change resource" />,
|
52
|
+
}),
|
53
|
+
[inlineType],
|
54
|
+
);
|
39
55
|
|
40
56
|
return (
|
41
57
|
<div className="inline-launch-button">
|
@@ -46,7 +62,7 @@ export const ResourceBrowserInlineButton = ({
|
|
46
62
|
}}
|
47
63
|
showLabel={false}
|
48
64
|
label=""
|
49
|
-
icon={
|
65
|
+
icon={inlineTypePickerIcons[inlineType]}
|
50
66
|
isDisabled={isDisabled}
|
51
67
|
scope="squiz-rb-scope"
|
52
68
|
containerClasses="inline-launch-button__button"
|
@@ -82,7 +98,7 @@ export const ResourceBrowserInlineButton = ({
|
|
82
98
|
</>
|
83
99
|
)}
|
84
100
|
</ModalTrigger>
|
85
|
-
<div className="inline-launch-button__label">{
|
101
|
+
<div className="inline-launch-button__label">{inlineTypePickerLabels[inlineType]}</div>
|
86
102
|
</div>
|
87
103
|
);
|
88
104
|
};
|
package/src/types.ts
CHANGED
@@ -3,7 +3,7 @@ import { SquizImageType } from '@squiz/dx-json-schema-lib';
|
|
3
3
|
|
4
4
|
export type OnRequestSources = () => Promise<ResourceBrowserSource[]>;
|
5
5
|
export type ResourceBrowserPluginType = 'dam' | 'matrix';
|
6
|
-
export type InlineType = 'image' | 'link';
|
6
|
+
export type InlineType = 'image' | 'link' | 'resource';
|
7
7
|
|
8
8
|
export type AuthenticationConfiguration = {
|
9
9
|
authUrl: string;
|