Skip to content

Commit

Permalink
Merge pull request #931 from XiaoMi/hotfix/theme
Browse files Browse the repository at this point in the history
Hotfix/theme
  • Loading branch information
solarjoker authored Feb 7, 2020
2 parents afa7792 + c08a65f commit e7e860b
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 29 deletions.
36 changes: 21 additions & 15 deletions components/context/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,34 @@ import locales from '../locales'

export const ThemeContext = React.createContext('hiui-blue')
export const LocaleContext = React.createContext('zh-CN')

/**
* 临时解决 notice组件获取不到theme的问题
*/
let noticeTheme = ''
export default (WrappedComponent) => {
class WrapperComponent extends Component {
static displayName = WrappedComponent.name
render () {
const { theme, locale, innerRef, ...restProps } = this.props
let ConsumerComponent = (
<ThemeContext.Consumer>
{(contextTheme) => (
<LocaleContext.Consumer>
{(contextLocale) => (
<WrappedComponent
theme={contextTheme}
locale={contextLocale}
localeDatas={locales[contextLocale]}
ref={innerRef}
innerRef={innerRef}
{...restProps}
/>
)}
</LocaleContext.Consumer>
)}
{(contextTheme) => {
noticeTheme = noticeTheme || contextTheme
return (
<LocaleContext.Consumer>
{(contextLocale) => (
<WrappedComponent
theme={WrappedComponent.IS_HIUI_NOTICE ? noticeTheme : contextTheme}
locale={contextLocale}
localeDatas={locales[contextLocale]}
ref={innerRef}
innerRef={innerRef}
{...restProps}
/>
)}
</LocaleContext.Consumer>
)
}}
</ThemeContext.Consumer>
)
return wrapProvider(theme, ThemeContext)(locale, LocaleContext)(
Expand Down
3 changes: 2 additions & 1 deletion components/menu/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class Menu extends Component {
}

renderMenu (data, parentIndex = '') {
const {showAllSubMenus, placement} = this.props
const {showAllSubMenus, placement, theme} = this.props
const {
activeIndex,
expandIndex,
Expand All @@ -237,6 +237,7 @@ class Menu extends Component {
items.push(
<SubMenu
key={index}
theme={theme}
onClick={this.onClickSubMenu.bind(this)}
clickInside={this.clickInside.bind(this)}
index={indexStr}
Expand Down
3 changes: 1 addition & 2 deletions components/menu/SubMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import classNames from 'classnames'
import Popper from '../popper'
import Icon from '../icon'
import Title from './Title'
import Provider from '../context'
class SubMenu extends Component {
onClick (index) {
this.props.onClick(index)
Expand Down Expand Up @@ -165,4 +164,4 @@ SubMenu.defaultProps = {
expandIndex: []
}

export default Provider(SubMenu)
export default SubMenu
1 change: 1 addition & 0 deletions components/notice/Notice.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ class Notice extends Component {
)
}
}
Notice.IS_HIUI_NOTICE = true
export default Provider(Notice)
export {Notice}
4 changes: 1 addition & 3 deletions components/notification/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import React from 'react'
import Button from '../button'
import classNames from 'classnames'
import _handleNotificate from './HandleNotification'

const iconMap = {
success: 'chenggong',
error: 'shibai',
Expand All @@ -29,8 +28,7 @@ const notification = {
type = 'info',
confirmText,
onConfirm,
onClose,
theme
onClose
}) => {
const NoticeContent = (
<React.Fragment>
Expand Down
5 changes: 4 additions & 1 deletion components/select/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,8 @@ class Select extends Component {
onFocus,
dataSource,
filterOption,
onSearch
onSearch,
theme
} = this.props
const placeholder = this.localeDatasProps('placeholder')
const {
Expand Down Expand Up @@ -579,6 +580,7 @@ class Select extends Component {
ref={node => {
this.selectInput = node
}}
theme={theme}
mode={type}
disabled={disabled}
searchable={searchable}
Expand Down Expand Up @@ -617,6 +619,7 @@ class Select extends Component {
<SelectDropdown
noFoundTip={emptyContent}
mode={type}
theme={theme}
onBlur={onBlur}
onFocus={onFocus}
isOnSearch = {onSearch || dataSource}
Expand Down
3 changes: 1 addition & 2 deletions components/select/SelectDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { Component } from 'react'
import classNames from 'classnames'
import Checkbox from '../checkbox'
import Loading from '../loading'
import Provider from '../context'
import Icon from '../icon'

class SelectDropdown extends Component {
Expand Down Expand Up @@ -253,4 +252,4 @@ class SelectDropdown extends Component {
}
}

export default Provider(SelectDropdown)
export default SelectDropdown
3 changes: 1 addition & 2 deletions components/select/SelectInput.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { Component } from 'react'
import classNames from 'classnames'
import { getTextWidth } from './common.js'
import Proivder from '../context'

class SelectInput extends Component {
constructor (props) {
Expand Down Expand Up @@ -279,4 +278,4 @@ class SelectInput extends Component {
}
}

export default Proivder(SelectInput)
export default SelectInput
6 changes: 3 additions & 3 deletions components/switch/__tests__/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
exports[`Switch basic use 1`] = `
<div>
<span
className="theme__orange hi-switch hi-switch--closed"
className="theme__hiui-blue hi-switch hi-switch--closed"
onClick={[Function]}
>
<span
className="hi-switch__text"
/>
</span>
<span
className="theme__orange hi-switch hi-switch--closed"
className="theme__hiui-blue hi-switch hi-switch--closed"
onClick={[Function]}
>
<span
Expand All @@ -21,7 +21,7 @@ exports[`Switch basic use 1`] = `
</span>
</span>
<span
className="theme__orange hi-switch hi-switch--disabled"
className="theme__hiui-blue hi-switch hi-switch--disabled"
onClick={[Function]}
>
<span
Expand Down

0 comments on commit e7e860b

Please sign in to comment.