main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
986 bytes
|
Line | |
---|
1 | "use strict";
|
---|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
3 | var tslib_1 = require("tslib");
|
---|
4 | var React = tslib_1.__importStar(require("react"));
|
---|
5 | var util_1 = require("./misc/util");
|
---|
6 | var useState = React.useState;
|
---|
7 | var useHover = function (element) {
|
---|
8 | var _a = useState(false), state = _a[0], setState = _a[1];
|
---|
9 | var onMouseEnter = function (originalOnMouseEnter) { return function (event) {
|
---|
10 | (originalOnMouseEnter || util_1.noop)(event);
|
---|
11 | setState(true);
|
---|
12 | }; };
|
---|
13 | var onMouseLeave = function (originalOnMouseLeave) { return function (event) {
|
---|
14 | (originalOnMouseLeave || util_1.noop)(event);
|
---|
15 | setState(false);
|
---|
16 | }; };
|
---|
17 | if (typeof element === 'function') {
|
---|
18 | element = element(state);
|
---|
19 | }
|
---|
20 | var el = React.cloneElement(element, {
|
---|
21 | onMouseEnter: onMouseEnter(element.props.onMouseEnter),
|
---|
22 | onMouseLeave: onMouseLeave(element.props.onMouseLeave),
|
---|
23 | });
|
---|
24 | return [el, state];
|
---|
25 | };
|
---|
26 | exports.default = useHover;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.