Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions thaw/src/color_picker/docs/mod.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,19 @@ view! {
}
```

### Label

```rust demo
view! {
<ColorPicker label="Color"/>
}
```

### ColorPicker Props

| Name | Type | Default | Desciption |
| ----- | ------------------------- | ------------------------- | -------------------- |
| class | `MaybeProp<String>` | `Default::default()` | |
| value | `Model<Color>` | `Default::default()` | Value of the picker. |
| size | `Signal<ColorPickerSize>` | `ColorPickerSize::Medium` | Size of the picker. |
| label | `MaybeProp<String>` | `Default::default()` | Label of the picker. |
13 changes: 8 additions & 5 deletions thaw/src/color_picker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ pub fn ColorPicker(
/// Size of the picker.
#[prop(optional, into)]
size: Signal<ColorPickerSize>,
/// Label of the picker.
#[prop(optional, into)]
label: MaybeProp<String>,
) -> impl IntoView {
mount_style("color-picker", include_str!("./color-picker.css"));
let hue = RwSignal::new(0f32);
let sv = RwSignal::new((0f32, 0f32));
let label = RwSignal::new(String::new());
let caption = RwSignal::new(String::new());
let style = Memo::new(move |_| {
let mut style = String::new();

Expand All @@ -39,7 +42,7 @@ pub fn ColorPicker(
let rgb = Srgb::<u8>::from_format(rgb.clone());
let color = format!("rgb({}, {}, {})", rgb.red, rgb.green, rgb.blue);
style.push_str(&format!("background-color: {color};"));
label.set(color);
caption.set(color);
}
Color::HSV(hsv) => {
let rgb: Srgb = hsv.clone().into_color();
Expand All @@ -53,7 +56,7 @@ pub fn ColorPicker(
hsv.saturation * 100.0,
hsv.value * 100.0
);
label.set(color);
caption.set(color);
}
Color::HSL(hsl) => {
let color = format!(
Expand All @@ -63,7 +66,7 @@ pub fn ColorPicker(
hsl.lightness * 100.0
);
style.push_str(&format!("background-color: {color};"));
label.set(color);
caption.set(color);
}
}
});
Expand Down Expand Up @@ -147,7 +150,7 @@ pub fn ColorPicker(
node_ref=trigger_ref
>
<div class="thaw-color-picker-trigger__content" style=move || style.get()>
{move || label.get()}
{move || label.get().unwrap_or_else(|| caption.get())}
</div>
</div>
<Follower slot show=is_show_popover placement=FollowerPlacement::BottomStart>
Expand Down