Last active
February 28, 2025 12:43
-
-
Save rickychilcott/01d8da30ab3b94199126fb773a3b2865 to your computer and use it in GitHub Desktop.
Slim-select stimulus controller
This file contains 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
import { Controller } from "stimulus" | |
import SlimSelect from "slim-select" | |
import "slim-select/dist/slimselect.min.css" | |
import "../style/slimselect-customized.css" | |
export default class extends Controller { | |
connect() { | |
const limit = this.data.get("limit") | |
const placeholder = this.data.get("placeholder") | |
const searchText = this.data.get("no-results") | |
const closeOnSelect = this.single | |
const allowDeselect = !this.element.required | |
this.select = new SlimSelect({ | |
select: this.element, | |
closeOnSelect, | |
allowDeselect, | |
limit, | |
placeholder, | |
searchText | |
}) | |
} | |
get single() { | |
return !this.element.multiple | |
} | |
get multi() { | |
return this.element.multiple | |
} | |
disconnect() { | |
if (this.select) { | |
this.select.destroy() | |
} | |
} | |
} |
This file contains 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
.ss-main .ss-single-selected, .ss-main .ss-multi-selected { | |
min-height: calc(1.5em + 0.75rem + 2px); | |
border: 1px solid #ced4da; | |
border-radius: 0.5rem; | |
} | |
.ss-main .ss-multi-selected .ss-add { | |
margin: 13px 12px 0 5px; | |
} | |
.ss-main .ss-multi-selected .ss-values .ss-value { | |
background-color: #f7f7f9; | |
padding: 6px 10px; | |
} | |
.ss-main .ss-multi-selected .ss-values .ss-value .ss-value-text { | |
color: #657072; | |
} | |
.ss-main .ss-multi-selected .ss-values .ss-value .ss-value-delete { | |
padding-left: 3px; | |
color: #BC3C35; | |
} | |
.ss-content .ss-list .ss-option.ss-highlighted, .ss-content .ss-list .ss-option:hover { | |
color: #657072; | |
background-color: #58B7C1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment