@artsy/palette-mobile 6.1.0 → 7.0.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/Theme.d.ts CHANGED
@@ -27,7 +27,7 @@ export declare const _test_THEMES: {
27
27
  "6": number;
28
28
  "12": number;
29
29
  };
30
- colors: Record<"black100" | "black60" | "black30" | "black15" | "black10" | "black5" | "white100" | "blue150" | "blue100" | "brand" | "blue10" | "green150" | "green100" | "green10" | "yellow150" | "yellow100" | "yellow10" | "orange150" | "orange100" | "orange10" | "red150" | "red100" | "red10" | "devpurple", string>;
30
+ colors: Record<"black100" | "black60" | "black30" | "black15" | "black10" | "black5" | "white100" | "blue150" | "blue100" | "blue10" | "green150" | "green100" | "green10" | "yellow150" | "yellow100" | "yellow10" | "orange150" | "orange100" | "orange10" | "red150" | "red100" | "red10" | "devpurple", string>;
31
31
  fonts: {
32
32
  sans: {
33
33
  regular: string;
@@ -1,11 +1,13 @@
1
1
  /// <reference types="react" />
2
2
  import { PressableProps } from "react-native";
3
3
  import { HapticFeedbackTypes } from "react-native-haptic-feedback";
4
- import { BoxProps } from "../../atoms";
4
+ import { BoxProps } from "../..";
5
+ type ButtonSize = "small" | "large";
6
+ type ButtonVariant = "fillDark" | "fillLight" | "fillGray" | "fillSuccess" | "outline" | "outlineGray" | "outlineLight" | "text";
5
7
  export interface ButtonProps extends BoxProps {
6
8
  children: React.ReactNode;
7
- size?: "small" | "large";
8
- variant?: "fillDark" | "fillLight" | "fillGray" | "fillSuccess" | "outline" | "outlineGray" | "outlineLight" | "text";
9
+ size?: ButtonSize;
10
+ variant?: ButtonVariant;
9
11
  onPress?: PressableProps["onPress"];
10
12
  icon?: React.ReactNode;
11
13
  iconPosition?: "left" | "left-start" | "right";
@@ -26,13 +28,7 @@ export interface ButtonProps extends BoxProps {
26
28
  /** Pass the longest text to the button for the button to keep longest text width */
27
29
  longestText?: string;
28
30
  /** Used only for tests and stories */
29
- testOnly_state?: DisplayState;
31
+ testOnly_pressed?: PressableProps["testOnly_pressed"];
30
32
  }
31
- declare enum DisplayState {
32
- Enabled = "enabled",
33
- Disabled = "disabled",
34
- Loading = "loading",
35
- Pressed = "pressed"
36
- }
37
- export declare const Button: ({ children, disabled, haptic, icon, iconPosition, loading, longestText, onPress, size, style, variant, testOnly_state, testID, ...restProps }: ButtonProps) => JSX.Element;
38
- export { DisplayState as _test_DisplayState };
33
+ export declare const Button: ({ children, disabled: disabledProp, haptic, icon, iconPosition, loading: loadingProp, block, longestText, onPress, size, style, variant, testOnly_pressed, testID, ...restProps }: ButtonProps) => JSX.Element;
34
+ export {};
@@ -1,302 +1,122 @@
1
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
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
5
28
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports._test_DisplayState = exports.Button = void 0;
29
+ exports.Button = void 0;
7
30
  const jsx_runtime_1 = require("react/jsx-runtime");
8
31
  const react_1 = require("react");
9
32
  const react_native_1 = require("react-native");
10
33
  const react_native_haptic_feedback_1 = __importDefault(require("react-native-haptic-feedback"));
11
- const react_spring_1 = require("react-spring");
12
- // @ts-ignore
13
- const renderprops_native_1 = require("react-spring/renderprops-native");
14
- const native_1 = __importDefault(require("styled-components/native"));
34
+ const react_native_reanimated_1 = __importStar(require("react-native-reanimated"));
35
+ const __1 = require("../..");
36
+ const MeasuredView_1 = require("../../utils/MeasuredView");
15
37
  const Spinner_1 = require("../Spinner");
16
38
  const Text_1 = require("../Text");
17
- const atoms_1 = require("../../atoms");
18
- const MeasuredView_1 = require("../../utils/MeasuredView");
19
- const hooks_1 = require("../../hooks");
20
- var DisplayState;
21
- (function (DisplayState) {
22
- DisplayState["Enabled"] = "enabled";
23
- DisplayState["Disabled"] = "disabled";
24
- DisplayState["Loading"] = "loading";
25
- DisplayState["Pressed"] = "pressed";
26
- })(DisplayState || (DisplayState = {}));
27
- exports._test_DisplayState = DisplayState;
28
- const Button = ({ children, disabled, haptic, icon, iconPosition = "left", loading, longestText, onPress, size = "large", style, variant = "fillDark", testOnly_state, testID, ...restProps }) => {
39
+ const colors_1 = require("./colors");
40
+ const Button = ({ children, disabled: disabledProp, haptic, icon, iconPosition = "left", loading: loadingProp, block, longestText, onPress, size = "large", style, variant = "fillDark", testOnly_pressed, testID, ...restProps }) => {
41
+ // these are basically booleans
42
+ const disabled = (0, react_native_reanimated_1.useSharedValue)(!!disabledProp ? 1 : 0);
43
+ const loading = (0, react_native_reanimated_1.useSharedValue)(!!loadingProp ? 1 : 0);
44
+ const pressed = (0, react_native_reanimated_1.useSharedValue)(!!testOnly_pressed ? 1 : 0);
45
+ const color = (0, __1.useColor)();
29
46
  const textStyle = (0, Text_1.useTextStyleForPalette)(size === "small" ? "xs" : "sm");
30
- const [innerDisplayState, setInnerDisplayState] = (0, react_1.useState)(DisplayState.Enabled);
31
47
  const [longestTextMeasurements, setLongestTextMeasurements] = (0, react_1.useState)({
32
48
  width: 0,
33
49
  height: 0,
34
50
  });
35
- const displayState = testOnly_state ?? // if we use the test prop, use that
36
- (loading // if we have loading or disabled in props, they are used
37
- ? DisplayState.Loading
38
- : disabled
39
- ? DisplayState.Disabled
40
- : innerDisplayState); // otherwise use the inner state for pressed or enabled
41
- const getSize = () => {
51
+ const height = (() => {
42
52
  switch (size) {
43
53
  case "small":
44
- return { height: 30, mx: 15 };
54
+ return 30;
45
55
  case "large":
46
- return { height: 50, mx: 30 };
56
+ return 50;
47
57
  }
48
- };
58
+ })();
49
59
  const spinnerColor = variant === "text" ? "blue100" : "white100";
50
60
  const handlePress = (event) => {
51
61
  if (onPress === undefined || onPress === null) {
52
62
  return;
53
63
  }
54
- if (displayState === DisplayState.Loading || displayState === DisplayState.Disabled) {
64
+ if (disabled.value === 1 || loading.value === 1) {
55
65
  return;
56
66
  }
57
- // Did someone tap really fast? Flick the highlighted state
58
- if (displayState === DisplayState.Enabled) {
59
- setInnerDisplayState(DisplayState.Pressed);
60
- setTimeout(() => {
61
- setInnerDisplayState(DisplayState.Enabled);
62
- }, 0.3);
63
- }
64
- else {
65
- // Was already selected
66
- setInnerDisplayState(DisplayState.Enabled);
67
- }
68
67
  if (haptic !== undefined) {
69
68
  react_native_haptic_feedback_1.default.trigger(haptic === true ? "impactLight" : haptic);
70
69
  }
71
70
  onPress(event);
72
71
  };
73
- const containerSize = getSize();
74
- const to = useStyleForVariantAndState(variant, testOnly_state ?? displayState);
75
- return ((0, jsx_runtime_1.jsx)(renderprops_native_1.Spring, { native: true, to: to, config: react_spring_1.config.stiff, children: (springProps) => ((0, jsx_runtime_1.jsx)(react_native_1.Pressable, { testOnly_pressed: testOnly_state === DisplayState.Pressed, disabled: testOnly_state === DisplayState.Disabled || disabled, onPressIn: () => {
76
- if (displayState === DisplayState.Loading) {
77
- return;
78
- }
79
- setInnerDisplayState(DisplayState.Pressed);
80
- }, onPressOut: () => {
81
- if (displayState === DisplayState.Loading) {
82
- return;
83
- }
84
- setInnerDisplayState(DisplayState.Enabled);
85
- }, onPress: handlePress, testID: testID, children: (0, jsx_runtime_1.jsx)(atoms_1.Flex, { flexDirection: "row", children: (0, jsx_runtime_1.jsx)(AnimatedContainer, { ...restProps, style: {
86
- backgroundColor: springProps.backgroundColor,
87
- borderColor: springProps.borderColor,
88
- height: containerSize.height,
89
- }, children: (0, jsx_runtime_1.jsxs)(atoms_1.Flex, { mx: containerSize.mx, children: [(0, jsx_runtime_1.jsxs)(atoms_1.Flex, { height: "100%", flexDirection: "row", alignItems: "center", justifyContent: "center", children: [iconPosition === "left-start" && !!icon ? ((0, jsx_runtime_1.jsxs)(atoms_1.Box, { position: "absolute", left: 0, children: [icon, (0, jsx_runtime_1.jsx)(atoms_1.Spacer, { mr: 0.5 })] })) : null, iconPosition === "left" && !!icon ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [icon, (0, jsx_runtime_1.jsx)(atoms_1.Spacer, { mr: 0.5 })] })) : null, (0, jsx_runtime_1.jsx)(MeasuredView_1.MeasuredView, { setMeasuredState: setLongestTextMeasurements, children: (0, jsx_runtime_1.jsx)(Text_1.Text, { color: "red", style: textStyle, children: longestText ? longestText : children }) }), (0, jsx_runtime_1.jsx)(AnimatedText, { style: [
90
- {
91
- width: Math.ceil(longestTextMeasurements.width),
92
- color: springProps.textColor,
93
- textDecorationLine: springProps.textDecorationLine,
94
- },
95
- textStyle,
96
- ], textAlign: "center", children: children }), iconPosition === "right" && !!icon ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(atoms_1.Spacer, { mr: 0.5 }), icon] })) : null] }), displayState === DisplayState.Loading ? ((0, jsx_runtime_1.jsx)(SpinnerContainer, { children: (0, jsx_runtime_1.jsx)(Spinner_1.Spinner, { size: size, color: spinnerColor }) })) : null] }) }) }) })) }));
97
- };
98
- exports.Button = Button;
99
- const useStyleForVariantAndState = (variant, state) => {
100
- const color = (0, hooks_1.useColor)();
101
- const retval = {
102
- textDecorationLine: "none",
103
- };
104
- if (state === DisplayState.Loading) {
105
- retval.backgroundColor = variant === "text" ? color("black10") : color("blue100");
106
- retval.borderColor = "rgba(0, 0, 0, 0)";
107
- retval.borderWidth = 0;
108
- retval.textColor = "rgba(0, 0, 0, 0)";
109
- return retval;
110
- }
111
- switch (variant) {
112
- case "fillDark":
113
- retval.textColor = color("onPrimaryHigh");
114
- switch (state) {
115
- case DisplayState.Enabled:
116
- retval.backgroundColor = color("primary");
117
- retval.borderColor = color("primary");
118
- break;
119
- case DisplayState.Disabled:
120
- retval.backgroundColor = color("black30");
121
- retval.borderColor = color("black30");
122
- break;
123
- case DisplayState.Pressed:
124
- retval.backgroundColor = color("blue100");
125
- retval.borderColor = color("blue100");
126
- retval.textDecorationLine = "underline";
127
- break;
128
- default:
129
- assertNever(state);
130
- }
131
- break;
132
- case "fillLight":
133
- switch (state) {
134
- case DisplayState.Enabled:
135
- retval.backgroundColor = color("white100");
136
- retval.borderColor = color("white100");
137
- retval.textColor = color("black100");
138
- break;
139
- case DisplayState.Disabled:
140
- retval.backgroundColor = color("black30");
141
- retval.borderColor = color("black30");
142
- retval.textColor = color("white100");
143
- break;
144
- case DisplayState.Pressed:
145
- retval.backgroundColor = color("blue100");
146
- retval.borderColor = color("blue100");
147
- retval.textColor = color("white100");
148
- retval.textDecorationLine = "underline";
149
- break;
150
- default:
151
- assertNever(state);
152
- }
153
- break;
154
- case "fillGray":
155
- switch (state) {
156
- case DisplayState.Enabled:
157
- retval.backgroundColor = color("black10");
158
- retval.borderColor = color("black10");
159
- retval.textColor = color("black100");
160
- break;
161
- case DisplayState.Disabled:
162
- retval.backgroundColor = color("black30");
163
- retval.borderColor = color("black30");
164
- retval.textColor = color("white100");
165
- break;
166
- case DisplayState.Pressed:
167
- retval.backgroundColor = color("blue100");
168
- retval.borderColor = color("blue100");
169
- retval.textColor = color("white100");
170
- retval.textDecorationLine = "underline";
171
- break;
172
- default:
173
- assertNever(state);
174
- }
175
- break;
176
- case "fillSuccess":
177
- retval.textColor = color("white100");
178
- switch (state) {
179
- case DisplayState.Enabled:
180
- retval.backgroundColor = color("blue100");
181
- retval.borderColor = color("blue100");
182
- break;
183
- case DisplayState.Disabled:
184
- retval.backgroundColor = color("blue100");
185
- retval.borderColor = color("blue100");
186
- break;
187
- case DisplayState.Pressed:
188
- retval.backgroundColor = color("blue10");
189
- retval.borderColor = color("blue10");
190
- retval.textDecorationLine = "underline";
191
- break;
192
- default:
193
- assertNever(state);
194
- }
195
- break;
196
- case "outline":
197
- switch (state) {
198
- case DisplayState.Enabled:
199
- retval.backgroundColor = color("background");
200
- retval.borderColor = color("onBackgroundMedium");
201
- retval.textColor = color("onBackgroundHigh");
202
- break;
203
- case DisplayState.Disabled:
204
- retval.backgroundColor = color("background");
205
- retval.borderColor = color("onBackgroundLow");
206
- retval.textColor = color("onBackgroundLow");
207
- break;
208
- case DisplayState.Pressed:
209
- retval.backgroundColor = color("blue100");
210
- retval.borderColor = color("blue100");
211
- retval.textColor = color("white100");
212
- retval.textDecorationLine = "underline";
213
- break;
214
- default:
215
- assertNever(state);
72
+ const bgColor = (0, react_native_reanimated_1.useSharedValue)("black");
73
+ const borderColor = (0, react_native_reanimated_1.useSharedValue)("black");
74
+ const containerColorsAnim = (0, react_native_reanimated_1.useAnimatedStyle)(() => ({
75
+ backgroundColor: bgColor.value,
76
+ borderColor: borderColor.value,
77
+ }));
78
+ const textColor = (0, react_native_reanimated_1.useSharedValue)("black");
79
+ const underline = (0, react_native_reanimated_1.useSharedValue)(0);
80
+ const textAnim = (0, react_native_reanimated_1.useAnimatedStyle)(() => ({
81
+ color: textColor.value,
82
+ textDecorationLine: underline.value === 1 ? "underline" : "none",
83
+ }));
84
+ const colorsForVariantAndState = (0, colors_1.useColorsForVariantAndState)();
85
+ (0, react_native_reanimated_1.useAnimatedReaction)(() => [disabled.value, loading.value, pressed.value], ([disabledVal, loadingVal, pressedVal]) => {
86
+ const toColor = (c) => (0, react_native_reanimated_1.withTiming)(c, { duration: 150 });
87
+ const states = colorsForVariantAndState[variant];
88
+ const colors = disabledVal === 1
89
+ ? states.disabled
90
+ : loadingVal === 1
91
+ ? states.loading
92
+ : pressedVal === 1
93
+ ? states.pressed
94
+ : states.active;
95
+ const { bg, border, text } = colors;
96
+ bgColor.value = toColor(bg);
97
+ borderColor.value = toColor(border);
98
+ textColor.value = toColor(text);
99
+ underline.value = pressedVal;
100
+ }, [variant]);
101
+ return ((0, jsx_runtime_1.jsx)(react_native_1.Pressable, { disabled: disabled.value === 1, onPressIn: () => {
102
+ if (loading.value === 1) {
103
+ return;
216
104
  }
217
- break;
218
- case "outlineGray":
219
- switch (state) {
220
- case DisplayState.Enabled:
221
- retval.backgroundColor = color("white100");
222
- retval.borderColor = color("black30");
223
- retval.textColor = color("black100");
224
- break;
225
- case DisplayState.Disabled:
226
- retval.backgroundColor = color("white100");
227
- retval.borderColor = color("black30");
228
- retval.textColor = color("black30");
229
- break;
230
- case DisplayState.Pressed:
231
- retval.backgroundColor = color("blue100");
232
- retval.borderColor = color("blue100");
233
- retval.textColor = color("white100");
234
- retval.textDecorationLine = "underline";
235
- break;
236
- default:
237
- assertNever(state);
105
+ pressed.value = 1;
106
+ }, onPressOut: () => {
107
+ if (loading.value === 1) {
108
+ return;
238
109
  }
239
- break;
240
- case "outlineLight":
241
- switch (state) {
242
- case DisplayState.Enabled:
243
- retval.backgroundColor = "rgba(0, 0, 0, 0)";
244
- retval.borderColor = color("white100");
245
- retval.textColor = color("white100");
246
- break;
247
- case DisplayState.Disabled:
248
- retval.backgroundColor = "rgba(0, 0, 0, 0)";
249
- retval.borderColor = color("black30");
250
- retval.textColor = color("black30");
251
- break;
252
- case DisplayState.Pressed:
253
- retval.backgroundColor = color("blue100");
254
- retval.borderColor = color("blue100");
255
- retval.textColor = color("white100");
256
- retval.textDecorationLine = "underline";
257
- break;
258
- default:
259
- assertNever(state);
260
- }
261
- break;
262
- case "text":
263
- retval.backgroundColor = "rgba(0, 0, 0, 0)";
264
- retval.borderColor = "rgba(0, 0, 0, 0)";
265
- switch (state) {
266
- case DisplayState.Enabled:
267
- retval.textColor = color("black100");
268
- break;
269
- case DisplayState.Disabled:
270
- retval.textColor = color("black30");
271
- break;
272
- case DisplayState.Pressed:
273
- retval.backgroundColor = color("black10");
274
- retval.borderColor = color("black10");
275
- retval.textColor = color("blue100");
276
- retval.textDecorationLine = "underline";
277
- break;
278
- default:
279
- assertNever(state);
280
- }
281
- break;
282
- default:
283
- assertNever(variant);
284
- }
285
- return retval;
110
+ pressed.value = 0;
111
+ }, onPress: handlePress, testID: testID, testOnly_pressed: testOnly_pressed, children: (0, jsx_runtime_1.jsx)(react_native_reanimated_1.default.View, { style: [
112
+ {
113
+ height: height,
114
+ width: block ? "100%" : undefined,
115
+ borderWidth: 1,
116
+ borderRadius: 50,
117
+ },
118
+ containerColorsAnim,
119
+ ], children: (0, jsx_runtime_1.jsxs)(__1.Flex, { height: "100%", mx: 25, flexDirection: "row", alignItems: "center", justifyContent: "center", children: [iconPosition === "left-start" && !!icon ? ((0, jsx_runtime_1.jsxs)(__1.Box, { position: "absolute", left: 0, children: [icon, (0, jsx_runtime_1.jsx)(__1.Spacer, { x: "0.5" })] })) : null, iconPosition === "left" && !!icon ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [icon, (0, jsx_runtime_1.jsx)(__1.Spacer, { x: "0.5" })] })) : null, (0, jsx_runtime_1.jsx)(AText, { style: [{ width: Math.ceil(longestTextMeasurements.width) }, textStyle, textAnim], textAlign: "center", children: children }), !__TEST__ && ((0, jsx_runtime_1.jsx)(MeasuredView_1.MeasuredView, { setMeasuredState: setLongestTextMeasurements, children: (0, jsx_runtime_1.jsx)(Text_1.Text, { color: "red", style: textStyle, children: longestText ? longestText : children }) })), iconPosition === "right" && !!icon ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(__1.Spacer, { x: "0.5" }), icon] })) : null, loading.value === 1 ? ((0, jsx_runtime_1.jsx)(__1.Box, { position: "absolute", width: "100%", height: "100%", alignItems: "center", justifyContent: "center", children: (0, jsx_runtime_1.jsx)(Spinner_1.Spinner, { size: size, color: spinnerColor }) })) : null] }) }) }));
286
120
  };
287
- const Container = (0, native_1.default)(atoms_1.Box) `
288
- position: relative;
289
- border-width: 1;
290
- border-radius: 50;
291
- width: ${(p) => (p.block ? "100%" : "auto")};
292
- overflow: hidden;
293
- `;
294
- const SpinnerContainer = (0, native_1.default)(atoms_1.Box) `
295
- position: absolute;
296
- width: 100%;
297
- height: 100%;
298
- align-items: center;
299
- justify-content: center;
300
- `;
301
- const AnimatedContainer = (0, renderprops_native_1.animated)(Container);
302
- const AnimatedText = (0, renderprops_native_1.animated)(Text_1.Text);
121
+ exports.Button = Button;
122
+ const AText = react_native_reanimated_1.default.createAnimatedComponent(Text_1.Text);
@@ -0,0 +1,17 @@
1
+ /// <reference types="react" />
2
+ import { ButtonProps } from ".";
3
+ declare const _default: {
4
+ title: string;
5
+ component: ({ children, disabled: disabledProp, haptic, icon, iconPosition, loading: loadingProp, block, longestText, onPress, size, style, variant, testOnly_pressed, testID, ...restProps }: ButtonProps) => JSX.Element;
6
+ };
7
+ export default _default;
8
+ export declare const Sizes: () => JSX.Element;
9
+ export declare const States: () => JSX.Element;
10
+ export declare const Variants: () => JSX.Element;
11
+ export declare const VariantsLoading: () => JSX.Element;
12
+ export declare const VariantsDisabled: () => JSX.Element;
13
+ export declare const TheFollowButton: () => JSX.Element;
14
+ export declare const TheCTAButton: () => JSX.Element;
15
+ export declare const TheLinkButton: () => JSX.Element;
16
+ export declare const Miscellaneous: () => JSX.Element;
17
+ export declare const Playground: () => JSX.Element;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Playground = exports.Miscellaneous = exports.TheLinkButton = exports.TheCTAButton = exports.TheFollowButton = exports.VariantsDisabled = exports.VariantsLoading = exports.Variants = exports.States = exports.Sizes = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_native_1 = require("react-native");
6
+ const react_1 = require("react");
7
+ const _1 = require(".");
8
+ const atoms_1 = require("../../atoms");
9
+ const storybookHelpers_1 = require("../../storybookHelpers");
10
+ const svgs_1 = require("../../svgs");
11
+ const Wrap_1 = require("../../utils/Wrap");
12
+ const lodash_1 = require("lodash");
13
+ const __1 = require("..");
14
+ const sizes = ["small", "large"];
15
+ const variants = [
16
+ "fillDark",
17
+ "fillLight",
18
+ "fillGray",
19
+ "fillSuccess",
20
+ "outline",
21
+ "outlineGray",
22
+ "outlineLight",
23
+ "text",
24
+ ];
25
+ exports.default = {
26
+ title: "Button",
27
+ component: _1.Button,
28
+ };
29
+ const Sizes = () => ((0, jsx_runtime_1.jsx)(storybookHelpers_1.DataList, { data: sizes, renderItem: ({ item: size }) => ((0, jsx_runtime_1.jsx)(_1.Button, { size: size, onPress: () => console.log(`tapped ${size}`), children: (0, lodash_1.capitalize)(size) })) }));
30
+ exports.Sizes = Sizes;
31
+ const States = () => {
32
+ const [variant, setVariant] = (0, react_1.useState)("fillDark");
33
+ return ((0, jsx_runtime_1.jsxs)(storybookHelpers_1.List, { children: [(0, jsx_runtime_1.jsx)(atoms_1.Flex, { flexDirection: "row", flexWrap: "wrap", px: "2", children: variants.map((variant) => ((0, jsx_runtime_1.jsx)(__1.LinkText, { color: "orange", onPress: () => setVariant(variant), mr: "2", children: variant }))) }), (0, jsx_runtime_1.jsx)(_1.Button, { variant: variant, onPress: () => console.log(`tapped`), longestText: "Regular YEA", children: "Regular" }), (0, jsx_runtime_1.jsx)(_1.Button, { variant: variant, onPress: () => console.log(`tapped`), disabled: true, children: "Disabled" }), (0, jsx_runtime_1.jsx)(_1.Button, { variant: variant, onPress: () => console.log(`tapped`), loading: true, children: "Loading" }), (0, jsx_runtime_1.jsx)(_1.Button, { variant: variant, onPress: () => console.log(`tapped`), testOnly_pressed: true, children: "Pressed" })] }));
34
+ };
35
+ exports.States = States;
36
+ const Variants = () => ((0, jsx_runtime_1.jsx)(storybookHelpers_1.DataList, { data: variants, renderItem: ({ item: variant }) => ((0, jsx_runtime_1.jsx)(Wrap_1.Wrap, { if: variant === "outlineLight" || variant === "fillLight", children: (0, jsx_runtime_1.jsx)(atoms_1.Flex, { backgroundColor: "pink", p: 10, children: (0, jsx_runtime_1.jsx)(Wrap_1.Wrap.Content, { children: (0, jsx_runtime_1.jsx)(_1.Button, { variant: variant, onPress: () => console.log(`tapped ${variant}`), children: variant }) }) }) })) }));
37
+ exports.Variants = Variants;
38
+ const VariantsLoading = () => ((0, jsx_runtime_1.jsx)(storybookHelpers_1.DataList, { data: variants, renderItem: ({ item: variant }) => ((0, jsx_runtime_1.jsx)(_1.Button, { variant: variant, loading: true, onPress: () => console.log(`tapped ${variant}`), children: variant })) }));
39
+ exports.VariantsLoading = VariantsLoading;
40
+ const VariantsDisabled = () => ((0, jsx_runtime_1.jsx)(storybookHelpers_1.DataList, { data: variants, renderItem: ({ item: variant }) => ((0, jsx_runtime_1.jsx)(Wrap_1.Wrap, { if: variant === "outlineLight", children: (0, jsx_runtime_1.jsx)(atoms_1.Flex, { backgroundColor: "black100", p: 10, children: (0, jsx_runtime_1.jsx)(Wrap_1.Wrap.Content, { children: (0, jsx_runtime_1.jsx)(_1.Button, { variant: variant, disabled: true, onPress: () => console.log(`tapped ${variant}`), children: variant }) }) }) })) }));
41
+ exports.VariantsDisabled = VariantsDisabled;
42
+ const TheFollowButton = () => {
43
+ const [follow, setFollow] = (0, react_1.useState)(true);
44
+ return ((0, jsx_runtime_1.jsx)(storybookHelpers_1.List, { children: (0, jsx_runtime_1.jsx)(_1.FollowButton, { isFollowed: follow, onPress: () => setFollow((v) => !v) }) }));
45
+ };
46
+ exports.TheFollowButton = TheFollowButton;
47
+ const TheCTAButton = () => ((0, jsx_runtime_1.jsx)(storybookHelpers_1.List, { children: (0, jsx_runtime_1.jsx)(_1.CTAButton, { onPress: () => console.log("pressed"), children: "cta button" }) }));
48
+ exports.TheCTAButton = TheCTAButton;
49
+ const TheLinkButton = () => ((0, jsx_runtime_1.jsx)(storybookHelpers_1.List, { children: (0, jsx_runtime_1.jsx)(_1.LinkButton, { onPress: () => console.log("pressed"), children: "LinkButton" }) }));
50
+ exports.TheLinkButton = TheLinkButton;
51
+ const Miscellaneous = () => ((0, jsx_runtime_1.jsxs)(storybookHelpers_1.List, { children: [(0, jsx_runtime_1.jsx)(_1.Button, { loading: true, disabled: true, children: "loading and disabled" }), (0, jsx_runtime_1.jsx)(_1.Button, { block: true, children: "block" }), (0, jsx_runtime_1.jsx)(atoms_1.Flex, { backgroundColor: "orange", width: 400, height: 80, alignItems: "center", justifyContent: "center", children: (0, jsx_runtime_1.jsx)(_1.Button, { variant: "fillLight", icon: (0, jsx_runtime_1.jsx)(svgs_1.LinkIcon, {}), children: "left icon" }) }), (0, jsx_runtime_1.jsx)(_1.Button, { icon: (0, jsx_runtime_1.jsx)(svgs_1.LinkIcon, { fill: "white100" }), iconPosition: "right", children: "right icon" }), (0, jsx_runtime_1.jsx)(_1.Button, { size: "small", icon: (0, jsx_runtime_1.jsx)(svgs_1.LinkIcon, { fill: "white100" }), iconPosition: "right", children: "Right Icon Small" }), (0, jsx_runtime_1.jsx)(_1.Button, { variant: "fillDark", size: "small", icon: (0, jsx_runtime_1.jsx)(svgs_1.BellIcon, { fill: "white100", width: "16px", height: "16px" }), children: "Create Alert" }), (0, jsx_runtime_1.jsxs)(atoms_1.Box, { flexDirection: "row", children: [(0, jsx_runtime_1.jsx)(atoms_1.Box, { width: 2, height: "100%", backgroundColor: "green100" }), (0, jsx_runtime_1.jsxs)(atoms_1.Box, { children: [(0, jsx_runtime_1.jsx)(_1.Button, { size: "small", icon: (0, jsx_runtime_1.jsx)(svgs_1.LinkIcon, { fill: "white100" }), iconPosition: "right", longestText: "this is a very long text", children: "shortest text" }), (0, jsx_runtime_1.jsx)(atoms_1.Spacer, { y: "1" }), (0, jsx_runtime_1.jsx)(_1.Button, { size: "small", icon: (0, jsx_runtime_1.jsx)(svgs_1.LinkIcon, { fill: "white100" }), iconPosition: "right", longestText: "this is a very long text", children: "this is a very long text" })] }), (0, jsx_runtime_1.jsx)(atoms_1.Box, { width: 2, height: "100%", backgroundColor: "green100" })] }), (0, jsx_runtime_1.jsx)(_1.Button, { icon: (0, jsx_runtime_1.jsx)(svgs_1.LinkIcon, { fill: "white100" }), block: true, iconPosition: "left-start", children: "left-start aligned icon" })] }));
52
+ exports.Miscellaneous = Miscellaneous;
53
+ const Playground = () => {
54
+ const [loading, setLoading] = (0, react_1.useState)(false);
55
+ const [disabled, setDisabled] = (0, react_1.useState)(true);
56
+ const [block, setBlock] = (0, react_1.useState)(false);
57
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_native_1.Button, { title: "loading", onPress: () => setLoading((v) => !v) }), (0, jsx_runtime_1.jsx)(react_native_1.Button, { title: "disabled", onPress: () => setDisabled((v) => !v) }), (0, jsx_runtime_1.jsx)(react_native_1.Button, { title: "block", onPress: () => setBlock((v) => !v) }), (0, jsx_runtime_1.jsx)(storybookHelpers_1.List, { children: (0, jsx_runtime_1.jsxs)(_1.Button, { loading: loading, disabled: disabled, block: block, children: ["loading ", loading ? "true" : "false", ", disabled ", disabled ? "true" : "false", ", block", " ", block ? "true" : "false"] }) })] }));
58
+ };
59
+ exports.Playground = Playground;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,31 @@
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 _1 = require(".");
6
+ const __1 = require("..");
7
+ const renderWithWrappers_1 = require("../../utils/tests/renderWithWrappers");
8
+ describe("Button", () => {
9
+ it("shows spinner if loading is true", () => {
10
+ const { UNSAFE_queryAllByType } = (0, renderWithWrappers_1.renderWithWrappers)((0, jsx_runtime_1.jsx)(_1.Button, { loading: true, children: "wow" }));
11
+ expect(UNSAFE_queryAllByType(__1.Spinner)).toHaveLength(1);
12
+ });
13
+ it("invokes the onClick callback", () => {
14
+ const onPress = jest.fn();
15
+ const { getByTestId } = (0, renderWithWrappers_1.renderWithWrappers)((0, jsx_runtime_1.jsx)(_1.Button, { testID: "the-button", onPress: onPress, children: "wow" }));
16
+ react_native_1.fireEvent.press(getByTestId("the-button"));
17
+ expect(onPress).toHaveBeenCalled();
18
+ });
19
+ it("does not invoke the onClick callback if loading is true", () => {
20
+ const onPress = jest.fn();
21
+ const { getByTestId } = (0, renderWithWrappers_1.renderWithWrappers)((0, jsx_runtime_1.jsx)(_1.Button, { testID: "the-button", onPress: onPress, loading: true, children: "wow" }));
22
+ react_native_1.fireEvent.press(getByTestId("the-button"));
23
+ expect(onPress).not.toHaveBeenCalled();
24
+ });
25
+ it("does not invoke the onClick callback if disabled is true", () => {
26
+ const onPress = jest.fn();
27
+ const { getByTestId } = (0, renderWithWrappers_1.renderWithWrappers)((0, jsx_runtime_1.jsx)(_1.Button, { testID: "the-button", onPress: onPress, disabled: true, children: "wow" }));
28
+ react_native_1.fireEvent.press(getByTestId("the-button"));
29
+ expect(onPress).not.toHaveBeenCalled();
30
+ });
31
+ });
@@ -0,0 +1,9 @@
1
+ import { ButtonProps } from "../..";
2
+ import { NoUndefined } from "../../utils/types";
3
+ type State = "disabled" | "loading" | "pressed" | "active";
4
+ export declare const useColorsForVariantAndState: () => Record<NoUndefined<ButtonProps["variant"]>, Record<State, {
5
+ bg: string;
6
+ border: string;
7
+ text: string;
8
+ }>>;
9
+ export {};
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useColorsForVariantAndState = void 0;
4
+ const __1 = require("../..");
5
+ const useColorsForVariantAndState = () => {
6
+ const color = (0, __1.useColor)();
7
+ return {
8
+ fillDark: {
9
+ disabled: { bg: color("black30"), border: color("black30"), text: color("onPrimaryHigh") },
10
+ loading: { bg: color("blue100"), border: color("blue100"), text: "transparent" },
11
+ pressed: { bg: color("blue100"), border: color("blue100"), text: color("onPrimaryHigh") },
12
+ active: { bg: color("primary"), border: color("primary"), text: color("onPrimaryHigh") },
13
+ },
14
+ fillLight: {
15
+ disabled: { bg: color("black30"), border: color("black30"), text: color("onPrimaryHigh") },
16
+ loading: { bg: color("blue100"), border: color("blue100"), text: "transparent" },
17
+ pressed: { bg: color("blue100"), border: color("blue100"), text: color("onPrimaryHigh") },
18
+ active: {
19
+ bg: color("white100"),
20
+ border: color("white100"),
21
+ text: color("black100"),
22
+ },
23
+ },
24
+ fillGray: {
25
+ disabled: { bg: color("black30"), border: color("black30"), text: color("white100") },
26
+ loading: { bg: color("blue100"), border: color("blue100"), text: "transparent" },
27
+ pressed: { bg: color("blue100"), border: color("blue100"), text: color("white100") },
28
+ active: { bg: color("black10"), border: color("black10"), text: color("black100") },
29
+ },
30
+ fillSuccess: {
31
+ disabled: { bg: color("blue100"), border: color("blue100"), text: color("white100") },
32
+ loading: { bg: color("blue100"), border: color("blue100"), text: "transparent" },
33
+ pressed: { bg: color("blue100"), border: color("blue100"), text: color("white100") },
34
+ active: { bg: color("blue10"), border: color("blue10"), text: color("white100") },
35
+ },
36
+ outline: {
37
+ disabled: {
38
+ bg: color("background"),
39
+ border: color("onBackgroundLow"),
40
+ text: color("onBackgroundLow"),
41
+ },
42
+ loading: { bg: color("blue100"), border: color("blue100"), text: "transparent" },
43
+ pressed: { bg: color("blue100"), border: color("blue100"), text: color("white100") },
44
+ active: {
45
+ bg: color("background"),
46
+ border: color("onBackgroundMedium"),
47
+ text: color("onBackgroundHigh"),
48
+ },
49
+ },
50
+ outlineGray: {
51
+ disabled: {
52
+ bg: color("white100"),
53
+ border: color("black30"),
54
+ text: color("black30"),
55
+ },
56
+ loading: { bg: color("blue100"), border: color("blue100"), text: "transparent" },
57
+ pressed: { bg: color("blue100"), border: color("blue100"), text: color("white100") },
58
+ active: {
59
+ bg: color("white100"),
60
+ border: color("black30"),
61
+ text: color("black100"),
62
+ },
63
+ },
64
+ outlineLight: {
65
+ disabled: {
66
+ bg: "rgba(0, 0, 0, 0)",
67
+ border: color("black30"),
68
+ text: color("black30"),
69
+ },
70
+ loading: { bg: color("blue100"), border: color("blue100"), text: "transparent" },
71
+ pressed: { bg: color("blue100"), border: color("blue100"), text: color("white100") },
72
+ active: {
73
+ bg: "rgba(0, 0, 0, 0)",
74
+ border: color("white100"),
75
+ text: color("white100"),
76
+ },
77
+ },
78
+ text: {
79
+ disabled: { bg: "rgba(0, 0, 0, 0)", border: "rgba(0, 0, 0, 0)", text: color("black30") },
80
+ loading: { bg: color("black10"), border: color("black10"), text: "transparent" },
81
+ pressed: { bg: color("black10"), border: color("black10"), text: color("blue100") },
82
+ active: { bg: "rgba(0, 0, 0, 0)", border: "rgba(0, 0, 0, 0)", text: color("black100") },
83
+ },
84
+ };
85
+ };
86
+ exports.useColorsForVariantAndState = useColorsForVariantAndState;
@@ -1,4 +1,4 @@
1
1
  export * from "./Button";
2
- export * from "./FollowButton";
3
2
  export * from "./CTAButton";
3
+ export * from "./FollowButton";
4
4
  export * from "./LinkButton";
@@ -15,6 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./Button"), exports);
18
- __exportStar(require("./FollowButton"), exports);
19
18
  __exportStar(require("./CTAButton"), exports);
19
+ __exportStar(require("./FollowButton"), exports);
20
20
  __exportStar(require("./LinkButton"), exports);
@@ -1,34 +1,5 @@
1
- import { Component } from "react";
2
- import { View } from "react-native";
3
- export interface CollapseProps {
4
- /** Determines whether content is expanded or collapsed */
1
+ import { ReactNode } from "react";
2
+ export declare const Collapse: ({ opened, children }: {
5
3
  opened: boolean;
6
- /**
7
- * If we're rendering within a statically-sized component (e.g. FlatList), we need
8
- * to propagate a sentinel value in order to trigger re-render or re-measure.
9
- */
10
- onAnimationFrame?: (animateValue: {
11
- height: number;
12
- }) => void;
13
- }
14
- interface State {
15
- isMounted: boolean;
16
- hasMeasured: boolean;
17
- isMeasuring: boolean;
18
- isAnimating: boolean;
19
- measuredHeight?: number;
20
- }
21
- /** Collapses content with animation when open is not true */
22
- export declare class Collapse extends Component<CollapseProps, State> {
23
- measureRef: View | null;
24
- state: State;
25
- componentDidMount(): void;
26
- handleMeasureRef: (ref: View) => void;
27
- measureChildren: () => void;
28
- handleLayout: (ev: any) => void;
29
- handleFrame: (animatedValue: any) => void;
30
- componentWillReceiveProps(nextProps: CollapseProps): void;
31
- measureView: () => JSX.Element;
32
- render(): JSX.Element;
33
- }
34
- export {};
4
+ children: ReactNode;
5
+ }) => JSX.Element | null;
@@ -2,89 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Collapse = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
- const react_1 = require("react");
6
5
  const react_native_1 = require("react-native");
7
- // @ts-ignore
8
- const renderprops_native_1 = require("react-spring/renderprops-native");
9
- const AnimatedView = (0, renderprops_native_1.animated)(react_native_1.View);
10
- /** Collapses content with animation when open is not true */
11
- class Collapse extends react_1.Component {
12
- measureRef = null;
13
- state = {
14
- isMounted: false,
15
- isMeasuring: false,
16
- isAnimating: false,
17
- hasMeasured: false,
18
- };
19
- componentDidMount() {
20
- this.setState({ isMounted: true });
21
- }
22
- handleMeasureRef = (ref) => {
23
- this.measureRef = ref;
24
- };
25
- measureChildren = () => {
26
- this.setState({ isMeasuring: true }, () => {
27
- requestAnimationFrame(() => {
28
- if (!this.measureRef) {
29
- this.setState({
30
- isMeasuring: false,
31
- });
32
- return;
33
- }
34
- // @ts-ignore
35
- this.measureRef.measure((x, y, width, height) => {
36
- this.setState({
37
- isMeasuring: false,
38
- hasMeasured: true,
39
- measuredHeight: height,
40
- });
41
- });
42
- });
43
- });
44
- };
45
- handleLayout = (ev) => {
46
- const { opened } = this.props;
47
- const { hasMeasured, isMeasuring, measuredHeight, isAnimating } = this.state;
48
- const height = ev.nativeEvent.layout.height;
49
- if (!hasMeasured || !opened || isMeasuring || measuredHeight === height || isAnimating) {
50
- return;
51
- }
52
- this.setState({
53
- measuredHeight: height,
54
- });
55
- };
56
- handleFrame = (animatedValue) => {
57
- if (this.props.onAnimationFrame) {
58
- this.props.onAnimationFrame(animatedValue);
59
- }
60
- };
61
- componentWillReceiveProps(nextProps) {
62
- const willExpand = nextProps.opened && !this.props.opened;
63
- if (nextProps.opened !== this.props.opened) {
64
- this.setState({ isAnimating: true }, () => {
65
- if (willExpand && !this.measureRef && this.state.hasMeasured) {
66
- // We've previously measured children and can animate without further work.
67
- return;
68
- }
69
- else if (!this.state.hasMeasured) {
70
- // Children are ready to measure, measureRef might be mounted already.
71
- this.measureChildren();
72
- }
73
- });
74
- }
75
- }
76
- measureView = () => ((0, jsx_runtime_1.jsx)(react_native_1.View, { ref: this.handleMeasureRef, style: { opacity: 0, position: "absolute" }, children: this.props.children }));
77
- render() {
78
- const { isMeasuring, isMounted, measuredHeight } = this.state;
79
- // @ts-expect-error
80
- const { opened, children } = this.props;
81
- // We must render children once in order to measure and derive a static height for animation.
82
- if (isMeasuring) {
83
- return this.measureView();
84
- }
85
- return ((0, jsx_runtime_1.jsx)(renderprops_native_1.Spring, { native: true, immediate: !isMounted, from: { height: 0 }, to: { height: opened && measuredHeight ? measuredHeight : 0 }, onRest: () => {
86
- this.setState({ isAnimating: false });
87
- }, onFrame: this.handleFrame, children: (props) => ((0, jsx_runtime_1.jsx)(AnimatedView, { style: { ...props, overflow: "hidden" }, onLayout: this.handleLayout, children: children })) }));
88
- }
89
- }
6
+ const Collapse = ({ opened, children }) => opened ? (0, jsx_runtime_1.jsx)(react_native_1.View, { children: children }) : null;
90
7
  exports.Collapse = Collapse;
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ declare const _default: {
3
+ title: string;
4
+ component: ({ opened, children }: {
5
+ opened: boolean;
6
+ children: import("react").ReactNode;
7
+ }) => JSX.Element | null;
8
+ };
9
+ export default _default;
10
+ export declare const Something: () => JSX.Element;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Something = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const _1 = require(".");
7
+ const Text_1 = require("../Text");
8
+ exports.default = {
9
+ title: "Collapse",
10
+ component: _1.Collapse,
11
+ };
12
+ const Something = () => {
13
+ const [opened, setOpened] = (0, react_1.useState)(true);
14
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Text_1.LinkText, { onPress: () => setOpened((v) => !v), children: "toggle" }), (0, jsx_runtime_1.jsx)(_1.Collapse, { opened: opened, children: (0, jsx_runtime_1.jsx)(Text_1.Text, { children: "inside" }) })] }));
15
+ };
16
+ exports.Something = Something;
@@ -20,8 +20,21 @@ exports.Text = (0, react_1.forwardRef)(({ variant = "sm", italic = false, color
20
20
  { textAlignVertical: "center" },
21
21
  { textDecorationLine: !!underline ? "underline" : "none" },
22
22
  style, // keep last so we can override
23
- ], fontFamily: fontFamily, ...theme.textTreatments[variant], children: children, color: color, ...restProps }));
23
+ ], fontFamily: fontFamily, ...fixTextTreatmentForStyledComponent(theme.textTreatments[variant]), children: children, color: color, ...restProps }));
24
24
  });
25
+ const fixTextTreatmentForStyledComponent = (treatment) => {
26
+ const treatmentWithUnits = { ...treatment };
27
+ if (treatment.fontSize !== undefined) {
28
+ treatmentWithUnits.fontSize = `${treatment.fontSize}px`;
29
+ }
30
+ if (treatment.lineHeight !== undefined) {
31
+ treatmentWithUnits.lineHeight = `${treatment.lineHeight}px`;
32
+ }
33
+ if (treatment.letterSpacing !== undefined) {
34
+ treatmentWithUnits.letterSpacing = `${treatment.letterSpacing}em`;
35
+ }
36
+ return treatmentWithUnits;
37
+ };
25
38
  const InnerStyledText = (0, native_1.default)(react_native_1.Text) `
26
39
  ${styled_system_1.color}
27
40
  ${styled_system_1.space}
package/dist/hooks.js CHANGED
@@ -6,4 +6,3 @@ const useColor = () => (0, Theme_1.useTheme)().color;
6
6
  exports.useColor = useColor;
7
7
  const useSpace = () => (0, Theme_1.useTheme)().space;
8
8
  exports.useSpace = useSpace;
9
- // ignore this comment
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ // @ts-expect-error
7
+ global.__TEST__ = true;
8
+ // @ts-expect-error
9
+ const mock_1 = __importDefault(require("react-native-safe-area-context/jest/mock"));
10
+ jest.mock("react-native-safe-area-context", () => mock_1.default);
11
+ jest.mock("react-native/Libraries/Animated/NativeAnimatedHelper");
12
+ require("react-native-reanimated/src/reanimated2/jestUtils").setUpTests();
13
+ // @ts-expect-error
14
+ global.__reanimatedWorkletInit = () => { };
15
+ jest.mock("react-native-reanimated", () => require("react-native-reanimated/mock"));
package/dist/tokens.d.ts CHANGED
@@ -4,7 +4,8 @@
4
4
  * https://www.notion.so/artsy/Master-Library-810612339f474d0997fe359af4285c56
5
5
  */
6
6
  import { SpacingUnit as SpacingUnitV3Numbers } from "@artsy/palette-tokens/dist/themes/v3";
7
- import { TextVariant as TextVariantV3 } from "@artsy/palette-tokens/dist/typography/v3";
7
+ import { TextTreatment as TextTreatmentWithUnits, TextVariant as TextVariantV3 } from "@artsy/palette-tokens/dist/typography/v3";
8
+ export type { TextTreatmentWithUnits };
8
9
  type SpacingUnitV3 = `${SpacingUnitV3Numbers}`;
9
10
  export type { SpacingUnitV3 };
10
11
  type SpacingUnitPixels = number & {};
@@ -12,14 +13,14 @@ type SpacingUnitStringPixels = `${number}px` & {};
12
13
  export type SpacingUnitStrict = SpacingUnitV3;
13
14
  export type SpacingUnit = SpacingUnitStrict | SpacingUnitPixels | SpacingUnitStringPixels;
14
15
  export type ColorCssString = string & {};
15
- export declare const NAMED_LAYER_NAMES: readonly ["black100", "black60", "black30", "black15", "black10", "black5", "white100", "blue150", "blue100", "brand", "blue10", "green150", "green100", "green10", "yellow150", "yellow100", "yellow10", "orange150", "orange100", "orange10", "red150", "red100", "red10", "devpurple"];
16
+ export declare const NAMED_LAYER_NAMES: readonly ["black100", "black60", "black30", "black15", "black10", "black5", "white100", "blue150", "blue100", "blue10", "green150", "green100", "green10", "yellow150", "yellow100", "yellow10", "orange150", "orange100", "orange10", "red150", "red100", "red10", "devpurple"];
16
17
  export type ColorNamedLayer = typeof NAMED_LAYER_NAMES[number];
17
- export declare const USAGE_LAYER_NAMES: readonly ["background", "surface", "primary", "secondary", "brand", "onBackground", "onBackgroundHigh", "onBackgroundMedium", "onBackgroundLow", "onSurface", "onSurfaceHigh", "onSurfaceMedium", "onSurfaceLow", "onPrimaryHigh", "onPrimaryMedium", "onPrimaryLow", "onSecondaryHigh", "onSecondaryMedium", "onSecondaryLow", "onBrand"];
18
+ export declare const USAGE_LAYER_NAMES: readonly ["background", "onBackground", "onBackgroundHigh", "onBackgroundMedium", "onBackgroundLow", "surface", "onSurface", "onSurfaceHigh", "onSurfaceMedium", "onSurfaceLow", "primary", "onPrimaryHigh", "onPrimaryMedium", "onPrimaryLow", "secondary", "onSecondaryHigh", "onSecondaryMedium", "onSecondaryLow", "brand", "onBrand"];
18
19
  export type ColorUsageLayer = typeof USAGE_LAYER_NAMES[number];
19
20
  export type ColorStrict = ColorNamedLayer | ColorUsageLayer;
20
21
  export type Color = ColorNamedLayer | ColorUsageLayer | ColorCssString;
21
- export declare const isUsageLayerName: (name: Color) => name is "brand" | "background" | "surface" | "primary" | "secondary" | "onBackground" | "onBackgroundHigh" | "onBackgroundMedium" | "onBackgroundLow" | "onSurface" | "onSurfaceHigh" | "onSurfaceMedium" | "onSurfaceLow" | "onPrimaryHigh" | "onPrimaryMedium" | "onPrimaryLow" | "onSecondaryHigh" | "onSecondaryMedium" | "onSecondaryLow" | "onBrand";
22
- export declare const isNamedLayerName: (name: Color) => name is "black100" | "black60" | "black30" | "black15" | "black10" | "black5" | "white100" | "blue150" | "blue100" | "brand" | "blue10" | "green150" | "green100" | "green10" | "yellow150" | "yellow100" | "yellow10" | "orange150" | "orange100" | "orange10" | "red150" | "red100" | "red10" | "devpurple";
22
+ export declare const isUsageLayerName: (name: Color) => name is "background" | "onBackground" | "onBackgroundHigh" | "onBackgroundMedium" | "onBackgroundLow" | "surface" | "onSurface" | "onSurfaceHigh" | "onSurfaceMedium" | "onSurfaceLow" | "primary" | "onPrimaryHigh" | "onPrimaryMedium" | "onPrimaryLow" | "secondary" | "onSecondaryHigh" | "onSecondaryMedium" | "onSecondaryLow" | "brand" | "onBrand";
23
+ export declare const isNamedLayerName: (name: Color) => name is "black100" | "black60" | "black30" | "black15" | "black10" | "black5" | "white100" | "blue150" | "blue100" | "blue10" | "green150" | "green100" | "green10" | "yellow150" | "yellow100" | "yellow10" | "orange150" | "orange100" | "orange10" | "red150" | "red100" | "red10" | "devpurple";
23
24
  export interface TextTreatment {
24
25
  fontSize: number;
25
26
  lineHeight: number;
@@ -41,7 +42,7 @@ export declare const THEMES: {
41
42
  "6": number;
42
43
  "12": number;
43
44
  };
44
- colors: Record<"black100" | "black60" | "black30" | "black15" | "black10" | "black5" | "white100" | "blue150" | "blue100" | "brand" | "blue10" | "green150" | "green100" | "green10" | "yellow150" | "yellow100" | "yellow10" | "orange150" | "orange100" | "orange10" | "red150" | "red100" | "red10" | "devpurple", string>;
45
+ colors: Record<"black100" | "black60" | "black30" | "black15" | "black10" | "black5" | "white100" | "blue150" | "blue100" | "blue10" | "green150" | "green100" | "green10" | "yellow150" | "yellow100" | "yellow10" | "orange150" | "orange100" | "orange10" | "red150" | "red100" | "red10" | "devpurple", string>;
45
46
  fonts: {
46
47
  sans: {
47
48
  regular: string;
package/dist/tokens.js CHANGED
@@ -32,7 +32,6 @@ exports.NAMED_LAYER_NAMES = [
32
32
  "white100",
33
33
  "blue150",
34
34
  "blue100",
35
- "brand",
36
35
  "blue10",
37
36
  "green150",
38
37
  "green100",
@@ -50,27 +49,28 @@ exports.NAMED_LAYER_NAMES = [
50
49
  "devpurple",
51
50
  ];
52
51
  exports.USAGE_LAYER_NAMES = [
53
- // Anything big/surface: background, cards, button fills, etc.
52
+ // name: Anything big/surface: background, cards, button fills, etc.
53
+ // onName: Anything small, texts, icons, etc.
54
+ // onNameContrast: Anything small, texts, icons, etc based on contrast.
54
55
  "background",
55
- "surface",
56
- "primary",
57
- "secondary",
58
- "brand",
59
- // Anything small, texts, icons, etc.
60
56
  "onBackground",
61
57
  "onBackgroundHigh",
62
58
  "onBackgroundMedium",
63
59
  "onBackgroundLow",
60
+ "surface",
64
61
  "onSurface",
65
62
  "onSurfaceHigh",
66
63
  "onSurfaceMedium",
67
64
  "onSurfaceLow",
65
+ "primary",
68
66
  "onPrimaryHigh",
69
67
  "onPrimaryMedium",
70
68
  "onPrimaryLow",
69
+ "secondary",
71
70
  "onSecondaryHigh",
72
71
  "onSecondaryMedium",
73
72
  "onSecondaryLow",
73
+ "brand",
74
74
  "onBrand",
75
75
  ];
76
76
  const isUsageLayerName = (name) => {
@@ -139,11 +139,11 @@ exports.THEMES = {
139
139
  onSurface: this.v3.colors.black100,
140
140
  onSurfaceHigh: this.v3.colors.black100,
141
141
  onSurfaceMedium: this.v3.colors.black60,
142
- onSurfaceLow: this.v3.colors.black10,
142
+ onSurfaceLow: this.v3.colors.black5,
143
143
  primary: this.v3.colors.black100,
144
144
  onPrimaryHigh: this.v3.colors.white100,
145
- onPrimaryMedium: this.v3.colors.black10,
146
- onPrimaryLow: this.v3.colors.black10,
145
+ onPrimaryMedium: this.v3.colors.black5,
146
+ onPrimaryLow: this.v3.colors.black5,
147
147
  secondary: this.v3.colors.black30,
148
148
  onSecondaryHigh: this.v3.colors.black100,
149
149
  onSecondaryMedium: this.v3.colors.black60,
@@ -178,8 +178,8 @@ exports.THEMES = {
178
178
  onPrimaryLow: this.v3.colors.black60,
179
179
  secondary: this.v3.colors.black60,
180
180
  onSecondaryHigh: this.v3.colors.white100,
181
- onSecondaryMedium: this.v3.colors.black10,
182
- onSecondaryLow: this.v3.colors.black10,
181
+ onSecondaryMedium: this.v3.colors.black5,
182
+ onSecondaryLow: this.v3.colors.black5,
183
183
  brand: this.v3.colors.blue100,
184
184
  onBrand: this.v3.colors.white100,
185
185
  },
@@ -0,0 +1,10 @@
1
+ import { ReactElement } from "react";
2
+ /**
3
+ * Renders a React Component with our page wrappers
4
+ * by using @testing-library/react-native
5
+ * @param component
6
+ */
7
+ export declare const renderWithWrappers: (component: ReactElement) => any;
8
+ export declare const Providers: ({ children }: {
9
+ children?: React.ReactNode;
10
+ }) => JSX.Element;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Providers = exports.renderWithWrappers = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_native_safe_area_context_1 = require("react-native-safe-area-context");
6
+ const react_native_1 = require("@testing-library/react-native");
7
+ const Theme_1 = require("../../Theme");
8
+ /**
9
+ * Renders a React Component with our page wrappers
10
+ * by using @testing-library/react-native
11
+ * @param component
12
+ */
13
+ const renderWithWrappers = (component) => {
14
+ try {
15
+ return (0, react_native_1.render)(component, { wrapper: exports.Providers });
16
+ }
17
+ catch (error) {
18
+ throw new Error(error.stack);
19
+ }
20
+ };
21
+ exports.renderWithWrappers = renderWithWrappers;
22
+ const Providers = ({ children }) => ((0, jsx_runtime_1.jsx)(react_native_safe_area_context_1.SafeAreaProvider, { children: (0, jsx_runtime_1.jsx)(Theme_1.Theme, { children: children }) }));
23
+ exports.Providers = Providers;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@artsy/palette-mobile",
3
- "version": "6.1.0",
3
+ "version": "7.0.0",
4
4
  "description": "Artsy's design system for React Native",
5
5
  "scripts": {
6
6
  "android": "react-native run-android",
@@ -19,7 +19,8 @@
19
19
  "setup:artsy": "./scripts/download-fonts",
20
20
  "start": "react-native start",
21
21
  "storybook-watcher": "sb-rn-watcher",
22
- "test": "jest"
22
+ "test": "jest",
23
+ "test:w": "jest --watch"
23
24
  },
24
25
  "dependenciesComments": [
25
26
  "ONLY ADD DEPS THAT ARE OK TO SHIP WITH THIS LIBRARY.",
@@ -32,7 +33,6 @@
32
33
  "events": "^3.3.0",
33
34
  "lodash": "^4.17.21",
34
35
  "react-nanny": "^2.15.0",
35
- "react-spring": "8.0.22",
36
36
  "styled-components": "^5.3.6",
37
37
  "styled-system": "^5.1.5"
38
38
  },
@@ -51,48 +51,54 @@
51
51
  "@auto-it/all-contributors": "^10.37.6",
52
52
  "@auto-it/first-time-contributor": "^10.37.6",
53
53
  "@babel/core": "^7.20.12",
54
+ "@babel/plugin-proposal-private-methods": "^7.18.6",
54
55
  "@babel/preset-react": "^7.18.6",
55
56
  "@babel/preset-typescript": "^7.18.6",
56
- "@babel/runtime": "^7.20.7",
57
- "@react-native-async-storage/async-storage": "^1.17.11",
58
- "@storybook/react-native": "^6.0.1-beta.11",
57
+ "@babel/runtime": "^7.20.13",
58
+ "@react-native-async-storage/async-storage": "1.17.11",
59
+ "@storybook/react-native": "^6.0.1-beta.12",
60
+ "@testing-library/jest-native": "5.4.1",
61
+ "@testing-library/react-native": "11.5.1",
59
62
  "@tsconfig/react-native": "^2.0.3",
60
63
  "@types/events": "^3.0.0",
61
- "@types/jest": "^29.2.5",
62
- "@types/lodash": "^4.14.191",
64
+ "@types/jest": "29.4.0",
65
+ "@types/lodash": "4.14.191",
63
66
  "@types/react-native": "^0.70.8",
64
67
  "@types/react-test-renderer": "^18.0.0",
65
68
  "@types/styled-components": "^5.1.26",
66
- "@types/styled-components-react-native": "^5.2.0",
69
+ "@types/styled-components-react-native": "^5.2.1",
67
70
  "@types/styled-system": "^5.1.16",
68
71
  "@types/styled-system__core": "^5.1.3",
69
72
  "@types/styled-system__theme-get": "^5.0.2",
70
- "@typescript-eslint/eslint-plugin": "^5.48.0",
71
- "@typescript-eslint/parser": "^5.48.0",
72
- "auto": "^10.37.6",
73
- "babel-jest": "^29.3.1",
74
- "eslint": "^8.31.0",
75
- "eslint-config-prettier": "^8.6.0",
76
- "eslint-import-resolver-typescript": "^3.5.2",
77
- "eslint-plugin-import": "^2.26.0",
73
+ "@typescript-eslint/eslint-plugin": "5.50.0",
74
+ "@typescript-eslint/parser": "^5.50.0",
75
+ "auto": "10.37.6",
76
+ "babel-jest": "29.4.1",
77
+ "eslint": "8.33.0",
78
+ "eslint-config-prettier": "8.6.0",
79
+ "eslint-import-resolver-typescript": "3.5.3",
80
+ "eslint-plugin-import": "2.27.5",
78
81
  "eslint-plugin-prettier": "^4.2.1",
79
- "eslint-plugin-storybook": "^0.6.8",
80
- "jest": "^29.3.1",
81
- "jotai": "^1.12.1",
82
- "metro-react-native-babel-preset": "^0.73.7",
82
+ "eslint-plugin-storybook": "0.6.10",
83
+ "jest": "29.4.1",
84
+ "jest-environment-jsdom": "29.4.1",
85
+ "jest-extended": "3.2.3",
86
+ "jest-watch-typeahead": "2.2.2",
87
+ "jotai": "1.12.1",
88
+ "metro-react-native-babel-preset": "0.73.7",
83
89
  "react": "18.2.0",
84
- "react-dom": "^18.2.0",
90
+ "react-dom": "18.2.0",
85
91
  "react-native": "0.70.6",
86
- "react-native-flipper": "^0.176.1",
87
- "react-native-haptic-feedback": "^1.14.0",
88
- "react-native-linear-gradient": "^2.6.2",
89
- "react-native-reanimated": "^2.13.0",
92
+ "react-native-flipper": "0.177.0",
93
+ "react-native-haptic-feedback": "1.14.0",
94
+ "react-native-linear-gradient": "2.6.2",
95
+ "react-native-reanimated": "2.14.4",
90
96
  "react-native-safe-area-context": "^4.4.1",
91
- "react-native-svg": "^13.7.0",
92
- "react-test-renderer": "^18.2.0",
93
- "rimraf": "^3.0.2",
94
- "rn-flipper-async-storage-advanced": "^1.0.4",
95
- "typescript": "^4.9.4"
97
+ "react-native-svg": "13.7.0",
98
+ "react-test-renderer": "18.2.0",
99
+ "rimraf": "4.1.2",
100
+ "rn-flipper-async-storage-advanced": "1.0.4",
101
+ "typescript": "4.9.5"
96
102
  },
97
103
  "files": [
98
104
  "dist"