Skip to content

Commit

Permalink
Fix missing props propagation in integration
Browse files Browse the repository at this point in the history
  • Loading branch information
martrapp committed Jan 27, 2024
1 parent f783ba0 commit e54a247
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 35 deletions.
5 changes: 5 additions & 0 deletions .changeset/unlucky-dodos-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro-vtbot": patch
---

Fixes a bug where explicitly set properties of `<ViewTransitions />` were lost.
14 changes: 9 additions & 5 deletions components/ProgressBar.astro
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
---
export interface Props {}
---

<script>
import "https://unpkg.com/@swup/progress-plugin@3"
import 'https://unpkg.com/@swup/progress-plugin@3';
import { loading } from './loading-indicator';

import { TRANSITION_AFTER_SWAP } from 'astro:transitions/client';
//@ts-ignore
const plugin = new SwupProgressPlugin();

document.addEventListener('astro:after-swap', () => plugin.progressBar.installStyleElement());
document.addEventListener(TRANSITION_AFTER_SWAP, () => plugin.progressBar.installStyleElement());

loading(() => plugin.startShowingProgress(), () => plugin.stopShowingProgress());
loading(
() => plugin.startShowingProgress(),
() => plugin.stopShowingProgress()
);
</script>

<style is:global>
.swup-progress-bar {
}
</style>

1 change: 1 addition & 0 deletions components/ProgressBar.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default function ProgressBar(_props: import('./ProgressBar.astro').Props): any;
9 changes: 5 additions & 4 deletions components/loading-indicator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/// <reference types="astro/client" />
import { TRANSITION_BEFORE_PREPARATION, TRANSITION_BEFORE_SWAP, TRANSITION_PAGE_LOAD } from 'astro:transitions/client';

import {
TRANSITION_BEFORE_PREPARATION,
TRANSITION_BEFORE_SWAP,
TRANSITION_PAGE_LOAD,
} from 'astro:transitions/client';

let show: () => void;
let hide: () => void;
Expand Down Expand Up @@ -36,7 +39,6 @@ export async function ensureLoadingIndicator() {
}
}


const beforePreparation = () => {
if (!ownIndicator) ensureLoadingIndicator();
document.documentElement.classList.add(`loading`);
Expand All @@ -56,4 +58,3 @@ export function init(createIndicator: boolean = false) {
createIndicator && document.addEventListener(TRANSITION_PAGE_LOAD, ensureLoadingIndicator);
!createIndicator && document.removeEventListener(TRANSITION_PAGE_LOAD, ensureLoadingIndicator);
}

48 changes: 28 additions & 20 deletions components/template/LoadingIndicatorTemplate_CSS.astro
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
---
import LoadingIndicator from 'astro-vtbot/components/LoadingIndicator.astro'
import LoadingIndicator from 'astro-vtbot/components/LoadingIndicator.astro';
---

{/* By rendering <LoadingIndicator/> here,
you inherit the logic that sets the "loading" CSS class */}
{
/* By rendering <LoadingIndicator/> here,
you inherit the logic that sets the "loading" CSS class */
}
<LoadingIndicator />

{/* Defining this div is only necessary
if you do not want to use the default element that holds the favicon image */}
<div id="vtbot-loading-indicator"> <!-- make sure to use this id -->
...
<div>

<style is:global>
#vtbot-loading-indicator {
/* basic styling, typically with position: fixed */
/* hide the indicator with display: none, opacity: 0, visibility: hidden, right: -100vw, ... */
...
}
html.loading #vtbot-loading-indicator {
/* show the indicator with display: block, opacity: 1, visibility: visible, right: 3vw, ... */
...
}
</style>
{
/* Defining this div is only necessary
if you do not want to use the default element that holds the favicon image */
}
<div id="vtbot-loading-indicator">
<!-- make sure to use this id -->
<!-- ... -->
<div>
<style is:global>
#vtbot-loading-indicator {
/* basic styling, typically with position: fixed */
/* hide the indicator with display: none, opacity: 0, visibility: hidden, right: -100vw, ... */

/* ... */
}
html.loading #vtbot-loading-indicator {
/* show the indicator with display: block, opacity: 1, visibility: visible, right: 3vw, ... */

/* ... */
}
</style>
</div>
</div>
2 changes: 1 addition & 1 deletion integration/env.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/// <reference types="astro/client" />
/// <reference types="astro/client" />
4 changes: 2 additions & 2 deletions integration/vite-plugin-extend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function vitePluginVtbotExtend(opts: ExtendOptions): Plugin {
if (!import.meta.env.DEV) linter = false;
if ((!linter && !loading) || id.match(/vtpl[123]\.astro$/) || !id.endsWith('.astro')) return;

const replacement = `"astro-vtbot/vtex${loading ? (linter ? "3" : "2") : "1"}"`;
const replacement = `"astro-vtbot/vtex${loading ? (linter ? '3' : '2') : '1'}"`;
const match = code.match(/from\s*['"]astro:transitions["']/ms);
if (match) {
const ast = parse(code, {
Expand All @@ -31,7 +31,7 @@ export default function vitePluginVtbotExtend(opts: ExtendOptions): Plugin {
if (node.type === 'ImportDeclaration' && node.source.value === 'astro:transitions') {
code =
code.substring(0, node.source.start) +
replacement +
replacement +
code.substring(node.source.end);
}
},
Expand Down
2 changes: 1 addition & 1 deletion integration/vtpl1.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { ViewTransitions } from 'astro:transitions';
import Linter from '../components/Linter.astro';
---

<ViewTransitions />
<ViewTransitions {...Astro.props} />
<Linter />
2 changes: 1 addition & 1 deletion integration/vtpl2.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { ViewTransitions } from 'astro:transitions';
import LoadingIndicator from '../components/LoadingIndicator.astro';
---

<ViewTransitions />
<ViewTransitions {...Astro.props} />
<LoadingIndicator />
2 changes: 1 addition & 1 deletion integration/vtpl3.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import VTPL from './vtpl1.astro';
import LoadingIndicator from '../components/LoadingIndicator.astro';
---

<VTPL />
<VTPL {...Astro.props} />
<LoadingIndicator />

0 comments on commit e54a247

Please sign in to comment.