From 6861c524766656837e007ff48798110456e150db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ramirez=20Vargas=2C=20Jos=C3=A9=20Pablo?= Date: Sat, 6 Sep 2025 22:44:45 -0600 Subject: [PATCH] chore(demo): Demo improvements --- demo/src/lib/Alert.svelte | 82 ++++ demo/src/lib/Badge.svelte | 53 +++ demo/src/lib/Card.svelte | 45 +- demo/src/lib/CardBody.svelte | 24 +- demo/src/lib/CardHeader.svelte | 36 +- demo/src/lib/NavBar.svelte | 2 +- demo/src/lib/types.ts | 29 ++ .../views/hash-routing/HashRoutingDemo.svelte | 220 ++++++++++ .../views/hash-routing/HashRoutingView.svelte | 388 +++--------------- .../code-samples/basic-hash-router.svelte | 8 + .../code-samples/basic-hash-router.txt | 8 + .../code-samples/hash-url-examples.ts | 9 + .../code-samples/links-and-navigation.svelte | 16 + .../code-samples/live-hash-display.svelte | 32 ++ .../code-samples/multi-hash-router.svelte | 12 + .../code-samples/multi-hash-router.txt | 12 + .../code-samples/path-and-hash.txt | 16 + demo/src/lib/views/home/FeaturesTable.svelte | 14 +- demo/src/lib/views/home/HomeView.svelte | 127 ++---- demo/src/lib/views/home/Quickstart.svelte | 15 +- .../code-samples/hash-routing-example.txt | 12 + .../home/code-samples/multi-hash-example.txt | 12 + .../code-samples/path-routing-example.txt | 10 + .../code-samples/basic-path-router.txt | 11 + .../code-samples/link-component.txt | 10 + .../code-samples/nested-routing.txt | 15 + .../code-samples/route-guards.txt | 15 + .../code-samples/route-parameters.txt | 23 ++ .../path-routing/code-samples/url-examples.ts | 13 + .../views/path-routing/views/HomeView.svelte | 200 +++------ 30 files changed, 906 insertions(+), 563 deletions(-) create mode 100644 demo/src/lib/Alert.svelte create mode 100644 demo/src/lib/Badge.svelte create mode 100644 demo/src/lib/types.ts create mode 100644 demo/src/lib/views/hash-routing/HashRoutingDemo.svelte create mode 100644 demo/src/lib/views/hash-routing/code-samples/basic-hash-router.svelte create mode 100644 demo/src/lib/views/hash-routing/code-samples/basic-hash-router.txt create mode 100644 demo/src/lib/views/hash-routing/code-samples/hash-url-examples.ts create mode 100644 demo/src/lib/views/hash-routing/code-samples/links-and-navigation.svelte create mode 100644 demo/src/lib/views/hash-routing/code-samples/live-hash-display.svelte create mode 100644 demo/src/lib/views/hash-routing/code-samples/multi-hash-router.svelte create mode 100644 demo/src/lib/views/hash-routing/code-samples/multi-hash-router.txt create mode 100644 demo/src/lib/views/hash-routing/code-samples/path-and-hash.txt create mode 100644 demo/src/lib/views/home/code-samples/hash-routing-example.txt create mode 100644 demo/src/lib/views/home/code-samples/multi-hash-example.txt create mode 100644 demo/src/lib/views/home/code-samples/path-routing-example.txt create mode 100644 demo/src/lib/views/path-routing/code-samples/basic-path-router.txt create mode 100644 demo/src/lib/views/path-routing/code-samples/link-component.txt create mode 100644 demo/src/lib/views/path-routing/code-samples/nested-routing.txt create mode 100644 demo/src/lib/views/path-routing/code-samples/route-guards.txt create mode 100644 demo/src/lib/views/path-routing/code-samples/route-parameters.txt create mode 100644 demo/src/lib/views/path-routing/code-samples/url-examples.ts diff --git a/demo/src/lib/Alert.svelte b/demo/src/lib/Alert.svelte new file mode 100644 index 0000000..05cbf9d --- /dev/null +++ b/demo/src/lib/Alert.svelte @@ -0,0 +1,82 @@ + + +{#if !dismissed} + +{/if} + + diff --git a/demo/src/lib/Badge.svelte b/demo/src/lib/Badge.svelte new file mode 100644 index 0000000..90e46a4 --- /dev/null +++ b/demo/src/lib/Badge.svelte @@ -0,0 +1,53 @@ + + + + {@render children?.()} + + + diff --git a/demo/src/lib/Card.svelte b/demo/src/lib/Card.svelte index f988799..7224cca 100644 --- a/demo/src/lib/Card.svelte +++ b/demo/src/lib/Card.svelte @@ -1,17 +1,58 @@ -
+
{@render children?.()}
+ + + + diff --git a/demo/src/lib/CardBody.svelte b/demo/src/lib/CardBody.svelte index 960e6d8..2fe2acc 100644 --- a/demo/src/lib/CardBody.svelte +++ b/demo/src/lib/CardBody.svelte @@ -1,8 +1,9 @@ -
+
{@render children?.()}
+ + diff --git a/demo/src/lib/CardHeader.svelte b/demo/src/lib/CardHeader.svelte index cb27b29..9407ac6 100644 --- a/demo/src/lib/CardHeader.svelte +++ b/demo/src/lib/CardHeader.svelte @@ -1,19 +1,51 @@ - + {@render children?.()} + + diff --git a/demo/src/lib/NavBar.svelte b/demo/src/lib/NavBar.svelte index d4cbc6b..a197bd9 100644 --- a/demo/src/lib/NavBar.svelte +++ b/demo/src/lib/NavBar.svelte @@ -14,7 +14,7 @@ { text: 'Home', href: '/hash-routing' }, { text: 'Start Demo', - href: '/hash-routing#' + (routingMode === 'multi' ? 'd1=/demo;d2=/demo' : '/demo') + href: `#${(routingMode === 'multi' ? 'd1=/demo;d2=/demo' : '/demo')}` } ]; diff --git a/demo/src/lib/types.ts b/demo/src/lib/types.ts new file mode 100644 index 0000000..45417c2 --- /dev/null +++ b/demo/src/lib/types.ts @@ -0,0 +1,29 @@ +/** + * Bootstrap color variants used throughout the demo application + */ +export type BootstrapColor = + | 'primary' + | 'secondary' + | 'success' + | 'danger' + | 'warning' + | 'info' + | 'light' + | 'dark'; + +/** + * Bootstrap text color variants + * Includes standard colors plus additional text-specific variants + */ +export type BootstrapTextColor = BootstrapColor | 'white' | 'muted' | 'black-50' | 'white-50' | 'body' | 'black'; + +/** + * Bootstrap background color variants + * Includes standard colors plus transparent + */ +export type BootstrapBackgroundColor = BootstrapColor | 'transparent'; + +/** + * Bootstrap size variants used for spacing, buttons, etc. + */ +export type BootstrapSize = 'sm' | 'md' | 'lg' | 'xl'; diff --git a/demo/src/lib/views/hash-routing/HashRoutingDemo.svelte b/demo/src/lib/views/hash-routing/HashRoutingDemo.svelte new file mode 100644 index 0000000..deaed5d --- /dev/null +++ b/demo/src/lib/views/hash-routing/HashRoutingDemo.svelte @@ -0,0 +1,220 @@ + + +{#snippet demo(hash: boolean | string)} + + + + + + + +{/snippet} + + +
+
+ + + 🎮 Interactive Demo + + +
+ + Current Mode: {routingMode} + +
+

Experience the difference between single and multi-hash routing modes!

+

+ Currently in {routingMode} mode. + {#if routingMode === 'single'} + The entire hash value represents one route. + {:else} + The hash contains multiple key/value pairs for independent routers. + {/if} +

+ +
+ âš ī¸ Note: The page will reload to apply the new mode. +
+
+
+
+
+ + +
+

đŸŽĒ Live Demo

+ {#if routingMode === 'multi'} +
+
+ + +
đŸŽ¯ Demo Router "d1"
+ Hash key: d1 +
+ + {@render demo('d1')} + +
+
+
+ + +
đŸŽĒ Demo Router "d2"
+ Hash key: d2 +
+ + {@render demo('d2')} + +
+
+
+
+
🔍 Live URL Hash
+

+ Watch how the URL hash updates in real-time as you navigate through both demos: +

+
+ Current hash: {location.url.hash || '#(empty)'} +
+ {#if Object.keys(parsedRoutes).length > 0} +
+ Parsed routes: +
    + {#each Object.entries(parsedRoutes) as [key, value]} +
  • {key}: {value || '(empty)'}
  • + {/each} +
+
+ {/if} +
+ +
+
+ {:else} + + +
đŸŽ¯ Single Hash Demo
+ The entire hash represents one route +
+ + {@render demo(true)} + +
+
+
🔍 Live URL Hash
+

In single mode, the entire hash represents one route:

+
+ Current hash: {location.url.hash || '#(empty)'} +
+ {#if parsedRoutes.main} +
+ Current route: + {parsedRoutes.main} +
+ {/if} +
+ +
+
+ {/if} +
+ + +{#if showCodeModal} + + +{/if} diff --git a/demo/src/lib/views/hash-routing/HashRoutingView.svelte b/demo/src/lib/views/hash-routing/HashRoutingView.svelte index 733f4c5..e6e5e32 100644 --- a/demo/src/lib/views/hash-routing/HashRoutingView.svelte +++ b/demo/src/lib/views/hash-routing/HashRoutingView.svelte @@ -1,123 +1,28 @@ -{#snippet demo(hash: boolean | string)} - - - - - - - -{/snippet} -

🚀 Hash Routing

@@ -127,12 +32,12 @@

-
-
-
-

✨ Basic Hash Routing

-
-
+
+ + + ✨ Basic Hash Routing + +

Hash routing is perfect for single-page applications. It works without server configuration and plays nicely with static hosting! @@ -147,34 +52,57 @@ 💡 Try changing the URL hash to see routing in action!

-
-
+ +
-
-
-
-

đŸŽ¯ URL Examples

-
-
+
+ + + đŸŽ¯ URL Examples + +

See how URLs look in both single and multi-hash modes:

-
-
+ + +
+
+ + + 🔗 Links & Navigation + + +

+ You should always stick to Link components when creating navigation links. However, + hash HREF's in anchor elements work: +

+ + + â„šī¸ Anchor elements, when clicked, carry the existing history state. + +
Live Code Sample
+ +
+
-
-
-

🔄 Multiple Hash Routers

-
-
+ + + 🔄 Multiple Hash Routers + +

Run multiple independent hash routers simultaneously! Each router gets its own namespace in the hash value using key-value pairs. @@ -191,15 +119,15 @@

💡 Pro tip: Keep your multi-hash path names short to prevent URLs from growing too long!
-
-
+ +
-
-
-

🤝 Path + Hash Harmony

-
-
+ + + 🤝 Path + Hash Harmony + +

Mix path and hash routing! Use path routing for main navigation and hash routing for modals, tabs, or secondary navigation. @@ -213,191 +141,9 @@ Best practice: Use path routing for main content and hash routing for overlays and temporary UI states.

-
-
-
-
- - -
-
-
-
-

🎮 Interactive Demo

-
-
-
- - Current Mode: {routingMode} - -
-

- Experience the difference between single and multi-hash routing modes! -

-

- Currently in {routingMode} mode. - {#if routingMode === 'single'} - The entire hash value represents one route. - {:else} - The hash contains multiple key/value pairs for independent routers. - {/if} -

- -
- - âš ī¸ Note: The page will reload to apply the new mode. - -
-
-
+ +
- - -
-

đŸŽĒ Live Demo

- {#if routingMode === 'multi'} -
-
-
-
-
đŸŽ¯ Demo Router "d1"
- Hash key: d1 -
-
- {@render demo('d1')} -
-
-
-
-
-
-
đŸŽĒ Demo Router "d2"
- Hash key: d2 -
-
- {@render demo('d2')} -
-
-
-
-
-
🔍 Live URL Hash
-

- Watch how the URL hash updates in real-time as you navigate through both demos: -

-
- Current hash: {location.url.hash || '#(empty)'} -
- {#if Object.keys(parsedRoutes).length > 0} -
- Parsed routes: -
    - {#each Object.entries(parsedRoutes) as [key, value]} -
  • {key}: {value || '(empty)'}
  • - {/each} -
-
- {/if} -
- -
-
- {:else} -
-
-
đŸŽ¯ Single Hash Demo
- The entire hash represents one route -
-
- {@render demo(true)} -
-
-
-
🔍 Live URL Hash
-

- In single mode, the entire hash represents one route: -

-
- Current hash: {location.url.hash || '#(empty)'} -
- {#if parsedRoutes.main} -
- Current route: {parsedRoutes.main} -
- {/if} -
- -
-
- {/if} -
+
- - -{#if showCodeModal} - - -{/if} diff --git a/demo/src/lib/views/hash-routing/code-samples/basic-hash-router.svelte b/demo/src/lib/views/hash-routing/code-samples/basic-hash-router.svelte new file mode 100644 index 0000000..3bbf182 --- /dev/null +++ b/demo/src/lib/views/hash-routing/code-samples/basic-hash-router.svelte @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/demo/src/lib/views/hash-routing/code-samples/basic-hash-router.txt b/demo/src/lib/views/hash-routing/code-samples/basic-hash-router.txt new file mode 100644 index 0000000..3bbf182 --- /dev/null +++ b/demo/src/lib/views/hash-routing/code-samples/basic-hash-router.txt @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/demo/src/lib/views/hash-routing/code-samples/hash-url-examples.ts b/demo/src/lib/views/hash-routing/code-samples/hash-url-examples.ts new file mode 100644 index 0000000..d0a27c7 --- /dev/null +++ b/demo/src/lib/views/hash-routing/code-samples/hash-url-examples.ts @@ -0,0 +1,9 @@ +// Single Hash Mode URLs: +// https://example.com#/ +// https://example.com#/profile/123 +// https://example.com#/settings/account + +// Multi Hash Mode URLs: +// https://example.com#sidebar=/nav;main=/dashboard +// https://example.com#d1=/demo/routes;d2=/demo/links +// https://example.com#nav=/home;content=/profile/123;modal=/settings diff --git a/demo/src/lib/views/hash-routing/code-samples/links-and-navigation.svelte b/demo/src/lib/views/hash-routing/code-samples/links-and-navigation.svelte new file mode 100644 index 0000000..c3de257 --- /dev/null +++ b/demo/src/lib/views/hash-routing/code-samples/links-and-navigation.svelte @@ -0,0 +1,16 @@ + + + + Start Demo + + + Start Demo (anchor link) + diff --git a/demo/src/lib/views/hash-routing/code-samples/live-hash-display.svelte b/demo/src/lib/views/hash-routing/code-samples/live-hash-display.svelte new file mode 100644 index 0000000..d1997fe --- /dev/null +++ b/demo/src/lib/views/hash-routing/code-samples/live-hash-display.svelte @@ -0,0 +1,32 @@ + + +
+
+ Current hash: {currentHash} +
+ + {#each Object.entries(routes) as [key, value]} +
+ {key}: {value || '(empty)'} +
+ {/each} +
diff --git a/demo/src/lib/views/hash-routing/code-samples/multi-hash-router.svelte b/demo/src/lib/views/hash-routing/code-samples/multi-hash-router.svelte new file mode 100644 index 0000000..f1488ad --- /dev/null +++ b/demo/src/lib/views/hash-routing/code-samples/multi-hash-router.svelte @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/demo/src/lib/views/hash-routing/code-samples/multi-hash-router.txt b/demo/src/lib/views/hash-routing/code-samples/multi-hash-router.txt new file mode 100644 index 0000000..f1488ad --- /dev/null +++ b/demo/src/lib/views/hash-routing/code-samples/multi-hash-router.txt @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/demo/src/lib/views/hash-routing/code-samples/path-and-hash.txt b/demo/src/lib/views/hash-routing/code-samples/path-and-hash.txt new file mode 100644 index 0000000..c066b11 --- /dev/null +++ b/demo/src/lib/views/hash-routing/code-samples/path-and-hash.txt @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/demo/src/lib/views/home/FeaturesTable.svelte b/demo/src/lib/views/home/FeaturesTable.svelte index 773b505..8ac4de4 100644 --- a/demo/src/lib/views/home/FeaturesTable.svelte +++ b/demo/src/lib/views/home/FeaturesTable.svelte @@ -1,4 +1,8 @@ -
-

Features

-
+ + Features +
@@ -146,8 +150,8 @@
-
-
+ +