1.1.0 ā€¢ Published 4 months ago

universal-tooltip v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago
Works on all platforms, Example project here.
iOSAndroidWeb

What

This is a pure and simple native tooltip component that supports fadeIn and zoomIn preset animations.

šŸŽ On iOS:

  • This component is written in Swift and wraps Popovers.

šŸ¤–ļø On Android:

  • This component is written in Kotlin and wraps the excellent library - Balloon.

šŸŒ On Web:

Please note that the @radix-ui/react-tooltip component from Radix only works on desktop, as per this thread.

Usage

import { useState } from "react";
import * as Tooltip from "universal-tooltip";
import { Text, View, Pressable, Platform } from "react-native";

// because each platform has different behaviors, but you can replace the components yourself, of course.
const TriggerView = Platform.OS === "web" ? View : Pressable;

const [open, setOpen] = useState(false);

<Tooltip.Root
  // For web, I would like to be triggered automatically with the mouse.
  {...Platform.select({
    web: {},
    default: {
      open,
      onDismiss: () => {
        console.log("onDismiss");
        setOpen(false);
      },
    },
  })}
>
  <Tooltip.Trigger>
    <TriggerView
      {...Platform.select({
        web: {},
        default: {
          open,
          onPress: () => {
            setOpen(true);
          },
        },
      })}
    >
      <Text>Hello!šŸ‘‹</Text>
    </TriggerView>
  </Tooltip.Trigger>
  <Tooltip.Content
    sideOffset={3}
    containerStyle={{
      paddingLeft: 16,
      paddingRight: 16,
      paddingTop: 8,
      paddingBottom: 8,
    }}
    onTap={() => {
      setOpen(false);
      console.log("onTap");
    }}
    dismissDuration={500}
    disableTapToDismiss
    side="right"
    presetAnimation="fadeIn"
    backgroundColor="black"
    borderRadius={12}
  >
    <Tooltip.Text text="Some copy..." style={{ color: "#000", fontSize: 16 }} />
  </Tooltip.Content>
</Tooltip.Root>;

API

This component's API basically same as the @radix-ui/react-tooltip component, but there are some differences on native.

Installation

yarn add universal-tooltip

Expo

expo install universal-tooltip expo-build-properties

To use this component, you need to add the expo-build-properties plugin to your app.json or app.config.js and ensure that your compileSdkVersion >= 32 as required by the Ballon lib. An example configuration might look like this:

[
  "expo-build-properties",
  {
    "android": {
      "compileSdkVersion": 32,
      "targetSdkVersion": 32,
      "minSdkVersion": 23,
      "buildToolsVersion": "32.0.0",
      "kotlinVersion": "1.6.10"
    },
    "ios": {
      "deploymentTarget": "13.0"
    }
  }
]

License

MIT

1.1.0

4 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

9 months ago

1.0.0-1

9 months ago

1.0.0-0

9 months ago

1.0.0-2

9 months ago

0.7.0

10 months ago

0.6.1

11 months ago

0.6.0

11 months ago

0.3.0

1 year ago

0.2.0

1 year ago

0.5.0

12 months ago

0.4.1

1 year ago

0.4.0

1 year ago

0.4.2

1 year ago

0.1.11

1 year ago

0.1.10

1 year ago

0.1.9

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago