- Notifications
You must be signed in to change notification settings - Fork328
editable header component#1024
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
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
7 commits Select commitHold shift + click to select a range
5c11d9f
editable heaader component
chillenberger26b6524
newlines
chillenberger69dc028
cleanup
chillenbergerc9673a0
scss name change
chillenbergerb94878c
clean up quote markes
chillenbergerb578d1d
rename component
chillenberger582748b
match input style to figma
chillenbergerFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
3 changes: 3 additions & 0 deletionspgml-dashboard/src/components/inputs/mod.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletionspgml-dashboard/src/components/inputs/text/editable_header/editable_header.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
div[data-controller="inputs-text-editable-header"] { | ||
.editable-header-container { | ||
span.material-symbols-outlined { | ||
color: #{$slate-shade-500}; | ||
font-size: inherit; | ||
text-overflow: ellipsis; | ||
&.active { | ||
color: #{$slate-tint-500}; | ||
} | ||
} | ||
&:hover { | ||
span.material-symbols-outlined { | ||
color: #{$slate-shade-300} | ||
} | ||
} | ||
&:focus, &:focus-within { | ||
span.material-symbols-outlined { | ||
color: #{$slate-tint-500}; | ||
} | ||
} | ||
} | ||
input, input:focus { | ||
border: none; | ||
border-radius: 0; | ||
border-bottom: 2px solid #{$slate-tint-500}; | ||
background: transparent; | ||
font-size: inherit; | ||
line-height: inherit; | ||
padding: 0px; | ||
margin-bottom: -2px; // compensate for border space | ||
} | ||
} |
35 changes: 35 additions & 0 deletionspgml-dashboard/src/components/inputs/text/editable_header/editable_header_controller.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Controller } from '@hotwired/stimulus' | ||
export default class extends Controller { | ||
static targets = ["input", "header"] | ||
initialize() { | ||
this.inputTarget.addEventListener("focusout", (e) => { | ||
this.headerTarget.innerHTML = e.target.value | ||
this.toggleEditor() | ||
}) | ||
// blur input on enter | ||
this.inputTarget.addEventListener("keydown", (e) => { | ||
if(e.key == "Enter") { | ||
this.inputTarget.blur() | ||
} | ||
}) | ||
} | ||
toggleEditor(e) { | ||
// dont toggle if click inside input | ||
if( e && this.inputTarget.contains(e.target)) { | ||
return | ||
} | ||
if(this.inputTarget.style.display == "none") { | ||
this.inputTarget.style.display = "block" | ||
this.headerTarget.style.display = "none" | ||
this.inputTarget.focus() | ||
} else { | ||
this.inputTarget.style.display = "none" | ||
this.headerTarget.style.display = "flex" | ||
} | ||
} | ||
} |
106 changes: 106 additions & 0 deletionspgml-dashboard/src/components/inputs/text/editable_header/mod.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
use pgml_components::component; | ||
use sailfish::runtime::{Buffer, Render}; | ||
use sailfish::TemplateOnce; | ||
use std::fmt; | ||
pub enum Headers { | ||
H1, | ||
H2, | ||
H3, | ||
H4, | ||
H5, | ||
H6, | ||
} | ||
impl fmt::Display for Headers { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
Headers::H1 => write!(f, "h1"), | ||
Headers::H2 => write!(f, "h2"), | ||
Headers::H3 => write!(f, "h3"), | ||
Headers::H4 => write!(f, "h4"), | ||
Headers::H5 => write!(f, "h5"), | ||
Headers::H6 => write!(f, "h6"), | ||
} | ||
} | ||
} | ||
pub struct StimulusTarget { | ||
controller: Option<String>, | ||
target_name: Option<String>, | ||
} | ||
impl StimulusTarget { | ||
pub fn new() -> StimulusTarget { | ||
StimulusTarget { | ||
controller: None, | ||
target_name: None, | ||
} | ||
} | ||
pub fn controller(mut self, controller: &str) -> Self { | ||
self.controller = Some(controller.to_string()); | ||
self | ||
} | ||
pub fn target_name(mut self, target_name: &str) -> Self { | ||
self.target_name = Some(target_name.to_string()); | ||
self | ||
} | ||
} | ||
impl Render for StimulusTarget { | ||
fn render(&self, b: &mut Buffer) -> Result<(), sailfish::RenderError> { | ||
if self.controller.is_none() || self.target_name.is_none() { | ||
return format!("").render(b); | ||
} | ||
format!( | ||
"data-{}-target=\"{}\"", | ||
self.controller.to_owned().unwrap(), | ||
self.target_name.to_owned().unwrap() | ||
) | ||
.render(b) | ||
} | ||
} | ||
#[derive(TemplateOnce)] | ||
#[template(path = "inputs/text/editable_header/template.html")] | ||
pub struct EditableHeader { | ||
value: String, | ||
header_type: Headers, | ||
input_target: StimulusTarget, | ||
input_name: Option<String>, | ||
} | ||
impl EditableHeader { | ||
pub fn new() -> EditableHeader { | ||
EditableHeader { | ||
value: String::from("Title Goes Here"), | ||
header_type: Headers::H3, | ||
input_target: StimulusTarget::new(), | ||
input_name: None, | ||
} | ||
} | ||
pub fn header_type(mut self, header_type: Headers) -> Self { | ||
self.header_type = header_type; | ||
self | ||
} | ||
pub fn value(mut self, value: &str) -> Self { | ||
self.value = value.to_string(); | ||
self | ||
} | ||
pub fn input_target(mut self, input_target: StimulusTarget) -> Self { | ||
self.input_target = input_target; | ||
self | ||
} | ||
pub fn input_name(mut self, input_name: &str) -> Self { | ||
self.input_name = Some(input_name.to_string()); | ||
self | ||
} | ||
} | ||
component!(EditableHeader); |
23 changes: 23 additions & 0 deletionspgml-dashboard/src/components/inputs/text/editable_header/template.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<div data-controller="inputs-text-editable-header"> | ||
<div class="editable-header-container" style="display: block" | ||
data-action="click->inputs-text-editable-header#toggleEditor"> | ||
<<%= header_type.to_string() %> class="align-items-center <%= header_type.to_string() %> d-flex gap-3"> | ||
<span data-inputs-text-editable-header-target="header"> | ||
<%= value %> | ||
</span> | ||
<input type="text" class="form-control" value="<%= value %>" style="display: none" maxlength="50" | ||
name='<%= input_name.unwrap_or_else(|| "".to_string()) %>' | ||
data-inputs-text-editable-header-target="input" | ||
<%- input_target %> > | ||
<div> | ||
<span class="material-symbols-outlined"> | ||
border_color | ||
</span> | ||
</div> | ||
</<%= header_type.to_string() %>> | ||
</div> | ||
</div> |
6 changes: 6 additions & 0 deletionspgml-dashboard/src/components/inputs/text/mod.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// This file is automatically generated. | ||
// You shouldn't modify it manually. | ||
// src/components/inputs/text/editable_header | ||
pub mod editable_header; | ||
pub use editable_header::EditableHeader; |
1 change: 1 addition & 0 deletionspgml-dashboard/static/css/modules.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletionspgml-dashboard/templates/content/playground.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.