@lobehub/ui
Version:
Lobe UI is an open-source UI component library for building AIGC web apps
1 lines • 4.83 kB
Source Map (JSON)
{"version":3,"file":"placement.mjs","names":["top: PlacementConfig","topLeft: PlacementConfig","topRight: PlacementConfig","bottom: PlacementConfig","bottomLeft: PlacementConfig","bottomRight: PlacementConfig","left: PlacementConfig","leftTop: PlacementConfig","leftBottom: PlacementConfig","right: PlacementConfig","rightTop: PlacementConfig","rightBottom: PlacementConfig","placementMap: Record<Placement, PlacementConfig>"],"sources":["../../src/utils/placement.ts"],"sourcesContent":["import type { Placement as FloatingUIPlacement } from '@floating-ui/react';\n\n/**\n * Base UI uses a small set of string literal unions for alignment and side.\n * We re-declare them here to avoid importing internal/non-exported Base UI paths.\n */\nexport type Side = 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start';\nexport type Align = 'start' | 'center' | 'end';\n\nexport type PlacementConfig = {\n align: Align;\n side: Side;\n};\n\n/**\n * All supported placement values\n * - Unified placement names for Tooltip, Popover, and DropdownMenu\n * - Ant Design style: topLeft, topCenter, topRight, etc.\n * - Additional aliases: top (same as topCenter), bottom (same as bottomCenter)\n */\nexport type Placement =\n | 'top'\n | 'topLeft'\n | 'topCenter'\n | 'topRight'\n | 'bottom'\n | 'bottomLeft'\n | 'bottomCenter'\n | 'bottomRight'\n | 'left'\n | 'leftTop'\n | 'leftBottom'\n | 'right'\n | 'rightTop'\n | 'rightBottom';\n\nconst top: PlacementConfig = { align: 'center', side: 'top' };\nconst topLeft: PlacementConfig = { align: 'start', side: 'top' };\nconst topRight: PlacementConfig = { align: 'end', side: 'top' };\nconst bottom: PlacementConfig = { align: 'center', side: 'bottom' };\nconst bottomLeft: PlacementConfig = { align: 'start', side: 'bottom' };\nconst bottomRight: PlacementConfig = { align: 'end', side: 'bottom' };\nconst left: PlacementConfig = { align: 'center', side: 'left' };\nconst leftTop: PlacementConfig = { align: 'start', side: 'left' };\nconst leftBottom: PlacementConfig = { align: 'end', side: 'left' };\nconst right: PlacementConfig = { align: 'center', side: 'right' };\nconst rightTop: PlacementConfig = { align: 'start', side: 'right' };\nconst rightBottom: PlacementConfig = { align: 'end', side: 'right' };\n\n/**\n * Map of placement values to Base UI placement config\n * Used by Popover and DropdownMenu components\n */\nexport const placementMap: Record<Placement, PlacementConfig> = {\n bottom,\n bottomCenter: bottom,\n bottomLeft,\n bottomRight,\n left,\n leftBottom,\n leftTop,\n right,\n rightBottom,\n rightTop,\n top,\n topCenter: top,\n topLeft,\n topRight,\n};\n\n/**\n * Convert unified Placement to Floating UI placement format\n * Used by Tooltip component which uses @floating-ui/react\n *\n * @param placement - Unified placement value\n * @returns Floating UI placement (e.g., 'top-start', 'bottom-end')\n */\nexport const toFloatingUIPlacement = (placement?: Placement): FloatingUIPlacement => {\n if (!placement) return 'top';\n\n switch (placement) {\n case 'topLeft': {\n return 'top-start';\n }\n case 'top':\n case 'topCenter': {\n return 'top';\n }\n case 'topRight': {\n return 'top-end';\n }\n case 'bottomLeft': {\n return 'bottom-start';\n }\n case 'bottom':\n case 'bottomCenter': {\n return 'bottom';\n }\n case 'bottomRight': {\n return 'bottom-end';\n }\n case 'leftTop': {\n return 'left-start';\n }\n case 'left': {\n return 'left';\n }\n case 'leftBottom': {\n return 'left-end';\n }\n case 'rightTop': {\n return 'right-start';\n }\n case 'right': {\n return 'right';\n }\n case 'rightBottom': {\n return 'right-end';\n }\n default: {\n return 'top';\n }\n }\n};\n"],"mappings":";AAoCA,MAAMA,MAAuB;CAAE,OAAO;CAAU,MAAM;CAAO;AAC7D,MAAMC,UAA2B;CAAE,OAAO;CAAS,MAAM;CAAO;AAChE,MAAMC,WAA4B;CAAE,OAAO;CAAO,MAAM;CAAO;AAC/D,MAAMC,SAA0B;CAAE,OAAO;CAAU,MAAM;CAAU;AACnE,MAAMC,aAA8B;CAAE,OAAO;CAAS,MAAM;CAAU;AACtE,MAAMC,cAA+B;CAAE,OAAO;CAAO,MAAM;CAAU;AACrE,MAAMC,OAAwB;CAAE,OAAO;CAAU,MAAM;CAAQ;AAC/D,MAAMC,UAA2B;CAAE,OAAO;CAAS,MAAM;CAAQ;AACjE,MAAMC,aAA8B;CAAE,OAAO;CAAO,MAAM;CAAQ;AAClE,MAAMC,QAAyB;CAAE,OAAO;CAAU,MAAM;CAAS;AACjE,MAAMC,WAA4B;CAAE,OAAO;CAAS,MAAM;CAAS;AACnE,MAAMC,cAA+B;CAAE,OAAO;CAAO,MAAM;CAAS;;;;;AAMpE,MAAaC,eAAmD;CAC9D;CACA,cAAc;CACd;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,WAAW;CACX;CACA;CACD;;;;;;;;AASD,MAAa,yBAAyB,cAA+C;AACnF,KAAI,CAAC,UAAW,QAAO;AAEvB,SAAQ,WAAR;EACE,KAAK,UACH,QAAO;EAET,KAAK;EACL,KAAK,YACH,QAAO;EAET,KAAK,WACH,QAAO;EAET,KAAK,aACH,QAAO;EAET,KAAK;EACL,KAAK,eACH,QAAO;EAET,KAAK,cACH,QAAO;EAET,KAAK,UACH,QAAO;EAET,KAAK,OACH,QAAO;EAET,KAAK,aACH,QAAO;EAET,KAAK,WACH,QAAO;EAET,KAAK,QACH,QAAO;EAET,KAAK,cACH,QAAO;EAET,QACE,QAAO"}