shadcn-cal-com

repository·master·Indexed 19 days ago

https://github.com/damianricobelli/shadcn-cal-com

A 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.

Tokens
1.5K
Snippets
6
Records
8
Agent score
66%

What's inside shadcn-cal-com

  1. Merge Tailwind classes with cn()

    master

    The cn utility function is used to conditionally merge CSS class names. It combines the functionality of clsx (for conditional logic) and tailwind-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");
  2. Use the Calendar component for date selection

    master

    The Calendar component provides a client-side interface for date selection, utilizing @react-aria/calendar and @react-stately/calendar for 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())} 
        />
      );
    }
  3. Parse phone number data with getPhoneData()

    master

    Use getPhoneData(phone: string) to extract detailed metadata from a raw phone number string. It uses libphonenumber-js internally 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"
  4. Generate CSS variable scales with generateScale()

    master

    The generateScale function 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)).
    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)",
      ...
    }
    */
  5. Use the PhoneInput component

    master

    The PhoneInput component 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 via Ctrl+Z or Cmd+Z using 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 to true.
    • ...rest: Any other standard HTML input attributes.
    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)} 
        />
      );
    }
  6. PhoneData type definition

    master

    The PhoneData type describes the structure returned by getPhoneData. 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).