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