@towsila/expo-ui-library 4.6.0 → 4.7.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@towsila/expo-ui-library",
3
- "version": "4.6.0",
3
+ "version": "4.7.0",
4
4
  "description": "",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -0,0 +1,3 @@
1
+ <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M10.2891 1.00684C10.1017 1.63863 10 2.3074 10 3C10 6.86599 13.134 10 17 10C17.6924 10 18.3606 9.8972 18.9922 9.70996C18.9952 9.8063 19 9.90292 19 10C19 14.9706 14.9706 19 10 19C5.02944 19 1 14.9706 1 10C1 5.02944 5.02944 1 10 1C10.0967 1 10.1931 1.00381 10.2891 1.00684Z" stroke-width="2" stroke-linejoin="round" stroke="currentColor"/>
3
+ </svg>
@@ -0,0 +1,11 @@
1
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <circle cx="12" cy="12" r="4" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/>
3
+ <path d="M20 12H21" stroke-width="2" stroke-linecap="round" stroke="currentColor"/>
4
+ <path d="M3 12H4" stroke-width="2" stroke-linecap="round" stroke="currentColor"/>
5
+ <path d="M12 20L12 21" stroke-width="2" stroke-linecap="round" stroke="currentColor"/>
6
+ <path d="M12 3L12 4" stroke-width="2" stroke-linecap="round" stroke="currentColor"/>
7
+ <path d="M17.6572 17.6569L18.3643 18.364" stroke-width="2" stroke-linecap="round" stroke="currentColor"/>
8
+ <path d="M5.63574 5.63603L6.34285 6.34314" stroke-width="2" stroke-linecap="round" stroke="currentColor"/>
9
+ <path d="M6.34277 17.6569L5.63567 18.364" stroke-width="2" stroke-linecap="round" stroke="currentColor"/>
10
+ <path d="M18.3643 5.63603L17.6572 6.34314" stroke-width="2" stroke-linecap="round" stroke="currentColor"/>
11
+ </svg>
@@ -1,154 +1,100 @@
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";
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";
6
5
  import { useAppTheme } from "../../context/ThemeContext";
7
6
  import { useLanguage } from "../../context/LanguageContext";
8
- import { Menu } from "../../types/menu";
9
- import LanguageSelect from "./languageSelect";
10
7
  import { Fonts, textSize } from "../../tokens/typography";
11
- const SIDEBAR_WIDTH = Dimensions.get("window").width * 0.7;
12
8
 
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;
9
+ interface TextTheme {
10
+ label?: string;
23
11
  }
24
12
 
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;
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;
31
18
 
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]);
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;
61
23
 
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>
24
+ useEffect(() => {
25
+ Animated.spring(progress, {
26
+ toValue: isDark ? 1 : 0,
27
+ useNativeDriver: true,
28
+ bounciness: 6,
29
+ }).start();
30
+ }, [isDark]);
86
31
 
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>
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
+ });
127
37
 
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>
143
38
 
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>
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>
151
96
  </View>
152
- </Modal>
153
- )
97
+ </TouchableOpacity>
98
+ </View>
99
+ );
154
100
  }