Skip to content

Commit

Permalink
Add start of collection
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielleHuisman committed Jun 24, 2024
1 parent 33862ab commit d082180
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/primitives/leptos/collection/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "radix-leptos-collection"
description = "Leptos port of Radix Collection."

authors.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true
version.workspace = true

[dependencies]
leptos.workspace = true
radix-leptos-compose-refs = { path = "../compose-refs", version = "0.0.1" }
radix-leptos-primitive = { path = "../primitive", version = "0.0.1" }
13 changes: 13 additions & 0 deletions packages/primitives/leptos/collection/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<p align="center">
<a href="../../../../logo.svg" alt="Rust Radix logo">
<img src="../../../../logo.svg" width="300" height="200">
</a>
</p>

<h1 align="center">radix-leptos-roving-focus</h1>

This is an internal utility, not intended for public usage.

## Rust Radix

[Rust Radix](https://github.com/NixySoftware/radix) is a Rust port of [Radix](https://www.radix-ui.com/primitives).
30 changes: 30 additions & 0 deletions packages/primitives/leptos/collection/src/collection.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// TODO: remove
#![allow(dead_code, unused_variables)]

use std::collections::HashMap;

use leptos::{
html::{AnyElement, ElementDescriptor},
*,
};

#[derive(Clone)]
struct CollectionContextValue<ItemElement: ElementDescriptor + 'static, ItemData: 'static> {
collection_ref: NodeRef<AnyElement>,
item_map: RwSignal<HashMap<String, (NodeRef<ItemElement>, ItemData)>>,
}

#[component]
pub fn CollectionProvider(children: ChildrenFn) -> impl IntoView {
// TODO: generics
let context_value = CollectionContextValue::<AnyElement, ()> {
collection_ref: create_node_ref(),
item_map: create_rw_signal(HashMap::new()),
};

view! {
<Provider value=context_value>
{children()}
</Provider>
}
}
9 changes: 9 additions & 0 deletions packages/primitives/leptos/collection/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//! Leptos port of [Radix Collection](https://www.radix-ui.com/primitives).
//!
//! This is an internal utility, not intended for public usage.
//!
//! See [`@radix-ui/react-collection`](https://www.npmjs.com/package/@radix-ui/react-collection) for the original package.

mod collection;

pub use collection::*;

0 comments on commit d082180

Please sign in to comment.