Updated
NPS Strip
NewCustomize
Colors
Width460px
Installation
npx shadcn@latest add https://uibrik.com/r/nps-strip.jsonInstall the packages
npm install @tabler/icons-react motion react-use-measureAdd the cn helper
Imports
cnfrom@/lib/utils, whichshadcn initcreates. Add it by hand without shadcn.Copy the source into your project
components/uibrik/nps-strip/nps-strip.tsx"use client"; import { IconLoader2 } from "@tabler/icons-react"; import { AnimatePresence, motion, useReducedMotion, type Variants } from "motion/react"; import { useEffect, useId, useRef, useState, type KeyboardEvent } from "react"; import useMeasure from "react-use-measure"; import { cn } from "@/lib/utils"; // Eleven scores on one track. One pill glides between them and blends into the // colour of its group on the way; a lighter one follows the pointer. The band // underneath fills up to the score within its group, and below it the card // grows into the follow-up for that group. Changing group swaps only the // question line; the note and the button stay put, so nothing you typed moves. const EASE_OUT: [number, number, number, number] = [0.23, 1, 0.32, 1]; const GLIDE = { type: "spring", duration: 0.42, bounce: 0.12 } as const; const HOVER = { type: "spring", duration: 0.28, bounce: 0 } as const; const GROW = { type: "spring", duration: 0.5, bounce: 0 } as const; const SCORES = Array.from({ length: 11 }, (_, i) => i); const PAD = 4; const group: Variants = { hidden: {}, shown: { transition: { staggerChildren: 0.05, delayChildren: 0.08 } }, gone: { opacity: 0, filter: "blur(4px)", transition: { duration: 0.14 } },
Adds the files to
components/uibrik/nps-strip and installs @tabler/icons-react, motion and react-use-measure. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/nps-strip.Usage
import { NpsStrip } from "@/components/uibrik/nps-strip/nps-strip";const prompt = "How likely are you to recommend us to a friend?";const followUps = ["What would have made it better?", "What would make it a 10?", "What do you love most?"];<NpsStrip prompt={prompt} lowLabel="Not likely" highLabel="Very likely" colors={["#e5484d", "#e8890c", "#16a35a"]} width={460} defaultValue={null} segmentLabels={["Detractor", "Passive", "Promoter"]} followUps={followUps} placeholder="Tell us a little more" submitLabel="Send" thanksLabel="Thanks for the feedback" onSubmit={(feedback) => {}} // value={0} // onChange={(score) => {}}/>Where to use NPS Strip
Quarterly NPS surveys
The whole survey is one card, and each group is asked the question that matters for it.
In-app feedback prompts
Eleven scores fit a phone-width card without wrapping or scrolling.
Pairs with Toast
Post-onboarding check
The coloured band shows people which group their score falls in as they pick.
Props
NpsStrip- prompt
- Type string
- "How likely are you to recommend us to a friend?"
- The question above the scores.
- lowLabel
- Type string
- "Not likely"
- Word under 0.
- highLabel
- Type string
- "Very likely"
- Word under 10.
- colors
- Type string[]
- ["#e5484d","#e8890c","#16a35a"]
- Colour of detractors (0 to 6), passives (7 to 8) and promoters (9 to 10).
- width
- Type number
- 460
- Width of the card; never wider than its container.
- value / onChange
- Type number | null / (score) => void
- –
- Controlled score from 0 to 10, null for none.
- defaultValue
- Type number | null
- null
- Score on mount when uncontrolled.
- segmentLabels
- Type [string, string, string]
- ["Detractor", "Passive", "Promoter"]
- Name of each group, shown as a chip once picked.
- followUps
- Type [string, string, string]
- –
- Follow-up question for each group.
- onSubmit
- Type (feedback: { score, segment, comment }) => void | Promise
- –
- Called when sent. Return a promise to hold the button in a sending state; a rejection keeps the card open.
- placeholder / submitLabel / thanksLabel
- Type string
- –
- Note placeholder, send button text and the line shown once sent.
- className
- Type string
- –
- Classes for the wrapper.