@juspay/blend-design-system 0.0.18 → 0.0.19-beta

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.
@@ -1,4 +1,4 @@
1
- import { DateRange } from './types';
1
+ import { DateRange, CustomRangeConfig } from './types';
2
2
  type CalendarGridProps = {
3
3
  selectedRange: DateRange;
4
4
  onDateSelect: (range: DateRange) => void;
@@ -8,6 +8,8 @@ type CalendarGridProps = {
8
8
  disablePastDates?: boolean;
9
9
  hideFutureDates?: boolean;
10
10
  hidePastDates?: boolean;
11
+ customDisableDates?: (date: Date) => boolean;
12
+ customRangeConfig?: CustomRangeConfig;
11
13
  showDateTimePicker?: boolean;
12
14
  };
13
15
  declare const CalendarGrid: import('react').ForwardRefExoticComponent<CalendarGridProps & import('react').RefAttributes<HTMLDivElement>>;
@@ -28,6 +28,11 @@ export type CalendarTokenType = {
28
28
  md: CSSObject['fontSize'];
29
29
  lg: CSSObject['fontSize'];
30
30
  };
31
+ disabled: {
32
+ borderLeft: CSSObject['borderLeft'];
33
+ borderTop: CSSObject['borderTop'];
34
+ borderBottom: CSSObject['borderBottom'];
35
+ };
31
36
  };
32
37
  content: {
33
38
  padding: CSSObject['padding'];
@@ -164,6 +169,7 @@ export type CalendarTokenType = {
164
169
  disabled: {
165
170
  opacity: CSSObject['opacity'];
166
171
  cursor: CSSObject['cursor'];
172
+ border: CSSObject['border'];
167
173
  };
168
174
  borderRadiusWithPresets: CSSObject['borderRadius'];
169
175
  borderRadiusWithoutPresets: CSSObject['borderRadius'];
@@ -4,8 +4,10 @@ export declare enum DateRangePreset {
4
4
  TODAY = "today",
5
5
  YESTERDAY = "yesterday",
6
6
  TOMORROW = "tomorrow",
7
+ LAST_30_MINS = "last30Mins",
7
8
  LAST_1_HOUR = "last1Hour",
8
9
  LAST_6_HOURS = "last6Hours",
10
+ LAST_24_HOURS = "last24Hours",
9
11
  LAST_7_DAYS = "last7Days",
10
12
  LAST_30_DAYS = "last30Days",
11
13
  LAST_3_MONTHS = "last3Months",
@@ -137,6 +139,76 @@ export type PickerColumnData = {
137
139
  items: (string | number)[];
138
140
  selectedIndex: number;
139
141
  };
142
+ /**
143
+ * Function type for custom date disabling logic
144
+ * @param date The date to check
145
+ * @returns true if the date should be disabled, false otherwise
146
+ */
147
+ export type CustomDateDisableFunction = (date: Date) => boolean;
148
+ /**
149
+ * Function type for custom range calculation
150
+ * @param selectedDate The date that was selected
151
+ * @param currentRange The current date range
152
+ * @param isStartDate Whether the selected date is for start or end
153
+ * @returns The new date range or null to use default behavior
154
+ */
155
+ export type CustomRangeCalculationFunction = (selectedDate: Date, currentRange: DateRange, isStartDate: boolean) => DateRange | null;
156
+ /**
157
+ * Configuration for automatic range calculation
158
+ */
159
+ export type AutoRangeConfig = {
160
+ /** Number of days to add to start date for end date */
161
+ rangeDays?: number;
162
+ /** Number of hours to add to start date for end date */
163
+ rangeHours?: number;
164
+ /** Number of minutes to add to start date for end date */
165
+ rangeMinutes?: number;
166
+ /** Whether to include the start date in the range (true) or exclude it (false) */
167
+ includeStartDate?: boolean;
168
+ /** Custom function to calculate the range */
169
+ customCalculation?: CustomRangeCalculationFunction;
170
+ };
171
+ /**
172
+ * Function type for custom range calculation
173
+ * @param startDate The selected start date
174
+ * @param currentRange The current selected range (if any)
175
+ * @returns The calculated end date, or null to use default behavior
176
+ */
177
+ export type CustomRangeCalculatorFunction = (startDate: Date, currentRange?: DateRange) => Date | null;
178
+ /**
179
+ * Configuration for custom range behavior
180
+ */
181
+ export type CustomRangeConfig = {
182
+ /**
183
+ * Function to calculate end date based on start date
184
+ */
185
+ calculateEndDate?: CustomRangeCalculatorFunction;
186
+ /**
187
+ * Fixed number of days for the range (alternative to calculateEndDate)
188
+ */
189
+ fixedDayRange?: number;
190
+ /**
191
+ * Reference date range to use for comparison/duration calculation
192
+ * When provided, the component will calculate a range with the same duration
193
+ */
194
+ referenceRange?: DateRange;
195
+ /**
196
+ * Number of days to go backward for backward ranges (e.g., last 5 days)
197
+ * Used when calculateEndDate returns the same date as clicked date
198
+ * @default 6
199
+ */
200
+ backwardDays?: number;
201
+ /**
202
+ * Whether to allow manual end date selection when using custom range logic
203
+ * @default false
204
+ */
205
+ allowManualEndDateSelection?: boolean;
206
+ /**
207
+ * Whether to apply custom range logic to preset selections
208
+ * @default false
209
+ */
210
+ applyToPresets?: boolean;
211
+ };
140
212
  export type DateRangePickerProps = {
141
213
  value?: DateRange;
142
214
  onChange?: (range: DateRange) => void;
@@ -153,6 +225,8 @@ export type DateRangePickerProps = {
153
225
  disablePastDates?: boolean;
154
226
  hideFutureDates?: boolean;
155
227
  hidePastDates?: boolean;
228
+ customDisableDates?: CustomDateDisableFunction;
229
+ customRangeConfig?: CustomRangeConfig;
156
230
  triggerElement?: ReactNode;
157
231
  useDrawerOnMobile?: boolean;
158
232
  skipQuickFiltersOnMobile?: boolean;
@@ -1,4 +1,4 @@
1
- import { DateRange, DateRangePreset, DateFormatConfig, CustomFormatFunction, HapticFeedbackType } from './types';
1
+ import { DateRange, DateRangePreset, DateFormatConfig, CustomFormatFunction, HapticFeedbackType, CustomRangeConfig, CustomRangeCalculatorFunction } from './types';
2
2
  import { CalendarTokenType } from './dateRangePicker.tokens';
3
3
  /**
4
4
  * Formats a date according to the specified format
@@ -277,9 +277,10 @@ export declare const getScrollToMonth: (monthIndex: number, monthHeight: number)
277
277
  * @param today Today's date
278
278
  * @param disableFutureDates Whether future dates are disabled
279
279
  * @param disablePastDates Whether past dates are disabled
280
+ * @param customDisableDates Custom function to disable specific dates
280
281
  * @returns Object with all date states
281
282
  */
282
- export declare const getDateCellStates: (date: Date, selectedRange: DateRange, today: Date, disableFutureDates?: boolean, disablePastDates?: boolean) => {
283
+ export declare const getDateCellStates: (date: Date, selectedRange: DateRange, today: Date, disableFutureDates?: boolean, disablePastDates?: boolean, customDisableDates?: (date: Date) => boolean) => {
283
284
  isStart: boolean;
284
285
  isEnd: boolean;
285
286
  isRangeDay: boolean;
@@ -473,9 +474,10 @@ export declare const createCalendarMonthData: (year: number, month: number, mont
473
474
  * @param disableFutureDates Whether future dates are disabled
474
475
  * @param disablePastDates Whether past dates are disabled
475
476
  * @param calendarToken Calendar token for styling
477
+ * @param customDisableDates Custom function to disable specific dates
476
478
  * @returns Day cell props
477
479
  */
478
- export declare const calculateDayCellProps: (date: Date, selectedRange: DateRange, today: Date, disableFutureDates: boolean, disablePastDates: boolean, calendarToken: CalendarTokenType) => {
480
+ export declare const calculateDayCellProps: (date: Date, selectedRange: DateRange, today: Date, disableFutureDates: boolean, disablePastDates: boolean, calendarToken: CalendarTokenType, customDisableDates?: (date: Date) => boolean) => {
479
481
  dateStates: ReturnType<typeof getDateCellStates>;
480
482
  styles: Record<string, unknown>;
481
483
  textColor: string | unknown;
@@ -727,3 +729,100 @@ export declare const matchesTomorrowPreset: (range: DateRange) => boolean;
727
729
  * Robust preset detection that works with both UTC and local timezone dates
728
730
  */
729
731
  export declare const detectPresetFromRange: (range: DateRange) => DateRangePreset;
732
+ /**
733
+ * Applies custom range calculation logic to a selected start date
734
+ * @param startDate The selected start date
735
+ * @param customRangeConfig Custom range configuration
736
+ * @param currentRange Current selected range (optional)
737
+ * @returns Calculated range or null to use default behavior
738
+ */
739
+ export declare const applyCustomRangeCalculation: (startDate: Date, customRangeConfig: CustomRangeConfig, currentRange?: DateRange) => DateRange | null;
740
+ /**
741
+ * Enhanced calendar date click handler with custom range calculation support
742
+ * @param clickedDate The date that was clicked
743
+ * @param selectedRange Current selected range
744
+ * @param allowSingleDateSelection Whether single date selection is allowed
745
+ * @param today Today's date for validation
746
+ * @param disableFutureDates Whether future dates are disabled
747
+ * @param disablePastDates Whether past dates are disabled
748
+ * @param customRangeConfig Custom range configuration
749
+ * @param isDoubleClick Whether this is a double-click event
750
+ * @returns New date range or null if click should be ignored
751
+ */
752
+ export declare const handleCustomRangeCalendarDateClick: (clickedDate: Date, selectedRange: DateRange, allowSingleDateSelection: boolean | undefined, today: Date, disableFutureDates?: boolean, disablePastDates?: boolean, customRangeConfig?: CustomRangeConfig, isDoubleClick?: boolean) => DateRange | null;
753
+ /**
754
+ * Validates custom range configuration
755
+ * @param config Custom range configuration to validate
756
+ * @returns Validation result with error message if invalid
757
+ */
758
+ export declare const validateCustomRangeConfig: (config: CustomRangeConfig) => {
759
+ isValid: boolean;
760
+ error?: string;
761
+ };
762
+ /**
763
+ * Creates common custom range calculation functions
764
+ */
765
+ export declare const createCustomRangeCalculators: {
766
+ /**
767
+ * Creates a calculator for fixed number of days
768
+ * @param days Number of days for the range
769
+ * @returns Custom range calculator function
770
+ */
771
+ fixedDays: (days: number) => CustomRangeCalculatorFunction;
772
+ /**
773
+ * Creates a calculator for business days (excluding weekends)
774
+ * @param businessDays Number of business days
775
+ * @returns Custom range calculator function
776
+ */
777
+ businessDays: (businessDays: number) => CustomRangeCalculatorFunction;
778
+ /**
779
+ * Creates a calculator for end of week (Sunday)
780
+ * @returns Custom range calculator function
781
+ */
782
+ endOfWeek: () => CustomRangeCalculatorFunction;
783
+ /**
784
+ * Creates a calculator for end of month
785
+ * @returns Custom range calculator function
786
+ */
787
+ endOfMonth: () => CustomRangeCalculatorFunction;
788
+ /**
789
+ * Creates a calculator for quarter end
790
+ * @returns Custom range calculator function
791
+ */
792
+ endOfQuarter: () => CustomRangeCalculatorFunction;
793
+ /**
794
+ * Creates a calculator that compares with another date range
795
+ * @param compareRange The range to compare with
796
+ * @returns Custom range calculator function
797
+ */
798
+ compareWithRange: (compareRange: DateRange) => CustomRangeCalculatorFunction;
799
+ };
800
+ /**
801
+ * Helper function to create common custom range configurations
802
+ */
803
+ export declare const createCustomRangeConfigs: {
804
+ /**
805
+ * Fixed 5-day range
806
+ */
807
+ fiveDayRange: () => CustomRangeConfig;
808
+ /**
809
+ * Fixed 7-day range (week)
810
+ */
811
+ weekRange: () => CustomRangeConfig;
812
+ /**
813
+ * Business week (5 business days)
814
+ */
815
+ businessWeek: () => CustomRangeConfig;
816
+ /**
817
+ * Month range (start date to end of month)
818
+ */
819
+ monthRange: () => CustomRangeConfig;
820
+ /**
821
+ * Quarter range (start date to end of quarter)
822
+ */
823
+ quarterRange: () => CustomRangeConfig;
824
+ /**
825
+ * Flexible range with manual override
826
+ */
827
+ flexibleRange: (defaultDays: number) => CustomRangeConfig;
828
+ };