|
1 | 1 | <script lang="ts"> |
2 | 2 | import MultiSelect from '$lib' |
3 | 3 | import { get_label } from '$lib/utils' |
4 | | - import { colors, foods, languages, octicons } from '$site/options' |
| 4 | + import { languages, octicons } from '$site/options' |
5 | 5 |
|
6 | | - let show_modal_1 = $state(false) |
7 | | - let show_modal_2 = $state(false) |
8 | | -
|
9 | | - const foods_options = foods |
10 | | - const colors_options = colors |
11 | | -
|
12 | | - let selected_foods = $state<string[]>([]) |
13 | | - let selected_colors = $state<string[]>([]) |
| 6 | + let show_modal = $state(false) |
14 | 7 | let selected_languages = $state<string[]>([]) |
15 | 8 | let selected_octicons = $state<string[]>([]) |
16 | 9 |
|
17 | 10 | function handle_escape(event: KeyboardEvent): void { |
18 | | - if (event.key === `Escape`) { |
19 | | - show_modal_1 = false |
20 | | - show_modal_2 = false |
21 | | - } |
| 11 | + if (event.key === `Escape`) show_modal = false |
22 | 12 | } |
23 | 13 | </script> |
24 | 14 |
|
25 | 15 | <svelte:window onkeydown={handle_escape} /> |
26 | 16 |
|
27 | 17 | <h2>MultiSelect in Modal Demo</h2> |
28 | 18 |
|
29 | | -<div class="button-bar"> |
30 | | - <button onclick={() => (show_modal_1 = true)}>Open Modal 1 (Vertical Selects)</button> |
31 | | - <button onclick={() => (show_modal_2 = true)}>Open Modal 2 (Horizontal Selects)</button> |
32 | | -</div> |
| 19 | +<button onclick={() => (show_modal = true)} style="padding: 3pt 6pt; margin: 1em auto;"> |
| 20 | + Open Modal |
| 21 | +</button> |
33 | 22 |
|
34 | | -{#if show_modal_1} |
| 23 | +{#if show_modal} |
35 | 24 | <div |
36 | 25 | class="modal-backdrop" |
37 | 26 | onclick={(event) => { |
38 | | - if (event.target === event.currentTarget) show_modal_1 = false |
| 27 | + if (event.target === event.currentTarget) show_modal = false |
39 | 28 | }} |
40 | 29 | onkeydown={(event) => { |
41 | | - if (event.key === `Enter` || event.key === ` `) show_modal_1 = false |
| 30 | + if (event.key === `Enter` || event.key === ` `) show_modal = false |
42 | 31 | }} |
43 | 32 | role="button" |
44 | 33 | tabindex="0" |
45 | 34 | > |
46 | 35 | <div |
47 | | - class="modal-content modal-1" |
| 36 | + class="modal-content modal" |
48 | 37 | onkeydown={(event) => { |
49 | 38 | if (event.key !== `Escape`) event.stopPropagation() |
50 | 39 | }} |
51 | 40 | role="dialog" |
52 | 41 | aria-modal="true" |
53 | | - aria-labelledby="modal-1-title" |
| 42 | + aria-labelledby="modal-title" |
54 | 43 | tabindex="-1" |
55 | 44 | > |
56 | | - <h2 id="modal-1-title">Modal 1: Favorite Foods & Colors</h2> |
| 45 | + <h2 id="modal-title">Modal: Languages & Octicons</h2> |
57 | 46 | <MultiSelect |
58 | | - bind:selected={selected_foods} |
59 | | - options={foods_options} |
| 47 | + bind:selected={selected_languages} |
| 48 | + options={languages} |
60 | 49 | portal={{ active: true }} |
61 | | - placeholder="Choose foods..." |
| 50 | + placeholder="Choose languages..." |
| 51 | + style="margin-bottom: 1em;" |
62 | 52 | /> |
63 | 53 | <MultiSelect |
64 | | - bind:selected={selected_colors} |
65 | | - options={colors_options} |
| 54 | + bind:selected={selected_octicons} |
| 55 | + options={octicons} |
66 | 56 | portal={{ active: true }} |
67 | | - placeholder="Choose colors..." |
| 57 | + placeholder="Choose octicons..." |
68 | 58 | /> |
69 | | - <p>Selected Foods: {selected_foods.map(get_label).join(`, `) || `None`}</p> |
70 | | - <p>Selected Colors: {selected_colors.map(get_label).join(`, `) || `None`}</p> |
71 | | - <button onclick={() => (show_modal_1 = false)}>Close Modal 1</button> |
72 | | - </div> |
73 | | - </div> |
74 | | -{/if} |
75 | | - |
76 | | -{#if show_modal_2} |
77 | | - <div |
78 | | - class="modal-backdrop" |
79 | | - onclick={(event) => { |
80 | | - if (event.target === event.currentTarget) show_modal_2 = false |
81 | | - }} |
82 | | - onkeydown={(event) => { |
83 | | - if (event.key === `Enter` || event.key === ` `) show_modal_2 = false |
84 | | - }} |
85 | | - role="button" |
86 | | - tabindex="0" |
87 | | - > |
88 | | - <div |
89 | | - class="modal-content modal-2" |
90 | | - onkeydown={(event) => { |
91 | | - if (event.key !== `Escape`) event.stopPropagation() |
92 | | - }} |
93 | | - role="dialog" |
94 | | - aria-modal="true" |
95 | | - aria-labelledby="modal-2-title" |
96 | | - tabindex="-1" |
97 | | - > |
98 | | - <h2 id="modal-2-title">Modal 2: Languages & Octicons (Horizontal)</h2> |
99 | | - <div class="horizontal-selects"> |
100 | | - <MultiSelect |
101 | | - bind:selected={selected_languages} |
102 | | - options={languages} |
103 | | - portal={{ active: true }} |
104 | | - placeholder="Choose languages..." |
105 | | - /> |
106 | | - <MultiSelect |
107 | | - bind:selected={selected_octicons} |
108 | | - options={octicons} |
109 | | - portal={{ active: true }} |
110 | | - placeholder="Choose octicons..." |
111 | | - /> |
112 | | - </div> |
113 | 59 | <p>Selected Languages: {selected_languages.map(get_label).join(`, `) || `None`}</p> |
114 | 60 | <p>Selected Octicons: {selected_octicons.map(get_label).join(`, `) || `None`}</p> |
115 | | - <button onclick={() => (show_modal_2 = false)}>Close Modal 2</button> |
| 61 | + <button onclick={() => (show_modal = false)}>Close Modal 2</button> |
116 | 62 | </div> |
117 | 63 | </div> |
118 | 64 | {/if} |
119 | 65 |
|
120 | 66 | <style> |
121 | | - .button-bar { |
122 | | - margin-bottom: 1.5em; |
123 | | - display: flex; |
124 | | - gap: 1em; |
125 | | - } |
126 | 67 | .modal-backdrop { |
127 | 68 | position: fixed; |
128 | 69 | top: 0; |
129 | 70 | left: 0; |
130 | 71 | width: 100%; |
131 | 72 | height: 100%; |
132 | | - background-color: rgba(0, 0, 0, 0.7); |
| 73 | + background-color: rgba(0, 0, 0, 0.5); |
133 | 74 | display: flex; |
134 | 75 | justify-content: center; |
135 | 76 | align-items: center; |
136 | 77 | } |
137 | | -
|
138 | 78 | .modal-content { |
139 | 79 | background-color: var(--modal-bg, #2d2d2d); |
140 | | - color: var(--modal-text-color, #f0f0f0); |
141 | 80 | padding: 10px 20px 20px; |
142 | 81 | border-radius: 8px; |
143 | | - box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5); |
144 | | - max-width: 600px; |
145 | | - max-height: 80vh; |
146 | | -
|
147 | | - --sms-bg: #3a3a3a; |
148 | | - --sms-text-color: #e0e0e0; |
149 | | - --sms-border: 1pt solid #555; |
150 | | - --sms-focus-border: 1pt solid #7799ff; |
151 | | - --sms-placeholder-color: #aaa; |
152 | | - --sms-selected-bg: #4a4a5a; |
153 | | - --sms-selected-text-color: #f0f0f0; |
154 | | - --sms-options-bg: #333; |
155 | | - --sms-li-active-bg: #505060; |
156 | | - --sms-li-selected-bg: #404050; |
157 | | - --sms-li-selected-color: #e0e0e0; |
158 | | - --sms-remove-btn-hover-color: #ff8f8f; |
159 | | - --sms-disabled-bg: #4f4f4f; |
160 | | - --sms-li-disabled-bg: #454545; |
161 | | - --sms-li-disabled-text: #888; |
162 | 82 | } |
163 | 83 | .modal-content h2 { |
164 | 84 | margin-top: 0; |
165 | 85 | } |
166 | | -
|
167 | | - .horizontal-selects { |
168 | | - display: flex; |
169 | | - gap: 1em; |
170 | | - } |
171 | | -
|
172 | 86 | .modal-content button { |
173 | 87 | background-color: #555; |
174 | 88 | color: white; |
|
0 commit comments