angular/adev/shared-docs/styles/docs/_code.scss
hawkgs 225b5fa23a docs(docs-infra): make font styles consistent in the API code ToC (#59072)
Since code lines are wrapped in `<button>`-s, the native font styles overrides the parent's one which results in the font-family and font-size (esp. Safari) difference. This change fixes that.

PR Close #59072
2024-12-12 16:19:45 -08:00

390 lines
8.2 KiB
SCSS

// TODO: Working on refactoring all code components & syntax highlighting
/* stylelint-disable */
$code-font-size: 0.875rem;
@mixin docs-code-block {
// code across docs, inline, blocks, shell, example viewer, etc.
code {
font-family: var(--code-font);
border-radius: 0.25rem;
font-weight: 400;
// Create a new stacking context to allow for the psuedo element content to be placed behind the
// text so that the text is properly selectable by the user.
isolation: isolate;
// Inline code only
&:not(pre *) {
position: relative;
padding: 0 0.3rem;
// Fallback for older browsers
background: #e62600;
background: var(--red-to-orange-horizontal-gradient);
background-clip: text;
-webkit-background-clip: text;
color: transparent;
max-width: max-content;
width: 100%;
display: inline-block;
&::before {
content: '';
position: absolute;
inset: 0;
width: 100%;
height: 100%;
background: var(--subtle-purple);
border-radius: 0.25rem;
z-index: -1;
}
a:not(.docs-anchor) > & {
position: relative;
padding: 0 0.3rem;
white-space: nowrap;
background: var(--purple-to-blue-horizontal-gradient);
background-clip: text;
-webkit-background-clip: text;
color: transparent;
max-width: max-content;
&::before {
content: '';
position: absolute;
inset: 0;
width: 100%;
height: 100%;
background: var(--subtle-purple);
border-radius: 0.25rem;
transition: background 0.3s ease;
z-index: -1;
}
&:hover {
background: var(--vivid-pink);
background-clip: text;
-webkit-background-clip: text;
color: transparent;
max-width: max-content;
}
}
}
// render inline code emjois without gradient
.docs-emoji {
color: initial;
}
}
pre {
white-space: pre;
}
// render inline code emjois without gradient
.docs-emoji {
color: inherit;
}
// docs-code shell, multifile, mermaid diagrams
.docs-code {
.docs-viewer & {
margin-block: 1rem;
}
display: block;
position: relative;
border: 1px solid var(--senary-contrast);
border-radius: 0.25rem;
background: var(--octonary-contrast);
transition:
background 0.3s ease,
border-color 0.3s ease;
container: codeblock / inline-size;
pre {
overflow-x: auto;
}
code {
display: flex;
flex-direction: column;
font-size: $code-font-size;
counter-reset: line;
}
}
// shell doesn't have a header, for commands only
.shell {
border: 1px solid var(--quinary-contrast);
pre {
white-space: nowrap;
}
.shiki .line {
&::before {
content: '$';
padding-inline-end: 0.5rem;
}
display: block;
&.hidden {
display: none;
}
}
button[docs-copy-source-code] {
background-color: var(--quaternary-contrast);
border: 1px solid var(--quinary-contrast);
@container codeblock (min-width: 400px) {
border: 1px solid transparent;
}
.docs-copy {
path {
fill: var(--quinary-contrast);
}
}
.docs-check {
color: var(--page-background);
}
&:hover {
.docs-copy {
path {
fill: var(--octonary-contrast);
}
}
}
}
}
// copy code button
button[docs-copy-source-code] {
padding: 0.375rem 0.4rem 0.15rem 0.5rem;
position: absolute;
top: 3.1rem;
right: 0.2rem;
border-radius: 0.25rem;
cursor: pointer;
z-index: var(--z-index-icon);
background-color: var(--octonary-contrast);
border: 1px solid var(--senary-contrast);
transition:
background-color 0.3s ease,
border-color 0.3s ease;
@container codeblock (min-width: 400px) {
border: 1px solid transparent;
}
.docs-icon {
transition: opacity 0.3s ease-out;
}
.docs-copy {
opacity: 1;
path {
transition: fill 0.3s ease;
fill: var(--gray-400);
}
}
.docs-check {
opacity: 0;
color: var(--primary-contrast);
position: absolute;
inset: 0;
top: 0.35rem;
path {
transition: fill 0.3s ease;
}
}
&.docs-copy-source-code-button-success {
.docs-copy {
opacity: 0;
}
.docs-check {
opacity: 1;
}
}
&:hover {
.docs-copy {
path {
fill: var(--primary-contrast);
}
}
}
}
.docs-code .docs-code-header {
position: relative;
h3 {
background-image: var(--purple-to-blue-horizontal-gradient);
background-clip: text;
-webkit-background-clip: text;
color: transparent;
font-size: $code-font-size;
font-style: normal;
font-weight: 400;
line-height: 1.4rem;
letter-spacing: -0.00875rem;
margin: 0;
word-wrap: break-word;
width: fit-content;
}
}
.docs-code-header {
padding: 0.75rem;
// docs header background
&::before {
content: '';
position: absolute;
inset: 0;
width: 100%;
height: 100%;
background: var(--subtle-purple);
border-radius: 0.25rem 0.25rem 0 0;
transition: background 0.3s ease;
}
}
// Single line docs-code elements, without headers, shell code
.docs-code:not(:has(.docs-code-header)) {
button[docs-copy-source-code] {
top: 0.2rem;
right: 0.2rem;
}
}
.docs-code[mermaid] {
border: 0;
width: 100%;
background-color: transparent;
}
// Line numbers styling: Add a grid, if there are line numbers
.docs-code:not([mermaid]),
.docs-example-viewer-code-wrapper {
code:has(.shiki-ln-number) {
display: grid;
grid-template-columns: min-content 1fr;
height: 100%;
}
pre {
overflow-x: auto;
display: flex;
flex-direction: column;
align-items: start;
}
pre > * {
min-width: 100%;
width: auto;
}
}
.docs-example-viewer-code-wrapper {
.docs-code-header {
display: none;
}
}
.shiki-ln-number {
border-inline-end: 1px solid var(--senary-contrast);
padding-inline-start: 0.75rem;
padding-inline-end: 0.5rem;
color: var(--quaternary-contrast);
font-size: $code-font-size;
text-align: right;
}
.highlighted {
background: color-mix(in srgb, var(--bright-blue) 9%, var(--page-background));
color: color-mix(in srgb, var(--bright-blue) 60%, var(--full-contrast));
}
.remove {
background: color-mix(in srgb, var(--orange-red) 10%, var(--page-background));
color: color-mix(in srgb, var(--hot-red) 80%, var(--full-contrast));
}
.add {
background: color-mix(in srgb, oklch(68.82% 0.224 155.13) 12%, var(--page-background));
color: color-mix(in srgb, var(--super-green), var(--full-contrast) 50%);
}
.hidden {
display: none;
}
}
@mixin docs-syntax-highlighting {
.shiki .line {
min-height: 1.375em;
padding-inline: 1rem;
color: var(--tertiary-contrast);
display: block;
font-size: $code-font-size;
font-family: var(--code-font);
font-weight: 400;
text-align: left;
padding-block: 0.25rem;
&.hidden {
display: none;
}
span:last-child {
margin-inline-end: 4rem;
}
}
.shiki-ln-group {
display: flex;
flex-direction: column;
margin: 1rem 0;
}
.shiki-deprecated {
text-decoration: line-through;
}
.gap {
color: var(--quaternary-contrast);
}
.hljs-constructor {
color: var(--symbolic-cyan);
}
.hljs-params {
color: var(--bright-blue);
}
}
@mixin docs-code-editor {
.cm-tooltip-hover {
display: flex;
flex-direction: column-reverse;
padding: 0.75rem;
&::-webkit-scrollbar-track {
background: rgba(0, 0, 0, 0);
}
&::-webkit-scrollbar {
width: 6px;
height: 6px;
}
&::-webkit-scrollbar-thumb {
background-color: var(--senary-contrast);
border-radius: 10px;
}
&::-webkit-scrollbar-thumb:hover {
background-color: var(--quinary-contrast);
}
}
}