@entur/datepicker 11.1.2 → 11.2.0

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.
@@ -50,6 +50,8 @@ type BaseCalendarProps<DateType extends DateValue> = {
50
50
  * @example (date) => isWeekend(date, 'no-NO') ? 'helgedag' : ''
51
51
  */
52
52
  ariaLabelForDate?: (date: CalendarDate) => string;
53
+ /** Callback-funksjon for når valideringen til datovelgeren endrer seg */
54
+ onValidate?: (isValid?: boolean) => void;
53
55
  disabled?: boolean;
54
56
  locale?: string;
55
57
  calendarRef?: React.MutableRefObject<HTMLDivElement | null>;
@@ -73,6 +73,8 @@ export type BaseDateFieldProps<DateType extends DateValue> = {
73
73
  * @default "negative"
74
74
  */
75
75
  validationVariant?: VariantType | typeof error | typeof info;
76
+ /** Callback-funksjon for når valideringen til datovelgeren endrer seg */
77
+ onValidate?: (isValid?: boolean) => void;
76
78
  labelTooltip?: React.ReactNode;
77
79
  labelProps?: React.DOMAttributes<Element>;
78
80
  fieldProps?: DateFieldProps<DateType>;
@@ -84,5 +86,5 @@ export type BaseDateFieldProps<DateType extends DateValue> = {
84
86
  style?: React.CSSProperties;
85
87
  };
86
88
  export type DateFieldProps<DateType extends DateValue> = BaseDateFieldProps<DateType> & ExtendedDateFieldProps<DateType>;
87
- export declare const DateField: <DateType extends DateValue>({ selectedDate, onChange, label, locale: customLocale, showTimeZone, showTime, granularity, disabled, readOnly, isDisabled, variant, feedback, validationVariant, validationFeedback, labelTooltip, minDate, maxDate, forcedReturnType, style, className, labelProps: parentLabelProps, append, prepend, dateFieldRef: ref, ...rest }: DateFieldProps<DateType>) => React.JSX.Element;
89
+ export declare const DateField: <DateType extends DateValue>({ selectedDate, onChange, label, locale: customLocale, showTimeZone, showTime, granularity, disabled, readOnly, isDisabled, variant, feedback, validationVariant, validationFeedback, labelTooltip, minDate, maxDate, forcedReturnType, style, className, labelProps: parentLabelProps, append, prepend, onValidate, dateFieldRef: ref, ...rest }: DateFieldProps<DateType>) => React.JSX.Element;
88
90
  export {};
@@ -220,7 +220,7 @@ function handleOnChange(_ref2) {
220
220
  onChange == null || onChange(value);
221
221
  }
222
222
 
223
- var _excluded$a = ["selectedDate", "onChange", "label", "locale", "showTimeZone", "showTime", "granularity", "disabled", "readOnly", "isDisabled", "variant", "feedback", "validationVariant", "validationFeedback", "labelTooltip", "minDate", "maxDate", "forcedReturnType", "style", "className", "labelProps", "append", "prepend", "dateFieldRef"];
223
+ var _excluded$a = ["selectedDate", "onChange", "label", "locale", "showTimeZone", "showTime", "granularity", "disabled", "readOnly", "isDisabled", "variant", "feedback", "validationVariant", "validationFeedback", "labelTooltip", "minDate", "maxDate", "forcedReturnType", "style", "className", "labelProps", "append", "prepend", "onValidate", "dateFieldRef"];
224
224
  var DateField = function DateField(_ref) {
225
225
  var selectedDate = _ref.selectedDate,
226
226
  _onChange = _ref.onChange,
@@ -248,6 +248,7 @@ var DateField = function DateField(_ref) {
248
248
  parentLabelProps = _ref.labelProps,
249
249
  append = _ref.append,
250
250
  prepend = _ref.prepend,
251
+ onValidate = _ref.onValidate,
251
252
  ref = _ref.dateFieldRef,
252
253
  rest = _objectWithoutPropertiesLoose(_ref, _excluded$a);
253
254
  var _useLocale = i18n.useLocale(),
@@ -278,6 +279,9 @@ var DateField = function DateField(_ref) {
278
279
  var _useDateField = datepicker.useDateField(_props, state, dateFieldRef),
279
280
  labelProps = _useDateField.labelProps,
280
281
  fieldProps = _useDateField.fieldProps;
282
+ React.useEffect(function () {
283
+ return onValidate == null ? void 0 : onValidate(!state.isInvalid);
284
+ }, [state.isInvalid]);
281
285
  var id = utils.useRandomId('datefield');
282
286
  return React.createElement(utils.ConditionalWrapper, {
283
287
  condition: customLocale !== undefined,
@@ -524,6 +528,9 @@ var CalendarBase = function CalendarBase(_ref2) {
524
528
  prevButtonProps = _useCalendar.prevButtonProps,
525
529
  nextButtonProps = _useCalendar.nextButtonProps,
526
530
  title = _useCalendar.title;
531
+ React.useEffect(function () {
532
+ return rest.onValidate == null ? void 0 : rest.onValidate(!state.isValueInvalid);
533
+ }, [state.isValueInvalid]);
527
534
  return React.createElement("div", _extends({}, calendarProps, {
528
535
  ref: calendarRef,
529
536
  className: classNames('eds-datepicker__calendar', className),