@autoguru/overdrive 4.23.3 → 4.23.5

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,3 +1,4 @@
1
1
  export declare const root: string;
2
2
  export declare const text: string;
3
+ export declare const textHidden: string;
3
4
  //# sourceMappingURL=EditableText.css.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"EditableText.css.d.ts","sourceRoot":"","sources":["../../../lib/components/EditableText/EditableText.css.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,IAAI,QAMf,CAAC;AAEH,eAAO,MAAM,IAAI,QAEf,CAAC"}
1
+ {"version":3,"file":"EditableText.css.d.ts","sourceRoot":"","sources":["../../../lib/components/EditableText/EditableText.css.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,IAAI,QAMf,CAAC;AAEH,eAAO,MAAM,IAAI,QAEf,CAAC;AAEH,eAAO,MAAM,UAAU,QAGrB,CAAC"}
@@ -14,4 +14,8 @@ export const root = style({
14
14
  export const text = style({
15
15
  cursor: 'pointer'
16
16
  }, "text");
17
+ export const textHidden = style({
18
+ position: 'absolute',
19
+ visibility: 'hidden'
20
+ }, "textHidden");
17
21
  __vanilla_filescope__.endFileScope();
@@ -1,9 +1,10 @@
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 Text>, 'display'>;
5
- type TextProps = Pick<ComponentProps<typeof Text>, 'is' | 'colour' | 'size' | 'display' | 'children' | 'noWrap'>;
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'>;
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' | keyof TextProps | keyof BoxProps>;
7
8
  export interface Props extends TextProps, InputProps, BoxProps {
8
9
  className?: string;
9
10
  }
@@ -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,EAGnB,MAAM,OAAO,CAAC;AAGf,OAAO,EAAE,IAAI,EAAiB,MAAM,SAAS,CAAC;AAK9C,KAAK,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,OAAO,IAAI,CAAC,EAAE,SAAS,CAAC,CAAC;AAC7D,KAAK,SAAS,GAAG,IAAI,CACpB,cAAc,CAAC,OAAO,IAAI,CAAC,EAC3B,IAAI,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,GAAG,UAAU,GAAG,QAAQ,CAC5D,CAAC;AACF,KAAK,UAAU,GAAG,IAAI,CACrB,mBAAmB,CAAC,gBAAgB,CAAC,EACnC,OAAO,GACP,IAAI,GACJ,WAAW,GACX,OAAO,GACP,QAAQ,GACR,MAAM,SAAS,GACf,MAAM,QAAQ,CAChB,CAAC;AAEF,MAAM,WAAW,KAAM,SAAQ,SAAS,EAAE,UAAU,EAAE,QAAQ;IAC7D,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,eAAO,MAAM,YAAY,iFAkExB,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,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,CAAC,CAAC;AACnF,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,MAAM,SAAS,GACf,MAAM,QAAQ,CAChB,CAAC;AAEF,MAAM,WAAW,KAAM,SAAQ,SAAS,EAAE,UAAU,EAAE,QAAQ;IAC7D,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,eAAO,MAAM,YAAY,iFA+ExB,CAAC;AAEF,eAAe,YAAY,CAAC"}
@@ -2,26 +2,27 @@
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"];
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, useRef, useState } from 'react';
11
- import { Box, useBoxStyles } from "../Box/index.js";
10
+ import { forwardRef, useEffect, useRef, useState } from 'react';
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
17
  export const EditableText = forwardRef((_ref, ref) => {
18
- var _textRef$current;
19
18
  let {
20
19
  is,
21
20
  colour = 'muted',
22
21
  size,
23
22
  display = 'inlineBlock',
24
- value
23
+ value,
24
+ onFocus,
25
+ onBlur
25
26
  } = _ref,
26
27
  inputProps = _objectWithoutProperties(_ref, _excluded);
27
28
  const textRef = useRef(null);
@@ -32,13 +33,26 @@ export const EditableText = forwardRef((_ref, ref) => {
32
33
  colour,
33
34
  size
34
35
  });
36
+ const [width, setWidth] = useState(undefined);
37
+ useEffect(() => {
38
+ if (textRef.current) {
39
+ setWidth(textRef.current.clientWidth);
40
+ }
41
+ }, [textRef.current, value]);
35
42
  return _jsxs(Box, {
36
43
  ref: ref,
37
44
  display: display,
45
+ position: "relative",
38
46
  className: styles.root,
39
47
  onClick: onRequestEdit,
40
- onFocus: onRequestEdit,
41
- onBlur: () => setIsEditing(false),
48
+ onFocus: e => {
49
+ onRequestEdit();
50
+ if (typeof onFocus === 'function') onFocus(e);
51
+ },
52
+ onBlur: e => {
53
+ setIsEditing(false);
54
+ if (typeof onBlur === 'function') onBlur(e);
55
+ },
42
56
  onKeyDown: e => {
43
57
  if (e.key === 'Enter' || e.key === 'Escape') {
44
58
  setIsEditing(false);
@@ -51,7 +65,7 @@ export const EditableText = forwardRef((_ref, ref) => {
51
65
  value: value,
52
66
  className: clsx(textStyles, inputStyles.input.itself.root),
53
67
  style: {
54
- width: (_textRef$current = textRef.current) === null || _textRef$current === void 0 ? void 0 : _textRef$current.offsetWidth
68
+ width
55
69
  }
56
70
  })), _jsx(Text, {
57
71
  noWrap: true,
@@ -59,9 +73,9 @@ export const EditableText = forwardRef((_ref, ref) => {
59
73
  is: is,
60
74
  colour: colour,
61
75
  size: size,
62
- className: clsx(textStyles, styles.text, useBoxStyles({
63
- display: isEditing ? 'none' : display
64
- })),
76
+ className: clsx(textStyles, styles.text, {
77
+ [styles.textHidden]: isEditing
78
+ }),
65
79
  children: value
66
80
  })]
67
81
  });
@@ -1,10 +1,13 @@
1
1
  "use strict";
2
2
 
3
3
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
5
+ const _excluded = ["onChange", "value"];
4
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; }
5
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; }
6
8
  import isChromatic from 'chromatic';
7
9
  import * as React from 'react';
10
+ import { useState } from 'react';
8
11
  import { EditableText } from "./index.js";
9
12
  import { jsx as _jsx } from "react/jsx-runtime";
10
13
  export default {
@@ -20,7 +23,21 @@ export default {
20
23
  }
21
24
  }
22
25
  };
23
- const template = args => _jsx(EditableText, _objectSpread({}, args));
26
+ const template = _ref => {
27
+ let {
28
+ onChange: incomingOnChange,
29
+ value: incomingValue
30
+ } = _ref,
31
+ args = _objectWithoutProperties(_ref, _excluded);
32
+ const [value, setValue] = useState(incomingValue);
33
+ return _jsx(EditableText, _objectSpread({
34
+ onChange: e => {
35
+ setValue(e.currentTarget.value);
36
+ typeof incomingOnChange === 'function' && incomingOnChange(e.currentTarget.value);
37
+ },
38
+ value: value
39
+ }, args));
40
+ };
24
41
  const textProps = {
25
42
  colour: 'muted',
26
43
  value: 'Hello World',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autoguru/overdrive",
3
- "version": "4.23.3",
3
+ "version": "4.23.5",
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",