浮层

computePopoverLayout 纯函数选侧(prefer → 翻对侧 → 取大侧);openPopover 负责 portal、跟随重算与外点/Esc 关闭。

<div class="demo-row">  <button class="btn" id="popover-demo-trigger">筛选 ▾</button></div><div class="popover" id="popover-demo-panel" hidden>  <div class="form-field">    <label class="form-label" for="popover-demo-input">包含关键词</label>    <input class="form-input" id="popover-demo-input" placeholder="例如:overlay" />  </div>  <div class="demo-row" style="margin-top:10px">    <button class="btn btn-sm btn-primary" id="popover-demo-apply">应用</button>  </div></div>

安装

bun add @icen.ai/ui

一行引入该组件(CSS 与 behavior 自动带上,无需关心内部 CSS 文件名):

import '@icen.ai/ui/kit/popover';

也可以用脚手架直接打印引入行:

bunx --bun @icen.ai/ui add popover

Astro 项目注意:kit 入口里的 CSS import 在页面 <script> 里会被 Astro 的 client bundle 摇掉——请改在布局 frontmatter 里引 CSS(import '@icen.ai/ui/components/popover.css';),JS 行为仍可走 kit。Vite SPA / webpack 项目无此问题。

用法

import { openPopover, closePopover, computePopoverLayout } from '@icen.ai/ui/behaviors/popover'; openPopover(panel, { anchor: trigger, side: 'bottom', align: 'start' });// panel 移入 body 定位;resize / 捕获 scroll 重算;外点 / Esc 关闭并还原