milk-lib 0.0.1 → 0.0.2
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/README.md +2 -57
- package/dist/assets/favicon.svg +4 -0
- package/dist/components/Menu/Menu.css +0 -0
- package/dist/components/Menu/Menu.svelte +114 -0
- package/dist/components/Menu/Menu.svelte.d.ts +4 -0
- package/dist/components/Menu/Menu.types.d.ts +25 -0
- package/dist/components/Menu/Menu.types.js +1 -0
- package/dist/components/Menu/MenuContent.svelte +18 -0
- package/dist/components/Menu/MenuContent.svelte.d.ts +4 -0
- package/dist/components/Menu/MenuItem.svelte +22 -0
- package/dist/components/Menu/MenuItem.svelte.d.ts +4 -0
- package/dist/components/Menu/MenuItemTitle.svelte +21 -0
- package/dist/components/Menu/MenuItemTitle.svelte.d.ts +4 -0
- package/dist/components/Menu/index.d.ts +5 -0
- package/dist/components/Menu/index.js +5 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +2 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/styles/index.scss +1 -0
- package/dist/styles/typography.scss +6 -0
- package/dist/utils/click-outside-handler.d.ts +2 -0
- package/dist/utils/click-outside-handler.js +16 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/package.json +5 -2
- /package/dist/{TestComponent → components/TestComponent}/TestComponent.svelte +0 -0
- /package/dist/{TestComponent → components/TestComponent}/TestComponent.svelte.d.ts +0 -0
- /package/dist/{TestComponent → components/TestComponent}/index.d.ts +0 -0
- /package/dist/{TestComponent → components/TestComponent}/index.js +0 -0
package/README.md
CHANGED
|
@@ -1,58 +1,3 @@
|
|
|
1
|
-
#
|
|
1
|
+
# MilkLib Sveltekit components library
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Read more about creating a library [in the docs](https://svelte.dev/docs/kit/packaging).
|
|
6
|
-
|
|
7
|
-
## Creating a project
|
|
8
|
-
|
|
9
|
-
If you're seeing this, you've probably already done this step. Congrats!
|
|
10
|
-
|
|
11
|
-
```sh
|
|
12
|
-
# create a new project in the current directory
|
|
13
|
-
npx sv create
|
|
14
|
-
|
|
15
|
-
# create a new project in my-app
|
|
16
|
-
npx sv create my-app
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## Developing
|
|
20
|
-
|
|
21
|
-
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
|
|
22
|
-
|
|
23
|
-
```sh
|
|
24
|
-
npm run dev
|
|
25
|
-
|
|
26
|
-
# or start the server and open the app in a new browser tab
|
|
27
|
-
npm run dev -- --open
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
Everything inside `src/lib` is part of your library, everything inside `src/routes` can be used as a showcase or preview app.
|
|
31
|
-
|
|
32
|
-
## Building
|
|
33
|
-
|
|
34
|
-
To build your library:
|
|
35
|
-
|
|
36
|
-
```sh
|
|
37
|
-
npm pack
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
To create a production version of your showcase app:
|
|
41
|
-
|
|
42
|
-
```sh
|
|
43
|
-
npm run build
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
You can preview the production build with `npm run preview`.
|
|
47
|
-
|
|
48
|
-
> To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment.
|
|
49
|
-
|
|
50
|
-
## Publishing
|
|
51
|
-
|
|
52
|
-
Go into the `package.json` and give your package the desired name through the `"name"` option. Also consider adding a `"license"` field and point it to a `LICENSE` file which you can create from a template (one popular option is the [MIT license](https://opensource.org/license/mit/)).
|
|
53
|
-
|
|
54
|
-
To publish your library to [npm](https://www.npmjs.com):
|
|
55
|
-
|
|
56
|
-
```sh
|
|
57
|
-
npm publish
|
|
58
|
-
```
|
|
3
|
+
Sveltekit library, powered by [`sv`](https://npmjs.com/package/sv).
|
|
File without changes
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
|
|
3
|
+
import { onMount, onDestroy } from "svelte";
|
|
4
|
+
import { browser } from "$app/environment";
|
|
5
|
+
import { clickOutsideObject } from "../..";
|
|
6
|
+
import type { IMenuProps } from "./Menu.types";
|
|
7
|
+
|
|
8
|
+
let {
|
|
9
|
+
hideMenu,
|
|
10
|
+
parentElement,
|
|
11
|
+
menuGap = 6,
|
|
12
|
+
appearanceOnHover = false,
|
|
13
|
+
isVisible = false,
|
|
14
|
+
menuElement = $bindable(),
|
|
15
|
+
maxHeight = 200,
|
|
16
|
+
width = 0,
|
|
17
|
+
fullWidth,
|
|
18
|
+
minWidth = 320,
|
|
19
|
+
id,
|
|
20
|
+
children
|
|
21
|
+
}: IMenuProps = $props();
|
|
22
|
+
|
|
23
|
+
let y = $state(0);
|
|
24
|
+
let innerWidth = $state(0);
|
|
25
|
+
let innerHeight = $state(0);
|
|
26
|
+
let scrollY = $state(0);
|
|
27
|
+
|
|
28
|
+
const calculatePosition = (parentEl: HTMLElement | null) => {
|
|
29
|
+
const boundingClientRect = parentEl?.getBoundingClientRect();
|
|
30
|
+
y = (boundingClientRect?.height || 0);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const mouseLeaveHandler = (e: MouseEvent) => {
|
|
34
|
+
if ((e.relatedTarget !== parentElement) && appearanceOnHover) {
|
|
35
|
+
hideMenu();
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const handleClickOutside = (event: MouseEvent) => {
|
|
40
|
+
clickOutsideObject(event, menuElement as HTMLElement, null, () => hideMenu());
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
onMount(() => {
|
|
44
|
+
if (!appearanceOnHover && browser) {
|
|
45
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
46
|
+
}
|
|
47
|
+
calculatePosition(parentElement);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
onDestroy(() => {
|
|
51
|
+
if (!appearanceOnHover && browser) {
|
|
52
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
$effect(() => {
|
|
57
|
+
if (innerWidth && innerHeight) {
|
|
58
|
+
calculatePosition(parentElement);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
$effect(() => {
|
|
63
|
+
if (isVisible) {
|
|
64
|
+
calculatePosition(parentElement);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
</script>
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
<svelte:window bind:innerWidth bind:innerHeight bind:scrollY />
|
|
72
|
+
|
|
73
|
+
{#if isVisible}
|
|
74
|
+
<div
|
|
75
|
+
{id}
|
|
76
|
+
role="menu"
|
|
77
|
+
tabindex="0"
|
|
78
|
+
onmouseleave={mouseLeaveHandler}
|
|
79
|
+
bind:this={menuElement}
|
|
80
|
+
class="Menu"
|
|
81
|
+
style={`
|
|
82
|
+
top: ${y}px;
|
|
83
|
+
width: ${fullWidth ? '100%' : width ? width + "px" : "auto"};
|
|
84
|
+
min-width: ${minWidth ? minWidth + "px" : "auto"};
|
|
85
|
+
max-height: ${maxHeight}px;
|
|
86
|
+
`}
|
|
87
|
+
>
|
|
88
|
+
<div style={`padding-top: ${menuGap}px`}>
|
|
89
|
+
{@render children()}
|
|
90
|
+
</div>
|
|
91
|
+
</div>
|
|
92
|
+
{/if}
|
|
93
|
+
|
|
94
|
+
<style>
|
|
95
|
+
.Menu {
|
|
96
|
+
position: absolute;
|
|
97
|
+
z-index: var(--zindex-dropdown);
|
|
98
|
+
top: 0;
|
|
99
|
+
left: 0;
|
|
100
|
+
margin: 0;
|
|
101
|
+
padding: 0;
|
|
102
|
+
list-style: none;
|
|
103
|
+
display: flex;
|
|
104
|
+
flex-direction: column;
|
|
105
|
+
gap: 0;
|
|
106
|
+
justify-content: space-between;
|
|
107
|
+
cursor: default;
|
|
108
|
+
|
|
109
|
+
&:focus-visible {
|
|
110
|
+
outline: none;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
</style>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
export interface IMenuProps {
|
|
3
|
+
hideMenu: () => void;
|
|
4
|
+
isVisible?: boolean;
|
|
5
|
+
menuElement?: HTMLDivElement | null;
|
|
6
|
+
parentElement: HTMLElement | null;
|
|
7
|
+
appearanceOnHover?: boolean;
|
|
8
|
+
menuGap?: number;
|
|
9
|
+
maxHeight?: number;
|
|
10
|
+
width?: number;
|
|
11
|
+
minWidth?: number;
|
|
12
|
+
fullWidth?: boolean;
|
|
13
|
+
id?: string;
|
|
14
|
+
children: Snippet;
|
|
15
|
+
}
|
|
16
|
+
export interface IMenuContentProps {
|
|
17
|
+
children: Snippet;
|
|
18
|
+
}
|
|
19
|
+
export interface IMenuItemTitleProps {
|
|
20
|
+
children: Snippet;
|
|
21
|
+
}
|
|
22
|
+
export interface IMenuItemProps {
|
|
23
|
+
onClick?: () => unknown;
|
|
24
|
+
children: Snippet;
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { IMenuContentProps } from './Menu.types';
|
|
3
|
+
let { children } : IMenuContentProps = $props();
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
|
+
<div class="MenuContent">
|
|
7
|
+
{@render children()}
|
|
8
|
+
</div>
|
|
9
|
+
|
|
10
|
+
<style>
|
|
11
|
+
.MenuContent {
|
|
12
|
+
border: 1px solid #ddd;
|
|
13
|
+
padding: .25rem;
|
|
14
|
+
background-color: white;
|
|
15
|
+
border-radius: 12px;
|
|
16
|
+
box-shadow: 0 0 40px rgba(0, 0, 0, 0.09);
|
|
17
|
+
}
|
|
18
|
+
</style>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { IMenuItemProps } from './Menu.types';
|
|
3
|
+
let { children, onClick } : IMenuItemProps = $props();
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
|
+
<div class="MenuItem" onclick={() => onClick?.()} role="listbox" tabindex="-1" onkeydown={() => null}>
|
|
7
|
+
{@render children()}
|
|
8
|
+
</div>
|
|
9
|
+
|
|
10
|
+
<style>
|
|
11
|
+
.MenuItem {
|
|
12
|
+
padding: 0.5rem;
|
|
13
|
+
border-radius: 8px;
|
|
14
|
+
cursor: pointer;
|
|
15
|
+
display: block;
|
|
16
|
+
width: 100%;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.MenuItem:hover {
|
|
20
|
+
background: #ccc;
|
|
21
|
+
}
|
|
22
|
+
</style>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { IMenuItemTitleProps } from './Menu.types';
|
|
3
|
+
let { children } : IMenuItemTitleProps = $props();
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
|
+
<h3 class="MenuItemTitle">
|
|
7
|
+
{@render children()}
|
|
8
|
+
</h3>
|
|
9
|
+
|
|
10
|
+
<style>
|
|
11
|
+
.MenuItemTitle {
|
|
12
|
+
padding: 0.5rem 0.5rem 0 0.5rem;
|
|
13
|
+
margin: 0 0 0.5rem 0;
|
|
14
|
+
font-size: 14px;
|
|
15
|
+
line-height: 20px;
|
|
16
|
+
text-transform: uppercase;
|
|
17
|
+
letter-spacing: 0.5px;
|
|
18
|
+
font-weight: 500;
|
|
19
|
+
color: #777;
|
|
20
|
+
}
|
|
21
|
+
</style>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { default as Menu } from './Menu.svelte';
|
|
2
|
+
export * from './Menu.types';
|
|
3
|
+
export { default as MenuContent } from './MenuContent.svelte';
|
|
4
|
+
export { default as MenuItem } from './MenuItem.svelte';
|
|
5
|
+
export { default as MenuItemTitle } from './MenuItemTitle.svelte';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { default as Menu } from './Menu.svelte';
|
|
2
|
+
export * from './Menu.types';
|
|
3
|
+
export { default as MenuContent } from './MenuContent.svelte';
|
|
4
|
+
export { default as MenuItem } from './MenuItem.svelte';
|
|
5
|
+
export { default as MenuItemTitle } from './MenuItemTitle.svelte';
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './components';
|
|
2
|
+
export * from './utils';
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@forward "./typography.scss";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Mostly we are using clickOutsideObject
|
|
3
|
+
// because className can't be unique
|
|
4
|
+
export const clickOutsideHandler = (event, className, handler) => {
|
|
5
|
+
if (!(event.target.closest('.' + className))) {
|
|
6
|
+
handler?.();
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
export const clickOutsideObject = (event, element, exclusion, handler) => {
|
|
10
|
+
const target = event.target;
|
|
11
|
+
if (!exclusion?.contains(target)) {
|
|
12
|
+
if (!(element?.contains(target)) || target.nodeName === 'BODY') {
|
|
13
|
+
handler?.();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './click-outside-handler';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './click-outside-handler';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "milk-lib",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.2",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "vite dev",
|
|
7
7
|
"build": "vite build && npm run prepack",
|
|
@@ -63,5 +63,8 @@
|
|
|
63
63
|
},
|
|
64
64
|
"keywords": [
|
|
65
65
|
"svelte"
|
|
66
|
-
]
|
|
66
|
+
],
|
|
67
|
+
"dependencies": {
|
|
68
|
+
"sass": "^1.93.2"
|
|
69
|
+
}
|
|
67
70
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|