Skip to main content

usePopup

The usePopup hook allows developers to manage popups with various types and customizable properties. This hook can be used in combination with the PopupProvider to display popups throughout the application.

Import

import usePopup, { PopupProvider } from "phaselis";
  • usePopup: The custom hook for managing popups.
  • PopupProvider: A provider component that needs to wrap your application or specific component tree to enable the use of usePopup.

Usage

Basic Example

Ensure that your application is wrapped with the PopupProvider so that the context is accessible.

import React from 'react';
import { PopupProvider } from 'phaselis';
import AppContent from './AppContent';

const App = () => {
return (
<PopupProvider>
<AppContent />
</PopupProvider>
);
};

export default App;

Using the usePopup Hook

import React from 'react';
import usePopup from 'phaselis';
import { Button, Text } from 'react-native';

const ExampleComponent = () => {
const [show, setShow] = usePopup('info', <Text>This is an info popup</Text>, {
duration: 3000,
title: 'Info',
});

return (
<Button
title="Show Popup"
onPress={() => setShow(show === 'show' ? 'hide' : 'show')}
/>
);
};

Props and Configuration

The usePopup hook supports different popup types, which change the appearance and icons used:

  • default
  • info (uses the "Info" icon)
  • success (uses the "CheckCheck" icon)
  • warning (uses the "MessageSquareWarning" icon)
  • error (uses the "Bomb" icon)
NameTypeDescription
idstringUnique identifier for the popup.
show`"show""hide"`
contentReactNodeThe content displayed inside the popup.
typePopupTypeThe type of popup (e.g., info, success).
extraPropsPopupExtraPropsAdditional properties for customizing the popup.

PopupExtraProps

NameTypeDescription
durationnumberThe duration for which the popup is shown (in milliseconds).
onClose() => voidCallback function triggered when the popup is closed.
fullScreenbooleanDetermines if the popup should be displayed in fullscreen mode.
contextValueanyContext value for further customization.
styleanyCustom styles for the popup container.
leftIconSlotIconNameThe name of the icon displayed on the left side of the popup header.
LeftSlotReactNodeCustom component to be displayed in the left slot of the popup header.
titlestringThe title displayed in the popup header.

Info

For available icons, refer to the Lucide Icons.