Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {Controller} from '@hotwired/stimulus';
import TomSelect from 'tom-select';
import {TomOptions} from 'tom-select/dist/types/types';

let collectionSelect:TomSelect | null = null;
let collectionSelectOptions:TomOptions | null = null;

export default class extends Controller {
initialize() {
this._onConnect = this._onConnect.bind(this);
this._onAddCollection = this._onAddCollection.bind(this);
}

connect() {
// eslint-disable-next-line @typescript-eslint/unbound-method
this.element.addEventListener('autocomplete:connect', this._onConnect);
// eslint-disable-next-line @typescript-eslint/unbound-method
this.element.addEventListener('assetviewAddCollection', this._onAddCollection);
}

disconnect() {
// eslint-disable-next-line @typescript-eslint/unbound-method
this.element.removeEventListener('autocomplete:connect', this._onConnect);
// eslint-disable-next-line @typescript-eslint/unbound-method
this.element.removeEventListener('assetviewAddCollection', this._onAddCollection);
}

_onAddCollection(event) {
if (!collectionSelect || !collectionSelectOptions) {
return;
}
collectionSelect.addOption(event.detail.option);
collectionSelect.refreshOptions();
collectionSelect.addItem(event.detail.slug);
}

_onConnect(event) {
collectionSelect = event.detail.tomSelect;
collectionSelectOptions = event.detail.options;
}
}
18 changes: 12 additions & 6 deletions app/assets/controllers/assetview_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export default class extends Controller {
'collectionSelect',
];

private hasCategoryFormTarget: boolean;
private hasCollectionFormTarget: boolean;

connect() {
hotkeys('esc', (event) => this.close(event));
hotkeys('right,arrowright', () => this.navigateNext());
Expand Down Expand Up @@ -78,16 +81,19 @@ export default class extends Controller {
if (response.data.body) {
const option = new Option(response.data.body.title, response.data.body.slug);

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
if (this.hasCategoryFormTarget && currentForm === this.categoryFormTarget) {
this.categorySelectTarget.append(option);
this.categorySelectTarget.value = response.data.body.slug;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
} else if (this.hasCollectionFormTarget && currentForm === this.collectionFormTarget) {
option.selected = true;
this.collectionSelectTarget.insertBefore(option, this.collectionSelectTarget.firstChild);
// option.selected = true;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Das muss ich noch rausnehmen.

// this.collectionSelectTarget.insertBefore(option, this.collectionSelectTarget.firstChild);

this.collectionSelectTarget.dispatchEvent(
new CustomEvent(
'assetviewAddCollection',
{detail: {title: response.data.body.title, slug: response.data.body.slug, option}},
),
);
}

if (response.data.message) {
Expand Down
35 changes: 35 additions & 0 deletions app/assets/controllers/clear-input-button_controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {Controller} from '@hotwired/stimulus';

export default class extends Controller {
declare readonly buttonTarget: HTMLButtonElement;
declare readonly inputTarget: HTMLInputElement;

static targets = ['button', 'input'];

connect() {
if (!('content' in document.createElement('template'))) {
return;
}

const template: HTMLTemplateElement | null = document.querySelector('#clear-input-button');
const clone: Node | undefined = template?.content.cloneNode(true);

if (clone === undefined) {
return;
}

this.element.appendChild(clone);
this.buttonTarget.addEventListener('click', () => {
this.inputTarget.value = '';
this.inputTarget.focus();
this.element.classList.remove('is-touched');
});
this.inputTarget.addEventListener('input', (event) => {
if ((event.target as HTMLInputElement)?.value && !this.element.classList.contains('is-touched')) {
this.element.classList.add('is-touched');
} else if (!(event.target as HTMLInputElement)?.value && this.element.classList.contains('is-touched')) {
this.element.classList.remove('is-touched');
}
});
}
}
4 changes: 4 additions & 0 deletions app/assets/styles/components/input.scss
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ input[type="file"]::file-selector-button {
border-radius: border-radius(m);
}

.ts-wrapper.multi & {
padding: 0.5rem 1rem;
}

.ts-wrapper.multi.has-items & {
padding: 0.5rem;
}
Expand Down
33 changes: 33 additions & 0 deletions app/assets/styles/components/search-form.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.search-form {
$this: &;

position: relative;
display: inline-flex;
align-items: center;
Expand Down Expand Up @@ -51,8 +53,39 @@
background-size: 14px;
}

body:not(.no-js) & {
&::-webkit-search-cancel-button{
display: none;
}
}

&:focus {
outline: none;
}
}

&__clear {
@include button-reset;

& {
display: block;
height: 24px;
width: 24px;
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAAAn0lEQVR42u3UMQrDMBBEUZ9WfQqDmm22EaTyjRMHAlM5K+Y7lb0wnUZPIKHlnutOa+25Z4D++MRBX98MD1V/trSppLKHqj9TTBWKcoUqffbUcbBBEhTjBOV4ja4l4OIAZThEOV6jHO8ARXD+gPPvKMABinGOrnu6gTNUawrcQKNCAQ7QeTxORzle3+sDfjJpPCqhJh7GixZq4rHcc9l5A9qZ+WeBhgEuAAAAAElFTkSuQmCC);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Das PNG gefällt mir hier nicht.

background-repeat: no-repeat;
background-size: 14px;
cursor: pointer;
visibility: hidden;
pointer-events: none;
background-position: center;
border-radius: 50%;
flex: 0 0 1.5rem;
}

#{$this}.is-touched:hover &,
#{$this}.is-touched:focus-within & {
visibility: visible;
pointer-events: all;
}
}
}
Loading