Skip to content

Commit b549fd3

Browse files
committed
fix: moved icons to css
1 parent 563b9f3 commit b549fd3

File tree

3 files changed

+73
-42
lines changed

3 files changed

+73
-42
lines changed

src/SearchInput.vue

+3-28
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
<template>
22
<div v-bind="attrsStyles">
33
<slot v-if="searchIcon" name="search-icon">
4-
<div class="search-icon search">
5-
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
6-
<path
7-
fill-rule="evenodd"
8-
clip-rule="evenodd"
9-
d="M18.319 14.4326C20.7628 11.2941 20.542 6.75347 17.6569 3.86829C14.5327 0.744098 9.46734 0.744098 6.34315 3.86829C3.21895 6.99249 3.21895 12.0578 6.34315 15.182C9.22833 18.0672 13.769 18.2879 16.9075 15.8442C16.921 15.8595 16.9351 15.8745 16.9497 15.8891L21.1924 20.1317C21.5829 20.5223 22.2161 20.5223 22.6066 20.1317C22.9971 19.7412 22.9971 19.1081 22.6066 18.7175L18.364 14.4749C18.3493 14.4603 18.3343 14.4462 18.319 14.4326ZM16.2426 5.28251C18.5858 7.62565 18.5858 11.4246 16.2426 13.7678C13.8995 16.1109 10.1005 16.1109 7.75736 13.7678C5.41421 11.4246 5.41421 7.62565 7.75736 5.28251C10.1005 2.93936 13.8995 2.93936 16.2426 5.28251Z"
10-
fill="currentColor"
11-
/>
12-
</svg>
13-
</div>
4+
<i class="search-icon search"></i>
145
</slot>
156
<input
167
ref="inputRef"
@@ -24,26 +15,10 @@
2415
@keydown="onKeydown"
2516
/>
2617
<slot v-if="shortcutIcon && !hasFocus && modelValue.length === 0" name="shortcut-icon">
27-
<div class="search-icon shortcut" title='Press "/" to search'>
28-
<svg width="16" height="20" viewBox="4 4 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
29-
<path
30-
fill-rule="evenodd"
31-
clip-rule="evenodd"
32-
d="M14.526 6.10576C15.0265 6.33917 15.2667 6.88343 15.0625 7.3214L9.88541 18.4237C9.68118 18.8616 9.10985 19.0275 8.60931 18.7941C8.10877 18.5607 7.86857 18.0164 8.0728 17.5784L13.2499 6.47616C13.4541 6.03819 14.0254 5.87235 14.526 6.10576Z"
33-
fill="currentColor"
34-
/>
35-
</svg>
36-
</div>
18+
<i class="search-icon shortcut" title='Press "/" to search'></i>
3719
</slot>
3820
<slot v-if="clearIcon && modelValue.length > 0" name="clear-icon" :clear="clear">
39-
<div class="search-icon clear" @mousedown="clear">
40-
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
41-
<path
42-
d="M6.2253 4.81108C5.83477 4.42056 5.20161 4.42056 4.81108 4.81108C4.42056 5.20161 4.42056 5.83477 4.81108 6.2253L10.5858 12L4.81114 17.7747C4.42062 18.1652 4.42062 18.7984 4.81114 19.1889C5.20167 19.5794 5.83483 19.5794 6.22535 19.1889L12 13.4142L17.7747 19.1889C18.1652 19.5794 18.7984 19.5794 19.1889 19.1889C19.5794 18.7984 19.5794 18.1652 19.1889 17.7747L13.4142 12L19.189 6.2253C19.5795 5.83477 19.5795 5.20161 19.189 4.81108C18.7985 4.42056 18.1653 4.42056 17.7748 4.81108L12 10.5858L6.2253 4.81108Z"
43-
fill="currentColor"
44-
/>
45-
</svg>
46-
</div>
21+
<i class="search-icon clear" @mousedown="clear"></i>
4722
</slot>
4823
</div>
4924
</template>

src/styles.scss

+66-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ $active-color: #1ea7fd;
66
.search-input-wrapper {
77
position: relative;
88

9-
input[data-search-input="true"] {
9+
input[data-search-input='true'] {
1010
display: block;
1111
font-family: 'Inter', system-ui, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
1212
width: 100%;
@@ -30,29 +30,85 @@ $active-color: #1ea7fd;
3030
.search-icon {
3131
color: $icon-color;
3232
position: absolute;
33-
bottom: 4px;
3433
&.search {
35-
left: 6px;
36-
bottom: 8px;
37-
height: 20px;
34+
left: 12px;
35+
bottom: 12px;
36+
box-sizing: border-box;
37+
display: block;
38+
width: 16px;
39+
height: 16px;
40+
border: 2px solid;
41+
border-radius: 100%;
42+
margin-left: -4px;
43+
margin-top: -4px;
44+
}
45+
&.search::after {
46+
content: '';
47+
display: block;
48+
box-sizing: border-box;
49+
position: absolute;
50+
border-radius: 3px;
51+
width: 2px;
52+
height: 7px;
53+
background: $icon-color;
54+
transform: rotate(-45deg);
55+
top: 11px;
56+
left: 12px;
3857
}
3958
&.shortcut {
59+
width: 22px;
60+
height: 24px;
4061
cursor: text;
4162
right: 8px;
4263
bottom: 7px;
43-
padding: 0px 3px;
44-
color: lighten($icon-color, 5%);
45-
background-color: darken($input-background, 5%);
64+
background-color: darken($input-background, 4%);
4665
border-radius: 3px;
4766
z-index: 50;
48-
height: 24px;
67+
}
68+
&.shortcut::after {
69+
content: '';
70+
display: block;
71+
box-sizing: border-box;
72+
position: absolute;
73+
border-radius: 2px;
74+
transform: rotate(25deg);
75+
width: 2px;
76+
height: 16px;
77+
top: 4px;
78+
left: 10px;
79+
z-index: 51;
80+
background-color: lighten($icon-color, 5%);
4981
}
5082
&.clear {
5183
right: 8px;
52-
bottom: 10px;
84+
bottom: 8px;
5385
cursor: pointer;
5486
z-index: 10;
5587
height: 18px;
88+
box-sizing: border-box;
89+
display: block;
90+
width: 22px;
91+
height: 22px;
92+
border: 2px solid transparent;
93+
border-radius: 40px;
94+
95+
}
96+
&.clear::after,
97+
&.clear::before {
98+
content: '';
99+
display: block;
100+
box-sizing: border-box;
101+
position: absolute;
102+
width: 16px;
103+
height: 2px;
104+
background: $icon-color;
105+
transform: rotate(45deg);
106+
border-radius: 5px;
107+
top: 8px;
108+
left: 1px;
109+
}
110+
&.clear::after {
111+
transform: rotate(-45deg);
56112
}
57113
}
58114
}

tests/searchInput.spec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ describe('SearchInput.vue', () => {
5050
it('should render a search icon', async () => {
5151
const wrapper = createWrapper()
5252

53-
const div = await wrapper.find('div.search-icon.search')
53+
const i = await wrapper.find('i.search-icon.search')
5454

55-
expect(div).toBeTruthy()
55+
expect(i).toBeTruthy()
5656
})
5757

5858
it('should pass class to the input wrapper', async () => {
@@ -101,9 +101,9 @@ describe('SearchInput.vue', () => {
101101
}
102102
})
103103

104-
const clearIcon = await wrapper.find('div.search-icon.clear')
104+
const i = await wrapper.find('i.search-icon.clear')
105105

106-
await clearIcon.trigger('mousedown')
106+
await i.trigger('mousedown')
107107

108108
expect(wrapper.emitted()['update:modelValue'][0]).toEqual([''])
109109
})

0 commit comments

Comments
 (0)