-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
282fcd0
commit 6873501
Showing
14 changed files
with
199 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Label | ||
|
||
```rust demo | ||
view! { | ||
<Label>"This is a label"</Label> | ||
} | ||
``` | ||
|
||
### Size | ||
|
||
```rust demo | ||
view! { | ||
<Flex> | ||
<Label size=LabelSize::Small>"Small"</Label> | ||
<Label>"Medium"</Label> | ||
<Label size=LabelSize::Large>"Large"</Label> | ||
</Flex> | ||
} | ||
``` | ||
|
||
### Weight | ||
|
||
```rust demo | ||
view! { | ||
<Flex> | ||
<Label>"Label"</Label> | ||
<Label weight=LabelWeight::Semibold>"Strong label"</Label> | ||
</Flex> | ||
} | ||
``` | ||
|
||
### Disabled | ||
|
||
```rust demo | ||
view! { | ||
<Label required=true disabled=true>"Required label"</Label> | ||
} | ||
``` | ||
|
||
### Required | ||
|
||
```rust demo | ||
view! { | ||
<Label required=true>"Required label"</Label> | ||
} | ||
``` | ||
|
||
### Label Props | ||
|
||
| Name | Type | Default | Desciption | | ||
| --- | --- | --- | --- | | ||
| class | `MaybeProp<String>` | `Default::default()` | | | ||
| size | `MaybeSignal<LabelSize>` | `LabelSize::Medium` | A label supports different sizes. | | ||
| weight | `MaybeSignal<LabelWeight>` | `LabelWeight::Regular` | A label supports regular and semibold fontweight. | | ||
| disabled | `MaybeSignal<bool>` | `false` | Renders the label as disabled. | | ||
| required | `MaybeSignal<bool>` | `false` | Displays an indicator that the label is for a required field. | | ||
| children | `Children` | | | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
.thaw-label { | ||
line-height: var(--lineHeightBase300); | ||
font-size: var(--fontSizeBase300); | ||
font-family: var(--fontFamilyBase); | ||
color: var(--colorNeutralForeground1); | ||
} | ||
|
||
.thaw-label__required { | ||
padding-left: var(--spacingHorizontalXS); | ||
color: var(--colorPaletteRedForeground3); | ||
} | ||
|
||
.thaw-label--disabled { | ||
color: var(--colorNeutralForegroundDisabled); | ||
} | ||
|
||
.thaw-label--disabled .thaw-label__required { | ||
color: var(--colorNeutralForegroundDisabled); | ||
} | ||
|
||
.thaw-label--small { | ||
font-size: var(--fontSizeBase200); | ||
line-height: var(--lineHeightBase200); | ||
} | ||
|
||
.thaw-label--large { | ||
font-weight: var(--fontWeightSemibold); | ||
font-size: var(--fontSizeBase400); | ||
line-height: var(--lineHeightBase400); | ||
} | ||
|
||
.thaw-label--semibold { | ||
font-weight: var(--fontWeightSemibold); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
use leptos::prelude::*; | ||
use thaw_components::{If, Then}; | ||
use thaw_utils::{class_list, mount_style}; | ||
|
||
#[component] | ||
pub fn Label( | ||
#[prop(optional, into)] class: MaybeProp<String>, | ||
/// A label supports different sizes. | ||
#[prop(optional, into)] | ||
size: MaybeSignal<LabelSize>, | ||
/// A label supports regular and semibold fontweight. | ||
#[prop(optional, into)] | ||
weight: MaybeSignal<LabelWeight>, | ||
/// Displays an indicator that the label is for a required field. | ||
#[prop(optional, into)] | ||
required: MaybeSignal<bool>, | ||
/// Renders the label as disabled. | ||
#[prop(optional, into)] | ||
disabled: MaybeSignal<bool>, | ||
children: Children, | ||
) -> impl IntoView { | ||
mount_style("label", include_str!("./label.css")); | ||
|
||
view! { | ||
<label class=class_list![ | ||
"thaw-label", | ||
("thaw-label--disabled", move || disabled.get()), | ||
move || format!("thaw-label--{}", size.get().as_str()), | ||
move || format!("thaw-label--{}", weight.get().as_str()), | ||
class | ||
]> | ||
{children()} <If cond=required> | ||
<Then slot> | ||
<span aria-hidden="true" class="thaw-label__required"> | ||
"*" | ||
</span> | ||
</Then> | ||
</If> | ||
</label> | ||
} | ||
} | ||
|
||
#[derive(Debug, Default, Clone)] | ||
pub enum LabelSize { | ||
Small, | ||
#[default] | ||
Medium, | ||
Large, | ||
} | ||
|
||
impl LabelSize { | ||
pub fn as_str(&self) -> &'static str { | ||
match self { | ||
Self::Small => "small", | ||
Self::Medium => "medium", | ||
Self::Large => "large", | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Default, Clone)] | ||
pub enum LabelWeight { | ||
#[default] | ||
Regular, | ||
Semibold, | ||
} | ||
|
||
impl LabelWeight { | ||
pub fn as_str(&self) -> &'static str { | ||
match self { | ||
Self::Regular => "regular", | ||
Self::Semibold => "semibold", | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mod label; | ||
|
||
pub use label::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters