百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
A

alpine-floating-ui

> 编程语言
开源

为 Alpine 3.x 组件添加浮动 UI 功能。

100 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

为 Alpine 3.x 组件添加浮动 UI 功能。

Alpine Floating UI

Add Floating UI functionality to Alpine 3.x components.

This package only supports Alpine ^3.x.

About

This plugin adds a $float magic and an x-float directive to Alpine, with modifiers for Floating UI functionality.

Installation

CDN

Include the following `

bash

### NPM

```bash
npm install @awcodes/alpine-floating-ui

This plugin has the option to use x-trap, but you must also include the Alpine Focus plugin as well to make use of it.

javascript
import Alpine from "alpinejs";
import Focus from "@alpinejs/focus"; // optional unless you want to use x-trap
import AlpineFloatingUI from "@awcodes/alpine-floating-ui";

Alpine.plugin(Focus); // optional unless you want to use x-trap
Alpine.plugin(AlpineFloatingUI);

window.Alpine = Alpine;
window.Alpine.start();

CSS

See the Floating UI Tutorial for infomation about styling.

Usage

$float Magic

To create a Floating UI component, use the $float magic on the trigger element and apply an x-ref to your 'panel'. Don't forget to have x-data on the root element of your component.

xml

x-float Directive

To create a floating UI component with x-float, add the directive to your floating element with an x-ref to name the name. You can then trigger the panel with a click event using $refs to target the panel.

Available methods on the trigger are toggle, open, and close.

To use the middleware with x-float simply chain on the middleware you need to use.

xml

Floating UI configuration

The first argument of $float should be an object.

This object currently accepts the 'position', 'flip', 'offset', 'shift', 'arrow', and 'hide' middleware for Floating UI. See the Floating UI Tutorial for infomation about these options.

Default options are:

javascript
{
    placement: 'bottom',
    middleware: [autoPlacement()],
}

With $float Magic

To use the default options for each middleware pass an empty object as the value.

xml

With x-float Directive

All settings should be configured within the expression of the x-float directive with the exception of placement which should be used directly on the directive itself. See https://floating-ui.com/docs/computePosition#placement placement options.

xml

  

With x-float Directive

xml

  

Styling the arrow (this is just an example, you are free to style it anyway you choose):

css
.arrow {
  position: absolute;
  background-color: inherit;
  width: 8px;
  height: 8px;
  transform: rotate(45deg);
}

X-Trap

The second argument that can be passed to $float is an object of plugin options for each float-ui element.

With $float Magic

xml

With x-float Directive

xml

Versioning

This projects follow the Semantic Versioning guidelines.

License

Copyright (c) 2022 Adam Weston and contributors

Licensed under the MIT license, see LICENSE.md for details.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言