@functionalcms/svelte-components 4.31.0 → 4.35.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,2 @@
1
+ export declare enum Icons {
2
+ }
@@ -0,0 +1,3 @@
1
+ export var Icons;
2
+ (function (Icons) {
3
+ })(Icons || (Icons = {}));
@@ -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;
@@ -1,174 +1,44 @@
1
1
  <script lang="ts">
2
- import type { Snippet } from "svelte";
2
+ import { cn } from '../../utils.js';
3
+ import type { Snippet } from 'svelte';
4
+
5
+ interface Css {}
3
6
 
4
7
  interface TwoColumnLayoutProps {
5
8
  leftRender: Snippet;
6
9
  rightRender: Snippet;
7
10
  containerCss: string;
8
- spitPercentage: number;
9
- isResizable: boolean;
10
- isCollapsible: boolean;
11
- collapsedWidthPx: number;
12
- minWidthPercent: number;
13
- maxWidthPercent: number;
11
+ leftCss: string;
12
+ rightCss: string;
13
+ isFullWidth: boolean;
14
+ isFullHeight: boolean;
14
15
  }
15
16
 
16
17
  let {
17
18
  leftRender,
18
19
  rightRender,
19
- containerCss = "",
20
- spitPercentage = 30,
21
- isResizable = true,
22
- isCollapsible = true,
23
- collapsedWidthPx = 60,
24
- minWidthPercent = 10,
25
- maxWidthPercent = 80,
26
- }: Partial<TwoColumnLayoutProps> = $props();
27
-
28
- let container: HTMLElement | undefined = undefined;
29
- let leftWidthPx = $state(0);
30
- let isCollapsed = $state(false);
31
- let isDragging = $state(false);
32
-
33
- $effect(() => {
34
- if (container) {
35
- const containerWidth = container.getBoundingClientRect().width;
36
- leftWidthPx = containerWidth * (spitPercentage / 100);
37
- }
38
- });
39
-
40
- const toggleCollapse = () => {
41
- isCollapsed = !isCollapsed;
42
- };
43
-
44
- let startX = 0;
45
-
46
- const handleMouseDown = (event: MouseEvent) => {
47
- isDragging = true;
48
- startX = event.clientX;
49
- event.preventDefault();
50
- };
51
-
52
- const handleMouseMove = (event: MouseEvent) => {
53
- if (!isDragging) return;
54
-
55
- const deltaX = event.clientX - startX;
56
- const containerWidth = container?.getBoundingClientRect().width || 1;
57
- const newWidth = leftWidthPx + deltaX;
58
- const minWidthPx = containerWidth * (minWidthPercent / 100);
59
- const maxWidthPx = containerWidth * (maxWidthPercent / 100);
60
-
61
- if (newWidth >= minWidthPx && newWidth <= maxWidthPx) {
62
- leftWidthPx = newWidth;
63
- startX = event.clientX;
64
- }
65
- };
66
-
67
- const handleMouseUp = () => {
68
- isDragging = false;
69
- };
70
-
71
- $effect(() => {
72
- if (isDragging) {
73
- document.addEventListener('mousemove', handleMouseMove);
74
- document.addEventListener('mouseup', handleMouseUp);
75
-
76
- return () => {
77
- document.removeEventListener('mousemove', handleMouseMove);
78
- document.removeEventListener('mouseup', handleMouseUp);
79
- };
80
- }
81
- });
20
+ isFullWidth = true,
21
+ isFullHeight = true,
22
+ containerCss = '',
23
+ leftCss = 'w50p',
24
+ rightCss = 'w50p'
25
+ }: TwoColumnLayoutProps = $props();
26
+
27
+ let containerCssEx = cn(
28
+ 'flex flex-row-dynamic',
29
+ isFullWidth ? 'fw' : '',
30
+ isFullHeight ? 'fh' : '',
31
+ containerCss,
32
+ );
82
33
  </script>
83
34
 
84
- <section class="container {containerCss}" bind:this={container}>
85
- <div class="left" style:width={isCollapsed ? `${collapsedWidthPx}px` : `${leftWidthPx}px`}>
86
- {#if isCollapsible}
87
- <div class="toggle-button-container">
88
- <button class="toggle-button" onclick={toggleCollapse} aria-label={isCollapsed ? "Expand" : "Collapse"}>
89
- <svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
90
- {#if isCollapsed}
91
- <path d="M6 12L10 8L6 4" stroke="currentColor" stroke-width="1.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
92
- {:else}
93
- <path d="M10 12L6 8L10 4" stroke="currentColor" stroke-width="1.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
94
- {/if}
95
- </svg>
96
- </button>
97
- </div>
98
- {/if}
99
- {@render leftRender?.(isCollapsed)}
35
+ <section class={containerCssEx}>
36
+ <div class="left {leftCss}">
37
+ {@render leftRender()}
100
38
  </div>
101
-
102
- {#if isResizable && !isCollapsed}
103
- <div
104
- class="isResizable"
105
- onmousedown={handleMouseDown}
106
- role="separator"
107
- aria-label="Resizer"
108
- ></div>
109
- {/if}
110
-
111
- <div class="right" style:flex="1">
112
- {@render rightRender?.()}
39
+ <div class="right {rightCss}">
40
+ {@render rightRender()}
113
41
  </div>
114
42
  </section>
115
43
 
116
- <style>
117
- .container {
118
- display: flex;
119
- flex-direction: row;
120
- width: 100%;
121
- height: 100%;
122
- position: relative;
123
- }
124
- .left {
125
- transition: width 0.3s ease;
126
- position: relative;
127
- overflow-x: hidden;
128
- }
129
- .right {
130
- }
131
- .isResizable {
132
- width: 4px;
133
- background-color: #e0e0e0;
134
- cursor: col-resize;
135
- transition: background-color 0.2s;
136
- flex-shrink: 0;
137
- }
138
- .isResizable:hover {
139
- background-color: #0078d4;
140
- }
141
- .toggle-button-container {
142
- position: sticky;
143
- top: 0;
144
- left: 0;
145
- width: 100%;
146
- height: 48px;
147
- display: flex;
148
- align-items: center;
149
- justify-content: flex-start;
150
- padding: 0 8px;
151
- background-color: transparent;
152
- z-index: 100;
153
- }
154
- .toggle-button {
155
- background-color: transparent;
156
- border: none;
157
- width: 32px;
158
- height: 32px;
159
- display: flex;
160
- align-items: center;
161
- justify-content: center;
162
- cursor: pointer;
163
- border-radius: 2px;
164
- color: #323130;
165
- transition: background-color 0.1s;
166
- padding: 0;
167
- }
168
- .toggle-button:hover {
169
- background-color: rgba(0, 0, 0, 0.05);
170
- }
171
- .toggle-button:active {
172
- background-color: rgba(0, 0, 0, 0.1);
173
- }
174
- </style>
44
+ <style></style>
@@ -1,14 +1,13 @@
1
- import type { Snippet } from "svelte";
2
- declare const TwoColumnsLayout: import("svelte").Component<Partial<{
1
+ import type { Snippet } from 'svelte';
2
+ interface TwoColumnLayoutProps {
3
3
  leftRender: Snippet;
4
4
  rightRender: Snippet;
5
5
  containerCss: string;
6
- spitPercentage: number;
7
- isResizable: boolean;
8
- isCollapsible: boolean;
9
- collapsedWidthPx: number;
10
- minWidthPercent: number;
11
- maxWidthPercent: number;
12
- }>, {}, "">;
6
+ leftCss: string;
7
+ rightCss: string;
8
+ isFullWidth: boolean;
9
+ isFullHeight: boolean;
10
+ }
11
+ declare const TwoColumnsLayout: import("svelte").Component<TwoColumnLayoutProps, {}, "">;
13
12
  type TwoColumnsLayout = ReturnType<typeof TwoColumnsLayout>;
14
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';
@@ -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
  */
@@ -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.31.0",
3
+ "version": "4.35.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",