From e00863a343a3e71468e7ddf6a550bac98972abe7 Mon Sep 17 00:00:00 2001 From: Aleksandr Gumroian Date: Fri, 18 Mar 2022 18:43:13 +0100 Subject: [PATCH] Add Bootstrap tooltip component --- src/bootstrap/Tooltip.js | 38 ++++++++++++++++++++++++++++++++++++++ src/index.js | 1 + 2 files changed, 39 insertions(+) create mode 100644 src/bootstrap/Tooltip.js diff --git a/src/bootstrap/Tooltip.js b/src/bootstrap/Tooltip.js new file mode 100644 index 0000000..064039e --- /dev/null +++ b/src/bootstrap/Tooltip.js @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2019 CZ.NIC z.s.p.o. (http://www.nic.cz/) + * + * This is free software, licensed under the GNU General Public License v3. + * See /LICENSE for more information. + */ + +import React, { useEffect, useRef } from "react"; +import PropTypes from "prop-types"; + +import { Tooltip as BSTooltip } from "bootstrap/dist/js/bootstrap.esm"; + +export function Tooltip({ title, placement, trigger, children }) { + const tooltipRef = useRef(); + + useEffect(() => { + const tooltip = new BSTooltip(tooltipRef.current, { + title, + placement, + trigger, + }); + }); + + return {children}; +} + +Tooltip.propTypes = { + /** Field label. */ + title: PropTypes.string.isRequired, + /** Error text. */ + placement: PropTypes.string, + /** Help text message. */ + trigger: PropTypes.string, + children: PropTypes.oneOfType([ + PropTypes.arrayOf(PropTypes.node), + PropTypes.node, + ]), +}; diff --git a/src/index.js b/src/index.js index ee7edad..26ad716 100644 --- a/src/index.js +++ b/src/index.js @@ -30,6 +30,7 @@ export { PasswordInput } from "./bootstrap/PasswordInput"; export { Radio, RadioSet } from "./bootstrap/RadioSet"; export { Select } from "./bootstrap/Select"; export { TextInput } from "./bootstrap/TextInput"; +export { Tooltip } from "./bootstrap/Tooltip"; export { formFieldsSize, buttonFormFieldsSize } from "./bootstrap/constants"; export { Switch } from "./bootstrap/Switch";