From 737bd60f2361fe86fcd16fd090d3a2209ce8ef1c Mon Sep 17 00:00:00 2001 From: xrk Date: Mon, 14 Sep 2020 10:48:08 +0800 Subject: [PATCH] docs: add direction & theme to url (#26567) * docs: add direction to localStorage * wip * wip * wip * wip * browserHistory push * add slider menu click query * expand getLocalizedPathname * add logo footer query * fix lint * wip pathname * wip: fix pathname * add hash & theme * remove only component theme * fix theme component change * change var * remove static * change color * chore: optimize code style * fix: exchange theme when router is change * fix: pathname * fix: location pathname * change dark * fix theme * fix router listen theme * remove console Co-authored-by: Kermit --- site/theme/static/dark.less | 9 ++++ .../template/Content/ComponentOverview.jsx | 3 +- site/theme/template/Content/MainContent.jsx | 18 ++++++- site/theme/template/Home/Banner/index.tsx | 11 ++-- site/theme/template/Home/DesignPage/index.tsx | 24 +++++---- site/theme/template/Home/index.tsx | 33 ++++++++---- site/theme/template/Layout/Footer.tsx | 32 ++++++++--- site/theme/template/Layout/Header/Logo.tsx | 26 +++++---- .../template/Layout/Header/Navigation.tsx | 10 ++-- site/theme/template/Layout/Header/index.tsx | 8 +-- site/theme/template/Layout/index.jsx | 53 +++++++++++++++---- site/theme/template/NotFound.tsx | 2 +- site/theme/template/Resources/index.tsx | 5 +- site/theme/template/utils.tsx | 3 +- 14 files changed, 171 insertions(+), 66 deletions(-) diff --git a/site/theme/static/dark.less b/site/theme/static/dark.less index b76ae999f7..6351c82670 100644 --- a/site/theme/static/dark.less +++ b/site/theme/static/dark.less @@ -353,4 +353,13 @@ .token.strong { font-weight: bold; } + + .components-overview { + &-img { + background-color: rgba(255, 255, 255, 0.1); + } + &-search input { + color: rgba(255, 255, 255, 0.65); + } + } } diff --git a/site/theme/template/Content/ComponentOverview.jsx b/site/theme/template/Content/ComponentOverview.jsx index a0db795fe8..841fa0745b 100644 --- a/site/theme/template/Content/ComponentOverview.jsx +++ b/site/theme/template/Content/ComponentOverview.jsx @@ -34,6 +34,7 @@ const ComponentOverview = ({ meta: { title }, content, }, + location, utils: { toReactComponent }, }) => { const { locale, formatMessage } = useIntl(); @@ -103,7 +104,7 @@ const ComponentOverview = ({ const url = `${component.filename .replace(/(\/index)?((\.zh-cn)|(\.en-us))?\.md$/i, '') .toLowerCase()}/`; - const href = getLocalizedPathname(url, locale === 'zh-CN'); + const href = getLocalizedPathname(url, locale === 'zh-CN', location.query); return ( onClickCard(href)}> diff --git a/site/theme/template/Content/MainContent.jsx b/site/theme/template/Content/MainContent.jsx index b16c2bd5e7..9acbf1f3a9 100644 --- a/site/theme/template/Content/MainContent.jsx +++ b/site/theme/template/Content/MainContent.jsx @@ -1,5 +1,5 @@ import React, { Component } from 'react'; -import { Link } from 'bisheng/router'; +import { Link, browserHistory } from 'bisheng/router'; import { Row, Col, Menu, Affix, Tooltip, Avatar, Dropdown } from 'antd'; import { injectIntl } from 'react-intl'; import { LeftOutlined, RightOutlined, ExportOutlined } from '@ant-design/icons'; @@ -230,6 +230,7 @@ class MainContent extends Component { generateMenuItem(isTop, item, { before = null, after = null }) { const { intl: { locale }, + location, } = this.props; const key = fileNameToPath(item.filename); if (!item.title) { @@ -246,11 +247,13 @@ class MainContent extends Component { ]; const { disabled } = item; const url = item.filename.replace(/(\/index)?((\.zh-cn)|(\.en-us))?\.md$/i, '').toLowerCase(); + const child = !item.link ? ( @@ -312,8 +315,19 @@ class MainContent extends Component { changeThemeMode = theme => { const { setTheme, theme: selectedTheme } = this.context; + const { pathname, hash, query } = this.props.location; if (selectedTheme !== theme) { setTheme(theme); + if (theme === 'default') { + delete query.theme; + } else { + query.theme = theme; + } + browserHistory.push({ + pathname: `/${pathname}`, + query, + hash, + }); } }; @@ -438,7 +452,7 @@ class MainContent extends Component { )} -