Skip to content

Commit

Permalink
Merge pull request ant-design#45271 from ant-design/master
Browse files Browse the repository at this point in the history
chore: feature merge master
  • Loading branch information
zombieJ authored Oct 12, 2023
2 parents bef9539 + 70ce748 commit 012e878
Show file tree
Hide file tree
Showing 37 changed files with 688 additions and 384 deletions.
4 changes: 3 additions & 1 deletion .dumi/pages/index/components/Theme/ColorPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const useStyle = createStyles(({ token, css }) => ({
}));

export interface ColorPickerProps {
id?: string;
children?: React.ReactNode;
value?: string | Color;
onChange?: (value?: Color | string) => void;
Expand Down Expand Up @@ -66,7 +67,7 @@ const DebouncedColorPicker: React.FC<ColorPickerProps> = (props) => {
);
};

const ThemeColorPicker: React.FC<ColorPickerProps> = ({ value, onChange }) => {
const ThemeColorPicker: React.FC<ColorPickerProps> = ({ value, onChange, id }) => {
const { styles } = useStyle();

const matchColors = React.useMemo(() => {
Expand Down Expand Up @@ -95,6 +96,7 @@ const ThemeColorPicker: React.FC<ColorPickerProps> = ({ value, onChange }) => {
value={typeof value === 'string' ? value : value?.toHexString()}
onChange={(event) => onChange?.(event.target.value)}
style={{ width: 120 }}
id={id}
/>

<Space size="middle">
Expand Down
6 changes: 4 additions & 2 deletions .dumi/pages/index/components/Theme/RadiusPicker.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React from 'react';
import { InputNumber, Space, Slider } from 'antd';
import { InputNumber, Slider, Space } from 'antd';

export interface RadiusPickerProps {
id?: string;
value?: number;
onChange?: (value: number | null) => void;
}

export default function RadiusPicker({ value, onChange }: RadiusPickerProps) {
export default function RadiusPicker({ value, onChange, id }: RadiusPickerProps) {
return (
<Space size="large">
<InputNumber
Expand All @@ -16,6 +17,7 @@ export default function RadiusPicker({ value, onChange }: RadiusPickerProps) {
min={0}
formatter={(val) => `${val}px`}
parser={(str) => (str ? parseFloat(str) : (str as any))}
id={id}
/>

<Slider
Expand Down
81 changes: 44 additions & 37 deletions .dumi/pages/index/components/Theme/ThemePicker.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { createStyles, useTheme } from 'antd-style';
import * as React from 'react';
import classNames from 'classnames';
import { Space } from 'antd';
import { createStyles, useTheme } from 'antd-style';
import classNames from 'classnames';

import useLocale from '../../../../hooks/useLocale';

export const THEMES = {
Expand Down Expand Up @@ -33,56 +34,62 @@ const locales = {

const useStyle = createStyles(({ token, css }) => ({
themeCard: css`
border-radius: ${token.borderRadius}px;
cursor: pointer;
transition: all ${token.motionDurationSlow};
overflow: hidden;
display: inline-block;
& > input[type="radio"] {
width: 0;
height: 0;
opacity: 0;
position: absolute;
}
img {
vertical-align: top;
box-shadow: 0 3px 6px -4px rgba(0, 0, 0, 0.12), 0 6px 16px 0 rgba(0, 0, 0, 0.08),
0 9px 28px 8px rgba(0, 0, 0, 0.05);
}
&:focus-within,
&:hover {
transform: scale(1.04);
}
`,
border-radius: ${token.borderRadius}px;
cursor: pointer;
transition: all ${token.motionDurationSlow};
overflow: hidden;
display: inline-block;
& > input[type='radio'] {
width: 0;
height: 0;
opacity: 0;
position: absolute;
}
img {
vertical-align: top;
box-shadow:
0 3px 6px -4px rgba(0, 0, 0, 0.12),
0 6px 16px 0 rgba(0, 0, 0, 0.08),
0 9px 28px 8px rgba(0, 0, 0, 0.05);
}
&:focus-within,
&:hover {
transform: scale(1.04);
}
`,

themeCardActive: css`
box-shadow: 0 0 0 1px ${token.colorBgContainer},
0 0 0 ${token.controlOutlineWidth * 2 + 1}px ${token.colorPrimary};
&,
&:hover:not(:focus-within) {
transform: scale(1);
}
`,
box-shadow:
0 0 0 1px ${token.colorBgContainer},
0 0 0 ${token.controlOutlineWidth * 2 + 1}px ${token.colorPrimary};
&,
&:hover:not(:focus-within) {
transform: scale(1);
}
`,
}));

export interface ThemePickerProps {
id?: string;
value?: string;
onChange?: (value: string) => void;
}

export default function ThemePicker({ value, onChange }: ThemePickerProps) {
export default function ThemePicker(props: ThemePickerProps) {
const { value, onChange, id } = props;

const token = useTheme();
const { styles } = useStyle();

const [locale] = useLocale(locales);

return (
<Space size={token.paddingLG}>
{Object.keys(THEMES).map((theme) => {
{Object.keys(THEMES).map((theme, index) => {
const url = THEMES[theme as THEME];

return (
Expand All @@ -94,7 +101,7 @@ export default function ThemePicker({ value, onChange }: ThemePickerProps) {
onChange?.(theme);
}}
>
<input type="radio" name="theme" />
<input type="radio" name="theme" id={index === 0 ? id : null} />
<img src={url} alt={theme} />
</label>
<span>{locale[theme as keyof typeof locale]}</span>
Expand Down
19 changes: 14 additions & 5 deletions .dumi/pages/index/components/Theme/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -534,11 +534,20 @@ export default function Theme() {
<Form.Item label={locale.titleBorderRadius} name="borderRadius">
<RadiusPicker />
</Form.Item>
<Form.Item label={locale.titleCompact} name="compact">
<Radio.Group>
<Radio value="default">{locale.default}</Radio>
<Radio value="compact">{locale.compact}</Radio>
</Radio.Group>
<Form.Item label={locale.titleCompact} name="compact" htmlFor="compact_default">
<Radio.Group
options={[
{
label: locale.default,
value: 'default',
id: 'compact_default',
},
{
label: locale.compact,
value: 'compact',
},
]}
/>
</Form.Item>
</Form>
</Card>
Expand Down
9 changes: 5 additions & 4 deletions .dumi/theme/builtins/Previewer/CodePreviewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import classNames from 'classnames';
import { FormattedMessage, useSiteData } from 'dumi';
import LZString from 'lz-string';

import type { AntdPreviewerProps } from '.';
import type { AntdPreviewerProps } from './Previewer';
import useLocation from '../../../hooks/useLocation';
import BrowserFrame from '../../common/BrowserFrame';
import ClientOnly from '../../common/ClientOnly';
Expand Down Expand Up @@ -171,7 +171,6 @@ const CodePreviewer: React.FC<AntdPreviewerProps> = (props) => {
});

const localizedTitle = title;
const introChildren = <div dangerouslySetInnerHTML={{ __html: description }} />;
const highlightClass = classNames('highlight-wrapper', {
'highlight-wrapper-expand': codeExpand,
});
Expand Down Expand Up @@ -205,7 +204,7 @@ const CodePreviewer: React.FC<AntdPreviewerProps> = (props) => {

const suffix = codeType === 'tsx' ? 'tsx' : 'js';

const dependencies: Record<PropertyKey, string> = jsx.split('\n').reduce(
const dependencies = (jsx as string).split('\n').reduce<Record<PropertyKey, string>>(
(acc, line) => {
const matches = line.match(/import .+? from '(.+)';$/);
if (matches?.[1]) {
Expand Down Expand Up @@ -377,7 +376,9 @@ createRoot(document.getElementById('container')).render(<Demo />);
</Tooltip>
<EditButton title={<FormattedMessage id="app.content.edit-demo" />} filename={filename} />
</div>
<div className="code-box-description">{introChildren}</div>
{description && (
<div className="code-box-description" dangerouslySetInnerHTML={{ __html: description }} />
)}
<Space wrap size="middle" className="code-box-actions">
{showOnlineUrl && (
<Tooltip title={<FormattedMessage id="app.demo.online" />}>
Expand Down
12 changes: 10 additions & 2 deletions .dumi/theme/layouts/DocLayout/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import classNames from 'classnames';
import dayjs from 'dayjs';
import 'dayjs/locale/zh-cn';
import { Helmet, useOutlet } from 'dumi';
import { Helmet, useOutlet, useSiteData } from 'dumi';
import React, { useContext, useEffect, useLayoutEffect, useMemo, useRef } from 'react';
import zhCN from 'antd/es/locale/zh_CN';
import ConfigProvider from 'antd/es/config-provider';
Expand Down Expand Up @@ -30,10 +30,11 @@ const locales = {
const DocLayout: React.FC = () => {
const outlet = useOutlet();
const location = useLocation();
const { pathname, search } = location;
const { pathname, search, hash } = location;
const [locale, lang] = useLocale(locales);
const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
const { direction } = useContext(SiteContext);
const { loading } = useSiteData();

useLayoutEffect(() => {
if (lang === 'cn') {
Expand All @@ -52,6 +53,13 @@ const DocLayout: React.FC = () => {
}
}, []);

// handle hash change or visit page hash from Link component, and jump after async chunk loaded
useEffect(() => {
const id = hash.replace('#', '');

if (id) document.getElementById(decodeURIComponent(id))?.scrollIntoView();
}, [loading, hash]);

useEffect(() => {
if (typeof (window as any).ga !== 'undefined') {
(window as any).ga('send', 'pageview', pathname + search);
Expand Down
96 changes: 0 additions & 96 deletions .github/workflows/preview-build.yml

This file was deleted.

Loading

0 comments on commit 012e878

Please sign in to comment.