forked from ant-design/ant-design
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* docs: live demo * chore: bump dumi * chore: fix lint * chore: fix lint * chore: update demo * chore: bump dumi * docs: enhance live demo * docs: update text
- Loading branch information
Showing
18 changed files
with
193 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import type { FC } from 'react'; | ||
import React, { useEffect, useState } from 'react'; | ||
import { createStyles } from 'antd-style'; | ||
import LiveEditor from '../slots/LiveEditor'; | ||
import LiveError from '../slots/LiveError'; | ||
import { EditFilled } from '@ant-design/icons'; | ||
import { Tooltip } from 'antd'; | ||
import useLocale from '../../hooks/useLocale'; | ||
|
||
const useStyle = createStyles(({ token, css }) => { | ||
const { colorPrimaryBorder, colorIcon, colorPrimary } = token; | ||
|
||
return { | ||
editor: css` | ||
.npm__react-simple-code-editor__textarea { | ||
outline: none; | ||
&:hover { | ||
border: 1px solid ${colorPrimaryBorder} !important; | ||
} | ||
&:focus { | ||
border: 1px solid ${colorPrimary} !important; | ||
} | ||
} | ||
`, | ||
|
||
editableIcon: css` | ||
position: absolute; | ||
height: 32px; | ||
width: 32px; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
top: 16px; | ||
inset-inline-end: 56px; | ||
color: ${colorIcon}; | ||
`, | ||
}; | ||
}); | ||
|
||
const locales = { | ||
cn: { | ||
demoEditable: '编辑 Demo 可实时预览', | ||
}, | ||
en: { | ||
demoEditable: 'Edit demo with real-time preview', | ||
}, | ||
}; | ||
|
||
const HIDE_LIVE_DEMO_TIP = 'hide-live-demo-tip'; | ||
|
||
const LiveCode: FC = () => { | ||
const [open, setOpen] = useState(false); | ||
const { styles } = useStyle(); | ||
const [locale] = useLocale(locales); | ||
|
||
useEffect(() => { | ||
const shouldOpen = !localStorage.getItem(HIDE_LIVE_DEMO_TIP); | ||
if (shouldOpen) { | ||
setOpen(true); | ||
} | ||
}, []); | ||
|
||
const handleOpenChange = (newOpen: boolean) => { | ||
setOpen(newOpen); | ||
if (!newOpen) { | ||
localStorage.setItem(HIDE_LIVE_DEMO_TIP, 'true'); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<div className={styles.editor}> | ||
<LiveEditor /> | ||
<LiveError /> | ||
</div> | ||
<Tooltip title={locale.demoEditable} open={open} onOpenChange={handleOpenChange}> | ||
<EditFilled className={styles.editableIcon} /> | ||
</Tooltip> | ||
</> | ||
); | ||
}; | ||
|
||
export default LiveCode; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { FC } from 'react'; | ||
import React from 'react'; | ||
import DumiLiveEditor from 'dumi/theme-default/slots/LiveEditor'; | ||
|
||
const LiveEditor: FC = () => ( | ||
<DumiLiveEditor | ||
style={{ | ||
fontSize: 13, | ||
lineHeight: 2, | ||
fontFamily: `'Lucida Console', Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace`, | ||
}} | ||
padding={{ | ||
top: 12, | ||
right: 16, | ||
bottom: 12, | ||
left: 16, | ||
}} | ||
/> | ||
); | ||
|
||
export default LiveEditor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { FC } from 'react'; | ||
import React, { useContext } from 'react'; | ||
import { LiveContext } from 'dumi'; | ||
import { Alert, theme } from 'antd'; | ||
|
||
const LiveError: FC = () => { | ||
const { error } = useContext(LiveContext); | ||
const { token } = theme.useToken(); | ||
|
||
return error ? ( | ||
<Alert banner type="error" message={error} style={{ color: token.colorError }} /> | ||
) : null; | ||
}; | ||
|
||
export default LiveError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.