@abgov/react-components 4.0.0-alpha.71 → 4.0.0-alpha.73

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,5 +1,6 @@
1
1
  import React, { FC } from 'react';
2
2
  import { GoAIconType } from '../..';
3
+ export declare type GoADate = Date | string;
3
4
  declare type GoAInputType = "text" | "password" | "email" | "number" | "date" | "datetime-local" | "month" | "range" | "search" | "tel" | "time" | "url" | "week";
4
5
  declare type GoAAutoCapitalize = "on" | "off" | "none" | "sentences" | "words" | "characters";
5
6
  interface WCProps {
@@ -55,25 +56,28 @@ interface BaseProps {
55
56
  suffix?: string;
56
57
  testId?: string;
57
58
  }
59
+ declare type OnChange = (name: string, value: string) => void;
58
60
  export interface InputProps extends BaseProps {
59
- onChange: (name: string, value: string) => void;
61
+ onChange: OnChange;
60
62
  value: string;
61
63
  min?: number | string;
62
64
  max?: number | string;
63
65
  step?: number;
64
66
  }
67
+ declare type OnNumberChange = (name: string, value: number) => void;
65
68
  interface NumberInputProps extends BaseProps {
66
- onChange: (name: string, value: number) => void;
69
+ onChange: OnNumberChange;
67
70
  value: number;
68
71
  min?: number;
69
72
  max?: number;
70
73
  step?: number;
71
74
  }
75
+ declare type OnDateChange = (name: string, value: GoADate) => void;
72
76
  interface DateInputProps extends BaseProps {
73
- onChange: (name: string, value: Date) => void;
74
- value: string | Date;
75
- min?: string | Date;
76
- max?: string | Date;
77
+ onChange: OnDateChange;
78
+ value: GoADate;
79
+ min?: GoADate;
80
+ max?: GoADate;
77
81
  step?: number;
78
82
  }
79
83
  export declare const GoAInput: FC<InputProps & {
@@ -82,7 +86,7 @@ export declare const GoAInput: FC<InputProps & {
82
86
  export declare const GoAInputText: FC<InputProps>;
83
87
  export declare const GoAInputPassword: FC<InputProps>;
84
88
  export declare const GoAInputDate: FC<DateInputProps>;
85
- export declare const GoAInputTime: FC<DateInputProps>;
89
+ export declare const GoAInputTime: FC<InputProps>;
86
90
  export declare const GoAInputDateTime: FC<DateInputProps>;
87
91
  export declare const GoAInputEmail: FC<InputProps>;
88
92
  export declare const GoAInputSearch: FC<InputProps>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abgov/react-components",
3
- "version": "4.0.0-alpha.71",
3
+ "version": "4.0.0-alpha.73",
4
4
  "description": "Government of Alberta - UI components for React",
5
5
  "bugs": {
6
6
  "url": "https://github.com/GovAlta/ui-components/issues"
@@ -7432,7 +7432,7 @@ function instance$h($$self, $$props, $$invalidate) {
7432
7432
  class FormItem extends SvelteElement {
7433
7433
  constructor(options) {
7434
7434
  super();
7435
- this.shadowRoot.innerHTML = `<style>:host{box-sizing:border-box;font-family:var(--font-family)}*{box-sizing:border-box}.label{display:block;font-weight:var(--fw-bold);color:var(--goa-color-text);font-size:var(--fs-base);padding:0.5rem 0;overflow-x:hidden;white-space:nowrap;text-overflow:ellipsis}.label em{color:var(--color-gray-600);font-weight:var(--fw-regular);font-size:var(--fs-sm);line-height:var(--lh-sm);font-style:normal}.form-item-input{margin-bottom:0.25rem}.help-msg{font-size:var(--fs-sm);color:var(--goa-color-text);margin-right:56px}.error-msg{font-size:var(--fs-sm);color:var(--goa-color-interactive--error);margin-bottom:0.25rem}</style>`;
7435
+ this.shadowRoot.innerHTML = `<style>:host{box-sizing:border-box;font-family:var(--font-family)}*{box-sizing:border-box}.label{display:block;font-weight:var(--fw-bold);color:var(--goa-color-text);font-size:var(--fs-base);padding:0.5rem 0}.label em{color:var(--color-gray-600);font-weight:var(--fw-regular);font-size:var(--fs-sm);line-height:var(--lh-sm);font-style:normal}.form-item-input{margin-bottom:0.25rem}.help-msg{font-size:var(--fs-sm);color:var(--goa-color-text);margin-right:56px}.error-msg{font-size:var(--fs-sm);color:var(--goa-color-interactive--error);margin-bottom:0.25rem}</style>`;
7436
7436
  init(this, {
7437
7437
  target: this.shadowRoot,
7438
7438
  props: attribute_to_object(this.attributes),
@@ -14839,6 +14839,45 @@ const GoAInput = ({
14839
14839
  handletrailingiconclick: !!onTrailingIconClick
14840
14840
  }, void 0);
14841
14841
  };
14842
+
14843
+ const onDateChangeHandler = onChange => {
14844
+ return (name, value) => {
14845
+ if (!value) {
14846
+ onChange(name, new Date(0));
14847
+ return;
14848
+ }
14849
+
14850
+ onChange(name, parseISO(value));
14851
+ };
14852
+ };
14853
+
14854
+ const onTimeChangeHandler = onChange => {
14855
+ return (name, value) => {
14856
+ if (!value) {
14857
+ onChange(name, "");
14858
+ return;
14859
+ }
14860
+
14861
+ onChange(name, value);
14862
+ };
14863
+ };
14864
+
14865
+ function toString(value, tmpl = "yyyy-MM-dd") {
14866
+ if (!value) {
14867
+ return "";
14868
+ }
14869
+
14870
+ if (typeof value === "string") {
14871
+ return format(parseISO(value), tmpl);
14872
+ }
14873
+
14874
+ if (value.toISOString() === new Date(0).toISOString()) {
14875
+ return "";
14876
+ }
14877
+
14878
+ return format(value, tmpl);
14879
+ }
14880
+
14842
14881
  const GoAInputText = props => {
14843
14882
  return jsx(GoAInput, Object.assign({}, props, {
14844
14883
  type: "text"
@@ -14857,26 +14896,12 @@ const GoAInputDate = _a => {
14857
14896
  } = _a,
14858
14897
  props = __rest(_a, ["value", "min", "max"]);
14859
14898
 
14860
- const _format = value => {
14861
- return format(value, "yyyy-MM-dd");
14862
- };
14863
-
14864
- const _value = _format(typeof value === "string" ? parseISO(value) : value);
14865
-
14866
- const _min = min && _format(typeof min === "string" ? parseISO(min) : min);
14867
-
14868
- const _max = max && _format(typeof max === "string" ? parseISO(max) : max);
14869
-
14870
- const onDateChange = (name, value) => {
14871
- props.onChange(name, parseISO(value));
14872
- };
14873
-
14874
14899
  return jsx(GoAInput, Object.assign({}, props, {
14875
- onChange: onDateChange,
14876
- min: _min,
14877
- max: _max,
14878
- value: _value,
14879
- type: "date"
14900
+ type: "date",
14901
+ onChange: onDateChangeHandler(props.onChange),
14902
+ min: toString(min),
14903
+ max: toString(max),
14904
+ value: toString(value)
14880
14905
  }), void 0);
14881
14906
  };
14882
14907
  const GoAInputTime = _a => {
@@ -14887,24 +14912,11 @@ const GoAInputTime = _a => {
14887
14912
  } = _a,
14888
14913
  props = __rest(_a, ["value", "min", "max"]);
14889
14914
 
14890
- const onDateChange = (name, value) => {
14891
- props.onChange(name, parseISO(value));
14892
- };
14893
-
14894
- try {
14895
- const d = typeof value === "string" ? parseISO(value) : value;
14896
- return jsx(GoAInput, Object.assign({}, props, {
14897
- onChange: onDateChange,
14898
- value: format(d, "hh:mm"),
14899
- type: "time"
14900
- }), void 0);
14901
- } catch (e) {
14902
- return jsx(GoAInput, Object.assign({}, props, {
14903
- onChange: onDateChange,
14904
- value: value,
14905
- type: "time"
14906
- }), void 0);
14907
- }
14915
+ return jsx(GoAInput, Object.assign({}, props, {
14916
+ onChange: onTimeChangeHandler(props.onChange),
14917
+ value: value,
14918
+ type: "time"
14919
+ }), void 0);
14908
14920
  };
14909
14921
  const GoAInputDateTime = _a => {
14910
14922
  var {
@@ -14914,15 +14926,9 @@ const GoAInputDateTime = _a => {
14914
14926
  } = _a,
14915
14927
  props = __rest(_a, ["value", "min", "max"]);
14916
14928
 
14917
- const d = typeof value === "string" ? parseISO(value) : value;
14918
-
14919
- const onDateChange = (name, value) => {
14920
- props.onChange(name, parseISO(value));
14921
- };
14922
-
14923
14929
  return jsx(GoAInput, Object.assign({}, props, {
14924
- onChange: onDateChange,
14925
- value: format(d, "yyyy-MM-dd'T'hh:mm"),
14930
+ onChange: onDateChangeHandler(props.onChange),
14931
+ value: toString(value, "yyyy-MM-dd'T'hh:mm"),
14926
14932
  type: "datetime-local"
14927
14933
  }), void 0);
14928
14934
  };
@@ -7479,7 +7479,7 @@
7479
7479
  class FormItem extends SvelteElement {
7480
7480
  constructor(options) {
7481
7481
  super();
7482
- this.shadowRoot.innerHTML = `<style>:host{box-sizing:border-box;font-family:var(--font-family)}*{box-sizing:border-box}.label{display:block;font-weight:var(--fw-bold);color:var(--goa-color-text);font-size:var(--fs-base);padding:0.5rem 0;overflow-x:hidden;white-space:nowrap;text-overflow:ellipsis}.label em{color:var(--color-gray-600);font-weight:var(--fw-regular);font-size:var(--fs-sm);line-height:var(--lh-sm);font-style:normal}.form-item-input{margin-bottom:0.25rem}.help-msg{font-size:var(--fs-sm);color:var(--goa-color-text);margin-right:56px}.error-msg{font-size:var(--fs-sm);color:var(--goa-color-interactive--error);margin-bottom:0.25rem}</style>`;
7482
+ this.shadowRoot.innerHTML = `<style>:host{box-sizing:border-box;font-family:var(--font-family)}*{box-sizing:border-box}.label{display:block;font-weight:var(--fw-bold);color:var(--goa-color-text);font-size:var(--fs-base);padding:0.5rem 0}.label em{color:var(--color-gray-600);font-weight:var(--fw-regular);font-size:var(--fs-sm);line-height:var(--lh-sm);font-style:normal}.form-item-input{margin-bottom:0.25rem}.help-msg{font-size:var(--fs-sm);color:var(--goa-color-text);margin-right:56px}.error-msg{font-size:var(--fs-sm);color:var(--goa-color-interactive--error);margin-bottom:0.25rem}</style>`;
7483
7483
  init(this, {
7484
7484
  target: this.shadowRoot,
7485
7485
  props: attribute_to_object(this.attributes),
@@ -14885,6 +14885,49 @@
14885
14885
  handletrailingiconclick: !!onTrailingIconClick
14886
14886
  }, void 0);
14887
14887
  };
14888
+
14889
+ var onDateChangeHandler = function onDateChangeHandler(onChange) {
14890
+ return function (name, value) {
14891
+ if (!value) {
14892
+ onChange(name, new Date(0));
14893
+ return;
14894
+ }
14895
+
14896
+ onChange(name, dateFns.parseISO(value));
14897
+ };
14898
+ };
14899
+
14900
+ var onTimeChangeHandler = function onTimeChangeHandler(onChange) {
14901
+ return function (name, value) {
14902
+ if (!value) {
14903
+ onChange(name, "");
14904
+ return;
14905
+ }
14906
+
14907
+ onChange(name, value);
14908
+ };
14909
+ };
14910
+
14911
+ function toString(value, tmpl) {
14912
+ if (tmpl === void 0) {
14913
+ tmpl = "yyyy-MM-dd";
14914
+ }
14915
+
14916
+ if (!value) {
14917
+ return "";
14918
+ }
14919
+
14920
+ if (typeof value === "string") {
14921
+ return dateFns.format(dateFns.parseISO(value), tmpl);
14922
+ }
14923
+
14924
+ if (value.toISOString() === new Date(0).toISOString()) {
14925
+ return "";
14926
+ }
14927
+
14928
+ return dateFns.format(value, tmpl);
14929
+ }
14930
+
14888
14931
  var GoAInputText = function GoAInputText(props) {
14889
14932
  return jsxRuntime.jsx(GoAInput, __assign({}, props, {
14890
14933
  type: "text"
@@ -14903,26 +14946,12 @@
14903
14946
  max = _c === void 0 ? "" : _c,
14904
14947
  props = __rest(_a, ["value", "min", "max"]);
14905
14948
 
14906
- var _format = function _format(value) {
14907
- return dateFns.format(value, "yyyy-MM-dd");
14908
- };
14909
-
14910
- var _value = _format(typeof value === "string" ? dateFns.parseISO(value) : value);
14911
-
14912
- var _min = min && _format(typeof min === "string" ? dateFns.parseISO(min) : min);
14913
-
14914
- var _max = max && _format(typeof max === "string" ? dateFns.parseISO(max) : max);
14915
-
14916
- var onDateChange = function onDateChange(name, value) {
14917
- props.onChange(name, dateFns.parseISO(value));
14918
- };
14919
-
14920
14949
  return jsxRuntime.jsx(GoAInput, __assign({}, props, {
14921
- onChange: onDateChange,
14922
- min: _min,
14923
- max: _max,
14924
- value: _value,
14925
- type: "date"
14950
+ type: "date",
14951
+ onChange: onDateChangeHandler(props.onChange),
14952
+ min: toString(min),
14953
+ max: toString(max),
14954
+ value: toString(value)
14926
14955
  }), void 0);
14927
14956
  };
14928
14957
  var GoAInputTime = function GoAInputTime(_a) {
@@ -14931,24 +14960,11 @@
14931
14960
  _a.max;
14932
14961
  var props = __rest(_a, ["value", "min", "max"]);
14933
14962
 
14934
- var onDateChange = function onDateChange(name, value) {
14935
- props.onChange(name, dateFns.parseISO(value));
14936
- };
14937
-
14938
- try {
14939
- var d = typeof value === "string" ? dateFns.parseISO(value) : value;
14940
- return jsxRuntime.jsx(GoAInput, __assign({}, props, {
14941
- onChange: onDateChange,
14942
- value: dateFns.format(d, "hh:mm"),
14943
- type: "time"
14944
- }), void 0);
14945
- } catch (e) {
14946
- return jsxRuntime.jsx(GoAInput, __assign({}, props, {
14947
- onChange: onDateChange,
14948
- value: value,
14949
- type: "time"
14950
- }), void 0);
14951
- }
14963
+ return jsxRuntime.jsx(GoAInput, __assign({}, props, {
14964
+ onChange: onTimeChangeHandler(props.onChange),
14965
+ value: value,
14966
+ type: "time"
14967
+ }), void 0);
14952
14968
  };
14953
14969
  var GoAInputDateTime = function GoAInputDateTime(_a) {
14954
14970
  var value = _a.value;
@@ -14956,15 +14972,9 @@
14956
14972
  _a.max;
14957
14973
  var props = __rest(_a, ["value", "min", "max"]);
14958
14974
 
14959
- var d = typeof value === "string" ? dateFns.parseISO(value) : value;
14960
-
14961
- var onDateChange = function onDateChange(name, value) {
14962
- props.onChange(name, dateFns.parseISO(value));
14963
- };
14964
-
14965
14975
  return jsxRuntime.jsx(GoAInput, __assign({}, props, {
14966
- onChange: onDateChange,
14967
- value: dateFns.format(d, "yyyy-MM-dd'T'hh:mm"),
14976
+ onChange: onDateChangeHandler(props.onChange),
14977
+ value: toString(value, "yyyy-MM-dd'T'hh:mm"),
14968
14978
  type: "datetime-local"
14969
14979
  }), void 0);
14970
14980
  };