Skip to content

Commit

Permalink
feat: ColorPicker adds size prop
Browse files Browse the repository at this point in the history
  • Loading branch information
luoxiaozero committed Dec 15, 2024
1 parent 259ecc9 commit 08686fc
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 5 deletions.
12 changes: 12 additions & 0 deletions thaw/src/color_picker/color-picker.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@
cursor: pointer;
}

.thaw-color-picker-trigger--small {
height: 24px;
font-size: var(--fontSizeBase200);
line-height: var(--lineHeightBase200);
}

.thaw-color-picker-trigger--large {
height: 40px;
font-size: var(--fontSizeBase400);
line-height: var(--lineHeightBase400);
}

.thaw-color-picker-trigger__content {
display: flex;
justify-content: center;
Expand Down
23 changes: 19 additions & 4 deletions thaw/src/color_picker/docs/mod.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,24 @@ view! {
}
```

### Size

```rust demo
use palette::Srgb;

let value = RwSignal::new(Color::from(Srgb::new(0.0, 0.0, 0.0)));

view! {
<ColorPicker value size=ColorPickerSize::Small/>
<ColorPicker value/>
<ColorPicker value size=ColorPickerSize::Large/>
}
```

### ColorPicker Props

| Name | Type | Default | Desciption |
| ----- | ------------------- | -------------------- | -------------------- |
| class | `MaybeProp<String>` | `Default::default()` | |
| value | `Model<Color>` | `Default::default()` | Value of the picker. |
| 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. |
11 changes: 10 additions & 1 deletion thaw/src/color_picker/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
mod color;
mod types;

pub use color::*;
pub use types::*;

use crate::ConfigInjection;
use leptos::leptos_dom::helpers::WindowListenerHandle;
Expand All @@ -15,6 +17,9 @@ pub fn ColorPicker(
/// Value of the picker.
#[prop(optional, into)]
value: Model<Color>,
/// Size of the picker.
#[prop(optional, into)]
size: Signal<ColorPickerSize>,
) -> impl IntoView {
mount_style("color-picker", include_str!("./color-picker.css"));
let config_provider = ConfigInjection::expect_context();
Expand Down Expand Up @@ -135,7 +140,11 @@ pub fn ColorPicker(
view! {
<Binder>
<div
class=class_list!["thaw-color-picker-trigger", class]
class=class_list![
"thaw-color-picker-trigger",
move || format!("thaw-color-picker-trigger--{}", size.get().as_str()),
class
]
on:click=show_popover
node_ref=trigger_ref
>
Expand Down
17 changes: 17 additions & 0 deletions thaw/src/color_picker/types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#[derive(Debug, Default, PartialEq, Clone, Copy)]
pub enum ColorPickerSize {
Small,
#[default]
Medium,
Large,
}

impl ColorPickerSize {
pub fn as_str(&self) -> &'static str {
match self {
Self::Small => "small",
Self::Medium => "medium",
Self::Large => "large",
}
}
}

0 comments on commit 08686fc

Please sign in to comment.