@flightlesslabs/dodo-ui 0.10.2 → 0.11.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 (53) hide show
  1. package/dist/index.d.ts +3 -3
  2. package/dist/index.js +2 -2
  3. package/dist/stories/Home.mdx +1 -1
  4. package/dist/stories/components/Form/DatePicker/DatePicker.stories.svelte +16 -0
  5. package/dist/stories/components/Form/DatePicker/DatePicker.svelte +2 -1
  6. package/dist/stories/components/Form/DatePicker/DatePicker.svelte.d.ts +3 -1
  7. package/dist/stories/components/Form/DatePicker/Positions/AutoPosition/AutoPosition.stories.svelte +43 -0
  8. package/dist/stories/components/Form/DatePicker/Positions/AutoPosition/AutoPosition.stories.svelte.d.ts +18 -0
  9. package/dist/stories/components/Form/DatePicker/Positions/Positions.stories.svelte +54 -0
  10. package/dist/stories/components/Form/DatePicker/Positions/Positions.stories.svelte.d.ts +18 -0
  11. package/dist/stories/components/Form/Select/Options/OptionFormat.mdx +1 -1
  12. package/dist/stories/components/Info/Calendar/Calendar.stories.svelte +14 -0
  13. package/dist/stories/components/Info/Calendar/Calendar.svelte +2 -1
  14. package/dist/stories/components/Info/Calendar/Calendar.svelte.d.ts +3 -3
  15. package/dist/stories/components/Info/Calendar/SubComponents/CalendarDatesChart/CalendarDateChip/CalendarDateChip.svelte +2 -215
  16. package/dist/stories/components/Info/Calendar/SubComponents/CalendarDatesChart/CalendarDateChip/CalendarDateChip.svelte.d.ts +1 -7
  17. package/dist/stories/components/Info/Calendar/SubComponents/CalendarDatesChart/CalendarDateChip/utils/scss/mixins.scss +0 -46
  18. package/dist/stories/components/Info/Calendar/SubComponents/CalendarDatesChart/CalendarDatesChart.stories.svelte +14 -0
  19. package/dist/stories/components/Info/Calendar/SubComponents/CalendarDatesChart/CalendarDatesChart.svelte +3 -25
  20. package/dist/stories/components/Info/Calendar/SubComponents/CalendarDatesChart/CalendarDatesChart.svelte.d.ts +4 -5
  21. package/dist/stories/components/Info/Calendar/utils/createDateOfMonth/createDateOfMonth.d.ts +27 -0
  22. package/dist/stories/components/Info/Calendar/utils/createDateOfMonth/createDateOfMonth.js +72 -0
  23. package/dist/stories/components/Info/Calendar/utils/createDateOfMonth/index.mdx +121 -0
  24. package/dist/stories/components/Info/Calendar/utils/getDatesOfMonth/getDatesOfMonth.d.ts +10 -0
  25. package/dist/stories/components/Info/Calendar/utils/{getDatesOfMonth.js → getDatesOfMonth/getDatesOfMonth.js} +20 -13
  26. package/dist/stories/components/Info/Calendar/utils/getDatesOfMonth/index.mdx +37 -0
  27. package/dist/stories/components/Info/Calendar/utils/types.d.ts +0 -4
  28. package/dist/stories/components/Layout/Menu/DynamicMenu/Options/OptionFormat.mdx +1 -1
  29. package/dist/stories/developer tools/directives/clickOutside/index.mdx +1 -1
  30. package/dist/stories/developer tools/helpers/Numbers/cleanNumericString/index.mdx +1 -1
  31. package/dist/stories/developer tools/helpers/Numbers/isValidNumberValue/index.mdx +1 -1
  32. package/dist/stories/developer tools/helpers/Time/getMoment/getMoment.d.ts +10 -11
  33. package/dist/stories/developer tools/helpers/Time/getMoment/getMoment.js +8 -8
  34. package/dist/stories/developer tools/helpers/Time/getMoment/index.mdx +32 -5
  35. package/dist/stories/developer tools/helpers/logger/index.mdx +1 -1
  36. package/dist/stories/developer tools/philosophy/Colors/Colors.mdx +1 -1
  37. package/dist/stories/developer tools/philosophy/Themes.mdx +1 -1
  38. package/package.json +22 -26
  39. package/src/lib/index.ts +3 -3
  40. package/src/lib/stories/components/Form/DatePicker/DatePicker.svelte +10 -0
  41. package/src/lib/stories/components/Info/Calendar/Calendar.svelte +8 -2
  42. package/src/lib/stories/components/Info/Calendar/SubComponents/CalendarDatesChart/CalendarDateChip/CalendarDateChip.svelte +2 -25
  43. package/src/lib/stories/components/Info/Calendar/SubComponents/CalendarDatesChart/CalendarDateChip/utils/scss/mixins.scss +0 -46
  44. package/src/lib/stories/components/Info/Calendar/SubComponents/CalendarDatesChart/CalendarDatesChart.svelte +23 -53
  45. package/src/lib/stories/components/Info/Calendar/utils/createDateOfMonth/createDateOfMonth.ts +120 -0
  46. package/src/lib/stories/components/Info/Calendar/utils/{getDatesOfMonth.ts → getDatesOfMonth/getDatesOfMonth.ts} +30 -16
  47. package/src/lib/stories/components/Info/Calendar/utils/types.ts +0 -5
  48. package/src/lib/stories/developer tools/helpers/Time/getMoment/getMoment.ts +11 -12
  49. package/dist/stories/components/Info/Calendar/utils/createDateOfMonth.d.ts +0 -28
  50. package/dist/stories/components/Info/Calendar/utils/createDateOfMonth.js +0 -87
  51. package/dist/stories/components/Info/Calendar/utils/getDatesOfMonth.d.ts +0 -10
  52. package/dist/stories/components/Info/Calendar/utils/index.mdx +0 -64
  53. package/src/lib/stories/components/Info/Calendar/utils/createDateOfMonth.ts +0 -160
@@ -56,22 +56,6 @@
56
56
  --dodo-ui-CalendarDateChip-selected-#{$color-name}-active-bg: var(
57
57
  --dodo-color-#{$color-name}-100
58
58
  );
59
-
60
- --dodo-ui-CalendarDateChip-isRangeStart-#{$color-name}-bg: var(--dodo-color-#{$color-name}-300);
61
- --dodo-ui-CalendarDateChip-isRangeStart-#{$color-name}-hover-bg: var(
62
- --dodo-color-#{$color-name}-200
63
- );
64
- --dodo-ui-CalendarDateChip-isRangeStart-#{$color-name}-active-bg: var(
65
- --dodo-color-#{$color-name}-100
66
- );
67
-
68
- --dodo-ui-CalendarDateChip-isRangeEnd-#{$color-name}-bg: var(--dodo-color-#{$color-name}-300);
69
- --dodo-ui-CalendarDateChip-isRangeEnd-#{$color-name}-hover-bg: var(
70
- --dodo-color-#{$color-name}-200
71
- );
72
- --dodo-ui-CalendarDateChip-isRangeEnd-#{$color-name}-active-bg: var(
73
- --dodo-color-#{$color-name}-100
74
- );
75
59
  }
76
60
 
77
61
  /// Mixin: generate-dodo-ui-calendarDateChip-color
@@ -119,35 +103,5 @@
119
103
  }
120
104
  }
121
105
  }
122
-
123
- &.isRangeStart {
124
- .chip:not([disabled]) {
125
- color: var(--dodo-color-constant-white);
126
- background-color: var(--dodo-ui-CalendarDateChip-isRangeStart-#{$theme}-bg);
127
-
128
- &:hover {
129
- background-color: var(--dodo-ui-CalendarDateChip-isRangeStart-#{$theme}-hover-bg);
130
- }
131
-
132
- &:active {
133
- background-color: var(--dodo-ui-CalendarDateChip-isRangeStart-#{$theme}-active-bg);
134
- }
135
- }
136
- }
137
-
138
- &.isRangeEnd {
139
- .chip:not([disabled]) {
140
- color: var(--dodo-color-constant-white);
141
- background-color: var(--dodo-ui-CalendarDateChip-isRangeEnd-#{$theme}-bg);
142
-
143
- &:hover {
144
- background-color: var(--dodo-ui-CalendarDateChip-isRangeEnd-#{$theme}-hover-bg);
145
- }
146
-
147
- &:active {
148
- background-color: var(--dodo-ui-CalendarDateChip-isRangeEnd-#{$theme}-active-bg);
149
- }
150
- }
151
- }
152
106
  }
153
107
  }
@@ -83,3 +83,17 @@ const { Story } = defineMeta({
83
83
  showNextMonth: false,
84
84
  }}
85
85
  />
86
+
87
+ <Story
88
+ name="ManipulateDate"
89
+ args={{
90
+ manipulateDate: (dateToModify: DateOfMonth) => {
91
+ // Disable all Fridays
92
+ if (getMoment(dateToModify.date, undefined).day() === 5) {
93
+ dateToModify.disabled = true;
94
+ }
95
+
96
+ return dateToModify;
97
+ },
98
+ }}
99
+ />
@@ -2,10 +2,10 @@
2
2
  </script>
3
3
 
4
4
  <script lang="ts">import getMoment from '../../../../../developer tools/helpers/Time/getMoment/getMoment.js';
5
- import getDatesOfMonth from '../../utils/getDatesOfMonth.js';
6
5
  import CalendarDateChip, {} from './CalendarDateChip/CalendarDateChip.svelte';
7
6
  import CalendarWeek from './CalendarWeek/CalendarWeek.svelte';
8
- let { class: className = '', ref = $bindable(), value, startOfWeek, timezone, utc, calendarDateChipProps, color, showToday, showLastMonth, showNextMonth, showSelected = true, activeMonth, onselect, customCalendarDateChipContent, customCalendarDateChip, today, minDate, maxDate, excludeDates, includeDates, weekDayNameType, customCalendarWeekContent, customCalendarWeek, size = 'normal', weekendDays, weekendDaysColorDays = true, rangeValue, onselectRange, } = $props();
7
+ import { getDatesOfMonth } from '../../../../../../index.js';
8
+ let { class: className = '', ref = $bindable(), value, startOfWeek, timezone, utc, calendarDateChipProps, color, showToday, showLastMonth, showNextMonth, showSelected = true, activeMonth, onselect, customCalendarDateChipContent, customCalendarDateChip, today, minDate, maxDate, excludeDates, includeDates, weekDayNameType, customCalendarWeekContent, customCalendarWeek, size = 'normal', weekendDays, weekendDaysColorDays = true, manipulateDate, } = $props();
9
9
  let monthToPick = $state(undefined);
10
10
  const daysGroup = $derived(getDatesOfMonth(monthToPick, {
11
11
  startOfWeek,
@@ -16,26 +16,7 @@ const daysGroup = $derived(getDatesOfMonth(monthToPick, {
16
16
  maxDate,
17
17
  excludeDates,
18
18
  includeDates,
19
- rangeValue,
20
- }) || []);
21
- function getRangeType(day, rangeValue) {
22
- if (!rangeValue) {
23
- return undefined;
24
- }
25
- const [range1, range2] = rangeValue;
26
- if (!range1 || !range2) {
27
- return undefined;
28
- }
29
- if (getMoment(range1, undefined, { timezone, utc }).format('MMM YYYY') ===
30
- getMoment(day.date, undefined, { timezone, utc }).format('DD-MM-YYY')) {
31
- return 'start';
32
- }
33
- else if (getMoment(range2, undefined, { timezone, utc }).format('MMM YYYY') ===
34
- getMoment(day.date, undefined, { timezone, utc }).format('DD-MM-YYY')) {
35
- return 'end';
36
- }
37
- return undefined;
38
- }
19
+ }, manipulateDate) || []);
39
20
  $effect(() => {
40
21
  if (!value) {
41
22
  monthToPick = activeMonth;
@@ -92,9 +73,6 @@ $effect(() => {
92
73
  )
93
74
  ? true
94
75
  : false}
95
- showValueRange={rangeValue ? true : false}
96
- rangeType={getRangeType(day, rangeValue)}
97
- {onselectRange}
98
76
  {...calendarDateChipProps}
99
77
  />
100
78
  {/each}
@@ -38,8 +38,6 @@ export interface CalendarDatesChartProps {
38
38
  includeDates?: Date[];
39
39
  /** onselect event handler */
40
40
  onselect?: (value: Date, dayOfMonth: DateOfMonth, e: ButtonClickEvent) => void;
41
- /** onselectRange event handler */
42
- onselectRange?: (value: Date, type: DateRangeType, dayOfMonth: DateOfMonth, e: ButtonClickEvent) => void;
43
41
  /** Custom Calendar Chip Content */
44
42
  customCalendarDateChipContent?: (dayOfMonth: DateOfMonth) => Snippet;
45
43
  /** Custom Calendar Chip */
@@ -56,15 +54,16 @@ export interface CalendarDatesChartProps {
56
54
  weekendDays?: CalendarWeekNames[];
57
55
  /** Color Weekend days */
58
56
  weekendDaysColorDays?: boolean;
59
- /** Range value */
60
- rangeValue?: [Date, Date];
57
+ /** manipulate date callback */
58
+ manipulateDate?: (dateToModify: DateOfMonth, settings?: CreateDatesOfMonthSettings) => DateOfMonth;
61
59
  }
62
60
  import type { ComponentColor } from '../../../../../../types/colors.js';
63
61
  import type { Snippet } from 'svelte';
64
- import type { DateOfMonth, DateRangeType } from '../../utils/types.js';
62
+ import type { DateOfMonth } from '../../utils/types.js';
65
63
  import { type CalendarDateChipProps } from './CalendarDateChip/CalendarDateChip.svelte';
66
64
  import type { CalendarWeekOption, CalendarWeekDayNameType, CalendarWeekNames } from './CalendarWeek/CalendarWeek.svelte';
67
65
  import type { ComponentSize } from '../../../../../../types/size.js';
66
+ import type { CreateDatesOfMonthSettings } from '../../utils/createDateOfMonth/createDateOfMonth.js';
68
67
  declare const CalendarDatesChart: import("svelte").Component<CalendarDatesChartProps, {}, "ref">;
69
68
  type CalendarDatesChart = ReturnType<typeof CalendarDatesChart>;
70
69
  export default CalendarDatesChart;
@@ -0,0 +1,27 @@
1
+ import type { DateOfMonth } from '../types.js';
2
+ import type { CalendarWeekNames } from '../../../../../../index.js';
3
+ /** Settings for generating calendar dates */
4
+ export interface CreateDatesOfMonthSettings {
5
+ startOfWeek?: CalendarWeekNames;
6
+ showLastMonth?: boolean;
7
+ showNextMonth?: boolean;
8
+ today?: Date;
9
+ minDate?: Date;
10
+ maxDate?: Date;
11
+ excludeDates?: Date[];
12
+ includeDates?: Date[];
13
+ timezone?: string;
14
+ utc?: boolean;
15
+ }
16
+ export type CreateDateOfMonthType = 'currentMonth' | 'nextMonth' | 'lastMonth';
17
+ /**
18
+ * Generates a DateOfMonth object with metadata for a specific day, including
19
+ * whether it's part of the current month, disabled, or today.
20
+ *
21
+ * @param date - The day to convert.
22
+ * @param settings - Optional configuration settings.
23
+ * @param monthType - Specifies if the day belongs to the current, previous, or next month.
24
+ * @param manipulateDate - Optional function to customize the resulting date object.
25
+ * @returns A DateOfMonth object representing the day.
26
+ */
27
+ export default function createDateOfMonth(date?: Date, settings?: CreateDatesOfMonthSettings, monthType?: CreateDateOfMonthType, manipulateDate?: (dateToModify: DateOfMonth, settings?: CreateDatesOfMonthSettings) => DateOfMonth): DateOfMonth;
@@ -0,0 +1,72 @@
1
+ import getMoment from '../../../../../developer tools/helpers/Time/getMoment/getMoment.js';
2
+ /**
3
+ * Creates a moment object from a Date with optional timezone and UTC settings.
4
+ */
5
+ function dateMoment(date, settings) {
6
+ return getMoment(date, undefined, {
7
+ timezone: settings?.timezone,
8
+ utc: settings?.utc,
9
+ });
10
+ }
11
+ /**
12
+ * Determines if the given day matches "today" (manual or actual).
13
+ */
14
+ function getIsToday(dayMoment, todayDate, todayManual) {
15
+ const dayDateFormat = dayMoment.format('DD-MM-YYYY');
16
+ return todayManual === dayDateFormat || todayDate === dayDateFormat;
17
+ }
18
+ /**
19
+ * Determines if a date should be disabled based on limits and included/excluded lists.
20
+ */
21
+ function getIsDateDisabled(dayMoment, minDate, maxDate, excludeDates, includeDates) {
22
+ const dayDateFormat = dayMoment.format('DD-MM-YYYY');
23
+ if (minDate?.isValid() && dayMoment.isBefore(minDate))
24
+ return true;
25
+ if (maxDate?.isValid() && dayMoment.isAfter(maxDate))
26
+ return true;
27
+ if (excludeDates?.includes(dayDateFormat))
28
+ return true;
29
+ if (includeDates && !includeDates.includes(dayDateFormat))
30
+ return true;
31
+ return false;
32
+ }
33
+ /**
34
+ * Generates a DateOfMonth object with metadata for a specific day, including
35
+ * whether it's part of the current month, disabled, or today.
36
+ *
37
+ * @param date - The day to convert.
38
+ * @param settings - Optional configuration settings.
39
+ * @param monthType - Specifies if the day belongs to the current, previous, or next month.
40
+ * @param manipulateDate - Optional function to customize the resulting date object.
41
+ * @returns A DateOfMonth object representing the day.
42
+ */
43
+ export default function createDateOfMonth(date, settings, monthType = 'currentMonth', manipulateDate) {
44
+ const minDate = settings?.minDate ? dateMoment(settings.minDate, settings) : undefined;
45
+ const maxDate = settings?.maxDate ? dateMoment(settings.maxDate, settings) : undefined;
46
+ const excludeDates = settings?.excludeDates?.map((item) => dateMoment(item, settings).format('DD-MM-YYYY'));
47
+ const includeDates = settings?.includeDates?.map((item) => dateMoment(item, settings).format('DD-MM-YYYY'));
48
+ const todayDate = dateMoment(undefined, settings).format('DD-MM-YYYY');
49
+ const todayManual = settings?.today
50
+ ? dateMoment(settings.today, settings).format('DD-MM-YYYY')
51
+ : undefined;
52
+ const dayMoment = dateMoment(date, settings);
53
+ let dataToExport = {
54
+ id: `${dayMoment.valueOf()}`,
55
+ date: dayMoment.toDate(),
56
+ isCurrentMonth: true,
57
+ disabled: getIsDateDisabled(dayMoment, minDate, maxDate, excludeDates, includeDates),
58
+ today: getIsToday(dayMoment, todayDate, todayManual),
59
+ };
60
+ if (monthType === 'lastMonth') {
61
+ dataToExport.isLastMonth = true;
62
+ dataToExport.isCurrentMonth = false;
63
+ }
64
+ else if (monthType === 'nextMonth') {
65
+ dataToExport.isNextMonth = true;
66
+ dataToExport.isCurrentMonth = false;
67
+ }
68
+ if (manipulateDate) {
69
+ dataToExport = manipulateDate(dataToExport, settings);
70
+ }
71
+ return dataToExport;
72
+ }
@@ -0,0 +1,121 @@
1
+ import { Source } from '@storybook/addon-docs/blocks';
2
+
3
+ # `createDateOfMonth`
4
+
5
+ `createDateOfMonth(date, settings, monthType?, manipulateDate?)` creates a single `DateOfMonth` object representing one calendar cell. This is typically used internally by `getDatesOfMonth` but can be useful for custom logic.
6
+
7
+ ## Usage
8
+
9
+ <Source
10
+ dark
11
+ language="ts"
12
+ code={`
13
+ // Manual usage for one day
14
+ import { createDateOfMonth } from '@flightlesslabs/dodo-ui';
15
+
16
+ const date = new Date();
17
+ const dateObj = createDateOfMonth(date, {
18
+ minDate: new Date('2025-01-01'),
19
+ timezone: 'UTC',
20
+ }, 'currentMonth');
21
+ `}
22
+ />
23
+
24
+ ---
25
+
26
+ # Types
27
+
28
+ ## `DateOfMonth`
29
+
30
+ <Source
31
+ dark
32
+ language="ts"
33
+ code={`
34
+ // Represents a single calendar cell
35
+ type DateOfMonth = {
36
+ id: string;
37
+ date: Date;
38
+ isCurrentMonth: boolean;
39
+ isLastMonth?: boolean;
40
+ isNextMonth?: boolean;
41
+ disabled?: boolean;
42
+ today?: boolean;
43
+ };
44
+ `}
45
+ />
46
+
47
+ ## `CreateDatesOfMonthSettings`
48
+
49
+ <Source
50
+ dark
51
+ language="ts"
52
+ code={`
53
+ // Configuration for calendar generation
54
+ interface CreateDatesOfMonthSettings {
55
+ startOfWeek?: 'SUN' | 'MON' | 'TUE' | 'WED' | 'THU' | 'FRI' | 'SAT';
56
+ showLastMonth?: boolean;
57
+ showNextMonth?: boolean;
58
+ today?: Date;
59
+ minDate?: Date;
60
+ maxDate?: Date;
61
+ excludeDates?: Date[];
62
+ includeDates?: Date[];
63
+ timezone?: string;
64
+ utc?: boolean;
65
+ }
66
+ `}
67
+ />
68
+
69
+ ## `CreateDateOfMonthType`
70
+
71
+ <Source
72
+ dark
73
+ language="ts"
74
+ code={`
75
+ // Indicates the month context of the date
76
+ type CreateDateOfMonthType = 'currentMonth' | 'nextMonth' | 'lastMonth';
77
+ `}
78
+ />
79
+
80
+ ## `DAYS_OF_WEEK` Enum
81
+
82
+ <Source
83
+ dark
84
+ language="ts"
85
+ code={`
86
+ // Weekday constants (Sunday = 0)
87
+ export const enum DAYS_OF_WEEK {
88
+ SUN,
89
+ MON,
90
+ TUE,
91
+ WED,
92
+ THU,
93
+ FRI,
94
+ SAT,
95
+ }
96
+ `}
97
+ />
98
+
99
+ ## `MONTHS` Enum
100
+
101
+ <Source
102
+ dark
103
+ language="ts"
104
+ code={`
105
+ // Month constants (January = 0)
106
+ export const enum MONTHS {
107
+ JAN,
108
+ FEB,
109
+ MAR,
110
+ APR,
111
+ MAY,
112
+ JUN,
113
+ JUL,
114
+ AUG,
115
+ SEP,
116
+ OCT,
117
+ NOV,
118
+ DEC,
119
+ }
120
+ `}
121
+ />
@@ -0,0 +1,10 @@
1
+ import { type CreateDatesOfMonthSettings, type DateOfMonth } from '../../../../../../index.js';
2
+ /**
3
+ * Generates a calendar grid of dates for a given month.
4
+ *
5
+ * @param date - The base date for the month to generate.
6
+ * @param settings - Optional settings for formatting and display.
7
+ * @param manipulateDate - Optional function to modify each generated DateOfMonth.
8
+ * @returns A 2D array of DateOfMonth objects representing the calendar, or null if invalid.
9
+ */
10
+ export default function getDatesOfMonth(date?: Date, settings?: CreateDatesOfMonthSettings, manipulateDate?: (dateToModify: DateOfMonth, settings?: CreateDatesOfMonthSettings) => DateOfMonth): DateOfMonth[][] | null;
@@ -1,13 +1,12 @@
1
- import getMoment from '../../../../developer tools/helpers/Time/getMoment/getMoment.js';
2
- import { calendarWeekOptions } from '../../../../../index.js';
3
- import createDateOfMonth, {} from './createDateOfMonth.js';
1
+ import getMoment from '../../../../../developer tools/helpers/Time/getMoment/getMoment.js';
2
+ import { calendarWeekOptions, createDateOfMonth, } from '../../../../../../index.js';
4
3
  /**
5
4
  * Divides an array into chunks of a given size.
6
5
  *
7
6
  * @template T - The type of elements in the array.
8
- * @param {T[]} arr - The array to be chunked.
9
- * @param {number} size - The chunk size.
10
- * @returns {T[][]} - An array of chunks.
7
+ * @param arr - The array to be chunked.
8
+ * @param size - The chunk size.
9
+ * @returns An array of chunks.
11
10
  */
12
11
  function chunkArray(arr, size) {
13
12
  const result = [];
@@ -16,6 +15,13 @@ function chunkArray(arr, size) {
16
15
  }
17
16
  return result;
18
17
  }
18
+ /**
19
+ * Creates a moment object from a Date with optional timezone and UTC settings.
20
+ *
21
+ * @param date - The date to convert.
22
+ * @param settings - Optional settings for timezone and UTC.
23
+ * @returns A moment object with the applied settings.
24
+ */
19
25
  function dateMoment(date, settings) {
20
26
  return getMoment(date, undefined, {
21
27
  timezone: settings?.timezone,
@@ -25,11 +31,12 @@ function dateMoment(date, settings) {
25
31
  /**
26
32
  * Generates a calendar grid of dates for a given month.
27
33
  *
28
- * @param {Date} date - The base date for the month to generate.
29
- * @param {GetDatesOfMonthSettings} [settings] - Optional settings for formatting and display.
30
- * @returns {(DateOfMonth[][] | null)} - A 2D array of DateOfMonth objects representing the calendar, or null if invalid.
34
+ * @param date - The base date for the month to generate.
35
+ * @param settings - Optional settings for formatting and display.
36
+ * @param manipulateDate - Optional function to modify each generated DateOfMonth.
37
+ * @returns A 2D array of DateOfMonth objects representing the calendar, or null if invalid.
31
38
  */
32
- export default function getDatesOfMonth(date, settings) {
39
+ export default function getDatesOfMonth(date, settings, manipulateDate) {
33
40
  if (!date) {
34
41
  return null;
35
42
  }
@@ -50,12 +57,12 @@ export default function getDatesOfMonth(date, settings) {
50
57
  if (showLastMonth) {
51
58
  for (let gap = 0; gap < startOfMonthDay; gap++) {
52
59
  const dayMoment = lastMonth.clone().add(gap, 'days');
53
- dates.push(createDateOfMonth(dayMoment.toDate(), settings, 'lastMonth'));
60
+ dates.push(createDateOfMonth(dayMoment.toDate(), settings, 'lastMonth', manipulateDate));
54
61
  }
55
62
  }
56
63
  for (let day = 1; day <= daysInMonth; day++) {
57
64
  const dayMoment = monthMoment.clone().set('date', day);
58
- dates.push(createDateOfMonth(dayMoment.toDate(), settings, 'currentMonth'));
65
+ dates.push(createDateOfMonth(dayMoment.toDate(), settings, 'currentMonth', manipulateDate));
59
66
  }
60
67
  const datesDivided = chunkArray(dates, 7);
61
68
  if (showNextMonth) {
@@ -65,7 +72,7 @@ export default function getDatesOfMonth(date, settings) {
65
72
  const nextMonthDates = [];
66
73
  for (let gap = 0; gap < nextMonthDaysRequired; gap++) {
67
74
  const dayMoment = nextMonth.clone().add(gap, 'days');
68
- nextMonthDates.push(createDateOfMonth(dayMoment.toDate(), settings, 'nextMonth'));
75
+ nextMonthDates.push(createDateOfMonth(dayMoment.toDate(), settings, 'nextMonth', manipulateDate));
69
76
  }
70
77
  datesDivided[datesDivided.length - 1] = [...lastRow, ...nextMonthDates];
71
78
  }
@@ -0,0 +1,37 @@
1
+ import { Source } from '@storybook/addon-docs/blocks';
2
+
3
+ # `getDatesOfMonth`
4
+
5
+ `getDatesOfMonth(date, settings, manipulateDate)` generates a 2D array of weeks, each containing `DateOfMonth` objects. It supports options via `CreateDatesOfMonthSettings` and allows injecting custom logic per date.
6
+
7
+ ## Usage
8
+
9
+ <Source
10
+ dark
11
+ language="ts"
12
+ code={`
13
+ // Basic usage
14
+ import { getDatesOfMonth, getMoment } from '@flightlesslabs/dodo-ui';
15
+
16
+ const dates = getDatesOfMonth(new Date(), {
17
+ showLastMonth: false,
18
+ showNextMonth: false,
19
+ });
20
+
21
+ // Using a formatted date
22
+ const dates2 = getDatesOfMonth(
23
+ getMoment('01-02-2025', 'DD-MM-YYYY').toDate()
24
+ );
25
+
26
+ // With custom manipulation
27
+ const dates3 = getDatesOfMonth(new Date(), {
28
+ timezone: 'America/New_York',
29
+ startOfWeek: 'MON',
30
+ }, (date, settings) => {
31
+ return {
32
+ ...date,
33
+ disabled: true,
34
+ };
35
+ });
36
+ `}
37
+ />
@@ -29,8 +29,4 @@ export type DateOfMonth = {
29
29
  isNextMonth?: boolean;
30
30
  disabled?: boolean;
31
31
  today?: boolean;
32
- isRangeStart?: boolean;
33
- isRangeEnd?: boolean;
34
- inRange?: boolean;
35
32
  };
36
- export type DateRangeType = 'start' | 'end';
@@ -1,4 +1,4 @@
1
- import { Source } from '@storybook/blocks';
1
+ import { Source } from '@storybook/addon-docs/blocks';
2
2
 
3
3
  # Option Format
4
4
 
@@ -1,4 +1,4 @@
1
- import { Source } from '@storybook/blocks';
1
+ import { Source } from '@storybook/addon-docs/blocks';
2
2
 
3
3
  # Click Outside
4
4
 
@@ -1,4 +1,4 @@
1
- import { Source } from '@storybook/blocks';
1
+ import { Source } from '@storybook/addon-docs/blocks';
2
2
 
3
3
  # `cleanNumericString`
4
4
 
@@ -1,4 +1,4 @@
1
- import { Source } from '@storybook/blocks';
1
+ import { Source } from '@storybook/addon-docs/blocks';
2
2
 
3
3
  # `isValidNumberValue`
4
4
 
@@ -1,18 +1,17 @@
1
1
  import type { ConfigType, OptionType } from 'dayjs';
2
- import dayjs from 'dayjs';
2
+ import { Dayjs } from 'dayjs';
3
3
  /**
4
4
  * Acceptable input types for the `getMoment` function, compatible with dayjs.
5
5
  */
6
6
  export type GetMomentDate = ConfigType;
7
7
  /**
8
8
  * Optional formatting string used to parse the date.
9
- * Refer to dayjs customParseFormat plugin for supported formats.
10
9
  */
11
10
  export type GetMomentFormat = OptionType;
12
11
  /**
13
12
  * Settings to control how the moment is returned (UTC, timezone, or local).
14
13
  */
15
- export type GetMomentSettings = {
14
+ export interface GetMomentSettings {
16
15
  /**
17
16
  * Timezone string (e.g., "America/New_York").
18
17
  */
@@ -21,18 +20,18 @@ export type GetMomentSettings = {
21
20
  * Whether to return the time in UTC. If true, overrides timezone.
22
21
  */
23
22
  utc?: boolean;
24
- };
23
+ }
25
24
  /**
26
25
  * A wrapper around dayjs to return a moment-like object with optional formatting,
27
26
  * timezone, or UTC handling.
28
27
  *
29
- * @param {GetMomentDate} [date] - The input date, time, or string to be parsed.
30
- * @param {format} [format] - A custom format string for parsing the input date.
31
- * @param {GetMomentSettings} [settings] - Optional settings for format, timezone, and UTC.
32
- * @returns {dayjs.Dayjs} - A dayjs object in local, UTC, or specified timezone.
28
+ * @param date - The input date, time, or string to be parsed.
29
+ * @param format - A custom format string for parsing the input date.
30
+ * @param settings - Optional settings for timezone or UTC output.
31
+ * @returns A dayjs object in local, UTC, or specified timezone.
33
32
  *
34
33
  * @example
35
- * getMoment('2025-01-01T12:00:00Z', { utc: true }).format()
36
- * getMoment('01-01-2025', { format: 'DD-MM-YYYY', timezone: 'Asia/Kolkata' }).format()
34
+ * getMoment('2025-01-01T12:00:00Z', undefined, { utc: true }).format()
35
+ * getMoment('01-01-2025', 'DD-MM-YYYY', { timezone: 'Asia/Kolkata' }).format()
37
36
  */
38
- export default function getMoment(date?: GetMomentDate, format?: GetMomentFormat, settings?: GetMomentSettings): dayjs.Dayjs;
37
+ export default function getMoment(date?: GetMomentDate, format?: GetMomentFormat, settings?: GetMomentSettings): Dayjs;
@@ -1,4 +1,4 @@
1
- import dayjs from 'dayjs';
1
+ import dayjs, { Dayjs } from 'dayjs';
2
2
  import utc from 'dayjs/plugin/utc.js';
3
3
  import timezone from 'dayjs/plugin/timezone.js';
4
4
  import customParseFormat from 'dayjs/plugin/customParseFormat.js';
@@ -9,18 +9,18 @@ dayjs.extend(customParseFormat);
9
9
  * A wrapper around dayjs to return a moment-like object with optional formatting,
10
10
  * timezone, or UTC handling.
11
11
  *
12
- * @param {GetMomentDate} [date] - The input date, time, or string to be parsed.
13
- * @param {format} [format] - A custom format string for parsing the input date.
14
- * @param {GetMomentSettings} [settings] - Optional settings for format, timezone, and UTC.
15
- * @returns {dayjs.Dayjs} - A dayjs object in local, UTC, or specified timezone.
12
+ * @param date - The input date, time, or string to be parsed.
13
+ * @param format - A custom format string for parsing the input date.
14
+ * @param settings - Optional settings for timezone or UTC output.
15
+ * @returns A dayjs object in local, UTC, or specified timezone.
16
16
  *
17
17
  * @example
18
- * getMoment('2025-01-01T12:00:00Z', { utc: true }).format()
19
- * getMoment('01-01-2025', { format: 'DD-MM-YYYY', timezone: 'Asia/Kolkata' }).format()
18
+ * getMoment('2025-01-01T12:00:00Z', undefined, { utc: true }).format()
19
+ * getMoment('01-01-2025', 'DD-MM-YYYY', { timezone: 'Asia/Kolkata' }).format()
20
20
  */
21
21
  export default function getMoment(date, format, settings) {
22
22
  const timezone = settings?.timezone;
23
- const utc = settings?.utc ? true : false;
23
+ const utc = settings?.utc ?? false;
24
24
  if (utc) {
25
25
  return dayjs.utc(dayjs(date, format));
26
26
  }
@@ -1,8 +1,10 @@
1
- import { Source } from '@storybook/blocks';
1
+ import { Source } from '@storybook/addon-docs/blocks';
2
2
 
3
3
  # `getMoment`
4
4
 
5
- a Day.js wrapper
5
+ A [Day.js](https://day.js.org/) wrapper that supports custom formats, UTC mode, and timezone conversion using `dayjs`, `utc`, `timezone`, and `customParseFormat` plugins.
6
+
7
+ ---
6
8
 
7
9
  ## Usage
8
10
 
@@ -10,9 +12,34 @@ a Day.js wrapper
10
12
  dark
11
13
  language="ts"
12
14
  code={`
13
- import { getMoment } from '@flightlesslabs/dodo-ui';
15
+ // Basic local time
16
+ getMoment('2025-01-01T00:00:00Z').format();
17
+
18
+ // UTC output
19
+ getMoment('2025-01-01T00:00:00Z', undefined, { utc: true }).format();
20
+ // → "2025-01-01T00:00:00Z"
21
+
22
+ // With custom format + timezone
23
+ getMoment('01-01-2025', 'DD-MM-YYYY', { timezone: 'Asia/Kolkata' }).format();
24
+ // → "2025-01-01T00:00:00+05:30"
25
+ `}
26
+ />
27
+
28
+ ---
14
29
 
15
- getMoment('2025-01-01T00:00:00Z', { utc: true }).format(); // "2025-01-01T00:00:00Z"
16
- getMoment('01-01-2025', { format: 'DD-MM-YYYY', timezone: 'Asia/Kolkata' }).format();
30
+ ## API
31
+
32
+ <Source
33
+ dark
34
+ language="ts"
35
+ code={`
36
+ getMoment(
37
+ date?: ConfigType,
38
+ format?: string,
39
+ settings?: {
40
+ utc?: boolean;
41
+ timezone?: string;
42
+ }
43
+ ): dayjs.Dayjs
17
44
  `}
18
45
  />