@trackunit/react-components 0.0.100 → 0.0.101

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,30 +1,19 @@
1
1
  /// <reference types="react" />
2
- import { Matcher } from "react-day-picker";
3
- import { BaseInputProps } from "../BaseInput";
4
- export interface DateFieldProps extends Pick<BaseInputProps, "placeholder" | "id" | "dataTestId" | "onChange" | "readOnly"> {
2
+ import { DateInputProps } from "../DateInput/DateInput";
3
+ import { FormGroupProps } from "../FormGroup/FormGroup";
4
+ declare type FormGroupExposedProps = Pick<FormGroupProps, "label" | "tip" | "helpText" | "helpAddon">;
5
+ export interface DateFieldProps extends DateInputProps, FormGroupExposedProps {
5
6
  /**
6
- * A text label to be displayed next to the indicator
7
+ * If a value is set, the field is rendered in its invalid state.
7
8
  */
8
- label?: string;
9
- /**
10
- * A text to be displayed under the input with a short description of field purpose
11
- */
12
- description?: string;
13
- /**
14
- * A default value to be displayed by a input field
15
- */
16
- defaultValue?: string;
17
- /**
18
- * A flag that can be used to disable the input, default value is false
19
- */
20
- disabled?: boolean;
21
- /**
22
- * Specification of dates not allowed to be selected - i the form of react-day-picker matcher
23
- */
24
- disabledDays?: Matcher | Matcher[] | undefined;
25
- /**
26
- * A flag that can be set to true to disallow the user to deselect a date. (if false the user can click the selected date to deselect)
27
- */
28
- preventDeselect?: boolean;
9
+ errorMessage?: string;
29
10
  }
11
+ /**
12
+ * The date field component is used for entering date values.
13
+ *
14
+ * _**Do use**_ the DateField for date input.
15
+ *
16
+ * _**Do not use**_ this fields for non-serialized dates. Use TextField instead.
17
+ */
30
18
  export declare const DateField: import("react").ForwardRefExoticComponent<DateFieldProps & import("react").RefAttributes<HTMLInputElement>>;
19
+ export {};
@@ -0,0 +1,29 @@
1
+ /// <reference types="react" />
2
+ import { Matcher } from "react-day-picker";
3
+ import { BaseInputProps } from "../BaseInput";
4
+ declare type BaseInputExposedProps = Omit<BaseInputProps, "defaultValue" | "onChange">;
5
+ export interface DateInputProps extends BaseInputExposedProps {
6
+ /**
7
+ * A default value to be displayed by a input field
8
+ */
9
+ defaultValue?: Date;
10
+ /**
11
+ * Specification of dates not allowed to be selected - i the form of react-day-picker matcher
12
+ */
13
+ disabledDays?: Matcher | Matcher[] | undefined;
14
+ /**
15
+ * A flag that can be set to true to disallow the user to deselect a date. (if false the user can click the selected date to deselect)
16
+ */
17
+ preventDeselect?: boolean;
18
+ /**
19
+ * onChange function returning the date instead of input event
20
+ */
21
+ onChange?: (date: Date) => void;
22
+ }
23
+ /**
24
+ * A wrapper around BaseInput with a pop-up day picker.
25
+ *
26
+ * NOTE: If shown with a label, please use the `DateField` component instead.
27
+ */
28
+ export declare const DateInput: import("react").ForwardRefExoticComponent<DateInputProps & import("react").RefAttributes<HTMLInputElement>>;
29
+ export {};
@@ -7,7 +7,8 @@ export * from "./Chart";
7
7
  export * from "./Checkbox";
8
8
  export * from "./Collapse";
9
9
  export * from "./CopyableText";
10
- export * from "./DateField";
10
+ export * from "./DateField/DateField";
11
+ export * from "./DateInput/DateInput";
11
12
  export * from "./DayPicker";
12
13
  export * from "./FormGroup/FormGroup";
13
14
  export * from "./Heading";
package/index.js CHANGED
@@ -1992,23 +1992,28 @@ const StyledCardBody = tw(CardBody)`
1992
1992
  max-h-full
1993
1993
  `;
1994
1994
 
1995
- const DateField = forwardRef(({
1996
- defaultValue,
1997
- onChange,
1998
- disabled = false,
1999
- readOnly = false,
2000
- id,
2001
- dataTestId,
2002
- placeholder,
2003
- disabledDays,
2004
- preventDeselect = false
2005
- }, ref) => {
2006
- const [selectedDay, setSelectedDay] = useState(defaultValue ? new Date(defaultValue) : undefined);
1995
+ /**
1996
+ * A wrapper around BaseInput with a pop-up day picker.
1997
+ *
1998
+ * NOTE: If shown with a label, please use the `DateField` component instead.
1999
+ */
2000
+
2001
+ const DateInput = forwardRef((_a, ref) => {
2002
+ var {
2003
+ defaultValue,
2004
+ disabledDays,
2005
+ disabled,
2006
+ preventDeselect,
2007
+ onChange
2008
+ } = _a,
2009
+ rest = __rest(_a, ["defaultValue", "disabledDays", "disabled", "preventDeselect", "onChange"]);
2010
+
2011
+ const [selectedDay, setSelectedDay] = useState(defaultValue);
2007
2012
  const onChangeHandler = useCallback(value => {
2008
2013
  const newValue = (value === null || value === void 0 ? void 0 : value.toLocaleDateString()) === (selectedDay === null || selectedDay === void 0 ? void 0 : selectedDay.toLocaleDateString()) && !preventDeselect ? undefined : value;
2009
2014
  setSelectedDay(newValue);
2010
2015
  onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
2011
- }, [setSelectedDay, onChange, selectedDay, preventDeselect]);
2016
+ }, [selectedDay, preventDeselect, onChange]);
2012
2017
  const target = useRef(null);
2013
2018
  const popover = useRef(null);
2014
2019
  const {
@@ -2023,15 +2028,11 @@ const DateField = forwardRef(({
2023
2028
  placement: "bottom"
2024
2029
  });
2025
2030
  return jsxs(Fragment, {
2026
- children: [jsx(BaseInput, {
2027
- placeholder: placeholder,
2028
- value: (selectedDay === null || selectedDay === void 0 ? void 0 : selectedDay.toLocaleDateString()) || "",
2029
- onChange: () => {},
2030
- disabled: disabled,
2031
- readOnly: readOnly,
2032
- dataTestId: dataTestId,
2033
- id: id,
2031
+ children: [jsx(BaseInput, Object.assign({
2034
2032
  ref: ref,
2033
+ value: (selectedDay === null || selectedDay === void 0 ? void 0 : selectedDay.toLocaleDateString()) || "",
2034
+ onChange: () => {}
2035
+ }, rest, {
2035
2036
  suffix: jsx(Icon$1, {
2036
2037
  dataTestId: "calendar",
2037
2038
  name: "CalendarIcon",
@@ -2050,8 +2051,9 @@ const DateField = forwardRef(({
2050
2051
  size: "small"
2051
2052
  })
2052
2053
  }))
2053
- })
2054
- }), jsx(AnimatedPopover, Object.assign({
2054
+ }),
2055
+ onClick: e => e.preventDefault()
2056
+ })), jsx(AnimatedPopover, Object.assign({
2055
2057
  ref: popoverRef,
2056
2058
  onRequestClose: () => {
2057
2059
  var _a;
@@ -2075,6 +2077,34 @@ const RemoveValueContainer = tw.div`
2075
2077
  tu-date__remove
2076
2078
  `;
2077
2079
 
2080
+ /**
2081
+ * The Label component is used for labels for input fields.
2082
+ * This component is **not used directly**, but is part of the FormGroup and Field components.
2083
+ *
2084
+ * @param {LabelProps} props - The props for the Label component
2085
+ * @returns {JSX.Element} Label component
2086
+ */
2087
+
2088
+ const Label$5 = ({
2089
+ id,
2090
+ htmlFor,
2091
+ children,
2092
+ className,
2093
+ dataTestId
2094
+ }) => {
2095
+ return jsx(Root$2, Object.assign({
2096
+ className: className,
2097
+ id: id,
2098
+ "data-testid": dataTestId,
2099
+ htmlFor: htmlFor
2100
+ }, {
2101
+ children: children
2102
+ }));
2103
+ };
2104
+ const Root$2 = tw.label`
2105
+ tu-label
2106
+ `;
2107
+
2078
2108
  /**
2079
2109
  * The PopoverListItem component.
2080
2110
  *
@@ -2190,143 +2220,6 @@ const StyledText$1 = tw(Text)`
2190
2220
  text-neutral-500
2191
2221
  `;
2192
2222
 
2193
- /**
2194
- * The DayPickerPopover component returns a button which when clicked shows the daypicker.
2195
- *
2196
- * @param {DayPickerPopoverProps} props - The props for the DayPickerPopover component
2197
- * @returns {JSX.Element} DayPickerPopover component
2198
- */
2199
-
2200
- const DayPickerPopover = ({
2201
- disabledDays,
2202
- className,
2203
- selectedDay,
2204
- onDaySelect,
2205
- intent = "secondary",
2206
- placement = "bottom",
2207
- size = "small",
2208
- buttonContent,
2209
- language
2210
- }) => {
2211
- const target = useRef(null);
2212
- const popover = useRef(null);
2213
- const {
2214
- popoverRef,
2215
- targetRef,
2216
- onShow,
2217
- onHide,
2218
- popoverProps
2219
- } = usePopover({
2220
- targetRef: target,
2221
- popoverRef: popover,
2222
- placement: placement
2223
- });
2224
- return jsxs(Fragment$1, {
2225
- children: [jsx(Button, Object.assign({
2226
- intent: intent,
2227
- size: size,
2228
- className: className,
2229
- prefix: jsx(Icon$1, {
2230
- name: "CalendarIcon",
2231
- size: "small"
2232
- }),
2233
- ref: targetRef,
2234
- onClick: onShow
2235
- }, {
2236
- children: buttonContent
2237
- })), jsx(AnimatedPopover, Object.assign({
2238
- ref: popoverRef,
2239
- onRequestClose: () => {
2240
- var _a;
2241
-
2242
- onHide();
2243
- (_a = targetRef === null || targetRef === void 0 ? void 0 : targetRef.current) === null || _a === void 0 ? void 0 : _a.blur();
2244
- }
2245
- }, popoverProps, {
2246
- children: jsx(PopoverList, {
2247
- children: jsx(DayPicker, {
2248
- disabledDays: disabledDays,
2249
- onDaySelect: onDaySelect,
2250
- selectedDays: selectedDay,
2251
- language: language
2252
- })
2253
- })
2254
- }))]
2255
- });
2256
- };
2257
-
2258
- /**
2259
- * The DayRangePicker component should be used when the user needs to select a range of dates.
2260
- *
2261
- * @param {DayRangePickerProps} props - The props for the DayRangePicker component
2262
- * @returns {JSX.Element} DayRangePicker component
2263
- */
2264
-
2265
- const DayRangePicker = ({
2266
- onRangeSelect,
2267
- selectedDays,
2268
- disabledDays,
2269
- dataTestId,
2270
- language
2271
- }) => {
2272
- const locale = useLocale(language);
2273
- const onSelect = useCallback(range => {
2274
- if (onRangeSelect && range === undefined) {
2275
- onRangeSelect(undefined);
2276
- }
2277
-
2278
- if (onRangeSelect && range) {
2279
- const from = range.from;
2280
- const to = range.to ? range.to : range.from;
2281
- onRangeSelect({
2282
- from,
2283
- to
2284
- });
2285
- }
2286
- }, [onRangeSelect]);
2287
- return jsx("div", Object.assign({
2288
- "data-testid": dataTestId
2289
- }, {
2290
- children: jsx(DayPicker$1, {
2291
- mode: "range",
2292
- onSelect: onSelect,
2293
- selected: selectedDays,
2294
- defaultMonth: selectedDays && selectedDays.from,
2295
- locale: locale,
2296
- disabled: disabledDays,
2297
- className: "custom-day-picker range-picker"
2298
- })
2299
- }));
2300
- };
2301
-
2302
- /**
2303
- * The Label component is used for labels for input fields.
2304
- * This component is **not used directly**, but is part of the FormGroup and Field components.
2305
- *
2306
- * @param {LabelProps} props - The props for the Label component
2307
- * @returns {JSX.Element} Label component
2308
- */
2309
-
2310
- const Label$5 = ({
2311
- id,
2312
- htmlFor,
2313
- children,
2314
- className,
2315
- dataTestId
2316
- }) => {
2317
- return jsx(Root$2, Object.assign({
2318
- className: className,
2319
- id: id,
2320
- "data-testid": dataTestId,
2321
- htmlFor: htmlFor
2322
- }, {
2323
- children: children
2324
- }));
2325
- };
2326
- const Root$2 = tw.label`
2327
- tu-label
2328
- `;
2329
-
2330
2223
  /**
2331
2224
  * The Tooltip component.
2332
2225
  *
@@ -2502,6 +2395,157 @@ const HelpAddon = tw.span`
2502
2395
  tu-form-group__help-addon
2503
2396
  `;
2504
2397
 
2398
+ /**
2399
+ * The date field component is used for entering date values.
2400
+ *
2401
+ * _**Do use**_ the DateField for date input.
2402
+ *
2403
+ * _**Do not use**_ this fields for non-serialized dates. Use TextField instead.
2404
+ */
2405
+
2406
+ const DateField = forwardRef((_a, ref) => {
2407
+ var {
2408
+ label,
2409
+ tip,
2410
+ helpText,
2411
+ errorMessage,
2412
+ helpAddon,
2413
+ isInvalid,
2414
+ className,
2415
+ defaultValue,
2416
+ dataTestId
2417
+ } = _a,
2418
+ rest = __rest(_a, ["label", "tip", "helpText", "errorMessage", "helpAddon", "isInvalid", "className", "defaultValue", "dataTestId"]);
2419
+
2420
+ const renderAsInvalid = isInvalid || Boolean(errorMessage);
2421
+ return jsx(FormGroup, Object.assign({
2422
+ label: label,
2423
+ tip: tip,
2424
+ isInvalid: renderAsInvalid,
2425
+ helpText: errorMessage || helpText,
2426
+ helpAddon: helpAddon,
2427
+ dataTestId: `${dataTestId}-FormGroup`
2428
+ }, {
2429
+ children: jsx(DateInput, Object.assign({
2430
+ ref: ref,
2431
+ defaultValue: defaultValue,
2432
+ isInvalid: renderAsInvalid
2433
+ }, rest, {
2434
+ className: className,
2435
+ dataTestId: dataTestId
2436
+ }))
2437
+ }));
2438
+ });
2439
+
2440
+ /**
2441
+ * The DayPickerPopover component returns a button which when clicked shows the daypicker.
2442
+ *
2443
+ * @param {DayPickerPopoverProps} props - The props for the DayPickerPopover component
2444
+ * @returns {JSX.Element} DayPickerPopover component
2445
+ */
2446
+
2447
+ const DayPickerPopover = ({
2448
+ disabledDays,
2449
+ className,
2450
+ selectedDay,
2451
+ onDaySelect,
2452
+ intent = "secondary",
2453
+ placement = "bottom",
2454
+ size = "small",
2455
+ buttonContent,
2456
+ language
2457
+ }) => {
2458
+ const target = useRef(null);
2459
+ const popover = useRef(null);
2460
+ const {
2461
+ popoverRef,
2462
+ targetRef,
2463
+ onShow,
2464
+ onHide,
2465
+ popoverProps
2466
+ } = usePopover({
2467
+ targetRef: target,
2468
+ popoverRef: popover,
2469
+ placement: placement
2470
+ });
2471
+ return jsxs(Fragment$1, {
2472
+ children: [jsx(Button, Object.assign({
2473
+ intent: intent,
2474
+ size: size,
2475
+ className: className,
2476
+ prefix: jsx(Icon$1, {
2477
+ name: "CalendarIcon",
2478
+ size: "small"
2479
+ }),
2480
+ ref: targetRef,
2481
+ onClick: onShow
2482
+ }, {
2483
+ children: buttonContent
2484
+ })), jsx(AnimatedPopover, Object.assign({
2485
+ ref: popoverRef,
2486
+ onRequestClose: () => {
2487
+ var _a;
2488
+
2489
+ onHide();
2490
+ (_a = targetRef === null || targetRef === void 0 ? void 0 : targetRef.current) === null || _a === void 0 ? void 0 : _a.blur();
2491
+ }
2492
+ }, popoverProps, {
2493
+ children: jsx(PopoverList, {
2494
+ children: jsx(DayPicker, {
2495
+ disabledDays: disabledDays,
2496
+ onDaySelect: onDaySelect,
2497
+ selectedDays: selectedDay,
2498
+ language: language
2499
+ })
2500
+ })
2501
+ }))]
2502
+ });
2503
+ };
2504
+
2505
+ /**
2506
+ * The DayRangePicker component should be used when the user needs to select a range of dates.
2507
+ *
2508
+ * @param {DayRangePickerProps} props - The props for the DayRangePicker component
2509
+ * @returns {JSX.Element} DayRangePicker component
2510
+ */
2511
+
2512
+ const DayRangePicker = ({
2513
+ onRangeSelect,
2514
+ selectedDays,
2515
+ disabledDays,
2516
+ dataTestId,
2517
+ language
2518
+ }) => {
2519
+ const locale = useLocale(language);
2520
+ const onSelect = useCallback(range => {
2521
+ if (onRangeSelect && range === undefined) {
2522
+ onRangeSelect(undefined);
2523
+ }
2524
+
2525
+ if (onRangeSelect && range) {
2526
+ const from = range.from;
2527
+ const to = range.to ? range.to : range.from;
2528
+ onRangeSelect({
2529
+ from,
2530
+ to
2531
+ });
2532
+ }
2533
+ }, [onRangeSelect]);
2534
+ return jsx("div", Object.assign({
2535
+ "data-testid": dataTestId
2536
+ }, {
2537
+ children: jsx(DayPicker$1, {
2538
+ mode: "range",
2539
+ onSelect: onSelect,
2540
+ selected: selectedDays,
2541
+ defaultMonth: selectedDays && selectedDays.from,
2542
+ locale: locale,
2543
+ disabled: disabledDays,
2544
+ className: "custom-day-picker range-picker"
2545
+ })
2546
+ }));
2547
+ };
2548
+
2505
2549
  /**
2506
2550
  * Indicators are non-interactive elements that communicate essential aspects of the state of an asset.
2507
2551
  *
@@ -4518,4 +4562,4 @@ const Layout = tw.div`
4518
4562
  tu-layout-TwoColumnLayout
4519
4563
  `;
4520
4564
 
4521
- export { Alert, AnimatedPopover, Badge, BaseInput, Button, Card, CardBody, CardFooter, CardHeader, Chart, Checkbox, Collapse, CopyableText, CreatableSelect, DateField, DayPicker, DayPickerPopover, DayRangePicker, DensityContainer, FilterListMapLayout, FormGroup, FullWidthRepeatingLayout, GridArea, Heading, Icon$1 as Icon, IconButton, Indicator$1 as Indicator, IntrinsicallyResponsiveGrid, Label$5 as Label, LegendItem, MenuButton, MenuItem, MenuList, MinTopFullContentLayout, Modal, ModalBackdrop, NumberField, NumberInput, PageHeading, PopoverLifecycle, PopoverList, PopoverListItem, PopoverTitle, Prompt, ROLE_CARD, RadioGroup, RadioItem, Select, SkeletonLines, Spacer, Spinner, StarButton, Tag, Text, TextArea, TextAreaField, TextField, TextInput, Timeline, TimelineElement, Tip, TitleNavContentLayout, Toggle, Tooltip, TwoColumnLayout, activityColors, colors, criticalityColors, docs, generalColors, intentColors, useContainerProps, useCustomComponents, useCustomStyles, useDebounce, useLocalStorage, useModal, usePopover, usePrompt, useTimeout };
4565
+ export { Alert, AnimatedPopover, Badge, BaseInput, Button, Card, CardBody, CardFooter, CardHeader, Chart, Checkbox, Collapse, CopyableText, CreatableSelect, DateField, DateInput, DayPicker, DayPickerPopover, DayRangePicker, DensityContainer, FilterListMapLayout, FormGroup, FullWidthRepeatingLayout, GridArea, Heading, Icon$1 as Icon, IconButton, Indicator$1 as Indicator, IntrinsicallyResponsiveGrid, Label$5 as Label, LegendItem, MenuButton, MenuItem, MenuList, MinTopFullContentLayout, Modal, ModalBackdrop, NumberField, NumberInput, PageHeading, PopoverLifecycle, PopoverList, PopoverListItem, PopoverTitle, Prompt, ROLE_CARD, RadioGroup, RadioItem, Select, SkeletonLines, Spacer, Spinner, StarButton, Tag, Text, TextArea, TextAreaField, TextField, TextInput, Timeline, TimelineElement, Tip, TitleNavContentLayout, Toggle, Tooltip, TwoColumnLayout, activityColors, colors, criticalityColors, docs, generalColors, intentColors, useContainerProps, useCustomComponents, useCustomStyles, useDebounce, useLocalStorage, useModal, usePopover, usePrompt, useTimeout };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-components",
3
- "version": "0.0.100",
3
+ "version": "0.0.101",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "UNLICENSED",
6
6
  "dependencies": {
@@ -1 +0,0 @@
1
- export * from "./DateField";