phoenix-duskmoon-ui
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePhoenix Duskmoon UI
Phoenix Duskmoon UI
Elixir component library providing 80+ LiveView HEEX components that render as
HTML Custom Elements () styled by .
<el-dm-*>@duskmoon-dev/coreVersion: 9.0.1
这是一个为Elixir提供的组件库,包含80+个LiveView HEEX组件,这些组件会渲染为由设置样式的HTML自定义元素()。
@duskmoon-dev/core<el-dm-*>版本:9.0.1
Installation
安装
elixir
undefinedelixir
undefinedmix.exs
mix.exs
{:phoenix_duskmoon, "~> 9.0"}
```bash
bun add @duskmoon-dev/core @duskmoon-dev/elements @duskmoon-dev/css-art @duskmoon-dev/art-elements{:phoenix_duskmoon, "~> 9.0"}
```bash
bun add @duskmoon-dev/core @duskmoon-dev/elements @duskmoon-dev/css-art @duskmoon-dev/art-elementsSetup
配置
1. Import components in app_web.ex
app_web.ex1. 在app_web.ex
中导入组件
app_web.exelixir
defp html_helpers do
quote do
use PhoenixDuskmoon.Component # all dm_* UI components
use PhoenixDuskmoon.ArtComponent # all dm_art_* decorative components
end
endelixir
defp html_helpers do
quote do
use PhoenixDuskmoon.Component # 所有dm_* UI组件
use PhoenixDuskmoon.ArtComponent # 所有dm_art_*装饰组件
end
end2. CSS (assets/css/app.css
)
assets/css/app.css2. CSS(assets/css/app.css
)
assets/css/app.csscss
@import "tailwindcss";
@plugin "@duskmoon-dev/core/plugin";
@import "@duskmoon-dev/core/themes/sunshine";
@import "@duskmoon-dev/core/themes/moonlight";
@import "@duskmoon-dev/core/components";For custom elements to inherit theme colors, include the element-theme-bridge
(ships with the package or copy from the repo's ).
assets/css/element-theme-bridge.cssFor CSS art effects, import each CSS art stylesheet you need:
css
@import "@duskmoon-dev/css-art/eclipse.css";
@import "@duskmoon-dev/css-art/snow.css";
/* ... etc */css
@import "tailwindcss";
@plugin "@duskmoon-dev/core/plugin";
@import "@duskmoon-dev/core/themes/sunshine";
@import "@duskmoon-dev/core/themes/moonlight";
@import "@duskmoon-dev/core/components";为了让自定义元素继承主题颜色,请引入element-theme-bridge(随包提供,或从仓库的复制)。
assets/css/element-theme-bridge.css如需CSS艺术效果,请导入你需要的每个CSS艺术样式表:
css
@import "@duskmoon-dev/css-art/eclipse.css";
@import "@duskmoon-dev/css-art/snow.css";
/* ... 等等 */3. JavaScript hooks (assets/js/app.js
)
assets/js/app.js3. JavaScript钩子(assets/js/app.js
)
assets/js/app.jsjavascript
import { LiveSocket } from "phoenix_live_view";
import * as DuskmoonHooks from "phoenix_duskmoon/hooks";
let liveSocket = new LiveSocket("/live", Socket, {
params: { _csrf_token: csrfToken },
hooks: DuskmoonHooks
});Merge with your own hooks: .
hooks: { ...DuskmoonHooks, ...MyHooks }javascript
import { LiveSocket } from "phoenix_live_view";
import * as DuskmoonHooks from "phoenix_duskmoon/hooks";
let liveSocket = new LiveSocket("/live", Socket, {
params: { _csrf_token: csrfToken },
hooks: DuskmoonHooks
});与你自己的钩子合并:。
hooks: { ...DuskmoonHooks, ...MyHooks }4. Register custom elements
4. 注册自定义元素
javascript
import "@duskmoon-dev/el-button/register";
import "@duskmoon-dev/el-card/register";
// ... register each el-* package you useWithout registration, content is invisible.
<el-dm-*>javascript
import "@duskmoon-dev/el-button/register";
import "@duskmoon-dev/el-card/register";
// ... 注册你使用的每个el-*包如果不注册,内容将不可见。
<el-dm-*>Architecture (v9)
架构(v9)
HEEX Components (dm_btn, dm_card)
|
Custom Elements (<el-dm-button>, <el-dm-card>)
|
@duskmoon-dev/core (CSS variables, design tokens)CSS class naming (BEM): , ,
dm-componentdm-component--variantdm-component__elementColor mapping: in component APIs maps to in CSS tokens.
"accent""tertiary"HEEX Components (dm_btn, dm_card)
|
Custom Elements (<el-dm-button>, <el-dm-card>)
|
@duskmoon-dev/core (CSS variables, design tokens)CSS类命名(BEM规范): , ,
dm-componentdm-component--variantdm-component__element颜色映射: 组件API中的对应CSS令牌中的。
"accent""tertiary"Hooks Reference
钩子参考
| Hook | Used by | Purpose |
|---|---|---|
| Any | Bridges custom element events to LiveView |
| Form | Adds |
| | Theme toggle + localStorage persistence |
| Spotlight search component | Cmd/Ctrl+K keyboard shortcut |
| | IntersectionObserver for scroll-based nav |
| 钩子 | 适用组件 | 用途 |
|---|---|---|
| 所有带有 | 将自定义元素事件桥接到LiveView |
| 表单类 | 支持 |
| | 主题切换 + localStorage持久化 |
| Spotlight搜索组件 | Cmd/Ctrl+K键盘快捷键 |
| | 基于IntersectionObserver的滚动导航 |
Component Quick Reference
组件快速参考
All components use prefix. Common attributes across most components:
dm_- ,
id— standard HTMLclass - — visual style (values vary per component)
variant - — primary | secondary | tertiary | accent | info | success | warning | error
color - — xs | sm | md | lg (varies per component)
size - — boolean
disabled - — passes through global HTML attributes
rest
For full component catalog with all attributes and slots, see
references/components.md.
所有组件均使用前缀。大多数组件的通用属性:
dm_- ,
id— 标准HTML属性class - — 视觉样式(值因组件而异)
variant - — primary | secondary | tertiary | accent | info | success | warning | error
color - — xs | sm | md | lg(因组件而异)
size - — 布尔值
disabled - — 传递全局HTML属性
rest
如需包含所有属性和插槽的完整组件目录,请查看references/components.md。
Action
操作组件
| Function | Module | Description |
|---|---|---|
| Action.Button | Button with variants, confirm dialog, noise effect |
| Action.Link | LiveView-aware link (navigate/patch/href) |
| Action.Dropdown | Popover-based dropdown with trigger + content slots |
| Action.Menu | Anchored menu with placement control |
| Action.Toggle | Toggle button group (segmented, chip, etc.) |
| 函数 | 模块 | 描述 |
|---|---|---|
| Action.Button | 带有多种变体、确认对话框、噪点效果的按钮 |
| Action.Link | 支持LiveView的链接(navigate/patch/href) |
| Action.Dropdown | 基于弹出框的下拉菜单,包含触发器和内容插槽 |
| Action.Menu | 可控制位置的锚定菜单 |
| Action.Toggle | 切换按钮组(分段式、芯片式等) |
Data Display
数据展示
| Function | Module | Description |
|---|---|---|
| DataDisplay.Accordion | Multi-panel expand/collapse |
| DataDisplay.Avatar | User avatar with status indicators |
| DataDisplay.Badge | Label badge with color variants |
| DataDisplay.Card | Content card with title/action slots |
| DataDisplay.Chip | Deletable chip/tag |
| DataDisplay.Collapse | Single collapsible panel |
| DataDisplay.Flash | Flash messages |
| DataDisplay.List | Structured list with icons and subtitles |
| DataDisplay.Markdown | Markdown renderer with syntax highlighting |
| DataDisplay.Pagination | Page navigation |
| DataDisplay.Popover | Contextual overlay with trigger |
| DataDisplay.Progress | Linear/circular progress |
| DataDisplay.Skeleton | 8 skeleton variants (text, avatar, card, table, list, form, comment, base) |
| DataDisplay.Stat | Stat display with icon slot |
| DataDisplay.Table | Data table with streaming support |
| DataDisplay.Timeline | Vertical/horizontal timeline |
| DataDisplay.Tooltip | Tooltip wrapper |
| 函数 | 模块 | 描述 |
|---|---|---|
| DataDisplay.Accordion | 多面板展开/折叠组件 |
| DataDisplay.Avatar | 带状态指示器的用户头像 |
| DataDisplay.Badge | 带颜色变体的标签徽章 |
| DataDisplay.Card | 带标题/操作插槽的内容卡片 |
| DataDisplay.Chip | 可删除的标签/芯片组件 |
| DataDisplay.Collapse | 单个可折叠面板 |
| DataDisplay.Flash | 提示消息组件 |
| DataDisplay.List | 带图标和副标题的结构化列表 |
| DataDisplay.Markdown | 带语法高亮的Markdown渲染器 |
| DataDisplay.Pagination | 分页导航组件 |
| DataDisplay.Popover | 带触发器的上下文浮层 |
| DataDisplay.Progress | 线性/圆形进度条 |
| DataDisplay.Skeleton | 8种骨架屏变体(文本、头像、卡片、表格、列表、表单、评论、基础款) |
| DataDisplay.Stat | 带图标插槽的统计展示组件 |
| DataDisplay.Table | 支持流式加载的数据表格 |
| DataDisplay.Timeline | 垂直/水平时间线 |
| DataDisplay.Tooltip | 提示框包裹组件 |
Data Entry
数据输入
| Function | Module | Description |
|---|---|---|
| DataEntry.Form | Form container + layout helpers ( |
| DataEntry.Input | Universal input (30+ types via |
| DataEntry.CompactInput | Compact variant of input |
| DataEntry.Checkbox | Checkbox with label |
| DataEntry.Radio | Radio button with label |
| DataEntry.Select | Select dropdown |
| DataEntry.Switch | Toggle switch |
| DataEntry.Slider | Range slider |
| DataEntry.Textarea | Multi-line text input |
| DataEntry.Rating | Star rating |
| DataEntry.SegmentControl | Segmented control |
| DataEntry.MultiSelect | Multi-select with tags |
| DataEntry.Autocomplete | Autocomplete input |
| DataEntry.OtpInput | OTP code input |
| DataEntry.PinInput | PIN input |
| DataEntry.FileUpload | File upload area |
| DataEntry.TimeInput | Time picker |
| DataEntry.Cascader | Cascading select |
| DataEntry.TreeSelect | Tree-structured select |
| DataEntry.MarkdownInput | Markdown editor with preview |
| 函数 | 模块 | 描述 |
|---|---|---|
| DataEntry.Form | 表单容器 + 布局辅助组件( |
| DataEntry.Input | 通用输入组件(通过 |
| DataEntry.CompactInput | 紧凑型输入组件 |
| DataEntry.Checkbox | 带标签的复选框 |
| DataEntry.Radio | 带标签的单选按钮 |
| DataEntry.Select | 下拉选择器 |
| DataEntry.Switch | 切换开关 |
| DataEntry.Slider | 范围滑块 |
| DataEntry.Textarea | 多行文本输入框 |
| DataEntry.Rating | 星级评分组件 |
| DataEntry.SegmentControl | 分段控制器 |
| DataEntry.MultiSelect | 带标签的多选组件 |
| DataEntry.Autocomplete | 自动补全输入框 |
| DataEntry.OtpInput | OTP验证码输入框 |
| DataEntry.PinInput | PIN码输入框 |
| DataEntry.FileUpload | 文件上传区域 |
| DataEntry.TimeInput | 时间选择器 |
| DataEntry.Cascader | 级联选择器 |
| DataEntry.TreeSelect | 树形结构选择器 |
| DataEntry.MarkdownInput | 带预览的Markdown编辑器 |
Feedback
反馈组件
| Function | Module | Description |
|---|---|---|
| Feedback.Dialog | Modal dialog with trigger/title/body/footer slots |
| Feedback.Loading | Loading indicators |
| Feedback.Toast | Toast notifications |
| Feedback.Snackbar | Snackbar messages |
| 函数 | 模块 | 描述 |
|---|---|---|
| Feedback.Dialog | 带触发器/标题/主体/页脚插槽的模态对话框 |
| Feedback.Loading | 加载指示器 |
| Feedback.Toast | 通知提示框 |
| Feedback.Snackbar | 底部消息条 |
Navigation
导航组件
| Function | Module | Description |
|---|---|---|
| Navigation.Actionbar | Action toolbar with left/right slots |
| Navigation.Appbar | Top navigation bar |
| Navigation.BottomNav | Mobile bottom navigation |
| Navigation.Breadcrumb | Breadcrumb trail |
| Navigation.LeftMenu | Sidebar menu |
| Navigation.Navbar | Horizontal navbar (start/center/end) |
| Navigation.NestedMenu | Nested collapsible menu |
| Navigation.PageFooter | Page footer with sections |
| Navigation.PageHeader | Page header with scroll-aware nav (needs hook) |
| Navigation.Stepper | CSS-only stepper |
| Navigation.Steps | Stepper via custom element |
| Navigation.Tab | Tabbed content |
| 函数 | 模块 | 描述 |
|---|---|---|
| Navigation.Actionbar | 带左侧/右侧插槽的操作工具栏 |
| Navigation.Appbar | 顶部导航栏 |
| Navigation.BottomNav | 移动端底部导航 |
| Navigation.Breadcrumb | 面包屑导航 |
| Navigation.LeftMenu | 侧边栏菜单 |
| Navigation.Navbar | 水平导航栏(左侧/中间/右侧) |
| Navigation.NestedMenu | 嵌套可折叠菜单 |
| Navigation.PageFooter | 带分区的页面页脚 |
| Navigation.PageHeader | 支持滚动感知的页面头部(需要钩子) |
| Navigation.Stepper | 纯CSS步骤指示器 |
| Navigation.Steps | 基于自定义元素的步骤指示器 |
| Navigation.Tab | 标签页内容切换组件 |
Layout
布局组件
| Function | Module | Description |
|---|---|---|
| Layout.BottomSheet | Bottom sheet overlay |
| Layout.Divider | Horizontal/vertical divider |
| Layout.Drawer | Slide-out drawer panel |
| Layout.ThemeSwitcher | Theme toggle (needs hook) |
| 函数 | 模块 | 描述 |
|---|---|---|
| Layout.BottomSheet | 底部弹出层 |
| Layout.Divider | 水平/垂直分隔线 |
| Layout.Drawer | 滑出式抽屉面板 |
| Layout.ThemeSwitcher | 主题切换器(需要钩子) |
Icon
图标组件
| Function | Module | Description |
|---|---|---|
| Icon.Icons | Material Design Icons (7000+ icons) |
| Icon.Icons | Bootstrap Icons (2000+ icons) |
| 函数 | 模块 | 描述 |
|---|---|---|
| Icon.Icons | Material Design Icons(7000+图标) |
| Icon.Icons | Bootstrap Icons(2000+图标) |
CSS Art (decorative)
CSS艺术(装饰性)
All art components require (required string) and accept + global attrs.
Import via .
idclassrestuse PhoenixDuskmoon.ArtComponent| Function | Module | Description |
|---|---|---|
| ArtComponent.Atom | Animated atom |
| ArtComponent.CatStargazer | Cat stargazer scene |
| ArtComponent.CircularGallery | Circular gallery |
| ArtComponent.ColorSpin | Color spin effect |
| ArtComponent.Eclipse | Animated eclipse |
| ArtComponent.FlowerAnimation | Flower animation |
| ArtComponent.GeminiInput | Gemini-style input (size, placeholder) |
| ArtComponent.Moon | Moon scene |
| ArtComponent.Mountain | Mountain landscape |
| ArtComponent.PlasmaBall | Interactive plasma ball |
| ArtComponent.Snow | Falling snowflakes (unicode, fall) |
| ArtComponent.Sun | Sun scene |
| ArtComponent.SynthwaveStarfield | Synthwave starfield |
所有艺术组件都需要(必填字符串),并支持 + 全局属性。需通过导入。
idclassrestuse PhoenixDuskmoon.ArtComponent| 函数 | 模块 | 描述 |
|---|---|---|
| ArtComponent.Atom | 动画原子效果 |
| ArtComponent.CatStargazer | 猫咪观星场景 |
| ArtComponent.CircularGallery | 圆形画廊效果 |
| ArtComponent.ColorSpin | 颜色旋转效果 |
| ArtComponent.Eclipse | 动画日食效果 |
| ArtComponent.FlowerAnimation | 花朵动画效果 |
| ArtComponent.GeminiInput | Gemini风格输入框(支持尺寸、占位符) |
| ArtComponent.Moon | 月亮场景效果 |
| ArtComponent.Mountain | 山脉景观效果 |
| ArtComponent.PlasmaBall | 交互式等离子球效果 |
| ArtComponent.Snow | 雪花飘落效果(Unicode字符、下落动画) |
| ArtComponent.Sun | 太阳场景效果 |
| ArtComponent.SynthwaveStarfield | 合成波星空效果 |
Usage Examples
使用示例
heex
<%!-- Button with variant --%>
<.dm_btn variant="primary" size="md">Save</.dm_btn>
<.dm_btn variant="error" shape="circle" loading={@saving}>X</.dm_btn>
<%!-- Button with confirmation dialog --%>
<.dm_btn confirm="Delete this item?" phx-click="delete" phx-value-id={@item.id}>
Delete
</.dm_btn>
<%!-- Card with slots --%>
<.dm_card variant="bordered">
<:title>Dashboard</:title>
Content here
<:action><.dm_btn variant="primary">View</.dm_btn></:action>
</.dm_card>
<%!-- Icons --%>
<.dm_mdi name="home" class="w-6 h-6" />
<.dm_bsi name="house" class="w-5 h-5" />
<%!-- Form with inputs --%>
<.dm_form for={@form} phx-submit="save">
<.dm_input field={@form[:name]} label="Name" />
<.dm_select field={@form[:role]} label="Role" options={[{"admin", "Admin"}, {"user", "User"}]} />
<.dm_switch field={@form[:active]} label="Active" />
<:actions>
<.dm_btn variant="primary" type="submit">Save</.dm_btn>
</:actions>
</.dm_form>
<%!-- Navigation --%>
<.dm_appbar title="My App" title_to={~p"/"}>
<:menu to={~p"/dashboard"} active={@active == :dashboard}>Dashboard</:menu>
<:menu to={~p"/settings"}>Settings</:menu>
<:user_profile>
<.dm_avatar name={@current_user.name} size="sm" />
</:user_profile>
</.dm_appbar>
<%!-- Theme switcher (requires ThemeSwitcher hook) --%>
<.dm_theme_switcher id="theme-toggle" theme={@theme} />
<%!-- Tabs --%>
<.dm_tab id="my-tabs" active_tab_index={0}>
<:tab name="overview">Overview</:tab>
<:tab name="details">Details</:tab>
<:tab_content name="overview">Overview content</:tab_content>
<:tab_content name="details">Details content</:tab_content>
</.dm_tab>
<%!-- Modal --%>
<.dm_modal id="confirm-modal">
<:trigger><.dm_btn>Open</.dm_btn></:trigger>
<:title>Confirm</:title>
<:body>Are you sure?</:body>
<:footer><.dm_btn variant="primary" phx-click="confirm">Yes</.dm_btn></:footer>
</.dm_modal>
<%!-- Art components --%>
<.dm_art_snow id="snow-1" />
<.dm_art_eclipse id="eclipse-1" />
<.dm_art_gemini_input id="ai-input" size="lg" placeholder="Ask anything..." />heex
<%!-- 带变体的按钮 --%>
<.dm_btn variant="primary" size="md">保存</.dm_btn>
<.dm_btn variant="error" shape="circle" loading={@saving}>X</.dm_btn>
<%!-- 带确认对话框的按钮 --%>
<.dm_btn confirm="确定要删除此项目吗?" phx-click="delete" phx-value-id={@item.id}>
删除
</.dm_btn>
<%!-- 带插槽的卡片 --%>
<.dm_card variant="bordered">
<:title>仪表盘</:title>
内容区域
<:action><.dm_btn variant="primary">查看</.dm_btn></:action>
</.dm_card>
<%!-- 图标 --%>
<.dm_mdi name="home" class="w-6 h-6" />
<.dm_bsi name="house" class="w-5 h-5" />
<%!-- 带输入组件的表单 --%>
<.dm_form for={@form} phx-submit="save">
<.dm_input field={@form[:name]} label="姓名" />
<.dm_select field={@form[:role]} label="角色" options={[{"admin", "管理员"}, {"user", "普通用户"}]} />
<.dm_switch field={@form[:active]} label="启用" />
<:actions>
<.dm_btn variant="primary" type="submit">保存</.dm_btn>
</:actions>
</.dm_form>
<%!-- 导航栏 --%>
<.dm_appbar title="我的应用" title_to={~p"/"}>
<:menu to={~p"/dashboard"} active={@active == :dashboard}>仪表盘</:menu>
<:menu to={~p"/settings"}>设置</:menu>
<:user_profile>
<.dm_avatar name={@current_user.name} size="sm" />
</:user_profile>
</.dm_appbar>
<%!-- 主题切换器(需要ThemeSwitcher钩子) --%>
<.dm_theme_switcher id="theme-toggle" theme={@theme} />
<%!-- 标签页 --%>
<.dm_tab id="my-tabs" active_tab_index={0}>
<:tab name="overview">概览</:tab>
<:tab name="details">详情</:tab>
<:tab_content name="overview">概览内容</:tab_content>
<:tab_content name="details">详情内容</:tab_content>
</.dm_tab>
<%!-- 模态框 --%>
<.dm_modal id="confirm-modal">
<:trigger><.dm_btn>打开</.dm_btn></:trigger>
<:title>确认操作</:title>
<:body>你确定要执行此操作吗?</:body>
<:footer><.dm_btn variant="primary" phx-click="confirm">确定</.dm_btn></:footer>
</.dm_modal>
<%!-- 艺术组件 --%>
<.dm_art_snow id="snow-1" />
<.dm_art_eclipse id="eclipse-1" />
<.dm_art_gemini_input id="ai-input" size="lg" placeholder="有什么想问的..." />Package Exports
包导出
| Import path | File |
|---|---|
| |
| |
| |
| |
| |
| 导入路径 | 文件 |
|---|---|
| |
| |
| |
| |
| |