price-format-sale
stackzero/price-format-saleFreeComponent
stackzero publishes no description for this item.
Install it
npx shadcn@latest add https://ui.stackzero.co/r/price-format-sale.jsonSource
1"use client";23import { cn } from "@/lib/utils";4import { NumericFormat } from "react-number-format";56interface PriceFormat_SaleProps extends React.HTMLAttributes<HTMLDivElement> {7 originalPrice: number;8 salePrice?: number;9 prefix?: string;10 thousandSeparator?: string;11 decimalSeparator?: string;12 decimalScale?: number;13 showSavePercentage?: boolean;14 classNameOriginalPrice?: string;15 classNameSalePrice?: string;16 classNameSalePercentage?: string;17}1819const PriceFormat_Sale: React.FC<PriceFormat_SaleProps> = ({20 className,21 classNameOriginalPrice,22 classNameSalePercentage,23 classNameSalePrice,24 decimalScale = 2,25 decimalSeparator = ",",26 originalPrice,27 prefix = "$",28 salePrice,29 showSavePercentage = false,30 thousandSeparator = ".",31}) => {32 const isSale = salePrice !== undefined && salePrice < originalPrice;33 const savePercentage = isSale34 ? ((originalPrice - salePrice) / originalPrice) * 10035 : 0;3637 return (38 <div className={cn("flex flex-wrap items-center gap-2", className)}>39 {isSale ? (40 <>41 <NumericFormat42 value={originalPrice}43 thousandSeparator={thousandSeparator}44 decimalSeparator={decimalSeparator}45 decimalScale={decimalScale}46 prefix={prefix}47 displayType="text"48 className={cn(49 "font-medium text-gray-500 line-through",50 classNameOriginalPrice51 )}52 />53 <NumericFormat54 value={salePrice}55 thousandSeparator={thousandSeparator}56 decimalSeparator={decimalSeparator}57 decimalScale={decimalScale}58 prefix={prefix}59 displayType="text"60 className={cn(61 "text-[length:inherit] font-medium",62 classNameSalePrice63 )}64 />65 {showSavePercentage && (66 <span67 className={cn(68 "rounded-sm bg-green-500/50 p-1 text-sm font-medium",69 classNameSalePercentage70 )}71 >72 Save {Math.round(savePercentage)}%73 </span>74 )}75 </>76 ) : (77 <NumericFormat78 value={originalPrice}79 thousandSeparator={thousandSeparator}80 decimalSeparator={decimalSeparator}81 decimalScale={decimalScale}82 prefix={prefix}83 displayType="text"84 className={cn(85 "text-[length:inherit] font-medium",86// … truncated
What it pulls in
npm packages
Other registry items
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 | |
| face-rating-gradientface-rating-gradient | stackzero | Components | Free | 2 deps | |
| 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 |
