@enso-ui/filters 3.0.28 → 3.1.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enso-ui/filters",
3
- "version": "3.0.28",
3
+ "version": "3.1.1",
4
4
  "description": "Renderless Vue Filter Components",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -2,14 +2,10 @@
2
2
  <vue-filter :i18n="i18n"/>
3
3
  </template>
4
4
 
5
- <script>
5
+ <script setup>
6
+ import { inject } from 'vue';
6
7
  import VueFilter from './VueFilter.vue';
7
8
 
8
- export default {
9
- name: 'EnsoFilter',
9
+ const i18n = inject('i18n');
10
10
 
11
- components: { VueFilter },
12
-
13
- inject: ['i18n'],
14
- };
15
11
  </script>
@@ -16,7 +16,7 @@
16
16
  <ul>
17
17
  <li v-for="(option, index) in options"
18
18
  :key="index"
19
- :class="{ 'is-active': option.value === modelValue }">
19
+ :class="cssClass(option)">
20
20
  <a @click="update(option.value)">
21
21
  <span v-if="icons"
22
22
  :class="['icon', option.class]">
@@ -30,10 +30,10 @@
30
30
  </a>
31
31
  </li>
32
32
  <li v-if="!hideOff"
33
- :class="{ 'is-active': modelValue === null }">
33
+ :class="{ 'is-active': emptyModel }">
34
34
  <a @click="update()">
35
35
  <span class="icon"
36
- :class="modelValue === null
36
+ :class="emptyModel
37
37
  ? 'has-text-danger'
38
38
  : 'has-text-success'">
39
39
  <fa icon="power-off"/>
@@ -50,8 +50,11 @@
50
50
  </div>
51
51
  </template>
52
52
 
53
- <script>
53
+ <script setup>
54
54
  import 'v-tooltip/dist/v-tooltip.css';
55
+ import {
56
+ computed, defineProps, defineModel, defineOptions,
57
+ } from 'vue';
55
58
  import { VTooltip } from 'v-tooltip';
56
59
  import { FontAwesomeIcon as Fa } from '@fortawesome/vue-fontawesome';
57
60
  import { library } from '@fortawesome/fontawesome-svg-core';
@@ -59,63 +62,94 @@ import { faPowerOff, faLock } from '@fortawesome/free-solid-svg-icons';
59
62
 
60
63
  library.add(faPowerOff, faLock);
61
64
 
62
- export default {
63
- name: 'VueFilter',
64
-
65
- directives: { tooltip: VTooltip },
65
+ defineOptions({
66
+ directives: {
67
+ tooltip: VTooltip,
68
+ },
69
+ });
66
70
 
67
- components: { Fa },
71
+ const model = defineModel({
72
+ required: true,
73
+ type: null,
74
+ });
68
75
 
69
- props: {
70
- compact: {
71
- type: Boolean,
72
- default: false,
73
- },
74
- hideOff: {
75
- type: Boolean,
76
- default: false,
77
- },
78
- i18n: {
79
- type: Function,
80
- default: v => v,
81
- },
82
- icons: {
83
- type: Boolean,
84
- default: false,
85
- },
86
- offLabel: {
87
- type: String,
88
- default: '',
89
- },
90
- options: {
91
- type: Array,
92
- default() {
93
- return [];
94
- },
95
- },
96
- readonly: {
97
- type: Boolean,
98
- default: false,
99
- },
100
- name: {
101
- type: String,
102
- default: null,
103
- },
104
- modelValue: {
105
- type: null,
106
- default: null,
76
+ const props = defineProps({
77
+ compact: {
78
+ type: Boolean,
79
+ default: false,
80
+ },
81
+ hideOff: {
82
+ type: Boolean,
83
+ default: false,
84
+ },
85
+ i18n: {
86
+ type: Function,
87
+ default: v => v,
88
+ },
89
+ icons: {
90
+ type: Boolean,
91
+ default: false,
92
+ },
93
+ offLabel: {
94
+ type: String,
95
+ default: '',
96
+ },
97
+ options: {
98
+ type: Array,
99
+ default() {
100
+ return [];
107
101
  },
108
102
  },
103
+ readonly: {
104
+ type: Boolean,
105
+ default: false,
106
+ },
107
+ name: {
108
+ type: String,
109
+ default: null,
110
+ },
111
+ multiple: {
112
+ type: Boolean,
113
+ default: false,
114
+ },
115
+ });
109
116
 
110
- emits: ['update:modelValue'],
117
+ const cssClass = option => ({
118
+ 'is-active': props.multiple
119
+ ? model.value.includes(option.value)
120
+ : option.value === model.value,
121
+ });
111
122
 
112
- methods: {
113
- update(value = null) {
114
- if (!this.readonly) {
115
- this.$emit('update:modelValue', value);
116
- }
117
- },
118
- },
123
+ const emptyModel = computed(() => (props.multiple
124
+ ? model.value.length < 1
125
+ : model.value === null));
126
+
127
+ const update = (value = null) => {
128
+ if (props.readonly) {
129
+ return;
130
+ }
131
+
132
+ if (!props.multiple) {
133
+ model.value = value;
134
+ return;
135
+ }
136
+
137
+ if (value === null) {
138
+ model.value = [];
139
+ return;
140
+ }
141
+
142
+ const current = Array.isArray(model.value) ? [...model.value] : [];
143
+
144
+ const index = current.indexOf(value);
145
+
146
+ if (index === -1) {
147
+ current.push(value);
148
+ } else {
149
+ current.splice(index, 1);
150
+ }
151
+
152
+ model.value = current;
119
153
  };
120
154
  </script>
121
155