@abgov/react-components 4.0.0-alpha.64 → 4.0.0-alpha.65

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,6 +1,6 @@
1
1
  import React, { FC } from 'react';
2
2
  import { GoAIconType } from '../..';
3
- declare type GoAInputType = "text" | "number" | "password" | "email" | "date" | "datetime-local" | "month" | "range" | "search" | "tel" | "time" | "url" | "week";
3
+ declare type GoAInputType = "text" | "password" | "email" | "number" | "date" | "datetime-local" | "month" | "range" | "search" | "tel" | "time" | "url" | "week";
4
4
  declare type GoAAutoCapitalize = "on" | "off" | "none" | "sentences" | "words" | "characters";
5
5
  interface WCProps {
6
6
  ref?: React.MutableRefObject<HTMLInputElement | null>;
@@ -24,8 +24,8 @@ interface WCProps {
24
24
  prefix?: string;
25
25
  suffix?: string;
26
26
  testid?: string;
27
- min?: string;
28
- max?: string;
27
+ min?: string | number;
28
+ max?: string | number;
29
29
  step?: number;
30
30
  }
31
31
  declare global {
@@ -35,10 +35,8 @@ declare global {
35
35
  }
36
36
  }
37
37
  }
38
- export interface InputProps {
38
+ interface BaseProps {
39
39
  name: string;
40
- value: string;
41
- onChange: (name: string, value: string) => void;
42
40
  id?: string;
43
41
  disabled?: boolean;
44
42
  autoCapitalize?: GoAAutoCapitalize;
@@ -56,8 +54,26 @@ export interface InputProps {
56
54
  prefix?: string;
57
55
  suffix?: string;
58
56
  testId?: string;
59
- min?: string;
60
- max?: string;
57
+ }
58
+ export interface InputProps extends BaseProps {
59
+ onChange: (name: string, value: string) => void;
60
+ value: string;
61
+ min?: number | string;
62
+ max?: number | string;
63
+ step?: number;
64
+ }
65
+ interface NumberInputProps extends BaseProps {
66
+ onChange: (name: string, value: number) => void;
67
+ value: number;
68
+ min?: number;
69
+ max?: number;
70
+ step?: number;
71
+ }
72
+ interface DateInputProps extends BaseProps {
73
+ onChange: (name: string, value: Date) => void;
74
+ value: string | Date;
75
+ min?: string | Date;
76
+ max?: string | Date;
61
77
  step?: number;
62
78
  }
63
79
  export declare const GoAInput: FC<InputProps & {
@@ -65,25 +81,15 @@ export declare const GoAInput: FC<InputProps & {
65
81
  }>;
66
82
  export declare const GoAInputText: FC<InputProps>;
67
83
  export declare const GoAInputPassword: FC<InputProps>;
68
- export declare const GoAInputDate: FC<Omit<InputProps, "value"> & {
69
- value: Date | string;
70
- }>;
71
- export declare const GoAInputTime: FC<Omit<InputProps, "value"> & {
72
- value: Date | string;
73
- }>;
74
- export declare const GoAInputDateTime: FC<Omit<InputProps, "value"> & {
75
- value: Date;
76
- }>;
84
+ export declare const GoAInputDate: FC<DateInputProps>;
85
+ export declare const GoAInputTime: FC<DateInputProps>;
86
+ export declare const GoAInputDateTime: FC<DateInputProps>;
77
87
  export declare const GoAInputEmail: FC<InputProps>;
78
88
  export declare const GoAInputSearch: FC<InputProps>;
79
89
  export declare const GoAInputUrl: FC<InputProps>;
80
90
  export declare const GoAInputTel: FC<InputProps>;
81
91
  export declare const GoAInputFile: FC<InputProps>;
82
92
  export declare const GoAInputMonth: FC<InputProps>;
83
- export declare const GoAInputNumber: FC<Omit<InputProps, "value" | "min" | "max"> & {
84
- value: number;
85
- min?: number;
86
- max?: number;
87
- }>;
93
+ export declare const GoAInputNumber: FC<NumberInputProps>;
88
94
  export declare const GoAInputRange: FC<InputProps>;
89
95
  export default GoAInput;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abgov/react-components",
3
- "version": "4.0.0-alpha.64",
3
+ "version": "4.0.0-alpha.65",
4
4
  "description": "Government of Alberta - UI components for React",
5
5
  "bugs": {
6
6
  "url": "https://github.com/GovAlta/ui-components/issues"
@@ -1,6 +1,6 @@
1
1
  import { jsx, jsxs } from 'react/jsx-runtime';
2
2
  import { useRef, useEffect } from 'react';
3
- import { format } from 'date-fns';
3
+ import { parseISO, format } from 'date-fns';
4
4
 
5
5
  function noop() {}
6
6
 
@@ -14828,38 +14828,55 @@ const GoAInputPassword = props => {
14828
14828
  const GoAInputDate = _a => {
14829
14829
  var {
14830
14830
  value,
14831
- min,
14832
- max
14831
+ min = "",
14832
+ max = ""
14833
14833
  } = _a,
14834
14834
  props = __rest(_a, ["value", "min", "max"]);
14835
14835
 
14836
- const _value = typeof value === "string" ? new Date(value) : value;
14836
+ const _format = value => {
14837
+ return format(value, "yyyy-MM-dd");
14838
+ };
14839
+
14840
+ const _value = _format(typeof value === "string" ? parseISO(value) : value);
14837
14841
 
14838
- const _min = min ? format(new Date(min), "yyyy-MM-dd") : "";
14842
+ const _min = min && _format(typeof min === "string" ? parseISO(min) : min);
14839
14843
 
14840
- const _max = max ? format(new Date(max), "yyyy-MM-dd") : "";
14844
+ const _max = max && _format(typeof max === "string" ? parseISO(max) : max);
14845
+
14846
+ const onDateChange = (name, value) => {
14847
+ props.onChange(name, parseISO(value));
14848
+ };
14841
14849
 
14842
14850
  return jsx(GoAInput, Object.assign({}, props, {
14851
+ onChange: onDateChange,
14843
14852
  min: _min,
14844
14853
  max: _max,
14845
- value: format(_value, "yyyy-MM-dd"),
14854
+ value: _value,
14846
14855
  type: "date"
14847
14856
  }), void 0);
14848
14857
  };
14849
14858
  const GoAInputTime = _a => {
14850
14859
  var {
14851
- value
14860
+ value,
14861
+ min = "",
14862
+ max = ""
14852
14863
  } = _a,
14853
- props = __rest(_a, ["value"]);
14864
+ props = __rest(_a, ["value", "min", "max"]);
14865
+
14866
+ const onDateChange = (name, value) => {
14867
+ props.onChange(name, parseISO(value));
14868
+ };
14854
14869
 
14855
14870
  try {
14856
- const d = typeof value === "string" ? new Date(value) : value;
14871
+ const d = typeof value === "string" ? parseISO(value) : value;
14857
14872
  return jsx(GoAInput, Object.assign({}, props, {
14873
+ onChange: onDateChange,
14858
14874
  value: format(d, "hh:mm"),
14859
14875
  type: "time"
14860
14876
  }), void 0);
14861
14877
  } catch (e) {
14862
14878
  return jsx(GoAInput, Object.assign({}, props, {
14879
+ onChange: onDateChange,
14863
14880
  value: value,
14864
14881
  type: "time"
14865
14882
  }), void 0);
@@ -14867,12 +14884,20 @@ const GoAInputTime = _a => {
14867
14884
  };
14868
14885
  const GoAInputDateTime = _a => {
14869
14886
  var {
14870
- value
14887
+ value,
14888
+ min = "",
14889
+ max = ""
14871
14890
  } = _a,
14872
- props = __rest(_a, ["value"]);
14891
+ props = __rest(_a, ["value", "min", "max"]);
14892
+
14893
+ const d = typeof value === "string" ? parseISO(value) : value;
14894
+
14895
+ const onDateChange = (name, value) => {
14896
+ props.onChange(name, parseISO(value));
14897
+ };
14873
14898
 
14874
- const d = typeof value === "string" ? new Date(value) : value;
14875
14899
  return jsx(GoAInput, Object.assign({}, props, {
14900
+ onChange: onDateChange,
14876
14901
  value: format(d, "yyyy-MM-dd'T'hh:mm"),
14877
14902
  type: "datetime-local"
14878
14903
  }), void 0);
@@ -14916,13 +14941,18 @@ const GoAInputMonth = props => {
14916
14941
  };
14917
14942
  const GoAInputNumber = _a => {
14918
14943
  var {
14919
- min,
14920
- max,
14944
+ min = Number.MIN_VALUE,
14945
+ max = Number.MAX_VALUE,
14921
14946
  value
14922
14947
  } = _a,
14923
14948
  props = __rest(_a, ["min", "max", "value"]);
14924
14949
 
14950
+ const onNumberChange = (name, value) => {
14951
+ props.onChange(name, parseInt(value));
14952
+ };
14953
+
14925
14954
  return jsx(GoAInput, Object.assign({}, props, {
14955
+ onChange: onNumberChange,
14926
14956
  min: min === null || min === void 0 ? void 0 : min.toString(),
14927
14957
  max: max === null || max === void 0 ? void 0 : max.toString(),
14928
14958
  value: value.toString(),
@@ -14873,46 +14873,73 @@
14873
14873
  };
14874
14874
  var GoAInputDate = function GoAInputDate(_a) {
14875
14875
  var value = _a.value,
14876
- min = _a.min,
14877
- max = _a.max,
14876
+ _b = _a.min,
14877
+ min = _b === void 0 ? "" : _b,
14878
+ _c = _a.max,
14879
+ max = _c === void 0 ? "" : _c,
14878
14880
  props = __rest(_a, ["value", "min", "max"]);
14879
14881
 
14880
- var _value = typeof value === "string" ? new Date(value) : value;
14882
+ var _format = function _format(value) {
14883
+ return dateFns.format(value, "yyyy-MM-dd");
14884
+ };
14885
+
14886
+ var _value = _format(typeof value === "string" ? dateFns.parseISO(value) : value);
14881
14887
 
14882
- var _min = min ? dateFns.format(new Date(min), "yyyy-MM-dd") : "";
14888
+ var _min = min && _format(typeof min === "string" ? dateFns.parseISO(min) : min);
14883
14889
 
14884
- var _max = max ? dateFns.format(new Date(max), "yyyy-MM-dd") : "";
14890
+ var _max = max && _format(typeof max === "string" ? dateFns.parseISO(max) : max);
14891
+
14892
+ var onDateChange = function onDateChange(name, value) {
14893
+ props.onChange(name, dateFns.parseISO(value));
14894
+ };
14885
14895
 
14886
14896
  return jsxRuntime.jsx(GoAInput, __assign({}, props, {
14897
+ onChange: onDateChange,
14887
14898
  min: _min,
14888
14899
  max: _max,
14889
- value: dateFns.format(_value, "yyyy-MM-dd"),
14900
+ value: _value,
14890
14901
  type: "date"
14891
14902
  }), void 0);
14892
14903
  };
14893
14904
  var GoAInputTime = function GoAInputTime(_a) {
14894
- var value = _a.value,
14895
- props = __rest(_a, ["value"]);
14905
+ var value = _a.value;
14906
+ _a.min;
14907
+ _a.max;
14908
+ var props = __rest(_a, ["value", "min", "max"]);
14909
+
14910
+ var onDateChange = function onDateChange(name, value) {
14911
+ props.onChange(name, dateFns.parseISO(value));
14912
+ };
14896
14913
 
14897
14914
  try {
14898
- var d = typeof value === "string" ? new Date(value) : value;
14915
+ var d = typeof value === "string" ? dateFns.parseISO(value) : value;
14899
14916
  return jsxRuntime.jsx(GoAInput, __assign({}, props, {
14917
+ onChange: onDateChange,
14900
14918
  value: dateFns.format(d, "hh:mm"),
14901
14919
  type: "time"
14902
14920
  }), void 0);
14903
14921
  } catch (e) {
14904
14922
  return jsxRuntime.jsx(GoAInput, __assign({}, props, {
14923
+ onChange: onDateChange,
14905
14924
  value: value,
14906
14925
  type: "time"
14907
14926
  }), void 0);
14908
14927
  }
14909
14928
  };
14910
14929
  var GoAInputDateTime = function GoAInputDateTime(_a) {
14911
- var value = _a.value,
14912
- props = __rest(_a, ["value"]);
14930
+ var value = _a.value;
14931
+ _a.min;
14932
+ _a.max;
14933
+ var props = __rest(_a, ["value", "min", "max"]);
14934
+
14935
+ var d = typeof value === "string" ? dateFns.parseISO(value) : value;
14936
+
14937
+ var onDateChange = function onDateChange(name, value) {
14938
+ props.onChange(name, dateFns.parseISO(value));
14939
+ };
14913
14940
 
14914
- var d = typeof value === "string" ? new Date(value) : value;
14915
14941
  return jsxRuntime.jsx(GoAInput, __assign({}, props, {
14942
+ onChange: onDateChange,
14916
14943
  value: dateFns.format(d, "yyyy-MM-dd'T'hh:mm"),
14917
14944
  type: "datetime-local"
14918
14945
  }), void 0);
@@ -14957,12 +14984,19 @@
14957
14984
  }), void 0);
14958
14985
  };
14959
14986
  var GoAInputNumber = function GoAInputNumber(_a) {
14960
- var min = _a.min,
14961
- max = _a.max,
14987
+ var _b = _a.min,
14988
+ min = _b === void 0 ? Number.MIN_VALUE : _b,
14989
+ _c = _a.max,
14990
+ max = _c === void 0 ? Number.MAX_VALUE : _c,
14962
14991
  value = _a.value,
14963
14992
  props = __rest(_a, ["min", "max", "value"]);
14964
14993
 
14994
+ var onNumberChange = function onNumberChange(name, value) {
14995
+ props.onChange(name, parseInt(value));
14996
+ };
14997
+
14965
14998
  return jsxRuntime.jsx(GoAInput, __assign({}, props, {
14999
+ onChange: onNumberChange,
14966
15000
  min: min === null || min === void 0 ? void 0 : min.toString(),
14967
15001
  max: max === null || max === void 0 ? void 0 : max.toString(),
14968
15002
  value: value.toString(),