@sebgroup/green-react 3.10.0 → 3.12.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.
package/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
2
- import React, { useState, useEffect, useRef, useLayoutEffect, useMemo, forwardRef, useCallback, useId } from 'react';
2
+ import React, { useRef, useState, useEffect, useLayoutEffect, useMemo, forwardRef, useCallback, useId } from 'react';
3
3
  import { randomId, validateClassName, debounce, delay, sliderColors, getSliderTrackBackground } from '@sebgroup/extract';
4
4
  import { createComponent } from '@lit/react';
5
5
  import { GdsDatepicker } from '@sebgroup/green-core/components/datepicker/index.js';
@@ -440,7 +440,9 @@ var AccordionItem = function AccordionItem(_ref) {
440
440
  var labelElementLevel = item.labelElementLevel,
441
441
  label = item.label,
442
442
  subLabel = item.subLabel,
443
- content = item.content;
443
+ content = item.content,
444
+ customLabel = item.customLabel;
445
+ var contentRef = useRef(null);
444
446
  var _useState = useState(item.defaultOpen || false),
445
447
  _useState2 = _slicedToArray(_useState, 2),
446
448
  isOpen = _useState2[0],
@@ -450,6 +452,13 @@ var AccordionItem = function AccordionItem(_ref) {
450
452
  setIsOpen(function (state) {
451
453
  if (!state) {
452
454
  item.onOpen && item.onOpen(event);
455
+ window.requestAnimationFrame(function () {
456
+ var _a;
457
+ (_a = contentRef.current) === null || _a === void 0 ? void 0 : _a.scrollIntoView({
458
+ behavior: 'smooth',
459
+ block: 'nearest'
460
+ });
461
+ });
453
462
  } else {
454
463
  item.onClose && item.onClose(event);
455
464
  }
@@ -467,7 +476,7 @@ var AccordionItem = function AccordionItem(_ref) {
467
476
  onClick: function onClick(event) {
468
477
  handleOnClick(event);
469
478
  },
470
- children: [jsx("span", {
479
+ children: [customLabel ? customLabel : jsx("span", {
471
480
  children: label
472
481
  }), subLabel && jsx("span", {
473
482
  children: subLabel
@@ -487,6 +496,7 @@ var AccordionItem = function AccordionItem(_ref) {
487
496
  "aria-labelledby": "accordion-item-button-".concat(index, "-").concat(uuid),
488
497
  hidden: !isOpen,
489
498
  children: jsx("div", {
499
+ ref: contentRef,
490
500
  children: content
491
501
  })
492
502
  })]
@@ -943,9 +953,10 @@ var Datepicker = function Datepicker(_a) {
943
953
  value = _a.value,
944
954
  showWeeks = _a.showWeeks,
945
955
  testId = _a.testId,
956
+ validator = _a.validator,
946
957
  selectedDate = _a.selectedDate,
947
958
  currentDate = _a.currentDate,
948
- props = __rest(_a, ["label", "onChange", "minDate", "maxDate", "value", "showWeeks", "testId", "selectedDate", "currentDate"]);
959
+ props = __rest(_a, ["label", "onChange", "minDate", "maxDate", "value", "showWeeks", "testId", "validator", "selectedDate", "currentDate"]);
949
960
  if (currentDate && !value) value = currentDate;
950
961
  if (selectedDate && !value) value = selectedDate;
951
962
  var min = minDate ? minDate : new Date(new Date().getFullYear() - 10, 0, 1);
@@ -955,6 +966,12 @@ var Datepicker = function Datepicker(_a) {
955
966
  onChange(e.detail.value);
956
967
  }
957
968
  };
969
+ var ref = React.useRef(null);
970
+ useEffect(function () {
971
+ if (ref.current) {
972
+ ref.current.validator = validator;
973
+ }
974
+ }, [validator]);
958
975
  return jsx("div", {
959
976
  className: "form-group",
960
977
  children: jsx(CoreDatepicker, Object.assign({
@@ -964,9 +981,8 @@ var Datepicker = function Datepicker(_a) {
964
981
  max: max,
965
982
  showWeekNumbers: showWeeks,
966
983
  onchange: onChangeHandler,
967
- size: props.size,
968
984
  value: value,
969
- hideLabel: props.hideLabel
985
+ ref: ref
970
986
  }, props))
971
987
  });
972
988
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sebgroup/green-react",
3
- "version": "3.10.0",
3
+ "version": "3.12.0",
4
4
  "peerDependencies": {
5
5
  "react": "^17 || ^18",
6
6
  "react-dom": "^17 || ^18"
@@ -1,11 +1,12 @@
1
- import React from 'react';
1
+ import React, { ReactNode } from 'react';
2
2
  interface AccordionItemProps {
3
3
  item: AccordionItemInterface;
4
4
  index: number;
5
5
  uuid: string;
6
6
  }
7
7
  export interface AccordionItemInterface {
8
- label: string;
8
+ label?: string;
9
+ customLabel?: ReactNode;
9
10
  labelElementLevel: 2 | 3 | 4 | 5 | 6;
10
11
  subLabel?: string;
11
12
  content: JSX.Element;
@@ -1,55 +1,78 @@
1
1
  import { GdsDatepicker } from '@sebgroup/green-core/components/datepicker/index.js';
2
+ import { GdsValidator } from '@sebgroup/green-core/components/form/form-control';
2
3
  export declare const CoreDatepicker: import("@lit/react").ReactWebComponent<GdsDatepicker, {
3
4
  onchange: string;
4
5
  }>;
5
- export interface DatepickerOptions {
6
+ export type DatepickerOptions = {
6
7
  /**
7
- * The label for the Datepicker.
8
+ * An array of dates that should be disabled in the calendar.
8
9
  */
9
- label?: string;
10
+ disabledDates?: Date[];
10
11
  /**
11
- * Callback function that is called when the value of the Datepicker changes.
12
+ * Whether to disable weekends in the calendar.
12
13
  */
13
- onChange?: (value: any) => void;
14
+ disabledWeekends: boolean;
14
15
  /**
15
- * The minimum date that can be selected.
16
+ * Whether to hide the label above the input field.
16
17
  */
17
- minDate?: Date;
18
+ hideLabel: boolean;
19
+ /**
20
+ * Validation state of the form control. Setting this to true triggers the invalid state of the control.
21
+ */
22
+ invalid: boolean;
23
+ /**
24
+ * Validate the form control element. Should return the validity state and an optional validation message.
25
+ */
26
+ validator: GdsValidator;
27
+ /**
28
+ * The label text displayed above the datepicker. This should always be set to a descriptive label.
29
+ */
30
+ label: string;
18
31
  /**
19
32
  * The maximum date that can be selected.
20
33
  */
21
- maxDate?: Date;
34
+ maxDate: Date;
22
35
  /**
23
- * The value of the Datepicker.
36
+ * The minimum date that can be selected.
24
37
  */
25
- value?: Date;
38
+ minDate: Date;
26
39
  /**
27
- * Whether to show the week numbers.
40
+ * Controls whether the datepicker popover is open.
28
41
  */
29
- showWeeks?: boolean;
42
+ open: boolean;
30
43
  /**
31
- * The test ID used for testing.
44
+ * Callback function that is called when the value of the Datepicker changes.
32
45
  */
33
- testId?: string;
46
+ onChange?: (value: any) => void;
34
47
  /**
35
- * The size of the Datepicker.
48
+ * Sets the datepicker as a required field for forms.
36
49
  */
37
- size?: 'small' | 'medium';
50
+ required: boolean;
38
51
  /**
39
- * Whether to hide the label.
52
+ * Whether to show a column of week numbers in the calendar.
40
53
  */
41
- hideLabel?: boolean;
54
+ showWeeks: boolean;
42
55
  /**
43
- * Whether to disable weekends.
56
+ * Whether to use the small variant of the datepicker field.
44
57
  */
45
- disabledWeekends?: boolean;
58
+ size: 'small' | 'medium';
46
59
  /**
47
- * An array of disabled dates.
60
+ * The test ID used for testing.
61
+ */
62
+ testId?: string;
63
+ /**
64
+ * The Date value of the datepicker. This can be set to undefined to clear the datepicker.
65
+ * This can be a string if set via the value attribute in markup, or via the setAttribute DOM API.
66
+ */
67
+ value?: Date;
68
+ /**
69
+ * @deprecated Use `value` instead.
48
70
  */
49
- disabledDates?: Date[];
50
- /** @deprecated Use `value` instead */
51
71
  selectedDate?: Date;
52
- /** @deprecated Use `value` instead */
72
+ /**
73
+ * @deprecated Use `value` instead.
74
+ */
53
75
  currentDate?: Date;
54
- }
55
- export declare const Datepicker: ({ label, onChange, minDate, maxDate, value, showWeeks, testId, selectedDate, currentDate, ...props }: DatepickerOptions) => import("react/jsx-runtime").JSX.Element;
76
+ };
77
+ export declare const Datepicker: ({ label, onChange, minDate, maxDate, value, showWeeks, testId, validator, selectedDate, currentDate, ...props }: DatepickerOptions) => import("react/jsx-runtime").JSX.Element;
78
+ export default Datepicker;