face-rating-gradient
stackzero/face-rating-gradientFreeComponent
stackzero publishes no description for this item.
Install it
npx shadcn@latest add https://ui.stackzero.co/r/face-rating-gradient.jsonSource
1"use client";23import { cn } from "@/lib/utils";4import {5 AngryIcon,6 FrownIcon,7 LaughIcon,8 MehIcon,9 SmileIcon,10} from "lucide-react";11import * as React from "react";12import tinycolor from "tinycolor2";1314interface FaceRatingGradientProps {15 value: number;16 onChange: (value: number) => void;17 className?: string;18 iconSize?: number;19 baseColor?: string;20}2122const FaceRating_Gradient = ({23 baseColor = "#22c55e", // Default green color24 className,25 iconSize = 24,26 onChange,27 value,28}: FaceRatingGradientProps) => {29 const generateColorGradient = (baseColor: string, steps: number) => {30 const color = tinycolor(baseColor);31 const hsl = color.toHsl();3233 return Array.from({ length: steps }, (_, i) => {34 const lightness = hsl.l - i * 0.1;35 return tinycolor({ ...hsl, l: Math.max(0.2, lightness) }).toHexString();36 }).reverse();37 };3839 const colors = generateColorGradient(baseColor, 5);4041 const handleIconClick = (index: number) => {42 const newRating = index + 1;43 onChange(newRating);44 };4546 const isActive = (index: number) => {47 return index < value;48 };4950 const icons = [51 <AngryIcon52 key="angry"53 size={iconSize}54 color={isActive(0) ? colors[0] : "gray"}55 onClick={() => handleIconClick(0)}56 className="transition-transform duration-200 hover:scale-110"57 style={{ cursor: "pointer" }}58 />,59 <FrownIcon60 key="frown"61 size={iconSize}62 color={isActive(1) ? colors[1] : "gray"}63 onClick={() => handleIconClick(1)}64 className="transition-transform duration-200 hover:scale-110"65 style={{ cursor: "pointer" }}66 />,67 <MehIcon68 key="meh"69 size={iconSize}70 color={isActive(2) ? colors[2] : "gray"}71 onClick={() => handleIconClick(2)}72 className="transition-transform duration-200 hover:scale-110"73 style={{ cursor: "pointer" }}74 />,75 <SmileIcon76 key="smile"77 size={iconSize}78 color={isActive(3) ? colors[3] : "gray"}79 onClick={() => handleIconClick(3)}80 className="transition-transform duration-200 hover:scale-110"81 style={{ cursor: "pointer" }}82 />,83 <LaughIcon84 key="laugh"85 size={iconSize}86 color={isActive(4) ? colors[4] : "gray"}87 onClick={() => handleIconClick(4)}88 className="transition-transform duration-200 hover:scale-110"89 style={{ cursor: "pointer" }}90 />,91 ];9293 return (94 <div className={cn("flex items-center gap-x-0.5", className)}>{icons}</div>95// … truncated
What it pulls in
npm packages
Files it writes
More from stackzero
All 112 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| face-rating-basicface-rating-basic | stackzero | Components | Free | 1 dep | |
| image-carousel-basicimage-carousel-basic | stackzero | Components | Free | 5 deps | |
| image-viewer-basicimage-viewer-basic | stackzero | Components | Free | 3 deps | |
| image-viewer-basic-ex-01image-viewer-basic-ex-01 | stackzero | Components | Free | 1 dep | |
| image-viewer-basic-ex-02image-viewer-basic-ex-02 | stackzero | Components | Free | 1 dep | |
| image-viewer-motionimage-viewer-motion | stackzero | Components | Free | 4 deps | |
| image-viewer-motion-ex-01image-viewer-motion-ex-01 | stackzero | Components | Free | 1 dep | |
| input-iconinput-icon | stackzero | Components | Free | 1 dep |
