mirror of
https://github.com/ant-design/ant-design.git
synced 2025-08-06 07:56:28 +08:00
feat: change theme
This commit is contained in:
parent
e53a05cf53
commit
8ffcbe468a
@ -767,5 +767,3 @@
|
|||||||
// Notification
|
// Notification
|
||||||
// ---
|
// ---
|
||||||
@notification-bg: @component-background;
|
@notification-bg: @component-background;
|
||||||
|
|
||||||
@import './dark.less';
|
|
||||||
|
@ -125,6 +125,10 @@ a {
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
&.page-theme-dark {
|
||||||
|
@import (inline) '../../../components/style/dark.less';
|
||||||
|
@import (less) '../../../dist/antd.dark.css';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.drawer-content {
|
.drawer-content {
|
||||||
@ -143,3 +147,13 @@ a {
|
|||||||
color: #fff !important;
|
color: #fff !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.fixed-widgets {
|
||||||
|
position: fixed;
|
||||||
|
z-index: 2147483640;
|
||||||
|
bottom: 102px;
|
||||||
|
right: 30px;
|
||||||
|
& > div {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { Link } from 'bisheng/router';
|
import { Link } from 'bisheng/router';
|
||||||
import { Row, Col, Menu, Affix } from 'antd';
|
import { Row, Col, Menu, Affix, Button } from 'antd';
|
||||||
import { FormattedMessage, injectIntl } from 'react-intl';
|
import { FormattedMessage, injectIntl } from 'react-intl';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import get from 'lodash/get';
|
import get from 'lodash/get';
|
||||||
@ -73,6 +73,8 @@ const getSubMenuTitle = menuItem => {
|
|||||||
class MainContent extends Component {
|
class MainContent extends Component {
|
||||||
static contextTypes = {
|
static contextTypes = {
|
||||||
isMobile: PropTypes.bool.isRequired,
|
isMobile: PropTypes.bool.isRequired,
|
||||||
|
theme: PropTypes.oneOf(['default', 'dark']),
|
||||||
|
setTheme: PropTypes.func,
|
||||||
};
|
};
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
@ -282,8 +284,13 @@ class MainContent extends Component {
|
|||||||
return this.flattenMenu((menu.props && menu.props.children) || menu.children);
|
return this.flattenMenu((menu.props && menu.props.children) || menu.children);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
changeTheme = () => {
|
||||||
|
const { theme, setTheme } = this.context;
|
||||||
|
setTheme(theme !== 'dark' ? 'dark' : 'default');
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { isMobile } = this.context;
|
const { isMobile, theme, setTheme } = this.context;
|
||||||
const { openKeys } = this.state;
|
const { openKeys } = this.state;
|
||||||
const { localizedPageData, demos } = this.props;
|
const { localizedPageData, demos } = this.props;
|
||||||
const activeMenuItem = this.getActiveMenuItem();
|
const activeMenuItem = this.getActiveMenuItem();
|
||||||
@ -308,6 +315,7 @@ class MainContent extends Component {
|
|||||||
{menuItems}
|
{menuItems}
|
||||||
</Menu>
|
</Menu>
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="main-wrapper">
|
<div className="main-wrapper">
|
||||||
<Row>
|
<Row>
|
||||||
@ -330,6 +338,11 @@ class MainContent extends Component {
|
|||||||
<Article {...this.props} content={localizedPageData} />
|
<Article {...this.props} content={localizedPageData} />
|
||||||
)}
|
)}
|
||||||
</section>
|
</section>
|
||||||
|
<div className="fixed-widgets">
|
||||||
|
<div>
|
||||||
|
<Button onClick={this.changeTheme}>{theme}</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<PrevAndNext prev={prev} next={next} />
|
<PrevAndNext prev={prev} next={next} />
|
||||||
<Footer />
|
<Footer />
|
||||||
</Col>
|
</Col>
|
||||||
|
@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
|
|||||||
import { enquireScreen } from 'enquire-js';
|
import { enquireScreen } from 'enquire-js';
|
||||||
import { IntlProvider } from 'react-intl';
|
import { IntlProvider } from 'react-intl';
|
||||||
import { Helmet, HelmetProvider } from 'react-helmet-async';
|
import { Helmet, HelmetProvider } from 'react-helmet-async';
|
||||||
|
import classNames from 'classnames';
|
||||||
import 'moment/locale/zh-cn';
|
import 'moment/locale/zh-cn';
|
||||||
import { ConfigProvider } from 'antd';
|
import { ConfigProvider } from 'antd';
|
||||||
import LogRocket from 'logrocket';
|
import LogRocket from 'logrocket';
|
||||||
@ -60,6 +61,8 @@ export default class Layout extends React.Component {
|
|||||||
|
|
||||||
static childContextTypes = {
|
static childContextTypes = {
|
||||||
isMobile: PropTypes.bool,
|
isMobile: PropTypes.bool,
|
||||||
|
theme: PropTypes.oneOf(['default', 'dark']),
|
||||||
|
setTheme: PropTypes.func,
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@ -70,12 +73,14 @@ export default class Layout extends React.Component {
|
|||||||
this.state = {
|
this.state = {
|
||||||
appLocale,
|
appLocale,
|
||||||
isMobile,
|
isMobile,
|
||||||
|
theme: 'default',
|
||||||
|
setTheme: this.setTheme,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
getChildContext() {
|
getChildContext() {
|
||||||
const { isMobile: mobile } = this.state;
|
const { isMobile: mobile, theme, setTheme } = this.state;
|
||||||
return { isMobile: mobile };
|
return { isMobile: mobile, theme, setTheme };
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
@ -109,9 +114,15 @@ export default class Layout extends React.Component {
|
|||||||
clearTimeout(this.timer);
|
clearTimeout(this.timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setTheme = theme => {
|
||||||
|
this.setState({
|
||||||
|
theme,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { children, helmetContext = {}, ...restProps } = this.props;
|
const { children, helmetContext = {}, ...restProps } = this.props;
|
||||||
const { appLocale } = this.state;
|
const { appLocale, theme } = this.state;
|
||||||
const title =
|
const title =
|
||||||
appLocale.locale === 'zh-CN'
|
appLocale.locale === 'zh-CN'
|
||||||
? 'Ant Design - 一套企业级 UI 设计语言和 React 组件库'
|
? 'Ant Design - 一套企业级 UI 设计语言和 React 组件库'
|
||||||
@ -120,6 +131,7 @@ export default class Layout extends React.Component {
|
|||||||
appLocale.locale === 'zh-CN'
|
appLocale.locale === 'zh-CN'
|
||||||
? '基于 Ant Design 设计体系的 React UI 组件库,用于研发企业级中后台产品。'
|
? '基于 Ant Design 设计体系的 React UI 组件库,用于研发企业级中后台产品。'
|
||||||
: 'An enterprise-class UI design language and React UI library with a set of high-quality React components, one of best React UI library for enterprises';
|
: 'An enterprise-class UI design language and React UI library with a set of high-quality React components, one of best React UI library for enterprises';
|
||||||
|
const wrapperCls = classNames('page-wrapper', `page-theme-${theme}`);
|
||||||
return (
|
return (
|
||||||
<HelmetProvider context={helmetContext}>
|
<HelmetProvider context={helmetContext}>
|
||||||
<Helmet encodeSpecialCharacters={false}>
|
<Helmet encodeSpecialCharacters={false}>
|
||||||
@ -140,7 +152,7 @@ export default class Layout extends React.Component {
|
|||||||
</Helmet>
|
</Helmet>
|
||||||
<IntlProvider locale={appLocale.locale} messages={appLocale.messages} defaultLocale="en-US">
|
<IntlProvider locale={appLocale.locale} messages={appLocale.messages} defaultLocale="en-US">
|
||||||
<ConfigProvider locale={appLocale.locale === 'zh-CN' ? zhCN : null}>
|
<ConfigProvider locale={appLocale.locale === 'zh-CN' ? zhCN : null}>
|
||||||
<div className="page-wrapper">
|
<div className={wrapperCls}>
|
||||||
<Header {...restProps} />
|
<Header {...restProps} />
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user