mirror of
https://github.com/adoyle0/thaw.git
synced 2025-01-22 22:09:22 -05:00
fix: nightly mode
This commit is contained in:
parent
7026a758b2
commit
ed9f592c01
6 changed files with 60 additions and 38 deletions
|
@ -27,11 +27,8 @@ default = ["csr"]
|
|||
tracing = ["leptos/tracing"]
|
||||
csr = ["leptos/csr", "thaw/csr"]
|
||||
ssr = ["leptos/ssr", "leptos_meta/ssr", "leptos_router/ssr", "thaw/ssr"]
|
||||
hydrate = [
|
||||
"leptos/hydrate",
|
||||
"thaw/hydrate",
|
||||
]
|
||||
nightly = ["leptos/nightly", "leptos_router/nightly"]
|
||||
hydrate = ["leptos/hydrate", "thaw/hydrate"]
|
||||
nightly = ["leptos/nightly", "leptos_router/nightly", "thaw/nightly"]
|
||||
|
||||
# https://benw.is/posts/how-i-improved-my-rust-compile-times-by-seventy-five-percent#optimization-level
|
||||
|
||||
|
|
|
@ -42,3 +42,4 @@ send_wrapper = "0.6"
|
|||
csr = ["leptos/csr", "thaw_components/csr", "thaw_utils/csr"]
|
||||
ssr = ["leptos/ssr", "thaw_components/ssr", "thaw_utils/ssr"]
|
||||
hydrate = ["leptos/hydrate", "thaw_components/hydrate", "thaw_utils/hydrate"]
|
||||
nightly = ["leptos/nightly", "thaw_utils/nightly"]
|
||||
|
|
|
@ -32,18 +32,6 @@ pub fn Anchor(
|
|||
id: String,
|
||||
}
|
||||
|
||||
impl OffsetTarget {
|
||||
fn get_bounding_client_rect(&self) -> Option<DomRect> {
|
||||
match self {
|
||||
OffsetTarget::Selector(selector) => {
|
||||
let el = document().query_selector(selector).ok().flatten()?;
|
||||
Some(el.get_bounding_client_rect())
|
||||
}
|
||||
OffsetTarget::Element(el) => Some(el.get_bounding_client_rect()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let offset_target = send_wrapper::SendWrapper::new(offset_target);
|
||||
|
||||
let on_scroll = move || {
|
||||
|
@ -212,7 +200,18 @@ pub enum OffsetTarget {
|
|||
Element(Element),
|
||||
}
|
||||
|
||||
|
||||
#[cfg(any(feature = "csr", feature = "hydrate"))]
|
||||
impl OffsetTarget {
|
||||
fn get_bounding_client_rect(&self) -> Option<DomRect> {
|
||||
match self {
|
||||
OffsetTarget::Selector(selector) => {
|
||||
let el = document().query_selector(selector).ok().flatten()?;
|
||||
Some(el.get_bounding_client_rect())
|
||||
}
|
||||
OffsetTarget::Element(el) => Some(el.get_bounding_client_rect()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&'static str> for OffsetTarget {
|
||||
fn from(value: &'static str) -> Self {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use leptos::prelude::*;
|
||||
use leptos::{either::EitherOf4, prelude::*};
|
||||
use thaw_utils::{class_list, mount_style, StoredMaybeSignal};
|
||||
|
||||
#[component]
|
||||
|
@ -6,7 +6,8 @@ pub fn MessageBar(
|
|||
#[prop(optional, into)] class: MaybeProp<String>,
|
||||
#[prop(optional, into)] layout: MaybeSignal<MessageBarLayout>,
|
||||
/// Default designs announcement presets.
|
||||
#[prop(optional, into)] intent: MaybeSignal<MessageBarIntent>,
|
||||
#[prop(optional, into)]
|
||||
intent: MaybeSignal<MessageBarIntent>,
|
||||
children: Children,
|
||||
) -> impl IntoView {
|
||||
mount_style("message-bar", include_str!("./message-bar.css"));
|
||||
|
@ -25,29 +26,29 @@ pub fn MessageBar(
|
|||
<div class="thaw-message-bar__icon">
|
||||
{
|
||||
move || match intent.get() {
|
||||
MessageBarIntent::Info => view! {
|
||||
MessageBarIntent::Info => EitherOf4::A(view! {
|
||||
<svg fill="currentColor" aria-hidden="true" width="1em" height="1em" viewBox="0 0 20 20">
|
||||
<path d="M18 10a8 8 0 1 0-16 0 8 8 0 0 0 16 0ZM9.5 8.91a.5.5 0 0 1 1 0V13.6a.5.5 0 0 1-1 0V8.9Zm-.25-2.16a.75.75 0 1 1 1.5 0 .75.75 0 0 1-1.5 0Z" fill="currentColor"></path>
|
||||
</svg>
|
||||
},
|
||||
MessageBarIntent::Success => view! {
|
||||
}),
|
||||
MessageBarIntent::Success => EitherOf4::B(view! {
|
||||
<svg fill="currentColor" aria-hidden="true" width="1em" height="1em" viewBox="0 0 20 20">
|
||||
<path d="M10 2a8 8 0 1 1 0 16 8 8 0 0 1 0-16Zm3.36 5.65a.5.5 0 0 0-.64-.06l-.07.06L9 11.3 7.35 9.65l-.07-.06a.5.5 0 0 0-.7.7l.07.07 2 2 .07.06c.17.11.4.11.56 0l.07-.06 4-4 .07-.08a.5.5 0 0 0-.06-.63Z" fill="currentColor">
|
||||
</path>
|
||||
</svg>
|
||||
},
|
||||
MessageBarIntent::Warning => view! {
|
||||
}),
|
||||
MessageBarIntent::Warning => EitherOf4::C(view! {
|
||||
<svg fill="currentColor" aria-hidden="true" width="1em" height="1em" viewBox="0 0 20 20">
|
||||
<path d="M8.68 2.79a1.5 1.5 0 0 1 2.64 0l6.5 12A1.5 1.5 0 0 1 16.5 17h-13a1.5 1.5 0 0 1-1.32-2.21l6.5-12ZM10.5 7.5a.5.5 0 0 0-1 0v4a.5.5 0 0 0 1 0v-4Zm.25 6.25a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Z" fill="currentColor">
|
||||
</path>
|
||||
</svg>
|
||||
},
|
||||
MessageBarIntent::Error => view! {
|
||||
}),
|
||||
MessageBarIntent::Error => EitherOf4::D(view! {
|
||||
<svg fill="currentColor" aria-hidden="true" width="1em" height="1em" viewBox="0 0 20 20">
|
||||
<path d="M10 2a8 8 0 1 1 0 16 8 8 0 0 1 0-16ZM7.8 7.11a.5.5 0 0 0-.63.06l-.06.07a.5.5 0 0 0 .06.64L9.3 10l-2.12 2.12-.06.07a.5.5 0 0 0 .06.64l.07.06c.2.13.47.11.64-.06L10 10.7l2.12 2.12.07.06c.2.13.46.11.64-.06l.06-.07a.5.5 0 0 0-.06-.64L10.7 10l2.12-2.12.06-.07a.5.5 0 0 0-.06-.64l-.07-.06a.5.5 0 0 0-.64.06L10 9.3 7.88 7.17l-.07-.06Z" fill="currentColor">
|
||||
</path>
|
||||
</svg>
|
||||
},
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,3 +24,4 @@ send_wrapper = "0.6"
|
|||
csr = ["leptos/csr"]
|
||||
ssr = ["leptos/ssr", "leptos_meta/ssr"]
|
||||
hydrate = ["leptos/hydrate"]
|
||||
nightly = ["leptos/nightly"]
|
|
@ -1,6 +1,11 @@
|
|||
#[cfg(not(feature = "nightly"))]
|
||||
use leptos::{
|
||||
prelude::{MaybeProp, Memo, Oco, RenderEffect, RwSignal},
|
||||
reactive_graph::traits::{Get, Update, With, WithUntracked},
|
||||
prelude::{MaybeProp, Memo},
|
||||
reactive_graph::traits::Get,
|
||||
};
|
||||
use leptos::{
|
||||
prelude::{Oco, RenderEffect, RwSignal},
|
||||
reactive_graph::traits::{Update, With, WithUntracked},
|
||||
tachys::renderer::DomRenderer,
|
||||
};
|
||||
use std::collections::HashSet;
|
||||
|
@ -280,6 +285,22 @@ pub enum Class {
|
|||
Fn(Oco<'static, str>, Box<dyn Fn() -> bool>),
|
||||
}
|
||||
|
||||
pub trait IntoClassValue {
|
||||
fn into_class_value(self) -> Option<Oco<'static, str>>;
|
||||
}
|
||||
|
||||
impl IntoClassValue for String {
|
||||
fn into_class_value(self) -> Option<Oco<'static, str>> {
|
||||
Some(self.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoClassValue for Option<String> {
|
||||
fn into_class_value(self) -> Option<Oco<'static, str>> {
|
||||
self.map(|v| v.into())
|
||||
}
|
||||
}
|
||||
|
||||
pub trait IntoClass {
|
||||
fn into_class(self) -> Class;
|
||||
}
|
||||
|
@ -299,10 +320,10 @@ impl IntoClass for &'static str {
|
|||
impl<T, U> IntoClass for T
|
||||
where
|
||||
T: Fn() -> U + 'static,
|
||||
U: ToString,
|
||||
U: IntoClassValue,
|
||||
{
|
||||
fn into_class(self) -> Class {
|
||||
Class::FnString(Box::new(move || (self)().to_string().into()))
|
||||
Class::FnOptionString(Box::new(move || (self)().into_class_value()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -320,6 +341,13 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "nightly"))]
|
||||
impl IntoClass for MaybeProp<String> {
|
||||
fn into_class(self) -> Class {
|
||||
Class::FnOptionString(Box::new(move || self.get().map(|c| Oco::from(c))))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> IntoClass for (&'static str, T)
|
||||
where
|
||||
T: Fn() -> bool + 'static,
|
||||
|
@ -339,18 +367,13 @@ impl IntoClass for (&'static str, bool) {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "nightly"))]
|
||||
impl IntoClass for (&'static str, Memo<bool>) {
|
||||
fn into_class(self) -> Class {
|
||||
Class::Fn(self.0.into(), Box::new(move || self.1.get()))
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoClass for MaybeProp<String> {
|
||||
fn into_class(self) -> Class {
|
||||
Class::FnOptionString(Box::new(move || self.get().map(|c| Oco::from(c))))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> IntoClass for (String, T)
|
||||
where
|
||||
T: Fn() -> bool + 'static,
|
||||
|
|
Loading…
Add table
Reference in a new issue