11import { defineComponent , h , ref , computed , watch } from '@vue/runtime-core'
2+ import type { PropType } from '@vue/runtime-core'
23import chalk from 'chalk'
34import { TuiText } from './Text'
45import { onInputData } from '../composables/input'
56import type { KeyDataEvent } from '../input/types'
67import { useFocus } from '../focus/Focusable'
78
89const SKIP_EVENT_KEY = [ 'ArrowUp' , 'ArrowDown' , 'Ctrl' , 'Tab' , 'Shift' ]
10+ const PWD_FIGURE = '*'
911
1012export 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
0 commit comments