Merge Component
and ComponentPreview
trait (#28365)
- Merge `Component` and `ComponentPreview` trait - Adds a number of component previews - Removes a number of stories Release Notes: - N/A
This commit is contained in:
parent
b15ee1b1cc
commit
c05bf096f8
52 changed files with 3276 additions and 1848 deletions
|
@ -4,6 +4,7 @@ use strum::{EnumIter, EnumString, IntoStaticStr};
|
|||
use ui_macros::{DerivePathStr, path_str};
|
||||
|
||||
use crate::Color;
|
||||
use crate::prelude::*;
|
||||
|
||||
#[derive(
|
||||
Debug,
|
||||
|
@ -30,7 +31,7 @@ pub enum VectorName {
|
|||
/// A [`Vector`] is different from an [`crate::Icon`] in that it is intended
|
||||
/// to be displayed at a specific size, or series of sizes, rather
|
||||
/// than conforming to the standard size of an icon.
|
||||
#[derive(IntoElement)]
|
||||
#[derive(IntoElement, RegisterComponent)]
|
||||
pub struct Vector {
|
||||
path: &'static str,
|
||||
color: Color,
|
||||
|
@ -61,7 +62,6 @@ impl Vector {
|
|||
/// Sets the vector size.
|
||||
pub fn size(mut self, size: impl Into<Size<Rems>>) -> Self {
|
||||
let size = size.into();
|
||||
|
||||
self.size = size;
|
||||
self
|
||||
}
|
||||
|
@ -83,24 +83,72 @@ impl RenderOnce for Vector {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "stories")]
|
||||
pub mod story {
|
||||
use gpui::Render;
|
||||
use story::{Story, StoryItem, StorySection};
|
||||
use strum::IntoEnumIterator;
|
||||
impl Component for Vector {
|
||||
fn scope() -> ComponentScope {
|
||||
ComponentScope::Images
|
||||
}
|
||||
|
||||
use crate::prelude::*;
|
||||
fn name() -> &'static str {
|
||||
"Vector"
|
||||
}
|
||||
|
||||
use super::{Vector, VectorName};
|
||||
fn description() -> Option<&'static str> {
|
||||
Some("A vector image component that can be displayed at specific sizes.")
|
||||
}
|
||||
|
||||
pub struct VectorStory;
|
||||
|
||||
impl Render for VectorStory {
|
||||
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||
Story::container().child(StorySection::new().children(VectorName::iter().map(
|
||||
|vector| StoryItem::new(format!("{:?}", vector), Vector::square(vector, rems(8.))),
|
||||
)))
|
||||
}
|
||||
fn preview(_window: &mut Window, _cx: &mut App) -> Option<AnyElement> {
|
||||
Some(
|
||||
v_flex()
|
||||
.gap_6()
|
||||
.children(vec![
|
||||
example_group_with_title(
|
||||
"Basic Usage",
|
||||
vec![
|
||||
single_example(
|
||||
"Default",
|
||||
Vector::square(VectorName::ZedLogo, rems(8.)).into_any_element(),
|
||||
),
|
||||
single_example(
|
||||
"Custom Size",
|
||||
Vector::new(VectorName::ZedLogo, rems(12.), rems(6.))
|
||||
.into_any_element(),
|
||||
),
|
||||
],
|
||||
),
|
||||
example_group_with_title(
|
||||
"Colored",
|
||||
vec![
|
||||
single_example(
|
||||
"Accent Color",
|
||||
Vector::square(VectorName::ZedLogo, rems(8.))
|
||||
.color(Color::Accent)
|
||||
.into_any_element(),
|
||||
),
|
||||
single_example(
|
||||
"Error Color",
|
||||
Vector::square(VectorName::ZedLogo, rems(8.))
|
||||
.color(Color::Error)
|
||||
.into_any_element(),
|
||||
),
|
||||
],
|
||||
),
|
||||
example_group_with_title(
|
||||
"Different Vectors",
|
||||
vec![
|
||||
single_example(
|
||||
"Zed Logo",
|
||||
Vector::square(VectorName::ZedLogo, rems(8.)).into_any_element(),
|
||||
),
|
||||
single_example(
|
||||
"Zed X Copilot",
|
||||
Vector::square(VectorName::ZedXCopilot, rems(8.))
|
||||
.into_any_element(),
|
||||
),
|
||||
],
|
||||
),
|
||||
])
|
||||
.into_any_element(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue