@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 { TouchableProps } from "../../elements";
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 __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;
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 react_native_reanimated_1 = __importStar(require("react-native-reanimated"));
31
- const elements_1 = require("../../elements");
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 CHECKBOX_SIZEx1 = 20;
37
- const ANIMATION_DURATION = 250;
38
- const Checkbox = ({ children, checked: checkedProp, disabled = false, error = false, onPress, text, subtitle, ...flexProps }) => {
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 = CHECKBOX_SIZEx1 * fontScale;
42
- const [checked, setChecked] = (0, react_1.useState)(checkedProp ?? false);
43
- const [displayState, setDisplayState] = (0, react_1.useState)("unpressed");
44
- const containerColor = {
45
- unchecked: { border: color("black100"), background: color("white100") },
46
- error: { border: color("red100"), background: color("white100") },
47
- checked: { border: color("black100"), background: color("black100") },
48
- disabled: { border: color("black30"), background: color("black30") },
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 toggleProgress = (0, react_native_reanimated_1.useDerivedValue)(() => (0, react_native_reanimated_1.withTiming)(checked ? 1 : 0, { duration: ANIMATION_DURATION }));
51
- const toggleAnim = (0, react_native_reanimated_1.useAnimatedStyle)(() => ({
52
- backgroundColor: (0, react_native_reanimated_1.interpolateColor)(toggleProgress.value, [0, 1], [
53
- containerColor.unchecked.background,
54
- disabled ? containerColor.disabled.background : containerColor.checked.background,
55
- ]),
56
- borderColor: (0, react_native_reanimated_1.interpolateColor)(toggleProgress.value, [0, 1], [
57
- error
58
- ? containerColor.error.border
59
- : disabled
60
- ? containerColor.disabled.border
61
- : containerColor.unchecked.border,
62
- disabled ? containerColor.disabled.border : containerColor.checked.border,
63
- ]),
64
- }), [toggleProgress]);
65
- const pressedStateProgress = (0, react_native_reanimated_1.useDerivedValue)(() => (0, react_native_reanimated_1.withTiming)(displayState === "pressed" ? 1 : 0, { duration: ANIMATION_DURATION }));
66
- const textColor = color(error ? "red100" : disabled ? "onBackgroundLow" : "onBackgroundHigh");
67
- const pressedTextColor = color("brand");
68
- const pressAnim = (0, react_native_reanimated_1.useAnimatedStyle)(() => ({
69
- color: (0, react_native_reanimated_1.interpolateColor)(pressedStateProgress.value, [0, 1], [textColor, pressedTextColor]),
70
- }), [pressedStateProgress]);
71
- const subtitleColor = error
72
- ? "red100"
73
- : disabled
74
- ? "onBackgroundLow"
75
- : "onBackgroundMedium";
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.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
- const AnimatedText = react_native_reanimated_1.default.createAnimatedComponent(Text_1.Text);
94
- const Checkmark = ({ size }) => {
95
- const color = (0, hooks_1.useColor)();
96
- return ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: {
97
- width: size * 0.625,
98
- height: size * 0.3125,
99
- borderColor: color("white100"),
100
- borderBottomWidth: 2,
101
- borderLeftWidth: 2,
102
- transform: [{ rotate: "-45deg" }],
103
- top: -2,
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
+ `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@artsy/palette-mobile",
3
- "version": "11.0.9",
3
+ "version": "11.0.10",
4
4
  "description": "Artsy's design system for React Native",
5
5
  "scripts": {
6
6
  "android": "react-native run-android",