@sierra-95/svelte-scaffold 1.0.23 → 1.0.25

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.
@@ -1,69 +1,118 @@
1
1
  <script lang="ts">
2
- import {isMobile} from '../../../../../index.js';
2
+ import { onMount, onDestroy } from 'svelte';
3
+ import { browser } from '$app/environment';
4
+
3
5
  let {
4
- width = '250px',
5
- height = '30px',
6
+ width = '200px',
7
+ height = '40px',
8
+ borderRadius = '5px',
6
9
  value = $bindable(''),
7
10
  placeholder = 'Search',
8
- isVisible = $bindable(!$isMobile),
9
- ...rest
11
+ enableHotkey = false,
12
+ onHotkey = () => {},
13
+ onSearch = () => {},
10
14
  } = $props();
11
15
 
12
- $effect(() => {
13
- isVisible = $isMobile ? false : true;
16
+ function handleKeydown(e: KeyboardEvent) {
17
+ if (!enableHotkey) return;
18
+
19
+ if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'k') {
20
+ e.preventDefault();
21
+ onHotkey?.();
22
+ }
23
+ }
24
+
25
+ onMount(() => {
26
+ if (!enableHotkey || !browser) return;
27
+ window.addEventListener('keydown', handleKeydown);
28
+ });
29
+
30
+ onDestroy(() => {
31
+ if(!browser) return;
32
+ window.removeEventListener('keydown', handleKeydown);
14
33
  });
15
34
  </script>
16
35
  <style>
36
+ #sierra-search-bar{
37
+ position: relative;
38
+ }
17
39
  #sierra-search-bar #sierra-search-input{
18
40
  width: 100%;
19
41
  height: 100%;
20
- border-top-left-radius: 25px;
21
- border-bottom-left-radius: 25px;
22
42
  background: transparent;
23
- border: 1px solid var(--input-border);
43
+ border-top: 1px solid var(--input-border);
44
+ border-bottom: 1px solid var(--input-border);
45
+ border-left: none;
24
46
  border-right: none;
47
+ padding: 8px 12px;
48
+ }
49
+ #sierra-search-bar div.hotkey{
50
+ display: flex;
51
+ align-items: center;
52
+ gap: 5px;
53
+ border-top: 1px solid var(--input-border);
54
+ border-bottom: 1px solid var(--input-border);
55
+ font-size: 0.9rem;
56
+ }
57
+
58
+ #sierra-search-bar div.hotkey span{
59
+ background-color: var(--background-secondary);
60
+ border: 1px solid var(--input-border);
61
+ padding: 0px 3px;
62
+ border-radius: 3px;
25
63
  }
26
- #sierra-search-bar div{
64
+ #sierra-search-bar div.search-button{
27
65
  display: flex;
28
66
  align-items: center;
29
67
  gap: 10px;
30
- padding: 0px 10px 0px 0px; /*top right bottom left */
68
+ padding: 0px 10px 0px 10px; /*top right bottom left */
31
69
  height: 100%;
32
70
  border: 1px solid var(--input-border);
33
71
  border-left: none;
34
- border-top-right-radius: 25px;
35
- border-bottom-right-radius: 25px;
36
72
  }
37
73
  </style>
38
- <main id="sierra-search-bar"
39
- style="
40
- height: {height};
41
- width: {width}; {isVisible? 'display:flex;' : 'display:none;'}
42
- transform: translateX({isVisible && isMobile ? '0' : '100%'});
43
- opacity: {isVisible && isMobile ? 1 : 0};
44
- transition: transform 0.3s ease, opacity 0.3s ease;
45
- ">
74
+ <main id="sierra-search-bar" role="none" style="height: {height}; display:flex; }">
75
+
76
+ <button
77
+ hidden={!enableHotkey}
78
+ style="border-top: 1px solid var(--input-border); border-bottom: 1px solid var(--input-border); border-left: 1px solid var(--input-border); border-top-left-radius: {borderRadius}; border-bottom-left-radius: {borderRadius}; padding: 0px 10px;"
79
+ aria-label="Search"
80
+ ><i class="fa fa-search"></i>
81
+ </button>
82
+
46
83
  <input
47
84
  id="sierra-search-input"
85
+ style="width: {width}; {enableHotkey ? 'cursor: pointer;' : ''}
86
+ {!enableHotkey ? `border-top: 1px solid var(--input-border); border-bottom: 1px solid var(--input-border); border-left: 1px solid var(--input-border); border-top-left-radius: ${borderRadius}; border-bottom-left-radius: ${borderRadius};`:''}
87
+ "
48
88
  type="text"
49
89
  bind:value={value}
90
+ readonly={enableHotkey}
50
91
  placeholder={placeholder}
51
- />
52
- <div>
92
+ onclick={() => {
93
+ if (!enableHotkey) return;
94
+ onHotkey?.();
95
+ }}
96
+ />
97
+
98
+ <div hidden={!enableHotkey} class="hotkey"
99
+ style="{enableHotkey ? `border-top-right-radius: ${borderRadius}; border-bottom-right-radius: ${borderRadius}; border-right: 1px solid var(--input-border); padding-right: 10px;` : ''}"
100
+ ><span>Ctrl</span> <span>K</span>
101
+ </div>
102
+
103
+ <div hidden={enableHotkey} class="search-button" style="border-bottom-right-radius: {borderRadius}; border-top-right-radius: {borderRadius};">
53
104
  {#if value}
54
105
  <button aria-label="Clear search" onclick={() => value = ''} style="color: var(--primary-bg);">
55
- <i class="fa fa-times-circle"></i>
106
+ <i class="fa fa-times"></i>
56
107
  </button>
57
108
  {/if}
58
109
  <button
59
110
  aria-label="Search"
60
111
  onclick={(e: MouseEvent) => {
61
- rest.onclick?.(e);
112
+ e.preventDefault();
113
+ onSearch?.(value);
62
114
  }}
63
115
  ><i class="fa fa-search"></i>
64
116
  </button>
65
117
  </div>
66
- </main>
67
- <button aria-label="Show search bar" onclick={() => isVisible = true} style="{isVisible? 'display:none;' : ''}">
68
- <i class="fa fa-search"></i>
69
- </button>
118
+ </main>
@@ -1,9 +1,12 @@
1
1
  declare const Search: import("svelte").Component<{
2
2
  width?: string;
3
3
  height?: string;
4
+ borderRadius?: string;
4
5
  value?: string;
5
6
  placeholder?: string;
6
- isVisible?: any;
7
- } & Record<string, any>, {}, "value" | "isVisible">;
7
+ enableHotkey?: boolean;
8
+ onHotkey?: Function;
9
+ onSearch?: Function;
10
+ }, {}, "value">;
8
11
  type Search = ReturnType<typeof Search>;
9
12
  export default Search;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sierra-95/svelte-scaffold",
3
- "version": "1.0.23",
3
+ "version": "1.0.25",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run prepack",