@autoguru/overdrive 4.26.2 → 4.26.4

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 +1 @@
1
- {"version":3,"file":"EditableText.d.ts","sourceRoot":"","sources":["../../../lib/components/EditableText/EditableText.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EACN,cAAc,EAEd,mBAAmB,EAInB,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAiB,MAAM,SAAS,CAAC;AAK9C,KAAK,QAAQ,GAAG,IAAI,CACnB,cAAc,CAAC,OAAO,GAAG,CAAC,EAC1B,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,WAAW,CAC9C,CAAC;AACF,KAAK,SAAS,GAAG,IAAI,CACpB,cAAc,CAAC,OAAO,IAAI,CAAC,EAC3B,IAAI,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU,GAAG,QAAQ,CAChD,CAAC;AACF,KAAK,UAAU,GAAG,IAAI,CACrB,mBAAmB,CAAC,gBAAgB,CAAC,EACnC,OAAO,GACP,IAAI,GACJ,WAAW,GACX,OAAO,GACP,QAAQ,GACR,SAAS,GACT,QAAQ,GACR,WAAW,GACX,MAAM,SAAS,GACf,MAAM,QAAQ,CAChB,CAAC;AAEF,MAAM,WAAW,KAAM,SAAQ,SAAS,EAAE,UAAU,EAAE,QAAQ;IAC7D,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;CACzC;AAED,KAAK,SAAS,GAAG,MAAM,GAAG,OAAO,CAAC;AAClC,eAAO,MAAM,YAAY,iFAuFxB,CAAC;AAEF,eAAe,YAAY,CAAC"}
1
+ {"version":3,"file":"EditableText.d.ts","sourceRoot":"","sources":["../../../lib/components/EditableText/EditableText.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAEN,cAAc,EAEd,mBAAmB,EAKnB,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAiB,MAAM,SAAS,CAAC;AAK9C,KAAK,QAAQ,GAAG,IAAI,CACnB,cAAc,CAAC,OAAO,GAAG,CAAC,EAC1B,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,WAAW,CAC9C,CAAC;AACF,KAAK,SAAS,GAAG,IAAI,CACpB,cAAc,CAAC,OAAO,IAAI,CAAC,EAC3B,IAAI,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU,GAAG,QAAQ,CAChD,CAAC;AACF,KAAK,UAAU,GAAG,IAAI,CACrB,mBAAmB,CAAC,gBAAgB,CAAC,EACnC,OAAO,GACP,IAAI,GACJ,WAAW,GACX,OAAO,GACP,QAAQ,GACR,SAAS,GACT,QAAQ,GACR,WAAW,GACX,MAAM,SAAS,GACf,MAAM,QAAQ,CAChB,CAAC;AAEF,MAAM,WAAW,KAAM,SAAQ,SAAS,EAAE,UAAU,EAAE,QAAQ;IAC7D,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;CACzC;AAED,KAAK,SAAS,GAAG,MAAM,GAAG,OAAO,CAAC;AAClC,eAAO,MAAM,YAAY,iFAqHxB,CAAC;AAEF,eAAe,YAAY,CAAC"}
@@ -2,19 +2,21 @@
2
2
 
3
3
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
4
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
5
- const _excluded = ["is", "colour", "size", "display", "value", "onFocus", "onBlur", "onKeyDown", "onModeChange", "tabIndex"];
5
+ const _excluded = ["is", "colour", "size", "display", "value", "onFocus", "onBlur", "onKeyDown", "onModeChange", "tabIndex", "onChange", "type"];
6
6
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
7
7
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
8
8
  import clsx from 'clsx';
9
9
  import * as React from 'react';
10
- import { forwardRef, useEffect, useRef, useState } from 'react';
10
+ import { forwardRef, useCallback, useEffect, useRef, useState } from 'react';
11
11
  import { Box } from "../Box/index.js";
12
12
  import { Text, useTextStyles } from "../Text/index.js";
13
13
  import * as inputStyles from "../private/InputBase/withEnhancedInput.css.js";
14
14
  import * as styles from "./EditableText.css.js";
15
15
  import { jsx as _jsx } from "react/jsx-runtime";
16
16
  import { jsxs as _jsxs } from "react/jsx-runtime";
17
+ const numberInputValuePattern = /^\d*\.?\d*$/;
17
18
  export const EditableText = forwardRef((_ref, ref) => {
19
+ var _inputRef$current;
18
20
  let {
19
21
  is,
20
22
  colour = 'muted',
@@ -25,17 +27,32 @@ export const EditableText = forwardRef((_ref, ref) => {
25
27
  onBlur,
26
28
  onKeyDown,
27
29
  onModeChange,
28
- tabIndex = 0
30
+ tabIndex = 0,
31
+ onChange: incomingOnChange,
32
+ type = 'text'
29
33
  } = _ref,
30
34
  inputProps = _objectWithoutProperties(_ref, _excluded);
31
35
  const textRef = useRef(null);
36
+ const inputRef = useRef(null);
32
37
  const [mode, setMode] = useState('TEXT');
38
+ const [inputValue, setInputValue] = useState(value);
33
39
  const onRequestModeChange = newMode => {
34
40
  setMode(newMode);
35
41
  if (typeof onModeChange === 'function') {
36
42
  onModeChange(newMode);
37
43
  }
38
44
  };
45
+ const onChange = useCallback(e => {
46
+ const changeValue = e.currentTarget.value;
47
+ const lastChar = changeValue.charAt(changeValue.length - 1);
48
+ if (type === 'number' && !numberInputValuePattern.test(lastChar)) {
49
+ return;
50
+ }
51
+ if (mode === 'INPUT') {
52
+ setInputValue(changeValue);
53
+ }
54
+ if (typeof incomingOnChange === 'function') incomingOnChange(e);
55
+ }, [incomingOnChange, type]);
39
56
  const textStyles = useTextStyles({
40
57
  is,
41
58
  colour,
@@ -46,7 +63,7 @@ export const EditableText = forwardRef((_ref, ref) => {
46
63
  if (textRef.current) {
47
64
  setWidth(textRef.current.clientWidth);
48
65
  }
49
- }, [textRef.current, value]);
66
+ }, [textRef.current, inputValue]);
50
67
  return _jsxs(Box, {
51
68
  ref: ref,
52
69
  display: display,
@@ -56,6 +73,7 @@ export const EditableText = forwardRef((_ref, ref) => {
56
73
  onClick: () => onRequestModeChange('INPUT'),
57
74
  onFocus: e => {
58
75
  if (typeof onFocus === 'function') onFocus(e);
76
+ setInputValue(value);
59
77
  onRequestModeChange('INPUT');
60
78
  },
61
79
  onBlur: e => {
@@ -72,8 +90,11 @@ export const EditableText = forwardRef((_ref, ref) => {
72
90
  is: "input"
73
91
  }, inputProps), {}, {
74
92
  autoFocus: true,
75
- value: value,
93
+ ref: inputRef,
94
+ type: type !== 'number' ? type : 'text',
95
+ value: inputValue,
76
96
  className: clsx(textStyles, inputStyles.input.itself.root),
97
+ onChange: onChange,
77
98
  style: {
78
99
  width
79
100
  }
@@ -86,7 +107,7 @@ export const EditableText = forwardRef((_ref, ref) => {
86
107
  className: clsx(textStyles, styles.text, {
87
108
  [styles.textHidden]: mode === 'INPUT'
88
109
  }),
89
- children: value
110
+ children: mode === 'INPUT' ? ((_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.value) || value : value
90
111
  })]
91
112
  });
92
113
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autoguru/overdrive",
3
- "version": "4.26.2",
3
+ "version": "4.26.4",
4
4
  "description": "Overdrive is a product component library, and design system for AutoGuru.",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
package/readme.md CHANGED
@@ -16,7 +16,7 @@
16
16
  Overdrive is a product component library and design system for AutoGuru, built
17
17
  with React, TypeScript, Vanilla Extract, and Storybook.
18
18
 
19
- [Storybook playground](http://overdrive.autoguru.io/).
19
+ [Storybook playground](https://overdrive.autoguru.io/).
20
20
 
21
21
  Overdrive is a product component library, and design system for AutoGuru. Built
22
22
  with [React](https://github.com/facebook/react),