-
-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 1.修复上传问题。2.优化样式单位,增加百分比、vw/vh等。
- Loading branch information
Showing
7 changed files
with
55 additions
and
22 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
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 |
---|---|---|
@@ -1,25 +1,44 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { InputNumber } from 'antd'; | ||
|
||
import { InputNumber, Select } from 'antd'; | ||
const { Option } = Select; | ||
const InputPx = ({ value, onChange, ...props }: any) => { | ||
const [num, setNum] = useState<null | number | string>(''); | ||
const [unit, setUnit] = useState<string>('px'); | ||
|
||
useEffect(() => { | ||
const num = value?.toString().replace('px', ''); | ||
const num = value?.toString().replace(/(px|%|vw|vh|rem|em)/, ''); | ||
if (num) setNum(num); | ||
}, [value]); | ||
|
||
// 输入框改变 | ||
const handleChange = (value: null | number | string) => { | ||
if (value) { | ||
setNum(value); | ||
onChange(value + 'px'); | ||
onChange(value + unit); | ||
} else { | ||
setNum(null); | ||
onChange(''); | ||
} | ||
}; | ||
|
||
return <InputNumber placeholder="输入尺寸: 10" {...props} addonAfter="px" value={num} onChange={(val) => handleChange(val)} />; | ||
// 下拉框改变 | ||
const handleSelect = (value: string) => { | ||
setUnit(value); | ||
if (num !== null && num !== '') onChange(num + value); | ||
}; | ||
|
||
const selectAfter = ( | ||
<Select defaultValue="px" onChange={handleSelect} size="small"> | ||
<Option value="px">px</Option> | ||
<Option value="%">%</Option> | ||
<Option value="vw">vw</Option> | ||
<Option value="vh">vh</Option> | ||
<Option value="em">em</Option> | ||
<Option value="rem">rem</Option> | ||
</Select> | ||
); | ||
|
||
return <InputNumber placeholder="输入尺寸: 10" {...props} addonAfter={selectAfter} value={num} onChange={(val) => handleChange(val)} />; | ||
}; | ||
|
||
export default InputPx; |
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