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.
wink-travel/wink-elements op GitHub Broncode, API-referentie en instructies voor bijdragen.
Installeren
Section titled “Installeren”npm install @wink/elementsSnel aan de slag
Section titled “Snel aan de slag”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>Frameworkvoorbeelden
Section titled “Frameworkvoorbeelden”Next.js (App Router)
Section titled “Next.js (App Router)”'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>;}Nuxt 3
Section titled “Nuxt 3”import { load } from '@wink/elements';
export default defineNuxtPlugin(() => { load({ clientId: useRuntimeConfig().public.winkClientId });});---import { load } from '@wink/elements';---<script> import { load } from '@wink/elements'; load({ clientId: import.meta.env.PUBLIC_WINK_CLIENT_ID });</script>SvelteKit
Section titled “SvelteKit”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 }); }}TypeScript-typen
Section titled “TypeScript-typen”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',};Gebruik van een staging CDN
Section titled “Gebruik van een staging CDN”load({ clientId: 'YOUR_CLIENT_ID', cdnBaseUrl: 'https://staging-elements.wink.travel',});load(options)
Section titled “load(options)”| Optie | Type | Verplicht | Standaard | Beschrijving |
|---|---|---|---|---|
clientId | string | Ja | — | Je Wink OAuth2 Client ID |
configurationId | string | Nee | — | Optionele aanpassings-ID |
cdnBaseUrl | string | Nee | https://elements.wink.travel | Overschrijf CDN-URL |