### Install Dependencies Source: https://github.com/silk-hq/silk/blob/main/examples/css/README.md Install project dependencies using npm, yarn, or pnpm. This is a standard step for Next.js projects. ```bash npm install # or yarn install # or pnpm install ``` -------------------------------- ### Clone CSS Examples Directory Source: https://github.com/silk-hq/silk/blob/main/examples/css/README.md Use npx degit to quickly copy the CSS examples directory locally. This command downloads the specified directory into a new local folder. ```bash npx degit silk-hq/silk/examples/css silk-examples-css ``` -------------------------------- ### Run Development Server Source: https://github.com/silk-hq/silk/blob/main/examples/css/README.md Start the Next.js development server using npm, yarn, or pnpm. Open http://localhost:3000 in your browser to view the application. ```bash npm run dev # or yarn dev # or pnpm dev ``` -------------------------------- ### Uncontrolled Sheet.Root Example Source: https://context7.com/silk-hq/silk/llms.txt Demonstrates the uncontrolled usage of Sheet.Root, which manages its own presented state. Requires a license key for production. ```tsx import { Sheet } from "@silk-hq/components"; // Uncontrolled Open Hello Sheet content goes here. Close ``` -------------------------------- ### Controlled Sheet.Root Example Source: https://context7.com/silk-hq/silk/llms.txt Shows the controlled usage of Sheet.Root, where the presented state is managed externally via the 'presented' and 'onPresentedChange' props. A license key is required. ```tsx import { Sheet } from "@silk-hq/components"; // Controlled const [open, setOpen] = useState(false); {/* ... */} ``` -------------------------------- ### Sheet Backdrop with Custom Opacity Animation Source: https://context7.com/silk-hq/silk/llms.txt Control the backdrop's opacity using travelAnimation. This example applies a custom curve that caps the opacity at 0.2. ```tsx Math.min(progress * 0.2, 0.2), }} themeColorDimming="auto" /> ``` -------------------------------- ### Card-style Sheet Content with Scale Animation Source: https://context7.com/silk-hq/silk/llms.txt Apply travelAnimation to Sheet.Content for effects like scaling. This example scales the content in from 80% of its original size. ```tsx {children} ``` -------------------------------- ### Sheet.View with Responsive Centered/Bottom Placement Source: https://context7.com/silk-hq/silk/llms.txt Sets up Sheet.View for responsive placement, appearing centered on large viewports and at the bottom on smaller ones. Utilizes 'useClientMediaQuery' for breakpoint detection. ```tsx import { Sheet, type SheetViewProps } from "@silk-hq/components"; const largeViewport = useClientMediaQuery("(min-width: 650px)"); const placement = largeViewport ? "center" : "bottom"; const tracks: SheetViewProps["tracks"] = largeViewport ? ["top", "bottom"] : "bottom"; {/* ... */} ``` -------------------------------- ### Sidebar Pattern with Sheet.Root Source: https://context7.com/silk-hq/silk/llms.txt Create a left-sliding sidebar drawer using Sheet.Root with `contentPlacement="left"`, `swipeOvershoot={false}`, and `sheetRole="dialog"`. Includes a visually hidden close trigger for accessibility. ```tsx import { Sheet, VisuallyHidden } from "@silk-hq/components"; const SidebarExample = () => ( ☰ Menu Navigation Sidebar Close Navigation ); ``` -------------------------------- ### Responsive Layout with useClientMediaQuery Hook Source: https://context7.com/silk-hq/silk/llms.txt Use the useClientMediaQuery hook to dynamically adjust layout properties like contentPlacement and tracks based on CSS media queries. This hook re-evaluates on window resize. ```tsx import { useClientMediaQuery } from "@silk-hq/components"; const MySheet = () => { const largeViewport = useClientMediaQuery("(min-width: 800px)"); const contentPlacement = largeViewport ? "center" : "bottom"; const tracks = largeViewport ? ["top", "bottom"] : "bottom"; return ( Open ... ); }; ``` -------------------------------- ### VisuallyHidden.Root for Accessibility Source: https://context7.com/silk-hq/silk/llms.txt Use VisuallyHidden.Root to hide content visually while keeping it accessible to assistive technologies. The `asChild` prop allows applying hidden styles directly to a child element. ```tsx import { VisuallyHidden } from "@silk-hq/components"; // Wrap an element Accessible label // Apply to child via asChild Accessible label ``` -------------------------------- ### Sheet.View with Spring Animation and Edge Swipe Prevention Source: https://context7.com/silk-hq/silk/llms.txt Configures Sheet.View for a bottom sheet with spring entrance animations, no overshoot, and native edge swipe prevention. Includes callbacks for travel status and progress. ```tsx import { Sheet, type SheetViewProps } from "@silk-hq/components"; const springSettings = { easing: "spring" as const, stiffness: 480, damping: 45, mass: 1.5, }; // Bottom sheet with spring entrance, no overshoot, edge-swipe prevention { // "idleOutside" | "entering" | "idleInside" | "exiting" console.log("Travel status:", status); }} onTravel={({ progress }) => { // progress: 0 (fully outside) → 1 (fully presented) if (progress < 0.999) someRef.current?.focus(); // dismiss keyboard }} > ... ``` -------------------------------- ### Custom Stacking Animation for Nested Sheets Source: https://context7.com/silk-hq/silk/llms.txt Configure stackingAnimation on Sheet.Content for custom animations on nested sheets, such as translateX and scale. ```tsx progress <= 1 ? `${progress * -10}px` : `calc(-12.5px + 2.5px * ${progress})`, scale: [1, 0.933], transformOrigin: "0 50%", }} > {children} ``` -------------------------------- ### Sheet.Root Source: https://context7.com/silk-hq/silk/llms.txt The root provider for a sheet instance. Manages presented state, license validation, stacking context, and accessibility role. Supports both controlled and uncontrolled usage. ```APIDOC ## Sheet.Root ### Description The root provider for a sheet instance. Manages presented state, license validation, stacking context (`forComponent`), and accessibility role (`sheetRole`). Accepts controlled (`presented` / `onPresentedChange`) or uncontrolled usage. ### Usage **Uncontrolled Example:** ```tsx import { Sheet } from "@silk-hq/components"; Open Hello Sheet content goes here. Close ``` **Controlled Example:** ```tsx import { Sheet } from "@silk-hq/components"; import { useState } from "react"; const [open, setOpen] = useState(false); {/* ... other sheet components ... */} ``` ### Props - **license** (string) - Required - Commercial license key for production use. - **presented** (boolean) - Optional - Controls the presented state of the sheet (for controlled usage). - **onPresentedChange** (function) - Optional - Callback function when the presented state changes (for controlled usage). - **sheetRole** (string) - Optional - Accessibility role for the sheet (e.g., "dialog"). ``` -------------------------------- ### Stacking-Aware Low-Opacity Backdrop Source: https://context7.com/silk-hq/silk/llms.txt Configure travelAnimation for Sheet.Backdrop to control opacity, useful for stacking sheets with a subtle dimming effect. ```tsx ``` -------------------------------- ### Sheet Handle - Contextual Step/Dismiss Action Source: https://context7.com/silk-hq/silk/llms.txt Conditionally set the action prop on Sheet.Handle to 'dismiss' when the last detent is reached, or 'step' otherwise. ```tsx ``` -------------------------------- ### Sheet Trigger - Step Action Source: https://context7.com/silk-hq/silk/llms.txt Use action='step' on Sheet.Trigger to advance the sheet to its next detent state. ```tsx Expand ``` -------------------------------- ### Toast Pattern with Sheet.Root Source: https://context7.com/silk-hq/silk/llms.txt Implement an auto-dismissing toast notification using Sheet.Root in controlled mode. A useEffect timer dismisses the toast after 5 seconds of inactivity. Ensure `sheetRole=""` and `inertOutside={false}` are set for toast behavior. ```tsx import { Sheet, useClientMediaQuery } from "@silk-hq/components"; import { useState, useEffect, useRef } from "react"; const ToastExample = () => { const [presented, setPresented] = useState(false); const [travelStatus, setTravelStatus] = useState("idleOutside"); const [pointerOver, setPointerOver] = useState(false); const timer = useRef>(); const largeViewport = useClientMediaQuery("(min-width: 1000px)"); const placement = largeViewport ? "right" : "top"; useEffect(() => { if (presented && travelStatus === "idleInside" && !pointerOver) { timer.current = setTimeout(() => setPresented(false), 5000); } else { clearTimeout(timer.current); } return () => clearTimeout(timer.current); }, [presented, travelStatus, pointerOver]); return ( <>
setPointerOver(true)} onPointerLeave={() => setPointerOver(false)} > File saved Your changes have been saved successfully.
); }; ``` -------------------------------- ### Basic Sheet Content with Bleeding Background Source: https://context7.com/silk-hq/silk/llms.txt Use Sheet.Content for the main panel. Include Sheet.BleedingBackground to extend the background color into safe area notches. ```tsx Panel Title

Body content

``` -------------------------------- ### Sheet Portal - Custom Container Source: https://context7.com/silk-hq/silk/llms.txt Specify a custom DOM element for Sheet.Portal to render into using the 'container' prop, often managed with a ref. ```tsx const containerRef = useRef(null); {/* ... */} ``` -------------------------------- ### Sheet Trigger - Dismiss Action Source: https://context7.com/silk-hq/silk/llms.txt Set the action prop to 'dismiss' on Sheet.Trigger to create a button that closes the sheet. ```tsx Got it ``` -------------------------------- ### Sheet Backdrop with Auto Theme Color Dimming Source: https://context7.com/silk-hq/silk/llms.txt Use Sheet.Backdrop for the dimming overlay. 'auto' themeColorDimming enables native-style status bar dimming by reading the meta theme-color tag. ```tsx ``` -------------------------------- ### Sheet Title and Description - Visible Source: https://context7.com/silk-hq/silk/llms.txt Use Sheet.Title and Sheet.Description for accessible headings and descriptions within the sheet. They can be styled with standard CSS classes. ```tsx import { Sheet, VisuallyHidden } from "@silk-hq/components"; // Visible title Edit Product Fill in the fields below. ``` -------------------------------- ### Sheet-aware Scrollable Regions with Scroll Components Source: https://context7.com/silk-hq/silk/llms.txt Integrate Scrollable regions with Silk sheets using Scroll.Root, Scroll.View, and Scroll.Content. These components handle gesture coordination, safe-area insets, and keyboard dismissal. ```tsx import { Scroll } from "@silk-hq/components"; // Vertical scroll inside a sheet with upward-swipe trap {items.map(item =>
{item.name}
)}
``` ```tsx // Horizontal scroll gallery (no native scrollbar) {images.map((_, i) =>
)} ``` ```tsx // Scroll position drives sheet track switching (for tall content) { setTrack(progress < 0.5 ? "bottom" : "top"); }} > {longContent} ``` -------------------------------- ### Sheet.View Source: https://context7.com/silk-hq/silk/llms.txt The element that receives swipe gestures, controls content placement, tracks/detents, and manages animation settings. It fires various travel lifecycle callbacks. ```APIDOC ## Sheet.View ### Description The element that receives swipe gestures, controls content placement direction, tracks/detents, animation settings, and fires travel lifecycle callbacks. ### Usage **Bottom sheet with spring entrance:** ```tsx import { Sheet, type SheetViewProps } from "@silk-hq/components"; const springSettings = { easing: "spring" as const, stiffness: 480, damping: 45, mass: 1.5, }; { // "idleOutside" | "entering" | "idleInside" | "exiting" console.log("Travel status:", status); }} onTravel={({ progress }) => { // progress: 0 (fully outside) → 1 (fully presented) if (progress < 0.999) someRef.current?.focus(); // dismiss keyboard }} > ... ``` **Centered detached sheet with responsive placement:** ```tsx import { Sheet, type SheetViewProps } from "@silk-hq/components"; import { useClientMediaQuery } from "@silk-hq/components"; // Assuming this hook is available const largeViewport = useClientMediaQuery("(min-width: 650px)"); const placement = largeViewport ? "center" : "bottom"; const tracks: SheetViewProps["tracks"] = largeViewport ? ["top", "bottom"] : "bottom"; {/* ... */} ``` ### Props - **contentPlacement** (string) - Optional - Defines the placement of the content (`"bottom"` | `"top"` | `"left"` | `"right"` | `"center"`). - **tracks** (string | string[]) - Optional - Specifies the track(s) the sheet can move between. - **detents** (array) - Optional - Defines the specific positions (heights/widths) the sheet can snap to. - **swipeOvershoot** (boolean) - Optional - Enables or disables swipe overshoot behavior. - **swipe** (boolean) - Optional - Enables or disables swipe gestures. - **nativeEdgeSwipePrevention** (boolean) - Optional - Enables native edge swipe gesture prevention. - **inertOutside** (boolean) - Optional - Controls whether content outside the sheet is inert. - **onTravelStatusChange** (function) - Optional - Callback fired when the travel status changes. - **onTravel** (function) - Optional - Callback fired during sheet travel, providing progress. - **onTravelRangeChange** (function) - Optional - Callback fired when the travel range changes. - **enteringAnimationSettings** (object) - Optional - Settings for the entering animation. - **exitingAnimationSettings** (object) - Optional - Settings for the exiting animation. ``` -------------------------------- ### SheetStack.Root for Nested Sheets Source: https://context7.com/silk-hq/silk/llms.txt Use SheetStack.Root to coordinate stacking animations for multiple Sheet.Root instances. Associate inner Sheet.Root components with the nearest SheetStack using forComponent="closest". ```tsx import { SheetStack, Sheet } from "@silk-hq/components"; Open Profile {/* nested sheet trigger inside */} Open Related ... ``` -------------------------------- ### Sheet Portal - Default Usage Source: https://context7.com/silk-hq/silk/llms.txt Sheet.Portal renders sheet UI outside the current DOM tree, typically appended to document.body. It requires Sheet.View, Sheet.Backdrop, and Sheet.Content within it. ```tsx ... ``` -------------------------------- ### Sheet Title - Visually Hidden for Accessibility Source: https://context7.com/silk-hq/silk/llms.txt Wrap Sheet.Title with VisuallyHidden.Root to make it accessible to screen readers but invisible on screen. ```tsx import { Sheet, VisuallyHidden } from "@silk-hq/components"; // Visually hidden title (accessible but invisible) Sheet label for screen readers ``` -------------------------------- ### Multi-stop Sheets with Sheet.View detents Source: https://context7.com/silk-hq/silk/llms.txt Create multi-stop sheets by passing CSS lengths or arrays to `detents`. Control the active detent with `activeDetent` and `onActiveDetentChange`. `swipeOvershoot={false}` prevents dragging past the last detent. ```tsx const [activeDetent, setActiveDetent] = useState(0); Open { if (start === 2) setReachedLastDetent(true); // 3rd detent reached }} onTravelStatusChange={(status) => { if (status === "idleOutside") setReachedLastDetent(false); }} > {scrollableContent} ``` -------------------------------- ### Sheet Handle - Dismiss Action Source: https://context7.com/silk-hq/silk/llms.txt Sheet.Handle provides a drag indicator and can also act as a trigger. Use action='dismiss' for closing the sheet. ```tsx ``` -------------------------------- ### Sheet Trigger - Default Present Action Source: https://context7.com/silk-hq/silk/llms.txt Sheet.Trigger is a button to present or dismiss the sheet. The default action is 'present'. ```tsx Open Sheet ``` -------------------------------- ### Sheet SpecialWrapper for Pointer Event Handling Source: https://context7.com/silk-hq/silk/llms.txt Sheet.SpecialWrapper is a composition helper for Sheet.Content when using 'asChild'. It allows overriding pointer events on child elements, like pausing auto-dismiss on hover. ```tsx setPaused(true)} onPointerLeave={() => setPaused(false)} > {children} ``` -------------------------------- ### Sheet Bleeding Background for Safe Area Fill Source: https://context7.com/silk-hq/silk/llms.txt Sheet.BleedingBackground is used within Sheet.Content to extend the background color into device safe areas, ensuring a seamless look. ```tsx {/* rest of content */} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.