Skip to content

Commit

Permalink
docs: backfill next readme with getGlobalStyles() and `getTemplat…
Browse files Browse the repository at this point in the history
…eData()` (#46)

* feat: adds docs for mudating default data

* refactor: updates file namec

* refactor: updates type definations in mutating-query doc

* fix: package URL

* refactor: migrate docs to next package

* refactor: format next readme

* refactor: add link to component in next package readme

* chore: cleanup

---------

Co-authored-by: Dovid Levine <[email protected]>
  • Loading branch information
Pathan-Amaankhan and justlevine authored Feb 18, 2025
1 parent 58fb993 commit f78375e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This guide will walk you through setting up a headless WordPress app using SnapW
### Prerequisites

- **PHP**: v7.4+
- **WordPress**: v6.0+
- **WordPress**: v6.7+
- A **[Block Theme](https://wordpress.org/documentation/article/block-themes/)**

### Installation Steps
Expand Down
52 changes: 42 additions & 10 deletions packages/next/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,16 @@ export default function ScriptModuleExample() {
<ScriptModule
src="https://example.com/main.js"
handle="example-main-script"
dependencies=[
{
importType: 'static',
connectedScriptModule: {
handle: '@module',
src: 'http://example.com/index.min.js'
}
}
]
/>
dependencies={[
{
importType: 'static',
connectedScriptModule: {
handle: '@module',
src: 'http://example.com/index.min.js'
}
}
]}
/>
</div>
);
}
Expand Down Expand Up @@ -207,6 +207,38 @@ export default function CustomFonts() {
}
```

### `getGlobalStyles()`

Global styles can be modified by passing the `getGlobalStyles` attribute to the [RootLayout](./src/root-layout/index.tsx) within the `src/app/layout.tsx` file of the frontend application.

`getGlobalStyles` takes an async callback function that returns an object containing global styles.

The default definition for `getGlobalStyles` function passed in `getGlobalStyles` attribute can be found in [@snapwp/query](../packages/query/README.md) package.

Type Definition of `getGlobalStyles`:

```typescript
type getGlobalStyles = () => Promise< GlobalHeadProps >;
```

Type definition of `GlobalHeadProps` can be found in [@snapwp/core](../packages/core/README.md) package.

### `getTemplateData()`

Template data can be modified by passing `getTemplateData` attribute to the [TemplateRenderer](./src/template-renderer/index.tsx) within `src/app/[[...path]]/page.tsx` file of the frontend application.

`getTemplateData` takes an async callback to get template styles and content.

The default definition for `getTemplateData` function passed in `getTemplateData` attribute can be found in [@snapwp/query](../packages/query/README.md) package.

Type Definition of `getTemplateData`:

```typescript
type getTemplateData = ( uri: string ) => Promise< TemplateData >;
```

Type definition of `TemplateData` can be found in [@snapwp/core](../packages/core/README.md) package.

## Contributing

This package is part of [SnapWP's monorepo](https://github.com/rtCamp/snapwp) and is actively maintained by [rtCamp](https://rtcamp.com/). Packages are published to [npm](https://www.npmjs.com/) from the `packages` directory, and can be used standalone in the headless WordPress ecosystem or as part of SnapWP's framework.
Expand Down

0 comments on commit f78375e

Please sign in to comment.