-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d1cf14b
commit 015fc99
Showing
14 changed files
with
429 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub fn clamp(value: f64, [min, max]: [f64; 2]) -> f64 { | ||
value.max(min).min(max) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "radix-leptos-menu" | ||
description = "Leptos port of Radix Menu." | ||
|
||
authors.workspace = true | ||
edition.workspace = true | ||
license.workspace = true | ||
repository.workspace = true | ||
version.workspace = true | ||
|
||
[dependencies] | ||
leptos.workspace = true | ||
radix-leptos-direction = { path = "../direction", version = "0.0.1" } | ||
radix-leptos-popper = { path = "../popper", version = "0.0.1" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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-menu</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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[package] | ||
name = "radix-leptos-menu-example" | ||
description = "Example for Radix Leptos Menu." | ||
publish = false | ||
|
||
authors.workspace = true | ||
edition.workspace = true | ||
license.workspace = true | ||
repository.workspace = true | ||
version.workspace = true | ||
|
||
[dependencies] | ||
console_log.workspace = true | ||
console_error_panic_hook.workspace = true | ||
leptos.workspace = true | ||
log.workspace = true | ||
radix-leptos-menu = { path = ".." } | ||
tailwind_fuse.workspace = true | ||
web-sys.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[[hooks]] | ||
stage = "pre_build" | ||
command = "sh" | ||
command_arguments = [ | ||
"-c", | ||
"npx tailwindcss -i style/tailwind.css -o style/tailwind.output.css", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<link data-trunk rel="css" href="/style/tailwind.output.css" /> | ||
</head> | ||
<body></body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
use leptos::*; | ||
use radix_leptos_menu::*; | ||
use tailwind_fuse::*; | ||
|
||
// TODO: add router and separate pages for each component, similar to Storybook | ||
|
||
#[component] | ||
pub fn App() -> impl IntoView { | ||
view! { | ||
<h1 class="text-xl pb-3">Styled</h1> | ||
|
||
<div class="h-[400px] overflow-y-auto"> | ||
<Styled /> | ||
</div> | ||
} | ||
} | ||
|
||
#[component] | ||
fn Styled() -> impl IntoView { | ||
let item_class = create_memo(move |_| ItemClass::default().to_class()); | ||
|
||
view! { | ||
<MenuWithAnchor> | ||
<MenuItem class=item_class> | ||
Undo | ||
</MenuItem> | ||
<MenuItem class=item_class> | ||
Redo | ||
</MenuItem> | ||
<MenuSeparator /> | ||
<MenuItem class=item_class> | ||
Cut | ||
</MenuItem> | ||
<MenuItem class=item_class> | ||
Copy | ||
</MenuItem> | ||
<MenuItem class=item_class> | ||
Paste | ||
</MenuItem> | ||
</MenuWithAnchor> | ||
} | ||
} | ||
|
||
#[component] | ||
fn Submenus() -> impl IntoView { | ||
view! {} | ||
} | ||
|
||
#[component] | ||
fn WithLabels() -> impl IntoView { | ||
view! {} | ||
} | ||
|
||
#[component] | ||
fn Typeahead() -> impl IntoView { | ||
view! {} | ||
} | ||
|
||
#[component] | ||
fn CheckboxItems() -> impl IntoView { | ||
view! {} | ||
} | ||
|
||
#[component] | ||
fn RadioItems() -> impl IntoView { | ||
view! {} | ||
} | ||
|
||
#[component] | ||
fn Animated() -> impl IntoView { | ||
view! {} | ||
} | ||
|
||
#[component] | ||
fn MenuWithAnchor( | ||
#[prop(into, optional)] open: MaybeProp<bool>, | ||
children: Children, | ||
) -> impl IntoView { | ||
let open = Signal::derive(move || open().unwrap_or(true)); | ||
|
||
let content_class = create_memo(move |_| ContentClass::default().to_class()); | ||
|
||
// TODO: add missing props | ||
view! { | ||
<Menu open=open modal=false> | ||
<MenuAnchor>{""}</MenuAnchor> | ||
<MenuPortal> | ||
<MenuContent class=content_class> | ||
{children()} | ||
</MenuContent> | ||
</MenuPortal> | ||
</Menu> | ||
} | ||
} | ||
|
||
#[component] | ||
fn Submenu() -> impl IntoView { | ||
view! {} | ||
} | ||
|
||
#[derive(TwClass, Default, Clone, Copy)] | ||
#[tw( | ||
class = "inline-block box-border min-w-[130px] bg-[#fff] border border-solid border-[#ccc] rounded-[6px] p-[5px] shadow-[0px_5px_10px_0px_rgba(0,0,0,0.1)] font-['apple-system, BlinkMacSystemFont, helvetica, arial, sans-serif'] text-[13px] focus-within:border-[#111]" | ||
)] | ||
pub struct ContentClass {} | ||
|
||
#[derive(TwClass, Default, Clone, Copy)] | ||
#[tw( | ||
class = "flex items-center justify-between leading-none cursor-default select-none whitespace-nowrap h-[25px] p-[0px_10px] text-[#ccc] rounded-[3px]" | ||
)] | ||
pub struct LabelClass {} | ||
|
||
#[derive(TwClass, Default, Clone, Copy)] | ||
#[tw( | ||
class = "flex items-center justify-between leading-none cursor-default select-none whitespace-nowrap h-[25px] p-[0px_10px] text-[#111] rounded-[3px] outline-none data-highlighted:bg-[#111] data-highlighted:text-[#fff] data-disabled:text-[#ccc]" | ||
)] | ||
pub struct ItemClass {} | ||
|
||
#[derive(TwClass, Default, Clone, Copy)] | ||
#[tw( | ||
class = "flex items-center justify-between leading-none cursor-default select-none whitespace-nowrap h-[25px] p-[0px_10px] text-[#111] rounded-[3px] outline-none data-highlighted:bg-[#111] data-highlighted:text-[#fff] data-disabled:text-[#ccc] [&:not([data-highlighted])[data-state=\"open\"]]:bg-[#ccc] [&:not([data-highlighted])[data-state=\"open\"]]:text-[#111]" | ||
)] | ||
pub struct SubTriggerClass {} | ||
|
||
#[derive(TwClass, Default, Clone, Copy)] | ||
#[tw(class = "h-[1px] m-[5px_10px] bg-[#ccc]")] | ||
pub struct SeparatorClass {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
mod app; | ||
|
||
use crate::app::App; | ||
|
||
pub fn main() { | ||
_ = console_log::init_with_level(log::Level::Debug); | ||
console_error_panic_hook::set_once(); | ||
|
||
leptos::mount_to_body(App); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** @type {import('tailwindcss').Config} */ | ||
module.exports = { | ||
content: ['*.html', './src/**/*.rs'], | ||
theme: { | ||
extend: {} | ||
}, | ||
plugins: [] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
//! Leptos port of [Radix Menu](https://www.radix-ui.com/primitives). | ||
//! | ||
//! This is an internal utility, not intended for public usage. | ||
//! | ||
//! See [`@radix-ui/react-menu`](https://www.npmjs.com/package/@radix-ui/react-menu) for the original package. | ||
mod menu; | ||
|
||
pub use menu::*; |
Oops, something went wrong.