Skip to content

Commit

Permalink
Use Admonition from @swmansion/t-rex-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
patrycjakalinska committed May 13, 2024
1 parent 6e1f613 commit 6fb2104
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 238 deletions.
142 changes: 2 additions & 140 deletions docs/src/theme/Admonition/index.js
Original file line number Diff line number Diff line change
@@ -1,141 +1,3 @@
import React from 'react';
import clsx from 'clsx';
import { ThemeClassNames } from '@docusaurus/theme-common';
import Translate from '@docusaurus/Translate';
import ThemedImage from '@theme/ThemedImage';
import styles from './styles.module.css';
import useBaseUrl from '@docusaurus/useBaseUrl';
import { Admonition } from '@swmansion/t-rex-ui';

const AdmonitionConfigs = {
note: {
infimaClassName: 'secondary',
label: (
<Translate
id="theme.admonition.note"
description="The default label used for the Note admonition (:::note)">
note
</Translate>
),
},
tip: {
infimaClassName: 'success',
label: (
<Translate
id="theme.admonition.tip"
description="The default label used for the Tip admonition (:::tip)">
tip
</Translate>
),
},
danger: {
infimaClassName: 'danger',
label: (
<Translate
id="theme.admonition.danger"
description="The default label used for the Danger admonition (:::danger)">
danger
</Translate>
),
},
info: {
infimaClassName: 'info',
label: (
<Translate
id="theme.admonition.info"
description="The default label used for the Info admonition (:::info)">
info
</Translate>
),
},
caution: {
infimaClassName: 'caution',
label: (
<Translate
id="theme.admonition.caution"
description="The default label used for the Caution admonition (:::caution)">
caution
</Translate>
),
},
};
// Legacy aliases, undocumented but kept for retro-compatibility
const aliases = {
secondary: 'note',
important: 'info',
success: 'tip',
warning: 'danger',
};

export default function Admonition(props) {
const {
children,
type,
title,
icon: iconProp,
} = processAdmonitionProps(props);
const typeConfig = getAdmonitionConfig(type);
const titleLabel = title ?? typeConfig.label;

const dangerIcon = {
light: useBaseUrl('/img/danger.svg'),
dark: useBaseUrl('/img/danger-dark.svg'),
};

return (
<div
className={clsx(
ThemeClassNames.common.admonition,
ThemeClassNames.common.admonitionType(props.type),
styles.admonition,
'alert',
styles[`alert--${typeConfig.infimaClassName}`]
)}>
<div className={styles.admonitionHeading}>
<div className={styles.admonitionIcon}>
<ThemedImage sources={dangerIcon} />
</div>

{titleLabel}
</div>
<div className={styles.admonitionContent}>{children}</div>
</div>
);

function getAdmonitionConfig(unsafeType) {
const type = aliases[unsafeType] ?? unsafeType;
const config = AdmonitionConfigs[type];
if (config) {
return config;
}
console.warn(
`No admonition config found for admonition type "${type}". Using Info as fallback.`
);
return AdmonitionConfigs.info;
}
}

// Workaround because it's difficult in MDX v1 to provide a MDX title as props
// See https://github.com/facebook/docusaurus/pull/7152#issuecomment-1145779682
function extractMDXAdmonitionTitle(children) {
const items = React.Children.toArray(children);
const mdxAdmonitionTitle = items.find(
(item) =>
React.isValidElement(item) && item.props?.mdxType === 'mdxAdmonitionTitle'
);
const rest = <>{items.filter((item) => item !== mdxAdmonitionTitle)}</>;
return {
mdxAdmonitionTitle,
rest,
};
}

function processAdmonitionProps(props) {
const { mdxAdmonitionTitle, rest } = extractMDXAdmonitionTitle(
props.children
);
return {
...props,
title: props.title ?? mdxAdmonitionTitle,
children: rest,
};
}
export default Admonition;
84 changes: 0 additions & 84 deletions docs/src/theme/Admonition/styles.module.css

This file was deleted.

11 changes: 0 additions & 11 deletions docs/src/theme/DocCategoryGeneratedIndexPage/index.js

This file was deleted.

This file was deleted.

4 changes: 4 additions & 0 deletions docs/src/theme/Logo/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@
display: none;
}
}

[class*='DocCategoryGeneratedIndexPage'][class*='title'] {
font-size: var(--swm-h1-font-size);
}

0 comments on commit 6fb2104

Please sign in to comment.