The TipModal
component is a Svelte-based modal designed for displaying various payment options and allowing users to trigger it with customizable buttons. This component is lightweight, easy to use, and allows customization via props and slots.
To use the TipModal
component in your project, install it like so:
npm install git+https://github.com/clams-tech/tip-modal.git
Then, import it into your project:
import {TipModal} from 'tip-modal';
and import the styles:
import 'tip-modal/app.css';
- Type:
boolean
- Description: Controls the visibility of the modal.
- Example:
let showModal = false;
- Type:
Function
- Description: Function to set
showModal
totrue
and open the modal. - Example:
function openModal() { showModal = true; }
- Type:
Function
- Description: Function to set
showModal
tofalse
and close the modal. - Example:
function closeModal() { showModal = false; }
- Type:
Array
- Description: An array of payment options to display in the modal.
- Example:
const paymentOptions = [ { label: 'BOLT12', value: 'lno1zrxq8pjw7qjlm68mtp7e3yvxee4y5xrgjhhyf2fxhlphpckrvevh50u0qt2rt2xr6uuj7cfce48c5cr8sa2dqp2nkumkuztlq840mpjj95anvqsrh809gs052xe9reyna6v2djjv4p7k0leqy9uhthm8tpvvppphlmfsqvcdy9947hanvmq9mssn970apemvm7hjhg54qfdahgq2t5rwzca27ksjcz7lwn8xyl9qet4lmd4zjq8ucy4gq0cjem6q47gcl8a4f9lcr0qajukk809lnu7az9wupm0vz6ljh3ajgqqspdlvl6crzaxz9ueuu5h9as269y' }, { label: 'LNURL', value: 'https://clams.tech/.well-known/lnurlp/tips' }, { label: 'LN Address', value: 'tips@clams.tech' }, { label: 'Onchain', value: 'bitcoin:32KAVNNDqjvw9SgProPnffVgdg4YEhgVKy' } ];
-
Type:
string
-
Default:
"tips"
-
Description: A customizable identifier for the default LNURL and LN Address payment options. This allows tracking of where payments originate, such as different apps.
-
Example Usage:
<TipModal paymentTag="remote" />
This results in the following payment options:
const paymentOptions = [
{ label: 'BOLT12', value: 'lno1zrxq8pjw7qjlm68mtp7e3yvxee4y5xrgjhhyf2fxhlphpckrvevh50u0qt2rt2xr6uuj7cfce48c5cr8sa2dqp2nkumkuztlq840mpjj95anvqsrh809gs052xe9reyna6v2djjv4p7k0leqy9uhthm8tpvvppphlmfsqvcdy9947hanvmq9mssn970apemvm7hjhg54qfdahgq2t5rwzca27ksjcz7lwn8xyl9qet4lmd4zjq8ucy4gq0cjem6q47gcl8a4f9lcr0qajukk809lnu7az9wupm0vz6ljh3ajgqqspdlvl6crzaxz9ueuu5h9as269y' },
{ label: 'LNURL', value: 'https://clams.tech/.well-known/lnurlp/remote' },
{ label: 'LN Address', value: 'remote@clams.tech' },
{ label: 'Onchain', value: 'bitcoin:32KAVNNDqjvw9SgProPnffVgdg4YEhgVKy' }
];
- Type:
string
- Default:
''
- Description: The title displayed at the top of the modal, typically describing the purpose of the modal (e.g., "Donate Now" or "Support Us"). It is displayed in a bold, larger font.
- Example:
<TipModal modalTitle="Support Us" />
- Type:
string
- Default:
''
- Description: The description displayed under the title in the modal. It provides additional context or instructions, in a smaller font than the title. Use this to give more details about the purpose of the modal, such as explaining a process or providing extra information.
- Example:
<TipModal modalDescription="Thank you for your contribution!" />
- Type:
'light'
|'dark'
- Default:
'dark'
- Description: Specifies the theme of the default trigger button.
- Example:
<TipModal buttonTheme="light" />
- Type:
string
- Default:
'Donate'
- Description: Text displayed on the default trigger button.
- Example:
<TipModal buttonText="DONATE" />
The TipModal
component supports a named slot (button
) to fully customize the trigger button or element.
If no custom content is provided, the modal uses a default button:
<TipModal />
You can pass custom elements or buttons using the slot="button"
syntax:
<TipModal>
<button on:click={openModal} slot="button" class="custom-button"> Custom Donate </button>
</TipModal>
<TipModal>
<p on:click={openModal} slot="button" class="custom-text">Donate Here</p>
</TipModal>
<script>
import TipModal from './lib/components/TipModal.svelte';
let showModal = false;
const paymentOptions = [
{ label: 'BOLT12', value: 'lno1zrxq...' },
{ label: 'LNURL', value: 'https://clams.tech/.well-known/lnurlp/tips' },
{ label: 'LN Address', value: 'tips@clams.tech' },
{ label: 'Onchain', value: 'bitcoin:32KAVNNDqjvw9SgProPnffVgdg4YEhgVKy' }
];
function openModal() {
showModal = true;
}
function closeModal() {
showModal = false;
}
</script>
<TipModal {showModal} {openModal} {closeModal} {paymentOptions} />
<TipModal {showModal} {openModal} {closeModal} {paymentOptions}>
<button on:click={openModal} slot="button" class="custom-button"> Custom Donate </button>
</TipModal>
<TipModal {showModal} {openModal} {closeModal} {paymentOptions}>
<p on:click={openModal} slot="button" class="custom-text">Donate Here</p>
</TipModal>
To run this component locally for development, follow these steps:
-
Clone the repository:
git clone https://github.com/clams-tech/tip-modal.git cd tip-modal
-
Install dependencies:
yarn
-
Start the development server:
yarn dev
This will start a local server (powered by Vite) for live preview and development.
-
Build the project:
yarn build
This command compiles the component for production.