Adds likes, dislikes, favourites, ratings, reviews with threaded replies, testimonials and social sharing to selected Payload collections. It creates its own collections, injects aggregate fields, registers REST endpoints under /api/lfrs and adds admin moderation views. Ready-made client React components are provided. Requires Payload 3.87 or later.
Like, Favourite, Rate & Review plugin for Payload CMS 3.x
Installation
npm i payload-lfrs9
Stars
1
Forks
1
Open Issues
4 months ago
Last Updated
66
Weekly Downloads
v1.5.0
npm Version
850.9 KB
Unpacked Size
0
Dependencies
9+1 since Sep 6
| Date | Stars |
|---|---|
| Dec 5, 2026 | 9 |
| Dec 4, 2026 | 9 |
| Dec 3, 2026 | 9 |
| Dec 2, 2026 | 9 |
| Dec 1, 2026 | 9 |
| Nov 30, 2026 | 9 |
| Nov 29, 2026 | 9 |
| Nov 28, 2026 | 9 |
| Nov 27, 2026 | 9 |
| Nov 26, 2026 | 9 |
| Nov 25, 2026 | 9 |
| Nov 24, 2026 | 9 |
| Nov 23, 2026 | 9 |
| Nov 22, 2026 | 9 |
| Nov 21, 2026 | 9 |
| Nov 20, 2026 | 9 |
| Nov 19, 2026 | 9 |
| Nov 18, 2026 | 9 |
| Nov 17, 2026 | 9 |
| Nov 16, 2026 | 9 |
| Nov 15, 2026 | 9 |
| Nov 14, 2026 | 9 |
| Nov 13, 2026 | 9 |
| Nov 12, 2026 | 9 |
| Nov 11, 2026 | 9 |
| Nov 10, 2026 | 9 |
| Nov 9, 2026 | 9 |
| Nov 8, 2026 | 9 |
| Nov 7, 2026 | 9 |
| Nov 6, 2026 | 9 |
| Nov 5, 2026 | 9 |
| Nov 4, 2026 | 9 |
| Nov 3, 2026 | 9 |
| Nov 2, 2026 | 9 |
| Nov 1, 2026 | 9 |
| Oct 31, 2026 | 9 |
| Oct 30, 2026 | 9 |
| Oct 29, 2026 | 9 |
| Oct 28, 2026 | 9 |
| Oct 27, 2026 | 9 |
| Oct 26, 2026 | 9 |
| Oct 25, 2026 | 9 |
| Oct 24, 2026 | 9 |
| Oct 23, 2026 | 9 |
| Oct 22, 2026 | 9 |
| Oct 21, 2026 | 9 |
| Oct 20, 2026 | 9 |
| Oct 19, 2026 | 9 |
| Oct 18, 2026 | 9 |
| Oct 17, 2026 | 9 |
| Oct 16, 2026 | 9 |
| Oct 15, 2026 | 9 |
| Oct 14, 2026 | 9 |
| Oct 13, 2026 | 9 |
| Oct 12, 2026 | 9 |
| Oct 11, 2026 | 9 |
| Oct 10, 2026 | 9 |
| Oct 9, 2026 | 9 |
| Oct 8, 2026 | 9 |
| Oct 7, 2026 | 9 |
| Oct 6, 2026 | 9 |
| Oct 5, 2026 | 9 |
| Oct 4, 2026 | 9 |
| Oct 3, 2026 | 9 |
| Oct 2, 2026 | 9 |
| Oct 1, 2026 | 9 |
| Sep 30, 2026 | 9 |
| Sep 29, 2026 | 9 |
| Sep 28, 2026 | 9 |
| Sep 27, 2026 | 9 |
| Sep 26, 2026 | 8 |
| Sep 25, 2026 | 8 |
| Sep 24, 2026 | 8 |
| Sep 23, 2026 | 8 |
| Sep 22, 2026 | 8 |
| Sep 21, 2026 | 8 |
| Sep 20, 2026 | 8 |
| Sep 19, 2026 | 8 |
| Sep 18, 2026 | 8 |
| Sep 17, 2026 | 8 |
| Sep 16, 2026 | 8 |
| Sep 15, 2026 | 8 |
| Sep 14, 2026 | 8 |
| Sep 13, 2026 | 8 |
| Sep 12, 2026 | 8 |
| Sep 11, 2026 | 8 |
| Sep 10, 2026 | 8 |
| Sep 9, 2026 | 8 |
| Sep 8, 2026 | 8 |
| Sep 7, 2026 | 8 |
| Sep 6, 2026 | 8 |
32−13 since Sep 6
| Date | Weekly downloads |
|---|---|
| Dec 5, 2026 | 32 |
| Dec 4, 2026 | 27 |
| Dec 3, 2026 | 26 |
| Dec 2, 2026 | 33 |
| Dec 1, 2026 | 45 |
| Nov 30, 2026 | 41 |
| Nov 29, 2026 | 44 |
| Nov 28, 2026 | 45 |
| Nov 27, 2026 | 50 |
| Nov 26, 2026 | 54 |
| Nov 25, 2026 | 63 |
| Nov 24, 2026 | 55 |
| Nov 23, 2026 | 59 |
| Nov 22, 2026 | 55 |
| Nov 21, 2026 | 54 |
| Nov 20, 2026 | 46 |
| Nov 19, 2026 | 42 |
| Nov 18, 2026 | 40 |
| Nov 17, 2026 | 36 |
| Nov 16, 2026 | 32 |
| Nov 15, 2026 | 36 |
| Nov 14, 2026 | 36 |
| Nov 13, 2026 | 34 |
| Nov 12, 2026 | 44 |
| Nov 11, 2026 | 28 |
| Nov 10, 2026 | 25 |
| Nov 9, 2026 | 25 |
| Nov 8, 2026 | 19 |
| Nov 7, 2026 | 23 |
| Nov 6, 2026 | 23 |
| Nov 5, 2026 | 10 |
| Nov 4, 2026 | 9 |
| Nov 3, 2026 | 9 |
| Nov 2, 2026 | 9 |
| Nov 1, 2026 | 9 |
| Oct 31, 2026 | 3 |
| Oct 30, 2026 | 2 |
| Oct 29, 2026 | 2 |
| Oct 28, 2026 | 2 |
| Oct 27, 2026 | 6 |
| Oct 26, 2026 | 6 |
| Oct 25, 2026 | 6 |
| Oct 24, 2026 | 7 |
| Oct 23, 2026 | 7 |
| Oct 22, 2026 | 23 |
| Oct 21, 2026 | 44 |
| Oct 20, 2026 | 42 |
| Oct 19, 2026 | 46 |
| Oct 18, 2026 | 45 |
| Oct 17, 2026 | 45 |
| Oct 16, 2026 | 45 |
| Oct 15, 2026 | 33 |
| Oct 14, 2026 | 23 |
| Oct 13, 2026 | 27 |
| Oct 12, 2026 | 25 |
| Oct 11, 2026 | 30 |
| Oct 10, 2026 | 35 |
| Oct 9, 2026 | 41 |
| Oct 8, 2026 | 39 |
| Oct 7, 2026 | 30 |
| Oct 6, 2026 | 28 |
| Oct 5, 2026 | 27 |
| Oct 4, 2026 | 33 |
| Oct 3, 2026 | 33 |
| Oct 2, 2026 | 29 |
| Oct 1, 2026 | 27 |
| Sep 30, 2026 | 26 |
| Sep 29, 2026 | 22 |
| Sep 28, 2026 | 22 |
| Sep 27, 2026 | 21 |
| Sep 26, 2026 | 22 |
| Sep 25, 2026 | 22 |
| Sep 24, 2026 | 26 |
| Sep 23, 2026 | 35 |
| Sep 22, 2026 | 48 |
| Sep 21, 2026 | 47 |
| Sep 20, 2026 | 41 |
| Sep 19, 2026 | 44 |
| Sep 18, 2026 | 42 |
| Sep 17, 2026 | 46 |
| Sep 16, 2026 | 39 |
| Sep 15, 2026 | 30 |
| Sep 14, 2026 | 31 |
| Sep 13, 2026 | 28 |
| Sep 12, 2026 | 27 |
| Sep 11, 2026 | 30 |
| Sep 10, 2026 | 26 |
| Sep 9, 2026 | 31 |
| Sep 8, 2026 | 29 |
| Sep 7, 2026 | 29 |
| Sep 6, 2026 | 45 |
Each point is npm's rolling 7-day download count.
Health Score
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/1276145587-root)<a href="https://payloaddirectory.dev/plugins/1276145587-root"><img src="https://payloaddirectory.dev/badge/1276145587-root.svg" alt="Payload Directory"></a>README
A comprehensive plugin for Payload CMS 3.x that adds Likes, Favourites, Ratings, and Reviews (LFRs) capabilities to your existing collections.
Here are examples of what you can build on the frontend using this plugin:




npm install payload-lfrs
# or
pnpm add payload-lfrs
# or
yarn add payload-lfrs
This repository includes a fully functioning Next.js example project located in the dev folder. It demonstrates how to integrate the plugin into a Payload configuration and how to use the provided React components in a frontend application.
To run the example project locally:
git clone https://github.com/Talaween/Payload-LFRs.git
cd Payload-LFRs
pnpm install
pnpm dev
The example application will be available at http://localhost:3000.
Add the plugin to your Payload configuration. Below is a comprehensive example showcasing all available configuration options:
import { buildConfig } from 'payload'
import { payloadLFRs } from 'payload-lfrs'
export default buildConfig({
// ... your existing config
plugins: [
payloadLFRs({
collections: {
// Target collection slug
posts: {
likes: true, // Enable likes for authenticated users
dislikes: true, // Enable dislikes (mutually exclusive with likes)
favourites: true, // Enable favourites
ratings: true, // Enable ratings (stored directly in reviews)
reviews: true, // Enable reviews
replies: ['admin'], // Enable replies, but restrict to admin roles
readReviews: 'public', // Access control for reading reviews ('public', true, or roles array)
allowMultipleReviews: false, // Prevent users from submitting multiple reviews on the same doc
shares: true, // Enable social sharing and track share counts
},
},
// Allow users to like/dislike reviews and replies
enableReviewReactions: true,
// Configure global rating options
rating: {
max: 5, // Max rating scale value (default: 5)
step: 0.5, // Value increment steps (default: 1)
icon: 'star', // Icon identifier hint for frontend (default: 'star')
},
// Enable review media uploads (requires an existing upload-enabled collection)
reviewMedia: {
uploadCollection: 'media',
allowedMimeTypes: ['image/*'],
maxFiles: 5,
maxFileSize: 5 * 1024 * 1024, // 5MB
},
testimonialFormUrl: 'https://example.com/add-testimonial', // URL to your frontend form page
reviewModeration: true, // Require reviews to be approved before they are public (default: false)
adminControls: true, // Set to false to hide the Global Settings from the Admin UI
adminGroup: 'LFRs', // Navigation group name in the Admin panel (default: 'LFRs')
usersCollectionSlug: 'users', // Slug of your auth collection (default: 'users')
// Custom callback to check if a user is an admin
isAdmin: ({ req }) => {
return (req.user?.roles as string[])?.includes('admin')
},
}),
],
})
The payloadLFRs plugin accepts a configuration object with the following properties:
collections (Required)A map of collection slugs to enable LFRs features on. For each collection, you can enable specific features and configure access control.
collections: {
posts: {
likes: true, // Enable likes for any authenticated user
dislikes: false, // Disabled
favourites: ['admin', 'subscriber'], // Only specific roles can favourite
ratings: true,
reviews: true,
readReviews: 'public', // Set who can read reviews
allowMultipleReviews: true, // Allow users to leave multiple reviews (default: false)
replies: ['admin'], // Enable replies, but only admins can respond
}
}
readReviewsAccess control for viewing reviews and replies.
Unlike the interaction features which default to true (requiring authentication), this defaults to 'public', allowing anyone (including guests) to read reviews and replies. You can restrict this to specific roles (e.g. ['admin']), to logged-in users only (true), or provide a custom function.
(Default: 'public')
allowMultipleReviewsIf true, users can submit more than one review on the same document. If false, they are restricted to a single review, and the UI component will present an "Edit Review" button instead of "Write a Review".
(Default: false)
enableReviewReactionsWhether users are allowed to like or dislike reviews and replies. If set to true, the plugin will add aggregate thumbs-up and thumbs-down reaction fields to both review and reply documents, and render action buttons for them in the UI.
(Default: false)
For each feature (likes, dislikes, favourites, ratings, reviews, replies, shares), you can provide:
true: Any authenticated user can use the feature (default if the feature key is omitted but the feature is mentioned, depending on implementation/type defaults).false: Feature disabled for this collection.string[]: Only users whose roles array includes at least one of these roles can use the feature. For example, replies: ['admin'] restricts replying to administrators.Function: A custom async function receiving the request and target document. Return true to allow, false to deny.likes: async ({ req, targetCollection, targetDoc }) => {
// Custom logic: e.g., only users who purchased this product can review it
return true
}
ratingConfigure the rating system (default: 5-star, whole numbers).
rating: {
max: 5, // Maximum rating value (default: 5)
step: 0.5, // Step increment, e.g., 0.5 for half-stars (default: 1)
icon: 'star', // Icon identifier hint for frontend (default: 'star')
}
reviewMediaAllow users to attach media to their reviews. Note: You must provide the slug of an existing upload-enabled collection.
reviewMedia: {
uploadCollection: 'media', // REQUIRED: an existing upload collection in your payload config
allowedMimeTypes: ['image/jpeg', 'image/png'], // default: ['image/*']
maxFiles: 3, // default: 5
maxFileSize: 5 * 1024 * 1024, // 5MB limit
}
reviewModerationSet to true to require reviews to be approved before they are publicly visible (default: false). This also adds a dedicated Review Moderation view in the Admin panel.
reviewModeration: true
testimonialFormUrlThe frontend URL where your testimonial submission form (using LfrsTestimonialForm) is hosted. When admins invite users to leave a testimonial, the plugin appends ?code=... to this URL in the invitation email.
payloadLFRs({
testimonialFormUrl: process.env.TESTIMONIAL_FORM_URL || 'http://localhost:3000/add-testimonial',
})
Add TESTIMONIAL_FORM_URL (or your chosen variable name) to your .env file pointing to the URL of the page hosting your testimonial submission form. See docs/testimonial.md for full details.
usersCollectionSlugThe slug of your users collection for authentication (default: 'users').
adminGroupThe group name under which the LFRs collections will appear in the Admin UI (default: 'LFRs').
adminControlsSet to false to hide the dynamic Global Settings page (LFRs Settings) from the Payload Admin panel (default: true). This prevents administrators from dynamically overriding the plugin's configuration at runtime, while keeping interaction collections accessible.
isAdminA custom callback to check if a user is an administrator. This is used throughout the plugin to determine administrative permissions, such as deleting interactions, viewing moderation workflows, and accessing the runtime settings.
By default, it checks if req.user.roles contains the role 'admin'.
isAdmin: async ({ req }) => {
// Custom check for admin logic...
return req.user?.customRole === 'superadmin'
}
disabledSet to true to completely disable the plugin's features without uninstalling it or losing data (default: false).
When disabled: true, the plugin will continue to register its collections and fields to keep your database schema consistent (which is important for migrations), but it will not register any API endpoints, lifecycle hooks, or Admin UI components. This is perfect for temporarily pausing interactions while keeping historical data intact.
collectionSlugsOverride the default slugs for the internal collections created by the plugin (likes, dislikes, favourites, reviews, replies).
LfrsSettings)The plugin automatically generates a Payload Global named LFRs Settings in the admin panel. This allows administrators to temporarily enable/disable features on the fly without changing code or restarting the server.
There is also a checkbox option for Enable Like/Dislike on Reviews and Replies which allows admins to toggle review reactions dynamically.
Security & Access Control:
LFRs Settings global are strictly restricted to administrators via the configured isAdmin callback. Non-admin users cannot view or modify plugin settings via the API or Admin UI.payload.config.ts). An admin cannot turn on a feature (like Reviews) if the developer explicitly set it to false in the code.callbacksHook into user interactions and moderation state changes to trigger custom business logic (e.g., sending email notifications, awarding points, syncing with external systems). All callbacks can be asynchronous.
plugins: [
payloadLFRs({
// ...
callbacks: {
onReviewSubmitted: async ({ req, review }) => {
// Triggered when a user creates or edits a review
console.log(`Review submitted by user ${req.user.id}`)
},
onReviewStateChanged: async ({ req, review, previousStatus }) => {
// Triggered when an admin changes a review's moderation status
if (review.status === 'approved' && previousStatus !== 'approved') {
// Send a notification email to the author
}
},
onLiked: async ({ req, like }) => {
// Example: Award points to the target document's author
},
},
}),
]
Available Callbacks (all receive the PayloadRequest object along with relevant context):
onReviewSubmitted: { req, review } — Triggered when a user creates or updates a review.onReviewDeleted: { req, reviewId, targetCollection, targetDoc } — Triggered when a user deletes their review.onReplySubmitted: { req, reply } — Triggered when a user creates or updates a reply.onReviewStateChanged: { req, review, previousStatus } — Triggered when an admin changes a review's status via the Admin panel.onLiked: { req, like } — Triggered when a user likes a document or review/reply.onUnliked: { req, targetCollection, targetDoc } — Triggered when a user removes their like.onDisliked: { req, dislike } — Triggered when a user dislikes a document or review/reply.onUndisliked: { req, targetCollection, targetDoc } — Triggered when a user removes their dislike.lfrs_likes, lfrs_reviews).lfrs field group into your target collections, containing aggregate data (e.g., lfrs.likesCount, lfrs.averageRating)./api/lfrs/... to handle interactions (e.g., /api/lfrs/like, /api/lfrs/rate).For each target collection where LFRs features are enabled, the plugin injects a custom Interactions Status Widget into the document's edit view sidebar. This widget displays an at-a-glance summary of all aggregated interactions for that document (such as total likes, total reviews, and average rating).
If reviewModeration: true is enabled in your configuration, the plugin provides a dedicated Review Moderation Queue view in the Admin panel. Accessible via /admin/lfrs-moderation, this dashboard allows administrators to efficiently review, approve, or reject pending user reviews and replies before they are publicly displayed.
The plugin exposes several endpoints for interacting with the LFRs features from your frontend:
POST /api/lfrs/like — Toggles a user's like on a document.
{ collection: string, id: string }{ liked: boolean, likesCount: number, disliked?: boolean, dislikesCount?: number }POST /api/lfrs/dislike — Toggles a user's dislike on a document.
{ collection: string, id: string }{ disliked: boolean, dislikesCount: number, liked?: boolean, likesCount?: number }POST /api/lfrs/favourite — Toggles a user's favorite on a document.
{ collection: string, id: string }{ favourited: boolean, favouritesCount: number }POST /api/lfrs/review — Submits or updates a user review and/or rating. (If ratings are enabled, a score is submitted. If reviews are enabled, text body and title are submitted. If reviews are disabled but ratings are enabled, title and body are not saved.)
{ collection: string, id: string, body?: string, title?: string, score?: number, media?: string[], reviewId?: string }{ review: object, reviewsCount: number }DELETE /api/lfrs/review — Deletes a user's review.
{ reviewId: string }{ deleted: true, reviewsCount: number }POST /api/lfrs/reply — Submits or updates a reply to a review.
{ body: string, reviewId: string, replyId?: string }{ reply: object, repliesCount: number }DELETE /api/lfrs/reply — Deletes a reply.
{ replyId: string }{ deleted: true, repliesCount: number }GET /api/lfrs/testimonials — Returns accepted testimonials.
featured (optional, boolean){ docs: Array, ... }POST /api/lfrs/testimonials/submit — Submits a testimonial via an invite code.
{ uniqueCode: string, firstName: string, rating: number, testimonial: string }{ success: boolean, testimonial: object }GET /api/lfrs/status — Returns feature configuration flags and the current user's interaction states.
collection (required), id (required){ likesCount: number, dislikesCount: number, liked: boolean, favourited: boolean, rating: number | null, review: object | null, ... }GET /api/lfrs/interactions — Fetches paginated lists of ratings or reviews.
collection (required), id (required), type (optional: 'reviews' | 'ratings', default: 'reviews'), page (optional), limit (optional), sort (optional: 'newest' | 'oldest' | 'highest' | 'lowest'){ docs: Array, page: number, totalDocs: number, totalPages: number }GET /api/lfrs/distribution — Returns rating score distribution frequencies.
collection (required), id (required){ averageScore: number, totalRatings: number, distribution: Array<{ score: number, count: number, percentage: number }> }GET /api/lfrs/user-favourites — Returns document IDs favorited by a user.
collection (required), userId (required), limit (optional){ ids: string[] }GET /api/lfrs/user-reviews — Gets a specific user's reviews for a document.
collection (required), id (required), userId (required){ reviews: Array }GET /api/lfrs/likes-count — Gets the total likes count.
collection (required), id (required){ likesCount: number }GET /api/lfrs/dislikes-count — Gets the total dislikes count.
collection (required), id (required){ dislikesCount: number }GET /api/lfrs/likes-users — Gets user IDs who liked a document.
collection (required), id (required), limit (optional){ userIds: string[] }GET /api/lfrs/dislikes-users — Gets user IDs who disliked a document.
collection (required), id (required), limit (optional){ userIds: string[] }POST /api/lfrs/share — Records a share event for a document to a specific platform.
{ collection: string, id: string, platform: string, url: string }{ shared: true, sharesCount: number }GET /api/lfrs/shares-count — Gets the total share count for a document.
collection (required), id (required){ sharesCount: number }Authentication (with user context) is required for all POST and DELETE endpoints.
The plugin provides a suite of ready-to-use React components for your frontend application. These components are exported via payload-lfrs/client and are built as client components ("use client") to handle user interactions and optimistic UI updates seamlessly.
LfrsLikeDislike: A toggleable thumbs-up/thumbs-down widget displaying current counts.LfrsFavourite: A bookmark/favorite button for saving documents.LfrsRating: An interactive star rating component for users to submit a score.LfrsRatingSummary: A visual summary showing the average rating and score distribution.LfrsComposeReview / LfrsComposeReply: Forms for submitting text reviews and nested replies.LfrsReviewCard / LfrsReplyCard: Display components for rendering individual reviews and replies.LfrsReviewsSection: A complete, integrated reviews area combining the summary, compose form, and a list of reviews.LfrsTestimonialForm: A form to capture invited testimonials securely.LfrsTestimonials: A beautiful display component showcasing featured testimonials.LfrsShare: A share button that opens an inline panel to share the document across social platforms or copy the link, while tracking share counts.import { LfrsLikeDislike, LfrsRating, LfrsShare } from 'payload-lfrs/client'
export function PostDetails({ post }) {
return (
<div>
<h1>{post.title}</h1>
{/* Share Button */}
<LfrsShare
targetCollection="posts"
targetDoc={post.id}
title={post.title}
url="https://example.com/post/1"
/>
{/* Like / Dislike Toggle */}
<LfrsLikeDislike
targetCollection="posts"
targetDoc={post.id}
initialLikesCount={post.lfrs?.likesCount || 0}
initialLiked={false} // Optionally pass initial state from server
/>
{/* 5-Star Rating */}
<LfrsRating targetCollection="posts" targetDoc={post.id} maxRating={5} />
</div>
)
}
The UI components are built to seamlessly integrate with your existing site. They use CSS Variables which can be overridden globally in your app (e.g. in your :root or body block), or scoped directly to the components using the style prop!
Components also include built-in fallback shadows (text-shadow and drop-shadow) on text, buttons, badges, and icon outlines to ensure visual contrast and readability across light and dark modes, even if custom background and foreground colors match.
Here are the available variables and their default fallback values:
:root {
--lfrs-primary: #000000; /* Used for primary buttons (e.g. "Write a Review") */
--lfrs-primary-text: #ffffff; /* Text color for primary buttons */
--lfrs-text: #333333; /* Main text color */
--lfrs-text-muted: #666666; /* Dates, secondary text, placeholders */
--lfrs-bg: #ffffff; /* Main background color for cards */
--lfrs-bg-muted: #f5f5f5; /* Background for replies and forms */
--lfrs-border: #e0e0e0; /* Borders around cards and inputs */
--lfrs-star-active: #ffb400; /* Color of filled rating stars and bars */
--lfrs-star-inactive: #e0e0e0; /* Color of empty rating stars */
--lfrs-like-active: #0066cc; /* Active state for Like button */
--lfrs-dislike-active: #cc0000; /* Active state for Dislike button */
--lfrs-favourite-active: #ff0055; /* Active state for Favourite button */
--lfrs-share-active: #0077b5; /* Active state for Share button */
--lfrs-like-inactive: #0066cc; /* InActive state for Like button */
--lfrs-dislike-inactive: #cc0000; /* InActive state for Dislike button */
--lfrs-radius: 6px; /* Border radius for buttons, inputs, and cards */
--lfrs-font: inherit; /* Font family inherited from your app by default */
}
classNames & styles)All LFRs UI components follow a unified styling API. You can apply styles to the root element using className and style, or target specific nested elements using the classNames and styles objects.
Here is an example for LfrsShare:
<LfrsShare
targetCollection="posts"
targetDoc={post.id}
classNames={{
container: 'custom-share-container',
button: 'custom-share-trigger',
panel: 'custom-share-panel',
platformButton: 'custom-platform-btn',
copyButton: 'custom-copy-btn',
}}
styles={{
container: { margin: '10px 0' },
button: { backgroundColor: '#10b981', color: '#ffffff' },
panel: { borderRadius: '12px' },
platformButton: { fontSize: '12px' },
copyButton: { backgroundColor: '#3b82f6' },
}}
/>
And here is an example for LfrsTestimonialForm:
<LfrsTestimonialForm
uniqueCode={code}
mediaCollectionSlug="media" // Optional: enables photo attachment input
classNames={{
container: 'custom-testimonial-container',
form: 'custom-testimonial-form',
input: 'custom-testimonial-input',
textarea: 'custom-testimonial-textarea',
submitButton: 'custom-testimonial-submit',
error: 'custom-testimonial-error',
success: 'custom-testimonial-success',
}}
styles={{
container: { padding: '24px', backgroundColor: '#fafafa' },
input: { borderRadius: '8px' },
submitButton: { backgroundColor: '#2563eb', color: '#fff' },
}}
/>
If you want to style a single component, you can pass the variables via the style prop:
<LfrsRatingSummary
targetCollection="posts"
targetDoc={post.id}
style={
{
'--lfrs-star-active': '#10b981', // Green stars
'--lfrs-bg': '#1f2937', // Dark mode background
'--lfrs-text': '#f9fafb', // Light text
} as React.CSSProperties
}
/>
The plugin is designed to be completely framework-agnostic. While we provide React components for convenience, you can build your own custom user interfaces in any framework (Vue, Svelte, Angular, React Native, or vanilla JavaScript) by directly interacting with the plugin's REST API.
Here is an example of how you might build a custom "Like" interaction in vanilla JavaScript:
async function toggleLike(targetCollection, targetDocId) {
try {
const response = await fetch('/api/lfrs/like', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
// 'Authorization': 'Bearer YOUR_TOKEN' // If required
},
body: JSON.stringify({
collection: targetCollection,
id: targetDocId,
}),
})
if (!response.ok) throw new Error('Failed to toggle like')
const data = await response.json()
// Update your custom UI state here...
} catch (error) {
console.error(error)
}
}
You can similarly use the GET /api/lfrs/status endpoint to fetch the current user's interaction state when a page loads, and map other interactions (Favorites, Ratings, Reviews) to their respective endpoints.
If you are reviewing, contributing to, or debugging the plugin, here's an overview of the codebase structure and internal architecture.
src/plugin.ts: The main entry point. It accepts user configuration, sanitizes it (applying defaults), and injects the collections, fields, and endpoints into the Payload config.src/collections/: Contains the definitions for the plugin-managed collections (likes, dislikes, favourites, ratings, reviews, replies). These store the actual user interactions.src/fields/:
aggregateFields.ts: Generates the lfrs field group (e.g., lfrs.likesCount, lfrs.averageRating) that gets injected into target collections.joinFields.ts: Injects Payload Join fields so administrators can see related LFRs documents directly from the target document's admin UI.src/endpoints/: The REST API implementations. These handle incoming user requests, enforce access control, and perform the database operations.src/hooks/: Contains Payload lifecycle hooks. E.g., cascadeDelete.ts ensures that when a target document is deleted, all associated interactions are also removed to prevent orphaned records.src/admin/: React components for Payload's Admin panel. Includes status widgets and the Review Moderation view.src/types.ts: TypeScript interfaces and types for configuration, internal sanitized config, and feature access.To ensure high reliability and avoid transaction context poisoning within Payload CMS, the aggregation logic (e.g., updating a post's likesCount or dislikesCount) is primarily Endpoint-Driven:
/api/lfrs/like), the endpoints perform the necessary database mutations (create, delete) while passing context: { skipLfrsHooks: true }. This suppresses the automatic hook-based recalculation.afterChange and afterDelete hooks in src/hooks/recalculateAggregates.ts are still kept as fallbacks. They will automatically recalculate the counts if an administrator creates or deletes an interaction manually from the Payload Admin UI, maintaining data consistency.We are continuously working to make payload-lfrs more robust, feature-rich, and developer-friendly. Below are planned features and improvements:
MIT
payload reviews
Product reviews for Payload ecommerce with verified purchase flags, moderation and exact aggregate ratings
7317/wk2v3
payload plugin reviews
Customer product reviews with star ratings, moderation and aggregate rating support
605/wk1v3
stripe
Connect Stripe and Payload CMS to work with Stripe data from your Payload project
10022.2k/wk46.1kv3 v4
payload oapi
Generate an OpenAPI spec from your Payload config with optional documentation UIs
7631.1k/wk125v3
payload plugin notifications
In-site notices with per-kind email copies, user preferences and a retrying send queue
74127/wk0v3
payload plugin openapi
Generate an OpenAPI 3.0, 3.1 or 3.2 spec from your Payload config and serve it with Scalar or Swagger UI
701.4k/wk18v4