Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Editable header custom input actions#1458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
levkk merged 2 commits intomasterfromlevkk-editable-input-actions
May 13, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
use crate::components::stimulus::stimulus_target::StimulusTarget;
use crate::components::stimulus::{
stimulus_action::{StimulusAction, StimulusActions},
stimulus_target::StimulusTarget,
};
use pgml_components::component;
use sailfish::TemplateOnce;
use std::fmt;

use crate::utils::random_string;

pub enum Headers {
H1,
H2,
Expand DownExpand Up@@ -32,17 +37,31 @@ pub struct EditableHeader {
header_type: Headers,
input_target: StimulusTarget,
input_name: Option<String>,
input_actions: StimulusActions,
id: String,
}

impl Default for EditableHeader {
fn default() -> Self {
let mut input_actions = StimulusActions::default();
input_actions.push(
StimulusAction::new_keydown_with_key("enter")
.controller("inputs-text-editable-header")
.method("blur"),
);
input_actions.push(
StimulusAction::new_focusout()
.controller("inputs-text-editable-header")
.method("focusout"),
);

Self {
value: String::from("TitleGoes Here"),
value: String::from("Titlegoes here"),
header_type: Headers::H3,
input_target: StimulusTarget::new(),
input_name: None,
id: String::from(""),
input_actions,
id: random_string(12),
}
}
}
Expand DownExpand Up@@ -72,6 +91,11 @@ impl EditableHeader {
self
}

pub fn input_action(mut self, input_action: StimulusAction) -> Self {
self.input_actions.push(input_action);
self
}

pub fn id(mut self, id: &str) -> Self {
self.id = id.to_string();
self
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,11 +9,18 @@
<%= value %>
</span>

<input type="text" class="form-control" value="<%= value %>" style="display: none" maxlength="50" autocomplete="off"
name='<%= input_name.unwrap_or_else(|| "".to_string()) %>'
data-inputs-text-editable-header-target="input"
data-action="keydown.enter->inputs-text-editable-header#blur focusout->inputs-text-editable-header#focusout"
<%- input_target %> >
<input
type="text"
class="form-control"
value="<%= value %>"
style="display: none"
maxlength="50"
autocomplete="off"
name="<%= input_name.unwrap_or_default() %>"
data-inputs-text-editable-header-target="input"
data-action="<%- input_actions %>"
<%- input_target %>
>

<div>
<span class="material-symbols-outlined">
Expand Down
11 changes: 11 additions & 0 deletionspgml-dashboard/src/components/stimulus/stimulus_action/mod.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@ pub enum StimulusEvents {
FocusIn,
KeyDown,
KeyUp,
KeyDownWithKey(String),
}

impl fmt::Display for StimulusEvents {
Expand All@@ -27,6 +28,7 @@ impl fmt::Display for StimulusEvents {
StimulusEvents::FocusIn => write!(f, "focusin"),
StimulusEvents::KeyDown => write!(f, "keydown"),
StimulusEvents::KeyUp => write!(f, "keyup"),
StimulusEvents::KeyDownWithKey(ref key) => write!(f, "keydown.{}", key),
}
}
}
Expand All@@ -45,6 +47,7 @@ impl FromStr for StimulusEvents {
"focusin" => Ok(StimulusEvents::FocusIn),
"keydown" => Ok(StimulusEvents::KeyDown),
"keyup" => Ok(StimulusEvents::KeyUp),
"keydown.enter" => Ok(StimulusEvents::KeyDownWithKey("enter".into())),
_ => Err(()),
}
}
Expand DownExpand Up@@ -88,6 +91,14 @@ impl StimulusAction {
pub fn new_input() -> Self {
Self::new().action(StimulusEvents::Input)
}

pub fn new_focusout() -> Self {
Self::new().action(StimulusEvents::FocusOut)
}

pub fn new_keydown_with_key(key: &str) -> Self {
Self::new().action(StimulusEvents::KeyDownWithKey(key.into()))
}
}

impl fmt::Display for StimulusAction {
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp