Skip to content

Commit 1365433

Browse files
committed
feat: add Input component and update Button styles
1 parent 8f73247 commit 1365433

File tree

7 files changed

+119
-1
lines changed

7 files changed

+119
-1
lines changed

packages/ui/src/components/button/Button.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<button :class="classes" @click="$emit('click', $event)">
2+
<button class="ant-btn" :class="classes" @click="$emit('click', $event)">
33
<slot></slot>
44
</button>
55
</template>

packages/ui/src/components/button/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { App, Plugin } from 'vue'
22
import Button from './Button.vue'
3+
import './style/index.css'
4+
5+
// 导出组件
6+
export { default as Button } from './Button.vue'
7+
export * from './meta'
38

49
/* istanbul ignore next */
510
Button.install = function (app: App) {

packages/ui/src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export { default as Button } from './button'
2+
export { default as Input } from './input'
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<template>
2+
<input
3+
class="ant-input"
4+
:class="classes"
5+
:value="modelValue"
6+
@input="$emit('update:modelValue', ($event.target as HTMLInputElement).value)"
7+
@focus="$emit('focus', $event)"
8+
@blur="$emit('blur', $event)"
9+
/>
10+
</template>
11+
12+
<script setup lang="ts">
13+
import { computed } from 'vue'
14+
import { inputProps, inputEmits, InputSlots } from './meta'
15+
16+
const props = defineProps(inputProps)
17+
18+
defineEmits(inputEmits)
19+
defineSlots<InputSlots>()
20+
21+
const classes = computed(() => {
22+
return [
23+
'w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent',
24+
{
25+
'border-red-500': props.status === 'error',
26+
'border-yellow-500': props.status === 'warning',
27+
},
28+
]
29+
})
30+
</script>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { App, Plugin } from 'vue'
2+
import Input from './Input.vue'
3+
import './style/index.css'
4+
5+
// 导出组件
6+
export { default as Input } from './Input.vue'
7+
export * from './meta'
8+
9+
/* istanbul ignore next */
10+
Input.install = function (app: App) {
11+
app.component('AInput', Input)
12+
return app
13+
}
14+
15+
export default Input as typeof Input & Plugin
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { PropType, ExtractPublicPropTypes } from 'vue'
2+
3+
// Input Props
4+
export const inputProps = {
5+
/**
6+
* The input value
7+
*/
8+
modelValue: {
9+
type: String,
10+
default: '',
11+
},
12+
/**
13+
* The status of the input
14+
*/
15+
status: {
16+
type: String as PropType<'error' | 'warning'>,
17+
default: undefined,
18+
},
19+
/**
20+
* The placeholder text
21+
*/
22+
placeholder: {
23+
type: String,
24+
default: '',
25+
},
26+
/**
27+
* Whether the input is disabled
28+
*/
29+
disabled: {
30+
type: Boolean,
31+
default: false,
32+
},
33+
} as const
34+
35+
export type InputProps = ExtractPublicPropTypes<typeof inputProps>
36+
37+
// Input Emits
38+
export const inputEmits = {
39+
/**
40+
* Triggered when the input value changes
41+
*/
42+
'update:modelValue': (value: string) => typeof value === 'string',
43+
/**
44+
* Triggered when the input receives focus
45+
*/
46+
focus: (e: FocusEvent) => e instanceof FocusEvent,
47+
/**
48+
* Triggered when the input loses focus
49+
*/
50+
blur: (e: FocusEvent) => e instanceof FocusEvent,
51+
} as const
52+
53+
export type InputEmits = typeof inputEmits
54+
55+
// Input Slots
56+
export const inputSlots = {} as const
57+
58+
export type InputSlots = typeof inputSlots
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* Input component styles */
2+
.ant-input {
3+
transition: all 0.2s ease-in-out;
4+
}
5+
6+
.ant-input:disabled {
7+
opacity: 0.6;
8+
cursor: not-allowed;
9+
}

0 commit comments

Comments
 (0)