@sebgroup/green-react 3.11.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
@@ -953,9 +953,10 @@ var Datepicker = function Datepicker(_a) {
953
953
  value = _a.value,
954
954
  showWeeks = _a.showWeeks,
955
955
  testId = _a.testId,
956
+ validator = _a.validator,
956
957
  selectedDate = _a.selectedDate,
957
958
  currentDate = _a.currentDate,
958
- 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"]);
959
960
  if (currentDate && !value) value = currentDate;
960
961
  if (selectedDate && !value) value = selectedDate;
961
962
  var min = minDate ? minDate : new Date(new Date().getFullYear() - 10, 0, 1);
@@ -965,6 +966,12 @@ var Datepicker = function Datepicker(_a) {
965
966
  onChange(e.detail.value);
966
967
  }
967
968
  };
969
+ var ref = React.useRef(null);
970
+ useEffect(function () {
971
+ if (ref.current) {
972
+ ref.current.validator = validator;
973
+ }
974
+ }, [validator]);
968
975
  return jsx("div", {
969
976
  className: "form-group",
970
977
  children: jsx(CoreDatepicker, Object.assign({
@@ -974,9 +981,8 @@ var Datepicker = function Datepicker(_a) {
974
981
  max: max,
975
982
  showWeekNumbers: showWeeks,
976
983
  onchange: onChangeHandler,
977
- size: props.size,
978
984
  value: value,
979
- hideLabel: props.hideLabel
985
+ ref: ref
980
986
  }, props))
981
987
  });
982
988
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sebgroup/green-react",
3
- "version": "3.11.0",
3
+ "version": "3.12.0",
4
4
  "peerDependencies": {
5
5
  "react": "^17 || ^18",
6
6
  "react-dom": "^17 || ^18"
@@ -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;