Skip to content

npm package

Ang @wink/elements npm package ang pinakamabilis na paraan para magdagdag ng Wink web components sa anumang JavaScript o TypeScript na proyekto. Nagbibigay ito ng load() function na nag-iinject ng CDN resources at kumpletong TypeScript type declarations para sa lahat ng component attributes.

Terminal window
npm install @wink/elements

Tawagin ang load() isang beses sa pagsisimula ng app. Ito ay idempotent — ligtas tawagin nang maraming beses.

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

Pagkatapos, gamitin ang anumang Wink component sa iyong HTML o 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 });
}
}

Lahat ng component attribute interfaces ay na-export para magamit sa JSX, template literals, o typed dictionaries:

import type { WinkContentLoaderAttributes, WinkLayout } from '@wink/elements';
const attrs: WinkContentLoaderAttributes = {
layout: 'HOTEL', // Mahuhuli ng TypeScript ang mga invalid na layout values
id: 'abc123',
sort: 'POPULARITY',
};
load({
clientId: 'YOUR_CLIENT_ID',
cdnBaseUrl: 'https://staging-elements.wink.travel',
});
OptionTypeRequiredDefaultDescription
clientIdstringOoAng iyong Wink OAuth2 Client ID
configurationIdstringHindiOpsyonal na customization ID
cdnBaseUrlstringHindihttps://elements.wink.travelPalitan ang CDN URL