@pequity/squirrel 6.1.1 → 7.0.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.
Files changed (96) hide show
  1. package/dist/cjs/chunks/index.js +748 -504
  2. package/dist/cjs/chunks/p-alert.js +52 -0
  3. package/dist/cjs/chunks/p-avatar.js +65 -0
  4. package/dist/cjs/chunks/p-btn.js +2 -2
  5. package/dist/cjs/chunks/p-date-picker.js +2 -2
  6. package/dist/cjs/chunks/p-input-number.js +161 -0
  7. package/dist/cjs/chunks/p-input-percent.js +2 -2
  8. package/dist/cjs/chunks/p-input.js +111 -0
  9. package/dist/cjs/chunks/p-progress-bar.js +38 -0
  10. package/dist/cjs/chunks/p-textarea.js +89 -0
  11. package/dist/cjs/index.js +69 -76
  12. package/dist/cjs/inputClasses.js +8 -2
  13. package/dist/cjs/p-alert.js +2 -64
  14. package/dist/cjs/p-avatar.js +2 -70
  15. package/dist/cjs/p-drawer.js +2 -2
  16. package/dist/cjs/p-input-number.js +2 -145
  17. package/dist/cjs/p-input-search.js +2 -2
  18. package/dist/cjs/p-input.js +2 -92
  19. package/dist/cjs/p-modal.js +2 -2
  20. package/dist/cjs/p-progress-bar.js +2 -40
  21. package/dist/cjs/p-table-filter-icon.js +14 -9
  22. package/dist/cjs/p-textarea.js +2 -72
  23. package/dist/cjs/p-toggle.js +76 -64
  24. package/dist/cjs/useInputClasses.js +13 -18
  25. package/dist/es/chunks/index.js +748 -504
  26. package/dist/es/chunks/p-alert.js +53 -0
  27. package/dist/es/chunks/p-avatar.js +66 -0
  28. package/dist/es/chunks/p-btn.js +2 -2
  29. package/dist/es/chunks/p-date-picker.js +2 -2
  30. package/dist/es/chunks/p-input-number.js +162 -0
  31. package/dist/es/chunks/p-input-percent.js +2 -2
  32. package/dist/es/chunks/p-input.js +112 -0
  33. package/dist/es/chunks/p-progress-bar.js +39 -0
  34. package/dist/es/chunks/p-textarea.js +90 -0
  35. package/dist/es/index.js +119 -126
  36. package/dist/es/inputClasses.js +8 -2
  37. package/dist/es/p-alert.js +2 -64
  38. package/dist/es/p-avatar.js +2 -70
  39. package/dist/es/p-drawer.js +2 -2
  40. package/dist/es/p-input-number.js +2 -145
  41. package/dist/es/p-input-search.js +2 -2
  42. package/dist/es/p-input.js +2 -92
  43. package/dist/es/p-modal.js +2 -2
  44. package/dist/es/p-progress-bar.js +2 -40
  45. package/dist/es/p-table-filter-icon.js +14 -9
  46. package/dist/es/p-textarea.js +2 -72
  47. package/dist/es/p-toggle.js +77 -65
  48. package/dist/es/useInputClasses.js +14 -19
  49. package/dist/squirrel/components/p-alert/p-alert.vue.d.ts +27 -10
  50. package/dist/squirrel/components/p-avatar/p-avatar.vue.d.ts +9 -10
  51. package/dist/squirrel/components/p-btn/p-btn.vue.d.ts +8 -248
  52. package/dist/squirrel/components/p-date-picker/p-date-picker.vue.d.ts +2 -2
  53. package/dist/squirrel/components/p-drawer/p-drawer.vue.d.ts +37 -13
  54. package/dist/squirrel/components/p-inline-date-picker/p-inline-date-picker.vue.d.ts +2 -2
  55. package/dist/squirrel/components/p-input/p-input.vue.d.ts +30 -61
  56. package/dist/squirrel/components/p-input-number/p-input-number.vue.d.ts +101 -65
  57. package/dist/squirrel/components/p-input-search/p-input-search.vue.d.ts +113 -83
  58. package/dist/squirrel/components/p-modal/p-modal.vue.d.ts +2 -2
  59. package/dist/squirrel/components/p-progress-bar/p-progress-bar.vue.d.ts +5 -20
  60. package/dist/squirrel/components/p-table-header-cell/p-table-header-cell.vue.d.ts +1 -1
  61. package/dist/squirrel/components/p-table-loader/p-table-loader.vue.d.ts +1 -1
  62. package/dist/squirrel/components/p-table-sort/p-table-sort.vue.d.ts +3 -7
  63. package/dist/squirrel/components/p-textarea/p-textarea.vue.d.ts +79 -42
  64. package/dist/squirrel/components/p-toggle/p-toggle.vue.d.ts +25 -62
  65. package/dist/squirrel/composables/useInputClasses.d.ts +2 -1
  66. package/dist/squirrel/utils/index.d.ts +1 -3
  67. package/dist/squirrel/utils/inputClasses.d.ts +9 -525
  68. package/dist/squirrel.css +5 -5
  69. package/package.json +28 -28
  70. package/squirrel/components/p-alert/p-alert.spec.js +9 -8
  71. package/squirrel/components/p-alert/p-alert.vue +19 -31
  72. package/squirrel/components/p-avatar/p-avatar.spec.ts +10 -3
  73. package/squirrel/components/p-avatar/p-avatar.vue +40 -42
  74. package/squirrel/components/p-btn/p-btn.spec.js +2 -3
  75. package/squirrel/components/p-btn/p-btn.vue +2 -2
  76. package/squirrel/components/p-input/p-input.vue +63 -40
  77. package/squirrel/components/p-input-number/p-input-number.vue +101 -86
  78. package/squirrel/components/p-progress-bar/p-progress-bar.vue +9 -14
  79. package/squirrel/components/p-table-header-cell/p-table-filter-icon.vue +8 -9
  80. package/squirrel/components/p-table-sort/p-table-sort.vue +13 -16
  81. package/squirrel/components/p-textarea/p-textarea.vue +55 -37
  82. package/squirrel/components/p-toggle/p-toggle.vue +59 -43
  83. package/squirrel/composables/useInputClasses.spec.js +50 -13
  84. package/squirrel/composables/useInputClasses.ts +18 -24
  85. package/squirrel/utils/index.ts +0 -7
  86. package/squirrel/utils/inputClasses.ts +8 -2
  87. package/dist/cjs/inputClassesMixin.js +0 -58
  88. package/dist/cjs/tailwind.js +0 -25
  89. package/dist/es/inputClassesMixin.js +0 -59
  90. package/dist/es/tailwind.js +0 -25
  91. package/dist/squirrel/utils/inputClassesMixin.d.ts +0 -56
  92. package/dist/squirrel/utils/tailwind.d.ts +0 -8
  93. package/squirrel/utils/inputClassesMixin.spec.js +0 -241
  94. package/squirrel/utils/inputClassesMixin.ts +0 -60
  95. package/squirrel/utils/tailwind.spec.js +0 -27
  96. package/squirrel/utils/tailwind.ts +0 -28
@@ -4,16 +4,7 @@ import {
4
4
  selectClasses as tvSelectClasses,
5
5
  textareaClasses as tvTextareaClasses,
6
6
  } from '@squirrel/utils/inputClasses';
7
- import { computed, ref, toRefs } from 'vue';
8
-
9
- const defaults = {
10
- size: ref<Size>('md'),
11
- errorMsg: ref(''),
12
- required: ref(false),
13
- prefix: ref(false),
14
- suffix: ref(false),
15
- rounded: ref(false),
16
- };
7
+ import { computed, type MaybeRefOrGetter, toValue } from 'vue';
17
8
 
18
9
  type Props = {
19
10
  size: Size;
@@ -24,21 +15,24 @@ type Props = {
24
15
  rounded: boolean;
25
16
  };
26
17
 
27
- type Defaults = typeof defaults;
18
+ const defaults: Props = {
19
+ size: 'md',
20
+ errorMsg: '',
21
+ required: false,
22
+ prefix: false,
23
+ suffix: false,
24
+ rounded: false,
25
+ } as const;
28
26
 
29
- export function useInputClasses(props: Partial<Props>) {
30
- const opts = { ...defaults, ...toRefs(props) } as Defaults;
31
- const { size, errorMsg, required, rounded, prefix, suffix } = opts;
27
+ export function useInputClasses(props: MaybeRefOrGetter<Partial<Props>>) {
28
+ const opts = computed(() => {
29
+ const propsValue = toValue(props);
30
+
31
+ return { ...defaults, ...propsValue, error: !!propsValue.errorMsg };
32
+ });
32
33
 
33
34
  const allClasses = computed(() => {
34
- const { input, label, errorMessage } = tvInputClasses({
35
- size: size.value,
36
- prefix: prefix.value,
37
- suffix: suffix.value,
38
- required: required.value,
39
- error: !!errorMsg.value,
40
- rounded: rounded.value,
41
- });
35
+ const { input, label, errorMessage } = tvInputClasses(opts.value);
42
36
 
43
37
  return { input: input(), label: label(), errorMessage: errorMessage() };
44
38
  });
@@ -50,13 +44,13 @@ export function useInputClasses(props: Partial<Props>) {
50
44
  const errorMsgClasses = computed(() => allClasses.value.errorMessage);
51
45
 
52
46
  const selectClasses = computed(() => {
53
- const { input } = tvSelectClasses({ size: size.value, required: required.value, error: !!errorMsg.value });
47
+ const { input } = tvSelectClasses(opts.value);
54
48
 
55
49
  return input();
56
50
  });
57
51
 
58
52
  const textareaClasses = computed(() => {
59
- const { input } = tvTextareaClasses({ required: required.value, error: !!errorMsg.value });
53
+ const { input } = tvTextareaClasses(opts.value);
60
54
 
61
55
  return input();
62
56
  });
@@ -1,25 +1,18 @@
1
1
  import { type Size, SIZES } from '@squirrel/components/p-btn/p-btn.types';
2
2
  import { CURRENCY_INPUT_DEFAULTS } from '@squirrel/utils/currency';
3
3
  import { getNextActiveElement, isElement, isVisible } from '@squirrel/utils/dom';
4
- import inputClassesMixin from '@squirrel/utils/inputClassesMixin';
5
4
  import { setupListKeyboardNavigation } from '@squirrel/utils/listKeyboardNavigation';
6
5
  import { toNumberOrNull } from '@squirrel/utils/number';
7
6
  import { isObject } from '@squirrel/utils/object';
8
7
  import { createPagingRange } from '@squirrel/utils/pagination';
9
8
  import { sanitizeUrl } from '@squirrel/utils/sanitization';
10
9
  import { toString } from '@squirrel/utils/string';
11
- import { type Color, getColor, getColorDeep, getScreen } from '@squirrel/utils/tailwind';
12
10
  import { splitStringForHighlight } from '@squirrel/utils/text';
13
11
 
14
12
  export {
15
- Color,
16
13
  createPagingRange,
17
14
  CURRENCY_INPUT_DEFAULTS,
18
- getColor,
19
- getColorDeep,
20
15
  getNextActiveElement,
21
- getScreen,
22
- inputClassesMixin,
23
16
  isElement,
24
17
  isObject,
25
18
  isVisible,
@@ -96,12 +96,18 @@ const inputClasses = tv({
96
96
  const textareaClasses = tv({
97
97
  extend: inputClasses,
98
98
  slots: {
99
- input: 'resize-y overflow-auto px-3 py-3',
99
+ input: 'resize-y overflow-auto',
100
100
  },
101
101
  variants: {
102
102
  size: {
103
+ sm: {
104
+ input: 'h-auto py-2',
105
+ },
103
106
  md: {
104
- input: 'h-auto',
107
+ input: 'h-auto py-3',
108
+ },
109
+ lg: {
110
+ input: 'h-auto py-4',
105
111
  },
106
112
  },
107
113
  },
@@ -1,58 +0,0 @@
1
- "use strict";
2
- const pBtn_types = require("./chunks/p-btn.types.js");
3
- const inputClasses = require("./inputClasses.js");
4
- const vue = require("vue");
5
- const inputClassesMixin = vue.defineComponent({
6
- props: {
7
- size: {
8
- type: String,
9
- default: "md",
10
- validator(value) {
11
- return pBtn_types.SIZES.includes(value);
12
- }
13
- },
14
- errorMsg: {
15
- type: String,
16
- default: ""
17
- },
18
- required: {
19
- type: Boolean,
20
- default: false
21
- },
22
- rounded: {
23
- type: Boolean,
24
- default: false
25
- }
26
- },
27
- computed: {
28
- allClasses() {
29
- const { input, label, errorMessage } = inputClasses.inputClasses({
30
- size: this.size,
31
- prefix: !!this.$slots.prefix,
32
- suffix: !!this.$slots.suffix,
33
- required: this.required,
34
- error: !!this.errorMsg,
35
- rounded: this.rounded
36
- });
37
- return { input: input(), label: label(), errorMessage: errorMessage() };
38
- },
39
- inputClasses() {
40
- return this.allClasses.input;
41
- },
42
- labelClasses() {
43
- return this.allClasses.label;
44
- },
45
- errorMsgClasses() {
46
- return this.allClasses.errorMessage;
47
- },
48
- selectClasses() {
49
- const { input } = inputClasses.selectClasses({ size: this.size, required: this.required, error: !!this.errorMsg });
50
- return input();
51
- },
52
- textareaClasses() {
53
- const { input } = inputClasses.textareaClasses({ required: this.required, error: !!this.errorMsg });
54
- return input();
55
- }
56
- }
57
- });
58
- module.exports = inputClassesMixin;
@@ -1,25 +0,0 @@
1
- "use strict";
2
- var _a;
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
4
- const config$1 = require("./config.js");
5
- const lodashEs = require("lodash-es");
6
- const resolveConfig = require("tailwindcss/resolveConfig");
7
- const config = resolveConfig(config$1.squirrelTailwindConfig);
8
- const theme = config.theme;
9
- const colors = theme == null ? void 0 : theme.colors;
10
- (_a = theme == null ? void 0 : theme.extend) == null ? void 0 : _a.colors;
11
- const screens = theme == null ? void 0 : theme.screens;
12
- const getColor = (name) => {
13
- return colors == null ? void 0 : colors[name];
14
- };
15
- const getColorDeep = (color) => {
16
- const baseColor = color.split("-").slice(0, -1).join("-");
17
- const colorNumber = String(color.split("-").pop());
18
- return lodashEs.get(getColor(baseColor), colorNumber);
19
- };
20
- const getScreen = (size) => {
21
- return screens == null ? void 0 : screens[size];
22
- };
23
- exports.getColor = getColor;
24
- exports.getColorDeep = getColorDeep;
25
- exports.getScreen = getScreen;
@@ -1,59 +0,0 @@
1
- import { S as SIZES } from "./chunks/p-btn.types.js";
2
- import { textareaClasses, selectClasses, inputClasses } from "./inputClasses.js";
3
- import { defineComponent } from "vue";
4
- const inputClassesMixin = defineComponent({
5
- props: {
6
- size: {
7
- type: String,
8
- default: "md",
9
- validator(value) {
10
- return SIZES.includes(value);
11
- }
12
- },
13
- errorMsg: {
14
- type: String,
15
- default: ""
16
- },
17
- required: {
18
- type: Boolean,
19
- default: false
20
- },
21
- rounded: {
22
- type: Boolean,
23
- default: false
24
- }
25
- },
26
- computed: {
27
- allClasses() {
28
- const { input, label, errorMessage } = inputClasses({
29
- size: this.size,
30
- prefix: !!this.$slots.prefix,
31
- suffix: !!this.$slots.suffix,
32
- required: this.required,
33
- error: !!this.errorMsg,
34
- rounded: this.rounded
35
- });
36
- return { input: input(), label: label(), errorMessage: errorMessage() };
37
- },
38
- inputClasses() {
39
- return this.allClasses.input;
40
- },
41
- labelClasses() {
42
- return this.allClasses.label;
43
- },
44
- errorMsgClasses() {
45
- return this.allClasses.errorMessage;
46
- },
47
- selectClasses() {
48
- const { input } = selectClasses({ size: this.size, required: this.required, error: !!this.errorMsg });
49
- return input();
50
- },
51
- textareaClasses() {
52
- const { input } = textareaClasses({ required: this.required, error: !!this.errorMsg });
53
- return input();
54
- }
55
- }
56
- });
57
- export {
58
- inputClassesMixin as default
59
- };
@@ -1,25 +0,0 @@
1
- var _a;
2
- import { squirrelTailwindConfig } from "./config.js";
3
- import { get } from "lodash-es";
4
- import resolveConfig from "tailwindcss/resolveConfig";
5
- const config = resolveConfig(squirrelTailwindConfig);
6
- const theme = config.theme;
7
- const colors = theme == null ? void 0 : theme.colors;
8
- (_a = theme == null ? void 0 : theme.extend) == null ? void 0 : _a.colors;
9
- const screens = theme == null ? void 0 : theme.screens;
10
- const getColor = (name) => {
11
- return colors == null ? void 0 : colors[name];
12
- };
13
- const getColorDeep = (color) => {
14
- const baseColor = color.split("-").slice(0, -1).join("-");
15
- const colorNumber = String(color.split("-").pop());
16
- return get(getColor(baseColor), colorNumber);
17
- };
18
- const getScreen = (size) => {
19
- return screens == null ? void 0 : screens[size];
20
- };
21
- export {
22
- getColor,
23
- getColorDeep,
24
- getScreen
25
- };
@@ -1,56 +0,0 @@
1
- import { type Size } from '../components/p-btn/p-btn.types';
2
- import { type PropType } from 'vue';
3
- declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
4
- size: {
5
- type: PropType<Size>;
6
- default: string;
7
- validator(value: Size): boolean;
8
- };
9
- errorMsg: {
10
- type: StringConstructor;
11
- default: string;
12
- };
13
- required: {
14
- type: BooleanConstructor;
15
- default: boolean;
16
- };
17
- rounded: {
18
- type: BooleanConstructor;
19
- default: boolean;
20
- };
21
- }>, {}, {}, {
22
- allClasses(): {
23
- input: string;
24
- label: string;
25
- errorMessage: string;
26
- };
27
- inputClasses(): string;
28
- labelClasses(): string;
29
- errorMsgClasses(): string;
30
- selectClasses(): string;
31
- textareaClasses(): string;
32
- }, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
33
- size: {
34
- type: PropType<Size>;
35
- default: string;
36
- validator(value: Size): boolean;
37
- };
38
- errorMsg: {
39
- type: StringConstructor;
40
- default: string;
41
- };
42
- required: {
43
- type: BooleanConstructor;
44
- default: boolean;
45
- };
46
- rounded: {
47
- type: BooleanConstructor;
48
- default: boolean;
49
- };
50
- }>> & Readonly<{}>, {
51
- size: "sm" | "md" | "lg";
52
- required: boolean;
53
- rounded: boolean;
54
- errorMsg: string;
55
- }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
56
- export default _default;
@@ -1,8 +0,0 @@
1
- declare const colors: import("tailwindcss/types/config").ResolvableTo<import("tailwindcss/types/config").RecursiveKeyValuePair<string, string>> | undefined;
2
- declare const extendedColors: import("tailwindcss/types/config").ResolvableTo<import("tailwindcss/types/config").RecursiveKeyValuePair<string, string>> | undefined;
3
- declare const screens: import("tailwindcss/types/config").ResolvableTo<import("tailwindcss/types/config").ScreensConfig> | undefined;
4
- export type Color = keyof typeof colors | keyof typeof extendedColors;
5
- export declare const getColor: (name: Color) => undefined;
6
- export declare const getColorDeep: (color: string) => undefined;
7
- export declare const getScreen: (size: keyof typeof screens) => undefined;
8
- export {};
@@ -1,241 +0,0 @@
1
- import inputClassesMixin from '@squirrel/utils/inputClassesMixin';
2
- import { shallowMount } from '@vue/test-utils';
3
-
4
- const baseInputClassesMd = () => [
5
- 'text-night',
6
- 'w-full',
7
- 'bg-surface',
8
- 'focus:outline-none',
9
- 'border-0',
10
- 'ring-1',
11
- 'ring-inset',
12
- 'focus:ring-2',
13
- 'disabled:ring-p-gray-30',
14
- 'disabled:hover:ring-p-gray-30',
15
- 'disabled:bg-p-blue-10',
16
- 'disabled:cursor-default',
17
- 'placeholder:text-p-gray-40',
18
- 'h-10',
19
- 'text-base',
20
- 'rounded',
21
- 'pl-4',
22
- 'pr-4',
23
- 'ring-p-gray-30',
24
- 'hover:ring-primary',
25
- 'focus:ring-primary',
26
- ];
27
-
28
- const baseInputClassesSm = () => {
29
- return baseInputClassesMd().map((item) => {
30
- return (
31
- {
32
- 'h-10': 'h-8',
33
- 'text-base': 'text-sm',
34
- 'pl-4': 'pl-3',
35
- 'pr-4': 'pr-3',
36
- }[item] || item
37
- );
38
- });
39
- };
40
-
41
- const baseInputClassesLg = () => {
42
- return baseInputClassesMd().map((item) => {
43
- return (
44
- {
45
- 'h-10': 'h-12',
46
- 'text-base': 'text-lg',
47
- 'pl-4': 'pl-5',
48
- 'pr-4': 'pr-5',
49
- }[item] || item
50
- );
51
- });
52
- };
53
-
54
- const baseLabelClassesMd = ['block', 'mb-1', 'font-medium', 'text-sm'];
55
-
56
- const createWrapper = (opts) => {
57
- const TestComponent = {
58
- render() {
59
- //
60
- },
61
- mixins: [inputClassesMixin],
62
- };
63
-
64
- return shallowMount(TestComponent, opts);
65
- };
66
-
67
- describe('inputClassesMixin', () => {
68
- it('generates input classes md', () => {
69
- const wrapper = createWrapper({ props: { size: 'md' } });
70
-
71
- const inputClasses = wrapper.vm.inputClasses.split(' ');
72
-
73
- expect(inputClasses).toEqual(expect.arrayContaining(baseInputClassesMd()));
74
- });
75
-
76
- it('generates input classes sm', () => {
77
- const wrapper = createWrapper({ props: { size: 'sm' } });
78
-
79
- const inputClasses = wrapper.vm.inputClasses.split(' ');
80
-
81
- expect(inputClasses).toEqual(expect.arrayContaining(baseInputClassesSm()));
82
- });
83
-
84
- it('generates input classes lg', () => {
85
- const wrapper = createWrapper({ props: { size: 'lg' } });
86
-
87
- const inputClasses = wrapper.vm.inputClasses.split(' ');
88
-
89
- expect(inputClasses).toEqual(expect.arrayContaining(baseInputClassesLg()));
90
- });
91
-
92
- it('generates label classes md', () => {
93
- const wrapper = createWrapper({ props: { size: 'md' } });
94
-
95
- const labelClasses = wrapper.vm.labelClasses.split(' ');
96
-
97
- expect(labelClasses).toEqual(expect.arrayContaining(baseLabelClassesMd));
98
- });
99
-
100
- it('generates label classes sm', () => {
101
- const wrapper = createWrapper({ props: { size: 'sm' } });
102
-
103
- const labelClasses = wrapper.vm.labelClasses.split(' ');
104
- const baseLabelClasses = baseLabelClassesMd.map((item) => {
105
- return (
106
- {
107
- 'text-sm': 'text-xs',
108
- }[item] || item
109
- );
110
- });
111
-
112
- expect(labelClasses).toEqual(expect.arrayContaining(baseLabelClasses));
113
- });
114
-
115
- it('generates label classes lg', () => {
116
- const wrapper = createWrapper({ props: { size: 'lg' } });
117
-
118
- const labelClasses = wrapper.vm.labelClasses.split(' ');
119
- const baseLabelClassesLg = baseLabelClassesMd.map((item) => {
120
- return (
121
- {
122
- 'text-sm': 'text-base',
123
- }[item] || item
124
- );
125
- });
126
-
127
- expect(labelClasses).toEqual(expect.arrayContaining(baseLabelClassesLg));
128
- });
129
-
130
- it('generates select classes md', () => {
131
- const wrapper = createWrapper({ props: { size: 'md' } });
132
-
133
- const selectClasses = wrapper.vm.selectClasses.split(' ');
134
- const baseInputClasses = baseInputClassesMd().filter((item) => {
135
- return !['pr-4', 'bg-surface'].includes(item);
136
- });
137
- const baseSelectClasses = [
138
- 'appearance-none',
139
- 'bg-[position:right_1rem_center]',
140
- 'bg-no-repeat',
141
- 'pr-10',
142
- 'squirrel-bg-chevron-down',
143
- 'truncate',
144
- ];
145
-
146
- const res = baseInputClasses.concat(baseSelectClasses);
147
-
148
- expect(selectClasses).toEqual(expect.arrayContaining(res));
149
- });
150
-
151
- it('generates select classes sm', () => {
152
- const wrapper = createWrapper({ props: { size: 'sm' } });
153
-
154
- const selectClasses = wrapper.vm.selectClasses.split(' ');
155
- const baseInputClasses = baseInputClassesSm().filter((item) => {
156
- return !['pr-3', 'bg-surface'].includes(item);
157
- });
158
- const baseSelectClasses = [
159
- 'appearance-none',
160
- 'bg-[position:right_0.675rem_center]',
161
- 'bg-no-repeat',
162
- 'pr-8',
163
- 'squirrel-bg-chevron-down',
164
- 'truncate',
165
- ];
166
- const res = baseInputClasses.concat(baseSelectClasses);
167
-
168
- expect(selectClasses).toEqual(expect.arrayContaining(res));
169
- });
170
-
171
- it('generates select classes lg', () => {
172
- const wrapper = createWrapper({ props: { size: 'lg' } });
173
-
174
- const selectClasses = wrapper.vm.selectClasses.split(' ');
175
- const baseInputClasses = baseInputClassesLg().filter((item) => {
176
- return !['pr-5', 'bg-surface'].includes(item);
177
- });
178
- const baseSelectClasses = [
179
- 'appearance-none',
180
- 'bg-[position:right_1.25rem_center]',
181
- 'bg-no-repeat',
182
- 'pr-12',
183
- 'squirrel-bg-chevron-down',
184
- 'truncate',
185
- ];
186
- const res = baseInputClasses.concat(baseSelectClasses);
187
-
188
- expect(selectClasses).toEqual(expect.arrayContaining(res));
189
- });
190
-
191
- it('generates textarea classes md', () => {
192
- const wrapper = createWrapper({ props: { size: 'md' } });
193
-
194
- const textareaClasses = wrapper.vm.textareaClasses.split(' ');
195
- const baseInputClasses = baseInputClassesMd().filter((item) => {
196
- return !['pl-3', 'pr-3', 'h-10'].includes(item);
197
- });
198
- const res = baseInputClasses.concat(['resize-y', 'px-3', 'py-3', 'overflow-auto', 'h-auto']);
199
-
200
- expect(textareaClasses).toEqual(expect.arrayContaining(res));
201
- });
202
-
203
- it('generates textarea classes sm', () => {
204
- const wrapper = createWrapper({ props: { size: 'sm' } });
205
-
206
- const textareaClasses = wrapper.vm.textareaClasses.split(' ');
207
- const baseInputClasses = baseInputClassesSm().filter((item) => {
208
- return !['pr-3', 'pl-3', 'h-8', 'text-sm'].includes(item);
209
- });
210
- const res = baseInputClasses.concat(['resize-y', 'px-3', 'py-3', 'overflow-auto', 'h-auto', 'pr-4', 'pl-4']);
211
-
212
- expect(textareaClasses).toEqual(expect.arrayContaining(res));
213
- });
214
-
215
- it('generates textarea classes lg', () => {
216
- const wrapper = createWrapper({ props: { size: 'lg' } });
217
-
218
- const textareaClasses = wrapper.vm.textareaClasses.split(' ');
219
- const baseInputClasses = baseInputClassesLg().filter((item) => {
220
- return !['pr-5', 'pl-5', 'h-12', 'text-lg'].includes(item);
221
- });
222
- const res = baseInputClasses.concat(['resize-y', 'px-3', 'py-3', 'overflow-auto', 'h-auto', 'pr-4', 'pl-4']);
223
-
224
- expect(textareaClasses).toEqual(expect.arrayContaining(res));
225
- });
226
-
227
- it('generates error classes', () => {
228
- const wrapper = createWrapper({ props: { size: 'md', errorMsg: 'Test error' } });
229
-
230
- const inputClasses = wrapper.vm.inputClasses.split(' ');
231
- const resInputClasses = baseInputClassesMd()
232
- .filter((item) => {
233
- return !['ring-p-gray-30', 'hover:ring-primary', 'focus:ring-primary'].includes(item);
234
- })
235
- .concat(['ring-on-error', 'hover:ring-on-error', 'focus:ring-on-error']);
236
- const errorMsgClasses = wrapper.vm.errorMsgClasses.split(' ');
237
-
238
- expect(inputClasses).toEqual(expect.arrayContaining(resInputClasses));
239
- expect(errorMsgClasses).toEqual(expect.arrayContaining(['text-xs', 'text-on-error', 'mt-1']));
240
- });
241
- });
@@ -1,60 +0,0 @@
1
- import { type Size, SIZES } from '@squirrel/components/p-btn/p-btn.types';
2
- import { inputClasses, selectClasses, textareaClasses } from '@squirrel/utils/inputClasses';
3
- import { defineComponent, type PropType } from 'vue';
4
-
5
- export default defineComponent({
6
- props: {
7
- size: {
8
- type: String as PropType<Size>,
9
- default: 'md',
10
- validator(value: Size) {
11
- return SIZES.includes(value);
12
- },
13
- },
14
- errorMsg: {
15
- type: String,
16
- default: '',
17
- },
18
- required: {
19
- type: Boolean,
20
- default: false,
21
- },
22
- rounded: {
23
- type: Boolean,
24
- default: false,
25
- },
26
- },
27
- computed: {
28
- allClasses() {
29
- const { input, label, errorMessage } = inputClasses({
30
- size: this.size,
31
- prefix: !!this.$slots.prefix,
32
- suffix: !!this.$slots.suffix,
33
- required: this.required,
34
- error: !!this.errorMsg,
35
- rounded: this.rounded,
36
- });
37
-
38
- return { input: input(), label: label(), errorMessage: errorMessage() };
39
- },
40
- inputClasses() {
41
- return this.allClasses.input;
42
- },
43
- labelClasses() {
44
- return this.allClasses.label;
45
- },
46
- errorMsgClasses() {
47
- return this.allClasses.errorMessage;
48
- },
49
- selectClasses() {
50
- const { input } = selectClasses({ size: this.size, required: this.required, error: !!this.errorMsg });
51
-
52
- return input();
53
- },
54
- textareaClasses() {
55
- const { input } = textareaClasses({ required: this.required, error: !!this.errorMsg });
56
-
57
- return input();
58
- },
59
- },
60
- });
@@ -1,27 +0,0 @@
1
- import { getScreen } from '@squirrel/utils/tailwind';
2
- import { cloneDeep } from 'lodash-es';
3
-
4
- const screens = { sm: '640px', md: '768px' };
5
-
6
- describe('tailwind', () => {
7
- it('should return the correct screen size for a valid key', () => {
8
- // Mock the theme.screens object
9
- const originalScreens = global.screens;
10
- global.screens = cloneDeep(screens);
11
-
12
- expect(getScreen('sm')).toBe('640px');
13
- expect(getScreen('md')).toBe('768px');
14
-
15
- // Restore the original screens object
16
- global.screens = originalScreens;
17
- });
18
-
19
- it('should return undefined for an invalid key', () => {
20
- const originalScreens = global.screens;
21
- global.screens = cloneDeep(screens);
22
-
23
- expect(getScreen('xxl')).toBeUndefined();
24
-
25
- global.screens = originalScreens;
26
- });
27
- });