Content-Length: 9851 | pFad | http://github.com/postgresml/postgresml/pull/1024.diff
thub.com diff --git a/pgml-dashboard/src/components/inputs/mod.rs b/pgml-dashboard/src/components/inputs/mod.rs index 51c02dbec..4036ea229 100644 --- a/pgml-dashboard/src/components/inputs/mod.rs +++ b/pgml-dashboard/src/components/inputs/mod.rs @@ -4,3 +4,6 @@ // src/components/inputs/range_group pub mod range_group; pub use range_group::RangeGroup; + +// src/components/inputs/text +pub mod text; diff --git a/pgml-dashboard/src/components/inputs/text/editable_header/editable_header.scss b/pgml-dashboard/src/components/inputs/text/editable_header/editable_header.scss new file mode 100644 index 000000000..49b36cad9 --- /dev/null +++ b/pgml-dashboard/src/components/inputs/text/editable_header/editable_header.scss @@ -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 + } +} diff --git a/pgml-dashboard/src/components/inputs/text/editable_header/editable_header_controller.js b/pgml-dashboard/src/components/inputs/text/editable_header/editable_header_controller.js new file mode 100644 index 000000000..9a72b59a5 --- /dev/null +++ b/pgml-dashboard/src/components/inputs/text/editable_header/editable_header_controller.js @@ -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" + } + } +} diff --git a/pgml-dashboard/src/components/inputs/text/editable_header/mod.rs b/pgml-dashboard/src/components/inputs/text/editable_header/mod.rs new file mode 100644 index 000000000..36e0626d7 --- /dev/null +++ b/pgml-dashboard/src/components/inputs/text/editable_header/mod.rs @@ -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: OptionFetched URL: http://github.com/postgresml/postgresml/pull/1024.diff
Alternative Proxies: