Skip to content

Commit e24f3ab

Browse files
nbarracloughclaude
andauthored
docs(@nylas/react): restructure README onto the SDK house style (#97)
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 925ef7b commit e24f3ab

2 files changed

Lines changed: 180 additions & 66 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nylas/react": patch
3+
---
4+
5+
Restructure the README onto the house style shared by the other Nylas SDKs, and document the hook options, hook return values, and button props that were previously missing.

‎packages/react/README.md‎

Lines changed: 175 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,94 @@
1-
# Nylas React Components
1+
<div align="center">
2+
<a href="https://www.nylas.com/">
3+
<img width="100%" alt="Nylas" src="https://github.com/user-attachments/assets/137517ae-244d-47a5-8ca7-b12984971fc4" />
4+
</a>
25

3-
React components for Nylas Scheduler
6+
<h1>Nylas React Components</h1>
47

5-
![npm](https://img.shields.io/npm/v/@nylas/react)
8+
<p>
9+
<strong>Scheduler components and OAuth connection hooks for React</strong>
10+
</p>
611

7-
## Requirements
12+
<p>
13+
<a href="https://www.npmjs.com/package/@nylas/react"><img src="https://img.shields.io/npm/v/@nylas/react" alt="npm version" /></a>
14+
<a href="https://www.npmjs.com/package/@nylas/react"><img src="https://img.shields.io/npm/dm/@nylas/react" alt="downloads" /></a>
15+
<a href="https://www.typescriptlang.org/"><img src="https://img.shields.io/badge/TypeScript-Ready-blue.svg" alt="TypeScript" /></a>
16+
<a href="LICENSE.md"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="license" /></a>
17+
</p>
818

9-
- [Node.js](https://nodejs.org/en/) v20 or higher
10-
- [React.js](https://react.dev/) v18 or higher
19+
<p>
20+
<a href="https://developer.nylas.com/docs/v3/scheduler/">📖 Scheduler guide</a> ·
21+
<a href="https://developer.nylas.com/docs/api/v3/scheduler/">📚 API Reference</a> ·
22+
<a href="https://dashboard-v3.nylas.com/register">🚀 Sign up</a> ·
23+
<a href="https://github.com/orgs/nylas-samples/repositories">💡 Samples</a> ·
24+
<a href="https://forums.nylas.com">💬 Forum</a>
25+
</p>
26+
</div>
27+
28+
<br />
29+
30+
`@nylas/react` gives you Nylas Scheduler as React components, so you can drop a booking page or a full scheduling-page editor into your app instead of building availability logic, timezone handling, and booking forms yourself. It also ships a `useNylasConnect` hook and a `NylasConnectButton` for the OAuth flow that connects a user's calendar.
31+
32+
This repository is for contributors and anyone installing from source. If you just want to use the library in your app, head to the [**Scheduler guide**](https://developer.nylas.com/docs/v3/scheduler/) on developer.nylas.com.
1133

12-
## Installation
34+
## Get started
1335

14-
Install Nylas React Components via npm:
36+
1. [Sign up for a free Nylas account](https://dashboard-v3.nylas.com/register) and grab your client ID from the [Nylas Dashboard](https://dashboard-v3.nylas.com/).
37+
2. Register your app's callback URI under **Hosted Authentication**, so the connection flow is allowed to run.
38+
3. Install the package and render your first component — see below.
39+
40+
The [Scheduler quickstart](https://developer.nylas.com/docs/v3/getting-started/scheduler/) walks through a working setup end to end, with the finished code in [quickstart-scheduler-react](https://github.com/nylas-samples/quickstart-scheduler-react).
41+
42+
## ⚙️ Install
1543

1644
```bash
1745
npm install @nylas/react@latest
46+
# or
47+
yarn add @nylas/react@latest
1848
```
1949

20-
or yarn
50+
### Requirements
51+
52+
- [Node.js](https://nodejs.org/en/) v20 or higher
53+
- [React](https://react.dev/) 18 or 19
54+
55+
The package ships its own TypeScript types, and exposes three subpaths so you only bundle what you use:
56+
57+
| Import from | Contains |
58+
| --- | --- |
59+
| `@nylas/react` | Everything below except the Connect symbols |
60+
| `@nylas/react/elements` | Scheduler and booking components |
61+
| `@nylas/react/utils` | `NylasIdentityRequestWrapper`, and the `LANGUAGE_CODE` type |
62+
| `@nylas/react/connect` | `useNylasConnect`, `NylasConnectButton`, and re-exports of `@nylas/connect` |
63+
64+
> **Note:** `useNylasConnect` and `NylasConnectButton` are available **only** from `@nylas/react/connect`, not from the package root.
65+
66+
To install from source:
2167

2268
```bash
23-
yarn add @nylas/react@latest
69+
git clone https://github.com/nylas/javascript.git
70+
cd javascript
71+
pnpm install
2472
```
2573

26-
## Exports overview
74+
## ⚡️ Usage
75+
76+
### Scheduler components
2777

28-
- **Elements**
29-
- `NylasSchedulerEditor`, `NylasScheduling`, `NylasSchedulingMethod`
30-
- Import from `@nylas/react` or `@nylas/react/elements`
78+
Three components are the entry points:
3179

32-
- **Connect**
33-
- `useNylasConnect`, `NylasConnectButton`
34-
- Import from `@nylas/react/connect`
80+
- **`NylasScheduling`** — the booking page your end users see.
81+
- **`NylasSchedulerEditor`** — the editor where your users build and configure scheduling pages.
82+
- **`NylasSchedulingMethod`** — picks a scheduling method.
3583

36-
## Getting Started
84+
Around 50 further components (`NylasAvailabilityPicker`, `NylasBookingForm`, `NylasBufferTime`, `NylasCancellationPolicy`, `NylasTimeslotPicker`, and so on) are exported as the building blocks those two compose, alongside `NylasNotetakerConfig` and a set of form primitives and icons. Most apps only need the entry points.
85+
86+
### Scheduler Editor
3787

3888
The following example adds the Nylas Scheduler Editor and Scheduling components to your React app.
3989

4090
> ⚠️ **Important:** Make sure to replace the `NYLAS_CLIENT_ID` with your Nylas Client ID. Your Nylas Client ID can be found in your app's Overview page on the [Nylas Dashboard](https://dashboard-v3.nylas.com).
4191
42-
### Adding the Components
43-
4492
```jsx
4593
import { BrowserRouter, Route, Routes } from "react-router-dom";
4694
import { NylasSchedulerEditor, NylasScheduling } from "@nylas/react";
@@ -101,32 +149,29 @@ function App() {
101149
export default App;
102150
```
103151

104-
### Start a local development server
152+
### Local development server
105153

106154
To create a Scheduling Page from the Scheduler Editor, you'll need a working Scheduler UI. To do this, run a local server to host your Scheduler Editor and Scheduling Pages.
107155

108-
Navigate the root directory of your project and run the following command.
156+
Navigate to the root directory of your project and run the following command.
109157

110158
```text
111159
npm run dev -- --port <PORT>
112160
```
113161

114162
After you run the command, open your browser to `http://localhost:<PORT>/scheduler-editor` to see your Scheduler Editor and create your first Scheduling Page.
115163

116-
117-
## Nylas Connect Hook
164+
### useNylasConnect hook
118165

119166
The `useNylasConnect` hook provides a simple way to add OAuth authentication to your React app using Nylas Connect.
120167

121-
### Basic Usage
122-
123168
```jsx
124169
import { useNylasConnect } from "@nylas/react/connect";
125170

126171
function LoginButton() {
127172
const { isConnected, connect, logout, grant, isLoading } = useNylasConnect({
128-
clientId: 'your-nylas-client-id',
129-
redirectUri: 'http://localhost:3000/callback'
173+
clientId: "your-nylas-client-id",
174+
redirectUri: "http://localhost:3000/callback",
130175
});
131176

132177
if (isLoading) return <div>Loading...</div>;
@@ -141,42 +186,45 @@ function LoginButton() {
141186
}
142187

143188
return (
144-
<button onClick={() => connect({ method: 'popup' })}>
145-
Connect Account
146-
</button>
189+
<button onClick={() => connect({ method: "popup" })}>Connect Account</button>
147190
);
148191
}
149192
```
150193
194+
#### Configuration
151195
152-
### Configuration
196+
`UseNylasConnectConfig` extends `ConnectConfig` from [`@nylas/connect`](https://github.com/nylas/javascript/tree/main/packages/nylas-connect), so every option there — `apiUrl`, `defaultScopes`, `persistTokens`, `logLevel`, `codeExchange`, `identityProviderToken`, and the rest — is accepted here too. The most common, plus the four the hook adds of its own:
153197
154198
| Option | Type | Default | Description |
155-
|--------|------|---------|-------------|
156-
| `clientId` | `string` | - | Your Nylas Client ID |
157-
| `redirectUri` | `string` | - | OAuth callback URL |
158-
| `autoHandleCallback` | `boolean` | `true` | Automatically handle OAuth callback |
159-
| `autoRefreshInterval` | `number` | - | Auto-refresh session interval (ms) |
160-
| `retryAttempts` | `number` | `0` | Number of retry attempts for failed operations |
161-
| `enableAutoRecovery` | `boolean` | `false` | Enable automatic error recovery |
199+
| --- | --- | --- | --- |
200+
| `clientId` | `string` | `NYLAS_CLIENT_ID` | Your Nylas Client ID |
201+
| `redirectUri` | `string` | `NYLAS_REDIRECT_URI` | OAuth callback URL |
202+
| `autoHandleCallback` | `boolean` | `true` | Automatically handle the OAuth callback |
203+
| `autoRefreshInterval` | `number` | disabled | Auto-refresh session interval, in ms |
204+
| `initialLoadingState` | `boolean` | `true` | Loading state the hook mounts with |
205+
| `retryAttempts` | `number` | `0` | Retry attempts for failed operations |
206+
| `enableAutoRecovery` | `boolean` | `false` | Automatic recovery from network errors |
162207
163-
### Hook Return Values
164-
165-
The hook returns an object with the following properties:
208+
#### Return values
166209
167210
**State:**
168-
- `isConnected` - Whether user is authenticated
169-
- `grant` - Current user's grant information
170-
- `isLoading` - Loading state for operations
171-
- `error` - Current error, if any
211+
212+
- `isConnected` — whether the user is authenticated
213+
- `grant` — the current user's `GrantInfo`, or `null`
214+
- `isLoading` — loading state for operations
215+
- `error` — current error, if any
172216
173217
**Actions:**
174-
- `connect(options)` - Start OAuth flow
175-
- `logout(grantId?)` - Sign out user
176-
- `refreshSession()` - Refresh current session
177-
- `subscribe(callback)` - Listen to connection events
178218
179-
### Environment Setup
219+
- `connect(options)` — start the OAuth flow
220+
- `logout(grantId?)` — sign the user out
221+
- `refreshSession()` — refresh the current session
222+
- `subscribe(callback)` — listen to connection events
223+
- `setLogLevel(level)` — change log verbosity at runtime
224+
225+
The underlying client is also returned as `connectClient`, for anything the hook doesn't wrap.
226+
227+
#### Environment setup
180228
181229
For security, use environment variables for your configuration:
182230
@@ -189,20 +237,16 @@ VITE_NYLAS_REDIRECT_URI=http://localhost:3000/callback
189237
```jsx
190238
const { isConnected, connect } = useNylasConnect({
191239
clientId: import.meta.env.VITE_NYLAS_CLIENT_ID,
192-
redirectUri: import.meta.env.VITE_NYLAS_REDIRECT_URI
240+
redirectUri: import.meta.env.VITE_NYLAS_REDIRECT_URI,
193241
});
194242
```
195243
244+
Next.js uses `NEXT_PUBLIC_` instead of `VITE_`.
196245
197-
198-
199-
200-
## Nylas Connect Button
246+
### NylasConnectButton
201247
202248
The `NylasConnectButton` component provides a simple way to add email provider authentication to your React application.
203249
204-
### Basic Usage
205-
206250
```jsx
207251
import { NylasConnectButton } from "@nylas/react/connect";
208252

@@ -222,7 +266,18 @@ function App() {
222266
}
223267
```
224268
225-
### External Identity Provider Integration
269+
Beyond `clientId` and `redirectUri`, the props fall into four groups:
270+
271+
| Group | Props |
272+
| --- | --- |
273+
| Connection | `apiUrl`, `defaultScopes`, `persistTokens`, `method`, `provider`, `scopes`, `loginHint`, `popupWidth`, `popupHeight` |
274+
| Appearance | `text`, `children`, `variant` (`primary` \| `outline`), `size` (`sm` \| `md` \| `lg`), `className`, `style`, `disabled`, `unstyled`, `cssVars` |
275+
| Callbacks | `onStart`, `onSuccess`, `onError`, `onCancel` |
276+
| Advanced | `identityProviderToken`, `codeExchange` |
277+
278+
`unstyled` drops the default styling entirely; `cssVars` re-themes it without doing so, accepting `--nylas-btn-bg`, `--nylas-btn-fg`, `--nylas-btn-border`, and `--nylas-btn-bg-hover`.
279+
280+
### External identity providers
226281
227282
For applications that use external identity providers (via JWKS), you can pass identity provider tokens during authentication:
228283
@@ -253,7 +308,9 @@ function App() {
253308
}
254309
```
255310
256-
### Custom Backend Code Exchange
311+
Returning `null` continues without IDP claims; throwing fails authentication. Per-provider setup guides for Auth0, Clerk, Google, and WorkOS: [external identity providers](https://developer.nylas.com/docs/v3/auth/nylas-connect-react/use-external-idp/).
312+
313+
### Custom code exchange
257314
258315
For enhanced security, you can handle the OAuth code exchange on your backend:
259316
@@ -309,12 +366,64 @@ function App() {
309366
}
310367
```
311368
312-
## Links
369+
### Error handling
370+
371+
The hook surfaces failures on `error` rather than throwing, so render from it directly. `NylasConnectButton` reports them through `onError`, and `onCancel` fires separately when the user closes the popup.
372+
373+
```jsx
374+
const { error, connect } = useNylasConnect({ clientId, redirectUri });
375+
376+
if (error) return <p role="alert">Couldn't connect: {error.message}</p>;
377+
```
378+
379+
Every error extends `NylasConnectError` and sets a distinct `name` — `PopupError` for a blocked or closed popup, `ConfigError` for a missing `clientId`, `OAuthError` when the provider rejects the request. All of them are re-exported from `@nylas/react/connect`.
380+
381+
## 💡 Examples
382+
383+
- [quickstart-scheduler-react](https://github.com/nylas-samples/quickstart-scheduler-react) — the finished code for the Scheduler quickstart.
384+
- [nylas-samples](https://github.com/orgs/nylas-samples/repositories) — full sample apps and product quickstarts.
385+
386+
## 🤖 AI agents
387+
388+
[nylas/skills](https://github.com/nylas/skills) drops Nylas into Claude Code, Cursor, Codex, and other agents that support the skills format:
389+
390+
```bash
391+
npx skills add nylas/skills
392+
/plugin marketplace add nylas/skills # Claude Code
393+
```
394+
395+
## 📚 Reference
396+
397+
- **Scheduler guide:** [developer.nylas.com/docs/v3/scheduler](https://developer.nylas.com/docs/v3/scheduler/)
398+
- **Scheduler quickstart:** [developer.nylas.com/docs/v3/getting-started/scheduler](https://developer.nylas.com/docs/v3/getting-started/scheduler/)
399+
- **Scheduler API reference:** [developer.nylas.com/docs/api/v3/scheduler](https://developer.nylas.com/docs/api/v3/scheduler/)
400+
- **React connect guide:** [developer.nylas.com/docs/v3/auth/nylas-connect-react](https://developer.nylas.com/docs/v3/auth/nylas-connect-react/)
401+
- **`useNylasConnect` reference:** [every option and return value](https://developer.nylas.com/docs/v3/auth/nylas-connect-react/usenylasconnect/)
402+
- **`NylasConnectButton` reference:** [every prop](https://developer.nylas.com/docs/v3/auth/nylas-connect-react/nylasconnectbutton/)
403+
- **Identity provider guides:** [Auth0, Clerk, Google, WorkOS](https://developer.nylas.com/docs/v3/auth/nylas-connect-react/use-external-idp/)
404+
- **Developer forum:** [forums.nylas.com](https://forums.nylas.com/)
405+
- **Changelog:** [CHANGELOG.md](CHANGELOG.md)
406+
407+
## ✨ Upgrading
408+
409+
See [`CHANGELOG.md`](CHANGELOG.md) for per-release notes.
410+
411+
## 💙 Contributing
412+
413+
Issues, ideas, and pull requests welcome — see [CONTRIBUTING.md](../../CONTRIBUTING.md). Before opening a large change, please open an issue or post in the [forum](https://forums.nylas.com) so we can sanity-check the direction.
414+
415+
## 🔒 Security
416+
417+
Found a vulnerability? Please **don't** open a public issue. Report it through our [Vulnerability Disclosure Policy](https://www.nylas.com/security/vulnerability-disclosure-policy/).
418+
419+
## 🔗 Other Nylas SDKs
313420

314-
A complete walkthrough for setting up Scheduler can be found at [https://developer.nylas.com/docs/v3/getting-started/scheduler/](https://developer.nylas.com/docs/v3/getting-started/scheduler/), with the complete code available on [GitHub](https://github.com/nylas-samples/quickstart-scheduler-react).
421+
- [@nylas/connect](https://github.com/nylas/javascript/tree/main/packages/nylas-connect) · `npm install @nylas/connect`
422+
- [nylas-nodejs](https://github.com/nylas/nylas-nodejs) · `npm install nylas`
423+
- [nylas-python](https://github.com/nylas/nylas-python) · `pip install nylas`
424+
- [nylas-ruby](https://github.com/nylas/nylas-ruby) · `gem install nylas`
425+
- [nylas-java](https://github.com/nylas/nylas-java) · Maven / Gradle (Kotlin too)
315426

316-
### Further reading:
427+
## 📝 License
317428

318-
- [Scheduler documentation](https://developer.nylas.com/docs/v3/scheduler/)
319-
- [Scheduler API reference](https://developer.nylas.com/docs/api/v3/scheduler/)
320-
- [Developer Forums](https://forums.nylas.com/)
429+
MIT — see [LICENSE.md](LICENSE.md).

0 commit comments

Comments
 (0)