@artsy/palette-mobile 13.2.3 → 13.2.5
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/Button/FollowButton.d.ts +3 -1
- package/dist/elements/Button/FollowButton.js +4 -2
- package/dist/elements/ButtonNew/Button.stories.js +1 -1
- package/dist/elements/ButtonNew/FollowButton.d.ts +4 -2
- package/dist/elements/ButtonNew/FollowButton.js +6 -4
- package/dist/elements/Message/Message.js +2 -2
- package/dist/elements/Message/Message.stories.js +2 -1
- package/dist/utils/formatLargeNumber.d.ts +1 -0
- package/dist/utils/formatLargeNumber.js +18 -0
- package/dist/utils/formatLargeNumbers.tests.d.ts +1 -0
- package/dist/utils/formatLargeNumbers.tests.js +20 -0
- package/package.json +1 -1
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
import { ButtonProps } from "../Button";
|
|
3
3
|
type FollowButtonProps = Omit<ButtonProps, "variant" | "size" | "longestText" | "icon" | "children"> & {
|
|
4
4
|
isFollowed: boolean;
|
|
5
|
+
followCount?: number;
|
|
6
|
+
longestText?: string;
|
|
5
7
|
};
|
|
6
|
-
export declare const FollowButton: ({ isFollowed, ...restProps }: FollowButtonProps) => JSX.Element;
|
|
8
|
+
export declare const FollowButton: ({ isFollowed, followCount, longestText, ...restProps }: FollowButtonProps) => JSX.Element;
|
|
7
9
|
export {};
|
|
@@ -3,8 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.FollowButton = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const CheckIcon_1 = require("../../svgs/CheckIcon");
|
|
6
|
+
const formatLargeNumber_1 = require("../../utils/formatLargeNumber");
|
|
6
7
|
const Button_1 = require("../Button");
|
|
7
|
-
const
|
|
8
|
-
|
|
8
|
+
const Text_1 = require("../Text");
|
|
9
|
+
const FollowButton = ({ isFollowed, followCount, longestText, ...restProps }) => {
|
|
10
|
+
return ((0, jsx_runtime_1.jsxs)(Button_1.Button, { variant: isFollowed ? "outline" : "outlineGray", size: "small", longestText: longestText ? longestText : "Following", icon: isFollowed && (0, jsx_runtime_1.jsx)(CheckIcon_1.CheckIcon, { fill: "black60", width: "16px", height: "16px" }), ...restProps, children: [(0, jsx_runtime_1.jsx)(Text_1.Text, { variant: "xs", children: isFollowed ? "Following" : "Follow" }), !!followCount && followCount > 1 && ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(Text_1.Text, { variant: "xs", color: "black60", children: " " + (0, formatLargeNumber_1.formatLargeNumber)(followCount, 1) }) }))] }));
|
|
9
11
|
};
|
|
10
12
|
exports.FollowButton = FollowButton;
|
|
@@ -46,7 +46,7 @@ const VariantsDisabled = () => ((0, jsx_runtime_1.jsx)(helpers_1.DataList, { dat
|
|
|
46
46
|
exports.VariantsDisabled = VariantsDisabled;
|
|
47
47
|
const TheFollowButton = () => {
|
|
48
48
|
const [follow, setFollow] = (0, react_1.useState)(true);
|
|
49
|
-
return ((0, jsx_runtime_1.
|
|
49
|
+
return ((0, jsx_runtime_1.jsxs)(helpers_1.List, { children: [(0, jsx_runtime_1.jsx)(FollowButton_1.FollowButton, { isFollowed: follow, onPress: () => setFollow((v) => !v) }), (0, jsx_runtime_1.jsx)(FollowButton_1.FollowButton, { followCount: 4, isFollowed: follow, onPress: () => setFollow((v) => !v) }), (0, jsx_runtime_1.jsx)(FollowButton_1.FollowButton, { followCount: 40, isFollowed: follow, onPress: () => setFollow((v) => !v) }), (0, jsx_runtime_1.jsx)(FollowButton_1.FollowButton, { followCount: 4000, isFollowed: follow, onPress: () => setFollow((v) => !v) }), (0, jsx_runtime_1.jsx)(FollowButton_1.FollowButton, { followCount: 400000, isFollowed: follow, onPress: () => setFollow((v) => !v) }), (0, jsx_runtime_1.jsx)(FollowButton_1.FollowButton, { followCount: 40000000, isFollowed: follow, onPress: () => setFollow((v) => !v) }), (0, jsx_runtime_1.jsx)(FollowButton_1.FollowButton, { followCount: 4000000000, isFollowed: follow, onPress: () => setFollow((v) => !v) })] }));
|
|
50
50
|
};
|
|
51
51
|
exports.TheFollowButton = TheFollowButton;
|
|
52
52
|
const TheCTAButton = () => ((0, jsx_runtime_1.jsx)(helpers_1.List, { children: (0, jsx_runtime_1.jsx)(CTAButton_1.CTAButton, { onPress: () => console.log("pressed"), children: "cta button" }) }));
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { ButtonProps } from "
|
|
2
|
+
import { ButtonProps } from "../Button";
|
|
3
3
|
type FollowButtonProps = Omit<ButtonProps, "variant" | "size" | "longestText" | "icon" | "children"> & {
|
|
4
4
|
isFollowed: boolean;
|
|
5
|
+
followCount?: number;
|
|
6
|
+
longestText?: string;
|
|
5
7
|
};
|
|
6
|
-
export declare const FollowButton: ({ isFollowed, ...restProps }: FollowButtonProps) => JSX.Element;
|
|
8
|
+
export declare const FollowButton: ({ isFollowed, followCount, longestText, ...restProps }: FollowButtonProps) => JSX.Element;
|
|
7
9
|
export {};
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FollowButton = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
5
|
+
const CheckIcon_1 = require("../../svgs/CheckIcon");
|
|
6
|
+
const formatLargeNumber_1 = require("../../utils/formatLargeNumber");
|
|
7
|
+
const Button_1 = require("../Button");
|
|
8
|
+
const Text_1 = require("../Text");
|
|
9
|
+
const FollowButton = ({ isFollowed, followCount, longestText, ...restProps }) => {
|
|
10
|
+
return ((0, jsx_runtime_1.jsxs)(Button_1.Button, { variant: isFollowed ? "outline" : "outlineGray", size: "small", longestText: longestText ? longestText : "Following", icon: isFollowed && (0, jsx_runtime_1.jsx)(CheckIcon_1.CheckIcon, { fill: "black60", width: "16px", height: "16px" }), ...restProps, children: [(0, jsx_runtime_1.jsx)(Text_1.Text, { variant: "xs", children: isFollowed ? "Following" : "Follow" }), !!followCount && followCount > 1 && ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(Text_1.Text, { variant: "xs", color: "black60", children: " " + (0, formatLargeNumber_1.formatLargeNumber)(followCount, 1) }) }))] }));
|
|
9
11
|
};
|
|
10
12
|
exports.FollowButton = FollowButton;
|
|
@@ -8,7 +8,7 @@ const svgs_1 = require("../../svgs");
|
|
|
8
8
|
const useColor_1 = require("../../utils/hooks/useColor");
|
|
9
9
|
const Flex_1 = require("../Flex");
|
|
10
10
|
const Text_1 = require("../Text");
|
|
11
|
-
const Message = ({ bodyTextStyle, containerStyle, IconComponent, iconPosition = "left", onClose, showCloseButton = false, testID, text, title, titleStyle, variant = "default", }) => {
|
|
11
|
+
const Message = ({ bodyTextStyle, children, containerStyle, IconComponent, iconPosition = "left", onClose, showCloseButton = false, testID, text, title, titleStyle, variant = "default", }) => {
|
|
12
12
|
const color = (0, useColor_1.useColor)();
|
|
13
13
|
const [tempHeight, setTempHeight] = (0, react_1.useState)(undefined);
|
|
14
14
|
const scaleYAnim = (0, react_1.useRef)(new react_native_1.Animated.Value(0)).current;
|
|
@@ -33,7 +33,7 @@ const Message = ({ bodyTextStyle, containerStyle, IconComponent, iconPosition =
|
|
|
33
33
|
}),
|
|
34
34
|
},
|
|
35
35
|
],
|
|
36
|
-
}, children: (0, jsx_runtime_1.jsx)(Flex_1.Flex, { backgroundColor: color(colors[variant].background), ...containerStyle, children: (0, jsx_runtime_1.jsxs)(Flex_1.Flex, { px: 2, py: 1, flexDirection: "row", justifyContent: "space-between", children: [(0, jsx_runtime_1.jsxs)(Flex_1.Flex, { flex: 1, children: [(0, jsx_runtime_1.jsxs)(Flex_1.Flex, { flexDirection: "row", children: [!!IconComponent && iconPosition === "left" && ((0, jsx_runtime_1.jsx)(Flex_1.Flex, { mr: 1, children: (0, jsx_runtime_1.jsx)(IconComponent, {}) })), (0, jsx_runtime_1.jsx)(Text_1.Text, { pr: 2, variant: "xs", color: color(colors[variant].title), ...titleStyle, children: title })] }), !!text && ((0, jsx_runtime_1.jsx)(Text_1.Text, { variant: "xs", color: color(colors[variant].text), ...bodyTextStyle, children: text }))] }), !!IconComponent && iconPosition === "right" && ((0, jsx_runtime_1.jsx)(Flex_1.Flex, { mr: showCloseButton ? 1 : 0, justifyContent: "center", children: (0, jsx_runtime_1.jsx)(IconComponent, {}) })), !!showCloseButton && ((0, jsx_runtime_1.jsx)(Flex_1.Flex, { style: { marginTop: 2 }, children: (0, jsx_runtime_1.jsx)(react_native_1.TouchableOpacity, { testID: "Message-close-button", onPress: handleClose, hitSlop: { bottom: 10, right: 10, left: 10, top: 10 }, children: (0, jsx_runtime_1.jsx)(svgs_1.CloseIcon, { fill: color("black100") }) }) }))] }) }) }));
|
|
36
|
+
}, children: (0, jsx_runtime_1.jsx)(Flex_1.Flex, { backgroundColor: color(colors[variant].background), ...containerStyle, children: (0, jsx_runtime_1.jsxs)(Flex_1.Flex, { px: 2, py: 1, flexDirection: "row", justifyContent: "space-between", children: [(0, jsx_runtime_1.jsxs)(Flex_1.Flex, { flex: 1, children: [(0, jsx_runtime_1.jsxs)(Flex_1.Flex, { flexDirection: "row", children: [!!IconComponent && iconPosition === "left" && ((0, jsx_runtime_1.jsx)(Flex_1.Flex, { mr: 1, children: (0, jsx_runtime_1.jsx)(IconComponent, {}) })), (0, jsx_runtime_1.jsx)(Text_1.Text, { pr: 2, variant: "xs", color: color(colors[variant].title), ...titleStyle, children: title })] }), !!text && ((0, jsx_runtime_1.jsx)(Text_1.Text, { variant: "xs", color: color(colors[variant].text), ...bodyTextStyle, children: text })), children] }), !!IconComponent && iconPosition === "right" && ((0, jsx_runtime_1.jsx)(Flex_1.Flex, { mr: showCloseButton ? 1 : 0, justifyContent: "center", children: (0, jsx_runtime_1.jsx)(IconComponent, {}) })), !!showCloseButton && ((0, jsx_runtime_1.jsx)(Flex_1.Flex, { style: { marginTop: 2 }, children: (0, jsx_runtime_1.jsx)(react_native_1.TouchableOpacity, { testID: "Message-close-button", onPress: handleClose, hitSlop: { bottom: 10, right: 10, left: 10, top: 10 }, children: (0, jsx_runtime_1.jsx)(svgs_1.CloseIcon, { fill: color("black100") }) }) }))] }) }) }));
|
|
37
37
|
};
|
|
38
38
|
exports.Message = Message;
|
|
39
39
|
const colors = {
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
4
|
const react_native_1 = require("@storybook/react-native");
|
|
5
|
+
const react_native_2 = require("react-native");
|
|
5
6
|
const Message_1 = require("./Message");
|
|
6
7
|
const decorators_1 = require("../../storybook/decorators");
|
|
7
8
|
const helpers_1 = require("../../storybook/helpers");
|
|
8
9
|
(0, react_native_1.storiesOf)("Message", module)
|
|
9
10
|
.addDecorator(decorators_1.withTheme)
|
|
10
|
-
.add("Variants", () => ((0, jsx_runtime_1.jsxs)(helpers_1.List, { contentContainerStyle: { marginHorizontal: 20, alignItems: "stretch" }, children: [(0, jsx_runtime_1.jsx)(Message_1.Message, { variant: "default", title: "Without Close Button", text: "Text" }), (0, jsx_runtime_1.jsx)(Message_1.Message, { variant: "default", showCloseButton: true, title: "Title", text: "Text" }), (0, jsx_runtime_1.jsx)(Message_1.Message, { variant: "default", showCloseButton: true, title: "Title", text: "Very very very very very very very very very very very very very very long text" }), (0, jsx_runtime_1.jsx)(Message_1.Message, { variant: "default", showCloseButton: true, title: "Very very very very very very very very very very very very very very long title", text: "Text" }), (0, jsx_runtime_1.jsx)(Message_1.Message, { variant: "default", showCloseButton: true, title: "Very very very very very very very very very very very very very very long title", text: "Very very very very very very very very very very very very very very long text" })] })))
|
|
11
|
+
.add("Variants", () => ((0, jsx_runtime_1.jsxs)(helpers_1.List, { contentContainerStyle: { marginHorizontal: 20, alignItems: "stretch" }, children: [(0, jsx_runtime_1.jsx)(Message_1.Message, { variant: "default", title: "Without Close Button", text: "Text" }), (0, jsx_runtime_1.jsx)(Message_1.Message, { variant: "default", title: "Without Close Button", children: (0, jsx_runtime_1.jsx)(react_native_2.Text, { children: "Text" }) }), (0, jsx_runtime_1.jsx)(Message_1.Message, { variant: "default", showCloseButton: true, title: "Title", text: "Text" }), (0, jsx_runtime_1.jsx)(Message_1.Message, { variant: "default", showCloseButton: true, title: "Title", text: "Very very very very very very very very very very very very very very long text" }), (0, jsx_runtime_1.jsx)(Message_1.Message, { variant: "default", showCloseButton: true, title: "Very very very very very very very very very very very very very very long title", text: "Text" }), (0, jsx_runtime_1.jsx)(Message_1.Message, { variant: "default", showCloseButton: true, title: "Very very very very very very very very very very very very very very long title", text: "Very very very very very very very very very very very very very very long text" })] })))
|
|
11
12
|
.add("Color Variants", () => ((0, jsx_runtime_1.jsxs)(helpers_1.List, { contentContainerStyle: { marginHorizontal: 20, alignItems: "stretch" }, children: [(0, jsx_runtime_1.jsx)(Message_1.Message, { variant: "default", showCloseButton: true, title: "Default", text: "Text" }), (0, jsx_runtime_1.jsx)(Message_1.Message, { variant: "info", showCloseButton: true, title: "Info", text: "Text" }), (0, jsx_runtime_1.jsx)(Message_1.Message, { variant: "success", showCloseButton: true, title: "Success", text: "Text" }), (0, jsx_runtime_1.jsx)(Message_1.Message, { variant: "warning", showCloseButton: true, title: "Warning", text: "Text" }), (0, jsx_runtime_1.jsx)(Message_1.Message, { variant: "error", showCloseButton: true, title: "Error", text: "Text" })] })));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function formatLargeNumber(number: number, decimalPlaces?: number): string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatLargeNumber = void 0;
|
|
4
|
+
function formatLargeNumber(number, decimalPlaces = 0) {
|
|
5
|
+
if (number < 1000) {
|
|
6
|
+
return number.toString();
|
|
7
|
+
}
|
|
8
|
+
else if (number < 1000000) {
|
|
9
|
+
return `${(number / 1000).toFixed(decimalPlaces)}K`;
|
|
10
|
+
}
|
|
11
|
+
else if (number < 1000000000) {
|
|
12
|
+
return `${(number / 1000000).toFixed(decimalPlaces)}M`;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
return `${(number / 1000000000).toFixed(decimalPlaces)}B`;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.formatLargeNumber = formatLargeNumber;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const formatLargeNumber_1 = require("./formatLargeNumber");
|
|
4
|
+
describe("formatLargeNumber", () => {
|
|
5
|
+
it("should return the same number for numbers less than 1000", () => {
|
|
6
|
+
expect((0, formatLargeNumber_1.formatLargeNumber)(500)).toBe("500");
|
|
7
|
+
});
|
|
8
|
+
it("should format numbers in thousands correctly", () => {
|
|
9
|
+
expect((0, formatLargeNumber_1.formatLargeNumber)(1500, 1)).toBe("1.5K");
|
|
10
|
+
expect((0, formatLargeNumber_1.formatLargeNumber)(1500, 2)).toBe("1.50K");
|
|
11
|
+
});
|
|
12
|
+
it("should format numbers in millions correctly", () => {
|
|
13
|
+
expect((0, formatLargeNumber_1.formatLargeNumber)(1500000, 1)).toBe("1.5M");
|
|
14
|
+
expect((0, formatLargeNumber_1.formatLargeNumber)(1500000, 2)).toBe("1.50M");
|
|
15
|
+
});
|
|
16
|
+
it("should format numbers in billions correctly", () => {
|
|
17
|
+
expect((0, formatLargeNumber_1.formatLargeNumber)(1500000000, 1)).toBe("1.5B");
|
|
18
|
+
expect((0, formatLargeNumber_1.formatLargeNumber)(1500000000, 2)).toBe("1.50B");
|
|
19
|
+
});
|
|
20
|
+
});
|