Pricing Table
alexcarpenter/pricing-tableFreeComponent
A pricing table component with support for monthly/yearly pricing.
Install it
npx shadcn@latest add https://ui.alexcarpenter.me/r/pricing-table.jsonSource
1"use client"23import * as React from "react"4import { cn } from "@/lib/utils"5import { Badge } from "@/registry/default/ui/badge"6import { Button } from "@/registry/default/ui/button"7import {8 Card,9 CardAction,10 CardContent,11 CardDescription,12 CardFooter,13 CardHeader,14 CardTitle,15} from "@/registry/default/ui/card"16import {17 InfoList,18 InfoListIcon,19 InfoListItem,20 InfoListText,21} from "@/registry/default/ui/info-list"22import { Switch } from "@/registry/default/ui/switch"23import {24 ToggleGroup,25 ToggleGroupItem,26} from "@/registry/default/ui/toggle-group"27import NumberFlow from "@number-flow/react"28import { useControllableState } from "@radix-ui/react-use-controllable-state"2930type BillingPeriod = "monthly" | "yearly"31export type { BillingPeriod as PricingTableBillingPeriod }3233type PriceFormatterOptions = {34 style: "currency"35 currency: string36 trailingZeroDisplay?: "stripIfInteger" | "auto"37 minimumFractionDigits?: number38 maximumFractionDigits?: number39}4041type PricingTableContextValue = {42 billingPeriod: BillingPeriod43 setBillingPeriod: (period: BillingPeriod) => void44 priceFormatter: Intl.NumberFormat45 priceFormatterOptions: PriceFormatterOptions46 locale: Intl.LocalesArgument47}4849const defaultPriceFormatterOptions: PriceFormatterOptions = {50 style: "currency",51 currency: "USD",52 trailingZeroDisplay: "stripIfInteger",53} as const5455const PricingTableContext = React.createContext<PricingTableContextValue>({56 billingPeriod: "monthly",57 setBillingPeriod: () => {},58 priceFormatter: new Intl.NumberFormat("en-US", defaultPriceFormatterOptions),59 priceFormatterOptions: defaultPriceFormatterOptions,60 locale: "en-US",61})6263export const usePricingTableContext = () =>64 React.useContext(PricingTableContext)6566export function PricingTable({67 billingPeriod: billingPeriodProp,68 setBillingPeriod: setBillingPeriodProp,69 defaultBillingPeriod = "monthly",70 priceFormatterOptions = defaultPriceFormatterOptions,71 locale = "en-US",72 children,73 className,74 ...props75}: React.ComponentProps<"div"> & {76 billingPeriod?: BillingPeriod77 setBillingPeriod?: (period: BillingPeriod) => void78 defaultBillingPeriod?: BillingPeriod79 priceFormatterOptions?: PriceFormatterOptions80 locale?: string81}) {82 const [billingPeriod, setBillingPeriod] = useControllableState({83 prop: billingPeriodProp,84 defaultProp: defaultBillingPeriod,85 onChange: setBillingPeriodProp,86 caller: "pricing-table",87 })8889 const priceFormatter = React.useMemo(90// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from alexcarpenter
All 6 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Info Listinfo-list | alexcarpenter | Components | Free | 1 dep | |
| Inline Textinline-text | alexcarpenter | Components | Free | 1 dep |
