Skip to content

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 --open

cg_component ​

Components ​

TypeConstructorMethods
BadgeBadge::new(impl Into<Content>)color(Color) size(Size) icon(impl Into<IconInput>) rounded(bool) class(&str) attribute(&str, impl Into<AttributeValue>) attributes(Attributes)
ButtonButton::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>
IconIcon::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.

TraitMethods
Componentwrite_html(&self, &mut String) (required); render(&self) -> Html (provided)

Option enums ​

TypeValues (as_str())Default
Colorneutral primary success warning danger infoBadge Neutral, Button Primary
Sizesm md lgMd
Variantsolid outline ghostSolid
IconSizexs sm md lg xlMd (Sm as a Badge / Button icon)
IconPositionbefore afterBefore
ButtonTypebutton submit resetButton

Every enum has ALL: &[Self], as_str(), Display and FromStr (the error lists the valid values).

Attributes and HTML ​

ItemDescription
Attributesset(&mut self, &str, impl Into<AttributeValue>), add_classes(iter), merge(Self), get(&str) -> Option<&AttributeValue>, render(&[&str]) -> String. See Template functions and attributes
AttributeValueAn attribute value; From<&str>, String, bool, integers, f64
ContentComponent content: plain text (escaped) or Html (as is). to_markup(), as_text()
escape(&str) -> Cow<str>Escapes & < > " ' like PHP's e()
ButtonValueThe argument of Button::value; From strings, numbers, bool (true → 1)
IconInputThe argument of icon(..); From<&str>, String (becomes an Sm Icon), Icon. into_icon()

The icon registry ​

FunctionDescription
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 ​

FunctionDescription
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 ​

ItemDescription
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_headWeb middleware: issues render tokens for page requests and shares the head tags with templates
HEAD_VARIABLE / HTML_ATTRIBUTE_VARIABLEThe names of the template variables share_head shares (cg_head_tags, cg_html_attribute)
AllowRender / StateRead / StateWrite
render_object(name, &[Allow]) -> AttributesA render object (permission boundary + namespace)
render_trigger(name, RenderMethod, Option<&str>, &[(&str, &str)]) -> AttributesRenders on click; the third argument is the target
render_auto(name, RenderMethod, &[(&str, &str)]) -> AttributesRenders automatically after load
kebab(&str) -> StringcustomerId → customer-id (for data-param-*)

runtime::render ​

ItemDescription
register(name, Fn(RenderInput) -> Future<Output = laravel::Result<Html>>)Registers a fragment
has(name) -> boolWhether it's registered
RenderInputmethod: RenderMethod, params: BTreeMap<String, String>, target: Option<String>, url: Option<String>; param(&str) -> Option<&str>
RenderMethodComponents / Toast / Page / Isolated; as_str()
POOLTokens kept per session (16)
SESSION_KEYThe session key tokens are stored under (cg_render_before)
issue(&Session) -> String / consume(&Session, &str) -> boolIssue / use a token (for tests or custom endpoints)
fingerprint(&str) -> StringA fragment fingerprint (hex of the first 16 bytes of SHA-256)
render / tokenEndpoint handlers (registered by routes)

runtime::endpoints ​

ItemDescription
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_METAThe purpose strings used for derivation

runtime::linker ​

ItemDescription
LinkerComponentA 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
LinkerContextuser: String, alias: &'static str, instance: Option<String>, referer: Option<String>
LinkerModeStateful / Stateless
Argsserde_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
LinkerMountattributes: Attributes; html() -> String
bind(&Value) -> Result<(String, String), String>data-linker-bind
MIN_DELAY_MS800
LinkerResponseok() 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()
FailureKindValidation Policy Expired Conflict Service Fatal; default_message(), status() (409 for Expired / Conflict, 200 otherwise)
Actionnew(&str, Value) -> Result<Self, String>; shortcuts scroll_to class focus reset state_set state_clear render_fragment render_page toast confirm; name()
OnThen / Catch / Always
BUILTIN_ACTIONSThe built-in action spec table
messagesFixed text: VALIDATION POLICY EXPIRED CONFLICT BUSY NOT_FOUND FATAL UNKNOWN_METHOD REFERER UNAUTHENTICATED UNVERIFIED
stateful / statelessEndpoint handlers (registered by routes)

runtime::linker::store ​

Storage for Stateful instances. Usually not used directly; tests or admin tools might.

ItemDescription
IDLE / RENEW_INTERVAL / MAX_LIFETIME1800 / 90 / 28800 seconds
Recordalias state rev created_at renewed_at expires_at absolute_expires_at
key(user, instance)linker:{user}:{instance}
create / find / update / renewAsync access

JavaScript (resources/js/cg/runtime.js) ​

ExportDescription
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 / bindComponentsIndividual binding (usually handled by boot)
CGEventThe PHP version's event base class

Synced from the PHP project; its documentation and source are authoritative for behavior.