Skip to content

Commit

Permalink
Add radix-leptos-direction
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielleHuisman committed May 8, 2024
1 parent 90ddc9f commit d1cf14b
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions packages/colors/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
//! Rust port of [Radix Colors](https://www.radix-ui.com/colors).
//!
//! A gorgeous, accessible color system.
//!
//! See <https://www.radix-ui.com/colors/docs/overview/installation> for the original documentation.
//!
//! See [`@radix-ui/colors`](https://www.npmjs.com/package/@radix-ui/colors) for the original package.

mod black_a;
mod dark;
mod light;
Expand Down
6 changes: 5 additions & 1 deletion packages/primitives/core/number/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@

//! Rust port of [Radix Core Number](https://www.radix-ui.com/primitives).
//!
//! This is an internal utility, not intended for public usage.
//!
//! See [`@radix-ui/number`](https://www.npmjs.com/package/@radix-ui/number) for the original package.
6 changes: 5 additions & 1 deletion packages/primitives/core/primitive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@

//! Rust port of [Radix Core Primitive](https://www.radix-ui.com/primitives).
//!
//! This is an internal utility, not intended for public usage.
//!
//! See [`@radix-ui/primitive`](https://www.npmjs.com/package/@radix-ui/primitive) for the original package.
6 changes: 6 additions & 0 deletions packages/primitives/core/rect/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//! Rust port of [Radix Core Rect](https://www.radix-ui.com/primitives).
//!
//! This is an internal utility, not intended for public usage.
//!
//! See [`@radix-ui/rect`](https://www.npmjs.com/package/@radix-ui/rect) for the original package.

mod observe_element_rect;

pub use observe_element_rect::*;
6 changes: 6 additions & 0 deletions packages/primitives/leptos/arrow/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//! Leptos port of [Radix Arrow](https://www.radix-ui.com/primitives).
//!
//! This is an internal utility, not intended for public usage.
//!
//! See [`@radix-ui/react-arrow`](https://www.npmjs.com/package/@radix-ui/react-arrow) for the original package.

mod arrow;

pub use arrow::*;
12 changes: 12 additions & 0 deletions packages/primitives/leptos/direction/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "radix-leptos-direction"
description = "Leptos port of Radix Direction."

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

[dependencies]
leptos.workspace = true
13 changes: 13 additions & 0 deletions packages/primitives/leptos/direction/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-direction</h1>

Wraps your app to provide global reading direction.

## Rust Radix

[Rust Radix](https://github.com/NixySoftware/radix) is a Rust port of [Radix](https://www.radix-ui.com/primitives).
29 changes: 29 additions & 0 deletions packages/primitives/leptos/direction/src/direction.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use leptos::*;

#[derive(Copy, Clone, Debug, PartialEq)]
pub enum Direction {
Ltr,
Rtl,
}

type DirectionContextValue = MaybeSignal<Direction>;

#[component]
pub fn DirectionProvider(
#[prop(into)] direction: DirectionContextValue,
children: Children,
) -> impl IntoView {
view! {
<Provider value={direction}>{children()}</Provider>
}
}

pub fn use_direction(local_dir: MaybeProp<Direction>) -> Signal<Direction> {
let global_dir = use_context::<DirectionContextValue>();

Signal::derive(move || {
local_dir()
.or(global_dir.map(|global_dir| global_dir()))
.unwrap_or(Direction::Ltr)
})
}
11 changes: 11 additions & 0 deletions packages/primitives/leptos/direction/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//! Leptos port of [Radix Direction](https://www.radix-ui.com/primitives/docs/utilities/direction-provider).
//!
//! Wraps your app to provide global reading direction.
//!
//! See <https://www.radix-ui.com/primitives/docs/utilities/direction-provider> for the original documentation.
//!
//! See [`@radix-ui/react-direction`](https://www.npmjs.com/package/@radix-ui/react-direction) for the original package.

mod direction;

pub use direction::*;
6 changes: 6 additions & 0 deletions packages/primitives/leptos/popper/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//! Leptos port of [Radix Popper](https://www.radix-ui.com/primitives).
//!
//! This is an internal utility, not intended for public usage.
//!
//! See [`@radix-ui/react-popper`](https://www.npmjs.com/package/@radix-ui/react-popper) for the original package.

mod popper;

pub use popper::*;
6 changes: 6 additions & 0 deletions packages/primitives/leptos/use-size/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//! Leptos port of [Radix Use Size](https://www.radix-ui.com/primitives).
//!
//! This is an internal utility, not intended for public usage.
//!
//! See [`@radix-ui/react-use-size`](https://www.npmjs.com/package/@radix-ui/react-use-size) for the original package.

mod use_size;

pub use use_size::*;

0 comments on commit d1cf14b

Please sign in to comment.