@elvia/elvis-spotlight 1.0.0-beta.3 → 1.2.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.
@@ -6,10 +6,9 @@ export interface SpotlightPosition {
6
6
  export interface SpotlightProps {
7
7
  position: SpotlightPosition | undefined;
8
8
  radius?: number;
9
+ hasLockBodyScroll?: boolean;
9
10
  className?: string;
10
- inlineStyle?: {
11
- [style: string]: CSSProperties;
12
- };
11
+ inlineStyle?: CSSProperties;
13
12
  }
14
13
  declare const Spotlight: FC<SpotlightProps>;
15
14
  export default Spotlight;
@@ -2,36 +2,62 @@
2
2
  * THIS FILE IS AUTOMATICALLY GENERATED AND WILL BE OVERWRITTEN.
3
3
  * DO NOT MAKE CHANGES TO THIS FILE DIRECTLY
4
4
  */
5
- import React from 'react';
6
- import { SpotlightArea, SpotlightCircle } from './styledComponents';
7
-
8
- const Spotlight = ({
9
- position,
10
- radius = 200,
11
- className,
12
- inlineStyle
13
- }) => {
14
- const hasPosition = position && position.horizontal && position.vertical;
15
- return /*#__PURE__*/React.createElement("div", {
16
- className: `${hasPosition && className ? className : ''}`,
17
- style: hasPosition ? inlineStyle : {}
18
- }, hasPosition && /*#__PURE__*/React.createElement(SpotlightArea, null, /*#__PURE__*/React.createElement("defs", null, /*#__PURE__*/React.createElement("mask", {
5
+ "use strict";
6
+
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ exports.default = void 0;
11
+
12
+ var _react = _interopRequireDefault(require("react"));
13
+
14
+ var _styledComponents = require("./styledComponents");
15
+
16
+ var _useLockBodyScroll = require("./useLockBodyScroll");
17
+
18
+ var _excluded = ["position", "radius", "hasLockBodyScroll", "className", "inlineStyle"];
19
+
20
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
+
22
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
23
+
24
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
25
+
26
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
27
+
28
+ var Spotlight = function Spotlight(_ref) {
29
+ var position = _ref.position,
30
+ _ref$radius = _ref.radius,
31
+ radius = _ref$radius === void 0 ? 200 : _ref$radius,
32
+ _ref$hasLockBodyScrol = _ref.hasLockBodyScroll,
33
+ hasLockBodyScroll = _ref$hasLockBodyScrol === void 0 ? true : _ref$hasLockBodyScrol,
34
+ className = _ref.className,
35
+ inlineStyle = _ref.inlineStyle,
36
+ rest = _objectWithoutProperties(_ref, _excluded);
37
+
38
+ var hasPosition = position && position.horizontal && position.vertical;
39
+ (0, _useLockBodyScroll.useLockBodyScroll)(hasLockBodyScroll);
40
+ return hasPosition ? /*#__PURE__*/_react.default.createElement("div", _extends({
41
+ className: "".concat(className ? className : ''),
42
+ style: inlineStyle
43
+ }, rest), /*#__PURE__*/_react.default.createElement(_styledComponents.SpotlightArea, null, /*#__PURE__*/_react.default.createElement("defs", null, /*#__PURE__*/_react.default.createElement("mask", {
19
44
  id: "hole"
20
- }, /*#__PURE__*/React.createElement("rect", {
45
+ }, /*#__PURE__*/_react.default.createElement("rect", {
21
46
  width: "100%",
22
47
  height: "100%",
23
48
  fill: "white"
24
- }), /*#__PURE__*/React.createElement(SpotlightCircle, {
49
+ }), /*#__PURE__*/_react.default.createElement(_styledComponents.SpotlightCircle, {
25
50
  r: radius,
26
51
  cx: position.horizontal,
27
52
  cy: position.vertical,
28
53
  fill: "black"
29
- }))), /*#__PURE__*/React.createElement("rect", {
54
+ }))), /*#__PURE__*/_react.default.createElement("rect", {
30
55
  fill: "rgba(0,0,0,0.25)",
31
56
  width: "100%",
32
57
  height: "100%",
33
58
  mask: "url(#hole)"
34
- })));
59
+ }))) : /*#__PURE__*/_react.default.createElement("div", null);
35
60
  };
36
61
 
37
- export default Spotlight;
62
+ var _default = Spotlight;
63
+ exports.default = _default;
@@ -2,12 +2,27 @@
2
2
  * THIS FILE IS AUTOMATICALLY GENERATED AND WILL BE OVERWRITTEN.
3
3
  * DO NOT MAKE CHANGES TO THIS FILE DIRECTLY
4
4
  */
5
- import styled from 'styled-components';
6
- export const SpotlightArea = styled.svg.withConfig({
5
+ "use strict";
6
+
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ exports.SpotlightCircle = exports.SpotlightArea = void 0;
11
+
12
+ var _styledComponents = _interopRequireDefault(require("styled-components"));
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ var SpotlightArea = _styledComponents.default.svg.withConfig({
7
17
  displayName: "styledComponents__SpotlightArea",
8
18
  componentId: "sc-env4mw-0"
9
19
  })(["position:fixed;top:0;left:0;z-index:99999;width:100vw;height:100vh;"]);
10
- export const SpotlightCircle = styled.circle.withConfig({
20
+
21
+ exports.SpotlightArea = SpotlightArea;
22
+
23
+ var SpotlightCircle = _styledComponents.default.circle.withConfig({
11
24
  displayName: "styledComponents__SpotlightCircle",
12
25
  componentId: "sc-env4mw-1"
13
- })(["transition:all 350ms ease-in-out;"]);
26
+ })(["transition:all 350ms ease-in-out;"]);
27
+
28
+ exports.SpotlightCircle = SpotlightCircle;
@@ -0,0 +1 @@
1
+ export declare function useLockBodyScroll(removeLockBodyScroll: boolean): void;
@@ -0,0 +1,33 @@
1
+ /*
2
+ * THIS FILE IS AUTOMATICALLY GENERATED AND WILL BE OVERWRITTEN.
3
+ * DO NOT MAKE CHANGES TO THIS FILE DIRECTLY
4
+ */
5
+ "use strict";
6
+
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ exports.useLockBodyScroll = useLockBodyScroll;
11
+
12
+ var _react = require("react");
13
+
14
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
15
+ function useLockBodyScroll(removeLockBodyScroll) {
16
+ (0, _react.useEffect)(function () {
17
+ var originalStyleOverflowBody = window.getComputedStyle(document.body).overflow;
18
+ var originalStyleOverflowHtml = window.getComputedStyle(document.documentElement).overflow;
19
+
20
+ if (!removeLockBodyScroll) {
21
+ document.body.style.overflow = originalStyleOverflowBody;
22
+ document.documentElement.style.overflow = originalStyleOverflowHtml;
23
+ return;
24
+ }
25
+
26
+ document.body.style.overflow = 'hidden';
27
+ document.documentElement.style.overflow = 'hidden';
28
+ return function () {
29
+ document.body.style.overflow = originalStyleOverflowBody;
30
+ document.documentElement.style.overflow = originalStyleOverflowHtml;
31
+ };
32
+ }, [removeLockBodyScroll]);
33
+ }
@@ -7,7 +7,7 @@ import { ElvisComponentWrapper } from '@elvia/elvis-component-wrapper';
7
7
  const style = ``;
8
8
  export default class ElviaComponent extends ElvisComponentWrapper {
9
9
  static get observedAttributes() {
10
- return ["position", "radius"];
10
+ return ["position", "radius", "haslockbodyscroll", "classname", "inlinestyle"];
11
11
  }
12
12
 
13
13
  static getComponentData() {
@@ -22,6 +22,18 @@ export default class ElviaComponent extends ElvisComponentWrapper {
22
22
  "name": "radius",
23
23
  "type": "number",
24
24
  "propType": "number"
25
+ }, {
26
+ "name": "hasLockBodyScroll",
27
+ "type": "boolean",
28
+ "propType": "boolean"
29
+ }, {
30
+ "name": "className",
31
+ "type": "string",
32
+ "propType": "string | undefined"
33
+ }, {
34
+ "name": "inlineStyle",
35
+ "type": "object",
36
+ "propType": "object | undefined"
25
37
  }],
26
38
  "reactName": "Spotlight",
27
39
  "slotItems": false,
@@ -50,6 +62,66 @@ export default class ElviaComponent extends ElvisComponentWrapper {
50
62
  return super.getProps()['radius'];
51
63
  }
52
64
 
65
+ set hasLockBodyScroll(newValue) {
66
+ super.setProps({
67
+ 'haslockbodyscroll': newValue
68
+ });
69
+ }
70
+
71
+ get hasLockBodyScroll() {
72
+ return super.getProps()['haslockbodyscroll'];
73
+ }
74
+
75
+ set haslockbodyscroll(newValue) {
76
+ super.setProps({
77
+ 'haslockbodyscroll': newValue
78
+ });
79
+ }
80
+
81
+ get haslockbodyscroll() {
82
+ return super.getProps()['haslockbodyscroll'];
83
+ }
84
+
85
+ set className(newValue) {
86
+ super.setProps({
87
+ 'classname': newValue
88
+ });
89
+ }
90
+
91
+ get className() {
92
+ return super.getProps()['classname'];
93
+ }
94
+
95
+ set classname(newValue) {
96
+ super.setProps({
97
+ 'classname': newValue
98
+ });
99
+ }
100
+
101
+ get classname() {
102
+ return super.getProps()['classname'];
103
+ }
104
+
105
+ set inlineStyle(newValue) {
106
+ super.setProps({
107
+ 'inlinestyle': newValue
108
+ });
109
+ }
110
+
111
+ get inlineStyle() {
112
+ return super.getProps()['inlinestyle'];
113
+ }
114
+
115
+ set inlinestyle(newValue) {
116
+ super.setProps({
117
+ 'inlinestyle': newValue
118
+ });
119
+ }
120
+
121
+ get inlinestyle() {
122
+ return super.getProps()['inlinestyle'];
123
+ }
124
+
53
125
  constructor() {
54
126
  super(ElviaComponent, ReactComponent['Spotlight'], style);
55
127
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elvia/elvis-spotlight",
3
- "version": "1.0.0-beta.3",
3
+ "version": "1.2.0",
4
4
  "description": "",
5
5
  "main": "web_component.js",
6
6
  "scripts": {
@@ -9,7 +9,7 @@
9
9
  "author": "",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
- "@elvia/elvis-component-wrapper": "^2.2.2",
12
+ "@elvia/elvis-component-wrapper": "^2.3.0",
13
13
  "styled-components": "^5.3.3"
14
14
  },
15
15
  "devDependencies": {
@@ -22,4 +22,4 @@
22
22
  "react-dom": "^16.8.0 || ^17.0.0",
23
23
  "react-is": ">= 16.8.0"
24
24
  }
25
- }
25
+ }
package/react.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ declare module '@elvia/elvis-spotlight/react';
2
+ export { default as Spotlight } from './dist/react/js/elvia-spotlight';
3
+ export type { SpotlightProps } from './dist/react/js/elvia-spotlight';
4
+ export type * from './dist/react/js/elvia-spotlight';
@@ -1,35 +1,45 @@
1
- import React, { CSSProperties, FC } from 'react';
2
- import { SpotlightArea, SpotlightCircle } from './styledComponents';
3
-
4
- export interface SpotlightPosition {
5
- vertical: number | undefined;
6
- horizontal: number | undefined;
7
- }
8
- export interface SpotlightProps {
9
- position: SpotlightPosition | undefined;
10
- radius?: number;
11
- className?: string;
12
- inlineStyle?: { [style: string]: CSSProperties };
13
- }
14
-
15
- const Spotlight: FC<SpotlightProps> = ({ position, radius = 200, className, inlineStyle }) => {
16
- const hasPosition = position && position.horizontal && position.vertical;
17
-
18
- return (
19
- <div className={`${hasPosition && className ? className : ''}`} style={hasPosition ? inlineStyle : {}}>
20
- {hasPosition && (
21
- <SpotlightArea>
22
- <defs>
23
- <mask id="hole">
24
- <rect width="100%" height="100%" fill="white" />
25
- <SpotlightCircle r={radius} cx={position.horizontal} cy={position.vertical} fill="black" />
26
- </mask>
27
- </defs>
28
- <rect fill="rgba(0,0,0,0.25)" width="100%" height="100%" mask="url(#hole)" />
29
- </SpotlightArea>
30
- )}
31
- </div>
32
- );
33
- };
34
-
35
- export default Spotlight;
1
+ import React, { CSSProperties, FC } from 'react';
2
+ import { SpotlightArea, SpotlightCircle } from './styledComponents';
3
+ import { useLockBodyScroll } from './useLockBodyScroll';
4
+
5
+ export interface SpotlightPosition {
6
+ vertical: number | undefined;
7
+ horizontal: number | undefined;
8
+ }
9
+ export interface SpotlightProps {
10
+ position: SpotlightPosition | undefined;
11
+ radius?: number;
12
+ hasLockBodyScroll?: boolean;
13
+ className?: string;
14
+ inlineStyle?: CSSProperties;
15
+ }
16
+
17
+ const Spotlight: FC<SpotlightProps> = ({
18
+ position,
19
+ radius = 200,
20
+ hasLockBodyScroll = true,
21
+ className,
22
+ inlineStyle,
23
+ ...rest
24
+ }) => {
25
+ const hasPosition = position && position.horizontal && position.vertical;
26
+ useLockBodyScroll(hasLockBodyScroll);
27
+
28
+ return hasPosition ? (
29
+ <div className={`${className ? className : ''}`} style={inlineStyle} {...rest}>
30
+ <SpotlightArea>
31
+ <defs>
32
+ <mask id="hole">
33
+ <rect width="100%" height="100%" fill="white" />
34
+ <SpotlightCircle r={radius} cx={position.horizontal} cy={position.vertical} fill="black" />
35
+ </mask>
36
+ </defs>
37
+ <rect fill="rgba(0,0,0,0.25)" width="100%" height="100%" mask="url(#hole)" />
38
+ </SpotlightArea>
39
+ </div>
40
+ ) : (
41
+ <div></div>
42
+ );
43
+ };
44
+
45
+ export default Spotlight;
@@ -0,0 +1,21 @@
1
+ import { useEffect } from 'react';
2
+
3
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
4
+ export function useLockBodyScroll(removeLockBodyScroll: boolean) {
5
+ useEffect(() => {
6
+ const originalStyleOverflowBody = window.getComputedStyle(document.body).overflow;
7
+ const originalStyleOverflowHtml = window.getComputedStyle(document.documentElement).overflow;
8
+ if (!removeLockBodyScroll) {
9
+ document.body.style.overflow = originalStyleOverflowBody;
10
+ document.documentElement.style.overflow = originalStyleOverflowHtml;
11
+ return;
12
+ }
13
+ document.body.style.overflow = 'hidden';
14
+ document.documentElement.style.overflow = 'hidden';
15
+
16
+ return () => {
17
+ document.body.style.overflow = originalStyleOverflowBody;
18
+ document.documentElement.style.overflow = originalStyleOverflowHtml;
19
+ };
20
+ }, [removeLockBodyScroll]);
21
+ }
@@ -1,4 +0,0 @@
1
- /*
2
- * THIS FILE IS AUTOMATICALLY GENERATED AND WILL BE OVERWRITTEN.
3
- * DO NOT MAKE CHANGES TO THIS FILE DIRECTLY
4
- */
@@ -1 +0,0 @@
1
- declare module '*';
@@ -1 +0,0 @@
1
- declare module '*';