Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 添加隐藏按钮,隐藏textarea输入框功能 #98

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 75 additions & 3 deletions examples/mini-program-example/src/components/buttonList/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,89 @@
justify-content: center;
}

.hidden-control {
width: 90%;
font-size: 32px;
display: flex;
align-items: center;
}

.stepper {
width: 24%;
height: 60px;
display: flex;
justify-content: space-around;
margin: 0 20px;
align-items: center;
border: 4px solid #ccc;
border-radius: 10px;
}

.stepper .stepper-num {
display: block;
width: 36%;
text-align: center;
border-left: 4px solid #ccc;
border-right: 4px solid #ccc;
}

.stepper .normal {
font-size: 42px;
padding: 0;
display: block;
width: 32%;
text-align: center;
}

.api-page-btn-area {
width: 100%;
display: flex;
flex-wrap: wrap;
justify-content: center;
transition: 0.3s;
}

.api-page-btn-area-hidden {
opacity: 0;
height: 0;
}

.api-textarea-area {
width: 100%;
position: relative;
}

.api-input-area {
width: 90%;
height: 200px;
min-height: 200px;
border: $color-grey-0 solid 2px;
border-radius: 5px;
margin: 20px auto;
border: $color-grey-0 solid 4px;
border-radius: 10px;
overflow: hidden;
transition: 0.3s;
resize: none;
}

.api-input-area-hidden {
height: 0;
margin: 0;
border: 0;
}

.textarea-control {
position: absolute;
right: 50px;
top: 36px;
height: 40px;
width: 40px;
border: 2px solid $color-grey-0;
background-color: $color-success;
border-radius: 100%;
opacity: $opacity-active;
text-align: center;
line-height: 40px;
}

.taro-textarea {
resize: none;
}
Expand All @@ -43,6 +110,11 @@ textarea {
transition: 0.3s;
}

.api-page-btn-uncreate {
opacity: $opacity-disabled;
pointer-events: none;
}

.api-page-btn:active {
color: $color-success;
background-color: $color-grey-6;
Expand Down
96 changes: 79 additions & 17 deletions examples/mini-program-example/src/components/buttonList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,27 @@ interface Props {

interface States {
inputData: Array<Object | String | undefined>
textareaControl: Array<Boolean>
hiddenNum: Number
}

export default class Index extends React.Component<Props, States> {
state = {
inputData: [],
textareaControl: [],
hiddenNum: 0,
}
componentDidMount(): void {
const buttonList = this.props.buttonList
const inputData: Array<Object> = []
const textareaControl: Array<Boolean> = []
buttonList.forEach((item) => {
if (item['inputData']) {
inputData.push(item.inputData)
} else {
inputData.push(undefined)
}
textareaControl.push(true)
})
this.setState({
inputData,
Expand Down Expand Up @@ -60,40 +66,96 @@ export default class Index extends React.Component<Props, States> {
}
}
}
minusHidden = () => {
const { hiddenNum } = this.state
if (hiddenNum > 0) {
this.setState({
hiddenNum: hiddenNum - 1,
})
} else {
Taro.showToast({
title: '无法继续减少',
})
}
}
addHidden = () => {
const { hiddenNum } = this.state
const btnLength = this.props.buttonList.length
if (hiddenNum < btnLength) {
this.setState({
hiddenNum: hiddenNum + 1,
})
} else {
Taro.showToast({
title: '无法继续增加',
})
}
}
hideTextarea = (apiIndex: Number) => {
const { textareaControl } = this.state
textareaControl[apiIndex] = !textareaControl[apiIndex]
this.setState({
textareaControl,
})
}
render() {
const { buttonList } = this.props
const { inputData } = this.state
const { inputData, textareaControl, hiddenNum } = this.state
return (
<View className='button-list'>
<View className='hidden-control'>
<Text>隐藏按钮</Text>
<View className='stepper'>
<View className='normal' onClick={this.minusHidden}>
-
</View>
<View className='stepper-num'>{hiddenNum}</View>
<View className='normal' onClick={this.addHidden}>
+
</View>
</View>
</View>
{buttonList.map((item, apiIndex) => {
return (
<View className='api-page-btn-area' key={item.id}>
<View
className={`api-page-btn-area ${apiIndex < hiddenNum ? 'api-page-btn-area-hidden' : ''}`}
key={item.id}
>
{inputData[apiIndex] != undefined ? (
<Textarea
className='api-input-area'
maxlength={-1}
id={`${item.id}-input`}
value={
typeof inputData[apiIndex] == 'string'
? inputData[apiIndex]
: JSON.stringify(inputData[apiIndex], null, 2)
}
onInput={(e) => {
this.changeData(e, apiIndex)
}}
/>
<View className='api-textarea-area'>
<Textarea
className={`api-input-area ${textareaControl[apiIndex] ? 'api-input-area-hidden' : ''}`}
maxlength={-1}
id={`${item.id}-input`}
value={
typeof inputData[apiIndex] == 'string'
? inputData[apiIndex]
: JSON.stringify(inputData[apiIndex], null, 2)
}
onInput={(e) => {
this.changeData(e, apiIndex)
}}
/>
<View
className='textarea-control'
onClick={() => {
this.hideTextarea(apiIndex)
}}
>
{textareaControl[apiIndex] ? '+' : '-'}
</View>
</View>
) : (
''
)}
<View
className='api-page-btn'
className={`api-page-btn ${item.func == null ? 'api-page-btn-uncreate' : ''}`}
id={item.id}
onClick={() => {
this.submitData(inputData[apiIndex], item, apiIndex)
}}
>
{item.id}
{item.func == null && <Text className='navigator-state tag'>未创建Demo</Text>}
{item.callbackRes != null ? <CallbackContents testApi={item.id} callbackRes={item.callbackRes} /> : ''}
</View>
</View>
Expand Down