インストールプロセスが完了したら、ReactアプリケーションでKonsta UIコンポーネントの使用を開始できます。
そのプロセスは非常に簡単で、konsta/react
からKonsta UI Reactコンポーネントをインポートする必要があります。
/* App.jsx */
import React from 'react';
import { Block, Button } from 'konsta/react';
export function MyApp() {
// ...
return (
<>
<Block>
<p>This is block with text</p>
</Block>
<Block className="space-y-4">
<p>Here comes the button</p>
<Button>Action</Button>
</Block>
</>
);
}
Konsta UIコンポーネントを他のフレームワーク(Framework7やIonicなど)と一緒に使用すると想定しています。
しかし、Konsta UIのみを使用する場合は、すべてのコンポーネントをKonsta UIのAppコンポーネントでラップする必要があります。
Appコンポーネントでは、グローバルテーマ(iOSまたはMaterial)やその他の便利なグローバルを定義できます。
/* App.jsx */
import React from 'react';
import { App, Page, Navbar, Block } from 'konsta/react';
export default function MyApp() {
return (
<App theme="ios">
<Page>
<Navbar title="My App" />
<Block>
<p>Here comes my app</p>
</Block>
</Page>
</App>
);
}
Konsta UI を他のフレームワークと併用する場合は、Konsta UI のグローバル値(テーマなど)を指定する必要があります(また指定することをお勧めします)。この場合は、KonstaProvider を使用する必要があります。
また、k-ios
または k-material
クラスをアプリの root 要素に追加する必要があります。
/* App.jsx */
import React from 'react';
// we use main App and Router components from Framework7
import { App, View, Page, Navbar } from 'framework7-react';
// we use KonstaProvider instead
import { KonstaProvider, Block, Button } from 'konsta/react';
export default function MyApp() {
return (
<>
{/* Wrap our app with KonstaProvider */}
<KonstaProvider theme="ios">
{/* We add extra `k-ios` class to the app root element */}
<App theme="ios" className="k-ios">
<View>
<Page>
<Navbar title="My App" />
{/* Konsta UI components */}
<Block>
<p>Here comes my app</p>
</Block>
<Block className="space-y-4">
<p>Here comes the button</p>
<Button>Action</Button>
</Block>
</Page>
</View>
</App>
</KonstaProvider>
</>
);
}