Skip to content

Commit

Permalink
Update to latest version @react-email/render (#13)
Browse files Browse the repository at this point in the history
* Add trait, emails relative from basepath by default, update readme.
* Npm install from vendor directory
* Drop php 8.1 from CI
* Update readme
  • Loading branch information
maantje authored Mar 1, 2025
1 parent 66f7674 commit a3a10f3
Show file tree
Hide file tree
Showing 15 changed files with 849 additions and 10,356 deletions.
25 changes: 15 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,25 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [ 8.1, 8.2 ]
testbench: [7.*, 8.*]
php: [ 8.2, 8.3, 8.4]
testbench: [7.*, 8.*, 9.*, 10.*]
steps:
- uses: actions/checkout@v3

- name: Set Node.js 16.x
uses: actions/setup-node@v3
- uses: pnpm/action-setup@v4
name: Install pnpm
with:
node-version: 16.x
version: 10
run_install: false

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -25,11 +35,6 @@ jobs:
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
coverage: none

- name: Install yarn dependencies
uses: borales/actions-yarn@v4
with:
cmd: install

- name: Install composer dependencies
run: |
composer require "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/vendor
.phpunit.result.cache
.phpunit.cache
composer.lock
70 changes: 43 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
# React email for Laravel
# React Email for Laravel

This package allows you to easily send [React email](https://react.email/) emails with Laravel.
Easily send [React Email](https://react.email/) emails with Laravel using this package.

## Install
## Installation

``` bash
First, install the package via Composer:

```bash
composer require maantje/react-email
yarn add @j4mie/react-email
```

## Usage
Then, install the required Node dependencies:

```bash
npm install vendor/maantje/react-email
```

## Getting Started

Install React email ([automatic](https://react.email/docs/getting-started/automatic-setup), [manual](https://react.email/docs/getting-started/manual-setup)).
1. Install React Email using the [automatic](https://react.email/docs/getting-started/automatic-setup) or [manual](https://react.email/docs/getting-started/manual-setup) setup.
2. Create an email component in the `emails` directory (e.g., `new-user.tsx`). Ensure the component is the default export.

Create an email in the emails directory e.g. new-user.tsx, make sure the component is the default export.
Example email component:

``` tsx
import { Html } from '@react-email/html';
import { Text } from '@react-email/text';
```tsx
import * as React from 'react';
import { Text, Html } from '@react-email/components';

export default function Email({ user }) {
return (
Expand All @@ -29,29 +36,35 @@ export default function Email({ user }) {
}
```

Set up the email directory in your Laravel .env.
``` env
REACT_EMAIL_DIRECTORY="/my/absolute/path/to/react-email-starter/emails/"
3. Define the email directory path in your Laravel `.env` file:

```env
REACT_EMAIL_DIRECTORY="emails/directory/relative/from/laravel/root"
```

Create a Laravel mailable.
4. Generate a new Laravel Mailable class:

``` bash
```bash
php artisan make:mail NewUser
```

Extend from ReactMailable instead of Mailable.
5. Use `ReactMailView` in your `Mailable`, or extend your `Mailable` from `ReactMailable``

``` php
```php
use App\Models\User;
use Maantje\ReactEmail\ReactMailable;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Mail\Mailables\Content;
use Maantje\ReactEmail\ReactMailView;

class NewUser extends ReactMailable
class NewUser extends ReactMailable // Extend, from \Maantje\ReactEmail\ReactMailable
{
public function __construct(public User $user)
use ReactMailView; // or use \Maantje\ReactEmail\ReactMailView

public function __construct(public User $user)
{
// public properties will be passed as props to the React email component
// Alternatively use the with property of content
// Public properties will be passed as props to the React email component.
// Alternatively, use the `with` property of `content`.
}

public function envelope()
Expand All @@ -64,22 +77,25 @@ class NewUser extends ReactMailable
public function content()
{
return new Content(
view: 'new-user', // name of the component file without extension
view: 'new-user', // Component filename without the extension
);
}
}
```

## Testing
## Running Tests

``` bash
Run tests using [Pest](https://pestphp.com/):

```bash
./vendor/bin/pest
```

## Security

If you discover any security related issues, please email author email instead of using the issue tracker.
If you discover any security-related issues, please email the author instead of using the issue tracker.

## License

The MIT License (MIT). Please see [License File](/LICENSE) for more information.
This package is open-source and licensed under the MIT License. See the [LICENSE](/LICENSE) file for details.~~

4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
}
},
"require-dev": {
"orchestra/testbench": "^7.20 || ^8.0 || ^9.0",
"pestphp/pest": "^1.20 || ^2.0"
"orchestra/testbench": "^7.20 || ^8.0 || ^9.0 || ^10",
"pestphp/pest": "^1.20 || ^2.0 || ^3"
},
"config": {
"allow-plugins": {
Expand Down
Loading

0 comments on commit a3a10f3

Please sign in to comment.