diff --git a/package-lock.json b/package-lock.json index b1b990c..6d3f263 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13285,9 +13285,9 @@ } }, "node_modules/vite": { - "version": "4.5.2", - "resolved": "https://registry.npmjs.org/vite/-/vite-4.5.2.tgz", - "integrity": "sha512-tBCZBNSBbHQkaGyhGCDUGqeo2ph8Fstyp6FMSvTtsXeZSPpSMGlviAOav2hxVTqFcx8Hj/twtWKsMJXNY0xI8w==", + "version": "4.5.3", + "resolved": "https://registry.npmjs.org/vite/-/vite-4.5.3.tgz", + "integrity": "sha512-kQL23kMeX92v3ph7IauVkXkikdDRsYMGTVl5KY2E9OY4ONLvkHf04MDTbnfo6NKxZiDLWzVpP5oTa8hQD8U3dg==", "dev": true, "dependencies": { "esbuild": "^0.18.10", @@ -23535,9 +23535,9 @@ "dev": true }, "vite": { - "version": "4.5.2", - "resolved": "https://registry.npmjs.org/vite/-/vite-4.5.2.tgz", - "integrity": "sha512-tBCZBNSBbHQkaGyhGCDUGqeo2ph8Fstyp6FMSvTtsXeZSPpSMGlviAOav2hxVTqFcx8Hj/twtWKsMJXNY0xI8w==", + "version": "4.5.3", + "resolved": "https://registry.npmjs.org/vite/-/vite-4.5.3.tgz", + "integrity": "sha512-kQL23kMeX92v3ph7IauVkXkikdDRsYMGTVl5KY2E9OY4ONLvkHf04MDTbnfo6NKxZiDLWzVpP5oTa8hQD8U3dg==", "dev": true, "requires": { "esbuild": "^0.18.10", diff --git a/src/_common b/src/_common index 3c5e05b..19099ac 160000 --- a/src/_common +++ b/src/_common @@ -1 +1 @@ -Subproject commit 3c5e05bc628c06ebdac96e99d67119017920f08f +Subproject commit 19099ac97d350f5e37f9036d9c8bb4ad41f3057f diff --git a/src/input/_example/clearable.tsx b/src/input/_example/clearable.tsx new file mode 100644 index 0000000..5f00f25 --- /dev/null +++ b/src/input/_example/clearable.tsx @@ -0,0 +1,17 @@ +import 'tdesign-web-components/input'; +import 'tdesign-web-components/space'; +import 'tdesign-icons-web-components/esm/components/lock-on'; + +import { Component } from 'omi'; + +export default class InputBase extends Component { + value1 = 'Welcome to TDesign'; + + render() { + return ( + + + + ); + } +} diff --git a/src/input/_example/password.tsx b/src/input/_example/password.tsx new file mode 100644 index 0000000..50b2d14 --- /dev/null +++ b/src/input/_example/password.tsx @@ -0,0 +1,20 @@ +import 'tdesign-web-components/input'; +import 'tdesign-web-components/space'; +import 'tdesign-icons-web-components/esm/components/lock-on'; + +import { Component } from 'omi'; + +export default class InputBase extends Component { + value1 = ''; + + value2 = 'Welcome to TDesign'; + + render() { + return ( + + } /> + } /> + + ); + } +} diff --git a/src/input/input.tsx b/src/input/input.tsx index 516de72..236e833 100644 --- a/src/input/input.tsx +++ b/src/input/input.tsx @@ -1,8 +1,11 @@ import 'tdesign-icons-web-components/esm/components/close-circle-filled'; +import 'tdesign-icons-web-components/esm/components/browse'; +import 'tdesign-icons-web-components/esm/components/browse-off'; -import { Component, createRef, OmiProps, tag } from 'omi'; +import { cloneElement, Component, createRef, OmiProps, tag, VNode } from 'omi'; import classname, { getClassPrefix } from '../_util/classname'; +import { convertToLightDomNode } from '../_util/lightDom'; import parseTNode from '../_util/parseTNode'; import { StyledProps, TElement, TNode } from '../common'; import { InputValue, TdInputProps } from './type'; @@ -90,7 +93,7 @@ export default class Input extends Component { status: TdInputProps['status'] = 'default'; - renderType = ''; + renderType = 'text'; isFocused = false; @@ -100,6 +103,14 @@ export default class Input extends Component { eventProps; + private handlePasswordVisible = (e: MouseEvent) => { + e.stopImmediatePropagation(); + if (this.props.disabled) return; + const toggleType = this.renderType === 'password' ? 'text' : 'password'; + this.renderType = toggleType; + this.update(); + }; + private handleChange = (e) => { e.stopImmediatePropagation(); const { maxlength, maxcharacter, allowInputOverMax, status, onValidate, onChange } = this.props; @@ -158,13 +169,15 @@ export default class Input extends Component { }; private handleMouseEnter = (e: MouseEvent) => { + e.stopImmediatePropagation(); const { onMouseenter } = this.props; this.isHover = true; - this.update(); onMouseenter?.({ e }); + this.update(); }; private handleMouseLeave = (e: MouseEvent) => { + e.stopImmediatePropagation(); const { onMouseleave } = this.props; this.isHover = false; this.update(); @@ -310,20 +323,62 @@ export default class Input extends Component { }); const isShowClearIcon = ((clearable && this.value && !disabled) || showClearIconOnEmpty) && this.isHover; - const prefixIconContent = renderIcon('t', 'prefix', parseTNode(prefixIcon)); - let suffixIconNew = suffixIcon; + const prefixIconContent = prefixIcon + ? renderIcon( + 't', + 'prefix', + cloneElement(parseTNode(convertToLightDomNode(prefixIcon)) as VNode, { + className: `${classPrefix}-input__prefix`, + style: { marginRight: '0px' }, + }), + ) + : renderIcon('t', 'prefix', parseTNode(convertToLightDomNode(prefixIcon))); + let suffixIconNew = suffixIcon; + const cleanMargin = { marginLeft: '0px' }; if (isShowClearIcon) { suffixIconNew = ( ) as any; } + if (props.type === 'password' && typeof suffixIcon === 'undefined') { + if (this.renderType === 'password') { + suffixIconNew = ( + + ) as any; + } else if (this.renderType === 'text') { + suffixIconNew = ( + + ) as any; + } + } - const suffixIconContent = renderIcon('t', 'suffix', parseTNode(suffixIconNew)); + const suffixIconContent = renderIcon('t', 'suffix', parseTNode(convertToLightDomNode(suffixIconNew))); const labelContent = isFunction(label) ? label() : label; const suffixContent = isFunction(suffix) ? suffix() : suffix; diff --git a/src/skeleton/skeleton.tsx b/src/skeleton/skeleton.tsx index 69f13a5..820870a 100644 --- a/src/skeleton/skeleton.tsx +++ b/src/skeleton/skeleton.tsx @@ -1,11 +1,11 @@ import isNumber from 'lodash/isNumber'; -import { classNames, Component, createRef,tag } from 'omi'; +import { classNames, Component, createRef, tag } from 'omi'; import { pxCompat } from '../_common/js/utils/helper'; import { getClassPrefix } from '../_util/classname'; import parseTNode from '../_util/parseTNode'; import { StyledProps, Styles, TNode } from '../common'; -import { SkeletonRowCol, SkeletonRowColObj,TdSkeletonProps } from './type'; +import { SkeletonRowCol, SkeletonRowColObj, TdSkeletonProps } from './type'; export type SkeletonProps = TdSkeletonProps & StyledProps & { children: TNode }; type SkeletonInjection = (props: SkeletonProps) => SkeletonProps;