atlas-design-system 1.8.1 → 1.9.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.
@@ -1,12 +1,7 @@
1
1
  import React from "react";
2
2
  import { StyleProp, ViewStyle } from "react-native";
3
- export declare enum ButtonType {
4
- Primary = 0,
5
- Destructive = 1
6
- }
7
3
  export interface ButtonProps {
8
4
  disabled?: boolean;
9
- type?: ButtonType;
10
5
  onPress?: () => void;
11
6
  text: string;
12
7
  loading?: boolean;
@@ -14,5 +9,5 @@ export interface ButtonProps {
14
9
  containerStyle?: StyleProp<ViewStyle>;
15
10
  appearance?: "primary" | "secondary" | "destructive";
16
11
  }
17
- export declare const Button: ({ testID, disabled, onPress, text, loading, containerStyle, appearance, type, }: ButtonProps) => React.JSX.Element;
12
+ export declare const Button: ({ testID, disabled, onPress, text, loading, containerStyle, appearance, }: ButtonProps) => React.JSX.Element;
18
13
  export default Button;
@@ -1,70 +1,17 @@
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;
24
- };
25
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
4
  };
28
5
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.Button = exports.ButtonType = void 0;
30
- const react_1 = __importStar(require("react"));
6
+ exports.Button = void 0;
7
+ const react_1 = __importDefault(require("react"));
31
8
  const react_native_1 = require("react-native");
32
9
  const ButtonStyle_1 = require("./styles/ButtonStyle");
33
10
  const Text_1 = __importDefault(require("../Text"));
34
- var ButtonType;
35
- (function (ButtonType) {
36
- ButtonType[ButtonType["Primary"] = 0] = "Primary";
37
- ButtonType[ButtonType["Destructive"] = 1] = "Destructive";
38
- })(ButtonType || (exports.ButtonType = ButtonType = {}));
39
- const getButtonStyle = (styles, appearance, disabled) => {
40
- const style = [styles.primary];
41
- if (appearance === "secondary") {
42
- style.push(styles.secondary);
43
- }
44
- if (appearance === "destructive") {
45
- style.push(styles.destructive);
46
- }
47
- if (disabled) {
48
- style.push(styles.disabled);
49
- }
50
- return style;
51
- };
52
- const Button = ({ testID, disabled = false, onPress, text, loading, containerStyle = {}, appearance = "primary", type, }) => {
53
- const { styles, theme } = (0, ButtonStyle_1.useButtonStyles)();
54
- const buttonStyle = (0, react_1.useMemo)(() => {
55
- let _apperance = appearance;
56
- if (type) {
57
- _apperance = type === ButtonType.Destructive ? "destructive" : "primary";
58
- }
59
- return getButtonStyle({
60
- disabled: styles.disabled,
61
- primary: styles.default,
62
- destructive: styles.destructiveContainer,
63
- secondary: styles.secondary,
64
- }, _apperance, disabled);
65
- }, [styles, appearance, disabled, type]);
66
- return (<react_native_1.TouchableOpacity testID={testID} style={[buttonStyle, disabled && styles.disabled, containerStyle]} onPress={onPress} disabled={disabled || loading}>
67
- {loading ? (<react_native_1.ActivityIndicator size="small" color={theme.colors.foregroundOnPrimary}/>) : (<Text_1.default category="h3" style={[styles.defaultText, disabled && styles.disabledText]}>
11
+ const Button = ({ testID, disabled = false, onPress, text, loading, containerStyle = {}, appearance = "primary", }) => {
12
+ const { buttonStyle, styles, textStyle } = (0, ButtonStyle_1.useButtonStyles)(appearance, disabled);
13
+ return (<react_native_1.TouchableOpacity testID={testID} style={[buttonStyle, containerStyle]} onPress={onPress} disabled={disabled || loading}>
14
+ {loading ? (<react_native_1.ActivityIndicator size="small" color={styles.loadingIndicator.color}/>) : (<Text_1.default category="h3" style={textStyle}>
68
15
  {text}
69
16
  </Text_1.default>)}
70
17
  </react_native_1.TouchableOpacity>);
@@ -1,5 +1,7 @@
1
- export declare const useButtonStyles: () => {
2
- theme: import("../../..").AtlasTheme;
1
+ import { StyleProp, TextStyle, ViewStyle } from "react-native";
2
+ import { ButtonProps } from "../Button";
3
+ import { AtlasTheme } from "../../../types";
4
+ export declare const useButtonStyles: (appearance?: ButtonProps["appearance"], disabled?: boolean, themeOverride?: AtlasTheme) => {
3
5
  styles: {
4
6
  default: {
5
7
  borderRadius: number;
@@ -34,5 +36,10 @@ export declare const useButtonStyles: () => {
34
36
  disabledText: {
35
37
  color: string;
36
38
  };
39
+ loadingIndicator: {
40
+ color: string;
41
+ };
37
42
  };
43
+ buttonStyle: StyleProp<ViewStyle>[];
44
+ textStyle: StyleProp<TextStyle>[];
38
45
  };
@@ -4,39 +4,83 @@ exports.useButtonStyles = void 0;
4
4
  const react_native_1 = require("react-native");
5
5
  const react_1 = require("react");
6
6
  const hooks_1 = require("../../../hooks");
7
- const useButtonStyles = () => (0, hooks_1.useThemedStyle)((0, react_1.useCallback)(theme => react_native_1.StyleSheet.create({
8
- default: {
9
- borderRadius: theme.borderRadius,
10
- justifyContent: 'center',
11
- backgroundColor: theme.colors.primary,
12
- paddingHorizontal: theme.size.baseSize * 4,
13
- paddingVertical: theme.size.baseSize * 2,
14
- textAlign: 'center',
15
- },
16
- secondary: {
17
- backgroundColor: theme.colors.foregroundLowContrast,
18
- },
19
- destructiveContainer: {
20
- borderRadius: theme.borderRadius,
21
- justifyContent: 'center',
22
- paddingHorizontal: theme.size.baseSize * 4,
23
- paddingVertical: theme.size.baseSize * 2,
24
- textAlign: 'center',
25
- backgroundColor: theme.colors.secondaryNegative,
26
- },
27
- destructiveText: {
28
- textAlign: 'center',
29
- color: theme.colors.backgroundPrimary,
30
- },
31
- defaultText: {
32
- textAlign: 'center',
33
- color: theme.colors.foregroundOnPrimary,
34
- },
35
- disabled: {
36
- backgroundColor: theme.colors.primaryLowContrast,
37
- },
38
- disabledText: {
39
- color: theme.colors.foregroundOnPrimary,
40
- },
41
- }), []));
7
+ const getButtonStyle = (styles, appearance, disabled) => {
8
+ const style = [styles.primary];
9
+ if (appearance === "secondary") {
10
+ style.push(styles.secondary);
11
+ }
12
+ if (appearance === "destructive") {
13
+ style.push(styles.destructive);
14
+ }
15
+ if (disabled) {
16
+ style.push(styles.disabled);
17
+ }
18
+ return style;
19
+ };
20
+ const getButtonTextStyle = (styles, appearance, disabled) => {
21
+ const style = [styles.primary];
22
+ if (disabled) {
23
+ style.push(styles.disabled);
24
+ }
25
+ return style;
26
+ };
27
+ const useButtonStyles = (appearance = "primary", disabled = false, themeOverride) => {
28
+ const styles = (0, hooks_1.useThemedStyle)((0, react_1.useCallback)((t) => {
29
+ const theme = t;
30
+ if (themeOverride) {
31
+ t = themeOverride;
32
+ }
33
+ return react_native_1.StyleSheet.create({
34
+ default: {
35
+ borderRadius: theme.borderRadius,
36
+ justifyContent: "center",
37
+ backgroundColor: theme.colors.primary,
38
+ paddingHorizontal: theme.size.baseSize * 4,
39
+ paddingVertical: theme.size.baseSize * 2,
40
+ textAlign: "center",
41
+ },
42
+ secondary: {
43
+ backgroundColor: theme.colors.foregroundLowContrast,
44
+ },
45
+ destructiveContainer: {
46
+ borderRadius: theme.borderRadius,
47
+ justifyContent: "center",
48
+ paddingHorizontal: theme.size.baseSize * 4,
49
+ paddingVertical: theme.size.baseSize * 2,
50
+ textAlign: "center",
51
+ backgroundColor: theme.colors.secondaryNegative,
52
+ },
53
+ destructiveText: {
54
+ textAlign: "center",
55
+ color: theme.colors.backgroundPrimary,
56
+ },
57
+ defaultText: {
58
+ textAlign: "center",
59
+ color: theme.colors.foregroundOnPrimary,
60
+ },
61
+ disabled: {
62
+ backgroundColor: theme.colors.primaryLowContrast,
63
+ },
64
+ disabledText: {
65
+ color: theme.colors.foregroundOnPrimary,
66
+ },
67
+ loadingIndicator: {
68
+ color: theme.colors.foregroundOnPrimary,
69
+ },
70
+ });
71
+ }, [themeOverride])).styles;
72
+ const buttonStyle = (0, react_1.useMemo)(() => {
73
+ return getButtonStyle({
74
+ disabled: styles.disabled,
75
+ primary: styles.default,
76
+ destructive: styles.destructiveContainer,
77
+ secondary: styles.secondary,
78
+ }, appearance, disabled);
79
+ }, [styles, appearance, disabled]);
80
+ const textStyle = (0, react_1.useMemo)(() => getButtonTextStyle({
81
+ disabled: styles.disabledText,
82
+ primary: styles.defaultText,
83
+ }, appearance, disabled), [styles, appearance, disabled]);
84
+ return { styles, buttonStyle, textStyle };
85
+ };
42
86
  exports.useButtonStyles = useButtonStyles;
@@ -7,7 +7,7 @@ export type SelectInputProps<T> = {
7
7
  options: Option<T>[];
8
8
  onChange: (newValue: Option<T>) => void;
9
9
  error?: string;
10
- renderOption?: (option: Option<T>) => React.ReactNode;
10
+ renderOption?: (option: Option<T>, onPress: (option: Option<T>) => void) => React.ReactNode;
11
11
  containerStyle?: StyleProp<ViewStyle>;
12
12
  };
13
13
  export declare function SelectInput<T>({ caption, label, options, onChange, error, renderOption, containerStyle, }: SelectInputProps<T>): React.JSX.Element;
@@ -83,10 +83,10 @@ function SelectInput({ caption, label, options = [], onChange, error, renderOpti
83
83
  ],
84
84
  };
85
85
  }, [rotation]);
86
- const handleOptionPress = (option) => {
86
+ const handleOptionPress = (0, react_1.useCallback)((option) => {
87
87
  onChange(option);
88
88
  setSheetOpen(false);
89
- };
89
+ }, []);
90
90
  return (<react_native_1.View style={containerStyle}>
91
91
  <react_native_1.TouchableOpacity onPress={() => setSheetOpen(true)}>
92
92
  <react_native_reanimated_1.default.View style={[styles.itemContainer, animatedBorderStyle]}>
@@ -107,9 +107,9 @@ function SelectInput({ caption, label, options = [], onChange, error, renderOpti
107
107
  </react_native_1.TouchableOpacity>
108
108
  {!!caption && <MenuItemDescription_1.MenuItemDescription description={caption}/>}
109
109
  <Sheet_1.default open={sheetOpen} setOpen={setSheetOpen} header={label}>
110
- {options.map((option, i) => (<react_native_1.TouchableOpacity onPress={() => handleOptionPress(option)} key={i + option.label}>
111
- {renderOption ? (renderOption(option)) : (<SelectionItem_1.default option={option}/>)}
112
- </react_native_1.TouchableOpacity>))}
110
+ {options.map((option, i) => renderOption ? (renderOption(option, handleOptionPress)) : (<react_native_1.TouchableOpacity onPress={() => handleOptionPress(option)} key={i + option.label}>
111
+ <SelectionItem_1.default option={option}/>
112
+ </react_native_1.TouchableOpacity>))}
113
113
  </Sheet_1.default>
114
114
  </react_native_1.View>);
115
115
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "atlas-design-system",
3
- "version": "1.8.1",
3
+ "version": "1.9.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",