Zum Inhalt springen

npm-Paket

Das @wink/elements npm-Paket ist der schnellste Weg, Wink-Webkomponenten in jedes JavaScript- oder TypeScript-Projekt einzubinden. Es stellt eine load()-Funktion bereit, die die CDN-Ressourcen injiziert und vollständige TypeScript-Typdeklarationen für alle Komponentenattribute liefert.

Terminal-Fenster
npm install @wink/elements

Rufen Sie load() einmal beim Start der App auf. Die Funktion ist idempotent — es ist sicher, sie mehrfach aufzurufen.

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

Verwenden Sie dann jede Wink-Komponente in Ihrem HTML oder 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 Schnittstellen der Komponentenattribute werden exportiert und können in JSX, Template-Literalen oder typisierten Dictionaries verwendet werden:

import type { WinkContentLoaderAttributes, WinkLayout } from '@wink/elements';
const attrs: WinkContentLoaderAttributes = {
layout: 'HOTEL', // TypeScript erkennt ungültige Layout-Werte
id: 'abc123',
sort: 'POPULARITY',
};
load({
clientId: 'YOUR_CLIENT_ID',
cdnBaseUrl: 'https://staging-elements.wink.travel',
});
OptionTypErforderlichStandardBeschreibung
clientIdstringJaIhre Wink OAuth2 Client-ID
configurationIdstringNeinOptionale Anpassungs-ID
cdnBaseUrlstringNeinhttps://elements.wink.travelCDN-URL überschreiben