-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
125 additions
and
5 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.form { | ||
display: none; | ||
width: 0; | ||
height: 0; | ||
overflow: hidden; | ||
pointer-events: none; | ||
} |
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,38 @@ | ||
import { Form, Button } from '@tarojs/components' | ||
import { noop } from 'vtils' | ||
import { component, RequiredProp } from '../component' | ||
import _ from './Collector.module.scss' | ||
import Self from './Collector' | ||
|
||
export default class Collector extends component({ | ||
props: { | ||
count: 0 as any as RequiredProp<number>, | ||
onCollect: noop as any as RequiredProp< | ||
(e: { detail: { formId: string } }) => void | ||
>, | ||
}, | ||
}) { | ||
public render() { | ||
const { count } = this.props | ||
return ( | ||
<Form | ||
className={_.form} | ||
reportSubmit={true} | ||
onSubmit={this.props.onCollect}> | ||
<Button formType='submit'> | ||
{ | ||
count > 1 | ||
? ( | ||
<Self | ||
count={count - 1} | ||
onCollect={this.props.onCollect}> | ||
{this.props.children} | ||
</Self> | ||
) | ||
: this.props.children | ||
} | ||
</Button> | ||
</Form> | ||
) | ||
} | ||
} |
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,45 @@ | ||
import { Label, View, Button } from '@tarojs/components' | ||
import { noop } from 'vtils' | ||
import { component } from '../component' | ||
import Collector from './Collector' | ||
|
||
/** | ||
* Form Id 收集组件。 | ||
*/ | ||
export default class MFormIdCollector extends component({ | ||
props: { | ||
/** 每次点击的收集个数 */ | ||
count: 1 as number, | ||
/** 是否禁用 */ | ||
disabled: false as boolean, | ||
/** 收集完成事件 */ | ||
onCollect: noop as (formIds: string[]) => void, | ||
}, | ||
}) { | ||
/** Form Id 列表 */ | ||
formIds: string[] = [] | ||
|
||
handleSubmit: Collector['props']['onCollect'] = e => { | ||
this.formIds.push(e.detail.formId) | ||
if (this.formIds.length === this.props.count) { | ||
this.props.onCollect(this.formIds.slice()) | ||
this.formIds = [] | ||
} | ||
} | ||
|
||
public render() { | ||
const { count, disabled } = this.props | ||
return disabled ? this.props.children : ( | ||
<View> | ||
<Label for='button'> | ||
{this.props.children} | ||
</Label> | ||
<Collector | ||
count={count} | ||
onCollect={this.handleSubmit}> | ||
<Button id='button' /> | ||
</Collector> | ||
</View> | ||
) | ||
} | ||
} |
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,10 @@ | ||
import { component } from '../../components/component' | ||
import Test from './Test' | ||
|
||
export default class extends component() { | ||
render() { | ||
return ( | ||
<Test n={1} /> | ||
) | ||
} | ||
} |
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,18 @@ | ||
import { Component } from '@tarojs/taro' | ||
import { View } from '@tarojs/components' | ||
import Self from './Test' | ||
|
||
export default class Test extends Component<{ n: number }> { | ||
render() { | ||
const { n } = this.props | ||
return ( | ||
<View> | ||
{ | ||
n === 1 | ||
? <Self n={0} /> | ||
: 'over' | ||
} | ||
</View> | ||
) | ||
} | ||
} |