Skip to content

Commit 41c11d0

Browse files
committed
support passing ids and additional attributes
1 parent 066a009 commit 41c11d0

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

packages/docusaurus-theme-classic/src/theme-classic.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ declare module '@theme/Admonition' {
4848
readonly icon?: ReactNode;
4949
readonly title?: ReactNode;
5050
readonly className?: string;
51+
readonly id?: string;
5152
}
5253

5354
export default function Admonition(props: Props): ReactNode;
@@ -123,6 +124,7 @@ declare module '@theme/Admonition/Layout' {
123124
readonly icon?: ReactNode;
124125
readonly title?: ReactNode;
125126
readonly className?: string;
127+
readonly id?: string;
126128
}
127129
export default function AdmonitionLayout(props: Props): ReactNode;
128130
}

packages/docusaurus-theme-classic/src/theme/Admonition/Layout/index.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@ function AdmonitionContainer({
1717
type,
1818
className,
1919
children,
20-
}: Pick<Props, 'type' | 'className'> & {children: ReactNode}) {
20+
...optional
21+
}: Pick<Props, 'type' | 'className' | 'id'> & {children: ReactNode}) {
2122
return (
2223
<div
2324
className={clsx(
2425
ThemeClassNames.common.admonition,
2526
ThemeClassNames.common.admonitionType(type),
2627
styles.admonition,
2728
className,
28-
)}>
29+
)}
30+
{...optional}>
2931
{children}
3032
</div>
3133
);
@@ -47,9 +49,9 @@ function AdmonitionContent({children}: Pick<Props, 'children'>) {
4749
}
4850

4951
export default function AdmonitionLayout(props: Props): ReactNode {
50-
const {type, icon, title, children, className} = props;
52+
const {type, icon, title, children, className, ...optional} = props;
5153
return (
52-
<AdmonitionContainer type={type} className={className}>
54+
<AdmonitionContainer type={type} className={className} {...optional}>
5355
{title || icon ? <AdmonitionHeading title={title} icon={icon} /> : null}
5456
<AdmonitionContent>{children}</AdmonitionContent>
5557
</AdmonitionContainer>

website/_dogfooding/_docs tests/tests/admonitions.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ import InfoIcon from "@theme/Admonition/Icon/Info"
6262
```css title="dogfooding.css"
6363
/* ... */
6464
.shadow {
65-
--shadow-color: red;
66-
box-shadow: 10px 10px 10px var(--shadow-color);
65+
--shadow-size: 10px;
66+
box-shadow: 10px 10px var(--shadow-size) var(--shadow-color);
6767

6868
&.blue {
6969
--shadow-color: blue;
@@ -111,9 +111,9 @@ The last provided id `info-2` wins when writing `:::{#info-3 #info-1 #info-2}`
111111

112112
### Combination
113113

114-
:::info{.shadow #info-4 .blue #info-2 hello=world}
114+
:::info{.shadow #info-4 .blue #info-2 style="--shadow-size:5px"}
115115

116-
Multiple Classes, Ids and attributes: `:::info{.shadow #id1 .blue #id2 hello=world}`. `hello` is passed to the admonition component, but not further used, so ignored in the output.
116+
Multiple Classes, Ids and attributes: `:::info{.shadow #id1 .blue #id2 style="--shadow-size:5px"}`.
117117

118118
:::
119119

website/_dogfooding/dogfooding.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ html {
2727

2828
.shadow {
2929
--shadow-color: red;
30-
box-shadow: 10px 10px 10px var(--shadow-color);
30+
--shadow-size: 10px;
31+
box-shadow: 10px 10px var(--shadow-size) var(--shadow-color);
3132

3233
&.blue {
3334
--shadow-color: blue;

0 commit comments

Comments
 (0)