Skip to content

Commit bb390d5

Browse files
committed
chore: update
1 parent 3818d0c commit bb390d5

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

packages/core/src/components/Input.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
import { defineComponent, h, ref, computed, watch } from '@vue/runtime-core'
2+
import type { PropType } from '@vue/runtime-core'
23
import chalk from 'chalk'
34
import { TuiText } from './Text'
45
import { onInputData } from '../composables/input'
56
import type { KeyDataEvent } from '../input/types'
67
import { useFocus } from '../focus/Focusable'
78

89
const SKIP_EVENT_KEY = ['ArrowUp', 'ArrowDown', 'Ctrl', 'Tab', 'Shift']
10+
const PWD_FIGURE = '*'
911

1012
export const TuiInput = defineComponent({
1113
props: {
1214
placeholder: {
1315
type: String,
14-
required: false,
1516
default: '',
1617
},
1718
modelValue: {
1819
type: String,
1920
required: true,
2021
},
22+
type: {
23+
type: String as PropType<'text' | 'password'>,
24+
default: 'text',
25+
},
2126
focus: {
2227
type: Boolean,
2328
required: true,
@@ -36,19 +41,29 @@ export const TuiInput = defineComponent({
3641
props.modelValue &&
3742
props.modelValue.length <= cursorOffset.value
3843
) {
39-
return props.modelValue + chalk.inverse(' ')
44+
return (
45+
(props.type === 'text'
46+
? props.modelValue
47+
: PWD_FIGURE.repeat(props.modelValue.length)) +
48+
chalk.inverse(' ')
49+
)
4050
}
4151

4252
const l = props.modelValue.slice(0, cursorOffset.value)
4353
const m = chalk.inverse(props.modelValue[cursorOffset.value])
4454
const r = props.modelValue.slice(cursorOffset.value + 1)
4555

46-
return l + m + r
56+
return props.type === 'text'
57+
? l + m + r
58+
: PWD_FIGURE.repeat(l.length) +
59+
chalk.inverse(PWD_FIGURE) +
60+
PWD_FIGURE.repeat(r.length)
4761
} else {
4862
return props.placeholder ? '' : chalk.inverse(' ')
4963
}
5064
} else {
51-
return props.modelValue
65+
const value = props.modelValue
66+
return props.type === 'text' ? value : PWD_FIGURE.repeat(value.length)
5267
}
5368
})
5469

packages/playground/src/InputDemo.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ watch(value, (v: string) => {
1414

1515
<template borderStyle="round">
1616
<Input v-model="value" :focus="isFocus" />
17-
<Input v-model="value1" :focus="isFocus1" />
17+
<Input v-model="value1" :focus="isFocus1" type="password" />
1818
</template>

0 commit comments

Comments
 (0)