Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more components #284

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import sitemap from "@astrojs/sitemap"

import tailwind from "@astrojs/tailwind"

import expressiveCode from "astro-expressive-code"

// https://astro.build/config
export default defineConfig({
site: "https://docs.scroll.io",
Expand All @@ -38,6 +40,21 @@ export default defineConfig({
}),
astroCallouts(),
solidityRemixCode(),
expressiveCode({
themes: ["dracula", "solarized-light"],
defaultProps: {
frame: "code",
},
styleOverrides: {
borderRadius: "27px",
borderColor: "transparent",
frames: {
shadowColor: "transparent",
editorTabBorderRadius: "0.5rem",
editorBackground: "#2b2b2b",
},
},
}),
mdx(),
tailwind({
applyBaseStyles: false,
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@astrojs/tailwind": "^5.1.0",
"@nanostores/preact": "^0.3.1",
"astro-auto-import": "^0.4.2",
"astro-expressive-code": "^0.35.3",
"astro-i18next": "^1.0.0-beta.21",
"clipboard": "^2.0.11",
"ethereum-rpc-table": "^0.0.1",
Expand All @@ -42,6 +43,7 @@
"query-string": "^7.1.1",
"react-instantsearch-hooks-web": "^6.38.1",
"react-mailchimp-subscribe": "^2.1.3",
"rehype-format": "^5.0.0",
"rehype-katex": "^7.0.0",
"rehype-mermaidjs": "^1.0.1",
"remark-gfm": "^4.0.0",
Expand Down
1 change: 0 additions & 1 deletion src/components/HeadCommon.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import "../styles/theme.css"
import "../styles/index.css"
import "../styles/migrated.css"
import "../styles/prism-darcula.css"
import "../styles/copy-to-clipboard.css"

import "../styles/design-system/global-styles.css"
---
Expand Down
33 changes: 33 additions & 0 deletions src/components/Icons/Icons.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
import { Icons } from "./Icons"

interface Props {
name: keyof typeof Icons
label?: string
color?: string
size?: string
class?: string
}

const { name, label, size = "1em", color } = Astro.props
const a11yAttrs = label ? ({ "aria-label": label } as const) : ({ "aria-hidden": "true" } as const)
---

<svg
{...a11yAttrs}
class={Astro.props.class}
width="16"
height="16"
viewBox="0 0 24 24"
fill="currentColor"
set:html={Icons[name]}
/>

<style define:vars={{ "sl-icon-color": color, "sl-icon-size": size }}>
svg {
color: var(--sl-icon-color);
font-size: var(--sl-icon-size, 1em);
width: 1em;
height: 1em;
}
</style>
155 changes: 155 additions & 0 deletions src/components/Icons/Icons.ts

Large diffs are not rendered by default.

117 changes: 81 additions & 36 deletions src/components/LeftSidebar/LeftSidebar.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { MENU, Frontmatter, getSidebar } from "../../config"
import { localizePath } from "astro-i18next"
import { changeLanguage } from "i18next"
import i18next from "i18next"
import Icon from "../Icons/Icons.astro"

export type Props = {
currentPage: string
Expand All @@ -26,6 +27,23 @@ const removeSlashes = function (url: string) {
}

const currentPageMatch = removeSlashes(currentPage.slice(1))

const processedSidebarSections = sidebarSections.map((section) => {
return {
...section,
contents: section.contents.map((child) => {
const isCurrent = currentPageMatch === removeSlashes(localizePath(child.url))
return {
...child,
isCurrent: isCurrent,
open:
isCurrent ||
(child.children &&
child.children.some((subChild) => currentPageMatch === removeSlashes(localizePath(subChild.url)))),
}
}),
}
})
---

<nav aria-labelledby="grid-left" class="menu-nav">
Expand All @@ -48,44 +66,46 @@ const currentPageMatch = removeSlashes(currentPage.slice(1))
<hr class="menu-separator" />
<ul class="nav-groups sidebar-nav-groups">
{
sidebarSections.map((section) => (
processedSidebarSections.map((section) => (
<li>
<div class="nav-group">
<h2 class="nav-group-title">{section.section}</h2>
<ul>
{!!section.contents &&
section.contents.map((child) => (
<>
<li class="nav-link">
<li class={`nav-link ${child.open ? "open" : ""}`}>
<a
href={isExternal(child.url) ? `${child.url}` : localizePath(child.url)}
target={isExternal(child.url) ? "_blank" : "_self"}
aria-current={`${
currentPageMatch === removeSlashes(localizePath(child.url)) ? "page" : "false"
}`}
aria-current={`${child.isCurrent ? "page" : "false"}`}
class="flex align-center justify-between width-full"
>
{child.title}
{isExternal(child.url) && (
<svg
xmlns="http://www.w3.org/2000/svg"
width="10"
height="11"
viewBox="0 0 10 11"
fill="none"
>
<g clip-path="url(#clip0_2084_4329)">
<path
d="M9 1.5V8.36538L7.83812 7.2035V3.46385C5.46463 5.76924 3.29542 8.27999 0.853849 10.5L0 9.66344C2.42536 7.44344 4.5762 4.96728 6.93347 2.6781H3.31272L2.13462 1.5H9Z"
fill="currentColor"
/>
</g>
<defs>
<clipPath id="clip0_2084_4329">
<rect width="10" height="10" fill="white" transform="translate(0 0.5)" />
</clipPath>
</defs>
</svg>
)}
<span>
{child.title}
{isExternal(child.url) && (
<svg
xmlns="http://www.w3.org/2000/svg"
width="10"
height="11"
viewBox="0 0 10 11"
fill="none"
>
<g clip-path="url(#clip0_2084_4329)">
<path
d="M9 1.5V8.36538L7.83812 7.2035V3.46385C5.46463 5.76924 3.29542 8.27999 0.853849 10.5L0 9.66344C2.42536 7.44344 4.5762 4.96728 6.93347 2.6781H3.31272L2.13462 1.5H9Z"
fill="currentColor"
/>
</g>
<defs>
<clipPath id="clip0_2084_4329">
<rect width="10" height="10" fill="white" transform="translate(0 0.5)" />
</clipPath>
</defs>
</svg>
)}
</span>
{!!child.children && <Icon name="right-caret" class="caret" size="1.25rem" />}
</a>
</li>
{!!child.children && (
Expand Down Expand Up @@ -140,14 +160,6 @@ const currentPageMatch = removeSlashes(currentPage.slice(1))
.sidebar-nav-groups.nav-groups > :first-child {
@apply pt-[15px];
}

@media (min-width: 50em) {
#mobile-menu,
.menu-separator {
display: none;
height: 0;
}
}
.menu-nav {
width: 100%;
}
Expand Down Expand Up @@ -187,11 +199,20 @@ const currentPageMatch = removeSlashes(currentPage.slice(1))
font: inherit;
color: inherit;
text-decoration: none;
display: block;
display: flex;
font-size: 16px;
/* line-height:1; */
margin-bottom: 10px;
font-weight: 500;
justify-content: space-between;
align-items: center;
}

.nav-link a span {
font-size: inherit;
font-weight: inherit;
color: inherit;
line-height: inherit;
}

.nav-link a:hover,
Expand All @@ -212,11 +233,35 @@ const currentPageMatch = removeSlashes(currentPage.slice(1))
color: hsla(var(--color-base-white), 100%, 1);
}

.nav-link + ul {
display: none;
}

.caret {
transition: transform 0.2s ease-in-out;
flex-shrink: 0;
}

.nav-link.open .caret {
transform: rotateZ(90deg);
}

.nav-link.open + ul {
display: block;
border-left-width: 1px;
border-left-style: solid;
}

.nested {
@apply pl-5;
}

@media (min-width: 50em) {
#mobile-menu,
.menu-separator {
display: none;
height: 0;
}
.nav-groups {
padding: 0;
}
Expand Down
91 changes: 91 additions & 0 deletions src/components/Steps/Steps.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
---
import { processSteps } from "./rehype-steps"

const content = await Astro.slots.render("default")
const { html } = processSteps(content)
---

<Fragment set:html={html} />

<style is:global>
.sl-steps {
--bullet-size: calc(1.75 * 1rem);
--bullet-margin: 0.375rem;

list-style: none;
counter-reset: steps-counter var(--sl-steps-start, 0);
padding-inline-start: 0;
}

.sl-steps > li {
counter-increment: steps-counter;
position: relative;
padding-inline-start: calc(var(--bullet-size) + 1rem);
/* HACK: Keeps any `margin-bottom` inside the `<li>`’s padding box to avoid gaps in the hairline border. */
padding-bottom: 1px;
/* Prevent bullets from touching in short list items. */
min-height: calc(var(--bullet-size) + var(--bullet-margin));
}
.sl-steps > li + li {
/* Remove margin between steps. */
margin-top: 0;
}

/* Custom list marker element. */
.sl-steps > li::before {
content: counter(steps-counter);
position: absolute;
top: 0;
inset-inline-start: 0;
width: var(--bullet-size);
height: var(--bullet-size);
line-height: var(--bullet-size);

font-size: var(--sl-text-xs);
font-weight: 600;
text-align: center;
color: hsl(0, 0%, 100%);
background-color: hsl(224, 14%, 16%);
border-radius: 99rem;
box-shadow: inset 0 0 0 1px hsl(224, 10%, 23%);
}

/* Vertical guideline linking list numbers. */
.sl-steps > li:not(:last-of-type)::after {
--guide-width: 1px;
content: "";
position: absolute;
top: calc(var(--bullet-size) + var(--bullet-margin));
bottom: var(--bullet-margin);
inset-inline-start: calc((var(--bullet-size) - var(--guide-width)) / 2);
width: var(--guide-width);
background-color: #24262e;
}

/* Adjust first item inside a step so that it aligns vertically with the number
even if using a larger font size (e.g. a heading) */
.sl-steps > li > :first-child {
/*
The `lh` unit is not yet supported by all browsers in our support matrix
— see https://caniuse.com/mdn-css_types_length_lh
In unsupported browsers we approximate this using our known line-heights.
*/
--lh: calc(1em * var(--sl-line-height));
--shift-y: calc(0.5 * (var(--bullet-size) - var(--lh)));
transform: translateY(var(--shift-y));
margin-bottom: var(--shift-y);
}
.sl-steps > li > :first-child:where(h1, h2, h3, h4, h5, h6) {
--lh: calc(1em * var(--sl-line-height-headings));
}
@supports (--prop: 1lh) {
.sl-steps > li > :first-child {
--lh: 1lh;
}
}

.sl-steps .expressive-code {
margin-top: 1rem;
margin-bottom: 1.25rem;
}
</style>
Loading