Skip to content

Commit

Permalink
feat: Spinner adds children prop
Browse files Browse the repository at this point in the history
  • Loading branch information
luoxiaozero committed Sep 11, 2024
1 parent b04feef commit 09ef9f8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
22 changes: 17 additions & 5 deletions thaw/src/spinner/docs/mod.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,22 @@ view! {
}
```

### Custom label

```rust demo
view! {
<Spinner label="Label"/>
<Spinner>
<b style="color: blue">"Label"</b>
</Spinner>
}
```

### Spinner Props

| Name | Type | Default | Description |
| ----- | -------------------------- | --------------------- | ---------------------------------- |
| class | `MaybeProp<String>` | `Default::default()` | |
| label | `MaybeProp<String>` | `Default::default()` | An optional label for the Spinner. |
| size | `MaybeSignal<SpinnerSize>` | `SpinnerSize::Medium` | The size of the spinner. |
| Name | Type | Default | Description |
| -------- | -------------------------- | --------------------- | ---------------------------------- |
| class | `MaybeProp<String>` | `Default::default()` | |
| label | `MaybeProp<String>` | `Default::default()` | An optional label for the Spinner. |
| size | `MaybeSignal<SpinnerSize>` | `SpinnerSize::Medium` | The size of the spinner. |
| children | `Option<Children>` | `None` | |
34 changes: 24 additions & 10 deletions thaw/src/spinner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ pub fn Spinner(
/// The size of the spinner.
#[prop(optional, into)]
size: MaybeSignal<SpinnerSize>,
#[prop(optional)] children: Option<Children>,
) -> impl IntoView {
mount_style("spinner", include_str!("./spinner.css"));
let id = StoredValue::new(uuid::Uuid::new_v4().to_string());

let spinner_label = label.clone();
let children_flag = children.is_some();
let labelledby = move || {
spinner_label.with(|label| {
if label.is_some() {
if label.is_some() || children_flag {
Some(id.get_value())
} else {
None
Expand All @@ -66,17 +68,29 @@ pub fn Spinner(
<span class="thaw-spinner__spinner">
<span class="thaw-spinner__spinner-tail"></span>
</span>
{move || {
if let Some(label) = label.get() {
view! {
<label class="thaw-spinner__label" id=id.get_value()>
{label}
</label>
{if let Some(children) = children {
view! {
<label class="thaw-spinner__label" id=id.get_value()>
{children()}
</label>
}
.into_any()
} else {
{
move || {
if let Some(label) = label.get() {
view! {
<label class="thaw-spinner__label" id=id.get_value()>
{label}
</label>
}
.into()
} else {
None
}
}
.into()
} else {
None
}
.into_any()
}}
</div>
}
Expand Down

0 comments on commit 09ef9f8

Please sign in to comment.