@autoguru/overdrive 4.23.4 → 4.23.6
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,12 +1,15 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { ComponentProps, InputHTMLAttributes } from 'react';
|
|
3
|
+
import { Box } from '../Box';
|
|
3
4
|
import { Text } from '../Text';
|
|
4
|
-
type BoxProps = Pick<ComponentProps<typeof
|
|
5
|
-
type TextProps = Pick<ComponentProps<typeof Text>, 'is' | 'colour' | 'size' | '
|
|
6
|
-
type InputProps = Omit<InputHTMLAttributes<HTMLInputElement>, 'style' | 'is' | 'autoFocus' | 'width' | 'height' | keyof TextProps | keyof BoxProps>;
|
|
5
|
+
type BoxProps = Pick<ComponentProps<typeof Box>, 'display' | 'onFocus' | 'onBlur' | 'onKeyDown'>;
|
|
6
|
+
type TextProps = Pick<ComponentProps<typeof Text>, 'is' | 'colour' | 'size' | 'children' | 'noWrap'>;
|
|
7
|
+
type InputProps = Omit<InputHTMLAttributes<HTMLInputElement>, 'style' | 'is' | 'autoFocus' | 'width' | 'height' | 'onFocus' | 'onBlur' | 'onKeyDown' | keyof TextProps | keyof BoxProps>;
|
|
7
8
|
export interface Props extends TextProps, InputProps, BoxProps {
|
|
8
9
|
className?: string;
|
|
10
|
+
onModeChange?: (mode: InputMode) => void;
|
|
9
11
|
}
|
|
12
|
+
type InputMode = 'TEXT' | 'INPUT';
|
|
10
13
|
export declare const EditableText: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLAnchorElement>>;
|
|
11
14
|
export default EditableText;
|
|
12
15
|
//# sourceMappingURL=EditableText.d.ts.map
|
|
@@ -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,
|
|
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,EAAE,cAAc,EAAc,mBAAmB,EAA+B,MAAM,OAAO,CAAC;AAErG,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAiB,MAAM,SAAS,CAAC;AAK9C,KAAK,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,OAAO,GAAG,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,WAAW,CAAC,CAAC;AACjG,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,iFAwFxB,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -2,7 +2,7 @@
|
|
|
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"];
|
|
5
|
+
const _excluded = ["is", "colour", "size", "display", "value", "onFocus", "onBlur", "onKeyDown", "onModeChange"];
|
|
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';
|
|
@@ -20,12 +20,21 @@ export const EditableText = forwardRef((_ref, ref) => {
|
|
|
20
20
|
colour = 'muted',
|
|
21
21
|
size,
|
|
22
22
|
display = 'inlineBlock',
|
|
23
|
-
value
|
|
23
|
+
value,
|
|
24
|
+
onFocus,
|
|
25
|
+
onBlur,
|
|
26
|
+
onKeyDown,
|
|
27
|
+
onModeChange
|
|
24
28
|
} = _ref,
|
|
25
29
|
inputProps = _objectWithoutProperties(_ref, _excluded);
|
|
26
30
|
const textRef = useRef(null);
|
|
27
|
-
const [
|
|
28
|
-
const
|
|
31
|
+
const [mode, setMode] = useState('TEXT');
|
|
32
|
+
const onRequestModeChange = newMode => {
|
|
33
|
+
setMode(newMode);
|
|
34
|
+
if (typeof onModeChange === 'function') {
|
|
35
|
+
onModeChange(newMode);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
29
38
|
const textStyles = useTextStyles({
|
|
30
39
|
is,
|
|
31
40
|
colour,
|
|
@@ -42,15 +51,22 @@ export const EditableText = forwardRef((_ref, ref) => {
|
|
|
42
51
|
display: display,
|
|
43
52
|
position: "relative",
|
|
44
53
|
className: styles.root,
|
|
45
|
-
onClick:
|
|
46
|
-
onFocus:
|
|
47
|
-
|
|
54
|
+
onClick: () => onRequestModeChange('INPUT'),
|
|
55
|
+
onFocus: e => {
|
|
56
|
+
if (typeof onFocus === 'function') onFocus(e);
|
|
57
|
+
onRequestModeChange('INPUT');
|
|
58
|
+
},
|
|
59
|
+
onBlur: e => {
|
|
60
|
+
if (typeof onBlur === 'function') onBlur(e);
|
|
61
|
+
onRequestModeChange('TEXT');
|
|
62
|
+
},
|
|
48
63
|
onKeyDown: e => {
|
|
64
|
+
if (typeof onKeyDown === 'function') onKeyDown(e);
|
|
49
65
|
if (e.key === 'Enter' || e.key === 'Escape') {
|
|
50
|
-
|
|
66
|
+
onRequestModeChange('TEXT');
|
|
51
67
|
}
|
|
52
68
|
},
|
|
53
|
-
children: [
|
|
69
|
+
children: [mode === 'INPUT' && _jsx(Box, _objectSpread(_objectSpread({
|
|
54
70
|
is: "input"
|
|
55
71
|
}, inputProps), {}, {
|
|
56
72
|
autoFocus: true,
|
|
@@ -66,7 +82,7 @@ export const EditableText = forwardRef((_ref, ref) => {
|
|
|
66
82
|
colour: colour,
|
|
67
83
|
size: size,
|
|
68
84
|
className: clsx(textStyles, styles.text, {
|
|
69
|
-
[styles.textHidden]:
|
|
85
|
+
[styles.textHidden]: mode === 'INPUT'
|
|
70
86
|
}),
|
|
71
87
|
children: value
|
|
72
88
|
})]
|