Skip to content

Progress 進捗バー - Vant 4

📈 Progress 進捗バー

🎯 紹介

Progress は操作の現在の進捗を表示するコンポーネントです。色・線の太さ・非アクティブ表示などを設定でき、タスクの完了度を直感的に示します ⏳

📦 導入

以下の方法でコンポーネントをグローバル登録します。詳細はコンポーネント登録を参照してください。

js
import { createApp } from 'vue';
import { Progress } from 'vant';

const app = createApp();
app.use(Progress);

🚀 コード例

🔧 基本用法

デフォルトは青色です。percentage で現在の進捗を設定し、完了状態を分かりやすく表示します ✨

html
<van-progress :percentage="50" />
js
import { ref } from 'vue';

export default {
  setup() {
    // 進捗の変化をシミュレーション 📊
    const percentage = ref(50);
    
    // 進捗を増やす関数
    const increaseProgress = () => {
      if (percentage.value < 100) {
        percentage.value += 10;
      }
    };
    
    // 進捗をリセットする関数
    const resetProgress = () => {
      percentage.value = 0;
    };

    return {
      percentage,
      increaseProgress,
      resetProgress,
    };
  },
};

📏 線の太さ

stroke-width で線の太さを設定して、視覚的なレイヤー感を調整します 🎨

html
<van-cell-group>
  <van-cell title="细线条">
    <van-progress :percentage="50" stroke-width="2" />
  </van-cell>
  <van-cell title="标准线条">
    <van-progress :percentage="50" />
  </van-cell>
  <van-cell title="粗线条">
    <van-progress :percentage="50" stroke-width="8" />
  </van-cell>
</van-cell-group>
js
import { ref } from 'vue';

export default {
  setup() {
    const percentage = ref(50);

    return {
      percentage,
    };
  },
};

🌫️ 非アクティブ表示

inactive を設定するとグレー表示になり、無効または一時停止状態を表します ⏸️

html
<van-cell-group>
  <van-cell title="正常状态">
    <van-progress :percentage="50" />
  </van-cell>
  <van-cell title="置灰状态">
    <van-progress :percentage="50" inactive />
  </van-cell>
</van-cell-group>
js
import { ref } from 'vue';

export default {
  setup() {
    const percentage = ref(50);
    const isInactive = ref(false);
    
    // 非アクティブ状態の切り替え
    const toggleInactive = () => {
      isInactive.value = !isInactive.value;
    };

    return {
      percentage,
      isInactive,
      toggleInactive,
    };
  },
};

🎨 スタイルカスタマイズ

pivot-text で表示文字を、color で進捗バーの色をカスタマイズして、個性的な表示に 🌈

html
<van-cell-group>
  <van-cell title="カスタムカラー">
    <van-progress :percentage="25" color="#f2826a" />
  </van-cell>
  <van-cell title="カスタムテキスト">
    <van-progress :percentage="50" pivot-text="进行中" />
  </van-cell>
  <van-cell title="グラデーション">
    <van-progress 
      :percentage="75" 
      color="linear-gradient(to right, #be99ff, #7232dd)" 
    />
  </van-cell>
  <van-cell title="テキストを非表示">
    <van-progress :percentage="50" :show-pivot="false" />
  </van-cell>
</van-cell-group>
js
import { ref } from 'vue';

export default {
  setup() {
    const percentage = ref(50);
    const customColor = ref('#f2826a');
    const customText = ref('進行中');
    
    // 進捗とスタイルを動的に変更
    const changeStyle = () => {
      percentage.value = Math.floor(Math.random() * 100);
      const colors = ['#f2826a', '#07c160', '#1989fa', '#ff976a'];
      customColor.value = colors[Math.floor(Math.random() * colors.length)];
    };

    return {
      percentage,
      customColor,
      customText,
      changeStyle,
    };
  },
};

🎯 動的進捗

動的に変化する進捗の表示。実際のロードシーンをシミュレートします 🔄

html
<van-cell-group>
  <van-cell title="ファイルアップロード">
    <van-progress :percentage="uploadProgress" color="#07c160" />
  </van-cell>
  <van-cell title="ダウンロード進捗">
    <van-progress :percentage="downloadProgress" color="#1989fa" />
  </van-cell>
  <van-button @click="startUpload" type="primary" size="small">
    アップロード開始
  </van-button>
  <van-button @click="startDownload" type="success" size="small">
    ダウンロード開始
  </van-button>
</van-cell-group>
js
import { ref } from 'vue';

export default {
  setup() {
    const uploadProgress = ref(0);
    const downloadProgress = ref(0);
    
    // アップロード進捗のシミュレーション
    const startUpload = () => {
      uploadProgress.value = 0;
      const timer = setInterval(() => {
        uploadProgress.value += Math.random() * 10;
        if (uploadProgress.value >= 100) {
          uploadProgress.value = 100;
          clearInterval(timer);
        }
      }, 200);
    };
    
    // ダウンロード進捗のシミュレーション
    const startDownload = () => {
      downloadProgress.value = 0;
      const timer = setInterval(() => {
        downloadProgress.value += Math.random() * 15;
        if (downloadProgress.value >= 100) {
          downloadProgress.value = 100;
          clearInterval(timer);
        }
      }, 300);
    };

    return {
      uploadProgress,
      downloadProgress,
      startUpload,
      startDownload,
    };
  },
};

スタイルカスタマイズ

pivot-text で文字、color で色をカスタマイズできます。

html

📋 API

🎛️ Props

属性名説明デフォルト
percentage進捗(%) 📊number | string0
stroke-width線の太さ(デフォルト単位は px) 📏number | string4px
color進捗バーの色(グラデーション対応) 🎨string#1989fa
track-colorトラックの色(背景) 🛤️string#e5e5e5
pivot-text進捗のテキスト(表示内容) 📝stringパーセンテージ
pivot-color進捗テキストの背景色 🏷️stringバーの色と同じ
text-color進捗テキストの文字色 ✍️stringwhite
inactive非アクティブ表示 🌫️booleanfalse
show-pivot進捗テキストを表示するか 👁️booleantrue

🏷️ 型定義

コンポーネントは以下の型定義をエクスポートします:

ts
import type { 
  ProgressProps, 
  ProgressInstance,
  ProgressThemeVars 
} from 'vant';

ProgressInstance はコンポーネントインスタンスの型です:

ts
import { ref } from 'vue';
import type { ProgressInstance } from 'vant';

const progressRef = ref<ProgressInstance>();

🎨 テーマカスタマイズ

🎭 スタイル変数

コンポーネントは以下の CSS 変数を提供しており、カスタムスタイルに使用できます。使用方法については ConfigProvider コンポーネント を参照してください。

名称デフォルト値説明
--van-progress-height4px進捗バーの高さ 📏
--van-progress-colorvar(--van-primary-color)進捗バーの色 🎨
--van-progress-inactive-colorvar(--van-gray-5)非アクティブ色 🌫️
--van-progress-backgroundvar(--van-gray-3)バックグラウンド色 🛤️
--van-progress-pivot-padding0 5pxテキストのパディング 📦
--van-progress-pivot-text-colorvar(--van-white)テキストの文字色 ✍️
--van-progress-pivot-font-sizevar(--van-font-size-xs)テキストのフォントサイズ 📝
--van-progress-pivot-line-height1.6テキストの行の高さ 📐
--van-progress-pivot-backgroundvar(--van-primary-color)テキスト背景色 🏷️

📚 関連ドキュメント

🔗 関連コンポーネント

Vant に基づく企業向けモバイルソリューション