Corex.Editable
(Corex v0.1.0-alpha.30)
View Source
Phoenix implementation of Zag.js Editable.
Examples
Basic
<.editable id="edit" value="Click to edit" class="editable">
<:label>Name</:label>
<:edit_trigger><.heroicon name="hero-pencil-square" class="icon" /></:edit_trigger>
<:submit_trigger><.heroicon name="hero-check" class="icon" /></:submit_trigger>
<:cancel_trigger><.heroicon name="hero-x-mark" class="icon" /></:cancel_trigger>
</.editable>Required slots: :label, :edit_trigger, :submit_trigger, :cancel_trigger. Preview value is managed by the component and the Editable TS hook.
Styling
Use data attributes to target elements:
[data-scope="editable"][data-part="root"] {}
[data-scope="editable"][data-part="area"] {}
[data-scope="editable"][data-part="label"] {}
[data-scope="editable"][data-part="input"] {}
[data-scope="editable"][data-part="preview"] {}
[data-scope="editable"][data-part="edit-trigger"] {}
[data-scope="editable"][data-part="control"] {}
[data-scope="editable"][data-part="submit-trigger"] {}
[data-scope="editable"][data-part="cancel-trigger"] {}If you wish to use the default Corex styling, you can use the class editable on the component.
This requires to install Mix.Tasks.Corex.Design first and import the component css file.
@import "../corex/main.css";
@import "../corex/tokens/themes/neo/light.css";
@import "../corex/components/editable.css";You can then use modifiers
<.editable class="editable editable--accent editable--lg" value="">
<:label>Label</:label>
<:edit_trigger>Edit</:edit_trigger>
<:submit_trigger>Save</:submit_trigger>
<:cancel_trigger>Cancel</:cancel_trigger>
</.editable>Learn more about modifiers and Corex Design
Summary
Components
Attributes
id(:string) - The id of the editable component.value(:string) - The current or initial value. Defaults to"".controlled(:boolean) - Whether the value is controlled externally. Defaults tofalse.disabled(:boolean) - Whether the editable is disabled. Defaults tofalse.read_only(:boolean) - Whether the editable is read-only. Defaults tofalse.required(:boolean) - Whether the input is required. Defaults tofalse.invalid(:boolean) - Whether the editable is in invalid state. Defaults tofalse.name(:string) - The name attribute for form submission. Defaults tonil.form(:string) - The id of the form this input belongs to. Defaults tonil.dir(:string) - Text direction. Defaults tonil. Must be one ofnil,"ltr", or"rtl".edit(:boolean) - Controlled edit state when controlled_edit is true. Defaults tofalse.controlled_edit(:boolean) - Whether edit state is controlled externally. Defaults tofalse.default_edit(:boolean) - Initial edit state when uncontrolled. Defaults tofalse.placeholder(:string) - Placeholder text when value is empty. Defaults tonil.activation_mode(:string) - How to activate edit mode. Defaults tonil. Must be one ofnil,"dblclick", or"focus".select_on_focus(:boolean) - Whether to select all text on focus. Defaults totrue.on_value_change(:string) - Server event name when value changes. Defaults tonil.on_value_change_client(:string) - Client event name when value changes. Defaults tonil.translation(Corex.Editable.Translation) - Override translatable strings. Defaults tonil.- Global attributes are accepted.
Slots
label(required) - Accepts attributes:class(:string)
edit_trigger(required) - Accepts attributes:class(:string)
submit_trigger(required) - Accepts attributes:class(:string)
cancel_trigger(required) - Accepts attributes:class(:string)