@gem-sdk/plugin-quick-view 1.0.0
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/README.md +1 -0
- package/dist/cjs/components/QuickView.js +58 -0
- package/dist/cjs/index.js +11 -0
- package/dist/cjs/setting/QuickView.js +10 -0
- package/dist/cjs/setting/index.js +9 -0
- package/dist/esm/components/QuickView.js +54 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/setting/QuickView.js +6 -0
- package/dist/esm/setting/index.js +5 -0
- package/dist/types/index.d.ts +13 -0
- package/package.json +40 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# GemX Plugin
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
var components = require('@gem-sdk/components');
|
|
7
|
+
var core = require('@gem-sdk/core');
|
|
8
|
+
var react = require('react');
|
|
9
|
+
|
|
10
|
+
const ModalContent = () => {
|
|
11
|
+
const product = core.useProduct();
|
|
12
|
+
const { data, isLoading: loading, error } = core.useProductQuery(product?.id);
|
|
13
|
+
if (loading)
|
|
14
|
+
return (jsxRuntime.jsx("div", { children: jsxRuntime.jsxs("svg", { className: "my-20 mx-auto h-8 w-8 animate-spin", xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: [jsxRuntime.jsx("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }), jsxRuntime.jsx("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" })] }) }));
|
|
15
|
+
if (error)
|
|
16
|
+
return jsxRuntime.jsx("p", { className: "py-20 text-center font-semibold", children: "Something went wrong" });
|
|
17
|
+
return (jsxRuntime.jsx(core.ProductProvider, { product: data, children: jsxRuntime.jsxs(components.Row, { setting: {
|
|
18
|
+
responsive: {
|
|
19
|
+
desktop: '50fr 50fr',
|
|
20
|
+
mobile: '100fr',
|
|
21
|
+
},
|
|
22
|
+
}, children: [jsxRuntime.jsx(components.Col, { children: jsxRuntime.jsx(components.ProductImages, {}) }), jsxRuntime.jsxs(components.Col, { children: [jsxRuntime.jsx(components.ProductTitle, { setting: {
|
|
23
|
+
htmlTag: 'p',
|
|
24
|
+
}, styles: {
|
|
25
|
+
typography: {
|
|
26
|
+
type: 'heading-3',
|
|
27
|
+
},
|
|
28
|
+
} }), jsxRuntime.jsxs(components.Row, { setting: {
|
|
29
|
+
responsive: {
|
|
30
|
+
desktop: 'minmax(max-content, auto) 1fr',
|
|
31
|
+
},
|
|
32
|
+
}, children: [jsxRuntime.jsx(components.Col, { children: jsxRuntime.jsx(components.ProductPrice, { styles: {
|
|
33
|
+
typography: {
|
|
34
|
+
type: 'subheading-2',
|
|
35
|
+
},
|
|
36
|
+
}, setting: {
|
|
37
|
+
priceType: 'regular',
|
|
38
|
+
} }) }), jsxRuntime.jsx(components.Col, { children: jsxRuntime.jsx(components.ProductPrice, { styles: {
|
|
39
|
+
typography: {
|
|
40
|
+
type: 'paragraph-2',
|
|
41
|
+
},
|
|
42
|
+
}, setting: {
|
|
43
|
+
priceType: 'compare',
|
|
44
|
+
} }) })] }), jsxRuntime.jsx(components.ProductVariants, {}), jsxRuntime.jsx(components.ProductQuantity, {}), jsxRuntime.jsx(components.ProductButton, { setting: { actionEffect: 'open-cart-drawer' } })] })] }) }));
|
|
45
|
+
};
|
|
46
|
+
const ProductQuickView = ({ setting }) => {
|
|
47
|
+
const [open, setOpen] = react.useState(false);
|
|
48
|
+
const plugins = core.usePluginEnable();
|
|
49
|
+
if (!plugins?.includes('quick-view')) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
return (jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("div", { "aria-hidden": true, role: "button", "aria-label": "Quick view", onClick: () => setOpen((prev) => !prev), children: setting?.label }), jsxRuntime.jsx(components.Modal, { setting: { open }, closeOnClickOutside: true, onClose: () => setOpen((prev) => !prev), children: jsxRuntime.jsx(ModalContent, {}) })] }));
|
|
53
|
+
};
|
|
54
|
+
ProductQuickView.defaultProps = {
|
|
55
|
+
setting: { label: 'Quick View' },
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
exports.default = ProductQuickView;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var QuickView = require('./components/QuickView.js');
|
|
6
|
+
var index = require('./setting/index.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
exports.default = QuickView.default;
|
|
11
|
+
exports.builderSetting = index.default;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { Modal, Row, Col, ProductImages, ProductTitle, ProductPrice, ProductVariants, ProductQuantity, ProductButton } from '@gem-sdk/components';
|
|
3
|
+
import { usePluginEnable, useProduct, useProductQuery, ProductProvider } from '@gem-sdk/core';
|
|
4
|
+
import { useState } from 'react';
|
|
5
|
+
|
|
6
|
+
const ModalContent = () => {
|
|
7
|
+
const product = useProduct();
|
|
8
|
+
const { data, isLoading: loading, error } = useProductQuery(product?.id);
|
|
9
|
+
if (loading)
|
|
10
|
+
return (jsx("div", { children: jsxs("svg", { className: "my-20 mx-auto h-8 w-8 animate-spin", xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: [jsx("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }), jsx("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" })] }) }));
|
|
11
|
+
if (error)
|
|
12
|
+
return jsx("p", { className: "py-20 text-center font-semibold", children: "Something went wrong" });
|
|
13
|
+
return (jsx(ProductProvider, { product: data, children: jsxs(Row, { setting: {
|
|
14
|
+
responsive: {
|
|
15
|
+
desktop: '50fr 50fr',
|
|
16
|
+
mobile: '100fr',
|
|
17
|
+
},
|
|
18
|
+
}, children: [jsx(Col, { children: jsx(ProductImages, {}) }), jsxs(Col, { children: [jsx(ProductTitle, { setting: {
|
|
19
|
+
htmlTag: 'p',
|
|
20
|
+
}, styles: {
|
|
21
|
+
typography: {
|
|
22
|
+
type: 'heading-3',
|
|
23
|
+
},
|
|
24
|
+
} }), jsxs(Row, { setting: {
|
|
25
|
+
responsive: {
|
|
26
|
+
desktop: 'minmax(max-content, auto) 1fr',
|
|
27
|
+
},
|
|
28
|
+
}, children: [jsx(Col, { children: jsx(ProductPrice, { styles: {
|
|
29
|
+
typography: {
|
|
30
|
+
type: 'subheading-2',
|
|
31
|
+
},
|
|
32
|
+
}, setting: {
|
|
33
|
+
priceType: 'regular',
|
|
34
|
+
} }) }), jsx(Col, { children: jsx(ProductPrice, { styles: {
|
|
35
|
+
typography: {
|
|
36
|
+
type: 'paragraph-2',
|
|
37
|
+
},
|
|
38
|
+
}, setting: {
|
|
39
|
+
priceType: 'compare',
|
|
40
|
+
} }) })] }), jsx(ProductVariants, {}), jsx(ProductQuantity, {}), jsx(ProductButton, { setting: { actionEffect: 'open-cart-drawer' } })] })] }) }));
|
|
41
|
+
};
|
|
42
|
+
const ProductQuickView = ({ setting }) => {
|
|
43
|
+
const [open, setOpen] = useState(false);
|
|
44
|
+
const plugins = usePluginEnable();
|
|
45
|
+
if (!plugins?.includes('quick-view')) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
return (jsxs("div", { children: [jsx("div", { "aria-hidden": true, role: "button", "aria-label": "Quick view", onClick: () => setOpen((prev) => !prev), children: setting?.label }), jsx(Modal, { setting: { open }, closeOnClickOutside: true, onClose: () => setOpen((prev) => !prev), children: jsx(ModalContent, {}) })] }));
|
|
49
|
+
};
|
|
50
|
+
ProductQuickView.defaultProps = {
|
|
51
|
+
setting: { label: 'Quick View' },
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export { ProductQuickView as default };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as _gem_sdk_core from '@gem-sdk/core';
|
|
2
|
+
import { BaseProps } from '@gem-sdk/core';
|
|
3
|
+
|
|
4
|
+
type ProductQuickViewProps = BaseProps<{
|
|
5
|
+
label?: React.ReactNode;
|
|
6
|
+
}>;
|
|
7
|
+
declare const ProductQuickView: React.FC<ProductQuickViewProps>;
|
|
8
|
+
|
|
9
|
+
declare const _default: {
|
|
10
|
+
QuickView: _gem_sdk_core.ComponentSetting<ProductQuickViewProps>;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export { _default as builderSetting, ProductQuickView as default };
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gem-sdk/plugin-quick-view",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"main": "dist/cjs/index.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"cleanup": "rimraf es dist lib",
|
|
12
|
+
"prebuild": "yarn cleanup",
|
|
13
|
+
"pre:publish": "node ./../../helpers/convert-publish.js -p",
|
|
14
|
+
"post:publish": "node ./../../helpers/convert-publish.js",
|
|
15
|
+
"watch": "rollup -c ./../../helpers/rollup.config.mjs -w",
|
|
16
|
+
"build": "rollup -c ./../../helpers/rollup.config.mjs --environment NODE_ENV:production",
|
|
17
|
+
"lint": "eslint ./src --ext .tsx,.ts",
|
|
18
|
+
"type-check": "yarn tsc --noEmit",
|
|
19
|
+
"test": "jest -c ./../../helpers/jest.config.ts"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@gem-sdk/components": "*",
|
|
23
|
+
"@gem-sdk/core": "*",
|
|
24
|
+
"@gem-sdk/styles": "*"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"react": "^17 || ^18",
|
|
28
|
+
"react-dom": "^17 || ^18"
|
|
29
|
+
},
|
|
30
|
+
"module": "dist/esm/index.js",
|
|
31
|
+
"types": "dist/types/index.d.ts",
|
|
32
|
+
"exports": {
|
|
33
|
+
"./package.json": "./package.json",
|
|
34
|
+
".": {
|
|
35
|
+
"import": "./dist/esm/index.js",
|
|
36
|
+
"require": "./dist/cjs/index.js",
|
|
37
|
+
"types": "./dist/types/index.d.ts"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|