2.5.4 • Published 1 year ago

svelte-reactions v2.5.4

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

🚀 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:

VariableDescription
--srTriggerBgDefine the background color of default Trigger component
--srTriggerColorDefine the text color of default Trigger component
--srTriggerHoverBgDefine the background hover color of default Trigger component
--srTriggerContainerBoxShadowDefine the style box shadow of the reactions container
--srTriggerContainerBgDefine the background color of the reactions container
--srReactionClickedBgDefine the background color of reaction block when this is already clicked
--srReactionNotClickedBgDefine the background color of reaction block when this is not already clicked
--srReactionHoverBgDefine the background hover color of reaction block
--srReactionClickedHoverBgDefine the background hover color of reaction block when this is already clicked
--srEmojiColorDefine the text color of reaction
--srEmojiClickedColorDefine the text color of reaction when this is already clicked
--srLabelBorderColorDefine the border color of default label component
--srLabelClickedBorderColorDefine the border color of default label component when reaction is already clicked
--srLabelBgDefine the background color of default label component
--srLabelClickedBgDefine the background color of default label component when reaction is already clicked
--srLabelColorDefine the text color of default label component
--srLabelClickedColorDefine the text color of default label component when reaction is already clicked
--srLabelHoverBgDefine the background hover color of default label component
--srLabelClickedHoverBgDefine 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 nameDescription
.trigger-containerDefault class for default trigger and labels container
.triggerDefault class for default trigger element
.reactions-containerDefault class for the reactions contanier (floating component)
.reactionDefault class for the reaction element
.emojiDefault class for the emoji element
.labels-containerDeault class for the labels container
.labelDefault class for the label element
.label-componentDefault 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

PropertyTypeDescription
idstringIdentifier of a reaction, useful for bind data with your database.
reactionstring | SvelteComponentYou 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.
labelReactionstring | SvelteComponent | undefinedSame as reaction property, this define the reaction representation on summary labels (by default this value is equal to provided reaction value
quantitynumberDefine the quantity of reactions, for example 50 likes in some post.
clickedbooleanDefine 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

PropertyTypeDescription
reactionsReactionType[]Define the set of reactions.
showLabelsbooleanDefine if the component generate summary of reactionis.
positionPlacementDefine the placement of the reactions containers.
on:reactionCustomEventThrow an event when some reaction is clicked
2.5.0

2 years ago

2.5.2

2 years ago

2.5.1

2 years ago

2.5.4

1 year ago

2.5.3

2 years ago

2.1.2

2 years ago

2.1.1

2 years ago

2.4.1

2 years ago

2.1.4

2 years ago

2.4.0

2 years ago

2.1.3

2 years ago

2.4.3

2 years ago

2.1.6

2 years ago

2.4.2

2 years ago

2.1.5

2 years ago

2.4.5

2 years ago

2.3.6

2 years ago

2.4.4

2 years ago

2.4.7

2 years ago

2.3.8

2 years ago

2.4.6

2 years ago

2.3.7

2 years ago

2.4.8

2 years ago

2.3.9

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.9.3

2 years ago

1.8.3

2 years ago

1.8.2

2 years ago

1.8.1

2 years ago

1.8.0

2 years ago

1.7.5

2 years ago

1.7.4

2 years ago

1.7.3

2 years ago

1.7.2

2 years ago

1.7.1

2 years ago

1.7.0

2 years ago

1.6.0

2 years ago

1.5.0

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago