leptos_twelements

Crates.ioleptos_twelements
lib.rsleptos_twelements
version0.0.7
sourcesrc
created_at2023-09-04 22:27:39.0877
updated_at2023-10-04 05:00:08.062842
descriptionA UI component library for the Leptos Web Framework, based on Tailwind Elements.
homepagehttps://github.com/smessmer/leptos_twelements
repositoryhttps://github.com/smessmer/leptos_twelements
max_upload_size
id963691
size41,733,896
Sebastian Messmer (smessmer)

documentation

https://docs.rs/leptos_twelements

README

Latest Version docs.rs unsafe forbidden

leptos-twelements

A UI component library for Leptos, based on Tailwind Elements.

Installation (for projects using cargo leptos)

  1. Use the nightly rust compiler. This crate doesn't work with stable rust yet.

  2. Add the following to the Cargo.toml of your Leptos project:

[dependencies]
leptos-twelements = "^0.1.0"

[build-dependencies]
leptos-twelements = "^0.1.0"

[features]
ssr = [
    # ... leptos probably already has some other entries here
    "leptos-twelements/ssr",
    # ...
]
  1. Add the following to your tailwind.config.js:
/** @type {import('tailwindcss').Config} */
module.exports = {
  content: {
    relative: true,
    files: [
      ...
      "./target/.leptos-twelements/rs/**/*.rs",
      "./target/.leptos-twelements/js/**/*.js",
    ],
  },
  plugins: [require("./target/.leptos-twelements/plugin.cjs")]
}

Note that plugin.cjs and the js directory aren't there just yet, but we'll add a build script generating them in the next step.

  1. Add the following build.rs to your Leptos project to generate those files:
use std::path::Path;

fn main() {
    let target_dir = Path::new(&env!("CARGO_MANIFEST_DIR")).join("target");
    leptos_twelements::install_files_to(&target_dir);
}
  1. Add a call to .setup_twelements() to the axum router setup:
    use leptos_twelements::AxumRouterExt;
    let app = Router::new()
        // ...
        .setup_twelements()
        // ...

This function call will add the necessary routes to your axum app to serve the JavaScript required by Tailwind Elements.

Note that this code, including the use statement, should be guarded by a #[cfg(feature = "ssr")] attribute. The default leptos setup should already do this correctly.

  1. Add <TwElementsSetup /> to your App component:
use leptos_twelements::TwElementsSetup;

#[component]
pub fn App(cx: Scope) -> impl IntoView {
    // ...
    view! {
        cx,
        // ...
        <TwElementsSetup />
        // ...
    }
}
Commit count: 46

cargo fmt