@artsy/palette-mobile 13.2.3 → 13.2.4
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/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;
|
|
@@ -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
|
+
});
|