@artsy/palette-mobile 11.2.7 → 11.2.8
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/elements/Pill/Pill.d.ts +20 -0
- package/dist/elements/Pill/Pill.js +156 -0
- package/dist/elements/Pill/Pill.stories.d.ts +6 -0
- package/dist/elements/Pill/Pill.stories.js +25 -0
- package/dist/elements/Pill/Pill.tests.d.ts +1 -0
- package/dist/elements/Pill/Pill.tests.js +20 -0
- package/dist/elements/Pill/index.d.ts +1 -0
- package/dist/elements/Pill/index.js +17 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
# v11.2.8 (Thu Jul 27 2023)
|
|
2
|
+
|
|
3
|
+
#### 🐛 Bug Fix
|
|
4
|
+
|
|
5
|
+
- feat(Pill): Pill element [#128](https://github.com/artsy/palette-mobile/pull/128) ([@araujobarret](https://github.com/araujobarret))
|
|
6
|
+
|
|
7
|
+
#### Authors: 1
|
|
8
|
+
|
|
9
|
+
- Carlos Alberto de Araujo Barreto ([@araujobarret](https://github.com/araujobarret))
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
1
13
|
# v11.2.7 (Mon Jul 24 2023)
|
|
2
14
|
|
|
3
15
|
:tada: This release contains work from a new contributor! :tada:
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { MotiPressableProps } from "moti/interactions";
|
|
3
|
+
import { IconProps } from "../../svgs/Icon";
|
|
4
|
+
import { FlexProps } from "../Flex";
|
|
5
|
+
export declare const PILL_VARIANT_NAMES: readonly ["default", "search", "filter", "artist", "badge"];
|
|
6
|
+
export type PillState = "default" | "selected" | "disabled";
|
|
7
|
+
export type PillVariant = typeof PILL_VARIANT_NAMES[number];
|
|
8
|
+
export type PillProps = (FlexProps & {
|
|
9
|
+
selected?: boolean;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
Icon?: React.FC<IconProps>;
|
|
12
|
+
onPress?: MotiPressableProps["onPress"];
|
|
13
|
+
}) & ({
|
|
14
|
+
variant?: Extract<PillVariant, "default" | "filter" | "badge" | "search">;
|
|
15
|
+
src?: never;
|
|
16
|
+
} | {
|
|
17
|
+
variant: Extract<PillVariant, "artist">;
|
|
18
|
+
src?: string;
|
|
19
|
+
});
|
|
20
|
+
export declare const Pill: React.FC<PillProps>;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.Pill = exports.PILL_VARIANT_NAMES = void 0;
|
|
30
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
31
|
+
const theme_get_1 = __importDefault(require("@styled-system/theme-get"));
|
|
32
|
+
const interactions_1 = require("moti/interactions");
|
|
33
|
+
const react_1 = require("react");
|
|
34
|
+
const styled_components_1 = __importStar(require("styled-components"));
|
|
35
|
+
const svgs_1 = require("../../svgs");
|
|
36
|
+
const Flex_1 = require("../Flex");
|
|
37
|
+
const Image_1 = require("../Image");
|
|
38
|
+
const Text_1 = require("../Text");
|
|
39
|
+
exports.PILL_VARIANT_NAMES = ["default", "search", "filter", "artist", "badge"];
|
|
40
|
+
const Pill = ({ variant = "default", src, selected, disabled, Icon, children, onPress, ...rest }) => {
|
|
41
|
+
const stateString = selected ? "selected" : disabled ? "disabled" : "default";
|
|
42
|
+
const color = TEXT_COLOR[variant][stateString];
|
|
43
|
+
return ((0, jsx_runtime_1.jsx)(Flex_1.Flex, { ...rest, children: (0, jsx_runtime_1.jsxs)(Container, { variant: variant, selected: selected, disabled: disabled, onPress: onPress, animate: (0, react_1.useMemo)(() => ({ hovered, pressed }) => {
|
|
44
|
+
"worklet";
|
|
45
|
+
return {
|
|
46
|
+
opacity: hovered || pressed ? 0.5 : 1,
|
|
47
|
+
};
|
|
48
|
+
}, []), children: [variant === "artist" && ((0, jsx_runtime_1.jsx)(Thumbnail, { src: src, height: 30, width: 30, style: { overflow: "hidden" } })), Icon && (0, jsx_runtime_1.jsx)(Icon, { fill: color, ml: -0.5, mr: 0.5 }), (0, jsx_runtime_1.jsx)(Text_1.Text, { variant: "xs", color: color, children: children }), ((variant === "filter" && !disabled) || (variant === "artist" && selected)) && ((0, jsx_runtime_1.jsx)(svgs_1.CloseIcon, { fill: color, ml: 0.5, width: 15, height: 15 }))] }) }));
|
|
49
|
+
};
|
|
50
|
+
exports.Pill = Pill;
|
|
51
|
+
const Container = (0, styled_components_1.default)(interactions_1.MotiPressable) `
|
|
52
|
+
align-items: center;
|
|
53
|
+
border: 1px solid ${(0, theme_get_1.default)("colors.black15")};
|
|
54
|
+
flex-direction: row;
|
|
55
|
+
justify-content: center;
|
|
56
|
+
text-align: center;
|
|
57
|
+
padding: 20px;
|
|
58
|
+
|
|
59
|
+
${(props) => {
|
|
60
|
+
const states = PILL_VARIANTS[props.variant];
|
|
61
|
+
return (0, styled_components_1.css) `
|
|
62
|
+
${states.default}
|
|
63
|
+
${props.selected && states.selected}
|
|
64
|
+
${props.disabled && states.disabled}
|
|
65
|
+
`;
|
|
66
|
+
}}
|
|
67
|
+
`;
|
|
68
|
+
const Thumbnail = (0, styled_components_1.default)(Image_1.Image) `
|
|
69
|
+
background-color: ${(0, theme_get_1.default)("colors.black30")};
|
|
70
|
+
border-radius: 50px;
|
|
71
|
+
margin-right: ${(0, theme_get_1.default)("space.1")};
|
|
72
|
+
`;
|
|
73
|
+
const PILL_STATES = {
|
|
74
|
+
default: (0, styled_components_1.css) `
|
|
75
|
+
border-radius: 15px;
|
|
76
|
+
height: 30px;
|
|
77
|
+
padding: 0 ${(0, theme_get_1.default)("space.2")};
|
|
78
|
+
`,
|
|
79
|
+
selected: (0, styled_components_1.css) `
|
|
80
|
+
border-color: ${(0, theme_get_1.default)("colors.blue100")};
|
|
81
|
+
background-color: ${(0, theme_get_1.default)("colors.blue100")};
|
|
82
|
+
`,
|
|
83
|
+
disabled: (0, styled_components_1.css) `
|
|
84
|
+
background-color: ${(0, theme_get_1.default)("colors.black5")};
|
|
85
|
+
border-color: ${(0, theme_get_1.default)("colors.black5")};
|
|
86
|
+
`,
|
|
87
|
+
};
|
|
88
|
+
const PILL_VARIANTS = {
|
|
89
|
+
default: PILL_STATES,
|
|
90
|
+
search: {
|
|
91
|
+
...PILL_STATES,
|
|
92
|
+
default: (0, styled_components_1.css) `
|
|
93
|
+
${PILL_STATES.default}
|
|
94
|
+
`,
|
|
95
|
+
},
|
|
96
|
+
artist: {
|
|
97
|
+
default: (0, styled_components_1.css) `
|
|
98
|
+
border-radius: 25px;
|
|
99
|
+
height: 50px;
|
|
100
|
+
padding: 0 ${(0, theme_get_1.default)("space.2")} 0 ${(0, theme_get_1.default)("space.1")};
|
|
101
|
+
`,
|
|
102
|
+
selected: (0, styled_components_1.css) `
|
|
103
|
+
border-color: ${(0, theme_get_1.default)("colors.blue100")};
|
|
104
|
+
`,
|
|
105
|
+
disabled: (0, styled_components_1.css) ``,
|
|
106
|
+
},
|
|
107
|
+
badge: {
|
|
108
|
+
default: (0, styled_components_1.css) `
|
|
109
|
+
border-radius: 15px;
|
|
110
|
+
height: 30px;
|
|
111
|
+
padding: 0 15px;
|
|
112
|
+
background-color: ${(0, theme_get_1.default)("colors.blue10")};
|
|
113
|
+
border-color: ${(0, theme_get_1.default)("colors.blue10")};
|
|
114
|
+
`,
|
|
115
|
+
selected: (0, styled_components_1.css) `
|
|
116
|
+
background-color: ${(0, theme_get_1.default)("colors.blue150")};
|
|
117
|
+
border-color: ${(0, theme_get_1.default)("colors.blue150")};
|
|
118
|
+
`,
|
|
119
|
+
disabled: (0, styled_components_1.css) `
|
|
120
|
+
background-color: ${(0, theme_get_1.default)("colors.blue10")};
|
|
121
|
+
border-color: ${(0, theme_get_1.default)("colors.blue10")};
|
|
122
|
+
`,
|
|
123
|
+
},
|
|
124
|
+
filter: {
|
|
125
|
+
...PILL_STATES,
|
|
126
|
+
default: (0, styled_components_1.css) `
|
|
127
|
+
height: 30px;
|
|
128
|
+
padding: 0 ${(0, theme_get_1.default)("space.1")};
|
|
129
|
+
`,
|
|
130
|
+
disabled: (0, styled_components_1.css) `
|
|
131
|
+
border-color: ${(0, theme_get_1.default)("colors.black60")};
|
|
132
|
+
`,
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
const defaultColors = {
|
|
136
|
+
default: "black100",
|
|
137
|
+
selected: "white100",
|
|
138
|
+
disabled: "black60",
|
|
139
|
+
};
|
|
140
|
+
const TEXT_COLOR = {
|
|
141
|
+
default: defaultColors,
|
|
142
|
+
search: defaultColors,
|
|
143
|
+
artist: {
|
|
144
|
+
...defaultColors,
|
|
145
|
+
selected: "black100",
|
|
146
|
+
},
|
|
147
|
+
badge: {
|
|
148
|
+
default: "blue100",
|
|
149
|
+
selected: "white100",
|
|
150
|
+
disabled: "blue100",
|
|
151
|
+
},
|
|
152
|
+
filter: {
|
|
153
|
+
...defaultColors,
|
|
154
|
+
disabled: "black100",
|
|
155
|
+
},
|
|
156
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
|
+
const react_native_1 = require("@storybook/react-native");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const Pill_1 = require("./Pill");
|
|
7
|
+
const helpers_1 = require("../../storybook/helpers");
|
|
8
|
+
const svgs_1 = require("../../svgs");
|
|
9
|
+
const Flex_1 = require("../Flex");
|
|
10
|
+
exports.default = {
|
|
11
|
+
title: "Pill",
|
|
12
|
+
component: Pill_1.Pill,
|
|
13
|
+
};
|
|
14
|
+
(0, react_native_1.storiesOf)("Pill", module)
|
|
15
|
+
.add("Variants", () => ((0, jsx_runtime_1.jsxs)(helpers_1.List, { contentContainerStyle: {
|
|
16
|
+
marginHorizontal: 20,
|
|
17
|
+
justifyContent: "flex-start",
|
|
18
|
+
alignItems: "flex-start",
|
|
19
|
+
}, children: [(0, jsx_runtime_1.jsxs)(Flex_1.Flex, { flexDirection: "row", children: [(0, jsx_runtime_1.jsx)(Pill_1.Pill, { children: "Default" }), (0, jsx_runtime_1.jsx)(Pill_1.Pill, { selected: true, ml: 1, children: "Selected" }), (0, jsx_runtime_1.jsx)(Pill_1.Pill, { disabled: true, ml: 1, children: "Disabled" })] }), (0, jsx_runtime_1.jsxs)(Flex_1.Flex, { flexDirection: "row", children: [(0, jsx_runtime_1.jsx)(Pill_1.Pill, { variant: "filter", children: "Filter" }), (0, jsx_runtime_1.jsx)(Pill_1.Pill, { variant: "filter", selected: true, ml: 1, children: "Selected" }), (0, jsx_runtime_1.jsx)(Pill_1.Pill, { variant: "filter", disabled: true, ml: 1, children: "Disabled" })] }), (0, jsx_runtime_1.jsxs)(Flex_1.Flex, { flexDirection: "row", children: [(0, jsx_runtime_1.jsx)(Pill_1.Pill, { Icon: svgs_1.GraphIcon, variant: "badge", children: "Badge" }), (0, jsx_runtime_1.jsx)(Pill_1.Pill, { Icon: svgs_1.GraphIcon, variant: "badge", selected: true, ml: 1, children: "Selected" }), (0, jsx_runtime_1.jsx)(Pill_1.Pill, { Icon: svgs_1.GraphIcon, variant: "badge", disabled: true, ml: 1, children: "Disabled" })] }), (0, jsx_runtime_1.jsxs)(Flex_1.Flex, { flexDirection: "row", children: [(0, jsx_runtime_1.jsx)(Pill_1.Pill, { variant: "artist", children: "Artist" }), (0, jsx_runtime_1.jsx)(Pill_1.Pill, { variant: "artist", selected: true, ml: 1, children: "Selected" }), (0, jsx_runtime_1.jsx)(Pill_1.Pill, { variant: "artist", disabled: true, ml: 1, children: "Disabled" })] }), (0, jsx_runtime_1.jsxs)(Flex_1.Flex, { flexDirection: "row", children: [(0, jsx_runtime_1.jsx)(Pill_1.Pill, { variant: "search", children: "Search" }), (0, jsx_runtime_1.jsx)(Pill_1.Pill, { variant: "search", selected: true, ml: 1, children: "Selected" }), (0, jsx_runtime_1.jsx)(Pill_1.Pill, { variant: "search", disabled: true, ml: 1, children: "Search" })] })] })))
|
|
20
|
+
.add("Artist with image", () => ((0, jsx_runtime_1.jsxs)(helpers_1.List, { contentContainerStyle: { marginHorizontal: 20 }, children: [(0, jsx_runtime_1.jsx)(Pill_1.Pill, { variant: "artist", src: src, children: "Artist" }), (0, jsx_runtime_1.jsx)(Pill_1.Pill, { variant: "artist", src: src, selected: true, ml: 1, children: "Selected" }), (0, jsx_runtime_1.jsx)(Pill_1.Pill, { variant: "artist", src: src, disabled: true, ml: 1, children: "Disabled" })] })))
|
|
21
|
+
.add("Controlled state", () => {
|
|
22
|
+
const [selected, setSelected] = (0, react_1.useState)(false);
|
|
23
|
+
return ((0, jsx_runtime_1.jsx)(helpers_1.List, { contentContainerStyle: { marginHorizontal: 20 }, children: (0, jsx_runtime_1.jsx)(Pill_1.Pill, { selected: selected, onPress: () => setSelected((prev) => !prev), children: "Pill" }) }));
|
|
24
|
+
});
|
|
25
|
+
const src = "https://d32dm0rphc51dk.cloudfront.net/A983VUIZusVBKy420xP3ow/normalized.jpg";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
|
+
const react_native_1 = require("@testing-library/react-native");
|
|
5
|
+
const Pill_1 = require("./Pill");
|
|
6
|
+
const Theme_1 = require("../../Theme");
|
|
7
|
+
describe("Pill", () => {
|
|
8
|
+
it("invokes the onClick callback", () => {
|
|
9
|
+
const onPress = jest.fn();
|
|
10
|
+
const { getByText } = (0, react_native_1.render)((0, jsx_runtime_1.jsx)(Theme_1.Theme, { children: (0, jsx_runtime_1.jsx)(Pill_1.Pill, { onPress: onPress, children: "wow" }) }));
|
|
11
|
+
react_native_1.fireEvent.press(getByText("wow"));
|
|
12
|
+
expect(onPress).toHaveBeenCalled();
|
|
13
|
+
});
|
|
14
|
+
it("should not be pressable if disabled is passed", () => {
|
|
15
|
+
const onPress = jest.fn();
|
|
16
|
+
const { getByText } = (0, react_native_1.render)((0, jsx_runtime_1.jsx)(Theme_1.Theme, { children: (0, jsx_runtime_1.jsx)(Pill_1.Pill, { disabled: true, onPress: onPress, children: "Press me" }) }));
|
|
17
|
+
react_native_1.fireEvent.press(getByText("Press me"));
|
|
18
|
+
expect(onPress).not.toHaveBeenCalled();
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Pill";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./Pill"), exports);
|