Rust API dictionary
The public API of the cg_component crate. The generated rustdoc is the final authority:
bash
cargo doc -p cg-component --no-deps --opencg_component
Components
| Type | Constructor | Methods |
|---|---|---|
Badge | Badge::new(impl Into<Content>) | color(Color) size(Size) icon(impl Into<IconInput>) rounded(bool) class(&str) attribute(&str, impl Into<AttributeValue>) attributes(Attributes) |
Button | Button::new(impl Into<Content>) | color size variant(Variant) icon icon_position(IconPosition) icon_only(Option<&str>) disabled(bool) button_type(ButtonType) name(impl Into<String>) value(impl Into<ButtonValue>) state_set(&str, impl Into<Value>) state_toggle(&str) opens_modal(&str) closes_modal(&str) class attribute attributes validate() -> Result<(), String> |
Icon | Icon::new(impl Into<String>) | size(IconSize) label(impl Into<String>) class attribute attributes name() -> &str |
All implement Component. Builder methods are #[must_use] and take self, returning Self.
| Trait | Methods |
|---|---|
Component | write_html(&self, &mut String) (required); render(&self) -> Html (provided) |
Option enums
| Type | Values (as_str()) | Default |
|---|---|---|
Color | neutral primary success warning danger info | Badge Neutral, Button Primary |
Size | sm md lg | Md |
Variant | solid outline ghost | Solid |
IconSize | xs sm md lg xl | Md (Sm as a Badge / Button icon) |
IconPosition | before after | Before |
ButtonType | button submit reset | Button |
Every enum has ALL: &[Self], as_str(), Display and FromStr (the error lists the valid values).
Attributes and HTML
| Item | Description |
|---|---|
Attributes | set(&mut self, &str, impl Into<AttributeValue>), add_classes(iter), merge(Self), get(&str) -> Option<&AttributeValue>, render(&[&str]) -> String. See Template functions and attributes |
AttributeValue | An attribute value; From<&str>, String, bool, integers, f64 |
Content | Component content: plain text (escaped) or Html (as is). to_markup(), as_text() |
escape(&str) -> Cow<str> | Escapes & < > " ' like PHP's e() |
ButtonValue | The argument of Button::value; From strings, numbers, bool (true → 1) |
IconInput | The argument of icon(..); From<&str>, String (becomes an Sm Icon), Icon. into_icon() |
The icon registry
| Function | Description |
|---|---|
IconDefinition::register(name, paths, view_box) -> Result<(), String> | Registers or replaces an icon |
IconDefinition::find(name) -> Result<IconDefinition, String> | Looks one up |
IconDefinition::names() -> Vec<String> | Every name |
Templates
| Function | Description |
|---|---|
cg_component::register(&mut ViewConfig) | Call inside .with_views to add every template function |
cg_component::jinja::add_functions(&mut Environment) | Adds them to a bare MiniJinja Environment (for tests) |
Template functions: cg_badge cg_button cg_icon cg_head cg_html_attrs. See Template functions and attributes.
cg_component::runtime
| Item | Description |
|---|---|
routes::<U>(&mut Router) | Registers the four endpoints: POST /{prefix}/render, /render/token (60/min), /linker (120/min), /linker/stateless/{alias}/call (120/min). U is the user model |
share_head | Web middleware: issues render tokens for page requests and shares the head tags with templates |
HEAD_VARIABLE / HTML_ATTRIBUTE_VARIABLE | The names of the template variables share_head shares (cg_head_tags, cg_html_attribute) |
Allow | Render / StateRead / StateWrite |
render_object(name, &[Allow]) -> Attributes | A render object (permission boundary + namespace) |
render_trigger(name, RenderMethod, Option<&str>, &[(&str, &str)]) -> Attributes | Renders on click; the third argument is the target |
render_auto(name, RenderMethod, &[(&str, &str)]) -> Attributes | Renders automatically after load |
kebab(&str) -> String | customerId → customer-id (for data-param-*) |
runtime::render
| Item | Description |
|---|---|
register(name, Fn(RenderInput) -> Future<Output = laravel::Result<Html>>) | Registers a fragment |
has(name) -> bool | Whether it's registered |
RenderInput | method: RenderMethod, params: BTreeMap<String, String>, target: Option<String>, url: Option<String>; param(&str) -> Option<&str> |
RenderMethod | Components / Toast / Page / Isolated; as_str() |
POOL | Tokens kept per session (16) |
SESSION_KEY | The session key tokens are stored under (cg_render_before) |
issue(&Session) -> String / consume(&Session, &str) -> bool | Issue / use a token (for tests or custom endpoints) |
fingerprint(&str) -> String | A fragment fingerprint (hex of the first 16 bytes of SHA-256) |
render / token | Endpoint handlers (registered by routes) |
runtime::endpoints
| Item | Description |
|---|---|
prefix() | The current endpoint prefix |
meta_name() | The name of the endpoint meta (m-…) |
render_url() / render_token_url() / linker_url() | Prefixed paths |
meta_payload() | The meta content {"r":…,"t":…,"l":…} |
html_attribute() | data-cg-endpoints="…" for <html> |
head_tags(csrf, render_token) | The meta tags for <head> |
derive(purpose, key) / app_key() | Underlying: HMAC-SHA256 derivation |
PURPOSE_PREFIX / PURPOSE_META | The purpose strings used for derivation |
runtime::linker
| Item | Description |
|---|---|
LinkerComponent | A trait requiring Serialize + DeserializeOwned + Default + Send + Sync + 'static. Constants ALIAS, MODE (default Stateful), METHODS, ALLOWS_REFERER_URLS (default empty = unrestricted); methods mount (default does nothing), booted, call |
LinkerContext | user: String, alias: &'static str, instance: Option<String>, referer: Option<String> |
LinkerMode | Stateful / Stateless |
Args | serde_json::Map<String, Value> |
register::<C>() | Registers a component (at startup) |
mount::<C, U>(&user, Args) -> laravel::Result<LinkerMount> | Creates an instance or signs a URL |
LinkerMount | attributes: Attributes; html() -> String |
bind(&Value) -> Result<(String, String), String> | data-linker-bind |
MIN_DELAY_MS | 800 |
LinkerResponse | ok() fail(FailureKind) validation(iter) policy(&str) not_found(); message(&str) data(&str, impl Serialize) then(Action) catch(Action) always(Action); is_ok() kind() to_json() status() |
FailureKind | Validation Policy Expired Conflict Service Fatal; default_message(), status() (409 for Expired / Conflict, 200 otherwise) |
Action | new(&str, Value) -> Result<Self, String>; shortcuts scroll_to class focus reset state_set state_clear render_fragment render_page toast confirm; name() |
On | Then / Catch / Always |
BUILTIN_ACTIONS | The built-in action spec table |
messages | Fixed text: VALIDATION POLICY EXPIRED CONFLICT BUSY NOT_FOUND FATAL UNKNOWN_METHOD REFERER UNAUTHENTICATED UNVERIFIED |
stateful / stateless | Endpoint handlers (registered by routes) |
runtime::linker::store
Storage for Stateful instances. Usually not used directly; tests or admin tools might.
| Item | Description |
|---|---|
IDLE / RENEW_INTERVAL / MAX_LIFETIME | 1800 / 90 / 28800 seconds |
Record | alias state rev created_at renewed_at expires_at absolute_expires_at |
key(user, instance) | linker:{user}:{instance} |
create / find / update / renew | Async access |
JavaScript (resources/js/cg/runtime.js)
| Export | Description |
|---|---|
boot(root?) (default) | Binds state, components and Linker, and runs auto-rendering |
registerLinkerAction(name, fn) | Registers a custom action, fn(args, context) |
within(context, selector) | querySelector inside the mount point |
callLinker(element, method, args) | Calls a Linker method from JS |
renderBlade(options) / renderBladeAuto(root) | Requests fragments directly |
bindState / bindLinker / bindComponents | Individual binding (usually handled by boot) |
CGEvent | The PHP version's event base class |
Synced from the PHP project; its documentation and source are authoritative for behavior.