shadcn-cal-com
repository·master·Indexed 19 days ago
https://github.com/damianricobelli/shadcn-cal-comA Next.js project combining shadcn/ui components with Cal.com functionality. It includes specialized components such as a Calendar for date selection and a PhoneInput with country selection and validation via libphonenumber-js, as well as utility functions for merging Tailwind classes and generating CSS variable scales.
What's inside shadcn-cal-com
- The project can be deployed using the Vercel Platform. For detailed instructions, refer to the official Next.js deployment documentation.
Run the development server
masterTo start the project in development mode, use your preferred package manager to run the
devscript. Once running, the application will be available athttp://localhost:3000.npm run dev # or yarn dev # or pnpm dev # or bun devMerge Tailwind classes with cn()
masterThe
cnutility function is used to conditionally merge CSS class names. It combines the functionality ofclsx(for conditional logic) andtailwind-merge(to resolve Tailwind class conflicts). This is the standard way to apply classes to components in this project to ensure that late-arriving utility classes correctly override previous ones.import { cn } from '@/lib/utils'; // Example usage with conditional classes const className = cn("base-class", isActive && "active-class", "extra-class");Use the Calendar component for date selection
masterThe
Calendarcomponent provides a client-side interface for date selection, utilizing@react-aria/calendarand@react-stately/calendarfor state management. It automatically handles locale-aware calendar logic and provides a header for navigation (previous/next month) and a grid for date selection.To use it, pass
CalendarProps<DateValue>which includes the initial date value and other standard calendar configuration options.import { Calendar } from "./components/calendar"; import { today, getLocalTimeZone } from "@internationalized/date"; export default function MyPage() { return ( <Calendar aria-label="Date selection" defaultValue={today(getLocalTimeZone())} /> ); }Parse phone number data with getPhoneData()
masterUse
getPhoneData(phone: string)to extract detailed metadata from a raw phone number string. It useslibphonenumber-jsinternally to provide information such as validity, country codes, and international formatting. This is useful for validating user input or displaying formatted numbers.import { getPhoneData } from "@/components/phone-input"; const data = getPhoneData("+14155552671"); console.log(data.isValid); // true console.log(data.countryCode); // "US" console.log(data.internationalNumber); // "+1 415 555 2671"Generate CSS variable scales with generateScale()
masterThe
generateScalefunction creates an object mapping CSS variable names to their corresponding values for a 12-step scale. This is typically used for generating design tokens like spacing, sizing, or opacity scales.Parameters
name: The base name of the CSS variable (e.g.,spacing).isOverlay: A boolean flag.- If
false(default), it generates both standard tokens (e.g.,1: var(--name-1)) and 'a' tokens (e.g.,a1: var(--name-a1)). - If
true, it only generates the 'a' tokens (e.g.,a1: var(--name-a1)).
- If
import { generateScale } from '@/lib/utils'; // Generates a standard scale with 12 steps const scale = generateScale({ name: 'spacing' }); /* Output structure example: { "1": "var(--spacing-1)", "a1": "var(--spacing-a1)", "2": "var(--spacing-2)", "a2": "var(--spacing-a2)", ... } */Use the PhoneInput component
masterThe
PhoneInputcomponent provides a specialized input field for phone numbers, including a country selector (popover/combobox) and automatic formatting as the user types. It supports undo functionality viaCtrl+ZorCmd+Zusing an internal history state.Props
value(optional): The current phone number string.defaultCountry(optional): The ISO 3166-1 alpha-2 country code to use as default (e.g., "US"). Defaults to "US".className: Standard CSS class for the container.id: The input ID.required: Boolean to indicate if the field is required. Defaults totrue....rest: Any other standard HTMLinputattributes.
import { PhoneInput } from "@/components/phone-input"; export function MyForm() { return ( <PhoneInput defaultCountry="US" placeholder="Enter your phone number" onChange={(e) => console.log(e.target.value)} /> ); }PhoneData type definition
masterThe
PhoneDatatype describes the structure returned bygetPhoneData. It includes:phoneNumber: The E164 formatted number.countryCode: The ISO 3166-1 alpha-2 country code.countryCallingCode: The numeric calling code (e.g., "1").carrierCode: The carrier code if available.nationalNumber: The number without the country code.internationalNumber: The formatted international string.possibleCountries: A comma-separated string of possible country matches.isValid: Boolean indicating if the number is valid.isPossible: Boolean indicating if the number is possible.uri: The URI representation of the number.type: The type of number (e.g., MOBILE, FIXED_LINE).