0.1.1 • Published 2 years ago

hyachin-ui v0.1.1

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

Hyachin-UI

Teach you how to code by youself(notes updating synchronously...)

https://www.yuque.com/docs/share/4cdc9c90-aac4-48fd-b5f2-28267609aa06?# 《hyachin-ui 搭建指南》

Project setup

npm install

Compiles and hot-reloads for development

npm run serve

Use Hyachin-UI

安装组件库

yarn add hyachin-ui

全局导入

import HyachinUI from "hyachin-ui";
import "hyahcin/dist/hyachin-ui.css";
Vue.use(HyachinUI);

Button

Basic usage

<div class="row">
  <!-- type使用 -->
  <hy-button @click="fn">按钮</hy-button>
  <hy-button type="primary">按钮</hy-button>
  <hy-button type="success">按钮</hy-button>
  <hy-button type="info">按钮</hy-button>
  <hy-button type="warning">按钮</hy-button>
  <hy-button type="danger">按钮</hy-button>
</div>
<!-- plain使用 -->
<div class="row">
  <hy-button>按钮</hy-button>
  <hy-button plain type="primary">按钮</hy-button>
</div>
<!-- round使用 -->
<div class="row">
  <hy-button round>按钮</hy-button>
</div>
<!-- icon+circle使用 -->
<div class="row">
  <hy-button round icon="hy-icon-close" circle type="primary"></hy-button>
</div>
<!-- disabled使用 -->
<div class="row">
  <hy-button
    disabled
    round
    icon="hy-icon-close"
    circle
    type="primary"
  ></hy-button>
</div>

Attributes

参数说明类型可选值默认值
type类型stringprimary/success/warning/danger/info
plain是否朴素按钮booleanfalse
round是否圆角按钮booleanfalse
circle是否圆形按钮booleanfalse
disabled是否禁用状态booleanfalse
icon图标类名string

Events

事件描述
click点击事件

Dialog

basic use

<template>
  <div id="app">
    <hy-button type="primary" @click="visible = true">显示</hy-button>
    <hy-dialog :visible.sync="visible" title="文字标题">
      <!-- 以下为slot,和title属性二选一 -->
      <!-- <template v-slot:header>
        <h3>自定义标题</h3>
      </template> -->
      内容
      <template v-slot:footer>
        <hy-button @click="visible = false">取消</hy-button>
        <hy-button type="primary" @click="visible = false">确定</hy-button>
      </template>
    </hy-dialog>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        visible: false,
      };
    },
  };
</script>

Attributes

参数说明类型可选值默认值
visible是否显示 Dialog,支持 .sync 修饰符booleanfalse
titleDialog 的标题,也可通过具名 slot (见下表)传入string
widthDialog 的宽度string50%
topDialog CSS 中的 margin-top 值string15vh

Slot

name说明
Dialog 的内容
titleDialog 标题区的内容
footerDialog 按钮操作区的内容

Input

basic use

<template>
  <div id="app">
    <hy-input
      placeholder="请输入用户名"
      type="password"
      name="username"
      disabled
      clearable
      show-password
    ></hy-input>
    <hy-input
      v-model="username"
      type="password"
      showPassword
      @blur="handleBlur"
      @change="handleChange"
      @focus="handleFocus"
    ></hy-input>
  </div>
</template>

<script>
  export default {
    name: "App",
    data() {
      return {
        username: "zs",
      };
    },
    methods: {
      handleBlur() {
        console.log("do something when blur");
      },
      handleChange() {
        console.log("do something when change");
      },
      handleFocus() {
        console.log("do something when focus");
      },
    },
  };
</script>
<style lang="scss">
  #app {
    .hy-input {
      width: 200px;
    }
  }
</style>

Attributes

参数说明类型可选值默认值
placeholder输入框占位文本string
type类型stringtext 和其他原生 input 的 type 值text
disabled禁用booleanfalse
clearable是否可清空booleanfalse
show-password是否显示切换密码图标booleanfalse
name原生属性string

Events

事件名称说明回调参数
blur在 Input 失去焦点时触发(event: Event)
focus在 Input 获得焦点时触发(event: Event)
change仅在输入框失去焦点或用户按下回车时触发(event: Event)

Switch

basic use

<template>
  <div id="app">
    <hy-switch v-model="active" :name="username"></hy-switch>
    <hy-switch
      v-model="active"
      inactiveColor="green"
      activeColor="red"
      @change="handleChange"
    ></hy-switch>
  </div>
</template>

<script>
  export default {
    name: "App",
    data() {
      return {
        active: false,
        username: "zs",
      };
    },
    methods: {
      handleChange(val) {
        console.log("do something when change", val);
      },
    },
  };
</script>

Attributes

参数说明类型可选值默认值
v-model绑定值string
nameswitch 对应的 name 属性string
activeColorswitch 打开时的背景色string#409eff
inactiveColorswitch 关闭时的背景色string#dcdfe6

Events

事件名称说明回调参数
changeswitch 状态发生变化时的回调函数新状态的值

Radio

basic use

<template>
  <div id="app">
    <hy-radio label="1" v-model="gender">男</hy-radio>
    <hy-radio label="0" v-model="gender">女</hy-radio>
  </div>
</template>

<script>
  export default {
    name: "App",
    data() {
      return {
        gender: "1",
      };
    },
    methods: {},
  };
</script>

Attributes

参数说明类型可选值默认值
v-model双向绑定string / number / boolean
labelRadio 的 valuestring / number / boolean
name原生 name 属性string

RadioGroup

在 RadioGroup 上写 v-model,可将绑定的值作用于其包裹的所有 radio

basic use

<hy-radio-group v-model="gender">
  <hy-radio label="1">男</hy-radio>
  <hy-radio label="0">女</hy-radio>
</hy-radio-group>

Attributes

参数说明类型可选值默认值
v-model双向绑定string / number / boolean

Checkbox

basic use

<template>
  <div id="app">
    <hy-checkbox v-model="active">是否选中</hy-checkbox>
  </div>
</template>

<script>
  export default {
    name: "App",
    data() {
      return {
        active: true,
      };
    },
  };
</script>

Attributes

参数说明类型可选值默认值
v-model双向绑定booleanfalse
labelCheckbox 的 valuestring
name原生 name 属性string

CheckboxGroup

basic use

<template>
  <div id="app">
    <hy-checkbox-group v-model="fruits">
      <hy-checkbox label="apple"></hy-checkbox>
      <hy-checkbox label="banana"></hy-checkbox>
      <hy-checkbox label="peach"></hy-checkbox>
    </hy-checkbox-group>
  </div>
</template>

<script>
  export default {
    name: "App",
    data() {
      return {
        fruits: ["apple"],
      };
    },
  };
</script>

Attributes

参数说明类型可选值默认值
v-model双向绑定array[]

Form&FormItem

basic use

<template>
  <div id="app">
    <hy-form :model="model" label-width="100px">
      <hy-form-item label="用户名">
        <hy-input
          placeholder="请输入用户名"
          v-model="model.username"
        ></hy-input>
      </hy-form-item>
      <hy-form-item label="选择">
        <hy-switch v-model="model.active"></hy-switch>
      </hy-form-item>
    </hy-form>
  </div>
</template>

<script>
  export default {
    name: "App",
    data() {
      return {
        model: {
          username: "zs",
          active: true,
        },
      };
    },
  };
</script>

Form Attributes

参数说明类型可选值默认值
model表单数据对象object
label-width表单域标签的宽度string

FormItem Attributes

参数说明类型可选值默认值
label标签文本string