Skip to main content

tablo_ui/components/primitives/
input.rs

1// SYNC: topcoat-ui-registry@0.12.0 sha256:22c01bc78089bfc7e22406af86cfd1e9ba6074f60a169b331dfe3e3882e93912 — do not hand-edit. Sync via `cargo xtask sync-topcoat-ui` (ADR-0007).
2use topcoat::{
3    Result,
4    context::Cx,
5    view::{Attributes, StaticClass, View, class, component, view},
6};
7
8/// Classes for the input's dimensions, border, and interaction states.
9const INPUT: StaticClass = class!(
10    "h-9 w-full min-w-0 rounded-lg border border-border bg-transparent px-3",
11    "text-sm transition-colors outline-none",
12    "placeholder:text-muted-foreground",
13    "file:mr-3 file:h-full file:border-0 file:bg-transparent file:text-sm file:font-medium",
14    "focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
15    "aria-invalid:border-destructive aria-invalid:focus-visible:ring-destructive",
16    "focus-visible:ring-offset-background disabled:pointer-events-none disabled:opacity-50",
17);
18
19/// A styled input.
20///
21/// Pass input attributes and event handlers through `attrs`. Extra classes are added to
22/// the input's classes. It fills its container by default. Set `aria-invalid="true"` to
23/// show the error border and focus ring.
24///
25/// ```ignore
26/// view! {
27///     input(attrs: attributes! { type="email" placeholder="you@example.com" })
28/// }
29/// ```
30#[component]
31pub async fn input(cx: &Cx, #[default] mut attrs: Attributes) -> Result<impl View> {
32    Ok(view! { <input class=(class!(INPUT, attrs.remove("class"))) (attrs)> })
33}