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 a Tailwind plugin and docs #337

Merged
merged 27 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8733174
Expose a Tailwind plugin from the main Starlight package
delucis Jul 14, 2023
4076587
Add tailwind starter project/example
delucis Jul 14, 2023
ace4da9
Add changeset
delucis Jul 14, 2023
3711edd
Merge branch 'main' into dx-387/tailwind-compat
delucis Aug 4, 2023
99334c3
Give plugin function a name
delucis Aug 4, 2023
760de15
Move Tailwind plugin to dedicated npm package
delucis Aug 4, 2023
a00e7ec
Add label for Tailwind package
delucis Aug 4, 2023
bfa0ff9
Refactor Tailwind plugin to use Tailwind’s `plugin` helper
delucis Aug 4, 2023
c93ca58
Fix-up new plugin shape
delucis Aug 4, 2023
c585e73
Add Tailwind tests
delucis Aug 4, 2023
3c56612
Update CI unit test command to run all packages
delucis Aug 4, 2023
f6b0bb6
Merge branch 'main' into dx-387/tailwind-compat
delucis Aug 4, 2023
7499bf8
Add README
delucis Aug 4, 2023
4de7617
Create new styling & Tailwind guide
delucis Aug 4, 2023
5c56f25
Run Prettier
delucis Aug 4, 2023
072c427
Bring example dependencies up to date
delucis Aug 4, 2023
4be0bee
Tweak Tailwind example site title
delucis Aug 4, 2023
1702734
Use accent & dark variants in starter landing hero
delucis Aug 4, 2023
ecf2c16
Remove repetitive comments
delucis Aug 5, 2023
58dd4f2
Bump astro to latest
delucis Aug 7, 2023
8e3602b
Remove workarounds
delucis Aug 7, 2023
a048abe
Upgrade to Astro with injectRoute fix
delucis Aug 7, 2023
54a76f7
Merge branch 'main' into dx-387/tailwind-compat
delucis Aug 7, 2023
3c7c99f
Add back custom CSS approach
delucis Aug 8, 2023
06d6c26
Update manual set-up docs with extra required steps
delucis Aug 8, 2023
82b64d6
Add docs note about what the TW plugin does
delucis Aug 9, 2023
adf7903
Merge branch 'main' into dx-387/tailwind-compat
delucis Aug 10, 2023
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
5 changes: 5 additions & 0 deletions .changeset/flat-hounds-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/starlight-tailwind": minor
---

Add Tailwind plugin
3 changes: 3 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ i18n:
'🌟 core':
- packages/starlight/**

'🌟 tailwind':
- packages/tailwind/**

'📚 docs':
- docs/**
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ jobs:
node-version: ${{ env.NODE_VERSION }}
cache: 'pnpm'
- run: pnpm i
- name: Test packages/starlight
working-directory: ./packages/starlight
run: pnpm test:coverage
- name: Test packages
run: pnpm -r test:coverage

pa11y:
name: Check for accessibility issues
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ pnpm-debug.log*

# macOS-specific files
.DS_Store

# Vitest
__coverage__/
196 changes: 196 additions & 0 deletions docs/src/content/docs/guides/css-and-tailwind.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
---
title: CSS & Styling
delucis marked this conversation as resolved.
Show resolved Hide resolved
description: Learn how to style your Starlight site with custom CSS or integrate with Tailwind CSS.
---

You can style your Starlight site with custom CSS files or use the Starlight Tailwind plugin.

## Custom CSS styles

Customize the styles applied to your Starlight site by providing additional CSS files to modify or extend Starlight’s default styles.

1. Add a CSS file to your `src/` directory.
For example, you could override Starlight’s default blue accent hue to purple:

```css
/* src/styles/custom.css */
:root {
--sl-hue-accent: 270;
}
```

2. Add the path to your CSS file to Starlight’s `customCss` array in `astro.config.mjs`:

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

export default defineConfig({
integrations: [
starlight({
title: 'Docs With Custom CSS',
customCss: [
// Relative path to your custom CSS file
'./src/styles/custom.css',
],
}),
],
});
```

You can see all the CSS custom properties used by Starlight that you can set to customize your site in the [`props.css` file on GitHub](https://github.com/withastro/starlight/blob/main/packages/starlight/style/props.css).

## Tailwind CSS

Tailwind CSS support in Astro projects is provided by the [Astro Tailwind integration](https://docs.astro.build/en/guides/integrations-guide/tailwind/).
Starlight provides a complementary Tailwind plugin to help configure Tailwind for compatibility with Starlight’s styles.

### Create a new project with Tailwind

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

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

<Tabs>
<TabItem label="npm">

```sh
# create a new project with npm
npm create astro@latest -- --template withastro/starlight/examples/tailwind
```

</TabItem>
<TabItem label="pnpm">

```sh
# create a new project with pnpm
pnpm create astro --template withastro/starlight/examples/tailwind
```

</TabItem>
<TabItem label="Yarn">

```sh
# create a new project with yarn
yarn create astro --template withastro/starlight/examples/tailwind
```

</TabItem>
</Tabs>

### Add Tailwind to an existing project

If you already have a Starlight site and want to add Tailwind CSS, follow these steps.

1. Add Astro’s Tailwind integration:

<Tabs>

<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>

2. Install the Starlight Tailwind plugin:
delucis marked this conversation as resolved.
Show resolved Hide resolved

<Tabs>

<TabItem label="npm">

```sh
npm install @astrojs/starlight-tailwind
```

</TabItem>

<TabItem label="pnpm">

```sh
pnpm install @astrojs/starlight-tailwind
```

</TabItem>

<TabItem label="Yarn">

```sh
yarn add @astrojs/starlight-tailwind
```

</TabItem>

</Tabs>

3. Add the Starlight Tailwind plugin to `tailwind.config.cjs`:

```js ins={2,7}
// tailwind.config.cjs
const starlightPlugin = require('@astrojs/starlight-tailwind');

/** @type {import('tailwindcss').Config} */
module.exports = {
content: ['./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}'],
plugins: [starlightPlugin()],
};
```

### Styling Starlight with Tailwind

Starlight will use values from your [Tailwind theme config](https://tailwindcss.com/docs/theme) in its UI.

If set, the following options will override Starlight’s default styles:

- `colors.accent` — used for links and current item highlighting
- `colors.gray` — used for background colors and borders
- `fontFamily.sans` — used for UI and content text
- `fontFamily.mono` — used for code examples

```js {12,14,18,20}
// tailwind.config.cjs
const starlightPlugin = require('@astrojs/starlight-tailwind');
const colors = require('tailwindcss/colors');

/** @type {import('tailwindcss').Config} */
module.exports = {
content: ['./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}'],
theme: {
extend: {
colors: {
// Your preferred accent color. Indigo is closest to Starlight’s defaults.
accent: colors.indigo,
// Your preferred gray scale. Zinc is closest to Starlight’s defaults.
gray: colors.zinc,
},
fontFamily: {
// Your preferred text font. Starlight uses a system font stack by default.
sans: ['"Atkinson Hyperlegible"'],
// Your preferred code font. Starlight uses system monospace fonts by default.
mono: ['"IBM Plex Mono"'],
},
},
},
plugins: [starlightPlugin()],
};
```
42 changes: 3 additions & 39 deletions docs/src/content/docs/guides/customization.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Customizing Starlight
description: Learn how to make your Starlight site your own with custom styles, fonts, and more.
description: Learn how to make your Starlight site your own with your logo, custom fonts, landing page design and more.
---

import { Tabs, TabItem } from '@astrojs/starlight/components';
Expand Down Expand Up @@ -263,42 +263,6 @@ hero:
---
```

## Custom CSS styles

Customize the styles applied to your Starlight site by providing additional CSS files to modify or extend Starlight’s default styles.

1. Add a CSS file to your `src/` directory.
For example, you could override Starlight’s default blue accent hue to purple:

```css
/* src/styles/custom.css */
:root {
--sl-hue-accent: 270;
}
```

2. Add the path to your CSS file to Starlight’s `customCss` array in `astro.config.mjs`:

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

export default defineConfig({
integrations: [
starlight({
title: 'Docs With Custom CSS',
customCss: [
// Relative path to your custom CSS file
'./src/styles/custom.css',
],
}),
],
});
```

You can see all the CSS custom properties used by Starlight that you can set to customize your site in the [`props.css` file on GitHub](https://github.com/withastro/starlight/blob/main/packages/starlight/style/props.css).

## Custom fonts

By default, Starlight uses sans-serif fonts available on a user’s local device for all text.
Expand Down Expand Up @@ -426,7 +390,7 @@ It provides npm modules you can install for the fonts you want to use and includ

### Use fonts

To apply the font you set up to your site, use your chosen font’s name in a custom CSS file.
To apply the font you set up to your site, use your chosen font’s name in a [custom CSS file](/guides/css-and-tailwind/#custom-css-styles).
For example, to override Starlight’s default font everywhere, set the `--sl-font` custom property:

```css
Expand All @@ -448,4 +412,4 @@ main {
}
```

Follow the [custom CSS instructions](#custom-css-styles) to add your styles to your site.
Follow the [custom CSS instructions](/guides/css-and-tailwind/#custom-css-styles) to add your styles to your site.
21 changes: 21 additions & 0 deletions examples/tailwind/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# build output
dist/
# generated types
.astro/

# dependencies
node_modules/

# logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*


# environment variables
.env
.env.production

# macOS-specific files
.DS_Store
4 changes: 4 additions & 0 deletions examples/tailwind/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"recommendations": ["astro-build.astro-vscode"],
"unwantedRecommendations": []
}
11 changes: 11 additions & 0 deletions examples/tailwind/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": "0.2.0",
"configurations": [
{
"command": "./node_modules/.bin/astro dev",
"name": "Development server",
"request": "launch",
"type": "node-terminal"
}
]
}
52 changes: 52 additions & 0 deletions examples/tailwind/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Starlight Starter Kit: Tailwind

```
npm create astro@latest -- --template withastro/starlight/examples/tailwind
```

[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/withastro/starlight/tree/main/examples/basics)
[![Open with CodeSandbox](https://assets.codesandbox.io/github/button-edit-lime.svg)](https://codesandbox.io/p/sandbox/github/withastro/starlight/tree/main/examples/basics)

> 🧑‍🚀 **Seasoned astronaut?** Delete this file. Have fun!

## 🚀 Project Structure

Inside of your Astro + Starlight project, you'll see the following folders and files:

```
.
├── public/
├── src/
│ ├── assets/
│ ├── content/
│ │ ├── docs/
│ │ └── config.ts
│ └── env.d.ts
├── astro.config.mjs
├── package.json
├── tailwind.config.cjs
└── tsconfig.json
```

Starlight looks for `.md` or `.mdx` files in the `src/content/docs/` directory. Each file is exposed as a route based on its file name.

Images can be added to `src/assets/` and embedded in Markdown with a relative link.

Static assets, like favicons, can be placed in the `public/` directory.

## 🧞 Commands

All commands are run from the root of the project, from a terminal:

| Command | Action |
| :------------------------ | :----------------------------------------------- |
| `npm install` | Installs dependencies |
| `npm run dev` | Starts local dev server at `localhost:3000` |
| `npm run build` | Build your production site to `./dist/` |
| `npm run preview` | Preview your build locally, before deploying |
| `npm run astro ...` | Run CLI commands like `astro add`, `astro check` |
| `npm run astro -- --help` | Get help using the Astro CLI |

## 👀 Want to learn more?

Check out [Starlight’s docs](https://starlight.astro.build/), read [the Astro documentation](https://docs.astro.build), or jump into the [Astro Discord server](https://astro.build/chat).
Loading