Overview
In the API demos on this site, you'll see some features which are not included in the default Docusaurus styling including the operation method sidebar badges. To add these to your site you can use one of the two options outlined below.
The method labels are pure CSS and as a result there are few, if any, limits on how you style / present these on your site.
Method Badge Styles
- Demo Styles
- High Contrast
- Simple
These are the styles implemented on this very demo site.
https://docusaurus-openapi.tryingpan.dev/customization/styling#method-badge-styles
Demo Styles
.api-method > .menu__link,
.schema > .menu__link {
align-items: center;
justify-content: start;
}
.api-method > .menu__link::before,
.schema > .menu__link::before {
width: 55px;
height: 20px;
font-size: 12px;
line-height: 20px;
text-transform: uppercase;
font-weight: 600;
border-radius: 0.25rem;
border: 1px solid;
margin-right: var(--ifm-spacing-horizontal);
text-align: center;
flex-shrink: 0;
border-color: transparent;
color: white;
}
.get > .menu__link::before {
content: "get";
background-color: var(--ifm-color-primary);
}
.post > .menu__link::before {
content: "post";
background-color: var(--openapi-code-green);
}
.delete > .menu__link::before {
content: "del";
background-color: var(--openapi-code-red);
}
.put > .menu__link::before {
content: "put";
background-color: var(--openapi-code-blue);
}
.patch > .menu__link::before {
content: "patch";
background-color: var(--openapi-code-orange);
}
.head > .menu__link::before {
content: "head";
background-color: var(--ifm-color-secondary-darkest);
}
.event > .menu__link::before {
content: "event";
background-color: var(--ifm-color-secondary-darkest);
}
.schema > .menu__link::before {
content: "schema";
background-color: var(--ifm-color-secondary-darkest);
}
In this issue community member @ThomasHeartman shared some alternative CSS with better contrast and some other stylistic tweaks to the method labels. The CSS to replicate this is below:
https://docusaurus-openapi.tryingpan.dev/customization/styling#method-badge-styles
High Contrast
.api-method > .menu__link,
.schema > .menu__link {
align-items: center;
justify-content: start;
}
.api-method > .menu__link::before,
.schema > .menu__link::before {
width: 55px;
height: 20px;
font-size: 12px;
line-height: 20px;
text-transform: uppercase;
font-weight: 600;
border-radius: 0.25rem;
border: 1px solid;
border-inline-start-width: 5px;
margin-right: var(--ifm-spacing-horizontal);
text-align: center;
flex-shrink: 0;
}
.get > .menu__link::before {
content: "get";
background-color: var(--ifm-color-info-contrast-background);
color: var(--ifm-color-info-contrast-foreground);
border-color: var(--ifm-color-info-dark);
}
.post > .menu__link::before {
content: "post";
background-color: var(--ifm-color-success-contrast-background);
color: var(--ifm-color-success-contrast-foreground);
border-color: var(--ifm-color-success-dark);
}
.delete > .menu__link::before {
content: "del";
background-color: var(--ifm-color-danger-contrast-background);
color: var(--ifm-color-danger-contrast-foreground);
border-color: var(--ifm-color-danger-dark);
}
.put > .menu__link::before {
content: "put";
background-color: var(--ifm-color-warning-contrast-background);
color: var(--ifm-color-warning-contrast-foreground);
border-color: var(--ifm-color-warning-dark);
}
.patch > .menu__link::before {
content: "patch";
background-color: var(--ifm-color-success-contrast-background);
color: var(--ifm-color-success-contrast-foreground);
border-color: var(--ifm-color-success-dark);
}
.head > .menu__link::before {
content: "head";
background-color: var(--ifm-color-secondary-contrast-background);
color: var(--ifm-color-secondary-contrast-foreground);
border-color: var(--ifm-color-secondary-dark);
}
.event > .menu__link::before {
content: "event";
background-color: var(--ifm-color-secondary-contrast-background);
color: var(--ifm-color-secondary-contrast-foreground);
border-color: var(--ifm-color-secondary-dark);
}
.schema > .menu__link::before {
content: "schema";
background-color: var(--ifm-color-secondary-contrast-background);
color: var(--ifm-color-secondary-contrast-foreground);
border-color: var(--ifm-color-secondary-dark);
}
These styles are more similar to the ones found on https://pan.dev.
https://docusaurus-openapi.tryingpan.dev/customization/styling#method-badge-styles
Simple
.api-method > .menu__link {
align-items: center;
justify-content: start;
}
.api-method > .menu__link::before {
width: 55px;
height: 20px;
font-size: 12px;
line-height: 20px;
text-transform: uppercase;
font-weight: 600;
border-radius: 0.25rem;
align-content: start;
margin-right: var(--ifm-spacing-horizontal);
text-align: right;
flex-shrink: 0;
border-color: transparent;
}
.get > .menu__link::before {
content: "get";
color: var(--ifm-color-info);
}
.post > .menu__link::before {
content: "post";
color: var(--ifm-color-success);
}
.delete > .menu__link::before {
content: "del";
color: var(--ifm-color-danger);
}
.put > .menu__link::before {
content: "put";
color: var(--ifm-color-warning);
}
.patch > .menu__link::before {
content: "patch";
color: var(--ifm-color-warning);
}
.head > .menu__link::before {
content: "head";
color: var(--ifm-color-secondary-contrast-foreground);
}
.event > .menu__link::before {
content: "event";
color: var(--ifm-color-secondary-contrast-foreground);
}
.schema > .menu__link::before {
content: "schema";
color: var(--ifm-color-secondary-contrast-foreground);
}