dhre-ui-kit 0.0.61 → 0.0.62

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": "dhre-ui-kit",
3
- "version": "0.0.61",
3
+ "version": "0.0.62",
4
4
  "main": "src/index.ts",
5
5
  "files": [
6
6
  "src",
@@ -1,13 +1,10 @@
1
- import {ReactElement} from 'react';
2
- import {ViewStyle} from 'react-native';
3
-
4
- export interface TabsProps {
5
- tabs: {label: string}[];
6
- onTabPress?: (index: number) => void;
7
- testID?: string;
8
- hideTitle?: boolean;
9
- hideIcon?: boolean;
10
- initialTab?: number;
11
- icon?: ReactElement;
12
- iconStyle?: ViewStyle;
1
+ export interface Tab {
2
+ id: string;
3
+ title: string;
4
+ isSelected?: boolean;
5
+ }
6
+ export interface MultipleTabsProps {
7
+ tabs: Tab[];
8
+ initialSelected?: string[];
9
+ onSelectionChange?: (selectedTabs: Tab[]) => void;
13
10
  }
@@ -1,36 +1,24 @@
1
- import {DHRE_COLORS_TEXT} from '../../theme/colors';
2
- import {horizontalScale, verticalScale} from '../../utils/stylehelper';
3
1
  import {StyleSheet} from 'react-native';
2
+ import {
3
+ horizontalScale,
4
+ moderateScale,
5
+ verticalScale,
6
+ } from '../../utils/stylehelper';
4
7
 
5
- const styles = StyleSheet.create({
6
- tabsContainer: {
8
+ export default StyleSheet.create({
9
+ container: {
7
10
  flexDirection: 'row',
8
- alignItems: 'center',
11
+ gap: horizontalScale(5),
12
+ flexWrap: 'wrap',
9
13
  },
10
- tabItem: {
11
- flex: 1,
12
- flexDirection: 'row',
14
+ button: {
15
+ minWidth: horizontalScale(94),
16
+ minHeight: verticalScale(32),
17
+ paddingVertical: verticalScale(8),
18
+ paddingHorizontal: horizontalScale(12),
19
+ borderRadius: moderateScale(32),
13
20
  alignItems: 'center',
14
21
  justifyContent: 'center',
15
- paddingVertical: verticalScale(6),
16
- paddingHorizontal: horizontalScale(12),
17
- marginHorizontal: horizontalScale(8),
18
- borderRadius: 50,
19
- gap: horizontalScale(8),
20
- backgroundColor: DHRE_COLORS_TEXT.DH_BLACK,
21
- },
22
- label: {
23
- color: DHRE_COLORS_TEXT.DH_WHITE,
24
- },
25
- activeTab: {
26
- backgroundColor: DHRE_COLORS_TEXT.DH_BLACK,
27
- },
28
- inactiveTab: {
29
- backgroundColor: DHRE_COLORS_TEXT.DH_WHITE,
30
- },
31
- inActiveLabel: {
32
- color: DHRE_COLORS_TEXT.DH_TEXTLIGHTEST,
22
+ borderWidth: 1,
33
23
  },
34
24
  });
35
-
36
- export default styles;
@@ -1,64 +1,73 @@
1
1
  import React, {useState} from 'react';
2
- import {ScrollView, Pressable, View} from 'react-native';
3
- import CustomTypography from '../customTypography/CustomTypography';
2
+ import {Pressable, View, ViewStyle} from 'react-native';
4
3
  import styles from './Tabs.styles';
5
- import {TabsProps} from './Tabs.interface';
6
- import {DHRE_COLORS_TEXT} from '../../theme/colors';
4
+ import {FontStyle} from '../../utils/appEnum';
5
+ import CustomText from '../customText';
6
+ import {useTheme} from '../../theme/ThemeContext';
7
7
 
8
- const Tabs: React.FC<TabsProps> = ({
9
- tabs,
10
- onTabPress,
11
- testID,
12
- hideTitle = false,
13
- hideIcon = true,
14
- initialTab = 0,
15
- icon: Icon,
16
- iconStyle,
8
+ interface Props {
9
+ options: string[];
10
+ initialSelected?: string[];
11
+ onSelectionChange?: (selected: string[]) => void;
12
+ style?: ViewStyle;
13
+ }
14
+
15
+ const Tabs: React.FC<Props> = ({
16
+ options,
17
+ initialSelected = [],
18
+ onSelectionChange,
19
+ style,
17
20
  }) => {
18
- const [activeTab, setActiveTab] = useState(initialTab);
21
+ const {theme} = useTheme();
22
+
23
+ const [data, setData] = useState(
24
+ options.map(option => ({
25
+ title: option,
26
+ id: option,
27
+ isSelected: initialSelected?.includes(option),
28
+ })),
29
+ );
19
30
 
20
- const handleTabPress = (index: number) => {
21
- setActiveTab(index);
22
- if (onTabPress) {
23
- onTabPress(index);
31
+ const handlePress = (id: string) => {
32
+ const updatedData = data?.map(item =>
33
+ item?.id === id ? {...item, isSelected: !item?.isSelected} : item,
34
+ );
35
+ setData(updatedData);
36
+ const selectedTabs = updatedData
37
+ .filter(item => item?.isSelected)
38
+ .map(item => item?.id);
39
+ if (onSelectionChange) {
40
+ onSelectionChange(selectedTabs);
24
41
  }
25
42
  };
26
43
 
27
44
  return (
28
- <ScrollView
29
- testID={testID}
30
- horizontal
31
- showsHorizontalScrollIndicator={false}
32
- contentContainerStyle={styles.tabsContainer}>
33
- {tabs?.map((tab, index) => (
45
+ <View style={[styles.container, style]}>
46
+ {data?.map(({id, title, isSelected}) => (
34
47
  <Pressable
35
- testID={`Press-Tab-${index}`}
36
- key={index}
37
- onPress={() => handleTabPress(index)}
38
- style={[
39
- styles.tabItem,
40
- activeTab === index ? styles.activeTab : styles.inactiveTab,
41
- ]}>
42
- {!hideIcon && Icon && (
43
- <View style={iconStyle}>
44
- {React.cloneElement(Icon, {
45
- fill:
46
- activeTab === index
47
- ? DHRE_COLORS_TEXT.DH_WHITE
48
- : DHRE_COLORS_TEXT.DH_TEXTLIGHTEST,
49
- })}
50
- </View>
51
- )}
52
- {!hideTitle && (
53
- <CustomTypography
54
- variant={activeTab === index ? 'H8semiBold' : 'H8medium'}
55
- style={activeTab === index ? styles.label : styles.inActiveLabel}
56
- text={tab?.label}
57
- />
58
- )}
48
+ key={id}
49
+ style={{
50
+ ...styles.button,
51
+ backgroundColor: isSelected
52
+ ? theme.CONTENT_PRIMARY
53
+ : theme.CONTENT_INVERTED,
54
+ borderColor: isSelected
55
+ ? theme.CONTENT_INVERTED
56
+ : theme.CONTENT_SECONDRY,
57
+ }}
58
+ onPress={() => handlePress(id)}>
59
+ <CustomText
60
+ variant={FontStyle.L2_REGULAR}
61
+ style={{
62
+ color: isSelected
63
+ ? theme.CONTENT_INVERTED
64
+ : theme.CONTENT_SECONDRY,
65
+ }}
66
+ text={title}
67
+ />
59
68
  </Pressable>
60
69
  ))}
61
- </ScrollView>
70
+ </View>
62
71
  );
63
72
  };
64
73
 
@@ -1,20 +0,0 @@
1
- import React from 'react';
2
- import {it} from '@jest/globals';
3
- import {render} from '@testing-library/react-native';
4
- import Tabs from './Tabs';
5
-
6
- const mockProps = {
7
- tabs: [{label: 'Tabs'}],
8
- hideTitle: false,
9
- hideIcon: false,
10
- initialTab: 1,
11
- onTabPress: jest.fn(),
12
- testID: 'TABS-COMPONENT',
13
- };
14
-
15
- describe('Tabs Component', () => {
16
- it('Component renders correctly', () => {
17
- const {getByTestId} = render(<Tabs {...mockProps} />);
18
- expect(getByTestId('TABS-COMPONENT')).toBeTruthy();
19
- });
20
- });