UNPKG

@kubit-ui-web/react-components

Version:

Kubit React Components is a customizable, accessible library of React web components, designed to enhance your application's user experience

36 lines 1.58 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.UseClickOutsideSample = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = __importDefault(require("react")); const useClickOutside_1 = require("../useClickOutside"); const C_BLACK = 'black'; const C_RED = 'red'; const UseClickOutsideSample = () => ((0, jsx_runtime_1.jsx)("div", { style: { height: 300, width: 300, display: 'flex', justifyContent: 'center', alignItems: 'center', }, children: (0, jsx_runtime_1.jsx)(WithHookComponent, {}) })); exports.UseClickOutsideSample = UseClickOutsideSample; const WithHookComponent = () => { const ref = react_1.default.useRef(null); const [backgroundColor, setBackgroundColor] = react_1.default.useState(C_BLACK); const onClickOutside = react_1.default.useCallback(() => setBackgroundColor(prevState => (prevState === C_BLACK ? C_RED : C_BLACK)), [setBackgroundColor]); (0, useClickOutside_1.useClickOutside)(ref, onClickOutside); return ((0, jsx_runtime_1.jsx)("div", { ref: ref, style: { height: 100, width: 100, display: 'flex', justifyContent: 'center', alignItems: 'center', textAlign: 'center', color: 'white', backgroundColor, }, children: "Click outside me" })); }; //# sourceMappingURL=useClickOutside.sample.js.map