Reactions

Slack-style emoji reactions with live-updating counts.

python 6 params

Preview

Arguments
reactions(options=['', '👍', '🎉', '❤️'], counts={'👍': 3, '🎉': 1, '❤️': 0}, active=['👍'])

Usage

views.py
python
from djust import LiveView
from djust.decorators import event_handler
from djust.components import Reactions


class MyView(LiveView):
    template_name = "my_template.html"

    def mount(self, request, **kwargs):
        self.component = Reactions(options=['', '👍', '🎉', '❤️'], counts={'👍': 3, '🎉': 1, '❤️': 0}, active=['👍'])

    @event_handler()
    def react(self, **kwargs):
        self.component.active = ...  # `toggle_member` — see this component's docs
my_template.html
django
{{ component }}

Events this component sends to the view: react.

Parameters

NameTypeDefault
optionsList[str] | NoneNone
countsDict[str, int] | NoneNone
eventstr — renames the event; identity is `name`'react'
activeList[str] | NoneNone
custom_classstr''
**kwargs— passed to `Component.__init__`: `name=` identifies the instance in the events it sends, `id=` sets `component.id`, and any other keyword is kept as state
Source & styles
FilePathNotes
moduledjust.components.components.reactionsSubclass it, or pass custom_class, to change how it renders.
cssdjust_components/components.cssDefines 5 of this component's classes at line 2268, 2269, 2271, 2272, 2273. Override those rules, or the custom properties they read, in a stylesheet loaded after it.