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

Refactor <Steps> counter #2041

Merged
merged 7 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
257 changes: 257 additions & 0 deletions docs/src/content/docs/guides/steps.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
---
title: ⚠️ Steps ⚠️
---

:::danger
Delete this page
:::

import { Tabs, TabItem, FileTree, Steps } from '@astrojs/starlight/components';

<Steps>

1. A step

2. A step with some code bloc

```js
// astro.config.mjs
import { defineConfig } from 'astro/config';
import starlight from '@astrojs/starlight';

export default defineConfig({
integrations: [
starlight({
title: 'Amazing',
}),
],
});
```

3. A step with a file tree

<FileTree>

- src/
- assets/
- **my-logo.svg**
- content/
- astro.config.mjs

</FileTree>

4. A step with an unordered list

- A
- B
- B1
- B2
- C

5. A step with some tabs

<Tabs syncKey="pkg">

<TabItem label="npm">

```sh
npx astro add tailwind
```

</TabItem>

<TabItem label="pnpm">

```sh
pnpm astro add tailwind
```

</TabItem>

<TabItem label="Yarn">

```sh
yarn astro add tailwind
```

</TabItem>

</Tabs>

6. A step with an ordered list

1. A
2. B
1. B1
2. B2
3. C

7. A step with nested steps

<Steps>

1. A step
2. A step with some code bloc

```js
// astro.config.mjs
import { defineConfig } from 'astro/config';
import starlight from '@astrojs/starlight';

export default defineConfig({
integrations: [
starlight({
title: 'Amazing',
}),
],
});
```

3. A step with a file tree

<FileTree>

- src/
- assets/
- **my-logo.svg**
- content/
- astro.config.mjs

</FileTree>

4. A step with an unordered list

- A
- B
- B1
- B2
- C

5. A step with some tabs

<Tabs syncKey="pkg">

<TabItem label="npm">

```sh
npx astro add tailwind
```

</TabItem>

<TabItem label="pnpm">

```sh
pnpm astro add tailwind
```

</TabItem>

<TabItem label="Yarn">

```sh
yarn astro add tailwind
```

</TabItem>

</Tabs>

6. A step with an ordered list

1. A
2. B
1. B1
2. B2
3. C

7. A step

</Steps>

8. A step with nested steps starting at 4

<Steps>

4. A step
5. A step with some code bloc

```js
// astro.config.mjs
import { defineConfig } from 'astro/config';
import starlight from '@astrojs/starlight';

export default defineConfig({
integrations: [
starlight({
title: 'Amazing',
}),
],
});
```

6. A step with a file tree

<FileTree>

- src/
- assets/
- **my-logo.svg**
- content/
- astro.config.mjs

</FileTree>

7. A step with an unordered list

- A
- B
- B1
- B2
- C

8. A step with some tabs

<Tabs syncKey="pkg">

<TabItem label="npm">

```sh
npx astro add tailwind
```

</TabItem>

<TabItem label="pnpm">

```sh
pnpm astro add tailwind
```

</TabItem>

<TabItem label="Yarn">

```sh
yarn astro add tailwind
```

</TabItem>

</Tabs>

9. A step with an ordered list

1. A
2. B
1. B1
2. B2
3. C

10. A step

</Steps>

9. A step

</Steps>
4 changes: 3 additions & 1 deletion packages/starlight/user-components/Steps.astro
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ const { html } = processSteps(content);
--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. */
Expand All @@ -31,7 +33,7 @@ const { html } = processSteps(content);

/* Custom list marker element. */
.sl-steps > li::before {
content: counter(list-item);
content: counter(steps-counter);
position: absolute;
top: 0;
inset-inline-start: 0;
Expand Down
6 changes: 6 additions & 0 deletions packages/starlight/user-components/rehype-steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ const stepsProcessor = rehype()
} else {
rootElement.properties.className.push('sl-steps');
}

// Add the `start` attribute as a CSS custom property so we can use it as the starting index
// of the steps custom counter.
if (typeof rootElement.properties.start === 'number') {
rootElement.properties.style = `${rootElement.properties.style ?? ''} --sl-steps-start: ${rootElement.properties.start - 1};`;
}
delucis marked this conversation as resolved.
Show resolved Hide resolved
};
});

Expand Down
Loading