@tactics/toddle-styleguide 1.4.21 → 1.5.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": "@tactics/toddle-styleguide",
3
- "version": "1.4.21",
3
+ "version": "1.5.0",
4
4
  "main": "index.tsx",
5
5
  "types": "index.d.ts",
6
6
  "prepublish": "tsc",
@@ -3,8 +3,7 @@ import { ToddleDateTime } from '../../../utilities/toddle-datetime/toddle-dateti
3
3
  type CalendarSelectProps = {
4
4
  onPressDate: (date: ToddleDateTime) => void;
5
5
  startDate: ToddleDateTime;
6
- pressChevronRight: (date: ToddleDateTime) => void;
7
- pressChevronLeft: (date: ToddleDateTime) => void;
6
+ onUpdateDate: (date: ToddleDateTime) => void;
8
7
  };
9
- declare const CalendarSelect: ({ onPressDate, startDate, pressChevronLeft, pressChevronRight, }: CalendarSelectProps) => React.JSX.Element;
8
+ declare const CalendarSelect: ({ onPressDate, startDate, onUpdateDate, }: CalendarSelectProps) => React.JSX.Element;
10
9
  export { CalendarSelect as CalendarSelect };
@@ -6,35 +6,43 @@ import {Stylesheet} from './calendar-select.styles';
6
6
  import {Pressable, View} from 'react-native';
7
7
  import {Paragraph} from '../../atoms/paragraph-components';
8
8
  import {Icon} from '../../../icons/index';
9
+ import { useDebounce } from '../../../hooks/use-debounce';
9
10
 
10
11
  type CalendarSelectProps = {
11
12
  onPressDate: (date: ToddleDateTime) => void;
12
13
  startDate: ToddleDateTime;
13
- pressChevronRight: (date: ToddleDateTime) => void;
14
- pressChevronLeft: (date: ToddleDateTime) => void;
14
+ onUpdateDate: (date: ToddleDateTime) => void;
15
15
  };
16
16
 
17
17
  const CalendarSelect = ({
18
18
  onPressDate,
19
19
  startDate,
20
- pressChevronLeft,
21
- pressChevronRight,
20
+ onUpdateDate,
22
21
  }: CalendarSelectProps) => {
23
22
  const context = useContext(ThemeCtx);
24
23
  const styles = Stylesheet(context);
25
24
 
26
25
  const [visibleDate, setVisibleDate] = useState(startDate);
26
+ const debouncedVisibleDate = useDebounce<ToddleDateTime>(visibleDate, 500);
27
27
 
28
28
  useEffect(() => {
29
29
  setVisibleDate(startDate);
30
30
  }, [startDate]);
31
31
 
32
+ useEffect(() => {
33
+ // If they are the same dont trigger event again.
34
+ if (visibleDate !== startDate) {
35
+ onUpdateDate(debouncedVisibleDate);
36
+ }
37
+ }, [debouncedVisibleDate])
38
+
32
39
  return (
33
40
  <View style={styles.container}>
34
41
  <Pressable
35
42
  onPress={() => {
36
- pressChevronLeft(visibleDate.minus({days: 1}));
43
+ setVisibleDate(visibleDate.minus({days: 1}));
37
44
  }}
45
+ style={styles.arrowContainer}
38
46
  >
39
47
  <Icon style={'regular'} name={'chevron-left'} />
40
48
  </Pressable>
@@ -59,8 +67,9 @@ const CalendarSelect = ({
59
67
 
60
68
  <Pressable
61
69
  onPress={() => {
62
- pressChevronRight(visibleDate.plus({days: 1}));
70
+ setVisibleDate(visibleDate.plus({days: 1}));
63
71
  }}
72
+ style={styles.arrowContainer}
64
73
  >
65
74
  <Icon style={'regular'} name={'chevron-right'} />
66
75
  </Pressable>
@@ -13,8 +13,7 @@ export const CalendarSelectPreview = ({}: {}) => {
13
13
  <CalendarSelect
14
14
  onPressDate={() => console.log('open modal')}
15
15
  startDate={date}
16
- pressChevronRight={setDate}
17
- pressChevronLeft={setDate}
16
+ onUpdateDate={setDate}
18
17
  />
19
18
  </View>
20
19
  );
@@ -1,24 +1,27 @@
1
1
  export function Stylesheet(context: any): {
2
- container: {
3
- color: any;
4
- flexDirection: 'row';
5
- alignItems: 'center';
6
- justifyContent: 'space-between';
7
- };
8
- dateContainer: {
9
- flexDirection: 'row';
10
- backgroundColor: any;
11
- borderRadius: number;
12
- paddingTop: number;
13
- paddingBottom: number;
14
- paddingLeft: number;
15
- paddingRight: number;
16
- alignItems: 'center';
17
- };
18
- text: {
19
- color: any;
20
- };
21
- icon: {
22
- marginRight: number;
23
- };
2
+ container: {
3
+ color: any;
4
+ flexDirection: "row";
5
+ alignItems: "center";
6
+ justifyContent: "space-between";
7
+ };
8
+ dateContainer: {
9
+ flexDirection: "row";
10
+ backgroundColor: any;
11
+ borderRadius: number;
12
+ paddingTop: number;
13
+ paddingBottom: number;
14
+ paddingLeft: number;
15
+ paddingRight: number;
16
+ alignItems: "center";
17
+ };
18
+ arrowContainer: {
19
+ width: number;
20
+ height: number;
21
+ alignItems: "center";
22
+ justifyContent: "center";
23
+ };
24
+ icon: {
25
+ marginRight: number;
26
+ };
24
27
  };
@@ -19,6 +19,12 @@ export const Stylesheet = (context) =>
19
19
  paddingRight: Scale.l,
20
20
  alignItems: 'center',
21
21
  },
22
+ arrowContainer: {
23
+ width: Scale.xxl,
24
+ height: Scale.xxl,
25
+ alignItems: 'center',
26
+ justifyContent: 'center'
27
+ },
22
28
  icon: {
23
29
  marginRight: Scale.m,
24
30
  },
@@ -11,8 +11,8 @@ type TimeLineProps = {
11
11
  };
12
12
 
13
13
  export const TimeLine = ({checkIn, checkOut}: TimeLineProps) => {
14
- const startHour = 6;
15
- const endHour = 21;
14
+ const startHour = 0;
15
+ const endHour = 24;
16
16
 
17
17
  const calculateCheckInPosition = (checkInTime: string) => {
18
18
  const [hours, minutes] = checkInTime.split(':');
@@ -0,0 +1 @@
1
+ export declare function useDebounce<T>(value: T, delay?: number): T;
@@ -0,0 +1,15 @@
1
+ import { useEffect, useState } from 'react'
2
+
3
+ export function useDebounce<T>(value: T, delay?: number): T {
4
+ const [debouncedValue, setDebouncedValue] = useState<T>(value)
5
+
6
+ useEffect(() => {
7
+ const timer = setTimeout(() => setDebouncedValue(value), delay || 500)
8
+
9
+ return () => {
10
+ clearTimeout(timer)
11
+ }
12
+ }, [value, delay])
13
+
14
+ return debouncedValue
15
+ }