@artsy/palette-mobile 13.1.13 → 13.1.14
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/Switch/Switch.d.ts +25 -0
- package/dist/elements/Switch/Switch.js +25 -0
- package/dist/elements/Switch/Switch.stories.d.ts +7 -0
- package/dist/elements/Switch/Switch.stories.js +26 -0
- package/dist/elements/Switch/index.d.ts +1 -0
- package/dist/elements/Switch/index.js +17 -0
- package/package.json +1 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Color } from "@artsy/palette-tokens";
|
|
3
|
+
import { SwitchProps as RNSwitchProps } from "react-native";
|
|
4
|
+
type CustomSwitchProps = Omit<RNSwitchProps, "onValueChange" | "onChange" | "trackColor" | "thumbColor" | "ios_backgroundColor" | "thumbTintColor" | "tintColor" | "onTintColor">;
|
|
5
|
+
export interface SwitchProps extends CustomSwitchProps {
|
|
6
|
+
onChange: (value: boolean) => void | Promise<void>;
|
|
7
|
+
/**
|
|
8
|
+
* The circular thumb's color on the 'ON' switch.
|
|
9
|
+
*/
|
|
10
|
+
thumbColorActive?: Color;
|
|
11
|
+
/**
|
|
12
|
+
* The circular thumb's color on the 'OFF' switch.
|
|
13
|
+
*/
|
|
14
|
+
thumbColorInactive?: Color;
|
|
15
|
+
/**
|
|
16
|
+
* The background's color on the 'ON' switch.
|
|
17
|
+
*/
|
|
18
|
+
trackColorActive?: Color;
|
|
19
|
+
/**
|
|
20
|
+
* The background's color on the 'OFF' switch.
|
|
21
|
+
*/
|
|
22
|
+
trackColorInactive?: Color;
|
|
23
|
+
}
|
|
24
|
+
export declare const Switch: ({ value, onChange, thumbColorActive, thumbColorInactive, trackColorActive, trackColorInactive, disabled, ...restProps }: SwitchProps) => JSX.Element;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Switch = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_native_1 = require("react-native");
|
|
6
|
+
const hooks_1 = require("../../utils/hooks");
|
|
7
|
+
const Switch = ({ value, onChange, thumbColorActive = react_native_1.Platform.OS === "ios" ? "white100" : "blue100", thumbColorInactive = react_native_1.Platform.OS === "ios" ? "white100" : "black10", trackColorActive = react_native_1.Platform.OS === "ios" ? "blue100" : "blue10", trackColorInactive = "black30", disabled, ...restProps }) => {
|
|
8
|
+
const color = (0, hooks_1.useColor)();
|
|
9
|
+
let thumbColor = value ? color(thumbColorActive) : color(thumbColorInactive);
|
|
10
|
+
let trackColor = {
|
|
11
|
+
false: color(trackColorInactive),
|
|
12
|
+
true: color(trackColorActive),
|
|
13
|
+
};
|
|
14
|
+
let iosBackground = color(trackColorInactive);
|
|
15
|
+
if (disabled) {
|
|
16
|
+
thumbColor = react_native_1.Platform.OS === "ios" ? color("white100") : color("black30");
|
|
17
|
+
trackColor = {
|
|
18
|
+
false: color("black10"),
|
|
19
|
+
true: color("black10"),
|
|
20
|
+
};
|
|
21
|
+
iosBackground = color("black10");
|
|
22
|
+
}
|
|
23
|
+
return ((0, jsx_runtime_1.jsx)(react_native_1.Switch, { accessibilityRole: "switch", value: value, disabled: disabled, onValueChange: onChange, thumbColor: thumbColor, trackColor: trackColor, ios_backgroundColor: iosBackground, ...restProps }));
|
|
24
|
+
};
|
|
25
|
+
exports.Switch = Switch;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
declare const _default: {
|
|
3
|
+
title: string;
|
|
4
|
+
component: ({ value, onChange, thumbColorActive, thumbColorInactive, trackColorActive, trackColorInactive, disabled, ...restProps }: import("./Switch").SwitchProps) => JSX.Element;
|
|
5
|
+
};
|
|
6
|
+
export default _default;
|
|
7
|
+
export declare const Variants: () => JSX.Element;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Variants = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const Switch_1 = require("./Switch");
|
|
7
|
+
const helpers_1 = require("../../storybook/helpers");
|
|
8
|
+
const Flex_1 = require("../Flex");
|
|
9
|
+
const Text_1 = require("../Text");
|
|
10
|
+
exports.default = {
|
|
11
|
+
title: "Switch",
|
|
12
|
+
component: Switch_1.Switch,
|
|
13
|
+
};
|
|
14
|
+
const Variants = () => {
|
|
15
|
+
const [switches, setSwitches] = (0, react_1.useState)([
|
|
16
|
+
{ id: 1, label: "Default colors", value: true },
|
|
17
|
+
{ id: 2, label: "disabled", value: false },
|
|
18
|
+
{ id: 3, label: "Custom #1", value: true },
|
|
19
|
+
{ id: 4, label: "Custom #2", value: false },
|
|
20
|
+
]);
|
|
21
|
+
const handleSwitchChange = (id) => {
|
|
22
|
+
setSwitches((prevSwitches) => prevSwitches.map((sw) => (sw.id === id ? { ...sw, value: !sw.value } : sw)));
|
|
23
|
+
};
|
|
24
|
+
return ((0, jsx_runtime_1.jsxs)(helpers_1.List, { children: [(0, jsx_runtime_1.jsxs)(Flex_1.Flex, { width: 200, flexDirection: "row", justifyContent: "space-between", children: [(0, jsx_runtime_1.jsx)(Text_1.Text, { children: "Default State" }), (0, jsx_runtime_1.jsx)(Switch_1.Switch, { value: switches[0].value, onChange: () => handleSwitchChange(1) })] }), (0, jsx_runtime_1.jsxs)(Flex_1.Flex, { width: 200, flexDirection: "row", justifyContent: "space-between", children: [(0, jsx_runtime_1.jsx)(Text_1.Text, { children: "Disabled" }), (0, jsx_runtime_1.jsx)(Switch_1.Switch, { disabled: true, value: switches[1].value, onChange: () => handleSwitchChange(2) })] }), (0, jsx_runtime_1.jsxs)(Flex_1.Flex, { width: 200, flexDirection: "row", justifyContent: "space-between", children: [(0, jsx_runtime_1.jsx)(Text_1.Text, { children: "Custom Colors 1" }), (0, jsx_runtime_1.jsx)(Switch_1.Switch, { value: switches[2].value, onChange: () => handleSwitchChange(3), trackColorActive: "red100", trackColorInactive: "green100", thumbColorActive: "yellow100", thumbColorInactive: "orange100" })] }), (0, jsx_runtime_1.jsxs)(Flex_1.Flex, { width: 200, flexDirection: "row", justifyContent: "space-between", children: [(0, jsx_runtime_1.jsx)(Text_1.Text, { children: "Custom Colors 2" }), (0, jsx_runtime_1.jsx)(Switch_1.Switch, { value: switches[3].value, onChange: () => handleSwitchChange(4), thumbColorActive: "yellow100", trackColorActive: "blue100", thumbColorInactive: "white100", trackColorInactive: "red100" })] })] }));
|
|
25
|
+
};
|
|
26
|
+
exports.Variants = Variants;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Switch";
|
|
@@ -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("./Switch"), exports);
|