@tactics/toddle-styleguide 1.2.8 → 1.3.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.
Files changed (106) hide show
  1. package/App.tsx +11 -0
  2. package/index.d.ts +2 -1
  3. package/index.tsx +2 -0
  4. package/package.json +1 -1
  5. package/src/components/atoms/calendar/__snapshots__/calendar.test.js.snap +18 -18
  6. package/src/components/atoms/line/line.component.d.ts +12 -0
  7. package/src/components/atoms/line/line.component.tsx +23 -0
  8. package/src/components/atoms/line/line.preview.d.ts +1 -0
  9. package/src/components/atoms/line/line.preview.tsx +54 -0
  10. package/src/components/atoms/line/line.styles.d.ts +12 -0
  11. package/src/components/atoms/line/line.styles.js +10 -0
  12. package/src/components/atoms/quick-message/__snapshots__/quick-message.test.js.snap +72 -1
  13. package/src/components/atoms/quick-message/quick-message.component.d.ts +2 -0
  14. package/src/components/atoms/quick-message/quick-message.component.tsx +3 -1
  15. package/src/components/atoms/quick-message/quick-message.preview.tsx +10 -1
  16. package/src/components/atoms/quick-message/quick-message.styles.d.ts +4 -1
  17. package/src/components/atoms/quick-message/quick-message.styles.js +4 -2
  18. package/src/components/atoms/quick-message/quick-message.test.js +38 -6
  19. package/src/components/atoms/text-input/__snapshots__/text-input.test.js.snap +38 -78
  20. package/src/components/atoms/text-input/text-input.component.tsx +6 -9
  21. package/src/components/atoms/text-input/text-input.preview.tsx +3 -3
  22. package/src/components/atoms/text-input/text-input.styles.d.ts +9 -25
  23. package/src/components/atoms/text-input/text-input.styles.js +7 -13
  24. package/src/components/molecules/day/__snapshots__/day.test.js.snap +24 -24
  25. package/src/components/molecules/day/day.component.tsx +17 -4
  26. package/src/components/molecules/day/day.styles.d.ts +33 -42
  27. package/src/components/molecules/day/day.styles.js +14 -17
  28. package/src/components/molecules/failed-to-send/failed-bubble.component.d.ts +2 -2
  29. package/src/components/molecules/failed-to-send/failed-bubble.component.tsx +39 -22
  30. package/src/components/molecules/password-input/__snapshots__/password-input.test.js.snap +53 -68
  31. package/src/components/molecules/password-input/password-input.component.tsx +7 -9
  32. package/src/components/molecules/password-input/password-input.styles.d.ts +8 -7
  33. package/src/components/molecules/password-input/password-input.styles.js +6 -6
  34. package/src/components/molecules/search-input/__snapshots__/search.test.js.snap +30 -31
  35. package/src/components/molecules/search-input/search.component.d.ts +9 -11
  36. package/src/components/molecules/search-input/search.component.tsx +19 -30
  37. package/src/components/molecules/search-input/search.preview.tsx +8 -6
  38. package/src/components/molecules/search-input/search.styles.d.ts +12 -11
  39. package/src/components/molecules/search-input/search.styles.js +14 -8
  40. package/src/components/molecules/search-input/search.test.js +3 -1
  41. package/src/components/molecules/send-bubble/__snapshots__/send-text-bubble.test.js.snap +12 -32
  42. package/src/components/molecules/send-bubble/send-text-bubble.component.d.ts +4 -4
  43. package/src/components/molecules/send-bubble/send-text-bubble.component.tsx +36 -25
  44. package/src/components/molecules/send-bubble/send-text-bubble.styles.d.ts +4 -7
  45. package/src/components/molecules/send-bubble/send-text-bubble.styles.js +2 -8
  46. package/src/components/molecules/timeline/__snapshots__/timeline.test.js.snap +4 -4
  47. package/src/components/molecules/timeline/timeline.styles.d.ts +1 -1
  48. package/src/components/molecules/timeline/timeline.styles.js +2 -2
  49. package/src/components/molecules/timestamp/__snapshots__/timestamp.test.js.snap +2 -1
  50. package/src/components/molecules/timestamp/timestamp.component.d.ts +2 -1
  51. package/src/components/molecules/timestamp/timestamp.component.tsx +4 -7
  52. package/src/components/organisms/child-list-item/__snapshots__/child-list-item.test.js.snap +165 -10
  53. package/src/components/organisms/child-list-item/child-list-item.component.d.ts +2 -0
  54. package/src/components/organisms/child-list-item/child-list-item.component.tsx +24 -1
  55. package/src/components/organisms/child-list-item/child-list-item.preview.tsx +11 -0
  56. package/src/components/organisms/child-list-item/child-list-item.styles.d.ts +0 -3
  57. package/src/components/organisms/child-list-item/child-list-item.styles.js +2 -3
  58. package/src/components/organisms/child-list-item/child-list-item.test.js +9 -4
  59. package/src/components/organisms/child-list-item/components/child-list-tag.component.d.ts +9 -0
  60. package/src/components/organisms/child-list-item/components/child-list-tag.component.tsx +28 -0
  61. package/src/components/organisms/child-list-item/components/child-list-tag.styles.d.ts +13 -0
  62. package/src/components/organisms/child-list-item/components/child-list-tag.styles.js +16 -0
  63. package/src/components/organisms/day-select/day-select.preview.tsx +9 -5
  64. package/src/components/organisms/journal-entry/components/entry-type-indicator/entry-type-indicator.d.ts +9 -0
  65. package/src/components/organisms/journal-entry/components/entry-type-indicator/entry-type-indicator.styles.d.ts +13 -0
  66. package/src/components/organisms/journal-entry/components/entry-type-indicator/entry-type-indicator.styles.js +17 -0
  67. package/src/components/organisms/journal-entry/components/entry-type-indicator/entry-type-indicator.test.js +21 -0
  68. package/src/components/organisms/journal-entry/components/entry-type-indicator/entry-type-indicator.tsx +97 -0
  69. package/src/components/organisms/journal-entry/components/index.d.ts +2 -0
  70. package/src/components/organisms/journal-entry/components/index.ts +2 -0
  71. package/src/components/organisms/journal-entry/components/journal-entry-type/__snapshots__/journal-entry-type.test.js.snap +304 -0
  72. package/src/components/organisms/journal-entry/components/journal-entry-type/journal-entry-type.component.d.ts +16 -0
  73. package/src/components/organisms/journal-entry/components/journal-entry-type/journal-entry-type.component.tsx +60 -0
  74. package/src/components/organisms/journal-entry/components/journal-entry-type/journal-entry-type.styles.d.ts +13 -0
  75. package/src/components/organisms/journal-entry/components/journal-entry-type/journal-entry-type.styles.js +16 -0
  76. package/src/components/organisms/journal-entry/components/journal-entry-type/journal-entry-type.test.js +48 -0
  77. package/src/components/organisms/journal-entry/journal-entry.component.d.ts +38 -0
  78. package/src/components/organisms/journal-entry/journal-entry.component.tsx +139 -0
  79. package/src/components/organisms/journal-entry/journal-entry.preview.d.ts +1 -0
  80. package/src/components/organisms/journal-entry/journal-entry.preview.tsx +212 -0
  81. package/src/components/organisms/journal-entry/journal-entry.styles.d.ts +42 -0
  82. package/src/components/organisms/journal-entry/journal-entry.styles.js +35 -0
  83. package/src/components/organisms/my-child-list-item/__snapshots__/my-child-list-item.test.js.snap +143 -399
  84. package/src/components/organisms/my-child-list-item/my-child-list-item.component.d.ts +5 -7
  85. package/src/components/organisms/my-child-list-item/my-child-list-item.component.tsx +32 -59
  86. package/src/components/organisms/my-child-list-item/my-child-list-item.preview.tsx +36 -24
  87. package/src/components/organisms/my-child-list-item/my-child-list-item.styles.d.ts +15 -11
  88. package/src/components/organisms/my-child-list-item/my-child-list-item.styles.js +16 -11
  89. package/src/components/organisms/my-child-list-item/my-child-list-item.test.js +5 -22
  90. package/src/components/organisms/text-bubble/__snapshots__/text-bubble.test.js.snap +45 -29
  91. package/src/components/organisms/text-bubble/text-bubble.component.d.ts +8 -6
  92. package/src/components/organisms/text-bubble/text-bubble.component.tsx +14 -12
  93. package/src/components/organisms/text-bubble/text-bubble.preview.tsx +14 -19
  94. package/src/components/organisms/text-bubble/text-bubble.styles.d.ts +14 -3
  95. package/src/components/organisms/text-bubble/text-bubble.styles.js +6 -0
  96. package/src/components/organisms/text-bubble/text-bubble.test.js +7 -7
  97. package/src/components/templates/modal/components/fade-panel.component.tsx +1 -1
  98. package/src/utilities/toddle-datetime/interfaces/toddle-datetime.interface.d.ts +4 -0
  99. package/src/utilities/toddle-datetime/interfaces/toddle-datetime.interface.tsx +6 -0
  100. package/src/utilities/toddle-datetime/toddle-datetime.class.d.ts +14 -1
  101. package/src/utilities/toddle-datetime/toddle-datetime.class.tsx +31 -2
  102. package/src/utilities/toddle-datetime/toddle-datetime.preview.tsx +114 -84
  103. package/src/utilities/toddle-datetime/types/{duration-like.type.d.ts → duration.type.d.ts} +2 -0
  104. package/src/utilities/toddle-datetime/types/{duration-like.type.tsx → duration.type.tsx} +3 -0
  105. package/src/utilities/toddle-datetime/types/toddle-datetime.type.d.ts +1 -0
  106. package/src/utilities/toddle-datetime/types/toddle-datetime.type.tsx +8 -1
@@ -6,11 +6,12 @@ type TextBubbleProps = {
6
6
  text: string;
7
7
  visualState: VisualState;
8
8
  bubbleAlignment: BubbleAlignment;
9
- timestamp: ToddleDateTime;
10
- send: boolean;
11
- onFail: (id: string) => void;
12
- onEdit: (id: string) => void;
13
- onDelete: (id: string) => void;
9
+ timestamp?: ToddleDateTime;
10
+ timestampLabel?: string;
11
+ sendOrReceived: boolean;
12
+ onFail?: (id: string) => void;
13
+ onEdit?: (id: string) => void;
14
+ onDelete?: (id: string) => void;
14
15
  };
15
16
  declare const TextBubble: ({
16
17
  id,
@@ -18,7 +19,8 @@ declare const TextBubble: ({
18
19
  visualState,
19
20
  bubbleAlignment,
20
21
  timestamp,
21
- send,
22
+ timestampLabel,
23
+ sendOrReceived,
22
24
  onFail,
23
25
  onEdit,
24
26
  onDelete,
@@ -1,9 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import {useContext, useEffect, useState} from 'react';
3
-
4
3
  import {View} from 'react-native';
5
4
  import {ThemeCtx} from '../../../context/theme.context';
6
-
7
5
  import {Stylesheet} from './text-bubble.styles';
8
6
  import {VisualState} from '../../../types/visual-state.enum';
9
7
  import {BubbleAlignment} from '../../../types/bubble-alignment.enum';
@@ -17,11 +15,12 @@ type TextBubbleProps = {
17
15
  text: string;
18
16
  visualState: VisualState;
19
17
  bubbleAlignment: BubbleAlignment;
20
- timestamp: ToddleDateTime;
21
- send: boolean;
22
- onFail: (id: string) => void;
23
- onEdit: (id: string) => void;
24
- onDelete: (id: string) => void;
18
+ timestamp?: ToddleDateTime;
19
+ timestampLabel?: string;
20
+ sendOrReceived: boolean;
21
+ onFail?: (id: string) => void;
22
+ onEdit?: (id: string) => void;
23
+ onDelete?: (id: string) => void;
25
24
  };
26
25
 
27
26
  const TextBubble = ({
@@ -30,7 +29,8 @@ const TextBubble = ({
30
29
  visualState,
31
30
  bubbleAlignment,
32
31
  timestamp,
33
- send,
32
+ timestampLabel,
33
+ sendOrReceived,
34
34
  onFail,
35
35
  onEdit,
36
36
  onDelete,
@@ -46,7 +46,7 @@ const TextBubble = ({
46
46
 
47
47
  return (
48
48
  <View style={styles.rootContainer}>
49
- {send ? (
49
+ {sendOrReceived ? (
50
50
  <View style={styles.textBubbleRootContainer}>
51
51
  <SendTextBubble
52
52
  id={id}
@@ -67,9 +67,11 @@ const TextBubble = ({
67
67
  />
68
68
  </View>
69
69
  )}
70
- <View style={styles.timestampContainer}>
71
- <Timestamp sent={timestamp} />
72
- </View>
70
+ {timestamp ? (
71
+ <View style={styles.timestampContainer}>
72
+ <Timestamp sent={timestamp} label={timestampLabel} />
73
+ </View>
74
+ ) : null}
73
75
  </View>
74
76
  );
75
77
  };
@@ -9,6 +9,9 @@ const {View} = require('react-native');
9
9
  export const TextBubblePreview = ({}: {}) => {
10
10
  const [sentTimeMessage, setSentTimeMessage] = useState(ToddleDateTime.now());
11
11
 
12
+ const dateTimeString = '2023-11-28T09:12:00';
13
+ const alternativeDateTime = ToddleDateTime.fromISO(dateTimeString);
14
+
12
15
  return (
13
16
  <View
14
17
  style={{
@@ -22,8 +25,9 @@ export const TextBubblePreview = ({}: {}) => {
22
25
  text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam suscipit velit in nibh varius, quis accumsan tellus maximus."
23
26
  bubbleAlignment={BubbleAlignment.SENT}
24
27
  visualState={VisualState.DEFAULT}
25
- timestamp={sentTimeMessage}
26
- send={true}
28
+ timestamp={alternativeDateTime}
29
+ timestampLabel={'ingevuld op'}
30
+ sendOrReceived={true}
27
31
  onFail={() => alert('Try to resend')}
28
32
  onEdit={() => alert('Edit the message')}
29
33
  onDelete={() => alert('Delete the message')}
@@ -34,10 +38,7 @@ export const TextBubblePreview = ({}: {}) => {
34
38
  bubbleAlignment={BubbleAlignment.RECEIVE}
35
39
  visualState={VisualState.WARNING}
36
40
  timestamp={sentTimeMessage}
37
- send={true}
38
- onFail={() => alert('Try to resend')}
39
- onEdit={() => alert('Edit the message')}
40
- onDelete={() => alert('Delete the message')}
41
+ sendOrReceived={true}
41
42
  />
42
43
  <TextBubble
43
44
  id={'3'}
@@ -45,18 +46,15 @@ export const TextBubblePreview = ({}: {}) => {
45
46
  bubbleAlignment={BubbleAlignment.RECEIVE}
46
47
  visualState={VisualState.DEFAULT}
47
48
  timestamp={sentTimeMessage}
48
- send={true}
49
- onFail={() => alert('Try to resend')}
50
- onEdit={() => alert('Edit the message')}
51
- onDelete={() => alert('Delete the message')}
49
+ sendOrReceived={true}
52
50
  />
53
51
  <TextBubble
54
52
  id={'4'}
55
53
  text="Error!"
56
54
  bubbleAlignment={BubbleAlignment.SENT}
57
- visualState={VisualState.ERROR}
55
+ visualState={VisualState.WARNING}
58
56
  timestamp={sentTimeMessage}
59
- send={false}
57
+ sendOrReceived={false}
60
58
  onFail={() => alert('Try to resend')}
61
59
  onEdit={() => alert('Edit the message')}
62
60
  onDelete={() => alert('Delete the message')}
@@ -65,9 +63,9 @@ export const TextBubblePreview = ({}: {}) => {
65
63
  id={'5'}
66
64
  text="Niet verzonden! Probeer het opnieuw aub! Swipe en refresh!"
67
65
  bubbleAlignment={BubbleAlignment.SENT}
68
- visualState={VisualState.ERROR}
66
+ visualState={VisualState.WARNING}
69
67
  timestamp={sentTimeMessage}
70
- send={false}
68
+ sendOrReceived={false}
71
69
  onFail={() => alert('Try to resend')}
72
70
  onEdit={() => alert('Edit the message')}
73
71
  onDelete={() => alert('Delete the message')}
@@ -76,12 +74,9 @@ export const TextBubblePreview = ({}: {}) => {
76
74
  id={'6'}
77
75
  text="We hebben uw betaling van vorige maand nog niet ontvangen!"
78
76
  bubbleAlignment={BubbleAlignment.RECEIVE}
79
- visualState={VisualState.ERROR}
77
+ visualState={VisualState.WARNING}
80
78
  timestamp={sentTimeMessage}
81
- send={true}
82
- onFail={() => alert('Try to resend')}
83
- onEdit={() => alert('Edit the message')}
84
- onDelete={() => alert('Delete the message')}
79
+ sendOrReceived={true}
85
80
  />
86
81
  </View>
87
82
  );
@@ -4,9 +4,18 @@ export function Stylesheet(
4
4
  ):
5
5
  | StyleSheet.NamedStyles<any>
6
6
  | StyleSheet.NamedStyles<{
7
- rootContainer: {
8
- width: string;
9
- }[];
7
+ rootContainer: (
8
+ | {
9
+ width: string;
10
+ gap: number;
11
+ marginLeft?: undefined;
12
+ }
13
+ | {
14
+ marginLeft: number;
15
+ width?: undefined;
16
+ gap?: undefined;
17
+ }
18
+ )[];
10
19
  textBubbleRootContainer: (
11
20
  | {
12
21
  maxWidth: string;
@@ -34,11 +43,13 @@ export function Stylesheet(
34
43
  timestampContainer: (
35
44
  | {
36
45
  maxWidth: string;
46
+ marginBottom: number;
37
47
  alignSelf?: undefined;
38
48
  }
39
49
  | {
40
50
  alignSelf: string;
41
51
  maxWidth?: undefined;
52
+ marginBottom?: undefined;
42
53
  }
43
54
  )[];
44
55
  }>;
@@ -1,11 +1,16 @@
1
1
  import {StyleSheet} from 'react-native';
2
2
  import {BubbleAlignment} from '../../../types/bubble-alignment.enum';
3
+ import {Scale} from '../../../theme/scale/index';
3
4
 
4
5
  export const Stylesheet = (context, bubbleAlignment) =>
5
6
  StyleSheet.create({
6
7
  rootContainer: [
7
8
  {
8
9
  width: '100%',
10
+ gap: Scale.xxs,
11
+ },
12
+ bubbleAlignment === BubbleAlignment.RECEIVE && {
13
+ marginLeft: Scale.l,
9
14
  },
10
15
  ],
11
16
  textBubbleRootContainer: [
@@ -29,6 +34,7 @@ export const Stylesheet = (context, bubbleAlignment) =>
29
34
  timestampContainer: [
30
35
  {
31
36
  maxWidth: '80%',
37
+ marginBottom: Scale.xxxs,
32
38
  },
33
39
  bubbleAlignment === BubbleAlignment.SENT && {
34
40
  alignSelf: 'flex-end',
@@ -20,7 +20,7 @@ describe('test text-bubble', () => {
20
20
  onFail={() => alert('resend the message')}
21
21
  onDelete={() => alert('delete the message')}
22
22
  onEdit={() => alert('edit the message')}
23
- send={true}
23
+ sendOrReceived={true}
24
24
  />
25
25
  )
26
26
  .toJSON();
@@ -39,7 +39,7 @@ describe('test text-bubble', () => {
39
39
  onFail={() => alert('resend the message')}
40
40
  onDelete={() => alert('delete the message')}
41
41
  onEdit={() => alert('edit the message')}
42
- send={true}
42
+ sendOrReceived={true}
43
43
  />
44
44
  )
45
45
  .toJSON();
@@ -58,7 +58,7 @@ describe('test text-bubble', () => {
58
58
  onFail={() => alert('resend the message')}
59
59
  onDelete={() => alert('delete the message')}
60
60
  onEdit={() => alert('edit the message')}
61
- send={true}
61
+ sendOrReceived={true}
62
62
  />
63
63
  )
64
64
  .toJSON();
@@ -77,7 +77,7 @@ describe('test text-bubble', () => {
77
77
  onFail={() => alert('resend the message')}
78
78
  onDelete={() => alert('delete the message')}
79
79
  onEdit={() => alert('edit the message')}
80
- send={true}
80
+ sendOrReceived={true}
81
81
  />
82
82
  )
83
83
  .toJSON();
@@ -96,7 +96,7 @@ describe('test text-bubble', () => {
96
96
  onFail={() => alert('resend the message')}
97
97
  onDelete={() => alert('delete the message')}
98
98
  onEdit={() => alert('edit the message')}
99
- send={true}
99
+ sendOrReceived={true}
100
100
  />
101
101
  )
102
102
  .toJSON();
@@ -115,7 +115,7 @@ describe('test text-bubble', () => {
115
115
  onFail={() => alert('resend the message')}
116
116
  onDelete={() => alert('delete the message')}
117
117
  onEdit={() => alert('edit the message')}
118
- send={true}
118
+ sendOrReceived={true}
119
119
  />
120
120
  )
121
121
  .toJSON();
@@ -134,7 +134,7 @@ describe('test text-bubble', () => {
134
134
  onFail={() => alert('resend the message')}
135
135
  onDelete={() => alert('delete the message')}
136
136
  onEdit={() => alert('edit the message')}
137
- send={false}
137
+ sendOrReceived={false}
138
138
  />
139
139
  )
140
140
  .toJSON();
@@ -36,7 +36,7 @@ export const FadePanel = ({
36
36
  } else if (!isVisible) {
37
37
  Animated.timing(fadeAnimation, {
38
38
  toValue: 0,
39
- duration: 600,
39
+ duration: 100,
40
40
  useNativeDriver: true,
41
41
  }).start();
42
42
  }
@@ -1,3 +1,4 @@
1
+ import {ConversionAccuracy} from '../types/toddle-datetime.type';
1
2
  export interface LocaleOptions {
2
3
  /**
3
4
  * @default system's locale
@@ -16,3 +17,6 @@ export interface DateTimeOptions extends LocaleOptions {
16
17
  */
17
18
  setZone?: boolean | undefined;
18
19
  }
20
+ export interface DiffOptions {
21
+ conversionAccuracy?: ConversionAccuracy | undefined;
22
+ }
@@ -1,3 +1,5 @@
1
+ import {ConversionAccuracy} from '../types/toddle-datetime.type';
2
+
1
3
  export interface LocaleOptions {
2
4
  /**
3
5
  * @default system's locale
@@ -17,3 +19,7 @@ export interface DateTimeOptions extends LocaleOptions {
17
19
  */
18
20
  setZone?: boolean | undefined;
19
21
  }
22
+
23
+ export interface DiffOptions {
24
+ conversionAccuracy?: ConversionAccuracy | undefined;
25
+ }
@@ -1,13 +1,21 @@
1
+ import {Duration as LuxonDuration} from 'luxon';
1
2
  import {
2
3
  LocaleOptions,
3
4
  DateTimeOptions,
5
+ DiffOptions,
4
6
  } from './interfaces/toddle-datetime.interface';
5
- import {DurationLike} from './types/duration-like.type';
7
+ import {DurationLike, DurationUnits} from './types/duration.type';
6
8
  import {
7
9
  DateTimeFormatOptions,
8
10
  DateTimeJSOptions,
9
11
  DateTimeUnit,
10
12
  } from './types/toddle-datetime.type';
13
+ import {DurationObjectUnits} from './interfaces/duration.interface';
14
+ export declare class Duration {
15
+ private duration;
16
+ constructor(duration: LuxonDuration);
17
+ toObject(): DurationObjectUnits;
18
+ }
11
19
  export declare class ToddleDateTime {
12
20
  private dateTime;
13
21
  private constructor();
@@ -91,4 +99,9 @@ export declare class ToddleDateTime {
91
99
  options?: LocaleOptions
92
100
  ): string;
93
101
  timestamp(): number;
102
+ diff(
103
+ otherDateTime: ToddleDateTime,
104
+ unit?: DurationUnits,
105
+ options?: DiffOptions
106
+ ): Duration;
94
107
  }
@@ -1,16 +1,30 @@
1
- import {DateTime as LuxonDateTime} from 'luxon';
1
+ import {DateTime as LuxonDateTime, Duration as LuxonDuration} from 'luxon';
2
2
 
3
3
  import {
4
4
  LocaleOptions,
5
5
  DateTimeOptions,
6
+ DiffOptions,
6
7
  } from './interfaces/toddle-datetime.interface';
7
8
 
8
- import {DurationLike} from './types/duration-like.type';
9
+ import {DurationLike, DurationUnits} from './types/duration.type';
9
10
  import {
10
11
  DateTimeFormatOptions,
11
12
  DateTimeJSOptions,
12
13
  DateTimeUnit,
13
14
  } from './types/toddle-datetime.type';
15
+ import {DurationObjectUnits} from './interfaces/duration.interface';
16
+
17
+ export class Duration {
18
+ private duration: LuxonDuration;
19
+
20
+ constructor(duration: LuxonDuration) {
21
+ this.duration = duration;
22
+ }
23
+
24
+ toObject(): DurationObjectUnits {
25
+ return this.duration.toObject();
26
+ }
27
+ }
14
28
 
15
29
  export class ToddleDateTime {
16
30
  private dateTime: LuxonDateTime;
@@ -174,4 +188,19 @@ export class ToddleDateTime {
174
188
  timestamp(): number {
175
189
  return this.dateTime.toUnixInteger();
176
190
  }
191
+
192
+ // COMPARE
193
+
194
+ diff(
195
+ otherDateTime: ToddleDateTime,
196
+ unit?: DurationUnits,
197
+ options?: DiffOptions
198
+ ): Duration {
199
+ const luxonDuration = this.dateTime.diff(
200
+ otherDateTime.dateTime,
201
+ unit,
202
+ options
203
+ );
204
+ return new Duration(luxonDuration);
205
+ }
177
206
  }
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import {ToddleDateTime} from './toddle-datetime.class';
3
- import {View, ScrollView} from 'react-native';
3
+ import {ScrollView, View} from 'react-native';
4
4
  import {Paragraph} from '../../components/atoms/paragraph-components';
5
5
  import {Heading2, Heading4} from '../../components/atoms/heading-components';
6
6
 
@@ -12,97 +12,36 @@ export const ToddleDateTimePreview = ({}: {}) => {
12
12
  return (
13
13
  <View
14
14
  style={{
15
- marginTop: 50,
15
+ marginTop: 24,
16
16
  alignContent: 'center',
17
17
  justifyContent: 'center',
18
- paddingBottom: 50,
18
+ paddingBottom: 100,
19
19
  }}
20
20
  >
21
21
  <Heading2 bold={true} textAlign={'center'} addStyle={{marginBottom: 50}}>
22
22
  ToddleDateTime
23
23
  </Heading2>
24
+ <Heading4 addStyle={{paddingHorizontal: 16, marginBottom: 24}}>
25
+ ToddleDateTime is a wrapper around Luxon, and provides less
26
+ functionality. This can and or will expand through time. You can find
27
+ the implemented methods below:
28
+ </Heading4>
24
29
  <ScrollView contentContainerStyle={{padding: 16}}>
25
30
  <Heading4 bold={true}>.now()</Heading4>
26
- <Paragraph addStyle={{marginBottom: 12}}>{now.toString()}</Paragraph>
31
+ <Paragraph addStyle={{marginBottom: 12}}>
32
+ Create a DateTime for the current instant, in the system's time zone.
33
+ </Paragraph>
27
34
 
28
35
  <Heading4 bold={true}>
29
36
  .fromISO(date: string, options?: DateTimeOptions)
30
37
  </Heading4>
31
38
  <Paragraph addStyle={{marginBottom: 12}}>
32
- From ISO
33
- {'\n'}
34
- {fromISO.toString()}
35
- {'\n'}
36
- {'\n'}
37
- Date time in a zone with the fromISO method
38
- {'\n'}
39
- Europe/Brussels
40
- {'\n'}
41
- {ToddleDateTime.fromISO(fromISO.toString(), {
42
- zone: 'Europe/Brussels',
43
- }).toString()}
44
- {'\n'}
45
- {'\n'}
46
- America/Los_Angeles
47
- {'\n'}
48
- {ToddleDateTime.fromISO(fromISO.toString(), {
49
- zone: 'America/Los_Angeles',
50
- }).toString()}
39
+ Create a ToddleDateTime from an ISO 8601 string
51
40
  </Paragraph>
52
41
 
53
42
  <Heading4 bold={true}>.local()</Heading4>
54
- <Paragraph bold={true}>Create a local DateTime{'\n'}</Paragraph>
55
- <Paragraph addStyle={{marginBottom: 12}}>
56
- local now
57
- {'\n'}
58
- {ToddleDateTime.local().toISO()}
59
- {'\n'}
60
- {'\n'}
61
- local now in US east coast time
62
- {'\n'}
63
- {ToddleDateTime.local({zone: 'America/New_York'}).toISO()}
64
- {'\n'}
65
- {'\n'}
66
- year
67
- {'\n'}
68
- {ToddleDateTime.local(1989).toISO()}
69
- {'\n'}
70
- {'\n'}
71
- year and month
72
- {'\n'}
73
- {ToddleDateTime.local(1989, 8).toISO()}
74
- {'\n'}
75
- {'\n'}
76
- year, month and day with a French locale
77
- {'\n'}
78
- {ToddleDateTime.local(1989, 8, 9, {locale: 'fr'}).toISO()}
79
- {'\n'}
80
- {'\n'}
81
- year, month, day and hour
82
- {'\n'}
83
- {ToddleDateTime.local(1989, 8, 9, 23).toISO()}
84
- {'\n'}
85
- {'\n'}
86
- year, month, day and hour in UTC
87
- {'\n'}
88
- {ToddleDateTime.local(1989, 8, 9, 23, {zone: 'utc'}).toISO()}
89
- {'\n'}
90
- {'\n'}
91
- year, month, day, hour and minutes
92
- {'\n'}
93
- {ToddleDateTime.local(1989, 8, 9, 23, 45).toISO()}
94
- {'\n'}
95
- {'\n'}
96
- year, month, day, hour, minutes and seconds
97
- {'\n'}
98
- {ToddleDateTime.local(1989, 8, 9, 23, 45, 10).toISO()}
99
- {'\n'}
100
- {'\n'}
101
- year, month, day, hour, minutes, seconds and milliseconds
102
- {'\n'}
103
- {ToddleDateTime.local(1989, 8, 9, 23, 45, 10, 782).toISO()}
104
- {'\n'}
105
- {'\n'}
43
+ <Paragraph addStyle={{marginBottom: 12}}>
44
+ Create a local ToddleDateTime
106
45
  </Paragraph>
107
46
 
108
47
  <Heading4 bold={true}>.timestamp()</Heading4>
@@ -114,15 +53,106 @@ export const ToddleDateTimePreview = ({}: {}) => {
114
53
  </Paragraph>
115
54
 
116
55
  <Heading4 bold={true}>.fromSeconds(seconds, options?)</Heading4>
117
- <Paragraph>Returns a ToddleDateTime from a timestamp.</Paragraph>
118
- <Paragraph addStyle={{marginBottom: 12}}>
119
- {ToddleDateTime.fromSeconds(timestamp).toLocaleString({
120
- day: 'numeric',
121
- month: 'short',
122
- hourCycle: 'h24',
123
- hour: 'numeric',
124
- minute: '2-digit',
125
- })}
56
+ <Paragraph addStyle={{marginBottom: 12}}>
57
+ Create a ToddleDateTime from a number of seconds since the epoch
58
+ (meaning since 1 January 1970 00:00:00 UTC). Uses the default zone.
59
+ </Paragraph>
60
+
61
+ <Heading4 bold={true}>.DATE_MED()</Heading4>
62
+ <Paragraph addStyle={{marginBottom: 12}}>
63
+ ToddleDateTime.toLocaleString format like 'Oct 14, 1983'
64
+ </Paragraph>
65
+
66
+ <Heading4 bold={true}>.hour()</Heading4>
67
+ <Paragraph addStyle={{marginBottom: 12}}>
68
+ Get the hour of the day (0-23)
69
+ </Paragraph>
70
+
71
+ <Heading4 bold={true}>.minute()</Heading4>
72
+ <Paragraph addStyle={{marginBottom: 12}}>
73
+ Get the minute of the hour (0-59).
74
+ </Paragraph>
75
+
76
+ <Heading4 bold={true}>.second()</Heading4>
77
+ <Paragraph addStyle={{marginBottom: 12}}>
78
+ Get the second of the minute (0-59).
79
+ </Paragraph>
80
+
81
+ <Heading4 bold={true}>.millisecond()</Heading4>
82
+ <Paragraph addStyle={{marginBottom: 12}}>
83
+ Get the millisecond of the second (0-999).
84
+ </Paragraph>
85
+
86
+ <Heading4 bold={true}>.day()</Heading4>
87
+ <Paragraph addStyle={{marginBottom: 12}}>
88
+ Get the day of the month (1-30ish).
89
+ </Paragraph>
90
+
91
+ <Heading4 bold={true}>.weekdayShort()</Heading4>
92
+ <Paragraph addStyle={{marginBottom: 12}}>
93
+ Get the human readable short weekday, such as 'Mon'. Defaults to the
94
+ system's locale if no locale has been specified
95
+ </Paragraph>
96
+
97
+ <Heading4 bold={true}>.plus(duration)</Heading4>
98
+ <Paragraph addStyle={{marginBottom: 12}}>
99
+ {`Adding hours, minutes, seconds, or milliseconds increases the timestamp by the right number of milliseconds. Adding days, months, or years shifts the calendar, accounting for DSTs and leap years along the way. Thus, dt.plus({ hours: 24 }) may result in a different time than dt.plus({ days: 1 }) if there's a DST shift in between.`}
100
+ </Paragraph>
101
+
102
+ <Heading4 bold={true}>.minus(duration)</Heading4>
103
+ <Paragraph addStyle={{marginBottom: 12}}>
104
+ See ToddleDateTime plus()
105
+ </Paragraph>
106
+
107
+ <Heading4 bold={true}>.startOf(unit)</Heading4>
108
+ <Paragraph addStyle={{marginBottom: 12}}>
109
+ "Set" this ToddleDateTime to the beginning of the given unit.
110
+ </Paragraph>
111
+
112
+ <Heading4 bold={true}>.endOf(unit)</Heading4>
113
+ <Paragraph addStyle={{marginBottom: 12}}>
114
+ "Set" this ToddleDateTime to the end (meaning the last millisecond) of
115
+ a unit of time
116
+ </Paragraph>
117
+
118
+ <Heading4 bold={true}>.toFormat(format, options?)</Heading4>
119
+ <Paragraph addStyle={{marginBottom: 12}}>
120
+ Returns a string representation of this ToddleDateTime formatted
121
+ according to the specified format string.
122
+ </Paragraph>
123
+
124
+ <Heading4 bold={true}>.toISO()</Heading4>
125
+ <Paragraph addStyle={{marginBottom: 12}}>
126
+ Returns an ISO 8601-compliant string representation of this
127
+ ToddleDateTime
128
+ </Paragraph>
129
+
130
+ <Heading4 bold={true}>.toISODate()</Heading4>
131
+ <Paragraph addStyle={{marginBottom: 12}}>
132
+ Returns an ISO 8601-compliant string representation of this
133
+ ToddleDateTime's date component
134
+ </Paragraph>
135
+
136
+ <Heading4 bold={true}>.toString()</Heading4>
137
+ <Paragraph addStyle={{marginBottom: 12}}>
138
+ Returns a string representation of this DateTime appropriate for
139
+ debugging
140
+ </Paragraph>
141
+
142
+ <Heading4 bold={true}>
143
+ .toLocaleString(formatOptions?, options?)
144
+ </Heading4>
145
+ <Paragraph addStyle={{marginBottom: 12}}>
146
+ Returns a localized string representing this date.
147
+ </Paragraph>
148
+
149
+ <Heading4 bold={true}>.timestamp()</Heading4>
150
+ <Paragraph addStyle={{marginBottom: 12}}>
151
+ Returns the epoch seconds (as a whole number) of this ToddleDateTime.{' '}
152
+ </Paragraph>
153
+ <Heading4 bold={true}>.diff(otherDateTime, unit?, options?)</Heading4>
154
+ <Paragraph addStyle={{marginBottom: 12}}>
155
+ Return the difference between two ToddleDateTimes as a Duration.
126
156
  </Paragraph>
127
157
  </ScrollView>
128
158
  </View>
@@ -1,2 +1,4 @@
1
1
  import {DurationLikeObject} from '../interfaces/duration.interface';
2
+ export type DurationUnit = keyof DurationLikeObject;
3
+ export type DurationUnits = DurationUnit | DurationUnit[];
2
4
  export type DurationLike = DurationLikeObject | number;
@@ -1,3 +1,6 @@
1
1
  import {DurationLikeObject} from '../interfaces/duration.interface';
2
2
 
3
+ export type DurationUnit = keyof DurationLikeObject;
4
+ export type DurationUnits = DurationUnit | DurationUnit[];
5
+
3
6
  export type DurationLike = DurationLikeObject | number;
@@ -11,3 +11,4 @@ export type DateTimeUnit =
11
11
  | 'second'
12
12
  | 'millisecond';
13
13
  export type DateTimeJSOptions = Omit<DateTimeOptions, 'setZone'>;
14
+ export type ConversionAccuracy = 'casual' | 'longterm';