@atlaskit/media-card 77.11.3 → 77.12.0
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 +12 -0
- package/dist/cjs/card/card.js +1 -1
- package/dist/cjs/card/cardView.js +6 -10
- package/dist/cjs/card/media-card-analytics-error-boundary.js +1 -1
- package/dist/cjs/card/ui/styles.js +1 -12
- package/dist/cjs/card/ui/wrapper/imageContainer.js +52 -0
- package/dist/cjs/card/ui/wrapper/index.js +8 -1
- package/dist/cjs/card/v2/cardV2.js +1 -1
- package/dist/cjs/card/v2/cardViewV2.js +12 -17
- package/dist/cjs/card/v2/cardviews/cardViewWrapper.js +5 -9
- package/dist/cjs/card/v2/fileCard.js +66 -20
- package/dist/cjs/card/v2/svgView/helpers.js +16 -0
- package/dist/cjs/card/v2/svgView/index.js +12 -0
- package/dist/cjs/card/v2/svgView/svgView.js +134 -0
- package/dist/cjs/inline/loader.js +1 -1
- package/dist/cjs/utils/ufoExperiences.js +1 -1
- package/dist/es2019/card/card.js +1 -1
- package/dist/es2019/card/cardView.js +8 -12
- package/dist/es2019/card/media-card-analytics-error-boundary.js +1 -1
- package/dist/es2019/card/ui/styles.js +0 -11
- package/dist/es2019/card/ui/wrapper/imageContainer.js +44 -0
- package/dist/es2019/card/ui/wrapper/index.js +2 -1
- package/dist/es2019/card/v2/cardV2.js +1 -1
- package/dist/es2019/card/v2/cardViewV2.js +13 -18
- package/dist/es2019/card/v2/cardviews/cardViewWrapper.js +6 -10
- package/dist/es2019/card/v2/fileCard.js +51 -8
- package/dist/es2019/card/v2/svgView/helpers.js +12 -0
- package/dist/es2019/card/v2/svgView/index.js +1 -0
- package/dist/es2019/card/v2/svgView/svgView.js +113 -0
- package/dist/es2019/inline/loader.js +1 -1
- package/dist/es2019/utils/ufoExperiences.js +1 -1
- package/dist/esm/card/card.js +1 -1
- package/dist/esm/card/cardView.js +8 -12
- package/dist/esm/card/media-card-analytics-error-boundary.js +1 -1
- package/dist/esm/card/ui/styles.js +0 -11
- package/dist/esm/card/ui/wrapper/imageContainer.js +45 -0
- package/dist/esm/card/ui/wrapper/index.js +2 -1
- package/dist/esm/card/v2/cardV2.js +1 -1
- package/dist/esm/card/v2/cardViewV2.js +13 -18
- package/dist/esm/card/v2/cardviews/cardViewWrapper.js +6 -10
- package/dist/esm/card/v2/fileCard.js +66 -20
- package/dist/esm/card/v2/svgView/helpers.js +10 -0
- package/dist/esm/card/v2/svgView/index.js +1 -0
- package/dist/esm/card/v2/svgView/svgView.js +123 -0
- package/dist/esm/inline/loader.js +1 -1
- package/dist/esm/utils/ufoExperiences.js +1 -1
- package/dist/types/card/ui/styles.d.ts +0 -1
- package/dist/types/card/ui/wrapper/imageContainer.d.ts +15 -0
- package/dist/types/card/ui/wrapper/index.d.ts +1 -0
- package/dist/types/card/v2/svgView/helpers.d.ts +3 -0
- package/dist/types/card/v2/svgView/index.d.ts +1 -0
- package/dist/types/card/v2/svgView/svgView.d.ts +31 -0
- package/dist/types-ts4.5/card/ui/styles.d.ts +0 -1
- package/dist/types-ts4.5/card/ui/wrapper/imageContainer.d.ts +15 -0
- package/dist/types-ts4.5/card/ui/wrapper/index.d.ts +1 -0
- package/dist/types-ts4.5/card/v2/svgView/helpers.d.ts +3 -0
- package/dist/types-ts4.5/card/v2/svgView/index.d.ts +1 -0
- package/dist/types-ts4.5/card/v2/svgView/svgView.d.ts +31 -0
- package/example-helpers/svg-helpers/cardContainer.tsx +30 -0
- package/example-helpers/svg-helpers/controls.tsx +21 -0
- package/example-helpers/svg-helpers/delayApiResponses.ts +31 -0
- package/example-helpers/svg-helpers/dimensionPicker.tsx +124 -0
- package/example-helpers/svg-helpers/index.ts +7 -0
- package/example-helpers/svg-helpers/svgContainer.tsx +32 -0
- package/example-helpers/svg-helpers/toggle.tsx +43 -0
- package/example-helpers/svg-helpers/uploader.ts +44 -0
- package/package.json +11 -3
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import React, { useEffect, useMemo, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { Label } from '@atlaskit/form';
|
|
4
|
+
import { Box, Flex, xcss } from '@atlaskit/primitives';
|
|
5
|
+
import Range from '@atlaskit/range';
|
|
6
|
+
|
|
7
|
+
import { ToggleBox } from './toggle';
|
|
8
|
+
|
|
9
|
+
const boxStyles = xcss({ width: '25%', padding: 'space.025' });
|
|
10
|
+
const wrapperStyles = xcss({ padding: 'space.025' });
|
|
11
|
+
|
|
12
|
+
const pixelRange = [1, 1600];
|
|
13
|
+
const percentRange = [1, 100];
|
|
14
|
+
|
|
15
|
+
type OnValue = (value: string | undefined) => void;
|
|
16
|
+
|
|
17
|
+
const defaultVlue = 500;
|
|
18
|
+
|
|
19
|
+
export const DimensionPicker = ({
|
|
20
|
+
targetName,
|
|
21
|
+
dimensionName,
|
|
22
|
+
onChange,
|
|
23
|
+
initialValue,
|
|
24
|
+
initialUnit,
|
|
25
|
+
}: {
|
|
26
|
+
initialValue?: number;
|
|
27
|
+
initialUnit?: '%' | 'px';
|
|
28
|
+
targetName: string;
|
|
29
|
+
dimensionName: string;
|
|
30
|
+
onChange: OnValue;
|
|
31
|
+
}) => {
|
|
32
|
+
const rangeId = `range-${targetName}-${dimensionName}`;
|
|
33
|
+
|
|
34
|
+
const [isPercent, setIsPercent] = useState(initialUnit === '%');
|
|
35
|
+
const [rawValue, setRawValue] = useState<number | undefined>(initialValue);
|
|
36
|
+
const rangeValues = useMemo(
|
|
37
|
+
() => (isPercent ? percentRange : pixelRange),
|
|
38
|
+
[isPercent],
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const value = useMemo(
|
|
42
|
+
() => (isPercent && !!rawValue && rawValue > 100 ? 100 : rawValue),
|
|
43
|
+
[isPercent, rawValue],
|
|
44
|
+
);
|
|
45
|
+
const unit = useMemo(() => (isPercent ? '%' : 'px'), [isPercent]);
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
onChange(value === undefined ? value : `${value}${unit}`);
|
|
49
|
+
}, [value, unit, onChange]);
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<Box xcss={boxStyles}>
|
|
53
|
+
<Label htmlFor={rangeId}>
|
|
54
|
+
{targetName} {dimensionName}:{' '}
|
|
55
|
+
{value ? `${value} ${isPercent ? '%' : 'px'}` : 'Not set'}
|
|
56
|
+
</Label>
|
|
57
|
+
<ToggleBox
|
|
58
|
+
label="Use %"
|
|
59
|
+
defaultChecked={initialUnit === '%'}
|
|
60
|
+
onChange={setIsPercent}
|
|
61
|
+
/>
|
|
62
|
+
<ToggleBox
|
|
63
|
+
label="Unset"
|
|
64
|
+
defaultChecked={!initialValue}
|
|
65
|
+
onChange={(value) => {
|
|
66
|
+
value ? setRawValue(undefined) : setRawValue(defaultVlue);
|
|
67
|
+
}}
|
|
68
|
+
/>
|
|
69
|
+
{rawValue && (
|
|
70
|
+
<Range
|
|
71
|
+
id={rangeId}
|
|
72
|
+
step={1}
|
|
73
|
+
min={rangeValues[0]}
|
|
74
|
+
max={rangeValues[1]}
|
|
75
|
+
onChange={setRawValue}
|
|
76
|
+
value={value}
|
|
77
|
+
/>
|
|
78
|
+
)}
|
|
79
|
+
</Box>
|
|
80
|
+
);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export const DimensionsPicker = ({
|
|
84
|
+
onContainerWidth,
|
|
85
|
+
onContainerHeight,
|
|
86
|
+
onImageWidth,
|
|
87
|
+
onImageHeight,
|
|
88
|
+
}: {
|
|
89
|
+
onContainerWidth: OnValue;
|
|
90
|
+
onContainerHeight: OnValue;
|
|
91
|
+
onImageWidth: OnValue;
|
|
92
|
+
onImageHeight: OnValue;
|
|
93
|
+
}) => {
|
|
94
|
+
return (
|
|
95
|
+
<Flex alignItems="stretch" direction="row" xcss={wrapperStyles}>
|
|
96
|
+
<DimensionPicker
|
|
97
|
+
targetName="Container"
|
|
98
|
+
dimensionName="width"
|
|
99
|
+
onChange={onContainerWidth}
|
|
100
|
+
initialValue={defaultVlue}
|
|
101
|
+
/>
|
|
102
|
+
<DimensionPicker
|
|
103
|
+
targetName="Container"
|
|
104
|
+
dimensionName="height"
|
|
105
|
+
onChange={onContainerHeight}
|
|
106
|
+
initialValue={defaultVlue}
|
|
107
|
+
/>
|
|
108
|
+
<DimensionPicker
|
|
109
|
+
targetName="Image"
|
|
110
|
+
dimensionName="width"
|
|
111
|
+
onChange={onImageWidth}
|
|
112
|
+
initialValue={80}
|
|
113
|
+
initialUnit="%"
|
|
114
|
+
/>
|
|
115
|
+
<DimensionPicker
|
|
116
|
+
targetName="Image"
|
|
117
|
+
dimensionName="height"
|
|
118
|
+
onChange={onImageHeight}
|
|
119
|
+
initialValue={80}
|
|
120
|
+
initialUnit="%"
|
|
121
|
+
/>
|
|
122
|
+
</Flex>
|
|
123
|
+
);
|
|
124
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { ControlsBox } from './controls';
|
|
2
|
+
export { DimensionsPicker } from './dimensionPicker';
|
|
3
|
+
export { ToggleBox } from './toggle';
|
|
4
|
+
export { SvgContainer } from './svgContainer';
|
|
5
|
+
export { useSvgUploader } from './uploader';
|
|
6
|
+
export { CardBox, CardRow } from './cardContainer';
|
|
7
|
+
export { delayApiResponses } from './delayApiResponses';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
import { jsx } from '@emotion/react';
|
|
5
|
+
|
|
6
|
+
import { Box, xcss } from '@atlaskit/primitives';
|
|
7
|
+
|
|
8
|
+
const containerStyles = xcss({
|
|
9
|
+
boxSizing: 'border-box',
|
|
10
|
+
borderColor: 'color.border.accent.orange',
|
|
11
|
+
borderStyle: 'solid',
|
|
12
|
+
borderWidth: 'border.width.indicator',
|
|
13
|
+
margin: 'auto',
|
|
14
|
+
marginTop: 'space.100',
|
|
15
|
+
backgroundColor: 'color.background.accent.green.subtler',
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export const SvgContainer = ({
|
|
19
|
+
children,
|
|
20
|
+
width,
|
|
21
|
+
height,
|
|
22
|
+
}: {
|
|
23
|
+
children: React.ReactNode;
|
|
24
|
+
width?: string;
|
|
25
|
+
height?: string;
|
|
26
|
+
}) => {
|
|
27
|
+
return (
|
|
28
|
+
<Box xcss={containerStyles} style={{ width, height }}>
|
|
29
|
+
{children}
|
|
30
|
+
</Box>
|
|
31
|
+
);
|
|
32
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { Label } from '@atlaskit/form';
|
|
4
|
+
import { Box } from '@atlaskit/primitives';
|
|
5
|
+
import Toggle from '@atlaskit/toggle';
|
|
6
|
+
|
|
7
|
+
function makeid(length = 12) {
|
|
8
|
+
let result = '';
|
|
9
|
+
const characters =
|
|
10
|
+
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
11
|
+
const charactersLength = characters.length;
|
|
12
|
+
let counter = 0;
|
|
13
|
+
while (counter < length) {
|
|
14
|
+
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
15
|
+
counter += 1;
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const ToggleBox = ({
|
|
21
|
+
label,
|
|
22
|
+
onChange,
|
|
23
|
+
...props
|
|
24
|
+
}: Omit<React.ComponentProps<typeof Toggle>, 'onChange'> & {
|
|
25
|
+
label: string;
|
|
26
|
+
onChange: (val: boolean) => void;
|
|
27
|
+
}) => {
|
|
28
|
+
const [id] = useState(makeid());
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<Box>
|
|
32
|
+
<Label htmlFor={id}>{label}</Label>
|
|
33
|
+
<Toggle
|
|
34
|
+
onChange={evt => {
|
|
35
|
+
const { checked } = evt.target;
|
|
36
|
+
onChange(checked);
|
|
37
|
+
}}
|
|
38
|
+
{...props}
|
|
39
|
+
id={id}
|
|
40
|
+
/>
|
|
41
|
+
</Box>
|
|
42
|
+
);
|
|
43
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type SyntheticEvent, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { type FileIdentifier } from '@atlaskit/media-client';
|
|
4
|
+
import { useMediaClient } from '@atlaskit/media-client-react';
|
|
5
|
+
|
|
6
|
+
export const useSvgUploader = (collectionName?: string) => {
|
|
7
|
+
const mediaClient = useMediaClient();
|
|
8
|
+
const [identifier, setIdentifier] = useState<FileIdentifier>();
|
|
9
|
+
const [status, setStatus] = useState<string>('');
|
|
10
|
+
|
|
11
|
+
const uploadFn = async (event: SyntheticEvent<HTMLInputElement>) => {
|
|
12
|
+
if (!event.currentTarget.files || !event.currentTarget.files.length) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
setStatus('Uploading');
|
|
16
|
+
|
|
17
|
+
const file = event.currentTarget.files[0];
|
|
18
|
+
const uplodableFile = {
|
|
19
|
+
content: file,
|
|
20
|
+
name: file.name,
|
|
21
|
+
collection: collectionName,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
mediaClient.file.upload(uplodableFile).subscribe({
|
|
25
|
+
next: ({ status, id }) => {
|
|
26
|
+
if (status === 'error') {
|
|
27
|
+
setStatus('Error while uploading');
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
setStatus(status);
|
|
31
|
+
setIdentifier({
|
|
32
|
+
id,
|
|
33
|
+
mediaItemType: 'file' as const,
|
|
34
|
+
collectionName,
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
error: () => {
|
|
38
|
+
setStatus('Error while uploading');
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
return { status, identifier, uploadFn };
|
|
44
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/media-card",
|
|
3
|
-
"version": "77.
|
|
3
|
+
"version": "77.12.0",
|
|
4
4
|
"description": "Includes all media card related components, CardView, CardViewSmall, Card...",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -38,12 +38,13 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@atlaskit/analytics-next": "^9.3.0",
|
|
40
40
|
"@atlaskit/dropdown-menu": "^12.10.0",
|
|
41
|
-
"@atlaskit/editor-shared-styles": "^2.
|
|
41
|
+
"@atlaskit/editor-shared-styles": "^2.12.0",
|
|
42
42
|
"@atlaskit/icon": "^22.3.0",
|
|
43
43
|
"@atlaskit/media-client": "^27.2.0",
|
|
44
44
|
"@atlaskit/media-client-react": "^2.0.0",
|
|
45
45
|
"@atlaskit/media-common": "^11.2.0",
|
|
46
46
|
"@atlaskit/media-file-preview": "^0.5.0",
|
|
47
|
+
"@atlaskit/media-svg": "^0.1.3",
|
|
47
48
|
"@atlaskit/media-ui": "^25.10.0",
|
|
48
49
|
"@atlaskit/media-viewer": "^48.6.0",
|
|
49
50
|
"@atlaskit/platform-feature-flags": "^0.2.2",
|
|
@@ -69,15 +70,19 @@
|
|
|
69
70
|
"@af/integration-testing": "*",
|
|
70
71
|
"@atlaskit/analytics-listeners": "^8.9.0",
|
|
71
72
|
"@atlaskit/analytics-namespaced-context": "^6.9.0",
|
|
73
|
+
"@atlaskit/form": "^10.2.0",
|
|
72
74
|
"@atlaskit/inline-message": "^12.1.0",
|
|
73
75
|
"@atlaskit/media-core": "^34.2.0",
|
|
74
76
|
"@atlaskit/media-picker": "^66.4.0",
|
|
75
77
|
"@atlaskit/media-state": "^1.1.0",
|
|
76
78
|
"@atlaskit/media-test-data": "^2.3.0",
|
|
77
79
|
"@atlaskit/media-test-helpers": "^33.0.0",
|
|
78
|
-
"@atlaskit/primitives": "^6.
|
|
80
|
+
"@atlaskit/primitives": "^6.5.0",
|
|
81
|
+
"@atlaskit/range": "^7.2.0",
|
|
79
82
|
"@atlaskit/ssr": "*",
|
|
83
|
+
"@atlaskit/toggle": "^13.1.0",
|
|
80
84
|
"@atlaskit/visual-regression": "*",
|
|
85
|
+
"@atlassian/feature-flags-test-utils": "^0.2.0",
|
|
81
86
|
"@atlassian/ufo": "^0.2.0",
|
|
82
87
|
"@testing-library/dom": "^8.17.1",
|
|
83
88
|
"@testing-library/react": "^12.1.5",
|
|
@@ -100,6 +105,9 @@
|
|
|
100
105
|
},
|
|
101
106
|
"platform.media-experience.card-views-refactor_b91lr": {
|
|
102
107
|
"type": "boolean"
|
|
108
|
+
},
|
|
109
|
+
"platform.media-svg-rendering": {
|
|
110
|
+
"type": "boolean"
|
|
103
111
|
}
|
|
104
112
|
},
|
|
105
113
|
"techstack": {
|