-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'refactor/generic-cms-text' into feature/cms-upload-form…
…-xlsx
- Loading branch information
Showing
6 changed files
with
182 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { observer } from 'mobx-react-lite'; | ||
import { CmsTextContext, useFirstCmsTextDocumentIfExists } from '@tdev-components/documents/CmsText/shared'; | ||
import React from 'react'; | ||
import CodeBlock, { Props as CodeBlockProps } from '@theme/CodeBlock'; | ||
import PermissionsPanel from '@tdev-components/PermissionsPanel'; | ||
import { Props as DefaultCmsProps } from '..'; | ||
import styles from './styles.module.scss'; | ||
import clsx from 'clsx'; | ||
|
||
interface Props extends DefaultCmsProps { | ||
codeBlockProps?: CodeBlockProps; | ||
} | ||
|
||
const CmsCode = observer((props: Props) => { | ||
const { id, name, showPermissionsPanel } = props; | ||
const contextId = name ? React.useContext(CmsTextContext)?.entries[name] : undefined; | ||
const rootId = id || contextId; | ||
const cmsText = useFirstCmsTextDocumentIfExists(rootId); | ||
if (!cmsText || !cmsText.canDisplay) { | ||
return showPermissionsPanel && rootId ? <PermissionsPanel documentRootId={rootId} /> : null; | ||
} | ||
if (showPermissionsPanel && rootId) { | ||
return ( | ||
<div className={clsx(styles.container, props.codeBlockProps?.title && styles.withTitle)}> | ||
<PermissionsPanel documentRootId={rootId} className={clsx(styles.codeBlock)} /> | ||
<CodeBlock {...(props.codeBlockProps || {})}>{cmsText.text}</CodeBlock> | ||
</div> | ||
); | ||
} | ||
|
||
return <CodeBlock {...(props.codeBlockProps || {})}>{cmsText.text}</CodeBlock>; | ||
}); | ||
|
||
export default CmsCode; |
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,18 @@ | ||
.container { | ||
.codeBlock { | ||
align-self: flex-end; | ||
} | ||
&:not(.withTitle) { | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
&.withTitle { | ||
position: relative; | ||
.codeBlock { | ||
z-index: var(--ifm-z-index-dropdown); | ||
position: absolute; | ||
right: 0; | ||
top: 0; | ||
} | ||
} | ||
} |
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