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 support for synced tabs #640

Merged
merged 32 commits into from Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
42dd4cc
feat: synced tabs
HiDeoo Sep 2, 2023
8dad024
test: add e2e tests
HiDeoo Sep 4, 2023
695cd01
docs: add synced tabs documentation
HiDeoo Sep 4, 2023
79b6e98
docs: use synced tabs in existing docs
HiDeoo Sep 4, 2023
9bb696d
docs: add e2e tests section to contributing guide
HiDeoo Sep 4, 2023
23b85c5
chore: add changeset
HiDeoo Sep 4, 2023
a5d6f13
test: update unit test coverage excludes
HiDeoo Sep 4, 2023
c056462
Merge branch 'main' into hd-feat-tabs-sync
delucis Sep 28, 2023
e22902b
Merge branch 'main' into hd-feat-tabs-sync
HiDeoo Dec 13, 2023
d99b29c
chore: update pr
HiDeoo Dec 13, 2023
e7e9f30
Merge branch 'main' into hd-feat-tabs-sync
HiDeoo Mar 25, 2024
d1d44ed
chore: update pr
HiDeoo Mar 25, 2024
f81a85e
fix: make tabs `syncKey` prop optional
HiDeoo Mar 25, 2024
f430682
feat: add tab scroll position lock
HiDeoo Mar 26, 2024
ea0ffcc
chore: update changeset
HiDeoo Mar 26, 2024
a878d76
ci: update e2e tests workflow
HiDeoo Mar 26, 2024
338f9b8
Merge branch 'main' into hd-feat-tabs-sync
delucis Apr 12, 2024
02743f4
Merge branch 'main' into hd-feat-tabs-sync
HiDeoo Apr 15, 2024
eff441f
refactor: calculate `previousTabsOffset` only for synced tabs
HiDeoo Apr 15, 2024
0c22232
docs: spell out E2E tests acronym
HiDeoo Apr 15, 2024
7649aca
docs: update sync tabs documentation
HiDeoo Apr 15, 2024
543e992
chore: add line height changeset
HiDeoo Apr 15, 2024
d98003f
test: add traces
HiDeoo Apr 15, 2024
bad60e4
test: save e2e reports
HiDeoo Apr 15, 2024
a8989df
test: disable dev toolbar
HiDeoo Apr 15, 2024
6a1a5e1
test: use prod build for e2e tests
HiDeoo Apr 15, 2024
101e5d6
docs: update `testFactory()` description in CONTRIBUTING.md
HiDeoo Apr 15, 2024
f682d22
Merge branch 'main' into hd-feat-tabs-sync
HiDeoo Apr 30, 2024
41a3f3b
docs: update synced tabs description
HiDeoo Apr 30, 2024
a1daf77
Merge branch 'main' into hd-feat-tabs-sync
delucis Apr 30, 2024
70cb28e
Increase JS budget by 500 bytes
delucis Apr 30, 2024
6f12a6b
Merge branch 'main' into hd-feat-tabs-sync
delucis Apr 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .changeset/config.json
Expand Up @@ -9,7 +9,7 @@
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": ["starlight-docs", "@example/*", "starlight-file-icons-generator"],
"ignore": ["starlight-docs", "@example/*", "starlight-file-icons-generator", "@e2e/*"],
"___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
"onlyUpdatePeerDependentsWhenOutOfRange": true
}
Expand Down
5 changes: 5 additions & 0 deletions .changeset/eight-pens-end.md
@@ -0,0 +1,5 @@
---
'@astrojs/starlight': minor
---

Adds support for syncing multiple sets of tabs on the same page.
13 changes: 13 additions & 0 deletions .changeset/slimy-swans-teach.md
@@ -0,0 +1,13 @@
---
'@astrojs/starlight': minor
---

Updates the default `line-height` from `1.8` to `1.75`. This change avoids having a line height with a fractional part which can cause scripts accessing dimensions involving the line height to get an inconsistent rounded value in various browsers.

If you want to preserve the previous `line-height`, you can add the following custom CSS to your site:

```css
:root {
--sl-line-height: 1.8;
}
```
14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -30,6 +30,20 @@ jobs:
- name: Test packages
run: pnpm -r test:coverage

e2e-test:
name: Run E2E tests
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'pnpm'
- run: pnpm i
- name: Test packages
run: pnpm -r test:e2e

pa11y:
name: Check for accessibility issues
runs-on: ubuntu-20.04
Expand Down
31 changes: 31 additions & 0 deletions CONTRIBUTING.md
Expand Up @@ -187,6 +187,36 @@ pnpm test:coverage

This will print a table to your terminal and also generate an HTML report you can load in a web browser by opening [`packages/starlight/__coverage__/index.html`](./packages/starlight/__coverage__/index.html).

### End-to-end (E2E) tests

Starlight also includes E2E tests in [`packages/starlight/__e2e__/`](./packages/starlight/__e2e__/), which are run using [Playwright][playwright].

To run these tests, move into the Starlight package and then run `pnpm test:e2e`:

```sh
cd packages/starlight
pnpm test:e2e
```

#### Test fixtures

Each subdirectory of `packages/starlight/__e2e__/fixtures` should contain the basic files needed to run Starlight (`package.json`, `astro.config.mjs`, a content collection configuration in `src/content/config.ts` and some content to render in `src/content/docs/`).

The `testFactory()` helper can be used in a test file to define the fixture which will be built and loaded in a preview server during a set of tests.

```ts
// packages/starlight/__e2e__/feature.test.ts
import { testFactory } from './test-utils';

const test = await testFactory('./fixtures/basics/');
```

This allows you to run tests against different combinations of Astro and Starlight configuration options for various content.

#### When to add E2E tests?

E2E are most useful for testing what happens on a page after it has been loaded by a browser. They run slower than unit tests so they should be used sparingly when unit tests aren’t sufficient.

## Translations

Translations help make Starlight accessible to more people.
Expand Down Expand Up @@ -254,6 +284,7 @@ To add a language, you will need its BCP-47 tag and a label. See [“Adding a ne
[gfi]: https://github.com/withastro/starlight/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22+
[api-docs]: https://docs.astro.build/en/reference/integrations-reference/
[vitest]: https://vitest.dev/
[playwright]: https://playwright.dev/

## Showcase

Expand Down
6 changes: 3 additions & 3 deletions docs/src/content/docs/getting-started.mdx
Expand Up @@ -15,7 +15,7 @@ See the [manual setup instructions](/manual-setup/) to add Starlight to an exist

Create a new Astro + Starlight project by running the following command in your terminal:

<Tabs>
<Tabs syncKey="pkg">
<TabItem label="npm">

```sh
Expand Down Expand Up @@ -52,7 +52,7 @@ When working locally, [Astro’s development server](https://docs.astro.build/en

Inside your project directory, run the following command to start the development server:

<Tabs>
<Tabs syncKey="pkg">
<TabItem label="npm">

```sh
Expand Down Expand Up @@ -103,7 +103,7 @@ Be sure to update Starlight regularly!

Starlight is an Astro integration. You can update it and other Astro packages by running the following command in your terminal:

<Tabs>
<Tabs syncKey="pkg">
<TabItem label="npm">

```sh
Expand Down
43 changes: 43 additions & 0 deletions docs/src/content/docs/guides/components.mdx
Expand Up @@ -87,6 +87,49 @@ The code above generates the following tabs on the page:
</TabItem>
</Tabs>

#### Synced tabs

Keep multiple sets of tabs on the same page in sync with the `syncKey` attribute.
Switching to a synced tab will also switch to the tab with the same label in other `<Tabs>` that share the same `syncKey`.

To synchronize tabs, add an identical `syncKey` property to each related `<Tabs>` component.
delucis marked this conversation as resolved.
Show resolved Hide resolved

```mdx 'syncKey="constellations"'
# src/content/docs/example.mdx

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

_Some stars:_

<Tabs syncKey="constellations">
<TabItem label="Orion">Bellatrix, Rigel, Betelgeuse</TabItem>
<TabItem label="Gemini">Pollux, Castor A, Castor B</TabItem>
</Tabs>

_Some exoplanets:_

<Tabs syncKey="constellations">
<TabItem label="Orion">HD 34445 b, Gliese 179 b, Wasp-82 b</TabItem>
<TabItem label="Gemini">Pollux b, HAT-P-24b, HD 50554 b</TabItem>
</Tabs>
```

The code above generates the following on the page:

_Some stars:_

<Tabs syncKey="constellations">
<TabItem label="Orion">Bellatrix, Rigel, Betelgeuse</TabItem>
<TabItem label="Gemini">Pollux, Castor A, Castor B</TabItem>
</Tabs>

_Some exoplanets:_

<Tabs syncKey="constellations">
<TabItem label="Orion">HD 34445 b, Gliese 179 b, Wasp-82 b</TabItem>
<TabItem label="Gemini">Pollux b, HAT-P-24b, HD 50554 b</TabItem>
</Tabs>

### Cards

import { Card, CardGrid } from '@astrojs/starlight/components';
Expand Down
6 changes: 3 additions & 3 deletions docs/src/content/docs/guides/css-and-tailwind.mdx
Expand Up @@ -63,7 +63,7 @@ The Starlight Tailwind plugin applies the following configuration:

Start a new Starlight project with Tailwind CSS pre-configured using `create astro`:

<Tabs>
<Tabs syncKey="pkg">
<TabItem label="npm">

```sh
Expand Down Expand Up @@ -95,7 +95,7 @@ If you already have a Starlight site and want to add Tailwind CSS, follow these

1. Add Astro’s Tailwind integration:

<Tabs>
<Tabs syncKey="pkg">

<TabItem label="npm">

Expand Down Expand Up @@ -125,7 +125,7 @@ If you already have a Starlight site and want to add Tailwind CSS, follow these

2. Install the Starlight Tailwind plugin:

<Tabs>
<Tabs syncKey="pkg">

<TabItem label="npm">

Expand Down
4 changes: 2 additions & 2 deletions docs/src/content/docs/guides/customization.mdx
Expand Up @@ -130,7 +130,7 @@ You can customize — or even disable — the table of contents globally in the

By default, `<h2>` and `<h3>` headings are included in the table of contents. Change which headings levels to include site-wide using the `minHeadingLevel` and `maxHeadingLevel` options in your [global `tableOfContents`](/reference/configuration/#tableofcontents). Override these defaults on an individual page by adding the corresponding [frontmatter `tableOfContents`](/reference/frontmatter/#tableofcontents) properties:

<Tabs>
<Tabs syncKey="config-type">
<TabItem label="Frontmatter">

```md {4-6}
Expand Down Expand Up @@ -164,7 +164,7 @@ defineConfig({

Disable the table of contents entirely by setting the `tableOfContents` option to `false`:

<Tabs>
<Tabs syncKey="config-type">
<TabItem label="Frontmatter">

```md {4}
Expand Down
3 changes: 3 additions & 0 deletions packages/starlight/__e2e__/.gitignore
@@ -0,0 +1,3 @@
# generated types
.astro/
dist/
10 changes: 10 additions & 0 deletions packages/starlight/__e2e__/fixtures/basics/astro.config.mjs
@@ -0,0 +1,10 @@
import starlight from '@astrojs/starlight';
import { defineConfig } from 'astro/config';

export default defineConfig({
integrations: [
starlight({
title: 'Basics',
}),
],
});
9 changes: 9 additions & 0 deletions packages/starlight/__e2e__/fixtures/basics/package.json
@@ -0,0 +1,9 @@
{
"name": "@e2e/basics",
"version": "0.0.0",
"private": true,
"dependencies": {
"@astrojs/starlight": "workspace:*",
"astro": "^4.3.5"
}
}
@@ -0,0 +1,6 @@
import { defineCollection } from 'astro:content';
import { docsSchema } from '@astrojs/starlight/schema';

export const collections = {
docs: defineCollection({ schema: docsSchema() }),
};