@povio/ui 2.2.9-rc.12 → 2.2.9-rc.14

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.
@@ -17,6 +17,7 @@ interface DateTimePickerBaseProps extends FormFieldProps, InputVariantProps, Omi
17
17
  isDirty?: boolean;
18
18
  disableManualEntry?: boolean;
19
19
  autoFixYear?: boolean;
20
+ setDateValueOnDateSelection?: boolean;
20
21
  placeholder?: string;
21
22
  inputClassName?: string;
22
23
  onBlur?: (e: FocusEvent<HTMLInputElement>) => void;
@@ -17,7 +17,7 @@ import { useCalendarState, useDatePickerState } from "react-stately";
17
17
  //#region src/components/inputs/DateTime/DateTimePicker/DateTimePicker.tsx
18
18
  var DateTimePickerBase = (props) => {
19
19
  const ui = UIConfig.useConfig();
20
- const { ref, label, tooltipText, helperText, isRequired, rightContent, isDisabled, isDirty, headerClassName, errorClassName, isHeaderHidden, error, onChange, onBlur, value, disableDropdown, isTimeOptional, placeholder, inputClassName, hideLabel = ui.input.hideLabel, variant = ui.input.variant, as = ui.input.as, size = ui.input.size, isClearable = ui.input.isClearable, todayIcon = ui.dateInput.todayIcon, todayIconButtonSize = ui.dateInput.todayIconButtonSize, shouldForceLeadingZeros = ui.dateInput.shouldForceLeadingZeros, disableManualEntry = ui.dateInput.disableManualEntry, autoFixYear = ui.dateInput.autoFixYear, ...rest } = props;
20
+ const { ref, label, tooltipText, helperText, isRequired, rightContent, isDisabled, isDirty, headerClassName, errorClassName, isHeaderHidden, error, onChange, onBlur, value, disableDropdown, isTimeOptional, placeholder, inputClassName, hideLabel = ui.input.hideLabel, variant = ui.input.variant, as = ui.input.as, size = ui.input.size, isClearable = ui.input.isClearable, todayIcon = ui.dateInput.todayIcon, todayIconButtonSize = ui.dateInput.todayIconButtonSize, shouldForceLeadingZeros = ui.dateInput.shouldForceLeadingZeros, disableManualEntry = ui.dateInput.disableManualEntry, autoFixYear = ui.dateInput.autoFixYear, setDateValueOnDateSelection = ui.dateInput.setDateValueOnDateSelection, ...rest } = props;
21
21
  const formFieldProps = {
22
22
  error,
23
23
  label,
@@ -177,7 +177,8 @@ var DateTimePickerBase = (props) => {
177
177
  calendarProps,
178
178
  includesTime: true,
179
179
  datePickerState: dialogState,
180
- onApply
180
+ onApply,
181
+ setDateValueOnDateSelection
181
182
  })
182
183
  })]
183
184
  })
@@ -1,4 +1,5 @@
1
1
  import { CalendarState, CalendarStateOptions } from '@react-stately/calendar';
2
+ import { DateValue } from 'react-aria';
2
3
  import { DatePickerState } from 'react-stately';
3
4
  type DateTimeCalendarProps = {
4
5
  includesTime?: false;
@@ -13,8 +14,10 @@ type CalendarProps = DateTimeCalendarProps & {
13
14
  className?: string;
14
15
  state: CalendarState;
15
16
  calendarProps: Omit<CalendarStateOptions, "locale" | "createCalendar">;
16
- onApply: () => void;
17
+ onApply: (selectedDate?: DateValue) => void;
18
+ onDateSelectionChange?: (selectedDate: DateValue) => void;
19
+ setDateValueOnDateSelection?: boolean;
17
20
  };
18
21
  export type ToggleState = "month" | "year" | "time";
19
- export declare const Calendar: ({ className, includesTime, datePickerState, hourCycle, onApply, ...props }: CalendarProps) => import("react/jsx-runtime").JSX.Element;
22
+ export declare const Calendar: ({ className, includesTime, datePickerState, hourCycle, onApply, onDateSelectionChange, setDateValueOnDateSelection, ...props }: CalendarProps) => import("react/jsx-runtime").JSX.Element;
20
23
  export {};
@@ -5,20 +5,37 @@ import { TimePickerForm } from "./TimePickerForm.js";
5
5
  import { YearPicker } from "./YearPicker.js";
6
6
  import { jsx, jsxs } from "react/jsx-runtime";
7
7
  import { clsx } from "clsx";
8
- import { useState } from "react";
8
+ import { useCallback, useState } from "react";
9
9
  import { useCalendar } from "@react-aria/calendar";
10
10
  //#region src/components/inputs/DateTime/shared/Calendar.tsx
11
- var Calendar = ({ className, includesTime, datePickerState, hourCycle, onApply, ...props }) => {
11
+ var Calendar = ({ className, includesTime, datePickerState, hourCycle, onApply, onDateSelectionChange, setDateValueOnDateSelection = false, ...props }) => {
12
12
  const [toggleState, setToggleState] = useState(null);
13
13
  const { calendarProps, prevButtonProps, nextButtonProps } = useCalendar(props.calendarProps, props.state);
14
- const handleDateChange = () => {
15
- if (includesTime && !datePickerState.value) setToggleState("time");
16
- else onApply();
14
+ const onDateSelection = useCallback((date) => {
15
+ if (!includesTime || !setDateValueOnDateSelection) return;
16
+ datePickerState.setDateValue(date);
17
+ }, [
18
+ includesTime,
19
+ datePickerState,
20
+ setDateValueOnDateSelection
21
+ ]);
22
+ const handleDateChange = (selectedDate) => {
23
+ const resolvedDate = selectedDate ?? props.state.focusedDate;
24
+ if (includesTime && resolvedDate && setDateValueOnDateSelection) {
25
+ datePickerState.setDateValue(resolvedDate);
26
+ onDateSelectionChange?.(resolvedDate);
27
+ }
28
+ if (includesTime && toggleState !== "time") {
29
+ setToggleState("time");
30
+ return;
31
+ }
32
+ onApply(resolvedDate);
17
33
  };
18
34
  const getContent = () => {
19
35
  if (!toggleState) return /* @__PURE__ */ jsx(CalendarGrid, {
20
36
  state: props.state,
21
- onApply: handleDateChange
37
+ onApply: handleDateChange,
38
+ onDateSelection
22
39
  });
23
40
  if (toggleState === "month") return /* @__PURE__ */ jsx(MonthPicker, {
24
41
  state: props.state,
@@ -4,7 +4,7 @@ import { KeyboardEvent } from 'react';
4
4
  import { DateValue } from 'react-aria';
5
5
  interface CalendarCellProps extends AriaCalendarCellProps {
6
6
  state: CalendarState | RangeCalendarState;
7
- onApply?: () => void;
7
+ onApply?: (selectedDate?: DateValue) => void;
8
8
  shouldCloseOnSelect?: boolean;
9
9
  onDateSelection?: (date: DateValue) => void;
10
10
  onDateHover?: (date: DateValue | null) => void;
@@ -17,12 +17,12 @@ var CalendarCell = ({ state, onApply, shouldCloseOnSelect = true, onDateSelectio
17
17
  const onClick = useCallback((event) => {
18
18
  buttonProps.onClick?.(event);
19
19
  if (onDateSelection) onDateSelection(props.date);
20
- if (isSelected && shouldCloseOnSelect) onApply?.();
20
+ if (shouldCloseOnSelect && !isDisabled) onApply?.(props.date);
21
21
  }, [
22
22
  buttonProps,
23
23
  onDateSelection,
24
24
  props.date,
25
- isSelected,
25
+ isDisabled,
26
26
  shouldCloseOnSelect,
27
27
  onApply
28
28
  ]);
@@ -87,7 +87,7 @@ var CalendarCell = ({ state, onApply, shouldCloseOnSelect = true, onDateSelectio
87
87
  state.setFocusedDate(props.date);
88
88
  }
89
89
  eventHandler?.(event);
90
- if (isSelected && shouldCloseOnSelect) onApply?.();
90
+ if (isSelected && shouldCloseOnSelect) onApply?.(props.date);
91
91
  };
92
92
  const onMouseEnter = useCallback(() => {
93
93
  if (onDateHover && selectionState.isSelectingMode) onDateHover(props.date);
@@ -4,7 +4,7 @@ import { KeyboardEvent } from 'react';
4
4
  import { DateValue } from 'react-aria';
5
5
  interface CalendarGridProps extends AriaCalendarGridProps {
6
6
  state: CalendarState | RangeCalendarState;
7
- onApply?: () => void;
7
+ onApply?: (selectedDate?: DateValue) => void;
8
8
  offset?: {
9
9
  months?: number;
10
10
  };
@@ -5,7 +5,7 @@ import { Controller } from "react-hook-form";
5
5
  //#region src/components/inputs/Selection/Autocomplete/Autocomplete.tsx
6
6
  function Autocomplete(props) {
7
7
  if ("formControl" in props && props.formControl) {
8
- const { formControl, ref, ...innerProps } = props;
8
+ const { ignoreInputValueFiltering = true, formControl, ref, ...innerProps } = props;
9
9
  return /* @__PURE__ */ jsx(Controller, {
10
10
  control: formControl.control,
11
11
  name: formControl.name,
@@ -18,7 +18,8 @@ function Autocomplete(props) {
18
18
  isDirty,
19
19
  isDisabled: field.disabled || props.isDisabled,
20
20
  error: props.error ?? error?.message,
21
- isSearchable: true
21
+ isSearchable: true,
22
+ ignoreInputValueFiltering
22
23
  })
23
24
  });
24
25
  }
@@ -11,11 +11,20 @@ export interface QueryAutocompleteInfinitePage<TSelectItem extends SelectItem =
11
11
  export type QueryResult<TSelectItem extends SelectItem = SelectItem> = UseQueryResult<Array<TSelectItem>> | UseInfiniteQueryResult<QueryAutocompleteInfinitePage<TSelectItem>>;
12
12
  export type QueryFn<TSelectItem extends SelectItem = SelectItem> = (...args: any[]) => QueryResult<TSelectItem>;
13
13
  export type QueryAutocompleteExtractedData<TSelectItem extends SelectItem = SelectItem> = Array<TSelectItem>;
14
+ type QueryAutocompleteParams<TQueryFn extends QueryFn> = Parameters<TQueryFn>[0];
15
+ type QueryAutocompleteFilter = {
16
+ search?: string;
17
+ };
18
+ type QueryAutocompleteSearchParams = {
19
+ search?: string;
20
+ } | {
21
+ filter?: QueryAutocompleteFilter;
22
+ };
14
23
  export type QueryAutocompleteProps<TFieldValues extends FieldValues, TSelectItem extends SelectItem<any>, TQueryFn extends QueryFn<TSelectItem>> = OmitDiscriminatedUnion<AutocompleteProps<TSelectItem["id"]>, "items" | "onSearchChange" | "isLoading" | keyof GroupedSelectProps> & GroupedSelectControlProps<TFieldValues, TSelectItem["id"]> & {
15
- query: Parameters<TQueryFn>[0] extends {
16
- search?: string;
17
- } ? TQueryFn : never;
18
- queryParams?: Omit<Parameters<TQueryFn>[0], "search">;
24
+ query: QueryAutocompleteParams<TQueryFn> extends QueryAutocompleteSearchParams ? TQueryFn : never;
25
+ queryParams?: Omit<QueryAutocompleteParams<TQueryFn>, "search" | "limit"> & {
26
+ limit?: number;
27
+ };
19
28
  queryOptions?: Parameters<TQueryFn>[1];
20
29
  queryMap?: (data: QueryAutocompleteExtractedData<TSelectItem>) => SelectItem<TSelectItem["id"]>[];
21
30
  isInitialQueryDisabled?: boolean;
@@ -28,3 +37,4 @@ export interface UseQueryAutocompleteOptions<TSelectItem extends SelectItem<any>
28
37
  initialQueryState?: boolean;
29
38
  search: string;
30
39
  }
40
+ export {};
@@ -6,4 +6,4 @@ export interface SelectListBoxProps extends Pick<SelectBaseProps, "label" | "new
6
6
  isScrollable?: boolean;
7
7
  onClose?: () => void;
8
8
  }
9
- export declare const SelectListBox: ({ label, selectionMode, isSearchable, isScrollable, virtualizerOptions, totalItems, hasLoadMore, newItemRender, onLoadMore, className, onClose, ...props }: SelectListBoxProps) => import("react/jsx-runtime").JSX.Element;
9
+ export declare const SelectListBox: ({ label, selectionMode, isSearchable, isScrollable, virtualizerOptions, totalItems, newItemRender, onLoadMore, className, onClose, ...props }: SelectListBoxProps) => import("react/jsx-runtime").JSX.Element;
@@ -7,8 +7,8 @@ import { jsx } from "react/jsx-runtime";
7
7
  import { clsx } from "clsx";
8
8
  import { ListBox, ListLayout, Virtualizer } from "react-aria-components";
9
9
  //#region src/components/inputs/Selection/shared/SelectListBox.tsx
10
- var SelectListBox = ({ label, selectionMode, isSearchable, isScrollable = true, virtualizerOptions, totalItems, hasLoadMore, newItemRender, onLoadMore, className, onClose, ...props }) => {
11
- const { fieldState, onChange, listItems, selectableListItems, selectedIds, isMultiple, onClear, onSelectAll } = SelectContext.useSelect();
10
+ var SelectListBox = ({ label, selectionMode, isSearchable, isScrollable = true, virtualizerOptions, totalItems, newItemRender, onLoadMore, className, onClose, ...props }) => {
11
+ const { fieldState, onChange, listItems, selectableListItems, selectedIds, isMultiple, onClear, onSelectAll, hasLoadMore } = SelectContext.useSelect();
12
12
  const onSelectionChange = (value) => {
13
13
  const ids = Array.from(value);
14
14
  if (!isMultiple && ids.length === 0) {
@@ -33,7 +33,9 @@ export declare namespace UIConfig {
33
33
  };
34
34
  toggle: Pick<ToggleProps, "variant">;
35
35
  slider: Pick<SliderProps, "minValue" | "maxValue">;
36
- dateInput: Pick<DatePickerProps, "todayIcon" | "todayIconButtonSize" | "shouldForceLeadingZeros" | "disableManualEntry" | "autoFixYear">;
36
+ dateInput: Pick<DatePickerProps, "todayIcon" | "todayIconButtonSize" | "shouldForceLeadingZeros" | "disableManualEntry" | "autoFixYear"> & {
37
+ setDateValueOnDateSelection?: boolean;
38
+ };
37
39
  actionModal: Pick<ActionModalProps, "titleTypography" | "descriptionTypography">;
38
40
  bottomSheet: Pick<BottomSheetProps, "closeDragThreshold" | "closeVelocityThreshold" | "hideThumb" | "headerTypography">;
39
41
  tableHeaderText: Pick<HeaderTextProps, "variant" | "size">;
@@ -46,7 +46,8 @@ var UIConfig;
46
46
  todayIconButtonSize: "none",
47
47
  shouldForceLeadingZeros: false,
48
48
  disableManualEntry: false,
49
- autoFixYear: false
49
+ autoFixYear: false,
50
+ setDateValueOnDateSelection: false
50
51
  },
51
52
  actionModal: {
52
53
  titleTypography: {
@@ -3,6 +3,6 @@ type UseIntersectionObserverProps = {
3
3
  onIntersectionChange?: (entry: IntersectionObserverEntry) => void;
4
4
  } & IntersectionObserverInit;
5
5
  export declare const useIntersectionObserver: <T extends HTMLElement>({ onIntersection, onIntersectionChange, root, rootMargin, threshold, }: UseIntersectionObserverProps) => {
6
- ref: import('react').RefObject<T | null>;
6
+ ref: (element: T | null) => void;
7
7
  };
8
8
  export {};
@@ -1,25 +1,44 @@
1
- import { useEffect, useRef } from "react";
1
+ import { useCallback, useEffect, useMemo, useRef } from "react";
2
2
  //#region src/hooks/useIntersectionObserver.ts
3
3
  var useIntersectionObserver = ({ onIntersection, onIntersectionChange, root, rootMargin, threshold }) => {
4
- const ref = useRef(null);
4
+ const elementRef = useRef(null);
5
+ const observerRef = useRef(null);
6
+ const onIntersectionRef = useRef(onIntersection);
7
+ const onIntersectionChangeRef = useRef(onIntersectionChange);
8
+ useEffect(() => {
9
+ onIntersectionRef.current = onIntersection;
10
+ }, [onIntersection]);
11
+ useEffect(() => {
12
+ onIntersectionChangeRef.current = onIntersectionChange;
13
+ }, [onIntersectionChange]);
5
14
  useEffect(() => {
6
15
  const observer = new IntersectionObserver((entries) => {
7
- if (entries.some((entry) => entry.isIntersecting)) onIntersection?.();
8
- onIntersectionChange?.(entries[0]);
16
+ if (entries.some((entry) => entry.isIntersecting)) onIntersectionRef.current?.();
17
+ onIntersectionChangeRef.current?.(entries[0]);
9
18
  }, {
10
19
  root,
11
20
  rootMargin,
12
21
  threshold
13
22
  });
14
- if (ref.current) observer.observe(ref.current);
15
- return () => observer.disconnect();
23
+ observerRef.current = observer;
24
+ if (elementRef.current) observer.observe(elementRef.current);
25
+ return () => {
26
+ if (elementRef.current) observer.unobserve(elementRef.current);
27
+ observer.disconnect();
28
+ observerRef.current = null;
29
+ };
16
30
  }, [
17
- ref,
18
31
  root,
19
- onIntersection,
20
- onIntersectionChange
32
+ rootMargin,
33
+ threshold
21
34
  ]);
22
- return { ref };
35
+ const ref = useCallback((element) => {
36
+ if (elementRef.current === element) return;
37
+ if (observerRef.current && elementRef.current) observerRef.current.unobserve(elementRef.current);
38
+ elementRef.current = element;
39
+ if (observerRef.current && elementRef.current) observerRef.current.observe(elementRef.current);
40
+ }, []);
41
+ return useMemo(() => ({ ref }), [ref]);
23
42
  };
24
43
  //#endregion
25
44
  export { useIntersectionObserver };
@@ -1,10 +1,16 @@
1
+ import { ApiQueryUtils } from "../utils/query.utils.js";
1
2
  import { useMemo, useState } from "react";
2
3
  //#region src/hooks/useQueryAutocomplete.ts
3
4
  var useQueryAutocomplete = ({ query, queryParams, queryOptions, mapItems, initialQueryState, search }) => {
4
5
  const [isQueryEnabled, setIsQueryEnabled] = useState(!initialQueryState);
5
6
  const queryResult = query(search === void 0 ? queryParams : {
7
+ ...queryParams,
8
+ limit: queryParams?.limit ?? ApiQueryUtils.DEFAULT_LIMIT,
6
9
  search,
7
- ...queryParams
10
+ filter: queryParams && "filter" in queryParams ? {
11
+ ...queryParams.filter,
12
+ search
13
+ } : void 0
8
14
  }, {
9
15
  ...queryOptions,
10
16
  enabled: isQueryEnabled && (queryOptions?.enabled ?? true)
@@ -0,0 +1,4 @@
1
+ export declare namespace ApiQueryUtils {
2
+ const DEFAULT_LIMIT = 20;
3
+ const DEFAULT_PAGE = 1;
4
+ }
@@ -0,0 +1,8 @@
1
+ //#region src/utils/query.utils.ts
2
+ var ApiQueryUtils;
3
+ (function(_ApiQueryUtils) {
4
+ _ApiQueryUtils.DEFAULT_LIMIT = 20;
5
+ _ApiQueryUtils.DEFAULT_PAGE = 1;
6
+ })(ApiQueryUtils || (ApiQueryUtils = {}));
7
+ //#endregion
8
+ export { ApiQueryUtils };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@povio/ui",
3
- "version": "2.2.9-rc.12",
3
+ "version": "2.2.9-rc.14",
4
4
  "type": "module",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",