@artsy/palette-mobile 11.0.9 → 11.0.10
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.
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import {
|
|
2
|
+
import { TouchableWithoutFeedbackProps } from "react-native";
|
|
3
3
|
import { FlexProps } from "../Flex";
|
|
4
|
-
export interface CheckboxProps extends FlexProps {
|
|
4
|
+
export interface CheckboxProps extends TouchableWithoutFeedbackProps, FlexProps {
|
|
5
5
|
checked?: boolean;
|
|
6
6
|
disabled?: boolean;
|
|
7
7
|
error?: boolean;
|
|
8
|
-
onPress?: TouchableProps["onPress"];
|
|
9
8
|
text?: React.ReactElement | string;
|
|
10
9
|
subtitle?: React.ReactElement | string;
|
|
10
|
+
children?: React.ReactElement | string;
|
|
11
11
|
}
|
|
12
12
|
export declare const Checkbox: React.FC<CheckboxProps>;
|
|
13
|
+
interface CheckMarkProps {
|
|
14
|
+
size: number;
|
|
15
|
+
}
|
|
16
|
+
export declare const CheckMark: ({ size }: CheckMarkProps) => JSX.Element;
|
|
17
|
+
export declare const DisabledMark: import("styled-components").StyledComponent<({ size }: CheckMarkProps) => JSX.Element, any, {}, never>;
|
|
18
|
+
export {};
|
|
@@ -1,105 +1,85 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
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;
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
4
|
};
|
|
25
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.Checkbox = void 0;
|
|
6
|
+
exports.DisabledMark = exports.CheckMark = exports.Checkbox = void 0;
|
|
27
7
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const theme_get_1 = require("@styled-system/theme-get");
|
|
28
9
|
const react_1 = require("react");
|
|
29
10
|
const react_native_1 = require("react-native");
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
const hooks_1 = require("../../utils/hooks");
|
|
11
|
+
const native_1 = __importDefault(require("styled-components/native"));
|
|
12
|
+
const CssTransition_1 = require("../../animation/CssTransition");
|
|
33
13
|
const useTheme_1 = require("../../utils/hooks/useTheme");
|
|
14
|
+
const Box_1 = require("../Box");
|
|
34
15
|
const Flex_1 = require("../Flex");
|
|
35
16
|
const Text_1 = require("../Text");
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
const Checkbox = ({
|
|
17
|
+
const CHECKBOX_SIZE = 20;
|
|
18
|
+
const DURATION = 250;
|
|
19
|
+
const Checkbox = ({ checked: checkedProp, disabled, error, onPress, text, subtitle, children, ...restProps }) => {
|
|
39
20
|
const { color, space } = (0, useTheme_1.useTheme)();
|
|
40
21
|
const fontScale = react_native_1.PixelRatio.getFontScale();
|
|
41
|
-
const checkboxSize =
|
|
42
|
-
const [checked, setChecked] = (0, react_1.useState)(checkedProp
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
22
|
+
const checkboxSize = CHECKBOX_SIZE * fontScale;
|
|
23
|
+
const [checked, setChecked] = (0, react_1.useState)(checkedProp);
|
|
24
|
+
const isChecked = checkedProp ?? checked;
|
|
25
|
+
const defaultCheckboxStyle = {
|
|
26
|
+
backgroundColor: color("white100"),
|
|
27
|
+
borderColor: color("black60"),
|
|
28
|
+
};
|
|
29
|
+
const checkedCheckboxStyle = {
|
|
30
|
+
backgroundColor: color("black100"),
|
|
31
|
+
borderColor: color("black100"),
|
|
32
|
+
};
|
|
33
|
+
const disabledCheckboxStyle = {
|
|
34
|
+
backgroundColor: color("black5"),
|
|
35
|
+
borderColor: color("black10"),
|
|
49
36
|
};
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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.jsxs)(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] })), children] })] }), 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 }) }))] }) }) }));
|
|
37
|
+
const checkboxStyles = {
|
|
38
|
+
default: {
|
|
39
|
+
unchecked: defaultCheckboxStyle,
|
|
40
|
+
checked: checkedCheckboxStyle,
|
|
41
|
+
},
|
|
42
|
+
error: {
|
|
43
|
+
unchecked: { backgroundColor: color("white100"), borderColor: color("red100") },
|
|
44
|
+
checked: checkedCheckboxStyle,
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
const checkboxStyle = disabled
|
|
48
|
+
? disabledCheckboxStyle
|
|
49
|
+
: checkboxStyles[error ? "error" : "default"][isChecked ? "checked" : "unchecked"];
|
|
50
|
+
const textColor = error ? color("red100") : disabled ? color("black30") : color("black100");
|
|
51
|
+
const subtitleColor = error ? color("red100") : color("black30");
|
|
52
|
+
return ((0, jsx_runtime_1.jsx)(react_native_1.TouchableWithoutFeedback, { onPress: (event) => {
|
|
53
|
+
if (disabled) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
setChecked(!checked);
|
|
57
|
+
onPress?.(event);
|
|
58
|
+
}, children: (0, jsx_runtime_1.jsxs)(Flex_1.Flex, { flex: 1, ...restProps, children: [(0, jsx_runtime_1.jsxs)(Flex_1.Flex, { flexDirection: "row", children: [(0, jsx_runtime_1.jsx)(Flex_1.Flex, { mt: "2px", children: (0, jsx_runtime_1.jsx)(CssTransition_1.CssTransition, { style: [
|
|
59
|
+
styles(fontScale).container,
|
|
60
|
+
text || subtitle || children ? { marginRight: space(1) * fontScale } : {},
|
|
61
|
+
checkboxStyle,
|
|
62
|
+
], animate: ["backgroundColor", "borderColor"], duration: DURATION, children: !!isChecked &&
|
|
63
|
+
(!!disabled ? ((0, jsx_runtime_1.jsx)(exports.DisabledMark, { size: checkboxSize })) : ((0, jsx_runtime_1.jsx)(exports.CheckMark, { size: checkboxSize }))) }) }), (0, jsx_runtime_1.jsxs)(Flex_1.Flex, { justifyContent: "center", flex: 1, children: [!!text && ((0, jsx_runtime_1.jsx)(Text_1.Text, { variant: "sm-display", color: textColor, children: text })), children] })] }), !!subtitle && ((0, jsx_runtime_1.jsx)(Flex_1.Flex, { ml: `${(CHECKBOX_SIZE + space(1)) * fontScale}px`, mt: "6px", children: (0, jsx_runtime_1.jsx)(Text_1.Text, { variant: "xs", color: subtitleColor, children: subtitle }) }))] }) }));
|
|
91
64
|
};
|
|
92
65
|
exports.Checkbox = Checkbox;
|
|
93
|
-
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
66
|
+
// styled-component does not have support for Animated.View
|
|
67
|
+
const styles = (fontScale) => react_native_1.StyleSheet.create({
|
|
68
|
+
container: {
|
|
69
|
+
display: "flex",
|
|
70
|
+
justifyContent: "center",
|
|
71
|
+
alignItems: "center",
|
|
72
|
+
borderWidth: 1,
|
|
73
|
+
borderStyle: "solid",
|
|
74
|
+
width: CHECKBOX_SIZE * fontScale,
|
|
75
|
+
height: CHECKBOX_SIZE * fontScale,
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
// This component represents the √ mark in CSS. We are not using styled-system since it's easier to specify raw CSS
|
|
79
|
+
// properties with styled-component.
|
|
80
|
+
const CheckMark = ({ size }) => ((0, jsx_runtime_1.jsx)(Box_1.Box, { style: { transform: [{ rotate: "-45deg" }] }, top: "-12%", width: size * 0.625, height: size * 0.3125, borderBottomWidth: "2px", borderBottomColor: "white100", borderLeftWidth: "2px", borderLeftColor: "white100" }));
|
|
81
|
+
exports.CheckMark = CheckMark;
|
|
82
|
+
exports.DisabledMark = (0, native_1.default)(exports.CheckMark) `
|
|
83
|
+
border-bottom-color: ${(0, theme_get_1.themeGet)("colors.black30")};
|
|
84
|
+
border-left-color: ${(0, theme_get_1.themeGet)("colors.black30")};
|
|
85
|
+
`;
|