Skip to main content

leptos_styles/
lib.rs

1#![doc = include_str!("../README.md")]
2
3mod convert;
4mod into_style;
5mod style_entry;
6mod style_list;
7mod styles;
8
9pub use convert::{IntoOptionalStyleDeclaration, IntoOptionalUncheckedStyleValue};
10pub use into_style::StylesState;
11pub use style_entry::{
12    IntoUncheckedPropertyName, ParseStyleEntryError, StyleEntry, UncheckedPropertyName,
13    UncheckedStyleValue,
14};
15pub use styles::{Styles, StylesBuilder};
16
17/// Grammar-checked CSS values, property selectors, and declarations. Available only when the
18/// `typed-css` cargo feature is enabled, which pulls in the [`leptos-css`] crate.
19///
20/// [`leptos-css`]: https://crates.io/crates/leptos-css
21#[cfg(feature = "typed-css")]
22pub use ::leptos_css;
23
24#[cfg(feature = "typed-css")]
25pub use ::leptos_css::{CheckedDeclaration, css_custom_property};
26
27/// Re-export the typed CSS value primitives from [`leptos_css`].
28#[cfg(feature = "typed-css")]
29pub mod css {
30    pub use crate::css_custom_property;
31    pub use ::leptos_css::{
32        BorderCornerRadius, CheckedCssValue, CssAngle, CssColor, CssColorName, CssCustomProperty,
33        CssDimension, CssDimensionExpr, CssEnvironmentVariable, CssLength, CssTime, CssValue,
34        CssVariableReference, CssWriteTo, DeclarationValue, FiniteF64, FontWeight,
35        ForcedColorAdjust, Gap, GapValue, GlobalKeyword, Inset, InsetAxis, InvalidCssNumber,
36        InvalidCustomPropertyName, InvalidNonNegativeLengthPercentage, InvalidViewTransitionName,
37        LengthPercentageAuto, LengthPercentageCalculation, Margin, MarginAxis, MaxSize,
38        NonNegativeFiniteF64, NonNegativeLengthPercentage, NonNegativeLengthPercentageValue,
39        Opacity, Padding, PaddingAxis, PercentageChannel, PrintColorAdjust, Size, TouchAction,
40        TouchActionGestures, TouchActionHorizontalPan, TouchActionVerticalPan, UnitInterval,
41        ViewTransitionName, ZIndex, ch, cqh, cqw, css_clamp, css_env, css_max, css_min, deg, dvh,
42        dvw, em, fr, grad, hsl, hsla, lvh, lvw, ms, number, pct, px, rad, rem, rgb, rgba, s, svh,
43        svw, try_ch, try_cqh, try_cqw, try_deg, try_dvh, try_dvw, try_em, try_fr, try_grad,
44        try_hsl, try_hsla, try_lvh, try_lvw, try_ms, try_number, try_pct, try_px, try_rad, try_rem,
45        try_rgba, try_s, try_svh, try_svw, try_turn, try_vh, try_vmax, try_vmin, try_vw, turn, var,
46        vh, vmax, vmin, vw,
47    };
48}
49
50/// Re-export the checked CSS property selectors from [`leptos_css`].
51#[cfg(feature = "typed-css")]
52pub mod property {
53    pub use ::leptos_css::property::*;
54}
55
56/// Compile-time assertions that the public types stay `Send + Sync`. `Styles` is intended to
57/// flow through Leptos component props, which require both bounds. If a future change to any
58/// internal field weakens that, this `const _` will fail to compile and surface the regression
59/// at the crate boundary instead of at a downstream consumer.
60const _: () = {
61    const fn assert_send_sync<T: Send + Sync>() {}
62    assert_send_sync::<Styles>();
63    assert_send_sync::<StylesBuilder>();
64    assert_send_sync::<StyleEntry>();
65    assert_send_sync::<ParseStyleEntryError>();
66};
67
68/// ```compile_fail
69/// use leptos_styles::{Styles, css::{CssColor, CssColorName}, property::PaddingProperty};
70///
71/// // A color grammar cannot be paired with the padding property.
72/// let _ = Styles::builder().with(
73///     PaddingProperty.declare(CssColor::Named(CssColorName::Red)),
74/// );
75/// ```
76///
77/// ```compile_fail
78/// use leptos_styles::Styles;
79///
80/// // Raw strings require the explicitly named unchecked API.
81/// let _ = Styles::builder().with("padding");
82/// ```
83///
84/// ```compile_fail
85/// use leptos_styles::Styles;
86///
87/// // Raw property/value tuples are not an implicit conversion boundary.
88/// let _: Styles = ("padding", "16px").into();
89/// ```
90#[cfg(feature = "typed-css")]
91const _: () = ();