@squiz/resource-browser 1.66.0 → 1.66.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @squiz/resource-browser
2
2
 
3
+ ## 1.66.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 81c7cba: Image asset previews will now display the image if there is a URL in the returned resource data
8
+ Also fixes a bug around the selected resource name not having break-word applied so the filename was not wrapping as expected
9
+
3
10
  ## 1.66.0
4
11
 
5
12
  ### Minor Changes
@@ -3,5 +3,5 @@ import { Resource } from '../../types';
3
3
  type MatrixResourceProps = {
4
4
  resource: Resource;
5
5
  };
6
- declare const MatrixResource: ({ resource: { id, type, name, status } }: MatrixResourceProps) => React.JSX.Element;
6
+ declare const MatrixResource: ({ resource: { id, type, name, status, url } }: MatrixResourceProps) => React.JSX.Element;
7
7
  export default MatrixResource;
@@ -6,11 +6,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const react_1 = __importDefault(require("react"));
7
7
  const generic_browser_lib_1 = require("@squiz/generic-browser-lib");
8
8
  const StatusIndicator_1 = __importDefault(require("../../StatusIndicator/StatusIndicator"));
9
- const MatrixResource = ({ resource: { id, type, name, status } }) => {
9
+ const ImageThumb = ({ url, name }) => {
10
+ return (react_1.default.createElement("div", { className: "checkered-bg w-full h-[164px] overflow-hidden flex justify-center items-center" },
11
+ react_1.default.createElement("img", { src: url, className: "max-w-full max-h-full", alt: name })));
12
+ };
13
+ const MatrixResource = ({ resource: { id, type, name, status, url } }) => {
10
14
  return (react_1.default.createElement("div", null,
11
15
  react_1.default.createElement("div", { className: "flex flex-col items-center text-gray-800 mt-7 mx-5 pb-4 border-b border-gray-300" },
12
- react_1.default.createElement(generic_browser_lib_1.Icon, { icon: type.code, resourceSource: "matrix", className: "w-14 h-14" }),
13
- react_1.default.createElement("div", { className: "mt-4 font-semibold text-base" }, name)),
16
+ type.code === 'image' && url ? (react_1.default.createElement(ImageThumb, { url: url, name: name })) : (react_1.default.createElement(generic_browser_lib_1.Icon, { icon: type.code, resourceSource: "matrix", className: "w-14 h-14" })),
17
+ react_1.default.createElement("div", { className: "mt-4 font-semibold text-base break-word" }, name)),
14
18
  react_1.default.createElement("div", { className: "text-gray-800 mx-6 mt-4" },
15
19
  react_1.default.createElement("dl", { className: "flex flex-col text-sm" },
16
20
  react_1.default.createElement("div", { className: "flex mb-2" },
package/lib/index.css CHANGED
@@ -565,6 +565,9 @@
565
565
  .squiz-rb-scope .h-9 {
566
566
  height: 2.25rem;
567
567
  }
568
+ .squiz-rb-scope .h-\[164px\] {
569
+ height: 164px;
570
+ }
568
571
  .squiz-rb-scope .h-\[20px\] {
569
572
  height: 20px;
570
573
  }
@@ -583,6 +586,9 @@
583
586
  .squiz-rb-scope .max-h-80 {
584
587
  max-height: 20rem;
585
588
  }
589
+ .squiz-rb-scope .max-h-full {
590
+ max-height: 100%;
591
+ }
586
592
  .squiz-rb-scope .min-h-\[64px\] {
587
593
  min-height: 64px;
588
594
  }
@@ -643,6 +649,9 @@
643
649
  .squiz-rb-scope .max-w-\[50rem\] {
644
650
  max-width: 50rem;
645
651
  }
652
+ .squiz-rb-scope .max-w-full {
653
+ max-width: 100%;
654
+ }
646
655
  .squiz-rb-scope .flex-1 {
647
656
  flex: 1 1 0%;
648
657
  }
@@ -1019,6 +1028,13 @@
1019
1028
  --tw-bg-opacity: 1;
1020
1029
  background-color: rgb(247 247 247 / var(--tw-bg-opacity));
1021
1030
  }
1031
+ .squiz-rb-scope .checkered-bg {
1032
+ --tw-bg-opacity: 1;
1033
+ background-color: rgb(255 255 255 / var(--tw-bg-opacity));
1034
+ background-size: 24px 24px;
1035
+ background-position: 0 0, 12px 12px;
1036
+ background-image: linear-gradient(45deg, #e0e0e0 25%, transparent 25%, transparent 75%, #e0e0e0 75%, #e0e0e0), linear-gradient(45deg, #e0e0e0 25%, transparent 25%, transparent 75%, #e0e0e0 75%, #e0e0e0);
1037
+ }
1022
1038
  .squiz-rb-scope .spinner {
1023
1039
  display: inline-block;
1024
1040
  border-radius: 9999px;
@@ -1083,6 +1099,10 @@
1083
1099
  .squiz-rb-scope .p-4\.5 {
1084
1100
  padding: 18px;
1085
1101
  }
1102
+ .squiz-rb-scope .break-word {
1103
+ word-break: break-word;
1104
+ overflow-wrap: anywhere;
1105
+ }
1086
1106
  .squiz-rb-scope .before\:fixed::before {
1087
1107
  content: var(--tw-content);
1088
1108
  position: fixed;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squiz/resource-browser",
3
- "version": "1.66.0",
3
+ "version": "1.66.1",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "private": false,
@@ -38,6 +38,22 @@ function mockResource(properties: Partial<Resource> = {}): Resource {
38
38
  };
39
39
  }
40
40
 
41
+ function mockImageResource(properties: Partial<Resource> = {}): Resource {
42
+ return {
43
+ id: 'test-image-resource',
44
+ name: 'Test image resource',
45
+ type: { code: 'image', name: 'Image' },
46
+ status: { code: 'live', name: 'Live' },
47
+ url: 'https://www.rspcasa.org.au/wp-content/uploads/2020/10/Baby-goat-in-tree.jpg',
48
+ urls: [
49
+ 'https://www.rspcasa.org.au/wp-content/uploads/2020/10/Baby-goat-in-tree.jpg',
50
+ 'http://www.rspcasa.org.au/wp-content/uploads/2020/10/Baby-goat-in-tree.jpg',
51
+ ],
52
+ childCount: 0,
53
+ ...properties,
54
+ };
55
+ }
56
+
41
57
  describe('PreviewPanel', () => {
42
58
  it('Renders a message when no item selected', async () => {
43
59
  const onSelect = jest.fn();
@@ -65,6 +81,33 @@ describe('PreviewPanel', () => {
65
81
  });
66
82
  });
67
83
 
84
+ it('Renders an image when an image is selected', async () => {
85
+ const onSelect = jest.fn();
86
+ const onClose = jest.fn();
87
+ const resource = mockImageResource();
88
+
89
+ render(
90
+ <PreviewPanelTestWrapper
91
+ constructFunction={(previewModalState, overlayProps) => {
92
+ return (
93
+ <PreviewPanel
94
+ resource={resource}
95
+ allowedTypes={undefined}
96
+ modalState={previewModalState}
97
+ previewModalOverlayProps={overlayProps}
98
+ onSelect={onSelect}
99
+ onClose={onClose}
100
+ />
101
+ );
102
+ }}
103
+ />,
104
+ );
105
+
106
+ await waitFor(() => {
107
+ expect(screen.queryByAltText(resource.name)).toBeTruthy();
108
+ });
109
+ });
110
+
68
111
  it('Renders tablet / desktop very above 640px', async () => {
69
112
  const onSelect = jest.fn();
70
113
  const onClose = jest.fn();
@@ -46,6 +46,29 @@ Primary.args = {
46
46
  allowedTypes: undefined,
47
47
  };
48
48
 
49
+ export const ImageAsset = Template.bind({});
50
+ ImageAsset.args = {
51
+ resource: {
52
+ id: '104',
53
+ name: 'Little goat face',
54
+ type: {
55
+ code: 'image',
56
+ name: 'Image',
57
+ },
58
+ status: {
59
+ code: 'live',
60
+ name: 'Live',
61
+ },
62
+ url: 'https://www.rspcasa.org.au/wp-content/uploads/2020/10/Baby-goat-in-tree.jpg',
63
+ urls: [
64
+ 'https://www.rspcasa.org.au/wp-content/uploads/2020/10/Baby-goat-in-tree.jpg',
65
+ 'http://www.rspcasa.org.au/wp-content/uploads/2020/10/Baby-goat-in-tree.jpg',
66
+ ],
67
+ childCount: 0,
68
+ },
69
+ allowedTypes: undefined,
70
+ };
71
+
49
72
  export const NoSelected = Template.bind({});
50
73
  NoSelected.args = {
51
74
  ...Primary.args,
@@ -8,12 +8,24 @@ type MatrixResourceProps = {
8
8
  resource: Resource;
9
9
  };
10
10
 
11
- const MatrixResource = ({ resource: { id, type, name, status } }: MatrixResourceProps) => {
11
+ const ImageThumb = ({ url, name }: { url: string; name: string }) => {
12
+ return (
13
+ <div className="checkered-bg w-full h-[164px] overflow-hidden flex justify-center items-center">
14
+ <img src={url} className="max-w-full max-h-full" alt={name} />
15
+ </div>
16
+ );
17
+ };
18
+
19
+ const MatrixResource = ({ resource: { id, type, name, status, url } }: MatrixResourceProps) => {
12
20
  return (
13
21
  <div>
14
22
  <div className="flex flex-col items-center text-gray-800 mt-7 mx-5 pb-4 border-b border-gray-300">
15
- <Icon icon={type.code as IconOptions} resourceSource="matrix" className="w-14 h-14" />
16
- <div className="mt-4 font-semibold text-base">{name}</div>
23
+ {type.code === 'image' && url ? (
24
+ <ImageThumb url={url} name={name} />
25
+ ) : (
26
+ <Icon icon={type.code as IconOptions} resourceSource="matrix" className="w-14 h-14" />
27
+ )}
28
+ <div className="mt-4 font-semibold text-base break-word">{name}</div>
17
29
  </div>
18
30
  <div className="text-gray-800 mx-6 mt-4">
19
31
  <dl className="flex flex-col text-sm">
@@ -0,0 +1,16 @@
1
+ $sds-grey-300: #e0e0e0;
2
+
3
+ .checkered-bg {
4
+ @apply bg-white;
5
+ background-size: 24px 24px;
6
+ background-position: 0 0, 12px 12px;
7
+ background-image: linear-gradient(
8
+ 45deg,
9
+ $sds-grey-300 25%,
10
+ transparent 25%,
11
+ transparent 75%,
12
+ $sds-grey-300 75%,
13
+ $sds-grey-300
14
+ ),
15
+ linear-gradient(45deg, $sds-grey-300 25%, transparent 25%, transparent 75%, $sds-grey-300 75%, $sds-grey-300);
16
+ }
@@ -75,7 +75,9 @@
75
75
  "name": "Live"
76
76
  },
77
77
  "name": "Image",
78
- "childCount": 0
78
+ "childCount": 0,
79
+ "url": "https://picsum.photos/200/150",
80
+ "urls": ["https://picsum.photos/200/150", "http://picsum.photos/200/150"]
79
81
  },
80
82
  {
81
83
  "id": "105",
@@ -470,6 +472,20 @@
470
472
  "name": "Asset with an even longer title to make it is so long that it causes the container to grow in size. It is truly really just so long and I don't know what else I could possibly say about it to express just how long it is.",
471
473
  "childCount": 456
472
474
  },
475
+ {
476
+ "id": "903",
477
+ "type": {
478
+ "code": "image",
479
+ "name": "Image"
480
+ },
481
+ "status": {
482
+ "code": "live",
483
+ "name": "Live"
484
+ },
485
+ "name": "image_asset_with_a_silly_long_image_file_name_to_check_that_it_does_not_break_out_of_the_layout.jpg.",
486
+ "childCount": 456,
487
+ "url": "https://www.rspcasa.org.au/wp-content/uploads/2020/10/Baby-goat-in-tree.jpg"
488
+ },
473
489
  {
474
490
  "id": "904",
475
491
  "type": {
@@ -9,8 +9,8 @@
9
9
  "code": "under_construction",
10
10
  "name": "Under Construction"
11
11
  },
12
- "url": "",
13
- "urls": [],
12
+ "url": "https://picsum.photos/200/150",
13
+ "urls": ["https://picsum.photos/200/150", "http://picsum.photos/200/150"],
14
14
  "childCount": 0,
15
15
  "squizImage": {
16
16
  "name": "Fancy music",
package/src/index.scss CHANGED
@@ -6,6 +6,7 @@
6
6
  // Components
7
7
  @import './ResourceBreadcrumb/resource-breadcrumb';
8
8
  @import './ResourcePicker/resource-picker';
9
+ @import './PreviewPanel/details/matrix-resource';
9
10
  @import '@squiz/generic-browser-lib/src/Spinner/spinner';
10
11
  @import '@squiz/generic-browser-lib/src/Skeleton/skeleton';
11
12
 
@@ -22,3 +23,11 @@ svg {
22
23
  .p-4\.5 {
23
24
  padding: 18px;
24
25
  }
26
+
27
+ // In tailwind there is no break-word as it is deprecated, but break-words which is slightly different does not work here, so I have added the suggested combination here
28
+ // https://v1.tailwindcss.com/docs/word-break
29
+ // https://github.com/tailwindlabs/tailwindcss/discussions/2213
30
+ .break-word {
31
+ word-break: break-word;
32
+ overflow-wrap: anywhere;
33
+ }