@artsy/palette-mobile 19.15.1 → 19.17.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/dist/elements/Avatar/Avatar.d.ts +2 -1
- package/dist/elements/Avatar/Avatar.js +2 -2
- package/dist/elements/Avatar/Avatar.stories.d.ts +9 -7
- package/dist/elements/Avatar/Avatar.stories.js +45 -4
- package/dist/elements/Image/Image.js +3 -12
- package/dist/elements/Image/__tests__/getImageURL.tests.d.ts +1 -0
- package/dist/elements/Image/__tests__/getImageURL.tests.js +30 -0
- package/dist/elements/Image/helpers/getImageURL.d.ts +14 -0
- package/dist/elements/Image/helpers/getImageURL.js +25 -0
- package/dist/storybook/decorators.js +3 -2
- package/dist/utils/createGeminiUrl.d.ts +1 -0
- package/dist/utils/createGeminiUrl.js +4 -1
- package/package.json +5 -1
|
@@ -7,6 +7,7 @@ export interface AvatarProps extends ImgHTMLAttributes<any> {
|
|
|
7
7
|
/** The size of the Avatar */
|
|
8
8
|
size?: AvatarSize;
|
|
9
9
|
src?: string;
|
|
10
|
+
performResize?: boolean;
|
|
10
11
|
}
|
|
11
12
|
/** A circular Avatar component containing an image or initials */
|
|
12
|
-
export declare const Avatar: ({ src, initials, size, blurhash }: AvatarProps) => import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export declare const Avatar: ({ src, initials, size, blurhash, performResize, }: AvatarProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -26,11 +26,11 @@ const VARIANTS = {
|
|
|
26
26
|
},
|
|
27
27
|
};
|
|
28
28
|
/** A circular Avatar component containing an image or initials */
|
|
29
|
-
export const Avatar = ({ src, initials, size = DEFAULT_SIZE, blurhash }) => {
|
|
29
|
+
export const Avatar = ({ src, initials, size = DEFAULT_SIZE, blurhash, performResize = true, }) => {
|
|
30
30
|
const color = useColor();
|
|
31
31
|
const { diameter, textSize } = VARIANTS[size];
|
|
32
32
|
if (src) {
|
|
33
|
-
return (_jsx(MotiView, { entering: FadeIn, children: _jsx(Box, { width: diameter, height: diameter, borderRadius: diameter / 2, overflow: "hidden", borderColor: color("mono0"), borderWidth: 1, children: _jsx(Image, { blurhash: blurhash, resizeMode: "cover", src: src, height: diameter, width: diameter, accessibilityLabel: "AvatarImage", style: {
|
|
33
|
+
return (_jsx(MotiView, { entering: FadeIn, children: _jsx(Box, { width: diameter, height: diameter, borderRadius: diameter / 2, overflow: "hidden", borderColor: color("mono0"), borderWidth: 1, children: _jsx(Image, { blurhash: blurhash, resizeMode: "cover", src: src, height: diameter, width: diameter, accessibilityLabel: "AvatarImage", performResize: performResize, style: {
|
|
34
34
|
width: diameter,
|
|
35
35
|
height: diameter,
|
|
36
36
|
} }) }) }));
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
export declare
|
|
1
|
+
import { Avatar } from "./Avatar";
|
|
2
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
3
|
+
declare const meta: Meta<typeof Avatar>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type AvatarStory = StoryObj<typeof Avatar>;
|
|
6
|
+
export declare const Default: AvatarStory;
|
|
7
|
+
export declare const WithImage: AvatarStory;
|
|
8
|
+
export declare const WithInitials: AvatarStory;
|
|
9
|
+
export declare const Variants: AvatarStory;
|
|
@@ -1,11 +1,52 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Avatar } from "./Avatar";
|
|
3
3
|
import { List, Row } from "../../storybook/helpers";
|
|
4
|
-
|
|
4
|
+
const meta = {
|
|
5
5
|
title: "Avatar",
|
|
6
6
|
component: Avatar,
|
|
7
|
+
argTypes: {
|
|
8
|
+
size: {
|
|
9
|
+
control: { type: "select" },
|
|
10
|
+
options: ["xxs", "xs", "sm", "md"],
|
|
11
|
+
description: "The size of the Avatar",
|
|
12
|
+
},
|
|
13
|
+
initials: {
|
|
14
|
+
control: { type: "text" },
|
|
15
|
+
description: "If an image is missing, show initials instead",
|
|
16
|
+
},
|
|
17
|
+
src: {
|
|
18
|
+
control: { type: "text" },
|
|
19
|
+
description: "URL of the avatar image",
|
|
20
|
+
},
|
|
21
|
+
blurhash: {
|
|
22
|
+
control: { type: "text" },
|
|
23
|
+
description: "Blurhash string for the image placeholder",
|
|
24
|
+
},
|
|
25
|
+
},
|
|
7
26
|
};
|
|
27
|
+
export default meta;
|
|
8
28
|
const sizes = ["md", "sm", "xs", "xxs"];
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
29
|
+
export const Default = {
|
|
30
|
+
args: {
|
|
31
|
+
initials: "AB",
|
|
32
|
+
size: "md",
|
|
33
|
+
},
|
|
34
|
+
render: (args) => _jsx(Avatar, { ...args }),
|
|
35
|
+
};
|
|
36
|
+
export const WithImage = {
|
|
37
|
+
args: {
|
|
38
|
+
src: "https://placekitten.com/300/300",
|
|
39
|
+
size: "md",
|
|
40
|
+
},
|
|
41
|
+
render: (args) => _jsx(Avatar, { ...args }),
|
|
42
|
+
};
|
|
43
|
+
export const WithInitials = {
|
|
44
|
+
args: {
|
|
45
|
+
initials: "JD",
|
|
46
|
+
size: "md",
|
|
47
|
+
},
|
|
48
|
+
render: (args) => _jsx(Avatar, { ...args }),
|
|
49
|
+
};
|
|
50
|
+
export const Variants = {
|
|
51
|
+
render: () => (_jsxs(List, { children: [_jsx(Row, { children: sizes.map((s) => (_jsx(Avatar, { initials: "A", size: s }, s))) }), _jsx(Row, { children: sizes.map((s) => (_jsx(Avatar, { initials: "AA", size: s }, s))) }), _jsx(Row, { children: sizes.map((s) => (_jsx(Avatar, { src: "https://placekitten.com/300/300", size: s }, s))) })] })),
|
|
52
|
+
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import FastImage from "@d11/react-native-fast-image";
|
|
3
3
|
import { memo, useRef } from "react";
|
|
4
|
-
import {
|
|
4
|
+
import { View, Animated } from "react-native";
|
|
5
5
|
import { Blurhash } from "react-native-blurhash";
|
|
6
|
-
import {
|
|
6
|
+
import { getImageURL } from "./helpers/getImageURL";
|
|
7
7
|
import { useColor } from "../../utils/hooks";
|
|
8
8
|
import { useScreenDimensions } from "../../utils/hooks/useScreenDimensions";
|
|
9
9
|
import { Flex } from "../Flex";
|
|
@@ -22,15 +22,6 @@ export const Image = memo(({ aspectRatio, width, height, performResize = true, s
|
|
|
22
22
|
if (showLoadingState) {
|
|
23
23
|
return (_jsx(ImageSkeleton, { dimensions: dimensions, blurhash: blurhash, style: { position: "absolute" } }));
|
|
24
24
|
}
|
|
25
|
-
let uri = src;
|
|
26
|
-
if (performResize) {
|
|
27
|
-
uri = createGeminiUrl({
|
|
28
|
-
imageURL: src,
|
|
29
|
-
width: PixelRatio.getPixelSizeForLayoutSize(dimensions.width),
|
|
30
|
-
height: PixelRatio.getPixelSizeForLayoutSize(dimensions.height),
|
|
31
|
-
resizeMode: geminiResizeMode,
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
25
|
return (_jsxs(Flex, { position: "relative", ...flexProps, style: { ...dimensions }, children: [_jsx(View, { style: [dimensions, { position: "absolute" }], children: _jsx(ImageSkeleton, { dimensions: dimensions, blurhash: blurhash, style: { position: "absolute" } }) }), _jsx(FastImage, { style: [
|
|
35
26
|
dimensions,
|
|
36
27
|
style,
|
|
@@ -39,7 +30,7 @@ export const Image = memo(({ aspectRatio, width, height, performResize = true, s
|
|
|
39
30
|
{ backgroundColor: blurhash ? "transparent" : color("mono30") },
|
|
40
31
|
], resizeMode: resizeMode, onLoadEnd: onLoadEnd, source: {
|
|
41
32
|
priority: FastImage.priority.normal,
|
|
42
|
-
uri,
|
|
33
|
+
uri: getImageURL({ src, dimensions, geminiResizeMode, performResize }),
|
|
43
34
|
} })] }));
|
|
44
35
|
});
|
|
45
36
|
const useImageDimensions = (props) => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { getImageURL } from "../helpers/getImageURL";
|
|
2
|
+
describe("getImageURL", () => {
|
|
3
|
+
it("should return the original url if performResize is true", () => {
|
|
4
|
+
const url = getImageURL({
|
|
5
|
+
src: "https://example.com/image.jpg",
|
|
6
|
+
dimensions: { width: 100, height: 100 },
|
|
7
|
+
geminiResizeMode: "fill",
|
|
8
|
+
performResize: true,
|
|
9
|
+
});
|
|
10
|
+
expect(url).toBe("https://d7hftxdivxxvm.cloudfront.net/?height=200&quality=80&resize_to=fill&src=https%3A%2F%2Fexample.com%2Fimage.jpg&width=200");
|
|
11
|
+
});
|
|
12
|
+
it("should return the original url if performResize is true and the url is already resized", () => {
|
|
13
|
+
const url = getImageURL({
|
|
14
|
+
src: "https://d7hftxdivxxvm.cloudfront.net/?height=100&quality=80&resize_to=fill&src=https%3A%2F%2Fexample.com%2Fimage.jpg&width=100",
|
|
15
|
+
dimensions: { width: 100, height: 100 },
|
|
16
|
+
geminiResizeMode: "fill",
|
|
17
|
+
performResize: true,
|
|
18
|
+
});
|
|
19
|
+
expect(url).toBe("https://d7hftxdivxxvm.cloudfront.net/?height=100&quality=80&resize_to=fill&src=https%3A%2F%2Fexample.com%2Fimage.jpg&width=100");
|
|
20
|
+
});
|
|
21
|
+
it("should return the original url if performResize is false", () => {
|
|
22
|
+
const url = getImageURL({
|
|
23
|
+
src: "https://example.com/image.jpg",
|
|
24
|
+
dimensions: { width: 100, height: 100 },
|
|
25
|
+
geminiResizeMode: "fill",
|
|
26
|
+
performResize: false,
|
|
27
|
+
});
|
|
28
|
+
expect(url).toBe("https://example.com/image.jpg");
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { GeminiResizeMode } from "../../../utils/createGeminiUrl";
|
|
2
|
+
/**
|
|
3
|
+
* This method retuns a valid image url to be used within an Image Component
|
|
4
|
+
* It handles the case of resizing the image on the fly using Gemini
|
|
5
|
+
*/
|
|
6
|
+
export declare const getImageURL: ({ src, dimensions, geminiResizeMode, performResize, }: {
|
|
7
|
+
src: string;
|
|
8
|
+
dimensions: {
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
};
|
|
12
|
+
geminiResizeMode: GeminiResizeMode;
|
|
13
|
+
performResize: boolean;
|
|
14
|
+
}) => string;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { PixelRatio } from "react-native";
|
|
2
|
+
import { createGeminiUrl, imageAlreadyResized, } from "../../../utils/createGeminiUrl";
|
|
3
|
+
/**
|
|
4
|
+
* This method retuns a valid image url to be used within an Image Component
|
|
5
|
+
* It handles the case of resizing the image on the fly using Gemini
|
|
6
|
+
*/
|
|
7
|
+
export const getImageURL = ({ src, dimensions, geminiResizeMode, performResize, }) => {
|
|
8
|
+
let uri = src;
|
|
9
|
+
if (performResize) {
|
|
10
|
+
if (!imageAlreadyResized(src)) {
|
|
11
|
+
uri = createGeminiUrl({
|
|
12
|
+
imageURL: src,
|
|
13
|
+
width: PixelRatio.getPixelSizeForLayoutSize(dimensions.width),
|
|
14
|
+
height: PixelRatio.getPixelSizeForLayoutSize(dimensions.height),
|
|
15
|
+
resizeMode: geminiResizeMode,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
if (__DEV__) {
|
|
20
|
+
console.warn("You are resizing a gemini url that is already resized. Pass performResize={false} or do not use a resized url");
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return uri;
|
|
25
|
+
};
|
|
@@ -5,7 +5,8 @@ import { Appearance } from "react-native";
|
|
|
5
5
|
import { SafeAreaProvider } from "react-native-safe-area-context";
|
|
6
6
|
import { Theme } from "../Theme";
|
|
7
7
|
import { Flex } from "../elements/Flex";
|
|
8
|
-
import {
|
|
8
|
+
import { Pill } from "../elements/Pill";
|
|
9
|
+
import { Text } from "../elements/Text";
|
|
9
10
|
import { ScreenDimensionsProvider } from "../utils/hooks";
|
|
10
11
|
export const withTheme = (story) => (_jsxs(Theme, { theme: "v3light", children: [_jsx(Text, { color: "red", children: "aaww" }), story()] }));
|
|
11
12
|
const DARK_MODE_STORAGE_KEY = "dark-mode-mode";
|
|
@@ -38,5 +39,5 @@ export const useDarkModeSwitcher = (story) => {
|
|
|
38
39
|
};
|
|
39
40
|
const isDarkMode = mode === "dark" || (mode === "system" && systemMode === "dark");
|
|
40
41
|
const theme = isDarkMode ? "v3dark" : "v3light";
|
|
41
|
-
return (_jsx(ScreenDimensionsProvider, { children: _jsx(SafeAreaProvider, { children: _jsx(Theme, { theme: theme, children: _jsxs(Flex, { flex: 1, backgroundColor: "background", children: [_jsxs(Flex, { flexDirection: "row", justifyContent: "space-around", children: [
|
|
42
|
+
return (_jsx(ScreenDimensionsProvider, { children: _jsx(SafeAreaProvider, { children: _jsx(Theme, { theme: theme, children: _jsxs(Flex, { flex: 1, backgroundColor: "background", children: [_jsxs(Flex, { flexDirection: "row", justifyContent: "space-around", py: 1, backgroundColor: "mono5", children: [_jsx(Text, { color: "mono100", children: "Dark mode" }), _jsxs(Flex, { flexDirection: "row", gap: 1, children: [_jsx(Pill, { variant: "default", selected: mode === "light", onPress: () => setMode("light"), children: "Light" }), _jsx(Pill, { variant: "default", selected: mode === "dark", onPress: () => setMode("dark"), children: "Dark" }), _jsx(Pill, { variant: "default", selected: mode === "system", onPress: () => setMode("system"), children: "System" })] })] }), _jsx(Flex, { p: 2, children: story() })] }) }) }) }));
|
|
42
43
|
};
|
|
@@ -3,8 +3,11 @@ const geminiHosts = [
|
|
|
3
3
|
"https://d7hftxdivxxvm.cloudfront.net",
|
|
4
4
|
"https://d196wkiy8qx2u5.cloudfront.net",
|
|
5
5
|
];
|
|
6
|
+
export const imageAlreadyResized = (imageURL) => {
|
|
7
|
+
return geminiHosts.some((host) => imageURL.includes(host));
|
|
8
|
+
};
|
|
6
9
|
export function createGeminiUrl({ imageURL, width, height, geminiHost = "d7hftxdivxxvm.cloudfront.net", imageQuality = 80, resizeMode = "fill", }) {
|
|
7
|
-
if (
|
|
10
|
+
if (imageAlreadyResized(imageURL)) {
|
|
8
11
|
console.error("Image: `performResize` on self referential url. Avoid resizing gemini urls. Pass performResize={false} to fix this.", { imageURL });
|
|
9
12
|
}
|
|
10
13
|
const src = encodeURIComponent(imageURL);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@artsy/palette-mobile",
|
|
3
|
-
"version": "19.
|
|
3
|
+
"version": "19.17.0",
|
|
4
4
|
"description": "Artsy's design system for React Native",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"android": "expo run:android --port 8082",
|
|
@@ -79,7 +79,11 @@
|
|
|
79
79
|
"@babel/runtime": "^7.25.0",
|
|
80
80
|
"@gorhom/bottom-sheet": "^4.6.4",
|
|
81
81
|
"@react-native-async-storage/async-storage": "2.2.0",
|
|
82
|
+
"@react-native-community/datetimepicker": "8.0.1",
|
|
83
|
+
"@react-native-community/slider": "4.5.2",
|
|
82
84
|
"@react-native/eslint-config": "0.76.9",
|
|
85
|
+
"@storybook/addon-ondevice-actions": "^8.3.5",
|
|
86
|
+
"@storybook/addon-ondevice-controls": "^8.3.5",
|
|
83
87
|
"@storybook/react-native": "^8.6.2",
|
|
84
88
|
"@testing-library/react-native": "13.2.0",
|
|
85
89
|
"@types/events": "^3.0.0",
|