-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e4af172
commit 273246e
Showing
8 changed files
with
9,088 additions
and
18 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,59 @@ | ||
import { FC } from 'react'; | ||
import { MdxFieldProps, UncontrolledMdxField } from '@atsnek/jaen-fields-mdx'; | ||
import { mdxEditorComponents } from './MdxEditor'; | ||
import Heading from '../main-content/heading/components/Heading'; | ||
import { Stack, chakra } from '@chakra-ui/react'; | ||
import { text } from 'stream/consumers'; | ||
import TabsTemplate from './TabsTemplate'; | ||
|
||
const svgEditorComponents: MdxFieldProps['components'] = { | ||
// include all svg components | ||
svg: props => <chakra.svg children={props.children} />, | ||
style: props => <style children={props.children} />, | ||
defs: props => <defs children={props.children} />, | ||
mask: props => <mask children={props.children} />, | ||
path: props => <path children={props.children} />, | ||
text: props => <text children={props.children} />, | ||
rect: props => <rect children={props.children} />, | ||
g: props => <g children={props.children} />, | ||
circle: props => <circle children={props.children} />, | ||
polygon: props => <polygon children={props.children} />, | ||
line: props => <line children={props.children} />, | ||
}; | ||
|
||
delete svgEditorComponents.Filesystem; | ||
delete svgEditorComponents.DocsIndex; | ||
delete svgEditorComponents.ImageCard; | ||
delete svgEditorComponents.Image; | ||
|
||
interface ICodeMdxEditorProps | ||
extends Omit<Parameters<typeof UncontrolledMdxField>[0], 'components'> {} | ||
|
||
/** | ||
* Standalone MDX editor without automatic loading/saving by Jaen. | ||
*/ | ||
const CodeMdxEditor: FC<ICodeMdxEditorProps> = ({ | ||
...props | ||
}) => { | ||
return ( | ||
<Stack | ||
pt={14} | ||
sx={{ | ||
'.cm-editor': { | ||
height: '60dvh' | ||
} | ||
}} | ||
> | ||
<UncontrolledMdxField | ||
{...props} | ||
tabsTemplate={TabsTemplate} | ||
components={{ | ||
wrapper: ({ children }) => <Stack>{children}</Stack>, | ||
...svgEditorComponents | ||
}} | ||
/> | ||
</Stack> | ||
); | ||
}; | ||
|
||
export default CodeMdxEditor; |
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,89 @@ | ||
import {AddIcon} from '@chakra-ui/icons' | ||
import { | ||
Box, | ||
Button, | ||
Menu, | ||
MenuButton, | ||
MenuItem, | ||
MenuList, | ||
Spacer, | ||
Tab, | ||
TabList, | ||
TabPanel, | ||
TabPanels, | ||
Tabs | ||
} from '@chakra-ui/react' | ||
import React, {useState} from 'react' | ||
|
||
interface ComponentInfoProps { | ||
items: Array<{ | ||
label: string | ||
onClick: () => void | ||
}> | ||
} | ||
|
||
export const ComponentInfo: React.FC<ComponentInfoProps> = ({items}) => ( | ||
<Menu> | ||
{/* <MenuButton | ||
as={Button} | ||
leftIcon={<AddIcon />} | ||
size="sm" | ||
variant="link" | ||
mx="2"> | ||
Components | ||
</MenuButton> */} | ||
|
||
<MenuList> | ||
{items.map(item => ( | ||
<MenuItem key={item.label} onClick={item.onClick}> | ||
{item.label} | ||
</MenuItem> | ||
))} | ||
</MenuList> | ||
</Menu> | ||
) | ||
|
||
export interface TabsProps { | ||
tabs: Array<{ | ||
label: React.ReactNode | ||
content: React.ReactNode | ||
}> | ||
selectedTab: number | ||
componentsInfo?: ComponentInfoProps['items'] | ||
} | ||
|
||
const TabsTemplate: React.FC<TabsProps> = props => { | ||
const [selectedTab, setSelectedTab] = useState(props.selectedTab) | ||
|
||
const handleTabChange = (index: number) => { | ||
setSelectedTab(index) | ||
} | ||
|
||
return ( | ||
<Box position="relative"> | ||
<Tabs | ||
index={selectedTab} | ||
onChange={handleTabChange} | ||
pos="relative" | ||
size="sm"> | ||
<TabList pos="sticky" top="0" zIndex="1"> | ||
{props.tabs.map((tab, i) => ( | ||
<Tab key={i}>{tab.label}</Tab> | ||
))} | ||
<Spacer /> | ||
<ComponentInfo items={props.componentsInfo || []} /> | ||
</TabList> | ||
|
||
<TabPanels> | ||
{props.tabs.map((tab, i) => ( | ||
<TabPanel key={i} p="0"> | ||
{tab.content} | ||
</TabPanel> | ||
))} | ||
</TabPanels> | ||
</Tabs> | ||
</Box> | ||
) | ||
} | ||
|
||
export default TabsTemplate |
Oops, something went wrong.