-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #794 from rainbowMorelhahahah/master
feat: input 和 input number 的实现
- Loading branch information
Showing
12 changed files
with
250 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { OmiProps, WeElement, define, h, tag } from "omi"; | ||
|
||
import '../../../../../src/input' | ||
import observable from "../../../../../src/utils/observable"; | ||
|
||
@tag('page-input') | ||
export default class extends WeElement { | ||
|
||
static css = ''; | ||
|
||
inputValue = '' | ||
|
||
render(props: {} | OmiProps<{}, any>, store: any) { | ||
|
||
return ( | ||
<div style="padding:24px"> | ||
<div style="display:flex;"> | ||
<div style="width:500px;margin:auto;text-align:center;"> | ||
<t-input | ||
status="error" | ||
tips="这是 tips 文本信息" | ||
align="center" | ||
value={this.inputValue} | ||
onChange={ | ||
(val: any) => { | ||
this.inputValue = val | ||
// this.update() | ||
} | ||
} | ||
/> | ||
</div> | ||
<div> | ||
{this.inputValue} | ||
</div> | ||
</div> | ||
</div> | ||
|
||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { h, OmiProps, tag, WeElement, render, classNames } from 'omi' | ||
import { InputProps } from './types'; | ||
import styles from './sytle' | ||
import { TdClassNamePefix } from '../../src/utils'; | ||
|
||
import '../input' | ||
|
||
const InputNumebrClassNamePefix = (name: string) => TdClassNamePefix('input') + name; | ||
|
||
@tag('t-input-number') | ||
export default class InputNumber extends WeElement<InputProps> { | ||
|
||
static css = styles; | ||
|
||
handleChange = (val: number) => { | ||
//@ts-ignore | ||
this.props?.onChangeValue?.(val) | ||
} | ||
|
||
render(props: InputProps, store: any) { | ||
|
||
const { value } = props; | ||
|
||
return ( | ||
<> | ||
<div class="t-slider__input-container"> | ||
<div class="t-input-number t-size-m t-is-controls-right t-input-number--column t-slider-input"> | ||
<button | ||
onClick={() => { | ||
this.handleChange(value - 1) | ||
}} | ||
type="button" class="t-input-number__decrease t-button t-button--theme-default t-button--variant-outline t-button--shape-square"> | ||
<svg fill="none" viewBox="0 0 24 24" width="1em" height="1em" class="t-icon t-icon-chevron-down t-size-m"> | ||
<path fill="currentColor" d="M17.5 8.09l-5.5 5.5-5.5-5.5L5.09 9.5 12 16.41l6.91-6.91-1.41-1.41z"></path> | ||
</svg> | ||
</button> | ||
|
||
<t-input autocomplete="off" value={value || 0} /> | ||
|
||
<button | ||
onClick={() => { | ||
this.handleChange(value + 1) | ||
}} | ||
type="button" class="t-input-number__increase t-button t-button--theme-default t-button--variant-outline t-button--shape-square"> | ||
<svg fill="none" viewBox="0 0 24 24" width="1em" height="1em" class="t-icon t-icon-chevron-up t-size-m"> | ||
<path fill="currentColor" d="M17.5 15.91l-5.5-5.5-5.5 5.5-1.41-1.41L12 7.59l6.91 6.91-1.41 1.41z"> | ||
</path> | ||
</svg> | ||
</button> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import inputSyle from '../../_common/style/web/components/input-number/_index.less' | ||
|
||
export default inputSyle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { HorizontalAlignEnum, SizeEnum, StatusEnum, TNode } from '@src/common' | ||
|
||
export type InputProps = { | ||
autoWidth: boolean; | ||
showClearIconOnEmpty: boolean; | ||
clearable: boolean; | ||
align: HorizontalAlignEnum; | ||
size: SizeEnum; | ||
status: StatusEnum; | ||
tips: TNode; | ||
onChangeValue: (value: any) => void; | ||
} & HTMLInputElement |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { h, OmiProps, tag, WeElement, render, classNames } from 'omi' | ||
import { InputProps } from './types'; | ||
import styles from './sytle' | ||
import { TdClassNamePefix } from '../../src/utils'; | ||
|
||
const InputClassNamePefix = (name: string) => TdClassNamePefix('input') + name; | ||
|
||
@tag('t-input') | ||
export default class Input extends WeElement<InputProps> { | ||
|
||
static css = styles; | ||
|
||
|
||
|
||
render(props: InputProps, store: any) { | ||
|
||
const { autofocus, disabled, readOnly, showClearIconOnEmpty, align, size, status, type, autoWidth } = props; | ||
const { placeholder, value, tips, autocomplete } = props; | ||
const { onChange } = props; | ||
|
||
const curStatus = status || 'default' | ||
|
||
return ( | ||
<> | ||
<div> | ||
<div class={classNames( | ||
InputClassNamePefix('__wrap'), | ||
{ | ||
[InputClassNamePefix('--auto-width')]: autoWidth | ||
} | ||
)}> | ||
<div class={ | ||
classNames( | ||
't-input', | ||
TdClassNamePefix(`is-${curStatus}`), | ||
TdClassNamePefix(`align-${align}`), | ||
{ | ||
[TdClassNamePefix(`is-readonly`)]: readOnly, | ||
[TdClassNamePefix(`is-disabled`)]: disabled, | ||
} | ||
) | ||
} | ||
> | ||
<input | ||
autocomplete={autocomplete} | ||
autofocus={autofocus} | ||
disabled={disabled} | ||
readonly={readOnly} | ||
placeholder={placeholder || '请输入'} type={type || 'text'} | ||
class={InputClassNamePefix('__inner')} | ||
onchange={(evt: any) => { | ||
const target = evt.target; | ||
(onChange as any)?.(target.value); | ||
}} | ||
value={value} /> | ||
</div> | ||
<div class={ | ||
classNames('t-input__tips', InputClassNamePefix(`__tips--${curStatus}`)) | ||
}> | ||
{tips} | ||
</div> | ||
</div> | ||
</div > | ||
</> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import inputSyle from '../../_common/style/web/components/input/_index.less' | ||
|
||
export default inputSyle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { HorizontalAlignEnum, SizeEnum, StatusEnum, TNode } from '@src/common' | ||
|
||
export type InputProps = HTMLInputElement & | ||
HTMLTextAreaElement & { | ||
autoWidth: boolean | ||
showClearIconOnEmpty: boolean | ||
clearable: boolean | ||
align: HorizontalAlignEnum | ||
size: SizeEnum | ||
status: StatusEnum | ||
tips: TNode | ||
onChange: (value: any) => void | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export default function observable(target: any, propertyKey: string) { | ||
// 保存原始属性值 | ||
let original = target[propertyKey] | ||
|
||
Object.defineProperty(target, propertyKey, { | ||
get() { | ||
console.log('Getting ', propertyKey) | ||
return original | ||
}, | ||
set(value) { | ||
console.log('Setting ', propertyKey) | ||
original = value | ||
try { | ||
// target.update() | ||
} catch (err) { | ||
console.warn(err) | ||
} | ||
}, | ||
}) | ||
|
||
} |