@autoguru/overdrive 4.3.1 → 4.3.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/CHANGELOG.md +6 -0
- package/dist/components/NumberBubble/NumberBubble.d.ts +1 -0
- package/dist/components/NumberBubble/NumberBubble.d.ts.map +1 -1
- package/dist/components/NumberBubble/NumberBubble.js +20 -4
- package/dist/components/NumberBubble/stories.js +7 -6
- package/dist/utils/number.d.ts +6 -0
- package/dist/utils/number.d.ts.map +1 -0
- package/dist/utils/number.js +25 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,7 @@ import { Box } from '../Box';
|
|
|
3
3
|
import { Text } from '../Text';
|
|
4
4
|
export interface Props extends Omit<ComponentProps<typeof Box>, 'borderRadius' | 'position' | 'padding'> {
|
|
5
5
|
value: number;
|
|
6
|
+
rawNumbers?: boolean;
|
|
6
7
|
textColour?: ComponentProps<typeof Text>['colour'];
|
|
7
8
|
}
|
|
8
9
|
export declare const NumberBubble: FunctionComponent<Props>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumberBubble.d.ts","sourceRoot":"","sources":["../../../lib/components/NumberBubble/NumberBubble.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"NumberBubble.d.ts","sourceRoot":"","sources":["../../../lib/components/NumberBubble/NumberBubble.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAW,MAAM,OAAO,CAAC;AAGnE,OAAO,EAAE,GAAG,EAAgB,MAAM,QAAQ,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAI/B,MAAM,WAAW,KAChB,SAAQ,IAAI,CACX,cAAc,CAAC,OAAO,GAAG,CAAC,EAC1B,cAAc,GAAG,UAAU,GAAG,SAAS,CACvC;IACD,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,UAAU,CAAC,EAAE,cAAc,CAAC,OAAO,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAC;CACnD;AAaD,eAAO,MAAM,YAAY,EAAE,iBAAiB,CAAC,KAAK,CAkCjD,CAAC"}
|
|
@@ -1,12 +1,28 @@
|
|
|
1
1
|
import clsx from 'clsx';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
import { toPrettyBigNumber } from '../../utils/number';
|
|
3
5
|
import { Box, useBoxStyles } from '../Box';
|
|
4
6
|
import { Text } from '../Text';
|
|
5
7
|
import * as styles from './NumberBubble.css';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
const valuePaddingMap = {
|
|
9
|
+
SMALL: '2',
|
|
10
|
+
MEDIUM: '3',
|
|
11
|
+
LARGE: '4',
|
|
12
|
+
X_LARGE: '5',
|
|
13
|
+
};
|
|
14
|
+
export const NumberBubble = ({ value, textColour = 'white', rawNumbers = false, ...boxProps }) => {
|
|
15
|
+
const size = useMemo(() => {
|
|
16
|
+
if (value > 9 && value < 100)
|
|
17
|
+
return 'MEDIUM';
|
|
18
|
+
if (value > 99 && value < 9999)
|
|
19
|
+
return 'LARGE';
|
|
20
|
+
if (value >= 9999)
|
|
21
|
+
return 'LARGE';
|
|
22
|
+
return 'SMALL';
|
|
23
|
+
}, [value]);
|
|
24
|
+
return (React.createElement(Box, { borderRadius: "full", backgroundColour: "gray900", display: "inlineBlock", position: "relative", padding: valuePaddingMap[size], ...boxProps },
|
|
9
25
|
React.createElement(Text, { size: "2", strong: true, className: clsx(styles.bubbleText, useBoxStyles({
|
|
10
26
|
position: 'absolute',
|
|
11
|
-
})), colour: textColour }, value)));
|
|
27
|
+
})), colour: textColour }, rawNumbers ? value : toPrettyBigNumber(value))));
|
|
12
28
|
};
|
|
@@ -7,15 +7,11 @@ 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
|
|
|
9
9
|
import * as React from 'react';
|
|
10
|
-
import { boxArgTypes } from "../Box/argTypes.js";
|
|
11
10
|
import { NumberBubble } from "./index.js";
|
|
12
11
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
12
|
export default {
|
|
14
13
|
title: 'Foundation/Typography/NumberBubble',
|
|
15
|
-
component: NumberBubble
|
|
16
|
-
argTypes: {
|
|
17
|
-
paddingX: boxArgTypes.paddingX
|
|
18
|
-
}
|
|
14
|
+
component: NumberBubble
|
|
19
15
|
};
|
|
20
16
|
|
|
21
17
|
const template = args => _jsx(NumberBubble, _objectSpread({}, args));
|
|
@@ -24,4 +20,9 @@ const standardProps = {
|
|
|
24
20
|
value: 0
|
|
25
21
|
};
|
|
26
22
|
export const standard = template.bind(standardProps);
|
|
27
|
-
standard.args = standardProps;
|
|
23
|
+
standard.args = standardProps;
|
|
24
|
+
const bigNumberProps = {
|
|
25
|
+
value: 2345
|
|
26
|
+
};
|
|
27
|
+
export const bigNumber = template.bind(bigNumberProps);
|
|
28
|
+
bigNumber.args = bigNumberProps;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../../lib/utils/number.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,QACtB,MAAM,KACT;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAoBrC,CAAC;AAEF,eAAO,MAAM,iBAAiB,WACrB,MAAM,8BAEZ,MAMF,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export const bigNumFormatter = (num) => {
|
|
2
|
+
if (num < 1e3)
|
|
3
|
+
return {
|
|
4
|
+
value: num,
|
|
5
|
+
descriptor: '',
|
|
6
|
+
};
|
|
7
|
+
else if (num < 1e6)
|
|
8
|
+
return {
|
|
9
|
+
value: num / 1e3,
|
|
10
|
+
descriptor: 'K',
|
|
11
|
+
};
|
|
12
|
+
else {
|
|
13
|
+
return {
|
|
14
|
+
value: num / 1e6,
|
|
15
|
+
descriptor: 'M',
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
export const toPrettyBigNumber = (number, fractionDigits = 1) => {
|
|
20
|
+
const formatChunks = bigNumFormatter(number);
|
|
21
|
+
const value = Number.isInteger(formatChunks.value)
|
|
22
|
+
? formatChunks.value
|
|
23
|
+
: formatChunks.value.toFixed(fractionDigits);
|
|
24
|
+
return `${value}${formatChunks.descriptor}`;
|
|
25
|
+
};
|