{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "peek-folder",
  "type": "registry:item",
  "title": "Peek Folder",
  "description": "Tiles tucked in a frosted-glass folder pocket, glowing through it; tap or hover and they spring up and fan out.",
  "categories": [
    "interaction"
  ],
  "dependencies": [
    "@shopify/react-native-skia",
    "react-native-reanimated",
    "react-native-svg",
    "react-native-worklets"
  ],
  "registryDependencies": [
    "https://kinetik-ui.dev/r/kinetik-tokens.json",
    "https://kinetik-ui.dev/r/kinetik-motion.json",
    "https://kinetik-ui.dev/r/kinetik-haptics.json"
  ],
  "files": [
    {
      "path": "src/components/kinetik/peek-folder.tsx",
      "type": "registry:file",
      "target": "~/components/kinetik/peek-folder.tsx",
      "content": "import {\n  BackdropBlur,\n  Canvas,\n  Group,\n  Path,\n  RoundedRect,\n  Skia,\n  type SkPath,\n} from '@shopify/react-native-skia';\nimport { useEffect, useMemo, useState } from 'react';\nimport { Pressable, StyleSheet, View, type StyleProp, type ViewStyle } from 'react-native';\nimport {\n  useDerivedValue,\n  useSharedValue,\n  withDelay,\n  withSpring,\n  type SharedValue,\n} from 'react-native-reanimated';\nimport Svg, { Path as SvgPath } from 'react-native-svg';\n\nimport { useHaptic } from '../../lib/kinetik/hooks/use-haptic';\nimport { useReduceMotion } from '../../lib/kinetik/hooks/use-reduce-motion';\nimport { spring } from '../../lib/kinetik/motion/motion';\nimport { useKinetikTheme } from '../../lib/kinetik/tokens/theme';\nimport { minTouchTarget, withAlpha } from '../../lib/kinetik/tokens/tokens';\n\nexport type FolderItem = {\n  /** An SVG path on a 24 pt grid, drawn as a bold stroke (any Tabler icon works, from https://iconstack.io). */\n  glyph: string;\n  /** Stroke colour of the glyph. */\n  color: string;\n};\n\nexport type PeekFolderProps = {\n  /** Read by screen readers, e.g. \"Fonts\". */\n  label: string;\n  /** Up to three tiles, left, middle, right. */\n  items: readonly FolderItem[];\n  /** Open state, if you control it. */\n  open?: boolean;\n  onOpenChange?: (open: boolean) => void;\n  /** Shows the round arrow button on the pocket. */\n  onOpen?: () => void;\n  /** Lift the tiles while a pointer hovers (web), without opening. Defaults to true. */\n  hover?: boolean;\n  /** A tap as the folder opens and closes. Defaults to true. */\n  haptics?: boolean;\n  style?: StyleProp<ViewStyle>;\n};\n\n/** Tile poses at rest and lifted, on a 300 × 258 stage: x, y, turn in degrees. */\nconst POSES = [\n  { rest: [96, 138, -10], open: [74, 92, -17] },\n  { rest: [150, 118, 0], open: [150, 66, -2] },\n  { rest: [204, 142, 9], open: [226, 96, 15] },\n] as const;\n/** Middle first, so the side tiles overlap it. */\nconst DRAW_ORDER = [1, 0, 2];\nconst TILE = 100;\n\n/** Arrow up-right from Tabler Icons (MIT, https://tabler.io/icons). */\n// Drawn with SVG: a Skia canvas for one small icon would be a GPU surface of its own.\nconst ARROW = 'M17 7l-10 10 M8 7l9 0l0 9';\n\nfunction pocketPath(u: number): SkPath {\n  const L = 16 * u;\n  const R = 284 * u;\n  const T1 = 146 * u;\n  const T2 = 164 * u;\n  const B = 252 * u;\n  const r = 18 * u;\n  const sx = 132 * u;\n  const sw = 30 * u;\n  return Skia.PathBuilder.Make()\n    .moveTo(L, T1 + r)\n    .quadTo(L, T1, L + r, T1)\n    .lineTo(sx, T1)\n    .cubicTo(sx + sw * 0.5, T1, sx + sw * 0.5, T2, sx + sw, T2)\n    .lineTo(R - r, T2)\n    .quadTo(R, T2, R, T2 + r)\n    .lineTo(R, B - r)\n    .quadTo(R, B, R - r, B)\n    .lineTo(L + r, B)\n    .quadTo(L, B, L, B - r)\n    .close()\n    .detach();\n}\n\nfunction backPath(u: number): SkPath {\n  return (\n    Skia.PathBuilder.Make()\n      // The same width as the pocket in front, so the folder reads as one object.\n      .addRRect(Skia.RRectXY(Skia.XYWHRect(16 * u, 74 * u, 268 * u, 178 * u), 18 * u, 18 * u))\n      .addRRect(Skia.RRectXY(Skia.XYWHRect(16 * u, 58 * u, 104 * u, 40 * u), 14 * u, 14 * u))\n      .detach()\n  );\n}\n\n/**\n * A folder with tiles tucked into a frosted-glass pocket, their colours\n * glowing through the glass. Tap it, or hover on the web, and the tiles\n * spring up and fan out; tap again and they drop back in.\n */\nexport function PeekFolder({\n  label,\n  items,\n  open: controlled,\n  onOpenChange,\n  onOpen,\n  hover = true,\n  haptics = true,\n  style,\n}: PeekFolderProps) {\n  const { colors, scheme, shadow } = useKinetikTheme();\n  const reduced = useReduceMotion();\n  const haptic = useHaptic(haptics);\n  const [own, setOwn] = useState(false);\n  const [hovered, setHovered] = useState(false);\n  const [width, setWidth] = useState(0);\n  const open = controlled ?? own;\n  // A hover only lifts the tiles for as long as it lasts; a tap opens the folder.\n  const raised = open || (hover && hovered);\n\n  const lift = useSharedValue(raised ? 1 : 0);\n  useEffect(() => {\n    lift.set(reduced ? (raised ? 1 : 0) : withSpring(raised ? 1 : 0, spring('bouncy')));\n  }, [raised, reduced, lift]);\n\n  const toggle = () => {\n    haptic('tap');\n    if (controlled === undefined) setOwn(!open);\n    onOpenChange?.(!open);\n  };\n\n  const u = width / 300;\n  const height = 258 * u;\n  const pocket = useMemo(() => (width > 0 ? pocketPath(u) : null), [width, u]);\n  const back = useMemo(() => (width > 0 ? backPath(u) : null), [width, u]);\n  const dark = scheme === 'dark';\n\n  return (\n    <View\n      style={[styles.host, style]}\n      onLayout={(e) => setWidth(Math.min(340, e.nativeEvent.layout.width))}\n    >\n      <Pressable\n        accessibilityRole=\"button\"\n        accessibilityLabel={label}\n        accessibilityHint={open ? 'Tucks the items away' : 'Shows what is inside'}\n        accessibilityState={{ expanded: open }}\n        onPress={toggle}\n        onHoverIn={hover ? () => setHovered(true) : undefined}\n        onHoverOut={hover ? () => setHovered(false) : undefined}\n        style={{ width: width || '100%', height: height || 240 }}\n      >\n        {pocket && !dark ? (\n          // The pocket's shadow lives outside the canvas, so it is not redrawn as the tiles move.\n          <View\n            pointerEvents=\"none\"\n            style={{\n              position: 'absolute',\n              left: 16 * u,\n              top: 164 * u,\n              width: 268 * u,\n              height: 88 * u,\n              borderRadius: 18 * u,\n              boxShadow: shadow.lg,\n            }}\n          />\n        ) : null}\n        {pocket && back ? (\n          <Canvas style={StyleSheet.absoluteFill} pointerEvents=\"none\">\n            <Path path={back} color={colors.skeleton} />\n            {DRAW_ORDER.map((i) =>\n              items[i] ? <Tile key={i} index={i} item={items[i]} u={u} lift={lift} /> : null,\n            )}\n            {/* The glass: everything behind it blurred. */}\n            <BackdropBlur blur={11 * u} clip={pocket}>\n              <Path path={pocket} color={withAlpha(colors.surfaceRaised, dark ? 0.55 : 0.5)} />\n            </BackdropBlur>\n            <Path\n              path={pocket}\n              style=\"stroke\"\n              strokeWidth={1.5}\n              color={withAlpha(colors.highlight, dark ? 0.16 : 0.95)}\n            />\n          </Canvas>\n        ) : null}\n      </Pressable>\n\n      {onOpen && width > 0 ? (\n        <Pressable\n          accessibilityRole=\"button\"\n          accessibilityLabel={`Open ${label}`}\n          onPress={onOpen}\n          style={({ pressed }) => [\n            styles.arrowHit,\n            {\n              left: 284 * u - 18 * u - minTouchTarget + 4,\n              top: 252 * u - 18 * u - minTouchTarget + 4,\n              transform: [{ scale: pressed ? 0.92 : 1 }],\n            },\n          ]}\n        >\n          <View\n            style={[\n              styles.arrow,\n              { backgroundColor: colors.ember, borderColor: withAlpha(colors.highlight, 0.9) },\n            ]}\n          >\n            <Svg width={18} height={18} viewBox=\"0 0 24 24\" fill=\"none\" pointerEvents=\"none\">\n              <SvgPath\n                d={ARROW}\n                stroke={colors.onEmber}\n                strokeWidth={2.4}\n                strokeLinecap=\"round\"\n                strokeLinejoin=\"round\"\n              />\n            </Svg>\n          </View>\n        </Pressable>\n      ) : null}\n    </View>\n  );\n}\n\n/** One tile, dropping in on arrival and fanning out when the folder opens. */\nfunction Tile({\n  index,\n  item,\n  u,\n  lift,\n}: {\n  index: number;\n  item: FolderItem;\n  u: number;\n  lift: SharedValue<number>;\n}) {\n  const { colors } = useKinetikTheme();\n  const reduced = useReduceMotion();\n  const glyph = useMemo(\n    () => Skia.Path.MakeFromSVGString(item.glyph) ?? Skia.Path.Make(),\n    [item.glyph],\n  );\n  const drop = useSharedValue(reduced ? 1 : 0);\n  useEffect(() => {\n    if (!reduced) drop.set(withDelay(160 + index * 110, withSpring(1, spring('bouncy'))));\n  }, [index, reduced, drop]);\n\n  const pose = POSES[index]!;\n  const transform = useDerivedValue(() => {\n    const o = lift.get();\n    const x = pose.rest[0] + (pose.open[0] - pose.rest[0]) * o;\n    const y = pose.rest[1] + (pose.open[1] - pose.rest[1]) * o - (1 - drop.get()) * 90;\n    const turn = pose.rest[2] + (pose.open[2] - pose.rest[2]) * o;\n    return [{ translateX: x * u }, { translateY: y * u }, { rotate: (turn * Math.PI) / 180 }];\n  });\n  const opacity = useDerivedValue(() => Math.min(1, drop.get() * 2));\n  const s = TILE * u;\n  const g = 2.7 * u;\n\n  return (\n    <Group transform={transform} opacity={opacity}>\n      {/* A soft shadow from two offset layers: no blur to redraw while the tile moves. */}\n      <RoundedRect\n        x={-s / 2 - 2 * u}\n        y={-s / 2 + 7 * u}\n        width={s + 4 * u}\n        height={s}\n        r={20 * u}\n        color={withAlpha(colors.text, 0.04)}\n      />\n      <RoundedRect\n        x={-s / 2}\n        y={-s / 2 + 3 * u}\n        width={s}\n        height={s}\n        r={18 * u}\n        color={withAlpha(colors.text, 0.06)}\n      />\n      <RoundedRect\n        x={-s / 2}\n        y={-s / 2}\n        width={s}\n        height={s}\n        r={18 * u}\n        color={colors.surfaceRaised}\n      />\n      <RoundedRect\n        x={-s / 2}\n        y={-s / 2}\n        width={s}\n        height={s}\n        r={18 * u}\n        style=\"stroke\"\n        strokeWidth={1}\n        color={colors.border}\n      />\n      <Group transform={[{ scale: g }, { translateX: -12 }, { translateY: -12 }]}>\n        <Path\n          path={glyph}\n          style=\"stroke\"\n          strokeWidth={2.6}\n          strokeCap=\"round\"\n          strokeJoin=\"round\"\n          color={item.color}\n        />\n      </Group>\n    </Group>\n  );\n}\n\nconst styles = StyleSheet.create({\n  host: { width: '100%', maxWidth: 340, alignSelf: 'center' },\n  arrowHit: {\n    position: 'absolute',\n    width: minTouchTarget,\n    height: minTouchTarget,\n    alignItems: 'center',\n    justifyContent: 'center',\n  },\n  arrow: {\n    width: 40,\n    height: 40,\n    borderRadius: 20,\n    borderWidth: 2,\n    alignItems: 'center',\n    justifyContent: 'center',\n  },\n});\n"
    }
  ],
  "meta": {
    "version": "1.0.0",
    "kind": "component",
    "platforms": [
      "ios",
      "android",
      "web"
    ],
    "category": "interaction",
    "web": "live",
    "perf": {
      "budget": "One Skia canvas: the tiles move by transforms from one UI-thread spring and the glass is a single backdrop blur. Nothing animates at rest.",
      "measurements": [
        {
          "device": "Pixel 9 emulator, API 35",
          "kind": "emulator",
          "date": "2026-10-14",
          "build": "release",
          "frameMs": 18,
          "p90Ms": 25,
          "baselineMs": 17,
          "jankyPercent": 1.71,
          "atRest": "idle",
          "memoryMb": 153
        }
      ]
    },
    "a11y": {
      "reducedMotion": "The tiles jump between tucked and lifted without the spring or the drop-in.",
      "screenReader": "The folder is a button named by `label` with its expanded state; the arrow is a separate \"Open …\" button.",
      "touchTarget": "The whole folder is the toggle; the arrow button is 44 pt."
    },
    "requires": "React Native New Architecture (Reanimated 4)",
    "guide": "## Usage\n\n```tsx\nimport { PeekFolder } from '@/components/kinetik/peek-folder';\n\n<PeekFolder\n  label=\"Design assets\"\n  items={[\n    { glyph: typeIconPath, color: '#FF6A00' },\n    { glyph: shapesIconPath, color: '#111' },\n    { glyph: sparkIconPath, color: '#0A84FF' },\n  ]}\n  onOpen={() => router.push('/assets')}\n/>;\n```\n\n## When to use\n\n- A playful entry point to a collection: a folder, an album, a kit.\n\n## When not to use\n\n- File browsers with many folders: the blur and the motion are for a few hero items.\n\n## Notes\n\n- `glyph` is an SVG path on a 24 pt grid, drawn as a bold stroke. Join an icon's paths with spaces.\n- Uncontrolled by default; pass `open` and `onOpenChange` to drive it yourself.\n- `hover` lifts the tiles while a pointer is over the folder on the web.\n- The glass is a Skia backdrop blur clipped to the pocket, so the tiles' colours glow through it.\n"
  },
  "docs": "Prefer `npx kinetik-ui add peek-folder`: it installs dependencies with expo install, so versions match your Expo SDK."
}
