@towsila/expo-ui-library 4.12.2 → 4.13.1
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/package.json
CHANGED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path d="M19 9L22 12L19 15M22 12L10 12" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" stroke="#F33621"/>
|
|
3
|
+
<path d="M15 6V4L6 4C4.89543 4 4 4.89543 4 6V18C4 19.1046 4.89543 20 6 20H15L15 18" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" stroke="#F33621"/>
|
|
4
|
+
</svg>
|
|
@@ -1,154 +1,236 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
TouchableOpacity,
|
|
3
|
+
View,
|
|
4
|
+
Text,
|
|
5
|
+
Modal,
|
|
6
|
+
Pressable,
|
|
7
|
+
Animated,
|
|
8
|
+
useWindowDimensions,
|
|
9
|
+
} from "react-native";
|
|
2
10
|
import React, { useState, useEffect, useRef } from "react";
|
|
3
|
-
import {
|
|
4
|
-
import {Logout} from "@towsila/icons";
|
|
11
|
+
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
5
12
|
import ThemeToggle from "./themeToggle";
|
|
6
13
|
import { useAppTheme } from "../../context/ThemeContext";
|
|
7
14
|
import { useLanguage } from "../../context/LanguageContext";
|
|
8
15
|
import { Menu } from "../../types/menu";
|
|
9
16
|
import LanguageSelect from "./languageSelect";
|
|
10
17
|
import { Fonts, textSize } from "../../tokens/typography";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
themeLabel?:string;
|
|
18
|
+
import Logout from "../../assets/icons/logout.svg";
|
|
19
|
+
interface AsideProps {
|
|
20
|
+
visible: boolean;
|
|
21
|
+
onClose: () => void;
|
|
22
|
+
logo: React.ReactNode;
|
|
23
|
+
name?: string;
|
|
24
|
+
menu: Menu[];
|
|
25
|
+
onLogout: () => void;
|
|
26
|
+
logoutLabel: string;
|
|
27
|
+
onNavigate: (link: string) => void;
|
|
28
|
+
themeLabel?: string;
|
|
23
29
|
}
|
|
24
30
|
|
|
25
|
-
export default function AsideBar({
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
Animated.timing(slideAnim, {
|
|
49
|
-
toValue: -SIDEBAR_WIDTH,
|
|
50
|
-
duration: 200,
|
|
51
|
-
useNativeDriver: true,
|
|
52
|
-
}),
|
|
53
|
-
Animated.timing(fadeAnim, {
|
|
54
|
-
toValue: 0,
|
|
55
|
-
duration: 200,
|
|
56
|
-
useNativeDriver: true,
|
|
57
|
-
}),
|
|
58
|
-
]).start();
|
|
59
|
-
}
|
|
60
|
-
}, [visible]);
|
|
61
|
-
const align = isRTL ? "row-reverse":"row";
|
|
62
|
-
return(
|
|
63
|
-
<Modal visible={visible} transparent animationType="none" onRequestClose={onClose}>
|
|
64
|
-
<View style={{ flex: 1, flexDirection:align}}>
|
|
65
|
-
{/* Animated sidebar panel sliding from left */}
|
|
66
|
-
<Animated.View style={{
|
|
67
|
-
justifyContent: "space-between",
|
|
68
|
-
height: "100%",
|
|
69
|
-
width: isRTL ? SIDEBAR_WIDTH : -SIDEBAR_WIDTH,
|
|
70
|
-
backgroundColor: colors.background.main,
|
|
71
|
-
paddingHorizontal: 20,
|
|
72
|
-
paddingVertical:50,
|
|
73
|
-
transform: [{ translateX: slideAnim }],
|
|
74
|
-
}}>
|
|
75
|
-
{/* top container */}
|
|
76
|
-
<View style={{flex: 1, gap: 30}}>
|
|
77
|
-
{/* logo, name and language row */}
|
|
78
|
-
<View style={{flexDirection:align, alignItems:"center", justifyContent:"space-between"}}>
|
|
79
|
-
<View style={{flexDirection: align, alignItems: "center", gap: 6}}>
|
|
80
|
-
{logo}
|
|
81
|
-
</View>
|
|
82
|
-
<View>
|
|
83
|
-
<LanguageSelect value={language} onChange={setLanguage} />
|
|
84
|
-
</View>
|
|
85
|
-
</View>
|
|
31
|
+
export default function AsideBar({
|
|
32
|
+
logo,
|
|
33
|
+
menu,
|
|
34
|
+
onLogout,
|
|
35
|
+
logoutLabel,
|
|
36
|
+
onNavigate,
|
|
37
|
+
visible,
|
|
38
|
+
onClose,
|
|
39
|
+
themeLabel,
|
|
40
|
+
}: AsideProps) {
|
|
41
|
+
const { language, setLanguage } = useLanguage();
|
|
42
|
+
const { colors } = useAppTheme();
|
|
43
|
+
const { isRTL } = useLanguage();
|
|
44
|
+
const insets = useSafeAreaInsets();
|
|
45
|
+
const { width: screenWidth } = useWindowDimensions();
|
|
46
|
+
|
|
47
|
+
// ~80% of screen, capped at 400 for tablets
|
|
48
|
+
const SIDEBAR_WIDTH = Math.min(screenWidth * 0.8, 400);
|
|
49
|
+
|
|
50
|
+
const [activeIndex, setActiveIndex] = useState<number | null>(0);
|
|
51
|
+
|
|
52
|
+
const slideAnim = useRef(new Animated.Value(-SIDEBAR_WIDTH)).current;
|
|
53
|
+
const fadeAnim = useRef(new Animated.Value(0)).current;
|
|
86
54
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
fontSize: textSize.md,
|
|
117
|
-
color: isActive ? colors.primary : colors.text.primary,
|
|
118
|
-
flex:1
|
|
119
|
-
}}>
|
|
120
|
-
{item.name}
|
|
121
|
-
</Text>
|
|
122
|
-
</TouchableOpacity>
|
|
123
|
-
);
|
|
124
|
-
})}
|
|
125
|
-
</View>
|
|
126
|
-
</View>
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
if (visible) {
|
|
57
|
+
Animated.parallel([
|
|
58
|
+
Animated.timing(slideAnim, {
|
|
59
|
+
toValue: 0,
|
|
60
|
+
duration: 250,
|
|
61
|
+
useNativeDriver: true,
|
|
62
|
+
}),
|
|
63
|
+
Animated.timing(fadeAnim, {
|
|
64
|
+
toValue: 1,
|
|
65
|
+
duration: 250,
|
|
66
|
+
useNativeDriver: true,
|
|
67
|
+
}),
|
|
68
|
+
]).start();
|
|
69
|
+
} else {
|
|
70
|
+
Animated.parallel([
|
|
71
|
+
Animated.timing(slideAnim, {
|
|
72
|
+
toValue: -SIDEBAR_WIDTH,
|
|
73
|
+
duration: 200,
|
|
74
|
+
useNativeDriver: true,
|
|
75
|
+
}),
|
|
76
|
+
Animated.timing(fadeAnim, {
|
|
77
|
+
toValue: 0,
|
|
78
|
+
duration: 200,
|
|
79
|
+
useNativeDriver: true,
|
|
80
|
+
}),
|
|
81
|
+
]).start();
|
|
82
|
+
}
|
|
83
|
+
}, [visible]);
|
|
127
84
|
|
|
128
|
-
|
|
129
|
-
<View style={{ gap: 16, paddingHorizontal: 16, }}>
|
|
130
|
-
<TouchableOpacity onPress={onLogout} style={{ flexDirection:align, alignItems: "center", gap: 10 }}>
|
|
131
|
-
<Logout width={22} height={22} color={colors.semantic.error} style={[isRTL && {transform: [{scale:-1}]}]}/>
|
|
132
|
-
<Text style={{
|
|
133
|
-
fontFamily: Fonts.montserrat.regular,
|
|
134
|
-
fontSize: textSize.md,
|
|
135
|
-
color: colors.text.primary,
|
|
136
|
-
}}>
|
|
137
|
-
{logoutLabel}
|
|
138
|
-
</Text>
|
|
139
|
-
</TouchableOpacity>
|
|
140
|
-
<ThemeToggle label={themeLabel}/>
|
|
141
|
-
</View>
|
|
142
|
-
</Animated.View>
|
|
85
|
+
const align = isRTL ? "row-reverse" : "row";
|
|
143
86
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
87
|
+
return (
|
|
88
|
+
<Modal
|
|
89
|
+
visible={visible}
|
|
90
|
+
transparent
|
|
91
|
+
animationType="none"
|
|
92
|
+
onRequestClose={onClose}
|
|
93
|
+
statusBarTranslucent
|
|
94
|
+
>
|
|
95
|
+
<View style={{ flex: 1, flexDirection: align }}>
|
|
96
|
+
{/* Animated sidebar panel */}
|
|
97
|
+
<Animated.View
|
|
98
|
+
style={{
|
|
99
|
+
justifyContent: "space-between",
|
|
100
|
+
height: "100%",
|
|
101
|
+
width: SIDEBAR_WIDTH,
|
|
102
|
+
backgroundColor: colors.background.main,
|
|
103
|
+
paddingHorizontal: 20,
|
|
104
|
+
paddingTop: Math.max(insets.top, 20) + 20,
|
|
105
|
+
paddingBottom: Math.max(insets.bottom, 20),
|
|
106
|
+
transform: [{ translateX: slideAnim }],
|
|
107
|
+
}}
|
|
108
|
+
>
|
|
109
|
+
{/* top container */}
|
|
110
|
+
<View style={{ flex: 1, gap: 30 }}>
|
|
111
|
+
{/* logo, name and language row */}
|
|
112
|
+
<View
|
|
113
|
+
style={{
|
|
114
|
+
flexDirection: align,
|
|
115
|
+
alignItems: "center",
|
|
116
|
+
justifyContent: "space-between",
|
|
117
|
+
gap: 12,
|
|
118
|
+
}}
|
|
119
|
+
>
|
|
120
|
+
{/* Logo takes remaining width, dropdown stays far side */}
|
|
121
|
+
<View
|
|
122
|
+
style={{
|
|
123
|
+
flexDirection: align,
|
|
124
|
+
alignItems: "center",
|
|
125
|
+
gap: 6,
|
|
126
|
+
flex: 1,
|
|
127
|
+
minWidth: 0,
|
|
128
|
+
}}
|
|
129
|
+
>
|
|
130
|
+
{logo}
|
|
131
|
+
</View>
|
|
132
|
+
<View style={{ flexShrink: 0 }}>
|
|
133
|
+
<LanguageSelect value={language} onChange={setLanguage} />
|
|
134
|
+
</View>
|
|
135
|
+
</View>
|
|
136
|
+
|
|
137
|
+
{/* menu links */}
|
|
138
|
+
<View style={{ flex: 1, gap: 11 }}>
|
|
139
|
+
{menu.map((item, index) => {
|
|
140
|
+
const isActive = activeIndex === index;
|
|
141
|
+
return (
|
|
142
|
+
<TouchableOpacity
|
|
143
|
+
key={index}
|
|
144
|
+
style={{
|
|
145
|
+
flexDirection: align,
|
|
146
|
+
alignItems: "center",
|
|
147
|
+
gap: 12,
|
|
148
|
+
paddingVertical: 14,
|
|
149
|
+
paddingHorizontal: 16,
|
|
150
|
+
borderRadius: 10,
|
|
151
|
+
backgroundColor: isActive
|
|
152
|
+
? colors.primary + "40"
|
|
153
|
+
: "transparent",
|
|
154
|
+
}}
|
|
155
|
+
onPress={() => {
|
|
156
|
+
setActiveIndex(index);
|
|
157
|
+
onNavigate(item.link);
|
|
158
|
+
onClose();
|
|
159
|
+
}}
|
|
160
|
+
>
|
|
161
|
+
{item.iconSvg && (
|
|
162
|
+
<View
|
|
163
|
+
style={{
|
|
164
|
+
flexShrink: 0,
|
|
165
|
+
...(isRTL && { transform: [{ scaleX: -1 }] }),
|
|
166
|
+
}}
|
|
167
|
+
>
|
|
168
|
+
{item.iconSvg?.(
|
|
169
|
+
isActive ? colors.primary : colors.text.primary,
|
|
170
|
+
isActive
|
|
171
|
+
)}
|
|
172
|
+
</View>
|
|
173
|
+
)}
|
|
174
|
+
<Text
|
|
175
|
+
numberOfLines={1}
|
|
176
|
+
style={{
|
|
177
|
+
fontFamily: isActive
|
|
178
|
+
? Fonts.montserrat.semiBold
|
|
179
|
+
: Fonts.montserrat.regular,
|
|
180
|
+
fontSize: textSize.md,
|
|
181
|
+
color: isActive ? colors.primary : colors.text.primary,
|
|
182
|
+
flex: 1,
|
|
183
|
+
minWidth: 0,
|
|
184
|
+
textAlign: isRTL ? "right" : "left",
|
|
185
|
+
}}
|
|
186
|
+
>
|
|
187
|
+
{item.name}
|
|
188
|
+
</Text>
|
|
189
|
+
</TouchableOpacity>
|
|
190
|
+
);
|
|
191
|
+
})}
|
|
192
|
+
</View>
|
|
193
|
+
</View>
|
|
194
|
+
|
|
195
|
+
{/* bottom container */}
|
|
196
|
+
<View style={{ gap: 16, paddingHorizontal: 16 }}>
|
|
197
|
+
<TouchableOpacity
|
|
198
|
+
onPress={onLogout}
|
|
199
|
+
style={{ flexDirection: align, alignItems: "center", gap: 10 }}
|
|
200
|
+
>
|
|
201
|
+
<View style={{ flexShrink: 0 }}>
|
|
202
|
+
<Logout
|
|
203
|
+
width={22}
|
|
204
|
+
height={22}
|
|
205
|
+
color={colors.semantic.error}
|
|
206
|
+
style={isRTL ? { transform: [{ scaleX: -1 }] } : undefined}
|
|
149
207
|
/>
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
208
|
+
</View>
|
|
209
|
+
<Text
|
|
210
|
+
numberOfLines={1}
|
|
211
|
+
style={{
|
|
212
|
+
flexShrink: 1,
|
|
213
|
+
minWidth: 0,
|
|
214
|
+
fontFamily: Fonts.montserrat.regular,
|
|
215
|
+
fontSize: textSize.md,
|
|
216
|
+
color: colors.text.primary,
|
|
217
|
+
}}
|
|
218
|
+
>
|
|
219
|
+
{logoutLabel}
|
|
220
|
+
</Text>
|
|
221
|
+
</TouchableOpacity>
|
|
222
|
+
<ThemeToggle label={themeLabel} />
|
|
223
|
+
</View>
|
|
224
|
+
</Animated.View>
|
|
225
|
+
|
|
226
|
+
{/* Dimmed backdrop — full remaining width, tap to close */}
|
|
227
|
+
<Animated.View style={{ flex: 1, opacity: fadeAnim }}>
|
|
228
|
+
<Pressable
|
|
229
|
+
style={{ flex: 1, backgroundColor: "rgba(0,0,0,0.5)" }}
|
|
230
|
+
onPress={onClose}
|
|
231
|
+
/>
|
|
232
|
+
</Animated.View>
|
|
233
|
+
</View>
|
|
234
|
+
</Modal>
|
|
235
|
+
);
|
|
154
236
|
}
|
package/src/types/menu.ts
CHANGED
|
@@ -4,7 +4,7 @@ export type Menu = {
|
|
|
4
4
|
key?: string,
|
|
5
5
|
icon?: keyof typeof Ionicons.glyphMap;
|
|
6
6
|
iconActive?: keyof typeof Ionicons.glyphMap;
|
|
7
|
-
iconSvg?: (color: string)=>React.ReactNode;
|
|
7
|
+
iconSvg?: (color: string, isActive?: boolean)=>React.ReactNode;
|
|
8
8
|
name: string;
|
|
9
9
|
link: string;
|
|
10
10
|
}
|