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.
@@ -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,4 @@
1
+ import type { ISheetProps } from './Sheet.types';
2
+ declare const Sheet: import("svelte").Component<ISheetProps, {}, "">;
3
+ type Sheet = ReturnType<typeof Sheet>;
4
+ export default Sheet;
@@ -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,4 @@
1
+ import type { ISheetActionsProps } from './Sheet.types';
2
+ declare const SheetActions: import("svelte").Component<ISheetActionsProps, {}, "">;
3
+ type SheetActions = ReturnType<typeof SheetActions>;
4
+ export default SheetActions;
@@ -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,4 @@
1
+ import type { ISheetContentProps } from "./Sheet.types";
2
+ declare const SheetContent: import("svelte").Component<ISheetContentProps, {}, "">;
3
+ type SheetContent = ReturnType<typeof SheetContent>;
4
+ export default SheetContent;
@@ -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,4 @@
1
+ import type { ISheetDescriptionProps } from "./Sheet.types";
2
+ declare const SheetDescription: import("svelte").Component<ISheetDescriptionProps, {}, "">;
3
+ type SheetDescription = ReturnType<typeof SheetDescription>;
4
+ export default SheetDescription;
@@ -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,4 @@
1
+ import type { ISheetHeaderProps } from "./Sheet.types";
2
+ declare const SheetHeader: import("svelte").Component<ISheetHeaderProps, {}, "">;
3
+ type SheetHeader = ReturnType<typeof SheetHeader>;
4
+ export default SheetHeader;
@@ -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,4 @@
1
+ import type { ISheetTitleProps } from './Sheet.types';
2
+ declare const SheetTitle: import("svelte").Component<ISheetTitleProps, {}, "">;
3
+ type SheetTitle = ReturnType<typeof SheetTitle>;
4
+ export default SheetTitle;
@@ -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';
@@ -18,3 +18,4 @@ export * from './Select';
18
18
  export * from './Icon';
19
19
  export * from './Checkbox';
20
20
  export * from './CheckboxGroup';
21
+ export * from './Sheet';
@@ -18,3 +18,4 @@ export * from './Select';
18
18
  export * from './Icon';
19
19
  export * from './Checkbox';
20
20
  export * from './CheckboxGroup';
21
+ export * from './Sheet';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "milk-lib",
3
3
  "license": "MIT",
4
- "version": "0.0.24",
4
+ "version": "0.0.27",
5
5
  "scripts": {
6
6
  "dev": "vite dev",
7
7
  "build": "vite build && npm run prepack",