-
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
144 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { noop, omit } from 'vtils' | ||
import defaultProps from '../PickerView/defaultProps' | ||
|
||
export default { | ||
...omit(defaultProps, ['onChange']), | ||
maskClosable: true as boolean, | ||
title: '' as string, | ||
noCancel: false as boolean, | ||
cancelText: '取消' as string, | ||
confirmText: '确定' as string, | ||
onCancel: noop as () => void, | ||
onConfirm: noop, | ||
} |
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 @@ | ||
import defaultProps from '../Picker/defaultProps' | ||
|
||
export default { | ||
...defaultProps, | ||
data: [], | ||
value: null, | ||
} |
Empty file.
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,66 @@ | ||
import { component } from '../component' | ||
import { NormalColData } from '../PickerView' | ||
import MPicker from '../Picker' | ||
import defaultProps from './defaultProps' | ||
import _ from './index.module.scss' | ||
|
||
class MSinglePicker<D extends NormalColData, V extends (D extends NormalColData<infer VV> ? VV : any) = any> extends component({ | ||
props: defaultProps, | ||
state: { | ||
localData: [], | ||
localValue: [], | ||
}, | ||
})<{ | ||
data: D, | ||
value?: V, | ||
onConfirm?: (value: V) => void, | ||
}, { | ||
localData: [D], | ||
localValue: [V], | ||
}> { | ||
componentWillMount() { | ||
const { data, value } = this.props | ||
this.setState({ | ||
localData: [data], | ||
localValue: [value], | ||
}) | ||
} | ||
|
||
componentWillReceiveProps({ data, value }: MSinglePicker<D>['props']) { | ||
this.setState({ | ||
localData: [data], | ||
localValue: [value], | ||
}) | ||
} | ||
|
||
handleCancel = () => { | ||
this.props.onCancel() | ||
} | ||
|
||
handleConfirm: MPicker<D[]>['props']['onConfirm'] = value => { | ||
this.props.onConfirm(value[0]) | ||
} | ||
|
||
render() { | ||
const { maskClosable, itemHeight, visibleItemCount, noCancel, cancelText, confirmText, title } = this.props | ||
const { localData, localValue } = this.state | ||
return ( | ||
<MPicker | ||
maskClosable={maskClosable} | ||
data={localData} | ||
value={localValue} | ||
itemHeight={itemHeight} | ||
visibleItemCount={visibleItemCount} | ||
noCancel={noCancel} | ||
cancelText={cancelText} | ||
confirmText={confirmText} | ||
title={title} | ||
onCancel={this.handleCancel} | ||
onConfirm={this.handleConfirm}> | ||
{this.props.children} | ||
</MPicker> | ||
) | ||
} | ||
} | ||
|
||
export default MSinglePicker |
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,53 @@ | ||
import { View } from '@tarojs/components' | ||
import { component } from '../../components/component' | ||
import { MSinglePicker } from '../../components' | ||
|
||
let i = 0 | ||
|
||
const getData = () => { | ||
const flag = i++ | ||
return [ | ||
`中国${flag}`, | ||
`日本${flag}`, | ||
`美国${flag}`, | ||
`俄罗斯${flag}`, | ||
].reduce((res, country) => { | ||
res.push({ | ||
label: country, | ||
value: country, | ||
}) | ||
return res | ||
}, [] as any) | ||
} | ||
|
||
export default class SinglePicker extends component({ | ||
state: { | ||
data: getData(), | ||
value: '日本0', | ||
}, | ||
}) { | ||
handleChange: MSinglePicker<any, any>['props']['onConfirm'] = value => { | ||
this.setState({ value }) | ||
} | ||
|
||
render() { | ||
const { data, value } = this.state | ||
return ( | ||
<View style={{ | ||
fontSize: '16px', | ||
}}> | ||
<View style={{ fontWeight: 'bold', padding: '10px 0', marginBottom: '10px', borderBottom: '1px solid #eee' }}> | ||
NormalPicker | ||
</View> | ||
<MSinglePicker | ||
maskClosable={false} | ||
title='选择一个国家' | ||
data={data} | ||
value={value} | ||
onConfirm={this.handleChange}> | ||
{JSON.stringify(value)} | ||
</MSinglePicker> | ||
</View> | ||
) | ||
} | ||
} |