solanaui は何をしますか?
shadcn/ui、Radix UI、Tailwind CSSをベースにしたSolana特化型Reactコンポーネントライブラリ。すべてのコンポーネントはプレゼンテーショナルであり、データをpropsで受け取りコールバックを発行します。ブロックチェーン依存関係、ウォレットアダプター、SDKインポートは一切ありません。開発者は自身のデータレイヤーと接続します。
使用するタイミング
Solanaアプリのインターフェースを構築する際にSolanaUIコンポーネントを使用します。コンポーネントはUIレイヤー(トークンアイコンのレンダリング、価格のフォーマット、テーブルやチャートの表示)を担当し、コードはデータフェッチ、ウォレット接続、トランザクションロジックを担当します。
典型的な統合フロー:APIまたはオンチェーンソースからデータを取得し、コンポーネントのpropインターフェースに合わせて変換し、渡します。コールバック(onSubmit、onSelect、onValueChange)にフックして、アプリケーションロジックをトリガーします。
インストール
プロジェクトでshadcn/uiが初期化されている必要があります(components.jsonが存在すること)。初期化されていない場合は、最初にpnpm dlx shadcn@latest initを実行してください。
SolanaUIレジストリをcomponents.jsonに追加します:
{
"registries": {
"@solanaui": "https://solanaui.dev/r/{name}.json"
}
}
その後、コンポーネントをインストールします:
pnpm dlx shadcn@latest add @solanaui/swap-box
必要なshadcn/uiプリミティブ(Card、Dialog、Buttonなど)は、レジストリの依存関係として自動的に解決されます。コンポーネントは@/lib/utilsのcn()ユーティリティにも依存します。
インポート規約
import { SwapBox } from "@/components/sol/swap-box";
import { PoolTable } from "@/components/sol/pool-table";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Button } from "@/components/ui/button";
統合パターン
データソースへの接続
コンポーネントはpropsを介してプレーンなデータを受け入れます。データをpropの形状にマッピングします:
// データソース(API、オンチェーン、状態管理など)
const positions = usePositions(); // あなたのフック
// コンポーネントのprop形状にマッピング
<PositionTable
positions={positions.map(p => ({
symbol: p.market.baseSymbol,
icon: p.market.baseIconUrl, // 独自のアイコンURLを使用
side: p.direction,
size: formatNumber(p.size),
value: formatUsd(p.notionalValue),
leverage: `${p.leverage}x`,
entryPrice: formatUsd(p.entryPrice),
markPrice: formatUsd(p.currentPrice),
pnl: formatPnl(p.unrealizedPnl),
pnlPercent: formatPercent(p.unrealizedPnlPercent),
pnlTrend: p.unrealizedPnl >= 0 ? "up" : "down",
}))}
onClosePosition={(pos) => closePosition(pos.symbol)}
onEditTpSl={(pos, values) => updateTpSl(pos.symbol, values)}
/>
トークンアイコン
コンポーネントはアイコンURLを文字列として受け入れます。プロジェクトですでに使用しているアイコンソース(独自のCDN、トークンレジストリ、メタデータサービスなど)を使用してください。
プロトタイピング用にプレースホルダーアイコンが必要な場合、以下のパブリックCDN URLが機能します:
- SOL:
https://raw.githubusercontent.com/solana-labs/token-list/main/assets/mainnet/So11111111111111111111111111111111111111112/logo.png - USDC:
https://raw.githubusercontent.com/solana-labs/token-list/main/assets/mainnet/EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v/logo.png - BONK:
https://arweave.net/hQiPZOsRZXGXBJd_82PhVdlM_hACsT_q6wqwf5cSY7I - JitoSOL:
https://storage.googleapis.com/token-metadata/JitoSOL-256.png - mSOL:
https://raw.githubusercontent.com/solana-labs/token-list/main/assets/mainnet/mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So/logo.png
コールバックの処理
コンポーネントはユーザーアクションに対してコールバックを発行します。これらをアプリケーションロジックに配線します:
<SwapBox
tokens={availableTokens}
defaultFromToken="USDC"
defaultToToken="SOL"
fromBalance={wallet.usdcBalance}
details={quoteDetails}
submitLabel="Swap"
// スワップ実行ロジック
onSubmit={() => executeSwap(fromToken, toToken, amount)}
/>
<ActionBox
tokens={supportedTokens}
label="Stake"
balance={wallet.solBalance}
details={stakingDetails}
submitLabel="Stake SOL"
onSubmit={() => submitStakeTransaction(selectedToken, amount)}
/>
コンポーネントカタログ(30コンポーネント)
ActionBox (action-box)
ステーキング、レンディング、LP預入、ブリッジング用の単一入力アクションフォーム。TradeBoxの汎用的な代替品。
interface ActionBoxProps {
tokens: { icon: string; symbol: string }[];
defaultToken?: string;
balance?: string;
label?: string;
details?: { label: string; value: string; className?: string }[];
submitLabel?: string;
onSubmit?: () => void;
className?: string;
}
ActivityFeed (activity-feed)
アイコン、タイムスタンプ(Dateオブジェクト)、値を持つ時系列アクティビティリスト。相対時間にdate-fnsのformatDistanceToNowを使用。
interface ActivityFeedProps {
items: { icon?: string; title: string; description?: string; timestamp: Date; value?: string }[];
className?: string;
}
AddressDisplay (address-display)
クリップボードへのコピーとオプションのエクスプローラリンク付きの短縮Solanaアドレス。explorerUrlはベースURLで、アドレスは自動的に追加されます。
interface AddressDisplayProps {
address: string; truncate?: boolean; truncateChars?: [number, number];
copyable?: boolean; explorerUrl?: string; className?: string;
}
AuthCard (auth-card)
オプションのメール入力、ソーシャルログインボタン、ウォレットプロバイダボタンを備えたサインインカード。
interface AuthCardProps {
title?: string; description?: string; showEmail?: boolean;
socialProviders?: { name: string; icon: React.ReactNode }[];
walletProviders?: { name: string; icon: React.ReactNode }[];
}
HealthBar (health-bar)
赤から緑へのグラデーションプログレスバー。色付きのパーセンテージ値を表示。
interface HealthBarProps { value: number; label?: string; showValue?: boolean; className?: string }
LeverageSlider (leverage-slider)
最小/最大ショートカットボタン付きのトレーディングレバレッジ選択用スライダー。
interface LeverageSliderProps {
min?: number; max?: number; step?: number; value?: number[];
defaultValue?: number[]; onValueChange?: (value: number[]) => void; className?: string;
}
NFTCard (nft-card)
NFT画像、名前、コレクション、価格を表示するカード。ローディング/エラー状態に対応。
interface NFTCardProps {
name: string; image: string; collection?: string;
price?: string; currency?: string; className?: string;
}
OrderBook (order-book)
bid/askレベル、サイズ、累計合計、スプレッド、ミッドプライス、深さバーを備えたトレーディングオーダーブック。
interface OrderBookProps {
bids: { price: number; size: number }[];
asks: { price: number; size: number }[];
className?: string;
}
OrderForm (order-form)
オープンポジション用TP/SLオーダーフォーム。デュアルTP入力(価格+利益%)、デュアルSL入力(価格+損失%)。entryPriceを渡すと、価格とパーセントフィールド間で自動同期します。
interface OrderFormProps {
title?: string; description?: string; entryPrice?: number;
details?: { label: string; value: string; className?: string }[];
onSubmit?: (values: { tpPrice: string; tpPercent: string; slPrice: string; slPercent: string }) => void;
className?: string;
}
PoolCard (pool-card)
シングルトークンまたはマルチトークンプール用の汎用カード。積み重ねアイコン、オプションの価格、説明、メトリクスグリッド、スパークラインチャート、子スロットを表示。
interface PoolCardProps {
tokens: { icon: string; symbol: string }[]; name?: string; price?: string; description?: string;
metrics?: { label: string; value: string; highlight?: boolean; className?: string }[];
series?: { time: string; value: number }[]; children?: React.ReactNode; className?: string;
}
PoolTable (pool-table)
トークンアイコン(行に1つ以上)、ユーザー定義列、ソート可能、オプションの行アクションを備えたデータテーブル。プール一覧、トークンテーブル、バリデータテーブルに使用可能。
interface PoolTableProps {
columns: { key: string; label: string; className?: string }[];
rows: { icons: { src: string; alt?: string }[]; name?: string; data: Record<string, string> }[];
actions?: React.ReactNode[]; className?: string;
}
PositionCard (position-card)
トークンアイコン、金額、USD価値、APY、オプションのアクションフッターを備えたDeFiポジション表示カード。
interface PositionCardProps {
symbol: string; icon: string; amount: string; value: string;
apy?: string; trend?: "up" | "down"; children?: React.ReactNode; className?: string;
}
PositionTable (position-table)
タイプ(ロング/ショート)、資産アイコン、サイズ、レバレッジ、エントリー/マーク価格、色付きP&Lを備えたオープントレーディングポジションのテーブル。TP/SL編集とクローズアクション列(ダイアログUI付き)を内蔵。
interface PositionTablePosition {
symbol: string; icon: string; side: "long" | "short";
size: string; value: string; leverage: string;
entryPrice: string; markPrice: string; liquidationPrice?: string;
pnl: string; pnlPercent?: string; pnlTrend?: "up" | "down";
}
interface PositionTableProps {
positions: PositionTablePosition[];
onEditTpSl?: (position: PositionTablePosition, values: { tpPrice: string; tpPercent: string; slPrice: string; slPercent: string }) => void;
onClosePosition?: (position: PositionTablePosition) => void;
className?: string;
}
PriceChart (price-chart)
軸、グリッド、グラデーション塗りつぶし、ツールチップを備えたトークン価格またはポートフォリオ価値履歴のエリアチャート。
interface PriceChartProps {
title?: string; description?: string;
series: { time: string; value: number }[]; className?: string;
}
SparklineChart (sparkline-chart)
自動正負色分けとパーセンテージ変化ラベル付きの最小限のインラインスパークライン。
interface SparklineChartProps { series: { time: string; value: number }[]; className?: string }
StatCard (stat-card)
ラベル、値、オプションのアイコン、オプションのトレンドバッジを備えた統計表示カード。
interface StatCardProps {
label: string; value: string; change?: string;
trend?: "up" | "down"; icon?: React.ReactNode; className?: string;
}
SwapBox (swap-box)
フリップボタン、詳細行、サブミットアクションを備えた二面トークンスワップフォーム。フリップボタンは選択されたトークンをその場で交換(ラベルは固定)。
interface SwapBoxProps {
tokens: { icon: string; symbol: string }[];
defaultFromToken?: string; defaultToToken?: string;
fromBalance?: string; toBalance?: string; fromLabel?: string; toLabel?: string;
details?: { label: string; value: string; className?: string }[];
submitLabel?: string; onSubmit?: () => void; className?: string;
}
TokenCombobox (token-combobox)
アイコンとチェックマーク選択付きの検索可能なトークン選択ドロップダウン。
interface TokenComboboxProps {
tokens: { icon: string; symbol: string }[];
defaultValue?: string; onSelect?: (token: { icon: string; symbol: string }) => void; className?: string;
}
TokenCommand (token-command)
トークンを検索・選択するためのCmd+Kコマンドダイアログ。tokens(フラットリスト)またはgroups(セクション分け)のいずれかを渡します(両方は不可)。
type TokenCommandProps = {
onSelect?: (token: { icon: string; symbol: string }) => void; className?: string;
} & (
| { tokens: { icon: string; symbol: string }[]; groups?: never }
| { groups: { heading: string; tokens: { icon: string; symbol: string }[] }[]; tokens?: never }
)
TokenIcon (token-icon)
ローディングスケルトンとエラーフォールバック付きの円形トークンアイコン画像。
type TokenIconProps = { src: string; alt: string; width?: number; height?: number; className?: string }
TokenIconGroup (token-icon-group)
LPペアまたはマルチトークングループ用の積み重ねられた重なりトークンアイコン。最大数超過時は+Nバッジを表示。
interface TokenIconGroupProps {
tokens: { src: string; alt?: string }[]; size?: number; overlap?: number; max?: number; className?: string;
}
TokenInput (token-input)
トークンセレクター、ウォレット残高、Half/Maxボタン、USD価値表示を統合した数値入力。千単位区切りでフォーマット。onValueChangeは未フォーマットの生の文字列を受け取ります。
interface TokenInputProps {
tokens: { icon: string; symbol: string }[]; defaultToken?: string; balance?: string;
value?: string; usdValue?: string; onValueChange?: (value: string) => void;
onTokenSelect?: (token: { icon: string; symbol: string }) => void; className?: string;
}
TradeBox (trade-box)
ロング/ショートトグル、トークン入力、レバレッジスライダー、詳細行、サブミットを備えたパーペチュアル/マージン取引フォーム。非取引アクションにはActionBoxを使用。
interface TradeBoxProps {
tokens: { icon: string; symbol: string }[]; defaultToken?: string; balance?: string;
labels?: [string, string]; defaultSide?: string;
leverageMin?: number; leverageMax?: number; leverageDefault?: number; leverageStep?: number;
details?: { label: string; value: string; className?: string }[];
submitLabel?: string; onSubmit?: () => void; className?: string;
}
TradeButtons (trade-buttons)
取引方向(ロング/ショートまたは買い/売り)選択用のトグルグループ。色分けされた状態。
interface TradeButtonsProps {
defaultValue?: string; value?: string; onValueChange?: (value: string) => void;
labels?: [string, string]; className?: string;
}
TradeChart (trade-chart)
ダーク/ライトテーマ対応のTradingView lightweight-chartsベースのローソク足チャート。
interface TradeChartProps {
data: { time: string | number; open: number; high: number; low: number; close: number }[];
visibleBars?: number; className?: string;
}
TrendBadge (trend-badge)
正(緑)または負(赤)の変化に対するトレンドアイコン付きの小さな色付きバッジ。
interface TrendBadgeProps { trend?: "up" | "down"; children: React.ReactNode; className?: string }
TxnTable (txn-table)
短縮署名リンク、相対タイムスタンプ(Dateオブジェクト、date-fns経由)、アクションバッジ、トークン金額を備えたトランザクションテーブル。
interface TxnTableProps {
transactions: {
signature: string; timestamp: Date; action: string; token: string;
tokenIcon?: string; amount: string; value?: string; explorerUrl?: string;
}[];
className?: string;
}