@autoguru/overdrive 4.9.2 → 4.9.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.
- package/dist/components/Stepper/Stepper.d.ts.map +1 -1
- package/dist/components/Stepper/Stepper.js +2 -1
- package/dist/themes/helpers.d.ts +27 -1
- package/dist/themes/helpers.d.ts.map +1 -1
- package/dist/themes/helpers.js +48 -1
- package/dist/utils/number.d.ts +1 -0
- package/dist/utils/number.d.ts.map +1 -1
- package/dist/utils/number.js +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Stepper.d.ts","sourceRoot":"","sources":["../../../lib/components/Stepper/Stepper.tsx"],"names":[],"mappings":"AAIA,OAAO,EACN,iBAAiB,EAIjB,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"Stepper.d.ts","sourceRoot":"","sources":["../../../lib/components/Stepper/Stepper.tsx"],"names":[],"mappings":"AAIA,OAAO,EACN,iBAAiB,EAIjB,MAAM,OAAO,CAAC;AAUf,MAAM,WAAW,KAAK;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB,MAAM,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAE/B,QAAQ,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B;AAiDD,eAAO,MAAM,OAAO,EAAE,iBAAiB,CAAC,KAAK,CA6H5C,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
|
@@ -3,6 +3,7 @@ import { clamp } from '@autoguru/utilities';
|
|
|
3
3
|
import clsx from 'clsx';
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import { useCallback, } from 'react';
|
|
6
|
+
import { addWithSafeDecimal } from '../../utils/number';
|
|
6
7
|
import { Box, useBoxStyles } from '../Box';
|
|
7
8
|
import { Column, Columns } from '../Columns';
|
|
8
9
|
import { Icon } from '../Icon';
|
|
@@ -10,7 +11,7 @@ import { Text, useTextStyles } from '../Text';
|
|
|
10
11
|
import * as styles from './Stepper.css';
|
|
11
12
|
const takeStep = ({ min, max, value, step, direction }) => {
|
|
12
13
|
const directionChange = (direction === 'DOWN' ? -1 : 1) * step;
|
|
13
|
-
return clamp(value
|
|
14
|
+
return clamp(addWithSafeDecimal(value, directionChange), min, max);
|
|
14
15
|
};
|
|
15
16
|
const Handle = ({ disabled, icon, label, onClick, }) => (React.createElement(Box, { is: "button", className: [
|
|
16
17
|
styles.handle.default,
|
package/dist/themes/helpers.d.ts
CHANGED
|
@@ -1,2 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
interface ShadedColourProps {
|
|
2
|
+
colour: string;
|
|
3
|
+
intensity: number | string | null;
|
|
4
|
+
direction: 'forward' | 'backward';
|
|
5
|
+
isDarkTheme: boolean;
|
|
6
|
+
transparency?: number | string | null;
|
|
7
|
+
}
|
|
8
|
+
export declare const shadedColour: ({ colour, intensity, direction, isDarkTheme, transparency, }: ShadedColourProps) => string;
|
|
9
|
+
declare type RGBNumbers = {
|
|
10
|
+
r: number;
|
|
11
|
+
g: number;
|
|
12
|
+
b: number;
|
|
13
|
+
} | null;
|
|
14
|
+
export declare const hexToRGB: (hex: string) => RGBNumbers;
|
|
15
|
+
export declare const rgbStrToRGB: (rgb: string) => RGBNumbers;
|
|
16
|
+
export declare const getRGBValues: (hexOrRGB: string) => RGBNumbers;
|
|
17
|
+
export declare const getColourLuminance: (rgb: RGBNumbers) => number;
|
|
18
|
+
export declare const getContrastRatio: (colour1: string, colour2: string) => number;
|
|
19
|
+
declare type AccessibilityLevel = 'AA' | 'AAA';
|
|
20
|
+
declare type AccessibilityTextSize = 'SMALL' | 'LARGE';
|
|
21
|
+
export declare const passesAccessibilityContrast: ({ colour1, colour2, level, textSize, }: {
|
|
22
|
+
colour1: string;
|
|
23
|
+
colour2: string;
|
|
24
|
+
level: AccessibilityLevel;
|
|
25
|
+
textSize: AccessibilityTextSize;
|
|
26
|
+
}) => boolean;
|
|
27
|
+
export {};
|
|
2
28
|
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../lib/themes/helpers.ts"],"names":[],"mappings":"AAEA,
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../lib/themes/helpers.ts"],"names":[],"mappings":"AAEA,UAAU,iBAAiB;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAClC,SAAS,EAAE,SAAS,GAAG,UAAU,CAAC;IAClC,WAAW,EAAE,OAAO,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;CACtC;AAED,eAAO,MAAM,YAAY,iEAMtB,iBAAiB,KAAG,MAiBtB,CAAC;AAEF,aAAK,UAAU,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC;AAE7D,eAAO,MAAM,QAAQ,QAAS,MAAM,KAAG,UAYtC,CAAC;AAEF,eAAO,MAAM,WAAW,QAAS,MAAM,KAAG,UAOzC,CAAC;AAEF,eAAO,MAAM,YAAY,aAAc,MAAM,KAAG,UACwB,CAAC;AAEzE,eAAO,MAAM,kBAAkB,QAAS,UAAU,WAQjD,CAAC;AAEF,eAAO,MAAM,gBAAgB,YAAa,MAAM,WAAW,MAAM,KAAG,MAMnE,CAAC;AAEF,aAAK,kBAAkB,GAAG,IAAI,GAAG,KAAK,CAAC;AACvC,aAAK,qBAAqB,GAAG,OAAO,GAAG,OAAO,CAAC;AAE/C,eAAO,MAAM,2BAA2B;aAM9B,MAAM;aACN,MAAM;WACR,kBAAkB;cACf,qBAAqB;MAC5B,OAQH,CAAC"}
|
package/dist/themes/helpers.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { colord } from 'colord';
|
|
2
|
-
export const shadedColour = (colour, intensity, direction, isDarkTheme
|
|
2
|
+
export const shadedColour = ({ colour, intensity, direction, isDarkTheme, transparency = 0, }) => {
|
|
3
3
|
const intensityValue = typeof intensity === 'string' ? Number(intensity) : intensity;
|
|
4
4
|
const transparencyValue = typeof transparency === 'string' ? Number(transparency) : transparency;
|
|
5
5
|
return colord(colour)[(!isDarkTheme && direction === 'backward') ||
|
|
@@ -9,3 +9,50 @@ export const shadedColour = (colour, intensity, direction, isDarkTheme = false,
|
|
|
9
9
|
.alpha(typeof transparencyValue === 'number' ? 1 - transparencyValue : 1)
|
|
10
10
|
.toHex();
|
|
11
11
|
};
|
|
12
|
+
export const hexToRGB = (hex) => {
|
|
13
|
+
const shorthandRegex = /^#?([\da-f])([\da-f])([\da-f])$/i;
|
|
14
|
+
hex = hex.replace(shorthandRegex, (_, r, g, b) => r + r + g + g + b + b);
|
|
15
|
+
const result = /^#?([\da-f]{2})([\da-f]{2})([\da-f]{2})$/i.exec(hex);
|
|
16
|
+
return result
|
|
17
|
+
? {
|
|
18
|
+
r: Number.parseInt(result[1], 16),
|
|
19
|
+
g: Number.parseInt(result[2], 16),
|
|
20
|
+
b: Number.parseInt(result[3], 16),
|
|
21
|
+
}
|
|
22
|
+
: null;
|
|
23
|
+
};
|
|
24
|
+
export const rgbStrToRGB = (rgb) => {
|
|
25
|
+
const components = rgb.replace(/[^\d,]/g, '').split(',');
|
|
26
|
+
return {
|
|
27
|
+
r: Number.parseInt(components[0]),
|
|
28
|
+
g: Number.parseInt(components[1]),
|
|
29
|
+
b: Number.parseInt(components[2]),
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export const getRGBValues = (hexOrRGB) => hexOrRGB.startsWith('rgb') ? rgbStrToRGB(hexOrRGB) : hexToRGB(hexOrRGB);
|
|
33
|
+
export const getColourLuminance = (rgb) => {
|
|
34
|
+
if (!rgb)
|
|
35
|
+
return 0;
|
|
36
|
+
const { r, g, b } = rgb;
|
|
37
|
+
const a = [r, g, b].map((v) => {
|
|
38
|
+
v /= 255;
|
|
39
|
+
return v <= 0.039_28 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);
|
|
40
|
+
});
|
|
41
|
+
return a[0] * 0.2126 + a[1] * 0.7152 + a[2] * 0.0722;
|
|
42
|
+
};
|
|
43
|
+
export const getContrastRatio = (colour1, colour2) => {
|
|
44
|
+
const color1luminance = getColourLuminance(getRGBValues(colour1));
|
|
45
|
+
const color2luminance = getColourLuminance(getRGBValues(colour2));
|
|
46
|
+
return color1luminance > color2luminance
|
|
47
|
+
? (color2luminance + 0.05) / (color1luminance + 0.05)
|
|
48
|
+
: (color1luminance + 0.05) / (color2luminance + 0.05);
|
|
49
|
+
};
|
|
50
|
+
export const passesAccessibilityContrast = ({ colour1, colour2, level, textSize, }) => {
|
|
51
|
+
const contrastRatio = getContrastRatio(colour1, colour2);
|
|
52
|
+
if (textSize === 'LARGE') {
|
|
53
|
+
return level === 'AAA'
|
|
54
|
+
? contrastRatio < 1 / 4.5
|
|
55
|
+
: contrastRatio < 1 / 3;
|
|
56
|
+
}
|
|
57
|
+
return level === 'AAA' ? contrastRatio < 1 / 7 : contrastRatio < 1 / 4.5;
|
|
58
|
+
};
|
package/dist/utils/number.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ export declare const bigNumFormatter: (num: number) => {
|
|
|
3
3
|
descriptor: string;
|
|
4
4
|
};
|
|
5
5
|
export declare const toPrettyBigNumber: (number: number, fractionDigits?: number) => string;
|
|
6
|
+
export declare const addWithSafeDecimal: (a: number, b: number) => number;
|
|
6
7
|
//# sourceMappingURL=number.d.ts.map
|
|
@@ -1 +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"}
|
|
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;AAEF,eAAO,MAAM,kBAAkB,MAAO,MAAM,KAAK,MAAM,KAAG,MAC9B,CAAC"}
|
package/dist/utils/number.js
CHANGED