@stianlarsen/react-code-preview
Version:
A React component that provides tabbed navigation for viewing a live component preview and its source code separately.
120 lines (117 loc) • 2.86 kB
CSS
.code-preview {
--cp-radius: 0.5rem;
--cp-background: hsl(0 0% 100%);
--cp-background-editor: hsl(240 6% 10%);
--cp-foreground: hsl(240 10% 3.9%);
--cp-muted-foreground: hsl(240 3.8% 46.1%);
--cp-border: hsl(240 5.9% 90%);
--cp-black: hsl(0 0 0%);
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content: flex-start;
height: 100%;
max-width: 700px;
padding: 1rem;
gap: 1.25rem;
}
.code-preview__tabs {
display: flex;
flex-wrap: nowrap;
align-items: center;
justify-content: flex-start;
position: relative;
min-width: 100%;
box-shadow: inset 0 -1px var(--cp-border);
}
.code-preview__tabs__trigger {
display: flex;
align-items: center;
justify-content: center;
background-color: transparent;
cursor: pointer;
padding: 0.5rem 1rem 0.75rem;
line-height: 1.25rem;
font-size: 0.875rem;
font-weight: 500;
position: relative;
background-color: transparent;
border-color: transparent;
cursor: pointer;
color: var(--cp-muted-foreground);
text-rendering: optimizeLegibility;
transition: color 0.15s ease;
}
.code-preview__tabs__trigger:hover {
color: var(--cp-foreground);
}
.code-preview__tabs__trigger-active {
color: var(--cp-foreground);
}
.code-preview__tabs__underline {
position: absolute;
bottom: 0;
height: 2px;
background-color: var(--cp-foreground);
transition: left 0.25s ease, width 0.25s ease;
border-radius: 0.7px;
}
.code-preview__content {
width: 100%;
overflow: hidden;
position: relative;
overflow-y: scroll;
scroll-behavior: smooth;
}
.code-preview__content__component-wrapper {
display: flex;
flex-direction: column;
gap: 1rem;
justify-content: center;
align-items: center;
width: 100%;
min-height: 250px;
padding: 1rem;
border: 1px solid var(--cp-border);
border-radius: var(--cp-radius);
}
.code-preview__content__code-wrapper {
height: 100%;
border: 1px solid var(--cp-border);
border-radius: var(--cp-radius);
overflow: auto;
}
.code-preview__content__code-wrapper pre {
padding: 1rem 0;
background-color: var(--cp-background-editor);
height: 100%;
max-height: 350px;
overflow: auto;
}
.code-preview__content__code-wrapper pre code {
font-size: 0.875rem;
line-height: 1.25rem;
display: grid;
min-width: 100%;
overflow-wrap: break-word;
border-radius: 0;
border-width: 0;
background-color: transparent;
padding: 0;
counter-reset: line;
-webkit-box-decoration-break: clone;
overflow-x: scroll;
}
.code-preview__content__code-wrapper pre code .line {
display: inline-block;
min-height: 1rem;
width: 100%;
padding: 0.125rem 1rem;
}
@media (prefers-color-scheme: dark) {
.code-preview {
--cp-background: hsl(240 10% 3.9%);
--cp-foreground: hsl(0 0% 98%);
--cp-border: hsl(240 3.7% 15.9%);
}
}/*# sourceMappingURL=codePreview.css.map */