@mozaic-ds/vue 0.20.0-beta.3 → 0.20.0-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,231 @@
1
+ <template>
2
+ <div v-click-outside="onClickOutside" class="mc-listbox-options">
3
+ <button
4
+ type="button"
5
+ class="mc-listbox-options__trigger"
6
+ @click="isOpen = !isOpen"
7
+ >
8
+ <m-icon name="DisplayOptions24" />
9
+ <span class="mc-listbox-options__trigger-label">{{ triggerLabel }}</span>
10
+ </button>
11
+ <div
12
+ ref="listbox"
13
+ class="mc-listbox-options__container"
14
+ :class="{ 'is-open': isOpen, 'align-right': position == 'right' }"
15
+ role="listbox"
16
+ aria-labelledby="listbox"
17
+ >
18
+ <ul
19
+ v-for="(list, index) in listItems"
20
+ :key="`${list}-${index}`"
21
+ class="mc-listbox-options__list"
22
+ >
23
+ <li
24
+ v-for="item in list"
25
+ :key="item.id"
26
+ class="mc-listbox-options__tile"
27
+ >
28
+ <m-icon
29
+ v-if="item.icon"
30
+ :name="item.icon"
31
+ class="mc-listbox-options__icon"
32
+ :color="item.danger ? '#C61112' : '#71706B'"
33
+ />
34
+ <component
35
+ :is="item.href ? 'a' : 'button'"
36
+ :href="item.href ? item.href : null"
37
+ :type="item.href ? null : 'button'"
38
+ class="mc-listbox-options__item"
39
+ :class="{ 'is-danger': item.danger }"
40
+ @click.self="$emit('update:itemSelected', item)"
41
+ >
42
+ {{ item.text }}
43
+ </component>
44
+ </li>
45
+ </ul>
46
+ </div>
47
+ </div>
48
+ </template>
49
+
50
+ <script>
51
+ import MIcon from '../icon/MIcon.vue';
52
+
53
+ export default {
54
+ name: 'MListBoxOptions',
55
+
56
+ components: {
57
+ MIcon,
58
+ },
59
+
60
+ directives: {
61
+ 'click-outside': {
62
+ bind(el, binding, vnode) {
63
+ el.clickOutsideEvent = (event) => {
64
+ if (!(el === event.target || el.contains(event.target))) {
65
+ vnode.context[binding.expression](event);
66
+ }
67
+ };
68
+ document.body.addEventListener('click', el.clickOutsideEvent);
69
+ },
70
+ unbind(el) {
71
+ document.body.removeEventListener('click', el.clickOutsideEvent);
72
+ },
73
+ },
74
+ },
75
+
76
+ props: {
77
+ open: {
78
+ type: Boolean,
79
+ default: false,
80
+ },
81
+ position: {
82
+ type: String,
83
+ default: 'left',
84
+ },
85
+ items: {
86
+ type: Array,
87
+ default: () => [],
88
+ },
89
+ triggerLabel: {
90
+ type: String,
91
+ default: 'Display options',
92
+ },
93
+ },
94
+
95
+ data() {
96
+ return {
97
+ isOpen: this.open,
98
+ };
99
+ },
100
+
101
+ computed: {
102
+ listItems: function () {
103
+ const hasNestedArray = this.items.filter(Array.isArray).length;
104
+
105
+ if (hasNestedArray === 0) {
106
+ const listItems = [];
107
+ listItems.push(this.items);
108
+ return [this.items];
109
+ }
110
+
111
+ return this.items;
112
+ },
113
+ },
114
+
115
+ methods: {
116
+ onClickOutside() {
117
+ this.isOpen = false;
118
+ },
119
+ },
120
+ };
121
+ </script>
122
+
123
+ <style lang="scss">
124
+ @import 'settings-tools/all-settings';
125
+
126
+ .mc-listbox-options {
127
+ display: inline-block;
128
+ position: relative;
129
+
130
+ &__trigger {
131
+ align-items: center;
132
+ background: none;
133
+ border: none;
134
+ cursor: pointer;
135
+ display: flex;
136
+ height: $mu150;
137
+ justify-content: center;
138
+ padding: 0;
139
+ width: $mu150;
140
+
141
+ &-label {
142
+ @include visually-hidden();
143
+ }
144
+ }
145
+
146
+ &__container {
147
+ position: absolute;
148
+ overflow-y: auto;
149
+ opacity: 0;
150
+ visibility: hidden;
151
+ min-width: $mu800;
152
+ background-color: $color-grey-000;
153
+ border: 1px solid $color-grey-600;
154
+ border-radius: 3px;
155
+
156
+ &.is-open {
157
+ opacity: 1;
158
+ visibility: visible;
159
+ z-index: 11;
160
+ }
161
+
162
+ &.align-right {
163
+ transform: translateX(calc(-100% + #{$mu150}));
164
+ }
165
+ }
166
+
167
+ &__list {
168
+ $parent: get-parent-selector(&);
169
+ @include unstyle-list();
170
+ margin: 0 auto;
171
+ padding: 8px 0;
172
+
173
+ &::-webkit-scrollbar {
174
+ background-color: $color-grey-100;
175
+ width: $mu025;
176
+
177
+ &-thumb {
178
+ background: $color-grey-600;
179
+ }
180
+ }
181
+
182
+ &:not(:last-child) {
183
+ border-bottom: 1px solid #bab6bc;
184
+ }
185
+ }
186
+
187
+ &__tile {
188
+ align-items: center;
189
+ color: #1e1e1c;
190
+ display: flex;
191
+ gap: $mu050;
192
+ min-height: $mu250;
193
+ padding-left: $mu075;
194
+ padding-right: $mu075;
195
+ position: relative;
196
+
197
+ &:hover {
198
+ background-color: #eeedea;
199
+ }
200
+ }
201
+
202
+ &__item {
203
+ @include set-font-scale('05', 'm');
204
+
205
+ background: none;
206
+ border: none;
207
+ color: currentColor;
208
+ cursor: pointer;
209
+ padding: 0;
210
+ white-space: nowrap;
211
+
212
+ &::after {
213
+ content: '';
214
+ position: absolute;
215
+ inset: 0;
216
+ z-index: 2;
217
+ }
218
+
219
+ &,
220
+ &:active,
221
+ &:hover,
222
+ &:focus {
223
+ text-decoration: none;
224
+ }
225
+
226
+ &.is-danger {
227
+ color: #c61112;
228
+ }
229
+ }
230
+ }
231
+ </style>
@@ -1,7 +1,12 @@
1
1
  import MListBox from './MListBox.vue';
2
+ import MListBoxOptions from './MListBoxOptions.vue';
2
3
 
3
4
  MListBox.install = function (Vue) {
4
5
  Vue.component(MListBox.name, MListBox);
5
6
  };
6
7
 
7
- export { MListBox };
8
+ MListBoxOptions.install = function (Vue) {
9
+ Vue.component(MListBoxOptions.name, MListBoxOptions);
10
+ };
11
+
12
+ export { MListBox, MListBoxOptions };
package/src/index.js CHANGED
@@ -37,7 +37,7 @@ export { MHero } from './components/hero';
37
37
  export { MIcon } from './components/icon';
38
38
  export { MLayer } from './components/layer';
39
39
  export { MLink } from './components/link';
40
- export { MListBox } from './components/listbox';
40
+ export { MListBox, MListBoxOptions } from './components/listbox';
41
41
  export { MLoader } from './components/loader';
42
42
  export { MModal } from './components/modal';
43
43
  export { MNotification } from './components/notification';
package/types/index.d.ts CHANGED
@@ -24,6 +24,7 @@ declare module '@mozaic-ds/vue' {
24
24
  const MLayer: VueConstructor;
25
25
  const MLink: VueConstructor;
26
26
  const MListBox: VueConstructor;
27
+ const MListBoxOptions: VueConstructor;
27
28
  const MLoader: VueConstructor;
28
29
  const MModal: VueConstructor;
29
30
  const MNotification: VueConstructor;
@@ -71,6 +72,7 @@ declare module '@mozaic-ds/vue' {
71
72
  MLayer,
72
73
  MLink,
73
74
  MListBox,
75
+ MListBoxOptions,
74
76
  MLoader,
75
77
  MModal,
76
78
  MNotification,