@autoguru/overdrive 4.0.4 → 4.1.3
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 +24 -0
- package/dist/components/AutoSuggest/AutoSuggest.d.ts +1 -0
- package/dist/components/AutoSuggest/AutoSuggest.d.ts.map +1 -1
- package/dist/components/AutoSuggest/AutoSuggest.js +12 -3
- package/dist/components/AutoSuggest/stories.js +1 -0
- package/dist/components/Image/Image.d.ts +8 -0
- package/dist/components/Image/Image.d.ts.map +1 -0
- package/dist/components/Image/Image.js +5 -0
- package/dist/components/Image/ImageServerProvider.d.ts +18 -0
- package/dist/components/Image/ImageServerProvider.d.ts.map +1 -0
- package/dist/components/Image/ImageServerProvider.js +45 -0
- package/dist/components/Image/ResponsiveImage.d.ts +11 -0
- package/dist/components/Image/ResponsiveImage.d.ts.map +1 -0
- package/dist/components/Image/ResponsiveImage.js +22 -0
- package/dist/components/Image/SimpleImage.d.ts +12 -0
- package/dist/components/Image/SimpleImage.d.ts.map +1 -0
- package/dist/components/Image/SimpleImage.js +2 -0
- package/dist/components/Image/index.d.ts +2 -0
- package/dist/components/Image/index.d.ts.map +1 -0
- package/dist/components/Image/index.js +1 -0
- package/dist/components/Image/stories.js +194 -0
- package/dist/components/Image/types.d.ts +2 -0
- package/dist/components/Image/types.d.ts.map +1 -0
- package/dist/components/Image/types.js +1 -0
- package/dist/components/private/InputBase/withEnhancedInput.css.d.ts.map +1 -1
- package/dist/hooks/useResponsiveValue/useResponsiveValue.d.ts +1 -1
- package/dist/hooks/useResponsiveValue/useResponsiveValue.d.ts.map +1 -1
- package/dist/hooks/useResponsiveValue/useResponsiveValue.js +2 -1
- package/dist/utils/resolveResponsiveProps.d.ts +1 -1
- package/dist/utils/resolveResponsiveProps.d.ts.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @autoguru/overdrive
|
|
2
2
|
|
|
3
|
+
## 4.1.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 9884f4c: Autosuggest: Closes results when enter key is pressed
|
|
8
|
+
|
|
9
|
+
## 4.1.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- e825a3d: useResponsiveValue Accepts any generic type
|
|
14
|
+
|
|
15
|
+
## 4.1.1
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- 4bae7d0: AutoSuggest accepts an 'onEnter' event callback
|
|
20
|
+
|
|
21
|
+
## 4.1.0
|
|
22
|
+
|
|
23
|
+
### Minor Changes
|
|
24
|
+
|
|
25
|
+
- af65bd3: New responsive Image component
|
|
26
|
+
|
|
3
27
|
## 4.0.4
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
|
@@ -21,6 +21,7 @@ export interface Props<PayloadType> extends Omit<ComponentPropsWithoutRef<typeof
|
|
|
21
21
|
suggestions: Suggestions<PayloadType>;
|
|
22
22
|
itemRenderer?: AutoSuggestItemRenderer<PayloadType>;
|
|
23
23
|
onChange?(value: AutoSuggestValue<PayloadType>): void;
|
|
24
|
+
onEnter?(value: AutoSuggestValue<PayloadType>): void;
|
|
24
25
|
}
|
|
25
26
|
export declare const AutoSuggest: <PayloadType extends unknown>(p: Props<PayloadType> & {
|
|
26
27
|
ref?: Ref<HTMLInputElement>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutoSuggest.d.ts","sourceRoot":"","sources":["../../../lib/components/AutoSuggest/AutoSuggest.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA8B,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAIvE,OAAO,EACN,wBAAwB,EAIxB,YAAY,EAEZ,GAAG,EAOH,MAAM,OAAO,CAAC;AAWf,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAMzC,MAAM,WAAW,gBAAgB,CAAC,WAAW;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
|
|
@@ -2,7 +2,7 @@ import { ChevronDownIcon, CloseIcon } from '@autoguru/icons';
|
|
|
2
2
|
import { wrapEvent } from '@autoguru/utilities';
|
|
3
3
|
import clsx from 'clsx';
|
|
4
4
|
import * as React from 'react';
|
|
5
|
-
import { forwardRef, useCallback, useEffect, useMemo, useReducer, useRef, useState, } from 'react';
|
|
5
|
+
import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useReducer, useRef, useState, } from 'react';
|
|
6
6
|
import { useMedia } from '../../hooks/useMedia';
|
|
7
7
|
import { setRef, useId } from '../../utils';
|
|
8
8
|
import { Box } from '../Box';
|
|
@@ -96,7 +96,9 @@ const inputReducerFactory = (suggestions) => (prevState, action) => {
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
};
|
|
99
|
-
export const AutoSuggest = forwardRef(function AutoSuggest({ autoFocus = false, autoWidth = false, inlineOptions = false, fieldIcon, suggestions, value, onChange: incomingOnChange, itemRenderer = defaultItemRenderer, onBlur: incomingOnBlur, onFocus: incomingOnFocus, onKeyDown, onClick, ...textInputProps }, ref) {
|
|
99
|
+
export const AutoSuggest = forwardRef(function AutoSuggest({ autoFocus = false, autoWidth = false, inlineOptions = false, fieldIcon, suggestions, value, onChange: incomingOnChange, onEnter, itemRenderer = defaultItemRenderer, onBlur: incomingOnBlur, onFocus: incomingOnFocus, onKeyDown, onClick, ...textInputProps }, ref) {
|
|
100
|
+
const inputRef = useRef();
|
|
101
|
+
useImperativeHandle(ref, () => inputRef.current);
|
|
100
102
|
const [isDesktop] = useMedia(['desktop'], false);
|
|
101
103
|
const [isFocused, setIsFocused] = useState(false);
|
|
102
104
|
const [showModal, setShowModal] = useState(false);
|
|
@@ -113,6 +115,13 @@ export const AutoSuggest = forwardRef(function AutoSuggest({ autoFocus = false,
|
|
|
113
115
|
if (typeof incomingOnChange === 'function')
|
|
114
116
|
incomingOnChange(value);
|
|
115
117
|
},
|
|
118
|
+
onKeyUp: (event) => {
|
|
119
|
+
if (event.key === 'Enter' && typeof onEnter === 'function') {
|
|
120
|
+
setShowModal(false);
|
|
121
|
+
setIsFocused(false);
|
|
122
|
+
inputRef.current?.blur();
|
|
123
|
+
}
|
|
124
|
+
},
|
|
116
125
|
itemRenderer,
|
|
117
126
|
onKeyDown,
|
|
118
127
|
onClick,
|
|
@@ -127,7 +136,7 @@ export const AutoSuggest = forwardRef(function AutoSuggest({ autoFocus = false,
|
|
|
127
136
|
setShowModal(false);
|
|
128
137
|
setIsFocused(false);
|
|
129
138
|
}, [setShowModal]);
|
|
130
|
-
return !inlineOptions && !isDesktop && showModal ? (React.createElement(AutoSuggestFullscreenInput, { ...props, isFocused: isFocused, inlineOptions: true, fieldIcon: fieldIcon, autoFocus: autoFocus, closeModal: closeModal })) : (React.createElement(AutoSuggestInput, { ref:
|
|
139
|
+
return !inlineOptions && !isDesktop && showModal ? (React.createElement(AutoSuggestFullscreenInput, { ...props, isFocused: isFocused, inlineOptions: true, fieldIcon: fieldIcon, autoFocus: autoFocus, closeModal: closeModal })) : (React.createElement(AutoSuggestInput, { ref: inputRef, ...props, isFocused: isFocused, inlineOptions: inlineOptions, fieldIcon: fieldIcon, autoFocus: autoFocus, autoWidth: autoWidth }));
|
|
131
140
|
});
|
|
132
141
|
const AutoSuggestFullscreenInput = forwardRef(function AutoSuggestFullscreenInput({ closeModal, ...props }, ref) {
|
|
133
142
|
const [showPortal, setShowPortal] = useState(false);
|
|
@@ -96,6 +96,7 @@ const standardProps = {
|
|
|
96
96
|
prefixIcon: void 0,
|
|
97
97
|
onReset: () => action('onReset')(),
|
|
98
98
|
onChange: thing => action('onChange')(thing),
|
|
99
|
+
onEnter: thing => action('onEnter')(thing),
|
|
99
100
|
onFocus: thing => action('onFocus')(thing),
|
|
100
101
|
onBlur: thing => action('onBlur')(thing)
|
|
101
102
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ComponentProps, FunctionComponent } from 'react';
|
|
2
|
+
import { ResponsiveImage } from './ResponsiveImage';
|
|
3
|
+
interface Props extends ComponentProps<typeof ResponsiveImage> {
|
|
4
|
+
unoptimised?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare const Image: FunctionComponent<Props>;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=Image.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Image.d.ts","sourceRoot":"","sources":["../../../lib/components/Image/Image.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAI/D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD,UAAU,KAAM,SAAQ,cAAc,CAAC,OAAO,eAAe,CAAC;IAI7D,WAAW,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,eAAO,MAAM,KAAK,EAAE,iBAAiB,CAAC,KAAK,CAQ1C,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useImageServer } from './ImageServerProvider';
|
|
3
|
+
import { ResponsiveImage } from './ResponsiveImage';
|
|
4
|
+
import { SimpleImage } from './SimpleImage';
|
|
5
|
+
export const Image = ({ unoptimised = false, ...props }) => ((useImageServer() && !unoptimised) ? (React.createElement(ResponsiveImage, { ...props })) : (React.createElement(SimpleImage, { ...props })));
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { FunctionComponent } from 'react';
|
|
2
|
+
import { WidthScale } from './types';
|
|
3
|
+
interface UrlParams {
|
|
4
|
+
src: string;
|
|
5
|
+
width: number;
|
|
6
|
+
quality: number;
|
|
7
|
+
}
|
|
8
|
+
interface ImageServerContext {
|
|
9
|
+
widthMap?: Record<WidthScale, number>;
|
|
10
|
+
getWidthValue?(width: WidthScale): number;
|
|
11
|
+
srcUrlMapper(params: UrlParams): string;
|
|
12
|
+
generateSrcSet(params: Omit<UrlParams, 'width'>): string;
|
|
13
|
+
}
|
|
14
|
+
export declare const widthMap: ImageServerContext['widthMap'];
|
|
15
|
+
export declare const useImageServer: () => ImageServerContext;
|
|
16
|
+
export declare const ImageServerProvider: FunctionComponent<Omit<ImageServerContext, 'generateSrcSet'>>;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=ImageServerProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ImageServerProvider.d.ts","sourceRoot":"","sources":["../../../lib/components/Image/ImageServerProvider.tsx"],"names":[],"mappings":"AACA,OAAO,EAA0B,iBAAiB,EAAoC,MAAM,OAAO,CAAC;AAEpG,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,UAAU,SAAS;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,UAAU,kBAAkB;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IACtC,aAAa,CAAC,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAAC;IAE1C,YAAY,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAAC;IACxC,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC;CACzD;AAED,eAAO,MAAM,QAAQ,EAAC,kBAAkB,CAAC,UAAU,CAiBjD,CAAC;AAWH,eAAO,MAAM,cAAc,0BAAmC,CAAC;AAE/D,eAAO,MAAM,mBAAmB,EAAE,iBAAiB,CAAC,IAAI,CAAC,kBAAkB,EAAE,gBAAgB,CAAC,CAgC7F,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { createContext, useCallback, useContext, useMemo } from 'react';
|
|
3
|
+
export const widthMap = {
|
|
4
|
+
'1': 16,
|
|
5
|
+
'2': 32,
|
|
6
|
+
'3': 48,
|
|
7
|
+
'4': 64,
|
|
8
|
+
'5': 96,
|
|
9
|
+
'6': 128,
|
|
10
|
+
'7': 256,
|
|
11
|
+
'8': 384,
|
|
12
|
+
'9': 640,
|
|
13
|
+
'10': 750,
|
|
14
|
+
'11': 828,
|
|
15
|
+
'12': 1080,
|
|
16
|
+
'13': 1200,
|
|
17
|
+
'14': 1920,
|
|
18
|
+
'15': 2048,
|
|
19
|
+
'16': 3840,
|
|
20
|
+
};
|
|
21
|
+
const defaultValue = {
|
|
22
|
+
widthMap,
|
|
23
|
+
getWidthValue: (width) => widthMap[width],
|
|
24
|
+
srcUrlMapper: null,
|
|
25
|
+
generateSrcSet: null,
|
|
26
|
+
};
|
|
27
|
+
const imageServerCtx = createContext(null);
|
|
28
|
+
export const useImageServer = () => useContext(imageServerCtx);
|
|
29
|
+
export const ImageServerProvider = ({ children, srcUrlMapper = defaultValue.srcUrlMapper, getWidthValue = defaultValue.getWidthValue, widthMap = defaultValue.widthMap, }) => {
|
|
30
|
+
const generateSrcSet = useCallback(({ quality, src }) => (Object.keys(widthMap).map((key) => {
|
|
31
|
+
const width = getWidthValue(key);
|
|
32
|
+
return `${srcUrlMapper({ quality, src, width })} ${width}w`;
|
|
33
|
+
}).join(', ')), [widthMap, srcUrlMapper, getWidthValue]);
|
|
34
|
+
return (React.createElement(imageServerCtx.Provider, { value: useMemo(() => ({
|
|
35
|
+
widthMap,
|
|
36
|
+
srcUrlMapper,
|
|
37
|
+
getWidthValue,
|
|
38
|
+
generateSrcSet,
|
|
39
|
+
}), [
|
|
40
|
+
srcUrlMapper,
|
|
41
|
+
widthMap,
|
|
42
|
+
getWidthValue,
|
|
43
|
+
generateSrcSet,
|
|
44
|
+
]) }, children));
|
|
45
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ComponentProps, FunctionComponent } from 'react';
|
|
2
|
+
import { ResponsiveProp } from '../../utils/responsiveProps.css';
|
|
3
|
+
import { widthMap } from './ImageServerProvider';
|
|
4
|
+
import { SimpleImage } from './SimpleImage';
|
|
5
|
+
export interface Props extends Omit<ComponentProps<typeof SimpleImage>, 'sizes'> {
|
|
6
|
+
imageWidth?: ResponsiveProp<keyof typeof widthMap>;
|
|
7
|
+
sizes?: ResponsiveProp<string>;
|
|
8
|
+
quality?: number;
|
|
9
|
+
}
|
|
10
|
+
export declare const ResponsiveImage: FunctionComponent<Props>;
|
|
11
|
+
//# sourceMappingURL=ResponsiveImage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResponsiveImage.d.ts","sourceRoot":"","sources":["../../../lib/components/Image/ResponsiveImage.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAK/D,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEjE,OAAO,EAAkB,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,MAAM,WAAW,KAAM,SAAQ,IAAI,CAAC,cAAc,CAAC,OAAO,WAAW,CAAC,EAAE,OAAO,CAAC;IAQ/E,UAAU,CAAC,EAAE,cAAc,CAAC,MAAM,OAAO,QAAQ,CAAC,CAAC;IAanD,KAAK,CAAC,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC;IAM/B,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,eAAe,EAAE,iBAAiB,CAAC,KAAK,CAgCpD,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { invariant } from '@autoguru/utilities';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
import { useResponsiveValue } from '../../hooks/useResponsiveValue';
|
|
5
|
+
import { useImageServer } from './ImageServerProvider';
|
|
6
|
+
import { SimpleImage } from './SimpleImage';
|
|
7
|
+
export const ResponsiveImage = ({ imageWidth: imageWidthList, sizes: sizesList = '100vw', quality = 70, src: incomingSrc, ...imgProps }) => {
|
|
8
|
+
invariant(quality > 0 && quality <= 100, 'Image must be a number between 1 and 100.');
|
|
9
|
+
const imageWidth = useResponsiveValue(imageWidthList);
|
|
10
|
+
const sizes = useResponsiveValue(sizesList);
|
|
11
|
+
const { srcUrlMapper, getWidthValue, generateSrcSet } = useImageServer();
|
|
12
|
+
const src = useMemo(() => srcUrlMapper({
|
|
13
|
+
src: incomingSrc,
|
|
14
|
+
width: getWidthValue(imageWidth),
|
|
15
|
+
quality,
|
|
16
|
+
}), [incomingSrc, imageWidth, quality, srcUrlMapper, getWidthValue]);
|
|
17
|
+
const srcset = useMemo(() => imageWidth ? void 0 : generateSrcSet({
|
|
18
|
+
src: incomingSrc,
|
|
19
|
+
quality,
|
|
20
|
+
}), [incomingSrc, quality]);
|
|
21
|
+
return (React.createElement(SimpleImage, { sizes: sizes, srcSet: srcset, src: src, ...imgProps }));
|
|
22
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FunctionComponent } from 'react';
|
|
2
|
+
export interface Props extends Omit<HTMLImageElement, 'loading' | 'className' | 'width' | 'height'> {
|
|
3
|
+
src: string;
|
|
4
|
+
eager?: boolean;
|
|
5
|
+
srcSet: string;
|
|
6
|
+
syncDecoding?: boolean;
|
|
7
|
+
width?: string;
|
|
8
|
+
height?: string;
|
|
9
|
+
className?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const SimpleImage: FunctionComponent<Props>;
|
|
12
|
+
//# sourceMappingURL=SimpleImage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SimpleImage.d.ts","sourceRoot":"","sources":["../../../lib/components/Image/SimpleImage.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE1C,MAAM,WAAW,KAAM,SAAQ,IAAI,CAAC,gBAAgB,EAAE,SAAS,GAAG,WAAW,GAAG,OAAO,GAAG,QAAQ,CAAC;IAClG,GAAG,EAAE,MAAM,CAAC;IAKZ,KAAK,CAAC,EAAE,OAAO,CAAC;IAMhB,MAAM,EAAE,MAAM,CAAC;IAMf,YAAY,CAAC,EAAE,OAAO,CAAC;IAMvB,KAAK,CAAC,EAAE,MAAM,CAAC;IAKf,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,SAAS,CAAC,EAAE,MAAM,CAAC;CAEnB;AAED,eAAO,MAAM,WAAW,EAAE,iBAAiB,CAAC,KAAK,CAiBhD,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export const SimpleImage = ({ eager = 'false', syncDecoding = 'false', className = '', src, srcSet, ...imgProps }) => (React.createElement("img", { loading: eager ? 'eager' : 'lazy', decoding: syncDecoding ? 'sync' : 'async', className: className, srcSet: srcSet, src: src, ...imgProps }));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/components/Image/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Image } from './Image';
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
4
|
+
|
|
5
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
6
|
+
|
|
7
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
8
|
+
|
|
9
|
+
import * as React from 'react';
|
|
10
|
+
import { Stack } from "../Stack/index.js";
|
|
11
|
+
import { Text } from "../Text/index.js";
|
|
12
|
+
import { ImageServerProvider, widthMap } from "./ImageServerProvider.js";
|
|
13
|
+
import { Image } from "./index.js";
|
|
14
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
16
|
+
const sizeOptions = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16'];
|
|
17
|
+
export default {
|
|
18
|
+
title: 'Foundation/Image/Image',
|
|
19
|
+
component: Image,
|
|
20
|
+
argTypes: {
|
|
21
|
+
imageWidth: {
|
|
22
|
+
options: [].concat(sizeOptions, ['full']),
|
|
23
|
+
defaultValue: 8,
|
|
24
|
+
control: {
|
|
25
|
+
type: 'select'
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
width: {
|
|
29
|
+
options: [].concat(sizeOptions, ['full']),
|
|
30
|
+
defaultValue: 8,
|
|
31
|
+
control: {
|
|
32
|
+
type: 'select'
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
quality: {
|
|
36
|
+
defaultValue: void 0,
|
|
37
|
+
control: {
|
|
38
|
+
type: 'number',
|
|
39
|
+
min: 1,
|
|
40
|
+
max: 100
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
eager: {
|
|
44
|
+
defaultValue: false,
|
|
45
|
+
control: {
|
|
46
|
+
type: 'boolean'
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
unoptimised: {
|
|
50
|
+
defaultValue: false,
|
|
51
|
+
control: {
|
|
52
|
+
type: 'boolean'
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const calcWidth = width => width === 'full' ? '100%' : widthMap[width];
|
|
59
|
+
|
|
60
|
+
const SimpleTemplate = args => _jsx("div", {
|
|
61
|
+
style: {
|
|
62
|
+
width: '100%',
|
|
63
|
+
overflow: 'auto'
|
|
64
|
+
},
|
|
65
|
+
children: _jsx(Image, _objectSpread(_objectSpread({}, args), {}, {
|
|
66
|
+
width: calcWidth(args.width)
|
|
67
|
+
}))
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const standardProps = {
|
|
71
|
+
src: 'https://cdn.autoguru.com.au/images/autoguru-og.jpg'
|
|
72
|
+
};
|
|
73
|
+
export const standard = SimpleTemplate.bind(standardProps);
|
|
74
|
+
standard.args = standardProps;
|
|
75
|
+
|
|
76
|
+
const srcUrlMapper = _ref => {
|
|
77
|
+
let {
|
|
78
|
+
src,
|
|
79
|
+
width,
|
|
80
|
+
quality
|
|
81
|
+
} = _ref;
|
|
82
|
+
return "https://images.autoguru.com.au/?url=".concat(src, "&w=").concat(width, "&q=").concat(quality);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const WidthProviderTemplate = args => _jsx(ImageServerProvider, {
|
|
86
|
+
srcUrlMapper: srcUrlMapper,
|
|
87
|
+
children: _jsx("div", {
|
|
88
|
+
style: {
|
|
89
|
+
width: '100%',
|
|
90
|
+
overflow: 'auto'
|
|
91
|
+
},
|
|
92
|
+
children: _jsx(Image, _objectSpread(_objectSpread({}, args), {}, {
|
|
93
|
+
width: calcWidth(args.width)
|
|
94
|
+
}))
|
|
95
|
+
})
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const withImageServerUnoptimisedProps = {
|
|
99
|
+
src: 'https://cdn.autoguru.com.au/images/autoguru-test-highres-image.jpg',
|
|
100
|
+
unoptimised: true
|
|
101
|
+
};
|
|
102
|
+
export const withImageServerUnoptimised = WidthProviderTemplate.bind(withImageServerUnoptimisedProps);
|
|
103
|
+
withImageServerUnoptimised.args = withImageServerUnoptimisedProps;
|
|
104
|
+
const withImageServerProps = {
|
|
105
|
+
src: 'https://cdn.autoguru.com.au/images/autoguru-test-highres-image.jpg',
|
|
106
|
+
quality: 60,
|
|
107
|
+
imageWidth: 8,
|
|
108
|
+
sizes: ['100vh',, '60vh', '40vh']
|
|
109
|
+
};
|
|
110
|
+
export const withImageServer = WidthProviderTemplate.bind(withImageServerProps);
|
|
111
|
+
withImageServer.args = withImageServerProps;
|
|
112
|
+
const withResponsiveImageWidthProps = {
|
|
113
|
+
src: 'https://cdn.autoguru.com.au/images/autoguru-test-highres-image.jpg',
|
|
114
|
+
width: 'full',
|
|
115
|
+
sizes: ['100vw', '70vw', '50vw', '40vw'],
|
|
116
|
+
imageWidth: [5, 8,, 12]
|
|
117
|
+
};
|
|
118
|
+
export const withResponsiveImageWidth = WidthProviderTemplate.bind(withResponsiveImageWidthProps);
|
|
119
|
+
withResponsiveImageWidth.args = withResponsiveImageWidthProps;
|
|
120
|
+
const withResponsiveSizesProps = {
|
|
121
|
+
src: 'https://cdn.autoguru.com.au/images/autoguru-test-highres-image.jpg',
|
|
122
|
+
width: 'full',
|
|
123
|
+
sizes: ['100vw', '70vw', '50vw', '40vw']
|
|
124
|
+
};
|
|
125
|
+
export const withResponsiveSizes = WidthProviderTemplate.bind(withResponsiveSizesProps);
|
|
126
|
+
withResponsiveSizes.args = withResponsiveSizesProps;
|
|
127
|
+
|
|
128
|
+
const AllQualityTemplate = args => _jsx(ImageServerProvider, {
|
|
129
|
+
srcUrlMapper: srcUrlMapper,
|
|
130
|
+
children: _jsx("div", {
|
|
131
|
+
style: {
|
|
132
|
+
width: '100%',
|
|
133
|
+
overflow: 'auto'
|
|
134
|
+
},
|
|
135
|
+
children: _jsx(Stack, {
|
|
136
|
+
space: "5",
|
|
137
|
+
children: [1, 20, 40, 60, 80, 100].map(quality => _jsxs(Stack, {
|
|
138
|
+
space: "1",
|
|
139
|
+
children: [_jsxs(Text, {
|
|
140
|
+
children: ["Quality: ", _jsx(Text, {
|
|
141
|
+
strong: true,
|
|
142
|
+
children: quality
|
|
143
|
+
})]
|
|
144
|
+
}), _jsx(Image, _objectSpread(_objectSpread({}, args), {}, {
|
|
145
|
+
width: calcWidth(args.width),
|
|
146
|
+
imageWidth: args.width,
|
|
147
|
+
quality: quality
|
|
148
|
+
}), quality)]
|
|
149
|
+
}, quality))
|
|
150
|
+
})
|
|
151
|
+
})
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
export const withImageServerQualities = AllQualityTemplate.bind(withImageServerProps);
|
|
155
|
+
withImageServerQualities.args = withImageServerProps;
|
|
156
|
+
|
|
157
|
+
const AllSizeTemplate = args => _jsx(ImageServerProvider, {
|
|
158
|
+
srcUrlMapper: srcUrlMapper,
|
|
159
|
+
children: _jsx("div", {
|
|
160
|
+
style: {
|
|
161
|
+
width: '100%',
|
|
162
|
+
overflow: 'auto'
|
|
163
|
+
},
|
|
164
|
+
children: _jsx(Stack, {
|
|
165
|
+
width: "full",
|
|
166
|
+
space: "5",
|
|
167
|
+
children: sizeOptions.map(width => _jsxs(Stack, {
|
|
168
|
+
space: "1",
|
|
169
|
+
children: [_jsxs(Text, {
|
|
170
|
+
children: ["Quality: ", _jsx(Text, {
|
|
171
|
+
strong: true,
|
|
172
|
+
children: args.quality
|
|
173
|
+
})]
|
|
174
|
+
}), _jsxs(Text, {
|
|
175
|
+
children: ["Width: ", _jsxs(Text, {
|
|
176
|
+
strong: true,
|
|
177
|
+
children: [width, ": ", calcWidth(width), "px"]
|
|
178
|
+
})]
|
|
179
|
+
}), _jsx(Image, _objectSpread(_objectSpread({}, args), {}, {
|
|
180
|
+
width: calcWidth(width),
|
|
181
|
+
imageWidth: width
|
|
182
|
+
}))]
|
|
183
|
+
}, width))
|
|
184
|
+
})
|
|
185
|
+
})
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
const withImageServerResizingProps = {
|
|
189
|
+
src: 'https://cdn.autoguru.com.au/images/autoguru-test-highres-image.jpg',
|
|
190
|
+
quality: 20,
|
|
191
|
+
sizes: ['100vh',, '60vh', '40vh']
|
|
192
|
+
};
|
|
193
|
+
export const withImageServerResizing = AllSizeTemplate.bind(withImageServerResizingProps);
|
|
194
|
+
withImageServerResizing.args = withImageServerResizingProps;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../lib/components/Image/types.ts"],"names":[],"mappings":"AAAA,oBAAY,UAAU,GACnB,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withEnhancedInput.css.d.ts","sourceRoot":"","sources":["../../../../lib/components/private/InputBase/withEnhancedInput.css.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"withEnhancedInput.css.d.ts","sourceRoot":"","sources":["../../../../lib/components/private/InputBase/withEnhancedInput.css.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,IAAI;;;CAGhB,CAAC;AAEF,eAAO,MAAM,KAAK;;CA+BjB,CAAC;AAIF,eAAO,MAAM,KAAK,4BAOhB,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ResponsiveProp } from '../../utils/responsiveProps.css';
|
|
2
|
-
export declare function useResponsiveValue<T extends string | number | boolean>(responsiveValue: ResponsiveProp<T>, fallbackCase?: boolean): T;
|
|
2
|
+
export declare function useResponsiveValue<T extends string | number | boolean | {}>(responsiveValue: ResponsiveProp<T>, fallbackCase?: boolean): T;
|
|
3
3
|
//# sourceMappingURL=useResponsiveValue.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useResponsiveValue.d.ts","sourceRoot":"","sources":["../../../lib/hooks/useResponsiveValue/useResponsiveValue.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useResponsiveValue.d.ts","sourceRoot":"","sources":["../../../lib/hooks/useResponsiveValue/useResponsiveValue.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEjE,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,EAAE,EAC1E,eAAe,EAAE,cAAc,CAAC,CAAC,CAAC,EAClC,YAAY,UAAQ,GAClB,CAAC,CAYH"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
1
2
|
import { useMedia } from '../..';
|
|
2
3
|
import { getEarliestKnownToken } from '../../utils/resolveResponsiveProps';
|
|
3
4
|
export function useResponsiveValue(responsiveValue, fallbackCase = false) {
|
|
@@ -10,5 +11,5 @@ export function useResponsiveValue(responsiveValue, fallbackCase = false) {
|
|
|
10
11
|
activeBreakPoint = index + 1;
|
|
11
12
|
return activeBreakPoint;
|
|
12
13
|
}, 1);
|
|
13
|
-
return getEarliestKnownToken(responsiveValue, activeBP);
|
|
14
|
+
return useMemo(() => getEarliestKnownToken(responsiveValue, activeBP), [responsiveValue, activeBP]);
|
|
14
15
|
}
|
|
@@ -2,6 +2,6 @@ import { breakpoints } from '../themes/makeTheme';
|
|
|
2
2
|
export declare type ResponsiveProp<T> = T | T[];
|
|
3
3
|
declare type BreakpointStyleMap = Record<keyof typeof breakpoints, any>;
|
|
4
4
|
export declare const resolveResponsiveStyle: <Tokens extends string | number>(responsiveArgument: ResponsiveProp<Tokens>, breakpointTokenMap: Record<Tokens, BreakpointStyleMap>) => any;
|
|
5
|
-
export declare function getEarliestKnownToken<Tokens extends string | number | boolean>(responsiveArgument: Tokens[], counter: number): Tokens;
|
|
5
|
+
export declare function getEarliestKnownToken<Tokens extends string | number | boolean | {}>(responsiveArgument: Tokens[], counter: number): Tokens;
|
|
6
6
|
export {};
|
|
7
7
|
//# sourceMappingURL=resolveResponsiveProps.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveResponsiveProps.d.ts","sourceRoot":"","sources":["../../lib/utils/resolveResponsiveProps.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,oBAAY,cAAc,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;AAExC,aAAK,kBAAkB,GAAG,MAAM,CAAC,MAAM,OAAO,WAAW,EAAE,GAAG,CAAC,CAAC;AAShE,eAAO,MAAM,sBAAsB,6IAalC,CAAC;AAwBF,wBAAgB,qBAAqB,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,GAAG,OAAO,
|
|
1
|
+
{"version":3,"file":"resolveResponsiveProps.d.ts","sourceRoot":"","sources":["../../lib/utils/resolveResponsiveProps.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,oBAAY,cAAc,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;AAExC,aAAK,kBAAkB,GAAG,MAAM,CAAC,MAAM,OAAO,WAAW,EAAE,GAAG,CAAC,CAAC;AAShE,eAAO,MAAM,sBAAsB,6IAalC,CAAC;AAwBF,wBAAgB,qBAAqB,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,EAAE,EAClF,kBAAkB,EAAE,MAAM,EAAE,EAC5B,OAAO,EAAE,MAAM,GACb,MAAM,CAaR"}
|