HextaUI

チェックアウト用の配送オプションと、商品ページ用のお届け日。注文の締め切り時刻、店舗受け取り、住所によって変わる料金に対応します。

カテゴリ
EC
使用コンポーネント
9
ファイル
7
使用例
3
利用
HextaUI Pro(55 ブロック)
ソース更新日
Open in new tab

HextaUI Pro に含まれます, 全 55 ブロック, $79 買い切り, プランを比較

ShippingMethods は、チェックアウトの配送ステップです。各選択肢は、「Mon, Oct 26 – Wed, Oct 28」や「Tomorrow」のような到着日から始まり、続いて配送方法と配送業者、右側に価格を表示するラジオカードです。買い物客は「3–5 business days」よりも日付のほうが比較しやすいため、ブロックは週末と渡された祝日を除いて、営業日数から実際の日付を算出します。

配送料金には注文の締め切りを設定できます。締め切り前は、カードに「Order within 3 h 12 min for delivery tomorrow」と表示され、1 分に 1 回更新されます。秒単位で刻むことはありません。締め切りを過ぎると、お届け予定は自動で翌営業日に移ります。最も速い有料の選択肢には小さなバッジが付き、最も安い選択肢もすでに無料でなければバッジが付きます。

受け取りの選択肢は、両方がある場合にだけ表示される Ship / Pick up の切り替えの先にあります。受け取りのカードには、「Ready today after 2 PM」のように注文の準備ができる時刻と、店舗名、距離、住所が表示されます。切り替えて戻ると、以前選んでいた配送の選択肢が復元されます。

ブロックが難しい状態を扱います。料金の読み込み中は実際のものと同じ形のスケルトンのカード、配送できない場合は Change address 付きの空の状態、Retry 付きのインラインのエラー、そして住所の変更後に変わる料金です。選択中の選択肢がまだ提供されていればそのまま選択され、提供されていなければ最も安いものが選ばれ、ブロックは「Express isn’t available for this address」と伝えます。DeliveryEstimate は、郵便番号のポップオーバーと返品の行とともに、同じ日付を商品ページに表示します。

  1. HextaUI Pro を入手する

    一度の支払いで、今後追加されるものも含めてすべてのブロックが使えます。料金を見る。

  2. Proレジストリをcomponents.jsonに追加する

    components.json
    {
      "registries": {
        "@hextaui-pro": {
          "url": "https://hextaui.com/r/pro/{name}.json",
          "headers": {
            "Authorization": "Bearer ${HEXTAUI_PRO_TOKEN}"
          }
        }
      }
    }
  3. トークンを追加する

    アカウントページでトークンを作成し、.env.local に HEXTAUI_PRO_TOKEN として設定してください。

  4. ブロックを追加する

    pnpm dlx shadcn@latest add @hextaui-pro/shipping-methods

Shopify の配送グループ

カートの deliveryGroups を rates に変換し、選択を cartSelectedDeliveryOptionsUpdate で保存します。受け取りとローカル配送の選択肢はそれぞれの kind を保持するため、Ship / Pick up の切り替えは自動で表示されます。

"use client"

import * as React from "react"

import type { ShippingRate } from "@/components/blocks/shipping-methods/shipping"
import { ShippingMethods } from "@/components/blocks/shipping-methods/shipping-methods"

type ShopifyDeliveryOption = {
  handle: string
  title: string | null
  description: string | null
  deliveryMethodType: "SHIPPING" | "PICK_UP" | "LOCAL" | "PICKUP_POINT" | "NONE"
  estimatedCost: { amount: string; currencyCode: string }
}

type ShopifyDeliveryGroup = {
  id: string
  deliveryOptions: ShopifyDeliveryOption[]
  selectedDeliveryOption: { handle: string } | null
}

const transitDays: Record<string, [number, number]> = {
  Standard: [3, 5],
  Express: [1, 2],
}

function fromShopify(group: ShopifyDeliveryGroup): ShippingRate[] {
  return group.deliveryOptions.map((option) => ({
    id: option.handle,
    title: option.title ?? "Shipping",
    price: option.estimatedCost,
    delivery: { businessDays: transitDays[option.title ?? ""] ?? [3, 7] },
    kind:
      option.deliveryMethodType === "PICK_UP" ||
      option.deliveryMethodType === "PICKUP_POINT"
        ? "pickup"
        : option.deliveryMethodType === "LOCAL"
          ? "local"
          : "ship",
    pickup:
      option.deliveryMethodType === "PICK_UP"
        ? { name: option.title ?? "Store pickup", address: option.description ?? "" }
        : undefined,
    note: option.deliveryMethodType === "PICK_UP" ? undefined : option.description ?? undefined,
  }))
}

export function CheckoutDelivery({
  group,
  loading,
  selectDeliveryOption,
}: {
  group: ShopifyDeliveryGroup | null
  loading: boolean
  selectDeliveryOption: (groupId: string, handle: string) => Promise<void>
}) {
  const rates = React.useMemo(() => (group ? fromShopify(group) : []), [group])
  return (
    <ShippingMethods
      rates={rates}
      status={loading ? "loading" : "idle"}
      value={group?.selectedDeliveryOption?.handle ?? null}
      onValueChange={(handle) => {
        if (group) void selectDeliveryOption(group.id, handle)
      }}
    />
  )
}

Shippo と EasyPost の料金

配送業者の API は輸送日数かお届け日を返します。それをそのまま渡すと、ブロックが週末と指定した祝日を除いて実際の日付に変換します。

"use client"

import { money } from "../price/money"
import type { ShippingRate } from "@/components/blocks/shipping-methods/shipping"
import { ShippingMethods } from "@/components/blocks/shipping-methods/shipping-methods"

type ShippoRate = {
  object_id: string
  amount: string
  currency: string
  provider: string
  servicelevel: { name: string; token: string }
  estimated_days: number | null
}

type EasyPostRate = {
  id: string
  rate: string
  currency: string
  carrier: string
  service: string
  delivery_days: number | null
  delivery_date: string | null
}

export function fromShippo(rate: ShippoRate): ShippingRate {
  const days = rate.estimated_days ?? 5
  return {
    id: rate.object_id,
    title: rate.servicelevel.name,
    carrier: rate.provider,
    price: money(rate.amount, rate.currency),
    delivery: { businessDays: [days, days] },
    kind: "ship",
  }
}

export function fromEasyPost(rate: EasyPostRate): ShippingRate {
  const days = rate.delivery_days ?? 5
  return {
    id: rate.id,
    title: rate.service.replace(/([a-z])([A-Z])/g, "$1 $2"),
    carrier: rate.carrier,
    price: money(rate.rate, rate.currency),
    delivery: rate.delivery_date
      ? { from: rate.delivery_date.slice(0, 10) }
      : { businessDays: [days, days] },
    kind: "ship",
  }
}

export function CarrierRates({
  rates,
  status,
  selected,
  onSelect,
  refetch,
  editAddress,
}: {
  rates: ShippoRate[]
  status: "idle" | "loading" | "error"
  selected: string | null
  onSelect: (rateId: string) => void
  refetch: () => Promise<void>
  editAddress: () => void
}) {
  return (
    <ShippingMethods
      rates={rates.map(fromShippo)}
      status={status}
      value={selected}
      onValueChange={onSelect}
      onRetry={refetch}
      onChangeAddress={editAddress}
      calendar={{ holidays: ["2026-11-26", "2026-12-25"] }}
    />
  )
}

Stripe の配送料金

Stripe の配送料金は、補助単位の価格と、営業日、時間、週単位のお届け予定を持ちます。一度変換すれば、ブロックが速さの代わりに日付を表示します。

"use client"

import { fromMinorUnits } from "../price/money"
import type { ShippingRate } from "@/components/blocks/shipping-methods/shipping"
import { ShippingMethods } from "@/components/blocks/shipping-methods/shipping-methods"

type StripeEstimateUnit = "hour" | "day" | "business_day" | "week" | "month"

type StripeShippingRate = {
  id: string
  display_name: string | null
  fixed_amount: { amount: number; currency: string } | null
  delivery_estimate: {
    minimum: { unit: StripeEstimateUnit; value: number } | null
    maximum: { unit: StripeEstimateUnit; value: number } | null
  } | null
}

function toBusinessDays(estimate?: { unit: StripeEstimateUnit; value: number } | null) {
  if (!estimate) return 5
  if (estimate.unit === "hour") return Math.ceil(estimate.value / 24)
  if (estimate.unit === "week") return estimate.value * 5
  if (estimate.unit === "month") return estimate.value * 21
  return estimate.value
}

export function fromStripe(rate: StripeShippingRate): ShippingRate {
  const amount = rate.fixed_amount ?? { amount: 0, currency: "usd" }
  return {
    id: rate.id,
    title: rate.display_name ?? "Shipping",
    price: fromMinorUnits(amount.amount, amount.currency),
    delivery: {
      businessDays: [
        toBusinessDays(rate.delivery_estimate?.minimum),
        toBusinessDays(rate.delivery_estimate?.maximum ?? rate.delivery_estimate?.minimum),
      ],
    },
    kind: "ship",
  }
}

export function StripeShippingOptions({
  shippingRates,
  value,
  updateSession,
}: {
  shippingRates: StripeShippingRate[]
  value: string | null
  updateSession: (shippingRateId: string) => Promise<void>
}) {
  return (
    <ShippingMethods
      rates={shippingRates.map(fromStripe)}
      value={value}
      onValueChange={(id) => void updateSession(id)}
    />
  )
}

構造

外側から内側へ組み合わせるパーツ。

パーツ説明
ShippingMethodsラジオカードとして表示される配送の選択肢。Ship / Pick up の切り替えと、読み込み、空、エラーのすべての状態を備えます。
DeliveryEstimate商品ページに表示する「Free delivery Mon, Oct 26 – Wed, Oct 28 to 94110」のような行。Change のポップオーバーと返品の行が付きます。
businessDaysFrom, formatDeliveryRange純粋な日付のヘルパー。週末と祝日を除いて営業日を加算し、Today と Tomorrow を使って日付範囲をフォーマットします。
resolveDelivery, rateBadges締め切りを含め、指定した時刻を基準に料金を日付に変換し、最速と最安のバッジを判定します。

ShippingMethods

divのプロップも受け付けます。

プロパティ型デフォルト
rates現在の住所に対する選択肢。
ShippingRate[]–
value選択された料金の id。非制御にするには undefined のままにします。
string | null–
defaultValue非制御時の最初の選択。ない場合は、最も安い選択肢が選ばれます。
string | null–
onValueChange買い物客が選択肢を選んだとき、および提供されなくなった選択肢をブロックが置き換えたときに呼ばれます。
(id: string, rate: ShippingRate) => void–
status読み込み中はスケルトンのカードを表示し、エラー時は Retry 付きでエラーメッセージを表示します。
"idle" | "loading" | "error""idle"
errorデフォルトの代わりに表示する具体的なエラーメッセージ。
string–
onRetryエラーの状態で Retry を表示します。promise を返すと、ボタンにスピナーが表示されます。
() => unknown–
onChangeAddress選択肢がないときに Change address を表示します。
() => void–
nowテストやプレビュー用に現在時刻を固定します。ない場合、ブロックはマウント後と 1 分ごとに時計を読み取ります。
Date | number–
calendar発送も配達も行われない日。
{ closedWeekdays?: number[]; holidays?: string[] }Saturday and Sunday
cutoffWindow締め切りまでこの分数以下になったときだけ、締め切りの行を表示します。
number1440
locale日付と価格のロケール。
Intl.LocalesArgument"en-US"
trailingZeros$18 ではなく $18.00 と表示します。
booleanfalse
labels締め切りと準備完了の文を含む、表示および読み上げられるすべての文字列。
Partial<ShippingMethodsLabels>–
プロパティ型デフォルト
id配送業者の料金 id や Shopify の handle などの、安定した id。
string–
titleStandard や Express のような配送方法。
string–
carrierUPS 2nd Day Air のような配送業者とサービス。
string–
price価格。ゼロの場合は Free と表示されます。
Money–
compareAtPrice送料が割引されているときに、取り消し線付きで表示される通常価格。
Money | null–
deliveryYYYY-MM-DD 形式のお届け日、または発送日から数えた営業日数。
{ from: string; to?: string } | { businessDays: [min, max] }–
cutoffこのお届け予定の注文締め切りの ISO 時刻。それを過ぎると、お届け予定は 1 営業日後ろにずれます。
string–
kind受け取りの料金は Pick up の切り替えの先に表示されます。
"ship" | "pickup" | "local"–
pickup受け取り用の店舗の詳細。readyBy は ISO 時刻です。
{ name; address; distance?; readyBy? }–
note受け取りの保管期間などの、短い補足の行。
string–

DeliveryEstimate

divのプロップも受け付けます。

プロパティ型デフォルト
defaultPostalCodeお届け予定の対象の郵便番号。
string | null–
defaultEstimateその郵便番号のお届け予定。
{ delivery; price?; cutoff? }–
onEstimate新しい郵便番号を検索します。配送対象外の場合は null を返し、メッセージを表示するにはエラーを投げます。
(postalCode: string) => Promise<DeliveryEstimateValue | null>–
onPostalCodeChange検索に成功した後、郵便番号を記憶するために呼ばれます。
(postalCode, estimate) => void–
validatePostalCodeエラーメッセージまたは null を返します。デフォルトは米国の郵便番号です。
(value: string) => string | null–
returns返品の行。null にすると非表示になります。
ReactNode | null"Free 30-day returns"
now, calendar, locale, labelsShippingMethods と同じです。
See ShippingMethods–
キーアクション
TabShip / Pick up の切り替えへ移動し、次に選択中の選択肢へ移動します。
ArrowDownArrowUp選択肢の間を移動して選択します。
ArrowLeftArrowRightShip と Pick up を切り替えます。
Enterお届け予定のポップオーバーで郵便番号を送信します。
Escape郵便番号のポップオーバーを閉じ、Change にフォーカスを戻します。
  • 選択肢は実際のラジオグループです。各カードは、まず「Arrives Mon, Oct 26 to Wed, Oct 28」のように日付を読み上げ、次に配送方法、配送業者、価格を読み上げます。
  • 住所の変更後、polite なライブリージョンが新しい選択肢と、選択肢が置き換えられた理由を読み上げます。エラーは role="alert" を使います。締め切りの行は 1 分に 1 回更新され、読み上げられないため、スクリーンリーダーが中断されることはありません。
  • Retry 後、料金が読み込まれると選択中の選択肢にフォーカスが移ります。
  • 選択は色だけでなく、リング、塗りつぶされたラジオ、色付きのカードで示されます。読み込みと日付の変更はフェードインし、視差効果を減らす設定では何も動きません。

使用技術

Shipping Methods を構成する無料のHextaUIコンポーネントです。それぞれ単独でインストールできます。

コード

7 個のファイルを components/blocks/shipping-methods に追加しました。