Skip to content

Commit 0b59dd6

Browse files
committed
cookbook: Add section about styles
1 parent 8a2f96d commit 0b59dd6

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ description: Common patterns when writing extensions
44
sidebar:
55
order: 3
66
---
7+
import { FileTree } from "@astrojs/starlight/components";
78

89
## Extension entrypoints
910

@@ -36,7 +37,7 @@ Remember to [restart the dev server](/ext-dev/pitfalls#restarting-dev-mode-is-re
3637

3738
On the web target (`index.ts`), you can export [patches](/ext-dev/webpack#patching), [Webpack modules](/ext-dev/webpack#webpack-module-insertion), and CSS styles:
3839

39-
```ts
40+
```ts title="index.ts"
4041
import type { ExtensionWebExports } from "@moonlight-mod/types";
4142

4243
export const patches: ExtensionWebExports["patches"] = [];
@@ -74,6 +75,37 @@ export default function MyElement() {
7475

7576
You can use this React component in a [patch](/ext-dev/webpack#patching) or through an [extension library](/ext-dev/api#app-panels). React must be imported into the scope [when using JSX](/ext-dev/pitfalls#using-jsx).
7677

78+
## Using custom styles
79+
80+
Custom CSS can be placed in a file named `style.css`:
81+
82+
<FileTree>
83+
- src/
84+
- sampleExtension/
85+
- manifest.json
86+
- **style.css**
87+
</FileTree>
88+
89+
```css title="style.css"
90+
.sampleExtension-whatever {
91+
/* your styles go here... */
92+
}
93+
```
94+
95+
Alternatively, you can [export CSS as strings from `index.ts`](#exporting-from-your-extension):
96+
97+
```ts title="index.ts"
98+
import type { ExtensionWebExports } from "@moonlight-mod/types";
99+
100+
export const styles: ExtensionWebExports["styles"] = [
101+
`
102+
.sampleExtension-whatever {
103+
/* your styles go here... */
104+
}
105+
`
106+
];
107+
```
108+
77109
## Using Flux
78110

79111
Discord internally maintains a heavily-modified fork of [Flux](https://github.com/facebookarchive/flux). Various state and events in the client are managed with Flux.

0 commit comments

Comments
 (0)