@djcali570/component-lib 0.1.91 → 0.1.92
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/Checkbox5.svelte +2 -0
- package/dist/ContextMenu5.svelte +190 -0
- package/dist/ContextMenu5.svelte.d.ts +13 -0
- package/dist/DatePicker5.svelte +3 -7
- package/dist/DropDown5.svelte +2 -2
- package/dist/index.d.ts +4 -3
- package/dist/index.js +2 -1
- package/dist/types.d.ts +8 -0
- package/package.json +5 -1
package/dist/Checkbox5.svelte
CHANGED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onMount } from 'svelte';
|
|
3
|
+
import type { Snippet } from 'svelte';
|
|
4
|
+
import type { ContextMenu5ColorScheme } from './types.js';
|
|
5
|
+
import { fly } from 'svelte/transition';
|
|
6
|
+
|
|
7
|
+
// Props
|
|
8
|
+
let {
|
|
9
|
+
icon,
|
|
10
|
+
content,
|
|
11
|
+
colorScheme: partialColorScheme = {},
|
|
12
|
+
ariaLabel = 'Open context menu',
|
|
13
|
+
menuAlign = 'right',
|
|
14
|
+
open = $bindable()
|
|
15
|
+
}: {
|
|
16
|
+
icon?: Snippet;
|
|
17
|
+
content: Snippet;
|
|
18
|
+
colorScheme?: Partial<ContextMenu5ColorScheme>;
|
|
19
|
+
ariaLabel?: string;
|
|
20
|
+
menuAlign?: 'left' | 'right';
|
|
21
|
+
open?: boolean;
|
|
22
|
+
} = $props();
|
|
23
|
+
|
|
24
|
+
// Default colors
|
|
25
|
+
const defaultColorScheme: ContextMenu5ColorScheme = {
|
|
26
|
+
contentBgColor: '#121212',
|
|
27
|
+
contentBorderColor: '#191919',
|
|
28
|
+
iconFillColor: '#121212',
|
|
29
|
+
iconBorderColor: '#121212',
|
|
30
|
+
iconColor: '#F5F5F5'
|
|
31
|
+
};
|
|
32
|
+
const colorScheme = $derived({
|
|
33
|
+
...defaultColorScheme,
|
|
34
|
+
...partialColorScheme
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// DOM refs
|
|
38
|
+
let triggerEl: HTMLElement | null = null;
|
|
39
|
+
let menuEl: HTMLElement | null = $state(null);
|
|
40
|
+
|
|
41
|
+
// Toggle menu
|
|
42
|
+
function toggle() {
|
|
43
|
+
open = !open;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Close menu
|
|
47
|
+
function closeMenu() {
|
|
48
|
+
open = false;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Click outside
|
|
52
|
+
function handlePointerDown(e: PointerEvent) {
|
|
53
|
+
if (!open) return;
|
|
54
|
+
|
|
55
|
+
const target = e.target as Node;
|
|
56
|
+
if (menuEl && triggerEl && !menuEl.contains(target) && !triggerEl.contains(target)) {
|
|
57
|
+
closeMenu();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Escape key
|
|
62
|
+
function handleKeyDown(e: KeyboardEvent) {
|
|
63
|
+
if (e.key === 'Escape') closeMenu();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
onMount(() => {
|
|
67
|
+
document.addEventListener('pointerdown', handlePointerDown);
|
|
68
|
+
document.addEventListener('keydown', handleKeyDown);
|
|
69
|
+
|
|
70
|
+
return () => {
|
|
71
|
+
document.removeEventListener('pointerdown', handlePointerDown);
|
|
72
|
+
document.removeEventListener('keydown', handleKeyDown);
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
</script>
|
|
76
|
+
|
|
77
|
+
<div
|
|
78
|
+
class="context5"
|
|
79
|
+
style="
|
|
80
|
+
--context5__ContentBgColor: {colorScheme.contentBgColor};
|
|
81
|
+
--context5__ContentBorderColor: {colorScheme.contentBorderColor};
|
|
82
|
+
--context5__IconBorderColor: {colorScheme.iconBorderColor};
|
|
83
|
+
--context5__IconColor: {colorScheme.iconColor};
|
|
84
|
+
--context5__IconFillColor: {colorScheme.iconFillColor};
|
|
85
|
+
"
|
|
86
|
+
>
|
|
87
|
+
<button
|
|
88
|
+
aria-label={ariaLabel}
|
|
89
|
+
type="button"
|
|
90
|
+
aria-haspopup="menu"
|
|
91
|
+
aria-expanded={open}
|
|
92
|
+
bind:this={triggerEl}
|
|
93
|
+
onclick={toggle}
|
|
94
|
+
class="context5__btn"
|
|
95
|
+
>
|
|
96
|
+
{#if icon}
|
|
97
|
+
<div class="context5__icon">
|
|
98
|
+
{@render icon()}
|
|
99
|
+
</div>
|
|
100
|
+
{:else}
|
|
101
|
+
<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor">
|
|
102
|
+
<circle cx="12" cy="5" r="2" />
|
|
103
|
+
<circle cx="12" cy="12" r="2" />
|
|
104
|
+
<circle cx="12" cy="19" r="2" />
|
|
105
|
+
</svg>
|
|
106
|
+
{/if}
|
|
107
|
+
</button>
|
|
108
|
+
|
|
109
|
+
{#if open}
|
|
110
|
+
<div
|
|
111
|
+
bind:this={menuEl}
|
|
112
|
+
role="menu"
|
|
113
|
+
class="context5__menu"
|
|
114
|
+
class:left={menuAlign === 'left'}
|
|
115
|
+
class:right={menuAlign === 'right'}
|
|
116
|
+
transition:fly={{ y: 10 }}
|
|
117
|
+
>
|
|
118
|
+
<div class="context5__content">
|
|
119
|
+
{@render content()}
|
|
120
|
+
</div>
|
|
121
|
+
</div>
|
|
122
|
+
{/if}
|
|
123
|
+
</div>
|
|
124
|
+
|
|
125
|
+
<style>
|
|
126
|
+
.context5 {
|
|
127
|
+
position: relative;
|
|
128
|
+
display: inline-block;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.context5__icon {
|
|
132
|
+
width: 20px;
|
|
133
|
+
height: 20px;
|
|
134
|
+
display: flex;
|
|
135
|
+
align-items: center;
|
|
136
|
+
justify-content: center;
|
|
137
|
+
flex-shrink: 0;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/* force ANY svg inside to obey the container */
|
|
141
|
+
.context5__icon :global(*) {
|
|
142
|
+
width: 100% !important;
|
|
143
|
+
height: 100% !important;
|
|
144
|
+
display: block;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
.context5__btn {
|
|
148
|
+
width: 30px; /* set width */
|
|
149
|
+
height: 30px; /* set height (same as width for a perfect circle) */
|
|
150
|
+
padding: 0; /* remove extra padding */
|
|
151
|
+
border-radius: 50%; /* fully round */
|
|
152
|
+
cursor: pointer;
|
|
153
|
+
background-color: var(--context5__IconFillColor);
|
|
154
|
+
border: none;
|
|
155
|
+
outline: none;
|
|
156
|
+
-webkit-tap-highlight-color: transparent; /* removes blue flash on touch devices */
|
|
157
|
+
display: flex; /* center the icon inside */
|
|
158
|
+
align-items: center;
|
|
159
|
+
justify-content: center;
|
|
160
|
+
border: 1px solid var(--context5__IconBorderColor);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.context5__btn > svg {
|
|
164
|
+
color: var(--context5__IconColor);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
.context5__menu {
|
|
168
|
+
position: absolute;
|
|
169
|
+
margin-top: 0.5rem;
|
|
170
|
+
z-index: 1000;
|
|
171
|
+
transform-origin: top;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
.context5__menu.right {
|
|
175
|
+
right: 0;
|
|
176
|
+
transform-origin: top right;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
.context5__menu.left {
|
|
180
|
+
left: 0;
|
|
181
|
+
transform-origin: top left;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
.context5__content {
|
|
185
|
+
background-color: var(--context5__ContentBgColor);
|
|
186
|
+
border-radius: 0.5rem;
|
|
187
|
+
padding: 0.5rem;
|
|
188
|
+
border: 1px solid var(--context5__ContentBorderColor);
|
|
189
|
+
}
|
|
190
|
+
</style>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { ContextMenu5ColorScheme } from './types.js';
|
|
3
|
+
type $$ComponentProps = {
|
|
4
|
+
icon?: Snippet;
|
|
5
|
+
content: Snippet;
|
|
6
|
+
colorScheme?: Partial<ContextMenu5ColorScheme>;
|
|
7
|
+
ariaLabel?: string;
|
|
8
|
+
menuAlign?: 'left' | 'right';
|
|
9
|
+
open?: boolean;
|
|
10
|
+
};
|
|
11
|
+
declare const ContextMenu5: import("svelte").Component<$$ComponentProps, {}, "open">;
|
|
12
|
+
type ContextMenu5 = ReturnType<typeof ContextMenu5>;
|
|
13
|
+
export default ContextMenu5;
|
package/dist/DatePicker5.svelte
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import {
|
|
2
|
+
import { BROWSER } from 'esm-env';
|
|
3
3
|
import { fly } from 'svelte/transition';
|
|
4
4
|
import type { DatePicker5ColorScheme } from './types.js';
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* Date Picker 5 v0.0.1
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
6
|
let {
|
|
11
7
|
colorScheme: partialColorScheme = {},
|
|
12
8
|
title = '',
|
|
@@ -123,7 +119,7 @@
|
|
|
123
119
|
|
|
124
120
|
// Close dropdown when clicking outside
|
|
125
121
|
$effect(() => {
|
|
126
|
-
if (!
|
|
122
|
+
if (!BROWSER || !showDropdown) return;
|
|
127
123
|
|
|
128
124
|
const handleClickOutside = (event: MouseEvent) => {
|
|
129
125
|
const target = event.target as Node;
|
|
@@ -149,7 +145,7 @@
|
|
|
149
145
|
// Auto-scroll to make dropdown fully visible
|
|
150
146
|
|
|
151
147
|
$effect(() => {
|
|
152
|
-
if (!
|
|
148
|
+
if (!BROWSER || !showDropdown || !dropdownRef) return;
|
|
153
149
|
setTimeout(() => {
|
|
154
150
|
if (!dropdownRef) return;
|
|
155
151
|
const dropdownRect = dropdownRef.getBoundingClientRect();
|
package/dist/DropDown5.svelte
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import {
|
|
2
|
+
import { BROWSER } from 'esm-env';
|
|
3
3
|
import { onDestroy, onMount } from 'svelte';
|
|
4
4
|
import { fly } from 'svelte/transition';
|
|
5
5
|
import type { DropDown5ColorScheme, DropDownItem } from './types.js';
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
let filteredItems: DropDownItem[] = $state([]);
|
|
48
48
|
|
|
49
49
|
$effect(() => {
|
|
50
|
-
if (!
|
|
50
|
+
if (!BROWSER || !showDropdown || !dropdownRef) return;
|
|
51
51
|
setTimeout(() => {
|
|
52
52
|
if (!dropdownRef) return;
|
|
53
53
|
const dropdownRect = dropdownRef.getBoundingClientRect();
|
package/dist/index.d.ts
CHANGED
|
@@ -6,8 +6,9 @@ import Accordion5 from "./Accordion5.svelte";
|
|
|
6
6
|
import Chart5 from "./Chart5.svelte";
|
|
7
7
|
import AdminPanel5 from "./AdminPanel5.svelte";
|
|
8
8
|
import Checkbox5 from "./Checkbox5.svelte";
|
|
9
|
-
import
|
|
9
|
+
import ContextMenu5 from "./ContextMenu5.svelte";
|
|
10
|
+
import type { Input5ColorScheme, DatePicker5ColorScheme, TimePicker5ColorScheme, DropDownItem, DropDown5ColorScheme, Accordion5ColorScheme, Chart5ColorScheme, AdminPanel5ColorScheme, BottomSheet5ColorScheme, Dialog5ColorScheme, Checkbox5ColorScheme, ContextMenu5ColorScheme } from "./types.js";
|
|
10
11
|
import BottomSheet5 from "./BottomSheet5.svelte";
|
|
11
12
|
import Dialog5 from "./Dialog5.svelte";
|
|
12
|
-
export { DatePicker5, Input5, DropDown5, TimePicker5, Accordion5, Chart5, AdminPanel5, BottomSheet5, Dialog5, Checkbox5 };
|
|
13
|
-
export type { Input5ColorScheme, DatePicker5ColorScheme, TimePicker5ColorScheme, Accordion5ColorScheme, DropDown5ColorScheme, DropDownItem, Chart5ColorScheme, AdminPanel5ColorScheme, BottomSheet5ColorScheme, Dialog5ColorScheme, Checkbox5ColorScheme };
|
|
13
|
+
export { DatePicker5, Input5, DropDown5, TimePicker5, Accordion5, Chart5, AdminPanel5, BottomSheet5, Dialog5, Checkbox5, ContextMenu5 };
|
|
14
|
+
export type { Input5ColorScheme, DatePicker5ColorScheme, TimePicker5ColorScheme, Accordion5ColorScheme, DropDown5ColorScheme, DropDownItem, Chart5ColorScheme, AdminPanel5ColorScheme, BottomSheet5ColorScheme, Dialog5ColorScheme, Checkbox5ColorScheme, ContextMenu5ColorScheme };
|
package/dist/index.js
CHANGED
|
@@ -9,4 +9,5 @@ import AdminPanel5 from "./AdminPanel5.svelte";
|
|
|
9
9
|
import BottomSheet5 from "./BottomSheet5.svelte";
|
|
10
10
|
import Dialog5 from "./Dialog5.svelte";
|
|
11
11
|
import Checkbox5 from "./Checkbox5.svelte";
|
|
12
|
-
|
|
12
|
+
import ContextMenu5 from "./ContextMenu5.svelte"
|
|
13
|
+
export { DatePicker5, Input5, DropDown5, TimePicker5, Accordion5, Chart5, AdminPanel5, BottomSheet5, Dialog5, Checkbox5, ContextMenu5 };
|
package/dist/types.d.ts
CHANGED
|
@@ -98,3 +98,11 @@ export interface Checkbox5ColorScheme {
|
|
|
98
98
|
focusedColor?: string;
|
|
99
99
|
checkmarkColor?: string;
|
|
100
100
|
}
|
|
101
|
+
|
|
102
|
+
export interface ContextMenu5ColorScheme {
|
|
103
|
+
contentBgColor?: string;
|
|
104
|
+
contentBorderColor?: string;
|
|
105
|
+
iconFillColor?: string;
|
|
106
|
+
iconBorderColor?: string;
|
|
107
|
+
iconColor?: string;
|
|
108
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@djcali570/component-lib",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.92",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist",
|
|
6
6
|
"!dist/**/*.test.*",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
|
+
"@sveltejs/kit": "^2.50.2",
|
|
22
23
|
"svelte": "^5.0.0"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
@@ -60,5 +61,8 @@
|
|
|
60
61
|
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
|
61
62
|
"format": "prettier --write .",
|
|
62
63
|
"lint": "prettier --check . && eslint ."
|
|
64
|
+
},
|
|
65
|
+
"dependencies": {
|
|
66
|
+
"esm-env": "^1.2.2"
|
|
63
67
|
}
|
|
64
68
|
}
|