docs: Add happy wave package (#44031)

* docs: theme add happy work

* docs: update happy

* fix: lint

* docs: rename
This commit is contained in:
二货爱吃白萝卜 2023-08-07 10:44:04 +08:00 committed by GitHub
parent 9427c264f4
commit e8f9f6a88d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 86 additions and 8 deletions

View File

@ -1,5 +1,6 @@
import { BgColorsOutlined } from '@ant-design/icons'; import { BgColorsOutlined, SmileOutlined } from '@ant-design/icons';
import { CompactTheme, DarkTheme, Motion } from 'antd-token-previewer/es/icons'; import { CompactTheme, DarkTheme } from 'antd-token-previewer/es/icons';
// import { Motion } from 'antd-token-previewer/es/icons';
import { FormattedMessage, Link, useLocation } from 'dumi'; import { FormattedMessage, Link, useLocation } from 'dumi';
import React from 'react'; import React from 'react';
import { useTheme } from 'antd-style'; import { useTheme } from 'antd-style';
@ -7,7 +8,7 @@ import { FloatButton } from 'antd';
import { getLocalizedPathname, isZhCN } from '../../utils'; import { getLocalizedPathname, isZhCN } from '../../utils';
import ThemeIcon from './ThemeIcon'; import ThemeIcon from './ThemeIcon';
export type ThemeName = 'light' | 'dark' | 'compact' | 'motion-off'; export type ThemeName = 'light' | 'dark' | 'compact' | 'motion-off' | 'happy-work';
export type ThemeSwitchProps = { export type ThemeSwitchProps = {
value?: ThemeName[]; value?: ThemeName[];
@ -19,7 +20,8 @@ const ThemeSwitch: React.FC<ThemeSwitchProps> = (props) => {
const token = useTheme(); const token = useTheme();
const { pathname, search } = useLocation(); const { pathname, search } = useLocation();
const isMotionOff = value.includes('motion-off'); // const isMotionOff = value.includes('motion-off');
const isHappyWork = value.includes('happy-work');
return ( return (
<FloatButton.Group trigger="click" icon={<ThemeIcon />} aria-label="Theme Switcher"> <FloatButton.Group trigger="click" icon={<ThemeIcon />} aria-label="Theme Switcher">
@ -56,7 +58,8 @@ const ThemeSwitch: React.FC<ThemeSwitchProps> = (props) => {
}} }}
tooltip={<FormattedMessage id="app.theme.switch.compact" />} tooltip={<FormattedMessage id="app.theme.switch.compact" />}
/> />
<FloatButton {/* Too many float button. Hide motion one */}
{/* <FloatButton
icon={<Motion />} icon={<Motion />}
type={!isMotionOff ? 'primary' : 'default'} type={!isMotionOff ? 'primary' : 'default'}
onClick={() => { onClick={() => {
@ -71,6 +74,22 @@ const ThemeSwitch: React.FC<ThemeSwitchProps> = (props) => {
id={isMotionOff ? 'app.theme.switch.motion.off' : 'app.theme.switch.motion.on'} id={isMotionOff ? 'app.theme.switch.motion.off' : 'app.theme.switch.motion.on'}
/> />
} }
/> */}
<FloatButton
icon={<SmileOutlined />}
type={isHappyWork ? 'primary' : 'default'}
onClick={() => {
if (isHappyWork) {
onChange(value.filter((theme) => theme !== 'happy-work'));
} else {
onChange([...value, 'happy-work']);
}
}}
tooltip={
<FormattedMessage
id={isHappyWork ? 'app.theme.switch.happy-work.off' : 'app.theme.switch.happy-work.on'}
/>
}
/> />
</FloatButton.Group> </FloatButton.Group>
); );

View File

@ -6,6 +6,7 @@ import {
StyleProvider, StyleProvider,
extractStyle, extractStyle,
} from '@ant-design/cssinjs'; } from '@ant-design/cssinjs';
import { HappyProvider } from '@ant-design/happy-work-theme';
import React, { useCallback, useEffect, useMemo } from 'react'; import React, { useCallback, useEffect, useMemo } from 'react';
import { createSearchParams, useOutlet, useSearchParams, useServerInsertedHTML } from 'dumi'; import { createSearchParams, useOutlet, useSearchParams, useServerInsertedHTML } from 'dumi';
import { App, theme as antdTheme } from 'antd'; import { App, theme as antdTheme } from 'antd';
@ -147,7 +148,7 @@ const GlobalLayout: React.FC = () => {
}, },
}} }}
> >
{content} <HappyProvider disabled={!theme.includes('happy-work')}>{content}</HappyProvider>
</SiteThemeProvider> </SiteThemeProvider>
</SiteContext.Provider> </SiteContext.Provider>
</StyleProvider> </StyleProvider>

View File

@ -5,6 +5,8 @@
"app.theme.switch.compact": "Compact theme", "app.theme.switch.compact": "Compact theme",
"app.theme.switch.motion.on": "Motion On", "app.theme.switch.motion.on": "Motion On",
"app.theme.switch.motion.off": "Motion Off", "app.theme.switch.motion.off": "Motion Off",
"app.theme.switch.happy-work.on": "Happy Work Effect On",
"app.theme.switch.happy-work.off": "Happy Work Effect Off",
"app.header.search": "Search...", "app.header.search": "Search...",
"app.header.menu.documentation": "Docs", "app.header.menu.documentation": "Docs",
"app.header.menu.more": "More", "app.header.menu.more": "More",

View File

@ -5,6 +5,8 @@
"app.theme.switch.compact": "紧凑主题", "app.theme.switch.compact": "紧凑主题",
"app.theme.switch.motion.on": "动画开启", "app.theme.switch.motion.on": "动画开启",
"app.theme.switch.motion.off": "动画关闭", "app.theme.switch.motion.off": "动画关闭",
"app.theme.switch.happy-work.on": "快乐工作特效开启",
"app.theme.switch.happy-work.off": "快乐工作特效关闭",
"app.header.search": "全文本搜索...", "app.header.search": "全文本搜索...",
"app.header.menu.documentation": "文档", "app.header.menu.documentation": "文档",
"app.header.menu.more": "更多", "app.header.menu.more": "更多",

View File

@ -1,7 +1,7 @@
## zh-CN ## zh-CN
波纹效果带来了灵动性,可以通过 `component` 判断来自哪个组件。 波纹效果带来了灵动性,可以通过 `component` 判断来自哪个组件。你也可以使用 [`@ant-design/happy-work-theme`](https://github.com/ant-design/happy-work-theme) 提供的 HappyProvider 实现动态波纹效果。
## en-US ## en-US
Wave effect brings dynamic. Use `component` to determine which component use it. Wave effect brings dynamic. Use `component` to determine which component use it. You can also use HappyProvider from [`@ant-design/happy-work-theme`](https://github.com/ant-design/happy-work-theme) to implement dynamic wave effect.

View File

@ -1,3 +1,4 @@
import { HappyProvider } from '@ant-design/happy-work-theme';
import React from 'react'; import React from 'react';
import { Button, ConfigProvider, Space } from 'antd'; import { Button, ConfigProvider, Space } from 'antd';
@ -122,6 +123,9 @@ const App = () => (
<Wrapper name="Default" /> <Wrapper name="Default" />
<Wrapper name="Inset" showEffect={showInsetEffect} /> <Wrapper name="Inset" showEffect={showInsetEffect} />
<Wrapper name="Shake" showEffect={showShakeEffect} /> <Wrapper name="Shake" showEffect={showShakeEffect} />
<HappyProvider>
<Button type="primary">Happy Work</Button>
</HappyProvider>
</Space> </Space>
); );

View File

@ -0,0 +1,7 @@
## zh-CN
通过 `token` 进行动画效果配置。
## en-US
Config animation effect by `token`.

View File

@ -0,0 +1,42 @@
import React from 'react';
import { Switch, ConfigProvider, Space, Checkbox, Radio, Row, Col } from 'antd';
export default () => {
const [checked, setChecked] = React.useState(false);
React.useEffect(() => {
const id = setInterval(() => {
setChecked((prev) => !prev);
}, 500);
return () => {
clearInterval(id);
};
}, []);
const nodes = (
<Space>
<Checkbox checked={checked}>Checkbox</Checkbox>
<Radio checked={checked}>Radio</Radio>
<Switch checked={checked} />
</Space>
);
return (
<Row gutter={[24, 24]}>
<Col span={24}>{nodes}</Col>
<Col span={24}>
<ConfigProvider
theme={{
token: {
motion: false,
},
}}
>
{nodes}
</ConfigProvider>
</Col>
</Row>
);
};

View File

@ -159,6 +159,7 @@
"throttle-debounce": "^5.0.0" "throttle-debounce": "^5.0.0"
}, },
"devDependencies": { "devDependencies": {
"@ant-design/happy-work-theme": "^1.0.0",
"@ant-design/tools": "^17.0.0", "@ant-design/tools": "^17.0.0",
"@antv/g6": "^4.8.13", "@antv/g6": "^4.8.13",
"@argos-ci/core": "^0.9.0", "@argos-ci/core": "^0.9.0",