Skip to content

Commit

Permalink
feat(theme): containers: add the success custom block
Browse files Browse the repository at this point in the history
This adds a custom block with the `success` keyword, which is a green
container.

The colours for this container already exist in vars.css
(--vp-c-success*), which, before this commit, is completely unused
outside of generating a diff.

For example, this can be used for messages such as:
```
::: success

You have completed the walkthrough!

:::
```
  • Loading branch information
lifehackerhansol committed Oct 8, 2024
1 parent 78c4d3d commit 056c6da
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/en/guide/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ This is a warning.
This is a dangerous warning.
:::

::: success
This is a success notice.
:::

::: details
This is a details block.
:::
Expand All @@ -172,6 +176,10 @@ This is a warning.
This is a dangerous warning.
:::

::: success
This is a success notice.
:::

::: details
This is a details block.
:::
Expand Down Expand Up @@ -218,6 +226,7 @@ export default defineConfig({
warningLabel: '警告',
dangerLabel: '危险',
infoLabel: '信息',
successLabel: '成功',
detailsLabel: '详细信息'
}
}
Expand Down
20 changes: 20 additions & 0 deletions src/client/theme-default/styles/components/custom-block.css
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,26 @@
background-color: var(--vp-custom-block-details-code-bg);
}

.custom-block.success {
border-color: var(--vp-custom-block-success-border);
color: var(--vp-custom-block-success-text);
background-color: var(--vp-custom-block-success-bg);
}

.custom-block.success a,
.custom-block.success code {
color: var(--vp-c-brand-1);
}

.custom-block.success a:hover,
.custom-block.success a:hover > code {
color: var(--vp-c-brand-2);
}

.custom-block.success code {
background-color: var(--vp-custom-block-success-code-bg);
}

.custom-block-title {
font-weight: 600;
}
Expand Down
5 changes: 5 additions & 0 deletions src/client/theme-default/styles/vars.css
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,11 @@
--vp-custom-block-caution-bg: var(--vp-c-caution-soft);
--vp-custom-block-caution-code-bg: var(--vp-c-caution-soft);

--vp-custom-block-success-border: transparent;
--vp-custom-block-success-text: var(--vp-c-text-1);
--vp-custom-block-success-bg: var(--vp-c-success-soft);
--vp-custom-block-success-code-bg: var(--vp-c-success-soft);

--vp-custom-block-details-border: var(--vp-custom-block-info-border);
--vp-custom-block-details-text: var(--vp-custom-block-info-text);
--vp-custom-block-details-bg: var(--vp-custom-block-info-bg);
Expand Down
8 changes: 8 additions & 0 deletions src/node/markdown/plugins/containers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ export const containerPlugin = (
md
)
)
.use(
...createContainer(
'success',
containerOptions?.successLabel || 'SUCCESS',
md
)
)
.use(
...createContainer(
'details',
Expand Down Expand Up @@ -138,4 +145,5 @@ export interface ContainerOptions {
detailsLabel?: string
importantLabel?: string
cautionLabel?: string
successLabel?: string
}

0 comments on commit 056c6da

Please sign in to comment.