@artsy/palette-mobile 11.0.4 → 11.0.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/Autocomplete/Autocomplete.tests.d.ts +1 -0
- package/dist/elements/Autocomplete/Autocomplete.tests.js +80 -0
- package/dist/elements/Avatar/Avatar.tests.d.ts +1 -0
- package/dist/elements/Avatar/Avatar.tests.js +14 -0
- package/dist/elements/BackButton/BackButton.d.ts +6 -3
- package/dist/elements/BackButton/BackButton.js +6 -2
- package/dist/elements/BackButton/BackButton.stories.d.ts +1 -1
- package/dist/elements/Checkbox/Check.d.ts +10 -0
- package/dist/elements/Checkbox/Check.js +92 -0
- package/dist/elements/Checkbox/Checkbox.d.ts +4 -7
- package/dist/elements/Checkbox/Checkbox.js +20 -20
- package/dist/elements/Checkbox/Checkbox.stories.d.ts +1 -1
- package/dist/elements/Checkbox/Checkbox.stories.js +1 -1
- package/dist/elements/Checkbox/index.d.ts +1 -0
- package/dist/elements/Checkbox/index.js +1 -0
- package/dist/elements/CollapsibleMenuItem/CollapsibleMenuItem.stories.d.ts +12 -0
- package/dist/elements/CollapsibleMenuItem/CollapsibleMenuItem.stories.js +94 -0
- package/dist/elements/Dialog/Dialog.d.ts +15 -0
- package/dist/elements/Dialog/Dialog.js +72 -0
- package/dist/elements/Dialog/Dialog.stories.d.ts +1 -0
- package/dist/elements/Dialog/Dialog.stories.js +24 -0
- package/dist/elements/Dialog/Dialog.tests.d.ts +1 -0
- package/dist/elements/Dialog/Dialog.tests.js +56 -0
- package/dist/elements/Dialog/index.d.ts +1 -0
- package/dist/elements/Dialog/index.js +17 -0
- package/dist/elements/Message/Message.d.ts +18 -0
- package/dist/elements/Message/Message.js +70 -0
- package/dist/elements/Message/Message.stories.d.ts +1 -0
- package/dist/elements/Message/Message.stories.js +11 -0
- package/dist/elements/Message/Message.tests.d.ts +1 -0
- package/dist/elements/Message/Message.tests.js +28 -0
- package/dist/elements/Message/index.d.ts +1 -0
- package/dist/elements/Message/index.js +17 -0
- package/dist/elements/index.d.ts +2 -0
- package/dist/elements/index.js +2 -0
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const Autocomplete_1 = require("./Autocomplete");
|
|
4
|
+
const artists = [
|
|
5
|
+
{
|
|
6
|
+
key: "Pablo Picasso",
|
|
7
|
+
importance: 100,
|
|
8
|
+
searchTerms: ["Pablo Picasso"],
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
key: "Grayson Perry",
|
|
12
|
+
importance: 10,
|
|
13
|
+
searchTerms: ["Grayson Perry"],
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
key: "Prince",
|
|
17
|
+
importance: 50,
|
|
18
|
+
searchTerms: ["Prince", "The artist formerly known as 'Prince'"],
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
key: "James Brown",
|
|
22
|
+
importance: 100,
|
|
23
|
+
searchTerms: ["JB", "The King of Funk"],
|
|
24
|
+
},
|
|
25
|
+
];
|
|
26
|
+
describe(Autocomplete_1.Autocomplete, () => {
|
|
27
|
+
it(`lets you search for individual words in search terms`, async () => {
|
|
28
|
+
const auto = new Autocomplete_1.Autocomplete(artists);
|
|
29
|
+
expect(auto.getSuggestions("formerly")).toEqual(["Prince"]);
|
|
30
|
+
});
|
|
31
|
+
it(`doesn't care about capitalization`, async () => {
|
|
32
|
+
const auto = new Autocomplete_1.Autocomplete(artists);
|
|
33
|
+
expect(auto.getSuggestions("fOrMerly")).toEqual(["Prince"]);
|
|
34
|
+
});
|
|
35
|
+
it(`doesn't care about punctuation`, async () => {
|
|
36
|
+
const auto = new Autocomplete_1.Autocomplete([
|
|
37
|
+
...artists,
|
|
38
|
+
{
|
|
39
|
+
key: "Dog",
|
|
40
|
+
importance: +Infinity,
|
|
41
|
+
searchTerms: ["Santa's little helper"],
|
|
42
|
+
},
|
|
43
|
+
]);
|
|
44
|
+
expect(auto.getSuggestions("fOrMerl,y")).toEqual(["Prince"]);
|
|
45
|
+
expect(auto.getSuggestions("santas")).toEqual(["Dog"]);
|
|
46
|
+
});
|
|
47
|
+
it(`doesn't care about diacritics`, async () => {
|
|
48
|
+
const auto = new Autocomplete_1.Autocomplete([
|
|
49
|
+
...artists,
|
|
50
|
+
{
|
|
51
|
+
key: "Nordic",
|
|
52
|
+
importance: +Infinity,
|
|
53
|
+
searchTerms: ["Jón Jønssön"],
|
|
54
|
+
},
|
|
55
|
+
]);
|
|
56
|
+
expect(auto.getSuggestions("Jon")).toEqual(["Nordic"]);
|
|
57
|
+
expect(auto.getSuggestions("Jonsson")).toEqual(["Nordic"]);
|
|
58
|
+
});
|
|
59
|
+
it(`orders results according to importance`, async () => {
|
|
60
|
+
const auto = new Autocomplete_1.Autocomplete(artists);
|
|
61
|
+
expect(auto.getSuggestions("p")).toEqual(["Pablo Picasso", "Prince", "Grayson Perry"]);
|
|
62
|
+
});
|
|
63
|
+
it(`returns nothing when there are no matches`, async () => {
|
|
64
|
+
const auto = new Autocomplete_1.Autocomplete(artists);
|
|
65
|
+
expect(auto.getSuggestions("z")).toEqual([]);
|
|
66
|
+
});
|
|
67
|
+
it(`ignores stop words which don't appear at the beginning of a search term`, async () => {
|
|
68
|
+
const auto = new Autocomplete_1.Autocomplete([
|
|
69
|
+
...artists,
|
|
70
|
+
{
|
|
71
|
+
key: "PaRappa the Rapper",
|
|
72
|
+
importance: +Infinity * 2,
|
|
73
|
+
searchTerms: ["PaRappa the Rapper"],
|
|
74
|
+
},
|
|
75
|
+
], 10, ["the"]);
|
|
76
|
+
expect(auto.getSuggestions("the")).toContain("James Brown");
|
|
77
|
+
expect(auto.getSuggestions("the")).not.toContain("PaRappa the Rapper");
|
|
78
|
+
expect(auto.getSuggestions("Rapper")).toEqual(["PaRappa the Rapper"]);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
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 react_native_2 = require("react-native");
|
|
6
|
+
const Avatar_1 = require("./Avatar");
|
|
7
|
+
const renderWithWrappers_1 = require("../../utils/tests/renderWithWrappers");
|
|
8
|
+
describe("Avatar", () => {
|
|
9
|
+
it("renders initials if no image url and initials provided", () => {
|
|
10
|
+
(0, renderWithWrappers_1.renderWithWrappers)((0, jsx_runtime_1.jsx)(Avatar_1.Avatar, { initials: "AB" }));
|
|
11
|
+
expect(react_native_1.screen.UNSAFE_queryByType(react_native_2.Image)).not.toBeTruthy();
|
|
12
|
+
expect(react_native_1.screen.getByText("AB")).toBeTruthy();
|
|
13
|
+
});
|
|
14
|
+
});
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { ViewProps } from "react-native";
|
|
2
|
+
import { TouchableOpacityProps, ViewProps } from "react-native";
|
|
3
|
+
import { Color } from "../../types";
|
|
3
4
|
export interface BackButtonProps {
|
|
5
|
+
color?: Color;
|
|
4
6
|
hitSlop?: ViewProps["hitSlop"];
|
|
5
7
|
onPress?: () => void;
|
|
6
8
|
showX?: boolean;
|
|
9
|
+
style?: TouchableOpacityProps["style"];
|
|
7
10
|
}
|
|
8
|
-
export declare const BackButton:
|
|
9
|
-
export declare const BackButtonWithBackground:
|
|
11
|
+
export declare const BackButton: React.FC<BackButtonProps>;
|
|
12
|
+
export declare const BackButtonWithBackground: React.FC<BackButtonProps>;
|
|
@@ -6,7 +6,11 @@ const react_native_1 = require("react-native");
|
|
|
6
6
|
const constants_1 = require("../../constants");
|
|
7
7
|
const svgs_1 = require("../../svgs");
|
|
8
8
|
const Flex_1 = require("../Flex");
|
|
9
|
-
const BackButton = ({ hitSlop = constants_1.DEFAULT_HIT_SLOP, onPress, showX = false,
|
|
9
|
+
const BackButton = ({ color = "onBackgroundHigh", hitSlop = constants_1.DEFAULT_HIT_SLOP, onPress, showX = false, style, }) => {
|
|
10
|
+
return ((0, jsx_runtime_1.jsx)(react_native_1.TouchableOpacity, { onPress: onPress, hitSlop: hitSlop, accessibilityRole: "button", accessibilityLabel: showX ? "Close" : "Go back", accessibilityHint: showX ? "Dismiss this screen" : "Go back to the previous screen", style: style, children: showX ? ((0, jsx_runtime_1.jsx)(svgs_1.CloseIcon, { fill: color, width: 26, height: 26 })) : ((0, jsx_runtime_1.jsx)(svgs_1.ChevronIcon, { direction: "left", fill: color })) }));
|
|
11
|
+
};
|
|
10
12
|
exports.BackButton = BackButton;
|
|
11
|
-
const BackButtonWithBackground = ({ hitSlop = constants_1.DEFAULT_HIT_SLOP, onPress, showX = false,
|
|
13
|
+
const BackButtonWithBackground = ({ color = "onBackgroundHigh", hitSlop = constants_1.DEFAULT_HIT_SLOP, onPress, showX = false, style, }) => {
|
|
14
|
+
return ((0, jsx_runtime_1.jsx)(react_native_1.TouchableOpacity, { onPress: onPress, hitSlop: hitSlop, children: (0, jsx_runtime_1.jsx)(Flex_1.Flex, { backgroundColor: "background", width: 40, height: 40, borderRadius: 20, alignItems: "center", justifyContent: "center", accessibilityRole: "button", accessibilityLabel: showX ? "Close" : "Go back", accessibilityHint: showX ? "Dismiss this screen" : "Go back to the previous screen", style: style, children: showX ? ((0, jsx_runtime_1.jsx)(svgs_1.CloseIcon, { fill: color, width: 26, height: 26 })) : ((0, jsx_runtime_1.jsx)(svgs_1.ChevronIcon, { fill: color, direction: "left" })) }) }));
|
|
15
|
+
};
|
|
12
16
|
exports.BackButtonWithBackground = BackButtonWithBackground;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
declare const _default: {
|
|
3
3
|
title: string;
|
|
4
|
-
component: (
|
|
4
|
+
component: import("react").FC<import("./BackButton").BackButtonProps>;
|
|
5
5
|
};
|
|
6
6
|
export default _default;
|
|
7
7
|
export declare const Styled: () => JSX.Element;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const CHECK_SIZE = 22;
|
|
3
|
+
export interface CheckProps {
|
|
4
|
+
disabled?: boolean;
|
|
5
|
+
error?: boolean;
|
|
6
|
+
hover?: boolean;
|
|
7
|
+
selected?: boolean;
|
|
8
|
+
}
|
|
9
|
+
/** Toggeable check mark */
|
|
10
|
+
export declare const Check: React.FC<CheckProps>;
|
|
@@ -0,0 +1,92 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.Check = exports.CHECK_SIZE = void 0;
|
|
27
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
28
|
+
const theme_get_1 = require("@styled-system/theme-get");
|
|
29
|
+
const native_1 = __importStar(require("styled-components/native"));
|
|
30
|
+
const CheckIcon_1 = require("../../svgs/CheckIcon");
|
|
31
|
+
const Box_1 = require("../Box");
|
|
32
|
+
exports.CHECK_SIZE = 22;
|
|
33
|
+
const CHECK_MODES = {
|
|
34
|
+
default: {
|
|
35
|
+
resting: (0, native_1.css) `
|
|
36
|
+
background-color: ${(0, theme_get_1.themeGet)("colors.white100")};
|
|
37
|
+
border-color: ${(0, theme_get_1.themeGet)("colors.black10")};
|
|
38
|
+
`,
|
|
39
|
+
selected: (0, native_1.css) `
|
|
40
|
+
background-color: ${(0, theme_get_1.themeGet)("colors.black100")};
|
|
41
|
+
border-color: ${(0, theme_get_1.themeGet)("colors.black100")};
|
|
42
|
+
`,
|
|
43
|
+
},
|
|
44
|
+
disabled: {
|
|
45
|
+
resting: (0, native_1.css) `
|
|
46
|
+
background-color: ${(0, theme_get_1.themeGet)("colors.black5")};
|
|
47
|
+
border-color: ${(0, theme_get_1.themeGet)("colors.black10")};
|
|
48
|
+
`,
|
|
49
|
+
selected: (0, native_1.css) `
|
|
50
|
+
background-color: ${(0, theme_get_1.themeGet)("colors.black30")};
|
|
51
|
+
border-color: ${(0, theme_get_1.themeGet)("colors.black30")};
|
|
52
|
+
`,
|
|
53
|
+
},
|
|
54
|
+
error: {
|
|
55
|
+
resting: (0, native_1.css) `
|
|
56
|
+
background-color: ${(0, theme_get_1.themeGet)("colors.white100")};
|
|
57
|
+
border-color: ${(0, theme_get_1.themeGet)("colors.red100")};
|
|
58
|
+
`,
|
|
59
|
+
selected: (0, native_1.css) `
|
|
60
|
+
background-color: ${(0, theme_get_1.themeGet)("colors.black100")};
|
|
61
|
+
border-color: ${(0, theme_get_1.themeGet)("colors.black100")};
|
|
62
|
+
`,
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
/** Toggeable check mark */
|
|
66
|
+
const Check = ({ disabled, selected, ...rest }) => {
|
|
67
|
+
return ((0, jsx_runtime_1.jsx)(Container, { disabled: disabled, selected: selected, ...rest, children: !!selected && (0, jsx_runtime_1.jsx)(CheckIcon_1.CheckIcon, { fill: "white100" }) }));
|
|
68
|
+
};
|
|
69
|
+
exports.Check = Check;
|
|
70
|
+
const Container = (0, native_1.default)(Box_1.Box) `
|
|
71
|
+
width: ${exports.CHECK_SIZE}px;
|
|
72
|
+
height: ${exports.CHECK_SIZE}px;
|
|
73
|
+
display: flex;
|
|
74
|
+
align-items: center;
|
|
75
|
+
justify-content: center;
|
|
76
|
+
border: 2px solid;
|
|
77
|
+
border-radius: 1px;
|
|
78
|
+
|
|
79
|
+
${(props) => {
|
|
80
|
+
const mode = (() => {
|
|
81
|
+
switch (true) {
|
|
82
|
+
case props.error:
|
|
83
|
+
return CHECK_MODES.error;
|
|
84
|
+
case props.disabled:
|
|
85
|
+
return CHECK_MODES.disabled;
|
|
86
|
+
default:
|
|
87
|
+
return CHECK_MODES.default;
|
|
88
|
+
}
|
|
89
|
+
})();
|
|
90
|
+
return props.selected ? mode.selected : mode.resting;
|
|
91
|
+
}};
|
|
92
|
+
`;
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { TouchableProps } from "../../elements";
|
|
3
|
-
|
|
4
|
-
export interface CheckboxProps {
|
|
3
|
+
import { FlexProps } from "../Flex";
|
|
4
|
+
export interface CheckboxProps extends FlexProps {
|
|
5
5
|
checked?: boolean;
|
|
6
6
|
disabled?: boolean;
|
|
7
7
|
error?: boolean;
|
|
8
|
+
onPress?: TouchableProps["onPress"];
|
|
8
9
|
text?: React.ReactElement | string;
|
|
9
10
|
subtitle?: React.ReactElement | string;
|
|
10
|
-
onPress?: TouchableProps["onPress"];
|
|
11
|
-
/** Used only for tests and stories */
|
|
12
|
-
testOnly_state?: DisplayState;
|
|
13
11
|
}
|
|
14
|
-
export declare const Checkbox:
|
|
15
|
-
export {};
|
|
12
|
+
export declare const Checkbox: React.FC<CheckboxProps>;
|
|
@@ -35,12 +35,12 @@ const Flex_1 = require("../Flex");
|
|
|
35
35
|
const Text_1 = require("../Text");
|
|
36
36
|
const CHECKBOX_SIZEx1 = 20;
|
|
37
37
|
const ANIMATION_DURATION = 250;
|
|
38
|
-
const Checkbox = ({ checked: checkedProp, disabled = false, error = false, onPress, text, subtitle,
|
|
38
|
+
const Checkbox = ({ checked: checkedProp, disabled = false, error = false, onPress, text, subtitle, ...flexProps }) => {
|
|
39
39
|
const { color, space } = (0, useTheme_1.useTheme)();
|
|
40
40
|
const fontScale = react_native_1.PixelRatio.getFontScale();
|
|
41
41
|
const checkboxSize = CHECKBOX_SIZEx1 * fontScale;
|
|
42
42
|
const [checked, setChecked] = (0, react_1.useState)(checkedProp ?? false);
|
|
43
|
-
const [displayState, setDisplayState] = (0, react_1.useState)(
|
|
43
|
+
const [displayState, setDisplayState] = (0, react_1.useState)("unpressed");
|
|
44
44
|
const containerColor = {
|
|
45
45
|
unchecked: { border: color("black100"), background: color("white100") },
|
|
46
46
|
error: { border: color("red100"), background: color("white100") },
|
|
@@ -73,25 +73,25 @@ const Checkbox = ({ checked: checkedProp, disabled = false, error = false, onPre
|
|
|
73
73
|
: disabled
|
|
74
74
|
? "onBackgroundLow"
|
|
75
75
|
: "onBackgroundMedium";
|
|
76
|
-
return ((0, jsx_runtime_1.jsx)(elements_1.Touchable, { noFeedback: true, disabled: disabled, onPressIn: () => setDisplayState("pressed"), onPressOut: () => setDisplayState("unpressed"), onPress: (event) => {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
76
|
+
return ((0, jsx_runtime_1.jsx)(Flex_1.Flex, { ...flexProps, children: (0, jsx_runtime_1.jsx)(elements_1.Touchable, { noFeedback: true, disabled: disabled, onPressIn: () => setDisplayState("pressed"), onPressOut: () => setDisplayState("unpressed"), onPress: (event) => {
|
|
77
|
+
if (disabled)
|
|
78
|
+
return;
|
|
79
|
+
setChecked(!checked);
|
|
80
|
+
onPress?.(event);
|
|
81
|
+
}, children: (0, jsx_runtime_1.jsxs)(Flex_1.Flex, { flex: 1, children: [(0, jsx_runtime_1.jsxs)(Flex_1.Flex, { flexDirection: "row", children: [(0, jsx_runtime_1.jsx)(react_native_reanimated_1.default.View, { style: [
|
|
82
|
+
{
|
|
83
|
+
width: checkboxSize,
|
|
84
|
+
height: checkboxSize,
|
|
85
|
+
alignItems: "center",
|
|
86
|
+
justifyContent: "center",
|
|
87
|
+
borderWidth: 1,
|
|
88
|
+
},
|
|
89
|
+
toggleAnim,
|
|
90
|
+
], children: checked && (0, jsx_runtime_1.jsx)(Checkmark, { size: checkboxSize }) }), (0, jsx_runtime_1.jsx)(Flex_1.Flex, { ml: 1, flex: 1, children: text !== undefined && ((0, jsx_runtime_1.jsxs)(AnimatedText, { variant: "sm-display", color: textColor, numberOfLines: 2, underline: displayState === "pressed", style: pressAnim, children: [text, " ", displayState] })) })] }), subtitle !== undefined && ((0, jsx_runtime_1.jsx)(Flex_1.Flex, { ml: `${(checkboxSize + space(1)) * fontScale}px`, mt: 0.5, children: (0, jsx_runtime_1.jsx)(Text_1.Text, { variant: "xs", color: subtitleColor, children: subtitle }) }))] }) }) }));
|
|
91
91
|
};
|
|
92
92
|
exports.Checkbox = Checkbox;
|
|
93
|
-
const
|
|
94
|
-
|
|
93
|
+
const AnimatedText = react_native_reanimated_1.default.createAnimatedComponent(Text_1.Text);
|
|
94
|
+
const Checkmark = ({ size }) => {
|
|
95
95
|
const color = (0, hooks_1.useColor)();
|
|
96
96
|
return ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: {
|
|
97
97
|
width: size * 0.625,
|
|
@@ -102,4 +102,4 @@ function Checkmark({ size }) {
|
|
|
102
102
|
transform: [{ rotate: "-45deg" }],
|
|
103
103
|
top: -2,
|
|
104
104
|
} }));
|
|
105
|
-
}
|
|
105
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
declare const _default: {
|
|
3
3
|
title: string;
|
|
4
|
-
component: (
|
|
4
|
+
component: import("react").FC<import("./Checkbox").CheckboxProps>;
|
|
5
5
|
};
|
|
6
6
|
export default _default;
|
|
7
7
|
export declare function Variants(): JSX.Element;
|
|
@@ -9,7 +9,7 @@ exports.default = {
|
|
|
9
9
|
component: Checkbox_1.Checkbox,
|
|
10
10
|
};
|
|
11
11
|
function Variants() {
|
|
12
|
-
return ((0, jsx_runtime_1.jsxs)(helpers_1.List, { style: { marginLeft: 20 }, children: [(0, jsx_runtime_1.jsx)(helpers_1.Row, { children: (0, jsx_runtime_1.jsx)(Checkbox_1.Checkbox, { text: "Default" }) }), (0, jsx_runtime_1.jsx)(helpers_1.Row, { children: (0, jsx_runtime_1.jsx)(Checkbox_1.Checkbox, { text: "
|
|
12
|
+
return ((0, jsx_runtime_1.jsxs)(helpers_1.List, { style: { marginLeft: 20 }, children: [(0, jsx_runtime_1.jsx)(helpers_1.Row, { children: (0, jsx_runtime_1.jsx)(Checkbox_1.Checkbox, { text: "Default" }) }), (0, jsx_runtime_1.jsx)(helpers_1.Row, { children: (0, jsx_runtime_1.jsx)(Checkbox_1.Checkbox, { text: "Checked", checked: true }) }), (0, jsx_runtime_1.jsx)(helpers_1.Row, { children: (0, jsx_runtime_1.jsx)(Checkbox_1.Checkbox, { text: "Disabled", disabled: true }) }), (0, jsx_runtime_1.jsx)(helpers_1.Row, { children: (0, jsx_runtime_1.jsx)(Checkbox_1.Checkbox, { text: "Checked and disabled", checked: true, disabled: true }) }), (0, jsx_runtime_1.jsx)(helpers_1.Row, { children: (0, jsx_runtime_1.jsx)(Checkbox_1.Checkbox, { text: "Error", error: true }) }), (0, jsx_runtime_1.jsx)(helpers_1.Row, { children: (0, jsx_runtime_1.jsx)(Checkbox_1.Checkbox, { text: `Default with multiline
|
|
13
13
|
text` }) }), (0, jsx_runtime_1.jsx)(helpers_1.Row, { children: (0, jsx_runtime_1.jsx)(Checkbox_1.Checkbox, { text: "Disabled", subtitle: "With subtitle", disabled: true }) }), (0, jsx_runtime_1.jsx)(helpers_1.Row, { children: (0, jsx_runtime_1.jsx)(Checkbox_1.Checkbox, { text: `Error with multiline
|
|
14
14
|
text`, subtitle: "With subtitle", error: true }) })] }));
|
|
15
15
|
}
|
|
@@ -14,4 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./Check"), exports);
|
|
17
18
|
__exportStar(require("./Checkbox"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const ArtworkDetails: ({ handlePress }: {
|
|
3
|
+
handlePress: () => void;
|
|
4
|
+
}) => JSX.Element;
|
|
5
|
+
export declare const UploadPhotos: ({ handlePress }: {
|
|
6
|
+
handlePress: () => void;
|
|
7
|
+
}) => JSX.Element;
|
|
8
|
+
export declare const ContactInformation: ({ handlePress }: {
|
|
9
|
+
handlePress: () => void;
|
|
10
|
+
}) => JSX.Element;
|
|
11
|
+
export declare const DisplayContent: () => JSX.Element;
|
|
12
|
+
export declare const ComponentWithCollapsibleMenu: () => JSX.Element;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ComponentWithCollapsibleMenu = exports.DisplayContent = exports.ContactInformation = exports.UploadPhotos = exports.ArtworkDetails = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_native_1 = require("@storybook/react-native");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const react_native_2 = require("react-native");
|
|
8
|
+
const CollapsibleMenuItem_1 = require("./CollapsibleMenuItem");
|
|
9
|
+
const Button_1 = require("../Button");
|
|
10
|
+
const Flex_1 = require("../Flex");
|
|
11
|
+
const Join_1 = require("../Join");
|
|
12
|
+
const Separator_1 = require("../Separator");
|
|
13
|
+
const Spacer_1 = require("../Spacer");
|
|
14
|
+
const Text_1 = require("../Text");
|
|
15
|
+
const ArtworkDetails = ({ handlePress }) => {
|
|
16
|
+
return ((0, jsx_runtime_1.jsxs)(Flex_1.Flex, { backgroundColor: "peachpuff", p: 1, mt: 1, children: [(0, jsx_runtime_1.jsx)(Text_1.Text, { children: "ArtworkDetails content" }), (0, jsx_runtime_1.jsx)(Spacer_1.Spacer, { y: 1 }), (0, jsx_runtime_1.jsx)(CTAButton, { text: "Save & Continue", onPress: handlePress })] }));
|
|
17
|
+
};
|
|
18
|
+
exports.ArtworkDetails = ArtworkDetails;
|
|
19
|
+
const UploadPhotos = ({ handlePress }) => {
|
|
20
|
+
return ((0, jsx_runtime_1.jsxs)(Flex_1.Flex, { backgroundColor: "peachpuff", p: 1, mt: 1, children: [(0, jsx_runtime_1.jsx)(Text_1.Text, { children: "Upload Photos content" }), (0, jsx_runtime_1.jsx)(Spacer_1.Spacer, { y: 1 }), (0, jsx_runtime_1.jsx)(CTAButton, { text: "Save & Continue", onPress: handlePress })] }));
|
|
21
|
+
};
|
|
22
|
+
exports.UploadPhotos = UploadPhotos;
|
|
23
|
+
const ContactInformation = ({ handlePress }) => {
|
|
24
|
+
return ((0, jsx_runtime_1.jsxs)(Flex_1.Flex, { backgroundColor: "peachpuff", p: 1, mt: 1, children: [(0, jsx_runtime_1.jsx)(Text_1.Text, { children: "ContactInformation content" }), (0, jsx_runtime_1.jsx)(Spacer_1.Spacer, { y: 1 }), (0, jsx_runtime_1.jsx)(CTAButton, { text: "Submit Artwork", onPress: handlePress })] }));
|
|
25
|
+
};
|
|
26
|
+
exports.ContactInformation = ContactInformation;
|
|
27
|
+
const CTAButton = ({ onPress, text }) => ((0, jsx_runtime_1.jsx)(Button_1.Button, { block: true, haptic: true, maxWidth: 540, onPress: onPress, children: text }));
|
|
28
|
+
const DisplayContent = () => {
|
|
29
|
+
return ((0, jsx_runtime_1.jsx)(react_native_2.View, { style: { backgroundColor: `rgba(255,145,125,.3)`, padding: 20, marginTop: 20 }, children: (0, jsx_runtime_1.jsx)(Text_1.Text, { children: "This is the collapsible menu content" }) }));
|
|
30
|
+
};
|
|
31
|
+
exports.DisplayContent = DisplayContent;
|
|
32
|
+
const ComponentWithCollapsibleMenu = () => {
|
|
33
|
+
const items = [
|
|
34
|
+
{
|
|
35
|
+
overtitle: "Optional overtitle",
|
|
36
|
+
title: "Artwork Details",
|
|
37
|
+
Content: ((0, jsx_runtime_1.jsx)(exports.ArtworkDetails, { handlePress: () => {
|
|
38
|
+
expandCollapsibleMenuContent(1);
|
|
39
|
+
enableStep(1);
|
|
40
|
+
} })),
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
overtitle: "Optional overtitle",
|
|
44
|
+
title: "Upload Photos",
|
|
45
|
+
Content: ((0, jsx_runtime_1.jsx)(exports.UploadPhotos, { handlePress: () => {
|
|
46
|
+
expandCollapsibleMenuContent(2);
|
|
47
|
+
enableStep(2);
|
|
48
|
+
} })),
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
overtitle: "Optional overtitle",
|
|
52
|
+
title: "Contact Information",
|
|
53
|
+
Content: ((0, jsx_runtime_1.jsx)(exports.ContactInformation, { handlePress: () => {
|
|
54
|
+
// navigation.navigate("ArtworkSubmittedScreen")
|
|
55
|
+
// do nothing
|
|
56
|
+
} })),
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
const TOTAL_STEPS = items.length;
|
|
60
|
+
const [validSteps, setValidSteps] = (0, react_1.useState)([true, ...new Array(TOTAL_STEPS - 1).fill(false)]);
|
|
61
|
+
const stepsRefs = (0, react_1.useRef)(new Array(TOTAL_STEPS).fill(null)).current;
|
|
62
|
+
const enableStep = (stepIndex) => {
|
|
63
|
+
const newValidSteps = [...validSteps];
|
|
64
|
+
newValidSteps[stepIndex] = true;
|
|
65
|
+
setValidSteps(newValidSteps);
|
|
66
|
+
};
|
|
67
|
+
const expandCollapsibleMenuContent = (indexToExpand) => {
|
|
68
|
+
items.forEach((_, index) => {
|
|
69
|
+
if (indexToExpand !== index) {
|
|
70
|
+
stepsRefs[index].collapse();
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
if (index > 0) {
|
|
74
|
+
stepsRefs[index - 1].completed();
|
|
75
|
+
}
|
|
76
|
+
stepsRefs[index].expand();
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
return ((0, jsx_runtime_1.jsx)(react_native_2.View, { style: { margin: 20 }, children: (0, jsx_runtime_1.jsx)(Flex_1.Flex, { children: (0, jsx_runtime_1.jsxs)(react_native_2.ScrollView, { contentContainerStyle: {
|
|
81
|
+
paddingVertical: 20,
|
|
82
|
+
paddingHorizontal: 20,
|
|
83
|
+
justifyContent: "center",
|
|
84
|
+
}, children: [(0, jsx_runtime_1.jsx)(Spacer_1.Spacer, { y: 4 }), (0, jsx_runtime_1.jsx)(Join_1.Join, { separator: (0, jsx_runtime_1.jsx)(Separator_1.Separator, { my: 2, marginTop: "40", marginBottom: "20" }), children: items.map(({ overtitle, title, Content }, index) => {
|
|
85
|
+
const disabled = !validSteps[index];
|
|
86
|
+
return ((0, jsx_runtime_1.jsx)(CollapsibleMenuItem_1.CollapsibleMenuItem, { overtitle: overtitle, title: title, onExpand: () => expandCollapsibleMenuContent(index), isExpanded: index === 0, disabled: disabled, ref: (ref) => {
|
|
87
|
+
if (ref) {
|
|
88
|
+
stepsRefs[index] = ref;
|
|
89
|
+
}
|
|
90
|
+
}, children: Content }, index));
|
|
91
|
+
}) })] }) }) }));
|
|
92
|
+
};
|
|
93
|
+
exports.ComponentWithCollapsibleMenu = ComponentWithCollapsibleMenu;
|
|
94
|
+
(0, react_native_1.storiesOf)("Collapsible Menu ", module).add("Collapse Collapse Items", () => ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(exports.ComponentWithCollapsibleMenu, {}) })));
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
interface DialogAction {
|
|
3
|
+
text: string;
|
|
4
|
+
onPress: () => void;
|
|
5
|
+
}
|
|
6
|
+
export interface DialogProps {
|
|
7
|
+
isVisible: boolean;
|
|
8
|
+
title: string;
|
|
9
|
+
detail?: string;
|
|
10
|
+
primaryCta: DialogAction;
|
|
11
|
+
secondaryCta?: DialogAction;
|
|
12
|
+
onBackgroundPress?: () => void;
|
|
13
|
+
}
|
|
14
|
+
export declare const Dialog: (props: DialogProps) => JSX.Element;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Dialog = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const react_native_1 = require("react-native");
|
|
7
|
+
const react_native_safe_area_context_1 = require("react-native-safe-area-context");
|
|
8
|
+
const useTheme_1 = require("../../utils/hooks/useTheme");
|
|
9
|
+
const Button_1 = require("../Button");
|
|
10
|
+
const Flex_1 = require("../Flex");
|
|
11
|
+
const Text_1 = require("../Text");
|
|
12
|
+
const Dialog = (props) => {
|
|
13
|
+
const { isVisible, title, detail, primaryCta, secondaryCta, onBackgroundPress, ...other } = props;
|
|
14
|
+
const [visible, setVisible] = (0, react_1.useState)(isVisible);
|
|
15
|
+
const { space, color } = (0, useTheme_1.useTheme)();
|
|
16
|
+
const value = (0, react_1.useRef)(new react_native_1.Animated.Value(Number(isVisible))).current;
|
|
17
|
+
const fadeIn = () => {
|
|
18
|
+
return new Promise((resolve) => {
|
|
19
|
+
react_native_1.Animated.timing(value, {
|
|
20
|
+
toValue: 1,
|
|
21
|
+
useNativeDriver: true,
|
|
22
|
+
duration: 180,
|
|
23
|
+
}).start(resolve);
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
const fadeOut = () => {
|
|
27
|
+
return new Promise((resolve) => {
|
|
28
|
+
react_native_1.Animated.timing(value, {
|
|
29
|
+
toValue: 0,
|
|
30
|
+
useNativeDriver: true,
|
|
31
|
+
duration: 150,
|
|
32
|
+
}).start(resolve);
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
(0, react_1.useEffect)(() => {
|
|
36
|
+
if (isVisible) {
|
|
37
|
+
setVisible(true);
|
|
38
|
+
fadeIn();
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
fadeOut().then(() => {
|
|
42
|
+
setVisible(false);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}, [isVisible]);
|
|
46
|
+
const backdrop = ((0, jsx_runtime_1.jsx)(react_native_1.Animated.View, { style: [
|
|
47
|
+
react_native_1.StyleSheet.absoluteFillObject,
|
|
48
|
+
{ opacity: value, backgroundColor: "rgba(194,194,194,0.5)" },
|
|
49
|
+
] }));
|
|
50
|
+
return ((0, jsx_runtime_1.jsxs)(react_native_1.Modal, { ...other, visible: visible, statusBarTranslucent: true, transparent: true, animationType: "none", children: [!!onBackgroundPress ? ((0, jsx_runtime_1.jsx)(react_native_1.TouchableWithoutFeedback, { testID: "dialog-backdrop", onPress: onBackgroundPress, children: backdrop })) : (backdrop), (0, jsx_runtime_1.jsx)(react_native_safe_area_context_1.SafeAreaView, { pointerEvents: "box-none", style: {
|
|
51
|
+
flex: 1,
|
|
52
|
+
justifyContent: "center",
|
|
53
|
+
alignItems: "center",
|
|
54
|
+
padding: space(2),
|
|
55
|
+
backgroundColor: "transparent",
|
|
56
|
+
}, children: (0, jsx_runtime_1.jsxs)(react_native_1.Animated.View, { style: {
|
|
57
|
+
width: "100%",
|
|
58
|
+
maxHeight: "100%",
|
|
59
|
+
opacity: value,
|
|
60
|
+
backgroundColor: color("white100"),
|
|
61
|
+
borderWidth: 1,
|
|
62
|
+
borderColor: color("black5"),
|
|
63
|
+
shadowColor: "rgba(0, 0, 0, 0.06)",
|
|
64
|
+
shadowOffset: {
|
|
65
|
+
height: 2,
|
|
66
|
+
width: 0,
|
|
67
|
+
},
|
|
68
|
+
shadowOpacity: 1,
|
|
69
|
+
shadowRadius: 10,
|
|
70
|
+
}, children: [(0, jsx_runtime_1.jsx)(Text_1.Text, { testID: "dialog-title", variant: "sm-display", mb: 0.5, mt: 2, mx: 2, children: title }), !!detail && ((0, jsx_runtime_1.jsx)(react_native_1.ScrollView, { alwaysBounceVertical: false, contentContainerStyle: { paddingHorizontal: space(2) }, children: (0, jsx_runtime_1.jsx)(Text_1.Text, { testID: "dialog-detail", variant: "sm", color: "black60", children: detail }) })), (0, jsx_runtime_1.jsxs)(Flex_1.Flex, { mt: 2, mb: 2, mx: 2, flexDirection: "row", justifyContent: "flex-end", children: [!!secondaryCta && ((0, jsx_runtime_1.jsx)(Button_1.Button, { size: "small", testID: "dialog-secondary-action-button", variant: "text", onPress: secondaryCta.onPress, children: secondaryCta.text })), (0, jsx_runtime_1.jsx)(Button_1.Button, { size: "small", variant: "fillDark", testID: "dialog-primary-action-button", ml: 2, onPress: primaryCta.onPress, children: primaryCta.text })] })] }) })] }));
|
|
71
|
+
};
|
|
72
|
+
exports.Dialog = Dialog;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
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 helpers_1 = require("storybook/helpers");
|
|
7
|
+
const _1 = require(".");
|
|
8
|
+
const Button_1 = require("../Button");
|
|
9
|
+
const DialogDemo = (props) => {
|
|
10
|
+
const [visible, setVisible] = (0, react_1.useState)(false);
|
|
11
|
+
return ((0, jsx_runtime_1.jsxs)(helpers_1.List, { children: [(0, jsx_runtime_1.jsx)(Button_1.Button, { onPress: () => setVisible(true), children: "Show" }), (0, jsx_runtime_1.jsx)(_1.Dialog, { isVisible: visible, title: "Dialog Title", primaryCta: {
|
|
12
|
+
text: "OK",
|
|
13
|
+
onPress: () => setVisible(false),
|
|
14
|
+
}, ...props })] }));
|
|
15
|
+
};
|
|
16
|
+
(0, react_native_1.storiesOf)("Dialog", module)
|
|
17
|
+
.add("Default", () => (0, jsx_runtime_1.jsx)(DialogDemo, {}))
|
|
18
|
+
.add("With secondary action", () => ((0, jsx_runtime_1.jsx)(DialogDemo, { secondaryCta: {
|
|
19
|
+
text: "Cancel",
|
|
20
|
+
onPress: () => { },
|
|
21
|
+
} })))
|
|
22
|
+
.add("With details", () => ((0, jsx_runtime_1.jsx)(DialogDemo, { detail: "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum." })))
|
|
23
|
+
.add("With long details", () => ((0, jsx_runtime_1.jsx)(DialogDemo, { detail: "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.".repeat(100) })))
|
|
24
|
+
.add("With background press handler", () => (0, jsx_runtime_1.jsx)(DialogDemo, { onBackgroundPress: () => { } }));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
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 Dialog_1 = require("./Dialog");
|
|
6
|
+
const renderWithWrappers_1 = require("../../utils/tests/renderWithWrappers");
|
|
7
|
+
describe("Dialog", () => {
|
|
8
|
+
it("renders without error", () => {
|
|
9
|
+
const { getByText } = (0, renderWithWrappers_1.renderWithWrappers)((0, jsx_runtime_1.jsx)(Dialog_1.Dialog, { title: "title", isVisible: true, primaryCta: {
|
|
10
|
+
text: "Primary Action Button",
|
|
11
|
+
onPress: jest.fn(),
|
|
12
|
+
} }));
|
|
13
|
+
expect(getByText("title")).toBeTruthy();
|
|
14
|
+
});
|
|
15
|
+
it("should render details if it is passed", () => {
|
|
16
|
+
const { getByText } = (0, renderWithWrappers_1.renderWithWrappers)((0, jsx_runtime_1.jsx)(Dialog_1.Dialog, { title: "title", detail: "Some unique detail", isVisible: true, primaryCta: {
|
|
17
|
+
text: "Primary Action Button",
|
|
18
|
+
onPress: jest.fn(),
|
|
19
|
+
} }));
|
|
20
|
+
expect(getByText("Some unique detail")).toBeTruthy();
|
|
21
|
+
});
|
|
22
|
+
it("should render the primary action button", () => {
|
|
23
|
+
const primaryActionMock = jest.fn();
|
|
24
|
+
const { getByTestId, getByText } = (0, renderWithWrappers_1.renderWithWrappers)((0, jsx_runtime_1.jsx)(Dialog_1.Dialog, { title: "title", isVisible: true, primaryCta: {
|
|
25
|
+
text: "Primary Action Button",
|
|
26
|
+
onPress: primaryActionMock,
|
|
27
|
+
} }));
|
|
28
|
+
const primaryButton = getByTestId("dialog-primary-action-button");
|
|
29
|
+
react_native_1.fireEvent.press(primaryButton);
|
|
30
|
+
expect(primaryActionMock).toHaveBeenCalled();
|
|
31
|
+
expect(getByText("Primary Action Button")).toBeTruthy();
|
|
32
|
+
});
|
|
33
|
+
it("should render the secondary action button if it is passed", () => {
|
|
34
|
+
const secondaryActionMock = jest.fn();
|
|
35
|
+
const { getByTestId, getByText } = (0, renderWithWrappers_1.renderWithWrappers)((0, jsx_runtime_1.jsx)(Dialog_1.Dialog, { title: "title", isVisible: true, primaryCta: {
|
|
36
|
+
text: "Primary Action Button",
|
|
37
|
+
onPress: jest.fn(),
|
|
38
|
+
}, secondaryCta: {
|
|
39
|
+
text: "Secondary Action Button",
|
|
40
|
+
onPress: secondaryActionMock,
|
|
41
|
+
} }));
|
|
42
|
+
const secondaryButton = getByTestId("dialog-secondary-action-button");
|
|
43
|
+
react_native_1.fireEvent.press(secondaryButton);
|
|
44
|
+
expect(secondaryActionMock).toHaveBeenCalled();
|
|
45
|
+
expect(getByText("Secondary Action Button")).toBeTruthy();
|
|
46
|
+
});
|
|
47
|
+
it("should call onBackgroundPress when backdrop is pressed", () => {
|
|
48
|
+
const onBackgroundPressMock = jest.fn();
|
|
49
|
+
const { getByTestId } = (0, renderWithWrappers_1.renderWithWrappers)((0, jsx_runtime_1.jsx)(Dialog_1.Dialog, { title: "title", isVisible: true, onBackgroundPress: onBackgroundPressMock, primaryCta: {
|
|
50
|
+
text: "Primary Action Button",
|
|
51
|
+
onPress: jest.fn(),
|
|
52
|
+
} }));
|
|
53
|
+
react_native_1.fireEvent.press(getByTestId("dialog-backdrop"));
|
|
54
|
+
expect(onBackgroundPressMock).toHaveBeenCalled();
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Dialog";
|
|
@@ -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("./Dialog"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { FlexProps } from "../Flex";
|
|
3
|
+
import { TextProps } from "../Text";
|
|
4
|
+
type MessageVariant = "default" | "info" | "success" | "alert" | "warning" | "error";
|
|
5
|
+
export interface MessageProps {
|
|
6
|
+
bodyTextStyle?: TextProps;
|
|
7
|
+
containerStyle?: FlexProps;
|
|
8
|
+
IconComponent?: React.FC<any>;
|
|
9
|
+
onClose?: () => void;
|
|
10
|
+
showCloseButton?: boolean;
|
|
11
|
+
testID?: string;
|
|
12
|
+
text?: string;
|
|
13
|
+
title: string;
|
|
14
|
+
titleStyle?: TextProps;
|
|
15
|
+
variant?: MessageVariant;
|
|
16
|
+
}
|
|
17
|
+
export declare const Message: React.FC<MessageProps>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Message = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const react_native_1 = require("react-native");
|
|
7
|
+
const svgs_1 = require("../../svgs");
|
|
8
|
+
const useColor_1 = require("../../utils/hooks/useColor");
|
|
9
|
+
const Flex_1 = require("../Flex");
|
|
10
|
+
const Text_1 = require("../Text");
|
|
11
|
+
const Message = ({ bodyTextStyle, containerStyle, IconComponent, onClose, showCloseButton = false, testID, text, title, titleStyle, variant = "default", }) => {
|
|
12
|
+
const color = (0, useColor_1.useColor)();
|
|
13
|
+
const [tempHeight, setTempHeight] = (0, react_1.useState)(undefined);
|
|
14
|
+
const scaleYAnim = (0, react_1.useRef)(new react_native_1.Animated.Value(0)).current;
|
|
15
|
+
const handleClose = () => {
|
|
16
|
+
react_native_1.Animated.timing(scaleYAnim, {
|
|
17
|
+
toValue: 1,
|
|
18
|
+
duration: 150,
|
|
19
|
+
easing: react_native_1.Easing.linear,
|
|
20
|
+
useNativeDriver: true,
|
|
21
|
+
}).start(() => {
|
|
22
|
+
setTempHeight(0);
|
|
23
|
+
});
|
|
24
|
+
onClose?.();
|
|
25
|
+
};
|
|
26
|
+
return ((0, jsx_runtime_1.jsx)(react_native_1.Animated.View, { testID: testID, style: {
|
|
27
|
+
height: tempHeight,
|
|
28
|
+
transform: [
|
|
29
|
+
{
|
|
30
|
+
scaleY: scaleYAnim.interpolate({
|
|
31
|
+
inputRange: [0, 1],
|
|
32
|
+
outputRange: [1, 0],
|
|
33
|
+
}),
|
|
34
|
+
},
|
|
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 && ((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 }))] }), !!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
|
+
};
|
|
38
|
+
exports.Message = Message;
|
|
39
|
+
const colors = {
|
|
40
|
+
default: {
|
|
41
|
+
background: "black5",
|
|
42
|
+
title: "black100",
|
|
43
|
+
text: "black60",
|
|
44
|
+
},
|
|
45
|
+
info: {
|
|
46
|
+
background: "blue10",
|
|
47
|
+
title: "blue100",
|
|
48
|
+
text: "black100",
|
|
49
|
+
},
|
|
50
|
+
success: {
|
|
51
|
+
background: "green10",
|
|
52
|
+
title: "green150",
|
|
53
|
+
text: "black100",
|
|
54
|
+
},
|
|
55
|
+
alert: {
|
|
56
|
+
background: "orange10",
|
|
57
|
+
title: "orange150",
|
|
58
|
+
text: "black100",
|
|
59
|
+
},
|
|
60
|
+
warning: {
|
|
61
|
+
background: "yellow10",
|
|
62
|
+
title: "yellow150",
|
|
63
|
+
text: "black100",
|
|
64
|
+
},
|
|
65
|
+
error: {
|
|
66
|
+
background: "red10",
|
|
67
|
+
title: "red100",
|
|
68
|
+
text: "black100",
|
|
69
|
+
},
|
|
70
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
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 decorators_1 = require("storybook/decorators");
|
|
6
|
+
const helpers_1 = require("storybook/helpers");
|
|
7
|
+
const Message_1 = require("./Message");
|
|
8
|
+
(0, react_native_1.storiesOf)("Message", module)
|
|
9
|
+
.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("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 {};
|
|
@@ -0,0 +1,28 @@
|
|
|
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 Message_1 = require("./Message");
|
|
6
|
+
const renderWithWrappers_1 = require("../../utils/tests/renderWithWrappers");
|
|
7
|
+
describe("Message", () => {
|
|
8
|
+
it("it renders", () => {
|
|
9
|
+
const MessageComponent = (0, renderWithWrappers_1.renderWithWrappers)((0, jsx_runtime_1.jsx)(Message_1.Message, { variant: "default", title: "title", text: "text" }));
|
|
10
|
+
expect(MessageComponent).toBeTruthy();
|
|
11
|
+
expect(MessageComponent.getByText("title")).toBeDefined();
|
|
12
|
+
expect(MessageComponent.getByText("text")).toBeDefined();
|
|
13
|
+
});
|
|
14
|
+
it("does not show close button when !showCloseButton", () => {
|
|
15
|
+
const { getByTestId } = (0, renderWithWrappers_1.renderWithWrappers)((0, jsx_runtime_1.jsx)(Message_1.Message, { variant: "default", title: "title", text: "text" }));
|
|
16
|
+
expect(() => getByTestId("Message-close-button")).toThrow("Unable to find an element with testID: Message-close-button");
|
|
17
|
+
});
|
|
18
|
+
it("shows close button when showCloseButton", () => {
|
|
19
|
+
const { getByTestId } = (0, renderWithWrappers_1.renderWithWrappers)((0, jsx_runtime_1.jsx)(Message_1.Message, { variant: "default", title: "title", text: "text", showCloseButton: true }));
|
|
20
|
+
expect(getByTestId("Message-close-button")).toBeDefined();
|
|
21
|
+
});
|
|
22
|
+
it("fires onClose press event", () => {
|
|
23
|
+
const onClose = jest.fn();
|
|
24
|
+
const { getByTestId } = (0, renderWithWrappers_1.renderWithWrappers)((0, jsx_runtime_1.jsx)(Message_1.Message, { variant: "default", onClose: onClose, title: "title", text: "text", showCloseButton: true }));
|
|
25
|
+
react_native_1.fireEvent.press(getByTestId("Message-close-button"));
|
|
26
|
+
expect(onClose).toHaveBeenCalled();
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Message";
|
|
@@ -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("./Message"), exports);
|
package/dist/elements/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from "./Checkbox";
|
|
|
10
10
|
export * from "./ClassTheme";
|
|
11
11
|
export * from "./Collapse";
|
|
12
12
|
export * from "./CollapsibleMenuItem";
|
|
13
|
+
export * from "./Dialog";
|
|
13
14
|
export * from "./EntityHeader";
|
|
14
15
|
export * from "./Flex";
|
|
15
16
|
export * from "./Header";
|
|
@@ -17,6 +18,7 @@ export * from "./Histogram";
|
|
|
17
18
|
export * from "./Input";
|
|
18
19
|
export * from "./Join";
|
|
19
20
|
export * from "./List";
|
|
21
|
+
export * from "./Message";
|
|
20
22
|
export * from "./MeasuredView";
|
|
21
23
|
export * from "./MenuItem";
|
|
22
24
|
export * from "./PopIn";
|
package/dist/elements/index.js
CHANGED
|
@@ -26,6 +26,7 @@ __exportStar(require("./Checkbox"), exports);
|
|
|
26
26
|
__exportStar(require("./ClassTheme"), exports);
|
|
27
27
|
__exportStar(require("./Collapse"), exports);
|
|
28
28
|
__exportStar(require("./CollapsibleMenuItem"), exports);
|
|
29
|
+
__exportStar(require("./Dialog"), exports);
|
|
29
30
|
__exportStar(require("./EntityHeader"), exports);
|
|
30
31
|
__exportStar(require("./Flex"), exports);
|
|
31
32
|
__exportStar(require("./Header"), exports);
|
|
@@ -33,6 +34,7 @@ __exportStar(require("./Histogram"), exports);
|
|
|
33
34
|
__exportStar(require("./Input"), exports);
|
|
34
35
|
__exportStar(require("./Join"), exports);
|
|
35
36
|
__exportStar(require("./List"), exports);
|
|
37
|
+
__exportStar(require("./Message"), exports);
|
|
36
38
|
__exportStar(require("./MeasuredView"), exports);
|
|
37
39
|
__exportStar(require("./MenuItem"), exports);
|
|
38
40
|
__exportStar(require("./PopIn"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@artsy/palette-mobile",
|
|
3
|
-
"version": "11.0.
|
|
3
|
+
"version": "11.0.5",
|
|
4
4
|
"description": "Artsy's design system for React Native",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"android": "react-native run-android",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"@babel/runtime": "7.20.13",
|
|
66
66
|
"@react-native-async-storage/async-storage": "1.17.11",
|
|
67
67
|
"@storybook/react-native": "6.0.1-beta.11",
|
|
68
|
-
"@testing-library/jest-native": "5.4.
|
|
68
|
+
"@testing-library/jest-native": "^5.4.2",
|
|
69
69
|
"@testing-library/react-hooks": "8.0.1",
|
|
70
70
|
"@testing-library/react-native": "11.5.1",
|
|
71
71
|
"@tsconfig/react-native": "^2.0.3",
|