infinity-ui-elements 1.8.7 → 1.8.9

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/dist/index.esm.js CHANGED
@@ -1,11 +1,12 @@
1
1
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
2
  import * as React from 'react';
3
+ import { Children, cloneElement, useMemo, forwardRef, useState, useCallback, useImperativeHandle } from 'react';
3
4
  import { cva } from 'class-variance-authority';
4
5
  import { Slot } from '@radix-ui/react-slot';
5
6
  import { PulseLoader, ClipLoader } from 'react-spinners';
6
- import { clsx } from 'clsx';
7
+ import clsx$1, { clsx } from 'clsx';
7
8
  import { twMerge } from 'tailwind-merge';
8
- import { ExternalLink, Loader2, Search, ChevronDown, ChevronLeft, ChevronRight } from 'lucide-react';
9
+ import { ExternalLink, Calendar as Calendar$1, Loader2, Search, ChevronDown, ChevronLeft, ChevronRight } from 'lucide-react';
9
10
  import { createPortal } from 'react-dom';
10
11
  import { flexRender } from '@tanstack/react-table';
11
12
 
@@ -1543,7 +1544,7 @@ const Checkbox = React.forwardRef(({ label, errorText, size = "medium", validati
1543
1544
  iconSize: 10,
1544
1545
  },
1545
1546
  medium: {
1546
- gap: "gap-2.5",
1547
+ gap: "gap-2",
1547
1548
  labelSize: "text-body-small-regular",
1548
1549
  iconSize: 12,
1549
1550
  },
@@ -1686,7 +1687,2767 @@ const Counter = React.forwardRef(({ value, max, size = "medium", color = "neutra
1686
1687
  emphasis,
1687
1688
  }), className), ...props, children: displayValue }));
1688
1689
  });
1689
- Counter.displayName = "Counter";
1690
+ Counter.displayName = "Counter";
1691
+
1692
+ const copyProperty = (to, from, property, ignoreNonConfigurable) => {
1693
+ // `Function#length` should reflect the parameters of `to` not `from` since we keep its body.
1694
+ // `Function#prototype` is non-writable and non-configurable so can never be modified.
1695
+ if (property === 'length' || property === 'prototype') {
1696
+ return;
1697
+ }
1698
+
1699
+ // `Function#arguments` and `Function#caller` should not be copied. They were reported to be present in `Reflect.ownKeys` for some devices in React Native (#41), so we explicitly ignore them here.
1700
+ if (property === 'arguments' || property === 'caller') {
1701
+ return;
1702
+ }
1703
+
1704
+ const toDescriptor = Object.getOwnPropertyDescriptor(to, property);
1705
+ const fromDescriptor = Object.getOwnPropertyDescriptor(from, property);
1706
+
1707
+ if (!canCopyProperty(toDescriptor, fromDescriptor) && ignoreNonConfigurable) {
1708
+ return;
1709
+ }
1710
+
1711
+ Object.defineProperty(to, property, fromDescriptor);
1712
+ };
1713
+
1714
+ // `Object.defineProperty()` throws if the property exists, is not configurable and either:
1715
+ // - one its descriptors is changed
1716
+ // - it is non-writable and its value is changed
1717
+ const canCopyProperty = function (toDescriptor, fromDescriptor) {
1718
+ return toDescriptor === undefined || toDescriptor.configurable || (
1719
+ toDescriptor.writable === fromDescriptor.writable
1720
+ && toDescriptor.enumerable === fromDescriptor.enumerable
1721
+ && toDescriptor.configurable === fromDescriptor.configurable
1722
+ && (toDescriptor.writable || toDescriptor.value === fromDescriptor.value)
1723
+ );
1724
+ };
1725
+
1726
+ const changePrototype = (to, from) => {
1727
+ const fromPrototype = Object.getPrototypeOf(from);
1728
+ if (fromPrototype === Object.getPrototypeOf(to)) {
1729
+ return;
1730
+ }
1731
+
1732
+ Object.setPrototypeOf(to, fromPrototype);
1733
+ };
1734
+
1735
+ const wrappedToString = (withName, fromBody) => `/* Wrapped ${withName}*/\n${fromBody}`;
1736
+
1737
+ const toStringDescriptor = Object.getOwnPropertyDescriptor(Function.prototype, 'toString');
1738
+ const toStringName = Object.getOwnPropertyDescriptor(Function.prototype.toString, 'name');
1739
+
1740
+ // We call `from.toString()` early (not lazily) to ensure `from` can be garbage collected.
1741
+ // We use `bind()` instead of a closure for the same reason.
1742
+ // Calling `from.toString()` early also allows caching it in case `to.toString()` is called several times.
1743
+ const changeToString = (to, from, name) => {
1744
+ const withName = name === '' ? '' : `with ${name.trim()}() `;
1745
+ const newToString = wrappedToString.bind(null, withName, from.toString());
1746
+ // Ensure `to.toString.toString` is non-enumerable and has the same `same`
1747
+ Object.defineProperty(newToString, 'name', toStringName);
1748
+ const {writable, enumerable, configurable} = toStringDescriptor; // We destructue to avoid a potential `get` descriptor.
1749
+ Object.defineProperty(to, 'toString', {value: newToString, writable, enumerable, configurable});
1750
+ };
1751
+
1752
+ function mimicFunction(to, from, {ignoreNonConfigurable = false} = {}) {
1753
+ const {name} = to;
1754
+
1755
+ for (const property of Reflect.ownKeys(from)) {
1756
+ copyProperty(to, from, property, ignoreNonConfigurable);
1757
+ }
1758
+
1759
+ changePrototype(to, from);
1760
+ changeToString(to, from, name);
1761
+
1762
+ return to;
1763
+ }
1764
+
1765
+ const maxTimeoutValue = 2_147_483_647;
1766
+ const cacheStore = new WeakMap();
1767
+ const cacheTimerStore = new WeakMap();
1768
+ const cacheKeyStore = new WeakMap();
1769
+ function getValidCacheItem(cache, key) {
1770
+ const item = cache.get(key);
1771
+ if (!item) {
1772
+ return undefined;
1773
+ }
1774
+ if (item.maxAge <= Date.now()) {
1775
+ cache.delete(key);
1776
+ return undefined;
1777
+ }
1778
+ return item;
1779
+ }
1780
+ /**
1781
+ [Memoize](https://en.wikipedia.org/wiki/Memoization) functions - An optimization used to speed up consecutive function calls by caching the result of calls with identical input.
1782
+
1783
+ @param function_ - The function to be memoized.
1784
+
1785
+ @example
1786
+ ```
1787
+ import memoize from 'memoize';
1788
+
1789
+ let index = 0;
1790
+ const counter = () => ++index;
1791
+ const memoized = memoize(counter);
1792
+
1793
+ memoized('foo');
1794
+ //=> 1
1795
+
1796
+ // Cached as it's the same argument
1797
+ memoized('foo');
1798
+ //=> 1
1799
+
1800
+ // Not cached anymore as the arguments changed
1801
+ memoized('bar');
1802
+ //=> 2
1803
+
1804
+ memoized('bar');
1805
+ //=> 2
1806
+ ```
1807
+ */
1808
+ function memoize(function_, { cacheKey, cache = new Map(), maxAge, } = {}) {
1809
+ if (maxAge === 0) {
1810
+ return function_;
1811
+ }
1812
+ if (typeof maxAge === 'number' && Number.isFinite(maxAge)) {
1813
+ if (maxAge > maxTimeoutValue) {
1814
+ throw new TypeError(`The \`maxAge\` option cannot exceed ${maxTimeoutValue}.`);
1815
+ }
1816
+ if (maxAge < 0) {
1817
+ throw new TypeError('The `maxAge` option should not be a negative number.');
1818
+ }
1819
+ }
1820
+ const memoized = function (...arguments_) {
1821
+ const key = cacheKey ? cacheKey(arguments_) : arguments_[0];
1822
+ const cacheItem = getValidCacheItem(cache, key);
1823
+ if (cacheItem) {
1824
+ return cacheItem.data;
1825
+ }
1826
+ const result = function_.apply(this, arguments_);
1827
+ const computedMaxAge = typeof maxAge === 'function' ? maxAge(...arguments_) : maxAge;
1828
+ if (computedMaxAge !== undefined && computedMaxAge !== Number.POSITIVE_INFINITY) {
1829
+ if (!Number.isFinite(computedMaxAge)) {
1830
+ throw new TypeError('The `maxAge` function must return a finite number, `0`, or `Infinity`.');
1831
+ }
1832
+ if (computedMaxAge <= 0) {
1833
+ return result; // Do not cache
1834
+ }
1835
+ if (computedMaxAge > maxTimeoutValue) {
1836
+ throw new TypeError(`The \`maxAge\` function result cannot exceed ${maxTimeoutValue}.`);
1837
+ }
1838
+ }
1839
+ cache.set(key, {
1840
+ data: result,
1841
+ maxAge: (computedMaxAge === undefined || computedMaxAge === Number.POSITIVE_INFINITY)
1842
+ ? Number.POSITIVE_INFINITY
1843
+ : Date.now() + computedMaxAge,
1844
+ });
1845
+ if (computedMaxAge !== undefined && computedMaxAge !== Number.POSITIVE_INFINITY) {
1846
+ const timer = setTimeout(() => {
1847
+ cache.delete(key);
1848
+ cacheTimerStore.get(memoized)?.delete(timer);
1849
+ }, computedMaxAge);
1850
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
1851
+ timer.unref?.();
1852
+ const timers = cacheTimerStore.get(memoized) ?? new Set();
1853
+ timers.add(timer);
1854
+ cacheTimerStore.set(memoized, timers);
1855
+ }
1856
+ return result;
1857
+ };
1858
+ mimicFunction(memoized, function_, {
1859
+ ignoreNonConfigurable: true,
1860
+ });
1861
+ cacheStore.set(memoized, cache);
1862
+ cacheKeyStore.set(memoized, (cacheKey ?? ((arguments_) => arguments_[0])));
1863
+ return memoized;
1864
+ }
1865
+
1866
+ function isString(el) {
1867
+ return typeof el === 'string';
1868
+ }
1869
+ function isUnique(el, index, arr) {
1870
+ return arr.indexOf(el) === index;
1871
+ }
1872
+ function isAllLowerCase(el) {
1873
+ return el.toLowerCase() === el;
1874
+ }
1875
+ function fixCommas(el) {
1876
+ return el.indexOf(',') === -1 ? el : el.split(',');
1877
+ }
1878
+ function normalizeLocale(locale) {
1879
+ if (!locale) {
1880
+ return locale;
1881
+ }
1882
+ if (locale === 'C' || locale === 'posix' || locale === 'POSIX') {
1883
+ return 'en-US';
1884
+ }
1885
+ // If there's a dot (.) in the locale, it's likely in the format of "en-US.UTF-8", so we only take the first part
1886
+ if (locale.indexOf('.') !== -1) {
1887
+ var _a = locale.split('.')[0], actualLocale = _a === void 0 ? '' : _a;
1888
+ return normalizeLocale(actualLocale);
1889
+ }
1890
+ // If there's an at sign (@) in the locale, it's likely in the format of "en-US@posix", so we only take the first part
1891
+ if (locale.indexOf('@') !== -1) {
1892
+ var _b = locale.split('@')[0], actualLocale = _b === void 0 ? '' : _b;
1893
+ return normalizeLocale(actualLocale);
1894
+ }
1895
+ // If there's a dash (-) in the locale and it's not all lower case, it's already in the format of "en-US", so we return it
1896
+ if (locale.indexOf('-') === -1 || !isAllLowerCase(locale)) {
1897
+ return locale;
1898
+ }
1899
+ var _c = locale.split('-'), splitEl1 = _c[0], _d = _c[1], splitEl2 = _d === void 0 ? '' : _d;
1900
+ return "".concat(splitEl1, "-").concat(splitEl2.toUpperCase());
1901
+ }
1902
+ function getUserLocalesInternal(_a) {
1903
+ var _b = _a === void 0 ? {} : _a, _c = _b.useFallbackLocale, useFallbackLocale = _c === void 0 ? true : _c, _d = _b.fallbackLocale, fallbackLocale = _d === void 0 ? 'en-US' : _d;
1904
+ var languageList = [];
1905
+ if (typeof navigator !== 'undefined') {
1906
+ var rawLanguages = navigator.languages || [];
1907
+ var languages = [];
1908
+ for (var _i = 0, rawLanguages_1 = rawLanguages; _i < rawLanguages_1.length; _i++) {
1909
+ var rawLanguagesItem = rawLanguages_1[_i];
1910
+ languages = languages.concat(fixCommas(rawLanguagesItem));
1911
+ }
1912
+ var rawLanguage = navigator.language;
1913
+ var language = rawLanguage ? fixCommas(rawLanguage) : rawLanguage;
1914
+ languageList = languageList.concat(languages, language);
1915
+ }
1916
+ if (useFallbackLocale) {
1917
+ languageList.push(fallbackLocale);
1918
+ }
1919
+ return languageList.filter(isString).map(normalizeLocale).filter(isUnique);
1920
+ }
1921
+ var getUserLocales = memoize(getUserLocalesInternal, { cacheKey: JSON.stringify });
1922
+ function getUserLocaleInternal(options) {
1923
+ return getUserLocales(options)[0] || null;
1924
+ }
1925
+ var getUserLocale = memoize(getUserLocaleInternal, { cacheKey: JSON.stringify });
1926
+
1927
+ /**
1928
+ * Utils
1929
+ */
1930
+ function makeGetEdgeOfNeighbor(getPeriod, getEdgeOfPeriod, defaultOffset) {
1931
+ return function makeGetEdgeOfNeighborInternal(date, offset = defaultOffset) {
1932
+ const previousPeriod = getPeriod(date) + offset;
1933
+ return getEdgeOfPeriod(previousPeriod);
1934
+ };
1935
+ }
1936
+ function makeGetEnd(getBeginOfNextPeriod) {
1937
+ return function makeGetEndInternal(date) {
1938
+ return new Date(getBeginOfNextPeriod(date).getTime() - 1);
1939
+ };
1940
+ }
1941
+ function makeGetRange(getStart, getEnd) {
1942
+ return function makeGetRangeInternal(date) {
1943
+ return [getStart(date), getEnd(date)];
1944
+ };
1945
+ }
1946
+ /**
1947
+ * Simple getters - getting a property of a given point in time
1948
+ */
1949
+ /**
1950
+ * Gets year from a given date.
1951
+ *
1952
+ * @param {DateLike} date Date to get year from
1953
+ * @returns {number} Year
1954
+ */
1955
+ function getYear(date) {
1956
+ if (date instanceof Date) {
1957
+ return date.getFullYear();
1958
+ }
1959
+ if (typeof date === 'number') {
1960
+ return date;
1961
+ }
1962
+ const year = Number.parseInt(date, 10);
1963
+ if (typeof date === 'string' && !Number.isNaN(year)) {
1964
+ return year;
1965
+ }
1966
+ throw new Error(`Failed to get year from date: ${date}.`);
1967
+ }
1968
+ /**
1969
+ * Gets month from a given date.
1970
+ *
1971
+ * @param {Date} date Date to get month from
1972
+ * @returns {number} Month
1973
+ */
1974
+ function getMonth(date) {
1975
+ if (date instanceof Date) {
1976
+ return date.getMonth();
1977
+ }
1978
+ throw new Error(`Failed to get month from date: ${date}.`);
1979
+ }
1980
+ /**
1981
+ * Gets day of the month from a given date.
1982
+ *
1983
+ * @param {Date} date Date to get day of the month from
1984
+ * @returns {number} Day of the month
1985
+ */
1986
+ function getDate(date) {
1987
+ if (date instanceof Date) {
1988
+ return date.getDate();
1989
+ }
1990
+ throw new Error(`Failed to get year from date: ${date}.`);
1991
+ }
1992
+ /**
1993
+ * Century
1994
+ */
1995
+ /**
1996
+ * Gets century start date from a given date.
1997
+ *
1998
+ * @param {DateLike} date Date to get century start from
1999
+ * @returns {Date} Century start date
2000
+ */
2001
+ function getCenturyStart(date) {
2002
+ const year = getYear(date);
2003
+ const centuryStartYear = year + ((-year + 1) % 100);
2004
+ const centuryStartDate = new Date();
2005
+ centuryStartDate.setFullYear(centuryStartYear, 0, 1);
2006
+ centuryStartDate.setHours(0, 0, 0, 0);
2007
+ return centuryStartDate;
2008
+ }
2009
+ /**
2010
+ * Gets previous century start date from a given date.
2011
+ *
2012
+ * @param {DateLike} date Date to get previous century start from
2013
+ * @param {number} [offset=-100] Offset in years to calculate previous century start from
2014
+ * @returns {Date} Previous century start date
2015
+ */
2016
+ const getPreviousCenturyStart = makeGetEdgeOfNeighbor(getYear, getCenturyStart, -100);
2017
+ /**
2018
+ * Gets next century start date from a given date.
2019
+ *
2020
+ * @param {DateLike} date Date to get next century start from
2021
+ * @param {number} [offset=100] Offset in years to calculate next century start from
2022
+ * @returns {Date} Next century start date
2023
+ */
2024
+ const getNextCenturyStart = makeGetEdgeOfNeighbor(getYear, getCenturyStart, 100);
2025
+ /**
2026
+ * Gets century end date from a given date.
2027
+ *
2028
+ * @param {DateLike} date Date to get century end from
2029
+ * @returns {Date} Century end date
2030
+ */
2031
+ const getCenturyEnd = makeGetEnd(getNextCenturyStart);
2032
+ /**
2033
+ * Gets previous century end date from a given date.
2034
+ *
2035
+ * @param {DateLike} date Date to get previous century end from
2036
+ * @param {number} [offset=-100] Offset in years to calculate previous century end from
2037
+ * @returns {Date} Previous century end date
2038
+ */
2039
+ const getPreviousCenturyEnd = makeGetEdgeOfNeighbor(getYear, getCenturyEnd, -100);
2040
+ /**
2041
+ * Gets century start and end dates from a given date.
2042
+ *
2043
+ * @param {DateLike} date Date to get century start and end from
2044
+ * @returns {[Date, Date]} Century start and end dates
2045
+ */
2046
+ const getCenturyRange = makeGetRange(getCenturyStart, getCenturyEnd);
2047
+ /**
2048
+ * Decade
2049
+ */
2050
+ /**
2051
+ * Gets decade start date from a given date.
2052
+ *
2053
+ * @param {DateLike} date Date to get decade start from
2054
+ * @returns {Date} Decade start date
2055
+ */
2056
+ function getDecadeStart(date) {
2057
+ const year = getYear(date);
2058
+ const decadeStartYear = year + ((-year + 1) % 10);
2059
+ const decadeStartDate = new Date();
2060
+ decadeStartDate.setFullYear(decadeStartYear, 0, 1);
2061
+ decadeStartDate.setHours(0, 0, 0, 0);
2062
+ return decadeStartDate;
2063
+ }
2064
+ /**
2065
+ * Gets previous decade start date from a given date.
2066
+ *
2067
+ * @param {DateLike} date Date to get previous decade start from
2068
+ * @param {number} [offset=-10] Offset in years to calculate previous decade start from
2069
+ * @returns {Date} Previous decade start date
2070
+ */
2071
+ const getPreviousDecadeStart = makeGetEdgeOfNeighbor(getYear, getDecadeStart, -10);
2072
+ /**
2073
+ * Gets next decade start date from a given date.
2074
+ *
2075
+ * @param {DateLike} date Date to get next decade start from
2076
+ * @param {number} [offset=10] Offset in years to calculate next decade start from
2077
+ * @returns {Date} Next decade start date
2078
+ */
2079
+ const getNextDecadeStart = makeGetEdgeOfNeighbor(getYear, getDecadeStart, 10);
2080
+ /**
2081
+ * Gets decade end date from a given date.
2082
+ *
2083
+ * @param {DateLike} date Date to get decade end from
2084
+ * @returns {Date} Decade end date
2085
+ */
2086
+ const getDecadeEnd = makeGetEnd(getNextDecadeStart);
2087
+ /**
2088
+ * Gets previous decade end date from a given date.
2089
+ *
2090
+ * @param {DateLike} date Date to get previous decade end from
2091
+ * @param {number} [offset=-10] Offset in years to calculate previous decade end from
2092
+ * @returns {Date} Previous decade end date
2093
+ */
2094
+ const getPreviousDecadeEnd = makeGetEdgeOfNeighbor(getYear, getDecadeEnd, -10);
2095
+ /**
2096
+ * Gets decade start and end dates from a given date.
2097
+ *
2098
+ * @param {DateLike} date Date to get decade start and end from
2099
+ * @returns {[Date, Date]} Decade start and end dates
2100
+ */
2101
+ const getDecadeRange = makeGetRange(getDecadeStart, getDecadeEnd);
2102
+ /**
2103
+ * Year
2104
+ */
2105
+ /**
2106
+ * Gets year start date from a given date.
2107
+ *
2108
+ * @param {DateLike} date Date to get year start from
2109
+ * @returns {Date} Year start date
2110
+ */
2111
+ function getYearStart(date) {
2112
+ const year = getYear(date);
2113
+ const yearStartDate = new Date();
2114
+ yearStartDate.setFullYear(year, 0, 1);
2115
+ yearStartDate.setHours(0, 0, 0, 0);
2116
+ return yearStartDate;
2117
+ }
2118
+ /**
2119
+ * Gets previous year start date from a given date.
2120
+ *
2121
+ * @param {DateLike} date Date to get previous year start from
2122
+ * @param {number} [offset=-1] Offset in years to calculate previous year start from
2123
+ * @returns {Date} Previous year start date
2124
+ */
2125
+ const getPreviousYearStart = makeGetEdgeOfNeighbor(getYear, getYearStart, -1);
2126
+ /**
2127
+ * Gets next year start date from a given date.
2128
+ *
2129
+ * @param {DateLike} date Date to get next year start from
2130
+ * @param {number} [offset=1] Offset in years to calculate next year start from
2131
+ * @returns {Date} Next year start date
2132
+ */
2133
+ const getNextYearStart = makeGetEdgeOfNeighbor(getYear, getYearStart, 1);
2134
+ /**
2135
+ * Gets year end date from a given date.
2136
+ *
2137
+ * @param {DateLike} date Date to get year end from
2138
+ * @returns {Date} Year end date
2139
+ */
2140
+ const getYearEnd = makeGetEnd(getNextYearStart);
2141
+ /**
2142
+ * Gets previous year end date from a given date.
2143
+ *
2144
+ * @param {DateLike} date Date to get previous year end from
2145
+ * @param {number} [offset=-1] Offset in years to calculate previous year end from
2146
+ * @returns {Date} Previous year end date
2147
+ */
2148
+ const getPreviousYearEnd = makeGetEdgeOfNeighbor(getYear, getYearEnd, -1);
2149
+ /**
2150
+ * Gets year start and end dates from a given date.
2151
+ *
2152
+ * @param {DateLike} date Date to get year start and end from
2153
+ * @returns {[Date, Date]} Year start and end dates
2154
+ */
2155
+ const getYearRange = makeGetRange(getYearStart, getYearEnd);
2156
+ /**
2157
+ * Month
2158
+ */
2159
+ function makeGetEdgeOfNeighborMonth(getEdgeOfPeriod, defaultOffset) {
2160
+ return function makeGetEdgeOfNeighborMonthInternal(date, offset = defaultOffset) {
2161
+ const year = getYear(date);
2162
+ const month = getMonth(date) + offset;
2163
+ const previousPeriod = new Date();
2164
+ previousPeriod.setFullYear(year, month, 1);
2165
+ previousPeriod.setHours(0, 0, 0, 0);
2166
+ return getEdgeOfPeriod(previousPeriod);
2167
+ };
2168
+ }
2169
+ /**
2170
+ * Gets month start date from a given date.
2171
+ *
2172
+ * @param {DateLike} date Date to get month start from
2173
+ * @returns {Date} Month start date
2174
+ */
2175
+ function getMonthStart(date) {
2176
+ const year = getYear(date);
2177
+ const month = getMonth(date);
2178
+ const monthStartDate = new Date();
2179
+ monthStartDate.setFullYear(year, month, 1);
2180
+ monthStartDate.setHours(0, 0, 0, 0);
2181
+ return monthStartDate;
2182
+ }
2183
+ /**
2184
+ * Gets previous month start date from a given date.
2185
+ *
2186
+ * @param {Date} date Date to get previous month start from
2187
+ * @param {number} [offset=-1] Offset in months to calculate previous month start from
2188
+ * @returns {Date} Previous month start date
2189
+ */
2190
+ const getPreviousMonthStart = makeGetEdgeOfNeighborMonth(getMonthStart, -1);
2191
+ /**
2192
+ * Gets next month start date from a given date.
2193
+ *
2194
+ * @param {Date} date Date to get next month start from
2195
+ * @param {number} [offset=1] Offset in months to calculate next month start from
2196
+ * @returns {Date} Next month start date
2197
+ */
2198
+ const getNextMonthStart = makeGetEdgeOfNeighborMonth(getMonthStart, 1);
2199
+ /**
2200
+ * Gets month end date from a given date.
2201
+ *
2202
+ * @param {Date} date Date to get month end from
2203
+ * @returns {Date} Month end date
2204
+ */
2205
+ const getMonthEnd = makeGetEnd(getNextMonthStart);
2206
+ /**
2207
+ * Gets previous month end date from a given date.
2208
+ *
2209
+ * @param {Date} date Date to get previous month end from
2210
+ * @param {number} [offset=-1] Offset in months to calculate previous month end from
2211
+ * @returns {Date} Previous month end date
2212
+ */
2213
+ const getPreviousMonthEnd = makeGetEdgeOfNeighborMonth(getMonthEnd, -1);
2214
+ /**
2215
+ * Gets month start and end dates from a given date.
2216
+ *
2217
+ * @param {Date} date Date to get month start and end from
2218
+ * @returns {[Date, Date]} Month start and end dates
2219
+ */
2220
+ const getMonthRange = makeGetRange(getMonthStart, getMonthEnd);
2221
+ /**
2222
+ * Day
2223
+ */
2224
+ function makeGetEdgeOfNeighborDay(getEdgeOfPeriod, defaultOffset) {
2225
+ return function makeGetEdgeOfNeighborDayInternal(date, offset = defaultOffset) {
2226
+ const year = getYear(date);
2227
+ const month = getMonth(date);
2228
+ const day = getDate(date) + offset;
2229
+ const previousPeriod = new Date();
2230
+ previousPeriod.setFullYear(year, month, day);
2231
+ previousPeriod.setHours(0, 0, 0, 0);
2232
+ return getEdgeOfPeriod(previousPeriod);
2233
+ };
2234
+ }
2235
+ /**
2236
+ * Gets day start date from a given date.
2237
+ *
2238
+ * @param {DateLike} date Date to get day start from
2239
+ * @returns {Date} Day start date
2240
+ */
2241
+ function getDayStart(date) {
2242
+ const year = getYear(date);
2243
+ const month = getMonth(date);
2244
+ const day = getDate(date);
2245
+ const dayStartDate = new Date();
2246
+ dayStartDate.setFullYear(year, month, day);
2247
+ dayStartDate.setHours(0, 0, 0, 0);
2248
+ return dayStartDate;
2249
+ }
2250
+ /**
2251
+ * Gets next day start date from a given date.
2252
+ *
2253
+ * @param {Date} date Date to get next day start from
2254
+ * @param {number} [offset=1] Offset in days to calculate next day start from
2255
+ * @returns {Date} Next day start date
2256
+ */
2257
+ const getNextDayStart = makeGetEdgeOfNeighborDay(getDayStart, 1);
2258
+ /**
2259
+ * Gets day end date from a given date.
2260
+ *
2261
+ * @param {Date} date Date to get day end from
2262
+ * @returns {Date} Day end date
2263
+ */
2264
+ const getDayEnd = makeGetEnd(getNextDayStart);
2265
+ /**
2266
+ * Gets day start and end dates from a given date.
2267
+ *
2268
+ * @param {DateLike} date Date to get day start and end from
2269
+ * @returns {[Date, Date]} Day start and end dates
2270
+ */
2271
+ const getDayRange = makeGetRange(getDayStart, getDayEnd);
2272
+ /**
2273
+ * Other
2274
+ */
2275
+ /**
2276
+ * Returns a number of days in a month of a given date.
2277
+ *
2278
+ * @param {Date} date Date
2279
+ * @returns {number} Number of days in a month
2280
+ */
2281
+ function getDaysInMonth(date) {
2282
+ return getDate(getMonthEnd(date));
2283
+ }
2284
+
2285
+ var CALENDAR_TYPES = {
2286
+ GREGORY: 'gregory',
2287
+ HEBREW: 'hebrew',
2288
+ ISLAMIC: 'islamic',
2289
+ ISO_8601: 'iso8601',
2290
+ };
2291
+ var CALENDAR_TYPE_LOCALES = {
2292
+ gregory: [
2293
+ 'en-CA',
2294
+ 'en-US',
2295
+ 'es-AR',
2296
+ 'es-BO',
2297
+ 'es-CL',
2298
+ 'es-CO',
2299
+ 'es-CR',
2300
+ 'es-DO',
2301
+ 'es-EC',
2302
+ 'es-GT',
2303
+ 'es-HN',
2304
+ 'es-MX',
2305
+ 'es-NI',
2306
+ 'es-PA',
2307
+ 'es-PE',
2308
+ 'es-PR',
2309
+ 'es-SV',
2310
+ 'es-VE',
2311
+ 'pt-BR',
2312
+ ],
2313
+ hebrew: ['he', 'he-IL'],
2314
+ islamic: [
2315
+ // ar-LB, ar-MA intentionally missing
2316
+ 'ar',
2317
+ 'ar-AE',
2318
+ 'ar-BH',
2319
+ 'ar-DZ',
2320
+ 'ar-EG',
2321
+ 'ar-IQ',
2322
+ 'ar-JO',
2323
+ 'ar-KW',
2324
+ 'ar-LY',
2325
+ 'ar-OM',
2326
+ 'ar-QA',
2327
+ 'ar-SA',
2328
+ 'ar-SD',
2329
+ 'ar-SY',
2330
+ 'ar-YE',
2331
+ 'dv',
2332
+ 'dv-MV',
2333
+ 'ps',
2334
+ 'ps-AR',
2335
+ ],
2336
+ };
2337
+ var WEEKDAYS = [0, 1, 2, 3, 4, 5, 6];
2338
+
2339
+ var formatterCache = new Map();
2340
+ function getFormatter(options) {
2341
+ return function formatter(locale, date) {
2342
+ var localeWithDefault = locale || getUserLocale();
2343
+ if (!formatterCache.has(localeWithDefault)) {
2344
+ formatterCache.set(localeWithDefault, new Map());
2345
+ }
2346
+ var formatterCacheLocale = formatterCache.get(localeWithDefault);
2347
+ if (!formatterCacheLocale.has(options)) {
2348
+ formatterCacheLocale.set(options, new Intl.DateTimeFormat(localeWithDefault || undefined, options).format);
2349
+ }
2350
+ return formatterCacheLocale.get(options)(date);
2351
+ };
2352
+ }
2353
+ /**
2354
+ * Changes the hour in a Date to ensure right date formatting even if DST is messed up.
2355
+ * Workaround for bug in WebKit and Firefox with historical dates.
2356
+ * For more details, see:
2357
+ * https://bugs.chromium.org/p/chromium/issues/detail?id=750465
2358
+ * https://bugzilla.mozilla.org/show_bug.cgi?id=1385643
2359
+ *
2360
+ * @param {Date} date Date.
2361
+ * @returns {Date} Date with hour set to 12.
2362
+ */
2363
+ function toSafeHour(date) {
2364
+ var safeDate = new Date(date);
2365
+ return new Date(safeDate.setHours(12));
2366
+ }
2367
+ function getSafeFormatter(options) {
2368
+ return function (locale, date) { return getFormatter(options)(locale, toSafeHour(date)); };
2369
+ }
2370
+ var formatDayOptions = { day: 'numeric' };
2371
+ var formatLongDateOptions = {
2372
+ day: 'numeric',
2373
+ month: 'long',
2374
+ year: 'numeric',
2375
+ };
2376
+ var formatMonthOptions = { month: 'long' };
2377
+ var formatMonthYearOptions = {
2378
+ month: 'long',
2379
+ year: 'numeric',
2380
+ };
2381
+ var formatShortWeekdayOptions = { weekday: 'short' };
2382
+ var formatWeekdayOptions = { weekday: 'long' };
2383
+ var formatYearOptions = { year: 'numeric' };
2384
+ var formatDay = getSafeFormatter(formatDayOptions);
2385
+ var formatLongDate = getSafeFormatter(formatLongDateOptions);
2386
+ var formatMonth = getSafeFormatter(formatMonthOptions);
2387
+ var formatMonthYear = getSafeFormatter(formatMonthYearOptions);
2388
+ var formatShortWeekday = getSafeFormatter(formatShortWeekdayOptions);
2389
+ var formatWeekday = getSafeFormatter(formatWeekdayOptions);
2390
+ var formatYear = getSafeFormatter(formatYearOptions);
2391
+
2392
+ var SUNDAY = WEEKDAYS[0];
2393
+ var FRIDAY = WEEKDAYS[5];
2394
+ var SATURDAY = WEEKDAYS[6];
2395
+ /* Simple getters - getting a property of a given point in time */
2396
+ /**
2397
+ * Gets day of the week of a given date.
2398
+ * @param {Date} date Date.
2399
+ * @param {CalendarType} [calendarType="iso8601"] Calendar type.
2400
+ * @returns {number} Day of the week.
2401
+ */
2402
+ function getDayOfWeek(date, calendarType) {
2403
+ if (calendarType === void 0) { calendarType = CALENDAR_TYPES.ISO_8601; }
2404
+ var weekday = date.getDay();
2405
+ switch (calendarType) {
2406
+ case CALENDAR_TYPES.ISO_8601:
2407
+ // Shifts days of the week so that Monday is 0, Sunday is 6
2408
+ return (weekday + 6) % 7;
2409
+ case CALENDAR_TYPES.ISLAMIC:
2410
+ return (weekday + 1) % 7;
2411
+ case CALENDAR_TYPES.HEBREW:
2412
+ case CALENDAR_TYPES.GREGORY:
2413
+ return weekday;
2414
+ default:
2415
+ throw new Error('Unsupported calendar type.');
2416
+ }
2417
+ }
2418
+ /**
2419
+ * Century
2420
+ */
2421
+ /**
2422
+ * Gets the year of the beginning of a century of a given date.
2423
+ * @param {Date} date Date.
2424
+ * @returns {number} Year of the beginning of a century.
2425
+ */
2426
+ function getBeginOfCenturyYear(date) {
2427
+ var beginOfCentury = getCenturyStart(date);
2428
+ return getYear(beginOfCentury);
2429
+ }
2430
+ /**
2431
+ * Decade
2432
+ */
2433
+ /**
2434
+ * Gets the year of the beginning of a decade of a given date.
2435
+ * @param {Date} date Date.
2436
+ * @returns {number} Year of the beginning of a decade.
2437
+ */
2438
+ function getBeginOfDecadeYear(date) {
2439
+ var beginOfDecade = getDecadeStart(date);
2440
+ return getYear(beginOfDecade);
2441
+ }
2442
+ /**
2443
+ * Week
2444
+ */
2445
+ /**
2446
+ * Returns the beginning of a given week.
2447
+ *
2448
+ * @param {Date} date Date.
2449
+ * @param {CalendarType} [calendarType="iso8601"] Calendar type.
2450
+ * @returns {Date} Beginning of a given week.
2451
+ */
2452
+ function getBeginOfWeek(date, calendarType) {
2453
+ if (calendarType === void 0) { calendarType = CALENDAR_TYPES.ISO_8601; }
2454
+ var year = getYear(date);
2455
+ var monthIndex = getMonth(date);
2456
+ var day = date.getDate() - getDayOfWeek(date, calendarType);
2457
+ return new Date(year, monthIndex, day);
2458
+ }
2459
+ /**
2460
+ * Gets week number according to ISO 8601 or US standard.
2461
+ * In ISO 8601, Arabic and Hebrew week 1 is the one with January 4.
2462
+ * In US calendar week 1 is the one with January 1.
2463
+ *
2464
+ * @param {Date} date Date.
2465
+ * @param {CalendarType} [calendarType="iso8601"] Calendar type.
2466
+ * @returns {number} Week number.
2467
+ */
2468
+ function getWeekNumber(date, calendarType) {
2469
+ if (calendarType === void 0) { calendarType = CALENDAR_TYPES.ISO_8601; }
2470
+ var calendarTypeForWeekNumber = calendarType === CALENDAR_TYPES.GREGORY ? CALENDAR_TYPES.GREGORY : CALENDAR_TYPES.ISO_8601;
2471
+ var beginOfWeek = getBeginOfWeek(date, calendarType);
2472
+ var year = getYear(date) + 1;
2473
+ var dayInWeekOne;
2474
+ var beginOfFirstWeek;
2475
+ // Look for the first week one that does not come after a given date
2476
+ do {
2477
+ dayInWeekOne = new Date(year, 0, calendarTypeForWeekNumber === CALENDAR_TYPES.ISO_8601 ? 4 : 1);
2478
+ beginOfFirstWeek = getBeginOfWeek(dayInWeekOne, calendarType);
2479
+ year -= 1;
2480
+ } while (date < beginOfFirstWeek);
2481
+ return Math.round((beginOfWeek.getTime() - beginOfFirstWeek.getTime()) / (8.64e7 * 7)) + 1;
2482
+ }
2483
+ /**
2484
+ * Others
2485
+ */
2486
+ /**
2487
+ * Returns the beginning of a given range.
2488
+ *
2489
+ * @param {RangeType} rangeType Range type (e.g. 'day')
2490
+ * @param {Date} date Date.
2491
+ * @returns {Date} Beginning of a given range.
2492
+ */
2493
+ function getBegin(rangeType, date) {
2494
+ switch (rangeType) {
2495
+ case 'century':
2496
+ return getCenturyStart(date);
2497
+ case 'decade':
2498
+ return getDecadeStart(date);
2499
+ case 'year':
2500
+ return getYearStart(date);
2501
+ case 'month':
2502
+ return getMonthStart(date);
2503
+ case 'day':
2504
+ return getDayStart(date);
2505
+ default:
2506
+ throw new Error("Invalid rangeType: ".concat(rangeType));
2507
+ }
2508
+ }
2509
+ /**
2510
+ * Returns the beginning of a previous given range.
2511
+ *
2512
+ * @param {RangeType} rangeType Range type (e.g. 'day')
2513
+ * @param {Date} date Date.
2514
+ * @returns {Date} Beginning of a previous given range.
2515
+ */
2516
+ function getBeginPrevious(rangeType, date) {
2517
+ switch (rangeType) {
2518
+ case 'century':
2519
+ return getPreviousCenturyStart(date);
2520
+ case 'decade':
2521
+ return getPreviousDecadeStart(date);
2522
+ case 'year':
2523
+ return getPreviousYearStart(date);
2524
+ case 'month':
2525
+ return getPreviousMonthStart(date);
2526
+ default:
2527
+ throw new Error("Invalid rangeType: ".concat(rangeType));
2528
+ }
2529
+ }
2530
+ /**
2531
+ * Returns the beginning of a next given range.
2532
+ *
2533
+ * @param {RangeType} rangeType Range type (e.g. 'day')
2534
+ * @param {Date} date Date.
2535
+ * @returns {Date} Beginning of a next given range.
2536
+ */
2537
+ function getBeginNext(rangeType, date) {
2538
+ switch (rangeType) {
2539
+ case 'century':
2540
+ return getNextCenturyStart(date);
2541
+ case 'decade':
2542
+ return getNextDecadeStart(date);
2543
+ case 'year':
2544
+ return getNextYearStart(date);
2545
+ case 'month':
2546
+ return getNextMonthStart(date);
2547
+ default:
2548
+ throw new Error("Invalid rangeType: ".concat(rangeType));
2549
+ }
2550
+ }
2551
+ function getBeginPrevious2(rangeType, date) {
2552
+ switch (rangeType) {
2553
+ case 'decade':
2554
+ return getPreviousDecadeStart(date, -100);
2555
+ case 'year':
2556
+ return getPreviousYearStart(date, -10);
2557
+ case 'month':
2558
+ return getPreviousMonthStart(date, -12);
2559
+ default:
2560
+ throw new Error("Invalid rangeType: ".concat(rangeType));
2561
+ }
2562
+ }
2563
+ function getBeginNext2(rangeType, date) {
2564
+ switch (rangeType) {
2565
+ case 'decade':
2566
+ return getNextDecadeStart(date, 100);
2567
+ case 'year':
2568
+ return getNextYearStart(date, 10);
2569
+ case 'month':
2570
+ return getNextMonthStart(date, 12);
2571
+ default:
2572
+ throw new Error("Invalid rangeType: ".concat(rangeType));
2573
+ }
2574
+ }
2575
+ /**
2576
+ * Returns the end of a given range.
2577
+ *
2578
+ * @param {RangeType} rangeType Range type (e.g. 'day')
2579
+ * @param {Date} date Date.
2580
+ * @returns {Date} End of a given range.
2581
+ */
2582
+ function getEnd(rangeType, date) {
2583
+ switch (rangeType) {
2584
+ case 'century':
2585
+ return getCenturyEnd(date);
2586
+ case 'decade':
2587
+ return getDecadeEnd(date);
2588
+ case 'year':
2589
+ return getYearEnd(date);
2590
+ case 'month':
2591
+ return getMonthEnd(date);
2592
+ case 'day':
2593
+ return getDayEnd(date);
2594
+ default:
2595
+ throw new Error("Invalid rangeType: ".concat(rangeType));
2596
+ }
2597
+ }
2598
+ /**
2599
+ * Returns the end of a previous given range.
2600
+ *
2601
+ * @param {RangeType} rangeType Range type (e.g. 'day')
2602
+ * @param {Date} date Date.
2603
+ * @returns {Date} End of a previous given range.
2604
+ */
2605
+ function getEndPrevious(rangeType, date) {
2606
+ switch (rangeType) {
2607
+ case 'century':
2608
+ return getPreviousCenturyEnd(date);
2609
+ case 'decade':
2610
+ return getPreviousDecadeEnd(date);
2611
+ case 'year':
2612
+ return getPreviousYearEnd(date);
2613
+ case 'month':
2614
+ return getPreviousMonthEnd(date);
2615
+ default:
2616
+ throw new Error("Invalid rangeType: ".concat(rangeType));
2617
+ }
2618
+ }
2619
+ function getEndPrevious2(rangeType, date) {
2620
+ switch (rangeType) {
2621
+ case 'decade':
2622
+ return getPreviousDecadeEnd(date, -100);
2623
+ case 'year':
2624
+ return getPreviousYearEnd(date, -10);
2625
+ case 'month':
2626
+ return getPreviousMonthEnd(date, -12);
2627
+ default:
2628
+ throw new Error("Invalid rangeType: ".concat(rangeType));
2629
+ }
2630
+ }
2631
+ /**
2632
+ * Returns an array with the beginning and the end of a given range.
2633
+ *
2634
+ * @param {RangeType} rangeType Range type (e.g. 'day')
2635
+ * @param {Date} date Date.
2636
+ * @returns {Date[]} Beginning and end of a given range.
2637
+ */
2638
+ function getRange(rangeType, date) {
2639
+ switch (rangeType) {
2640
+ case 'century':
2641
+ return getCenturyRange(date);
2642
+ case 'decade':
2643
+ return getDecadeRange(date);
2644
+ case 'year':
2645
+ return getYearRange(date);
2646
+ case 'month':
2647
+ return getMonthRange(date);
2648
+ case 'day':
2649
+ return getDayRange(date);
2650
+ default:
2651
+ throw new Error("Invalid rangeType: ".concat(rangeType));
2652
+ }
2653
+ }
2654
+ /**
2655
+ * Creates a range out of two values, ensuring they are in order and covering entire period ranges.
2656
+ *
2657
+ * @param {RangeType} rangeType Range type (e.g. 'day')
2658
+ * @param {Date} date1 First date.
2659
+ * @param {Date} date2 Second date.
2660
+ * @returns {Date[]} Beginning and end of a given range.
2661
+ */
2662
+ function getValueRange(rangeType, date1, date2) {
2663
+ var rawNextValue = [date1, date2].sort(function (a, b) { return a.getTime() - b.getTime(); });
2664
+ return [getBegin(rangeType, rawNextValue[0]), getEnd(rangeType, rawNextValue[1])];
2665
+ }
2666
+ function toYearLabel(locale, formatYear$1, dates) {
2667
+ return dates.map(function (date) { return (formatYear$1 || formatYear)(locale, date); }).join(' – ');
2668
+ }
2669
+ /**
2670
+ * @callback FormatYear
2671
+ * @param {string} locale Locale.
2672
+ * @param {Date} date Date.
2673
+ * @returns {string} Formatted year.
2674
+ */
2675
+ /**
2676
+ * Returns a string labelling a century of a given date.
2677
+ * For example, for 2017 it will return 2001-2100.
2678
+ *
2679
+ * @param {string} locale Locale.
2680
+ * @param {FormatYear} formatYear Function to format a year.
2681
+ * @param {Date|string|number} date Date or a year as a string or as a number.
2682
+ * @returns {string} String labelling a century of a given date.
2683
+ */
2684
+ function getCenturyLabel(locale, formatYear, date) {
2685
+ return toYearLabel(locale, formatYear, getCenturyRange(date));
2686
+ }
2687
+ /**
2688
+ * Returns a string labelling a decade of a given date.
2689
+ * For example, for 2017 it will return 2011-2020.
2690
+ *
2691
+ * @param {string} locale Locale.
2692
+ * @param {FormatYear} formatYear Function to format a year.
2693
+ * @param {Date|string|number} date Date or a year as a string or as a number.
2694
+ * @returns {string} String labelling a decade of a given date.
2695
+ */
2696
+ function getDecadeLabel(locale, formatYear, date) {
2697
+ return toYearLabel(locale, formatYear, getDecadeRange(date));
2698
+ }
2699
+ /**
2700
+ * Returns a boolean determining whether a given date is the current day of the week.
2701
+ *
2702
+ * @param {Date} date Date.
2703
+ * @returns {boolean} Whether a given date is the current day of the week.
2704
+ */
2705
+ function isCurrentDayOfWeek(date) {
2706
+ return date.getDay() === new Date().getDay();
2707
+ }
2708
+ /**
2709
+ * Returns a boolean determining whether a given date is a weekend day.
2710
+ *
2711
+ * @param {Date} date Date.
2712
+ * @param {CalendarType} [calendarType="iso8601"] Calendar type.
2713
+ * @returns {boolean} Whether a given date is a weekend day.
2714
+ */
2715
+ function isWeekend(date, calendarType) {
2716
+ if (calendarType === void 0) { calendarType = CALENDAR_TYPES.ISO_8601; }
2717
+ var weekday = date.getDay();
2718
+ switch (calendarType) {
2719
+ case CALENDAR_TYPES.ISLAMIC:
2720
+ case CALENDAR_TYPES.HEBREW:
2721
+ return weekday === FRIDAY || weekday === SATURDAY;
2722
+ case CALENDAR_TYPES.ISO_8601:
2723
+ case CALENDAR_TYPES.GREGORY:
2724
+ return weekday === SATURDAY || weekday === SUNDAY;
2725
+ default:
2726
+ throw new Error('Unsupported calendar type.');
2727
+ }
2728
+ }
2729
+
2730
+ var className$6 = 'react-calendar__navigation';
2731
+ function Navigation(_a) {
2732
+ var activeStartDate = _a.activeStartDate, drillUp = _a.drillUp, _b = _a.formatMonthYear, formatMonthYear$1 = _b === void 0 ? formatMonthYear : _b, _c = _a.formatYear, formatYear$1 = _c === void 0 ? formatYear : _c, locale = _a.locale, maxDate = _a.maxDate, minDate = _a.minDate, _d = _a.navigationAriaLabel, navigationAriaLabel = _d === void 0 ? '' : _d, navigationAriaLive = _a.navigationAriaLive, navigationLabel = _a.navigationLabel, _e = _a.next2AriaLabel, next2AriaLabel = _e === void 0 ? '' : _e, _f = _a.next2Label, next2Label = _f === void 0 ? '»' : _f, _g = _a.nextAriaLabel, nextAriaLabel = _g === void 0 ? '' : _g, _h = _a.nextLabel, nextLabel = _h === void 0 ? '›' : _h, _j = _a.prev2AriaLabel, prev2AriaLabel = _j === void 0 ? '' : _j, _k = _a.prev2Label, prev2Label = _k === void 0 ? '«' : _k, _l = _a.prevAriaLabel, prevAriaLabel = _l === void 0 ? '' : _l, _m = _a.prevLabel, prevLabel = _m === void 0 ? '‹' : _m, setActiveStartDate = _a.setActiveStartDate, showDoubleView = _a.showDoubleView, view = _a.view, views = _a.views;
2733
+ var drillUpAvailable = views.indexOf(view) > 0;
2734
+ var shouldShowPrevNext2Buttons = view !== 'century';
2735
+ var previousActiveStartDate = getBeginPrevious(view, activeStartDate);
2736
+ var previousActiveStartDate2 = shouldShowPrevNext2Buttons
2737
+ ? getBeginPrevious2(view, activeStartDate)
2738
+ : undefined;
2739
+ var nextActiveStartDate = getBeginNext(view, activeStartDate);
2740
+ var nextActiveStartDate2 = shouldShowPrevNext2Buttons
2741
+ ? getBeginNext2(view, activeStartDate)
2742
+ : undefined;
2743
+ var prevButtonDisabled = (function () {
2744
+ if (previousActiveStartDate.getFullYear() < 0) {
2745
+ return true;
2746
+ }
2747
+ var previousActiveEndDate = getEndPrevious(view, activeStartDate);
2748
+ return minDate && minDate >= previousActiveEndDate;
2749
+ })();
2750
+ var prev2ButtonDisabled = shouldShowPrevNext2Buttons &&
2751
+ (function () {
2752
+ if (previousActiveStartDate2.getFullYear() < 0) {
2753
+ return true;
2754
+ }
2755
+ var previousActiveEndDate = getEndPrevious2(view, activeStartDate);
2756
+ return minDate && minDate >= previousActiveEndDate;
2757
+ })();
2758
+ var nextButtonDisabled = maxDate && maxDate < nextActiveStartDate;
2759
+ var next2ButtonDisabled = shouldShowPrevNext2Buttons && maxDate && maxDate < nextActiveStartDate2;
2760
+ function onClickPrevious() {
2761
+ setActiveStartDate(previousActiveStartDate, 'prev');
2762
+ }
2763
+ function onClickPrevious2() {
2764
+ setActiveStartDate(previousActiveStartDate2, 'prev2');
2765
+ }
2766
+ function onClickNext() {
2767
+ setActiveStartDate(nextActiveStartDate, 'next');
2768
+ }
2769
+ function onClickNext2() {
2770
+ setActiveStartDate(nextActiveStartDate2, 'next2');
2771
+ }
2772
+ function renderLabel(date) {
2773
+ var label = (function () {
2774
+ switch (view) {
2775
+ case 'century':
2776
+ return getCenturyLabel(locale, formatYear$1, date);
2777
+ case 'decade':
2778
+ return getDecadeLabel(locale, formatYear$1, date);
2779
+ case 'year':
2780
+ return formatYear$1(locale, date);
2781
+ case 'month':
2782
+ return formatMonthYear$1(locale, date);
2783
+ default:
2784
+ throw new Error("Invalid view: ".concat(view, "."));
2785
+ }
2786
+ })();
2787
+ return navigationLabel
2788
+ ? navigationLabel({
2789
+ date: date,
2790
+ label: label,
2791
+ locale: locale || getUserLocale() || undefined,
2792
+ view: view,
2793
+ })
2794
+ : label;
2795
+ }
2796
+ function renderButton() {
2797
+ var labelClassName = "".concat(className$6, "__label");
2798
+ return (jsxs("button", { "aria-label": navigationAriaLabel, "aria-live": navigationAriaLive, className: labelClassName, disabled: !drillUpAvailable, onClick: drillUp, style: { flexGrow: 1 }, type: "button", children: [jsx("span", { className: "".concat(labelClassName, "__labelText ").concat(labelClassName, "__labelText--from"), children: renderLabel(activeStartDate) }), showDoubleView ? (jsxs(Fragment, { children: [jsx("span", { className: "".concat(labelClassName, "__divider"), children: " \u2013 " }), jsx("span", { className: "".concat(labelClassName, "__labelText ").concat(labelClassName, "__labelText--to"), children: renderLabel(nextActiveStartDate) })] })) : null] }));
2799
+ }
2800
+ return (jsxs("div", { className: className$6, children: [prev2Label !== null && shouldShowPrevNext2Buttons ? (jsx("button", { "aria-label": prev2AriaLabel, className: "".concat(className$6, "__arrow ").concat(className$6, "__prev2-button"), disabled: prev2ButtonDisabled, onClick: onClickPrevious2, type: "button", children: prev2Label })) : null, prevLabel !== null && (jsx("button", { "aria-label": prevAriaLabel, className: "".concat(className$6, "__arrow ").concat(className$6, "__prev-button"), disabled: prevButtonDisabled, onClick: onClickPrevious, type: "button", children: prevLabel })), renderButton(), nextLabel !== null && (jsx("button", { "aria-label": nextAriaLabel, className: "".concat(className$6, "__arrow ").concat(className$6, "__next-button"), disabled: nextButtonDisabled, onClick: onClickNext, type: "button", children: nextLabel })), next2Label !== null && shouldShowPrevNext2Buttons ? (jsx("button", { "aria-label": next2AriaLabel, className: "".concat(className$6, "__arrow ").concat(className$6, "__next2-button"), disabled: next2ButtonDisabled, onClick: onClickNext2, type: "button", children: next2Label })) : null] }));
2801
+ }
2802
+
2803
+ var __assign$e = (undefined && undefined.__assign) || function () {
2804
+ __assign$e = Object.assign || function(t) {
2805
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
2806
+ s = arguments[i];
2807
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
2808
+ t[p] = s[p];
2809
+ }
2810
+ return t;
2811
+ };
2812
+ return __assign$e.apply(this, arguments);
2813
+ };
2814
+ var __rest$a = (undefined && undefined.__rest) || function (s, e) {
2815
+ var t = {};
2816
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
2817
+ t[p] = s[p];
2818
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
2819
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
2820
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
2821
+ t[p[i]] = s[p[i]];
2822
+ }
2823
+ return t;
2824
+ };
2825
+ function toPercent(num) {
2826
+ return "".concat(num, "%");
2827
+ }
2828
+ function Flex(_a) {
2829
+ var children = _a.children, className = _a.className, count = _a.count, direction = _a.direction, offset = _a.offset, style = _a.style, wrap = _a.wrap, otherProps = __rest$a(_a, ["children", "className", "count", "direction", "offset", "style", "wrap"]);
2830
+ return (jsx("div", __assign$e({ className: className, style: __assign$e({ display: 'flex', flexDirection: direction, flexWrap: wrap ? 'wrap' : 'nowrap' }, style) }, otherProps, { children: Children.map(children, function (child, index) {
2831
+ var marginInlineStart = offset && index === 0 ? toPercent((100 * offset) / count) : null;
2832
+ return cloneElement(child, __assign$e(__assign$e({}, child.props), { style: {
2833
+ flexBasis: toPercent(100 / count),
2834
+ flexShrink: 0,
2835
+ flexGrow: 0,
2836
+ overflow: 'hidden',
2837
+ marginLeft: marginInlineStart,
2838
+ marginInlineStart: marginInlineStart,
2839
+ marginInlineEnd: 0,
2840
+ } }));
2841
+ }) })));
2842
+ }
2843
+
2844
+ /**
2845
+ * Returns a value no smaller than min and no larger than max.
2846
+ *
2847
+ * @param {Date} value Value to return.
2848
+ * @param {Date} min Minimum return value.
2849
+ * @param {Date} max Maximum return value.
2850
+ * @returns {Date} Value between min and max.
2851
+ */
2852
+ function between(value, min, max) {
2853
+ if (min && min > value) {
2854
+ return min;
2855
+ }
2856
+ if (max && max < value) {
2857
+ return max;
2858
+ }
2859
+ return value;
2860
+ }
2861
+ function isValueWithinRange(value, range) {
2862
+ return range[0] <= value && range[1] >= value;
2863
+ }
2864
+ function isRangeWithinRange(greaterRange, smallerRange) {
2865
+ return greaterRange[0] <= smallerRange[0] && greaterRange[1] >= smallerRange[1];
2866
+ }
2867
+ function doRangesOverlap(range1, range2) {
2868
+ return isValueWithinRange(range1[0], range2) || isValueWithinRange(range1[1], range2);
2869
+ }
2870
+ function getRangeClassNames(valueRange, dateRange, baseClassName) {
2871
+ var isRange = doRangesOverlap(dateRange, valueRange);
2872
+ var classes = [];
2873
+ if (isRange) {
2874
+ classes.push(baseClassName);
2875
+ var isRangeStart = isValueWithinRange(valueRange[0], dateRange);
2876
+ var isRangeEnd = isValueWithinRange(valueRange[1], dateRange);
2877
+ if (isRangeStart) {
2878
+ classes.push("".concat(baseClassName, "Start"));
2879
+ }
2880
+ if (isRangeEnd) {
2881
+ classes.push("".concat(baseClassName, "End"));
2882
+ }
2883
+ if (isRangeStart && isRangeEnd) {
2884
+ classes.push("".concat(baseClassName, "BothEnds"));
2885
+ }
2886
+ }
2887
+ return classes;
2888
+ }
2889
+ function isCompleteValue(value) {
2890
+ if (Array.isArray(value)) {
2891
+ return value[0] !== null && value[1] !== null;
2892
+ }
2893
+ return value !== null;
2894
+ }
2895
+ function getTileClasses(args) {
2896
+ if (!args) {
2897
+ throw new Error('args is required');
2898
+ }
2899
+ var value = args.value, date = args.date, hover = args.hover;
2900
+ var className = 'react-calendar__tile';
2901
+ var classes = [className];
2902
+ if (!date) {
2903
+ return classes;
2904
+ }
2905
+ var now = new Date();
2906
+ var dateRange = (function () {
2907
+ if (Array.isArray(date)) {
2908
+ return date;
2909
+ }
2910
+ var dateType = args.dateType;
2911
+ if (!dateType) {
2912
+ throw new Error('dateType is required when date is not an array of two dates');
2913
+ }
2914
+ return getRange(dateType, date);
2915
+ })();
2916
+ if (isValueWithinRange(now, dateRange)) {
2917
+ classes.push("".concat(className, "--now"));
2918
+ }
2919
+ if (!value || !isCompleteValue(value)) {
2920
+ return classes;
2921
+ }
2922
+ var valueRange = (function () {
2923
+ if (Array.isArray(value)) {
2924
+ return value;
2925
+ }
2926
+ var valueType = args.valueType;
2927
+ if (!valueType) {
2928
+ throw new Error('valueType is required when value is not an array of two dates');
2929
+ }
2930
+ return getRange(valueType, value);
2931
+ })();
2932
+ if (isRangeWithinRange(valueRange, dateRange)) {
2933
+ classes.push("".concat(className, "--active"));
2934
+ }
2935
+ else if (doRangesOverlap(valueRange, dateRange)) {
2936
+ classes.push("".concat(className, "--hasActive"));
2937
+ }
2938
+ var valueRangeClassNames = getRangeClassNames(valueRange, dateRange, "".concat(className, "--range"));
2939
+ classes.push.apply(classes, valueRangeClassNames);
2940
+ var valueArray = Array.isArray(value) ? value : [value];
2941
+ if (hover && valueArray.length === 1) {
2942
+ var hoverRange = hover > valueRange[0] ? [valueRange[0], hover] : [hover, valueRange[0]];
2943
+ var hoverRangeClassNames = getRangeClassNames(hoverRange, dateRange, "".concat(className, "--hover"));
2944
+ classes.push.apply(classes, hoverRangeClassNames);
2945
+ }
2946
+ return classes;
2947
+ }
2948
+
2949
+ function TileGroup(_a) {
2950
+ var className = _a.className, _b = _a.count, count = _b === void 0 ? 3 : _b, dateTransform = _a.dateTransform, dateType = _a.dateType, end = _a.end, hover = _a.hover, offset = _a.offset, renderTile = _a.renderTile, start = _a.start, _c = _a.step, step = _c === void 0 ? 1 : _c, value = _a.value, valueType = _a.valueType;
2951
+ var tiles = [];
2952
+ for (var point = start; point <= end; point += step) {
2953
+ var date = dateTransform(point);
2954
+ tiles.push(renderTile({
2955
+ classes: getTileClasses({
2956
+ date: date,
2957
+ dateType: dateType,
2958
+ hover: hover,
2959
+ value: value,
2960
+ valueType: valueType,
2961
+ }),
2962
+ date: date,
2963
+ }));
2964
+ }
2965
+ return (jsx(Flex, { className: className, count: count, offset: offset, wrap: true, children: tiles }));
2966
+ }
2967
+
2968
+ function Tile(props) {
2969
+ var activeStartDate = props.activeStartDate, children = props.children, classes = props.classes, date = props.date, formatAbbr = props.formatAbbr, locale = props.locale, maxDate = props.maxDate, maxDateTransform = props.maxDateTransform, minDate = props.minDate, minDateTransform = props.minDateTransform, onClick = props.onClick, onMouseOver = props.onMouseOver, style = props.style, tileClassNameProps = props.tileClassName, tileContentProps = props.tileContent, tileDisabled = props.tileDisabled, view = props.view;
2970
+ var tileClassName = useMemo(function () {
2971
+ var args = { activeStartDate: activeStartDate, date: date, view: view };
2972
+ return typeof tileClassNameProps === 'function' ? tileClassNameProps(args) : tileClassNameProps;
2973
+ }, [activeStartDate, date, tileClassNameProps, view]);
2974
+ var tileContent = useMemo(function () {
2975
+ var args = { activeStartDate: activeStartDate, date: date, view: view };
2976
+ return typeof tileContentProps === 'function' ? tileContentProps(args) : tileContentProps;
2977
+ }, [activeStartDate, date, tileContentProps, view]);
2978
+ return (jsxs("button", { className: clsx$1(classes, tileClassName), disabled: (minDate && minDateTransform(minDate) > date) ||
2979
+ (maxDate && maxDateTransform(maxDate) < date) ||
2980
+ (tileDisabled === null || tileDisabled === void 0 ? void 0 : tileDisabled({ activeStartDate: activeStartDate, date: date, view: view })), onClick: onClick ? function (event) { return onClick(date, event); } : undefined, onFocus: onMouseOver ? function () { return onMouseOver(date); } : undefined, onMouseOver: onMouseOver ? function () { return onMouseOver(date); } : undefined, style: style, type: "button", children: [formatAbbr ? jsx("abbr", { "aria-label": formatAbbr(locale, date), children: children }) : children, tileContent] }));
2981
+ }
2982
+
2983
+ var __assign$d = (undefined && undefined.__assign) || function () {
2984
+ __assign$d = Object.assign || function(t) {
2985
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
2986
+ s = arguments[i];
2987
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
2988
+ t[p] = s[p];
2989
+ }
2990
+ return t;
2991
+ };
2992
+ return __assign$d.apply(this, arguments);
2993
+ };
2994
+ var __rest$9 = (undefined && undefined.__rest) || function (s, e) {
2995
+ var t = {};
2996
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
2997
+ t[p] = s[p];
2998
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
2999
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
3000
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
3001
+ t[p[i]] = s[p[i]];
3002
+ }
3003
+ return t;
3004
+ };
3005
+ var className$5 = 'react-calendar__century-view__decades__decade';
3006
+ function Decade(_a) {
3007
+ var _b = _a.classes, classes = _b === void 0 ? [] : _b, currentCentury = _a.currentCentury, _c = _a.formatYear, formatYear$1 = _c === void 0 ? formatYear : _c, otherProps = __rest$9(_a, ["classes", "currentCentury", "formatYear"]);
3008
+ var date = otherProps.date, locale = otherProps.locale;
3009
+ var classesProps = [];
3010
+ if (classes) {
3011
+ classesProps.push.apply(classesProps, classes);
3012
+ }
3013
+ {
3014
+ classesProps.push(className$5);
3015
+ }
3016
+ if (getCenturyStart(date).getFullYear() !== currentCentury) {
3017
+ classesProps.push("".concat(className$5, "--neighboringCentury"));
3018
+ }
3019
+ return (jsx(Tile, __assign$d({}, otherProps, { classes: classesProps, maxDateTransform: getDecadeEnd, minDateTransform: getDecadeStart, view: "century", children: getDecadeLabel(locale, formatYear$1, date) })));
3020
+ }
3021
+
3022
+ var __assign$c = (undefined && undefined.__assign) || function () {
3023
+ __assign$c = Object.assign || function(t) {
3024
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
3025
+ s = arguments[i];
3026
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
3027
+ t[p] = s[p];
3028
+ }
3029
+ return t;
3030
+ };
3031
+ return __assign$c.apply(this, arguments);
3032
+ };
3033
+ var __rest$8 = (undefined && undefined.__rest) || function (s, e) {
3034
+ var t = {};
3035
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
3036
+ t[p] = s[p];
3037
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
3038
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
3039
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
3040
+ t[p[i]] = s[p[i]];
3041
+ }
3042
+ return t;
3043
+ };
3044
+ function Decades(props) {
3045
+ var activeStartDate = props.activeStartDate, hover = props.hover, showNeighboringCentury = props.showNeighboringCentury, value = props.value, valueType = props.valueType, otherProps = __rest$8(props, ["activeStartDate", "hover", "showNeighboringCentury", "value", "valueType"]);
3046
+ var start = getBeginOfCenturyYear(activeStartDate);
3047
+ var end = start + (showNeighboringCentury ? 119 : 99);
3048
+ return (jsx(TileGroup, { className: "react-calendar__century-view__decades", dateTransform: getDecadeStart, dateType: "decade", end: end, hover: hover, renderTile: function (_a) {
3049
+ var date = _a.date, otherTileProps = __rest$8(_a, ["date"]);
3050
+ return (jsx(Decade, __assign$c({}, otherProps, otherTileProps, { activeStartDate: activeStartDate, currentCentury: start, date: date }), date.getTime()));
3051
+ }, start: start, step: 10, value: value, valueType: valueType }));
3052
+ }
3053
+
3054
+ var __assign$b = (undefined && undefined.__assign) || function () {
3055
+ __assign$b = Object.assign || function(t) {
3056
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
3057
+ s = arguments[i];
3058
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
3059
+ t[p] = s[p];
3060
+ }
3061
+ return t;
3062
+ };
3063
+ return __assign$b.apply(this, arguments);
3064
+ };
3065
+ /**
3066
+ * Displays a given century.
3067
+ */
3068
+ function CenturyView(props) {
3069
+ function renderDecades() {
3070
+ return jsx(Decades, __assign$b({}, props));
3071
+ }
3072
+ return jsx("div", { className: "react-calendar__century-view", children: renderDecades() });
3073
+ }
3074
+
3075
+ var __assign$a = (undefined && undefined.__assign) || function () {
3076
+ __assign$a = Object.assign || function(t) {
3077
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
3078
+ s = arguments[i];
3079
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
3080
+ t[p] = s[p];
3081
+ }
3082
+ return t;
3083
+ };
3084
+ return __assign$a.apply(this, arguments);
3085
+ };
3086
+ var __rest$7 = (undefined && undefined.__rest) || function (s, e) {
3087
+ var t = {};
3088
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
3089
+ t[p] = s[p];
3090
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
3091
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
3092
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
3093
+ t[p[i]] = s[p[i]];
3094
+ }
3095
+ return t;
3096
+ };
3097
+ var className$4 = 'react-calendar__decade-view__years__year';
3098
+ function Year(_a) {
3099
+ var _b = _a.classes, classes = _b === void 0 ? [] : _b, currentDecade = _a.currentDecade, _c = _a.formatYear, formatYear$1 = _c === void 0 ? formatYear : _c, otherProps = __rest$7(_a, ["classes", "currentDecade", "formatYear"]);
3100
+ var date = otherProps.date, locale = otherProps.locale;
3101
+ var classesProps = [];
3102
+ if (classes) {
3103
+ classesProps.push.apply(classesProps, classes);
3104
+ }
3105
+ {
3106
+ classesProps.push(className$4);
3107
+ }
3108
+ if (getDecadeStart(date).getFullYear() !== currentDecade) {
3109
+ classesProps.push("".concat(className$4, "--neighboringDecade"));
3110
+ }
3111
+ return (jsx(Tile, __assign$a({}, otherProps, { classes: classesProps, maxDateTransform: getYearEnd, minDateTransform: getYearStart, view: "decade", children: formatYear$1(locale, date) })));
3112
+ }
3113
+
3114
+ var __assign$9 = (undefined && undefined.__assign) || function () {
3115
+ __assign$9 = Object.assign || function(t) {
3116
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
3117
+ s = arguments[i];
3118
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
3119
+ t[p] = s[p];
3120
+ }
3121
+ return t;
3122
+ };
3123
+ return __assign$9.apply(this, arguments);
3124
+ };
3125
+ var __rest$6 = (undefined && undefined.__rest) || function (s, e) {
3126
+ var t = {};
3127
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
3128
+ t[p] = s[p];
3129
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
3130
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
3131
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
3132
+ t[p[i]] = s[p[i]];
3133
+ }
3134
+ return t;
3135
+ };
3136
+ function Years(props) {
3137
+ var activeStartDate = props.activeStartDate, hover = props.hover, showNeighboringDecade = props.showNeighboringDecade, value = props.value, valueType = props.valueType, otherProps = __rest$6(props, ["activeStartDate", "hover", "showNeighboringDecade", "value", "valueType"]);
3138
+ var start = getBeginOfDecadeYear(activeStartDate);
3139
+ var end = start + (showNeighboringDecade ? 11 : 9);
3140
+ return (jsx(TileGroup, { className: "react-calendar__decade-view__years", dateTransform: getYearStart, dateType: "year", end: end, hover: hover, renderTile: function (_a) {
3141
+ var date = _a.date, otherTileProps = __rest$6(_a, ["date"]);
3142
+ return (jsx(Year, __assign$9({}, otherProps, otherTileProps, { activeStartDate: activeStartDate, currentDecade: start, date: date }), date.getTime()));
3143
+ }, start: start, value: value, valueType: valueType }));
3144
+ }
3145
+
3146
+ var __assign$8 = (undefined && undefined.__assign) || function () {
3147
+ __assign$8 = Object.assign || function(t) {
3148
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
3149
+ s = arguments[i];
3150
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
3151
+ t[p] = s[p];
3152
+ }
3153
+ return t;
3154
+ };
3155
+ return __assign$8.apply(this, arguments);
3156
+ };
3157
+ /**
3158
+ * Displays a given decade.
3159
+ */
3160
+ function DecadeView(props) {
3161
+ function renderYears() {
3162
+ return jsx(Years, __assign$8({}, props));
3163
+ }
3164
+ return jsx("div", { className: "react-calendar__decade-view", children: renderYears() });
3165
+ }
3166
+
3167
+ var __assign$7 = (undefined && undefined.__assign) || function () {
3168
+ __assign$7 = Object.assign || function(t) {
3169
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
3170
+ s = arguments[i];
3171
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
3172
+ t[p] = s[p];
3173
+ }
3174
+ return t;
3175
+ };
3176
+ return __assign$7.apply(this, arguments);
3177
+ };
3178
+ var __rest$5 = (undefined && undefined.__rest) || function (s, e) {
3179
+ var t = {};
3180
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
3181
+ t[p] = s[p];
3182
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
3183
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
3184
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
3185
+ t[p[i]] = s[p[i]];
3186
+ }
3187
+ return t;
3188
+ };
3189
+ var __spreadArray = (undefined && undefined.__spreadArray) || function (to, from, pack) {
3190
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
3191
+ if (ar || !(i in from)) {
3192
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
3193
+ ar[i] = from[i];
3194
+ }
3195
+ }
3196
+ return to.concat(ar || Array.prototype.slice.call(from));
3197
+ };
3198
+ var className$3 = 'react-calendar__year-view__months__month';
3199
+ function Month(_a) {
3200
+ var _b = _a.classes, classes = _b === void 0 ? [] : _b, _c = _a.formatMonth, formatMonth$1 = _c === void 0 ? formatMonth : _c, _d = _a.formatMonthYear, formatMonthYear$1 = _d === void 0 ? formatMonthYear : _d, otherProps = __rest$5(_a, ["classes", "formatMonth", "formatMonthYear"]);
3201
+ var date = otherProps.date, locale = otherProps.locale;
3202
+ return (jsx(Tile, __assign$7({}, otherProps, { classes: __spreadArray(__spreadArray([], classes, true), [className$3], false), formatAbbr: formatMonthYear$1, maxDateTransform: getMonthEnd, minDateTransform: getMonthStart, view: "year", children: formatMonth$1(locale, date) })));
3203
+ }
3204
+
3205
+ var __assign$6 = (undefined && undefined.__assign) || function () {
3206
+ __assign$6 = Object.assign || function(t) {
3207
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
3208
+ s = arguments[i];
3209
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
3210
+ t[p] = s[p];
3211
+ }
3212
+ return t;
3213
+ };
3214
+ return __assign$6.apply(this, arguments);
3215
+ };
3216
+ var __rest$4 = (undefined && undefined.__rest) || function (s, e) {
3217
+ var t = {};
3218
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
3219
+ t[p] = s[p];
3220
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
3221
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
3222
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
3223
+ t[p[i]] = s[p[i]];
3224
+ }
3225
+ return t;
3226
+ };
3227
+ function Months(props) {
3228
+ var activeStartDate = props.activeStartDate, hover = props.hover, value = props.value, valueType = props.valueType, otherProps = __rest$4(props, ["activeStartDate", "hover", "value", "valueType"]);
3229
+ var start = 0;
3230
+ var end = 11;
3231
+ var year = getYear(activeStartDate);
3232
+ return (jsx(TileGroup, { className: "react-calendar__year-view__months", dateTransform: function (monthIndex) {
3233
+ var date = new Date();
3234
+ date.setFullYear(year, monthIndex, 1);
3235
+ return getMonthStart(date);
3236
+ }, dateType: "month", end: end, hover: hover, renderTile: function (_a) {
3237
+ var date = _a.date, otherTileProps = __rest$4(_a, ["date"]);
3238
+ return (jsx(Month, __assign$6({}, otherProps, otherTileProps, { activeStartDate: activeStartDate, date: date }), date.getTime()));
3239
+ }, start: start, value: value, valueType: valueType }));
3240
+ }
3241
+
3242
+ var __assign$5 = (undefined && undefined.__assign) || function () {
3243
+ __assign$5 = Object.assign || function(t) {
3244
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
3245
+ s = arguments[i];
3246
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
3247
+ t[p] = s[p];
3248
+ }
3249
+ return t;
3250
+ };
3251
+ return __assign$5.apply(this, arguments);
3252
+ };
3253
+ /**
3254
+ * Displays a given year.
3255
+ */
3256
+ function YearView(props) {
3257
+ function renderMonths() {
3258
+ return jsx(Months, __assign$5({}, props));
3259
+ }
3260
+ return jsx("div", { className: "react-calendar__year-view", children: renderMonths() });
3261
+ }
3262
+
3263
+ var __assign$4 = (undefined && undefined.__assign) || function () {
3264
+ __assign$4 = Object.assign || function(t) {
3265
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
3266
+ s = arguments[i];
3267
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
3268
+ t[p] = s[p];
3269
+ }
3270
+ return t;
3271
+ };
3272
+ return __assign$4.apply(this, arguments);
3273
+ };
3274
+ var __rest$3 = (undefined && undefined.__rest) || function (s, e) {
3275
+ var t = {};
3276
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
3277
+ t[p] = s[p];
3278
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
3279
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
3280
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
3281
+ t[p[i]] = s[p[i]];
3282
+ }
3283
+ return t;
3284
+ };
3285
+ var className$2 = 'react-calendar__month-view__days__day';
3286
+ function Day(_a) {
3287
+ var calendarType = _a.calendarType, _b = _a.classes, classes = _b === void 0 ? [] : _b, currentMonthIndex = _a.currentMonthIndex, _c = _a.formatDay, formatDay$1 = _c === void 0 ? formatDay : _c, _d = _a.formatLongDate, formatLongDate$1 = _d === void 0 ? formatLongDate : _d, otherProps = __rest$3(_a, ["calendarType", "classes", "currentMonthIndex", "formatDay", "formatLongDate"]);
3288
+ var date = otherProps.date, locale = otherProps.locale;
3289
+ var classesProps = [];
3290
+ if (classes) {
3291
+ classesProps.push.apply(classesProps, classes);
3292
+ }
3293
+ {
3294
+ classesProps.push(className$2);
3295
+ }
3296
+ if (isWeekend(date, calendarType)) {
3297
+ classesProps.push("".concat(className$2, "--weekend"));
3298
+ }
3299
+ if (date.getMonth() !== currentMonthIndex) {
3300
+ classesProps.push("".concat(className$2, "--neighboringMonth"));
3301
+ }
3302
+ return (jsx(Tile, __assign$4({}, otherProps, { classes: classesProps, formatAbbr: formatLongDate$1, maxDateTransform: getDayEnd, minDateTransform: getDayStart, view: "month", children: formatDay$1(locale, date) })));
3303
+ }
3304
+
3305
+ var __assign$3 = (undefined && undefined.__assign) || function () {
3306
+ __assign$3 = Object.assign || function(t) {
3307
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
3308
+ s = arguments[i];
3309
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
3310
+ t[p] = s[p];
3311
+ }
3312
+ return t;
3313
+ };
3314
+ return __assign$3.apply(this, arguments);
3315
+ };
3316
+ var __rest$2 = (undefined && undefined.__rest) || function (s, e) {
3317
+ var t = {};
3318
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
3319
+ t[p] = s[p];
3320
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
3321
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
3322
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
3323
+ t[p[i]] = s[p[i]];
3324
+ }
3325
+ return t;
3326
+ };
3327
+ function Days(props) {
3328
+ var activeStartDate = props.activeStartDate, calendarType = props.calendarType, hover = props.hover, showFixedNumberOfWeeks = props.showFixedNumberOfWeeks, showNeighboringMonth = props.showNeighboringMonth, value = props.value, valueType = props.valueType, otherProps = __rest$2(props, ["activeStartDate", "calendarType", "hover", "showFixedNumberOfWeeks", "showNeighboringMonth", "value", "valueType"]);
3329
+ var year = getYear(activeStartDate);
3330
+ var monthIndex = getMonth(activeStartDate);
3331
+ var hasFixedNumberOfWeeks = showFixedNumberOfWeeks || showNeighboringMonth;
3332
+ var dayOfWeek = getDayOfWeek(activeStartDate, calendarType);
3333
+ var offset = hasFixedNumberOfWeeks ? 0 : dayOfWeek;
3334
+ /**
3335
+ * Defines on which day of the month the grid shall start. If we simply show current
3336
+ * month, we obviously start on day one, but if showNeighboringMonth is set to
3337
+ * true, we need to find the beginning of the week the first day of the month is in.
3338
+ */
3339
+ var start = (hasFixedNumberOfWeeks ? -dayOfWeek : 0) + 1;
3340
+ /**
3341
+ * Defines on which day of the month the grid shall end. If we simply show current
3342
+ * month, we need to stop on the last day of the month, but if showNeighboringMonth
3343
+ * is set to true, we need to find the end of the week the last day of the month is in.
3344
+ */
3345
+ var end = (function () {
3346
+ if (showFixedNumberOfWeeks) {
3347
+ // Always show 6 weeks
3348
+ return start + 6 * 7 - 1;
3349
+ }
3350
+ var daysInMonth = getDaysInMonth(activeStartDate);
3351
+ if (showNeighboringMonth) {
3352
+ var activeEndDate = new Date();
3353
+ activeEndDate.setFullYear(year, monthIndex, daysInMonth);
3354
+ activeEndDate.setHours(0, 0, 0, 0);
3355
+ var daysUntilEndOfTheWeek = 7 - getDayOfWeek(activeEndDate, calendarType) - 1;
3356
+ return daysInMonth + daysUntilEndOfTheWeek;
3357
+ }
3358
+ return daysInMonth;
3359
+ })();
3360
+ return (jsx(TileGroup, { className: "react-calendar__month-view__days", count: 7, dateTransform: function (day) {
3361
+ var date = new Date();
3362
+ date.setFullYear(year, monthIndex, day);
3363
+ return getDayStart(date);
3364
+ }, dateType: "day", hover: hover, end: end, renderTile: function (_a) {
3365
+ var date = _a.date, otherTileProps = __rest$2(_a, ["date"]);
3366
+ return (jsx(Day, __assign$3({}, otherProps, otherTileProps, { activeStartDate: activeStartDate, calendarType: calendarType, currentMonthIndex: monthIndex, date: date }), date.getTime()));
3367
+ }, offset: offset, start: start, value: value, valueType: valueType }));
3368
+ }
3369
+
3370
+ var className$1 = 'react-calendar__month-view__weekdays';
3371
+ var weekdayClassName = "".concat(className$1, "__weekday");
3372
+ function Weekdays(props) {
3373
+ var calendarType = props.calendarType, _a = props.formatShortWeekday, formatShortWeekday$1 = _a === void 0 ? formatShortWeekday : _a, _b = props.formatWeekday, formatWeekday$1 = _b === void 0 ? formatWeekday : _b, locale = props.locale, onMouseLeave = props.onMouseLeave;
3374
+ var anyDate = new Date();
3375
+ var beginOfMonth = getMonthStart(anyDate);
3376
+ var year = getYear(beginOfMonth);
3377
+ var monthIndex = getMonth(beginOfMonth);
3378
+ var weekdays = [];
3379
+ for (var weekday = 1; weekday <= 7; weekday += 1) {
3380
+ var weekdayDate = new Date(year, monthIndex, weekday - getDayOfWeek(beginOfMonth, calendarType));
3381
+ var abbr = formatWeekday$1(locale, weekdayDate);
3382
+ weekdays.push(jsx("div", { className: clsx$1(weekdayClassName, isCurrentDayOfWeek(weekdayDate) && "".concat(weekdayClassName, "--current"), isWeekend(weekdayDate, calendarType) && "".concat(weekdayClassName, "--weekend")), children: jsx("abbr", { "aria-label": abbr, title: abbr, children: formatShortWeekday$1(locale, weekdayDate).replace('.', '') }) }, weekday));
3383
+ }
3384
+ return (jsx(Flex, { className: className$1, count: 7, onFocus: onMouseLeave, onMouseOver: onMouseLeave, children: weekdays }));
3385
+ }
3386
+
3387
+ var __assign$2 = (undefined && undefined.__assign) || function () {
3388
+ __assign$2 = Object.assign || function(t) {
3389
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
3390
+ s = arguments[i];
3391
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
3392
+ t[p] = s[p];
3393
+ }
3394
+ return t;
3395
+ };
3396
+ return __assign$2.apply(this, arguments);
3397
+ };
3398
+ var __rest$1 = (undefined && undefined.__rest) || function (s, e) {
3399
+ var t = {};
3400
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
3401
+ t[p] = s[p];
3402
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
3403
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
3404
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
3405
+ t[p[i]] = s[p[i]];
3406
+ }
3407
+ return t;
3408
+ };
3409
+ var className = 'react-calendar__tile';
3410
+ function WeekNumber(props) {
3411
+ var onClickWeekNumber = props.onClickWeekNumber, weekNumber = props.weekNumber;
3412
+ var children = jsx("span", { children: weekNumber });
3413
+ if (onClickWeekNumber) {
3414
+ var date_1 = props.date, onClickWeekNumber_1 = props.onClickWeekNumber, weekNumber_1 = props.weekNumber, otherProps = __rest$1(props, ["date", "onClickWeekNumber", "weekNumber"]);
3415
+ return (jsx("button", __assign$2({}, otherProps, { className: className, onClick: function (event) { return onClickWeekNumber_1(weekNumber_1, date_1, event); }, type: "button", children: children })));
3416
+ // biome-ignore lint/style/noUselessElse: TypeScript is unhappy if we remove this else
3417
+ }
3418
+ else {
3419
+ props.date; props.onClickWeekNumber; props.weekNumber; var otherProps = __rest$1(props, ["date", "onClickWeekNumber", "weekNumber"]);
3420
+ return (jsx("div", __assign$2({}, otherProps, { className: className, children: children })));
3421
+ }
3422
+ }
3423
+
3424
+ function WeekNumbers(props) {
3425
+ var activeStartDate = props.activeStartDate, calendarType = props.calendarType, onClickWeekNumber = props.onClickWeekNumber, onMouseLeave = props.onMouseLeave, showFixedNumberOfWeeks = props.showFixedNumberOfWeeks;
3426
+ var numberOfWeeks = (function () {
3427
+ if (showFixedNumberOfWeeks) {
3428
+ return 6;
3429
+ }
3430
+ var numberOfDays = getDaysInMonth(activeStartDate);
3431
+ var startWeekday = getDayOfWeek(activeStartDate, calendarType);
3432
+ var days = numberOfDays - (7 - startWeekday);
3433
+ return 1 + Math.ceil(days / 7);
3434
+ })();
3435
+ var dates = (function () {
3436
+ var year = getYear(activeStartDate);
3437
+ var monthIndex = getMonth(activeStartDate);
3438
+ var day = getDate(activeStartDate);
3439
+ var result = [];
3440
+ for (var index = 0; index < numberOfWeeks; index += 1) {
3441
+ result.push(getBeginOfWeek(new Date(year, monthIndex, day + index * 7), calendarType));
3442
+ }
3443
+ return result;
3444
+ })();
3445
+ var weekNumbers = dates.map(function (date) { return getWeekNumber(date, calendarType); });
3446
+ return (jsx(Flex, { className: "react-calendar__month-view__weekNumbers", count: numberOfWeeks, direction: "column", onFocus: onMouseLeave, onMouseOver: onMouseLeave, style: { flexBasis: 'calc(100% * (1 / 8)', flexShrink: 0 }, children: weekNumbers.map(function (weekNumber, weekIndex) {
3447
+ var date = dates[weekIndex];
3448
+ if (!date) {
3449
+ throw new Error('date is not defined');
3450
+ }
3451
+ return (jsx(WeekNumber, { date: date, onClickWeekNumber: onClickWeekNumber, weekNumber: weekNumber }, weekNumber));
3452
+ }) }));
3453
+ }
3454
+
3455
+ var __assign$1 = (undefined && undefined.__assign) || function () {
3456
+ __assign$1 = Object.assign || function(t) {
3457
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
3458
+ s = arguments[i];
3459
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
3460
+ t[p] = s[p];
3461
+ }
3462
+ return t;
3463
+ };
3464
+ return __assign$1.apply(this, arguments);
3465
+ };
3466
+ var __rest = (undefined && undefined.__rest) || function (s, e) {
3467
+ var t = {};
3468
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
3469
+ t[p] = s[p];
3470
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
3471
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
3472
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
3473
+ t[p[i]] = s[p[i]];
3474
+ }
3475
+ return t;
3476
+ };
3477
+ function getCalendarTypeFromLocale(locale) {
3478
+ if (locale) {
3479
+ for (var _i = 0, _a = Object.entries(CALENDAR_TYPE_LOCALES); _i < _a.length; _i++) {
3480
+ var _b = _a[_i], calendarType = _b[0], locales = _b[1];
3481
+ if (locales.includes(locale)) {
3482
+ return calendarType;
3483
+ }
3484
+ }
3485
+ }
3486
+ return CALENDAR_TYPES.ISO_8601;
3487
+ }
3488
+ /**
3489
+ * Displays a given month.
3490
+ */
3491
+ function MonthView(props) {
3492
+ var activeStartDate = props.activeStartDate, locale = props.locale, onMouseLeave = props.onMouseLeave, showFixedNumberOfWeeks = props.showFixedNumberOfWeeks;
3493
+ var _a = props.calendarType, calendarType = _a === void 0 ? getCalendarTypeFromLocale(locale) : _a, formatShortWeekday = props.formatShortWeekday, formatWeekday = props.formatWeekday, onClickWeekNumber = props.onClickWeekNumber, showWeekNumbers = props.showWeekNumbers, childProps = __rest(props, ["calendarType", "formatShortWeekday", "formatWeekday", "onClickWeekNumber", "showWeekNumbers"]);
3494
+ function renderWeekdays() {
3495
+ return (jsx(Weekdays, { calendarType: calendarType, formatShortWeekday: formatShortWeekday, formatWeekday: formatWeekday, locale: locale, onMouseLeave: onMouseLeave }));
3496
+ }
3497
+ function renderWeekNumbers() {
3498
+ if (!showWeekNumbers) {
3499
+ return null;
3500
+ }
3501
+ return (jsx(WeekNumbers, { activeStartDate: activeStartDate, calendarType: calendarType, onClickWeekNumber: onClickWeekNumber, onMouseLeave: onMouseLeave, showFixedNumberOfWeeks: showFixedNumberOfWeeks }));
3502
+ }
3503
+ function renderDays() {
3504
+ return jsx(Days, __assign$1({ calendarType: calendarType }, childProps));
3505
+ }
3506
+ var className = 'react-calendar__month-view';
3507
+ return (jsx("div", { className: clsx$1(className, showWeekNumbers ? "".concat(className, "--weekNumbers") : ''), children: jsxs("div", { style: {
3508
+ display: 'flex',
3509
+ alignItems: 'flex-end',
3510
+ }, children: [renderWeekNumbers(), jsxs("div", { style: {
3511
+ flexGrow: 1,
3512
+ width: '100%',
3513
+ }, children: [renderWeekdays(), renderDays()] })] }) }));
3514
+ }
3515
+
3516
+ var __assign = (undefined && undefined.__assign) || function () {
3517
+ __assign = Object.assign || function(t) {
3518
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
3519
+ s = arguments[i];
3520
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
3521
+ t[p] = s[p];
3522
+ }
3523
+ return t;
3524
+ };
3525
+ return __assign.apply(this, arguments);
3526
+ };
3527
+ var baseClassName = 'react-calendar';
3528
+ var allViews = ['century', 'decade', 'year', 'month'];
3529
+ var allValueTypes = ['decade', 'year', 'month', 'day'];
3530
+ var defaultMinDate = new Date();
3531
+ defaultMinDate.setFullYear(1, 0, 1);
3532
+ defaultMinDate.setHours(0, 0, 0, 0);
3533
+ var defaultMaxDate = new Date(8.64e15);
3534
+ function toDate(value) {
3535
+ if (value instanceof Date) {
3536
+ return value;
3537
+ }
3538
+ return new Date(value);
3539
+ }
3540
+ /**
3541
+ * Returns views array with disallowed values cut off.
3542
+ */
3543
+ function getLimitedViews(minDetail, maxDetail) {
3544
+ return allViews.slice(allViews.indexOf(minDetail), allViews.indexOf(maxDetail) + 1);
3545
+ }
3546
+ /**
3547
+ * Determines whether a given view is allowed with currently applied settings.
3548
+ */
3549
+ function isViewAllowed(view, minDetail, maxDetail) {
3550
+ var views = getLimitedViews(minDetail, maxDetail);
3551
+ return views.indexOf(view) !== -1;
3552
+ }
3553
+ /**
3554
+ * Gets either provided view if allowed by minDetail and maxDetail, or gets
3555
+ * the default view if not allowed.
3556
+ */
3557
+ function getView(view, minDetail, maxDetail) {
3558
+ if (!view) {
3559
+ return maxDetail;
3560
+ }
3561
+ if (isViewAllowed(view, minDetail, maxDetail)) {
3562
+ return view;
3563
+ }
3564
+ return maxDetail;
3565
+ }
3566
+ /**
3567
+ * Returns value type that can be returned with currently applied settings.
3568
+ */
3569
+ function getValueType(view) {
3570
+ var index = allViews.indexOf(view);
3571
+ return allValueTypes[index];
3572
+ }
3573
+ function getValue(value, index) {
3574
+ var rawValue = Array.isArray(value) ? value[index] : value;
3575
+ if (!rawValue) {
3576
+ return null;
3577
+ }
3578
+ var valueDate = toDate(rawValue);
3579
+ if (Number.isNaN(valueDate.getTime())) {
3580
+ throw new Error("Invalid date: ".concat(value));
3581
+ }
3582
+ return valueDate;
3583
+ }
3584
+ function getDetailValue(_a, index) {
3585
+ var value = _a.value, minDate = _a.minDate, maxDate = _a.maxDate, maxDetail = _a.maxDetail;
3586
+ var valuePiece = getValue(value, index);
3587
+ if (!valuePiece) {
3588
+ return null;
3589
+ }
3590
+ var valueType = getValueType(maxDetail);
3591
+ var detailValueFrom = (function () {
3592
+ switch (index) {
3593
+ case 0:
3594
+ return getBegin(valueType, valuePiece);
3595
+ case 1:
3596
+ return getEnd(valueType, valuePiece);
3597
+ default:
3598
+ throw new Error("Invalid index value: ".concat(index));
3599
+ }
3600
+ })();
3601
+ return between(detailValueFrom, minDate, maxDate);
3602
+ }
3603
+ var getDetailValueFrom = function (args) { return getDetailValue(args, 0); };
3604
+ var getDetailValueTo = function (args) { return getDetailValue(args, 1); };
3605
+ var getDetailValueArray = function (args) {
3606
+ return [getDetailValueFrom, getDetailValueTo].map(function (fn) { return fn(args); });
3607
+ };
3608
+ function getActiveStartDate(_a) {
3609
+ var maxDate = _a.maxDate, maxDetail = _a.maxDetail, minDate = _a.minDate, minDetail = _a.minDetail, value = _a.value, view = _a.view;
3610
+ var rangeType = getView(view, minDetail, maxDetail);
3611
+ var valueFrom = getDetailValueFrom({
3612
+ value: value,
3613
+ minDate: minDate,
3614
+ maxDate: maxDate,
3615
+ maxDetail: maxDetail,
3616
+ }) || new Date();
3617
+ return getBegin(rangeType, valueFrom);
3618
+ }
3619
+ function getInitialActiveStartDate(_a) {
3620
+ var activeStartDate = _a.activeStartDate, defaultActiveStartDate = _a.defaultActiveStartDate, defaultValue = _a.defaultValue, defaultView = _a.defaultView, maxDate = _a.maxDate, maxDetail = _a.maxDetail, minDate = _a.minDate, minDetail = _a.minDetail, value = _a.value, view = _a.view;
3621
+ var rangeType = getView(view, minDetail, maxDetail);
3622
+ var valueFrom = activeStartDate || defaultActiveStartDate;
3623
+ if (valueFrom) {
3624
+ return getBegin(rangeType, valueFrom);
3625
+ }
3626
+ return getActiveStartDate({
3627
+ maxDate: maxDate,
3628
+ maxDetail: maxDetail,
3629
+ minDate: minDate,
3630
+ minDetail: minDetail,
3631
+ value: value || defaultValue,
3632
+ view: view || defaultView,
3633
+ });
3634
+ }
3635
+ function getIsSingleValue(value) {
3636
+ return value && (!Array.isArray(value) || value.length === 1);
3637
+ }
3638
+ function areDatesEqual(date1, date2) {
3639
+ return date1 instanceof Date && date2 instanceof Date && date1.getTime() === date2.getTime();
3640
+ }
3641
+ var Calendar = forwardRef(function Calendar(props, ref) {
3642
+ var activeStartDateProps = props.activeStartDate, allowPartialRange = props.allowPartialRange, calendarType = props.calendarType, className = props.className, defaultActiveStartDate = props.defaultActiveStartDate, defaultValue = props.defaultValue, defaultView = props.defaultView, formatDay = props.formatDay, formatLongDate = props.formatLongDate, formatMonth = props.formatMonth, formatMonthYear = props.formatMonthYear, formatShortWeekday = props.formatShortWeekday, formatWeekday = props.formatWeekday, formatYear = props.formatYear, _a = props.goToRangeStartOnSelect, goToRangeStartOnSelect = _a === void 0 ? true : _a, inputRef = props.inputRef, locale = props.locale, _b = props.maxDate, maxDate = _b === void 0 ? defaultMaxDate : _b, _c = props.maxDetail, maxDetail = _c === void 0 ? 'month' : _c, _d = props.minDate, minDate = _d === void 0 ? defaultMinDate : _d, _e = props.minDetail, minDetail = _e === void 0 ? 'century' : _e, navigationAriaLabel = props.navigationAriaLabel, navigationAriaLive = props.navigationAriaLive, navigationLabel = props.navigationLabel, next2AriaLabel = props.next2AriaLabel, next2Label = props.next2Label, nextAriaLabel = props.nextAriaLabel, nextLabel = props.nextLabel, onActiveStartDateChange = props.onActiveStartDateChange, onChangeProps = props.onChange, onClickDay = props.onClickDay, onClickDecade = props.onClickDecade, onClickMonth = props.onClickMonth, onClickWeekNumber = props.onClickWeekNumber, onClickYear = props.onClickYear, onDrillDown = props.onDrillDown, onDrillUp = props.onDrillUp, onViewChange = props.onViewChange, prev2AriaLabel = props.prev2AriaLabel, prev2Label = props.prev2Label, prevAriaLabel = props.prevAriaLabel, prevLabel = props.prevLabel, _f = props.returnValue, returnValue = _f === void 0 ? 'start' : _f, selectRange = props.selectRange, showDoubleView = props.showDoubleView, showFixedNumberOfWeeks = props.showFixedNumberOfWeeks, _g = props.showNavigation, showNavigation = _g === void 0 ? true : _g, showNeighboringCentury = props.showNeighboringCentury, showNeighboringDecade = props.showNeighboringDecade, _h = props.showNeighboringMonth, showNeighboringMonth = _h === void 0 ? true : _h, showWeekNumbers = props.showWeekNumbers, tileClassName = props.tileClassName, tileContent = props.tileContent, tileDisabled = props.tileDisabled, valueProps = props.value, viewProps = props.view;
3643
+ var _j = useState(defaultActiveStartDate), activeStartDateState = _j[0], setActiveStartDateState = _j[1];
3644
+ var _k = useState(null), hoverState = _k[0], setHoverState = _k[1];
3645
+ var _l = useState(Array.isArray(defaultValue)
3646
+ ? defaultValue.map(function (el) { return (el !== null ? toDate(el) : null); })
3647
+ : defaultValue !== null && defaultValue !== undefined
3648
+ ? toDate(defaultValue)
3649
+ : null), valueState = _l[0], setValueState = _l[1];
3650
+ var _m = useState(defaultView), viewState = _m[0], setViewState = _m[1];
3651
+ var activeStartDate = activeStartDateProps ||
3652
+ activeStartDateState ||
3653
+ getInitialActiveStartDate({
3654
+ activeStartDate: activeStartDateProps,
3655
+ defaultActiveStartDate: defaultActiveStartDate,
3656
+ defaultValue: defaultValue,
3657
+ defaultView: defaultView,
3658
+ maxDate: maxDate,
3659
+ maxDetail: maxDetail,
3660
+ minDate: minDate,
3661
+ minDetail: minDetail,
3662
+ value: valueProps,
3663
+ view: viewProps,
3664
+ });
3665
+ var value = (function () {
3666
+ var rawValue = (function () {
3667
+ // In the middle of range selection, use value from state
3668
+ if (selectRange && getIsSingleValue(valueState)) {
3669
+ return valueState;
3670
+ }
3671
+ return valueProps !== undefined ? valueProps : valueState;
3672
+ })();
3673
+ if (!rawValue) {
3674
+ return null;
3675
+ }
3676
+ return Array.isArray(rawValue)
3677
+ ? rawValue.map(function (el) { return (el !== null ? toDate(el) : null); })
3678
+ : rawValue !== null
3679
+ ? toDate(rawValue)
3680
+ : null;
3681
+ })();
3682
+ var valueType = getValueType(maxDetail);
3683
+ var view = getView(viewProps || viewState, minDetail, maxDetail);
3684
+ var views = getLimitedViews(minDetail, maxDetail);
3685
+ var hover = selectRange ? hoverState : null;
3686
+ var drillDownAvailable = views.indexOf(view) < views.length - 1;
3687
+ var drillUpAvailable = views.indexOf(view) > 0;
3688
+ var getProcessedValue = useCallback(function (value) {
3689
+ var processFunction = (function () {
3690
+ switch (returnValue) {
3691
+ case 'start':
3692
+ return getDetailValueFrom;
3693
+ case 'end':
3694
+ return getDetailValueTo;
3695
+ case 'range':
3696
+ return getDetailValueArray;
3697
+ default:
3698
+ throw new Error('Invalid returnValue.');
3699
+ }
3700
+ })();
3701
+ return processFunction({
3702
+ maxDate: maxDate,
3703
+ maxDetail: maxDetail,
3704
+ minDate: minDate,
3705
+ value: value,
3706
+ });
3707
+ }, [maxDate, maxDetail, minDate, returnValue]);
3708
+ var setActiveStartDate = useCallback(function (nextActiveStartDate, action) {
3709
+ setActiveStartDateState(nextActiveStartDate);
3710
+ var args = {
3711
+ action: action,
3712
+ activeStartDate: nextActiveStartDate,
3713
+ value: value,
3714
+ view: view,
3715
+ };
3716
+ if (onActiveStartDateChange && !areDatesEqual(activeStartDate, nextActiveStartDate)) {
3717
+ onActiveStartDateChange(args);
3718
+ }
3719
+ }, [activeStartDate, onActiveStartDateChange, value, view]);
3720
+ var onClickTile = useCallback(function (value, event) {
3721
+ var callback = (function () {
3722
+ switch (view) {
3723
+ case 'century':
3724
+ return onClickDecade;
3725
+ case 'decade':
3726
+ return onClickYear;
3727
+ case 'year':
3728
+ return onClickMonth;
3729
+ case 'month':
3730
+ return onClickDay;
3731
+ default:
3732
+ throw new Error("Invalid view: ".concat(view, "."));
3733
+ }
3734
+ })();
3735
+ if (callback)
3736
+ callback(value, event);
3737
+ }, [onClickDay, onClickDecade, onClickMonth, onClickYear, view]);
3738
+ var drillDown = useCallback(function (nextActiveStartDate, event) {
3739
+ if (!drillDownAvailable) {
3740
+ return;
3741
+ }
3742
+ onClickTile(nextActiveStartDate, event);
3743
+ var nextView = views[views.indexOf(view) + 1];
3744
+ if (!nextView) {
3745
+ throw new Error('Attempted to drill down from the lowest view.');
3746
+ }
3747
+ setActiveStartDateState(nextActiveStartDate);
3748
+ setViewState(nextView);
3749
+ var args = {
3750
+ action: 'drillDown',
3751
+ activeStartDate: nextActiveStartDate,
3752
+ value: value,
3753
+ view: nextView,
3754
+ };
3755
+ if (onActiveStartDateChange && !areDatesEqual(activeStartDate, nextActiveStartDate)) {
3756
+ onActiveStartDateChange(args);
3757
+ }
3758
+ if (onViewChange && view !== nextView) {
3759
+ onViewChange(args);
3760
+ }
3761
+ if (onDrillDown) {
3762
+ onDrillDown(args);
3763
+ }
3764
+ }, [
3765
+ activeStartDate,
3766
+ drillDownAvailable,
3767
+ onActiveStartDateChange,
3768
+ onClickTile,
3769
+ onDrillDown,
3770
+ onViewChange,
3771
+ value,
3772
+ view,
3773
+ views,
3774
+ ]);
3775
+ var drillUp = useCallback(function () {
3776
+ if (!drillUpAvailable) {
3777
+ return;
3778
+ }
3779
+ var nextView = views[views.indexOf(view) - 1];
3780
+ if (!nextView) {
3781
+ throw new Error('Attempted to drill up from the highest view.');
3782
+ }
3783
+ var nextActiveStartDate = getBegin(nextView, activeStartDate);
3784
+ setActiveStartDateState(nextActiveStartDate);
3785
+ setViewState(nextView);
3786
+ var args = {
3787
+ action: 'drillUp',
3788
+ activeStartDate: nextActiveStartDate,
3789
+ value: value,
3790
+ view: nextView,
3791
+ };
3792
+ if (onActiveStartDateChange && !areDatesEqual(activeStartDate, nextActiveStartDate)) {
3793
+ onActiveStartDateChange(args);
3794
+ }
3795
+ if (onViewChange && view !== nextView) {
3796
+ onViewChange(args);
3797
+ }
3798
+ if (onDrillUp) {
3799
+ onDrillUp(args);
3800
+ }
3801
+ }, [
3802
+ activeStartDate,
3803
+ drillUpAvailable,
3804
+ onActiveStartDateChange,
3805
+ onDrillUp,
3806
+ onViewChange,
3807
+ value,
3808
+ view,
3809
+ views,
3810
+ ]);
3811
+ var onChange = useCallback(function (rawNextValue, event) {
3812
+ var previousValue = value;
3813
+ onClickTile(rawNextValue, event);
3814
+ var isFirstValueInRange = selectRange && !getIsSingleValue(previousValue);
3815
+ var nextValue;
3816
+ if (selectRange) {
3817
+ // Range selection turned on
3818
+ if (isFirstValueInRange) {
3819
+ // Value has 0 or 2 elements - either way we're starting a new array
3820
+ // First value
3821
+ nextValue = getBegin(valueType, rawNextValue);
3822
+ }
3823
+ else {
3824
+ if (!previousValue) {
3825
+ throw new Error('previousValue is required');
3826
+ }
3827
+ if (Array.isArray(previousValue)) {
3828
+ throw new Error('previousValue must not be an array');
3829
+ }
3830
+ // Second value
3831
+ nextValue = getValueRange(valueType, previousValue, rawNextValue);
3832
+ }
3833
+ }
3834
+ else {
3835
+ // Range selection turned off
3836
+ nextValue = getProcessedValue(rawNextValue);
3837
+ }
3838
+ var nextActiveStartDate =
3839
+ // Range selection turned off
3840
+ !selectRange ||
3841
+ // Range selection turned on, first value
3842
+ isFirstValueInRange ||
3843
+ // Range selection turned on, second value, goToRangeStartOnSelect toggled on
3844
+ goToRangeStartOnSelect
3845
+ ? getActiveStartDate({
3846
+ maxDate: maxDate,
3847
+ maxDetail: maxDetail,
3848
+ minDate: minDate,
3849
+ minDetail: minDetail,
3850
+ value: nextValue,
3851
+ view: view,
3852
+ })
3853
+ : null;
3854
+ event.persist();
3855
+ setActiveStartDateState(nextActiveStartDate);
3856
+ setValueState(nextValue);
3857
+ var args = {
3858
+ action: 'onChange',
3859
+ activeStartDate: nextActiveStartDate,
3860
+ value: nextValue,
3861
+ view: view,
3862
+ };
3863
+ if (onActiveStartDateChange && !areDatesEqual(activeStartDate, nextActiveStartDate)) {
3864
+ onActiveStartDateChange(args);
3865
+ }
3866
+ if (onChangeProps) {
3867
+ if (selectRange) {
3868
+ var isSingleValue = getIsSingleValue(nextValue);
3869
+ if (!isSingleValue) {
3870
+ onChangeProps(nextValue || null, event);
3871
+ }
3872
+ else if (allowPartialRange) {
3873
+ if (Array.isArray(nextValue)) {
3874
+ throw new Error('value must not be an array');
3875
+ }
3876
+ onChangeProps([nextValue || null, null], event);
3877
+ }
3878
+ }
3879
+ else {
3880
+ onChangeProps(nextValue || null, event);
3881
+ }
3882
+ }
3883
+ }, [
3884
+ activeStartDate,
3885
+ allowPartialRange,
3886
+ getProcessedValue,
3887
+ goToRangeStartOnSelect,
3888
+ maxDate,
3889
+ maxDetail,
3890
+ minDate,
3891
+ minDetail,
3892
+ onActiveStartDateChange,
3893
+ onChangeProps,
3894
+ onClickTile,
3895
+ selectRange,
3896
+ value,
3897
+ valueType,
3898
+ view,
3899
+ ]);
3900
+ function onMouseOver(nextHover) {
3901
+ setHoverState(nextHover);
3902
+ }
3903
+ function onMouseLeave() {
3904
+ setHoverState(null);
3905
+ }
3906
+ useImperativeHandle(ref, function () { return ({
3907
+ activeStartDate: activeStartDate,
3908
+ drillDown: drillDown,
3909
+ drillUp: drillUp,
3910
+ onChange: onChange,
3911
+ setActiveStartDate: setActiveStartDate,
3912
+ value: value,
3913
+ view: view,
3914
+ }); }, [activeStartDate, drillDown, drillUp, onChange, setActiveStartDate, value, view]);
3915
+ function renderContent(next) {
3916
+ var currentActiveStartDate = next
3917
+ ? getBeginNext(view, activeStartDate)
3918
+ : getBegin(view, activeStartDate);
3919
+ var onClick = drillDownAvailable ? drillDown : onChange;
3920
+ var commonProps = {
3921
+ activeStartDate: currentActiveStartDate,
3922
+ hover: hover,
3923
+ locale: locale,
3924
+ maxDate: maxDate,
3925
+ minDate: minDate,
3926
+ onClick: onClick,
3927
+ onMouseOver: selectRange ? onMouseOver : undefined,
3928
+ tileClassName: tileClassName,
3929
+ tileContent: tileContent,
3930
+ tileDisabled: tileDisabled,
3931
+ value: value,
3932
+ valueType: valueType,
3933
+ };
3934
+ switch (view) {
3935
+ case 'century': {
3936
+ return (jsx(CenturyView, __assign({ formatYear: formatYear, showNeighboringCentury: showNeighboringCentury }, commonProps)));
3937
+ }
3938
+ case 'decade': {
3939
+ return (jsx(DecadeView, __assign({ formatYear: formatYear, showNeighboringDecade: showNeighboringDecade }, commonProps)));
3940
+ }
3941
+ case 'year': {
3942
+ return (jsx(YearView, __assign({ formatMonth: formatMonth, formatMonthYear: formatMonthYear }, commonProps)));
3943
+ }
3944
+ case 'month': {
3945
+ return (jsx(MonthView, __assign({ calendarType: calendarType, formatDay: formatDay, formatLongDate: formatLongDate, formatShortWeekday: formatShortWeekday, formatWeekday: formatWeekday, onClickWeekNumber: onClickWeekNumber, onMouseLeave: selectRange ? onMouseLeave : undefined, showFixedNumberOfWeeks: typeof showFixedNumberOfWeeks !== 'undefined'
3946
+ ? showFixedNumberOfWeeks
3947
+ : showDoubleView, showNeighboringMonth: showNeighboringMonth, showWeekNumbers: showWeekNumbers }, commonProps)));
3948
+ }
3949
+ default:
3950
+ throw new Error("Invalid view: ".concat(view, "."));
3951
+ }
3952
+ }
3953
+ function renderNavigation() {
3954
+ if (!showNavigation) {
3955
+ return null;
3956
+ }
3957
+ return (jsx(Navigation, { activeStartDate: activeStartDate, drillUp: drillUp, formatMonthYear: formatMonthYear, formatYear: formatYear, locale: locale, maxDate: maxDate, minDate: minDate, navigationAriaLabel: navigationAriaLabel, navigationAriaLive: navigationAriaLive, navigationLabel: navigationLabel, next2AriaLabel: next2AriaLabel, next2Label: next2Label, nextAriaLabel: nextAriaLabel, nextLabel: nextLabel, prev2AriaLabel: prev2AriaLabel, prev2Label: prev2Label, prevAriaLabel: prevAriaLabel, prevLabel: prevLabel, setActiveStartDate: setActiveStartDate, showDoubleView: showDoubleView, view: view, views: views }));
3958
+ }
3959
+ var valueArray = Array.isArray(value) ? value : [value];
3960
+ return (jsxs("div", { className: clsx$1(baseClassName, selectRange && valueArray.length === 1 && "".concat(baseClassName, "--selectRange"), showDoubleView && "".concat(baseClassName, "--doubleView"), className), ref: inputRef, children: [renderNavigation(), jsxs("div", { className: "".concat(baseClassName, "__viewContainer"), onBlur: selectRange ? onMouseLeave : undefined, onMouseLeave: selectRange ? onMouseLeave : undefined, children: [renderContent(), showDoubleView ? renderContent(true) : null] })] }));
3961
+ });
3962
+
3963
+ const tooltipVariants = cva("fixed z-50 bg-popup-fill-intense text-action-ink-on-primary-normal rounded-medium border border-popup-outline-subtle flex flex-col p-4 rounded-xlarge min-w-[200px] max-w-[300px] transition-opacity duration-200", {
3964
+ variants: {
3965
+ isVisible: {
3966
+ true: "opacity-100 pointer-events-auto shadow-[0_4px_20px_rgba(0,0,0,0.15)]",
3967
+ false: "opacity-0 pointer-events-none",
3968
+ },
3969
+ },
3970
+ defaultVariants: {
3971
+ isVisible: false,
3972
+ },
3973
+ });
3974
+ const tooltipArrowVariants = cva("absolute w-0 h-0 border-solid border-[6px] -translate-x-1/2", {
3975
+ variants: {
3976
+ placement: {
3977
+ "top-start": "top-full border-t-popup-fill-intense border-x-transparent border-b-transparent",
3978
+ top: "top-full border-t-popup-fill-intense border-x-transparent border-b-transparent",
3979
+ "top-end": "top-full border-t-popup-fill-intense border-x-transparent border-b-transparent",
3980
+ "bottom-start": "bottom-full border-b-popup-fill-intense border-x-transparent border-t-transparent",
3981
+ bottom: "bottom-full border-b-popup-fill-intense border-x-transparent border-t-transparent",
3982
+ "bottom-end": "bottom-full border-b-popup-fill-intense border-x-transparent border-t-transparent",
3983
+ },
3984
+ },
3985
+ defaultVariants: {
3986
+ placement: "top",
3987
+ },
3988
+ });
3989
+ const Tooltip = React.forwardRef(({ children, heading, description, placement = "top", showArrow = true, className, delay = 200, disabled = false, }, ref) => {
3990
+ const [isVisible, setIsVisible] = React.useState(false);
3991
+ const [position, setPosition] = React.useState({ top: 0, left: 0 });
3992
+ const [arrowPosition, setArrowPosition] = React.useState({ left: 0 });
3993
+ const [actualPlacement, setActualPlacement] = React.useState(placement);
3994
+ const timeoutRef = React.useRef(null);
3995
+ const triggerRef = React.useRef(null);
3996
+ const tooltipRef = React.useRef(null);
3997
+ const calculatePosition = React.useCallback(() => {
3998
+ if (!triggerRef.current || !tooltipRef.current)
3999
+ return;
4000
+ const triggerRect = triggerRef.current.getBoundingClientRect();
4001
+ const tooltipRect = tooltipRef.current.getBoundingClientRect();
4002
+ const gap = 8; // 8px gap between trigger and tooltip
4003
+ const arrowSize = 6; // Size of the arrow
4004
+ const viewportPadding = 8; // Minimum padding from viewport edges
4005
+ let top = 0;
4006
+ let left = 0;
4007
+ let currentPlacement = placement;
4008
+ // Calculate initial position based on placement
4009
+ switch (placement) {
4010
+ case "top-start":
4011
+ top = triggerRect.top - tooltipRect.height - gap - arrowSize;
4012
+ left = triggerRect.left;
4013
+ break;
4014
+ case "top":
4015
+ top = triggerRect.top - tooltipRect.height - gap - arrowSize;
4016
+ left =
4017
+ triggerRect.left + triggerRect.width / 2 - tooltipRect.width / 2;
4018
+ break;
4019
+ case "top-end":
4020
+ top = triggerRect.top - tooltipRect.height - gap - arrowSize;
4021
+ left = triggerRect.right - tooltipRect.width;
4022
+ break;
4023
+ case "bottom-start":
4024
+ top = triggerRect.bottom + gap + arrowSize;
4025
+ left = triggerRect.left;
4026
+ break;
4027
+ case "bottom":
4028
+ top = triggerRect.bottom + gap + arrowSize;
4029
+ left =
4030
+ triggerRect.left + triggerRect.width / 2 - tooltipRect.width / 2;
4031
+ break;
4032
+ case "bottom-end":
4033
+ top = triggerRect.bottom + gap + arrowSize;
4034
+ left = triggerRect.right - tooltipRect.width;
4035
+ break;
4036
+ }
4037
+ // Get viewport dimensions
4038
+ const viewportWidth = window.innerWidth;
4039
+ const viewportHeight = window.innerHeight;
4040
+ // Adjust horizontal position to keep tooltip within viewport
4041
+ if (left < viewportPadding) {
4042
+ // Tooltip would overflow on the left
4043
+ left = viewportPadding;
4044
+ }
4045
+ else if (left + tooltipRect.width > viewportWidth - viewportPadding) {
4046
+ // Tooltip would overflow on the right
4047
+ left = viewportWidth - tooltipRect.width - viewportPadding;
4048
+ }
4049
+ // Adjust vertical position to keep tooltip within viewport
4050
+ if (top < viewportPadding) {
4051
+ // Tooltip would overflow at the top
4052
+ // Try to flip to bottom if there's more space there
4053
+ const spaceBelow = viewportHeight - triggerRect.bottom;
4054
+ const spaceAbove = triggerRect.top;
4055
+ if (spaceBelow > spaceAbove) {
4056
+ // Flip to bottom
4057
+ top = triggerRect.bottom + gap + arrowSize;
4058
+ // Update placement to reflect the flip
4059
+ if (placement === "top-start")
4060
+ currentPlacement = "bottom-start";
4061
+ else if (placement === "top")
4062
+ currentPlacement = "bottom";
4063
+ else if (placement === "top-end")
4064
+ currentPlacement = "bottom-end";
4065
+ }
4066
+ else {
4067
+ // Keep at top but adjust to stay in viewport
4068
+ top = viewportPadding;
4069
+ }
4070
+ }
4071
+ else if (top + tooltipRect.height > viewportHeight - viewportPadding) {
4072
+ // Tooltip would overflow at the bottom
4073
+ // Try to flip to top if there's more space there
4074
+ const spaceAbove = triggerRect.top;
4075
+ const spaceBelow = viewportHeight - triggerRect.bottom;
4076
+ if (spaceAbove > spaceBelow) {
4077
+ // Flip to top
4078
+ top = triggerRect.top - tooltipRect.height - gap - arrowSize;
4079
+ // Update placement to reflect the flip
4080
+ if (placement === "bottom-start")
4081
+ currentPlacement = "top-start";
4082
+ else if (placement === "bottom")
4083
+ currentPlacement = "top";
4084
+ else if (placement === "bottom-end")
4085
+ currentPlacement = "top-end";
4086
+ }
4087
+ else {
4088
+ // Keep at bottom but adjust to stay in viewport
4089
+ top = viewportHeight - tooltipRect.height - viewportPadding;
4090
+ }
4091
+ }
4092
+ // Calculate arrow position relative to trigger
4093
+ // The arrow should point to the center of the trigger element
4094
+ const triggerCenterX = triggerRect.left + triggerRect.width / 2;
4095
+ const tooltipLeft = left;
4096
+ const arrowLeft = triggerCenterX - tooltipLeft;
4097
+ // Clamp arrow position to stay within tooltip bounds (with padding)
4098
+ const arrowPadding = 16; // Minimum distance from tooltip edges
4099
+ const clampedArrowLeft = Math.max(arrowPadding, Math.min(arrowLeft, tooltipRect.width - arrowPadding));
4100
+ setPosition({ top, left });
4101
+ setArrowPosition({ left: clampedArrowLeft });
4102
+ setActualPlacement(currentPlacement);
4103
+ }, [placement]);
4104
+ const handleMouseEnter = () => {
4105
+ if (disabled)
4106
+ return;
4107
+ if (timeoutRef.current) {
4108
+ clearTimeout(timeoutRef.current);
4109
+ }
4110
+ timeoutRef.current = setTimeout(() => {
4111
+ setIsVisible(true);
4112
+ }, delay);
4113
+ };
4114
+ const handleMouseLeave = () => {
4115
+ if (timeoutRef.current) {
4116
+ clearTimeout(timeoutRef.current);
4117
+ }
4118
+ setIsVisible(false);
4119
+ };
4120
+ const handleFocus = () => {
4121
+ if (disabled)
4122
+ return;
4123
+ setIsVisible(true);
4124
+ };
4125
+ const handleBlur = () => {
4126
+ setIsVisible(false);
4127
+ };
4128
+ React.useEffect(() => {
4129
+ if (isVisible) {
4130
+ calculatePosition();
4131
+ window.addEventListener("scroll", calculatePosition, true);
4132
+ window.addEventListener("resize", calculatePosition);
4133
+ }
4134
+ return () => {
4135
+ window.removeEventListener("scroll", calculatePosition, true);
4136
+ window.removeEventListener("resize", calculatePosition);
4137
+ };
4138
+ }, [isVisible, calculatePosition]);
4139
+ React.useEffect(() => {
4140
+ // Reset actualPlacement when placement prop changes
4141
+ setActualPlacement(placement);
4142
+ }, [placement]);
4143
+ React.useEffect(() => {
4144
+ return () => {
4145
+ if (timeoutRef.current) {
4146
+ clearTimeout(timeoutRef.current);
4147
+ }
4148
+ };
4149
+ }, []);
4150
+ // Merge refs function
4151
+ const mergeRefs = (...refs) => {
4152
+ return (node) => {
4153
+ refs.forEach((ref) => {
4154
+ if (typeof ref === "function") {
4155
+ ref(node);
4156
+ }
4157
+ else if (ref && typeof ref === "object" && "current" in ref) {
4158
+ ref.current = node;
4159
+ }
4160
+ });
4161
+ };
4162
+ };
4163
+ // Clone the child element and add event handlers
4164
+ const trigger = React.cloneElement(children, {
4165
+ ref: mergeRefs(triggerRef, children.ref),
4166
+ onMouseEnter: (e) => {
4167
+ handleMouseEnter();
4168
+ children.props.onMouseEnter?.(e);
4169
+ },
4170
+ onMouseLeave: (e) => {
4171
+ handleMouseLeave();
4172
+ children.props.onMouseLeave?.(e);
4173
+ },
4174
+ onFocus: (e) => {
4175
+ handleFocus();
4176
+ children.props.onFocus?.(e);
4177
+ },
4178
+ onBlur: (e) => {
4179
+ handleBlur();
4180
+ children.props.onBlur?.(e);
4181
+ },
4182
+ "aria-describedby": isVisible ? "tooltip-content" : undefined,
4183
+ });
4184
+ return (jsxs(Fragment, { children: [trigger, jsxs("div", { ref: mergeRefs(tooltipRef, ref), id: "tooltip-content", role: "tooltip", className: cn(tooltipVariants({ isVisible }), className), style: {
4185
+ top: `${position.top}px`,
4186
+ left: `${position.left}px`,
4187
+ }, "aria-hidden": !isVisible, onMouseEnter: handleMouseEnter, onMouseLeave: handleMouseLeave, children: [showArrow && (jsx("div", { className: cn(tooltipArrowVariants({ placement: actualPlacement })), style: {
4188
+ left: `${arrowPosition.left}px`,
4189
+ } })), jsxs("div", { className: "relative flex flex-col gap-2", children: [heading && (jsx(Text, { variant: "body", size: "medium", weight: "semibold", color: "onPrimary", children: heading })), jsx(Text, { variant: "body", size: "small", weight: "regular", color: "onPrimary", children: description })] })] })] }));
4190
+ });
4191
+ Tooltip.displayName = "Tooltip";
4192
+
4193
+ const FormHeader = React.forwardRef(({ label, size = "medium", isOptional = false, isRequired = false, infoHeading, infoDescription, LinkComponent, linkText, linkHref, onLinkClick, linkLeadingIcon, linkTrailingIcon, htmlFor, className, labelClassName, linkClassName, }, ref) => {
4194
+ // Size-based configurations
4195
+ const sizeConfig = {
4196
+ small: {
4197
+ textClassName: "text-body-xsmall-semibold",
4198
+ textClassNameRegular: "text-caption-small-regular",
4199
+ iconSize: 12,
4200
+ gap: "gap-1.5",
4201
+ },
4202
+ medium: {
4203
+ textClassName: "text-body-small-semibold",
4204
+ textClassNameRegular: "text-caption-medium-regular",
4205
+ iconSize: 14,
4206
+ gap: "gap-2",
4207
+ },
4208
+ large: {
4209
+ textClassName: "text-body-medium-semibold",
4210
+ textClassNameRegular: "text-caption-large-regular",
4211
+ iconSize: 16,
4212
+ gap: "gap-2.5",
4213
+ },
4214
+ };
4215
+ const config = sizeConfig[size];
4216
+ return (jsxs("div", { ref: ref, className: cn("flex items-center justify-between px-1", config.gap, className), children: [jsxs("div", { className: cn("flex items-center", config.gap), children: [jsxs("label", { htmlFor: htmlFor, className: cn("flex items-center", labelClassName), children: [jsx("span", { className: cn(config.textClassName, "text-surface-neutral-subtle"), children: label }), isRequired && (jsx("span", { className: cn(config.textClassName, "text-color-negative ml-0.5"), children: "*" })), isOptional && (jsx("span", { className: cn(config.textClassNameRegular, "text-surface-neutral-muted italic ml-1"), children: "(optional)" }))] }), infoDescription && (jsx(Tooltip, { description: infoDescription, heading: infoHeading, children: jsx(Icon, { name: "info", size: config.iconSize }) }))] }), LinkComponent
4217
+ ? LinkComponent
4218
+ : linkText && (jsx(Link, { href: linkHref, onClick: onLinkClick, type: "action", color: "primary", size: size === "large" ? "small" : "xsmall", leadingIcon: linkLeadingIcon, trailingIcon: linkTrailingIcon, children: linkText }))] }));
4219
+ });
4220
+ FormHeader.displayName = "FormHeader";
4221
+
4222
+ const datePickerVariants = cva("relative flex items-center gap-2 border rounded-large transition-all font-display font-size-100 leading-100", {
4223
+ variants: {
4224
+ size: {
4225
+ small: "h-[28px] px-3 text-xs gap-2",
4226
+ medium: "h-[36px] px-4 text-sm gap-2",
4227
+ large: "h-[44px] px-5 text-base gap-3",
4228
+ },
4229
+ validationState: {
4230
+ none: `
4231
+ border-action-outline-neutral-faded
4232
+ hover:border-action-outline-primary-hover
4233
+ focus-within:border-action-outline-primary-hover
4234
+ focus-within:ring-2
4235
+ ring-action-outline-primary-faded-hover`,
4236
+ positive: `
4237
+ border-action-outline-positive-default
4238
+ focus-within:border-action-outline-positive-hover
4239
+ focus-within:ring-2
4240
+ ring-action-outline-positive-faded-hover`,
4241
+ negative: `border-action-outline-negative-default
4242
+ focus-within:border-action-outline-negative-hover
4243
+ focus-within:ring-2
4244
+ ring-action-outline-negative-faded-hover`,
4245
+ },
4246
+ isDisabled: {
4247
+ true: `
4248
+ border-[var(--border-width-thinner)]
4249
+ hover:border-action-outline-neutral-disabled
4250
+ border-action-outline-neutral-disabled
4251
+ bg-surface-fill-neutral-intense cursor-not-allowed opacity-60`,
4252
+ false: "bg-surface-fill-neutral-intense",
4253
+ },
4254
+ },
4255
+ defaultVariants: {
4256
+ size: "medium",
4257
+ validationState: "none",
4258
+ isDisabled: false,
4259
+ },
4260
+ });
4261
+ // Helper functions
4262
+ const parseDate = (date) => {
4263
+ if (!date)
4264
+ return null;
4265
+ if (date instanceof Date)
4266
+ return date;
4267
+ if (typeof date === "string") {
4268
+ const parsed = new Date(date);
4269
+ return isNaN(parsed.getTime()) ? null : parsed;
4270
+ }
4271
+ return null;
4272
+ };
4273
+ const formatDateDefault = (date) => {
4274
+ return date.toLocaleDateString("en-US", {
4275
+ year: "numeric",
4276
+ month: "short",
4277
+ day: "numeric",
4278
+ });
4279
+ };
4280
+ const DatePicker = React.forwardRef(({ className, value: controlledValue, defaultValue, onChange, placeholder = "Select a date", label, helperText, errorText, successText, validationState = "none", isDisabled = false, isRequired = false, isOptional = false, size = "medium", showClearButton = false, onClear, containerClassName, labelClassName, triggerClassName, calendarClassName, minDate, maxDate, formatDate = formatDateDefault, infoHeading, infoDescription, LinkComponent, linkText, linkHref, onLinkClick, ...props }, ref) => {
4281
+ const [uncontrolledValue, setUncontrolledValue] = React.useState(parseDate(defaultValue));
4282
+ const [isOpen, setIsOpen] = React.useState(false);
4283
+ const datePickerRef = React.useRef(null);
4284
+ const calendarRef = React.useRef(null);
4285
+ const [dropdownPlacement, setDropdownPlacement] = React.useState("bottom");
4286
+ const value = controlledValue !== undefined
4287
+ ? parseDate(controlledValue)
4288
+ : uncontrolledValue;
4289
+ const hasValue = value !== null;
4290
+ // Determine which helper text to show
4291
+ const displayHelperText = errorText || successText || helperText;
4292
+ const currentValidationState = errorText
4293
+ ? "negative"
4294
+ : successText
4295
+ ? "positive"
4296
+ : validationState;
4297
+ const handleOpenChange = (newOpen) => {
4298
+ if (!isDisabled) {
4299
+ setIsOpen(newOpen);
4300
+ }
4301
+ };
4302
+ const toggleOpen = () => {
4303
+ handleOpenChange(!isOpen);
4304
+ };
4305
+ const handleCalendarChange = (value, event) => {
4306
+ // react-calendar can return Date, Date[], or null
4307
+ // We only support single date selection, so we take the first date if it's an array
4308
+ if (!value) {
4309
+ if (controlledValue === undefined) {
4310
+ setUncontrolledValue(null);
4311
+ }
4312
+ onChange?.(null);
4313
+ setIsOpen(false);
4314
+ return;
4315
+ }
4316
+ const selectedDate = Array.isArray(value) ? value[0] : value;
4317
+ // Ensure we have a valid Date object
4318
+ if (selectedDate instanceof Date) {
4319
+ if (controlledValue === undefined) {
4320
+ setUncontrolledValue(selectedDate);
4321
+ }
4322
+ onChange?.(selectedDate);
4323
+ setIsOpen(false);
4324
+ }
4325
+ };
4326
+ const handleClear = (e) => {
4327
+ e.stopPropagation();
4328
+ if (onClear) {
4329
+ onClear();
4330
+ }
4331
+ else {
4332
+ if (controlledValue === undefined) {
4333
+ setUncontrolledValue(null);
4334
+ }
4335
+ onChange?.(null);
4336
+ }
4337
+ };
4338
+ const updateDropdownPlacement = React.useCallback(() => {
4339
+ if (typeof window === "undefined")
4340
+ return;
4341
+ const trigger = datePickerRef.current;
4342
+ if (!trigger)
4343
+ return;
4344
+ const triggerRect = trigger.getBoundingClientRect();
4345
+ const spaceBelow = window.innerHeight - triggerRect.bottom;
4346
+ const spaceAbove = triggerRect.top;
4347
+ const calendarHeight = calendarRef.current
4348
+ ? calendarRef.current.offsetHeight
4349
+ : 0;
4350
+ if (calendarHeight === 0) {
4351
+ setDropdownPlacement(spaceBelow >= spaceAbove ? "bottom" : "top");
4352
+ return;
4353
+ }
4354
+ if (spaceBelow >= calendarHeight || spaceBelow >= spaceAbove) {
4355
+ setDropdownPlacement("bottom");
4356
+ }
4357
+ else {
4358
+ setDropdownPlacement("top");
4359
+ }
4360
+ }, []);
4361
+ React.useEffect(() => {
4362
+ if (!isOpen)
4363
+ return;
4364
+ if (typeof window === "undefined")
4365
+ return;
4366
+ let rafId = requestAnimationFrame(updateDropdownPlacement);
4367
+ const handleUpdate = () => updateDropdownPlacement();
4368
+ window.addEventListener("resize", handleUpdate);
4369
+ window.addEventListener("scroll", handleUpdate, true);
4370
+ return () => {
4371
+ cancelAnimationFrame(rafId);
4372
+ window.removeEventListener("resize", handleUpdate);
4373
+ window.removeEventListener("scroll", handleUpdate, true);
4374
+ };
4375
+ }, [isOpen, updateDropdownPlacement]);
4376
+ React.useEffect(() => {
4377
+ if (isOpen) {
4378
+ updateDropdownPlacement();
4379
+ }
4380
+ }, [isOpen, updateDropdownPlacement]);
4381
+ // Close calendar when clicking outside
4382
+ React.useEffect(() => {
4383
+ const handleClickOutside = (event) => {
4384
+ if (datePickerRef.current &&
4385
+ !datePickerRef.current.contains(event.target)) {
4386
+ handleOpenChange(false);
4387
+ }
4388
+ };
4389
+ if (isOpen) {
4390
+ document.addEventListener("mousedown", handleClickOutside);
4391
+ return () => {
4392
+ document.removeEventListener("mousedown", handleClickOutside);
4393
+ };
4394
+ }
4395
+ }, [isOpen]);
4396
+ // Close on escape key
4397
+ React.useEffect(() => {
4398
+ const handleEscape = (event) => {
4399
+ if (event.key === "Escape") {
4400
+ handleOpenChange(false);
4401
+ }
4402
+ };
4403
+ if (isOpen) {
4404
+ document.addEventListener("keydown", handleEscape);
4405
+ return () => {
4406
+ document.removeEventListener("keydown", handleEscape);
4407
+ };
4408
+ }
4409
+ }, [isOpen]);
4410
+ const minDateParsed = parseDate(minDate);
4411
+ const maxDateParsed = parseDate(maxDate);
4412
+ const sizeConfig = {
4413
+ small: {
4414
+ gap: "gap-2",
4415
+ },
4416
+ medium: {
4417
+ gap: "gap-2",
4418
+ },
4419
+ large: {
4420
+ gap: "gap-3",
4421
+ },
4422
+ };
4423
+ return (jsxs("div", { className: cn("w-full flex flex-col", sizeConfig[size].gap, containerClassName), children: [label && (jsx(FormHeader, { label: label, size: size, isRequired: isRequired, isOptional: isOptional, infoHeading: infoHeading, infoDescription: infoDescription, LinkComponent: LinkComponent, linkText: linkText, linkHref: linkHref, onLinkClick: onLinkClick, htmlFor: props.id, className: "mb-2", labelClassName: labelClassName })), jsxs("div", { ref: datePickerRef, className: cn(datePickerVariants({
4424
+ size,
4425
+ validationState: currentValidationState,
4426
+ isDisabled,
4427
+ }), "relative w-full cursor-pointer", className), onClick: !isDisabled ? toggleOpen : undefined, role: "button", "aria-haspopup": "dialog", "aria-expanded": isOpen, "aria-disabled": isDisabled, ...props, children: [jsx(Calendar$1, { className: cn("shrink-0 w-4 h-4", isDisabled
4428
+ ? "text-surface-ink-neutral-disabled"
4429
+ : currentValidationState === "positive"
4430
+ ? "text-feedback-ink-positive-intense"
4431
+ : currentValidationState === "negative"
4432
+ ? "text-feedback-ink-negative-subtle"
4433
+ : "text-surface-ink-neutral-muted") }), jsx("span", { className: cn("flex-1 text-left truncate", !hasValue && "text-surface-ink-neutral-muted", isDisabled && "text-surface-ink-neutral-disabled"), children: hasValue && value ? formatDate(value) : placeholder }), showClearButton && hasValue && !isDisabled && (jsx("button", { type: "button", onClick: handleClear, className: "shrink-0 flex items-center justify-center text-surface-ink-neutral-muted hover:text-surface-ink-neutral-normal transition-colors", tabIndex: -1, children: jsx("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: jsx("path", { d: "M12 4L4 12M4 4L12 12", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round" }) }) })), isOpen && !isDisabled && (jsx("div", { ref: calendarRef, className: cn("absolute z-50 left-0 bg-surface-fill-neutral-intense rounded-large shadow-lg p-4", dropdownPlacement === "bottom"
4434
+ ? "top-full mt-1"
4435
+ : "bottom-full mb-1", calendarClassName), onClick: (e) => e.stopPropagation(), children: jsx("div", { className: "react-calendar-wrapper w-fit", children: jsx(Calendar, { onChange: handleCalendarChange, value: value ?? null, minDate: minDateParsed ?? undefined, maxDate: maxDateParsed ?? undefined, locale: "en-US", formatShortWeekday: (locale, date) => {
4436
+ const weekdayNames = [
4437
+ "Su",
4438
+ "Mo",
4439
+ "Tu",
4440
+ "We",
4441
+ "Th",
4442
+ "Fr",
4443
+ "Sa",
4444
+ ];
4445
+ return weekdayNames[date.getDay()];
4446
+ } }) }) }))] }), jsx(FormFooter, { helperText: displayHelperText, validationState: currentValidationState === "none"
4447
+ ? "default"
4448
+ : currentValidationState, size: size, isDisabled: isDisabled, className: "mt-1" })] }));
4449
+ });
4450
+ DatePicker.displayName = "DatePicker";
1690
4451
 
1691
4452
  const dividerVariants = cva("", {
1692
4453
  variants: {
@@ -1949,263 +4710,6 @@ const Dropdown = React.forwardRef(({ className, trigger, items = [], customConte
1949
4710
  });
1950
4711
  Dropdown.displayName = "Dropdown";
1951
4712
 
1952
- const tooltipVariants = cva("fixed z-50 bg-popup-fill-intense text-action-ink-on-primary-normal rounded-medium border border-popup-outline-subtle flex flex-col p-4 rounded-xlarge min-w-[200px] max-w-[300px] transition-opacity duration-200", {
1953
- variants: {
1954
- isVisible: {
1955
- true: "opacity-100 pointer-events-auto shadow-[0_4px_20px_rgba(0,0,0,0.15)]",
1956
- false: "opacity-0 pointer-events-none",
1957
- },
1958
- },
1959
- defaultVariants: {
1960
- isVisible: false,
1961
- },
1962
- });
1963
- const tooltipArrowVariants = cva("absolute w-0 h-0 border-solid border-[6px] -translate-x-1/2", {
1964
- variants: {
1965
- placement: {
1966
- "top-start": "top-full border-t-popup-fill-intense border-x-transparent border-b-transparent",
1967
- top: "top-full border-t-popup-fill-intense border-x-transparent border-b-transparent",
1968
- "top-end": "top-full border-t-popup-fill-intense border-x-transparent border-b-transparent",
1969
- "bottom-start": "bottom-full border-b-popup-fill-intense border-x-transparent border-t-transparent",
1970
- bottom: "bottom-full border-b-popup-fill-intense border-x-transparent border-t-transparent",
1971
- "bottom-end": "bottom-full border-b-popup-fill-intense border-x-transparent border-t-transparent",
1972
- },
1973
- },
1974
- defaultVariants: {
1975
- placement: "top",
1976
- },
1977
- });
1978
- const Tooltip = React.forwardRef(({ children, heading, description, placement = "top", showArrow = true, className, delay = 200, disabled = false, }, ref) => {
1979
- const [isVisible, setIsVisible] = React.useState(false);
1980
- const [position, setPosition] = React.useState({ top: 0, left: 0 });
1981
- const [arrowPosition, setArrowPosition] = React.useState({ left: 0 });
1982
- const [actualPlacement, setActualPlacement] = React.useState(placement);
1983
- const timeoutRef = React.useRef(null);
1984
- const triggerRef = React.useRef(null);
1985
- const tooltipRef = React.useRef(null);
1986
- const calculatePosition = React.useCallback(() => {
1987
- if (!triggerRef.current || !tooltipRef.current)
1988
- return;
1989
- const triggerRect = triggerRef.current.getBoundingClientRect();
1990
- const tooltipRect = tooltipRef.current.getBoundingClientRect();
1991
- const gap = 8; // 8px gap between trigger and tooltip
1992
- const arrowSize = 6; // Size of the arrow
1993
- const viewportPadding = 8; // Minimum padding from viewport edges
1994
- let top = 0;
1995
- let left = 0;
1996
- let currentPlacement = placement;
1997
- // Calculate initial position based on placement
1998
- switch (placement) {
1999
- case "top-start":
2000
- top = triggerRect.top - tooltipRect.height - gap - arrowSize;
2001
- left = triggerRect.left;
2002
- break;
2003
- case "top":
2004
- top = triggerRect.top - tooltipRect.height - gap - arrowSize;
2005
- left =
2006
- triggerRect.left + triggerRect.width / 2 - tooltipRect.width / 2;
2007
- break;
2008
- case "top-end":
2009
- top = triggerRect.top - tooltipRect.height - gap - arrowSize;
2010
- left = triggerRect.right - tooltipRect.width;
2011
- break;
2012
- case "bottom-start":
2013
- top = triggerRect.bottom + gap + arrowSize;
2014
- left = triggerRect.left;
2015
- break;
2016
- case "bottom":
2017
- top = triggerRect.bottom + gap + arrowSize;
2018
- left =
2019
- triggerRect.left + triggerRect.width / 2 - tooltipRect.width / 2;
2020
- break;
2021
- case "bottom-end":
2022
- top = triggerRect.bottom + gap + arrowSize;
2023
- left = triggerRect.right - tooltipRect.width;
2024
- break;
2025
- }
2026
- // Get viewport dimensions
2027
- const viewportWidth = window.innerWidth;
2028
- const viewportHeight = window.innerHeight;
2029
- // Adjust horizontal position to keep tooltip within viewport
2030
- if (left < viewportPadding) {
2031
- // Tooltip would overflow on the left
2032
- left = viewportPadding;
2033
- }
2034
- else if (left + tooltipRect.width > viewportWidth - viewportPadding) {
2035
- // Tooltip would overflow on the right
2036
- left = viewportWidth - tooltipRect.width - viewportPadding;
2037
- }
2038
- // Adjust vertical position to keep tooltip within viewport
2039
- if (top < viewportPadding) {
2040
- // Tooltip would overflow at the top
2041
- // Try to flip to bottom if there's more space there
2042
- const spaceBelow = viewportHeight - triggerRect.bottom;
2043
- const spaceAbove = triggerRect.top;
2044
- if (spaceBelow > spaceAbove) {
2045
- // Flip to bottom
2046
- top = triggerRect.bottom + gap + arrowSize;
2047
- // Update placement to reflect the flip
2048
- if (placement === "top-start")
2049
- currentPlacement = "bottom-start";
2050
- else if (placement === "top")
2051
- currentPlacement = "bottom";
2052
- else if (placement === "top-end")
2053
- currentPlacement = "bottom-end";
2054
- }
2055
- else {
2056
- // Keep at top but adjust to stay in viewport
2057
- top = viewportPadding;
2058
- }
2059
- }
2060
- else if (top + tooltipRect.height > viewportHeight - viewportPadding) {
2061
- // Tooltip would overflow at the bottom
2062
- // Try to flip to top if there's more space there
2063
- const spaceAbove = triggerRect.top;
2064
- const spaceBelow = viewportHeight - triggerRect.bottom;
2065
- if (spaceAbove > spaceBelow) {
2066
- // Flip to top
2067
- top = triggerRect.top - tooltipRect.height - gap - arrowSize;
2068
- // Update placement to reflect the flip
2069
- if (placement === "bottom-start")
2070
- currentPlacement = "top-start";
2071
- else if (placement === "bottom")
2072
- currentPlacement = "top";
2073
- else if (placement === "bottom-end")
2074
- currentPlacement = "top-end";
2075
- }
2076
- else {
2077
- // Keep at bottom but adjust to stay in viewport
2078
- top = viewportHeight - tooltipRect.height - viewportPadding;
2079
- }
2080
- }
2081
- // Calculate arrow position relative to trigger
2082
- // The arrow should point to the center of the trigger element
2083
- const triggerCenterX = triggerRect.left + triggerRect.width / 2;
2084
- const tooltipLeft = left;
2085
- const arrowLeft = triggerCenterX - tooltipLeft;
2086
- // Clamp arrow position to stay within tooltip bounds (with padding)
2087
- const arrowPadding = 16; // Minimum distance from tooltip edges
2088
- const clampedArrowLeft = Math.max(arrowPadding, Math.min(arrowLeft, tooltipRect.width - arrowPadding));
2089
- setPosition({ top, left });
2090
- setArrowPosition({ left: clampedArrowLeft });
2091
- setActualPlacement(currentPlacement);
2092
- }, [placement]);
2093
- const handleMouseEnter = () => {
2094
- if (disabled)
2095
- return;
2096
- if (timeoutRef.current) {
2097
- clearTimeout(timeoutRef.current);
2098
- }
2099
- timeoutRef.current = setTimeout(() => {
2100
- setIsVisible(true);
2101
- }, delay);
2102
- };
2103
- const handleMouseLeave = () => {
2104
- if (timeoutRef.current) {
2105
- clearTimeout(timeoutRef.current);
2106
- }
2107
- setIsVisible(false);
2108
- };
2109
- const handleFocus = () => {
2110
- if (disabled)
2111
- return;
2112
- setIsVisible(true);
2113
- };
2114
- const handleBlur = () => {
2115
- setIsVisible(false);
2116
- };
2117
- React.useEffect(() => {
2118
- if (isVisible) {
2119
- calculatePosition();
2120
- window.addEventListener("scroll", calculatePosition, true);
2121
- window.addEventListener("resize", calculatePosition);
2122
- }
2123
- return () => {
2124
- window.removeEventListener("scroll", calculatePosition, true);
2125
- window.removeEventListener("resize", calculatePosition);
2126
- };
2127
- }, [isVisible, calculatePosition]);
2128
- React.useEffect(() => {
2129
- // Reset actualPlacement when placement prop changes
2130
- setActualPlacement(placement);
2131
- }, [placement]);
2132
- React.useEffect(() => {
2133
- return () => {
2134
- if (timeoutRef.current) {
2135
- clearTimeout(timeoutRef.current);
2136
- }
2137
- };
2138
- }, []);
2139
- // Merge refs function
2140
- const mergeRefs = (...refs) => {
2141
- return (node) => {
2142
- refs.forEach((ref) => {
2143
- if (typeof ref === "function") {
2144
- ref(node);
2145
- }
2146
- else if (ref && typeof ref === "object" && "current" in ref) {
2147
- ref.current = node;
2148
- }
2149
- });
2150
- };
2151
- };
2152
- // Clone the child element and add event handlers
2153
- const trigger = React.cloneElement(children, {
2154
- ref: mergeRefs(triggerRef, children.ref),
2155
- onMouseEnter: (e) => {
2156
- handleMouseEnter();
2157
- children.props.onMouseEnter?.(e);
2158
- },
2159
- onMouseLeave: (e) => {
2160
- handleMouseLeave();
2161
- children.props.onMouseLeave?.(e);
2162
- },
2163
- onFocus: (e) => {
2164
- handleFocus();
2165
- children.props.onFocus?.(e);
2166
- },
2167
- onBlur: (e) => {
2168
- handleBlur();
2169
- children.props.onBlur?.(e);
2170
- },
2171
- "aria-describedby": isVisible ? "tooltip-content" : undefined,
2172
- });
2173
- return (jsxs(Fragment, { children: [trigger, jsxs("div", { ref: mergeRefs(tooltipRef, ref), id: "tooltip-content", role: "tooltip", className: cn(tooltipVariants({ isVisible }), className), style: {
2174
- top: `${position.top}px`,
2175
- left: `${position.left}px`,
2176
- }, "aria-hidden": !isVisible, onMouseEnter: handleMouseEnter, onMouseLeave: handleMouseLeave, children: [showArrow && (jsx("div", { className: cn(tooltipArrowVariants({ placement: actualPlacement })), style: {
2177
- left: `${arrowPosition.left}px`,
2178
- } })), jsxs("div", { className: "relative flex flex-col gap-2", children: [heading && (jsx(Text, { variant: "body", size: "medium", weight: "semibold", color: "onPrimary", children: heading })), jsx(Text, { variant: "body", size: "small", weight: "regular", color: "onPrimary", children: description })] })] })] }));
2179
- });
2180
- Tooltip.displayName = "Tooltip";
2181
-
2182
- const FormHeader = React.forwardRef(({ label, size = "medium", isOptional = false, isRequired = false, infoHeading, infoDescription, linkText, linkHref, onLinkClick, linkLeadingIcon, linkTrailingIcon, htmlFor, className, labelClassName, linkClassName, }, ref) => {
2183
- // Size-based configurations
2184
- const sizeConfig = {
2185
- small: {
2186
- textClassName: "text-body-xsmall-semibold",
2187
- textClassNameRegular: "text-caption-small-regular",
2188
- iconSize: 12,
2189
- gap: "gap-1.5",
2190
- },
2191
- medium: {
2192
- textClassName: "text-body-small-semibold",
2193
- textClassNameRegular: "text-caption-medium-regular",
2194
- iconSize: 14,
2195
- gap: "gap-2",
2196
- },
2197
- large: {
2198
- textClassName: "text-body-medium-semibold",
2199
- textClassNameRegular: "text-caption-large-regular",
2200
- iconSize: 16,
2201
- gap: "gap-2.5",
2202
- },
2203
- };
2204
- const config = sizeConfig[size];
2205
- return (jsxs("div", { ref: ref, className: cn("flex items-center justify-between px-1", config.gap, className), children: [jsxs("div", { className: cn("flex items-center", config.gap), children: [jsxs("label", { htmlFor: htmlFor, className: cn("flex items-center", labelClassName), children: [jsx("span", { className: cn(config.textClassName, "text-surface-neutral-subtle"), children: label }), isRequired && (jsx("span", { className: cn(config.textClassName, "text-color-negative ml-0.5"), children: "*" })), isOptional && (jsx("span", { className: cn(config.textClassNameRegular, "text-surface-neutral-muted italic ml-1"), children: "(optional)" }))] }), infoDescription && (jsx(Tooltip, { description: infoDescription, heading: infoHeading, children: jsx(Icon, { name: "info", size: config.iconSize }) }))] }), linkText && (jsx(Link, { href: linkHref, onClick: onLinkClick, type: "action", color: "primary", size: size === "large" ? "small" : "xsmall", leadingIcon: linkLeadingIcon, trailingIcon: linkTrailingIcon, children: linkText }))] }));
2206
- });
2207
- FormHeader.displayName = "FormHeader";
2208
-
2209
4713
  const Modal = React.forwardRef(({ isOpen, onClose, title, description, footer, children, size = "medium", showCloseButton = true, closeOnOverlayClick = true, closeOnEscape = true, className, contentClassName, headerClassName, bodyClassName, footerClassName, overlayClassName, ariaLabel, ariaDescribedBy, }, ref) => {
2210
4714
  const modalRef = React.useRef(null);
2211
4715
  const contentRef = ref || modalRef;
@@ -2293,7 +4797,7 @@ const selectVariants = cva("relative flex items-center gap-2 border rounded-larg
2293
4797
  isDisabled: false,
2294
4798
  },
2295
4799
  });
2296
- const Select = React.forwardRef(({ className, options = [], value: controlledValue, defaultValue, onChange, placeholder = "Select an option", label, helperText, errorText, successText, validationState = "none", isDisabled = false, isRequired = false, isOptional = false, isLoading = false, size = "medium", prefix, suffix, showClearButton = false, onClear, containerClassName, labelClassName, triggerClassName, menuClassName, menuWidth = "full", sectionHeading, emptyTitle = "No options available", emptyDescription = "There are no options to select from.", emptyIcon, infoHeading, infoDescription, linkText, linkHref, onLinkClick, ...props }, ref) => {
4800
+ const Select = React.forwardRef(({ className, options = [], value: controlledValue, defaultValue, onChange, placeholder = "Select an option", label, helperText, errorText, successText, validationState = "none", isDisabled = false, isRequired = false, isOptional = false, isLoading = false, size = "medium", prefix, suffix, showClearButton = false, onClear, containerClassName, labelClassName, triggerClassName, menuClassName, menuWidth = "full", sectionHeading, emptyTitle = "No options available", emptyDescription = "There are no options to select from.", emptyIcon, infoHeading, infoDescription, LinkComponent, linkText, linkHref, onLinkClick, ...props }, ref) => {
2297
4801
  const [uncontrolledValue, setUncontrolledValue] = React.useState(defaultValue);
2298
4802
  const [isOpen, setIsOpen] = React.useState(false);
2299
4803
  const [dropdownPlacement, setDropdownPlacement] = React.useState("bottom");
@@ -2468,7 +4972,7 @@ const Select = React.forwardRef(({ className, options = [], value: controlledVal
2468
4972
  gap: "gap-3",
2469
4973
  },
2470
4974
  };
2471
- return (jsxs("div", { className: cn("w-full flex flex-col", sizeConfig[size].gap, containerClassName), children: [label && (jsx(FormHeader, { label: label, size: size, isRequired: isRequired, isOptional: isOptional, infoHeading: infoHeading, infoDescription: infoDescription, linkText: linkText, linkHref: linkHref, onLinkClick: onLinkClick, htmlFor: props.id, className: "mb-2", labelClassName: labelClassName })), jsxs("div", { ref: selectRef, className: cn(selectVariants({
4975
+ return (jsxs("div", { className: cn("w-full flex flex-col", sizeConfig[size].gap, containerClassName), children: [label && (jsx(FormHeader, { label: label, size: size, isRequired: isRequired, isOptional: isOptional, infoHeading: infoHeading, infoDescription: infoDescription, LinkComponent: LinkComponent, linkText: linkText, linkHref: linkHref, onLinkClick: onLinkClick, htmlFor: props.id, className: "mb-2", labelClassName: labelClassName })), jsxs("div", { ref: selectRef, className: cn(selectVariants({
2472
4976
  size,
2473
4977
  validationState: currentValidationState,
2474
4978
  isDisabled,
@@ -2827,7 +5331,7 @@ const textFieldVariants = cva("relative flex items-center gap-2 border rounded-l
2827
5331
  isDisabled: false,
2828
5332
  },
2829
5333
  });
2830
- const TextField = React.forwardRef(({ label, helperText, errorText, successText, size = "medium", validationState = "none", isDisabled = false, isRequired = false, isOptional = false, prefix, suffix, showClearButton = false, infoDescription, infoHeading, linkText, linkHref, onLinkClick, onClear, containerClassName, labelClassName, inputClassName, className, value, onChange, ...props }, ref) => {
5334
+ const TextField = React.forwardRef(({ label, helperText, errorText, successText, size = "medium", validationState = "none", isDisabled = false, isRequired = false, isOptional = false, prefix, suffix, showClearButton = false, infoDescription, infoHeading, LinkComponent, linkText, linkHref, onLinkClick, onClear, containerClassName, labelClassName, inputClassName, className, value, onChange, ...props }, ref) => {
2831
5335
  const [internalValue, setInternalValue] = React.useState("");
2832
5336
  const inputValue = value !== undefined ? value : internalValue;
2833
5337
  const hasValue = inputValue && String(inputValue).length > 0;
@@ -2870,7 +5374,7 @@ const TextField = React.forwardRef(({ label, helperText, errorText, successText,
2870
5374
  gap: "gap-3",
2871
5375
  },
2872
5376
  };
2873
- return (jsxs("div", { className: cn("w-full flex flex-col", sizeConfig[size].gap, containerClassName), children: [label && (jsx(FormHeader, { label: label, size: size, isRequired: isRequired, isOptional: isOptional, infoHeading: infoHeading, infoDescription: infoDescription, linkText: linkText, linkHref: linkHref, onLinkClick: onLinkClick, htmlFor: props.id, className: "mb-2", labelClassName: labelClassName })), jsxs("div", { className: cn(textFieldVariants({
5377
+ return (jsxs("div", { className: cn("w-full flex flex-col", sizeConfig[size].gap, containerClassName), children: [label && (jsx(FormHeader, { label: label, size: size, isRequired: isRequired, isOptional: isOptional, infoHeading: infoHeading, infoDescription: infoDescription, LinkComponent: LinkComponent, linkText: linkText, linkHref: linkHref, onLinkClick: onLinkClick, htmlFor: props.id, className: "mb-2", labelClassName: labelClassName })), jsxs("div", { className: cn(textFieldVariants({
2874
5378
  size,
2875
5379
  validationState: currentValidationState,
2876
5380
  isDisabled,
@@ -3659,7 +6163,7 @@ const textAreaVariants = cva("relative flex flex-col border rounded-large transi
3659
6163
  isDisabled: false,
3660
6164
  },
3661
6165
  });
3662
- const TextArea = React.forwardRef(({ label, helperText, errorText, successText, size = "medium", validationState = "none", isDisabled = false, isRequired = false, isOptional = false, maxChar, showCharCount = true, infoDescription, infoHeading, linkText, linkHref, onLinkClick, containerClassName, labelClassName, textAreaClassName, className, value, onChange, rows = 4, ...props }, ref) => {
6166
+ const TextArea = React.forwardRef(({ label, helperText, errorText, successText, size = "medium", validationState = "none", isDisabled = false, isRequired = false, isOptional = false, maxChar, showCharCount = true, infoDescription, infoHeading, LinkComponent, linkText, linkHref, onLinkClick, containerClassName, labelClassName, textAreaClassName, className, value, onChange, rows = 4, ...props }, ref) => {
3663
6167
  const [internalValue, setInternalValue] = React.useState("");
3664
6168
  const textAreaValue = value !== undefined ? value : internalValue;
3665
6169
  const currentLength = String(textAreaValue).length;
@@ -3697,7 +6201,7 @@ const TextArea = React.forwardRef(({ label, helperText, errorText, successText,
3697
6201
  gap: "gap-3",
3698
6202
  },
3699
6203
  };
3700
- return (jsxs("div", { className: cn("w-full flex flex-col", sizeConfig[size].gap, containerClassName), children: [label && (jsx(FormHeader, { label: label, size: size, isRequired: isRequired, isOptional: isOptional, infoHeading: infoHeading, infoDescription: infoDescription, linkText: linkText, linkHref: linkHref, onLinkClick: onLinkClick, htmlFor: props.id, className: "mb-2", labelClassName: labelClassName })), jsx("div", { className: cn(textAreaVariants({
6204
+ return (jsxs("div", { className: cn("w-full flex flex-col", sizeConfig[size].gap, containerClassName), children: [label && (jsx(FormHeader, { label: label, size: size, isRequired: isRequired, isOptional: isOptional, infoHeading: infoHeading, infoDescription: infoDescription, LinkComponent: LinkComponent, linkText: linkText, linkHref: linkHref, onLinkClick: onLinkClick, htmlFor: props.id, className: "mb-2", labelClassName: labelClassName })), jsx("div", { className: cn(textAreaVariants({
3701
6205
  size,
3702
6206
  validationState: currentValidationState,
3703
6207
  isDisabled,
@@ -3711,5 +6215,5 @@ const TextArea = React.forwardRef(({ label, helperText, errorText, successText,
3711
6215
  });
3712
6216
  TextArea.displayName = "TextArea";
3713
6217
 
3714
- export { Alert, Avatar, AvatarCell, Badge, Button, ButtonGroup, Checkbox, Counter, Divider, Dropdown, DropdownMenu, FormFooter, FormHeader, Icon, IconButton, IconCell, Link, ListItem, Modal, NumberCell, Pagination, Radio, SearchableDropdown, Select, Skeleton, SlotCell, SpacerCell, Switch, TabItem, Table, TableDetailPanel, Tabs, Text, TextArea, TextField, Tooltip, alertVariants, avatarVariants, badgeVariants, buttonGroupVariants, buttonVariants, checkboxVariants, cn, counterVariants, dropdownVariants, getAvailableIcons, hasIcon, iconButtonVariants, iconRegistry, linkVariants, listItemVariants, paginationVariants, radioVariants, selectVariants, switchVariants, tableCellVariants, tableHeaderVariants, tableVariants, textAreaVariants, textFieldVariants, tooltipVariants };
6218
+ export { Alert, Avatar, AvatarCell, Badge, Button, ButtonGroup, Checkbox, Counter, DatePicker, Divider, Dropdown, DropdownMenu, FormFooter, FormHeader, Icon, IconButton, IconCell, Link, ListItem, Modal, NumberCell, Pagination, Radio, SearchableDropdown, Select, Skeleton, SlotCell, SpacerCell, Switch, TabItem, Table, TableDetailPanel, Tabs, Text, TextArea, TextField, Tooltip, alertVariants, avatarVariants, badgeVariants, buttonGroupVariants, buttonVariants, checkboxVariants, cn, counterVariants, datePickerVariants, dropdownVariants, getAvailableIcons, hasIcon, iconButtonVariants, iconRegistry, linkVariants, listItemVariants, paginationVariants, radioVariants, selectVariants, switchVariants, tableCellVariants, tableHeaderVariants, tableVariants, textAreaVariants, textFieldVariants, tooltipVariants };
3715
6219
  //# sourceMappingURL=index.esm.js.map