Skip to content

Commit

Permalink
feat: 将组件的 styleIsolation 设为 shared,以支持在高阶组件中设置基础组件的样式
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Apr 12, 2019
1 parent e00684f commit a8fda4c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 9 additions & 0 deletions global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,17 @@ declare module '*.scss'
declare module '*.sass'
declare module '*.styl'

// @ts-ignore
declare const process: {
env: {
TARO_ENV: 'weapp' | 'swan' | 'alipay' | 'h5' | 'rn' | 'tt',
[key: string]: any,
},
}

declare namespace wx {
interface ComponentOptions {
addGlobalClass?: boolean,
styleIsolation?: 'isolated' | 'apply-shared' | 'shared' | 'page-isolated' | 'page-apply-shared' | 'page-shared',
}
}
7 changes: 4 additions & 3 deletions src/components/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,16 @@ const component = <
Overwrite<PP, ExtraProps>,
Overwrite<SS, ExtraState>
> {
static options: wx.ComponentOptions = {
addGlobalClass: !disableGlobalClass,
static options: wx.ComponentOptions = disableGlobalClass ? {} : {
addGlobalClass: true,
styleIsolation: 'shared',
}

static defaultProps: P = props

constructor() {
super(...arguments)
if (Taro.getEnv() !== Taro.ENV_TYPE.WEB) {
if (process.env.TARO_ENV !== 'h5') {
this.props = props as any
}
this.state = state as any
Expand Down

0 comments on commit a8fda4c

Please sign in to comment.