Skip to content

Commit

Permalink
chore: tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Feb 14, 2019
1 parent d5a2ef7 commit 4464027
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mounted",
"version": "0.1.0",
"description": "基于 Taro 的小程序、H5 组件库",
"description": "基于 Taro 的微信小程序组件库",
"main": "src/index.js",
"scripts": {
"dev:weapp": "taro build --type weapp --watch",
Expand Down
3 changes: 2 additions & 1 deletion src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ class App extends Taro.Component {
// 'pages/Home/Home',
// 'pages/Sticky/Sticky',
// 'pages/Transition/X',
'pages/Popup/Popup',
// 'pages/Popup/Popup',
'pages/PickerView/PickerView',
],
window: {
navigationBarTitleText: 'DEMO',
Expand Down
36 changes: 24 additions & 12 deletions src/components/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,27 @@ type RequiredProp<T = any> = {
__REQUIRED__: true,
__TYPE__: T,
}
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U

const component = <
P extends StringKeyedObject,
S extends StringKeyedObject,
PP = PartialBy<
{ [K in keyof P]: P[K] extends RequiredProp<infer T> ? T : P[K] },
{ [K in keyof P]: P[K] extends RequiredProp ? never : K }[keyof P]
> & {
/** 应用级别、页面级别的类 */
className?: string,
/** 组件级别的类 */
[CUSTOM_CLASS]?: string,
/** 组件本身的类 */
nativeClass?: string,
},
PP = (
Overwrite<
PartialBy<
{ [K in keyof P]: P[K] extends RequiredProp<infer T> ? T : P[K] },
{ [K in keyof P]: P[K] extends RequiredProp ? never : K }[keyof P]
>,
{
/** 应用级别、页面级别的类 */
className?: string,
/** 组件级别的类 */
[CUSTOM_CLASS]?: string,
/** 组件本身的类 */
nativeClass?: string,
}
>
),
SS = S
>(
{
Expand All @@ -34,7 +40,13 @@ const component = <
state?: S,
} = {} as any
) => (
class Component extends Taro.Component<PP, SS> {
class Component<
ExtraProps extends StringKeyedObject = {},
ExtraState extends StringKeyedObject = {}
> extends Taro.Component<
Overwrite<PP, ExtraProps>,
Overwrite<SS, ExtraState>
> {
static externalClasses = [CUSTOM_CLASS]

static options = {
Expand Down
3 changes: 3 additions & 0 deletions src/pages/Popup/Popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export default class Popup extends component({
const { visible } = this.state
return (
<View>
{range(0, 20).map(index => (
<View key={index}>{index}</View>
))}
<MPopup position='center' visible={visible} onVisibleChange={this.toggleVisible}>
<View className='content'>
hello
Expand Down

0 comments on commit 4464027

Please sign in to comment.