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

svelte-reactions

v2.5.4

Published

Easy to use emoji reactions for your app.

Downloads

65

Readme

🚀 Install

Using npm

  npm i svelte-reactions

Or using yarn

  yarn add svelte-reactions

🤔 Usage

Using js

<script>
    import 'svelte-reactions/global.css';
    import { Trigger } from 'svelte-reactions';

        const reactions = [
            {
                id: '1',
                reaction: '👍',
                quantity: 100,
                clicked: false
            }
        ];
</script>

<Trigger bind:reactions />

Using ts

<script lang="ts">
    import 'svelte-reactions/global.css';
    import { Trigger, type ReactionType } from 'svelte-reactions';

        const reactions: ReactionType = [
            {
                id: '1',
                reaction: '👍',
                quantity: 100,
                clicked: false
            }
        ];
</script>

<Trigger bind:reactions />

For more expamples go to the REPL

🎨 Theming

We expose some CSS Variables to make more easy customize the colors of the component:

| Variable | Description | | :------- | ----------: | | --srTriggerBg | Define the background color of default Trigger component | | --srTriggerColor | Define the text color of default Trigger component | | --srTriggerHoverBg | Define the background hover color of default Trigger component | | --srTriggerContainerBoxShadow | Define the style box shadow of the reactions container | | --srTriggerContainerBg | Define the background color of the reactions container | | --srReactionClickedBg | Define the background color of reaction block when this is already clicked | | --srReactionNotClickedBg | Define the background color of reaction block when this is not already clicked | | --srReactionHoverBg | Define the background hover color of reaction block | | --srReactionClickedHoverBg | Define the background hover color of reaction block when this is already clicked | | --srEmojiColor | Define the text color of reaction | | --srEmojiClickedColor | Define the text color of reaction when this is already clicked | | --srLabelBorderColor | Define the border color of default label component | | --srLabelClickedBorderColor | Define the border color of default label component when reaction is already clicked | | --srLabelBg | Define the background color of default label component | | --srLabelClickedBg | Define the background color of default label component when reaction is already clicked | | --srLabelColor | Define the text color of default label component | | --srLabelClickedColor | Define the text color of default label component when reaction is already clicked | | --srLabelHoverBg | Define the background hover color of default label component | | --srLabelClickedHoverBg | Define the background hover color of default label component when reaction is already clicked |

Then you can use this variables to customize the component, for example:

<!-- CustomReactionComponent.svelte -->
    
<script>
    import { Trigger } from 'svelte-reaction';
    
    export let reactions;
    export let showLabels = true;
    export let position = 'bottom-left'
</script>
    
<Trigger {reactions} {showLabels} {position} />

<style global>
    :root {
        --srTriggerBg: red;
        --srTriggerHoverBg: blue;
        --srTriggerColor: white;
     }
</style>

If you need to be more strict, always you can overwrite the next classes to get the better result:

| Class name | Description | | :------- | ----------: | | .trigger-container | Default class for default trigger and labels container | | .trigger | Default class for default trigger element | | .reactions-container| Default class for the reactions contanier (floating component) | | .reaction | Default class for the reaction element | | .emoji | Default class for the emoji element | | .labels-container | Deault class for the labels container | | .label | Default class for the label element | | .label-component | Default class for the label element, when the reaction is defined as SvelteComponent insted of String |

Remember alway use global styles for overwriting CSS variables and classes

📂 API

ReactionType attributes

| Property | Type | Description | | :------- | :--: | ----------: | | id | string | Identifier of a reaction, useful for bind data with your database. | | reaction | string | SvelteComponent | You can use any string for a reaction, however we recomend you to use a string with 1 value of lenght, when you use an SvelteComponent as reaction, components like svg or img or any other, we recomend you to use this sizes: width between 20px and 35px same as height. | | labelReaction | string | SvelteComponent | undefined | Same as reaction property, this define the reaction representation on summary labels (by default this value is equal to provided reaction value | | quantity | number | Define the quantity of reactions, for example 50 likes in some post. | | clicked | boolean | Define if the current user clicked some reaction. |

Placment type

This type is used on the <Trigger /> component props, for example:

  <Trigger position='bottom-left' />

valid values:

'bottom-left' | 'top-left' | 'bottom-right' | 'top-right'

Trigger properties

| Property | Type | Description | | :------- | :--: | ----------: | | reactions | ReactionType[] | Define the set of reactions. | | showLabels | boolean | Define if the component generate summary of reactionis. | | position | Placement | Define the placement of the reactions containers. | | on:reaction | CustomEvent | Throw an event when some reaction is clicked |