@crave/farmblocks-hoc-disabled-tooltip

2.2.8 • Public • Published

Farmblocks Disabled Tooltip HOC

A Higher Order Component that adds the behaviour of displaying a tooltip when a component is disabled (disabled property true)

Installation

npm install @crave/farmblocks-hoc-disabled-tooltip

Usage

import React from "react";
import ReactDOM from "react-dom";
import disabledTooltip from "@crave/farmblocks-hoc-disabled-tooltip";

const MyComponent = ({ children, ...props }) => (
  <button {...props}>{children}</button>
);
const ButtonWithDisabledTooltip = disabledTooltip(MyComponent);

const root = document.createElement("div");

ReactDOM.render(
  <div>
    <ButtonWithDisabledTooltip>
      My Button
    </ButtonWithDisabledTooltip>
    <ButtonWithDisabledTooltip
      disabled
      tooltipText="my custom text"
      tooltipAlign="right"
    >
      My Disabled Button
    </ButtonWithDisabledTooltip>
  </div>,
  root
);

document.body.appendChild(root);

See more examples in the stories file.

API

This HOC will add the following properties to a given component:

Property Type Description
disabled Boolean a flag that indicates that the element is disabled, and so should display the tooltip
tooltipAlign String, one of "left" or "right" Which side to align the disabled tooltip balloon
tooltipText String A custom text to display as tooltip when the component is disabled
displayBlock Boolean use this flag to override the default css style of the resulting element from inline-block to block

License

MIT

Dependencies (1)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i @crave/farmblocks-hoc-disabled-tooltip

    Weekly Downloads

    962

    Version

    2.2.8

    License

    MIT

    Unpacked Size

    22.5 kB

    Total Files

    7

    Last publish

    Collaborators

    • viniciusmartin
    • luis.nascimento
    • seocam
    • vnakamura
    • alcferreira
    • imwra