|
1 | | -import { IntersectionLoad } from '@/components/LazyLoad'; |
2 | 1 | import { createStyles } from 'antd-style'; |
3 | 2 | import { IPreviewerProps } from 'dumi/dist/client/theme-api/types'; |
4 | 3 | import Previewer from 'dumi/theme-default/builtins/Previewer'; |
5 | 4 | import { rgba } from 'polished'; |
6 | | -import { useMemo } from 'react'; |
7 | 5 |
|
8 | | -const useStyles = createStyles(({ css, token, prefixCls }, { center, nopadding }: any) => { |
| 6 | +const useStyles = createStyles(({ css, token, prefixCls }) => { |
9 | 7 | return { |
| 8 | + center: css` |
| 9 | + .dumi-default-previewer-demo { |
| 10 | + display: flex; |
| 11 | + align-items: center; |
| 12 | + justify-content: center; |
| 13 | + } |
| 14 | + `, |
| 15 | + nopadding: css` |
| 16 | + .dumi-default-previewer-demo { |
| 17 | + padding: 0; |
| 18 | + } |
| 19 | + `, |
10 | 20 | container: css` |
11 | 21 | .dumi-default-previewer { |
12 | | - border-color: ${token.colorBorderSecondary}; |
| 22 | + overflow: hidden; |
13 | 23 | display: flex; |
14 | 24 | flex-direction: column; |
15 | | - overflow: hidden; |
| 25 | + border-color: ${token.colorBorderSecondary}; |
16 | 26 | &-demo { |
17 | 27 | flex: 1; |
18 | | - ${nopadding && |
19 | | - css` |
20 | | - padding: 0; |
21 | | - `} |
22 | | - ${center && |
23 | | - css` |
24 | | - display: flex; |
25 | | - align-items: center; |
26 | | - justify-content: center; |
27 | | - `} |
28 | 28 |
|
29 | 29 | &[data-iframe]::before { |
30 | 30 | background: ${token.colorFillContent}; |
31 | 31 | } |
32 | 32 | } |
33 | 33 |
|
34 | 34 | &-meta { |
35 | | - border-color: ${token.colorBorderSecondary}; |
36 | 35 | flex: 1; |
| 36 | + border-color: ${token.colorBorderSecondary}; |
37 | 37 |
|
38 | 38 | .${prefixCls}-highlighter { |
39 | 39 | pre { |
@@ -134,24 +134,19 @@ export interface PreviewerProps extends IPreviewerProps { |
134 | 134 | nopadding?: boolean; |
135 | 135 | } |
136 | 136 |
|
137 | | -export default (props: IPreviewerProps) => { |
138 | | - const { styles, cx } = useStyles(props); |
139 | | - |
140 | | - const height = useMemo(() => { |
141 | | - if (typeof props.iframe === 'number') { |
142 | | - return props.iframe; |
143 | | - } |
144 | | - if (props.height) { |
145 | | - return props.height; |
146 | | - } |
147 | | - return 300; |
148 | | - }, [props.iframe, props.height]); |
| 137 | +export default ({ center, codePlacement, nopadding, ...props }: PreviewerProps) => { |
| 138 | + const { styles, cx } = useStyles(); |
149 | 139 |
|
150 | 140 | return ( |
151 | | - <div className={cx(styles.container, styles[props.codePlacement as 'left' | 'right' | 'top'])}> |
152 | | - <IntersectionLoad height={height} elementType="section"> |
153 | | - <Previewer {...props} /> |
154 | | - </IntersectionLoad> |
| 141 | + <div |
| 142 | + className={cx( |
| 143 | + styles.container, |
| 144 | + center && styles.center, |
| 145 | + nopadding && styles.nopadding, |
| 146 | + styles[codePlacement as 'left' | 'right' | 'top'], |
| 147 | + )} |
| 148 | + > |
| 149 | + <Previewer {...props} /> |
155 | 150 | </div> |
156 | 151 | ); |
157 | 152 | }; |
0 commit comments