@towsila/expo-ui-library 4.7.0 → 4.7.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@towsila/expo-ui-library",
3
- "version": "4.7.0",
3
+ "version": "4.7.1",
4
4
  "description": "",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -1,100 +1,154 @@
1
- import { useRef, useEffect } from "react";
2
- import { Animated, TouchableOpacity, View, Text } from "react-native";
3
- import DarkMode from "@/assets/images/icons/dark.svg";
4
- import LightMode from "@/assets/images/icons/light.svg";
1
+ import { TouchableOpacity, View, Text, Modal, Pressable, Animated, I18nManager } from "react-native";
2
+ import React, { useState, useEffect, useRef } from "react";
3
+ import { Dimensions } from "react-native";
4
+ import {Logout} from "@towsila/icons";
5
+ import ThemeToggle from "./themeToggle";
5
6
  import { useAppTheme } from "../../context/ThemeContext";
6
7
  import { useLanguage } from "../../context/LanguageContext";
8
+ import { Menu } from "../../types/menu";
9
+ import LanguageSelect from "./languageSelect";
7
10
  import { Fonts, textSize } from "../../tokens/typography";
11
+ const SIDEBAR_WIDTH = Dimensions.get("window").width * 0.7;
8
12
 
9
- interface TextTheme {
10
- label?: string;
13
+ interface AsideProps{
14
+ visible: boolean;
15
+ onClose: () => void;
16
+ logo: React.ReactNode;
17
+ name?: string;
18
+ menu: Menu[];
19
+ onLogout: ()=>void;
20
+ logoutLabel: string;
21
+ onNavigate: (link: string) => void;
22
+ themeLabel?:string;
11
23
  }
12
24
 
13
- const TRACK_W = 52;
14
- const TRACK_H = 30;
15
- const THUMB = 22;
16
- const MARGIN = 4;
17
- const TRAVEL = TRACK_W - THUMB - MARGIN * 2;
25
+ export default function AsideBar({logo, menu, onLogout, logoutLabel, onNavigate, visible, onClose, themeLabel}:AsideProps){
26
+ const { language, setLanguage } = useLanguage();
27
+ const {colors} = useAppTheme();
28
+ const [activeIndex, setActiveIndex] = useState<number | null>(0);
29
+ const slideAnim = useRef(new Animated.Value(-SIDEBAR_WIDTH)).current;
30
+ const fadeAnim = useRef(new Animated.Value(0)).current;
18
31
 
19
- export default function ThemeToggle({ label }: TextTheme) {
20
- const { isDark, toggleTheme, colors } = useAppTheme();
21
- const { isRTL } = useLanguage();
22
- const progress = useRef(new Animated.Value(isDark ? 1 : 0)).current;
32
+ useEffect(() => {
33
+ if (visible) {
34
+ Animated.parallel([
35
+ Animated.timing(slideAnim, {
36
+ toValue: 0,
37
+ duration: 250,
38
+ useNativeDriver: true,
39
+ }),
40
+ Animated.timing(fadeAnim, {
41
+ toValue: 1,
42
+ duration: 250,
43
+ useNativeDriver: true,
44
+ }),
45
+ ]).start();
46
+ } else {
47
+ Animated.parallel([
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]);
23
61
 
24
- useEffect(() => {
25
- Animated.spring(progress, {
26
- toValue: isDark ? 1 : 0,
27
- useNativeDriver: true,
28
- bounciness: 6,
29
- }).start();
30
- }, [isDark]);
62
+ return(
63
+ <Modal visible={visible} transparent animationType="none" onRequestClose={onClose}>
64
+ <View style={{ flex: 1, flexDirection: "row" }}>
65
+ {/* Animated sidebar panel sliding from left */}
66
+ <Animated.View style={{
67
+ justifyContent: "space-between",
68
+ height: "100%",
69
+ 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: "row", alignItems:"center", justifyContent:"space-between"}}>
79
+ <View style={{flexDirection: "row", alignItems: "center", gap: 6}}>
80
+ {logo}
81
+ </View>
82
+ <View>
83
+ <LanguageSelect value={language} onChange={setLanguage} />
84
+ </View>
85
+ </View>
31
86
 
32
- // in RTL the thumb travels the other way
33
- const translateX = progress.interpolate({
34
- inputRange: [0, 1],
35
- outputRange: isRTL ? [0, TRAVEL] : [0, -TRAVEL],
36
- });
87
+ {/* menu links */}
88
+ <View style={{flex: 1, gap: 11}}>
89
+ {menu.map((item, index) => {
90
+ const isActive = activeIndex === index;
91
+ return (
92
+ <TouchableOpacity
93
+ key={index}
94
+ style={{
95
+ flexDirection: "row",
96
+ alignItems: "center",
97
+ gap: 12,
98
+ paddingVertical: 14,
99
+ paddingHorizontal: 16,
100
+ borderRadius: 10,
101
+ backgroundColor: isActive ? colors.primary + "20" : "transparent"
102
+ }}
103
+ onPress={() => {
104
+ setActiveIndex(index);
105
+ onNavigate(item.link);
106
+ onClose();
107
+ }}
108
+ >
109
+ {item.iconSvg && (
110
+ <View style={[I18nManager.isRTL && {transform: [{ scaleX: -1 }]} ]}>
111
+ {item.iconSvg(isActive ? colors.primary : "transparent")}
112
+ </View>
113
+ )}
114
+ <Text style={{
115
+ fontFamily: isActive ? Fonts.montserrat.semiBold : Fonts.montserrat.regular,
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>
37
127
 
128
+ {/* bottom container */}
129
+ <View style={{ gap: 16, paddingHorizontal: 16, }}>
130
+ <TouchableOpacity onPress={onLogout} style={{ flexDirection: "row", alignItems: "center", gap: 10 }}>
131
+ <Logout width={22} height={22} color={colors.semantic.error} style={[I18nManager.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>
38
143
 
39
- return (
40
- <View style={{ flexDirection: isRTL ? "row" : "row-reverse", alignItems: "center",justifyContent:"space-between"}}>
41
- <View style={{flexDirection: isRTL ? "row" : "row-reverse", gap: isDark ? 20:17}}>
42
- {isDark ? (
43
- <DarkMode width={22} height={22} color={colors.text.primary} />
44
- ) : (
45
- <LightMode width={26} height={26} color={colors.text.primary} />
46
- )}
47
-
48
- {label && (
49
- <Text style={{ fontFamily: Fonts.montserrat.semiBold, fontSize: textSize.md, color: colors.text.primary }}>
50
- {label}
51
- </Text>
52
- )}
53
- </View>
54
- <TouchableOpacity
55
- onPress={toggleTheme}
56
- activeOpacity={0.9}
57
- accessibilityRole="switch"
58
- accessibilityState={{ checked: isDark }}
59
- >
60
- <View
61
- style={{
62
- width: TRACK_W,
63
- height: TRACK_H,
64
- borderRadius: TRACK_H / 2,
65
- backgroundColor: colors.primary,
66
- borderWidth: 1,
67
- borderColor: colors.text.primary,
68
- justifyContent: "center",
69
- }}
70
- >
71
- <Animated.View
72
- style={{
73
- position: "absolute",
74
- top: (TRACK_H - THUMB) / 2 - 1,
75
- ...(isRTL ? { right: MARGIN - 1 } : { left: MARGIN - 1 }),
76
- width: THUMB,
77
- height: THUMB,
78
- borderRadius: THUMB / 2,
79
- backgroundColor: colors.text.primary,
80
- alignItems: "center",
81
- justifyContent: "center",
82
- transform: [{ translateX }],
83
- elevation: 3,
84
- shadowColor: "#000",
85
- shadowOffset: { width: 0, height: 2 },
86
- shadowOpacity: 0.25,
87
- shadowRadius: 3,
88
- }}
89
- >
90
- {isDark ? (
91
- <LightMode width={16} height={16} color={colors.background.main} />
92
- ) : (
93
- <DarkMode width={12} height={12} color={colors.background.main} />
94
- )}
95
- </Animated.View>
144
+ {/* Dimmed backdrop — full remaining width, tap to close */}
145
+ <Animated.View style={{ flex: 1, opacity: fadeAnim }}>
146
+ <Pressable
147
+ style={{ flex: 1, backgroundColor: "rgba(0,0,0,0.5)" }}
148
+ onPress={onClose}
149
+ />
150
+ </Animated.View>
96
151
  </View>
97
- </TouchableOpacity>
98
- </View>
99
- );
152
+ </Modal>
153
+ )
100
154
  }
@@ -1,8 +1,9 @@
1
1
  import { useRef, useEffect } from "react";
2
- import { Animated, TouchableOpacity, View, Text, I18nManager } from "react-native";
3
- import {LightMode, DarkMode} from "@towsila/icons";
4
- import Svg, { Path } from "react-native-svg";
2
+ import { Animated, TouchableOpacity, View, Text } from "react-native";
3
+ import DarkMode from "../../assets/icons/dark.svg";
4
+ import LightMode from "../../assets/icons/light.svg";
5
5
  import { useAppTheme } from "../../context/ThemeContext";
6
+ import { useLanguage } from "../../context/LanguageContext";
6
7
  import { Fonts, textSize } from "../../tokens/typography";
7
8
 
8
9
  interface TextTheme {
@@ -11,84 +12,86 @@ interface TextTheme {
11
12
 
12
13
  const TRACK_W = 52;
13
14
  const TRACK_H = 30;
14
- const THUMB = 22;
15
- const MARGIN = 4;
16
- const TRAVEL = TRACK_W - THUMB - MARGIN * 2;
15
+ const THUMB = 22;
16
+ const MARGIN = 4;
17
+ const TRAVEL = TRACK_W - THUMB - MARGIN * 2;
17
18
 
18
19
  export default function ThemeToggle({ label }: TextTheme) {
19
20
  const { isDark, toggleTheme, colors } = useAppTheme();
20
- const translateX = useRef(new Animated.Value(isDark ? TRAVEL : 0)).current;
21
+ const { isRTL } = useLanguage();
22
+ const progress = useRef(new Animated.Value(isDark ? 1 : 0)).current;
21
23
 
22
24
  useEffect(() => {
23
- Animated.spring(translateX, {
24
- toValue: isDark ? TRAVEL : 0,
25
+ Animated.spring(progress, {
26
+ toValue: isDark ? 1 : 0,
25
27
  useNativeDriver: true,
26
28
  bounciness: 6,
27
29
  }).start();
28
30
  }, [isDark]);
29
31
 
32
+ // in RTL the thumb travels the other way
33
+ const translateX = progress.interpolate({
34
+ inputRange: [0, 1],
35
+ outputRange: isRTL ? [0, TRAVEL] : [0, -TRAVEL],
36
+ });
37
+
38
+
30
39
  return (
31
- <View style={{ flexDirection: "row", alignItems: "center", gap: 10 }}>
32
- {isDark
33
- ? <DarkMode width={22} height={22} color={colors.text.primary} style={[I18nManager.isRTL && {transform:[{scaleX: -1}]}]}/>
34
- : <LightMode width={24} height={24} color={colors.text.primary} style={[I18nManager.isRTL && {transform:[{scaleX: -1}]}]}/>
35
- }
40
+ <View style={{ flexDirection: isRTL ? "row" : "row-reverse", alignItems: "center",justifyContent:"space-between"}}>
41
+ <View style={{flexDirection: isRTL ? "row" : "row-reverse", gap: isDark ? 20:17}}>
42
+ {isDark ? (
43
+ <DarkMode width={22} height={22} color={colors.text.primary} />
44
+ ) : (
45
+ <LightMode width={26} height={26} color={colors.text.primary} />
46
+ )}
36
47
 
37
48
  {label && (
38
- <Text style={{
39
- fontFamily: Fonts.montserrat.regular,
40
- fontSize: textSize.md,
41
- color: colors.text.primary,
42
-
43
- }}>
49
+ <Text style={{ fontFamily: Fonts.montserrat.semiBold, fontSize: textSize.md, color: colors.text.primary }}>
44
50
  {label}
45
51
  </Text>
46
52
  )}
47
-
48
- <TouchableOpacity onPress={toggleTheme} activeOpacity={0.9}>
49
- <View style={{ width: TRACK_W, height: TRACK_H }}>
50
- {/* Track SVG — fill + border */}
51
- <Svg
52
- width={TRACK_W}
53
- height={TRACK_H}
54
- viewBox="0 0 58 34"
55
- style={{ position: "absolute" }}
56
- >
57
- {/* Fill */}
58
- <Path
59
- d="M0.576172 16.5552C0.576172 7.71862 7.73962 0.555176 16.5762 0.555176H40.5762C49.4127 0.555176 56.5762 7.71862 56.5762 16.5552C56.5762 25.3917 49.4127 32.5552 40.5762 32.5552H16.5762C7.73961 32.5552 0.576172 25.3917 0.576172 16.5552Z"
60
- fill={colors.primary}
61
- />
62
- {/* Border */}
63
- <Path
64
- d="M16.5762 0.555176C19.0518 0.621842 21.5273 0.685176 24.0029 0.745176C29.5273 0.87907 35.0518 0.996364 40.5762 1.09706C48.8146 1.06558 55.9659 8.51881 55.6907 16.5552C55.6907 16.5552 55.6907 16.5552 55.6907 16.5552C55.8007 24.604 48.5576 31.7464 40.5762 31.5552C32.5762 31.5552 24.5762 31.59 16.5762 31.6596C8.54491 31.9309 1.10353 24.7824 1.13849 16.5552C1.13849 16.5552 1.13849 16.5552 1.13849 16.5552C0.96865 10.834 4.30374 5.12979 9.49713 2.41467C11.6569 1.26135 14.098 0.618935 16.5762 0.555176C14.0986 0.48538 11.5935 1.00216 9.32675 2.07501C3.8814 4.58411 0.0515389 10.4081 0.0138575 16.5552C0.0138575 16.5552 0.0138575 16.5552 0.0138575 16.5552C-0.365635 25.3731 7.56226 33.5939 16.5762 33.4507C24.5762 33.5204 32.5762 33.5552 40.5762 33.5552C40.5762 33.5552 40.5762 33.5552 40.5762 33.5552C49.6399 33.7784 57.7661 25.5516 57.4616 16.5552C57.4616 16.5552 57.4616 16.5552 57.4616 16.5552C57.6009 7.54638 49.383 -0.369685 40.5762 0.0132933C35.0518 0.113988 29.5273 0.231282 24.0029 0.365176C21.5273 0.425176 19.0518 0.488509 16.5762 0.555176ZM16.5762 0.555176"
65
- fill={colors.text.primary}
66
- />
67
- </Svg>
68
-
69
- {/* Thumb */}
70
- <Animated.View style={{
71
- position: "absolute",
72
- top: MARGIN,
73
- ...(I18nManager.isRTL ? { right: MARGIN } : { left: MARGIN }),
74
- width: THUMB,
75
- height: THUMB,
76
- borderRadius: THUMB / 2,
77
- backgroundColor: colors.text.primary,
78
- transform: [{ translateX }],
79
- overflow: "hidden",
53
+ </View>
54
+ <TouchableOpacity
55
+ onPress={toggleTheme}
56
+ activeOpacity={0.9}
57
+ accessibilityRole="switch"
58
+ accessibilityState={{ checked: isDark }}
59
+ >
60
+ <View
61
+ style={{
62
+ width: TRACK_W,
63
+ height: TRACK_H,
64
+ borderRadius: TRACK_H / 2,
65
+ backgroundColor: colors.primary,
66
+ borderWidth: 1,
67
+ borderColor: colors.text.primary,
80
68
  justifyContent: "center",
81
- alignItems: "center",
82
- shadowColor: "#000",
83
- shadowOffset: { width: 0, height: 2 },
84
- shadowOpacity: 0.25,
85
- shadowRadius: 3,
86
- elevation: 4,
87
- }}>
88
- {isDark
89
- ? <LightMode width={20} height={20} color={colors.background.main} style={[I18nManager.isRTL && {transform:[{scaleX: -1}]}]}/>
90
- : <DarkMode width={16} height={16} color={colors.background.main} style={[I18nManager.isRTL && {transform:[{scaleX: -1}]}]}/>
91
- }
69
+ }}
70
+ >
71
+ <Animated.View
72
+ style={{
73
+ position: "absolute",
74
+ top: (TRACK_H - THUMB) / 2 - 1,
75
+ ...(isRTL ? { right: MARGIN - 1 } : { left: MARGIN - 1 }),
76
+ width: THUMB,
77
+ height: THUMB,
78
+ borderRadius: THUMB / 2,
79
+ backgroundColor: colors.text.primary,
80
+ alignItems: "center",
81
+ justifyContent: "center",
82
+ transform: [{ translateX }],
83
+ elevation: 3,
84
+ shadowColor: "#000",
85
+ shadowOffset: { width: 0, height: 2 },
86
+ shadowOpacity: 0.25,
87
+ shadowRadius: 3,
88
+ }}
89
+ >
90
+ {isDark ? (
91
+ <LightMode width={16} height={16} color={colors.background.main} />
92
+ ) : (
93
+ <DarkMode width={12} height={12} color={colors.background.main} />
94
+ )}
92
95
  </Animated.View>
93
96
  </View>
94
97
  </TouchableOpacity>