@pequity/squirrel 5.4.11 → 6.0.0
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/dist/cjs/chunks/p-icon.js +157 -49
- package/dist/cjs/chunks/p-link.js +1 -0
- package/dist/cjs/p-dropdown.js +37 -31
- package/dist/cjs/p-modal.js +10 -7
- package/dist/cjs/p-select-pill.js +2 -1
- package/dist/es/chunks/p-icon.js +157 -49
- package/dist/es/chunks/p-link.js +1 -0
- package/dist/es/p-dropdown.js +37 -31
- package/dist/es/p-modal.js +10 -7
- package/dist/es/p-select-pill.js +2 -1
- package/dist/squirrel/components/p-dropdown/p-dropdown.vue.d.ts +406 -24
- package/dist/{style.css → squirrel.css} +14 -14
- package/package.json +37 -37
- package/squirrel/components/p-dropdown/p-dropdown.spec.js +2 -2
- package/squirrel/components/p-dropdown/p-dropdown.vue +55 -33
- package/squirrel/components/p-modal/p-modal.vue +2 -2
- package/squirrel/components/p-select-pill/p-select-pill.spec.js +2 -0
- package/squirrel/components/p-select-pill/p-select-pill.vue +1 -0
- package/squirrel/utils/tailwind.spec.js +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
2
|
+
<Dropdown ref="vPopper" v-bind="{ ...defaultAttrs, ...$attrs }" @show="onShow" @hide="destroy">
|
|
3
3
|
<template v-for="(_, slot) in $slots" #[slot]="scope">
|
|
4
4
|
<slot :name="slot" v-bind="scope || {}" />
|
|
5
5
|
</template>
|
|
6
|
-
</
|
|
6
|
+
</Dropdown>
|
|
7
7
|
</template>
|
|
8
8
|
|
|
9
9
|
<script lang="ts">
|
|
@@ -88,7 +88,10 @@ import {
|
|
|
88
88
|
type ListKeyboardNavigationInstance,
|
|
89
89
|
setupListKeyboardNavigation,
|
|
90
90
|
} from '@squirrel/utils/listKeyboardNavigation';
|
|
91
|
-
import {
|
|
91
|
+
import { Dropdown } from 'floating-vue';
|
|
92
|
+
import { defineComponent } from 'vue';
|
|
93
|
+
|
|
94
|
+
type DropdownProps = InstanceType<typeof Dropdown>['$props'];
|
|
92
95
|
|
|
93
96
|
type VPopper = {
|
|
94
97
|
$refs: {
|
|
@@ -98,19 +101,33 @@ type VPopper = {
|
|
|
98
101
|
reference: HTMLElement;
|
|
99
102
|
popper: {
|
|
100
103
|
shown: boolean;
|
|
104
|
+
isShown: boolean;
|
|
101
105
|
hide: (options?: { skipDelay: boolean }) => void;
|
|
106
|
+
show: () => void;
|
|
102
107
|
$_detachPopperNode: () => void;
|
|
103
108
|
$_referenceNode: HTMLElement;
|
|
104
109
|
$_computePosition: () => void;
|
|
105
110
|
$el: HTMLElement;
|
|
111
|
+
$emit: (event: string, ...args: unknown[]) => void;
|
|
106
112
|
};
|
|
107
113
|
};
|
|
108
114
|
};
|
|
109
115
|
|
|
110
116
|
const ESCAPE_KEY = 'Escape';
|
|
111
117
|
|
|
118
|
+
const nextFrame = () => {
|
|
119
|
+
return new Promise((resolve) =>
|
|
120
|
+
requestAnimationFrame(() => {
|
|
121
|
+
requestAnimationFrame(resolve);
|
|
122
|
+
})
|
|
123
|
+
);
|
|
124
|
+
};
|
|
125
|
+
|
|
112
126
|
export default defineComponent({
|
|
113
127
|
name: 'PDropdown',
|
|
128
|
+
components: {
|
|
129
|
+
Dropdown,
|
|
130
|
+
},
|
|
114
131
|
inheritAttrs: false,
|
|
115
132
|
props: {
|
|
116
133
|
/**
|
|
@@ -138,49 +155,23 @@ export default defineComponent({
|
|
|
138
155
|
display: 'inline-block',
|
|
139
156
|
}),
|
|
140
157
|
},
|
|
141
|
-
/**
|
|
142
|
-
* Custom reference element that is used to position the popper.
|
|
143
|
-
* Can be changed at runtime to create a dynamically positioned dropdown.
|
|
144
|
-
*/
|
|
145
|
-
reference: {
|
|
146
|
-
type: HTMLElement as PropType<HTMLElement | null | undefined>,
|
|
147
|
-
default: null,
|
|
148
|
-
},
|
|
149
158
|
},
|
|
150
159
|
data() {
|
|
151
160
|
return {
|
|
152
161
|
defaultAttrs: {
|
|
153
162
|
triggers: ['click'],
|
|
154
|
-
|
|
163
|
+
autoHide: true,
|
|
155
164
|
theme: 'p-dropdown-theme',
|
|
156
|
-
|
|
165
|
+
popperClass: 'dropdown',
|
|
157
166
|
placement: 'bottom-start',
|
|
158
167
|
distance: 4,
|
|
159
168
|
delay: 0,
|
|
160
169
|
handleResize: true,
|
|
161
|
-
},
|
|
170
|
+
} satisfies DropdownProps,
|
|
162
171
|
navigationSvc: null as ListKeyboardNavigationInstance | null,
|
|
172
|
+
prevReference: null as HTMLElement | null,
|
|
163
173
|
};
|
|
164
174
|
},
|
|
165
|
-
watch: {
|
|
166
|
-
reference: {
|
|
167
|
-
async handler(nV, oV) {
|
|
168
|
-
if (nV && oV !== nV) {
|
|
169
|
-
const popper = (this.$refs.vPopper as VPopper).$refs.popper;
|
|
170
|
-
|
|
171
|
-
if (popper) {
|
|
172
|
-
popper.$_detachPopperNode();
|
|
173
|
-
if (popper.shown) {
|
|
174
|
-
popper.hide({ skipDelay: true });
|
|
175
|
-
}
|
|
176
|
-
if (this.reference) {
|
|
177
|
-
popper.$_referenceNode = this.reference;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
},
|
|
182
|
-
},
|
|
183
|
-
},
|
|
184
175
|
mounted() {
|
|
185
176
|
Object.assign((this.$refs.vPopper as VPopper).$refs.popper.$el.style, this.triggerStyle);
|
|
186
177
|
},
|
|
@@ -208,6 +199,37 @@ export default defineComponent({
|
|
|
208
199
|
this.navigationSvc?.destroy();
|
|
209
200
|
document.removeEventListener('keydown', this.popoverEscKeydown);
|
|
210
201
|
},
|
|
202
|
+
async updateReference(newReference: HTMLElement) {
|
|
203
|
+
if (!newReference) {
|
|
204
|
+
throw Error('Reference element is required');
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const popper = (this.$refs.vPopper as VPopper).$refs.popper;
|
|
208
|
+
|
|
209
|
+
if (popper) {
|
|
210
|
+
// Fixes popper flicker issue when changing reference
|
|
211
|
+
popper.$_detachPopperNode();
|
|
212
|
+
|
|
213
|
+
if (popper.isShown) {
|
|
214
|
+
popper.$emit('update:shown', false);
|
|
215
|
+
|
|
216
|
+
if (newReference === this.prevReference) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// Wait for the popper to hide
|
|
222
|
+
await nextFrame();
|
|
223
|
+
|
|
224
|
+
popper.$_referenceNode = newReference;
|
|
225
|
+
this.prevReference = newReference;
|
|
226
|
+
|
|
227
|
+
// Wait for the popper to update the reference
|
|
228
|
+
await nextFrame();
|
|
229
|
+
|
|
230
|
+
popper.$emit('update:shown', true);
|
|
231
|
+
}
|
|
232
|
+
},
|
|
211
233
|
},
|
|
212
234
|
});
|
|
213
235
|
</script>
|
|
@@ -59,8 +59,8 @@
|
|
|
59
59
|
<slot></slot>
|
|
60
60
|
</div>
|
|
61
61
|
</slot>
|
|
62
|
-
<slot
|
|
63
|
-
<div class="
|
|
62
|
+
<slot name="footer-wrapper">
|
|
63
|
+
<div v-if="$slots['footer']" class="px-8 pt-6">
|
|
64
64
|
<slot name="footer"></slot>
|
|
65
65
|
</div>
|
|
66
66
|
</slot>
|
|
@@ -45,6 +45,7 @@ describe('PSelectPill.vue', () => {
|
|
|
45
45
|
const selected = wrapper.findAll('button')[3];
|
|
46
46
|
|
|
47
47
|
expect(selected.classes()).toContain(ACTIVE_CLASS);
|
|
48
|
+
expect(selected.attributes('data-selected')).toBe('true');
|
|
48
49
|
});
|
|
49
50
|
|
|
50
51
|
it(`updates the value bound with v-model when an option is clicked`, async () => {
|
|
@@ -64,6 +65,7 @@ describe('PSelectPill.vue', () => {
|
|
|
64
65
|
const selected = wrapper.findAll('button')[3];
|
|
65
66
|
|
|
66
67
|
expect(selected.classes()).toContain(ACTIVE_CLASS);
|
|
68
|
+
expect(selected.attributes('data-selected')).toBe('true');
|
|
67
69
|
});
|
|
68
70
|
|
|
69
71
|
it('works with custom itemValue and itemText', async () => {
|