npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-kofi-overlay

v1.0.2

Published

React component for accepting donations though Ko-fi without leaving your website

Downloads

80

Readme

Ko-fi overlay widget

Jump to usage

A React component for accepting donations though Ko-fi without leaving your website:

react-kofi-overlay example

Features

  • Fully customize donate button style & content
  • Accept donations in page context (no redirect)
  • Customize donation panel size & placement
  • Trigger a function when donation panel is open or closed

Motivation

To set up what Ko-fi calls their "Floating Button Donation Widget," they let you do some basic customization and ask you to copy and paste two <script> tags onto your site:

Ko-fi donation widget setup

This has some limitations:

  • Only a few choices for button CTA (call-to-action text)
  • Limited selection of background colors
  • Requires you to load a <script> tag from their CDN, which creates a global variable, and you then need to call a method on that global to render the donate button. Few potential issues with that:
    • Requires an extra network request on every page load
    • Doesn't work well with modern JS bundling + import/export syntax
    • Doesn't work well with a React component-based frontend
    • Doesn't play nice with web frameworks like Next.js. Next.js makes it difficult to inject an arbitrary script like kofiWidgetOverlay.draw(...) – and to only run that code after the external overlay-widget.js script is loaded.

This component is designed to address those limitations.

Install

npm install react-kofi-overlay

(or equivalent on your package manager)

Usage

Example

import { Donate } from 'react-kofi-overlay'

<Donate
  username="liddiard"
  classNames={{
    donateBtn: 'myDonateButton',
    profileLink: 'myProfileLink'
  }}
  styles={{
    panel: { marginRight: '4em' }
  }}
  onToggle={(open) => {
    console.log(`Donate panel ${open ? 'opened' : 'closed'}`)
  }}
>
  ❤️ Support Me
</Donate>

Full example on CodePen

Props

| Prop | Required | Type | Description | | ------------- | ------------- | ------------- | ------------- | | (children) | required | ReactNode | Contents of the donation button. Can be plain text or any React nodes that are valid children of a <button> element. | | username | required | string | Ko-fi profile to display in the donation panel. Corresponds to the page at ko-fi.com/<username>. | | classNames | optional | object | Class names to apply to different parts of the component for styling. See Styling for more info. | | styles | optional | object | Inline styles to apply to different parts of the component for styling. See Styling for more info. | | onToggle | optional | function | Function to call when the donate panel is opened or closed. It receives one argument: a boolean open value that indicates if the panel was opened or closed. |

Styling

The component accepts classNames or styles props to customize the appearance of the donate button and various parts of the donate panel. Both props should be an object with one or more of the keys below.

Note: While you could provide both classNames and styles, it isn't recommended because they will override one another. Pick one based on how you're writing CSS in your codebase.

| Name | Description | | ------------- | ------------- | | donateBtn | Donate <button> element. | | panel | Wrapper <div> around panel that appears when donate button is clicked. By default, the panel is anchored to the bottom right of the viewport on desktop and full screen on mobile. | | closeBtn | <button> to close the donate panel. | | closeIcon | (X) icon within the panel close button. | | profileLink | Wrapper <div> around the link to your Ko-fi profile. By default, it's anchored to the bottom of the donate panel. |

Visual reference

Styling reference diagram

Development

For local development of this plugin:

  1. Clone the repository
  2. npm install

To build: npm run build

Disclaimer

This project is not endorsed by or affiliated with Ko-fi Labs, the company behind Ko-fi.