React
React 19+ má prvotriednu podporu pre vlastné elementy. React 18 a staršie verzie odovzdávajú iba reťazcové atribúty — použite nižšie uvedený typovaný pomocný vzor, aby ste zostali v bezpečí naprieč verziami.
@wink/elements npm package Nainštalujte a načítajte CDN balík s typmi pre TypeScript.
Inštalácia
Section titled “Inštalácia”npm install @wink/elementsNačítajte raz v koreňovej časti aplikácie
Section titled “Načítajte raz v koreňovej časti aplikácie”Zavolajte load() vo vašej najvyššej komponente. Je idempotentná — bezpečné volať viackrát.
import { useEffect } from 'react';import { load } from '@wink/elements';
export default function App() { useEffect(() => { load({ clientId: import.meta.env.VITE_WINK_CLIENT_ID }); }, []);
return <YourRoutes />;}Použitie komponentov v JSX
Section titled “Použitie komponentov v JSX”export default function HotelPage() { return ( <main> <wink-content-loader layout="HOTEL" id="YOUR_LAYOUT_ID" /> <wink-lookup /> </main> );}TypeScript — deklarujte JSX intrinsics
Section titled “TypeScript — deklarujte JSX intrinsics”React štandardne nepozná názvy vlastných elementov. Pridajte raz deklaráciu, aby ste odstránili chyby typov:
import type { WinkContentLoaderAttributes, WinkLookupAttributes, WinkSearchButtonAttributes, WinkAccountButtonAttributes, WinkItineraryButtonAttributes, WinkShoppingCartButtonAttributes, WinkAppLoaderAttributes,} from '@wink/elements';
declare module 'react' { namespace JSX { interface IntrinsicElements { 'wink-content-loader': WinkContentLoaderAttributes & React.HTMLAttributes<HTMLElement>; 'wink-lookup': WinkLookupAttributes & React.HTMLAttributes<HTMLElement>; 'wink-search-button': WinkSearchButtonAttributes & React.HTMLAttributes<HTMLElement>; 'wink-account-button': WinkAccountButtonAttributes & React.HTMLAttributes<HTMLElement>; 'wink-itinerary-button': WinkItineraryButtonAttributes & React.HTMLAttributes<HTMLElement>; 'wink-shopping-cart-button': WinkShoppingCartButtonAttributes & React.HTMLAttributes<HTMLElement>; 'wink-app-loader': WinkAppLoaderAttributes & React.HTMLAttributes<HTMLElement>; } }}Odovzdávanie typovaných atribútov (bezpečné pre React 18)
Section titled “Odovzdávanie typovaných atribútov (bezpečné pre React 18)”import type { WinkContentLoaderAttributes } from '@wink/elements';
const attrs: WinkContentLoaderAttributes = { layout: 'HOTEL', id: 'abc123', sort: 'POPULARITY',};
// Spread funguje v React 19; pre React 18 sú všetky hodnoty aj tak reťazceexport default function HotelCard() { return <wink-content-loader layout={attrs.layout} id={attrs.id} sort={attrs.sort} />;}