@pequity/squirrel 5.4.1 → 5.4.3

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.
Files changed (82) hide show
  1. package/dist/cjs/chunks/p-action-bar.js +10 -11
  2. package/dist/cjs/chunks/p-date-picker.js +108 -0
  3. package/dist/cjs/chunks/p-dropdown-select.js +7 -8
  4. package/dist/cjs/chunks/p-inline-date-picker.js +112 -0
  5. package/dist/cjs/chunks/p-input-percent.js +3 -5
  6. package/dist/cjs/chunks/p-pagination-info.js +1 -1
  7. package/dist/cjs/chunks/p-pagination.js +12 -16
  8. package/dist/cjs/index.js +55 -53
  9. package/dist/cjs/p-btn.js +8 -5
  10. package/dist/cjs/p-chips.js +3 -5
  11. package/dist/cjs/p-date-picker.js +2 -138
  12. package/dist/cjs/p-info-icon.js +1 -3
  13. package/dist/cjs/p-inline-date-picker.js +2 -143
  14. package/dist/cjs/p-table-td.js +3 -5
  15. package/dist/es/chunks/p-action-bar.js +10 -11
  16. package/dist/es/chunks/p-date-picker.js +109 -0
  17. package/dist/es/chunks/p-dropdown-select.js +7 -8
  18. package/dist/es/chunks/p-inline-date-picker.js +113 -0
  19. package/dist/es/chunks/p-input-percent.js +3 -5
  20. package/dist/es/chunks/p-pagination-info.js +1 -1
  21. package/dist/es/chunks/p-pagination.js +12 -16
  22. package/dist/es/index.js +104 -102
  23. package/dist/es/p-btn.js +8 -5
  24. package/dist/es/p-chips.js +4 -6
  25. package/dist/es/p-date-picker.js +2 -138
  26. package/dist/es/p-info-icon.js +2 -4
  27. package/dist/es/p-inline-date-picker.js +2 -143
  28. package/dist/es/p-table-td.js +4 -6
  29. package/dist/squirrel/components/p-action-bar/p-action-bar.vue.d.ts +5 -14
  30. package/dist/squirrel/components/p-alert/p-alert.vue.d.ts +4 -4
  31. package/dist/squirrel/components/p-avatar/p-avatar.vue.d.ts +5 -5
  32. package/dist/squirrel/components/p-btn/p-btn.vue.d.ts +40 -5
  33. package/dist/squirrel/components/p-card/p-card.vue.d.ts +4 -4
  34. package/dist/squirrel/components/p-checkbox/p-checkbox.vue.d.ts +5 -5
  35. package/dist/squirrel/components/p-chips/p-chips.vue.d.ts +5 -5
  36. package/dist/squirrel/components/p-close-btn/p-close-btn.vue.d.ts +4 -4
  37. package/dist/squirrel/components/p-date-picker/p-date-picker.vue.d.ts +35 -128
  38. package/dist/squirrel/components/p-drawer/p-drawer.vue.d.ts +37 -5
  39. package/dist/squirrel/components/p-dropdown/p-dropdown.vue.d.ts +5 -5
  40. package/dist/squirrel/components/p-dropdown-select/p-dropdown-select.vue.d.ts +128 -29
  41. package/dist/squirrel/components/p-file-upload/p-file-upload.vue.d.ts +5 -5
  42. package/dist/squirrel/components/p-icon/p-icon.vue.d.ts +1 -10
  43. package/dist/squirrel/components/p-info-icon/p-info-icon.vue.d.ts +2 -23
  44. package/dist/squirrel/components/p-input/p-input.vue.d.ts +9 -9
  45. package/dist/squirrel/components/p-input-number/p-input-number.vue.d.ts +40 -10
  46. package/dist/squirrel/components/p-input-percent/p-input-percent.vue.d.ts +5 -5
  47. package/dist/squirrel/components/p-input-search/p-input-search.vue.d.ts +121 -5
  48. package/dist/squirrel/components/p-link/p-link.vue.d.ts +1 -10
  49. package/dist/squirrel/components/p-loading/p-loading.vue.d.ts +1 -1
  50. package/dist/squirrel/components/p-modal/p-modal.vue.d.ts +5 -5
  51. package/dist/squirrel/components/p-pagination/p-pagination.vue.d.ts +5 -5
  52. package/dist/squirrel/components/p-pagination-info/p-pagination-info.vue.d.ts +4 -4
  53. package/dist/squirrel/components/p-progress-bar/p-progress-bar.vue.d.ts +3 -3
  54. package/dist/squirrel/components/p-ring-loader/p-ring-loader.vue.d.ts +4 -4
  55. package/dist/squirrel/components/p-select/p-select.vue.d.ts +5 -5
  56. package/dist/squirrel/components/p-select-btn/p-select-btn.vue.d.ts +4 -45
  57. package/dist/squirrel/components/p-select-list/p-select-list.vue.d.ts +143 -29
  58. package/dist/squirrel/components/p-select-list/useSelectList.d.ts +4 -4
  59. package/dist/squirrel/components/p-select-pill/p-select-pill.vue.d.ts +5 -5
  60. package/dist/squirrel/components/p-skeleton-loader/p-skeleton-loader.vue.d.ts +4 -4
  61. package/dist/squirrel/components/p-table/p-table.vue.d.ts +10 -47
  62. package/dist/squirrel/components/p-table/usePTableColResize.d.ts +4 -4
  63. package/dist/squirrel/components/p-table/usePTableRowVirtualizer.d.ts +10 -4
  64. package/dist/squirrel/components/p-table-header-cell/p-table-filter-icon.vue.d.ts +4 -4
  65. package/dist/squirrel/components/p-table-header-cell/p-table-header-cell.vue.d.ts +48 -5
  66. package/dist/squirrel/components/p-table-loader/p-table-loader.vue.d.ts +4 -4
  67. package/dist/squirrel/components/p-table-sort/p-table-sort.vue.d.ts +5 -5
  68. package/dist/squirrel/components/p-table-td/p-table-td.vue.d.ts +2 -25
  69. package/dist/squirrel/components/p-tabs/p-tabs.vue.d.ts +5 -5
  70. package/dist/squirrel/components/p-textarea/p-textarea.vue.d.ts +9 -9
  71. package/dist/squirrel/components/p-toggle/p-toggle.vue.d.ts +9 -9
  72. package/dist/squirrel/composables/useInputClasses.d.ts +1 -1
  73. package/dist/squirrel/utils/inputClassesMixin.d.ts +4 -4
  74. package/package.json +25 -25
  75. package/squirrel/components/p-btn/p-btn.spec.js +33 -4
  76. package/squirrel/components/p-btn/p-btn.vue +5 -2
  77. package/squirrel/components/p-date-picker/p-date-picker.vue +79 -86
  78. package/squirrel/components/p-inline-date-picker/p-inline-date-picker.spec.js +12 -14
  79. package/squirrel/components/p-inline-date-picker/p-inline-date-picker.vue +87 -99
  80. package/squirrel/components/p-select-list/p-select-list.spec.js +26 -0
  81. package/squirrel/components/p-select-list/p-select-list.vue +8 -1
  82. package/dist/squirrel/components/p-inline-date-picker/p-inline-date-picker.vue.d.ts +0 -154
@@ -6,7 +6,7 @@
6
6
  </label>
7
7
  </slot>
8
8
  <DatePicker
9
- ref="datepicker"
9
+ ref="datepickerRef"
10
10
  :class="{ 'pointer-events-none opacity-70': $attrs.disabled }"
11
11
  :model-value="innerValue"
12
12
  :select-attribute="selectAttribute"
@@ -22,12 +22,17 @@
22
22
  </div>
23
23
  </template>
24
24
 
25
- <script lang="ts">
25
+ <script setup lang="ts">
26
26
  import dayjs from 'dayjs';
27
- import inputClassesMixin from '@squirrel/utils/inputClassesMixin';
28
27
  import { type AttributeConfig } from 'v-calendar/dist/types/src/utils/attribute.d';
29
28
  import { DatePicker } from 'v-calendar';
30
- import { type PropType, type StyleValue, defineComponent } from 'vue';
29
+ import { type StyleValue, computed, ref, useAttrs, watch } from 'vue';
30
+ import { useInputClasses } from '@squirrel/composables/useInputClasses';
31
+
32
+ defineOptions({
33
+ name: 'PInlineDatePicker',
34
+ inheritAttrs: false,
35
+ });
31
36
 
32
37
  const selectAttribute: AttributeConfig = {
33
38
  highlight: { class: 'bg-primary', contentClass: 'text-white' },
@@ -40,100 +45,83 @@ const DEFAULT_MASKS = {
40
45
  data: 'YYYY-MM-DD',
41
46
  };
42
47
 
43
- export default defineComponent({
44
- name: 'PInlineDatePicker',
45
- components: {
46
- DatePicker,
47
- },
48
- mixins: [inputClassesMixin],
49
- inheritAttrs: false,
50
- props: {
51
- modelValue: {
52
- type: String as PropType<string | null | undefined>,
53
- default: '',
54
- },
55
- label: {
56
- type: String,
57
- default: '',
58
- },
59
- errorMsg: {
60
- type: String,
61
- default: '',
62
- },
63
- required: {
64
- type: Boolean,
65
- default: false,
66
- },
67
- minDate: {
68
- type: Date,
69
- default: null,
70
- },
71
- maxDate: {
72
- type: Date,
73
- default: null,
74
- },
75
- timezone: {
76
- type: String,
77
- default: '',
78
- },
79
- },
80
- emits: ['update:modelValue'],
81
- data() {
82
- return {
83
- // innerValue is a Date object
84
- innerValue: null as Date | null,
85
- selectAttribute,
86
- };
87
- },
88
- computed: {
89
- masks() {
90
- return Object.assign(DEFAULT_MASKS, this.$attrs.masks);
91
- },
92
- attrs() {
93
- const { class: classes, style, ...rest } = this.$attrs;
94
-
95
- return rest;
96
- },
97
- listeners() {
98
- return Object.keys(this.$attrs).reduce((acc, curr) => {
99
- if (curr.startsWith('on')) {
100
- return { ...acc, [curr]: this.$attrs[curr] };
101
- } else {
102
- return acc;
103
- }
104
- }, {});
105
- },
106
- style() {
107
- return this.$attrs.style as StyleValue;
108
- },
109
- styleDatepicker() {
110
- return this.errorMsg ? { border: '1px solid var(--color-on-error)' } : {};
111
- },
112
- },
113
- watch: {
114
- modelValue: {
115
- async handler(nV) {
116
- const date = dayjs(nV, this.masks.data).toDate();
117
-
118
- if (nV && date.toString() === 'Invalid Date') {
119
- this.$emit('update:modelValue', null);
120
- return;
121
- }
122
-
123
- this.innerValue = nV ? dayjs(nV, this.masks.data).toDate() : null;
124
- const datepicker = this.$refs.datepicker as { move: (val: unknown) => void };
125
-
126
- if (datepicker && typeof datepicker.move === 'function' && this.innerValue) {
127
- await datepicker.move(this.innerValue);
128
- }
129
- },
130
- immediate: true,
131
- },
132
- },
133
- methods: {
134
- dayclick(e: { id: string }) {
135
- this.$emit('update:modelValue', e.id);
136
- },
137
- },
48
+ type Props = {
49
+ modelValue?: string | null;
50
+ label?: string;
51
+ errorMsg?: string;
52
+ required?: boolean;
53
+ minDate?: Date | null;
54
+ maxDate?: Date | null;
55
+ timezone?: string;
56
+ };
57
+
58
+ const props = withDefaults(defineProps<Props>(), {
59
+ modelValue: '',
60
+ label: '',
61
+ errorMsg: '',
62
+ required: false,
63
+ minDate: null,
64
+ maxDate: null,
65
+ timezone: '',
138
66
  });
67
+
68
+ const emit = defineEmits<{
69
+ 'update:modelValue': [value: string | null];
70
+ }>();
71
+
72
+ // Data
73
+ const { labelClasses, errorMsgClasses } = useInputClasses(props);
74
+ const attrs = useAttrs();
75
+ // innerValue is a Date object
76
+ const innerValue = ref<Date | null>(null);
77
+ const datepickerRef = ref<InstanceType<typeof DatePicker> | null>(null);
78
+
79
+ // Computed
80
+ const masks = computed(() => {
81
+ return Object.assign(DEFAULT_MASKS, attrs.masks);
82
+ });
83
+
84
+ const listeners = computed(() => {
85
+ return Object.keys(attrs).reduce((acc, curr) => {
86
+ if (curr.startsWith('on')) {
87
+ return { ...acc, [curr]: attrs[curr] };
88
+ } else {
89
+ return acc;
90
+ }
91
+ }, {});
92
+ });
93
+
94
+ const style = computed(() => {
95
+ return attrs.style as StyleValue;
96
+ });
97
+
98
+ const styleDatepicker = computed(() => {
99
+ return props.errorMsg ? { border: '1px solid #f0453c' } : {};
100
+ });
101
+
102
+ // Methods
103
+ const dayclick = (e: { id: string }) => {
104
+ emit('update:modelValue', e.id);
105
+ };
106
+
107
+ // Watch
108
+ watch(
109
+ () => props.modelValue,
110
+ async (nV) => {
111
+ const date = dayjs(nV, masks.value.data).toDate();
112
+
113
+ if (nV && date.toString() === 'Invalid Date') {
114
+ emit('update:modelValue', null);
115
+ return;
116
+ }
117
+
118
+ innerValue.value = nV ? dayjs(nV, masks.value.data).toDate() : null;
119
+ const datepicker = datepickerRef.value as { move: (val: unknown) => void };
120
+
121
+ if (datepicker && typeof datepicker.move === 'function' && innerValue.value) {
122
+ await datepicker.move(innerValue.value);
123
+ }
124
+ },
125
+ { immediate: true }
126
+ );
139
127
  </script>
@@ -89,6 +89,32 @@ describe('PSelectList.vue', () => {
89
89
  cleanup(wrapper);
90
90
  });
91
91
 
92
+ it('focuses on the search input on mount', async () => {
93
+ useVirtualizer.mockImplementation(() => createMockedVirtualizer(20));
94
+
95
+ const wrapper = createWrapper({ selected: 17 }, { searchable: true, focusSearchOnMount: true });
96
+
97
+ const inputSearch = wrapper.findComponent({ name: 'PInputSearch' });
98
+
99
+ expect(inputSearch.exists()).toBe(true);
100
+ expect(inputSearch.element.querySelector('input')).toBe(document.activeElement);
101
+
102
+ cleanup(wrapper);
103
+ });
104
+
105
+ it('does not focus on the search input on mount', async () => {
106
+ useVirtualizer.mockImplementation(() => createMockedVirtualizer(20));
107
+
108
+ const wrapper = createWrapper({ selected: 17 }, { searchable: true, focusSearchOnMount: false });
109
+
110
+ const inputSearch = wrapper.findComponent({ name: 'PInputSearch' });
111
+
112
+ expect(inputSearch.exists()).toBe(true);
113
+ expect(inputSearch.element.querySelector('input')).not.toBe(document.activeElement);
114
+
115
+ cleanup(wrapper);
116
+ });
117
+
92
118
  it('emits the selected value when clicked (v-model)', async () => {
93
119
  useVirtualizer.mockImplementation(() => createMockedVirtualizer(20));
94
120
 
@@ -251,6 +251,13 @@ const props = defineProps({
251
251
  type: Boolean,
252
252
  default: true,
253
253
  },
254
+ /**
255
+ * Focus the search input on mount
256
+ */
257
+ focusSearchOnMount: {
258
+ type: Boolean,
259
+ default: true,
260
+ },
254
261
  });
255
262
 
256
263
  // Data
@@ -298,7 +305,7 @@ onMounted(async () => {
298
305
  putSelectedItemsOnTop();
299
306
 
300
307
  if (props.searchable) {
301
- inputSearch.value?.$el.querySelector('input').focus();
308
+ props.focusSearchOnMount && inputSearch.value?.$el.querySelector('input').focus();
302
309
  } else {
303
310
  setupNavigationSvc();
304
311
  }
@@ -1,154 +0,0 @@
1
- import { type PropType, type StyleValue } from 'vue';
2
- declare const _default: import("vue").DefineComponent<{
3
- modelValue: {
4
- type: PropType<string | null | undefined>;
5
- default: string;
6
- };
7
- label: {
8
- type: StringConstructor;
9
- default: string;
10
- };
11
- errorMsg: {
12
- type: StringConstructor;
13
- default: string;
14
- };
15
- required: {
16
- type: BooleanConstructor;
17
- default: boolean;
18
- };
19
- minDate: {
20
- type: DateConstructor;
21
- default: null;
22
- };
23
- maxDate: {
24
- type: DateConstructor;
25
- default: null;
26
- };
27
- timezone: {
28
- type: StringConstructor;
29
- default: string;
30
- };
31
- }, unknown, {
32
- innerValue: Date | null;
33
- selectAttribute: Partial<{
34
- key: string | number;
35
- hashcode: string;
36
- content: import("v-calendar/dist/types/src/utils/glyph.js").ContentConfig;
37
- highlight: import("v-calendar/dist/types/src/utils/glyph.js").HighlightConfig;
38
- dot: import("v-calendar/dist/types/src/utils/glyph.js").DotConfig;
39
- bar: import("v-calendar/dist/types/src/utils/glyph.js").BarConfig;
40
- popover: import("v-calendar/dist/types/src/utils/attribute.js").PopoverConfig;
41
- event: import("v-calendar/dist/types/src/utils/attribute.js").EventConfig;
42
- dates: import("v-calendar/dist/types/src/utils/date/range.js").DateRangeSource[];
43
- customData: any;
44
- order: number;
45
- pinPage: boolean;
46
- }>;
47
- }, {
48
- masks(): {
49
- input: string;
50
- data: string;
51
- };
52
- attrs(): {
53
- [x: string]: unknown;
54
- };
55
- listeners(): {};
56
- style(): StyleValue;
57
- styleDatepicker(): {
58
- border: string;
59
- } | {
60
- border?: undefined;
61
- };
62
- }, {
63
- dayclick(e: {
64
- id: string;
65
- }): void;
66
- }, import("vue").DefineComponent<{
67
- size: {
68
- type: PropType<import("../../index.js").InputSize>;
69
- default: string;
70
- validator(value: import("../../index.js").InputSize): boolean;
71
- };
72
- errorMsg: {
73
- type: StringConstructor;
74
- default: string;
75
- };
76
- required: {
77
- type: BooleanConstructor;
78
- default: boolean;
79
- };
80
- rounded: {
81
- type: BooleanConstructor;
82
- default: boolean;
83
- };
84
- }, unknown, {
85
- errorMsgClasses: string;
86
- }, {
87
- inputClasses(): string;
88
- labelClasses(): string;
89
- selectClasses(): string;
90
- textareaClasses(): string;
91
- }, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
92
- size: {
93
- type: PropType<import("../../index.js").InputSize>;
94
- default: string;
95
- validator(value: import("../../index.js").InputSize): boolean;
96
- };
97
- errorMsg: {
98
- type: StringConstructor;
99
- default: string;
100
- };
101
- required: {
102
- type: BooleanConstructor;
103
- default: boolean;
104
- };
105
- rounded: {
106
- type: BooleanConstructor;
107
- default: boolean;
108
- };
109
- }>>, {
110
- size: "sm" | "lg" | "md";
111
- rounded: boolean;
112
- required: boolean;
113
- errorMsg: string;
114
- }, {}>, import("vue").ComponentOptionsMixin, "update:modelValue"[], "update:modelValue", import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
115
- modelValue: {
116
- type: PropType<string | null | undefined>;
117
- default: string;
118
- };
119
- label: {
120
- type: StringConstructor;
121
- default: string;
122
- };
123
- errorMsg: {
124
- type: StringConstructor;
125
- default: string;
126
- };
127
- required: {
128
- type: BooleanConstructor;
129
- default: boolean;
130
- };
131
- minDate: {
132
- type: DateConstructor;
133
- default: null;
134
- };
135
- maxDate: {
136
- type: DateConstructor;
137
- default: null;
138
- };
139
- timezone: {
140
- type: StringConstructor;
141
- default: string;
142
- };
143
- }>> & {
144
- "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
145
- }, {
146
- label: string;
147
- required: boolean;
148
- modelValue: string | null | undefined;
149
- errorMsg: string;
150
- timezone: string;
151
- minDate: Date;
152
- maxDate: Date;
153
- }, {}>;
154
- export default _default;