milk-lib 0.0.35 → 0.0.37
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/Accordion/Accordion.types.d.ts +25 -0
- package/dist/components/Accordion/Accordion.types.js +1 -0
- package/dist/components/Accordion/AccordionContent.svelte +30 -0
- package/dist/components/Accordion/AccordionContent.svelte.d.ts +4 -0
- package/dist/components/Accordion/AccordionItem.svelte +27 -0
- package/dist/components/Accordion/AccordionItem.svelte.d.ts +4 -0
- package/dist/components/Accordion/AccordionRoot.svelte +22 -0
- package/dist/components/Accordion/AccordionRoot.svelte.d.ts +4 -0
- package/dist/components/Accordion/AccordionTrigger.svelte +41 -0
- package/dist/components/Accordion/AccordionTrigger.svelte.d.ts +4 -0
- package/dist/components/Accordion/index.d.ts +4 -0
- package/dist/components/Accordion/index.js +4 -0
- package/dist/components/CheckboxGroup/CheckboxGroup.svelte +22 -16
- package/dist/components/CheckboxGroup/CheckboxGroup.types.d.ts +1 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Snippet } from "svelte";
|
|
2
|
+
import type { Writable } from "svelte/store";
|
|
3
|
+
export interface IAccordionProps {
|
|
4
|
+
children: Snippet;
|
|
5
|
+
value: string | null;
|
|
6
|
+
}
|
|
7
|
+
export interface IAccordionItemProps {
|
|
8
|
+
children: Snippet;
|
|
9
|
+
value: string | null;
|
|
10
|
+
}
|
|
11
|
+
export interface IAccordionTriggerProps {
|
|
12
|
+
children: Snippet;
|
|
13
|
+
}
|
|
14
|
+
export interface IAccordionContentProps {
|
|
15
|
+
children: Snippet;
|
|
16
|
+
}
|
|
17
|
+
export interface IAccordionContext {
|
|
18
|
+
value: Writable<string | null>;
|
|
19
|
+
open: (val: string | null) => unknown;
|
|
20
|
+
close: () => unknown;
|
|
21
|
+
}
|
|
22
|
+
export interface IAccordionItemContext {
|
|
23
|
+
isOpen: Writable<boolean>;
|
|
24
|
+
value: string | null;
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { getContext } from "svelte";
|
|
3
|
+
import type {IAccordionContentProps, IAccordionItemContext} from "./Accordion.types";
|
|
4
|
+
|
|
5
|
+
let { children }: IAccordionContentProps = $props();
|
|
6
|
+
const { isOpen } = getContext<IAccordionItemContext>('accordion-item-context');
|
|
7
|
+
let accordionContent: HTMLDivElement | null = $state(null);
|
|
8
|
+
let height = $derived<number>(
|
|
9
|
+
accordionContent
|
|
10
|
+
? (accordionContent as HTMLDivElement).getBoundingClientRect?.().height
|
|
11
|
+
: 0
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<div class="AccordionContentWrapper" style={`height: ${$isOpen ? height + 8 : 0}px`}>
|
|
17
|
+
<div class="AccordionContent" bind:this={accordionContent}>
|
|
18
|
+
{@render children()}
|
|
19
|
+
</div>
|
|
20
|
+
</div>
|
|
21
|
+
|
|
22
|
+
<style>.AccordionContent {
|
|
23
|
+
margin-bottom: 1em;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.AccordionContentWrapper {
|
|
27
|
+
overflow: hidden;
|
|
28
|
+
height: 0;
|
|
29
|
+
transition: all 0.3s ease-in-out;
|
|
30
|
+
}</style>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { setContext, getContext } from 'svelte';
|
|
3
|
+
import { writable } from 'svelte/store';
|
|
4
|
+
import type {IAccordionContext, IAccordionItemContext, IAccordionItemProps} from "./Accordion.types";
|
|
5
|
+
|
|
6
|
+
let { children, value }: IAccordionItemProps = $props();
|
|
7
|
+
const accordionState = getContext<IAccordionContext>('accordion-context');
|
|
8
|
+
|
|
9
|
+
let isOpen = writable(false);
|
|
10
|
+
let currentValue = $state<string | null>(null);
|
|
11
|
+
accordionState.value.subscribe((val: string | null) => currentValue = val);
|
|
12
|
+
setContext('accordion-item-context', { isOpen, value });
|
|
13
|
+
|
|
14
|
+
$effect(() => {
|
|
15
|
+
isOpen.set(value === currentValue);
|
|
16
|
+
setContext<IAccordionItemContext>('accordion-item-context', { isOpen, value });
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<div class="AccordionItem">
|
|
22
|
+
{@render children()}
|
|
23
|
+
</div>
|
|
24
|
+
|
|
25
|
+
<style>.AccordionItem {
|
|
26
|
+
border-bottom: 1px solid var(--line-base);
|
|
27
|
+
}</style>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { setContext } from "svelte";
|
|
3
|
+
import { writable } from 'svelte/store';
|
|
4
|
+
import type { IAccordionProps, IAccordionContext } from './Accordion.types';
|
|
5
|
+
|
|
6
|
+
let { children, value }: IAccordionProps = $props();
|
|
7
|
+
|
|
8
|
+
// Initialisation
|
|
9
|
+
const innerValue = writable<string | null>(value);
|
|
10
|
+
const open = (val: string | null) => innerValue.set(val);
|
|
11
|
+
const close = () => innerValue.set(null);
|
|
12
|
+
|
|
13
|
+
// Reactivity
|
|
14
|
+
// If value changed
|
|
15
|
+
$effect(() => innerValue.set(value));
|
|
16
|
+
|
|
17
|
+
setContext<IAccordionContext>('accordion-context', { value: innerValue, open, close });
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<div class="AccordionRoot">
|
|
21
|
+
{@render children()}
|
|
22
|
+
</div>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { getContext } from "svelte";
|
|
3
|
+
import { ArrowDownSLineArrows, ArrowUpSLineArrows } from 'svelte-remix';
|
|
4
|
+
import type {IAccordionTriggerProps, IAccordionItemContext, IAccordionContext} from './Accordion.types';
|
|
5
|
+
|
|
6
|
+
let { children }: IAccordionTriggerProps = $props();
|
|
7
|
+
|
|
8
|
+
const { isOpen, value } = getContext<IAccordionItemContext>('accordion-item-context');
|
|
9
|
+
const { open, close } = getContext<IAccordionContext>('accordion-context');
|
|
10
|
+
|
|
11
|
+
const handleClick = () => {
|
|
12
|
+
if ($isOpen) { close?.() } else { open?.(value) }
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<div class="AccordionTrigger">
|
|
18
|
+
<button class="AccordionTriggerButton" onclick={handleClick}>
|
|
19
|
+
<span class="flex">
|
|
20
|
+
{@render children()}
|
|
21
|
+
</span>
|
|
22
|
+
{#if $isOpen }
|
|
23
|
+
<ArrowUpSLineArrows size="1em"/>
|
|
24
|
+
{:else}
|
|
25
|
+
<ArrowDownSLineArrows size="1em"/>
|
|
26
|
+
{/if}
|
|
27
|
+
</button>
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
<style>.AccordionTriggerButton {
|
|
31
|
+
padding: 0.75em 0;
|
|
32
|
+
display: flex;
|
|
33
|
+
width: 100%;
|
|
34
|
+
justify-content: space-between;
|
|
35
|
+
transition: all 0.3s ease-in-out;
|
|
36
|
+
align-items: center;
|
|
37
|
+
cursor: pointer;
|
|
38
|
+
border: none;
|
|
39
|
+
background: var(--bg-base);
|
|
40
|
+
font-size: 1rem;
|
|
41
|
+
}</style>
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { default as AccordionRoot } from './AccordionRoot.svelte';
|
|
2
|
+
export { default as AccordionItem } from './AccordionItem.svelte';
|
|
3
|
+
export { default as AccordionTrigger } from './AccordionTrigger.svelte';
|
|
4
|
+
export { default as AccordionContent } from './AccordionContent.svelte';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { default as AccordionRoot } from './AccordionRoot.svelte';
|
|
2
|
+
export { default as AccordionItem } from './AccordionItem.svelte';
|
|
3
|
+
export { default as AccordionTrigger } from './AccordionTrigger.svelte';
|
|
4
|
+
export { default as AccordionContent } from './AccordionContent.svelte';
|
|
@@ -7,9 +7,17 @@
|
|
|
7
7
|
legend = 'Choose options',
|
|
8
8
|
options = [] as CheckboxGroupItem[],
|
|
9
9
|
selectedValues = $bindable([] as string[]),
|
|
10
|
-
name
|
|
10
|
+
name,
|
|
11
|
+
maxHeight
|
|
11
12
|
}: CheckboxGroupProps = $props();
|
|
12
13
|
|
|
14
|
+
const maxHeightValue = $derived.by(() => {
|
|
15
|
+
if (maxHeight === undefined || maxHeight === null || maxHeight === '') {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
return typeof maxHeight === 'number' ? `${maxHeight}px` : maxHeight;
|
|
19
|
+
});
|
|
20
|
+
|
|
13
21
|
function handleOptionToggle(value: string) {
|
|
14
22
|
toggleOption(value);
|
|
15
23
|
}
|
|
@@ -28,7 +36,12 @@
|
|
|
28
36
|
<legend>{legend}</legend>
|
|
29
37
|
{/if}
|
|
30
38
|
|
|
31
|
-
<ul
|
|
39
|
+
<ul
|
|
40
|
+
class="checkbox-list"
|
|
41
|
+
class:scrollable={Boolean(maxHeightValue)}
|
|
42
|
+
style={`max-height: ${maxHeightValue || 'auto'};`}
|
|
43
|
+
|
|
44
|
+
>
|
|
32
45
|
{#if options.length === 0}
|
|
33
46
|
<li class="checkbox-placeholder">No option for choice</li>
|
|
34
47
|
{:else}
|
|
@@ -63,14 +76,14 @@
|
|
|
63
76
|
{/if}
|
|
64
77
|
</ul>
|
|
65
78
|
|
|
66
|
-
<div class="checkbox-selected">
|
|
79
|
+
<!-- <div class="checkbox-selected">
|
|
67
80
|
<strong>Selected:</strong>
|
|
68
81
|
{#if selectedValues.length === 0}
|
|
69
82
|
<span>nothing</span>
|
|
70
83
|
{:else}
|
|
71
84
|
<span>{selectedValues.join(', ')}</span>
|
|
72
85
|
{/if}
|
|
73
|
-
</div>
|
|
86
|
+
</div> -->
|
|
74
87
|
</fieldset>
|
|
75
88
|
|
|
76
89
|
<style>.checkbox-group {
|
|
@@ -98,6 +111,11 @@ legend {
|
|
|
98
111
|
gap: 8px;
|
|
99
112
|
}
|
|
100
113
|
|
|
114
|
+
.checkbox-list.scrollable {
|
|
115
|
+
overflow-y: auto;
|
|
116
|
+
min-height: 0;
|
|
117
|
+
}
|
|
118
|
+
|
|
101
119
|
.checkbox-placeholder {
|
|
102
120
|
color: var(--text-base-placeholder, #7c7c7c);
|
|
103
121
|
font-size: 14px;
|
|
@@ -137,16 +155,4 @@ legend {
|
|
|
137
155
|
display: block;
|
|
138
156
|
color: var(--text-base-placeholder, #7c7c7c);
|
|
139
157
|
font-size: 12px;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
.checkbox-selected {
|
|
143
|
-
font-size: 13px;
|
|
144
|
-
color: var(--text-base-placeholder, #7c7c7c);
|
|
145
|
-
display: flex;
|
|
146
|
-
gap: 6px;
|
|
147
|
-
flex-wrap: wrap;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
.checkbox-selected strong {
|
|
151
|
-
color: var(--text-base-main, #222);
|
|
152
158
|
}</style>
|
package/dist/components/index.js
CHANGED