use dioxus::prelude::*;
use crate::parser::ApiParameter;
use super::schema_viewer::SchemaViewer;
#[derive(Props, Clone, PartialEq)]
pub struct ParametersListProps {
pub parameters: Vec<ApiParameter>,
}
#[component]
pub fn ParametersList(props: ParametersListProps) -> Element {
if props.parameters.is_empty() {
return rsx! {};
}
rsx! {
div { class: "space-y-1",
for param in &props.parameters {
ParameterItem { key: "{param.name}", parameter: param.clone() }
}
}
}
}
#[derive(Props, Clone, PartialEq)]
pub struct ParameterItemProps {
pub parameter: ApiParameter,
}
#[component]
pub fn ParameterItem(props: ParameterItemProps) -> Element {
let param = &props.parameter;
let location_badge = param.location.badge_class();
let location_str = param.location.as_str();
rsx! {
div { class: "border-b border-base-300 py-3 first:pt-0 last:border-b-0",
div { class: "flex items-center gap-2 flex-wrap",
code { class: "font-mono font-semibold text-primary",
"{param.name}"
}
span { class: "badge {location_badge} badge-sm badge-outline",
"{location_str}"
}
if let Some(schema) = ¶m.schema {
span { class: "text-xs px-2 py-0.5 rounded-full bg-base-300 text-base-content/70",
"{schema.display_type()}"
}
}
if param.required {
span { class: "text-xs px-2 py-0.5 rounded-full bg-error/20 text-error",
"required"
}
}
if param.deprecated {
span { class: "text-xs px-2 py-0.5 rounded-full bg-warning/20 text-warning line-through",
"deprecated"
}
}
}
if let Some(desc) = ¶m.description {
p { class: "mt-2 text-sm text-base-content/70",
"{desc}"
}
}
if let Some(schema) = ¶m.schema {
if schema.is_complex() {
div { class: "mt-2",
SchemaViewer {
schema: schema.clone(),
depth: 1,
}
}
}
}
if let Some(example) = ¶m.example {
div { class: "mt-2",
span { class: "text-xs text-base-content/50", "Example: " }
code { class: "text-xs font-mono text-secondary",
"{example}"
}
}
}
}
}
}