@pequity/squirrel 7.2.5 → 8.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-input-number.js +16 -3
- package/dist/es/chunks/p-input-number.js +16 -3
- package/dist/squirrel/components/p-input-number/p-input-number.vue.d.ts +20 -0
- package/package.json +5 -5
- package/squirrel/components/p-input-number/p-input-number.spec.js +40 -0
- package/squirrel/components/p-input-number/p-input-number.stories.js +30 -0
- package/squirrel/components/p-input-number/p-input-number.vue +19 -3
|
@@ -47,6 +47,10 @@ const _sfc_main = /* @__PURE__ */ vue.defineComponent({
|
|
|
47
47
|
tooltipText: {
|
|
48
48
|
type: String,
|
|
49
49
|
default: ""
|
|
50
|
+
},
|
|
51
|
+
prefixString: {
|
|
52
|
+
type: String,
|
|
53
|
+
default: ""
|
|
50
54
|
}
|
|
51
55
|
},
|
|
52
56
|
emits: ["update:modelValue", "change"],
|
|
@@ -64,13 +68,18 @@ const _sfc_main = /* @__PURE__ */ vue.defineComponent({
|
|
|
64
68
|
"useGrouping",
|
|
65
69
|
"valueScaling"
|
|
66
70
|
];
|
|
71
|
+
const prefixClasses = {
|
|
72
|
+
sm: "text-sm h-8 left-2",
|
|
73
|
+
md: "text-base h-10 left-3",
|
|
74
|
+
lg: "text-lg h-12 left-5"
|
|
75
|
+
};
|
|
67
76
|
const emit = __emit;
|
|
68
77
|
const props = __props;
|
|
69
78
|
const slots = vue.useSlots();
|
|
70
79
|
const { labelClasses, inputClasses, errorMsgClasses } = useInputClasses.useInputClasses(
|
|
71
80
|
vue.computed(() => ({
|
|
72
81
|
...props,
|
|
73
|
-
prefix: !!slots.prefix,
|
|
82
|
+
prefix: !!slots.prefix || !!props.prefixString,
|
|
74
83
|
suffix: !!slots.suffix
|
|
75
84
|
}))
|
|
76
85
|
);
|
|
@@ -137,8 +146,12 @@ const _sfc_main = /* @__PURE__ */ vue.defineComponent({
|
|
|
137
146
|
}, null, 8, ["text"])) : vue.createCommentVNode("", true)
|
|
138
147
|
]),
|
|
139
148
|
vue.createElementVNode("div", _hoisted_3, [
|
|
140
|
-
!!_ctx.$slots.prefix ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_4, [
|
|
141
|
-
vue.renderSlot(_ctx.$slots, "prefix")
|
|
149
|
+
!!_ctx.$slots.prefix || __props.prefixString ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_4, [
|
|
150
|
+
vue.renderSlot(_ctx.$slots, "prefix", {}, () => [
|
|
151
|
+
vue.createElementVNode("div", {
|
|
152
|
+
class: vue.normalizeClass([{ "absolute left-3 flex items-center": __props.prefixString }, __props.prefixString ? prefixClasses[__props.size] : ""])
|
|
153
|
+
}, vue.toDisplayString(__props.prefixString), 3)
|
|
154
|
+
])
|
|
142
155
|
])) : vue.createCommentVNode("", true),
|
|
143
156
|
vue.createElementVNode("input", vue.mergeProps({
|
|
144
157
|
ref_key: "inputRef",
|
|
@@ -46,6 +46,10 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
46
46
|
tooltipText: {
|
|
47
47
|
type: String,
|
|
48
48
|
default: ""
|
|
49
|
+
},
|
|
50
|
+
prefixString: {
|
|
51
|
+
type: String,
|
|
52
|
+
default: ""
|
|
49
53
|
}
|
|
50
54
|
},
|
|
51
55
|
emits: ["update:modelValue", "change"],
|
|
@@ -63,13 +67,18 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
63
67
|
"useGrouping",
|
|
64
68
|
"valueScaling"
|
|
65
69
|
];
|
|
70
|
+
const prefixClasses = {
|
|
71
|
+
sm: "text-sm h-8 left-2",
|
|
72
|
+
md: "text-base h-10 left-3",
|
|
73
|
+
lg: "text-lg h-12 left-5"
|
|
74
|
+
};
|
|
66
75
|
const emit = __emit;
|
|
67
76
|
const props = __props;
|
|
68
77
|
const slots = useSlots();
|
|
69
78
|
const { labelClasses, inputClasses, errorMsgClasses } = useInputClasses(
|
|
70
79
|
computed(() => ({
|
|
71
80
|
...props,
|
|
72
|
-
prefix: !!slots.prefix,
|
|
81
|
+
prefix: !!slots.prefix || !!props.prefixString,
|
|
73
82
|
suffix: !!slots.suffix
|
|
74
83
|
}))
|
|
75
84
|
);
|
|
@@ -136,8 +145,12 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
136
145
|
}, null, 8, ["text"])) : createCommentVNode("", true)
|
|
137
146
|
]),
|
|
138
147
|
createElementVNode("div", _hoisted_3, [
|
|
139
|
-
!!_ctx.$slots.prefix ? (openBlock(), createElementBlock("div", _hoisted_4, [
|
|
140
|
-
renderSlot(_ctx.$slots, "prefix")
|
|
148
|
+
!!_ctx.$slots.prefix || __props.prefixString ? (openBlock(), createElementBlock("div", _hoisted_4, [
|
|
149
|
+
renderSlot(_ctx.$slots, "prefix", {}, () => [
|
|
150
|
+
createElementVNode("div", {
|
|
151
|
+
class: normalizeClass([{ "absolute left-3 flex items-center": __props.prefixString }, __props.prefixString ? prefixClasses[__props.size] : ""])
|
|
152
|
+
}, toDisplayString(__props.prefixString), 3)
|
|
153
|
+
])
|
|
141
154
|
])) : createCommentVNode("", true),
|
|
142
155
|
createElementVNode("input", mergeProps({
|
|
143
156
|
ref_key: "inputRef",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type Size } from '../p-btn/p-btn.types';
|
|
2
2
|
import PInfoIcon from '../p-info-icon/p-info-icon.vue';
|
|
3
3
|
import { type PropType, type StyleValue } from 'vue';
|
|
4
|
+
declare const prefixClasses: Record<Size, string>;
|
|
4
5
|
declare const labelClasses: import("vue").ComputedRef<string>, inputClasses: import("vue").ComputedRef<string>, errorMsgClasses: import("vue").ComputedRef<string>;
|
|
5
6
|
declare const inputRef: import("vue").Ref<any, any>;
|
|
6
7
|
declare const computedAttrs: import("vue").ComputedRef<{
|
|
@@ -48,8 +49,13 @@ declare const __VLS_self: import("vue").DefineComponent<import("vue").ExtractPro
|
|
|
48
49
|
type: StringConstructor;
|
|
49
50
|
default: string;
|
|
50
51
|
};
|
|
52
|
+
prefixString: {
|
|
53
|
+
type: StringConstructor;
|
|
54
|
+
default: string;
|
|
55
|
+
};
|
|
51
56
|
}>, {
|
|
52
57
|
PInfoIcon: typeof PInfoIcon;
|
|
58
|
+
prefixClasses: typeof prefixClasses;
|
|
53
59
|
labelClasses: typeof labelClasses;
|
|
54
60
|
inputClasses: typeof inputClasses;
|
|
55
61
|
errorMsgClasses: typeof errorMsgClasses;
|
|
@@ -90,6 +96,10 @@ declare const __VLS_self: import("vue").DefineComponent<import("vue").ExtractPro
|
|
|
90
96
|
type: StringConstructor;
|
|
91
97
|
default: string;
|
|
92
98
|
};
|
|
99
|
+
prefixString: {
|
|
100
|
+
type: StringConstructor;
|
|
101
|
+
default: string;
|
|
102
|
+
};
|
|
93
103
|
}>> & Readonly<{
|
|
94
104
|
onChange?: ((...args: any[]) => any) | undefined;
|
|
95
105
|
"onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
|
|
@@ -101,6 +111,7 @@ declare const __VLS_self: import("vue").DefineComponent<import("vue").ExtractPro
|
|
|
101
111
|
errorMsg: string;
|
|
102
112
|
selectOnClick: boolean;
|
|
103
113
|
tooltipText: string;
|
|
114
|
+
prefixString: string;
|
|
104
115
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
105
116
|
declare const __VLS_component: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
106
117
|
modelValue: {
|
|
@@ -132,6 +143,10 @@ declare const __VLS_component: import("vue").DefineComponent<import("vue").Extra
|
|
|
132
143
|
type: StringConstructor;
|
|
133
144
|
default: string;
|
|
134
145
|
};
|
|
146
|
+
prefixString: {
|
|
147
|
+
type: StringConstructor;
|
|
148
|
+
default: string;
|
|
149
|
+
};
|
|
135
150
|
}>, {
|
|
136
151
|
setValue: (number: number | null) => void;
|
|
137
152
|
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
@@ -167,6 +182,10 @@ declare const __VLS_component: import("vue").DefineComponent<import("vue").Extra
|
|
|
167
182
|
type: StringConstructor;
|
|
168
183
|
default: string;
|
|
169
184
|
};
|
|
185
|
+
prefixString: {
|
|
186
|
+
type: StringConstructor;
|
|
187
|
+
default: string;
|
|
188
|
+
};
|
|
170
189
|
}>> & Readonly<{
|
|
171
190
|
onChange?: ((...args: any[]) => any) | undefined;
|
|
172
191
|
"onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
|
|
@@ -178,6 +197,7 @@ declare const __VLS_component: import("vue").DefineComponent<import("vue").Extra
|
|
|
178
197
|
errorMsg: string;
|
|
179
198
|
selectOnClick: boolean;
|
|
180
199
|
tooltipText: string;
|
|
200
|
+
prefixString: string;
|
|
181
201
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
182
202
|
declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
|
|
183
203
|
export default _default;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pequity/squirrel",
|
|
3
3
|
"description": "Squirrel component library",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "8.0.0",
|
|
5
5
|
"packageManager": "pnpm@10.6.4",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"@vue/test-utils": "^2.4.6",
|
|
76
76
|
"@vuepic/vue-datepicker": "11.0.2",
|
|
77
77
|
"autoprefixer": "^10.4.21",
|
|
78
|
-
"eslint": "^9.
|
|
78
|
+
"eslint": "^9.24.0",
|
|
79
79
|
"eslint-plugin-storybook": "^0.12.0",
|
|
80
80
|
"floating-vue": "5.2.2",
|
|
81
81
|
"glob": "^11.0.1",
|
|
@@ -90,12 +90,12 @@
|
|
|
90
90
|
"prettier-plugin-tailwindcss": "^0.6.11",
|
|
91
91
|
"resolve-tspaths": "^0.8.23",
|
|
92
92
|
"rimraf": "^6.0.1",
|
|
93
|
-
"sass": "^1.86.
|
|
93
|
+
"sass": "^1.86.3",
|
|
94
94
|
"semantic-release": "^24.2.3",
|
|
95
95
|
"storybook": "^8.6.12",
|
|
96
96
|
"svgo": "^3.3.2",
|
|
97
97
|
"tailwindcss": "^3.4.17",
|
|
98
|
-
"typescript": "5.8.
|
|
98
|
+
"typescript": "5.8.3",
|
|
99
99
|
"vite": "^6.2.5",
|
|
100
100
|
"vitest": "^3.1.1",
|
|
101
101
|
"vue": "3.5.13",
|
|
@@ -109,7 +109,7 @@
|
|
|
109
109
|
},
|
|
110
110
|
"pnpm": {
|
|
111
111
|
"overrides": {
|
|
112
|
-
"typescript": "5.8.
|
|
112
|
+
"typescript": "5.8.3"
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import PInputNumber from '@squirrel/components/p-input-number/p-input-number.vue';
|
|
2
|
+
import { expect } from '@storybook/test';
|
|
2
3
|
import { createWrapperFor } from '@tests/vitest.helpers';
|
|
3
4
|
|
|
4
5
|
const baseClasses = () => [
|
|
@@ -139,6 +140,45 @@ describe('PInputNumber.vue', () => {
|
|
|
139
140
|
expect(wrapper.find('input').classes()).toEqual(expect.arrayContaining(res));
|
|
140
141
|
});
|
|
141
142
|
|
|
143
|
+
it('renders the prefixString prop content when no slot is provided', () => {
|
|
144
|
+
const wrapper = createWrapperFor(PInputNumber, {
|
|
145
|
+
props: {
|
|
146
|
+
prefixString: '$',
|
|
147
|
+
label: 'test input',
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
const prefixDiv = wrapper.find('div > div.relative > div');
|
|
152
|
+
expect(prefixDiv.exists()).toBe(true);
|
|
153
|
+
expect(prefixDiv.text()).toBe('$');
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('works correctly when the component is stubbed', () => {
|
|
157
|
+
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
158
|
+
|
|
159
|
+
const wrapper = createWrapperFor(
|
|
160
|
+
{
|
|
161
|
+
template: `<PInputNumber v-model="numberVal" />`,
|
|
162
|
+
components: { PInputNumber },
|
|
163
|
+
data() {
|
|
164
|
+
return {
|
|
165
|
+
numberVal: null,
|
|
166
|
+
};
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
global: {
|
|
171
|
+
stubs: {
|
|
172
|
+
PInputNumber: true,
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
}
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
expect(wrapper.findComponent({ name: 'PInputNumber' }).exists()).toBe(true);
|
|
179
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
180
|
+
});
|
|
181
|
+
|
|
142
182
|
it('emits a number on input', async () => {
|
|
143
183
|
const wrapper = createWrapperFor({
|
|
144
184
|
template: `<PInputNumber v-model="numberVal" />`,
|
|
@@ -87,3 +87,33 @@ export const Currency = {
|
|
|
87
87
|
modelValue: 2000,
|
|
88
88
|
},
|
|
89
89
|
};
|
|
90
|
+
|
|
91
|
+
export const WithPrefix = {
|
|
92
|
+
render: (args) => ({
|
|
93
|
+
components: { PInputNumber },
|
|
94
|
+
setup() {
|
|
95
|
+
return { args };
|
|
96
|
+
},
|
|
97
|
+
template: `
|
|
98
|
+
<div class="space-y-4">
|
|
99
|
+
<PInputNumber v-bind="args" prefix="$" label="Using prefix prop" />
|
|
100
|
+
<PInputNumber v-bind="args" label="Using prefix slot">
|
|
101
|
+
<template #prefix>
|
|
102
|
+
<span class="text-primary font-semibold">$</span>
|
|
103
|
+
</template>
|
|
104
|
+
</PInputNumber>
|
|
105
|
+
</div>
|
|
106
|
+
`,
|
|
107
|
+
}),
|
|
108
|
+
args: {
|
|
109
|
+
modelValue: 1234,
|
|
110
|
+
},
|
|
111
|
+
parameters: {
|
|
112
|
+
docs: {
|
|
113
|
+
description: {
|
|
114
|
+
story:
|
|
115
|
+
'The prefix can be added either using the `prefix` prop for simple text, or using the prefix slot for more complex content.',
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
};
|
|
@@ -9,8 +9,14 @@
|
|
|
9
9
|
<PInfoIcon v-if="tooltipText" :text="tooltipText" class="ml-1" />
|
|
10
10
|
</div>
|
|
11
11
|
<div class="relative w-full">
|
|
12
|
-
<div v-if="!!$slots.prefix">
|
|
13
|
-
<slot name="prefix"
|
|
12
|
+
<div v-if="!!$slots.prefix || prefixString">
|
|
13
|
+
<slot name="prefix">
|
|
14
|
+
<div
|
|
15
|
+
:class="[{ 'absolute left-3 flex items-center': prefixString }, prefixString ? prefixClasses[size] : '']"
|
|
16
|
+
>
|
|
17
|
+
{{ prefixString }}
|
|
18
|
+
</div>
|
|
19
|
+
</slot>
|
|
14
20
|
</div>
|
|
15
21
|
<input ref="inputRef" type="text" v-bind="computedAttrs" :class="inputClasses" @focus="focus" />
|
|
16
22
|
</div>
|
|
@@ -41,6 +47,12 @@ const ALL_OPTIONS = [
|
|
|
41
47
|
'valueScaling',
|
|
42
48
|
];
|
|
43
49
|
|
|
50
|
+
const prefixClasses: Record<Size, string> = {
|
|
51
|
+
sm: 'text-sm h-8 left-2',
|
|
52
|
+
md: 'text-base h-10 left-3',
|
|
53
|
+
lg: 'text-lg h-12 left-5',
|
|
54
|
+
};
|
|
55
|
+
|
|
44
56
|
defineOptions({
|
|
45
57
|
name: 'PInputNumber',
|
|
46
58
|
inheritAttrs: false,
|
|
@@ -80,6 +92,10 @@ const props = defineProps({
|
|
|
80
92
|
type: String,
|
|
81
93
|
default: '',
|
|
82
94
|
},
|
|
95
|
+
prefixString: {
|
|
96
|
+
type: String,
|
|
97
|
+
default: '',
|
|
98
|
+
},
|
|
83
99
|
});
|
|
84
100
|
|
|
85
101
|
const slots = useSlots();
|
|
@@ -87,7 +103,7 @@ const slots = useSlots();
|
|
|
87
103
|
const { labelClasses, inputClasses, errorMsgClasses } = useInputClasses(
|
|
88
104
|
computed(() => ({
|
|
89
105
|
...props,
|
|
90
|
-
prefix: !!slots.prefix,
|
|
106
|
+
prefix: !!slots.prefix || !!props.prefixString,
|
|
91
107
|
suffix: !!slots.suffix,
|
|
92
108
|
}))
|
|
93
109
|
);
|