Ga naar inhoud

npm-pakket

Het @wink/elements npm-pakket is de snelste manier om Wink webcomponenten toe te voegen aan elk JavaScript- of TypeScript-project. Het biedt een load() functie die de CDN-bronnen injecteert en volledige TypeScript type declaraties voor alle componentattributen.

Terminal window
npm install @wink/elements

Roep load() één keer aan bij het opstarten van de app. Het is idempotent — veilig om meerdere keren aan te roepen.

import { load } from '@wink/elements';
load({ clientId: 'YOUR_CLIENT_ID' });

Gebruik daarna elk Wink-component in je HTML of JSX:

<wink-content-loader layout="HOTEL" id="YOUR_LAYOUT_ID"></wink-content-loader>
app/layout.tsx
'use client';
import { useEffect } from 'react';
import { load } from '@wink/elements';
export default function RootLayout({ children }: { children: React.ReactNode }) {
useEffect(() => {
load({ clientId: process.env.NEXT_PUBLIC_WINK_CLIENT_ID! });
}, []);
return <html><body>{children}</body></html>;
}
plugins/wink.client.ts
import { load } from '@wink/elements';
export default defineNuxtPlugin(() => {
load({ clientId: useRuntimeConfig().public.winkClientId });
});
src/layouts/Layout.astro
---
import { load } from '@wink/elements';
---
<script>
import { load } from '@wink/elements';
load({ clientId: import.meta.env.PUBLIC_WINK_CLIENT_ID });
</script>
src/routes/+layout.ts
import { load as loadWink } from '@wink/elements';
import { browser } from '$app/environment';
export function load() {
if (browser) {
loadWink({ clientId: import.meta.env.PUBLIC_WINK_CLIENT_ID });
}
}

Alle interfaces voor componentattributen worden geëxporteerd voor gebruik in JSX, template literals of getypeerde dictionaries:

import type { WinkContentLoaderAttributes, WinkLayout } from '@wink/elements';
const attrs: WinkContentLoaderAttributes = {
layout: 'HOTEL', // TypeScript detecteert ongeldige layoutwaarden
id: 'abc123',
sort: 'POPULARITY',
};
load({
clientId: 'YOUR_CLIENT_ID',
cdnBaseUrl: 'https://staging-elements.wink.travel',
});
OptieTypeVerplichtStandaardBeschrijving
clientIdstringJaJe Wink OAuth2 Client ID
configurationIdstringNeeOptionele aanpassings-ID
cdnBaseUrlstringNeehttps://elements.wink.travelOverschrijf CDN-URL