@trackunit/react-components 0.0.146 → 0.0.147
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/components/DateInput/DateInput.d.ts +9 -10
- package/index.js +94 -149
- package/package.json +2 -2
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { Matcher } from "react-day-picker";
|
|
3
2
|
import { BaseInputProps } from "../BaseInput";
|
|
4
|
-
declare type BaseInputExposedProps = Omit<BaseInputProps, "defaultValue" | "
|
|
3
|
+
declare type BaseInputExposedProps = Omit<BaseInputProps, "defaultValue" | "min" | "max" | "value">;
|
|
5
4
|
export interface DateInputProps extends BaseInputExposedProps {
|
|
6
5
|
/**
|
|
7
|
-
* A
|
|
6
|
+
* A min value in type Date
|
|
8
7
|
*/
|
|
9
|
-
|
|
8
|
+
min?: Date;
|
|
10
9
|
/**
|
|
11
|
-
*
|
|
10
|
+
* A max date value in type Date
|
|
12
11
|
*/
|
|
13
|
-
|
|
12
|
+
max?: Date;
|
|
14
13
|
/**
|
|
15
|
-
* A
|
|
14
|
+
* A default value in type Date
|
|
16
15
|
*/
|
|
17
|
-
|
|
16
|
+
defaultValue?: Date;
|
|
18
17
|
/**
|
|
19
|
-
*
|
|
18
|
+
* A value in type Date
|
|
20
19
|
*/
|
|
21
|
-
|
|
20
|
+
value?: Date;
|
|
22
21
|
}
|
|
23
22
|
/**
|
|
24
23
|
* A wrapper around BaseInput with a pop-up day picker.
|
package/index.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import { tw, tws, twx } from '@trackunit/tailwind-styled-components';
|
|
3
3
|
import * as React from 'react';
|
|
4
|
-
import React__default, { useState, forwardRef,
|
|
4
|
+
import React__default, { useState, forwardRef, useRef, Fragment as Fragment$1, useCallback, createElement, useEffect, useContext, memo } from 'react';
|
|
5
5
|
import { HeroIconsArray, heroIconLookup, TrackunitSolidIconsArray, TrackunitOutlineIconsArray, trackunitIconLookup } from '@trackunit/ui-icons';
|
|
6
6
|
import EChart from 'echarts-for-react';
|
|
7
7
|
import { v4 } from 'uuid';
|
|
8
8
|
import { useMeasure, useCopyToClipboard, useKeyPressEvent } from 'react-use';
|
|
9
|
-
import {
|
|
10
|
-
import { enGB, enUS, da, de, cs, nl, fr, fi, hu, it, nb, pl, pt, ru, ro, es, sv, ja, th } from 'date-fns/locale';
|
|
9
|
+
import { format, formatDistance } from 'date-fns';
|
|
11
10
|
import { useSpring, animated } from '@react-spring/web';
|
|
12
11
|
import usePortal from 'react-useportal';
|
|
13
12
|
import { createPopper } from '@popperjs/core';
|
|
13
|
+
import { DayPicker as DayPicker$1 } from 'react-day-picker';
|
|
14
|
+
import { enGB, enUS, da, de, cs, nl, fr, fi, hu, it, nb, pl, pt, ru, ro, es, sv, ja, th } from 'date-fns/locale';
|
|
14
15
|
import { Helmet } from 'react-helmet';
|
|
15
16
|
import { UNSAFE_NavigationContext } from 'react-router-dom';
|
|
16
17
|
import ReactSelect, { components } from 'react-select';
|
|
@@ -18,7 +19,6 @@ export { default as ValueType } from 'react-select';
|
|
|
18
19
|
import ReactAsyncCreatableSelect from 'react-select/async-creatable';
|
|
19
20
|
import ReactCreatableSelect from 'react-select/creatable';
|
|
20
21
|
import ReactAsyncSelect from 'react-select/async';
|
|
21
|
-
import { format, formatDistance } from 'date-fns';
|
|
22
22
|
import { getColorValue } from '@trackunit/ui-design-tokens';
|
|
23
23
|
|
|
24
24
|
const docs = {
|
|
@@ -1833,64 +1833,45 @@ const StyledCopyableText = tw.span`
|
|
|
1833
1833
|
tu-copyable-text
|
|
1834
1834
|
${p => p.$animating ? tws`tu-copyable-text--animating` : null}`;
|
|
1835
1835
|
|
|
1836
|
-
const localeLookup = {
|
|
1837
|
-
en: enGB,
|
|
1838
|
-
"en-US": enUS,
|
|
1839
|
-
"en-GB": enGB,
|
|
1840
|
-
da,
|
|
1841
|
-
de,
|
|
1842
|
-
cs,
|
|
1843
|
-
nl,
|
|
1844
|
-
fr,
|
|
1845
|
-
fi,
|
|
1846
|
-
hu,
|
|
1847
|
-
it,
|
|
1848
|
-
nb,
|
|
1849
|
-
pl,
|
|
1850
|
-
pt,
|
|
1851
|
-
ru,
|
|
1852
|
-
ro,
|
|
1853
|
-
es,
|
|
1854
|
-
sv,
|
|
1855
|
-
ja,
|
|
1856
|
-
th
|
|
1857
|
-
};
|
|
1858
|
-
/**
|
|
1859
|
-
* A helper function to get the matching Locale object for a given language.
|
|
1860
|
-
*
|
|
1861
|
-
* @param {string} language The language to match
|
|
1862
|
-
* @returns {Locale} The corresponding Locale object
|
|
1863
|
-
*/
|
|
1864
|
-
|
|
1865
|
-
const useLocale = language => {
|
|
1866
|
-
return localeLookup[language] || localeLookup.en;
|
|
1867
|
-
};
|
|
1868
|
-
|
|
1869
1836
|
/**
|
|
1870
|
-
*
|
|
1837
|
+
* A wrapper around BaseInput with a pop-up day picker.
|
|
1871
1838
|
*
|
|
1872
|
-
*
|
|
1873
|
-
* @returns {JSX.Element} DayPicker component
|
|
1839
|
+
* NOTE: If shown with a label, please use the `DateField` component instead.
|
|
1874
1840
|
*/
|
|
1875
1841
|
|
|
1876
|
-
const
|
|
1842
|
+
const DateInput = forwardRef((_a, ref) => {
|
|
1877
1843
|
var {
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1844
|
+
min,
|
|
1845
|
+
max,
|
|
1846
|
+
defaultValue,
|
|
1847
|
+
value
|
|
1882
1848
|
} = _a,
|
|
1883
|
-
rest = __rest(_a, ["
|
|
1849
|
+
rest = __rest(_a, ["min", "max", "defaultValue", "value"]);
|
|
1884
1850
|
|
|
1885
|
-
const
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1851
|
+
const formatDateToInputString = date => date ? format(date, "yyyy-MM-dd") : date; // @ts-ignore
|
|
1852
|
+
// Chrome needs it's default icon to have datepicker functionality.
|
|
1853
|
+
// window.chrome doesn't exist in TS but is available on chrome browsers.
|
|
1854
|
+
// If it fails it will just show our icon.
|
|
1855
|
+
|
|
1856
|
+
|
|
1857
|
+
const hideOnChrome = () => window.chrome !== null && typeof window.chrome !== "undefined" ? "hidden" : "";
|
|
1858
|
+
|
|
1859
|
+
return jsx(BaseInput, Object.assign({
|
|
1860
|
+
type: "date",
|
|
1861
|
+
value: formatDateToInputString(value),
|
|
1862
|
+
defaultValue: formatDateToInputString(defaultValue),
|
|
1863
|
+
min: formatDateToInputString(min),
|
|
1864
|
+
max: formatDateToInputString(max),
|
|
1865
|
+
ref: ref,
|
|
1866
|
+
suffix: jsx(Icon$1, {
|
|
1867
|
+
dataTestId: "calendar",
|
|
1868
|
+
name: "CalendarIcon",
|
|
1869
|
+
size: "medium",
|
|
1870
|
+
type: "solid",
|
|
1871
|
+
className: hideOnChrome()
|
|
1872
|
+
})
|
|
1892
1873
|
}, rest));
|
|
1893
|
-
};
|
|
1874
|
+
});
|
|
1894
1875
|
|
|
1895
1876
|
var PopoverLifecycle;
|
|
1896
1877
|
|
|
@@ -2096,101 +2077,6 @@ const StyledCardBody = twx(CardBody)`
|
|
|
2096
2077
|
tu-popover-list-body
|
|
2097
2078
|
`;
|
|
2098
2079
|
|
|
2099
|
-
/**
|
|
2100
|
-
* A wrapper around BaseInput with a pop-up day picker.
|
|
2101
|
-
*
|
|
2102
|
-
* NOTE: If shown with a label, please use the `DateField` component instead.
|
|
2103
|
-
*/
|
|
2104
|
-
|
|
2105
|
-
const DateInput = forwardRef((_a, ref) => {
|
|
2106
|
-
var {
|
|
2107
|
-
defaultValue,
|
|
2108
|
-
disabledDays,
|
|
2109
|
-
disabled,
|
|
2110
|
-
preventDeselect,
|
|
2111
|
-
onChange
|
|
2112
|
-
} = _a,
|
|
2113
|
-
rest = __rest(_a, ["defaultValue", "disabledDays", "disabled", "preventDeselect", "onChange"]);
|
|
2114
|
-
|
|
2115
|
-
const [selectedDay, setSelectedDay] = useState(defaultValue);
|
|
2116
|
-
const onChangeHandler = useCallback(value => {
|
|
2117
|
-
const newValue = (value === null || value === void 0 ? void 0 : value.toLocaleDateString()) === (selectedDay === null || selectedDay === void 0 ? void 0 : selectedDay.toLocaleDateString()) && !preventDeselect ? undefined : value;
|
|
2118
|
-
setSelectedDay(newValue);
|
|
2119
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
|
|
2120
|
-
}, [selectedDay, preventDeselect, onChange]);
|
|
2121
|
-
const target = useRef(null);
|
|
2122
|
-
const popover = useRef(null);
|
|
2123
|
-
const {
|
|
2124
|
-
popoverRef,
|
|
2125
|
-
targetRef,
|
|
2126
|
-
onShow,
|
|
2127
|
-
onHide,
|
|
2128
|
-
popoverProps
|
|
2129
|
-
} = usePopover({
|
|
2130
|
-
targetRef: target,
|
|
2131
|
-
popoverRef: popover,
|
|
2132
|
-
placement: "bottom"
|
|
2133
|
-
});
|
|
2134
|
-
return jsxs(Fragment, {
|
|
2135
|
-
children: [jsx(BaseInput, Object.assign({
|
|
2136
|
-
ref: ref,
|
|
2137
|
-
value: (selectedDay === null || selectedDay === void 0 ? void 0 : selectedDay.toLocaleDateString()) || "",
|
|
2138
|
-
onChange: () => {}
|
|
2139
|
-
}, rest, {
|
|
2140
|
-
dataTestId: "dateInput",
|
|
2141
|
-
onFocus: () => {
|
|
2142
|
-
onShow();
|
|
2143
|
-
},
|
|
2144
|
-
nonInteractive: true,
|
|
2145
|
-
suffix: jsx(Icon$1, {
|
|
2146
|
-
dataTestId: "calendar",
|
|
2147
|
-
name: "CalendarIcon",
|
|
2148
|
-
size: "medium",
|
|
2149
|
-
type: "solid",
|
|
2150
|
-
onClick: !disabled ? onShow : undefined,
|
|
2151
|
-
forwardedRef: targetRef
|
|
2152
|
-
}),
|
|
2153
|
-
actions: selectedDay && jsx(RemoveValueContainer, {
|
|
2154
|
-
children: jsx(Button, Object.assign({
|
|
2155
|
-
color: "tertiary",
|
|
2156
|
-
onClick: e => {
|
|
2157
|
-
e.preventDefault();
|
|
2158
|
-
setSelectedDay(undefined);
|
|
2159
|
-
}
|
|
2160
|
-
}, {
|
|
2161
|
-
children: jsx(Icon$1, {
|
|
2162
|
-
name: "XIcon",
|
|
2163
|
-
size: "small"
|
|
2164
|
-
})
|
|
2165
|
-
}))
|
|
2166
|
-
}),
|
|
2167
|
-
onClick: e => e.preventDefault()
|
|
2168
|
-
})), jsx(AnimatedPopover, Object.assign({
|
|
2169
|
-
ref: popoverRef,
|
|
2170
|
-
onRequestClose: () => {
|
|
2171
|
-
var _a;
|
|
2172
|
-
|
|
2173
|
-
onHide();
|
|
2174
|
-
(_a = targetRef === null || targetRef === void 0 ? void 0 : targetRef.current) === null || _a === void 0 ? void 0 : _a.blur();
|
|
2175
|
-
}
|
|
2176
|
-
}, popoverProps, {
|
|
2177
|
-
children: jsx(PopoverList, Object.assign({
|
|
2178
|
-
dataTestId: "datePickerPopover"
|
|
2179
|
-
}, {
|
|
2180
|
-
children: jsx(DayPicker, {
|
|
2181
|
-
onDaySelect: onChangeHandler,
|
|
2182
|
-
disabledDays: disabledDays,
|
|
2183
|
-
selectedDays: selectedDay,
|
|
2184
|
-
language: navigator.language
|
|
2185
|
-
})
|
|
2186
|
-
}))
|
|
2187
|
-
}))]
|
|
2188
|
-
});
|
|
2189
|
-
});
|
|
2190
|
-
const RemoveValueContainer = tw.div`
|
|
2191
|
-
tu-date__remove
|
|
2192
|
-
`;
|
|
2193
|
-
|
|
2194
2080
|
/**
|
|
2195
2081
|
* The PopoverListItem component.
|
|
2196
2082
|
*
|
|
@@ -2516,6 +2402,65 @@ const DateField = forwardRef((_a, ref) => {
|
|
|
2516
2402
|
}));
|
|
2517
2403
|
});
|
|
2518
2404
|
|
|
2405
|
+
const localeLookup = {
|
|
2406
|
+
en: enGB,
|
|
2407
|
+
"en-US": enUS,
|
|
2408
|
+
"en-GB": enGB,
|
|
2409
|
+
da,
|
|
2410
|
+
de,
|
|
2411
|
+
cs,
|
|
2412
|
+
nl,
|
|
2413
|
+
fr,
|
|
2414
|
+
fi,
|
|
2415
|
+
hu,
|
|
2416
|
+
it,
|
|
2417
|
+
nb,
|
|
2418
|
+
pl,
|
|
2419
|
+
pt,
|
|
2420
|
+
ru,
|
|
2421
|
+
ro,
|
|
2422
|
+
es,
|
|
2423
|
+
sv,
|
|
2424
|
+
ja,
|
|
2425
|
+
th
|
|
2426
|
+
};
|
|
2427
|
+
/**
|
|
2428
|
+
* A helper function to get the matching Locale object for a given language.
|
|
2429
|
+
*
|
|
2430
|
+
* @param {string} language The language to match
|
|
2431
|
+
* @returns {Locale} The corresponding Locale object
|
|
2432
|
+
*/
|
|
2433
|
+
|
|
2434
|
+
const useLocale = language => {
|
|
2435
|
+
return localeLookup[language] || localeLookup.en;
|
|
2436
|
+
};
|
|
2437
|
+
|
|
2438
|
+
/**
|
|
2439
|
+
* The DayPicker component is used when the user needs to select a date.
|
|
2440
|
+
*
|
|
2441
|
+
* @param {DayPickerProps} props - The props for the DayPicker component
|
|
2442
|
+
* @returns {JSX.Element} DayPicker component
|
|
2443
|
+
*/
|
|
2444
|
+
|
|
2445
|
+
const DayPicker = _a => {
|
|
2446
|
+
var {
|
|
2447
|
+
onDaySelect,
|
|
2448
|
+
disabledDays,
|
|
2449
|
+
selectedDays,
|
|
2450
|
+
language
|
|
2451
|
+
} = _a,
|
|
2452
|
+
rest = __rest(_a, ["onDaySelect", "disabledDays", "selectedDays", "language"]);
|
|
2453
|
+
|
|
2454
|
+
const locale = useLocale(language);
|
|
2455
|
+
return jsx(DayPicker$1, Object.assign({
|
|
2456
|
+
onDayClick: onDaySelect,
|
|
2457
|
+
selected: selectedDays,
|
|
2458
|
+
locale: locale,
|
|
2459
|
+
disabled: disabledDays,
|
|
2460
|
+
className: "custom-day-picker"
|
|
2461
|
+
}, rest));
|
|
2462
|
+
};
|
|
2463
|
+
|
|
2519
2464
|
/**
|
|
2520
2465
|
* The DayPickerPopover component returns a button which when clicked shows the daypicker.
|
|
2521
2466
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-components",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.147",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"dependencies": {
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"echarts-for-react": "^3.0.2",
|
|
12
12
|
"uuid": "^8.3.2",
|
|
13
13
|
"react-use": "^17.4.0",
|
|
14
|
-
"react-day-picker": "^8.3.0",
|
|
15
14
|
"date-fns": "^2.29.3",
|
|
15
|
+
"react-day-picker": "^8.3.0",
|
|
16
16
|
"@trackunit/ui-icons": "0.0.46",
|
|
17
17
|
"react-useportal": "1.0.16",
|
|
18
18
|
"react-helmet": "^6.1.0",
|