@squiz/resource-browser 1.32.1-alpha.27 → 1.32.1-alpha.29

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 (48) hide show
  1. package/lib/Modal/ModalTrigger.d.ts +2 -1
  2. package/lib/Modal/ModalTrigger.js +5 -4
  3. package/lib/PreviewPanel/PreviewPanel.d.ts +0 -1
  4. package/lib/PreviewPanel/details/MatrixResource.d.ts +0 -1
  5. package/lib/PreviewPanel/details/MatrixResource.js +2 -17
  6. package/lib/ResourceBreadcrumb/ResourceBreadcrumb.d.ts +0 -1
  7. package/lib/ResourceError/ResourceError.d.ts +0 -1
  8. package/lib/ResourceItem/ResourceItem.d.ts +0 -1
  9. package/lib/ResourceList/ResourceList.d.ts +0 -1
  10. package/lib/ResourcePickerContainer/ResourcePickerContainer.d.ts +0 -1
  11. package/lib/Skeleton/List/SkeletonList.d.ts +0 -1
  12. package/lib/Skeleton/ListItem/SkeletonListItem.d.ts +0 -1
  13. package/lib/SourceDropdown/SourceDropdown.d.ts +0 -1
  14. package/lib/SourceDropdown/SourceDropdown.js +1 -1
  15. package/lib/SourceList/SourceList.d.ts +0 -1
  16. package/lib/StatusIndicator/StatusIndicator.d.ts +6 -0
  17. package/lib/StatusIndicator/StatusIndicator.js +26 -0
  18. package/lib/index.css +110 -4
  19. package/lib/index.d.ts +2 -5
  20. package/lib/index.js +9 -3
  21. package/package.json +5 -3
  22. package/src/Icons/Icon.stories.tsx +5 -0
  23. package/src/Modal/Modal.spec.tsx +25 -0
  24. package/src/Modal/ModalTrigger.tsx +14 -2
  25. package/src/PreviewPanel/details/MatrixResource.tsx +2 -22
  26. package/src/ResourceError/ResourceError.spec.tsx +0 -4
  27. package/src/ResourceItem/ResourceItem.spec.tsx +0 -4
  28. package/src/ResourcePicker/ResetButton.tsx +14 -0
  29. package/src/ResourcePicker/ResourcePicker.spec.tsx +81 -0
  30. package/src/ResourcePicker/ResourcePicker.stories.tsx +62 -0
  31. package/src/ResourcePicker/ResourcePicker.tsx +55 -0
  32. package/src/ResourcePicker/States/Error.tsx +12 -0
  33. package/src/ResourcePicker/States/Loading.tsx +9 -0
  34. package/src/ResourcePicker/States/Selected.tsx +51 -0
  35. package/src/ResourcePicker/mock-image-resource.json +51 -0
  36. package/src/ResourcePicker/mock-resource.json +15 -0
  37. package/src/ResourcePicker/resource-picker.scss +13 -0
  38. package/src/ResourcePickerContainer/ResourcePickerContainer.stories.tsx +1 -1
  39. package/src/SourceDropdown/SourceDropdown.tsx +1 -1
  40. package/src/Spinner/Spinner.stories.tsx +1 -1
  41. package/src/Spinner/_spinner.scss +1 -1
  42. package/src/StatusIndicator/StatusIndicator.stories.tsx +83 -0
  43. package/src/StatusIndicator/StatusIndicator.tsx +35 -0
  44. package/src/index.scss +1 -0
  45. package/src/index.spec.tsx +44 -0
  46. package/src/index.stories.tsx +15 -17
  47. package/src/index.tsx +41 -20
  48. package/src/types.d.ts +5 -4
package/src/index.tsx CHANGED
@@ -2,46 +2,67 @@ import React from 'react';
2
2
  import ModalTrigger from './Modal/ModalTrigger';
3
3
  import ResourcePickerContainer from './ResourcePickerContainer/ResourcePickerContainer';
4
4
  import { HydratedResourceReference, Resource, ResourceReference, Source } from './types';
5
+ import AdsClickRoundedIcon from '@mui/icons-material/AdsClickRounded';
6
+ import AddCircleOutlineRoundedIcon from '@mui/icons-material/AddCircleOutlineRounded';
7
+ import PhotoLibraryRoundedIcon from '@mui/icons-material/PhotoLibraryRounded';
8
+ import clsx from 'clsx';
9
+ // import { LoadingState, ErrorState, SelectedState } from './ResourcePicker/ResourcePicker';
5
10
 
6
11
  export type { HydratedResourceReference, Resource, ResourceReference, Source };
7
12
 
8
13
  export default function ComponentEditorContentBrowser({
9
- showButtonLabel,
10
- buttonLabel,
11
- buttonIcon,
12
14
  modalTitle,
13
15
  allowedTypes,
14
16
  onRequestSources,
15
17
  onRequestChildren,
16
18
  onChange,
19
+ isDisabled,
17
20
  }: {
18
- showButtonLabel?: boolean;
19
- buttonLabel: string;
20
- buttonIcon: React.ReactNode;
21
21
  modalTitle: string;
22
22
  allowedTypes: string[] | undefined;
23
23
  onRequestSources: () => Promise<Source[]>;
24
24
  onRequestChildren(source: Source, resource: Resource | null): Promise<Resource[]>;
25
25
  onRequestResource(reference: ResourceReference): Promise<Resource | null>;
26
26
  onChange(resource: HydratedResourceReference | null): void;
27
+ isDisabled?: boolean;
27
28
  }) {
28
- const showLabel = showButtonLabel || false;
29
-
29
+ const isImagePicker = allowedTypes && allowedTypes.length === 1 && allowedTypes.includes('image');
30
30
  return (
31
31
  <div className="squiz-rb-scope">
32
- <ModalTrigger showLabel={showLabel} label={buttonLabel} icon={buttonIcon}>
33
- {(onClose, titleProps) => (
34
- <ResourcePickerContainer
35
- title={modalTitle}
36
- titleAriaProps={titleProps}
37
- allowedTypes={allowedTypes}
38
- onClose={onClose}
39
- onRequestSources={onRequestSources}
40
- onRequestChildren={onRequestChildren}
41
- onChange={onChange}
42
- />
32
+ <div className={clsx('resource-picker', isDisabled && 'bg-gray-300')}>
33
+ {isImagePicker ? (
34
+ <PhotoLibraryRoundedIcon aria-hidden className="w-6 h-6" />
35
+ ) : (
36
+ <AdsClickRoundedIcon aria-hidden className="w-6 h-6" />
43
37
  )}
44
- </ModalTrigger>
38
+
39
+ <ModalTrigger
40
+ showLabel={true}
41
+ label={isImagePicker ? `Choose image` : `Choose asset`}
42
+ icon={<AddCircleOutlineRoundedIcon aria-hidden className="!w-4 !h-4" />}
43
+ isDisabled={isDisabled}
44
+ >
45
+ {(onClose, titleProps) => (
46
+ <ResourcePickerContainer
47
+ title={modalTitle}
48
+ titleAriaProps={titleProps}
49
+ allowedTypes={allowedTypes}
50
+ onClose={onClose}
51
+ onRequestSources={onRequestSources}
52
+ onRequestChildren={onRequestChildren}
53
+ onChange={onChange}
54
+ />
55
+ )}
56
+ </ModalTrigger>
57
+ {/* TODO: Add all these states in - examples of them can be found in the Resource Picker story and corresponding file /ResourcePicker/ResourcePicker.tsx */}
58
+ {/* <div className="resource-picker-info">
59
+ <div className="resource-picker-info__layout">
60
+ {isLoading && <LoadingState />}
61
+ {isError && <ErrorState />}
62
+ {resource !== null && <SelectedState resource={resource} />}
63
+ </div>
64
+ </div> */}
65
+ </div>
45
66
  </div>
46
67
  );
47
68
  }
package/src/types.d.ts CHANGED
@@ -1,5 +1,9 @@
1
1
  import { SquizImageType } from '@squiz/dx-json-schema-lib';
2
2
 
3
+ export type Status = {
4
+ code: string;
5
+ name: string;
6
+ };
3
7
  /**
4
8
  * Represents a resource that has been picked from a source.
5
9
  */
@@ -10,10 +14,7 @@ export type Resource = {
10
14
  code: string;
11
15
  name: string;
12
16
  };
13
- status: {
14
- code: string;
15
- name: string;
16
- };
17
+ status: Status;
17
18
  url: string;
18
19
  urls: string[];
19
20
  childCount: number;