Skip to content

Commit

Permalink
revert: default previewer changes in (#1282)
Browse files Browse the repository at this point in the history
  • Loading branch information
PeachScript committed Nov 20, 2022
1 parent 6defb8c commit 560c4d4
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 107 deletions.
12 changes: 0 additions & 12 deletions src/client/theme-api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,6 @@ export interface IThemeConfig {
nav?: (INavItem & { children?: INavItem[] })[];
sidebar?: Record<string, ISidebarGroup[]>;
footer?: string;
/**
* hd solution configurations
* @note base on https://github.com/umijs/umi-hd
*/
hd: {
rules: {
minWidth?: number;
maxWidth?: number;
mode: 'vl' | 'flex' | 'vw' | 'vh';
options?: number | [number, number];
}[];
};
[key: string]: any;
}

Expand Down
31 changes: 0 additions & 31 deletions src/client/theme-default/builtins/Previewer/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@

&-meta {
border-top: 1px solid @c-border-light;
// h5 mode
&[data-h5] {
border-style: none;
}
}

&-desc {
Expand Down Expand Up @@ -133,31 +129,4 @@
box-shadow: 0 0 0 4px fade(@c-warning, 10%);
}
}

// h5 mode
&[data-h5] {
border-style: none;
}

&-flex {
display: flex;
height: 700px;
margin-bottom: 24px;
width: 100%;
justify-content: flex-start;
align-items: stretch;
border-radius: 12px;
overflow: hidden;
border: 1px solid #e6e6e6;
@media only screen and (max-width: 1440px) {
height: 600px;
}
@media only screen and (max-width: 960px) {
height: 500px;
}

&-actions {
flex: 1;
}
}
}
63 changes: 23 additions & 40 deletions src/client/theme-default/builtins/Previewer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,48 +1,40 @@
import { IPreviewerProps, useLocation, useSiteData } from 'dumi';
import Device from 'dumi/theme/slots/Device';
import { IPreviewerProps, useLocation } from 'dumi';
import PreviewerActions from 'dumi/theme/slots/PreviewerActions';
import React, { type FC } from 'react';
import './index.less';

const Previewer: FC<IPreviewerProps> = (props) => {
const { hash } = useLocation();
const link = `#${props.asset.id}`;
const {
themeConfig: { hd },
} = useSiteData();
const isH5 = !!hd;

return (
<div
id={props.asset.id}
className="dumi-default-previewer"
data-debug={props.debug}
data-active={hash === link || undefined}
data-h5={isH5}
>
{!isH5 && (
<div
className="dumi-default-previewer-demo"
style={{ background: props.background }}
data-compact={props.compact || undefined}
data-transform={props.transform || undefined}
data-iframe={props.iframe || undefined}
>
{props.iframe ? (
<iframe
style={
['string', 'number'].includes(typeof props.iframe)
? { height: Number(props.iframe) }
: {}
}
src={props.demoUrl}
></iframe>
) : (
props.children
)}
</div>
)}
<div className="dumi-default-previewer-meta" data-h5={isH5}>
<div
className="dumi-default-previewer-demo"
style={{ background: props.background }}
data-compact={props.compact || undefined}
data-transform={props.transform || undefined}
data-iframe={props.iframe || undefined}
>
{props.iframe ? (
<iframe
style={
['string', 'number'].includes(typeof props.iframe)
? { height: Number(props.iframe) }
: {}
}
src={props.demoUrl}
></iframe>
) : (
props.children
)}
</div>
<div className="dumi-default-previewer-meta">
{(props.title || props.debug) && (
<div className="dumi-default-previewer-desc">
<h5>
Expand All @@ -59,16 +51,7 @@ const Previewer: FC<IPreviewerProps> = (props) => {
)}
</div>
)}

{!isH5 && <PreviewerActions {...props} />}
{isH5 && (
<div className="dumi-default-previewer-flex">
<div className="dumi-default-previewer-flex-actions">
<PreviewerActions {...props} />
</div>
<Device url={props.demoUrl} />
</div>
)}
<PreviewerActions {...props} />
</div>
</div>
);
Expand Down
1 change: 0 additions & 1 deletion src/client/theme-default/builtins/SourceCode/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

&-copy {
position: absolute;
z-index: 1;
top: 9px;
right: 12px;
display: inline-block;
Expand Down
4 changes: 0 additions & 4 deletions src/client/theme-default/slots/Content/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
color: @c-primary;
}

img {
max-width: 100%;
}

// inline code
*:not(pre) code {
padding: 2px 5px;
Expand Down
1 change: 0 additions & 1 deletion src/client/theme-default/slots/Device/index.tsx

This file was deleted.

29 changes: 11 additions & 18 deletions src/client/theme-default/slots/PreviewerActions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
openCodeSandbox,
openStackBlitz,
useIntl,
useSiteData,
type IPreviewerProps,
} from 'dumi';
import SourceCode from 'dumi/theme/builtins/SourceCode';
Expand Down Expand Up @@ -45,12 +44,8 @@ const PreviewerActions: FC<IPreviewerActionsProps> = (props) => {
const files = Object.entries(props.asset.dependencies).filter(
([, { type }]) => type === 'FILE',
);
const {
themeConfig: { hd },
} = useSiteData();
const isH5 = !!hd;
const [activeKey, setActiveKey] = useState(0);
const [showCode, setShowCode] = useState(isH5);
const [showCode, setShowCode] = useState(false);
const isSingleFile = files.length === 1;
const lang = (files[activeKey][0].match(/\.([^.]+)$/)?.[1] || 'text') as any;

Expand Down Expand Up @@ -107,18 +102,16 @@ const PreviewerActions: FC<IPreviewerActionsProps> = (props) => {
</a>
)}
<PreviewerActionsExtra {...props} />
{!isH5 && (
<button
className="dumi-default-previewer-action-btn"
type="button"
onClick={() => setShowCode((prev) => !prev)}
data-dumi-tooltip={intl.formatMessage({
id: `previewer.actions.code.${showCode ? 'shrink' : 'expand'}`,
})}
>
{showCode ? <IconCodeExpand /> : <IconCode />}
</button>
)}
<button
className="dumi-default-previewer-action-btn"
type="button"
onClick={() => setShowCode((prev) => !prev)}
data-dumi-tooltip={intl.formatMessage({
id: `previewer.actions.code.${showCode ? 'shrink' : 'expand'}`,
})}
>
{showCode ? <IconCodeExpand /> : <IconCode />}
</button>
</div>
{showCode && (
<>
Expand Down

0 comments on commit 560c4d4

Please sign in to comment.