Skip to content

Commit

Permalink
Merge pull request #19 from HiDeoo/hd-feat-remove-component-override-…
Browse files Browse the repository at this point in the history
…warning
  • Loading branch information
HiDeoo committed Aug 21, 2024
2 parents b46bc13 + d1657fc commit a417609
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
19 changes: 19 additions & 0 deletions docs/src/content/docs/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,22 @@ import { PackageManagers } from '@hideoo/starlight-plugins-docs-components'
</Steps>

The Starlight Image Zoom plugin behavior can be tweaked using various [configuration options](/configuration).

## Component overrides

The Starlight Image Zoom plugin uses a Starlight [component override](https://starlight.astro.build/guides/overriding-components/) for the [`MarkdownContent`](https://starlight.astro.build/reference/overrides/#markdowncontent) component to add zoom capabilities to images.

If you have a custom `MarkdownContent` component override in your Starlight project, you will need to manually render the `ImageZoom` component from the Starlight Image Zoom plugin in your custom component:

```diff lang="astro"
---
// src/components/overrides/MarkdownContent.astro
import type { Props } from '@astrojs/starlight/props'
import Default from '@astrojs/starlight/components/MarkdownContent.astro'
+import ImageZoom from 'starlight-image-zoom/components/ImageZoom.astro'
---

+<ImageZoom />
<p>Custom content in the MarkdownContent override</p>
<Default {...Astro.props}><slot /></Default>
```
11 changes: 2 additions & 9 deletions packages/starlight-image-zoom/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,14 @@ export default function starlightImageZoomPlugin(userConfig?: StarlightImageZoom
return {
name: 'starlight-image-zoom-plugin',
hooks: {
setup({ addIntegration, config, logger, updateConfig }) {
setup({ addIntegration, config, updateConfig }) {
const updatedConfig: Partial<StarlightUserConfig> = { components: { ...config.components } }

if (!updatedConfig.components) {
updatedConfig.components = {}
}

if (config.components?.MarkdownContent) {
logger.warn(
'It looks like you already have a `MarkdownContent` component override in your Starlight configuration.',
)
logger.warn(
'To use `starlight-image-zoom`, either remove the override or manually render `starlight-image-zoom/components/ImageZoom.astro`.',
)
} else {
if (!config.components?.MarkdownContent) {
updatedConfig.components.MarkdownContent = 'starlight-image-zoom/overrides/MarkdownContent.astro'
}

Expand Down

0 comments on commit a417609

Please sign in to comment.