created button components
This commit is contained in:
parent
840829e47a
commit
9bf4d6124c
46
leptos_components/src/components/buttons.rs
Normal file
46
leptos_components/src/components/buttons.rs
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
use leptos::prelude::*;
|
||||||
|
use leptos::logging;
|
||||||
|
|
||||||
|
pub enum ButtonStyle {
|
||||||
|
Primary,
|
||||||
|
Secondary,
|
||||||
|
Success,
|
||||||
|
Danger,
|
||||||
|
Warning
|
||||||
|
}
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn Button(
|
||||||
|
#[prop(optional)]
|
||||||
|
style: Option<ButtonStyle>,
|
||||||
|
children: Children,
|
||||||
|
) -> impl IntoView {
|
||||||
|
let style_type;
|
||||||
|
if style.is_none() {
|
||||||
|
style_type = ButtonStyle::Primary;
|
||||||
|
} else {
|
||||||
|
style_type = style.unwrap();
|
||||||
|
}
|
||||||
|
let mut stylestring = "";
|
||||||
|
match style_type {
|
||||||
|
ButtonStyle::Primary => {
|
||||||
|
stylestring = "bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded";
|
||||||
|
},
|
||||||
|
ButtonStyle::Secondary => {
|
||||||
|
stylestring = "bg-gray-300 hover:bg-gray-500 text-black font-semibold py-2 px-4 rounded";
|
||||||
|
},
|
||||||
|
ButtonStyle::Success => {
|
||||||
|
stylestring = "bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded";
|
||||||
|
},
|
||||||
|
ButtonStyle::Danger => {
|
||||||
|
stylestring = "bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded";
|
||||||
|
},
|
||||||
|
ButtonStyle::Warning => {
|
||||||
|
stylestring = "bg-yellow-500 hover:bg-yellow-700 text-black font-semibold py-2 px-4 rounded";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
logging::log!("{}", stylestring);
|
||||||
|
view! {
|
||||||
|
<button class={stylestring}>{children()}</button>
|
||||||
|
}
|
||||||
|
}
|
||||||
1
leptos_components/src/components/mod.rs
Normal file
1
leptos_components/src/components/mod.rs
Normal file
@ -0,0 +1 @@
|
|||||||
|
pub mod buttons;
|
||||||
@ -1,11 +1,2 @@
|
|||||||
use leptos::prelude::*;
|
pub mod components;
|
||||||
|
|
||||||
|
|
||||||
#[component]
|
|
||||||
pub fn Button(
|
|
||||||
children: Children,
|
|
||||||
) -> impl IntoView {
|
|
||||||
view! {
|
|
||||||
<button>{children()}</button>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -56,7 +56,11 @@ site-root = "target/site"
|
|||||||
site-pkg-dir = "pkg"
|
site-pkg-dir = "pkg"
|
||||||
|
|
||||||
# [Optional] The source CSS file. If it ends with .sass or .scss then it will be compiled by dart-sass into CSS. The CSS is optimized by Lightning CSS before being written to <site-root>/<site-pkg>/app.css
|
# [Optional] The source CSS file. If it ends with .sass or .scss then it will be compiled by dart-sass into CSS. The CSS is optimized by Lightning CSS before being written to <site-root>/<site-pkg>/app.css
|
||||||
style-file = "style/main.scss"
|
#style-file = "style/tailwind.css"
|
||||||
|
|
||||||
|
# Optional, Activates the tailwind build
|
||||||
|
tailwind-input-file = "style/tailwind.css"
|
||||||
|
|
||||||
# Assets source dir. All files found here will be copied and synchronized to site-root.
|
# Assets source dir. All files found here will be copied and synchronized to site-root.
|
||||||
# The assets-dir cannot have a sub directory with the same name/path as site-pkg-dir.
|
# The assets-dir cannot have a sub directory with the same name/path as site-pkg-dir.
|
||||||
#
|
#
|
||||||
@ -64,10 +68,10 @@ style-file = "style/main.scss"
|
|||||||
assets-dir = "public"
|
assets-dir = "public"
|
||||||
|
|
||||||
# The IP and port (ex: 127.0.0.1:3000) where the server serves the content. Use it in your server setup.
|
# The IP and port (ex: 127.0.0.1:3000) where the server serves the content. Use it in your server setup.
|
||||||
site-addr = "127.0.0.1:3000"
|
site-addr = "127.0.0.1:5000"
|
||||||
|
|
||||||
# The port to use for automatic reload monitoring
|
# The port to use for automatic reload monitoring
|
||||||
reload-port = 3001
|
reload-port = 5001
|
||||||
|
|
||||||
# [Optional] Command to use when running end2end tests. It will run in the end2end dir.
|
# [Optional] Command to use when running end2end tests. It will run in the end2end dir.
|
||||||
# [Windows] for non-WSL use "npx.cmd playwright test"
|
# [Windows] for non-WSL use "npx.cmd playwright test"
|
||||||
|
|||||||
@ -4,7 +4,7 @@ use leptos_router::{
|
|||||||
components::{Route, Router, Routes},
|
components::{Route, Router, Routes},
|
||||||
StaticSegment,
|
StaticSegment,
|
||||||
};
|
};
|
||||||
use leptos_components::Button;
|
use leptos_components::components::buttons::Button;
|
||||||
|
|
||||||
pub fn shell(options: LeptosOptions) -> impl IntoView {
|
pub fn shell(options: LeptosOptions) -> impl IntoView {
|
||||||
view! {
|
view! {
|
||||||
@ -57,7 +57,7 @@ fn HomePage() -> impl IntoView {
|
|||||||
|
|
||||||
view! {
|
view! {
|
||||||
<h1>"Welcome to Leptos!"</h1>
|
<h1>"Welcome to Leptos!"</h1>
|
||||||
<button on:click=on_click>"Click Me: " {count}</button>
|
<button on:click=on_click>"Click Me: " {move || count.get()}</button>
|
||||||
<Button on:click=on_click>"Click Me: " {count}</Button>
|
<Button on:click=on_click>"Click Me: " {move || count.get()}</Button>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
/** @type {import('tailwindcss').Config} */
|
/** @type {import('tailwindcss').Config} */
|
||||||
module.exports = {
|
module.exports = {
|
||||||
content: {
|
content: {
|
||||||
files: ["*.html", "./src/**/*.rs"],
|
files: ["*.html", "./src/**/*.rs", "../leptos_components/src/**/*.rs"],
|
||||||
transform: {
|
transform: {
|
||||||
rs: (content) => content.replace(/(?:^|\s)class:/g, ' '),
|
rs: (content) => content.replace(/(?:^|\s)class:/g, ' '),
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user