diff --git a/demo/src/components/demo.css b/demo/src/components/demo.css index 55a7608..ac8befe 100644 --- a/demo/src/components/demo.css +++ b/demo/src/components/demo.css @@ -14,29 +14,21 @@ } .demo-demo__toolbar { - display: flex; - justify-content: center; - align-items: center; - padding: 0.4rem; + height: 26px; + box-sizing: border-box; + text-align: center; border-top: 1px dashed var(--demo-border-color); border-bottom: 1px dashed var(--demo-border-color); } +.demo-demo__toolbar > .thaw-tooltip { + height: 24px; +} + .demo-demo__toolbar--code { border-bottom-width: 0; } -.demo-demo__toolbar-btn { - display: flex; - cursor: pointer; - color: var(--demo-color); - transition: color .3s; -} - -.demo-demo__toolbar-btn:hover { - color: var(--demo-color-hover); -} - .demo-demo__code { font-weight: 400; font-size: 0.875em; diff --git a/demo/src/components/demo.rs b/demo/src/components/demo.rs index 1923b4f..7894665 100644 --- a/demo/src/components/demo.rs +++ b/demo/src/components/demo.rs @@ -17,13 +17,9 @@ pub fn Demo(demo_code: DemoCode, #[prop(optional)] children: Option) - let mut css_vars = String::new(); theme.with(|theme| { if theme.color.color_scheme == "dark" { - css_vars.push_str("--demo-color: #ffffff60;"); - css_vars.push_str("--demo-color-hover: #ffffffe0;"); css_vars.push_str("--demo-border-color: #383f52;"); css_vars.push_str("--demo-background-color: #242832;"); } else { - css_vars.push_str("--demo-color: #00000060;"); - css_vars.push_str("--demo-color-hover: #000000e0;"); css_vars.push_str(&format!("--demo-border-color: var(--colorNeutralStroke2);",)); css_vars.push_str("--demo-background-color: #f9fafb;"); } @@ -52,31 +48,24 @@ pub fn Demo(demo_code: DemoCode, #[prop(optional)] children: Option) - view! {
{children()}
- - - - { - move || if is_show_code.get() { - view! { - - } - } else { - view! { - - } - } - } - - - { - move || if is_show_code.get() { - "Hide code" + +
}.into() } else { diff --git a/thaw/src/theme/color.rs b/thaw/src/theme/color.rs index 128f198..ad7bf07 100644 --- a/thaw/src/theme/color.rs +++ b/thaw/src/theme/color.rs @@ -44,6 +44,9 @@ pub struct ColorTheme { pub color_neutral_stroke_accessible_hover: String, pub color_neutral_stroke_accessible_pressed: String, + pub color_neutral_shadow_ambient: String, + pub color_neutral_shadow_key: String, + pub color_neutral_stencil_1: String, pub color_neutral_stencil_2: String, @@ -160,6 +163,9 @@ impl ColorTheme { color_neutral_stroke_accessible_hover: "#575757".into(), color_neutral_stroke_accessible_pressed: "#4d4d4d".into(), + color_neutral_shadow_ambient: "rgba(0,0,0,0.12)".into(), + color_neutral_shadow_key: "rgba(0,0,0,0.14)".into(), + color_neutral_stencil_1: "#e6e6e6".into(), color_neutral_stencil_2: "#fafafa".into(), @@ -277,6 +283,9 @@ impl ColorTheme { color_neutral_stroke_accessible_hover: "#bdbdbd".into(), color_neutral_stroke_accessible_pressed: "#b3b3b3".into(), + color_neutral_shadow_ambient: "rgba(0,0,0,0.24)".into(), + color_neutral_shadow_key: "rgba(0,0,0,0.28)".into(), + color_neutral_stencil_1: "#575757".into(), color_neutral_stencil_2: "#333333".into(), diff --git a/thaw/src/tooltip/docs/mod.md b/thaw/src/tooltip/docs/mod.md index b9c5c2c..ffa9d18 100644 --- a/thaw/src/tooltip/docs/mod.md +++ b/thaw/src/tooltip/docs/mod.md @@ -8,4 +8,26 @@ view! { } -``` \ No newline at end of file +``` + +### Appearance: inverted + +```rust demo +view! { + + + +} +``` + +### Textarea Props + +| Name | Type | Default | Description | +| ---------- | -------------------------------- | ------------------------- | -------------------------------------- | +| class | `MaybeProp` | `Default::default()` | | +| content | `Option>` | `None` | The text of the tooltip. | +| position | `TooltipPosition` | `TooltipPosition::Top` | Configure the position of the tooltip. | +| appearance | `MaybeSignal` | `TooltipAppearance::None` | The tooltip's visual appearance. | +| children | `Children` | | | diff --git a/thaw/src/tooltip/mod.rs b/thaw/src/tooltip/mod.rs index 2aff231..4e228ef 100644 --- a/thaw/src/tooltip/mod.rs +++ b/thaw/src/tooltip/mod.rs @@ -1,3 +1,3 @@ mod tooltip; -pub use tooltip::*; \ No newline at end of file +pub use tooltip::*; diff --git a/thaw/src/tooltip/tooltip.css b/thaw/src/tooltip/tooltip.css index e69de29..db308a4 100644 --- a/thaw/src/tooltip/tooltip.css +++ b/thaw/src/tooltip/tooltip.css @@ -0,0 +1,130 @@ +div.thaw-tooltip-content { + position: relative; + transform-origin: inherit; + + padding: 4px 11px 6px; + border-radius: var(--borderRadiusMedium); + border: 1px solid var(--colorTransparentStroke); + line-height: var(--lineHeightBase200); + font-size: var(--fontSizeBase200); + font-family: var(--fontFamilyBase); + max-width: 240px; + overflow-wrap: break-word; + box-sizing: border-box; + filter: drop-shadow(0 0 2px var(--colorNeutralShadowAmbient)) + drop-shadow(0 4px 8px var(--colorNeutralShadowKey)); +} + +div.thaw-tooltip-content--normal { + background-color: var(--colorNeutralBackground1); + color: var(--colorNeutralForeground1); +} + +div.thaw-tooltip-content--inverted { + background-color: var(--colorNeutralBackgroundStatic); + color: var(--colorNeutralForegroundStaticInverted); +} + +.thaw-tooltip-content__angle { + position: absolute; + background-color: inherit; + width: 8px; + height: 8px; +} + +.thaw-tooltip { + display: inline-block; +} + +[data-thaw-placement="top-start"] > .thaw-tooltip-content, +[data-thaw-placement="top-end"] > .thaw-tooltip-content, +[data-thaw-placement="top"] > .thaw-tooltip-content { + margin-bottom: 7px; +} + +[data-thaw-placement="top-start"] .thaw-tooltip-content__angle, +[data-thaw-placement="top-end"] .thaw-tooltip-content__angle, +[data-thaw-placement="top"] .thaw-tooltip-content__angle { + transform: rotate(45deg) translateX(-7px); + bottom: -10px; + left: 50%; +} + +[data-thaw-placement="bottom-start"] > .thaw-tooltip-content, +[data-thaw-placement="bottom-end"] > .thaw-tooltip-content, +[data-thaw-placement="bottom"] > .thaw-tooltip-content { + margin-top: 7px; +} + +[data-thaw-placement="bottom-start"] .thaw-tooltip-content__angle, +[data-thaw-placement="bottom-end"] .thaw-tooltip-content__angle, +[data-thaw-placement="bottom"] .thaw-tooltip-content__angle { + transform: rotate(45deg) translateY(7px); + top: -10px; + left: 50%; +} + +[data-thaw-placement="left-start"] > .thaw-tooltip-content, +[data-thaw-placement="left-end"] > .thaw-tooltip-content, +[data-thaw-placement="left"] > .thaw-tooltip-content { + margin-right: 7px; +} + +[data-thaw-placement="left-start"] .thaw-tooltip-content__angle, +[data-thaw-placement="left-end"] .thaw-tooltip-content__angle, +[data-thaw-placement="left"] .thaw-tooltip-content__angle { + transform: rotate(45deg) translateX(-7px); + top: 50%; + right: -10px; +} + +[data-thaw-placement="right-start"] > .thaw-tooltip-content, +[data-thaw-placement="right-end"] > .thaw-tooltip-content, +[data-thaw-placement="right"] > .thaw-tooltip-content { + margin-left: 7px; +} + +[data-thaw-placement="right-start"] .thaw-tooltip-content__angle, +[data-thaw-placement="right-end"] .thaw-tooltip-content__angle, +[data-thaw-placement="right"] .thaw-tooltip-content__angle { + transform: rotate(45deg) translateY(-7px); + top: 50%; + left: -10px; +} + +[data-thaw-placement="bottom-start"] .thaw-tooltip-content__angle, +[data-thaw-placement="top-start"] .thaw-tooltip-content__angle { + left: 16px; +} +[data-thaw-placement="bottom-end"] .thaw-tooltip-content__angle, +[data-thaw-placement="top-end"] .thaw-tooltip-content__angle { + left: initial; + right: 7px; +} +[data-thaw-placement="right-start"] .thaw-tooltip-content__angle, +[data-thaw-placement="left-start"] .thaw-tooltip-content__angle { + top: 16px; +} +[data-thaw-placement="right-end"] .thaw-tooltip-content__angle, +[data-thaw-placement="left-end"] .thaw-tooltip-content__angle { + top: initial; + bottom: 7px; +} + +.thaw-tooltip-content.tooltip-transition-enter-from, +.thaw-tooltip-content.tooltip-transition-leave-to { + opacity: 0; + transform: scale(0.85); +} + +.thaw-tooltip-content.tooltip-transition-enter-to, +.thaw-tooltip-content.tooltip-transition-leave-from { + transform: scale(1); + opacity: 1; +} + +.thaw-tooltip-content.tooltip-transition-leave-active, +.thaw-tooltip-content.tooltip-transition-enter-active { + transition: opacity var(--durationNormal) var(--curveDecelerateMid), + transform var(--durationNormal) var(--curveDecelerateMid); +} diff --git a/thaw/src/tooltip/tooltip.rs b/thaw/src/tooltip/tooltip.rs index 2be3157..c0ebd70 100644 --- a/thaw/src/tooltip/tooltip.rs +++ b/thaw/src/tooltip/tooltip.rs @@ -4,26 +4,18 @@ use std::time::Duration; use thaw_components::{Binder, CSSTransition, Follower, FollowerPlacement}; use thaw_utils::{class_list, mount_style}; -#[slot] -pub struct TooltipContent { - #[prop(optional, into)] - class: MaybeProp, - children: Children, -} - #[component] pub fn Tooltip( #[prop(optional, into)] class: MaybeProp, - #[prop(optional)] tooltip_content: Option, /// The text of the tooltip. #[prop(optional, into)] - content: MaybeProp, - /// Configure the positioning of the tooltip + content: Option>, + /// Configure the position of the tooltip. #[prop(optional)] position: TooltipPosition, /// The tooltip's visual appearance. #[prop(optional, into)] - appearance: MaybeProp, + appearance: MaybeSignal, children: Children, ) -> impl IntoView { mount_style("tooltip", include_str!("./tooltip.css")); @@ -86,7 +78,7 @@ pub fn Tooltip(
- { - move || { - content.get() - } - } + {move || { content.as_ref().map(|c| c.get()).unwrap_or_default() }}
@@ -108,8 +96,9 @@ pub fn Tooltip( } } -#[derive(Clone)] +#[derive(Clone, Default)] pub enum TooltipAppearance { + #[default] Normal, Inverted, }