milk-lib 0.0.24 → 0.0.27
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/components/Sheet/Sheet.svelte +109 -0
- package/dist/components/Sheet/Sheet.svelte.d.ts +4 -0
- package/dist/components/Sheet/Sheet.types.d.ts +24 -0
- package/dist/components/Sheet/Sheet.types.js +1 -0
- package/dist/components/Sheet/SheetActions.svelte +28 -0
- package/dist/components/Sheet/SheetActions.svelte.d.ts +4 -0
- package/dist/components/Sheet/SheetContent.svelte +13 -0
- package/dist/components/Sheet/SheetContent.svelte.d.ts +4 -0
- package/dist/components/Sheet/SheetDescription.svelte +13 -0
- package/dist/components/Sheet/SheetDescription.svelte.d.ts +4 -0
- package/dist/components/Sheet/SheetHeader.svelte +13 -0
- package/dist/components/Sheet/SheetHeader.svelte.d.ts +4 -0
- package/dist/components/Sheet/SheetTitle.svelte +13 -0
- package/dist/components/Sheet/SheetTitle.svelte.d.ts +4 -0
- package/dist/components/Sheet/index.d.ts +6 -0
- package/dist/components/Sheet/index.js +6 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
TODO: Сейчас при смене пропса side на лету анимация слегка корявая
|
|
3
|
+
Нужно будет подумать как ее сделать поприятнее.
|
|
4
|
+
-->
|
|
5
|
+
|
|
6
|
+
<script lang="ts">
|
|
7
|
+
import { clickOutsideObject } from '../..';
|
|
8
|
+
import Portal from '../Portal/Portal.svelte';
|
|
9
|
+
import type { ISheetProps } from './Sheet.types';
|
|
10
|
+
import { onDestroy, onMount } from "svelte";
|
|
11
|
+
import { browser } from "$app/environment";
|
|
12
|
+
|
|
13
|
+
let { children, isOpen, hide, hideOnClickOutside, side = 'right' }: ISheetProps = $props();
|
|
14
|
+
|
|
15
|
+
let sheetElement = $state<HTMLDivElement | null>(null)
|
|
16
|
+
let shouldRender = $state(isOpen);
|
|
17
|
+
|
|
18
|
+
const sheetClassNames = $derived(`Sheet Sheet-${side}`);
|
|
19
|
+
|
|
20
|
+
const handleClickOutside = (event: MouseEvent) => {
|
|
21
|
+
clickOutsideObject(event, sheetElement as HTMLElement, null, () => hide?.());
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
onMount(() => {
|
|
25
|
+
if (browser && hideOnClickOutside) {
|
|
26
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
onDestroy(() => {
|
|
31
|
+
if (browser && hideOnClickOutside) {
|
|
32
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
$effect(() => {
|
|
37
|
+
if (isOpen) {
|
|
38
|
+
shouldRender = true;
|
|
39
|
+
|
|
40
|
+
const timeout = setTimeout(() => {
|
|
41
|
+
if (sheetElement) {
|
|
42
|
+
sheetElement.classList.add('Sheet-open');
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return () => clearTimeout(timeout);
|
|
46
|
+
|
|
47
|
+
} else {
|
|
48
|
+
if (sheetElement) {
|
|
49
|
+
sheetElement.classList.remove('Sheet-open');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const handleTransitionEnd = (e: TransitionEvent) => {
|
|
55
|
+
e.stopPropagation();
|
|
56
|
+
if (!isOpen) {
|
|
57
|
+
if (e.propertyName === 'transform') {
|
|
58
|
+
console.log('hide');
|
|
59
|
+
shouldRender = false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
</script>
|
|
65
|
+
|
|
66
|
+
<Portal>
|
|
67
|
+
{#if shouldRender}
|
|
68
|
+
<div
|
|
69
|
+
class={sheetClassNames}
|
|
70
|
+
bind:this={sheetElement}
|
|
71
|
+
ontransitionend={handleTransitionEnd}
|
|
72
|
+
>
|
|
73
|
+
{@render children()}
|
|
74
|
+
</div>
|
|
75
|
+
{/if}
|
|
76
|
+
</Portal>
|
|
77
|
+
|
|
78
|
+
<style>.Sheet {
|
|
79
|
+
position: fixed;
|
|
80
|
+
z-index: var(--zindex-sheet);
|
|
81
|
+
top: 0;
|
|
82
|
+
height: 100vh;
|
|
83
|
+
background: white;
|
|
84
|
+
width: 400px;
|
|
85
|
+
box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
|
|
86
|
+
opacity: 0;
|
|
87
|
+
transition: all 0.3s ease-in-out;
|
|
88
|
+
}
|
|
89
|
+
@media (max-width: 400px) {
|
|
90
|
+
.Sheet {
|
|
91
|
+
width: 100%;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
.Sheet.Sheet-right {
|
|
95
|
+
right: 0;
|
|
96
|
+
left: auto;
|
|
97
|
+
border-left: 1px solid var(--line-base);
|
|
98
|
+
transform: translateX(110%);
|
|
99
|
+
}
|
|
100
|
+
.Sheet.Sheet-left {
|
|
101
|
+
left: 0;
|
|
102
|
+
right: auto;
|
|
103
|
+
border-right: 1px solid var(--line-base);
|
|
104
|
+
transform: translateX(-110%);
|
|
105
|
+
}
|
|
106
|
+
.Sheet.Sheet-open {
|
|
107
|
+
transform: translateX(0);
|
|
108
|
+
opacity: 1;
|
|
109
|
+
}</style>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Snippet } from "svelte";
|
|
2
|
+
export interface ISheetProps {
|
|
3
|
+
children: Snippet;
|
|
4
|
+
isOpen: boolean;
|
|
5
|
+
hide?: () => unknown;
|
|
6
|
+
hideOnClickOutside?: boolean;
|
|
7
|
+
side?: 'left' | 'right';
|
|
8
|
+
}
|
|
9
|
+
export interface ISheetHeaderProps {
|
|
10
|
+
children: Snippet;
|
|
11
|
+
}
|
|
12
|
+
export interface ISheetDescriptionProps {
|
|
13
|
+
children: Snippet;
|
|
14
|
+
}
|
|
15
|
+
export interface ISheetContentProps {
|
|
16
|
+
children: Snippet;
|
|
17
|
+
}
|
|
18
|
+
export interface ISheetActionsProps {
|
|
19
|
+
children: Snippet;
|
|
20
|
+
hide?: () => unknown;
|
|
21
|
+
}
|
|
22
|
+
export interface ISheetTitleProps {
|
|
23
|
+
children: Snippet;
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { ButtonMilk } from "../..";
|
|
3
|
+
import type { ISheetActionsProps } from './Sheet.types';
|
|
4
|
+
import { CloseLargeLineSystem } from "svelte-remix";
|
|
5
|
+
let { children, hide }: ISheetActionsProps = $props();
|
|
6
|
+
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<div class="SheetActions">
|
|
10
|
+
{@render children()}
|
|
11
|
+
{#if hide}
|
|
12
|
+
<div class="SheetActions-hide">
|
|
13
|
+
<ButtonMilk onClick={hide} iconButton variant="base-contained" size="sm">
|
|
14
|
+
<CloseLargeLineSystem size="1em"/>
|
|
15
|
+
</ButtonMilk>
|
|
16
|
+
</div>
|
|
17
|
+
{/if}
|
|
18
|
+
</div>
|
|
19
|
+
|
|
20
|
+
<style>.SheetActions {
|
|
21
|
+
padding: 0.5rem;
|
|
22
|
+
border-bottom: 1px solid var(--line-base);
|
|
23
|
+
}
|
|
24
|
+
.SheetActions .SheetActions-hide {
|
|
25
|
+
position: absolute;
|
|
26
|
+
right: 0.5rem;
|
|
27
|
+
top: 0.5rem;
|
|
28
|
+
}</style>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { ISheetContentProps } from "./Sheet.types";
|
|
3
|
+
|
|
4
|
+
let { children }: ISheetContentProps = $props();
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<div class="SheetContent">
|
|
8
|
+
{@render children()}
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
<style>.SheetContent {
|
|
12
|
+
padding: 0.5rem 1.5rem;
|
|
13
|
+
}</style>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type {ISheetDescriptionProps} from "./Sheet.types";
|
|
3
|
+
|
|
4
|
+
let { children }: ISheetDescriptionProps = $props();
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<div class="SheetDescription">
|
|
8
|
+
{@render children()}
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
<style>.SheetDescription {
|
|
12
|
+
color: var(--text-base-muted);
|
|
13
|
+
}</style>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type {ISheetHeaderProps} from "./Sheet.types";
|
|
3
|
+
|
|
4
|
+
let { children }: ISheetHeaderProps = $props();
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<div class="SheetHeader">
|
|
8
|
+
{@render children()}
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
<style>.SheetHeader {
|
|
12
|
+
padding: 1.5rem 1.5rem 0.5rem;
|
|
13
|
+
}</style>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { ISheetTitleProps } from './Sheet.types';
|
|
3
|
+
let { children } : ISheetTitleProps = $props();
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
|
+
<h2 class="SheetTitle">
|
|
7
|
+
{@render children()}
|
|
8
|
+
</h2>
|
|
9
|
+
|
|
10
|
+
<style>.SheetTitle {
|
|
11
|
+
font-size: var(--font-size-h2);
|
|
12
|
+
font-weight: 500;
|
|
13
|
+
}</style>
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default as Sheet } from './Sheet.svelte';
|
|
2
|
+
export { default as SheetHeader } from './SheetHeader.svelte';
|
|
3
|
+
export { default as SheetActions } from './SheetActions.svelte';
|
|
4
|
+
export { default as SheetTitle } from './SheetTitle.svelte';
|
|
5
|
+
export { default as SheetContent } from './SheetContent.svelte';
|
|
6
|
+
export { default as SheetDescription } from './SheetDescription.svelte';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default as Sheet } from './Sheet.svelte';
|
|
2
|
+
export { default as SheetHeader } from './SheetHeader.svelte';
|
|
3
|
+
export { default as SheetActions } from './SheetActions.svelte';
|
|
4
|
+
export { default as SheetTitle } from './SheetTitle.svelte';
|
|
5
|
+
export { default as SheetContent } from './SheetContent.svelte';
|
|
6
|
+
export { default as SheetDescription } from './SheetDescription.svelte';
|
package/dist/components/index.js
CHANGED