x
1
<input type="text" name="tags" id="tags" value="incrivel,impressionante" autocomplete="off" placeholder="Quão legal é isso?" data-controller="combobox" data-combobox-option-create-value="Adicionar" data-combobox-no-results-value="Nenhum resultado encontrado" />1
<%= text_field_tag :tags, "incrivel,impressionante", autocomplete: "off", placeholder: "Quão legal é isso?", data: { controller: "combobox", combobox_option_create_value: "Adicionar", combobox_no_results_value: "Nenhum resultado encontrado" } %>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
@import url("https://esm.sh/tom-select@2.5.2/dist/css/tom-select.min.css");.ts-control { align-items: center; background-color: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--rounded-md); color: var(--color-text); display: inline-flex; font-size: var(--text-sm); line-height: inherit; min-block-size: var(--size-9); padding: var(--size-1_5) var(--size-3); > input { color: inherit; font-size: inherit; }}.ts-dropdown { background-color: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--rounded-md); box-shadow: var(--shadow-md); color: var(--color-text); font-size: var(--text-sm); line-height: inherit; /* Setup transition */ transition-behavior: allow-discrete; transition-duration: var(--time-150); transition-property: display, opacity, transform; /* Exit stage to */ opacity: 0; transform: var(--scale-95); /* On stage */ .dropdown-active & { opacity: 1; transform: var(--scale-100); } /* Enter stage from */ @starting-style { .dropdown-active & { opacity: 0; transform: var(--scale-95); } } .ts-dropdown-content:not(:has(.optgroup)) { padding: var(--size-1); } .optgroup:not(:first-child) { border-block-start-width: var(--border); } .optgroup { padding: var(--size-1); } .optgroup-header { background-color: inherit; color: var(--color-text-subtle); font-size: var(--text-xs); padding: var(--size-1_5) var(--size-2); } .create { padding: var(--size-1_5) var(--size-2); } .option { border: 1px solid transparent; border-radius: var(--rounded-md); padding: var(--size-1_5) var(--size-2); } [data-selectable].option { cursor: default; } .active { background-color: var(--color-border-light); color: inherit !important; } .highlight { background-color: transparent !important; } .spinner { margin: var(--size-1_5) 0 0; } .spinner::after { border-block-color: var(--color-border-dark); }}.ts-wrapper.single .ts-control { background-color: var(--color-surface) !important; background-image: url("chevron-down-zinc-500.svg") !important; background-position: center right var(--size-2) !important; background-repeat: no-repeat !important; background-size: var(--size-4) auto !important; cursor: text; input { cursor: inherit; }}.ts-wrapper.multi .ts-control > .item { background: var(--color-border-light); border-radius: var(--rounded-md); color: inherit; line-height: var(--leading-tight);}.disabled .ts-control { opacity: var(--opacity-50);}.disabled .ts-control * { cursor: not-allowed !important;}.invalid .ts-control { border-color: var(--color-negative);}[data-controller~="combobox"] { clip: rect(0 0 0 0); position: absolute;}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { Controller } from "@hotwired/stimulus"import { get } from "https://esm.sh/@rails/request.js@0.0.13?standalone"import TomSelect from "https://esm.sh/tom-select@2.5.2/base?standalone"export default class extends Controller { static values = { url: String, optionCreate: { type: String, default: "Add" }, noResults: { type: String, default: "No results found" } } initialize() { this.load = this.load.bind(this) } connect() { if (this.element.nodeName === "INPUT") { this.tomSelect = new TomSelect(this.element, this.#inputSettings) } else { this.tomSelect = new TomSelect(this.element, this.#selectSettings) } } disconnect() { this.tomSelect.destroy() } async load(query, callback) { const response = await get(this.urlValue, { responseKind: "json", query: { q: query } }) const jsonResponse = await response.json callback(jsonResponse) } get #inputSettings() { return { render: this.#render, load: this.#loadSetting, persist: false, createOnBlur: true, create: true } } get #selectSettings() { return { render: this.#render, load: this.#loadSetting } } get #render() { return { option_create: (data, escape) => { return `<div class="create">${this.optionCreateValue} <b>${escape(data.input)}</b>...</div>` }, no_results: () => { return `<div class="no-results">${this.noResultsValue}</div>` } } } get #loadSetting() { return this.hasUrlValue && this.load }}