Skip to content

elixir-saas/phx-hook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


phx-hook

A collection of useful hooks for Phoenix LiveView JavaScript interop.

See interactive examples in the demo application.

Hooks

Installation

To install a phx-hook from the root of your Phoenix project, run:

npm i --save @phx-hook/package --prefix assets

Then, import it in your app.js file and configure it in your LiveSocket hooks:

import PackageHook from "@phx-hook/package";

const hooks = {
  Package: PackageHook(),
};

let liveSocket = new LiveSocket("/live", Socket, { hooks, ... });

Additional installation instructions and documentation for each package can be found in the package directories in this repo.

Modification

These hooks are designed to be concise, to be easy to understand, and to have zero npm package dependencies. If a hook doesn't quite work for you and requires modificaiton, I encourage you to copy it into your own project and develop it from there.

Vendoring a hook is easy, just copy the source file from this repo. For example, you might copy from packages/sortable/src/index.js to assets/js/hooks/sortable.js in your Phoenix project. Then, change the import path to your local path in your app.js file:

- import SortableHook from "@phx-hook/sortable";
+ import SortableHook from "./hooks/sortable";

If manual copying sounds tedious, each package includes a command to instantly copy its code into your project for you. From your project root directory, simply run:

npx @phx-hook/package vendor

Contributions back to @phx-hook are also welcome!

Development

Run lerna run format to run Prettier across all packages.

Run lerna create [package] and follow prompts to create a new package.

Publishing

Run lerna publish and follow prompts.

About

A collection of useful hooks for Phoenix LiveView JavaScript interop.

Resources

Stars

Watchers

Forks

Packages

No packages published