-
Notifications
You must be signed in to change notification settings - Fork 839
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EUI+] Initial typography and doc content updates (#7848)
- Loading branch information
Showing
17 changed files
with
426 additions
and
25 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
packages/docusaurus-theme/src/components/call_out/index.tsx
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,81 @@ | ||
import { css } from '@emotion/react'; | ||
import { EuiText, useEuiMemoizedStyles, UseEuiTheme } from '@elastic/eui'; | ||
import { FunctionComponent, PropsWithChildren } from 'react'; | ||
|
||
type VARIANTS = 'info' | 'tip' | 'note' | 'danger' | 'warning'; | ||
type TEXT_COLORS = 'primaryText' | 'successText' | 'dangerText' | 'warningText'; | ||
|
||
const VARIANT_TO_COLOR_MAP: Record< | ||
VARIANTS, | ||
{ backgroundVariable: string; colorKey: TEXT_COLORS } | ||
> = { | ||
info: { | ||
backgroundVariable: 'var(--eui-background-color-primary)', | ||
colorKey: 'primaryText', | ||
}, | ||
note: { | ||
backgroundVariable: 'var(--eui-background-color-primary)', | ||
colorKey: 'primaryText', | ||
}, | ||
tip: { | ||
backgroundVariable: 'var(--eui-background-color-success)', | ||
colorKey: 'successText', | ||
}, | ||
danger: { | ||
backgroundVariable: 'var(--eui-background-color-danger)', | ||
colorKey: 'dangerText', | ||
}, | ||
warning: { | ||
backgroundVariable: 'var(--eui-background-color-warning)', | ||
colorKey: 'warningText', | ||
}, | ||
}; | ||
|
||
const getStyles = ({ euiTheme }: UseEuiTheme, variant: VARIANTS) => { | ||
const colorKey = VARIANT_TO_COLOR_MAP[variant].colorKey; | ||
const color = euiTheme.colors[colorKey]; | ||
|
||
return { | ||
note: css` | ||
&:not(:last-of-type) { | ||
margin-block-end: ${euiTheme.size.m}; | ||
} | ||
.alert { | ||
--ifm-alert-background-color: ${VARIANT_TO_COLOR_MAP[variant] | ||
.backgroundVariable}; | ||
--ifm-alert-foreground-color: ${euiTheme.colors.text}; | ||
--ifm-alert-padding-horizontal: ${euiTheme.size.base}; | ||
--ifm-alert-padding-vertical: ${euiTheme.size.base}; | ||
--ifm-alert-border-width: ${euiTheme.border.width.thin}; | ||
--ifm-alert-border-left-width: ${euiTheme.border.width.thin}; | ||
--ifm-alert-border-color: ${color}; | ||
[class^='admonitionHeading'] { | ||
--ifm-alert-foreground-color: ${color}; | ||
color: var(--ifm-alert-foreground-color); | ||
} | ||
} | ||
`, | ||
}; | ||
}; | ||
|
||
type CallOutProps = PropsWithChildren & { | ||
variant: VARIANTS; | ||
}; | ||
|
||
export const CallOut: FunctionComponent<CallOutProps> = ({ | ||
children, | ||
variant, | ||
}) => { | ||
const styles = useEuiMemoizedStyles((euiTheme) => | ||
getStyles(euiTheme, variant) | ||
); | ||
|
||
return ( | ||
<EuiText size="s" css={styles.note}> | ||
{children} | ||
</EuiText> | ||
); | ||
}; |
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
16 changes: 16 additions & 0 deletions
16
packages/docusaurus-theme/src/theme/Admonition/Type/Danger.tsx
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,16 @@ | ||
import OriginalDanger from '@theme-init/Admonition/Type/Danger'; | ||
import type WarningType from '@theme-init/Admonition/Type/Danger'; | ||
import type { WrapperProps } from '@docusaurus/types'; | ||
import { CallOut } from '../../../components/call_out'; | ||
|
||
type Props = WrapperProps<typeof WarningType>; | ||
|
||
const Danger = (props: Props): JSX.Element => { | ||
return ( | ||
<CallOut variant="danger"> | ||
<OriginalDanger {...props} /> | ||
</CallOut> | ||
); | ||
}; | ||
|
||
export default Danger; |
16 changes: 16 additions & 0 deletions
16
packages/docusaurus-theme/src/theme/Admonition/Type/Info.tsx
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,16 @@ | ||
import OriginalInfo from '@theme-init/Admonition/Type/Info'; | ||
import type InfoType from '@theme-init/Admonition/Type/Info'; | ||
import type { WrapperProps } from '@docusaurus/types'; | ||
import { CallOut } from '../../../components/call_out'; | ||
|
||
type Props = WrapperProps<typeof InfoType>; | ||
|
||
const Note = (props: Props): JSX.Element => { | ||
return ( | ||
<CallOut variant="info"> | ||
<OriginalInfo {...props} /> | ||
</CallOut> | ||
); | ||
}; | ||
|
||
export default Note; |
16 changes: 16 additions & 0 deletions
16
packages/docusaurus-theme/src/theme/Admonition/Type/Note.tsx
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,16 @@ | ||
import OriginalNote from '@theme-init/Admonition/Type/Note'; | ||
import type NoteType from '@theme-init/Admonition/Type/Note'; | ||
import type { WrapperProps } from '@docusaurus/types'; | ||
import { CallOut } from '../../../components/call_out'; | ||
|
||
type Props = WrapperProps<typeof NoteType>; | ||
|
||
const Note = (props: Props): JSX.Element => { | ||
return ( | ||
<CallOut variant="note"> | ||
<OriginalNote {...props} /> | ||
</CallOut> | ||
); | ||
}; | ||
|
||
export default Note; |
16 changes: 16 additions & 0 deletions
16
packages/docusaurus-theme/src/theme/Admonition/Type/Tip.tsx
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,16 @@ | ||
import OriginalTip from '@theme-init/Admonition/Type/Tip'; | ||
import type TipType from '@theme-init/Admonition/Type/Tip'; | ||
import type { WrapperProps } from '@docusaurus/types'; | ||
import { CallOut } from '../../../components/call_out'; | ||
|
||
type Props = WrapperProps<typeof TipType>; | ||
|
||
const Tip = (props: Props): JSX.Element => { | ||
return ( | ||
<CallOut variant="tip"> | ||
<OriginalTip {...props} /> | ||
</CallOut> | ||
); | ||
}; | ||
|
||
export default Tip; |
16 changes: 16 additions & 0 deletions
16
packages/docusaurus-theme/src/theme/Admonition/Type/Warning.tsx
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,16 @@ | ||
import OriginalWarning from '@theme-init/Admonition/Type/Warning'; | ||
import type WarningType from '@theme-init/Admonition/Type/Warning'; | ||
import type { WrapperProps } from '@docusaurus/types'; | ||
import { CallOut } from '../../../components/call_out'; | ||
|
||
type Props = WrapperProps<typeof WarningType>; | ||
|
||
const Warning = (props: Props): JSX.Element => { | ||
return ( | ||
<CallOut variant="warning"> | ||
<OriginalWarning {...props} /> | ||
</CallOut> | ||
); | ||
}; | ||
|
||
export default Warning; |
33 changes: 33 additions & 0 deletions
33
packages/docusaurus-theme/src/theme/DocItem/Content/index.tsx
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,33 @@ | ||
import OriginalContent from '@theme-init/DocItem/Content'; | ||
import type ContentType from '@theme-init/DocItem/Content'; | ||
import type { WrapperProps } from '@docusaurus/types'; | ||
import { useEuiMemoizedStyles, UseEuiTheme } from '@elastic/eui'; | ||
import { css } from '@emotion/react'; | ||
|
||
type Props = WrapperProps<typeof ContentType>; | ||
|
||
const getContentStyles = ({ euiTheme }: UseEuiTheme) => { | ||
return { | ||
content: css` | ||
// required specificity to apply styles | ||
.markdown header > h1 { | ||
--ifm-h1-font-size: 2.86rem; | ||
--ifm-h1-vertical-rhythm-bottom: 1.486; | ||
} | ||
`, | ||
}; | ||
}; | ||
|
||
/* OriginalContent holds the document title and markdown content | ||
NOTE: ejecting this results in an error due to using useDoc() hook outside of DocProvider | ||
https://github.com/facebook/docusaurus/blob/main/packages/docusaurus-theme-classic/src/theme/DocItem/Content/index.tsx */ | ||
const Content = (props: Props): JSX.Element => { | ||
const styles = useEuiMemoizedStyles(getContentStyles); | ||
return ( | ||
<div css={styles.content}> | ||
<OriginalContent {...props} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Content; |
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,22 @@ | ||
import type AType from '@theme-init/MDXComponents/A'; | ||
import type { WrapperProps } from '@docusaurus/types'; | ||
import { css } from '@emotion/react'; | ||
import { EuiLink, useEuiMemoizedStyles, UseEuiTheme } from '@elastic/eui'; | ||
|
||
type Props = WrapperProps<typeof AType>; | ||
|
||
const getStyles = ({ euiTheme }: UseEuiTheme) => { | ||
return { | ||
link: css` | ||
text-decoration: underline; | ||
`, | ||
}; | ||
}; | ||
|
||
const A = (props: Props): JSX.Element => { | ||
const styles = useEuiMemoizedStyles(getStyles); | ||
|
||
return <EuiLink {...props} css={styles.link} />; | ||
}; | ||
|
||
export default A; |
47 changes: 47 additions & 0 deletions
47
packages/docusaurus-theme/src/theme/MDXComponents/Code.tsx
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,47 @@ | ||
import React from 'react'; | ||
import type CodeType from '@theme-init/MDXComponents/Code'; | ||
import type { WrapperProps } from '@docusaurus/types'; | ||
import { css } from '@emotion/react'; | ||
import { | ||
EuiCode, | ||
EuiCodeBlock, | ||
useEuiMemoizedStyles, | ||
UseEuiTheme, | ||
} from '@elastic/eui'; | ||
|
||
type Props = WrapperProps<typeof CodeType>; | ||
|
||
const getStyles = ({ euiTheme }: UseEuiTheme) => { | ||
return { | ||
code: css` | ||
// reset docusaurus code styles | ||
border: none; | ||
vertical-align: initial; | ||
`, | ||
}; | ||
}; | ||
|
||
const Code = ({ children, className, ...rest }: Props): JSX.Element => { | ||
const styles = useEuiMemoizedStyles(getStyles); | ||
const language = className?.startsWith('language-') | ||
? className.replace('language-', '') | ||
: undefined; | ||
|
||
const isInlineCode = children | ||
? React.Children.toArray(children).every( | ||
(el) => typeof el === 'string' && !el.includes('\n') | ||
) | ||
: false; | ||
|
||
return isInlineCode ? ( | ||
<EuiCode {...rest} language={language} css={styles.code}> | ||
{children} | ||
</EuiCode> | ||
) : ( | ||
<EuiCodeBlock {...rest} fontSize="m" language={language}> | ||
{children} | ||
</EuiCodeBlock> | ||
); | ||
}; | ||
|
||
export default Code; |
29 changes: 29 additions & 0 deletions
29
packages/docusaurus-theme/src/theme/MDXComponents/Heading.tsx
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,29 @@ | ||
import OriginalHeading from '@theme-init/MDXComponents/Heading'; | ||
import type HeadingType from '@theme-init/MDXComponents/Heading'; | ||
import type { WrapperProps } from '@docusaurus/types'; | ||
import { EuiTitle, EuiTitleSize } from '@elastic/eui'; | ||
import { FunctionComponent } from 'react'; | ||
|
||
type Props = WrapperProps<typeof HeadingType>; | ||
|
||
const SIZE_TO_LEVEL_MAP: Record<string, EuiTitleSize> = { | ||
h6: 'xxxs', | ||
h5: 'xxs', | ||
h4: 'xs', | ||
h3: 's', | ||
h2: 'm', | ||
h1: 'l', | ||
}; | ||
|
||
const Heading: FunctionComponent<Omit<Props, 'as'> & { as: string }> = ({ | ||
as, | ||
...rest | ||
}): JSX.Element => { | ||
return ( | ||
<EuiTitle size={SIZE_TO_LEVEL_MAP[as]}> | ||
<OriginalHeading as={as} {...rest} /> | ||
</EuiTitle> | ||
); | ||
}; | ||
|
||
export default Heading; |
Oops, something went wrong.