forstok-ui-lib 5.0.2 → 5.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "forstok-ui-lib",
3
- "version": "5.0.2",
3
+ "version": "5.0.3",
4
4
  "description": "Forstok UI Components Library",
5
5
  "path": "dist",
6
6
  "main": "dist/index.js",
@@ -0,0 +1,17 @@
1
+ import type { ImgHTMLAttributes, ReactEventHandler } from 'react';
2
+ import ImagePlaceholder from '../../assets/images/image-placeholder.jpg';
3
+ import { ImageContainer } from './styles';
4
+
5
+ type TImage = ImgHTMLAttributes<HTMLImageElement> & {
6
+ $mode?: string
7
+ }
8
+
9
+ const ImageComponent = ({ $mode, ...props }: TImage) => {
10
+ const { width, height } = props;
11
+ const evError: ReactEventHandler<HTMLImageElement> = e => {
12
+ (e.target as HTMLImageElement).src = ImagePlaceholder;
13
+ }
14
+ return <ImageContainer $mode={$mode} width={width} height={height} onError={evError} {...props} />;
15
+ }
16
+
17
+ export default ImageComponent;
@@ -0,0 +1,39 @@
1
+ import styled, { css } from 'styled-components'
2
+
3
+ const storeStyles = css `
4
+ width: 32px;
5
+ height: 32px;
6
+ `
7
+ const productStyles = css`
8
+ background-color: var(--mt-clr-bg);
9
+ `
10
+
11
+ const getImageModifiedStyled = ({ $mode, width, height }: { $mode?: string, width?: string|number, height?: string|number }) => {
12
+ let style = ''
13
+ if ($mode === 'store') {
14
+ style += storeStyles
15
+ } else if ($mode === 'product') {
16
+ style += productStyles
17
+ }
18
+ if (width && height) {
19
+ style += `
20
+ width:${width};
21
+ height:${height};
22
+ `
23
+ } else if (width) {
24
+ style += `
25
+ width:${width};
26
+ height:${width};
27
+ `
28
+ } else if (height) {
29
+ style += `
30
+ width:${width};
31
+ height:${height};
32
+ `
33
+ }
34
+ return style
35
+ }
36
+
37
+ export const ImageContainer = styled.img<{ $mode?: string, width?: string|number, height?: string|number }>`
38
+ ${getImageModifiedStyled}
39
+ `
@@ -11,6 +11,7 @@ export { default as MessageComponent } from './message';
11
11
  export { default as MessageQuestionComponent } from './message/question';
12
12
  export { default as PopupComponent } from './popup';
13
13
  export { default as ReactPortalComponent } from './portal';
14
+ export { default as ImageComponent } from './image';
14
15
 
15
16
  export * from './dropdown/typed';
16
17
  export * from './message/typed';
package/tsconfig.json CHANGED
@@ -22,8 +22,7 @@
22
22
  },
23
23
  "include": [
24
24
  "src",
25
- "src/declarations.d.ts"
26
- ],
25
+ "src/declarations.d.ts" ],
27
26
  "exclude": [
28
27
  "node_modules",
29
28
  "dist"