Giter Site home page Giter Site logo

liddiard / react-kofi-overlay Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 1.0 1.23 MB

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

Home Page: https://ko-fi.com/

License: MIT License

SCSS 29.83% TypeScript 43.30% JavaScript 26.87%
donations ko-fi payments react typescript

react-kofi-overlay's Introduction

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.

react-kofi-overlay's People

Contributors

liddiard avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

martirubio

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.