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';
showModalbooleanlet showModal = false;
openModalFunctionshowModal to true and open the modal.function openModal() {
showModal = true;
}
closeModalFunctionshowModal to false and close the modal.function closeModal() {
showModal = false;
}
paymentOptionsArrayconst paymentOptions = [
{ label: 'BOLT12', value: 'lno1zrxq8pjw7qjlm68mtp7e3yvxee4y5xrgjhhyf2fxhlphpckrvevh50u0qt2rt2xr6uuj7cfce48c5cr8sa2dqp2nkumkuztlq840mpjj95anvqsrh809gs052xe9reyna6v2djjv4p7k0leqy9uhthm8tpvvppphlmfsqvcdy9947hanvmq9mssn970apemvm7hjhg54qfdahgq2t5rwzca27ksjcz7lwn8xyl9qet4lmd4zjq8ucy4gq0cjem6q47gcl8a4f9lcr0qajukk809lnu7az9wupm0vz6ljh3ajgqqspdlvl6crzaxz9ueuu5h9as269y' },
{ label: 'LNURL', value: 'https://clams.tech/.well-known/lnurlp/tips' },
{ label: 'LN Address', value: '[email protected]' },
{ label: 'Onchain', value: 'bitcoin:32KAVNNDqjvw9SgProPnffVgdg4YEhgVKy' }
];
paymentTagType: 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: '[email protected]' },
{ label: 'Onchain', value: 'bitcoin:32KAVNNDqjvw9SgProPnffVgdg4YEhgVKy' }
];
modalTitlestring''<TipModal modalTitle="Support Us" />
modalDescriptionstring''<TipModal modalDescription="Thank you for your contribution!" />
buttonTheme'light' | 'dark''dark'<TipModal buttonTheme="light" />
buttonTextstring'Donate'<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: '[email protected]' },
{ 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.