use fission::prelude::*;
fission_component! {
pub ProjectNameEditor<()> {
props {
draft: String,
editing: bool,
edit_draft: ActionEnvelope,
begin_edit: ActionEnvelope,
commit: ActionEnvelope,
cancel: ActionEnvelope,
}
}
view(editor, _state, cx) =>
Editable(
id: WidgetId::explicit("project.name"),
value: editor.draft.clone(),
placeholder: cx.tr("project.untitled"),
is_editing: editor.editing,
on_input: editor.edit_draft.clone(),
on_edit: editor.begin_edit.clone(),
on_submit: editor.commit.clone(),
on_cancel: editor.cancel.clone(),
)
}
Field | Type | Meaning | Notes / default behavior |
|---|---|---|---|
id | Option<WidgetId> | Stable identity for the editing field. | Defaults to None. |
value | String | Current displayed or edited text. | Controlled by app state. |
placeholder | String | Text shown when value is empty. | Required for a good empty-state experience. |
is_editing | bool | Whether the widget is currently in edit mode. | Controlled by app state. |
on_input | Option<ActionEnvelope> | Action fired when the text changes in edit mode. | Preserves the bound action; read the edit through ctx.input.text_change(). |
on_submit | Option<ActionEnvelope> | Action dispatched when the user presses Enter in the single-line editor. | Use it to commit the controlled draft and leave edit mode. |
on_edit | Option<ActionEnvelope> | Action fired when the read-mode button is pressed. | Usually flips is_editing to true. |
on_cancel | Option<ActionEnvelope> | Action dispatched when the user presses Escape in the editor. | Use it to restore the committed value and leave edit mode. |