56 lines
1.7 KiB
Plaintext
Raw Normal View History

import { alias, or } from "@ember/object/computed";
import { makeArray } from "discourse-common/lib/helpers";
import { on } from "discourse-common/utils/decorators";
import discourseComputed from "discourse-common/utils/decorators";
import SelectKitHeaderComponent from "select-kit/components/select-kit/select-kit-header";
2017-10-19 12:51:08 -07:00
export default SelectKitHeaderComponent.extend({
attributeBindings: [
"label:title",
"label:aria-label",
"names:data-name",
"values:data-value"
],
classNames: "multi-select-header",
2018-06-15 17:03:24 +02:00
layoutName:
"select-kit/templates/components/multi-select/multi-select-header",
selectedNameComponent: alias("options.selectedNameComponent"),
2017-10-19 12:51:08 -07:00
forceEscape: alias("options.forceEscape"),
ariaLabel: or("computedContent.ariaLabel", "title", "names"),
title: or("computedContent.title", "names"),
2017-10-19 12:51:08 -07:00
@on("didRender")
_positionFilter() {
if (!this.shouldDisplayFilter) return;
2017-11-09 10:57:53 -08:00
const $filter = $(this.element.querySelector(".filter"));
2017-11-09 10:57:53 -08:00
$filter.width(0);
2017-10-19 12:51:08 -07:00
const leftHeaderOffset = $(this.element).offset().left;
2017-11-09 10:57:53 -08:00
const leftFilterOffset = $filter.offset().left;
2017-10-19 12:51:08 -07:00
const offset = leftFilterOffset - leftHeaderOffset;
const width = $(this.element).outerWidth(false);
2017-10-19 12:51:08 -07:00
const availableSpace = width - offset;
2017-11-09 10:57:53 -08:00
const $choices = $filter.parent(".choices");
2018-06-15 17:03:24 +02:00
const parentRightPadding = parseInt($choices.css("padding-right"), 10);
2017-11-09 10:57:53 -08:00
$filter.width(availableSpace - parentRightPadding * 4);
2017-10-19 12:51:08 -07:00
},
@discourseComputed("computedContent.selection.[]")
names(selection) {
return makeArray(selection)
2018-06-15 17:03:24 +02:00
.map(s => s.name)
.join(",");
},
@discourseComputed("computedContent.selection.[]")
values(selection) {
return makeArray(selection)
2018-06-15 17:03:24 +02:00
.map(s => s.value)
.join(",");
}
2017-10-19 12:51:08 -07:00
});