@autoguru/overdrive 4.23.1 → 4.23.2
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.
- package/dist/components/EditableText/EditableText.d.ts.map +1 -1
- package/dist/components/EditableText/EditableText.js +14 -15
- package/dist/components/EditableText/stories.js +8 -1
- package/dist/components/Text/Text.d.ts +3 -2
- package/dist/components/Text/Text.d.ts.map +1 -1
- package/dist/components/Text/Text.js +4 -2
- package/dist/components/TextLink/TextLink.d.ts +1 -1
- package/dist/components/TextLink/TextLink.d.ts.map +1 -1
- package/dist/utils/estimateTextWidth.d.ts +2 -0
- package/dist/utils/estimateTextWidth.d.ts.map +1 -0
- package/dist/utils/estimateTextWidth.js +15 -0
- package/package.json +1 -1
|
@@ -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,
|
|
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,iFAiExB,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -7,13 +7,15 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
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, useState } from 'react';
|
|
11
|
-
import { Box } from "../Box/index.js";
|
|
10
|
+
import { forwardRef, useRef, useState } from 'react';
|
|
11
|
+
import { Box, useBoxStyles } 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
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
16
17
|
export const EditableText = forwardRef((_ref, ref) => {
|
|
18
|
+
var _textRef$current;
|
|
17
19
|
let {
|
|
18
20
|
is,
|
|
19
21
|
colour = 'muted',
|
|
@@ -22,6 +24,7 @@ export const EditableText = forwardRef((_ref, ref) => {
|
|
|
22
24
|
value
|
|
23
25
|
} = _ref,
|
|
24
26
|
inputProps = _objectWithoutProperties(_ref, _excluded);
|
|
27
|
+
const textRef = useRef(null);
|
|
25
28
|
const [isEditing, setIsEditing] = useState(false);
|
|
26
29
|
const onRequestEdit = () => setIsEditing(true);
|
|
27
30
|
const textStyles = useTextStyles({
|
|
@@ -29,14 +32,10 @@ export const EditableText = forwardRef((_ref, ref) => {
|
|
|
29
32
|
colour,
|
|
30
33
|
size
|
|
31
34
|
});
|
|
32
|
-
|
|
33
|
-
return _jsx(Box, {
|
|
35
|
+
return _jsxs(Box, {
|
|
34
36
|
ref: ref,
|
|
35
37
|
display: display,
|
|
36
38
|
className: styles.root,
|
|
37
|
-
style: {
|
|
38
|
-
maxWidth: width
|
|
39
|
-
},
|
|
40
39
|
onClick: onRequestEdit,
|
|
41
40
|
onFocus: onRequestEdit,
|
|
42
41
|
onBlur: () => setIsEditing(false),
|
|
@@ -45,25 +44,25 @@ export const EditableText = forwardRef((_ref, ref) => {
|
|
|
45
44
|
setIsEditing(false);
|
|
46
45
|
}
|
|
47
46
|
},
|
|
48
|
-
children: isEditing
|
|
47
|
+
children: [isEditing && _jsx(Box, _objectSpread(_objectSpread({
|
|
49
48
|
is: "input"
|
|
50
49
|
}, inputProps), {}, {
|
|
51
50
|
autoFocus: true,
|
|
52
51
|
value: value,
|
|
53
52
|
className: clsx(textStyles, inputStyles.input.itself.root),
|
|
54
53
|
style: {
|
|
55
|
-
width
|
|
54
|
+
width: (_textRef$current = textRef.current) === null || _textRef$current === void 0 ? void 0 : _textRef$current.offsetWidth
|
|
56
55
|
}
|
|
57
|
-
}))
|
|
56
|
+
})), _jsx(Text, {
|
|
58
57
|
noWrap: true,
|
|
58
|
+
ref: textRef,
|
|
59
59
|
is: is,
|
|
60
60
|
colour: colour,
|
|
61
|
-
className: clsx(textStyles, styles.text
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
},
|
|
61
|
+
className: clsx(textStyles, styles.text, useBoxStyles({
|
|
62
|
+
display: isEditing ? 'none' : display
|
|
63
|
+
})),
|
|
65
64
|
children: value
|
|
66
|
-
})
|
|
65
|
+
})]
|
|
67
66
|
});
|
|
68
67
|
});
|
|
69
68
|
export default EditableText;
|
|
@@ -44,9 +44,16 @@ const dateProps = {
|
|
|
44
44
|
value: todayStr,
|
|
45
45
|
type: 'date'
|
|
46
46
|
};
|
|
47
|
+
const narrowCharactersProps = {
|
|
48
|
+
colour: 'muted',
|
|
49
|
+
value: 'Price is $111.01',
|
|
50
|
+
type: 'text'
|
|
51
|
+
};
|
|
47
52
|
export const text = template.bind(textProps);
|
|
48
53
|
export const number = template.bind(numberProps);
|
|
49
54
|
export const date = template.bind(dateProps);
|
|
55
|
+
export const narrowCharacters = template.bind(narrowCharactersProps);
|
|
50
56
|
text.args = textProps;
|
|
51
57
|
number.args = numberProps;
|
|
52
|
-
date.args = dateProps;
|
|
58
|
+
date.args = dateProps;
|
|
59
|
+
narrowCharacters.args = narrowCharactersProps;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CSSProperties, ReactNode } from 'react';
|
|
2
|
+
import * as React from 'react';
|
|
2
3
|
import type { BoxStyleProps } from '../Box';
|
|
3
4
|
import { TextStyleProps } from './useTextStyles';
|
|
4
5
|
export interface Props extends TextStyleProps {
|
|
@@ -9,6 +10,6 @@ export interface Props extends TextStyleProps {
|
|
|
9
10
|
display?: Extract<BoxStyleProps['display'], 'inline' | 'inlineBlock' | 'block'>;
|
|
10
11
|
style?: CSSProperties;
|
|
11
12
|
}
|
|
12
|
-
export declare const Text:
|
|
13
|
+
export declare const Text: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLElement>>;
|
|
13
14
|
export default Text;
|
|
14
15
|
//# sourceMappingURL=Text.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Text.d.ts","sourceRoot":"","sources":["../../../lib/components/Text/Text.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"Text.d.ts","sourceRoot":"","sources":["../../../lib/components/Text/Text.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAG5C,OAAO,EAAE,cAAc,EAAiB,MAAM,iBAAiB,CAAC;AAEhE,MAAM,WAAW,KAAM,SAAQ,cAAc;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,EAAE,CAAC,EAAE,GAAG,GAAG,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAChB,aAAa,CAAC,SAAS,CAAC,EACxB,QAAQ,GAAG,aAAa,GAAG,OAAO,CAClC,CAAC;IACF,KAAK,CAAC,EAAE,aAAa,CAAC;CACtB;AAED,eAAO,MAAM,IAAI,2EAyChB,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import * as React from 'react';
|
|
4
|
+
import { forwardRef } from 'react';
|
|
4
5
|
import { Box } from "../Box/index.js";
|
|
5
6
|
import { useTextStyles } from "./useTextStyles.js";
|
|
6
7
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
-
export const Text = _ref => {
|
|
8
|
+
export const Text = forwardRef((_ref, ref) => {
|
|
8
9
|
let {
|
|
9
10
|
children,
|
|
10
11
|
className = '',
|
|
@@ -22,6 +23,7 @@ export const Text = _ref => {
|
|
|
22
23
|
} = _ref;
|
|
23
24
|
return _jsx(Box, {
|
|
24
25
|
is: Component,
|
|
26
|
+
ref: ref,
|
|
25
27
|
display: display,
|
|
26
28
|
textAlign: align,
|
|
27
29
|
className: [useTextStyles({
|
|
@@ -36,5 +38,5 @@ export const Text = _ref => {
|
|
|
36
38
|
style: style,
|
|
37
39
|
children: children
|
|
38
40
|
});
|
|
39
|
-
};
|
|
41
|
+
});
|
|
40
42
|
export default Text;
|
|
@@ -11,6 +11,6 @@ export interface Props extends TextProps, AnchorProps {
|
|
|
11
11
|
muted?: boolean;
|
|
12
12
|
icon?: IconType;
|
|
13
13
|
}
|
|
14
|
-
export declare const TextLink: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLAnchorElement>>;
|
|
14
|
+
export declare const TextLink: React.ForwardRefExoticComponent<Omit<Props, "ref"> & React.RefAttributes<HTMLAnchorElement>>;
|
|
15
15
|
export default TextLink;
|
|
16
16
|
//# sourceMappingURL=TextLink.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextLink.d.ts","sourceRoot":"","sources":["../../../lib/components/TextLink/TextLink.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAG3C,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EACN,oBAAoB,EAEpB,cAAc,EAEd,WAAW,EAGX,YAAY,EACZ,SAAS,EACT,MAAM,OAAO,CAAC;AAIf,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAI/B,KAAK,SAAS,GAAG,IAAI,CAAC,cAAc,CAAC,OAAO,IAAI,CAAC,EAAE,IAAI,GAAG,QAAQ,CAAC,CAAC;AACpE,KAAK,WAAW,GAAG,IAAI,CACtB,oBAAoB,CAAC,iBAAiB,CAAC,EACvC,UAAU,GAAG,OAAO,GAAG,IAAI,GAAG,MAAM,SAAS,CAC7C,CAAC;AAEF,MAAM,WAAW,KAAM,SAAQ,SAAS,EAAE,WAAW;IACpD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,EAAE,CAAC,EAAE,WAAW,GAAG,YAAY,CAAC;IAChC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,IAAI,CAAC,EAAE,QAAQ,CAAC;CAChB;AAED,eAAO,MAAM,QAAQ,
|
|
1
|
+
{"version":3,"file":"TextLink.d.ts","sourceRoot":"","sources":["../../../lib/components/TextLink/TextLink.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAG3C,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EACN,oBAAoB,EAEpB,cAAc,EAEd,WAAW,EAGX,YAAY,EACZ,SAAS,EACT,MAAM,OAAO,CAAC;AAIf,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAI/B,KAAK,SAAS,GAAG,IAAI,CAAC,cAAc,CAAC,OAAO,IAAI,CAAC,EAAE,IAAI,GAAG,QAAQ,CAAC,CAAC;AACpE,KAAK,WAAW,GAAG,IAAI,CACtB,oBAAoB,CAAC,iBAAiB,CAAC,EACvC,UAAU,GAAG,OAAO,GAAG,IAAI,GAAG,MAAM,SAAS,CAC7C,CAAC;AAEF,MAAM,WAAW,KAAM,SAAQ,SAAS,EAAE,WAAW;IACpD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,EAAE,CAAC,EAAE,WAAW,GAAG,YAAY,CAAC;IAChC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,IAAI,CAAC,EAAE,QAAQ,CAAC;CAChB;AAED,eAAO,MAAM,QAAQ,8FAyEpB,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"estimateTextWidth.d.ts","sourceRoot":"","sources":["../../lib/utils/estimateTextWidth.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,iBAAiB,UAAW,MAAM,WAQ9C,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const narrowChars = /[!"'()*+,./:;<=>?I[\\\]^_`b-vx-z{|}~\-]/g;
|
|
4
|
+
const wideChars = /[\dA-HJ-Z]/g;
|
|
5
|
+
const narrowCharWidth = 0.5;
|
|
6
|
+
const defaultCharWidth = 0.8;
|
|
7
|
+
export const estimateTextWidth = value => {
|
|
8
|
+
if (!value) return '0ch';
|
|
9
|
+
const charWidths = value.split('').map(char => {
|
|
10
|
+
if (narrowChars.test(char)) return narrowCharWidth;
|
|
11
|
+
if (wideChars.test(char)) return 1;
|
|
12
|
+
return defaultCharWidth;
|
|
13
|
+
});
|
|
14
|
+
return charWidths.reduce((sum, width) => sum + width, 0) + 'ch';
|
|
15
|
+
};
|