atlas-design-system 1.2.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.
Files changed (98) hide show
  1. package/.eslintrc.js +33 -0
  2. package/README.md +5 -0
  3. package/example/README.md +50 -0
  4. package/example/app/_layout.tsx +32 -0
  5. package/example/app/buttonGallery.tsx +49 -0
  6. package/example/app/dateTimeInputGallery.tsx +28 -0
  7. package/example/app/index.tsx +58 -0
  8. package/example/app/selectInputGallery.tsx +45 -0
  9. package/example/app/sheetGallery.tsx +36 -0
  10. package/example/app/switchToggleInputGallery.tsx +28 -0
  11. package/example/app/textGallery.tsx +68 -0
  12. package/example/app/textInputGallery.tsx +28 -0
  13. package/example/app.json +37 -0
  14. package/example/assets/fonts/SpaceMono-Regular.ttf +0 -0
  15. package/example/assets/images/adaptive-icon.png +0 -0
  16. package/example/assets/images/favicon.png +0 -0
  17. package/example/assets/images/icon.png +0 -0
  18. package/example/assets/images/partial-react-logo.png +0 -0
  19. package/example/assets/images/react-logo.png +0 -0
  20. package/example/assets/images/react-logo@2x.png +0 -0
  21. package/example/assets/images/react-logo@3x.png +0 -0
  22. package/example/assets/images/splash.png +0 -0
  23. package/example/babel.config.js +6 -0
  24. package/example/components/Collapsible.tsx +41 -0
  25. package/example/components/ExternalLink.tsx +24 -0
  26. package/example/components/ParallaxScrollView.tsx +76 -0
  27. package/example/components/ThemedText.tsx +60 -0
  28. package/example/components/ThemedView.tsx +14 -0
  29. package/example/components/__tests__/ThemedText-test.tsx +10 -0
  30. package/example/components/__tests__/__snapshots__/ThemedText-test.tsx.snap +24 -0
  31. package/example/components/navigation/TabBarIcon.js +24 -0
  32. package/example/components/navigation/TabBarIcon.tsx +9 -0
  33. package/example/constants/Colors.ts +26 -0
  34. package/example/hooks/useColorScheme.ts +1 -0
  35. package/example/hooks/useThemeColor.ts +22 -0
  36. package/example/ios/.xcode.env +11 -0
  37. package/example/ios/Podfile +58 -0
  38. package/example/ios/Podfile.lock +1603 -0
  39. package/example/ios/Podfile.properties.json +4 -0
  40. package/example/ios/example/AppDelegate.h +7 -0
  41. package/example/ios/example/AppDelegate.mm +62 -0
  42. package/example/ios/example/Images.xcassets/AppIcon.appiconset/App-Icon-1024x1024@1x.png +0 -0
  43. package/example/ios/example/Images.xcassets/AppIcon.appiconset/Contents.json +14 -0
  44. package/example/ios/example/Images.xcassets/Contents.json +6 -0
  45. package/example/ios/example/Images.xcassets/SplashScreen.imageset/Contents.json +21 -0
  46. package/example/ios/example/Images.xcassets/SplashScreen.imageset/image.png +0 -0
  47. package/example/ios/example/Images.xcassets/SplashScreenBackground.imageset/Contents.json +21 -0
  48. package/example/ios/example/Images.xcassets/SplashScreenBackground.imageset/image.png +0 -0
  49. package/example/ios/example/Info.plist +81 -0
  50. package/example/ios/example/PrivacyInfo.xcprivacy +48 -0
  51. package/example/ios/example/SplashScreen.storyboard +51 -0
  52. package/example/ios/example/Supporting/Expo.plist +12 -0
  53. package/example/ios/example/example-Bridging-Header.h +3 -0
  54. package/example/ios/example/example.entitlements +5 -0
  55. package/example/ios/example/main.m +10 -0
  56. package/example/ios/example/noop-file.swift +4 -0
  57. package/example/ios/example.xcodeproj/project.pbxproj +555 -0
  58. package/example/ios/example.xcodeproj/xcshareddata/xcschemes/example.xcscheme +88 -0
  59. package/example/ios/example.xcworkspace/contents.xcworkspacedata +10 -0
  60. package/example/metro.config.js +34 -0
  61. package/example/package.json +53 -0
  62. package/example/react-native.config.js +9 -0
  63. package/example/scripts/reset-project.js +73 -0
  64. package/example/tsconfig.json +17 -0
  65. package/example/yarn.lock +8571 -0
  66. package/package.json +49 -0
  67. package/src/components/Button/Button.tsx +110 -0
  68. package/src/components/Button/index.ts +2 -0
  69. package/src/components/Button/styles/ButtonStyle.ts +47 -0
  70. package/src/components/DateTimeInput/index.tsx +172 -0
  71. package/src/components/DragHandle/index.tsx +49 -0
  72. package/src/components/MenuItemDescription/MenuItemDescription.tsx +34 -0
  73. package/src/components/MenuItemDescription/index.ts +1 -0
  74. package/src/components/NavigationListRow/index.tsx +68 -0
  75. package/src/components/SelectInput/SelectInput.tsx +191 -0
  76. package/src/components/SelectInput/index.ts +2 -0
  77. package/src/components/SelectInput/types.ts +5 -0
  78. package/src/components/Sheet/index.tsx +189 -0
  79. package/src/components/SwitchToggle/index.tsx +31 -0
  80. package/src/components/Text/Text.tsx +74 -0
  81. package/src/components/Text/index.tsx +2 -0
  82. package/src/components/TextInput/TextInput.tsx +241 -0
  83. package/src/components/TextInput/index.tsx +2 -0
  84. package/src/components/TitleBar/TitleBar.tsx +150 -0
  85. package/src/components/TitleBar/index.ts +2 -0
  86. package/src/components/index.ts +11 -0
  87. package/src/context/index.ts +6 -0
  88. package/src/hooks/index.ts +2 -0
  89. package/src/hooks/useTheme.ts +7 -0
  90. package/src/hooks/useThemedStyle.ts +18 -0
  91. package/src/index.ts +5 -0
  92. package/src/shared/styles/index.ts +33 -0
  93. package/src/themes/AtlasLightTheme.ts +90 -0
  94. package/src/themes/index.ts +1 -0
  95. package/src/types/index.ts +3 -0
  96. package/src/types/theme.ts +45 -0
  97. package/src/types/typography.ts +14 -0
  98. package/tsconfig.json +111 -0
@@ -0,0 +1,191 @@
1
+ import React, { useCallback, useEffect, useMemo, useState } from "react";
2
+ import { StyleSheet, TouchableOpacity, View } from "react-native";
3
+ import Animated, {
4
+ Easing,
5
+ interpolate,
6
+ interpolateColor,
7
+ useAnimatedStyle,
8
+ useSharedValue,
9
+ withTiming,
10
+ } from "react-native-reanimated";
11
+ import IonIcons from "react-native-vector-icons/Ionicons";
12
+
13
+ import Text from "../Text";
14
+ import Sheet from "../Sheet";
15
+ import { MenuItemDescription } from "../MenuItemDescription";
16
+ import { useThemedStyle } from "../../hooks";
17
+ import { Option } from "./types";
18
+
19
+ type Props<T> = {
20
+ caption?: string;
21
+ label: string;
22
+ options: Option<T>[];
23
+ onChange: (newValue: Option<T>) => void;
24
+ };
25
+
26
+ export function SelectInput<T>({
27
+ caption,
28
+ label,
29
+ options = [],
30
+ onChange,
31
+ }: Props<T>) {
32
+ // Rest of the component stays the same.
33
+ const { styles, theme } = useStyles();
34
+
35
+ const values = useMemo(() => {
36
+ return options.filter((v) => v.selected);
37
+ }, options);
38
+
39
+ const [sheetOpen, setSheetOpen] = useState(false);
40
+
41
+ const animatedValue = useSharedValue(values.length ? 1 : 0);
42
+ const rotation = useSharedValue(sheetOpen ? 1 : 0);
43
+
44
+ useEffect(() => {
45
+ rotation.value = withTiming(sheetOpen ? 1 : 0, {
46
+ duration: 200,
47
+ easing: Easing.bezier(0.5, 0, 0, 0.75),
48
+ });
49
+ }, [sheetOpen]);
50
+
51
+ useEffect(() => {
52
+ animatedValue.value = values.length ? 1 : 0;
53
+ }, [values.length]);
54
+
55
+ const animatedLabelStyles = useAnimatedStyle(() => {
56
+ return {
57
+ transform: [
58
+ { translateY: interpolate(animatedValue.value, [0, 1], [1, -8]) },
59
+ ],
60
+ fontSize: interpolate(animatedValue.value, [0, 1], [14, 10]),
61
+ };
62
+ }, []);
63
+
64
+ const animatedContainerStyles = useAnimatedStyle(() => {
65
+ return {
66
+ borderColor: interpolateColor(
67
+ animatedValue.value,
68
+ [0, 1],
69
+ ["#ffffff00", theme.colors.border]
70
+ ),
71
+ };
72
+ }, [animatedValue]);
73
+
74
+ const animatedValueStyle = useAnimatedStyle(() => {
75
+ return {
76
+ flex: 1,
77
+ transform: [{ translateY: animatedValue.value * 6 }],
78
+ };
79
+ }, [animatedValue]);
80
+
81
+ const animatedChevronStyle = useAnimatedStyle(() => {
82
+ return {
83
+ transform: [
84
+ { rotateX: `${interpolate(rotation.value, [0, 1], [0, 180])}deg` },
85
+ ],
86
+ };
87
+ }, [rotation]);
88
+
89
+ const handleOptionPress = (option: Option<T>) => {
90
+ onChange(option);
91
+ setSheetOpen(false);
92
+ };
93
+
94
+ return (
95
+ <>
96
+ <TouchableOpacity onPress={() => setSheetOpen(true)}>
97
+ <Animated.View style={[styles.itemContainer, animatedContainerStyles]}>
98
+ <View pointerEvents="none" style={styles.labelContainer}>
99
+ <Animated.Text style={[styles.label, animatedLabelStyles]}>
100
+ {label}
101
+ </Animated.Text>
102
+ </View>
103
+ <Animated.View style={animatedValueStyle}>
104
+ {!!values.length && (
105
+ <Text contrast="low" style={styles.value}>
106
+ {values[0].label}
107
+ </Text>
108
+ )}
109
+ </Animated.View>
110
+ <Animated.View style={animatedChevronStyle}>
111
+ <IonIcons
112
+ style={styles.chevron}
113
+ name="chevron-down-outline"
114
+ size={20}
115
+ />
116
+ </Animated.View>
117
+ </Animated.View>
118
+ </TouchableOpacity>
119
+ {!!caption && <MenuItemDescription description={caption} />}
120
+ <Sheet open={sheetOpen} setOpen={setSheetOpen} header={label}>
121
+ {options.map((option, i) => (
122
+ <TouchableOpacity
123
+ style={[
124
+ styles.selectionItem,
125
+ option.selected && styles.selectedSelectionItem,
126
+ ]}
127
+ key={i}
128
+ onPress={() => handleOptionPress(option)}
129
+ >
130
+ <Text contrast={option.selected ? "high" : "low"}>
131
+ {option.label}
132
+ </Text>
133
+ </TouchableOpacity>
134
+ ))}
135
+ </Sheet>
136
+ </>
137
+ );
138
+ }
139
+
140
+ const useStyles = () =>
141
+ useThemedStyle(
142
+ useCallback(
143
+ (theme) =>
144
+ StyleSheet.create({
145
+ chevron: {
146
+ paddingRight: theme.size.baseSize * 2,
147
+ color: theme.colors.foreground,
148
+ },
149
+ selectedSelectionItem: {
150
+ borderColor: theme.colors.primary,
151
+ },
152
+ selectionItem: {
153
+ alignItems: "center",
154
+ borderWidth: theme.borderWidth,
155
+ borderColor: theme.colors.border,
156
+ marginBottom: theme.size.baseSize * 2,
157
+ padding: theme.size.baseSize * 2,
158
+ borderRadius: theme.borderRadius,
159
+ },
160
+ itemContainer: {
161
+ borderWidth: theme.borderWidth,
162
+ borderColor: theme.colors.borderSecondary,
163
+ backgroundColor: theme.colors.backgroundOnPrimary,
164
+ marginBottom: theme.size.baseSize * 2,
165
+ borderRadius: theme.borderRadius,
166
+ minHeight: theme.size.baseSize * 8,
167
+ flexDirection: "row",
168
+ alignItems: "center",
169
+ justifyContent: "space-between",
170
+ },
171
+ labelContainer: {
172
+ left: theme.size.baseSize * 2,
173
+ position: "absolute",
174
+ },
175
+ label: {
176
+ color: theme.text,
177
+ ...theme.typography.p1,
178
+ },
179
+ descriptionContainer: {
180
+ marginHorizontal: theme.size.baseSize * 4,
181
+ marginBottom: theme.size.baseSize * 2,
182
+ },
183
+ value: {
184
+ paddingHorizontal: theme.size.baseSize * 2,
185
+ },
186
+ }),
187
+ []
188
+ )
189
+ );
190
+
191
+ export default SelectInput;
@@ -0,0 +1,2 @@
1
+ export { default } from './SelectInput'
2
+ export * from './SelectInput'
@@ -0,0 +1,5 @@
1
+ export type Option<T> = {
2
+ value: T;
3
+ label: string;
4
+ selected: boolean;
5
+ };
@@ -0,0 +1,189 @@
1
+ import React, {
2
+ Dispatch,
3
+ SetStateAction,
4
+ useCallback,
5
+ useEffect,
6
+ useState,
7
+ } from "react";
8
+ import {
9
+ Modal,
10
+ Pressable,
11
+ ScrollView,
12
+ StyleProp,
13
+ StyleSheet,
14
+ View,
15
+ ViewStyle,
16
+ } from "react-native";
17
+ import Animated, {
18
+ Easing,
19
+ SlideInDown,
20
+ SlideOutDown,
21
+ useAnimatedStyle,
22
+ useSharedValue,
23
+ withTiming,
24
+ runOnJS,
25
+ } from "react-native-reanimated";
26
+ import { useSafeAreaInsets } from "react-native-safe-area-context";
27
+
28
+ import { useThemedStyle } from "../../hooks/useThemedStyle";
29
+ import Text from "../Text";
30
+
31
+ type Props = {
32
+ open: boolean;
33
+ setOpen: Dispatch<SetStateAction<boolean>>;
34
+ children?: React.ReactNode;
35
+ containerStyle?: StyleProp<ViewStyle>;
36
+ defaultMargins?: boolean;
37
+ header?: string;
38
+ transparent?: boolean;
39
+ disableScroll?: boolean;
40
+ };
41
+
42
+ const BACKGROUND_OPACITY = 0.6;
43
+
44
+ export const Sheet = ({
45
+ open,
46
+ setOpen,
47
+ children,
48
+ containerStyle,
49
+ defaultMargins = true,
50
+ header,
51
+ transparent = false,
52
+ disableScroll = false
53
+ }: Props) => {
54
+ const styles = useStyles(defaultMargins).styles;
55
+ const [visible, setVisible] = useState(open);
56
+
57
+ const opacity = useSharedValue(0);
58
+
59
+ useEffect(() => {
60
+ if (!open) {
61
+ setVisible(false);
62
+ return;
63
+ }
64
+
65
+ setVisible(true);
66
+ }, [open]);
67
+
68
+ useEffect(() => {
69
+ if (!visible) {
70
+ opacity.value = withTiming(
71
+ 0,
72
+ {
73
+ duration: 200,
74
+ easing: Easing.bezier(0.5, 0, 0, 0.75),
75
+ },
76
+ () => {
77
+ runOnJS(setOpen)(false);
78
+ }
79
+ );
80
+ return;
81
+ }
82
+ opacity.value = withTiming(BACKGROUND_OPACITY, {
83
+ duration: 250,
84
+ easing: Easing.bezier(0.5, 0, 0, 0.75),
85
+ });
86
+ }, [visible]);
87
+
88
+ const animatedModalBackgroundStyles = useAnimatedStyle(() => ({
89
+ opacity: opacity.value,
90
+ }));
91
+
92
+ const content = (
93
+ <>
94
+ {!transparent && (
95
+ <Pressable
96
+ style={styles.modalPressable}
97
+ onPress={() => {
98
+ setVisible(false);
99
+ }}
100
+ >
101
+ <Animated.View
102
+ style={[styles.modalBackground, animatedModalBackgroundStyles]}
103
+ />
104
+ </Pressable>
105
+ )}
106
+ {visible && (
107
+ <Animated.View
108
+ entering={SlideInDown}
109
+ exiting={SlideOutDown}
110
+ style={[styles.sheet, containerStyle]}
111
+ >
112
+ {!!header && (
113
+ <View style={styles.headerContainer}>
114
+ <Text>{header}</Text>
115
+ </View>
116
+ )}
117
+ <ScrollView scrollEnabled={!disableScroll} contentContainerStyle={styles.contentContainer}>
118
+ {children}
119
+ </ScrollView>
120
+ </Animated.View>
121
+ )}
122
+ </>
123
+ );
124
+
125
+ // // Don't render anything if it's not visible
126
+ if (!visible && !open) {
127
+ return null;
128
+ }
129
+
130
+ return (
131
+ <Modal transparent visible>
132
+ <View style={styles.wrapper}>{content}</View>
133
+ </Modal>
134
+ );
135
+ };
136
+
137
+ export default Sheet;
138
+
139
+ const useStyles = (defaultMargins: boolean) => {
140
+ const { bottom: bottomInset } = useSafeAreaInsets();
141
+ return useThemedStyle(
142
+ useCallback(
143
+ (theme) =>
144
+ StyleSheet.create({
145
+ wrapper: {
146
+ flex: 1,
147
+ justifyContent: "flex-end",
148
+ },
149
+ headerContainer: {
150
+ paddingVertical: theme.size.baseSize * 3,
151
+ justifyContent: "center",
152
+ alignItems: "center",
153
+ borderBottomWidth: theme.borderWidth / 2,
154
+ borderColor: theme.colors.border,
155
+ },
156
+ modalPressable: {
157
+ position: "absolute",
158
+ top: 0,
159
+ bottom: 0,
160
+ right: 0,
161
+ left: 0,
162
+ },
163
+ modalBackground: {
164
+ backgroundColor: "#000000",
165
+ position: "absolute",
166
+ top: 0,
167
+ bottom: 0,
168
+ right: 0,
169
+ left: 0,
170
+ },
171
+ sheet: {
172
+ alignSelf: "center",
173
+ display: "flex",
174
+ width: "100%",
175
+ maxWidth: 600,
176
+ maxHeight: "80%",
177
+ backgroundColor: theme.colors.backgroundPrimary,
178
+ },
179
+ contentContainer: {
180
+ padding: defaultMargins ? theme.size.baseSize * 4 : 0,
181
+ paddingBottom: defaultMargins
182
+ ? theme.size.baseSize * 4 + bottomInset
183
+ : bottomInset,
184
+ },
185
+ }),
186
+ [bottomInset]
187
+ )
188
+ );
189
+ };
@@ -0,0 +1,31 @@
1
+ import React from 'react';
2
+ import { StyleProp, Switch, TouchableOpacity, View, ViewStyle } from 'react-native';
3
+
4
+
5
+ import Text from '../Text';
6
+ import { MenuItemDescription } from '../MenuItemDescription';
7
+ import { useMenuItemStyles } from '../../shared/styles/index';
8
+
9
+ export type SwitchToggleProps = {
10
+ label: string;
11
+ value?: boolean;
12
+ caption?: string;
13
+ testId?: string;
14
+ onChange?: (value: boolean) => void;
15
+ touchableStyle?: StyleProp<ViewStyle>;
16
+ };
17
+
18
+ export const SwitchToggle = ({ testId, onChange, value, caption, label, touchableStyle }: SwitchToggleProps) => {
19
+ const styles = useMenuItemStyles().styles;
20
+ return (
21
+ <View style={styles.container}>
22
+ <TouchableOpacity testID={testId} style={[styles.itemContainer, touchableStyle]}>
23
+ <Text numberOfLines={1}>{label}</Text>
24
+ <Switch testID={`${testId}_toggle`} onValueChange={onChange} value={value} />
25
+ </TouchableOpacity>
26
+ {!!caption && <MenuItemDescription description={caption} />}
27
+ </View>
28
+ );
29
+ };
30
+
31
+ export default SwitchToggle;
@@ -0,0 +1,74 @@
1
+ import React, { useCallback } from 'react';
2
+ import { StyleProp, StyleSheet, Text as RNText, TextProps as RNTextProps, TextStyle } from 'react-native';
3
+
4
+ import { TypographyStyles, TypographyVariants } from '../../types/typography';
5
+ import { useThemedStyle } from '../../hooks';
6
+
7
+ type TextContrast = 'high' | 'medium' | 'low';
8
+ type TextStatus = 'error' | 'informative' | 'warning' | 'success';
9
+
10
+ export interface TextProps extends RNTextProps {
11
+ status?: TextStatus;
12
+ category?: TypographyVariants;
13
+ contrast?: TextContrast;
14
+ style?: StyleProp<TextStyle>;
15
+ }
16
+
17
+ const getFontStyle = ({ fontFamily, fontSize, fontWeight, lineHeight }: TypographyStyles): TextStyle => {
18
+ return {
19
+ fontFamily,
20
+ fontSize,
21
+ fontWeight,
22
+ lineHeight,
23
+ };
24
+ };
25
+
26
+ export const Text = ({ category = 'p1', contrast, style, status, ...rest }: TextProps) => {
27
+ const styles = useStyles(category, contrast, status).styles;
28
+ return <RNText style={[styles.fontStyle, styles.colorStyle, style]} {...rest} />;
29
+ };
30
+
31
+ export default Text;
32
+
33
+ const useStyles = (category: TypographyVariants, contrast: TextContrast = 'high', status?: TextStatus) =>
34
+ useThemedStyle(
35
+ useCallback(
36
+ theme => {
37
+ let color = theme.colors.foregroundHighContrast;
38
+ if (contrast) {
39
+ if (contrast === 'medium') {
40
+ color = theme.colors.foreground;
41
+ } else if (contrast === 'low') {
42
+ color = theme.colors.foregroundLowContrast;
43
+ }
44
+ }
45
+ if (status) {
46
+ if (status) {
47
+ switch (status) {
48
+ case 'error':
49
+ color = theme.colors.secondaryNegative;
50
+ break;
51
+ case 'informative':
52
+ color = theme.colors.primary;
53
+ break;
54
+ case 'warning':
55
+ color = theme.colors.secondaryWarning;
56
+ break;
57
+ case 'success':
58
+ color = theme.colors.secondaryPositive;
59
+ break;
60
+ default:
61
+ break;
62
+ }
63
+ }
64
+ }
65
+ return StyleSheet.create({
66
+ colorStyle: {
67
+ color,
68
+ },
69
+ fontStyle: getFontStyle(theme.typography[category]),
70
+ });
71
+ },
72
+ [category, contrast, status]
73
+ )
74
+ );
@@ -0,0 +1,2 @@
1
+ export { default } from './Text';
2
+ export * from './Text';