@weni/unnnic-system 2.22.0 → 2.23.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/CHANGELOG.md +6 -0
- package/dist/{es-494a7dd2.mjs → es-fb6be0a1.mjs} +1 -1
- package/dist/{index-6ef10629.mjs → index-99296064.mjs} +269 -254
- package/dist/{pt-br-4174b355.mjs → pt-br-d2df436c.mjs} +1 -1
- package/dist/style.css +1 -1
- package/dist/unnnic.mjs +1 -1
- package/dist/unnnic.umd.js +23 -23
- package/package.json +1 -1
- package/src/components/SelectSmart/SelectSmart.vue +36 -5
- package/src/components/SelectSmart/SelectSmartOption.vue +13 -0
- package/src/components/SelectSmart/__tests__/SelectSmart.spec.js +66 -0
- package/src/components/SelectSmart/__tests__/SelectSmartOption.spec.js +25 -0
- package/src/stories/SelectSmart.stories.js +27 -0
package/package.json
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div
|
|
3
3
|
v-on-click-outside="onClickOutside"
|
|
4
|
-
class="
|
|
4
|
+
:class="[
|
|
5
|
+
'unnnic-select-smart',
|
|
6
|
+
{ 'unnnic-select-smart--secondary': type === 'secondary' },
|
|
7
|
+
]"
|
|
5
8
|
data-testid="select-smart"
|
|
6
9
|
@keydown="onKeyDownSelect"
|
|
7
10
|
>
|
|
@@ -13,7 +16,10 @@
|
|
|
13
16
|
>
|
|
14
17
|
<TextInput
|
|
15
18
|
ref="selectSmartInput"
|
|
16
|
-
class="
|
|
19
|
+
:class="[
|
|
20
|
+
'unnnic-select-smart__input',
|
|
21
|
+
{ 'unnnic-select-smart__input--secondary': type === 'secondary' },
|
|
22
|
+
]"
|
|
17
23
|
data-testid="select-smart-input"
|
|
18
24
|
:modelValue="inputValue"
|
|
19
25
|
:placeholder="placeholder || autocompletePlaceholder || selectedLabel"
|
|
@@ -75,6 +81,7 @@
|
|
|
75
81
|
"
|
|
76
82
|
:focused="focusedOption && focusedOption.value === option.value"
|
|
77
83
|
:allowCheckbox="!!multiple"
|
|
84
|
+
:activeColor="type === 'secondary' ? 'secondary' : 'primary'"
|
|
78
85
|
@click="handleSelect(option)"
|
|
79
86
|
/>
|
|
80
87
|
<p
|
|
@@ -140,7 +147,7 @@ export default {
|
|
|
140
147
|
type: String,
|
|
141
148
|
default: 'normal',
|
|
142
149
|
validator(value) {
|
|
143
|
-
return ['normal', 'error'].indexOf(value) !== -1;
|
|
150
|
+
return ['normal', 'error', 'secondary'].indexOf(value) !== -1;
|
|
144
151
|
},
|
|
145
152
|
},
|
|
146
153
|
disabled: {
|
|
@@ -640,11 +647,27 @@ export default {
|
|
|
640
647
|
display: block;
|
|
641
648
|
z-index: 2;
|
|
642
649
|
}
|
|
650
|
+
|
|
651
|
+
.unnnic-select-smart--secondary & {
|
|
652
|
+
border-radius: 0.25rem;
|
|
653
|
+
margin-top: -1px;
|
|
654
|
+
box-shadow: $unnnic-shadow-level-near;
|
|
655
|
+
}
|
|
643
656
|
}
|
|
644
657
|
|
|
645
|
-
|
|
646
|
-
|
|
658
|
+
&--secondary {
|
|
659
|
+
.unnnic-select-smart__input {
|
|
660
|
+
.unnnic-input {
|
|
661
|
+
border-radius: $unnnic-border-radius-sm $unnnic-border-radius-sm 0 0;
|
|
662
|
+
}
|
|
647
663
|
|
|
664
|
+
&.active .unnnic-input {
|
|
665
|
+
border-bottom-color: transparent;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
.unnnic-select-smart__input input {
|
|
648
671
|
&:read-only {
|
|
649
672
|
cursor: pointer;
|
|
650
673
|
}
|
|
@@ -653,6 +676,14 @@ export default {
|
|
|
653
676
|
cursor: not-allowed;
|
|
654
677
|
}
|
|
655
678
|
}
|
|
679
|
+
|
|
680
|
+
.unnnic-select-smart__input--secondary input {
|
|
681
|
+
border: none;
|
|
682
|
+
color: $unnnic-color-neutral-darkest;
|
|
683
|
+
font-family: $unnnic-font-family-secondary;
|
|
684
|
+
font-size: $unnnic-font-size-body-gt;
|
|
685
|
+
line-height: $unnnic-line-height-md + $unnnic-font-size-body-gt;
|
|
686
|
+
}
|
|
656
687
|
}
|
|
657
688
|
|
|
658
689
|
::-webkit-scrollbar {
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
'unnnic-select-smart-option': true,
|
|
5
5
|
'unnnic-select-smart-option--focused': focused,
|
|
6
6
|
'unnnic-select-smart-option--active': active,
|
|
7
|
+
'unnnic-select-smart-option--active-secondary':
|
|
8
|
+
active && activeColor === 'secondary',
|
|
7
9
|
'unnnic--clickable': selectable,
|
|
8
10
|
'unnnic-select-smart-option--selectable': selectable,
|
|
9
11
|
'unnnic-select-smart-option--with-checkbox': allowCheckbox,
|
|
@@ -79,6 +81,13 @@ export default {
|
|
|
79
81
|
default: false,
|
|
80
82
|
},
|
|
81
83
|
isMultiple: Boolean,
|
|
84
|
+
activeColor: {
|
|
85
|
+
type: String,
|
|
86
|
+
default: 'primary',
|
|
87
|
+
validator(value) {
|
|
88
|
+
return ['primary', 'secondary'].indexOf(value) !== -1;
|
|
89
|
+
},
|
|
90
|
+
},
|
|
82
91
|
},
|
|
83
92
|
};
|
|
84
93
|
</script>
|
|
@@ -114,6 +123,10 @@ export default {
|
|
|
114
123
|
&--active:not(&--with-checkbox) {
|
|
115
124
|
color: $unnnic-color-weni-600;
|
|
116
125
|
font-weight: $unnnic-font-weight-bold;
|
|
126
|
+
|
|
127
|
+
&.unnnic-select-smart-option--active-secondary {
|
|
128
|
+
color: $unnnic-color-neutral-darkest;
|
|
129
|
+
}
|
|
117
130
|
}
|
|
118
131
|
|
|
119
132
|
&--with-checkbox {
|
|
@@ -237,4 +237,70 @@ describe('SelectSmart.vue', () => {
|
|
|
237
237
|
expect(wrapper.emitted('update:modelValue')[0][0]).toEqual([options[1]]);
|
|
238
238
|
});
|
|
239
239
|
});
|
|
240
|
+
|
|
241
|
+
describe('Secondary Type', () => {
|
|
242
|
+
beforeEach(() => {
|
|
243
|
+
mountWrapper({
|
|
244
|
+
type: 'secondary',
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it('should apply secondary class to root element when type is secondary', () => {
|
|
249
|
+
expect(selectSmart().classes()).toContain(
|
|
250
|
+
'unnnic-select-smart--secondary',
|
|
251
|
+
);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it('should apply secondary class to input when type is secondary', () => {
|
|
255
|
+
expect(input().classes()).toContain(
|
|
256
|
+
'unnnic-select-smart__input--secondary',
|
|
257
|
+
);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it('should maintain secondary styling when dropdown is opened', async () => {
|
|
261
|
+
await input().trigger('click');
|
|
262
|
+
expect(selectSmart().classes()).toContain(
|
|
263
|
+
'unnnic-select-smart--secondary',
|
|
264
|
+
);
|
|
265
|
+
expect(optionsContainer().exists()).toBe(true);
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
describe('SelectSmartOption activeColor', () => {
|
|
270
|
+
beforeEach(async () => {
|
|
271
|
+
mountWrapper({
|
|
272
|
+
options: [
|
|
273
|
+
{ label: 'Apple', value: 'apple' },
|
|
274
|
+
{ label: 'Banana', value: 'banana' },
|
|
275
|
+
{ label: 'Orange', value: 'orange' },
|
|
276
|
+
],
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it('passes primary activeColor by default', async () => {
|
|
281
|
+
wrapper.vm.active = true;
|
|
282
|
+
await nextTick();
|
|
283
|
+
|
|
284
|
+
const option = wrapper.findComponent('[data-testid="option"]');
|
|
285
|
+
expect(option.props('activeColor')).toBe('primary');
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it('passes secondary activeColor when type is secondary', async () => {
|
|
289
|
+
await wrapper.setProps({ type: 'secondary' });
|
|
290
|
+
wrapper.vm.active = true;
|
|
291
|
+
await nextTick();
|
|
292
|
+
|
|
293
|
+
const option = wrapper.findComponent('[data-testid="option"]');
|
|
294
|
+
expect(option.props('activeColor')).toBe('secondary');
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it('maintains primary activeColor for error type', async () => {
|
|
298
|
+
await wrapper.setProps({ type: 'error' });
|
|
299
|
+
wrapper.vm.active = true;
|
|
300
|
+
await nextTick();
|
|
301
|
+
|
|
302
|
+
const option = wrapper.findComponent('[data-testid="option"]');
|
|
303
|
+
expect(option.props('activeColor')).toBe('primary');
|
|
304
|
+
});
|
|
305
|
+
});
|
|
240
306
|
});
|
|
@@ -111,4 +111,29 @@ describe('SelectSmartOption.vue', () => {
|
|
|
111
111
|
);
|
|
112
112
|
});
|
|
113
113
|
});
|
|
114
|
+
|
|
115
|
+
describe('Active color variants', () => {
|
|
116
|
+
it('uses primary color by default when active', async () => {
|
|
117
|
+
await wrapper.setProps({
|
|
118
|
+
active: true,
|
|
119
|
+
allowCheckbox: false,
|
|
120
|
+
});
|
|
121
|
+
expect(wrapper.classes()).toContain('unnnic-select-smart-option--active');
|
|
122
|
+
expect(wrapper.classes()).not.toContain(
|
|
123
|
+
'unnnic-select-smart-option--active-secondary',
|
|
124
|
+
);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('uses secondary color when activeColor is secondary', async () => {
|
|
128
|
+
await wrapper.setProps({
|
|
129
|
+
active: true,
|
|
130
|
+
activeColor: 'secondary',
|
|
131
|
+
allowCheckbox: false,
|
|
132
|
+
});
|
|
133
|
+
expect(wrapper.classes()).toContain('unnnic-select-smart-option--active');
|
|
134
|
+
expect(wrapper.classes()).toContain(
|
|
135
|
+
'unnnic-select-smart-option--active-secondary',
|
|
136
|
+
);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
114
139
|
});
|
|
@@ -74,6 +74,18 @@ const TemplateDisabled = (args, { argTypes }) => ({
|
|
|
74
74
|
`,
|
|
75
75
|
});
|
|
76
76
|
|
|
77
|
+
const TemplateSecondary = (args, { argTypes }) => ({
|
|
78
|
+
props: Object.keys(argTypes),
|
|
79
|
+
components: { unnnicSelectSmart },
|
|
80
|
+
setup() {
|
|
81
|
+
return { args };
|
|
82
|
+
},
|
|
83
|
+
data() {
|
|
84
|
+
return { exampleValue: [] };
|
|
85
|
+
},
|
|
86
|
+
template: `<unnnicSelectSmart v-bind="args" v-model="exampleValue"/>`,
|
|
87
|
+
});
|
|
88
|
+
|
|
77
89
|
export const Default = {
|
|
78
90
|
args: {
|
|
79
91
|
options: [
|
|
@@ -228,3 +240,18 @@ export const Multiple = {
|
|
|
228
240
|
multipleWithoutSelectsMessage: 'No country selected yet :(',
|
|
229
241
|
},
|
|
230
242
|
};
|
|
243
|
+
|
|
244
|
+
export const Secondary = TemplateSecondary.bind({});
|
|
245
|
+
Secondary.args = {
|
|
246
|
+
type: 'secondary',
|
|
247
|
+
options: [
|
|
248
|
+
{ value: '', label: 'Select some option' },
|
|
249
|
+
{ value: '5', label: 'Option 5' },
|
|
250
|
+
{ value: '3', label: 'Option 3' },
|
|
251
|
+
{ value: '1', label: 'Option 1' },
|
|
252
|
+
{ value: '4', label: 'Option 4' },
|
|
253
|
+
{ value: '2', label: 'Option 2' },
|
|
254
|
+
{ value: '6', label: 'Option 6' },
|
|
255
|
+
{ value: '7', label: 'Option 7' },
|
|
256
|
+
],
|
|
257
|
+
};
|