Skip to content

Commit 712bf6a

Browse files
committed
update readme
1 parent 5f2aa1b commit 712bf6a

File tree

1 file changed

+31
-50
lines changed

1 file changed

+31
-50
lines changed

packages/toolbar/README.md

Lines changed: 31 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@ A lightweight, performant toolbar for headless WordPress. Works with any JavaScr
3030

3131
## Features
3232

33-
- 🎯 **Framework Agnostic** - Works with React, Vue, Svelte, or vanilla JavaScript
34-
-**Zero Dependencies** - Core library has no dependencies
35-
- 🔒 **Type Safe** - Full TypeScript support
36-
- 🪝 **React Hooks** - First-class React support with hooks
37-
- 🎨 **Headless UI** - Full control over rendering and styling
33+
- **Framework Agnostic** - Works with React, Vue, Svelte, or vanilla JavaScript
34+
- **Zero Dependencies** - Core library has no dependencies
35+
- **React Hooks** - First-class React support with hooks
36+
- **Headless UI** - Full control over rendering and styling
3837

3938
## Installation
4039

@@ -56,44 +55,44 @@ Each example includes setup instructions and demonstrates different integration
5655
### Vanilla JavaScript
5756

5857
```javascript
59-
import { Toolbar, VanillaRenderer } from '@wpengine/hwp-toolbar';
60-
import '@wpengine/hwp-toolbar/styles';
58+
import { Toolbar, VanillaRenderer } from "@wpengine/hwp-toolbar";
59+
import "@wpengine/hwp-toolbar/styles";
6160

6261
const toolbar = new Toolbar({
6362
onPreviewChange: (enabled) => {
64-
console.log('Preview mode:', enabled);
65-
}
63+
console.log("Preview mode:", enabled);
64+
},
6665
});
6766

6867
toolbar.setWordPressContext({
69-
user: { id: 1, name: 'Admin' },
70-
site: { url: 'https://example.com', adminUrl: 'https://example.com/wp-admin' },
71-
post: { id: 123, title: 'Hello World', type: 'post', status: 'draft', slug: 'hello-world' }
68+
user: { id: 1, name: "Admin" },
69+
site: { url: "https://example.com", adminUrl: "https://example.com/wp-admin" },
70+
post: { id: 123, title: "Hello World", type: "post", status: "draft", slug: "hello-world" },
7271
});
7372

74-
const renderer = new VanillaRenderer(toolbar, 'toolbar');
73+
const renderer = new VanillaRenderer(toolbar, "toolbar");
7574
```
7675

7776
### React (Recommended)
7877

7978
```tsx
80-
import { Toolbar } from '@wpengine/hwp-toolbar';
81-
import { useToolbar } from '@wpengine/hwp-toolbar/react';
79+
import { Toolbar } from "@wpengine/hwp-toolbar";
80+
import { useToolbar } from "@wpengine/hwp-toolbar/react";
8281

8382
const toolbar = new Toolbar({
8483
onPreviewChange: (enabled) => {
85-
console.log('Preview mode:', enabled);
86-
}
84+
console.log("Preview mode:", enabled);
85+
},
8786
});
8887

8988
function MyToolbar() {
9089
const { state, nodes } = useToolbar(toolbar);
9190

9291
return (
93-
<div className="toolbar">
94-
{nodes.map(node => (
92+
<div className='toolbar'>
93+
{nodes.map((node) => (
9594
<button key={node.id} onClick={node.onClick}>
96-
{typeof node.label === 'function' ? node.label() : node.label}
95+
{typeof node.label === "function" ? node.label() : node.label}
9796
</button>
9897
))}
9998
{state.user && <span>User: {state.user.name}</span>}
@@ -107,11 +106,13 @@ function MyToolbar() {
107106
### Toolbar
108107

109108
**Constructor**
109+
110110
```javascript
111111
new Toolbar(config?)
112112
```
113113
114114
**Config:**
115+
115116
- `onPreviewChange?: (enabled: boolean) => void` - Preview toggle callback
116117
117118
**Methods:**
@@ -139,9 +140,9 @@ toolbar.destroy()
139140
### VanillaRenderer
140141
141142
```javascript
142-
const renderer = new VanillaRenderer(toolbar, 'element-id');
143+
const renderer = new VanillaRenderer(toolbar, "element-id");
143144
// or
144-
const renderer = new VanillaRenderer(toolbar, document.getElementById('toolbar'));
145+
const renderer = new VanillaRenderer(toolbar, document.getElementById("toolbar"));
145146

146147
// Cleanup
147148
renderer.destroy();
@@ -160,7 +161,7 @@ The toolbar includes three built-in nodes:
160161
Import the base styles:
161162
162163
```javascript
163-
import '@wpengine/hwp-toolbar/styles';
164+
import "@wpengine/hwp-toolbar/styles";
164165
```
165166
166167
### Customization
@@ -174,22 +175,14 @@ Override CSS custom properties:
174175
}
175176
```
176177
177-
Available variables:
178-
- `--hwp-toolbar-bg` - Background color
179-
- `--hwp-toolbar-border` - Border color
180-
- `--hwp-toolbar-text` - Text color
181-
- `--hwp-toolbar-primary` - Primary button color
182-
- `--hwp-toolbar-primary-hover` - Primary button hover
183-
- And more...
184-
185178
## React Hooks API
186179
187180
### `useToolbar(toolbar)`
188181
189182
Returns both state and nodes in a single hook:
190183
191184
```tsx
192-
import { useToolbar } from '@wpengine/hwp-toolbar/react';
185+
import { useToolbar } from "@wpengine/hwp-toolbar/react";
193186

194187
function MyToolbar() {
195188
const { state, nodes } = useToolbar(toolbar);
@@ -202,7 +195,7 @@ function MyToolbar() {
202195
Subscribe to toolbar state only:
203196
204197
```tsx
205-
import { useToolbarState } from '@wpengine/hwp-toolbar/react';
198+
import { useToolbarState } from "@wpengine/hwp-toolbar/react";
206199

207200
function UserDisplay() {
208201
const state = useToolbarState(toolbar);
@@ -215,15 +208,15 @@ function UserDisplay() {
215208
Subscribe to visible nodes only:
216209
217210
```tsx
218-
import { useToolbarNodes } from '@wpengine/hwp-toolbar/react';
211+
import { useToolbarNodes } from "@wpengine/hwp-toolbar/react";
219212

220213
function ToolbarButtons() {
221214
const nodes = useToolbarNodes(toolbar);
222215
return (
223216
<>
224-
{nodes.map(node => (
217+
{nodes.map((node) => (
225218
<button key={node.id} onClick={node.onClick}>
226-
{typeof node.label === 'function' ? node.label() : node.label}
219+
{typeof node.label === "function" ? node.label() : node.label}
227220
</button>
228221
))}
229222
</>
@@ -241,8 +234,8 @@ function ToolbarButtons() {
241234
</template>
242235

243236
<script setup>
244-
import { onMounted, onUnmounted, ref } from 'vue';
245-
import { Toolbar, VanillaRenderer } from '@wpengine/hwp-toolbar';
237+
import { onMounted, onUnmounted, ref } from "vue";
238+
import { Toolbar, VanillaRenderer } from "@wpengine/hwp-toolbar";
246239

247240
const toolbarRef = ref(null);
248241
let toolbar, renderer;
@@ -263,18 +256,6 @@ onUnmounted(() => {
263256
264257
See `demo.html` for a complete example.
265258
266-
## TypeScript
267-
268-
```typescript
269-
import type {
270-
Toolbar,
271-
ToolbarState,
272-
WordPressUser,
273-
WordPressPost,
274-
WordPressSite
275-
} from '@wpengine/hwp-toolbar';
276-
```
277-
278259
## Development
279260
280261
```bash

0 commit comments

Comments
 (0)