atlas-design-system 1.6.2 → 1.8.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.
@@ -0,0 +1,8 @@
1
+ import { FieldProps } from "informed";
2
+ import { SegmentedControlProps } from "../../SegmentedControl";
3
+ import { Option } from "../../SelectInput/types";
4
+ type FormSegmentedControlProps<T> = Omit<SegmentedControlProps<T>, "options"> & {
5
+ options: Omit<Option<T>, "selected">[];
6
+ };
7
+ export declare function FormSegmentedControl<T>(props: FieldProps<FormSegmentedControlProps<T>>): JSX.Element;
8
+ export {};
@@ -0,0 +1,23 @@
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
+ exports.FormSegmentedControl = FormSegmentedControl;
7
+ const informed_1 = require("informed");
8
+ const SegmentedControl_1 = __importDefault(require("../../SegmentedControl"));
9
+ const react_1 = require("react");
10
+ function FormSegmentedControl(props) {
11
+ const { render, userProps, fieldApi, informed, fieldState } = (0, informed_1.useField)(Object.assign({}, props));
12
+ const { value } = informed;
13
+ const options = (0, react_1.useMemo)(() => {
14
+ return userProps.options.map((v) => {
15
+ return Object.assign(Object.assign({}, v), { selected: v.value === value });
16
+ });
17
+ }, [userProps.options, value]);
18
+ return render(<SegmentedControl_1.default onChange={(v) => {
19
+ fieldApi.setValue(v.value);
20
+ }}
21
+ //@ts-expect-error no types yet :(
22
+ error={fieldState.error} {...userProps} options={options}/>);
23
+ }
@@ -0,0 +1 @@
1
+ export * from './FormSegmentedControl';
@@ -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("./FormSegmentedControl"), exports);
@@ -1,3 +1,9 @@
1
1
  import { FieldProps } from "informed";
2
- import { SelectInputProps } from '../../SelectInput';
3
- export declare function FormSelectInput<T>(props: FieldProps<SelectInputProps<T>>): JSX.Element;
2
+ import { SelectInputProps } from "../../SelectInput";
3
+ import { Option } from "../../SelectInput/types";
4
+ type FormSelectInputProps<T> = Omit<SelectInputProps<T>, "options"> & {
5
+ options: Omit<Option<T>, "selected">[];
6
+ };
7
+ type Props<T> = FieldProps<FormSelectInputProps<T>>;
8
+ export declare function FormSelectInput<T>(props: Props<T>): JSX.Element;
9
+ export {};
@@ -3,3 +3,4 @@ export * from './FormSwitchToggle';
3
3
  export * from './FormTextInput';
4
4
  export * from './FormDateTimeInput';
5
5
  export * from './FormSelectInput';
6
+ export * from './FormSegmentedControl';
@@ -19,3 +19,4 @@ __exportStar(require("./FormSwitchToggle"), exports);
19
19
  __exportStar(require("./FormTextInput"), exports);
20
20
  __exportStar(require("./FormDateTimeInput"), exports);
21
21
  __exportStar(require("./FormSelectInput"), exports);
22
+ __exportStar(require("./FormSegmentedControl"), exports);
@@ -0,0 +1,11 @@
1
+ import { Option } from "../SelectInput/types";
2
+ export type SegmentedControlProps<T> = {
3
+ label: string;
4
+ options: Option<T>[];
5
+ silenceWarning?: boolean;
6
+ error?: string;
7
+ caption?: string;
8
+ onChange: (newValue: Option<T>) => void;
9
+ };
10
+ export declare function SegmentedControl<T>({ label, options, silenceWarning, error, caption, onChange, }: SegmentedControlProps<T>): import("react").JSX.Element;
11
+ export default SegmentedControl;
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SegmentedControl = SegmentedControl;
4
+ const react_native_1 = require("react-native");
5
+ const Text_1 = require("../Text");
6
+ const hooks_1 = require("../../hooks");
7
+ const react_1 = require("react");
8
+ const FieldError_1 = require("../FieldError/FieldError");
9
+ const MenuItemDescription_1 = require("../MenuItemDescription");
10
+ function SegmentedControl({ label, options = [], silenceWarning, error, caption, onChange, }) {
11
+ const styles = useStyles().styles;
12
+ if (options.length > 4 && !silenceWarning) {
13
+ console.warn("SegmentedControl should have 4 or fewer options, consider using a SelectInput instead");
14
+ }
15
+ return (<react_native_1.View style={styles.container}>
16
+ <Text_1.Text numberOfLines={1}>{label}</Text_1.Text>
17
+ <react_native_1.View style={styles.contentContainer}>
18
+ {!options.length && <Text_1.Text>No options</Text_1.Text>}
19
+ {options.map((option, index, list) => {
20
+ const optionStyle = [styles.optionContainer];
21
+ if (index === 0) {
22
+ optionStyle.push(styles.firstOptionContainer);
23
+ }
24
+ if (index === list.length - 1) {
25
+ optionStyle.push(styles.lastOptionContainer);
26
+ }
27
+ if (option.selected) {
28
+ optionStyle.push(styles.selectedOptionContainer);
29
+ }
30
+ return (<react_native_1.Pressable onPress={() => {
31
+ onChange(option);
32
+ }} style={optionStyle} key={option.value + option.label}>
33
+ <Text_1.Text style={option.selected ? styles.selectedOptionText : undefined}>
34
+ {option.label}
35
+ </Text_1.Text>
36
+ </react_native_1.Pressable>);
37
+ })}
38
+ </react_native_1.View>
39
+ {!!error && <FieldError_1.FieldError error={error}/>}
40
+ {!!caption && <MenuItemDescription_1.MenuItemDescription description={caption}/>}
41
+ </react_native_1.View>);
42
+ }
43
+ exports.default = SegmentedControl;
44
+ function scaleBorderRadius(originalRadius, originalSize, newSize) {
45
+ if (originalSize === 0) {
46
+ throw new Error("Original size cannot be zero.");
47
+ }
48
+ const scalingFactor = newSize / originalSize;
49
+ const newRadius = originalRadius * scalingFactor;
50
+ return newRadius;
51
+ }
52
+ const useStyles = () => (0, hooks_1.useThemedStyle)((0, react_1.useCallback)((t) => react_native_1.StyleSheet.create({
53
+ container: {},
54
+ contentContainer: {
55
+ marginTop: t.size.baseSize,
56
+ flexDirection: "row",
57
+ backgroundColor: t.colors.backgroundOnPrimary,
58
+ height: t.size.baseSize * 9,
59
+ borderRadius: t.borderRadius,
60
+ alignItems: "center",
61
+ justifyContent: "center",
62
+ columnGap: t.borderWidth * 2,
63
+ },
64
+ optionContainer: {
65
+ flex: 1,
66
+ backgroundColor: `${t.colors.backgroundPrimary}90`,
67
+ borderRadius: scaleBorderRadius(t.borderRadius, t.size.baseSize * 9, t.size.baseSize * 7.5),
68
+ height: t.size.baseSize * 7.5,
69
+ justifyContent: "center",
70
+ alignItems: "center",
71
+ // borderWidth: t.borderWidth,
72
+ // borderColor: t.colors.backgroundOnPrimary,
73
+ },
74
+ firstOptionContainer: {
75
+ marginLeft: t.borderWidth * 2,
76
+ },
77
+ lastOptionContainer: {
78
+ marginRight: t.borderWidth * 2,
79
+ },
80
+ selectedOptionContainer: {
81
+ backgroundColor: t.colors.primary,
82
+ // borderWidth: t.borderWidth,
83
+ borderColor: t.colors.primary,
84
+ },
85
+ selectedOptionText: {
86
+ color: t.colors.foregroundOnPrimary,
87
+ },
88
+ }), []));
@@ -0,0 +1,2 @@
1
+ export * from "./SegmentedControl";
2
+ export { default } from "./SegmentedControl";
@@ -0,0 +1,23 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.default = void 0;
21
+ __exportStar(require("./SegmentedControl"), exports);
22
+ var SegmentedControl_1 = require("./SegmentedControl");
23
+ Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(SegmentedControl_1).default; } });
@@ -10,4 +10,5 @@ export * from "./DragHandle";
10
10
  export * from "./TitleBar";
11
11
  export * from "./SelectInput";
12
12
  export * from "./Search";
13
+ export * from "./SegmentedControl";
13
14
  export * from "./Forms";
@@ -26,5 +26,6 @@ __exportStar(require("./DragHandle"), exports);
26
26
  __exportStar(require("./TitleBar"), exports);
27
27
  __exportStar(require("./SelectInput"), exports);
28
28
  __exportStar(require("./Search"), exports);
29
+ __exportStar(require("./SegmentedControl"), exports);
29
30
  // Forms
30
31
  __exportStar(require("./Forms"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "atlas-design-system",
3
- "version": "1.6.2",
3
+ "version": "1.8.0",
4
4
  "description": "A react native design system for the Atlas workout app",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",