跳转到内容

XiHan UI 基础组件

XiHan UI 提供了一系列基础组件,这些组件是构建用户界面的基本元素。本文将详细介绍这些基础组件的用法和配置选项。

Button 按钮

按钮用于触发操作,是用户界面中最常用的交互元素之一。

基础用法

vue
<template>
  <xh-button>默认按钮</xh-button>
  <xh-button type="primary">主要按钮</xh-button>
  <xh-button type="success">成功按钮</xh-button>
  <xh-button type="warning">警告按钮</xh-button>
  <xh-button type="danger">危险按钮</xh-button>
  <xh-button type="info">信息按钮</xh-button>
</template>

按钮尺寸

提供大、中、小三种尺寸的按钮。

vue
<template>
  <xh-button size="large">大型按钮</xh-button>
  <xh-button>默认按钮</xh-button>
  <xh-button size="small">小型按钮</xh-button>
</template>

按钮状态

按钮可以处于禁用状态或加载状态。

vue
<template>
  <xh-button disabled>禁用按钮</xh-button>
  <xh-button loading>加载中</xh-button>
  <xh-button loading type="primary">加载中</xh-button>
</template>

图标按钮

按钮可以包含图标,提高辨识度。

vue
<template>
  <xh-button icon="search">搜索</xh-button>
  <xh-button icon="edit" type="primary">编辑</xh-button>
  <xh-button icon="delete" type="danger"></xh-button>
</template>

按钮组

将多个按钮组合在一起。

vue
<template>
  <xh-button-group>
    <xh-button icon="left" type="primary">上一页</xh-button>
    <xh-button icon="right" type="primary">下一页</xh-button>
  </xh-button-group>
</template>

属性

属性说明类型可选值默认值
type按钮类型stringprimary / success / warning / danger / infodefault
size按钮尺寸stringlarge / smalldefault
disabled是否禁用booleantrue / falsefalse
loading是否加载中booleantrue / falsefalse
icon图标名称string--
round是否圆角按钮booleantrue / falsefalse
circle是否圆形按钮booleantrue / falsefalse
plain是否朴素按钮booleantrue / falsefalse
link是否链接按钮booleantrue / falsefalse
text是否文本按钮booleantrue / falsefalse
autofocus是否自动获取焦点booleantrue / falsefalse

事件

事件名说明回调参数
click点击按钮时触发event

Typography 排版

排版组件提供了文本的基本格式化功能。

基础用法

vue
<template>
  <xh-typography>
    <xh-typography-title>标题</xh-typography-title>
    <xh-typography-text>这是一段普通文本</xh-typography-text>
    <xh-typography-paragraph>
      这是一个段落,可以包含多行文本。这是一个段落,可以包含多行文本。
      这是一个段落,可以包含多行文本。这是一个段落,可以包含多行文本。
    </xh-typography-paragraph>
  </xh-typography>
</template>

文本类型

vue
<template>
  <xh-typography-text>默认文本</xh-typography-text>
  <xh-typography-text type="primary">主要文本</xh-typography-text>
  <xh-typography-text type="success">成功文本</xh-typography-text>
  <xh-typography-text type="warning">警告文本</xh-typography-text>
  <xh-typography-text type="danger">危险文本</xh-typography-text>
  <xh-typography-text disabled>禁用文本</xh-typography-text>
  <xh-typography-text mark>标记文本</xh-typography-text>
  <xh-typography-text code>代码文本</xh-typography-text>
  <xh-typography-text underline>下划线文本</xh-typography-text>
  <xh-typography-text delete>删除线文本</xh-typography-text>
  <xh-typography-text strong>加粗文本</xh-typography-text>
  <xh-typography-text italic>斜体文本</xh-typography-text>
</template>

标题级别

vue
<template>
  <xh-typography-title :level="1">h1. XiHan UI</xh-typography-title>
  <xh-typography-title :level="2">h2. XiHan UI</xh-typography-title>
  <xh-typography-title :level="3">h3. XiHan UI</xh-typography-title>
  <xh-typography-title :level="4">h4. XiHan UI</xh-typography-title>
  <xh-typography-title :level="5">h5. XiHan UI</xh-typography-title>
</template>

可交互文本

vue
<template>
  <xh-typography-paragraph copyable>这是可复制的文本</xh-typography-paragraph>
  <xh-typography-paragraph :ellipsis="{ rows: 2, expandable: true }">
    这是一段很长的文本,当超过指定行数时会自动省略,并显示展开按钮。
    这是一段很长的文本,当超过指定行数时会自动省略,并显示展开按钮。
    这是一段很长的文本,当超过指定行数时会自动省略,并显示展开按钮。
  </xh-typography-paragraph>
  <xh-typography-paragraph editable>这是可编辑的文本</xh-typography-paragraph>
</template>

属性

Typography

属性说明类型可选值默认值
component要渲染的 HTML 元素string-'article'

Typography.Title

属性说明类型可选值默认值
level标题级别number1-51
type文本类型stringprimary / success / warning / danger-
copyable是否可复制booleantrue / falsefalse
editable是否可编辑booleantrue / falsefalse

Typography.Text

属性说明类型可选值默认值
type文本类型stringprimary / success / warning / danger-
disabled禁用文本booleantrue / falsefalse
mark添加标记样式booleantrue / falsefalse
code添加代码样式booleantrue / falsefalse
underline添加下划线booleantrue / falsefalse
delete添加删除线booleantrue / falsefalse
strong是否加粗booleantrue / falsefalse
italic是否斜体booleantrue / falsefalse
copyable是否可复制booleantrue / falsefalse

Typography.Paragraph

属性说明类型可选值默认值
type文本类型stringprimary / success / warning / danger-
copyable是否可复制booleantrue / falsefalse
editable是否可编辑booleantrue / falsefalse
ellipsis自动溢出省略boolean / objecttrue /false

Icon 图标

XiHan UI 提供了一套丰富的图标集合。

基础用法

vue
<template>
  <xh-icon name="home" />
  <xh-icon name="user" />
  <xh-icon name="settings" />
  <xh-icon name="search" />
</template>

图标尺寸

vue
<template>
  <xh-icon name="home" size="small" />
  <xh-icon name="home" />
  <xh-icon name="home" size="large" />
  <xh-icon name="home" :size="32" />
</template>

图标颜色

vue
<template>
  <xh-icon name="home" color="primary" />
  <xh-icon name="user" color="success" />
  <xh-icon name="settings" color="warning" />
  <xh-icon name="search" color="danger" />
  <xh-icon name="message" color="#8c0776" />
</template>

自定义图标

vue
<template>
  <xh-icon>
    <svg viewBox="0 0 24 24">
      <!-- SVG 路径 -->
      <path d="M12 2L2 12h3v8h14v-8h3L12 2z" />
    </svg>
  </xh-icon>
</template>

属性

属性说明类型可选值默认值
name图标名称string--
size图标大小string / numbersmall / large / 具体数值-
color图标颜色stringprimary / success / warning / danger / info / 自定义颜色-
spin是否旋转booleantrue / falsefalse

Grid 栅格

栅格系统是用于页面布局的基础组件,XiHan UI 的栅格系统基于 24 列布局。

基础用法

vue
<template>
  <xh-row>
    <xh-col :span="24">col-24</xh-col>
  </xh-row>
  <xh-row>
    <xh-col :span="12">col-12</xh-col>
    <xh-col :span="12">col-12</xh-col>
  </xh-row>
  <xh-row>
    <xh-col :span="8">col-8</xh-col>
    <xh-col :span="8">col-8</xh-col>
    <xh-col :span="8">col-8</xh-col>
  </xh-row>
  <xh-row>
    <xh-col :span="6">col-6</xh-col>
    <xh-col :span="6">col-6</xh-col>
    <xh-col :span="6">col-6</xh-col>
    <xh-col :span="6">col-6</xh-col>
  </xh-row>
</template>

列间距

vue
<template>
  <xh-row :gutter="16">
    <xh-col :span="12">col-12</xh-col>
    <xh-col :span="12">col-12</xh-col>
  </xh-row>
</template>

列偏移

vue
<template>
  <xh-row>
    <xh-col :span="8">col-8</xh-col>
    <xh-col :span="8" :offset="8">col-8 offset-8</xh-col>
  </xh-row>
</template>

响应式布局

vue
<template>
  <xh-row>
    <xh-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4">响应式列</xh-col>
    <xh-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4">响应式列</xh-col>
    <xh-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4">响应式列</xh-col>
    <xh-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4">响应式列</xh-col>
  </xh-row>
</template>

Flex 布局

vue
<template>
  <xh-row type="flex" justify="center" align="middle">
    <xh-col :span="6">col-6</xh-col>
    <xh-col :span="6">col-6</xh-col>
    <xh-col :span="6">col-6</xh-col>
  </xh-row>
</template>

属性

Row

属性说明类型可选值默认值
gutter列间距number-0
type布局模式stringflex-
justifyflex 布局下的水平排列方式stringstart / end / center / space-around / space-betweenstart
alignflex 布局下的垂直对齐方式stringtop / middle / bottomtop
wrap是否自动换行booleantrue / falsetrue

Col

属性说明类型可选值默认值
span栅格占据的列数number1-24-
offset栅格左侧的间隔列数number0-240
push栅格向右移动格数number0-240
pull栅格向左移动格数number0-240
xs<768px 响应式栅格number / object--
sm≥768px 响应式栅格number / object--
md≥992px 响应式栅格number / object--
lg≥1200px 响应式栅格number / object--
xl≥1920px 响应式栅格number / object--

Layout 布局

布局组件用于组织页面的整体结构。

基础用法

vue
<template>
  <xh-layout>
    <xh-header>Header</xh-header>
    <xh-content>Content</xh-content>
    <xh-footer>Footer</xh-footer>
  </xh-layout>
</template>

常见页面布局

vue
<template>
  <!-- 顶部-内容-底部 -->
  <xh-layout>
    <xh-header>Header</xh-header>
    <xh-content>Content</xh-content>
    <xh-footer>Footer</xh-footer>
  </xh-layout>

  <!-- 顶部-侧边栏-内容 -->
  <xh-layout>
    <xh-header>Header</xh-header>
    <xh-layout>
      <xh-sider>Sider</xh-sider>
      <xh-content>Content</xh-content>
    </xh-layout>
    <xh-footer>Footer</xh-footer>
  </xh-layout>

  <!-- 侧边栏-内容 -->
  <xh-layout>
    <xh-sider>Sider</xh-sider>
    <xh-layout>
      <xh-header>Header</xh-header>
      <xh-content>Content</xh-content>
      <xh-footer>Footer</xh-footer>
    </xh-layout>
  </xh-layout>
</template>

可收起的侧边栏

vue
<template>
  <xh-layout>
    <xh-sider collapsible v-model:collapsed="collapsed"> Sider </xh-sider>
    <xh-layout>
      <xh-header>Header</xh-header>
      <xh-content>Content</xh-content>
      <xh-footer>Footer</xh-footer>
    </xh-layout>
  </xh-layout>
</template>

<script setup>
import { ref } from "vue";

const collapsed = ref(false);
</script>

属性

Layout

属性说明类型可选值默认值
direction子元素的排列方向stringhorizontal / vertical自动判断

Layout.Sider

属性说明类型可选值默认值
collapsed当前收起状态boolean-false
collapsible是否可收起boolean-false
width宽度number / string-200
collapsedWidth收缩时的宽度number-80
breakpoint触发响应式布局的断点stringxs / sm / md / lg / xl-

事件

Layout.Sider

事件名说明回调参数
collapse展开-收起时的回调函数collapsed: boolean
breakpoint触发响应式布局断点时的回调broken: boolean

Space 间距

Space 组件用于设置组件之间的间距。

基础用法

vue
<template>
  <xh-space>
    <xh-button>按钮1</xh-button>
    <xh-button>按钮2</xh-button>
    <xh-button>按钮3</xh-button>
  </xh-space>
</template>

垂直间距

vue
<template>
  <xh-space direction="vertical">
    <xh-button>按钮1</xh-button>
    <xh-button>按钮2</xh-button>
    <xh-button>按钮3</xh-button>
  </xh-space>
</template>

间距大小

vue
<template>
  <xh-space size="small">
    <xh-button>小间距</xh-button>
    <xh-button>小间距</xh-button>
  </xh-space>

  <xh-space>
    <xh-button>默认间距</xh-button>
    <xh-button>默认间距</xh-button>
  </xh-space>

  <xh-space size="large">
    <xh-button>大间距</xh-button>
    <xh-button>大间距</xh-button>
  </xh-space>

  <xh-space :size="20">
    <xh-button>自定义间距</xh-button>
    <xh-button>自定义间距</xh-button>
  </xh-space>
</template>

对齐方式

vue
<template>
  <xh-space align="center">
    <xh-button>按钮</xh-button>
    <xh-card style="height: 100px">卡片</xh-card>
  </xh-space>

  <xh-space align="start">
    <xh-button>按钮</xh-button>
    <xh-card style="height: 100px">卡片</xh-card>
  </xh-space>

  <xh-space align="end">
    <xh-button>按钮</xh-button>
    <xh-card style="height: 100px">卡片</xh-card>
  </xh-space>
</template>

属性

属性说明类型可选值默认值
direction间距方向stringvertical / horizontalhorizontal
size间距大小string / number / [number, number]small / middle / large / 自定义值middle
align对齐方式stringstart / end / center / baselinecenter
wrap是否自动换行booleantrue / falsefalse
fill是否填充父容器booleantrue / falsefalse
fillRatio填充父容器时子元素的比例number-100

Divider 分割线

分割线用于分隔内容。

基础用法

vue
<template>
  <p>段落内容</p>
  <xh-divider></xh-divider>
  <p>段落内容</p>
</template>

垂直分割线

vue
<template>
  <span>文本</span>
  <xh-divider direction="vertical"></xh-divider>
  <span>文本</span>
  <xh-divider direction="vertical"></xh-divider>
  <span>文本</span>
</template>

带文本的分割线

vue
<template>
  <p>段落内容</p>
  <xh-divider orientation="left">左侧文本</xh-divider>
  <p>段落内容</p>

  <p>段落内容</p>
  <xh-divider orientation="right">右侧文本</xh-divider>
  <p>段落内容</p>
</template>

自定义样式

vue
<template>
  <p>段落内容</p>
  <xh-divider dashed></xh-divider>
  <p>段落内容</p>

  <p>段落内容</p>
  <xh-divider style="border-color: #f56c6c;"></xh-divider>
  <p>段落内容</p>
</template>

属性

属性说明类型可选值默认值
direction分割线方向stringhorizontal / verticalhorizontal
orientation分割线标题的位置stringleft / right / centercenter
dashed是否为虚线booleantrue / falsefalse
border-style分割线样式stringCSS 边框样式solid

下一步

Released under The MIT License.