Skip to main content

gpui_form_component/
lib.rs

1//! Runtime helpers for gpui-form components.
2//!
3//! This crate provides:
4//! - `date_picker` for localized runtime date and date-range pickers
5//! - `file_picker` for native GPUI path selection with GPUI Kit styling
6//! - `infinite_select` for cascading selects over nested enums
7
8#[cfg(feature = "derive")]
9pub use gpui_form_component_derive::InfiniteSelect;
10
11mod calendar;
12mod calendar_navigation;
13
14/// Runtime helpers for the localized date picker component.
15pub mod date_picker;
16
17/// Runtime helpers for the native file picker component.
18pub mod file_picker;
19
20/// Embedded i18n adapter used by runtime components and generated code.
21pub mod i18n;
22
23/// Runtime helpers for the InfiniteSelect component.
24pub mod infinite_select;
25
26/// Implementation details used by `#[derive(InfiniteSelect)]` expansions.
27///
28/// This module is public so generated code in downstream crates can resolve
29/// strict Fluent labels without requiring a direct `gpui-es-fluent`
30/// dependency. Its contents are not a stable application-facing API.
31#[doc(hidden)]
32pub mod __macro_support {
33    pub use gpui_es_fluent::{localize_label, localize_message};
34}
35
36#[cfg(all(test, feature = "component-shape"))]
37mod tests {
38    use std::path::PathBuf;
39
40    use component_shape::DeclaredComponentShape;
41    use gpui_form_runtime::shape::{
42        GpuiComponentEventOf, GpuiComponentShape, GpuiComponentShapeFor, GpuiComponentStateOf,
43        GpuiComponentValueBinding, GpuiFormComponentShapePolicy,
44    };
45    use gpui_kit::EventEmitter;
46
47    use crate::{
48        date_picker::{DatePicker, DateRangePicker},
49        file_picker::FilePicker,
50    };
51
52    fn assert_declared_shape<Shape>()
53    where
54        Shape: DeclaredComponentShape + GpuiComponentShape + GpuiFormComponentShapePolicy,
55    {
56    }
57
58    fn assert_shape_for<Shape, Value>()
59    where
60        Shape: GpuiComponentShapeFor<Value>,
61    {
62    }
63
64    fn assert_value_binding<Shape, Value>()
65    where
66        Shape: GpuiComponentValueBinding<Value>,
67        GpuiComponentStateOf<Shape>: EventEmitter<GpuiComponentEventOf<Shape, Value>>,
68    {
69    }
70
71    #[test]
72    fn component_shape_feature_publishes_runtime_component_contracts() {
73        assert_declared_shape::<DatePicker>();
74        assert_shape_for::<DatePicker, chrono::NaiveDate>();
75        assert_value_binding::<DatePicker, chrono::NaiveDate>();
76
77        assert_declared_shape::<DateRangePicker>();
78        assert_shape_for::<DateRangePicker, (chrono::NaiveDate, chrono::NaiveDate)>();
79        assert_value_binding::<DateRangePicker, (chrono::NaiveDate, chrono::NaiveDate)>();
80
81        assert_declared_shape::<FilePicker>();
82        assert_shape_for::<FilePicker, Vec<PathBuf>>();
83        assert_value_binding::<FilePicker, Vec<PathBuf>>();
84    }
85}