@functionalcms/svelte-components 4.30.0 → 4.32.0

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,228 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte";
3
+ import type { MenuSection } from "./menuLayout.js";
4
+ import Accordion from "../presentation/Accordion.svelte";
5
+ import Icon from "@iconify/svelte";
6
+ import { IconsSet, getIcon } from "../MaterialIconSet.js";
7
+
8
+ interface TwoColumnLayoutProps {
9
+ rightRender: Snippet;
10
+ containerCss: string;
11
+ spitPercentage: number;
12
+ isResizable: boolean;
13
+ isCollapsible: boolean;
14
+ collapsedWidthPx: number;
15
+ minWidthPercent: number;
16
+ maxWidthPercent: number;
17
+ menuItems: MenuSection[];
18
+ buttonCss: string;
19
+ }
20
+
21
+ let {
22
+ rightRender,
23
+ containerCss = "",
24
+ spitPercentage = 15,
25
+ isResizable = true,
26
+ isCollapsible = true,
27
+ collapsedWidthPx = 60,
28
+ minWidthPercent = 10,
29
+ maxWidthPercent = 80,
30
+ menuItems = [],
31
+ buttonCss = "",
32
+ }: Partial<TwoColumnLayoutProps> = $props();
33
+
34
+ let container: HTMLElement | undefined = undefined;
35
+ let leftWidthPx = $state(0);
36
+ let isCollapsed = $state(false);
37
+ let isDragging = $state(false);
38
+ let iconStyleWidth = $derived(isCollapsed ? "2.25rem" : "1.5rem");
39
+
40
+ $effect(() => {
41
+ if (container) {
42
+ const containerWidth = container.getBoundingClientRect().width;
43
+ leftWidthPx = containerWidth * (spitPercentage / 100);
44
+ }
45
+ });
46
+
47
+ const toggleCollapse = () => {
48
+ isCollapsed = !isCollapsed;
49
+ };
50
+
51
+ let startX = 0;
52
+
53
+ const handleMouseDown = (event: MouseEvent) => {
54
+ isDragging = true;
55
+ startX = event.clientX;
56
+ event.preventDefault();
57
+ };
58
+
59
+ const handleMouseMove = (event: MouseEvent) => {
60
+ if (!isDragging) {
61
+ return;
62
+ }
63
+
64
+ const deltaX = event.clientX - startX;
65
+ const containerWidth = container?.getBoundingClientRect().width || 1;
66
+ const newWidth = leftWidthPx + deltaX;
67
+ const minWidthPx = containerWidth * (minWidthPercent / 100);
68
+ const maxWidthPx = containerWidth * (maxWidthPercent / 100);
69
+
70
+ if (newWidth >= minWidthPx && newWidth <= maxWidthPx) {
71
+ leftWidthPx = newWidth;
72
+ startX = event.clientX;
73
+ }
74
+ };
75
+
76
+ const handleMouseUp = () => {
77
+ isDragging = false;
78
+ };
79
+
80
+ $effect(() => {
81
+ if (isDragging) {
82
+ document.addEventListener("mousemove", handleMouseMove);
83
+ document.addEventListener("mouseup", handleMouseUp);
84
+
85
+ return () => {
86
+ document.removeEventListener("mousemove", handleMouseMove);
87
+ document.removeEventListener("mouseup", handleMouseUp);
88
+ };
89
+ }
90
+ });
91
+ </script>
92
+
93
+ <section class="layout {containerCss}" bind:this={container}>
94
+ <div
95
+ class="menu"
96
+ style:width={isCollapsed ? `${collapsedWidthPx}px` : `${leftWidthPx}px`}
97
+ >
98
+ {#if isCollapsible}
99
+ <div class="toggle-button-container">
100
+ <button
101
+ class="toggle-button"
102
+ onclick={toggleCollapse}
103
+ aria-label={isCollapsed ? "Expand" : "Collapse"}
104
+ >
105
+ {#if isCollapsed}
106
+ <Icon
107
+ icon={getIcon(IconsSet.arrow_menu_close)}
108
+ width="48"
109
+ height="48"
110
+ />
111
+ {:else}
112
+ <Icon
113
+ icon={getIcon(IconsSet.arrow_menu_open)}
114
+ width="48"
115
+ height="48"
116
+ />
117
+ {/if}
118
+ </button>
119
+ </div>
120
+ {/if}
121
+ <section>
122
+ {#each menuItems as section}
123
+ <Accordion title={section.title}>
124
+ <div class="menu-section">
125
+ {#each section.items as item}
126
+ <a href={item.href} class="{buttonCss} button">
127
+ {#if item.icon}
128
+ <Icon
129
+ icon={item.icon}
130
+ width={iconStyleWidth}
131
+ />
132
+ {/if}
133
+ {#if !isCollapsed}
134
+ {item.title}
135
+ {/if}
136
+ </a>
137
+ {/each}
138
+ </div>
139
+ </Accordion>
140
+ {/each}
141
+ </section>
142
+ </div>
143
+
144
+ {#if isResizable && !isCollapsed}
145
+ <div
146
+ class="isResizable"
147
+ onmousedown={handleMouseDown}
148
+ role="separator"
149
+ aria-label="Resizer"
150
+ ></div>
151
+ {/if}
152
+
153
+ <div class="content" style:flex="1">
154
+ {@render rightRender?.()}
155
+ </div>
156
+ </section>
157
+
158
+ <style>
159
+ .container {
160
+ display: flex;
161
+ flex-direction: row;
162
+ width: 100%;
163
+ height: 100%;
164
+ position: relative;
165
+ }
166
+ .left {
167
+ transition: width 0.3s ease;
168
+ position: relative;
169
+ overflow-x: hidden;
170
+ }
171
+ .right {
172
+ }
173
+ .isResizable {
174
+ width: 4px;
175
+ background-color: #e0e0e0;
176
+ cursor: col-resize;
177
+ transition: background-color 0.2s;
178
+ flex-shrink: 0;
179
+ }
180
+ .isResizable:hover {
181
+ background-color: #0078d4;
182
+ }
183
+ .toggle-button-container {
184
+ position: sticky;
185
+ top: 0;
186
+ left: 0;
187
+ width: 100%;
188
+ height: 48px;
189
+ display: flex;
190
+ align-items: center;
191
+ justify-content: flex-start;
192
+ padding: 0 8px;
193
+ background-color: transparent;
194
+ z-index: 100;
195
+ }
196
+ .toggle-button {
197
+ background-color: transparent;
198
+ border: none;
199
+ width: 32px;
200
+ height: 32px;
201
+ display: flex;
202
+ align-items: center;
203
+ justify-content: center;
204
+ cursor: pointer;
205
+ border-radius: 2px;
206
+ color: #323130;
207
+ transition: background-color 0.1s;
208
+ padding: 0;
209
+ }
210
+ .toggle-button:hover {
211
+ background-color: rgba(0, 0, 0, 0.05);
212
+ }
213
+ .toggle-button:active {
214
+ background-color: rgba(0, 0, 0, 0.1);
215
+ }
216
+ .menu-section {
217
+ display: flex;
218
+ flex-direction: column;
219
+ }
220
+
221
+ .button {
222
+ width: 100%;
223
+ height: 2em;
224
+ text-decoration: none;
225
+ }
226
+ .button:hover {
227
+ }
228
+ </style>
@@ -0,0 +1,16 @@
1
+ import type { Snippet } from "svelte";
2
+ import type { MenuSection } from "./menuLayout.js";
3
+ declare const MenuLayout: import("svelte").Component<Partial<{
4
+ rightRender: Snippet;
5
+ containerCss: string;
6
+ spitPercentage: number;
7
+ isResizable: boolean;
8
+ isCollapsible: boolean;
9
+ collapsedWidthPx: number;
10
+ minWidthPercent: number;
11
+ maxWidthPercent: number;
12
+ menuItems: MenuSection[];
13
+ buttonCss: string;
14
+ }>, {}, "">;
15
+ type MenuLayout = ReturnType<typeof MenuLayout>;
16
+ export default MenuLayout;
@@ -22,7 +22,7 @@
22
22
  containerCss = '',
23
23
  leftCss = 'w50p',
24
24
  rightCss = 'w50p'
25
- }: Partial<TwoColumnLayoutProps> = $props();
25
+ }: TwoColumnLayoutProps = $props();
26
26
 
27
27
  let containerCssEx = cn(
28
28
  'flex flex-row-dynamic',
@@ -1,5 +1,5 @@
1
1
  import type { Snippet } from 'svelte';
2
- declare const TwoColumnsLayout: import("svelte").Component<Partial<{
2
+ interface TwoColumnLayoutProps {
3
3
  leftRender: Snippet;
4
4
  rightRender: Snippet;
5
5
  containerCss: string;
@@ -7,6 +7,7 @@ declare const TwoColumnsLayout: import("svelte").Component<Partial<{
7
7
  rightCss: string;
8
8
  isFullWidth: boolean;
9
9
  isFullHeight: boolean;
10
- }>, {}, "">;
10
+ }
11
+ declare const TwoColumnsLayout: import("svelte").Component<TwoColumnLayoutProps, {}, "">;
11
12
  type TwoColumnsLayout = ReturnType<typeof TwoColumnsLayout>;
12
13
  export default TwoColumnsLayout;
@@ -0,0 +1,12 @@
1
+ export type MenuIcon = string;
2
+ export type MenuItem = {
3
+ icon: MenuIcon;
4
+ title: string;
5
+ href: string;
6
+ };
7
+ export type MenuSection = {
8
+ title: string;
9
+ icon: MenuIcon;
10
+ showTitle: boolean;
11
+ items: MenuItem[];
12
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,64 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte';
3
+
4
+ interface AccordionProps {
5
+ children: Snippet;
6
+ isOpenByDefault: boolean;
7
+ animationDurationMs: number;
8
+ title: string;
9
+ }
10
+
11
+ let {
12
+ children,
13
+ title = "",
14
+ isOpenByDefault = true,
15
+ animationDurationMs = 300,
16
+ }: Partial<AccordionProps> = $props();
17
+
18
+ let isOpen = $state(isOpenByDefault);
19
+ let contentElement: HTMLDivElement;
20
+
21
+ const toggleAccordion = () => {
22
+ isOpen = !isOpen;
23
+ };
24
+ </script>
25
+
26
+ <article>
27
+ <header onclick={toggleAccordion} role="button" tabindex="0" onkeydown={(e) => e.key === 'Enter' && toggleAccordion()}>
28
+ {title}
29
+ <span class="toggle-icon">{isOpen ? '−' : '+'}</span>
30
+ </header>
31
+ <div
32
+ bind:this={contentElement}
33
+ class="content"
34
+ class:folded={!isOpen}
35
+ style={`max-height: ${isOpen ? contentElement?.scrollHeight + 'px' : '0'}; transition: max-height 500ms ease-in-out, opacity 500ms ease-in-out;`}>
36
+ {@render children?.()}
37
+ </div>
38
+ </article>
39
+
40
+ <style>
41
+ header {
42
+ cursor: pointer;
43
+ user-select: none;
44
+ display: flex;
45
+ justify-content: space-between;
46
+ align-items: center;
47
+ }
48
+
49
+ .toggle-icon {
50
+ font-weight: bold;
51
+ font-size: 1.2em;
52
+ transition: transform 500ms ease-in-out;
53
+ }
54
+
55
+ .content {
56
+ overflow: hidden;
57
+ opacity: 1;
58
+ }
59
+
60
+ .folded {
61
+ opacity: 0;
62
+ max-height: 0 !important;
63
+ }
64
+ </style>
@@ -0,0 +1,9 @@
1
+ import type { Snippet } from 'svelte';
2
+ declare const Accordion: import("svelte").Component<Partial<{
3
+ children: Snippet;
4
+ isOpenByDefault: boolean;
5
+ animationDurationMs: number;
6
+ title: string;
7
+ }>, {}, "">;
8
+ type Accordion = ReturnType<typeof Accordion>;
9
+ export default Accordion;
package/dist/index.d.ts CHANGED
@@ -7,6 +7,8 @@ export { default as Banner } from './components/layouts/Banner.svelte';
7
7
  export { default as SimpleFooter } from './components/layouts/SimpleFooter.svelte';
8
8
  export { default as Tabs } from './components/layouts/Tabs.svelte';
9
9
  export type { Tab, TabSizes, NavigationDirection } from './components/layouts/tabs.js';
10
+ export { default as MenuLayout } from './components/layouts/MenuLayout.svelte';
11
+ export type { MenuItem, MenuSection, MenuIcon } from './components/layouts/menuLayout.js';
10
12
  export { Justify, AlignItmes, Placement, Orientation, Position, Sizes, ComponentSize } from './components/Styling.js';
11
13
  export { default as Link } from './components/presentation/Link.svelte';
12
14
  export { default as Logo } from './components/presentation/Logo.svelte';
@@ -19,6 +21,7 @@ export { default as Disclose } from './components/presentation/Disclose.svelte';
19
21
  export { default as EmptyState } from './components/presentation/EmptyState.svelte';
20
22
  export { default as ImageCompare } from './components/presentation/ImageCompare.svelte';
21
23
  export { default as Dialog } from './components/presentation/Dialog.svelte';
24
+ export { default as Icon } from "@iconify/svelte";
22
25
  export { default as ListMenu } from './components/menu/ListMenu.svelte';
23
26
  export { default as DynamicMenu } from './components/menu/DynamicMenu.svelte';
24
27
  export { default as HamburgerMenu } from './components/menu/HamburgerMenu.svelte';
@@ -29,7 +32,7 @@ export { default as Button } from './components/form/Button.svelte';
29
32
  export { default as Input } from './components/form/Input.svelte';
30
33
  export { default as Switch } from './components/form/Switch.svelte';
31
34
  export { default as ChoiceInput } from './components/form/ChoiceInput.svelte';
32
- export { InputType, FieldType, LabelSize, type Field, SubmitResult, readForm, refreshPage } from './components/form/form.js';
35
+ export { InputType, FieldType, LabelSize, type Field, SubmitResult } from './components/form/form.js';
33
36
  export { default as AntiBot } from './components/form/AntiBot.svelte';
34
37
  export { default as Dropzone } from './components/form/Dropzone.svelte';
35
38
  export { default as Select } from './components/form/Select.svelte';
@@ -47,3 +50,7 @@ export { default as Spinner } from './components/indicators/Spinner.svelte';
47
50
  **/
48
51
  export { default as DynamicButton } from './components/dynamic/DynamicButton.svelte';
49
52
  export { executeRest } from './components/dynamic/DynamicButton.js';
53
+ /**
54
+ * Icons
55
+ **/
56
+ export { getIcon, MaterialSet, IconsSet } from './components/MaterialIconSet.js';
package/dist/index.js CHANGED
@@ -9,6 +9,7 @@ export { default as Well } from './components/layouts/Well.svelte';
9
9
  export { default as Banner } from './components/layouts/Banner.svelte';
10
10
  export { default as SimpleFooter } from './components/layouts/SimpleFooter.svelte';
11
11
  export { default as Tabs } from './components/layouts/Tabs.svelte';
12
+ export { default as MenuLayout } from './components/layouts/MenuLayout.svelte';
12
13
  /*
13
14
  * Styling
14
15
  */
@@ -26,6 +27,7 @@ export { default as Disclose } from './components/presentation/Disclose.svelte';
26
27
  export { default as EmptyState } from './components/presentation/EmptyState.svelte';
27
28
  export { default as ImageCompare } from './components/presentation/ImageCompare.svelte';
28
29
  export { default as Dialog } from './components/presentation/Dialog.svelte';
30
+ export { default as Icon } from "@iconify/svelte";
29
31
  /*
30
32
  * Menu
31
33
  */
@@ -42,7 +44,7 @@ export { default as Button } from './components/form/Button.svelte';
42
44
  export { default as Input } from './components/form/Input.svelte';
43
45
  export { default as Switch } from './components/form/Switch.svelte';
44
46
  export { default as ChoiceInput } from './components/form/ChoiceInput.svelte';
45
- export { InputType, FieldType, LabelSize, SubmitResult, readForm, refreshPage } from './components/form/form.js';
47
+ export { InputType, FieldType, LabelSize, SubmitResult } from './components/form/form.js';
46
48
  export { default as AntiBot } from './components/form/AntiBot.svelte';
47
49
  export { default as Dropzone } from './components/form/Dropzone.svelte';
48
50
  export { default as Select } from './components/form/Select.svelte';
@@ -69,3 +71,7 @@ export { default as Spinner } from './components/indicators/Spinner.svelte';
69
71
  **/
70
72
  export { default as DynamicButton } from './components/dynamic/DynamicButton.svelte';
71
73
  export { executeRest } from './components/dynamic/DynamicButton.js';
74
+ /**
75
+ * Icons
76
+ **/
77
+ export { getIcon, MaterialSet, IconsSet } from './components/MaterialIconSet.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@functionalcms/svelte-components",
3
- "version": "4.30.0",
3
+ "version": "4.32.0",
4
4
  "license": "MIT",
5
5
  "watch": {
6
6
  "build": {
@@ -47,7 +47,10 @@
47
47
  "@eslint/compat": "^1.2.9",
48
48
  "@eslint/js": "^9.26.0",
49
49
  "@functionalcms/services": "^0.12.0",
50
+ "@iconify/json": "^2.2.429",
51
+ "@iconify/svelte": "^5.2.1",
50
52
  "@sveltejs/adapter-auto": "^4.0.0",
53
+ "@sveltejs/kit": "^2.20.8",
51
54
  "@sveltejs/package": "^2.3.11",
52
55
  "@sveltejs/vite-plugin-svelte": "^5.0.3",
53
56
  "autoprefixer": "^10.4.21",
@@ -63,8 +66,8 @@
63
66
  "svelte-check": "^4.1.7",
64
67
  "typescript": "^5.8.3",
65
68
  "typescript-eslint": "^8.31.1",
66
- "vite": "^6.3.4",
67
- "@sveltejs/kit": "^2.20.8"
69
+ "unplugin-icons": "^23.0.1",
70
+ "vite": "^6.3.4"
68
71
  },
69
72
  "dependencies": {
70
73
  "embla-carousel-svelte": "^8.6.0",