- Notifications
You must be signed in to change notification settings - Fork328
Dan select component#1048
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
Dan select component#1048
Changes fromall commits
Commits
Show all changes
10 commits Select commitHold shift + click to select a range
d722b51
create select component from dropdown
chillenbergerd63e4d8
correct dropdown padding
chillenberger56596c5
fix disappearing expand icon
chillenberger5335763
turn off auto complete on input header
chillenberger3ce6e26
typo edit
chillenbergerf90968f
Merge branch 'master' into dan-select-component
chillenbergerebc17be
Merge branch 'master' into dan-select-component
chillenberger5be03a0
web app content container mobile padding fix
chillenberger0ac4c8a
dropdown overflow and left nav z-index fix
chillenberger7fa8f1d
Merge branch 'master' into dan-select-component
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
2 changes: 1 addition & 1 deletionpgml-dashboard/content/blog/how-to-improve-search-results-with-machine-learning.md
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
7 changes: 6 additions & 1 deletionpgml-dashboard/src/components/dropdown/dropdown.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
46 changes: 40 additions & 6 deletionspgml-dashboard/src/components/dropdown/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
14 changes: 4 additions & 10 deletionspgml-dashboard/src/components/dropdown/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
4 changes: 4 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
111 changes: 111 additions & 0 deletionspgml-dashboard/src/components/inputs/select/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,111 @@ | ||
use crate::components::stimulus::stimulus_action::{StimulusAction, StimulusEvents}; | ||
use pgml_components::component; | ||
use pgml_components::Component; | ||
use sailfish::TemplateOnce; | ||
#[derive(TemplateOnce, Default)] | ||
#[template(path = "inputs/select/template.html")] | ||
pub struct Select { | ||
options: Vec<Component>, | ||
value: String, | ||
offset: String, | ||
collapsable: bool, | ||
offset_collapsed: String, | ||
menu_position: String, | ||
expandable: bool, | ||
name: String, | ||
} | ||
impl Select { | ||
pub fn new() -> Select { | ||
Select { | ||
options: Vec::new(), | ||
value: "Select".to_owned(), | ||
offset: "0, 10".to_owned(), | ||
offset_collapsed: "68, -44".to_owned(), | ||
menu_position: "".to_owned(), | ||
name: "input_name".to_owned(), | ||
..Default::default() | ||
} | ||
.options(vec![ | ||
"option1".to_owned(), | ||
"option2".to_owned(), | ||
"option3".to_owned(), | ||
]) | ||
} | ||
pub fn options(mut self, values: Vec<String>) -> Self { | ||
let mut options = Vec::new(); | ||
self.value = values.first().unwrap().to_owned(); | ||
for value in values { | ||
let item = Option::new( | ||
value, | ||
StimulusAction::new() | ||
.controller("inputs-select") | ||
.method("choose") | ||
.action(StimulusEvents::Click), | ||
); | ||
options.push(item.into()); | ||
} | ||
self.options = options; | ||
self | ||
} | ||
pub fn name(mut self, name: &str) -> Self { | ||
self.name = name.to_owned(); | ||
self | ||
} | ||
pub fn text(mut self, value: String) -> Self { | ||
self.value = value; | ||
self | ||
} | ||
pub fn collapsable(mut self) -> Self { | ||
self.collapsable = true; | ||
self | ||
} | ||
pub fn menu_end(mut self) -> Self { | ||
self.menu_position = "dropdown-menu-end".to_owned(); | ||
self | ||
} | ||
pub fn menu_start(mut self) -> Self { | ||
self.menu_position = "dropdown-menu-start".to_owned(); | ||
self | ||
} | ||
pub fn offset(mut self, offset: &str) -> Self { | ||
self.offset = offset.to_owned(); | ||
self | ||
} | ||
pub fn offset_collapsed(mut self, offset: &str) -> Self { | ||
self.offset_collapsed = offset.to_owned(); | ||
self | ||
} | ||
pub fn expandable(mut self) -> Self { | ||
self.expandable = true; | ||
self | ||
} | ||
} | ||
#[derive(TemplateOnce)] | ||
#[template(path = "inputs/select/option.html")] | ||
pub struct Option { | ||
value: String, | ||
action: StimulusAction, | ||
} | ||
impl Option { | ||
pub fn new(value: String, action: StimulusAction) -> Self { | ||
Option { value, action } | ||
} | ||
} | ||
component!(Option); | ||
component!(Select); |
4 changes: 4 additions & 0 deletionspgml-dashboard/src/components/inputs/select/option.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,4 @@ | ||
<li class="menu-item d-flex align-items-center"> | ||
<button type="button" class="dropdown-item" data-action="<%- action %>"><%= value %></button> | ||
</li> |
3 changes: 3 additions & 0 deletionspgml-dashboard/src/components/inputs/select/select.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,3 @@ | ||
div[data-controller="inputs-select"] { | ||
} |
11 changes: 11 additions & 0 deletionspgml-dashboard/src/components/inputs/select/select_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,11 @@ | ||
import { Controller } from '@hotwired/stimulus' | ||
export default class extends Controller { | ||
static targets = ["input", "value"] | ||
choose(e) { | ||
this.inputTarget.value = e.target.innerHTML | ||
this.valueTarget.innerHTML = e.target.innerHTML | ||
} | ||
} |
33 changes: 33 additions & 0 deletionspgml-dashboard/src/components/inputs/select/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,33 @@ | ||
<% | ||
use crate::components::dropdown::Dropdown; | ||
use crate::components::stimulus::stimulus_target::StimulusTarget; | ||
%> | ||
<div data-controller="inputs-select"> | ||
<% let mut dropdown = Dropdown::new() | ||
.items(options) | ||
.offset(&offset) | ||
.offset_collapsed(&offset_collapsed) | ||
.text(value.clone().into()); | ||
if menu_position == "dropdown-menu-end" { | ||
dropdown = dropdown.menu_end(); | ||
} else if menu_position == "dropdown-menu-start" { | ||
dropdown = dropdown.menu_start(); | ||
} | ||
if collapsable { | ||
dropdown = dropdown.collapsable(); | ||
} | ||
if expandable { | ||
dropdown = dropdown.expandable(); | ||
} | ||
dropdown = dropdown.value_target(StimulusTarget::new().controller("inputs-select").name("value")); | ||
%> | ||
<%+ dropdown %> | ||
<input type="hidden" name="<%= name %>" value="<%= value %>" data-inputs-select-target="input"> | ||
</div> |
40 changes: 1 addition & 39 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
2 changes: 1 addition & 1 deletionpgml-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
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
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.