mirror of
https://github.com/adoyle0/thaw.git
synced 2025-01-22 22:09:22 -05:00
feat(docs): adds component prop
This commit is contained in:
parent
efc00d1699
commit
8fb236358a
20 changed files with 371 additions and 209 deletions
|
@ -1,31 +0,0 @@
|
|||
# Image
|
||||
|
||||
```rust demo
|
||||
view! {
|
||||
<Image src="https://s3.bmp.ovh/imgs/2021/10/2c3b013418d55659.jpg" width="500px"/>
|
||||
<Image width="200px" height="200px"/>
|
||||
}
|
||||
```
|
||||
|
||||
### Shape
|
||||
|
||||
```rust demo
|
||||
view! {
|
||||
<Image src="https://s3.bmp.ovh/imgs/2021/10/2c3b013418d55659.jpg" width="200px" height="200px"/>
|
||||
<Image src="https://s3.bmp.ovh/imgs/2021/10/2c3b013418d55659.jpg" width="200px" height="200px" shape=ImageShape::Circular/>
|
||||
<Image src="https://s3.bmp.ovh/imgs/2021/10/2c3b013418d55659.jpg" width="200px" height="200px" shape=ImageShape::Rounded/>
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### Image Props
|
||||
|
||||
| Name | Type | Default | Desciption |
|
||||
| --- | --- | --- | --- |
|
||||
| class | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Addtional classes for the image element. |
|
||||
| src | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Image source. |
|
||||
| alt | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Image alt information. |
|
||||
| width | `MaybeSignal<String>` | `Default::default()` | Image width. |
|
||||
| height | `MaybeSignal<String>` | `Default::default()` | Image height. |
|
||||
| border_radius | `MaybeSignal<String>` | `Default::default()` | Image border radius. |
|
||||
| object_fit | `MaybeSignal<String>` | `Default::default()` | Object-fit type of the image in the container. |
|
|
@ -1,48 +0,0 @@
|
|||
# Nav
|
||||
|
||||
```rust demo
|
||||
|
||||
view! {
|
||||
<NavDrawer>
|
||||
<NavCategory value="area">
|
||||
<NavCategoryItem slot icon=icondata::AiAreaChartOutlined>
|
||||
"Area Chart"
|
||||
</NavCategoryItem>
|
||||
<NavSubItem value="target">
|
||||
"Target"
|
||||
</NavSubItem>
|
||||
<NavSubItem value="above">
|
||||
"Above"
|
||||
</NavSubItem>
|
||||
<NavSubItem value="below">
|
||||
"Below"
|
||||
</NavSubItem>
|
||||
</NavCategory>
|
||||
<NavCategory value="pie">
|
||||
<NavCategoryItem slot icon=icondata::AiPieChartOutlined>
|
||||
"Pie Chart"
|
||||
</NavCategoryItem>
|
||||
<NavSubItem value="pie-target">
|
||||
"Pie Target"
|
||||
</NavSubItem>
|
||||
<NavSubItem value="pin-above">
|
||||
"Pin Above"
|
||||
</NavSubItem>
|
||||
<NavSubItem value="pin-below">
|
||||
"Pin Below"
|
||||
</NavSubItem>
|
||||
</NavCategory>
|
||||
<NavItem
|
||||
icon=icondata::AiGithubOutlined
|
||||
value="github"
|
||||
href="https://github.com/thaw-ui/thaw"
|
||||
attr:target="_blank"
|
||||
>
|
||||
"Github"
|
||||
</NavItem>
|
||||
<NavItem icon=icondata::AiChromeOutlined value="chrome">
|
||||
"Chrome"
|
||||
</NavItem>
|
||||
</NavDrawer>
|
||||
}
|
||||
```
|
|
@ -44,13 +44,13 @@ pub fn include_md(_token_stream: proc_macro::TokenStream) -> proc_macro::TokenSt
|
|||
"DrawerMdPage" => "../../thaw/src/drawer/docs/mod.md",
|
||||
"GridMdPage" => "../../thaw/src/grid/docs/mod.md",
|
||||
"IconMdPage" => "../../thaw/src/icon/docs/mod.md",
|
||||
"ImageMdPage" => "../docs/image/mod.md",
|
||||
"InputMdPage" => "../docs/input/mod.md",
|
||||
"LayoutMdPage" => "../docs/layout/mod.md",
|
||||
"LoadingBarMdPage" => "../docs/loading_bar/mod.md",
|
||||
"MenuMdPage" => "../docs/menu/mod.md",
|
||||
"MessageBarMdPage" => "../docs/message_bar/mod.md",
|
||||
"NavMdPage" => "../docs/nav/mod.md",
|
||||
"ImageMdPage" => "../../thaw/src/image/docs/mod.md",
|
||||
"InputMdPage" => "../../thaw/src/input/docs/mod.md",
|
||||
"LayoutMdPage" => "../../thaw/src/layout/docs/mod.md",
|
||||
"LoadingBarMdPage" => "../../thaw/src/loading_bar/docs/mod.md",
|
||||
"MenuMdPage" => "../../thaw/src/menu/docs/mod.md",
|
||||
"MessageBarMdPage" => "../../thaw/src/message_bar/docs/mod.md",
|
||||
"NavMdPage" => "../../thaw/src/nav/docs/mod.md",
|
||||
"PaginationMdPage" => "../../thaw/src/pagination/docs/mod.md",
|
||||
"PopoverMdPage" => "../docs/popover/mod.md",
|
||||
"ProgressBarMdPage" => "../docs/progress_bar/mod.md",
|
||||
|
|
32
thaw/src/image/docs/mod.md
Normal file
32
thaw/src/image/docs/mod.md
Normal file
|
@ -0,0 +1,32 @@
|
|||
# Image
|
||||
|
||||
```rust demo
|
||||
view! {
|
||||
<Image src="https://s3.bmp.ovh/imgs/2021/10/2c3b013418d55659.jpg" width="500px"/>
|
||||
<Image width="200px" height="200px"/>
|
||||
}
|
||||
```
|
||||
|
||||
### Shape
|
||||
|
||||
```rust demo
|
||||
view! {
|
||||
<Image src="https://s3.bmp.ovh/imgs/2021/10/2c3b013418d55659.jpg" width="200px" height="200px"/>
|
||||
<Image src="https://s3.bmp.ovh/imgs/2021/10/2c3b013418d55659.jpg" width="200px" height="200px" shape=ImageShape::Circular/>
|
||||
<Image src="https://s3.bmp.ovh/imgs/2021/10/2c3b013418d55659.jpg" width="200px" height="200px" shape=ImageShape::Rounded/>
|
||||
}
|
||||
```
|
||||
|
||||
### Image Props
|
||||
|
||||
| Name | Type | Default | Desciption |
|
||||
| --- | --- | --- | --- |
|
||||
| class | `MaybeProp<String>` | `Default::default()` | |
|
||||
| src | `MaybeProp<String>` | `Default::default()` | path to the image you want to display. |
|
||||
| alt | `MaybeProp<String>` | `Default::default()` | description of the image, which isn't mandatory but is incredibly useful for accessibility. |
|
||||
| width | `MaybeProp<String>` | `Default::default()` | Image width. |
|
||||
| height | `MaybeProp<String>` | `Default::default()` | Image height. |
|
||||
| shape | `MaybeSignal<ImageShape>` | `ImageShape::Square` | An image can appear square, circular, or rounded. |
|
||||
| block | `MaybeSignal<bool>` | `Default::default()` | An image can take up the width of its container. |
|
||||
| shadow | `MaybeSignal<bool>` | `Default::default()` | An image can appear elevated with shadow. |
|
||||
| fit | `MaybeSignal<ImageFit>` | `ImageFit::Fill` | An image can set how it should be resized to fit its container. |
|
|
@ -3,18 +3,21 @@ use thaw_utils::{class_list, mount_style};
|
|||
|
||||
#[component]
|
||||
pub fn Image(
|
||||
/// path to the image you want to display
|
||||
#[prop(optional, into)] class: MaybeProp<String>,
|
||||
/// path to the image you want to display.
|
||||
#[prop(optional, into)]
|
||||
src: MaybeProp<String>,
|
||||
/// description of the image, which isn't mandatory but is incredibly useful for accessibility
|
||||
/// description of the image, which isn't mandatory but is incredibly useful for accessibility.
|
||||
#[prop(optional, into)]
|
||||
alt: MaybeProp<String>,
|
||||
/// Image width.
|
||||
#[prop(optional, into)] width: MaybeProp<String>,
|
||||
/// Image height.
|
||||
#[prop(optional, into)] height: MaybeProp<String>,
|
||||
/// An image can appear square, circular, or rounded.
|
||||
#[prop(optional, into)]
|
||||
shape: MaybeSignal<ImageShape>,
|
||||
/// An image can set how it should be resized to fit its container.
|
||||
/// An image can take up the width of its container.
|
||||
#[prop(optional, into)]
|
||||
block: MaybeSignal<bool>,
|
||||
/// An image can appear elevated with shadow.
|
||||
|
@ -23,7 +26,6 @@ pub fn Image(
|
|||
/// An image can set how it should be resized to fit its container.
|
||||
#[prop(optional, into)]
|
||||
fit: MaybeSignal<ImageFit>,
|
||||
#[prop(optional, into)] class: MaybeProp<String>,
|
||||
) -> impl IntoView {
|
||||
mount_style("image", include_str!("./image.css"));
|
||||
|
||||
|
|
|
@ -105,31 +105,35 @@ view! {
|
|||
|
||||
| Name | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| class | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Addtional classes for the input element. |
|
||||
| class | `MaybeProp<String>` | `Default::default()` | |
|
||||
| value | `Model<String>` | `Default::default()` | Set the input value. |
|
||||
| variant | `MaybeSignal<InputVariant>` | `InputVariant::Text` | Input's variant. |
|
||||
| placeholder | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Placeholder of input. |
|
||||
| allow_value | `Option<ArcOneCallback<String, bool>>` | `None` | Check the incoming value, if it returns false, input will not be accepted. |
|
||||
| input_type | `MaybeSignal<InputType>` | `InputType::Text` | An input can have different text-based types based on the type of value the user will enter. |
|
||||
| placeholder | `MaybeProp<String>` | `Default::default()` | Placeholder text for the input. |
|
||||
| disabled | `MaybeSignal<bool>` | `false` | Whether the input is disabled. |
|
||||
| invalid | `MaybeSignal<bool>` | `false` | Whether the input is invalid. |
|
||||
| allow_value | `Option<Callback<String, bool>>` | `None` | Check the incoming value, if it returns false, input will not be accepted. |
|
||||
| on_focus | `Option<Callback<ev::FocusEvent>>` | `None` | Callback triggered when the input is focussed on. |
|
||||
| on_blur | `Option<Callback<ev::FocusEvent>>` | `None` | Callback triggered when the input is blurred. |
|
||||
| attr: | `Vec<(&'static str, Attribute)>` | `Default::default()` | The dom attrs of the input element inside the component. |
|
||||
| on_focus | `Option<BoxOneCallback<ev::FocusEvent>>` | `None` | Callback triggered when the input is focussed on. |
|
||||
| on_blur | `Option<BoxOneCallback<ev::FocusEvent>>` | `None` | Callback triggered when the input is blurred. |
|
||||
| parser | `OptionalProp<BoxOneCallback<String, Option<String>>>` | `None` | Modifies the user input before assigning it to the value. |
|
||||
| format | `OptionalProp<BoxOneCallback<String, String>>` | `None` | Formats the value to be shown to the user |
|
||||
| input_prefix | slot `Option<InputPrefix>` | `None` | |
|
||||
| input_suffix | slot `Option<InputSuffix>` | `None` | |
|
||||
| comp_ref | ref `ComponentRef<InputRef>` | `Default::default()` | |
|
||||
|
||||
### Input Slots
|
||||
### InputPrefix Props
|
||||
|
||||
| Name | Default | Description |
|
||||
| ----------- | ------- | -------------------- |
|
||||
| InputPrefix | `None` | InputPrefix content. |
|
||||
| InputSuffix | `None` | InputSuffix content. |
|
||||
| Name | Type | Default | Description |
|
||||
| -------- | ---------- | ------- | ----------- |
|
||||
| children | `Children` | | |
|
||||
|
||||
### Input Ref
|
||||
### InputSuffix Props
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| -------- | ---------- | ------- | ----------- |
|
||||
| children | `Children` | | |
|
||||
|
||||
### InputRef Props
|
||||
|
||||
| Name | Type | Description |
|
||||
| ----- | ----------- | ------------------------ |
|
||||
| focus | `Fn(&self)` | Focus the input element. |
|
||||
| blur | `Fn(&self)` | Blur the input element. |
|
||||
|
||||
### TextArea Props
|
||||
|
||||
Removes variant and slot from Input component.
|
|
@ -19,23 +19,37 @@ pub struct InputSuffix {
|
|||
|
||||
#[component]
|
||||
pub fn Input(
|
||||
#[prop(optional, into)] value: Model<String>,
|
||||
#[prop(optional, into)] allow_value: Option<ArcOneCallback<String, bool>>,
|
||||
#[prop(optional, into)] input_type: MaybeSignal<InputType>,
|
||||
#[prop(optional, into)] class: MaybeProp<String>,
|
||||
/// Set the input value.
|
||||
#[prop(optional, into)]
|
||||
value: Model<String>,
|
||||
/// Check the incoming value, if it returns false, input will not be accepted.
|
||||
#[prop(optional, into)]
|
||||
allow_value: Option<ArcOneCallback<String, bool>>,
|
||||
/// An input can have different text-based types based on the type of value the user will enter.
|
||||
#[prop(optional, into)]
|
||||
input_type: MaybeSignal<InputType>,
|
||||
/// Placeholder text for the input.
|
||||
#[prop(optional, into)]
|
||||
placeholder: MaybeProp<String>,
|
||||
#[prop(optional, into)] on_focus: Option<BoxOneCallback<ev::FocusEvent>>,
|
||||
#[prop(optional, into)] on_blur: Option<BoxOneCallback<ev::FocusEvent>>,
|
||||
/// Callback triggered when the input is focussed on.
|
||||
#[prop(optional, into)]
|
||||
on_focus: Option<BoxOneCallback<ev::FocusEvent>>,
|
||||
/// Callback triggered when the input is blurred.
|
||||
#[prop(optional, into)]
|
||||
on_blur: Option<BoxOneCallback<ev::FocusEvent>>,
|
||||
/// Whether the input is disabled.
|
||||
#[prop(optional, into)]
|
||||
disabled: MaybeSignal<bool>,
|
||||
#[prop(optional)] input_prefix: Option<InputPrefix>,
|
||||
#[prop(optional)] input_suffix: Option<InputSuffix>,
|
||||
#[prop(optional)] comp_ref: ComponentRef<InputRef>,
|
||||
#[prop(optional, into)] class: MaybeProp<String>,
|
||||
#[prop(optional, into)] parser: OptionalProp<BoxOneCallback<String, Option<String>>>,
|
||||
#[prop(optional, into)] format: OptionalProp<BoxOneCallback<String, String>>,
|
||||
/// Modifies the user input before assigning it to the value.
|
||||
#[prop(optional, into)]
|
||||
parser: OptionalProp<BoxOneCallback<String, Option<String>>>,
|
||||
/// Formats the value to be shown to the user.
|
||||
#[prop(optional, into)]
|
||||
format: OptionalProp<BoxOneCallback<String, String>>,
|
||||
// #[prop(attrs)] attrs: Vec<(&'static str, Attribute)>,
|
||||
) -> impl IntoView {
|
||||
mount_style("input", include_str!("./input.css"));
|
||||
|
@ -219,12 +233,14 @@ pub struct InputRef {
|
|||
}
|
||||
|
||||
impl InputRef {
|
||||
/// Focus the input element.
|
||||
pub fn focus(&self) {
|
||||
if let Some(input_el) = self.input_ref.get_untracked() {
|
||||
_ = input_el.focus();
|
||||
}
|
||||
}
|
||||
|
||||
/// Blur the input element.
|
||||
pub fn blur(&self) {
|
||||
if let Some(input_el) = self.input_ref.get_untracked() {
|
||||
_ = input_el.blur();
|
||||
|
|
|
@ -35,18 +35,25 @@ view! {
|
|||
|
||||
| Name | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| class | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Class of scrollable content node. |
|
||||
| style | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Layout's style. |
|
||||
| content_class | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Addtional classes for the layout element. |
|
||||
| content_style | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Style of scrollable content node. |
|
||||
| class | `MaybeProp<String>` | `Default::default()` | |
|
||||
| content_class | `MaybeProp<String>` | `Default::default()` | Addtional classes for the layout element. |
|
||||
| content_style | `MaybeProp<String>` | `Default::default()` | Style of scrollable content node. |
|
||||
| position | `LayoutPosition` | `LayoutPosition::Static` | static position will make it css position set to static. absolute position will make it css position set to absolute and left, right, top, bottom to 0. absolute position is very useful when you want to make content scroll in a fixed container or make the whole page's layout in a fixed position. You may need to change the style of the component to make it display as you expect. |
|
||||
| has_sider | `MaybeSignal<bool>` | `false` | Whether the component has sider inside. If so it must be true. |
|
||||
| children | `Children` | | Layout's content. |
|
||||
| children | `Children` | | |
|
||||
|
||||
### LayoutHeader, LayoutSider Props
|
||||
### LayoutHeader Props
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| class | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Addtional classes for the layout header element. |
|
||||
| style | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | LayoutHeader's style. |
|
||||
| children | `Children` | | LayoutHeader's content. |
|
||||
| Name | Type | Default | Description |
|
||||
| -------- | ------------------- | -------------------- | ----------- |
|
||||
| class | `MaybeProp<String>` | `Default::default()` | |
|
||||
| children | `Children` | | |
|
||||
|
||||
### LayoutSider Props
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| ------------- | ------------------- | -------------------- | ----------------------------------------- |
|
||||
| class | `MaybeProp<String>` | `Default::default()` | |
|
||||
| content_class | `MaybeProp<String>` | `Default::default()` | Addtional classes for the layout element. |
|
||||
| content_style | `MaybeProp<String>` | `Default::default()` | Style of scrollable content node. |
|
||||
| children | `Children` | | |
|
|
@ -5,7 +5,9 @@ use thaw_utils::{class_list, mount_style};
|
|||
#[component]
|
||||
pub fn LayoutSider(
|
||||
#[prop(optional, into)] class: MaybeProp<String>,
|
||||
/// Addtional classes for the scroll element.
|
||||
#[prop(optional, into)] content_class: MaybeProp<String>,
|
||||
/// Style of scrollable content node.
|
||||
#[prop(optional, into)] content_style: MaybeProp<String>,
|
||||
children: Children,
|
||||
) -> impl IntoView {
|
||||
|
|
|
@ -27,8 +27,16 @@ impl LayoutPosition {
|
|||
#[component]
|
||||
pub fn Layout(
|
||||
#[prop(optional, into)] class: MaybeProp<String>,
|
||||
/// Addtional classes for the layout element.
|
||||
#[prop(optional, into)] content_class: MaybeProp<String>,
|
||||
/// Style of scrollable content node.
|
||||
#[prop(optional, into)] content_style: MaybeProp<String>,
|
||||
/// static position will make it css position set to static.
|
||||
/// absolute position will make it css position set to absolute and left,
|
||||
/// right, top, bottom to 0. absolute position is very useful
|
||||
/// when you want to make content scroll in a fixed container or make
|
||||
/// the whole page's layout in a fixed position. You may need to change
|
||||
/// the style of the component to make it display as you expect.
|
||||
#[prop(optional)] position: LayoutPosition,
|
||||
/// Whether the component has sider inside. If so it must be true.
|
||||
#[prop(optional, into)] has_sider: MaybeSignal<bool>,
|
||||
|
|
|
@ -30,18 +30,21 @@ impl LoadingBarInjection {
|
|||
expect_context::<Self>()
|
||||
}
|
||||
|
||||
/// Callback function for loading bar to start loading.
|
||||
pub fn start(&self) {
|
||||
if let Some(loading_bar_ref) = self.loading_bar_ref.get_untracked() {
|
||||
loading_bar_ref.start();
|
||||
}
|
||||
}
|
||||
|
||||
/// The callback function when the loading bar finishes loading.
|
||||
pub fn finish(&self) {
|
||||
if let Some(loading_bar_ref) = self.loading_bar_ref.get_untracked() {
|
||||
loading_bar_ref.finish();
|
||||
}
|
||||
}
|
||||
|
||||
/// Callback function for loading bar error.
|
||||
pub fn error(&self) {
|
||||
if let Some(loading_bar_ref) = self.loading_bar_ref.get_untracked() {
|
||||
loading_bar_ref.error();
|
||||
|
|
|
@ -150,33 +150,29 @@ view! {
|
|||
|
||||
### Menu Props
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| class | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Addtional classes for the menu element. |
|
||||
| on_select | `Callback<String>` | | Called when item is selected. |
|
||||
| trigger_type | `MenuTriggerType` | `MenuTriggerType::Click` | Action that displays the menu. |
|
||||
| position | `MenuPosition` | `MenuPosition::Bottom` | Menu position. |
|
||||
| children | `Children` | | The content inside menu. |
|
||||
|
||||
### MenuItem Props
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| class | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Addtional classes for the menu item element. |
|
||||
| value | `MaybeSignal<String>` | `Default::default()` | The value of the menu item. |
|
||||
| label | `MaybeSignal<String>` | `Default::default()` | The label of the menu item. |
|
||||
| icon | `OptionalMaybeSignal<icondata_core::Icon>` | `None` | The icon of the menu item. |
|
||||
| disabled | `MaybeSignal<bool>` | `false` | Whether the menu item is disabled. |
|
||||
|
||||
### Menu Slots
|
||||
|
||||
| Name | Default | Description |
|
||||
| ----------- | ------- | -------------------------------------------- |
|
||||
| MenuTrigger | `None` | The element or component that triggers menu. |
|
||||
| Name | Type | Default | Description |
|
||||
| ------------ | --------------------------- | ------------------------ | -------------------------------------------- |
|
||||
| class | `MaybeProp<String>,` | `Default::default()` | |
|
||||
| on_select | `BoxOneCallback<String>` | | Called when item is selected. |
|
||||
| trigger_type | `MenuTriggerType` | `MenuTriggerType::Click` | Action that displays the menu. |
|
||||
| position | `MenuPosition` | `MenuPosition::Bottom` | Menu position. |
|
||||
| appearance | `MaybeProp<MenuAppearance>` | `Default::default()` | |
|
||||
| menu_trigger | slot `MenuTrigger` | | The element or component that triggers menu. |
|
||||
| children | `Children` | | |
|
||||
|
||||
### MenuTriger Props
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| class | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Addtional classes for the menu trigger element. |
|
||||
| children | `Children` | | The content inside menu trigger. |
|
||||
| Name | Type | Default | Description |
|
||||
| -------- | ------------------- | -------------------- | ----------- |
|
||||
| class | `MaybeProp<String>` | `Default::default()` | |
|
||||
| children | `Children` | | |
|
||||
|
||||
### MenuItem Props
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| -------- | -------------------------------- | -------------------- | ---------------------------------- |
|
||||
| class | `MaybeProp<String>` | `Default::default()` | |
|
||||
| value | `MaybeSignal<String>` | `Default::default()` | The value of the menu item. |
|
||||
| icon | `MaybeProp<icondata_core::Icon>` | `None` | The icon of the menu item. |
|
||||
| disabled | `MaybeSignal<bool>` | `false` | Whether the menu item is disabled. |
|
||||
| children | `Children` | | |
|
|
@ -1,34 +1,39 @@
|
|||
use crate::{
|
||||
menu::{HasIcon, OnSelect},
|
||||
Icon,
|
||||
};
|
||||
use crate::{Icon, MenuInjection};
|
||||
use leptos::prelude::*;
|
||||
use thaw_components::{Fallback, If, OptionComp, Then};
|
||||
use thaw_utils::{class_list, mount_style};
|
||||
|
||||
#[component]
|
||||
pub fn MenuItem(
|
||||
#[prop(optional, into)] icon: MaybeProp<icondata_core::Icon>,
|
||||
#[prop(into)] value: MaybeSignal<String>,
|
||||
#[prop(optional, into)] disabled: MaybeSignal<bool>,
|
||||
#[prop(optional, into)] class: MaybeProp<String>,
|
||||
/// The icon of the menu item.
|
||||
#[prop(optional, into)]
|
||||
icon: MaybeProp<icondata_core::Icon>,
|
||||
/// The value of the menu item.
|
||||
#[prop(into)]
|
||||
value: MaybeSignal<String>,
|
||||
/// Whether the menu item is disabled.
|
||||
#[prop(optional, into)]
|
||||
disabled: MaybeSignal<bool>,
|
||||
children: Children,
|
||||
) -> impl IntoView {
|
||||
mount_style("menu-item", include_str!("./menu-item.css"));
|
||||
|
||||
let has_icon = use_context::<HasIcon>().expect("HasIcon not provided").0;
|
||||
let MenuInjection {
|
||||
has_icon,
|
||||
on_select,
|
||||
} = MenuInjection::expect_context();
|
||||
|
||||
if icon.get().is_some() {
|
||||
if icon.with_untracked(|i| i.is_some()) {
|
||||
has_icon.set(true);
|
||||
}
|
||||
|
||||
let on_select = use_context::<OnSelect>().expect("OnSelect not provided").0;
|
||||
|
||||
let on_click = move |_| {
|
||||
if disabled.get() {
|
||||
if disabled.get_untracked() {
|
||||
return;
|
||||
}
|
||||
on_select(value.get());
|
||||
|
||||
on_select(value.get_untracked());
|
||||
};
|
||||
|
||||
view! {
|
||||
|
|
|
@ -3,11 +3,12 @@ mod menu_item;
|
|||
pub use menu_item::*;
|
||||
|
||||
use crate::ConfigInjection;
|
||||
use leptos::{ev, html::Div, leptos_dom::helpers::TimeoutHandle, prelude::*};
|
||||
use leptos::{context::Provider, ev, html::Div, leptos_dom::helpers::TimeoutHandle, prelude::*};
|
||||
use std::time::Duration;
|
||||
use thaw_components::{Binder, CSSTransition, Follower, FollowerPlacement};
|
||||
use thaw_utils::{
|
||||
add_event_listener, call_on_click_outside, class_list, mount_style, ArcOneCallback, BoxCallback,
|
||||
add_event_listener, call_on_click_outside, class_list, mount_style, ArcOneCallback,
|
||||
BoxCallback, BoxOneCallback,
|
||||
};
|
||||
|
||||
#[slot]
|
||||
|
@ -17,20 +18,21 @@ pub struct MenuTrigger {
|
|||
children: Children,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
struct HasIcon(RwSignal<bool>);
|
||||
|
||||
#[derive(Clone)]
|
||||
struct OnSelect(ArcOneCallback<String>);
|
||||
|
||||
#[component]
|
||||
pub fn Menu(
|
||||
#[prop(optional, into)] class: MaybeProp<String>,
|
||||
/// The element or component that triggers menu.
|
||||
menu_trigger: MenuTrigger,
|
||||
#[prop(optional)] trigger_type: MenuTriggerType,
|
||||
#[prop(optional)] position: MenuPosition,
|
||||
#[prop(into)] on_select: ArcOneCallback<String>,
|
||||
#[prop(optional, into)] appearance: Option<MaybeSignal<MenuAppearance>>,
|
||||
/// Action that displays the menu.
|
||||
#[prop(optional)]
|
||||
trigger_type: MenuTriggerType,
|
||||
/// Menu position.
|
||||
#[prop(optional)]
|
||||
position: MenuPosition,
|
||||
/// Called when item is selected.
|
||||
#[prop(into)]
|
||||
on_select: BoxOneCallback<String>,
|
||||
#[prop(optional, into)] appearance: MaybeProp<MenuAppearance>,
|
||||
children: Children,
|
||||
) -> impl IntoView {
|
||||
mount_style("menu", include_str!("./menu.css"));
|
||||
|
@ -93,11 +95,13 @@ pub fn Menu(
|
|||
children: trigger_children,
|
||||
} = menu_trigger;
|
||||
|
||||
provide_context(HasIcon(RwSignal::new(false)));
|
||||
provide_context(OnSelect(ArcOneCallback::<String>::new(move |key| {
|
||||
is_show_menu.set(false);
|
||||
on_select(key);
|
||||
})));
|
||||
let menu_injection = MenuInjection {
|
||||
has_icon: RwSignal::new(false),
|
||||
on_select: ArcOneCallback::new(move |value| {
|
||||
is_show_menu.set(false);
|
||||
on_select(value);
|
||||
}),
|
||||
};
|
||||
|
||||
view! {
|
||||
<Binder target_ref>
|
||||
|
@ -110,33 +114,47 @@ pub fn Menu(
|
|||
{trigger_children()}
|
||||
</div>
|
||||
<Follower slot show=is_show_menu placement=position>
|
||||
<CSSTransition
|
||||
node_ref=menu_ref
|
||||
name="menu-transition"
|
||||
appear=is_show_menu.get_untracked()
|
||||
show=is_show_menu
|
||||
let:display
|
||||
>
|
||||
<div
|
||||
class=class_list![
|
||||
"thaw-config-provider thaw-menu",
|
||||
appearance.map(|appearance| move || format!("thaw-menu--{}", appearance.get().as_str())),
|
||||
class
|
||||
]
|
||||
data-thaw-id=config_provider.id().clone()
|
||||
style=move || display.get().unwrap_or_default()
|
||||
<Provider value=menu_injection>
|
||||
<CSSTransition
|
||||
node_ref=menu_ref
|
||||
on:mouseenter=on_mouse_enter
|
||||
on:mouseleave=on_mouse_leave
|
||||
name="menu-transition"
|
||||
appear=is_show_menu.get_untracked()
|
||||
show=is_show_menu
|
||||
let:display
|
||||
>
|
||||
{children()}
|
||||
</div>
|
||||
</CSSTransition>
|
||||
<div
|
||||
class=class_list![
|
||||
"thaw-config-provider thaw-menu",
|
||||
move || appearance.get().map(|a| format!("thaw-menu--{}", a.as_str())),
|
||||
class
|
||||
]
|
||||
data-thaw-id=config_provider.id().clone()
|
||||
style=move || display.get().unwrap_or_default()
|
||||
node_ref=menu_ref
|
||||
on:mouseenter=on_mouse_enter
|
||||
on:mouseleave=on_mouse_leave
|
||||
>
|
||||
{children()}
|
||||
</div>
|
||||
</CSSTransition>
|
||||
</Provider>
|
||||
</Follower>
|
||||
</Binder>
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct MenuInjection {
|
||||
has_icon: RwSignal<bool>,
|
||||
on_select: ArcOneCallback<String>,
|
||||
}
|
||||
|
||||
impl MenuInjection {
|
||||
pub fn expect_context() -> Self {
|
||||
expect_context()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, PartialEq, Clone)]
|
||||
pub enum MenuTriggerType {
|
||||
Hover,
|
||||
|
|
|
@ -65,3 +65,38 @@ view! {
|
|||
</MessageBar>
|
||||
}
|
||||
```
|
||||
|
||||
### MessageBar Props
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| -------- | ------------------------------- | ------------------------------ | ------------------------------------- |
|
||||
| class | `MaybeProp<String>,` | `Default::default()` | |
|
||||
| layout | `MaybeSignal<MessageBarLayout>` | `MessageBarLayout::Singleline` | |
|
||||
| intent | `MaybeSignal<MessageBarIntent>` | `MessageBarIntent::Info` | Default designs announcement presets. |
|
||||
| children | `Children` | | |
|
||||
|
||||
### MessageBarTitle Props
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| -------- | ------------------- | -------------------- | ----------- |
|
||||
| class | `MaybeProp<String>` | `Default::default()` | |
|
||||
| children | `Children` | | |
|
||||
|
||||
### MessageBarBody Props
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| -------- | ---------- | ------- | ----------- |
|
||||
| children | `Children` | | |
|
||||
|
||||
### MessageBarActions Props
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| ---------------------------- | -------------------------------- | ------- | ----------- |
|
||||
| message_bar_container_action | slot `MessageBarContainerAction` | | |
|
||||
| children | `Children` | | |
|
||||
|
||||
### MessageBarContainerAction Props
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| -------- | ---------- | ------- | ----------- |
|
||||
| children | `Children` | | |
|
97
thaw/src/nav/docs/mod.md
Normal file
97
thaw/src/nav/docs/mod.md
Normal file
|
@ -0,0 +1,97 @@
|
|||
# Nav
|
||||
|
||||
```rust demo
|
||||
|
||||
view! {
|
||||
<NavDrawer>
|
||||
<NavCategory value="area">
|
||||
<NavCategoryItem slot icon=icondata::AiAreaChartOutlined>
|
||||
"Area Chart"
|
||||
</NavCategoryItem>
|
||||
<NavSubItem value="target">
|
||||
"Target"
|
||||
</NavSubItem>
|
||||
<NavSubItem value="above">
|
||||
"Above"
|
||||
</NavSubItem>
|
||||
<NavSubItem value="below">
|
||||
"Below"
|
||||
</NavSubItem>
|
||||
</NavCategory>
|
||||
<NavCategory value="pie">
|
||||
<NavCategoryItem slot icon=icondata::AiPieChartOutlined>
|
||||
"Pie Chart"
|
||||
</NavCategoryItem>
|
||||
<NavSubItem value="pie-target">
|
||||
"Pie Target"
|
||||
</NavSubItem>
|
||||
<NavSubItem value="pin-above">
|
||||
"Pin Above"
|
||||
</NavSubItem>
|
||||
<NavSubItem value="pin-below">
|
||||
"Pin Below"
|
||||
</NavSubItem>
|
||||
</NavCategory>
|
||||
<NavItem
|
||||
icon=icondata::AiGithubOutlined
|
||||
value="github"
|
||||
href="https://github.com/thaw-ui/thaw"
|
||||
attr:target="_blank"
|
||||
>
|
||||
"Github"
|
||||
</NavItem>
|
||||
<NavItem icon=icondata::AiChromeOutlined value="chrome">
|
||||
"Chrome"
|
||||
</NavItem>
|
||||
</NavDrawer>
|
||||
}
|
||||
```
|
||||
|
||||
### NavDrawer Props
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| class | `MaybeProp<String>,` | `Default::default()` | |
|
||||
| selected_value | `OptionModel<String>` | `Default::default()` | The value of the currently selected navItem. |
|
||||
| selected_category_value | `VecModel<String>` | `vec![]` | Indicates a category that has a selected child Will show the category as selected if it is closed. |
|
||||
| nav_drawer_header | slot `Option<NavDrawerHeader>` | `None` | |
|
||||
| nav_drawer_footer | slot `Option<NavDrawerFooter>` | `None` | |
|
||||
| children | `Children` | | |
|
||||
|
||||
### NavDrawerHeader Props
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| -------- | ---------- | ------- | ----------- |
|
||||
| children | `Children` | | |
|
||||
|
||||
### NavDrawerFooter Props
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| -------- | ---------- | ------- | ----------- |
|
||||
| children | `Children` | | |
|
||||
|
||||
### NavCategory Props
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| ----------------- | ---------------------- | ------- | ----------- |
|
||||
| value | `MaybeSignal<String>` | | |
|
||||
| nav_category_item | slot `NavCategoryItem` | | |
|
||||
| children | `Children` | | |
|
||||
|
||||
### NavCategoryItem Props
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| -------- | ------------------------------- | -------------------- | ----------- |
|
||||
| class | `MaybeProp<String>,` | `Default::default()` | |
|
||||
| icon | `MaybeProp<icondata_core::Icon` | `None` | |
|
||||
| children | `Children` | | |
|
||||
|
||||
### NavItem Props
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| -------- | ------------------------------- | -------------------- | ----------- |
|
||||
| class | `MaybeProp<String>,` | `Default::default()` | |
|
||||
| icon | `MaybeProp<icondata_core::Icon` | `None` | |
|
||||
| value | `MaybeSignal<String>` | | |
|
||||
| href | `Option<MaybeSignal<String>>` | `None` | |
|
||||
| children | `Children` | | |
|
|
@ -6,8 +6,12 @@ use thaw_utils::{class_list, mount_style, OptionModel, VecModel};
|
|||
#[component]
|
||||
pub fn NavDrawer(
|
||||
#[prop(optional, into)] class: MaybeProp<String>,
|
||||
#[prop(optional, into)] selected_value: OptionModel<String>,
|
||||
#[prop(default = vec![].into(), into)] selected_category_value: VecModel<String>,
|
||||
/// The value of the currently selected navItem.
|
||||
#[prop(optional, into)]
|
||||
selected_value: OptionModel<String>,
|
||||
/// Indicates a category that has a selected child Will show the category as selected if it is closed.
|
||||
#[prop(default = vec![].into(), into)]
|
||||
selected_category_value: VecModel<String>,
|
||||
children: Children,
|
||||
#[prop(optional)] nav_drawer_header: Option<NavDrawerHeader>,
|
||||
#[prop(optional)] nav_drawer_footer: Option<NavDrawerFooter>,
|
||||
|
|
|
@ -23,3 +23,12 @@ view! {
|
|||
</Space>
|
||||
}
|
||||
```
|
||||
|
||||
### Pagination Props
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| class | `MaybeProp<String>` | `Default::default()` | |
|
||||
| page | `Model<usize>` | `1` | The current page starts from 1. |
|
||||
| page_count | `MaybeSignal<usize>` | | The total numbers of pages. |
|
||||
| sibling_count | `MaybeSignal<usize>` | `1` | Number of visible pages after and before the current page. |
|
||||
|
|
|
@ -5,10 +5,13 @@ use thaw_utils::{class_list, mount_style, Model};
|
|||
|
||||
#[component]
|
||||
pub fn Pagination(
|
||||
#[prop(default = 1.into(), into)] page: Model<usize>,
|
||||
#[prop(into)] page_count: MaybeSignal<usize>,
|
||||
#[prop(default = 1.into(), into)] sibling_count: MaybeSignal<usize>,
|
||||
#[prop(optional, into)] class: MaybeProp<String>,
|
||||
/// The current page starts from 1.
|
||||
#[prop(default = 1.into(), into)] page: Model<usize>,
|
||||
/// The total numbers of pages.
|
||||
#[prop(into)] page_count: MaybeSignal<usize>,
|
||||
/// Number of visible pages after and before the current page.
|
||||
#[prop(default = 1.into(), into)] sibling_count: MaybeSignal<usize>,
|
||||
) -> impl IntoView {
|
||||
mount_style("pagination", include_str!("./pagination.css"));
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue