Skip to content

Commit

Permalink
feat(ConfigProvider): support set global rtl
Browse files Browse the repository at this point in the history
  • Loading branch information
youluna committed Dec 5, 2018
1 parent 531fe43 commit 622dda4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
11 changes: 10 additions & 1 deletion src/config-provider/config.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function getDisplayName(Component) {
let globalLocales;
let currentGlobalLanguage = 'zh-cn';
let currentGlobalLocale = {};
let currentGlobalRtl = false;

export function initLocales(locales) {
globalLocales = locales;
Expand All @@ -33,6 +34,10 @@ export function setLocale(locale) {
};
}

export function setDirection(dir) {
currentGlobalRtl = dir === 'rtl';
}

export function getLocale() {
return currentGlobalLocale;
}
Expand All @@ -41,6 +46,10 @@ export function getLanguage() {
return currentGlobalLanguage;
}

export function getDirection() {
return currentGlobalRtl;
}

export function config(Component, options = {}) {
if (Component.prototype.shouldComponentUpdate === undefined) {
Component.prototype.shouldComponentUpdate = function shouldComponentUpdate(
Expand Down Expand Up @@ -124,7 +133,7 @@ export function config(Component, options = {}) {
nextPrefix,
nextLocale: { ...currentGlobalLocale, ...nextLocale },
nextPure,
nextRtl
nextRtl: typeof nextRtl === 'boolean' ? nextRtl : currentGlobalRtl
},
displayName
);
Expand Down
9 changes: 6 additions & 3 deletions src/config-provider/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import {
initLocales,
setLanguage,
setLocale,
setDirection,
getLocale,
getLanguage
getLanguage,
getDirection
} from './config';
import Consumer from './consumer';
import Cache from './cache';
Expand Down Expand Up @@ -47,8 +49,7 @@ class ConfigProvider extends Component {
};

static defaultProps = {
warning: true,
rtl: false
warning: true
};

static childContextTypes = {
Expand Down Expand Up @@ -82,8 +83,10 @@ class ConfigProvider extends Component {
static initLocales = initLocales;
static setLanguage = setLanguage;
static setLocale = setLocale;
static setDirection = setDirection;
static getLanguage = getLanguage;
static getLocale = getLocale;
static getDirection = getDirection;
static Consumer = Consumer;

static getContext = () => {
Expand Down

0 comments on commit 622dda4

Please sign in to comment.