Skip to content

Commit

Permalink
docs: fix site issue (ant-design#38552)
Browse files Browse the repository at this point in the history
* docs: put an example loading component

* fix: site issue

* fix: site issue

* feat: add loading

* feat: alert

* docs: rm ReactDOM.render in md

* docs: use style tag

* chore: update snapshot

* Revert "docs: use style tag"

This reverts commit 1f75a99.

* docs: update demo

* chore: update demo

Co-authored-by: PeachScript <[email protected]>
  • Loading branch information
MadCcc and PeachScript authored Nov 15, 2022
1 parent 31a401b commit fab90b0
Show file tree
Hide file tree
Showing 42 changed files with 1,492 additions and 492 deletions.
8 changes: 8 additions & 0 deletions .dumi/theme/builtins/Alert/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Alert, AlertProps } from 'antd';
import React, { FC } from 'react';

const MdAlert: FC<AlertProps> = ({ style, ...props }) => {
return <Alert {...props} style={{ margin: '24px 0', ...style }} />;
};

export default MdAlert;
4 changes: 4 additions & 0 deletions .dumi/theme/builtins/ColorPaletteTool/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @ts-ignore
import ColorPaletteTool from '../../common/Color/ColorPaletteTool';

export default ColorPaletteTool;
4 changes: 4 additions & 0 deletions .dumi/theme/builtins/ColorPaletteToolDark/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @ts-ignore
import ColorPaletteToolDark from '../../common/Color/ColorPaletteToolDark';

export default ColorPaletteToolDark;
4 changes: 4 additions & 0 deletions .dumi/theme/builtins/ColorPalettes/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @ts-ignore
import ColorPalettes from '../../common/Color/ColorPalettes';

export default ColorPalettes;
4 changes: 4 additions & 0 deletions .dumi/theme/builtins/Palette/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @ts-ignore
import Palette from '../../common/Color/Palette';

export default Palette;
36 changes: 36 additions & 0 deletions .dumi/theme/common/Color/ColorBlock.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React, { Component } from 'react';
import CopyToClipboard from 'react-copy-to-clipboard';
import { message } from 'antd';

export default class ColorBlock extends Component {
getTextStyle() {
const { color, index, dark } = this.props;
const colorMap = {
default: ['#fff', 'unset'],
dark: ['#314659', '#fff'],
};
const [lastColor, firstColor] = dark ? colorMap.dark : colorMap.default;
return {
background: color,
color: index > 5 ? lastColor : firstColor,
fontWeight: index === 6 ? 'bold' : 'normal',
};
}

onCopied = () => {
const { color } = this.props;
message.success(`Copied: ${color}`);
};

render() {
const { color, index } = this.props;
return (
<CopyToClipboard text={color} onCopy={this.onCopied} title="click to copy color">
<div className="main-color-item" style={this.getTextStyle()}>
color-{index}
<span className="main-color-value">{color.toLowerCase()}</span>
</div>
</CopyToClipboard>
);
}
}
61 changes: 61 additions & 0 deletions .dumi/theme/common/Color/ColorPaletteTool.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import React, { Component } from 'react';
import { FormattedMessage } from 'dumi';
import ColorPicker from './ColorPicker';
import ColorPatterns from './ColorPatterns';

const primaryMinSaturation = 70; // 主色推荐最小饱和度
const primaryMinBrightness = 70; // 主色推荐最小亮度

export default class ColorPaletteTool extends Component {
state = {
primaryColor: '#1890ff',
primaryColorInstance: null,
};

handleChangeColor = (e, color) => {
const value = e.target ? e.target.value : e;
this.setState({
primaryColor: value,
primaryColorInstance: color,
});
};

renderColorValidation() {
const { primaryColorInstance } = this.state;
let text = '';
if (primaryColorInstance) {
if (primaryColorInstance.hsv.s * 100 < primaryMinSaturation) {
text += ` 饱和度建议不低于${primaryMinSaturation}(现在 ${(
primaryColorInstance.hsv.s * 100
).toFixed(2)})`;
}
if (primaryColorInstance.hsv.v * 100 < primaryMinBrightness) {
text += ` 亮度建议不低于${primaryMinBrightness}(现在 ${(
primaryColorInstance.hsv.v * 100
).toFixed(2)})`;
}
}
return <span className="color-palette-picker-validation">{text.trim()}</span>;
}

render() {
const { primaryColor } = this.state;
return (
<div className="color-palette-horizontal">
<div className="color-palette-pick">
<FormattedMessage id="app.docs.color.pick-primary" />
</div>
<div className="main-color">
<ColorPatterns color={primaryColor} />
</div>
<div className="color-palette-picker">
<span style={{ display: 'inline-block', verticalAlign: 'middle' }}>
<ColorPicker type="chrome" color={primaryColor} onChange={this.handleChangeColor} />
</span>
<span className="color-palette-picker-value">{primaryColor}</span>
{this.renderColorValidation()}
</div>
</div>
);
}
}
107 changes: 107 additions & 0 deletions .dumi/theme/common/Color/ColorPaletteToolDark.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import React, { Component } from 'react';
import { FormattedMessage } from 'dumi';
import { Row, Col } from 'antd';
import ColorPicker from './ColorPicker';
import ColorPatterns from './ColorPatterns';

const primaryMinSaturation = 70; // 主色推荐最小饱和度
const primaryMinBrightness = 70; // 主色推荐最小亮度

export default class ColorPaletteTool extends Component {
state = {
primaryColor: '#1890ff',
backgroundColor: '#141414',
primaryColorInstance: null,
};

handleChangeColor = (e, color) => {
const value = e.target ? e.target.value : e;
this.setState({
primaryColor: value,
primaryColorInstance: color,
});
};

handleChangeBackgroundColor = e => {
const value = e.target ? e.target.value : e;
this.setState({
backgroundColor: value,
});
};

renderColorValidation() {
const { primaryColorInstance } = this.state;
let text = '';
if (primaryColorInstance) {
if (primaryColorInstance.hsv.s * 100 < primaryMinSaturation) {
text += ` 饱和度建议不低于${primaryMinSaturation}(现在 ${(
primaryColorInstance.hsv.s * 100
).toFixed(2)})`;
}
if (primaryColorInstance.hsv.v * 100 < primaryMinBrightness) {
text += ` 亮度建议不低于${primaryMinBrightness}(现在 ${(
primaryColorInstance.hsv.v * 100
).toFixed(2)})`;
}
}
return (
<span className="color-palette-picker-validation color-palette-picker-validation-dark">
{text.trim()}
</span>
);
}

render() {
const { primaryColor, backgroundColor } = this.state;
return (
<div className="color-palette-horizontal color-palette-horizontal-dark">
<div className="main-color">
<ColorPatterns color={primaryColor} dark backgroundColor={backgroundColor} />
</div>
<div className="color-palette-picker">
<Row>
<Col span={12}>
<div className="color-palette-pick">
<FormattedMessage id="app.docs.color.pick-primary" />
</div>
<span style={{ display: 'inline-block', verticalAlign: 'middle' }}>
<Row>
<Col span={18}>
<ColorPicker
type="chrome"
color={primaryColor}
onChange={this.handleChangeColor}
/>
</Col>
<Col span={6}>
<span className="color-palette-pick-hex">{primaryColor}</span>
</Col>
</Row>
</span>
</Col>
<Col span={12}>
<div className="color-palette-pick">
<FormattedMessage id="app.docs.color.pick-background" />
</div>
<span style={{ display: 'inline-block', verticalAlign: 'middle' }}>
<Row>
<Col span={18}>
<ColorPicker
type="chrome"
color={backgroundColor}
onChange={this.handleChangeBackgroundColor}
/>
</Col>
<Col span={6}>
<span className="color-palette-pick-hex">{backgroundColor}</span>
</Col>
</Row>
</span>
</Col>
</Row>
{this.renderColorValidation()}
</div>
</div>
);
}
}
94 changes: 94 additions & 0 deletions .dumi/theme/common/Color/ColorPalettes.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import React from 'react';
import cls from 'classnames';
import Palette from './Palette';

const ColorPalettes = props => {
const { dark } = props;

const colors = [
{
name: 'red',
english: 'Dust Red',
chinese: '薄暮',
description: '斗志、奔放',
},
{
name: 'volcano',
english: 'Volcano',
chinese: '火山',
description: '醒目、澎湃',
},
{
name: 'orange',
english: 'Sunset Orange',
chinese: '日暮',
description: '温暖、欢快',
},
{
name: 'gold',
english: 'Calendula Gold',
chinese: '金盏花',
description: '活力、积极',
},
{
name: 'yellow',
english: 'Sunrise Yellow',
chinese: '日出',
description: '出生、阳光',
},
{
name: 'lime',
english: 'Lime',
chinese: '青柠',
description: '自然、生机',
},
{
name: 'green',
english: 'Polar Green',
chinese: '极光绿',
description: '健康、创新',
},
{
name: 'cyan',
english: 'Cyan',
chinese: '明青',
description: '希望、坚强',
},
{
name: 'blue',
english: 'Daybreak Blue',
chinese: '拂晓蓝',
description: '包容、科技、普惠',
},
{
name: 'geekblue',
english: 'Geek Blue',
chinese: '极客蓝',
description: '探索、钻研',
},
{
name: 'purple',
english: 'Golden Purple',
chinese: '酱紫',
description: '优雅、浪漫',
},
{
name: 'magenta',
english: 'Magenta',
chinese: '法式洋红',
description: '明快、感性',
},
];
const colorCls = cls('color-palettes', {
'color-palettes-dark': !!dark,
});
return (
<div className={colorCls}>
{colors.map(color => (
<Palette key={color.name} color={color} dark={dark} showTitle />
))}
</div>
);
};

export default ColorPalettes;
11 changes: 11 additions & 0 deletions .dumi/theme/common/Color/ColorPatterns.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';
import { generate } from '@ant-design/colors';
import uniq from 'lodash/uniq';
import ColorBlock from './ColorBlock';

export default function ColorPatterns({ color, dark, backgroundColor }) {
const colors = generate(color, dark ? { theme: 'dark', backgroundColor } : {});
return uniq(colors).map((colorString, i) => (
<ColorBlock color={colorString} index={i + 1} dark={dark} key={colorString} />
));
}
Loading

0 comments on commit fab90b0

Please sign in to comment.