diff --git a/cspell-wordlist.txt b/cspell-wordlist.txt index c19525fad1d..76d855bf4cf 100644 --- a/cspell-wordlist.txt +++ b/cspell-wordlist.txt @@ -39,6 +39,7 @@ flexbox frontmatter fullscreen geolocation +iconset interactives isopen jank diff --git a/docs/angular/add-to-existing.md b/docs/angular/add-to-existing.md new file mode 100644 index 00000000000..d9a41e4e1a1 --- /dev/null +++ b/docs/angular/add-to-existing.md @@ -0,0 +1,344 @@ +--- +title: Add to Existing Angular Project +sidebar_label: Add to Existing +--- + +import DocsCard from '@components/global/DocsCard'; +import DocsCards from '@components/global/DocsCards'; + + + Add Ionic Angular to Existing Project: Integration Guide + + + +This guide covers how to add Ionic Angular to an existing Angular project. If you're looking to start a new project from scratch, check out the [Ionic Angular Quickstart](/docs/angular/quickstart.md) guide. For an overview of how Ionic Angular works with Angular, including version support and tooling, check out the [Ionic Angular Overview](/docs/angular/overview.md). + +:::tip + +This guide uses `.css` file extensions for stylesheets. If you created your Angular app with a different stylesheet format (such as `.scss`, `.sass`, or `.less`), use that extension instead. + +::: + +## Setup + +:::info + +This guide follows the structure of an Angular app created with the Angular CLI. If you started your Angular app using a different method, your file structure and setup may differ. + +::: + +You can add Ionic Angular to your existing Angular project using the Angular CLI's `ng add` feature or by installing it manually. + +### Using ng add + +The easiest way to add Ionic Angular is to use the Angular CLI's `ng add` feature: + +```bash +ng add @ionic/angular +``` + +This will install the `@ionic/angular` package and automatically configure the necessary imports and styles. + +### Manual Installation + +If you prefer to install Ionic Angular manually, you can follow these steps: + +#### 1. Install the Package + +```bash +npm install @ionic/angular +``` + +#### 2. Add Ionic Framework Stylesheets + +Replace the existing `styles` array in `angular.json` with the following: + +```json title="angular.json" +"styles": [ + "src/styles.css", + { + "input": "node_modules/@ionic/angular/css/core.css" + }, + { + "input": "node_modules/@ionic/angular/css/normalize.css" + }, + { + "input": "node_modules/@ionic/angular/css/structure.css" + }, + { + "input": "node_modules/@ionic/angular/css/typography.css" + } +] +``` + +:::info + +While `core.css` is required, `normalize.css`, `structure.css`, and `typography.css` are recommended but not required. They normalize cross-browser differences, ensure proper scrolling behavior, and provide consistent typography and form styling. Without them, you may need to handle these concerns yourself. For more details, refer to [Global Stylesheets](/docs/layout/global-stylesheets.md). + +::: + +#### 3. Configure Ionic Angular + +Update `src/app/app.config.ts` to include `provideIonicAngular`: + +```typescript title="src/app/app.config.ts" +import { ApplicationConfig, provideBrowserGlobalErrorListeners, provideZoneChangeDetection } from '@angular/core'; +import { provideRouter } from '@angular/router'; + +import { routes } from './app.routes'; +import { provideIonicAngular } from '@ionic/angular/standalone'; + +export const appConfig: ApplicationConfig = { + providers: [ + provideBrowserGlobalErrorListeners(), + provideZoneChangeDetection({ eventCoalescing: true }), + provideRouter(routes), + provideIonicAngular({}), + ], +}; +``` + +## Using Individual Components + +After completing the setup above, you can start using Ionic components in your existing Angular app. Here's an example of how to use them: + +Update `src/app/app.html` to the following: + +```html title="src/app/app.html" +Button +``` + +Then, import the components in `src/app/app.ts`: + +```ts title="src/app/app.ts" +import { Component } from '@angular/core'; +import { IonButton, IonDatetime } from '@ionic/angular/standalone'; + +@Component({ + selector: 'app-root', + imports: [IonButton, IonDatetime], + templateUrl: './app.html', + styleUrl: './app.css', +}) +export class App {} +``` + +Visit the [components](/docs/components.md) page for all of the available Ionic components. + +## Using Ionic Pages + +If you want to use Ionic pages with full navigation and page transitions, follow these additional setup steps. + +#### 1. Add Additional Ionic Framework Stylesheets + +Replace the existing `styles` array in `angular.json` with the following: + +```json title="angular.json" +"styles": [ + "src/styles.css", + { + "input": "node_modules/@ionic/angular/css/core.css" + }, + { + "input": "node_modules/@ionic/angular/css/normalize.css" + }, + { + "input": "node_modules/@ionic/angular/css/structure.css" + }, + { + "input": "node_modules/@ionic/angular/css/typography.css" + }, + { + "input": "node_modules/@ionic/angular/css/display.css" + }, + { + "input": "node_modules/@ionic/angular/css/padding.css" + }, + { + "input": "node_modules/@ionic/angular/css/float-elements.css" + }, + { + "input": "node_modules/@ionic/angular/css/text-alignment.css" + }, + { + "input": "node_modules/@ionic/angular/css/text-transformation.css" + }, + { + "input": "node_modules/@ionic/angular/css/flex-utils.css" + }, + { + "input": "src/theme/variables.css" + } +] +``` + +These stylesheets set up the overall page structure and provide [CSS utilities](/docs/layout/css-utilities.md) for faster development. Some stylesheets are optional. For details on which stylesheets are required, check out [Global Stylesheets](/docs/layout/global-stylesheets.md). + +#### 2. Set up Theming + +Create a `src/theme/variables.css` file with the following content: + +```css title="src/theme/variables.css" +/** + * Ionic Dark Theme + * ----------------------------------------------------- + * For more info, please refer to: + * https://ionicframework.com/docs/theming/dark-mode + */ + +/* @import "@ionic/angular/css/palettes/dark.always.css"; */ +/* @import "@ionic/angular/css/palettes/dark.class.css"; */ +@import '@ionic/angular/css/palettes/dark.system.css'; +``` + +This file enables [dark mode support](/docs/theming/dark-mode.md) for your Ionic app when the system is set to prefer a dark appearance. You can customize the theming behavior by uncommenting different dark palette imports or adding custom CSS variables. + +#### 3. Update the App Component + +Update `src/app/app.html` to the following: + +```html title="src/app/app.html" + + + +``` + +Then, update `src/app/app.ts` to include the component imports: + +```ts title="src/app/app.ts" +import { Component } from '@angular/core'; +import { IonApp, IonRouterOutlet } from '@ionic/angular/standalone'; + +@Component({ + selector: 'app-root', + imports: [IonApp, IonRouterOutlet], + templateUrl: './app.html', + styleUrl: './app.css', +}) +export class App {} +``` + +#### 4. Create a Home Page + +Start by adding a template at `src/app/home/home.html`: + +```html title="src/app/home/home.html" + + + Home + + + + + + + Home + + + +
+ Ready to create an app? +

+ Start with Ionic + UI Components +

+
+
+``` + +Then, create `src/app/home/home.ts` with the following: + +```ts title="src/app/home/home.ts" +import { Component } from '@angular/core'; +import { IonContent, IonHeader, IonTitle, IonToolbar } from '@ionic/angular/standalone'; + +@Component({ + selector: 'app-home', + imports: [IonContent, IonHeader, IonTitle, IonToolbar], + templateUrl: './home.html', + styleUrl: './home.css', +}) +export class HomePage {} +``` + +Finally, add a `src/app/home/home.css` file: + +```css title="src/app/home/home.css" +#container { + text-align: center; + + position: absolute; + left: 0; + right: 0; + top: 50%; + transform: translateY(-50%); +} + +#container strong { + font-size: 20px; + line-height: 26px; +} + +#container p { + font-size: 16px; + line-height: 22px; + + color: #8c8c8c; + + margin: 0; +} + +#container a { + text-decoration: none; +} +``` + +#### 5. Set up Routing + +Update `src/app/app.routes.ts` to add a `home` route: + +```ts title="src/app/app.routes.ts" +import { Routes } from '@angular/router'; +import { HomePage } from './home/home'; + +export const routes: Routes = [ + { + path: '', + redirectTo: 'home', + pathMatch: 'full', + }, + { + path: 'home', + component: HomePage, + }, +]; +``` + +You're all set! Your Ionic Angular app is now configured with full Ionic page support. Run `ng serve` to start your development server and view your app. + +## Next Steps + +Now that you have Ionic Angular integrated into your project, check out: + + + + +

Discover how to handle routing and navigation in Ionic Angular apps using the Angular Router.

+
+ + +

Explore Ionic's rich library of UI components for building beautiful apps.

+
+ + +

Learn how to customize the look and feel of your app with Ionic's powerful theming system.

+
+ + +

Explore how to access native device features and deploy your app to iOS, Android, and the web with Capacitor.

+
+ +
diff --git a/docs/angular/quickstart.md b/docs/angular/quickstart.md index fa4505c70d3..08ae4926861 100644 --- a/docs/angular/quickstart.md +++ b/docs/angular/quickstart.md @@ -4,41 +4,41 @@ sidebar_label: Quickstart --- - Ionic Angular Quickstart Using Ionic CLI: Angular Basics + Ionic CLIを使用したIonic Angularクイックスタート: Angularの基本 import DocsCard from '@components/global/DocsCard'; import DocsCards from '@components/global/DocsCards'; -Welcome! This guide will walk you through the basics of Ionic Angular development. You'll learn how to set up your development environment, generate a simple project, explore the project structure, and understand how Ionic components work. This is perfect for getting familiar with Ionic Angular before building your first real app. +ようこそ!このガイドでは、Ionic Angular 開発の基本を説明します。開発環境のセットアップ、シンプルなプロジェクトの生成、プロジェクト構造の探索、Ionic コンポーネントの動作方法を学びます。最初の実際のアプリを構築する前に Ionic Angular に慣れるのに最適です。 -If you're looking for a high-level overview of what Ionic Angular is and how it fits into the Angular ecosystem, see the [Ionic Angular Overview](overview). +Ionic Angular とは何か、Angular エコシステムにどのように適合するかの高レベルの概要をお探しの場合は、[Ionic Angular の概要](overview)を参照してください。 -## Prerequisites +## 前提条件 -Before you begin, make sure you have Node.js and npm installed on your machine. -You can check by running: +始める前に、マシンに Node.js と npm がインストールされていることを確認してください。 +次を実行して確認できます: ```shell node -v npm -v ``` -If you don't have Node.js and npm, [download Node.js here](https://nodejs.org/en/download) (which includes npm). +Node.js と npm がない場合は、[こちらから Node.js をダウンロード](https://nodejs.org/en/download)してください(npm が含まれています)。 -## Create a Project with the Ionic CLI +## Ionic CLI でプロジェクトを作成 -First, install the latest [Ionic CLI](../cli): +まず、最新の[Ionic CLI](../cli)をインストールします: ```shell npm install -g @ionic/cli ``` -Then, run the following commands to create and run a new project: +次に、次のコマンドを実行して新しいプロジェクトを作成し、実行します: ```shell ionic start myApp blank --type angular @@ -47,39 +47,41 @@ cd myApp ionic serve ``` -At the first prompt, choose `Standalone`. +最初のプロンプトで、`Standalone`を選択します。 -After running `ionic serve`, your project will open in the browser. +`ionic serve`を実行すると、プロジェクトがブラウザで開きます。 ![Screenshot of the Ionic Angular Home page](/img/guides/quickstart/home-page.png 'Ionic Angular Home Component') ## Explore the Project Structure -Your new app's `src/app` directory will look like this: +Your new app's directory will look like this: ```shell -├── app.component.html -├── app.component.scss -├── app.component.ts -├── app.routes.ts -└── home/ - ├── home.page.html - ├── home.page.scss - ├── home.page.spec.ts - └── home.page.ts +└── src/ + └── app + ├── app.component.html + ├── app.component.scss + ├── app.component.ts + ├── app.routes.ts + └── home/ + ├── home.page.html + ├── home.page.scss + ├── home.page.spec.ts + └── home.page.ts ``` :::info -All file paths in the examples below are relative to the `src/app/` directory. +以下の例のすべてのファイルパスは、プロジェクトのルートディレクトリを基準にしています。 ::: -Let's walk through these files to understand the app's structure. +アプリの構造を理解するために、これらのファイルを見ていきましょう。 ## View the App Component The root of your app is defined in `app.component.ts`: -```ts +```ts title="src/app/app.component.ts" import { Component } from '@angular/core'; import { IonApp, IonRouterOutlet } from '@ionic/angular/standalone'; @@ -95,19 +97,19 @@ export class AppComponent { And its template in `app.component.html`: -```html +```html title="src/app/app.component.html" ``` -This sets up the root of your application, using Ionic's `ion-app` and `ion-router-outlet` components. The router outlet is where your pages will be displayed. +これにより、Ionic の`ion-app`と`ion-router-outlet`コンポーネントを使用してアプリケーションのルートが設定されます。ルーターアウトレットは、ページが表示される場所です。 ## View Routes Routes are defined in `app.routes.ts`: -```ts +```ts title="src/app/app.routes.ts" import { Routes } from '@angular/router'; export const routes: Routes = [ @@ -123,13 +125,13 @@ export const routes: Routes = [ ]; ``` -When you visit the root URL (`/`), the `HomePage` component will be loaded. +ルート URL(`/`)にアクセスすると、`HomePage`コンポーネントが読み込まれます。 ## View the Home Page -The Home page component, defined in `home/home.page.ts`, imports the Ionic components it uses: +The Home page component, defined in `home.page.ts`, imports the Ionic components it uses: -```ts +```ts title="src/app/home/home.page.ts" import { Component } from '@angular/core'; import { IonHeader, IonToolbar, IonTitle, IonContent } from '@ionic/angular/standalone'; @@ -146,7 +148,7 @@ export class HomePage { And the template, in the `home.page.html` file, uses those components: -```html +```html title="src/app/home/home.page.html" Blank @@ -170,17 +172,17 @@ And the template, in the `home.page.html` file, uses those components: ``` -This creates a page with a header and scrollable content area. The second header shows a [collapsible large title](/docs/api/title#collapsible-large-titles) that displays when at the top of the content, then condenses to show the smaller title in the first header when scrolling down. +これにより、ヘッダーとスクロール可能なコンテンツ領域を持つページが作成されます。2 番目のヘッダーは、コンテンツの上部にあるときに表示される[折りたたみ可能な大きなタイトル](/docs/api/title.md#collapsible-large-titles)を示し、スクロールダウンすると最初のヘッダーの小さなタイトルを表示するために縮小されます。 -:::tip Learn More -For detailed information about Ionic layout components, see the [Header](/docs/api/header), [Toolbar](/docs/api/toolbar), [Title](/docs/api/title), and [Content](/docs/api/content) documentation. +:::tip 詳細情報 +Ionic レイアウトコンポーネントの詳細については、[Header](/docs/api/header.md)、[Toolbar](/docs/api/toolbar.md)、[Title](/docs/api/title.md)、[Content](/docs/api/content.md)のドキュメントを参照してください。 ::: -## Add an Ionic Component +## Ionic コンポーネントを追加 -You can enhance your Home page with more Ionic UI components. For example, add a [Button](/docs/api/button) at the end of the `ion-content`: +より多くの Ionic UI コンポーネントで Home ページを強化できます。たとえば、`ion-content`の最後に[Button](/docs/api/button.md)を追加します: -```html +```html title="src/app/home/home.page.html" @@ -190,7 +192,7 @@ You can enhance your Home page with more Ionic UI components. For example, add a Then, import the `IonButton` component in `home.page.ts`: -```ts +```ts title="src/app/home/home.page.ts" import { IonButton, IonContent, IonHeader, IonTitle, IonToolbar } from '@ionic/angular/standalone'; @Component({ @@ -209,9 +211,9 @@ ionic generate page new A route will be automatically added to `app.routes.ts`. -In your `new/new.page.html`, you can add a [Back Button](/docs/api/back-button) to the [Toolbar](/docs/api/toolbar): +In `new.page.html`, you can add a [Back Button](/docs/api/back-button.md) to the [Toolbar](/docs/api/toolbar.md): -```html +```html title="src/app/new/new.page.html" @@ -222,9 +224,9 @@ In your `new/new.page.html`, you can add a [Back Button](/docs/api/back-button) ``` -And import `IonBackButton` and `IonButtons` in `new/new.page.ts`: +And import `IonBackButton` and `IonButtons` in `new.page.ts`: -```ts +```ts title="src/app/new/new.page.ts" import { IonBackButton, IonButtons, IonContent, IonHeader, IonTitle, IonToolbar } from '@ionic/angular/standalone'; @Component({ @@ -233,19 +235,19 @@ import { IonBackButton, IonButtons, IonContent, IonHeader, IonTitle, IonToolbar }) ``` -The `ion-back-button` will automatically handle navigation back to the previous page, or to `/` if there is no history. +`ion-back-button`は、前のページへのナビゲーション、または履歴がない場合は`/`へのナビゲーションを自動的に処理します。 ## Navigate to the New Page -To navigate to the new page, update the button in `home/home.page.html`: +To navigate to the new page, update the button in `home.page.html`: -```html +```html title="src/app/home/home.page.html" Navigate ``` -Then, import `RouterLink` in `home/home.page.ts`: +Then, import `RouterLink` in `home.page.ts`: -```ts +```ts title="src/app/home/home.page.ts" import { RouterLink } from '@angular/router'; @Component({ @@ -255,14 +257,14 @@ import { RouterLink } from '@angular/router'; ``` :::info -Navigating can also be performed using Angular's Router service. See the [Angular Navigation documentation](/docs/angular/navigation#navigating-to-different-routes) for more information. +Angular の Router サービスを使用してナビゲーションを実行することもできます。詳細については、[Angular Navigation ドキュメント](/docs/angular/navigation.md#navigating-to-different-routes)を参照してください。 ::: -## Add Icons to the New Page +## 新しいページにアイコンを追加 -Ionic Angular comes with [Ionicons](https://ionic.io/ionicons/) pre-installed. You can use any icon by setting the `name` property on the `ion-icon` component. Add the following icons to `new/new.page.html`: +Ionic Angular には[Ionicons](https://ionic.io/ionicons/)がプリインストールされています。`ion-icon`コンポーネントの`name`プロパティを設定することで、任意のアイコンを使用できます。次のアイコンを`new.page.html`に追加します: -```html +```html title="src/app/new/new.page.html" @@ -271,9 +273,9 @@ Ionic Angular comes with [Ionicons](https://ionic.io/ionicons/) pre-installed. Y ``` -You'll also need to import and register these icons in `new/new.page.ts`: +You'll also need to import and register these icons in `new.page.ts`: -```ts +```ts title="src/app/new/new.page.ts" // ...existing imports... import { IonBackButton, IonButtons, IonContent, IonHeader, IonIcon, IonTitle, IonToolbar } from '@ionic/angular/standalone'; import { addIcons } from 'ionicons'; @@ -287,7 +289,7 @@ import { heart, logoIonic } from 'ionicons/icons'; Then, update the constructor of the page to use `addIcons`: -```ts +```ts title="src/app/new/new.page.ts" export class NewPage implements OnInit { constructor() { addIcons({ heart, logoIonic }); @@ -297,17 +299,17 @@ export class NewPage implements OnInit { } ``` -Alternatively, you can register icons in `app.component.ts` to use them throughout your app. +または、`app.component.ts`でアイコンを登録して、アプリ全体で使用することもできます。 -For more information, see the [Icon documentation](/docs/api/icon) and the [Ionicons documentation](https://ionic.io/ionicons/). +詳細については、[Icon ドキュメント](/docs/api/icon.md)と[Ionicons ドキュメント](https://ionic.io/ionicons/)を参照してください。 -## Call Component Methods +## コンポーネントメソッドを呼び出す -Let's add a button that can scroll the content area to the bottom. +コンテンツ領域を下部にスクロールできるボタンを追加しましょう。 -Update the `ion-content` in your `new/new.page.html` to include a button and some items after the existing icons: +Update the `ion-content` in your `new.page.html` to include a button and some items after the existing icons: -```html +```html title="src/app/new/new.page.html" @@ -331,7 +333,7 @@ Update the `ion-content` in your `new/new.page.html` to include a button and som In the component, add the `ViewChild` import, the new component imports and define the `scrollToBottom` function: -```ts +```ts title="src/app/new/new.page.ts" import { Component, OnInit, ViewChild } from '@angular/core'; import { IonBackButton, @@ -380,16 +382,16 @@ export class NewPage implements OnInit { } ``` -To call methods on Ionic components: +Ionic コンポーネントのメソッドを呼び出すには: -1. Create a `ViewChild` reference for the component -2. Call the method directly on the component instance +1. コンポーネントの`ViewChild`参照を作成します +2. コンポーネントインスタンスでメソッドを直接呼び出します -You can find available methods for each component in the [Methods](/docs/api/content#methods) section of their API documentation. +各コンポーネントの利用可能なメソッドは、API ドキュメントの[Methods](/docs/api/content.md#methods)セクションで見つけることができます。 -## Run on a Device +## デバイスで実行 -Ionic's components work everywhere: on iOS, Android, and PWAs. To deploy to mobile, use [Capacitor](https://capacitorjs.com): +Ionic のコンポーネントは、iOS、Android、PWA のどこでも動作します。モバイルにデプロイするには、[Capacitor](https://capacitorjs.com)を使用します: ```shell ionic build @@ -397,43 +399,45 @@ ionic cap add ios ionic cap add android ``` -Open the native projects in their IDEs: +ネイティブプロジェクトを IDE で開きます: ```shell ionic cap open ios ionic cap open android ``` -See [Capacitor's Getting Started guide](https://capacitorjs.com/docs/getting-started/with-ionic) for more. +詳細については、[Capacitor の Getting Started ガイド](https://capacitorjs.com/docs/getting-started/with-ionic)を参照してください。 -## Explore More +## さらに探索 -This guide covered the basics of creating an Ionic Angular app, adding navigation, and introducing Capacitor for native builds. To dive deeper, check out: +このガイドでは、Ionic Angular アプリの作成、ナビゲーションの追加、ネイティブビルド用の Capacitor の導入の基本をカバーしました。さらに深く掘り下げるには、以下を確認してください: - -

Build a real Photo Gallery app with Ionic Angular and native device features.

+ +

Ionic Angularとネイティブデバイス機能を使用して実際のPhoto Galleryアプリを構築します。

- -

Learn more about Angular's core concepts, tools, and best practices from the official Angular documentation.

+ +

公式Angularドキュメントから、Angularのコアコンセプト、ツール、ベストプラクティスについて詳しく学びます。

- -

Discover how to handle routing and navigation in Ionic Angular apps using the Angular Router.

+ +

Angular Routerを使用してIonic Angularアプリでルーティングとナビゲーションを処理する方法を発見します。

- -

Explore Ionic's rich library of UI components for building beautiful apps.

+ +

美しいアプリを構築するためのIonicの豊富なUIコンポーネントライブラリを探索します。

- -

Learn how to customize the look and feel of your app with Ionic's powerful theming system.

+ +

Ionicの強力なテーマ設定システムを使用してアプリの外観と操作性をカスタマイズする方法を学びます。

- -

Explore how to access native device features and deploy your app to iOS, Android, and the web with Capacitor.

+ +

+ Capacitorを使用してネイティブデバイス機能にアクセスし、アプリをiOS、Android、Webにデプロイする方法を探索します。 +

diff --git a/docs/angular/your-first-app.md b/docs/angular/your-first-app.md index 22a9b47a603..e72e878738b 100644 --- a/docs/angular/your-first-app.md +++ b/docs/angular/your-first-app.md @@ -4,16 +4,16 @@ sidebar_label: はじめてのアプリ --- - Build Your First Ionic Mobile App: Angular Development Tutorial + Angularで最初のIonicモバイルアプリを構築 | Ionic Capacitor Camera -Ionic の素晴らしいところは、1 つのコードベースで、使い慣れた Web ツールと言語を使用して任意のプラットフォーム用にビルドできることです。 Follow along as we learn the fundamentals of Ionic app development by creating a realistic app step by step. +Ionic の素晴らしいところは、1 つのコードベースで、使い慣れた Web ツールと言語を使用して任意のプラットフォーム用にビルドできることです。現実的なアプリを段階的に作成しながら、Ionic アプリ開発の基礎を学びましょう。 -Here’s the finished app running on all 3 platforms: +3 つのプラットフォームすべてで実行されている完成したアプリは次のとおりです: :::note -Looking for the previous version of this guide that covered Ionic 4 and Cordova? [See here.](../developer-resources/guides/first-app-v4/intro.md) +Ionic 4 と Cordova をカバーしたこのガイドの以前のバージョンを探していますか?[こちらを参照してください。](../developer-resources/guides/first-app-v4/intro.md) ::: -## What We'll Build +## 構築するもの -We'll create a Photo Gallery app that offers the ability to take photos with your device's camera, display them in a grid, and store them permanently on the device. +デバイスのカメラで写真を撮影し、グリッドに表示し、デバイスに永続的に保存する機能を提供する Photo Gallery アプリを作成します。 -Highlights include: +ハイライトには以下が含まれます: -- One Angular-based codebase that runs on the web, iOS, and Android using Ionic Framework [UI components](https://ionicframework.com/docs/components). -- Deployed as a native iOS and Android mobile app using [Capacitor](https://capacitorjs.com), Ionic's official native app runtime. -- Photo Gallery functionality powered by the Capacitor [Camera](https://capacitorjs.com/docs/apis/camera), [Filesystem](https://capacitorjs.com/docs/apis/filesystem), and [Preferences](https://capacitorjs.com/docs/apis/preferences) APIs. +- Ionic Framework の[UI コンポーネント](../components.md)を使用して、Web、iOS、Android で実行される 1 つの Angular ベースのコードベース。 +- Ionic の公式ネイティブアプリランタイムである[Capacitor](https://capacitorjs.com)を使用して、ネイティブ iOS および Android モバイルアプリとしてデプロイ。 +- Capacitor の[Camera](../native/camera.md)、[Filesystem](../native/filesystem.md)、[Preferences](../native/preferences.md) API によって提供される Photo Gallery 機能。 -Find the complete app code referenced in this guide [on GitHub](https://github.com/ionic-team/photo-gallery-capacitor-ng). +このガイドで参照されている[完全なアプリコード](https://github.com/ionic-team/tutorial-photo-gallery-angular)を GitHub で見つけてください。 -## Download Required Tools +## 必要なツールのダウンロード -Download and install these right away to ensure an optimal Ionic development experience: +最適な Ionic 開発体験を確保するために、以下をすぐにダウンロードしてインストールしてください: -- **Node.js** for interacting with the Ionic ecosystem. [Download the LTS version here](https://nodejs.org/en/). -- **A code editor** for... writing code! We are fans of [Visual Studio Code](https://code.visualstudio.com/). -- **Command-line interface/terminal (CLI)**: - - **Windows** users: for the best Ionic experience, we recommend the built-in command line (cmd) or the Powershell - CLI, running in Administrator mode. - - **Mac/Linux** users, virtually any terminal will work. +- **Node.js** - Ionic エコシステムと対話するため。[LTS バージョンをこちらからダウンロード](https://nodejs.org/en/)。 +- **コードエディタ** - コードを書くため![Visual Studio Code](https://code.visualstudio.com/)をお勧めします。 +- **コマンドラインインターフェース/ターミナル(CLI)**: + - **Windows**ユーザー:最適な Ionic 体験のために、管理者モードで実行される組み込みコマンドライン(cmd)または Powershell CLI をお勧めします。 + - **Mac/Linux**ユーザー:事実上、どのターミナルでも動作します。 -## Install Ionic Tooling +## Ionic ツールのインストール -Run the following in the command line terminal to install the Ionic CLI (`ionic`), `native-run`, used to run native binaries on devices and simulators/emulators, and `cordova-res`, used to generate native app icons and splash screens: +コマンドラインターミナルで以下を実行して、Ionic CLI(`ionic`)、デバイスやシミュレーター/エミュレーターでネイティブバイナリを実行するために使用される`native-run`、ネイティブアプリのアイコンとスプラッシュスクリーンを生成するために使用される`cordova-res`をインストールします: :::note -To open a terminal in Visual Studio Code, go to Terminal -> New Terminal. +Visual Studio Code でターミナルを開くには、Terminal -> New Terminal に移動します。 ::: ```shell @@ -64,9 +63,9 @@ npm install -g @ionic/cli native-run cordova-res ``` :::note -The `-g` option means _install globally_. When packages are installed globally, `EACCES` permission errors can occur. +`-g`オプションは*グローバルにインストール*を意味します。パッケージをグローバルにインストールすると、`EACCES`権限エラーが発生する可能性があります。 -Consider setting up npm to operate globally without elevated permissions. See [Resolving Permission Errors](../developing/tips.md#resolving-permission-errors) for more information. +昇格された権限なしで npm をグローバルに操作するように設定することを検討してください。詳細については、[権限エラーの解決](../developing/tips.md#resolving-permission-errors)を参照してください。 ::: ## アプリの作成 @@ -74,7 +73,7 @@ Consider setting up npm to operate globally without elevated permissions. See [R 次に、"Tabs" というアプリテンプレートを使用して Ionic Angular アプリを生成し、Native 機能を使うために Capacitor を追加します。 ```shell -ionic start photo-gallery tabs --type=angular --capacitor +ionic start photo-gallery tabs --type=angular ``` :::note @@ -91,7 +90,7 @@ ionic start photo-gallery tabs --type=angular --capacitor cd photo-gallery ``` -Next we'll need to install the necessary Capacitor plugins to make the app's native functionality work: +次に、アプリのネイティブ機能を動作させるために必要な Capacitor プラグインをインストールする必要があります: ```shell npm install @capacitor/camera @capacitor/preferences @capacitor/filesystem @@ -99,9 +98,9 @@ npm install @capacitor/camera @capacitor/preferences @capacitor/filesystem ### PWA Elements -Some Capacitor plugins, including the Camera API, provide the web-based functionality and UI via the Ionic [PWA Elements library](https://github.com/ionic-team/ionic-pwa-elements). +[Camera API](../native/camera.md)を含む一部の Capacitor プラグインは、Ionic の[PWA Elements ライブラリ](https://github.com/ionic-team/pwa-elements)を介して Web ベースの機能と UI を提供します。 -It's a separate dependency, so install it next: +これは別の依存関係なので、次にインストールします: ```shell npm install @ionic/pwa-elements @@ -109,14 +108,21 @@ npm install @ionic/pwa-elements Next, import `@ionic/pwa-elements` by editing `src/main.ts`. -```tsx +```ts +import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; +import { AppModule } from './app/app.module'; +// CHANGE: Add the following import import { defineCustomElements } from '@ionic/pwa-elements/loader'; -// Call the element loader before the bootstrapModule/bootstrapApplication call +// CHANGE: Call the element loader before the `bootstrapModule` call defineCustomElements(window); + +platformBrowserDynamic() + .bootstrapModule(AppModule) + .catch((err) => console.log(err)); ``` -That’s it! Now for the fun part - let’s see the app in action. +これで完了です!それでは、楽しい部分 - アプリの動作を見てみましょう。 ## アプリを起動 @@ -126,57 +132,107 @@ That’s it! Now for the fun part - let’s see the app in action. ionic serve ``` -And voilà! Your Ionic app is now running in a web browser. Most of your app can be built and tested right in the browser, greatly increasing development and testing speed. +そして、完成です!Ionic アプリが Web ブラウザで実行されています。アプリの大部分はブラウザ内で直接ビルドおよびテストできるため、開発とテストの速度が大幅に向上します。 -## Photo Gallery!!! +## Photo Gallery -There are three tabs. Click on the Tab2 tab. It’s a blank canvas, aka the perfect spot to transform into a Photo Gallery. The Ionic CLI features Live Reload, so when you make changes and save them, the app is updated immediately! +3 つのタブがあります。「Tab2」タブをクリックしてください。これは空白のキャンバス、つまり Photo Gallery に変換するのに最適な場所です。Ionic CLI には Live Reload 機能があるため、変更を加えて保存すると、アプリがすぐに更新されます! ![Animated GIF showing the live reload feature in an Ionic app, with changes in code immediately updating the app in a web browser.](/img/guides/first-app-cap-ng/email-photogallery.gif 'Live Reload Feature in Ionic App') -Open the photo-gallery app folder in your code editor of choice, then navigate to `/src/app/tab2/tab2.page.html`. We see: +`/src/app/tab2/tab2.page.html`を開きます。次のようになっています: ```html - + - Tab 2 + Tab 2 - + Tab 2 + + ``` -`ion-header` represents the top navigation and toolbar, with "Tab 2" as the title (there are two of them due to iOS [Collapsible Large Title](https://ionicframework.com/docs/api/title#collapsible-large-titles) support). Rename both `ion-title` elements to: +`ion-header`は上部のナビゲーションとツールバーを表し、「Tab 2」がタイトルです(iOS の[折りたたみ可能な大きなタイトル](../api/title.md#collapsible-large-titles)サポートにより、2 つあります)。両方の`ion-title`要素を次のように変更します: ```html -Photo Gallery + + + + Photo Gallery + + + + + + + + Photo Gallery + + + + + ``` -We put the visual aspects of our app into ``. In this case, it’s where we’ll add a button that opens the device’s camera as well as displays the image captured by the camera. Start by adding a [floating action button](https://ionicframework.com/docs/api/fab) (FAB) to the bottom of the page and set the camera image as the icon. +アプリの視覚的な側面を``に配置します。この場合、デバイスのカメラを開くボタンと、カメラでキャプチャした画像を表示する場所を追加します。まず、ページの下部に[フローティングアクションボタン](../api/fab.md)(FAB)を追加し、カメラ画像をアイコンとして設定します。 ```html + + + Photo Gallery + + + + + + Photo Gallery + + + + + + + ``` -Next, open `src/app/tabs/tabs.page.html`. Change the label to “Photos” and the icon name to “images”: +次に、`src/app/tabs/tabs.page.html`を開きます。中央のタブボタンのラベルを「Photos」に変更し、`ellipse`アイコンを`images`に変更します。 ```html - - - Photos - + + + + + Tab 1 + + + + + + + Photos + + + + + Tab 3 + + + ``` -Save all changes to see them automatically applied in the browser. That’s just the start of all the cool things we can do with Ionic. Up next, implement camera taking functionality on the web, then build it for iOS and Android. +これは、Ionic でできるすべての素晴らしいことの始まりに過ぎません。次に、Web でカメラ撮影機能を実装し、その後 iOS と Android 用にビルドします。 diff --git a/docs/angular/your-first-app/2-taking-photos.md b/docs/angular/your-first-app/2-taking-photos.md index efaa4f38961..072d0058da2 100644 --- a/docs/angular/your-first-app/2-taking-photos.md +++ b/docs/angular/your-first-app/2-taking-photos.md @@ -4,63 +4,102 @@ sidebar_label: カメラ撮影 --- - Build Camera API for iOS, Android & Web | Ionic Capacitor Camera + Take Photos with Camera API for iOS, Android & Web with Angular | Ionic Capacitor Camera -Now for the fun part - adding the ability to take photos with the device’s camera using the Capacitor [Camera API](https://capacitorjs.com/docs/apis/camera). We’ll begin with building it for the web, then make some small tweaks to make it work on mobile (iOS and Android). +Now for the fun part - adding the ability to take photos with the device’s camera using the Capacitor [Camera API](../../native/camera.md). We’ll begin with building it for the web, then make some small tweaks to make it work on mobile (iOS and Android). ## Photo Service All Capacitor logic (Camera usage and other native features) will be encapsulated in a service class. Create `PhotoService` using the `ionic generate` command: ```shell -ionic g service services/photo +ionic g service services/photo.service ``` -Open the new `services/photo.service.ts` file, and let’s add the logic that will power the camera functionality. First, import Capacitor dependencies and get references to the Camera, Filesystem, and Storage plugins: +Open the new `services/photo.service.ts` file, and let’s add the logic that will power the camera functionality. First, import Capacitor dependencies and get references to the `Camera`, `Filesystem`, and `Storage` plugins: -```tsx -import { Camera, CameraResultType, CameraSource, Photo } from '@capacitor/camera'; -import { Filesystem, Directory } from '@capacitor/filesystem'; -import { Preferences } from '@capacitor/preferences'; +```ts +import { Injectable } from '@angular/core'; +// CHANGE: Add the following import +import { Camera, CameraResultType, CameraSource } from '@capacitor/camera'; + +@Injectable({ + providedIn: 'root', +}) +export class PhotoService {} ``` -Next, define a new class method, `addNewToGallery`, that will contain the core logic to take a device photo and save it to the filesystem. Let’s start by opening the device camera: +Next, define a new class method, `addNewToGallery()`, that will contain the core logic to take a device photo and save it to the filesystem. Let’s start by opening the device camera. -```tsx -public async addNewToGallery() { - // Take a photo - const capturedPhoto = await Camera.getPhoto({ - resultType: CameraResultType.Uri, - source: CameraSource.Camera, - quality: 100 - }); +```ts +import { Injectable } from '@angular/core'; +import { Camera, CameraResultType, CameraSource } from '@capacitor/camera'; + +@Injectable({ + providedIn: 'root', +}) +export class PhotoService { + // CHANGE: Add the gallery method + public async addNewToGallery() { + // Take a photo + const capturedPhoto = await Camera.getPhoto({ + resultType: CameraResultType.Uri, + source: CameraSource.Camera, + quality: 100, + }); + } } ``` Notice the magic here: there's no platform-specific code (web, iOS, or Android)! The Capacitor Camera plugin abstracts that away for us, leaving just one method call - `Camera.getPhoto()` - that will open up the device's camera and allow us to take photos. -Next, open up `tab2.page.ts` and import the PhotoService class and add a method that calls the `addNewToGallery` method on the imported service: +Next, in `tab2.page.ts`, import the `PhotoService` class and add a method to call its `addNewToGallery` method. -```tsx +```ts +import { Component } from '@angular/core'; +// CHANGE: Import the PhotoService import { PhotoService } from '../services/photo.service'; -constructor(public photoService: PhotoService) { } - -addPhotoToGallery() { - this.photoService.addNewToGallery(); +@Component({ + selector: 'app-tab2', + templateUrl: 'tab2.page.html', + styleUrls: ['tab2.page.scss'], + standalone: false, +}) +export class Tab2Page { + // CHANGE: Update constructor to include `photoService` + constructor(public photoService: PhotoService) {} + + // CHANGE: Add `addNewToGallery()` method + addPhotoToGallery() { + this.photoService.addNewToGallery(); + } } ``` -Then, open `tab2.page.html` and call the `addPhotoToGallery()` function when the FAB is tapped/clicked: +Then, open `tab2.page.html` and call the `addPhotoToGallery()` method when the FAB is tapped/clicked: ```html - + + + Photo Gallery + + + + + + + Photo Gallery + + + + @@ -68,7 +107,7 @@ Then, open `tab2.page.html` and call the `addPhotoToGallery()` function when the ``` -Save the file, and if it's not running already, restart the development server in your browser by running `ionic serve`. On the Photo Gallery tab, click the Camera button. If your computer has a webcam of any sort, a modal window appears. Take a selfie! +If it's not running already, restart the development server in your browser by running `ionic serve`. On the Photo Gallery tab, click the Camera button. If your computer has a webcam of any sort, a modal window appears. Take a selfie! ![A photo gallery app displaying a webcam selfie.](/img/guides/first-app-cap-ng/camera-web.png 'Webcam Selfie in Photo Gallery') @@ -78,34 +117,46 @@ After taking a photo, it disappears right away. We need to display it within our ## Displaying Photos -Outside of the `PhotoService` class definition (the very bottom of the file), create a new interface, `UserPhoto`, to hold our photo metadata: +To define the data structure for our photo metadata, create a new interface named `UserPhoto`. Add this interface at the very bottom of the `photo.service.ts` file, immediately after the `PhotoService` class definition: -```tsx +```ts +export class PhotoService { + // ...existing code... +} + +// CHANGE: Add the `UserPhoto` interface export interface UserPhoto { filepath: string; webviewPath?: string; } ``` -Back at the top of the file, define an array of Photos, which will contain a reference to each photo captured with the Camera. +Above the `addNewToGallery()` method, define an array of `UserPhoto`, which will contain a reference to each photo captured with the Camera. -```tsx +```ts export class PhotoService { + // CHANGE: Add the `photos` array public photos: UserPhoto[] = []; - // other code + public async addNewToGallery() { + // ...existing code... + } } ``` -Over in the `addNewToGallery` function, add the newly captured photo to the beginning of the Photos array. +Over in the `addNewToGallery` method, add the newly captured photo to the beginning of the `photos` array. -```tsx +```ts +// CHANGE: Update `addNewToGallery()` method +public async addNewToGallery() { + // Take a photo const capturedPhoto = await Camera.getPhoto({ resultType: CameraResultType.Uri, source: CameraSource.Camera, quality: 100 }); + // CHANGE: Add the new photo to the photos array this.photos.unshift({ filepath: "soon...", webviewPath: capturedPhoto.webPath! @@ -113,22 +164,73 @@ Over in the `addNewToGallery` function, add the newly captured photo to the begi } ``` -Next, move over to `tab2.page.html` so we can display the image on the screen. Add a [Grid component](https://ionicframework.com/docs/api/grid) so that each photo will display nicely as photos are added to the gallery, and loop through each photo in the `PhotoServices`'s Photos array, adding an Image component (``) for each. Point the `src` (source) at the photo’s path: +`photo.service.ts` should now look like this: + +```ts +import { Injectable } from '@angular/core'; +import { Camera, CameraResultType, CameraSource } from '@capacitor/camera'; + +@Injectable({ + providedIn: 'root', +}) +export class PhotoService { + public photos: UserPhoto[] = []; + + public async addNewToGallery() { + // Take a photo + const capturedPhoto = await Camera.getPhoto({ + resultType: CameraResultType.Uri, + source: CameraSource.Camera, + quality: 100, + }); + + this.photos.unshift({ + filepath: 'soon...', + webviewPath: capturedPhoto.webPath!, + }); + } +} + +export interface UserPhoto { + filepath: string; + webviewPath?: string; +} +``` + +Next, switch to `tab2.page.html` to display the images. We'll add a [Grid component](../../api/grid.md) to ensure the photos display neatly as they're added to the gallery. Inside the grid, loop through each photo in the `PhotoService`'s `photos` array. For each item, add an [Image component](../../api/img.md) and set its `src` property to the photo's path. ```html - + + + Photo Gallery + + + + + + + Photo Gallery + + + + + - + + + + + ``` -Save all files. Within the web browser, click the Camera button and take another photo. This time, the photo is displayed in the Photo Gallery! +Within the web browser, click the camera button and take another photo. This time, the photo is displayed in the Photo Gallery! Up next, we’ll add support for saving the photos to the filesystem, so they can be retrieved and displayed in our app at a later time. diff --git a/docs/angular/your-first-app/3-saving-photos.md b/docs/angular/your-first-app/3-saving-photos.md index cf9b948c221..9b6fffcaf70 100644 --- a/docs/angular/your-first-app/3-saving-photos.md +++ b/docs/angular/your-first-app/3-saving-photos.md @@ -1,81 +1,220 @@ --- +title: Saving Photos to the Filesystem sidebar_label: 写真の保存 --- -# Saving Photos to the Filesystem + + Saving Photos to the Filesystem with Angular | Ionic Capacitor Camera + + We’re now able to take multiple photos and display them in a photo gallery on the second tab of our app. These photos, however, are not currently being stored permanently, so when the app is closed, they will be deleted. ## Filesystem API -Fortunately, saving them to the filesystem only takes a few steps. Begin by creating a new class method, `savePicture()`, in the `PhotoService` class (`src/app/services/photo.service.ts`). We pass in the `photo` object, which represents the newly captured device photo: +Fortunately, saving them to the filesystem only takes a few steps. Begin by creating a new class method, `savePicture()`, in the `PhotoService` class. We pass in the `photo` object, which represents the newly captured device photo: + +```ts +import { Camera, CameraResultType, CameraSource } from '@capacitor/camera'; +// CHANGE: Add import +import type { Photo } from '@capacitor/camera'; + +@Injectable({ + providedIn: 'root', +}) +export class PhotoService { + // ...existing code... + + // CHANGE: Add the `savePicture()` method + private async savePicture(photo: Photo) { + return { + filepath: 'soon...', + webviewPath: 'soon...', + }; + } +} -```tsx -private async savePicture(photo: Photo) { } +export interface UserPhoto { + filepath: string; + webviewPath?: string; +} ``` -We can use this new method immediately in `addNewToGallery()`: - -```tsx -public async addNewToGallery() { - // Take a photo - const capturedPhoto = await Camera.getPhoto({ - resultType: CameraResultType.Uri, // file-based data; provides best performance - source: CameraSource.Camera, // automatically take a new photo with the camera - quality: 100 // highest quality (0 to 100) - }); - - // Save the picture and add it to photo collection - const savedImageFile = await this.savePicture(capturedPhoto); - this.photos.unshift(savedImageFile); +We can use this new method immediately in `addNewToGallery()`. + +```ts +import { Injectable } from '@angular/core'; +import { Camera, CameraResultType, CameraSource, Photo } from '@capacitor/camera'; + +@Injectable({ + providedIn: 'root', +}) +export class PhotoService { + public photos: UserPhoto[] = []; + + // CHANGE: Update the `addNewToGallery()` method + public async addNewToGallery() { + // Take a photo + const capturedPhoto = await Camera.getPhoto({ + resultType: CameraResultType.Uri, + source: CameraSource.Camera, + quality: 100, + }); + + // CHANGE: Add `savedImageFile` + // Save the picture and add it to photo collection + const savedImageFile = await this.savePicture(capturedPhoto); + + // CHANGE: Update argument to unshift array method + this.photos.unshift(savedImageFile); + } + + private async savePicture(photo: Photo) { + return { + filepath: 'soon...', + webviewPath: 'soon...', + }; + } } -``` -We’ll use the Capacitor [Filesystem API](https://capacitorjs.com/docs/apis/filesystem) to save the photo to the filesystem. To start, convert the photo to base64 format, then feed the data to the Filesystem’s `writeFile` function. As you’ll recall, we display each photo on the screen by setting each image’s source path (`src` attribute) in `tab2.page.html` to the webviewPath property. So, set it then return the new Photo object. - -```tsx -private async savePicture(photo: Photo) { - // Convert photo to base64 format, required by Filesystem API to save - const base64Data = await this.readAsBase64(photo); - - // Write the file to the data directory - const fileName = Date.now() + '.jpeg'; - const savedFile = await Filesystem.writeFile({ - path: fileName, - data: base64Data, - directory: Directory.Data - }); - - // Use webPath to display the new image instead of base64 since it's - // already loaded into memory - return { - filepath: fileName, - webviewPath: photo.webPath - }; +export interface UserPhoto { + filepath: string; + webviewPath?: string; } ``` -`readAsBase64()` is a helper function we’ll define next. It's useful to organize via a separate method since it requires a small amount of platform-specific (web vs. mobile) logic - more on that in a bit. For now, implement the logic for running on the web: +We'll use the Capacitor [Filesystem API](../../native/filesystem.md) to save the photo. First, convert the photo to base64 format. + +Then, pass the data to the Filesystem's `writeFile` method. Recall that we display photos by setting the image's source path (`src`) to the `webviewPath` property. So, set the `webviewPath` and return the new `Photo` object. + +For now, create a new helper method, `convertBlobToBase64()`, to implement the necessary logic for running on the web. + +```ts +import { Injectable } from '@angular/core'; +import { Camera, CameraResultType, CameraSource } from '@capacitor/camera'; +import type { Photo } from '@capacitor/camera'; +// CHANGE: Add import +import { Filesystem, Directory } from '@capacitor/filesystem'; + +@Injectable({ + providedIn: 'root', +}) +export class PhotoService { + // ...existing code... + + // CHANGE: Update the `savePicture()` method + private async savePicture(photo: Photo) { + // Fetch the photo, read as a blob, then convert to base64 format + const response = await fetch(photo.webPath!); + const blob = await response.blob(); + const base64Data = (await this.convertBlobToBase64(blob)) as string; + + // Write the file to the data directory + const fileName = Date.now() + '.jpeg'; + const savedFile = await Filesystem.writeFile({ + path: fileName, + data: base64Data, + directory: Directory.Data, + }); + + // Use webPath to display the new image instead of base64 since it's + // already loaded into memory + return { + filepath: fileName, + webviewPath: photo.webPath, + }; + } + + // CHANGE: Add the `convertBlobToBase64` method + private convertBlobToBase64(blob: Blob) { + return new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.onerror = reject; + reader.onload = () => { + resolve(reader.result); + }; + reader.readAsDataURL(blob); + }); + } +} -```tsx -private async readAsBase64(photo: Photo) { - // Fetch the photo, read as a blob, then convert to base64 format - const response = await fetch(photo.webPath!); - const blob = await response.blob(); +export interface UserPhoto { + filepath: string; + webviewPath?: string; +} +``` - return await this.convertBlobToBase64(blob) as string; +`photo.service.ts` should now look like this: + +```ts +import { Injectable } from '@angular/core'; +import { Camera, CameraResultType, CameraSource } from '@capacitor/camera'; +import type { Photo } from '@capacitor/camera'; +import { Filesystem, Directory } from '@capacitor/filesystem'; + +@Injectable({ + providedIn: 'root', +}) +export class PhotoService { + public photos: UserPhoto[] = []; + + public async addNewToGallery() { + // Take a photo + const capturedPhoto = await Camera.getPhoto({ + resultType: CameraResultType.Uri, + source: CameraSource.Camera, + quality: 100, + }); + + // Save the picture and add it to photo collection + const savedImageFile = await this.savePicture(capturedPhoto); + + this.photos.unshift(savedImageFile); + } + + private async savePicture(photo: Photo) { + // Fetch the photo, read as a blob, then convert to base64 format + const response = await fetch(photo.webPath!); + const blob = await response.blob(); + const base64Data = (await this.convertBlobToBase64(blob)) as string; + + // Write the file to the data directory + const fileName = Date.now() + '.jpeg'; + const savedFile = await Filesystem.writeFile({ + path: fileName, + data: base64Data, + directory: Directory.Data, + }); + + // Use webPath to display the new image instead of base64 since it's + // already loaded into memory + return { + filepath: fileName, + webviewPath: photo.webPath, + }; + } + + private convertBlobToBase64(blob: Blob) { + return new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.onerror = reject; + reader.onload = () => { + resolve(reader.result); + }; + reader.readAsDataURL(blob); + }); + } } -private convertBlobToBase64 = (blob: Blob) => new Promise((resolve, reject) => { - const reader = new FileReader(); - reader.onerror = reject; - reader.onload = () => { - resolve(reader.result); - }; - reader.readAsDataURL(blob); -}); +export interface UserPhoto { + filepath: string; + webviewPath?: string; +} ``` Obtaining the camera photo as base64 format on the web appears to be a bit trickier than on mobile. In reality, we’re just using built-in web APIs: [fetch()](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) as a neat way to read the file into blob format, then FileReader’s [readAsDataURL()](https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsDataURL) to convert the photo blob to base64. -There we go! Each time a new photo is taken, it’s now automatically saved to the filesystem. +There we go! Each time a new photo is taken, it’s now automatically saved to the filesystem. Next up, we'll load and display our saved images. diff --git a/docs/angular/your-first-app/4-loading-photos.md b/docs/angular/your-first-app/4-loading-photos.md index f2fc61b1fd1..26d8371524d 100644 --- a/docs/angular/your-first-app/4-loading-photos.md +++ b/docs/angular/your-first-app/4-loading-photos.md @@ -1,69 +1,247 @@ --- +title: Loading Photos from the Filesystem sidebar_label: 写真の読み込み --- -# Loading Photos from the Filesystem + + Loading Photos from the Filesystem with Angular | Ionic Capacitor Camera + + We’ve implemented photo taking and saving to the filesystem. There’s one last piece of functionality missing: the photos are stored in the filesystem, but we need a way to save pointers to each file so that they can be displayed again in the photo gallery. -Fortunately, this is easy: we’ll leverage the Capacitor [Preferences API](https://capacitorjs.com/docs/apis/preferences) to store our array of Photos in a key-value store. +Fortunately, this is easy: we’ll leverage the Capacitor [Preferences API](../../native/preferences.md) to store our array of Photos in a key-value store. ## Preferences API -Begin by defining a constant variable that will act as the key for the store: +Open `photo.service.ts` and begin by defining a new property in the `PhotoService` class that will act as the key for the store. -```tsx +```ts export class PhotoService { public photos: UserPhoto[] = []; + + // CHANGE: Add a key for photo storage private PHOTO_STORAGE: string = 'photos'; - // other code + // ...existing code... } ``` -Next, at the end of the `addNewToGallery` function, add a call to `Preferences.set()` to save the Photos array. By adding it here, the Photos array is stored each time a new photo is taken. This way, it doesn’t matter when the app user closes or switches to a different app - all photo data is saved. +Next, at the end of the `addNewToGallery()` method, add a call to `Preferences.set()` to save the `photos` array. By adding it here, the `photos` array is stored each time a new photo is taken. This way, it doesn’t matter when the app user closes or switches to a different app - all photo data is saved. + +```ts +import { Injectable } from '@angular/core'; +import { Camera, CameraResultType, CameraSource } from '@capacitor/camera'; +import type { Photo } from '@capacitor/camera'; +import { Filesystem, Directory } from '@capacitor/filesystem'; +// CHANGE: Add import +import { Preferences } from '@capacitor/preferences'; + +@Injectable({ + providedIn: 'root', +}) +export class PhotoService { + // ...existing code... + + // CHANGE: Update `addNewToGallery()` method + public async addNewToGallery() { + // Take a photo + const capturedPhoto = await Camera.getPhoto({ + resultType: CameraResultType.Uri, + source: CameraSource.Camera, + quality: 100, + }); + + const savedImageFile = await this.savePicture(capturedPhoto); + + this.photos.unshift(savedImageFile); + + // CHANGE: Add method to cache all photo data for future retrieval + Preferences.set({ + key: this.PHOTO_STORAGE, + value: JSON.stringify(this.photos), + }); + } -```tsx -Preferences.set({ - key: this.PHOTO_STORAGE, - value: JSON.stringify(this.photos), -}); + // ...existing code... +} + +export interface UserPhoto { + filepath: string; + webviewPath?: string; +} ``` -With the photo array data saved, create a function called `loadSaved()` that can retrieve that data. We use the same key to retrieve the photos array in JSON format, then parse it into an array: +With the photo array data saved, create a new public method in the `PhotoService` class called `loadSaved()` that can retrieve the photo data. We use the same key to retrieve the `photos` array in JSON format, then parse it into an array: + +```ts +export class PhotoService { + // ...existing code... + + // CHANGE: Add the method to load the photo data + public async loadSaved() { + // Retrieve cached photo array data + const { value: photoList } = await Preferences.get({ key: this.PHOTO_STORAGE }); + this.photos = (photoList ? JSON.parse(photoList) : []) as UserPhoto[]; + } +} +``` -```tsx -public async loadSaved() { - // Retrieve cached photo array data - const { value } = await Preferences.get({ key: this.PHOTO_STORAGE }); - this.photos = (value ? JSON.parse(value) : []) as UserPhoto[]; +On mobile (coming up next!), we can directly set the source of an image tag - `` - to each photo file on the `Filesystem`, displaying them automatically. On the web, however, we must read each image from the `Filesystem` into base64 format, using a new `base64` property on the `Photo` object. This is because the `Filesystem` API uses [IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API) under the hood. Add the following code to complete the `loadSaved()` method: - // more to come... +```ts +export class PhotoService { + // ...existing code... + + // CHANGE: Update the `loadSaved()` method + public async loadSaved() { + // Retrieve cached photo array data + const { value: photoList } = await Preferences.get({ key: this.PHOTO_STORAGE }); + this.photos = (photoList ? JSON.parse(photoList) : []) as UserPhoto[]; + + // CHANGE: Display the photo by reading into base64 format + for (let photo of this.photos) { + // Read each saved photo's data from the Filesystem + const readFile = await Filesystem.readFile({ + path: photo.filepath, + directory: Directory.Data, + }); + + // Web platform only: Load the photo as base64 data + photo.webviewPath = `data:image/jpeg;base64,${readFile.data}`; + } + } } ``` -On mobile (coming up next!), we can directly set the source of an image tag - `` - to each photo file on the Filesystem, displaying them automatically. On the web, however, we must read each image from the Filesystem into base64 format, using a new `base64` property on the `Photo` object. This is because the Filesystem API uses [IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API) under the hood. Below is the code you need to add in the `loadSaved()` function you just added: +`photo.service.ts` should now look like this: + +```ts +import { Injectable } from '@angular/core'; +import { Camera, CameraResultType, CameraSource } from '@capacitor/camera'; +import type { Photo } from '@capacitor/camera'; +import { Filesystem, Directory } from '@capacitor/filesystem'; +import { Preferences } from '@capacitor/preferences'; + +@Injectable({ + providedIn: 'root', +}) +export class PhotoService { + public photos: UserPhoto[] = []; + + private PHOTO_STORAGE: string = 'photos'; -```tsx -// Display the photo by reading into base64 format -for (let photo of this.photos) { - // Read each saved photo's data from the Filesystem - const readFile = await Filesystem.readFile({ - path: photo.filepath, - directory: Directory.Data, - }); + public async addNewToGallery() { + // Take a photo + const capturedPhoto = await Camera.getPhoto({ + resultType: CameraResultType.Uri, + source: CameraSource.Camera, + quality: 100, + }); + + // Save the picture and add it to photo collection + const savedImageFile = await this.savePicture(capturedPhoto); + + this.photos.unshift(savedImageFile); + + Preferences.set({ + key: this.PHOTO_STORAGE, + value: JSON.stringify(this.photos), + }); + } + + private async savePicture(photo: Photo) { + // Fetch the photo, read as a blob, then convert to base64 format + const response = await fetch(photo.webPath!); + const blob = await response.blob(); + const base64Data = (await this.convertBlobToBase64(blob)) as string; + + // Write the file to the data directory + const fileName = Date.now() + '.jpeg'; + const savedFile = await Filesystem.writeFile({ + path: fileName, + data: base64Data, + directory: Directory.Data, + }); + + // Use webPath to display the new image instead of base64 since it's + // already loaded into memory + return { + filepath: fileName, + webviewPath: photo.webPath, + }; + } + + private convertBlobToBase64(blob: Blob) { + return new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.onerror = reject; + reader.onload = () => { + resolve(reader.result); + }; + reader.readAsDataURL(blob); + }); + } + + public async loadSaved() { + // Retrieve cached photo array data + const { value: photoList } = await Preferences.get({ key: this.PHOTO_STORAGE }); + this.photos = (photoList ? JSON.parse(photoList) : []) as UserPhoto[]; + + for (let photo of this.photos) { + // Read each saved photo's data from the Filesystem + const readFile = await Filesystem.readFile({ + path: photo.filepath, + directory: Directory.Data, + }); + + // Web platform only: Load the photo as base64 data + photo.webviewPath = `data:image/jpeg;base64,${readFile.data}`; + } + } +} - // Web platform only: Load the photo as base64 data - photo.webviewPath = `data:image/jpeg;base64,${readFile.data}`; +export interface UserPhoto { + filepath: string; + webviewPath?: string; } ``` -After, call this new method in `tab2.page.ts` so that when the user first navigates to Tab 2 (the Photo Gallery), all photos are loaded and displayed on the screen. +Our `PhotoService` can now load the saved images, but we'll need to update `tab2.page.ts` to put that new code to work. We'll call `loadSaved()` within the [ngOnInit](https://angular.dev/guide/components/lifecycle#ngoninit) lifecycle method so that when the user first navigates to the Photo Gallery, all photos are loaded and displayed on the screen. + +Update `tab2.page.ts` to look like the following: + +```ts +import { Component } from '@angular/core'; +import { PhotoService } from '../services/photo.service'; + +@Component({ + selector: 'app-tab2', + templateUrl: 'tab2.page.html', + styleUrls: ['tab2.page.scss'], + standalone: false, +}) +export class Tab2Page { + constructor(public photoService: PhotoService) {} -```tsx -async ngOnInit() { - await this.photoService.loadSaved(); + // CHANGE: Add call to `loadSaved()` when navigating to the Photos tab + async ngOnInit() { + await this.photoService.loadSaved(); + } + + addPhotoToGallery() { + this.photoService.addNewToGallery(); + } } ``` +:::note +If you're seeing broken image links or missing photos after following these steps, you may need to open your browser's dev tools and clear both [localStorage](https://developer.chrome.com/docs/devtools/storage/localstorage) and [IndexedDB](https://developer.chrome.com/docs/devtools/storage/indexeddb). + +In localStorage, look for domain `http://localhost:8100` and key `CapacitorStorage.photos`. In IndexedDB, find a store called "FileStorage". Your photos will have a key like `/DATA/123456789012.jpeg`. +::: + That’s it! We’ve built a complete Photo Gallery feature in our Ionic app that works on the web. Next up, we’ll transform it into a mobile app for iOS and Android! diff --git a/docs/angular/your-first-app/5-adding-mobile.md b/docs/angular/your-first-app/5-adding-mobile.md index 16235a008a4..9a33d3745ee 100644 --- a/docs/angular/your-first-app/5-adding-mobile.md +++ b/docs/angular/your-first-app/5-adding-mobile.md @@ -1,8 +1,15 @@ --- +title: Adding Mobile strip_number_prefixes: false --- -# モバイルデバイス機能の追加 + + モバイルデバイス機能の追加 with Angular | Ionic Capacitor Camera + + Our photo gallery app won’t be complete until it runs on iOS, Android, and the web - all using one codebase. All it takes is some small logic changes to support mobile platforms, installing some native tooling, then running the app on a device. Let’s go! @@ -10,98 +17,154 @@ Our photo gallery app won’t be complete until it runs on iOS, Android, and the Let’s start with making some small code changes - then our app will “just work” when we deploy it to a device. -Import the Ionic [Platform API](https://ionicframework.com/docs/angular/platform) into `photo.service.ts`, which is used to retrieve information about the current device. In this case, it’s useful for selecting which code to execute based on the platform the app is running on (web or mobile): +Import the Ionic [Platform API](../platform.md) into `photo.service.ts`, which is used to retrieve information about the current device. In this case, it’s useful for selecting which code to execute based on the platform the app is running on (web or mobile). -```tsx +Add `Platform` to the imports at the top of the file and a new property `platform` to the `PhotoService` class. We'll also need to update the constructor to set the user's platform. + +```ts +import { Injectable } from '@angular/core'; +import { Camera, CameraResultType, CameraSource } from '@capacitor/camera'; +import type { Photo } from '@capacitor/camera'; +import { Filesystem, Directory } from '@capacitor/filesystem'; +import { Preferences } from '@capacitor/preferences'; +// CHANGE: Add import import { Platform } from '@ionic/angular'; +@Injectable({ + providedIn: 'root', +}) export class PhotoService { public photos: UserPhoto[] = []; + private PHOTO_STORAGE: string = 'photos'; + + // CHANGE: Add a property to track the app's running platform private platform: Platform; + // CHANGE: Update constructor to set `platform` constructor(platform: Platform) { this.platform = platform; } - // other code + // ...existing code... } ``` ## Platform-specific Logic -First, we’ll update the photo saving functionality to support mobile. In the `readAsBase64()` function, check which platform the app is running on. If it’s “hybrid” (Capacitor or Cordova, two native runtimes), then read the photo file into base64 format using the Filesystem `readFile()` method. Otherwise, use the same logic as before when running the app on the web: +First, we’ll update the photo saving functionality to support mobile. In the `savePicture()` method, check which platform the app is running on. If it’s “hybrid” (Capacitor, the native runtime), then read the photo file into base64 format using the `Filesystem.readFile()` method. Otherwise, use the same logic as before when running the app on the web. + +Update `savePicture()` to look like the following: + +```ts +// CHANGE: Update the `savePicture()` method +private async savePicture(photo: Photo) { + let base64Data: string | Blob; -```tsx -private async readAsBase64(photo: Photo) { + // CHANGE: Add platform check // "hybrid" will detect Cordova or Capacitor if (this.platform.is('hybrid')) { // Read the file into base64 format const file = await Filesystem.readFile({ path: photo.path! }); - - return file.data; - } - else { + base64Data = file.data; + } else { // Fetch the photo, read as a blob, then convert to base64 format const response = await fetch(photo.webPath!); const blob = await response.blob(); - - return await this.convertBlobToBase64(blob) as string; + base64Data = await this.convertBlobToBase64(blob) as string; } + + // Write the file to the data directory + const fileName = Date.now() + '.jpeg'; + const savedFile = await Filesystem.writeFile({ + path: fileName, + data: base64Data, + directory: Directory.Data + }); + + // Use webPath to display the new image instead of base64 since it's + // already loaded into memory + return { + filepath: fileName, + webviewPath: photo.webPath, + }; } ``` -Next, update the `savePicture()` method. When running on mobile, set `filepath` to the result of the `writeFile()` operation - `savedFile.uri`. When setting the `webviewPath`, use the special `Capacitor.convertFileSrc()` method ([details here](https://ionicframework.com/docs/core-concepts/webview#file-protocol)). +When running on mobile, set `filepath` to the result of the `writeFile()` operation - `savedFile.uri`. When setting the `webviewPath`, use the special `Capacitor.convertFileSrc()` method ([details on the File Protocol](../../core-concepts/webview.md#file-protocol)). To use this method, we'll need to import Capacitor into `photo.service.ts`. + +```ts +import { Injectable } from '@angular/core'; +import { Camera, CameraResultType, CameraSource } from '@capacitor/camera'; +import type { Photo } from '@capacitor/camera'; +import { Filesystem, Directory } from '@capacitor/filesystem'; +import { Preferences } from '@capacitor/preferences'; +import { Platform } from '@ionic/angular'; +// Change: Add import +import { Capacitor } from '@capacitor/core'; -```tsx -// Save picture to file on device +// ...existing code... +``` + +Then update `savePicture()` to look like the following: + +```ts +// CHANGE: Update `savePicture()` method private async savePicture(photo: Photo) { - // Convert photo to base64 format, required by Filesystem API to save - const base64Data = await this.readAsBase64(photo); + let base64Data: string | Blob; + // "hybrid" will detect mobile - iOS or Android + if (this.platform.is('hybrid')) { + const file = await Filesystem.readFile({ + path: photo.path!, + }); + base64Data = file.data; + } else { + // Fetch the photo, read as a blob, then convert to base64 format + const response = await fetch(photo.webPath!); + const blob = await response.blob(); + base64Data = await this.convertBlobToBase64(blob) as string; + } // Write the file to the data directory const fileName = Date.now() + '.jpeg'; const savedFile = await Filesystem.writeFile({ path: fileName, data: base64Data, - directory: Directory.Data + directory: Directory.Data, }); + // CHANGE: Add platform check if (this.platform.is('hybrid')) { // Display the new image by rewriting the 'file://' path to HTTP - // Details: https://ionicframework.com/docs/building/webview#file-protocol return { filepath: savedFile.uri, webviewPath: Capacitor.convertFileSrc(savedFile.uri), }; - } - else { + } else { // Use webPath to display the new image instead of base64 since it's // already loaded into memory return { filepath: fileName, - webviewPath: photo.webPath + webviewPath: photo.webPath, }; } } ``` -Next, head back over to the `loadSaved()` function we implemented for the web earlier. On mobile, we can directly set the source of an image tag - `` - to each photo file on the Filesystem, displaying them automatically. Thus, only the web requires reading each image from the Filesystem into base64 format. Update this function to add an _if statement_ around the Filesystem code: +Next, add a new bit of logic in the `loadSaved()` method. On mobile, we can directly point to each photo file on the Filesystem and display them automatically. On the web, however, we must read each image from the Filesystem into base64 format. This is because the Filesystem API uses [IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API) under the hood. Update the `loadSaved()` method: -```tsx +```ts +// CHANGE: Update `loadSaved()` method public async loadSaved() { - // Retrieve cached photo array data - const { value } = await Preferences.get({ key: this.PHOTO_STORAGE }); - this.photos = (value ? JSON.parse(value) : []) as UserPhoto[]; + const { value: photoList } = await Preferences.get({ key: this.PHOTO_STORAGE }); + this.photos = (photoList ? JSON.parse(photoList) : []) as UserPhoto[]; - // Easiest way to detect when running on the web: - // “when the platform is NOT hybrid, do this” + // CHANGE: Add platform check + // If running on the web... if (!this.platform.is('hybrid')) { - // Display the photo by reading into base64 format for (let photo of this.photos) { - // Read each saved photo's data from the Filesystem const readFile = await Filesystem.readFile({ path: photo.filepath, directory: Directory.Data @@ -114,4 +177,128 @@ public async loadSaved() { } ``` -Our Photo Gallery now consists of one codebase that runs on the web, Android, and iOS. Next up, the part you’ve been waiting for - deploying the app to a device. +Our Photo Gallery now consists of one codebase that runs on the web, Android, and iOS. + +`photos.service.ts` should now look like this: + +```ts +import { Injectable } from '@angular/core'; +import { Camera, CameraResultType, CameraSource } from '@capacitor/camera'; +import type { Photo } from '@capacitor/camera'; +import { Filesystem, Directory } from '@capacitor/filesystem'; +import { Preferences } from '@capacitor/preferences'; +import { Platform } from '@ionic/angular'; +import { Capacitor } from '@capacitor/core'; + +@Injectable({ + providedIn: 'root', +}) +export class PhotoService { + public photos: UserPhoto[] = []; + + private PHOTO_STORAGE: string = 'photos'; + + private platform: Platform; + + constructor(platform: Platform) { + this.platform = platform; + } + + public async addNewToGallery() { + // Take a photo + const capturedPhoto = await Camera.getPhoto({ + resultType: CameraResultType.Uri, + source: CameraSource.Camera, + quality: 100, + }); + + const savedImageFile = await this.savePicture(capturedPhoto); + + this.photos.unshift(savedImageFile); + + Preferences.set({ + key: this.PHOTO_STORAGE, + value: JSON.stringify(this.photos), + }); + } + + private async savePicture(photo: Photo) { + let base64Data: string | Blob; + + // "hybrid" will detect Cordova or Capacitor + if (this.platform.is('hybrid')) { + // Read the file into base64 format + const file = await Filesystem.readFile({ + path: photo.path!, + }); + + base64Data = file.data; + } else { + // Fetch the photo, read as a blob, then convert to base64 format + const response = await fetch(photo.webPath!); + const blob = await response.blob(); + + base64Data = (await this.convertBlobToBase64(blob)) as string; + } + + // Write the file to the data directory + const fileName = Date.now() + '.jpeg'; + const savedFile = await Filesystem.writeFile({ + path: fileName, + data: base64Data, + directory: Directory.Data, + }); + + if (this.platform.is('hybrid')) { + // Display the new image by rewriting the 'file://' path to HTTP + return { + filepath: savedFile.uri, + webviewPath: Capacitor.convertFileSrc(savedFile.uri), + }; + } else { + // Use webPath to display the new image instead of base64 since it's + // already loaded into memory + return { + filepath: fileName, + webviewPath: photo.webPath, + }; + } + } + + private convertBlobToBase64(blob: Blob) { + return new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.onerror = reject; + reader.onload = () => { + resolve(reader.result); + }; + reader.readAsDataURL(blob); + }); + } + + public async loadSaved() { + // Retrieve cached photo array data + const { value: photoList } = await Preferences.get({ key: this.PHOTO_STORAGE }); + this.photos = (photoList ? JSON.parse(photoList) : []) as UserPhoto[]; + + // If running on the web... + if (!this.platform.is('hybrid')) { + for (let photo of this.photos) { + const readFile = await Filesystem.readFile({ + path: photo.filepath, + directory: Directory.Data, + }); + // Web platform only: Load the photo as base64 data + photo.webviewPath = `data:image/jpeg;base64,${readFile.data}`; + } + } + } +} + +export interface UserPhoto { + filepath: string; + webviewPath?: string; +} +``` + +Next up, the part you’ve been waiting for - deploying the app to a device. diff --git a/docs/angular/your-first-app/6-deploying-mobile.md b/docs/angular/your-first-app/6-deploying-mobile.md index 06ae7100d8f..06638c9c34d 100644 --- a/docs/angular/your-first-app/6-deploying-mobile.md +++ b/docs/angular/your-first-app/6-deploying-mobile.md @@ -4,20 +4,20 @@ sidebar_label: モバイルへのデプロイ --- - Deploying to iOS and Android Apps - Capacitor Setup on Ionic + Adding Mobile Support with Angular | Ionic Capacitor Camera -Since we added Capacitor to our project when it was first created, there’s only a handful of steps remaining until the Photo Gallery app is on our device! Remember, you can find the complete source code for this app [here](https://github.com/ionic-team/photo-gallery-capacitor-ng). +Since we added Capacitor to our project when it was first created, there’s only a handful of steps remaining until the Photo Gallery app is on our device! ## Capacitor Setup Capacitor is Ionic’s official app runtime that makes it easy to deploy web apps to native platforms like iOS, Android, and more. If you’ve used Cordova in the past, consider reading more about the differences [here](https://capacitorjs.com/docs/cordova#differences-between-capacitor-and-cordova). -If you’re still running `ionic serve` in the terminal, cancel it. Complete a fresh build of your Ionic project, fixing any errors that it reports: +If you’re still running `ionic serve` in the terminal, cancel it. Complete a fresh build of the Ionic project, fixing any errors that it reports: ```shell ionic build @@ -26,8 +26,8 @@ ionic build Next, create both the iOS and Android projects: ```shell -$ ionic cap add ios -$ ionic cap add android +ionic cap add ios +ionic cap add android ``` Both android and ios folders at the root of the project are created. These are entirely standalone native projects that should be considered part of your Ionic app (i.e., check them into source control, edit them using their native tooling, etc.). @@ -46,7 +46,7 @@ ionic cap sync ## iOS Deployment -:::note +:::important To build an iOS app, you’ll need a Mac computer. ::: @@ -58,7 +58,7 @@ First, run the Capacitor `open` command, which opens the native iOS project in X ionic cap open ios ``` -In order for some native plugins to work, user permissions must be configured. In our photo gallery app, this includes the Camera plugin: iOS displays a modal dialog automatically after the first time that `Camera.getPhoto()` is called, prompting the user to allow the app to use the Camera. The permission that drives this is labeled “Privacy - Camera Usage.” To set it, the `Info.plist` file must be modified ([more details here](https://capacitorjs.com/docs/ios/configuration)). To access it, click "Info," then expand "Custom iOS Target Properties." +In order for some native plugins to work, user permissions must be configured. In our photo gallery app, this includes the Camera plugin: iOS displays a modal dialog automatically after the first time that `Camera.getPhoto()` is called, prompting the user to allow the app to use the Camera. The permission that drives this is labeled "Privacy - Camera Usage." To set it, the `Info.plist` file must be modified ([more details here](https://capacitorjs.com/docs/ios/configuration)). To access it, click "Info," then expand "Custom iOS Target Properties." ![The Info.plist file in Xcode showing the NSCameraUsageDescription key added for camera access.](/img/guides/first-app-cap-ng/xcode-info-plist.png 'Xcode Info.plist Configuration') @@ -111,4 +111,4 @@ Once again, upon tapping the Camera button on the Photo Gallery tab, the permiss Our Photo Gallery app has just been deployed to Android and iOS devices. 🎉 -In the next portion of this tutorial, we’ll use the Ionic CLI’s Live Reload functionality to quickly implement photo deletion - thus completing our Photo Gallery feature. +In the final portion of this tutorial, we’ll use the Ionic CLI’s Live Reload functionality to quickly implement photo deletion - thus completing our Photo Gallery feature. diff --git a/docs/angular/your-first-app/7-live-reload.md b/docs/angular/your-first-app/7-live-reload.md index 484feddcc0f..a0bd1b578d1 100644 --- a/docs/angular/your-first-app/7-live-reload.md +++ b/docs/angular/your-first-app/7-live-reload.md @@ -4,6 +4,7 @@ sidebar_label: ライブリロード --- + Rapid App Development with Live Reload with Angular | Ionic Capacitor Camera ` element. When the app user taps on a photo in our gallery, we’ll display an [Action Sheet](https://ionicframework.com/docs/api/action-sheet) dialog with the option to either delete the selected photo or cancel (close) the dialog. +With Live Reload running and the app open on your device, let’s implement photo deletion functionality. + +In `photo.service.ts`, add the `deletePhoto()` method. The selected photo is removed from the `photos` array first. Then, we use the Capacitor Preferences API to update the cached version of the `photos` array. Finally, we delete the actual photo file itself using the Filesystem API. + +```ts +import { Injectable } from '@angular/core'; +import { Camera, CameraResultType, CameraSource } from '@capacitor/camera'; +import type { Photo } from '@capacitor/camera'; +import { Filesystem, Directory } from '@capacitor/filesystem'; +import { Preferences } from '@capacitor/preferences'; +import { Platform } from '@ionic/angular'; +import { Capacitor } from '@capacitor/core'; + +@Injectable({ + providedIn: 'root', +}) +export class PhotoService { + // ...existing code... + + // CHANGE: Add `deletePhoto()` method + public async deletePhoto(photo: UserPhoto, position: number) { + // Remove this photo from the Photos reference data array + this.photos.splice(position, 1); + + // Update photos array cache by overwriting the existing photo array + Preferences.set({ + key: this.PHOTO_STORAGE, + value: JSON.stringify(this.photos), + }); + + // Delete photo file from filesystem + const filename = photo.filepath.slice(photo.filepath.lastIndexOf('/') + 1); + + await Filesystem.deleteFile({ + path: filename, + directory: Directory.Data, + }); + } +} -```html - - - +export interface UserPhoto { + filepath: string; + webviewPath?: string; +} ``` -Over in `tab2.page.ts`, import Action Sheet and add it to the constructor: +Next, in `tab2.page.ts`, implement the `showActionSheet()` method. We're adding two options: "Delete", which calls `PhotoService.deletePhoto()`, and "Cancel". The cancel button will automatically close the action sheet when assigned the "cancel" role. -```tsx +```ts +import { Component } from '@angular/core'; +// Change: Add import +import type { UserPhoto } from '../services/photo.service'; +import { PhotoService } from '../services/photo.service'; +// CHANGE: Add import import { ActionSheetController } from '@ionic/angular'; -constructor(public photoService: PhotoService, - public actionSheetController: ActionSheetController) {} -``` - -Add `UserPhoto` to the import statement. - -```tsx -import { PhotoService, UserPhoto } from '../services/photo.service'; -``` - -Next, implement the `showActionSheet()` function. We add two options: `Delete` that calls PhotoService’s `deletePicture()` function (to be added next) and `Cancel`, which when given the role of “cancel” will automatically close the action sheet: - -```tsx -public async showActionSheet(photo: UserPhoto, position: number) { - const actionSheet = await this.actionSheetController.create({ - header: 'Photos', - buttons: [{ - text: 'Delete', - role: 'destructive', - icon: 'trash', - handler: () => { - this.photoService.deletePicture(photo, position); - } - }, { - text: 'Cancel', - icon: 'close', - role: 'cancel', - handler: () => { - // Nothing to do, action sheet is automatically closed - } - }] - }); - await actionSheet.present(); +@Component({ + selector: 'app-tab2', + templateUrl: 'tab2.page.html', + styleUrls: ['tab2.page.scss'], + standalone: false, +}) +export class Tab2Page { + // CHANGE: Update constructor + constructor(public photoService: PhotoService, public actionSheetController: ActionSheetController) {} + + // ...existing code... + + // CHANGE: Add `showActionSheet()` method + public async showActionSheet(photo: UserPhoto, position: number) { + const actionSheet = await this.actionSheetController.create({ + header: 'Photos', + buttons: [ + { + text: 'Delete', + role: 'destructive', + icon: 'trash', + handler: () => { + this.photoService.deletePhoto(photo, position); + }, + }, + { + text: 'Cancel', + icon: 'close', + role: 'cancel', + handler: () => { + // Nothing to do, action sheet is automatically closed + }, + }, + ], + }); + await actionSheet.present(); + } } ``` -Save both of the files we just edited. The Photo Gallery app will reload automatically, and now when we tap on one of the photos in the gallery, the action sheet displays. Tapping “Delete” doesn’t do anything yet, so head back into your code editor. - -In `src/app/services/photo.service.ts`, add the `deletePicture()` function: - -```tsx -public async deletePicture(photo: UserPhoto, position: number) { - // Remove this photo from the Photos reference data array - this.photos.splice(position, 1); - - // Update photos array cache by overwriting the existing photo array - Preferences.set({ - key: this.PHOTO_STORAGE, - value: JSON.stringify(this.photos) - }); +Open `tab2.page.html` and add a new click handler to each `` element. When the app user taps on a photo in our gallery, we’ll display an [Action Sheet](../../api/action-sheet.md) dialog with the option to either delete the selected photo or cancel (close) the dialog. - // delete photo file from filesystem - const filename = photo.filepath - .substr(photo.filepath.lastIndexOf('/') + 1); - - await Filesystem.deleteFile({ - path: filename, - directory: Directory.Data - }); -} +```html + + + Photo Gallery + + + + + + + Photo Gallery + + + + + + + + + + + + + + + + + + ``` -The selected photo is removed from the Photos array first. Then, we use the Capacitor Preferences API to update the cached version of the Photos array. Finally, we delete the actual photo file itself using the Filesystem API. +Tap on a photo again and choose the “Delete” option. The photo is deleted! Implemented much faster using Live Reload. 💪 -Save this file, then tap on a photo again and choose the “Delete” option. This time, the photo is deleted! Implemented much faster using Live Reload. 💪 +:::note +Remember, you can find the complete source code for this app [here](https://github.com/ionic-team/photo-gallery-capacitor-ng). +::: In the final portion of this tutorial, we’ll walk you through the basics of the Appflow product used to build and deploy your application to users' devices. diff --git a/docs/angular/your-first-app/8-distribute.md b/docs/angular/your-first-app/8-distribute.md index 65ef475f6be..bf495f68421 100644 --- a/docs/angular/your-first-app/8-distribute.md +++ b/docs/angular/your-first-app/8-distribute.md @@ -1,8 +1,15 @@ --- +title: Build and Distribute your App sidebar_label: Distribute --- -# Build and Deploy your App + + Build and Deploy your App with Angular | Ionic Capacitor Camera + + Now that you have built your first app, you are going to want to get it distributed so everyone can start using it. The mechanics of building and deploying your application can be quite cumbersome. That is where [Appflow](https://ionic.io/docs/appflow/) comes into play. Appflow allows you to effectively generate web and native builds, push out live app updates, publish your app to the app stores, and automate the whole process. The entire Quickstart guide can be found [here](https://ionic.io/docs/appflow/quickstart). @@ -52,7 +59,7 @@ Upon completion of the Web Build, additional versioning options are available to To receive this live update, you will need to run the app on a device or an emulator. The quickest and easiest way to do this is through the following command: ```shell -ionic [cordova | cap] run [ios | android] [options] +ionic cap run [ios | android] [options] ``` Assuming the app is configured correctly to listen to the channel you deployed to, the app should immediately update on startup if you have chosen the auto update method during setup. If the background update method was chosen, be sure to stay in the app for about 30 seconds to ensure the update was downloaded. Then, close the application, reopen it, and you will see the updates applied! @@ -93,8 +100,8 @@ For access to the ability to create a Native Configuration, you will need to be ## What’s Next? -Congratulations! You developed a complete cross-platform Photo Gallery app that runs on the web, iOS, and Android. Not only that, you have also then built the app and deployed it to your users devices! +Congratulations! You developed a complete cross-platform Photo Gallery app that runs on the web, iOS, and Android. Not only that, you have also then built the app and deployed it to your users' devices! -There are many paths to follow from here. Try adding another [Ionic UI component](https://ionicframework.com/docs/components) to the app, or more [native functionality](https://capacitorjs.com/docs/apis). The sky’s the limit. Once you have added another feature, run the build and deploy process again through Appflow to get it out to your users. +There are many paths to follow from here. Try adding another [Ionic UI component](../../components.md) to the app, or more [native functionality](https://capacitorjs.com/docs/apis). The sky’s the limit. Once you have added another feature, run the build and deploy process again through Appflow to get it out to your users. Happy app building! 💙 diff --git a/docs/api/alert.md b/docs/api/alert.md index f313ff8c8bf..934733ece62 100644 --- a/docs/api/alert.md +++ b/docs/api/alert.md @@ -42,7 +42,7 @@ import IsOpen from '@site/static/usage/v8/alert/presenting/isOpen/index.md'; ## Controller Alerts -`alertController`は、アラートを表示するタイミングや解除するタイミングをより細かく制御する必要がある場合に使用することができる。 +`alertController`は、アラートを表示するタイミングや解除するタイミングをより細かく制御する必要がある場合に使用することができます。 import Controller from '@site/static/usage/v8/alert/presenting/controller/index.md'; @@ -186,7 +186,7 @@ const alert = await alertController.create({ #### Alert Buttons の概要 -Buttons containing text will be read by a screen reader. If a description other than the existing text is desired, a label can be set on the button by passing `aria-label` to the `htmlAttributes` property on the button. +テキストを含むボタンはスクリーンリーダーによって読み取られます。既存のテキスト以外の説明が必要な場合は、ボタンの`htmlAttributes`プロパティに`aria-label`を渡して、ボタンにラベルを設定できます。 diff --git a/docs/api/app.md b/docs/api/app.md index 32602254b86..3898c496557 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -26,9 +26,9 @@ AppはIonicアプリケーションのコンテナ要素です。1つのプロ * Material Design モードでのボタン操作時の[Ripple effect](./リップルエフェクト) が使えます。 * Ionicアプリの使用感をよりネイティブなものにする、その他のタップやフォーカスのユーティリティが使えます。 -## Programmatic Focus +## プログラムによるフォーカス -Ionic offers focus utilities for components with the `ion-focusable` class. These utilities automatically manage focus for components when certain keyboard keys, like Tab, are pressed. Components can also be programmatically focused in response to user actions using the `setFocus` method from `ion-app`. +Ionicは、`ion-focusable`クラスを持つコンポーネント用のフォーカスユーティリティを提供します。これらのユーティリティは、Tabなどの特定のキーボードキーが押されたときに、コンポーネントのフォーカスを自動的に管理します。コンポーネントは、`ion-app`の`setFocus`メソッドを使用して、ユーザーのアクションに応じてプログラムでフォーカスを設定することもできます。 import SetFocus from '@site/static/usage/v8/app/set-focus/index.md'; diff --git a/docs/api/badge.md b/docs/api/badge.md index c7682a087a3..77e7cc731f4 100644 --- a/docs/api/badge.md +++ b/docs/api/badge.md @@ -30,7 +30,7 @@ import Basic from '@site/static/usage/v8/badge/basic/index.md'; バッジはTabボタン内に追加することができ、多くの場合、通知を示したり、要素に関連する追加項目を強調するために使用されます。 :::info -Empty badges are only available for `md` mode. +空のバッジは`md`モードでのみ利用可能です。 ::: import InsideTabBar from '@site/static/usage/v8/badge/inside-tab-bar/index.md'; diff --git a/docs/api/input.md b/docs/api/input.md index 3b4ec38664b..1346470a356 100644 --- a/docs/api/input.md +++ b/docs/api/input.md @@ -86,7 +86,7 @@ Material Design では、Inputに塗りつぶしのスタイルが用意され Filled inputs をiOSで使うためには、inputの `mode` を `md` に設定する必要があります。 :::warning -Inputs that use `fill` should not be used in an `ion-item` due to styling conflicts between the components. +コンポーネント間のスタイリングの競合のため、`fill`を使用する入力は`ion-item`内で使用すべきではありません。 ::: import Fill from '@site/static/usage/v8/input/fill/index.md'; @@ -108,13 +108,13 @@ import HelperError from '@site/static/usage/v8/input/helper-error/index.md'; Input Counterは、Inputの下に表示されるテキストで、入力可能な文字数のうち、何文字が入力されたかをユーザーに通知するものです。カウンターを追加する場合、デフォルトの動作は、表示される値を `inputLength` / `maxLength` としてフォーマットすることです。この動作は、`counterFormatter`プロパティにフォーマッタ関数を渡すことでカスタマイズすることができます。 -The `counter` and `counterFormatter` properties on `ion-item` were [deprecated in Ionic 7](/docs/api/input#using-the-modern-syntax) and should be used directly on `ion-input` instead. +`ion-item`の`counter`と`counterFormatter`プロパティは[Ionic 7で非推奨](/docs/api/input#using-the-modern-syntax)となり、代わりに`ion-input`で直接使用すべきです。 import Counter from '@site/static/usage/v8/input/counter/index.md'; -Inputs with a counter add a border between the input and the counter, therefore they should not be placed inside of an `ion-item` which adds an additional border under the item. The `ion-padding-start` class can be added to align the counter inputs with inputs inside of items. +カウンター付きのInputは、Inputとカウンターの間にボーダーを追加するため、アイテムの下に追加のボーダーを追加する`ion-item`内に配置すべきではありません。`ion-padding-start`クラスを追加して、カウンターInputとアイテム内Inputを揃えることができます。 import CounterAlignment from '@site/static/usage/v8/input/counter-alignment/index.md'; diff --git a/docs/api/item.md b/docs/api/item.md index ae23c687b98..00adbba440c 100644 --- a/docs/api/item.md +++ b/docs/api/item.md @@ -189,7 +189,7 @@ This feature is not enabled by default on clickable items for the `md` mode, but --item-detail-push-show: true; ``` -See the [theming documentation](/docs/theming/css-variables) for more information. +詳細については、[theming documentation](/docs/theming/css-variables)を参照してください。 --> diff --git a/docs/api/label.md b/docs/api/label.md index db2d8284e5b..32f3b29362d 100644 --- a/docs/api/label.md +++ b/docs/api/label.md @@ -19,7 +19,7 @@ import EncapsulationPill from '@components/page/api/EncapsulationPill'; Labelは、主に[Item](./item.md)コンポーネントにテキストコンテンツを追加するために使用される要素です。Labelは、[Input](./input.md)や[Radio](./radio.md)のようなフォーム制御コンポーネントの内部で、可視ラベルを指定する場合にも使用できますが、必須ではありません。 -The position of the label inside of an item can be inline, fixed, stacked, or floating. +アイテム内のラベルの位置は、inline、fixed、stacked、またはfloatingにすることができます。 ## 基本的な使い方 diff --git a/docs/api/modal.md b/docs/api/modal.md index 56d2ab1a9a3..c8afa0a00b4 100644 --- a/docs/api/modal.md +++ b/docs/api/modal.md @@ -143,9 +143,9 @@ import SheetBackgroundContentExample from '@site/static/usage/v8/modal/sheet/bac ### 任意の高さのシート -Developers should use the `--height` CSS Variable to change the height of the sheet modal instead of changing the last breakpoint in the `breakpoints` array. The reason for this is changing the last breakpoint in the `breakpoints` array to a value less than `1` will cause some of the modal to be inaccessible outside of the viewport. +開発者は、`breakpoints`配列の最後のブレークポイントを変更する代わりに、`--height` CSS変数を使用してシートモーダルの高さを変更すべきです。その理由は、`breakpoints`配列の最後のブレークポイントを`1`未満の値に変更すると、モーダルの一部がビューポート外でアクセスできなくなるためです。 -The following example shows how to get a sheet modal that is automatically sized based on its content. Note that by keeping the maximum breakpoint at `1` we ensure that the entire modal is accessible in the viewport. +次の例は、コンテンツに基づいて自動的にサイズ調整されるシートモーダルを取得する方法を示しています。最大ブレークポイントを`1`に保つことで、モーダル全体がビューポート内でアクセス可能であることを保証することに注意してください。 import SheetAutoHeightExample from '@site/static/usage/v8/modal/sheet/auto-height/index.md'; @@ -161,7 +161,7 @@ import SheetHandleBehaviorExample from '@site/static/usage/v8/modal/sheet/handle ### Scrolling content at all breakpoints -Sheet modals can be configured to allow scrolling content at all breakpoints, making them ideal for displaying content larger than the viewport. By setting the `expandToScroll` property to `false`, the content remains scrollable at every breakpoint. Otherwise, by default, scrolling is only enabled when the sheet modal is fully expanded. +シートモーダルは、すべてのブレークポイントでコンテンツのスクロールを許可するように設定でき、ビューポートより大きいコンテンツを表示するのに理想的です。`expandToScroll`プロパティを`false`に設定すると、コンテンツはすべてのブレークポイントでスクロール可能なままです。それ以外の場合、デフォルトでは、シートモーダルが完全に展開されている場合にのみスクロールが有効になります。 import SheetScrollingContentExample from '@site/static/usage/v8/modal/sheet/expand-to-scroll/index.md'; @@ -272,7 +272,7 @@ interface ModalCustomEvent extends CustomEvent { 開発者が手動でフォーカスを移動しても、アシストはモーダル要素のコンテンツへのナビゲーションを制限しません。ただし、Ionic では、フォーカスのトラッピングが有効になっているモーダルに対して、モーダルの外側に手動でフォーカスを移動することはサポートされていません。 -See https://w3c.github.io/aria/#aria-modal for more information. +詳細については、https://w3c.github.io/aria/#aria-modal を参照してください。 ### フォーカスのトラッピング diff --git a/docs/api/nav.md b/docs/api/nav.md index f3f41882aa8..61e902f6b26 100644 --- a/docs/api/nav.md +++ b/docs/api/nav.md @@ -39,7 +39,7 @@ Modal can use Nav to offer a linear navigation that is independent of the URL. :::note -The example below uses a reference to Nav and the public method APIs to push and pop views. It is recommended to use NavLink in implementations that do not require this level of granular access and control. +以下の例では、Navへの参照とパブリックメソッドAPIを使用してビューをプッシュおよびポップします。このレベルの細かいアクセスと制御が必要ない実装では、NavLinkを使用することをお勧めします。 ::: diff --git a/docs/api/picker.md b/docs/api/picker.md index ade139e0e8b..5f2cfa6eb4b 100644 --- a/docs/api/picker.md +++ b/docs/api/picker.md @@ -266,6 +266,37 @@ Each [Picker Column](./picker-column) can be navigated using the keyboard when f | Home | Scroll to the first option. | | End | Scroll to the last option. | +## Accessibility + +### Screen Readers + +Pickerは、各[Picker Column](./picker-column)に[`slider` role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/slider_role)を実装することで、スクリーンリーダーを使用したナビゲーションをサポートします。以下のジェスチャーを使用してPickerをナビゲートできます。 + +| Gesture | Function | +| - | - | +| Swipe Left | Move focus to the previous Picker Column. | +| Swipe Right | Move focus to the next Picker Column. | +| Swipe Up | Select the next option in the Picker Column. | +| Swipe Down | Select the previous option in the Picker Column. | +| Double Tap and Slide Up/Down | Adjust the selected option in the Picker Column. Can be used as an alternative to swiping up and down. | + +:::caution +The Swipe Up and Swipe Down gestures rely on the correct key events being synthesized as noted on the [`slider` documentation](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/slider_role). [Chromium-based browsers do not synthesize keyboard events correctly](https://issues.chromium.org/issues/40816094), but the "Double Tap and Slide Up/Down" gesture can be used as an alternative until this has been implemented in Chromium-based browsers. +::: + +### Keyboard Interactions + +Each [Picker Column](./picker-column) can be navigated using the keyboard when focused. + +| Key | Description | +| -------------------- | ------------------------------------ | +| ArrowUp | Scroll to the previous option. | +| ArrowDown | Scroll to the next option. | +| PageUp | Scroll up by more than one option. | +| PageDown | Scroll down by more than one option. | +| Home | Scroll to the first option. | +| End | Scroll to the last option. | + ## プロパティ diff --git a/docs/api/radio.md b/docs/api/radio.md index 6c1defac5b8..44629c81f14 100644 --- a/docs/api/radio.md +++ b/docs/api/radio.md @@ -38,7 +38,7 @@ import LabelPlacement from '@site/static/usage/v8/radio/label-placement/index.md ## Label Wrapping -Regardless of label placement, long text will not wrap by default. If the width of the radio is constrained, overflowing text will be truncated with an ellipsis. You can enable text wrapping by adding the `ion-text-wrap` class to a wrapper around the radio text or styling the `label` shadow part using the `::part()` selector. +ラベルの配置に関係なく、長いテキストはデフォルトで折り返されません。ラジオの幅が制約されている場合、オーバーフローしたテキストは省略記号で切り詰められます。ラジオテキストの周りのラッパーに`ion-text-wrap`クラスを追加するか、`::part()`セレクタを使用して`label`シャドウパーツをスタイリングすることで、テキストの折り返しを有効にできます。 import LabelWrap from '@site/static/usage/v8/radio/label-wrap/index.md'; @@ -54,10 +54,10 @@ import UsingComparewith from '@site/static/usage/v8/radio/using-comparewith/inde ## Alignment -Developers can use the `alignment` property to control how the label and control are aligned on the cross axis. This property mirrors the flexbox `align-items` property. +開発者は`alignment`プロパティを使用して、ラベルとコントロールがクロス軸上でどのように配置されるかを制御できます。このプロパティは、flexboxの`align-items`プロパティを反映しています。 :::note -Stacked radios can be aligned using the `alignment` property. This can be useful when the label and control need to be centered horizontally. +スタックされたラジオは、`alignment`プロパティを使用して配置できます。ラベルとコントロールを水平方向に中央揃えする必要がある場合に便利です。 ::: import Alignment from '@site/static/usage/v8/radio/alignment/index.md'; @@ -86,9 +86,9 @@ import EmptySelection from '@site/static/usage/v8/radio/empty-selection/index.md ## Helper & Error Text -Helper and error text can be used inside of a radio group with the `helperText` and `errorText` property. The error text will not be displayed unless the `ion-invalid` and `ion-touched` classes are added to the `ion-radio-group`. This ensures errors are not shown before the user has a chance to enter data. +ヘルパーテキストとエラーテキストは、`helperText`と`errorText`プロパティを使用してラジオグループ内で使用できます。エラーテキストは、`ion-invalid`と`ion-touched`クラスが`ion-radio-group`に追加されていない限り表示されません。これにより、ユーザーがデータを入力する前にエラーが表示されることはありません。 -In Angular, this is done automatically through form validation. In JavaScript, React and Vue, the class needs to be manually added based on your own validation. +Angularでは、これはフォームバリデーションによって自動的に行われます。JavaScript、React、Vueでは、独自のバリデーションに基づいてクラスを手動で追加する必要があります。 import HelperError from '@site/static/usage/v8/radio/helper-error/index.md'; diff --git a/docs/api/reorder-group.md b/docs/api/reorder-group.md index 1f5fce2f2fa..5b3ef9cbfc5 100644 --- a/docs/api/reorder-group.md +++ b/docs/api/reorder-group.md @@ -16,9 +16,9 @@ import Slots from '@ionic-internal/component-api/v8/reorder-group/slots.md'; import EncapsulationPill from '@components/page/api/EncapsulationPill'; -The reorder group is a container for items using the [reorder](./reorder) component. When the user drags an item and drops it, the `ionReorderEnd` event is dispatched. A handler for this event should be implemented that calls the `complete` method. +Reorder groupは、[reorder](./reorder)コンポーネントを使用するアイテムのコンテナです。ユーザーがアイテムをドラッグしてドロップすると、`ionReorderEnd`イベントが発行されます。このイベントのハンドラを実装し、`complete`メソッドを呼び出す必要があります。 -The `detail` property of the `ionReorderEnd` event includes all of the relevant information about the reorder operation, including the `from` and `to` indexes. In the context of reordering, an item moves `from` an index `to` an index. For example usage of the reorder group, see the [reorder](./reorder) documentation. +`ionReorderEnd`イベントの`detail`プロパティには、`from`と`to`のインデックスを含む、reorder操作に関するすべての関連情報が含まれています。reorderのコンテキストでは、アイテムはインデックス`from`からインデックス`to`に移動します。reorder groupの使用例については、[reorder](./reorder)ドキュメントを参照してください。 ## Interfaces @@ -44,7 +44,7 @@ interface ReorderEndEventDetail { ### ReorderMoveCustomEvent -While not required, this interface can be used in place of the `CustomEvent` interface for stronger typing with Ionic events emitted from this component. +必須ではありませんが、このコンポーネントから発行されるIonicイベントでより強く型付けを行うために、`CustomEvent`インターフェースの代わりにこのインターフェースを使用することが可能です。 ```typescript interface ReorderMoveCustomEvent extends CustomEvent { @@ -56,7 +56,7 @@ interface ReorderMoveCustomEvent extends CustomEvent { ### ReorderEndCustomEvent -While not required, this interface can be used in place of the `CustomEvent` interface for stronger typing with Ionic events emitted from this component. +必須ではありませんが、このコンポーネントから発行されるIonicイベントでより強く型付けを行うために、`CustomEvent`インターフェースの代わりにこのインターフェースを使用することが可能です。 ```typescript interface ReorderEndCustomEvent extends CustomEvent { diff --git a/docs/api/reorder.md b/docs/api/reorder.md index abad8547a3e..e7b475daee4 100644 --- a/docs/api/reorder.md +++ b/docs/api/reorder.md @@ -20,7 +20,7 @@ import EncapsulationPill from '@components/page/api/EncapsulationPill'; Reorderは、アイテムのグループ内での順序を変更するためにアイテムをドラッグできるようにするコンポーネントです。視覚的なドラッグ&ドロップのインターフェイスを提供するために、[reorder group](./reorder-group)内で使用されなければなりません。 -The reorder is the anchor used to drag and drop the items. Once the reorder is complete, the `ionReorderEnd` event will be dispatched from the reorder group and the `complete` method needs to be called. +Reorderは、アイテムをドラッグ&ドロップするために使用されるアンカーです。Reorderが完了すると、reorder groupから`ionReorderEnd`イベントが発行され、`complete`メソッドを呼び出す必要があります。 ## 基本的な使い方 diff --git a/docs/api/router-link.md b/docs/api/router-link.md index cd340172388..24b1dd26daf 100644 --- a/docs/api/router-link.md +++ b/docs/api/router-link.md @@ -24,7 +24,7 @@ router linkコンポーネントは、指定されたリンクに移動するた Note: このコンポーネントは、vanilla と Stencil での JavaScriptプロジェクトでのみ使用してください。Angularプロジェクトでは、[`ion-router-outlet`](router-outlet.md) と Angularルータを使用してください。 ::: -See the [Router](./router) documentation for more information. +詳細については、[Router](./router)ドキュメントを参照してください。 ## プロパティ diff --git a/docs/api/select.md b/docs/api/select.md index 347715f8249..ec45b02e90e 100644 --- a/docs/api/select.md +++ b/docs/api/select.md @@ -154,7 +154,7 @@ Material DesignはセレクトにFilledスタイルを提供します。select iOSでは、Selectの `mode` を `md` に設定することで、Filled Selectsを使うことができます。 :::warning -Selects that use `fill` should not be used in an `ion-item` due to styling conflicts between the components. +コンポーネント間のスタイリングの競合のため、`fill`を使用するセレクトは`ion-item`内で使用すべきではありません。 ::: import FillExample from '@site/static/usage/v8/select/fill/index.md'; @@ -167,8 +167,8 @@ import FillExample from '@site/static/usage/v8/select/fill/index.md'; `action-sheet` と `popover` インターフェースには `OK` ボタンがありません。オプションのいずれかをクリックすると自動的にオーバーレイが閉じ、その値が選択されます。 `popover` インターフェースには `Cancel` ボタンがなく、背景をクリックするとオーバーレイが閉じます。 -The `modal` interface has a single `Close` button in the header. This button is only responsible for dismissing the modal. Any selections made will persist -after clicking this button or if the modal is dismissed using an alternative method. +`modal`インターフェースには、ヘッダーに単一の`Close`ボタンがあります。このボタンは、モーダルを閉じることのみを担当します。 +このボタンをクリックした後、または代替方法でモーダルが閉じられた場合でも、行われた選択は保持されます。 import ButtonTextExample from '@site/static/usage/v8/select/customization/button-text/index.md'; @@ -189,12 +189,12 @@ import InterfaceOptionsExample from '@site/static/usage/v8/select/customization/ ## Start and End Slots -The `start` and `end` slots can be used to place icons, buttons, or prefix/suffix text on either side of the select. If the slot content is clicked, the select will not open. +`start`と`end`スロットは、セレクトの両側にアイコン、ボタン、またはプレフィックス/サフィックステキストを配置するために使用できます。スロットコンテンツがクリックされた場合、セレクトは開きません。 :::note -In most cases, [Icon](./icon.md) components placed in these slots should have `aria-hidden="true"`. See the [Icon accessibility docs](https://ionicframework.com/docs/api/icon#accessibility) for more information. +ほとんどの場合、これらのスロットに配置された[Icon](./icon.md)コンポーネントには`aria-hidden="true"`を設定すべきです。詳細については、[Icon accessibility docs](https://ionicframework.com/docs/api/icon#accessibility)を参照してください。 -If slot content is meant to be interacted with, it should be wrapped in an interactive element such as a [Button](./button.md). This ensures that the content can be tabbed to. +スロットコンテンツが操作対象である場合、[Button](./button.md)などのインタラクティブ要素でラップする必要があります。これにより、コンテンツにタブで移動できるようになります。 ::: import StartEndSlots from '@site/static/usage/v8/select/start-end-slots/index.md'; @@ -255,9 +255,9 @@ import TypeaheadExample from '@site/static/usage/v8/select/typeahead/index.md'; ## Helper & Error Text -Helper and error text can be used inside of a select with the `helperText` and `errorText` property. The error text will not be displayed unless the `ion-invalid` and `ion-touched` classes are added to the `ion-select`. This ensures errors are not shown before the user has a chance to enter data. +ヘルパーテキストとエラーテキストは、`helperText`と`errorText`プロパティを使用してセレクト内で使用できます。エラーテキストは、`ion-invalid`と`ion-touched`クラスが`ion-select`に追加されていない限り表示されません。これにより、ユーザーがデータを入力する前にエラーが表示されることはありません。 -In Angular, this is done automatically through form validation. In JavaScript, React and Vue, the class needs to be manually added based on your own validation. +Angularでは、これはフォームバリデーションによって自動的に行われます。JavaScript、React、Vueでは、独自のバリデーションに基づいてクラスを手動で追加する必要があります。 import HelperError from '@site/static/usage/v8/select/helper-error/index.md'; @@ -304,7 +304,7 @@ These keyboard interactions apply to all `ion-select` elements when the followin Single selection keyboard interaction follows the [ARIA implementation patterns of a radio](https://www.w3.org/WAI/ARIA/apg/patterns/radio/). -These keyboard interactions apply to `ion-action-sheet`, `ion-alert`, `ion-popover`, and `ion-modal` elements when the overlay is presented and focused. +これらのキーボード操作は、オーバーレイが表示され、フォーカスされている場合に`ion-action-sheet`、`ion-alert`、`ion-popover`、および`ion-modal`要素に適用されます。 | Key | Description | | --------------------- | ------------------------------------------------------------ | @@ -321,7 +321,7 @@ These keyboard interactions apply to `ion-action-sheet`, `ion-alert`, `ion-popov Multiple selection keyboard interaction follows the [ARIA implementation patterns of a checkbox](https://www.w3.org/WAI/ARIA/apg/patterns/checkbox/). -These keyboard interactions apply to `ion-alert`, `ion-popover`, and `ion-modal` elements when the overlay is presented and multiple selection is enabled. +これらのキーボード操作は、オーバーレイが表示され、複数選択が有効になっている場合に`ion-alert`、`ion-popover`、および`ion-modal`要素に適用されます。 | Key | Description | | ------------------ | ------------------------------------------------------------ | diff --git a/docs/api/spinner.md b/docs/api/spinner.md index 841396ed0de..ddd3348563a 100644 --- a/docs/api/spinner.md +++ b/docs/api/spinner.md @@ -39,7 +39,7 @@ import Colors from '@site/static/usage/v8/spinner/theming/colors/index.md'; ### Styling -You may use custom CSS to style the spinner. For example, you can resize the spinner by setting the width and height. +カスタムCSSを使用してスピナーのスタイルを設定できます。たとえば、幅と高さを設定してスピナーのサイズを変更できます。 import Resizing from '@site/static/usage/v8/spinner/theming/resizing/index.md'; diff --git a/docs/api/tab-bar.md b/docs/api/tab-bar.md index 0c42eecfefb..7ce4af6486a 100644 --- a/docs/api/tab-bar.md +++ b/docs/api/tab-bar.md @@ -145,7 +145,7 @@ import { call, person, settings } from 'ionicons/icons'; バッジはTabボタン内に追加することができ、多くの場合、通知を示したり、要素に関連する追加項目を強調するために使用されます。 :::info -Empty badges are only available for `md` mode. +空のバッジは`md`モードでのみ利用可能です。 ::: import InsideTabBar from '@site/static/usage/v8/badge/inside-tab-bar/index.md'; diff --git a/docs/api/tabs.md b/docs/api/tabs.md index 2838bd2f491..cc041871449 100644 --- a/docs/api/tabs.md +++ b/docs/api/tabs.md @@ -48,7 +48,13 @@ Ionicでは、タブを使ったルーティングパターンのベストプラ ::: - +## Programmatically Selecting Tabs + +タブは`select`メソッドを使用してプログラムで選択できます。これは、ボタンのクリックに応答したり、フォームを完了した後など、アプリケーションロジックからタブの変更をトリガーする必要がある場合に便利です。次の例では、ボタンを使用して`select`メソッドを呼び出し、別のタブにナビゲートする方法を示しています。 + +import SelectMethod from '@site/static/usage/v8/tabs/select-method/index.md'; + + ## Interfaces diff --git a/docs/api/textarea.md b/docs/api/textarea.md index 8ce7c170c85..b26f1a88f2e 100644 --- a/docs/api/textarea.md +++ b/docs/api/textarea.md @@ -31,11 +31,11 @@ import BasicPlayground from '@site/static/usage/v8/textarea/basic/index.md'; ## Labels -Labels should be used to describe the textarea. They can be used visually, and they will also be read out by screen readers when the user is focused on the textarea. This makes it easy for the user to understand the intent of the textarea. Textarea has several ways to assign a label: +ラベルは、textareaを説明するために使用すべきです。視覚的に使用でき、ユーザーがtextareaにフォーカスしたときにスクリーンリーダーによって読み上げられます。これにより、ユーザーがtextareaの意図を理解しやすくなります。Textareaには、ラベルを割り当てるいくつかの方法があります: -- `label` property: used for plaintext labels -- `label` slot: used for custom HTML labels (experimental) -- `aria-label`: used to provide a label for screen readers but adds no visible label +- `label` プロパティ: プレーンテキストのラベルに使用 +- `label` スロット: カスタムHTMLラベルに使用(実験的) +- `aria-label`: スクリーンリーダーにラベルを提供するために使用されますが、表示されるラベルは追加されません ### Label Placement @@ -70,7 +70,7 @@ Material Designでは、テキストエリアの塗りつぶしスタイルが iOSでは、Textareasの`mode`を`md`に設定することで、Filled Textareasを使うことができます。 :::warning -Textareas that use `fill` should not be used in an `ion-item` due to styling conflicts between the components. +コンポーネント間のスタイリングの競合のため、`fill`を使用するTextareaは`ion-item`内で使用すべきではありません。 ::: import Fill from '@site/static/usage/v8/textarea/fill/index.md'; @@ -113,14 +113,14 @@ import ClearOnEditPlayground from '@site/static/usage/v8/textarea/clear-on-edit/ ## Start and End Slots (experimental) -The `start` and `end` slots can be used to place icons, buttons, or prefix/suffix text on either side of the textarea. +`start`と`end`スロットは、textareaの両側にアイコン、ボタン、またはプレフィックス/サフィックステキストを配置するために使用できます。 -Note that this feature is considered experimental because it relies on a simulated version of [Web Component slots](https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_templates_and_slots). As a result, the simulated behavior may not exactly match the native slot behavior. +この機能は、[Web Component slots](https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_templates_and_slots)のシミュレート版に依存しているため、実験的なものとみなされていることに注意してください。その結果、シミュレートされた動作はネイティブのスロットの動作と完全に一致するとは限りません。 :::note -In most cases, [Icon](./icon.md) components placed in these slots should have `aria-hidden="true"`. See the [Icon accessibility docs](https://ionicframework.com/docs/api/icon#accessibility) for more information. +ほとんどの場合、これらのスロットに配置された[Icon](./icon.md)コンポーネントには`aria-hidden="true"`を設定すべきです。詳細については、[Icon accessibility docs](https://ionicframework.com/docs/api/icon#accessibility)を参照してください。 -If slot content is meant to be interacted with, it should be wrapped in an interactive element such as a [Button](./button.md). This ensures that the content can be tabbed to. +スロットコンテンツが操作対象である場合、[Button](./button.md)などのインタラクティブ要素でラップする必要があります。これにより、コンテンツにタブで移動できるようになります。 ::: import StartEndSlots from '@site/static/usage/v8/textarea/start-end-slots/index.md'; diff --git a/docs/api/toast.md b/docs/api/toast.md index 8f343251090..b74c6bbd8de 100644 --- a/docs/api/toast.md +++ b/docs/api/toast.md @@ -202,7 +202,7 @@ const toast = await toastController.create({ ### Tips -While this is not a complete list, here are some guidelines to follow when using toasts. +これは完全なリストではありませんが、トーストを使用する際に従うべきガイドラインを以下に示します。 * Do not require user interaction to dismiss toasts. For example, having a "Dismiss" button in the toast is fine, but the toast should also automatically dismiss on its own after a timeout period. If you need user interaction for a notification, consider using an [alert](./alert) instead. diff --git a/docs/api/toggle.md b/docs/api/toggle.md index 88e1c67e8e7..a54100d2549 100644 --- a/docs/api/toggle.md +++ b/docs/api/toggle.md @@ -55,10 +55,10 @@ import LabelPlacement from '@site/static/usage/v8/toggle/label-placement/index.m ## Alignment -Developers can use the `alignment` property to control how the label and control are aligned on the cross axis. This property mirrors the flexbox `align-items` property. +開発者は`alignment`プロパティを使用して、ラベルとコントロールがクロス軸上でどのように配置されるかを制御できます。このプロパティは、flexboxの`align-items`プロパティを反映しています。 :::note -Stacked toggles can be aligned using the `alignment` property. This can be useful when the label and control need to be centered horizontally. +スタックされたトグルは、`alignment`プロパティを使用して配置できます。ラベルとコントロールを水平方向に中央揃えする必要がある場合に便利です。 ::: import Alignment from '@site/static/usage/v8/toggle/alignment/index.md'; @@ -75,9 +75,9 @@ import Justify from '@site/static/usage/v8/toggle/justify/index.md'; ## Helper & Error Text -Helper and error text can be used inside of a toggle with the `helperText` and `errorText` property. The error text will not be displayed unless the `ion-invalid` and `ion-touched` classes are added to the `ion-toggle`. This ensures errors are not shown before the user has a chance to enter data. +ヘルパーテキストとエラーテキストは、`helperText`と`errorText`プロパティを使用してトグル内で使用できます。エラーテキストは、`ion-invalid`と`ion-touched`クラスが`ion-toggle`に追加されていない限り表示されません。これにより、ユーザーがデータを入力する前にエラーが表示されることはありません。 -In Angular, this is done automatically through form validation. In JavaScript, React and Vue, the class needs to be manually added based on your own validation. +Angularでは、これはフォームバリデーションによって自動的に行われます。JavaScript、React、Vueでは、独自のバリデーションに基づいてクラスを手動で追加する必要があります。 import HelperError from '@site/static/usage/v8/toggle/helper-error/index.md'; diff --git a/docs/components.md b/docs/components.md index 2c614b4927b..dddb57829b5 100644 --- a/docs/components.md +++ b/docs/components.md @@ -19,17 +19,17 @@ import DocsCards from '@components/global/DocsCards'; `} -Ionic apps are made of high-level building blocks called Components, which allow you to quickly construct the UI for your app. Ionic comes stock with a number of components, including cards, lists, and tabs. Once you're familiar with the basics, refer to the [API Index](api.md) for a complete list of each component and sub-component. +Ionic アプリは、コンポーネントと呼ばれる高レベルのビルディングブロックで構成されており、アプリの UI を迅速に構築できます。Ionic には、カード、リスト、タブなど、多数のコンポーネントが標準装備されています。基本を理解したら、各コンポーネントとサブコンポーネントの完全なリストについては[API Index](api.md)を参照してください。 -

Accordions provide collapsible sections in your content to reduce vertical space while providing a way of organizing and grouping information.

+

アコーディオンは、情報を整理・グループ化する方法を提供しながら、垂直方向のスペースを減らすために、コンテンツに折りたたみ可能なセクションを提供します。

-

Action Sheets display a set of options with the ability to confirm or cancel an action.

+

アクションシートは、アクションを確認またはキャンセルする機能とともに、一連のオプションを表示します。

@@ -41,7 +41,7 @@ Ionic apps are made of high-level building blocks called Components, which allow -

Breadcrumbs are navigation items that are used to indicate where a user is on an app.

+

Breadcrumbsは、ユーザーがアプリ内のどこにいるかを示すために使用されるナビゲーションアイテムです。

@@ -49,9 +49,7 @@ Ionic apps are made of high-level building blocks called Components, which allow -

- Cards are a great way to display an important piece of content, and can contain images, buttons, text, and more. -

+

カードは重要なコンテンツを表示する優れた方法であり、画像、ボタン、テキストなどを含めることができます。

@@ -59,15 +57,15 @@ Ionic apps are made of high-level building blocks called Components, which allow -

チップはデータやアクションを表示するためのコンパクトな方法です。

+

Chipはデータやアクションを表示するためのコンパクトな方法です。

-

コンテンツは、アプリと対話してアプリをナビゲートするための典型的な方法です。

+

Contentは、アプリと対話してアプリをナビゲートするための典型的な方法です。

-

Date & time pickers are used to present an interface that makes it easy for users to select dates and times.

+

Date & Timeピッカーは、ユーザーが日付と時刻を簡単に選択できるインターフェースを提供するために使用されます。

@@ -81,7 +79,7 @@ Ionic apps are made of high-level building blocks called Components, which allow -

Beautifully designed icons for use in web, iOS, and Android apps.

+

Web、iOS、Androidアプリで使用するために美しくデザインされたアイコン。

@@ -89,13 +87,13 @@ Ionic apps are made of high-level building blocks called Components, which allow -

Inputs provides a way for users to enter data in your app.

+

Inputは、ユーザーがアプリにデータを入力する方法を提供します。

- Items are elements that can contain text, icons, avatars, images, inputs, and any other native or custom elements. - Items can be swiped, deleted, reordered, edited, and more. + Itemは、テキスト、アイコン、アバター、画像、入力、およびその他のネイティブまたはカスタム要素を含むことができる要素です。 + Itemは、スワイプ、削除、並び替え、編集などが可能です。

@@ -105,8 +103,7 @@ Ionic apps are made of high-level building blocks called Components, which allow

- A collection of media components, including avatars, icons, images, and thumbnails, designed to enhance visual - content. + アバター、アイコン、画像、サムネイルを含むメディアコンポーネントのコレクションで、視覚的なコンテンツを強化するように設計されています。

@@ -123,7 +120,7 @@ Ionic apps are made of high-level building blocks called Components, which allow -

Navigation is how users move between different pages in your app.

+

Navigationは、ユーザーがアプリ内の異なるページ間を移動する方法です。

@@ -139,11 +136,11 @@ Ionic apps are made of high-level building blocks called Components, which allow -

Range sliders let users select a value by dragging a knob along a track.

+

Rangeスライダーは、ユーザーがトラックに沿ってノブをドラッグして値を選択できるようにします。

-

Refresher provides pull-to-refresh functionality on a content component.

+

Refresherは、コンテンツコンポーネントにプルツーリフレッシュ機能を提供します。

@@ -155,7 +152,7 @@ Ionic apps are made of high-level building blocks called Components, which allow -

Searchbar is used to search or filter items, usually from a toolbar.

+

検索バーは、通常ツールバーから、アイテムを検索またはフィルタリングするために使用されます。

@@ -173,7 +170,7 @@ Ionic apps are made of high-level building blocks called Components, which allow -

Toasts are subtle notifications that appear over your app's content without interrupting user interaction.

+

Toastは、ユーザーの操作を中断することなく、アプリのコンテンツの上に表示される控えめな通知です。

@@ -181,10 +178,10 @@ Ionic apps are made of high-level building blocks called Components, which allow -

Toolbars are used to house information and actions relating to your app.

+

Toolbarは、アプリに関連する情報とアクションを配置するために使用されます。

-

Text is used to style or change the color of text within an application.

+

Typographyは、アプリケーション内のテキストのスタイルを設定したり、色を変更したりするために使用されます。

diff --git a/docs/core-concepts/cross-platform.md b/docs/core-concepts/cross-platform.md index 0666ed6b8d6..0fd097627a8 100644 --- a/docs/core-concepts/cross-platform.md +++ b/docs/core-concepts/cross-platform.md @@ -67,7 +67,7 @@ this.platform.ready().then(() => { -To improve this experience, we can wrap the items in a [Grid](../api/grid.md) component. The view can be easily rewritten into something more usable on larger screens: +このエクスペリエンスを改善するために、アイテムを[Grid](../api/grid.md)コンポーネントで囲むことができます。ビューは、大きな画面でより使いやすくなるように簡単に書き直すことができます: ```html diff --git a/docs/core-concepts/fundamentals.md b/docs/core-concepts/fundamentals.md index 0542875ce50..09e173484e9 100644 --- a/docs/core-concepts/fundamentals.md +++ b/docs/core-concepts/fundamentals.md @@ -4,10 +4,10 @@ sidebar_label: 基本的な考え方 --- - App Development Core Concepts and Tools - Ionic Framework API + アプリ開発のコアコンセプトとツール - Ionic Framework API @@ -53,28 +53,28 @@ Ionic Framework はPrimary Button ``` -The `color` property is a reactive property that configures how the button appears. If you change the `color` value after the initial render, the button will update to reflect the new value. +`color`プロパティは、ボタンの外観を設定するリアクティブプロパティです。初期レンダリング後に`color`値を変更すると、ボタンは新しい値を反映するように更新されます。 -### Virtual Properties +### 仮想プロパティ -Virtual properties are designed for one-time configuration during component initialization. They do not trigger re-renders when updated. +仮想プロパティは、コンポーネントの初期化中に 1 回だけ設定するように設計されています。更新されても再レンダリングをトリガーしません。 ```html iOS Style Button Material Design Button ``` -The `mode` property is a virtual property that determines which platform styles to use for a component. It can be set at the component level or globally through the app configuration. In both cases, it's set once during initialization and doesn't change during the component's lifecycle. +`mode`プロパティは、コンポーネントに使用するプラットフォームスタイルを決定する仮想プロパティです。コンポーネントレベルで設定することも、アプリ設定を通じてグローバルに設定することもできます。どちらの場合も、初期化中に一度設定され、コンポーネントのライフサイクル中は変更されません。 -For more information on Ionic modes, read the [Platform Styles documentation](/docs/theming/platform-styles). +Ionic モードの詳細については、[Platform Styles documentation](/docs/theming/platform-styles)を参照してください。 diff --git a/docs/core-concepts/webview.md b/docs/core-concepts/webview.md index b8ceda1f189..6c7ac4e2f16 100644 --- a/docs/core-concepts/webview.md +++ b/docs/core-concepts/webview.md @@ -3,10 +3,10 @@ title: Web View --- - Capacitor Web View for iOS and Android Apps - Ionic Framework + iOSおよびAndroidアプリ用Capacitor Web View - Ionic Framework @@ -28,7 +28,7 @@ Ionic Web View プラグインは、最新の JavaScript アプリケーショ ### CORS -Web Views enforce [CORS](../reference/glossary.md#cors), so it's important that external services properly handle cross-origin requests. See the [CORS FAQs](../troubleshooting/cors.md) for information on dealing with CORS in Ionic apps. +Web View は[CORS](../reference/glossary.md#cors)を強制するため、外部サービスがクロスオリジンリクエストを適切に処理することが重要です。Ionic アプリで CORS を処理する方法については、[CORS FAQs](../troubleshooting/cors.md)を参照してください。 ### File プロトコル @@ -42,7 +42,7 @@ import { Capacitor } from '@capacitor/core'; Capacitor.convertFileSrc(filePath); ``` -For Cordova apps, the [Ionic Web View plugin](https://github.com/ionic-team/cordova-plugin-ionic-webview) provides a utility function for converting File URIs: `window.Ionic.WebView.convertFileSrc()`. There is also a corresponding Ionic Native plugin: [`@awesome-cordova-plugins/ionic-webview`](https://danielsogl.gitbook.io/awesome-cordova-plugins/ionic-webview). +Cordova アプリの場合、[Ionic Web View plugin](https://github.com/ionic-team/cordova-plugin-ionic-webview)は、File URI を変換するためのユーティリティ関数を提供します:`window.Ionic.WebView.convertFileSrc()`。対応する Ionic Native プラグインもあります:[`@awesome-cordova-plugins/ionic-webview`](https://danielsogl.gitbook.io/awesome-cordova-plugins/ionic-webview)。 ### 実装 diff --git a/docs/core-concepts/what-are-progressive-web-apps.md b/docs/core-concepts/what-are-progressive-web-apps.md index 272fd6c3b07..1fdc27f1fc5 100644 --- a/docs/core-concepts/what-are-progressive-web-apps.md +++ b/docs/core-concepts/what-are-progressive-web-apps.md @@ -7,7 +7,7 @@ title: Progressive Web Apps Progressive Web Applications: PWAとは - Ionic Documentation diff --git a/docs/deployment/app-store.md b/docs/deployment/app-store.md index c21978684dd..37a9765dd49 100644 --- a/docs/deployment/app-store.md +++ b/docs/deployment/app-store.md @@ -7,10 +7,10 @@ import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; - iOS App Storeでのリリース: Apple App Store Deployment for Ionic + iOS App Storeでのリリース: Ionic向けApple App Storeデプロイメント @@ -36,7 +36,7 @@ iOS プラットフォームがまだ追加されていない場合は、必ず ionic cap add ios ``` -With the platform added, run the build command with the `--prod` flag: +プラットフォームが追加されたら、`--prod`フラグを付けてビルドコマンドを実行します: ```shell ionic build --prod diff --git a/docs/deployment/desktop-app.md b/docs/deployment/desktop-app.md new file mode 100644 index 00000000000..8fdfd46e8eb --- /dev/null +++ b/docs/deployment/desktop-app.md @@ -0,0 +1,48 @@ +--- +title: デスクトップアプリへのデプロイ +sidebar_label: Electronデスクトップアプリ +--- + + + WindowsとmacOS App Stores向けにデスクトップアプリとしてビルド + + + +Ionic でデスクトップアプリケーションを構築すると、開発者はコードを 100%再利用し、従来のデスクトップアプリケーションをリリースしながら、プッシュ通知などのすべてのネイティブデバイスの機能を利用することができます。このガイドでは、Electron に精通していることを前提としており、Electron アプリの「作り方」については触れません。 詳しくは Electron guide. をご覧ください。 + +## macOS アプリ + +### 要件 + +macOS アプリをストアでアプリを公開するには、難しい要件が 2 つあります。 + +- [Xcode](https://itunes.apple.com/us/app/xcode/id497799835?mt=12) が最新版であること +- 開発者アカウント ($100 through Apple's developer portal) が有効であること + +### リリース + +Electron チームは、macOS 用のアプリを公開する方法についての詳細なガイドを持っています。[the docs](https://electronjs.org/docs/tutorial/mac-app-store-submission-guide) をご覧ください。 + +## Windows アプリ + +### 要件 + +Windows アプリをストアでアプリを公開するには、2 つの厳しい要件があります。 + +- Anniversary Update 付き Windows 10(2016 年 8 月 2 日リリース) +- Windows 10 SDK、[こちらからダウンロード](https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk) +- Node +- electron-windows-store CLI + +`electron-windows-store` は npm を使ってインストールすることができます: + +```shell +npm install -g electron-windows-store +``` + +### リリース作業 + +macOS と同様、Electron は Windows 用のアプリを公開する方法についても詳細なガイドを提供している。 [the docs](https://electronjs.org/docs/tutorial/windows-store-guide) を確認してください diff --git a/docs/deployment/play-store.md b/docs/deployment/play-store.md new file mode 100644 index 00000000000..cab86a54e89 --- /dev/null +++ b/docs/deployment/play-store.md @@ -0,0 +1,79 @@ +--- +title: Android Play Storeへの開発 +sidebar_label: Android Play Store +--- + + + Android Play Storeでのリリース: Ionicアプリを公開 + + + +## アプリのリリースビルド作成 + +Android 用のリリースビルドを生成するには、以下の cli コマンドを実行します。 + +```shell +$ ionic cordova build android --prod --release +``` + +これは、アプリの `platforms/android/app/build/outputs/apk` ディレクトリにある `config.xml` の設定に基づき、リリースビルドを生成するものです。 +Ionic アプリはこのファイルにあらかじめデフォルト値が設定されていますが、ビルドをカスタマイズするために変更することができます。 + +## APK への署名 + +まず、署名されていない APK に署名する必要があります。署名鍵がすでに生成されている場合は、この手順をスキップして、代わりにその鍵を使用します。 +Android SDK に付属する keytool コマンドを使用して、秘密鍵を生成します。 + +```shell +$ keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000 +``` + +このコマンドを実行し、プロンプトに答えると、カレントディレクトリに `my-release-key.keystore` という名前のファイルが作成されます。 + +:::warning +このファイルを保存し、安全な場所に保管してください。このファイルを紛失すると、Google Play ストアはこのアプリのアップデートを受け付けません! +::: + +署名されていない APK に署名するには、Android SDK に含まれる jarsigner ツールを実行します。 + +```shell +$ jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore HelloWorld-release-unsigned.apk alias_name +``` + +最後に、APK を最適化するために、`zipalign` ツールを実行する必要があります。 +`zipalign` ツールは `/path/to/Android/sdk/build-tools/VERSION/zipalign` にあります。 +例えば、Android Studio がインストールされている macOS では、`zipalign`は `~/Library/Android/sdk/build-tools/VERSION/zipalign` の中に入っています。 + +```shell +$ zipalign -v 4 HelloWorld-release-unsigned.apk HelloWorld.apk +``` + +これにより、Google Play ストアに受け入れられる HelloWorld.apk という最終リリースバイナリが生成されます。 + +## Google Play Store にアプリを送信する + +リリース用 APK が生成されたので、Play ストアのリスティングを書き、APK をアップロードすることができるようになりました。 + +まずは、[Google Play Store Developer Console](https://play.google.com/apps/publish)にアクセスし、開発者アカウントを新規に作成します。 + +:::note +Google Play で開発者アカウントを作るには、25US ドルが必要です。 +::: + +開発者アカウントを作成したら、「アプリケーションを作成する」ボタン(Create an Application)をクリックします。 + +![Create an App button](/img/publishing/newAppGPlay.png) + +アプリの説明、スクリーンショット、その他の情報を入力してください。 +準備ができたら、生成された署名付きリリース APK をアップロードし、アプリを公開します。 + +## アプリのアップデート + +アプリの進化に伴い、新機能の追加や修正などのアップデートが必要になってきます。アプリのアップデートは、Google Play Store に新バージョンを提出するか、Appflow の Live Update 機能のようなライブアップデートサービスを使用することで行うことができます。ライブアップデートでは、Play ストアに変更を送信することなく、Appflow のダッシュボードから直接ユーザーに変更をプッシュすることができます。Live Update についてもっと知るためにはこちらにアクセスください。 + +:::note +Google Play ストアでアップデートされた APK を受け入れるには、config.xml ファイルを編集してバージョンをあげて、上記の手順に従ってアプリをリリース用に再構築する必要があります。 +::: diff --git a/docs/deployment/progressive-web-app.md b/docs/deployment/progressive-web-app.md index 83ecdcfd90a..e0460c187d0 100644 --- a/docs/deployment/progressive-web-app.md +++ b/docs/deployment/progressive-web-app.md @@ -10,7 +10,7 @@ import DocsCards from '@components/global/DocsCards'; Progressive Web Applicationへのデプロイ @@ -19,7 +19,13 @@ Ionic Apps は Web 技術で構築されているため、ネイティブアプ Ionic が対応しているフレームワークについては、専用のガイドを作成し、より詳しく解説しています。以下は、Angular と React と Vue のリンクです。 - - - + + AngularでProgressive Web Appを始めましょう。 + + + ReactでProgressive Web Appを始めましょう。 + + + VueでProgressive Web Appを始めましょう。 + diff --git a/docs/developing/android.md b/docs/developing/android.md index 53c9d76f634..88a6daa4c40 100644 --- a/docs/developing/android.md +++ b/docs/developing/android.md @@ -7,32 +7,32 @@ sidebar_label: Androidでの開発 Androidアプリ開発ガイド: Build Ionic Apps in Android Studio import DocsCard from '@components/global/DocsCard'; import DocsCards from '@components/global/DocsCards'; -:::info Looking for the legacy Android guide? +:::info レガシー Android ガイドをお探しですか? -The Developing for Android guide has officially migrated to the [Capacitor documentation for Android](https://capacitorjs.com/docs/android). If you need to access the legacy documentation, you can find it under the [legacy developing for Android guide](https://ionic-docs-o31kiyk8l-ionic1.vercel.app/docs/v6/developing/android). +Android 開発ガイドは、正式に[Capacitor の Android ドキュメント](https://capacitorjs.com/docs/android)に移行されました。レガシードキュメントにアクセスする必要がある場合は、[レガシー Android 開発ガイド](https://ionic-docs-fo03f34h5-ionic1.vercel.app/docs/v6/developing/android)で見つけることができます。 ::: -

Learn the fundamentals you need to know to start building Android apps with Ionic Framework and Capacitor.

+

Ionic FrameworkとCapacitorを使用してAndroidアプリの構築を開始するために知っておく必要がある基本を学びます。

-

Learn the fundamentals you need to know to start building Android apps with Ionic Framework and Cordova.

+

Ionic FrameworkとCordovaを使用してAndroidアプリの構築を開始するために知っておく必要がある基本を学びます。

diff --git a/docs/developing/config.md b/docs/developing/config.md index 6cce3de4a1d..d542be832d7 100644 --- a/docs/developing/config.md +++ b/docs/developing/config.md @@ -5,72 +5,72 @@ title: Config import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; -Ionic Config provides a way to change the properties of components globally across an app. It can set the app mode, tab button layout, animations, and more. +Ionic Config は、アプリ全体でコンポーネントのプロパティをグローバルに変更する方法を提供します。アプリモード、タブボタンのレイアウト、アニメーションなどを設定できます。 -## Global Config +## グローバル設定 -The available config keys can be found in the [`IonicConfig`](#ionicconfig) interface. +利用可能な設定キーは、[`IonicConfig`](#ionicconfig)インターフェースで見つけることができます。 -The following example disables ripple effects and default the mode to Material Design: +次の例では、リップル効果を無効にし、モードを Material Design にデフォルト設定します: import GlobalExample from '@site/docs/developing/config/global/index.md'; -## Per-Component Config +## コンポーネントごとの設定 -Ionic Config is not reactive. Updating the config's value after the component has rendered will result in the previous value. It is recommended to use a component's properties instead of updating the config, when you require reactive values. +Ionic Config はリアクティブではありません。コンポーネントがレンダリングされた後に設定の値を更新しても、以前の値のままになります。リアクティブな値が必要な場合は、設定を更新する代わりに、コンポーネントのプロパティを使用することをお勧めします。 import PerComponentExample from '@site/docs/developing/config/per-component/index.md'; -## Per-Platform Config +## プラットフォームごとの設定 -Ionic Config can also be set on a per-platform basis. For example, this allows you to disable animations if the app is being run in a browser on a potentially slower device. Developers can take advantage of the Platform utilities to accomplish this. +Ionic Config は、プラットフォームごとに設定することもできます。たとえば、これにより、潜在的に遅いデバイスのブラウザでアプリが実行されている場合にアニメーションを無効にできます。開発者は、Platform ユーティリティを活用してこれを実現できます。 -In the following example, we are disabling all animations in our Ionic app only if the app is running in a mobile web browser. +次の例では、モバイル Web ブラウザでアプリが実行されている場合にのみ、Ionic アプリのすべてのアニメーションを無効にしています。 import PerPlatformExample from '@site/docs/developing/config/per-platform/index.md'; -### Fallbacks +### フォールバック -The next example allows you to set an entirely different configuration based upon the platform, falling back to a default config if no platforms match: +次の例では、プラットフォームに基づいて完全に異なる設定を設定でき、プラットフォームが一致しない場合はデフォルト設定にフォールバックします: import PerPlatformFallbackExample from '@site/docs/developing/config/per-platform-overrides/index.md'; -### Overrides +### オーバーライド -This final example allows you to accumulate a config object based upon different platform requirements. +この最後の例では、異なるプラットフォーム要件に基づいて設定オブジェクトを累積できます。 import PerPlatformOverridesExample from '@site/docs/developing/config/per-platform-fallback/index.md'; -## Accessing the Mode +## モードへのアクセス -In some cases, you may need to access the current Ionic mode programmatically within your application logic. This can be useful for applying conditional behavior, fetching specific assets, or performing other actions based on the active styling mode. +場合によっては、アプリケーションロジック内で現在の Ionic モードにプログラム的にアクセスする必要があるかもしれません。これは、条件付き動作を適用したり、特定のアセットを取得したり、アクティブなスタイリングモードに基づいて他のアクションを実行したりするのに役立ちます。 import IonicMode from '@site/static/usage/v8/config/mode/index.md'; -## Reading the Config (Angular) +## 設定の読み取り(Angular) -Ionic Angular provides a `Config` provider for accessing the Ionic Config. +Ionic Angular は、Ionic Config にアクセスするための`Config`プロバイダーを提供します。 ### get -| | | -| --------------- | -------------------------------------------------------------------------------- | -| **Description** | Returns a config value as an `any`. Returns `null` if the config is not defined. | -| **Signature** | `get(key: string, fallback?: any) => any` | +| | | +| -------------- | --------------------------------------------------------------------------- | +| **説明** | 設定値を`any`として返します。設定が定義されていない場合は`null`を返します。 | +| **シグネチャ** | `get(key: string, fallback?: any) => any` | -#### Examples +#### 例 boolean` | +| | | +| -------------- | -------------------------------------------------------------------------------- | +| **説明** | 設定値を`boolean`として返します。設定が定義されていない場合は`false`を返します。 | +| **シグネチャ** | `getBoolean(key: string, fallback?: boolean) => boolean` | -#### Examples +#### 例 number` | +| | | +| -------------- | --------------------------------------------------------------------------- | +| **説明** | 設定値を`number`として返します。設定が定義されていない場合は`0`を返します。 | +| **シグネチャ** | `getNumber(key: string, fallback?: number) => number` | -## Interfaces +## インターフェース ### IonicConfig -Below are the config options that Ionic uses. +以下は、Ionic が使用する設定オプションです。 -| Config | Type | Description | +| Config | Type | 説明 | | --------------------------- | --------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `actionSheetEnter` | `AnimationBuilder` | Provides a custom enter animation for all `ion-action-sheet`, overriding the default "animation". | | `actionSheetLeave` | `AnimationBuilder` | Provides a custom leave animation for all `ion-action-sheet`, overriding the default "animation". | diff --git a/docs/developing/hardware-back-button.md b/docs/developing/hardware-back-button.md index 25c68c2cde2..c5a8b08d1e4 100644 --- a/docs/developing/hardware-back-button.md +++ b/docs/developing/hardware-back-button.md @@ -27,22 +27,22 @@ Ionic Framework は、サポートされている環境でユーザーがハー 複数のハンドラを起動したい場合があります。各ハンドラのコールバックは、フレームワークに次のハンドラを呼び出すように指示するために使用できるパラメーターとして関数を渡します。 -## Support +## サポート -The table below shows how hardware back button support varies by environment. +以下の表は、環境によってハードウェアの戻るボタンのサポートがどのように異なるかを示しています。 -| Environment | Status | -| ----------- | --------------------------------------------------------------------------------------------------------- | -| Capacitor | Supported only when the `@capacitor/app` package is installed. | -| Cordova | Supported | -| Browser | Supported only when `experimentalCloseWatcher` is `true` and the platform supports the Close Watcher API. | -| PWA | Supported only when `experimentalCloseWatcher` is `true` and the platform supports the Close Watcher API. | +| Environment | Status | +| ----------- | ----------------------------------------------------------------------------------------------------------------------- | +| Capacitor | `@capacitor/app`パッケージがインストールされている場合のみサポートされます。 | +| Cordova | サポートされています | +| Browser | `experimentalCloseWatcher`が`true`で、プラットフォームが Close Watcher API をサポートしている場合のみサポートされます。 | +| PWA | `experimentalCloseWatcher`が`true`で、プラットフォームが Close Watcher API をサポートしている場合のみサポートされます。 | -### Hardware Back Button in a Browser or a PWA +### ブラウザまたは PWA でのハードウェアの戻るボタン -Ionic has experimental support for handling the hardware back button in a browser or a PWA by setting [`experimentalCloseWatcher: true` in the IonicConfig](./config.md). When this feature is enabled, Ionic will use the [Close Watcher API](https://github.com/WICG/close-watcher) to pass any close requests through the `ionBackButton` event. This includes pressing the hardware back button to navigate or the Escape key to dismiss a modal. +Ionic は、[IonicConfig で`experimentalCloseWatcher: true`を設定](./config.md)することで、ブラウザまたは PWA でハードウェアの戻るボタンを処理する実験的なサポートを提供します。この機能が有効になっている場合、Ionic は[Close Watcher API](https://github.com/WICG/close-watcher)を使用して、すべての閉じるリクエストを`ionBackButton`イベントを通じて渡します。これには、ナビゲーションのためにハードウェアの戻るボタンを押すことや、モーダルを閉じるために Escape キーを押すことが含まれます。 -Chrome has support for Close Watcher starting in [Chrome 120](https://developer.chrome.com/blog/new-in-chrome-120). +Chrome は[Chrome 120](https://developer.chrome.com/blog/new-in-chrome-120)から Close Watcher をサポートしています。 ハードウェアバックボタンを完全にサポートするには、Capacitor または Cordova の使用をお勧めします。 diff --git a/docs/developing/ios.md b/docs/developing/ios.md index a9ddb7cceb9..0e9a3cf6423 100644 --- a/docs/developing/ios.md +++ b/docs/developing/ios.md @@ -8,32 +8,32 @@ skipIntros: true iOSアプリ開発ガイド: Xcode Setup to Build and Run iOS Apps import DocsCard from '@components/global/DocsCard'; import DocsCards from '@components/global/DocsCards'; -:::info Looking for the legacy iOS guide? +:::info レガシー iOS ガイドをお探しですか? -The Developing for iOS guide has officially migrated to the [Capacitor documentation for iOS](https://capacitorjs.com/docs/ios). If you need to access the legacy documentation, you can find it under the [legacy developing for iOS guide](https://ionic-docs-o31kiyk8l-ionic1.vercel.app/docs/v6/developing/ios). +iOS 開発ガイドは、正式に[Capacitor の iOS ドキュメント](https://capacitorjs.com/docs/ios)に移行されました。レガシードキュメントにアクセスする必要がある場合は、[レガシー iOS 開発ガイド](https://ionic-docs-fo03f34h5-ionic1.vercel.app/docs/v6/developing/ios)で見つけることができます。 ::: -

Learn the fundamentals you need to know to start building iOS apps with Ionic Framework and Capacitor.

+

Ionic FrameworkとCapacitorを使用してiOSアプリの構築を開始するために知っておく必要がある基本を学びます。

-

Learn the fundamentals you need to know to start building iOS apps with Ionic Framework and Cordova.

+

Ionic FrameworkとCordovaを使用してiOSアプリの構築を開始するために知っておく必要がある基本を学びます。

diff --git a/docs/developing/managing-focus.md b/docs/developing/managing-focus.md index 9859ed2fb78..d68cfc2b971 100644 --- a/docs/developing/managing-focus.md +++ b/docs/developing/managing-focus.md @@ -6,44 +6,44 @@ import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; - Managing Focus + フォーカス管理 -## Manual Focus Management +## 手動フォーカス管理 -Ionic provides a `setFocus` API on components such as [Input](../api/input), [Searchbar](../api/searchbar), and [Textarea](../api/textarea) that allows developers to manually set focus to an element. This API should be used in place of the `autofocus` attribute and called within: +Ionic は、[Input](../api/input)、[Searchbar](../api/searchbar)、[Textarea](../api/textarea)などのコンポーネントに`setFocus` API を提供し、開発者が要素に手動でフォーカスを設定できるようにします。この API は`autofocus`属性の代わりに使用し、以下のタイミングで呼び出す必要があります: -- The `ionViewDidEnter` lifecycle event for routing applications when a page is entered. -- The `didPresent` lifecycle event for overlays when an overlay is presented. -- The `appload` event for vanilla JavaScript applications when the application loads. -- The result of a user gesture or interaction. +- ルーティングアプリケーションでページが入力されたときの`ionViewDidEnter`ライフサイクルイベント。 +- オーバーレイが表示されたときのオーバーレイの`didPresent`ライフサイクルイベント。 +- アプリケーションが読み込まれたときのバニラ JavaScript アプリケーションの`appload`イベント。 +- ユーザーのジェスチャーやインタラクションの結果。 -### Why not autofocus? +### なぜ autofocus を使わないのか? -The `autofocus` attribute is a standard HTML attribute that allows developers to set focus to an element when a page loads. This attribute is commonly used to set focus to the first input element on a page. However, the `autofocus` attribute can cause issues in routing applications when navigating between pages. This is because the `autofocus` attribute will set focus to the element when the page loads, but will not set focus to the element when the page is revisited. Learn more about the `autofocus` attribute in the [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autofocus). +`autofocus`属性は、ページが読み込まれたときに要素にフォーカスを設定できる標準の HTML 属性です。この属性は、通常、ページの最初の入力要素にフォーカスを設定するために使用されます。ただし、`autofocus`属性は、ページ間をナビゲートする際にルーティングアプリケーションで問題を引き起こす可能性があります。これは、`autofocus`属性がページが読み込まれたときに要素にフォーカスを設定しますが、ページが再訪問されたときに要素にフォーカスを設定しないためです。`autofocus`属性の詳細については、[MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autofocus)を参照してください。 -### Platform Restrictions +### プラットフォームの制限 -There are platform restrictions you should be aware of when using the `setFocus` API, including: +`setFocus` API を使用する際に注意すべきプラットフォームの制限があります: -1. Android requires user interaction before setting focus to an element. This can be as simple as a user tapping on the screen. -2. Interactive elements can only focused a result of a user gesture on Mobile Safari (iOS), such as calling `setFocus` as the result of a button click. +1. Android では、要素にフォーカスを設定する前にユーザーのインタラクションが必要です。これは、ユーザーが画面をタップするだけでも可能です。 +2. Mobile Safari(iOS)では、インタラクティブ要素はユーザーのジェスチャーの結果としてのみフォーカスできます。たとえば、ボタンクリックの結果として`setFocus`を呼び出すなどです。 -### Basic Usage +### 基本的な使用方法 -The example below demonstrates how to use the `setFocus` API to request focus on an input when the user clicks a button. +以下の例は、ユーザーがボタンをクリックしたときに`setFocus` API を使用して入力にフォーカスを要求する方法を示しています。 import Basic from '@site/static/usage/v8/input/set-focus/index.md'; -### Routing +### ルーティング -Developers can use the `ionViewDidEnter` lifecycle event to set focus to an element when a page is entered. +開発者は、`ionViewDidEnter`ライフサイクルイベントを使用して、ページが入力されたときに要素にフォーカスを設定できます。 ````mdx-code-block ```` -### Overlays +### オーバーレイ -Developers can use the `didPresent` lifecycle event to set focus to an element when an overlay is presented. +開発者は、`didPresent`ライフサイクルイベントを使用して、オーバーレイが表示されたときに要素にフォーカスを設定できます。 ````mdx-code-block ```` -## Assistive Technology Focus Management +## アシスティブテクノロジーのフォーカス管理 -By default, Single Page Applications have no built-in way of informing screen readers that the active view has changed in a browser or webview. This means that users who rely on assistive technology do not always know if a navigation event occurred. +デフォルトでは、シングルページアプリケーションには、ブラウザまたは WebView でアクティブなビューが変更されたことをスクリーンリーダーに通知する組み込みの方法がありません。これは、アシスティブテクノロジーに依存するユーザーが、ナビゲーションイベントが発生したかどうかを常に知ることができないことを意味します。 -Developers who enable the [focusManagerPriority config](./config#ionicconfig) can delegate focus management to Ionic during page transitions. When enabled, Ionic will move focus to the correct element as specified in the config option. This will inform screen readers that a navigation event occurred. +[focusManagerPriority 設定](./config#ionicconfig)を有効にした開発者は、ページ遷移中にフォーカス管理を Ionic に委任できます。有効にすると、Ionic は設定オプションで指定された正しい要素にフォーカスを移動します。これにより、スクリーンリーダーにナビゲーションイベントが発生したことが通知されます。 -### Types +### 型 ```typescript type FocusManagerPriority = 'content' | 'heading' | 'banner'; ``` -### Content Types +### コンテンツタイプ -The following table explains what each content type represents: +次の表は、各コンテンツタイプが何を表すかを説明しています: -| Type | Description | Ionic Component | Semantic HTML Equivalent | Landmark Equivalent | -| --------- | ----------------------------- | ------------------------- | ---------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `content` | The main portion of the view. | [Content](../api/content) | [`main`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/main) | [`role="main"`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/Main_role) | -| `heading` | The title of the view. | [Title](../api/title) | [`h1`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/h1) | [`role="heading"`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/heading_role) with [`aria-level="1"`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-level) | -| `banner` | The header of the view. | [Header](../api/header) | [`header`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/header) | [`role="banner"`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/Banner_Role) | +| Type | 説明 | Ionic Component | Semantic HTML Equivalent | Landmark Equivalent | +| --------- | ------------------ | ------------------------- | ---------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `content` | ビューの主要部分。 | [Content](../api/content) | [`main`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/main) | [`role="main"`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/Main_role) | +| `heading` | ビューのタイトル。 | [Title](../api/title) | [`h1`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/h1) | [`role="heading"`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/heading_role) with [`aria-level="1"`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-level) | +| `banner` | ビューのヘッダー。 | [Header](../api/header) | [`header`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/header) | [`role="banner"`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/Banner_Role) | :::important -Developers should assign `role="heading"` and `aria-level="1"` to the primary [Title](../api/title) on each view. Since multiple [Title](../api/title) components can be used in a single view, Ionic does not automatically assign these attributes. +開発者は、各ビューの主要な[Title](../api/title)に`role="heading"`と`aria-level="1"`を割り当てる必要があります。単一のビューで複数の[Title](../api/title)コンポーネントを使用できるため、Ionic はこれらの属性を自動的に割り当てません。 ::: -### Specifying Priority +### 優先順位の指定 -The config should be specified in order of decreasing priority. In the following example, Ionic will always focus headings to start. Ionic only proceeds to the next focus priority, banner, if a view does not have a heading: +設定は優先順位の降順で指定する必要があります。次の例では、Ionic は常に最初に見出しにフォーカスします。ビューに見出しがない場合にのみ、Ionic は次のフォーカス優先順位である banner に進みます: ```js focusManagerPriority: ['heading', 'banner']; ``` -### Implementation Notes +### 実装に関する注意事項 -- When specifying a focus priority, browsers may still move focus within that focus priority. For example, when specifying a `'content'` focus priority, Ionic will move focus to the content. However, the browser may then move focus within that content to the first focusable element such as a button. -- If none of the focus priorities are found in a view, Ionic will instead focus the view itself to ensure focus generally moves to the correct place. Browsers may then adjust focus within the view. -- When navigating from the current view to the previous view, Ionic will move focus back to the element that presented the current view. -- The focus manager can be overridden on a per-view basis as shown in [Manual Focus Management with Routing](#routing). +- フォーカス優先順位を指定する場合、ブラウザはそのフォーカス優先順位内でフォーカスを移動する場合があります。たとえば、`'content'`フォーカス優先順位を指定すると、Ionic はコンテンツにフォーカスを移動します。ただし、ブラウザはその後、そのコンテンツ内の最初のフォーカス可能な要素(ボタンなど)にフォーカスを移動する場合があります。 +- ビューでフォーカス優先順位が見つからない場合、Ionic は代わりにビュー自体にフォーカスを移動して、フォーカスが一般的に正しい場所に移動するようにします。その後、ブラウザはビュー内でフォーカスを調整する場合があります。 +- 現在のビューから前のビューにナビゲートする場合、Ionic は現在のビューを表示した要素にフォーカスを戻します。 +- フォーカスマネージャーは、[ルーティングでの手動フォーカス管理](#routing)に示すように、ビューごとにオーバーライドできます。 diff --git a/docs/developing/scaffolding.md b/docs/developing/scaffolding.md index 137b6aeb9d6..31c12962975 100644 --- a/docs/developing/scaffolding.md +++ b/docs/developing/scaffolding.md @@ -48,11 +48,7 @@ src/ This command is only supported in Ionic Angular. ::: -:::note -This command is only supported in Ionic Angular. -::: - -The Ionic CLI can generate new app features with the [`ionic generate`](../cli/commands/generate.md) command. By running `ionic generate` in the command line, a selection prompt is displayed which lists the available features that can be generated. +Ionic CLI は、[`ionic generate`](../cli/commands/generate.md)コマンドを使用して新しいアプリ機能を生成できます。コマンドラインで`ionic generate`を実行すると、生成可能な利用可能な機能をリストする選択プロンプトが表示されます。 ```shell-session $ ionic generate diff --git a/docs/index.md b/docs/index.md index 2adc722dc0e..58a37537ff8 100644 --- a/docs/index.md +++ b/docs/index.md @@ -14,7 +14,7 @@ import DocsCards from '@components/global/DocsCards'; モバイルとディスクトップアプリをつくるためのオープンソースのUIキット @@ -22,19 +22,19 @@ import DocsCards from '@components/global/DocsCards'; -Ionic is an open source UI toolkit for building performant, high-quality mobile apps using web technologies — HTML, CSS, and JavaScript — with integrations for popular frameworks like [Angular](angular/overview.md), [React](react/overview.md), and [Vue](vue/overview.md). +Ionic は、Web 技術(HTML、CSS、JavaScript)を使用して、高性能で高品質なモバイルアプリを構築するためのオープンソース UI ツールキットで、[Angular](angular/overview.md)、[React](react/overview.md)、[Vue](vue/overview.md)などの人気フレームワークとの統合を提供しています。 [Ionic のインストール](intro/cli.md) や [First App Tutorial](intro/next.md#build-your-first-app) を参考に、主な概念を学ぶことができます。 - +

あなたのシステムの設定方法とフレームワークのインストールガイド。

created a video to walk you through the basics. +Ionic は、アプリのフロントエンド UX と UI インタラクションに焦点を当てています — UI コントロール、インタラクション、ジェスチャー、アニメーション。学習が容易で、[Angular](angular/overview.md)、[React](react/overview.md)、[Vue](vue/overview.md)などの他のライブラリやフレームワークと統合できます。また、シンプルな[script include](intro/cdn.md)を使用して、フロントエンドフレームワークなしでスタンドアロンで使用することもできます。Ionic について詳しく知りたい場合は、基本を説明する動画を作成しました。 ### どこでもひとつのコードで @@ -115,7 +115,7 @@ Ionic は現在、人気の React ライブラリを公式にサポートして Ionic は現在、人気の Vue3 ライブラリを公式にサポートしています。 Ionic Vue を使用すると、Vue 開発者は既存の Web スキルを使用して、iOS、Android、Web、およびデスクトップを対象とするアプリを構築できます。 `@ionic/vue` を使用すると、すべてのコア Ionic コンポーネントを使用できますが、ネイティブの Vue コンポーネントを使用しているように感じられます。 -### Future Support +### 将来のサポート 他のフレームワークのサポートは、将来のリリースで検討される予定です。 @@ -140,10 +140,10 @@ Ionic Framework はコアチームによって積極的に開発され、メン Ionic の開発者は世界 200 か国以上に何百万人もいます。コミュニティへの参加方法をいくつか紹介します: -- Forum: A great place for asking questions and sharing ideas. -- Twitter: Where we post updates and share content from the Ionic community. -- GitHub: For reporting bugs or requesting new features, create an issue here. PRs welcome! -- Content authoring: Write a technical blog or share your story with the Ionic community. +- フォーラム: 質問をしたり、アイデアを共有したりするのに最適な場所です。 +- Twitter: アップデートを投稿し、Ionicコミュニティからのコンテンツを共有しています。 +- GitHub: バグの報告や新機能のリクエストは、こちらでイシューを作成してください。プルリクエストも歓迎します! +- コンテンツ作成: 技術ブログを書いたり、Ionicコミュニティにあなたのストーリーを共有したりしてください。 ## ライセンス diff --git a/docs/intro/cdn.md b/docs/intro/cdn.md index 0d8370ba705..22546868578 100644 --- a/docs/intro/cdn.md +++ b/docs/intro/cdn.md @@ -1,156 +1,122 @@ --- -title: Ionicパッケージ +title: Ionic パッケージ & CDN sidebar_label: パッケージ & CDN --- - Ionic Framework Packages: CDN, Angular, Vue, and React + Ionic Frameworkパッケージ: CDN、Angular、Vue、React、JavaScript -Ionic は、テスト環境、Angular、その他のフレームワーク、または Vanilla JS といったすべての状況で、Ionic Framework を使い始めるために使用できるさまざまなパッケージを提供しています。 +import DocsCard from '@components/global/DocsCard'; +import DocsCards from '@components/global/DocsCards'; -## Ionic Framework CDN - -Ionic フレームワークは、[Plunker](https://plnkr.co/)、[Codepen](https://codepen.io)、またはその他のオンラインコードエディタですばやくテストするために、CDN から組み込むことができます。 - -CDN からフレームワークにアクセスするには、 [jsdelivr](https://www.jsdelivr.com/) を使用することをお勧めします。最新バージョンを入手するためには HTML ファイルの `` 要素、もしくはオンラインコードエディタの呼び出しコードに、次のコードを追加します。 - -```html - - - -``` +Ionic Framework は、Angular、React、Vue、JavaScript 用の npm パッケージと、迅速なプロトタイピング用の CDN リンクを提供しています。下記からフレームワークを選択して始めるか、CDN を使用してブラウザで Ionic Framework コンポーネントをテストしてください。 -これにより、フレームワークをインストールしなくても、すべての Ionic Framework のコアコンポーネントを使用することができます。CSS バンドルには、すべての Ionic [Global Stylesheets](../layout/global-stylesheets) が含まれます。 +## Ionic Angular -:::note -これは Angular や他のフレームワークをインストールしません。これにより、フレームワークなしで Ionic Framework のコアコンポーネントを使用できます。 -::: +新しい Ionic Angular アプリを開始するか、既存の Angular プロジェクトに Ionic を追加します。 -## Ionic + Angular + -Angular プロジェクトで Ionic Framework を使用する場合は、 [npm](../reference/glossary.md#npm) から最新の `@ionic/angular` をインストールしてください。これによって、すべての Ionic Framework コンポーネントと、Angular のサービスおよび機能を使うことができます。 + +

Ionic CLIを使用して新しいIonic Angularアプリを作成します。

+
-```shell -npm install @ionic/angular@latest --save -``` + +

既存のAngularプロジェクトにIonic Angularを追加します。

+
-新しい Ionic Framework のリリースがあるたびに、最新バージョンの機能と修正を入手するために [バージョン](../reference/versioning.md) を更新する必要があります。最新のバージョンは [npm を使ったアップデート](../developing/tips.md#updating-dependencies) から取得することができます。 +
-Ionic を既存の Angular プロジェクトに追加するには、Angular CLI の `ng add` 機能を使用します。 +## Ionic React -```shell -ng add @ionic/angular -``` +新しい Ionic React アプリを開始するか、既存の React プロジェクトに Ionic を追加します。 -これにより、`@ionic/angular` に必要なパッケージと、必要なスタイルが追加されます。 + -## Ionic + React + +

Ionic CLIを使用して新しいIonic Reactアプリを作成します。

+
-Ionic を既存の React プロジェクトに追加するには、 `@ionic/react` および `@ionic/react-router` パッケージをインストールします。 + +

既存のReactプロジェクトにIonic Reactを追加します。

+
-```shell -$ npm install @ionic/react -$ npm install @ionic/react-router -``` +
-### CSS +## Ionic Vue -必要な CSS を React プロジェクトに含めるには、ルートアプリコンポーネントに以下を追加します。 +新しい Ionic Vue アプリを開始するか、既存の Vue プロジェクトに Ionic を追加します。 -```javascript -/* Core CSS required for Ionic components to work properly */ -import '@ionic/react/css/core.css'; + -/* Basic CSS for apps built with Ionic */ -import '@ionic/react/css/normalize.css'; -import '@ionic/react/css/structure.css'; -import '@ionic/react/css/typography.css'; + +

Ionic CLIを使用して新しいIonic Vueアプリを作成します。

+
-/* Optional CSS utils that can be commented out */ -import '@ionic/react/css/padding.css'; -import '@ionic/react/css/float-elements.css'; -import '@ionic/react/css/text-alignment.css'; -import '@ionic/react/css/text-transformation.css'; -import '@ionic/react/css/flex-utils.css'; -import '@ionic/react/css/display.css'; -``` + +

既存のVueプロジェクトにIonic Vueを追加します。

+
-## Ionic + Vue +
-既存の Vue プロジェクトに Ionic Framework を追加するには、 `@ionic/vue` と `@ionic/vue-router` パッケージをインストールします。 +## Ionic JavaScript -```shell -npm install @ionic/vue @ionic/vue-router -``` - -その後、Vue アプリに`IonicVue`プラグインをインストールする必要があります。 +新しい Ionic JavaScript アプリを開始します。 -**main.js** + -```javascript -import { IonicVue } from '@ionic/vue'; + +

Viteを使用して新しいIonic JavaScriptアプリを作成します。

+
-import App from './App.vue'; -import router from './router'; +
-const app = createApp(App).use(IonicVue).use(router); - -router.isReady().then(() => { - app.mount('#app'); -}); -``` - -`router.isReady()`が解決したら、必ずアプリをマウントしてください。 - -### ルーティング - -Vue アプリでルーティングを設定する場合、`vue-router`ではなく、`@ionic/vue-router`から依存関係をインポートする必要があります。 - -**router/index.js** - -```javascript -import { createRouter, createWebHistory } from '@ionic/vue-router'; - -const routes = [ - // routes go here -]; - -const router = createRouter({ - history: createWebHistory(process.env.BASE_URL), - routes, -}); - -export default router; -``` - -### CSS - -Vue プロジェクトで必要な CSS を import するには、`main.js` ファイルに以下を追加します。 +## Ionic Framework CDN -```javascript -/* Core CSS required for Ionic components to work properly */ -import '@ionic/vue/css/core.css'; +Ionic Framework は、[StackBlitz](https://stackblitz.com/)、[Plunker](https://plnkr.co/)、[Codepen](https://codepen.io)、またはその他のオンラインコードエディタで迅速にテストするために、CDN から含めることができます! -/* Basic CSS for apps built with Ionic */ -import '@ionic/vue/css/normalize.css'; -import '@ionic/vue/css/structure.css'; -import '@ionic/vue/css/typography.css'; +CDN からフレームワークにアクセスするには、 [jsdelivr](https://www.jsdelivr.com/) を使用することをお勧めします。最新バージョンを入手するためには HTML ファイルの `` 要素、もしくはオンラインコードエディタの呼び出しコードに、次のコードを追加します。 -/* Optional CSS utils that can be commented out */ -import '@ionic/vue/css/padding.css'; -import '@ionic/vue/css/float-elements.css'; -import '@ionic/vue/css/text-alignment.css'; -import '@ionic/vue/css/text-transformation.css'; -import '@ionic/vue/css/flex-utils.css'; -import '@ionic/vue/css/display.css'; +```html + + + ``` -ここからは、Ionic Framework での開発方法について、 [Ionic Vue Quickstart Guide](https://ionicframework.com/docs/vue/quickstart) でご紹介しています。 +これにより、フレームワークをインストールすることなく、Ionic Framework のすべてのコアコンポーネントを使用できます。CSS バンドルには、Ionic のすべての[グローバルスタイルシート](/docs/layout/global-stylesheets.md)が含まれます。 ## Ionicons CDN @@ -161,6 +127,4 @@ Ionicons はデフォルトで Ionic Framework に同梱されているので、 ``` -:::note -アイコンの使い方については [Ionicons usage](https://ionic.io/ionicons/usage) をご覧ください。 -::: +Ionicons の使用に関する詳細については、[Ionicons ドキュメント](https://ionic.io/ionicons/usage)をご覧ください。 diff --git a/docs/intro/vscode-extension.md b/docs/intro/vscode-extension.md index 2a4d3bddeac..7f16fec0145 100644 --- a/docs/intro/vscode-extension.md +++ b/docs/intro/vscode-extension.md @@ -1,30 +1,30 @@ --- -title: VS Code Extension +title: VS Code拡張機能 --- - VS Code Extension - + VS Code拡張機能 + -The [WebNative Visual Studio Code extension](https://marketplace.visualstudio.com/items?itemName=WebNative.webnative) is a community-maintained plugin that helps you perform common Ionic Framework development tasks without needing to remember CLI commands. +[WebNative Visual Studio Code 拡張機能](https://marketplace.visualstudio.com/items?itemName=WebNative.webnative)は、コミュニティがメンテナンスしているプラグインで、CLI コマンドを覚える必要なく、一般的な Ionic Framework 開発タスクを実行するのに役立ちます。 -If you have VS Code on this computer click Install below. You can also find the extension by searching for "WebNative". +このコンピューターに VS Code がインストールされている場合は、下の「インストール」をクリックしてください。「WebNative」を検索して拡張機能を見つけることもできます。 - + - + -## Additional Documentation +## 追加ドキュメント -Full documentation of the WebNative extension can be found at [webnative.dev](https://webnative.dev/introduction/getting-started/) covering topics like: +WebNative 拡張機能の完全なドキュメントは、[webnative.dev](https://webnative.dev/introduction/getting-started/)で見つけることができ、以下のようなトピックをカバーしています: -- Building, debugging and running your Ionic Framework application. -- Bundle analysis, dependency upgrades. -- Migration from Cordova. -- Changing native settings. -- Splash Screens & Icons. -- Developing without a Mac using the WebNative app. +- Ionic Framework アプリケーションのビルド、デバッグ、実行。 +- バンドル分析、依存関係のアップグレード。 +- Cordova からの移行。 +- ネイティブ設定の変更。 +- スプラッシュスクリーンとアイコン。 +- WebNative アプリを使用した Mac なしでの開発。 diff --git a/docs/javascript/overview.md b/docs/javascript/overview.md new file mode 100644 index 00000000000..46eabac81c3 --- /dev/null +++ b/docs/javascript/overview.md @@ -0,0 +1,77 @@ +--- +title: 'Ionic JavaScript Overview' +sidebar_label: Overview +--- + + + Ionic JavaScript Overview | JavaScript Version Support and Tooling + + + +import DocsCard from '@components/global/DocsCard'; +import DocsCards from '@components/global/DocsCards'; + +`@ionic/core` brings the full power of the Ionic Framework to JavaScript developers. It offers seamless integration with the JavaScript ecosystem, so you can build high-quality cross-platform apps using familiar JavaScript tools, components, and best practices. You also get access to Ionic's extensive UI library and native capabilities. + +## JavaScript Version Support + +Ionic Core supports the latest versions of JavaScript. For detailed information on supported JavaScript runtime versions, see the [Stencil Support Policy](https://stenciljs.com/docs/support-policy#javascript-runtime). + +## JavaScript Tooling + +Ionic Core works seamlessly with modern JavaScript tooling and build systems. You can use popular tools like Vite, Webpack, or Parcel to scaffold and build your apps. Ionic Core is designed to fit naturally into the JavaScript ecosystem, so you can use your favorite libraries for state management, testing, and more. + +## Native Tooling + +[Capacitor](https://capacitorjs.com) is the official cross-platform runtime for Ionic Core, enabling your apps to run natively on iOS, Android, and the web with a single codebase. + +## Installation + +Before you begin, make sure you have [Node.js](https://nodejs.org/) (which includes npm) installed on your machine. + +```shell-session +$ npm create vite@latest my-app -- --template vanilla + +$ cd my-app +$ npm install && npm install @ionic/core +$ npm run dev █ +``` + +## Resources + + + + +

Quickly set up your first Ionic JavaScript app and learn the basics of the framework and CLI.

+
+ + +

+ Learn more about JavaScript's core concepts, tools, and best practices from the official JavaScript documentation. +

+
+ + +

Discover how to handle routing and navigation in Ionic JavaScript apps using the Ionic Router.

+
+ + +

Explore Ionic's rich library of UI components for building beautiful apps.

+
+ + +

Learn how to customize the look and feel of your app with Ionic's powerful theming system.

+
+ + +

Explore how to access native device features and deploy your app to iOS, Android, and the web with Capacitor.

+
+ +
diff --git a/docs/javascript/quickstart.md b/docs/javascript/quickstart.md new file mode 100644 index 00000000000..7da5f0e77f3 --- /dev/null +++ b/docs/javascript/quickstart.md @@ -0,0 +1,508 @@ +--- +title: Ionic JavaScript Quickstart +sidebar_label: Quickstart +--- + + + Ionic JavaScript Quickstart: JavaScript Basics + + + +import DocsCard from '@components/global/DocsCard'; +import DocsCards from '@components/global/DocsCards'; + +Welcome! This guide will walk you through the basics of Ionic JavaScript development using Vite. You'll learn how to set up your development environment, create a simple project, explore the project structure, and understand how Ionic components work. This is perfect for getting familiar with Ionic JavaScript before building your first real app. + +If you're looking for a high-level overview of what Ionic JavaScript is and how it fits into the web development ecosystem, see the [Ionic JavaScript Overview](overview). + +## Prerequisites + +Before you begin, make sure you have Node.js and npm installed on your machine. +You can check by running: + +```shell +node -v +npm -v +``` + +If you don't have Node.js and npm, [download Node.js here](https://nodejs.org/en/download) (which includes npm). + +## Create a Project with Vite + +First, create a new Vite project with vanilla JavaScript: + +```shell +npm create vite@latest my-app -- --template vanilla + +cd my-app +``` + +Install the project dependencies and Ionic Core: + +```shell +npm install +npm install @ionic/core +``` + +After installation, start the development server: + +```shell +npm run dev +``` + +Open your browser and visit the URL shown in the console. + +## Explore the Project Structure + +Your new app's directory will look like this: + +```shell +├── index.html +└── src/ + ├── counter.js + ├── main.js + └── style.css +``` + +:::warning Delete files +The `counter.js` and `style.css` files can be deleted. We will not be using them. +::: + +:::info +All file paths in the examples below are relative to the project root directory. +::: + +Let's configure the project, initialize Ionic, and add components to create our app. + +## Configure Vite + +Install the `vite-plugin-static-copy` package: + +```shell +npm install vite-plugin-static-copy --save-dev +``` + +Add a `vite.config.js` file at the project root with the following: + +```js title="vite.config.js" +import { defineConfig } from 'vite'; +import { viteStaticCopy } from 'vite-plugin-static-copy'; + +export default defineConfig({ + optimizeDeps: { + exclude: ['@ionic/core'], + }, + build: { + rollupOptions: { + output: { + manualChunks: undefined, + }, + external: ['/ionic.esm.js'], + }, + }, + plugins: [ + viteStaticCopy({ + targets: [ + { + src: 'node_modules/@ionic/core/dist/ionic/*', + dest: '', + }, + ], + }), + ], +}); +``` + +This copies the necessary Ionic files that Capacitor will need to work with lazy loaded Ionic components. + +## Initialize Ionic + +Replace the contents of `main.js` with the following: + +```js title="src/main.js" +// Load Ionic +(async () => { + // Set the path to a variable to + // prevent Vite from analyzing in dev + const ionicPath = '/ionic.esm.js'; + await import(/* @vite-ignore */ ionicPath); +})(); + +// Core CSS required for Ionic components to work properly +import '@ionic/core/css/core.css'; + +// Basic CSS for apps built with Ionic +import '@ionic/core/css/normalize.css'; +import '@ionic/core/css/structure.css'; +import '@ionic/core/css/typography.css'; + +// Optional CSS utils that can be commented out +import '@ionic/core/css/padding.css'; +import '@ionic/core/css/float-elements.css'; +import '@ionic/core/css/text-alignment.css'; +import '@ionic/core/css/text-transformation.css'; +import '@ionic/core/css/flex-utils.css'; +import '@ionic/core/css/display.css'; +``` + +This initializes Ionic based on the environment and then imports all of the available CSS files. + +## Add the App Component + +Update your `index.html` to configure the metadata and use Ionic components: + +```html title="index.html" + + + + + + + my-app + + + + + + + + + + + + + +``` + +This sets up the root of your application, using Ionic's `ion-app`, `ion-router`, and `ion-router-outlet` components. The key change is replacing the default `
` with Ionic's routing and layout components. The router outlet is where your pages will be displayed. + +## View Routes + +Routes are defined in the `index.html` using `ion-route` components inside the `ion-router`: + +```html title="index.html" + + + + +``` + +When you visit the root URL (`/`), the `home-page` component will be loaded. When you visit the `/new` URL, the `new-page` component will be loaded. We will define these components next. + +## Add the Home Page + +Create a new directory called `pages` inside the `src` folder, then add a file called `HomePage.js` in that directory with the following content: + +```js title="src/pages/HomePage.js" +class HomePage extends HTMLElement { + connectedCallback() { + this.innerHTML = ` + + + Blank + + + +
+ Ready to create an app? +

+ Start with Ionic + UI Components +

+
+
+ `; + } +} + +customElements.define('home-page', HomePage); +``` + +This creates a custom element called `home-page` that contains the layout for your Home page. The page uses Ionic's layout components to create a header with a toolbar and scrollable content area. + +:::tip Learn More +For detailed information about Ionic layout components, see the [Header](/docs/api/header.md), [Toolbar](/docs/api/toolbar.md), [Title](/docs/api/title.md), and [Content](/docs/api/content.md) documentation. +::: + +Next, add a ` + + +``` + +At this point your browser should be displaying the Home page. + +![Screenshot of the Ionic Core Home page](/img/guides/quickstart/unstyled-home-page.png 'Ionic Core Home Component') + +## Add an Ionic Component + +You can enhance your Home page with more Ionic UI components. For example, add a [Button](/docs/api/button.md) to navigate to another page. Update the `HomePage` component in `HomePage.js`: + +```js title="src/pages/HomePage.js" +class HomePage extends HTMLElement { + connectedCallback() { + this.innerHTML = ` + + + Blank + + + +
+ Ready to create an app? +

+ Start with Ionic + UI Components +

+
+ + Navigate +
+ `; + } +} + +customElements.define('home-page', HomePage); +``` + +## Add a New Page + +Add a new file named `NewPage.js` to `src/pages` with the following content: + +```js title="src/pages/NewPage.js" +class NewPage extends HTMLElement { + connectedCallback() { + this.innerHTML = ` + + + + + + New + + + +

Welcome to the new page!

+
+ `; + } +} + +customElements.define('new-page', NewPage); +``` + +This creates a page with a [Back Button](/docs/api/back-button.md) in the [Toolbar](/docs/api/toolbar.md). The back button will automatically handle navigation back to the previous page, or to `/` if there is no history. + +Next, update the ` +``` + +## Navigate to the New Page + +To navigate to the new page, update the button in `HomePage.js` to be inside of an `ion-router-link`: + +```html title="src/pages/HomePage.js" + + Navigate + +``` + +When the button is clicked, Ionic's router will automatically navigate to the `/new` route and display the `new-page` component. + +:::info +Navigating can also be performed programmatically using `document.querySelector('ion-router').push('/new')`. See the [Ionic Router documentation](/docs/api/router.md) for more information. +::: + +## Add Icons to the New Page + +Ionic JavaScript comes with [Ionicons](https://ionic.io/ionicons/) support. To use icons, you need to import them, register them with `addIcons`, and then use them with the `ion-icon` component. + +Add the necessary imports and register the icons in `main.js`: + +```js title="src/main.js" +// ...Ionic initialization + +// Icon imports +import { addIcons } from 'ionicons'; +import { heart, logoIonic } from 'ionicons/icons'; + +addIcons({ heart, logoIonic }); + +// ...CSS imports +``` + +Next, update `NewPage.js` to include the icons: + +```js title="src/pages/NewPage.js" +class NewPage extends HTMLElement { + connectedCallback() { + this.innerHTML = ` + + + + + + New + + + +

Welcome to the new page!

+ + + +
+ `; + } +} + +customElements.define('new-page', NewPage); +``` + +For more information, see the [Icon documentation](/docs/api/icon.md) and the [Ionicons documentation](https://ionic.io/ionicons/). + +## Call Component Methods + +Let's add a button that can scroll the content area to the bottom. Update `NewPage.js` to include scrollable content and a scroll button: + +```js title="src/pages/NewPage.js" +class NewPage extends HTMLElement { + connectedCallback() { + this.innerHTML = ` + + + + + + New + + + +

Welcome to the new page!

+ + + + + Scroll to Bottom + + +
+
+ `; + + // Generate items and add scroll functionality after the element is connected + this.setupScrolling(); + } + + setupScrolling() { + // Wait for ion-content to be ready + customElements.whenDefined('ion-content').then(() => { + // Generate items + const itemList = this.querySelector('#item-list'); + for (let i = 1; i <= 50; i++) { + const item = document.createElement('ion-item'); + const label = document.createElement('ion-label'); + label.textContent = `Item ${i}`; + item.appendChild(label); + itemList.appendChild(item); + } + + // Add scroll functionality + const scrollBtn = this.querySelector('#scroll-btn'); + const content = this.querySelector('ion-content'); + + if (scrollBtn && content) { + scrollBtn.addEventListener('click', () => { + content.scrollToBottom(300); + }); + } + }); + } +} + +customElements.define('new-page', NewPage); +``` + +To call methods on Ionic components: + +1. Get a reference to the component element using `querySelector` +2. Call the method directly on the element + +You can find available methods for each component in the [Methods](/docs/api/content.md#methods) section of their API documentation. + +## Run on a Device + +Ionic's components work everywhere: on iOS, Android, and PWAs. To deploy to mobile, use [Capacitor](https://capacitorjs.com): + +```shell +npm install @capacitor/core @capacitor/cli @capacitor/ios @capacitor/android +npx cap init + +npm run build + +npx cap add ios +npx cap add android +``` + +Open the native projects in their IDEs: + +```shell +npx cap open ios +npx cap open android +``` + +See [Capacitor's Getting Started guide](https://capacitorjs.com/docs/getting-started/with-ionic) for more. + +## Framework Integrations + +Ionic Core also works with other frameworks and libraries that support custom elements, such as [Alpine.js](https://alpinejs.dev/), [Lit](https://lit.dev/), and [Svelte](https://svelte.dev/). However, when using Ionic Core with these libraries, you won't have the built-in form and routing capabilities that are tightly coupled with Ionic's official Angular, React, and Vue framework integrations, and will need to use their respective routing and form solutions instead. + +## Explore More + +This guide covered the basics of creating an Ionic JavaScript app with Vite, adding navigation, and introducing Capacitor for native builds. To dive deeper, check out: + + + + +

Learn advanced Vite configuration and optimization techniques for Ionic JavaScript apps.

+
+ + +

Learn more about JavaScript's core concepts, tools, and best practices from MDN Web Docs.

+
+ + +

Discover how to handle routing and navigation in Ionic JavaScript apps using the Ionic Router.

+
+ + +

Explore Ionic's rich library of UI components for building beautiful apps.

+
+ + +

Learn how to customize the look and feel of your app with Ionic's powerful theming system.

+
+ + +

Explore how to access native device features and deploy your app to iOS, Android, and the web with Capacitor.

+
+ +
diff --git a/docs/layout/css-utilities.md b/docs/layout/css-utilities.md index df0d71d3097..6a6948a08aa 100644 --- a/docs/layout/css-utilities.md +++ b/docs/layout/css-utilities.md @@ -6,14 +6,14 @@ title: CSSユーティリティ CSSユーティリティ: Classes for Text/Element Alignment or Modification Ionic Framework は、テキストの順番を入れ替えたり、要素の配置や padding や margin を修正する一連のユーティリティ属性を提供します。これは要素で使うことができます。 :::important -If your app was not started using an available Ionic Framework starter, the stylesheets listed in the [optional section of the global stylesheets](global-stylesheets.md#optional) will need to be included in order for these styles to work. +利用可能な Ionic Framework スターターを使用してアプリを開始しなかった場合、これらのスタイルを機能させるには、[グローバルスタイルシートのオプションセクション](global-stylesheets.md#optional)にリストされているスタイルシートを含める必要があります。 ::: ## テキストの修正 @@ -65,16 +65,16 @@ If your app was not started using an available Ionic Framework starter, the styl ``` -| Class | Style Rule | Description | -| ------------------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `.ion-text-left` | `text-align: left` | The inline contents are aligned to the left edge of the line box. | -| `.ion-text-right` | `text-align: right` | The inline contents are aligned to the right edge of the line box. | -| `.ion-text-start` | `text-align: start` | The same as `text-left` if direction is left-to-right and `text-right` if direction is right-to-left. | -| `.ion-text-end` | `text-align: end` | The same as `text-right` if direction is left-to-right and `text-left` if direction is right-to-left. | -| `.ion-text-center` | `text-align: center` | The inline contents are centered within the line box. | -| `.ion-text-justify` | `text-align: justify` | The inline contents are justified. Text should be spaced to line up its left and right edges to the left and right edges of the line box, except for the last line. | -| `.ion-text-wrap` | `white-space: normal` | Sequences of whitespace are collapsed. Newline characters in the source are handled as other whitespace. Breaks lines as necessary to fill line boxes. | -| `.ion-text-nowrap` | `white-space: nowrap` | Collapses whitespace as for `normal`, but suppresses line breaks (text wrapping) within text. | +| Class | Style Rule | 説明 | +| ------------------- | --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | +| `.ion-text-left` | `text-align: left` | インラインコンテンツは行ボックスの左端に揃えられます。 | +| `.ion-text-right` | `text-align: right` | インラインコンテンツは行ボックスの右端に揃えられます。 | +| `.ion-text-start` | `text-align: start` | 方向が左から右の場合は`text-left`と同じで、方向が右から左の場合は`text-right`と同じです。 | +| `.ion-text-end` | `text-align: end` | 方向が左から右の場合は`text-right`と同じで、方向が右から左の場合は`text-left`と同じです。 | +| `.ion-text-center` | `text-align: center` | インラインコンテンツは行ボックス内で中央揃えされます。 | +| `.ion-text-justify` | `text-align: justify` | インラインコンテンツは両端揃えされます。テキストは、最後の行を除いて、その左右の端を行ボックスの左右の端に揃えるように間隔を空ける必要があります。 | +| `.ion-text-wrap` | `white-space: normal` | 空白の連続は折りたたまれます。ソース内の改行文字は他の空白として処理されます。必要に応じて行を折り返して行ボックスを埋めます。 | +| `.ion-text-nowrap` | `white-space: nowrap` | `normal`と同様に空白を折りたたみますが、テキスト内の改行(テキストの折り返し)を抑制します。 | ### Text Transform @@ -103,11 +103,11 @@ If your app was not started using an available Ionic Framework starter, the styl ``` -| Class | Style Rule | Description | -| ---------------------- | ---------------------------- | ------------------------------------------------------------------ | -| `.ion-text-uppercase` | `text-transform: uppercase` | Forces all characters to be converted to uppercase. | -| `.ion-text-lowercase` | `text-transform: lowercase` | Forces all characters to be converted to lowercase. | -| `.ion-text-capitalize` | `text-transform: capitalize` | Forces the first letter of each word to be converted to uppercase. | +| Class | Style Rule | 説明 | +| ---------------------- | ---------------------------- | ---------------------------------------- | +| `.ion-text-uppercase` | `text-transform: uppercase` | すべての文字を大文字に変換します。 | +| `.ion-text-lowercase` | `text-transform: lowercase` | すべての文字を小文字に変換します。 | +| `.ion-text-capitalize` | `text-transform: capitalize` | 各単語の最初の文字を大文字に変換します。 | ### Responsive Text Classes @@ -115,19 +115,19 @@ If your app was not started using an available Ionic Framework starter, the styl 以下の表は、 `{modifier}` のデフォルトの挙動です。 `left`, `right`, `start`, `end`, `center`, `justify`, `wrap`, `nowrap`, `uppercase`, `lowercase`, `capitalize` は上記の通りです。 -| Class | Description | -| ------------------------- | ------------------------------------------------------------- | -| `.ion-text-{modifier}` | Applies the modifier to the element on all screen sizes. | -| `.ion-text-sm-{modifier}` | Applies the modifier to the element when `min-width: 576px`. | -| `.ion-text-md-{modifier}` | Applies the modifier to the element when `min-width: 768px`. | -| `.ion-text-lg-{modifier}` | Applies the modifier to the element when `min-width: 992px`. | -| `.ion-text-xl-{modifier}` | Applies the modifier to the element when `min-width: 1200px`. | +| Class | 説明 | +| ------------------------- | ----------------------------------------------------- | +| `.ion-text-{modifier}` | すべての画面サイズで要素に修飾子を適用します。 | +| `.ion-text-sm-{modifier}` | `min-width: 576px`のときに要素に修飾子を適用します。 | +| `.ion-text-md-{modifier}` | `min-width: 768px`のときに要素に修飾子を適用します。 | +| `.ion-text-lg-{modifier}` | `min-width: 992px`のときに要素に修飾子を適用します。 | +| `.ion-text-xl-{modifier}` | `min-width: 1200px`のときに要素に修飾子を適用します。 | ## 要素の配置 ### Float -The [float](https://developer.mozilla.org/en-US/docs/Web/CSS/float) CSS property specifies that an element should be placed along the left or right side of its container, where text and inline elements will wrap around it. This way, the element is taken from the normal flow of the web page, though still remaining a part of the flow, contrary to absolute positioning. +[float](https://developer.mozilla.org/en-US/docs/Web/CSS/float) CSS プロパティは、要素をコンテナの左側または右側に配置する必要があることを指定します。テキストとインライン要素はその周りに折り返されます。この方法により、要素は Web ページの通常のフローから取り出されますが、絶対配置とは異なり、フローの一部として残ります。 ```html @@ -165,12 +165,12 @@ The [float](https://developer.mozilla.org/en-US/docs/Web/CSS/float) CSS property ``` -| Class | Style Rule | Description | -| ------------------ | ------------------------------ | ------------------------------------------------------------------------------------------------------- | -| `.ion-float-left` | `float: left` | The element will float on the left side of its containing block. | -| `.ion-float-right` | `float: right` | The element will float on the right side of its containing block. | -| `.ion-float-start` | `float: left` / `float: right` | The same as `float-left` if direction is left-to-right and `float-right` if direction is right-to-left. | -| `.ion-float-end` | `float: left` / `float: right` | The same as `float-right` if direction is left-to-right and `float-left` if direction is right-to-left. | +| Class | Style Rule | 説明 | +| ------------------ | ------------------------------ | ------------------------------------------------------------------------------------------- | +| `.ion-float-left` | `float: left` | 要素は包含ブロックの左側にフロートします。 | +| `.ion-float-right` | `float: right` | 要素は包含ブロックの右側にフロートします。 | +| `.ion-float-start` | `float: left` / `float: right` | 方向が左から右の場合は`float-left`と同じで、方向が右から左の場合は`float-right`と同じです。 | +| `.ion-float-end` | `float: left` / `float: right` | 方向が左から右の場合は`float-right`と同じで、方向が右から左の場合は`float-left`と同じです。 | ### レスポンシブな Float クラス @@ -178,65 +178,65 @@ The [float](https://developer.mozilla.org/en-US/docs/Web/CSS/float) CSS property 次の表に、デフォルトの動作を示します。 `{modifier}` は、前述のように `left`, `right`, `start`, `end` のいずれかです。 -| Class | Description | -| -------------------------- | ------------------------------------------------------------- | -| `.ion-float-{modifier}` | Applies the modifier to the element on all screen sizes. | -| `.ion-float-sm-{modifier}` | Applies the modifier to the element when `min-width: 576px`. | -| `.ion-float-md-{modifier}` | Applies the modifier to the element when `min-width: 768px`. | -| `.ion-float-lg-{modifier}` | Applies the modifier to the element when `min-width: 992px`. | -| `.ion-float-xl-{modifier}` | Applies the modifier to the element when `min-width: 1200px`. | +| Class | 説明 | +| -------------------------- | ----------------------------------------------------- | +| `.ion-float-{modifier}` | すべての画面サイズで要素に修飾子を適用します。 | +| `.ion-float-sm-{modifier}` | `min-width: 576px`のときに要素に修飾子を適用します。 | +| `.ion-float-md-{modifier}` | `min-width: 768px`のときに要素に修飾子を適用します。 | +| `.ion-float-lg-{modifier}` | `min-width: 992px`のときに要素に修飾子を適用します。 | +| `.ion-float-xl-{modifier}` | `min-width: 1200px`のときに要素に修飾子を適用します。 | ## 要素の表示 ### Display -The [display](https://developer.mozilla.org/en-US/docs/Web/CSS/display) CSS property sets whether an element is treated as a block or inline box and the layout used for its children, such as flow layout, grid or flex. It can also be used to completely hide an element from the layout. +[display](https://developer.mozilla.org/en-US/docs/Web/CSS/display) CSS プロパティは、要素をブロックまたはインラインボックスとして扱うかどうか、およびその子に使用されるレイアウト(フローレイアウト、グリッド、flex など)を設定します。レイアウトから要素を完全に非表示にするためにも使用できます。 -Ionic provides the following utility classes for `display`: +Ionic は`display`用に以下のユーティリティクラスを提供します: -| Class | Style Rule | Description | -| --------------------------- | ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------- | -| `.ion-display-none` | `display: none` | Turns off the display of an element so that it has no effect on layout (the document is rendered as though the element did not exist). | -| `.ion-display-inline` | `display: inline` | The element behaves as an inline element that does not create line breaks before or after itself. | -| `.ion-display-inline-block` | `display: inline-block` | The element behaves as a block element that flows with surrounding content as if it were a single inline box. | -| `.ion-display-block` | `display: block` | The element behaves as a block element, creating line breaks both before and after itself when in the normal flow. | -| `.ion-display-flex` | `display: flex` | The element behaves like a block element and lays out its content according to the flexbox model. | -| `.ion-display-inline-flex` | `display: inline-flex` | The element behaves like an inline element and lays out its content according to the flexbox model. | -| `.ion-display-grid` | `display: grid` | The element behaves like a block element and lays out its content according to the grid model. | -| `.ion-display-inline-grid` | `display: inline-grid` | The element behaves like an inline element and lays out its content according to the grid model. | -| `.ion-display-table` | `display: table` | The element behaves like an HTML `` element. It defines a block-level box. | -| `.ion-display-table-cell` | `display: table-cell` | The element behaves like an HTML `` element. | +| Class | Style Rule | 説明 | +| --------------------------- | ----------------------- | -------------------------------------------------------------------------------------------------------------------------------- | +| `.ion-display-none` | `display: none` | 要素の表示をオフにして、レイアウトに影響を与えないようにします(要素が存在しないかのようにドキュメントがレンダリングされます)。 | +| `.ion-display-inline` | `display: inline` | 要素はインライン要素として動作し、その前後に改行を作成しません。 | +| `.ion-display-inline-block` | `display: inline-block` | 要素はブロック要素として動作し、単一のインラインボックスであるかのように周囲のコンテンツと流れます。 | +| `.ion-display-block` | `display: block` | 要素はブロック要素として動作し、通常のフローではその前後に改行を作成します。 | +| `.ion-display-flex` | `display: flex` | 要素はブロック要素のように動作し、flexbox モデルに従ってコンテンツをレイアウトします。 | +| `.ion-display-inline-flex` | `display: inline-flex` | 要素はインライン要素のように動作し、flexbox モデルに従ってコンテンツをレイアウトします。 | +| `.ion-display-grid` | `display: grid` | 要素はブロック要素のように動作し、グリッドモデルに従ってコンテンツをレイアウトします。 | +| `.ion-display-inline-grid` | `display: inline-grid` | 要素はインライン要素のように動作し、グリッドモデルに従ってコンテンツをレイアウトします。 | +| `.ion-display-table` | `display: table` | 要素は HTML の`
` element. | -| `.ion-display-table-row` | `display: table-row` | The element behaves like an HTML `
`要素のように動作します。ブロックレベルのボックスを定義します。 | +| `.ion-display-table-cell` | `display: table-cell` | 要素は HTML の``要素のように動作します。 | -### Responsive Display Classes +### レスポンシブ Display クラス -All of the display classes listed above have additional classes to modify the display based on the screen size. Instead of `display-` in each class, use `display-{breakpoint}-` to only use the class on specific screen sizes, where `{breakpoint}` is one of the breakpoint names listed in [Ionic Breakpoints](#ionic-breakpoints). +上記のすべての display クラスには、画面サイズに基づいて display を変更する追加のクラスがあります。各クラスで`display-`の代わりに`display-{breakpoint}-`を使用して、特定の画面サイズでのみクラスを使用します。`{breakpoint}`は[Ionic Breakpoints](#ionic-breakpoints)にリストされているブレークポイント名の 1 つです。 -The table below shows the default behavior, where `{modifier}` is any of the following: `none`, `inline`, `inline-block`, `block`, `flex`, `inline-flex`, `grid`, `inline-grid`, `table`, `table-cell`, `table-row`, as they are described above. +以下の表は、デフォルトの動作を示しています。`{modifier}`は、上記で説明されているように、`none`、`inline`、`inline-block`、`block`、`flex`、`inline-flex`、`grid`、`inline-grid`、`table`、`table-cell`、`table-row`のいずれかです。 -| Class | Description | -| ---------------------------- | ------------------------------------------------------------- | -| `.ion-display-{modifier}` | Applies the modifier to the element on all screen sizes. | -| `.ion-display-sm-{modifier}` | Applies the modifier to the element when `min-width: 576px`. | -| `.ion-display-md-{modifier}` | Applies the modifier to the element when `min-width: 768px`. | -| `.ion-display-lg-{modifier}` | Applies the modifier to the element when `min-width: 992px`. | -| `.ion-display-xl-{modifier}` | Applies the modifier to the element when `min-width: 1200px`. | +| Class | 説明 | +| ---------------------------- | ----------------------------------------------------- | +| `.ion-display-{modifier}` | すべての画面サイズで要素に修飾子を適用します。 | +| `.ion-display-sm-{modifier}` | `min-width: 576px`のときに要素に修飾子を適用します。 | +| `.ion-display-md-{modifier}` | `min-width: 768px`のときに要素に修飾子を適用します。 | +| `.ion-display-lg-{modifier}` | `min-width: 992px`のときに要素に修飾子を適用します。 | +| `.ion-display-xl-{modifier}` | `min-width: 1200px`のときに要素に修飾子を適用します。 | -### Deprecated Classes +### 非推奨クラス -:::warning Deprecation Notice +:::warning 非推奨通知 -The following classes are deprecated and will be removed in the next major release. Use the recommended `.ion-display-*` classes instead. +以下のクラスは非推奨であり、次のメジャーリリースで削除されます。代わりに推奨される`.ion-display-*`クラスを使用してください。 ::: -| Class | Description | -| -------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `.ion-hide` | Applies `display: none` to the element on all screen sizes.
**Deprecated** — Use the `ion-display-none` class instead. | -| `.ion-hide-sm-{dir}` | Applies the modifier to the element when `min-width: 576px` (`up`) or `max-width: 576px` (`down`).
**Deprecated** — Use the `ion-display-sm-{modifier}` classes instead. | -| `.ion-hide-md-{dir}` | Applies the modifier to the element when `min-width: 768px` (`up`) or `max-width: 768px` (`down`).
**Deprecated** — Use the `ion-display-md-{modifier}` classes instead. | -| `.ion-hide-lg-{dir}` | Applies the modifier to the element when `min-width: 992px` (`up`) or `max-width: 992px` (`down`).
**Deprecated** — Use the `ion-display-lg-{modifier}` classes instead. | -| `.ion-hide-xl-{dir}` | Applies the modifier to the element when `min-width: 1200px` (`up`) or `max-width: 1200px` (`down`).
**Deprecated** — Use the `ion-display-xl-{modifier}` classes instead. | +| Class | 説明 | +| -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `.ion-hide` | すべての画面サイズで要素に`display: none`を適用します。
**非推奨** — 代わりに`ion-display-none`クラスを使用してください。 | +| `.ion-hide-sm-{dir}` | `min-width: 576px`(`up`)または`max-width: 576px`(`down`)のときに要素に修飾子を適用します。
**非推奨** — 代わりに`ion-display-sm-{modifier}`クラスを使用してください。 | +| `.ion-hide-md-{dir}` | `min-width: 768px`(`up`)または`max-width: 768px`(`down`)のときに要素に修飾子を適用します。
**非推奨** — 代わりに`ion-display-md-{modifier}`クラスを使用してください。 | +| `.ion-hide-lg-{dir}` | `min-width: 992px`(`up`)または`max-width: 992px`(`down`)のときに要素に修飾子を適用します。
**非推奨** — 代わりに`ion-display-lg-{modifier}`クラスを使用してください。 | +| `.ion-hide-xl-{dir}` | `min-width: 1200px`(`up`)または`max-width: 1200px`(`down`)のときに要素に修飾子を適用します。
**非推奨** — 代わりに`ion-display-xl-{modifier}`クラスを使用してください。 | ## コンテンツのスペース @@ -279,16 +279,16 @@ padding 属性は、要素の padding エリアを設定します。padding エ ``` -| Class | Style Rule | Description | +| Class | Style Rule | 説明 | | ------------------------- | ---------------------- | -------------------------------------- | -| `.ion-padding` | `padding: 16px` | Applies padding to all sides. | -| `.ion-padding-top` | `padding-top: 16px` | Applies padding to the top. | -| `.ion-padding-start` | `padding-start: 16px` | Applies padding to the start. | -| `.ion-padding-end` | `padding-end: 16px` | Applies padding to the end. | -| `.ion-padding-bottom` | `padding-bottom: 16px` | Applies padding to the bottom. | -| `.ion-padding-vertical` | `padding: 16px 0` | Applies padding to the top and bottom. | -| `.ion-padding-horizontal` | `padding: 0 16px` | Applies padding to the left and right. | -| `.ion-no-padding` | `padding: 0` | Applies no padding to all sides. | +| `.ion-padding` | `padding: 16px` | すべての側にパディングを適用します。 | +| `.ion-padding-top` | `padding-top: 16px` | 上部にパディングを適用します。 | +| `.ion-padding-start` | `padding-start: 16px` | 開始側にパディングを適用します。 | +| `.ion-padding-end` | `padding-end: 16px` | 終了側にパディングを適用します。 | +| `.ion-padding-bottom` | `padding-bottom: 16px` | 下部にパディングを適用します。 | +| `.ion-padding-vertical` | `padding: 16px 0` | 上下にパディングを適用します。 | +| `.ion-padding-horizontal` | `padding: 0 16px` | 左右にパディングを適用します。 | +| `.ion-no-padding` | `padding: 0` | すべての側にパディングを適用しません。 | ### Margin @@ -329,109 +329,109 @@ Margin エリアは、隣り合う要素とのスペースを広げるために ``` -| Class | Style Rule | Description | -| ------------------------ | --------------------- | ------------------------------------- | -| `.ion-margin` | `margin: 16px` | Applies margin to all sides. | -| `.ion-margin-top` | `margin-top: 16px` | Applies margin to the top. | -| `.ion-margin-start` | `margin-start: 16px` | Applies margin to the left. | -| `.ion-margin-end` | `margin-end: 16px` | Applies margin to the right. | -| `.ion-margin-bottom` | `margin-bottom: 16px` | Applies margin to the bottom. | -| `.ion-margin-vertical` | `margin: 16px 0` | Applies margin to the top and bottom. | -| `.ion-margin-horizontal` | `margin: 0 16px` | Applies margin to the left and right. | -| `.ion-no-margin` | `margin: 0` | Applies no margin to all sides. | +| Class | Style Rule | 説明 | +| ------------------------ | --------------------- | ------------------------------------ | +| `.ion-margin` | `margin: 16px` | すべての側にマージンを適用します。 | +| `.ion-margin-top` | `margin-top: 16px` | 上部にマージンを適用します。 | +| `.ion-margin-start` | `margin-start: 16px` | 開始側にマージンを適用します。 | +| `.ion-margin-end` | `margin-end: 16px` | 終了側にマージンを適用します。 | +| `.ion-margin-bottom` | `margin-bottom: 16px` | 下部にマージンを適用します。 | +| `.ion-margin-vertical` | `margin: 16px 0` | 上下にマージンを適用します。 | +| `.ion-margin-horizontal` | `margin: 0 16px` | 左右にマージンを適用します。 | +| `.ion-no-margin` | `margin: 0` | すべての側にマージンを適用しません。 | -## Flex Container Properties +## Flex コンテナプロパティ -Flexbox properties are divided into two categories: **container properties** that control the layout of all flex items, and **item properties** that control individual flex items. See [Flex Item Properties](#flex-item-properties) for item-level alignment. +Flexbox プロパティは、すべての flex アイテムのレイアウトを制御する**コンテナプロパティ**と、個々の flex アイテムを制御する**アイテムプロパティ**の 2 つのカテゴリに分けられます。アイテムレベルの配置については、[Flex Item Properties](#flex-item-properties)を参照してください。 ### Align Items -The [align-items](https://developer.mozilla.org/en-US/docs/Web/CSS/align-items) CSS property sets the [align-self](#align-self) value on all direct children as a group. In flexbox, it controls the alignment of items on the cross axis. In grid layout, it controls the alignment of items on the block axis within their grid areas. +[align-items](https://developer.mozilla.org/en-US/docs/Web/CSS/align-items) CSS プロパティは、すべての直接の子要素をグループとして[align-self](#align-self)値を設定します。flexbox では、交差軸上のアイテムの配置を制御します。グリッドレイアウトでは、グリッド領域内のブロック軸上のアイテムの配置を制御します。 -Ionic provides the following utility classes for `align-items`: +Ionic は`align-items`用に以下のユーティリティクラスを提供します: -| Class | Style Rule | Description | -| --------------------------- | ------------------------- | ---------------------------------------------------- | -| `.ion-align-items-start` | `align-items: flex-start` | Items are packed toward the start on the cross axis. | -| `.ion-align-items-end` | `align-items: flex-end` | Items are packed toward the end on the cross axis. | -| `.ion-align-items-center` | `align-items: center` | Items are centered along the cross axis. | -| `.ion-align-items-baseline` | `align-items: baseline` | Items are aligned so that their baselines align. | -| `.ion-align-items-stretch` | `align-items: stretch` | Items are stretched to fill the container. | +| Class | Style Rule | 説明 | +| --------------------------- | ------------------------- | ------------------------------------------------ | +| `.ion-align-items-start` | `align-items: flex-start` | アイテムは交差軸の開始側に詰められます。 | +| `.ion-align-items-end` | `align-items: flex-end` | アイテムは交差軸の終了側に詰められます。 | +| `.ion-align-items-center` | `align-items: center` | アイテムは交差軸に沿って中央揃えされます。 | +| `.ion-align-items-baseline` | `align-items: baseline` | アイテムはベースラインが揃うように配置されます。 | +| `.ion-align-items-stretch` | `align-items: stretch` | アイテムはコンテナを埋めるように伸ばされます。 | ### Align Content -The [align-content](https://developer.mozilla.org/en-US/docs/Web/CSS/align-content) CSS property sets the distribution of space between and around content items along a flexbox's cross axis, or a grid or block-level element's block axis. +[align-content](https://developer.mozilla.org/en-US/docs/Web/CSS/align-content) CSS プロパティは、flexbox の交差軸、またはグリッドまたはブロックレベル要素のブロック軸に沿って、コンテンツアイテム間および周囲のスペースの分布を設定します。 -This property has no effect on single line flex containers (i.e., ones with `flex-wrap: nowrap`). +このプロパティは、単一行の flex コンテナ(つまり、`flex-wrap: nowrap`を持つもの)には影響しません。 -Ionic provides the following utility classes for `align-content`: +Ionic は`align-content`用に以下のユーティリティクラスを提供します: -| Class | Style Rule | Description | -| ---------------------------- | ------------------------------ | ---------------------------------------------------------- | -| `.ion-align-content-start` | `align-content: flex-start` | Lines are packed toward the start of the cross axis. | -| `.ion-align-content-end` | `align-content: flex-end` | Lines are packed toward the end of the cross axis. | -| `.ion-align-content-center` | `align-content: center` | Lines are centered along the cross axis. | -| `.ion-align-content-stretch` | `align-content: stretch` | Lines are stretched to fill the container. | -| `.ion-align-content-between` | `align-content: space-between` | Lines are evenly distributed on the cross axis. | -| `.ion-align-content-around` | `align-content: space-around` | Lines are evenly distributed with equal space around them. | +| Class | Style Rule | 説明 | +| ---------------------------- | ------------------------------ | ---------------------------------------------------- | +| `.ion-align-content-start` | `align-content: flex-start` | 行は交差軸の開始側に詰められます。 | +| `.ion-align-content-end` | `align-content: flex-end` | 行は交差軸の終了側に詰められます。 | +| `.ion-align-content-center` | `align-content: center` | 行は交差軸に沿って中央揃えされます。 | +| `.ion-align-content-stretch` | `align-content: stretch` | 行はコンテナを埋めるように伸ばされます。 | +| `.ion-align-content-between` | `align-content: space-between` | 行は交差軸上で均等に配置されます。 | +| `.ion-align-content-around` | `align-content: space-around` | 行は周囲に等しいスペースを持って均等に配置されます。 | ### Justify Content -The [justify-content](https://developer.mozilla.org/en-US/docs/Web/CSS/justify-content) CSS property defines how the browser distributes space between and around content items along the main axis of a flex container and the inline axis of grid and multi-column containers. +[justify-content](https://developer.mozilla.org/en-US/docs/Web/CSS/justify-content) CSS プロパティは、ブラウザが flex コンテナの主軸、およびグリッドとマルチカラムコンテナのインライン軸に沿って、コンテンツアイテム間および周囲のスペースをどのように分配するかを定義します。 -Ionic provides the following utility classes for `justify-content`: +Ionic は`justify-content`用に以下のユーティリティクラスを提供します: -| Class | Style Rule | Description | -| ------------------------------ | -------------------------------- | --------------------------------------------------------------------------- | -| `.ion-justify-content-start` | `justify-content: flex-start` | Items are packed toward the start on the main axis. | -| `.ion-justify-content-end` | `justify-content: flex-end` | Items are packed toward the end on the main axis. | -| `.ion-justify-content-center` | `justify-content: center` | Items are centered along the main axis. | -| `.ion-justify-content-around` | `justify-content: space-around` | Items are evenly distributed on the main axis with equal space around them. | -| `.ion-justify-content-between` | `justify-content: space-between` | Items are evenly distributed on the main axis. | -| `.ion-justify-content-evenly` | `justify-content: space-evenly` | Items are distributed so that the spacing between any two items is equal. | +| Class | Style Rule | 説明 | +| ------------------------------ | -------------------------------- | ----------------------------------------------------------------------------- | +| `.ion-justify-content-start` | `justify-content: flex-start` | アイテムは主軸の開始側に詰められます。 | +| `.ion-justify-content-end` | `justify-content: flex-end` | アイテムは主軸の終了側に詰められます。 | +| `.ion-justify-content-center` | `justify-content: center` | アイテムは主軸に沿って中央揃えされます。 | +| `.ion-justify-content-around` | `justify-content: space-around` | アイテムは主軸上で周囲に等しいスペースを持って均等に配置されます。 | +| `.ion-justify-content-between` | `justify-content: space-between` | アイテムは主軸上で均等に配置されます。 | +| `.ion-justify-content-evenly` | `justify-content: space-evenly` | アイテムは、任意の 2 つのアイテム間のスペースが等しくなるように配置されます。 | ### Flex Direction -The [flex-direction](https://developer.mozilla.org/en-US/docs/Web/CSS/flex-direction) CSS property sets how flex items are placed in the flex container defining the main axis and the direction (normal or reversed). +[flex-direction](https://developer.mozilla.org/en-US/docs/Web/CSS/flex-direction) CSS プロパティは、flex アイテムが flex コンテナ内にどのように配置されるかを設定し、主軸と方向(通常または逆)を定義します。 -Ionic provides the following utility classes for `flex-direction`: +Ionic は`flex-direction`用に以下のユーティリティクラスを提供します: -| Class | Style Rule | Description | -| -------------------------- | -------------------------------- | ----------------------------------------------------------------- | -| `.ion-flex-row` | `flex-direction: row` | Items are placed in the same direction as the text direction. | -| `.ion-flex-row-reverse` | `flex-direction: row-reverse` | Items are placed in the opposite direction as the text direction. | -| `.ion-flex-column` | `flex-direction: column` | Items are placed vertically. | -| `.ion-flex-column-reverse` | `flex-direction: column-reverse` | Items are placed vertically in reverse order. | +| Class | Style Rule | 説明 | +| -------------------------- | -------------------------------- | -------------------------------------------------- | +| `.ion-flex-row` | `flex-direction: row` | アイテムはテキストの方向と同じ方向に配置されます。 | +| `.ion-flex-row-reverse` | `flex-direction: row-reverse` | アイテムはテキストの方向と逆の方向に配置されます。 | +| `.ion-flex-column` | `flex-direction: column` | アイテムは垂直に配置されます。 | +| `.ion-flex-column-reverse` | `flex-direction: column-reverse` | アイテムは逆順で垂直に配置されます。 | ### Flex Wrap -The [flex-wrap](https://developer.mozilla.org/en-US/docs/Web/CSS/flex-wrap) CSS property sets whether flex items are forced onto one line or can wrap onto multiple lines. If wrapping is allowed, it sets the direction that lines are stacked. +[flex-wrap](https://developer.mozilla.org/en-US/docs/Web/CSS/flex-wrap) CSS プロパティは、flex アイテムが 1 行に強制されるか、複数行に折り返すことができるかを設定します。折り返しが許可されている場合、行が積み重ねられる方向を設定します。 -Ionic provides the following utility classes for `flex-wrap`: +Ionic は`flex-wrap`用に以下のユーティリティクラスを提供します: -| Class | Style Rule | Description | -| ------------------------ | ------------------------- | -------------------------------------------------------- | -| `.ion-flex-nowrap` | `flex-wrap: nowrap` | Items will all be on one line. | -| `.ion-flex-wrap` | `flex-wrap: wrap` | Items will wrap onto multiple lines, from top to bottom. | -| `.ion-flex-wrap-reverse` | `flex-wrap: wrap-reverse` | Items will wrap onto multiple lines, from bottom to top. | +| Class | Style Rule | 説明 | +| ------------------------ | ------------------------- | ------------------------------------------------------ | +| `.ion-flex-nowrap` | `flex-wrap: nowrap` | すべてのアイテムが 1 行になります。 | +| `.ion-flex-wrap` | `flex-wrap: wrap` | アイテムは複数行に折り返され、上から下へ配置されます。 | +| `.ion-flex-wrap-reverse` | `flex-wrap: wrap-reverse` | アイテムは複数行に折り返され、下から上へ配置されます。 | -### Responsive Flex Container Classes +### レスポンシブ Flex コンテナクラス -All of the flex container classes listed above have additional classes to modify the properties based on the screen size. Instead of the base class name, use `{property}-{breakpoint}-{modifier}` to only use the class on specific screen sizes, where `{breakpoint}` is one of the breakpoint names listed in [Ionic Breakpoints](#ionic-breakpoints). +上記のすべての flex コンテナクラスには、画面サイズに基づいてプロパティを変更する追加のクラスがあります。基本クラス名の代わりに、`{property}-{breakpoint}-{modifier}`を使用して、特定の画面サイズでのみクラスを使用します。`{breakpoint}`は[Ionic Breakpoints](#ionic-breakpoints)にリストされているブレークポイント名の 1 つです。 -The table below shows the default behavior, where `{property}` is one of the following: `justify-content`, `align-content`, `align-items`, `flex`, or `flex-wrap`, and `{modifier}` is the corresponding value as described above. +以下の表は、デフォルトの動作を示しています。`{property}`は次のいずれかです:`justify-content`、`align-content`、`align-items`、`flex`、または`flex-wrap`。`{modifier}`は上記で説明されている対応する値です。 | Class | Description | | ------------------------------- | ------------------------------------------------------------- | @@ -441,127 +441,127 @@ The table below shows the default behavior, where `{property}` is one of the fol | `.ion-{property}-lg-{modifier}` | Applies the modifier to the element when `min-width: 992px`. | | `.ion-{property}-xl-{modifier}` | Applies the modifier to the element when `min-width: 1200px`. | -### Deprecated Classes +### 非推奨クラス -:::warning Deprecation Notice +:::warning 非推奨通知 -The following classes are deprecated and will be removed in the next major release. Use the recommended `.ion-flex-*` classes instead. +以下のクラスは非推奨であり、次のメジャーリリースで削除されます。代わりに推奨される`.ion-flex-*`クラスを使用してください。 ::: -| Class | Description | -| ------------------- | -------------------------------------------------------------------------------------------------------------------- | -| `.ion-nowrap` | Items will all be on one line.
**Deprecated** — Use `.ion-flex-nowrap` instead. | -| `.ion-wrap` | Items will wrap onto multiple lines, from top to bottom.
**Deprecated** — Use `.ion-flex-wrap` instead. | -| `.ion-wrap-reverse` | Items will wrap onto multiple lines, from bottom to top.
**Deprecated** — Use `.ion-flex-wrap-reverse` instead. | +| Class | 説明 | +| ------------------- | ----------------------------------------------------------------------------------------------------------------------------- | +| `.ion-nowrap` | すべてのアイテムが 1 行になります。
**非推奨** — 代わりに`.ion-flex-nowrap`を使用してください。 | +| `.ion-wrap` | アイテムは複数行に折り返され、上から下へ配置されます。
**非推奨** — 代わりに`.ion-flex-wrap`を使用してください。 | +| `.ion-wrap-reverse` | アイテムは複数行に折り返され、下から上へ配置されます。
**非推奨** — 代わりに`.ion-flex-wrap-reverse`を使用してください。 | -## Flex Item Properties +## Flex アイテムプロパティ -Flex item properties control how individual flex items behave within their flex container. See also: [Flex Container Properties](#flex-container-properties) for container-level alignment. +Flex アイテムプロパティは、個々の flex アイテムが flex コンテナ内でどのように動作するかを制御します。コンテナレベルの配置については、[Flex Container Properties](#flex-container-properties)も参照してください。 ### Align Self -The [align-self](https://developer.mozilla.org/en-US/docs/Web/CSS/align-self) CSS property overrides a grid or flex item's align-items value. In grid, it aligns the item inside the grid area. In flexbox, it aligns the item on the cross axis. +[align-self](https://developer.mozilla.org/en-US/docs/Web/CSS/align-self) CSS プロパティは、グリッドまたは flex アイテムの align-items 値をオーバーライドします。グリッドでは、グリッド領域内でアイテムを配置します。flexbox では、交差軸上でアイテムを配置します。 -The property doesn't apply to block-level boxes, or to table cells. If a flexbox item's cross-axis margin is `auto`, then `align-self` is ignored. +このプロパティは、ブロックレベルのボックスやテーブルセルには適用されません。flexbox アイテムの交差軸マージンが`auto`の場合、`align-self`は無視されます。 -Ionic provides the following utility classes for `align-self`: +Ionic は`align-self`用に以下のユーティリティクラスを提供します: -| Class | Style Rule | Description | -| -------------------------- | ------------------------ | ---------------------------------------------------------------------- | -| `.ion-align-self-start` | `align-self: flex-start` | Item is packed toward the start on the cross axis. | -| `.ion-align-self-end` | `align-self: flex-end` | Item is packed toward the end on the cross axis. | -| `.ion-align-self-center` | `align-self: center` | Item is centered along the cross axis. | -| `.ion-align-self-baseline` | `align-self: baseline` | Item is aligned so that its baseline aligns with other item baselines. | -| `.ion-align-self-stretch` | `align-self: stretch` | Item is stretched to fill the container. | -| `.ion-align-self-auto` | `align-self: auto` | Item is positioned according to the parent's `align-items` value. | +| Class | Style Rule | 説明 | +| -------------------------- | ------------------------ | ---------------------------------------------------------------------------------- | +| `.ion-align-self-start` | `align-self: flex-start` | アイテムは交差軸の開始側に詰められます。 | +| `.ion-align-self-end` | `align-self: flex-end` | アイテムは交差軸の終了側に詰められます。 | +| `.ion-align-self-center` | `align-self: center` | アイテムは交差軸に沿って中央揃えされます。 | +| `.ion-align-self-baseline` | `align-self: baseline` | アイテムは、そのベースラインが他のアイテムのベースラインと揃うように配置されます。 | +| `.ion-align-self-stretch` | `align-self: stretch` | アイテムはコンテナを埋めるように伸ばされます。 | +| `.ion-align-self-auto` | `align-self: auto` | アイテムは親の`align-items`値に従って配置されます。 | ### Flex -The [flex](https://developer.mozilla.org/en-US/docs/Web/CSS/flex) CSS property is a shorthand property for `flex-grow`, `flex-shrink` and `flex-basis`. It sets how a flex item will grow or shrink to fit the space available in its flex container. +[flex](https://developer.mozilla.org/en-US/docs/Web/CSS/flex) CSS プロパティは、`flex-grow`、`flex-shrink`、`flex-basis`の短縮プロパティです。flex アイテムが flex コンテナ内で利用可能なスペースに合わせてどのように拡大または縮小するかを設定します。 -Ionic provides the following utility classes for `flex`: +Ionic は`flex`用に以下のユーティリティクラスを提供します: -| Class | Style Rule | Description | -| ------------------- | --------------- | ----------------------------------------------------------- | -| `.ion-flex-1` | `flex: 1` | Item grows and shrinks equally with other flex items. | -| `.ion-flex-auto` | `flex: auto` | Item grows and shrinks based on its content size. | -| `.ion-flex-initial` | `flex: initial` | Item shrinks to its minimum content size but does not grow. | -| `.ion-flex-none` | `flex: none` | Item does not grow or shrink. | +| Class | Style Rule | 説明 | +| ------------------- | --------------- | -------------------------------------------------------------- | +| `.ion-flex-1` | `flex: 1` | アイテムは他の flex アイテムと等しく拡大および縮小します。 | +| `.ion-flex-auto` | `flex: auto` | アイテムはそのコンテンツサイズに基づいて拡大および縮小します。 | +| `.ion-flex-initial` | `flex: initial` | アイテムは最小コンテンツサイズまで縮小しますが、拡大しません。 | +| `.ion-flex-none` | `flex: none` | アイテムは拡大も縮小もしません。 | ### Flex Grow -The [flex-grow](https://developer.mozilla.org/en-US/docs/Web/CSS/flex-grow) CSS property sets the flex grow factor, which specifies how much of the flex container's positive free space, if any, should be assigned to the flex item's main size. +[flex-grow](https://developer.mozilla.org/en-US/docs/Web/CSS/flex-grow) CSS プロパティは、flex 拡大係数を設定します。これは、flex コンテナの正の自由スペース(存在する場合)のうち、flex アイテムの主サイズに割り当てるべき量を指定します。 -Ionic provides the following utility classes for `flex-grow`: +Ionic は`flex-grow`用に以下のユーティリティクラスを提供します: -| Class | Style Rule | Description | -| ------------------ | -------------- | -------------------------------------------------- | -| `.ion-flex-grow-0` | `flex-grow: 0` | Item does not grow beyond its content size. | -| `.ion-flex-grow-1` | `flex-grow: 1` | Item grows to fill available space proportionally. | +| Class | Style Rule | 説明 | +| ------------------ | -------------- | -------------------------------------------------------------- | +| `.ion-flex-grow-0` | `flex-grow: 0` | アイテムはコンテンツサイズを超えて拡大しません。 | +| `.ion-flex-grow-1` | `flex-grow: 1` | アイテムは利用可能なスペースを比例して埋めるように拡大します。 | ### Flex Shrink -The [flex-shrink](https://developer.mozilla.org/en-US/docs/Web/CSS/flex-shrink) CSS property sets the flex shrink factor of a flex item. If the size of all flex items is larger than the flex container, the flex items can shrink to fit according to their `flex-shrink` value. Each flex line's negative free space is distributed between the line's flex items that have a `flex-shrink` value greater than `0`. +[flex-shrink](https://developer.mozilla.org/en-US/docs/Web/CSS/flex-shrink) CSS プロパティは、flex アイテムの flex 縮小係数を設定します。すべての flex アイテムのサイズが flex コンテナより大きい場合、flex アイテムは`flex-shrink`値に従って縮小して収まります。各 flex 行の負の自由スペースは、`flex-shrink`値が`0`より大きい行の flex アイテム間で分配されます。 -Ionic provides the following utility classes for `flex-shrink`: +Ionic は`flex-shrink`用に以下のユーティリティクラスを提供します: -| Class | Style Rule | Description | +| Class | Style Rule | 説明 | | -------------------- | ---------------- | -------------------------------------------------------- | -| `.ion-flex-shrink-0` | `flex-shrink: 0` | Item does not shrink below its content size. | -| `.ion-flex-shrink-1` | `flex-shrink: 1` | Item shrinks proportionally when container is too small. | +| `.ion-flex-shrink-0` | `flex-shrink: 0` | アイテムはコンテンツサイズを下回って縮小しません。 | +| `.ion-flex-shrink-1` | `flex-shrink: 1` | コンテナが小さすぎる場合、アイテムは比例して縮小します。 | ### Order -The [order](https://developer.mozilla.org/en-US/docs/Web/CSS/order) CSS property sets the order to lay out an item in a flex or grid container. Items in a container are sorted by ascending `order` value and then by their source code order. Items not given an explicit `order` value are assigned the default value of `0`. +[order](https://developer.mozilla.org/en-US/docs/Web/CSS/order) CSS プロパティは、flex またはグリッドコンテナ内でアイテムをレイアウトする順序を設定します。コンテナ内のアイテムは、昇順の`order`値で並べ替えられ、次にソースコードの順序で並べ替えられます。明示的な`order`値が指定されていないアイテムには、デフォルト値`0`が割り当てられます。 -Ionic provides the following utility classes for `order`: +Ionic は`order`用に以下のユーティリティクラスを提供します: -| Class | Style Rule | Description | -| ------------------ | ----------- | ----------------------------------------- | -| `.ion-order-first` | `order: -1` | Item appears first in the flex container. | -| `.ion-order-0` | `order: 0` | Item appears in its natural order. | -| `.ion-order-1` | `order: 1` | Item appears after items with order 0. | -| `.ion-order-2` | `order: 2` | Item appears after items with order 1. | -| `.ion-order-3` | `order: 3` | Item appears after items with order 2. | -| `.ion-order-4` | `order: 4` | Item appears after items with order 3. | -| `.ion-order-5` | `order: 5` | Item appears after items with order 4. | -| `.ion-order-6` | `order: 6` | Item appears after items with order 5. | -| `.ion-order-7` | `order: 7` | Item appears after items with order 6. | -| `.ion-order-8` | `order: 8` | Item appears after items with order 7. | -| `.ion-order-9` | `order: 9` | Item appears after items with order 8. | -| `.ion-order-10` | `order: 10` | Item appears after items with order 9. | -| `.ion-order-11` | `order: 11` | Item appears after items with order 10. | -| `.ion-order-12` | `order: 12` | Item appears after items with order 11. | -| `.ion-order-last` | `order: 13` | Item appears last in the flex container. | +| Class | Style Rule | 説明 | +| ------------------ | ----------- | -------------------------------------------------- | +| `.ion-order-first` | `order: -1` | アイテムは flex コンテナの最初に表示されます。 | +| `.ion-order-0` | `order: 0` | アイテムは自然な順序で表示されます。 | +| `.ion-order-1` | `order: 1` | アイテムは order 0 のアイテムの後に表示されます。 | +| `.ion-order-2` | `order: 2` | アイテムは order 1 のアイテムの後に表示されます。 | +| `.ion-order-3` | `order: 3` | アイテムは order 2 のアイテムの後に表示されます。 | +| `.ion-order-4` | `order: 4` | アイテムは order 3 のアイテムの後に表示されます。 | +| `.ion-order-5` | `order: 5` | アイテムは order 4 のアイテムの後に表示されます。 | +| `.ion-order-6` | `order: 6` | アイテムは order 5 のアイテムの後に表示されます。 | +| `.ion-order-7` | `order: 7` | アイテムは order 6 のアイテムの後に表示されます。 | +| `.ion-order-8` | `order: 8` | アイテムは order 7 のアイテムの後に表示されます。 | +| `.ion-order-9` | `order: 9` | アイテムは order 8 のアイテムの後に表示されます。 | +| `.ion-order-10` | `order: 10` | アイテムは order 9 のアイテムの後に表示されます。 | +| `.ion-order-11` | `order: 11` | アイテムは order 10 のアイテムの後に表示されます。 | +| `.ion-order-12` | `order: 12` | アイテムは order 11 のアイテムの後に表示されます。 | +| `.ion-order-last` | `order: 13` | アイテムは flex コンテナの最後に表示されます。 | -### Responsive Flex Item Classes +### レスポンシブ Flex アイテムクラス -All of the flex item classes listed above have additional classes to modify the properties based on the screen size. Instead of the base class name, use `{property}-{breakpoint}-{modifier}` to only use the class on specific screen sizes, where `{breakpoint}` is one of the breakpoint names listed in [Ionic Breakpoints](#ionic-breakpoints). +上記のすべての flex アイテムクラスには、画面サイズに基づいてプロパティを変更する追加のクラスがあります。基本クラス名の代わりに、`{property}-{breakpoint}-{modifier}`を使用して、特定の画面サイズでのみクラスを使用します。`{breakpoint}`は[Ionic Breakpoints](#ionic-breakpoints)にリストされているブレークポイント名の 1 つです。 -The table below shows the default behavior, where `{property}` is one of the following: `align-self`, `flex`, `flex-grow`, `flex-shrink`, or `order`, and `{modifier}` is the corresponding value as described above. +以下の表は、デフォルトの動作を示しています。`{property}`は次のいずれかです:`align-self`、`flex`、`flex-grow`、`flex-shrink`、または`order`。`{modifier}`は上記で説明されている対応する値です。 -| Class | Description | -| ------------------------------- | ------------------------------------------------------------- | -| `.ion-{property}-{modifier}` | Applies the modifier to the element on all screen sizes. | -| `.ion-{property}-sm-{modifier}` | Applies the modifier to the element when `min-width: 576px`. | -| `.ion-{property}-md-{modifier}` | Applies the modifier to the element when `min-width: 768px`. | -| `.ion-{property}-lg-{modifier}` | Applies the modifier to the element when `min-width: 992px`. | -| `.ion-{property}-xl-{modifier}` | Applies the modifier to the element when `min-width: 1200px`. | +| Class | 説明 | +| ------------------------------- | ----------------------------------------------------- | +| `.ion-{property}-{modifier}` | すべての画面サイズで要素に修飾子を適用します。 | +| `.ion-{property}-sm-{modifier}` | `min-width: 576px`のときに要素に修飾子を適用します。 | +| `.ion-{property}-md-{modifier}` | `min-width: 768px`のときに要素に修飾子を適用します。 | +| `.ion-{property}-lg-{modifier}` | `min-width: 992px`のときに要素に修飾子を適用します。 | +| `.ion-{property}-xl-{modifier}` | `min-width: 1200px`のときに要素に修飾子を適用します。 | -## Border Display +## ボーダー表示 -The `.ion-no-border` utility class can be used to remove borders from Ionic components. This class can be applied to the `ion-header` and `ion-footer` components. +`.ion-no-border`ユーティリティクラスは、Ionic コンポーネントからボーダーを削除するために使用できます。このクラスは`ion-header`と`ion-footer`コンポーネントに適用できます。 ```html @@ -577,9 +577,9 @@ The `.ion-no-border` utility class can be used to remove borders from Ionic comp ``` -| Class | Description | -| ---------------- | -------------------------------- | -| `.ion-no-border` | The element will have no border. | +| Class | 説明 | +| ---------------- | ---------------------------- | +| `.ion-no-border` | 要素にボーダーがありません。 | ## Ionic のブレイクポイント diff --git a/docs/layout/dynamic-font-scaling.md b/docs/layout/dynamic-font-scaling.md index 929868b59e3..1848cb11a47 100644 --- a/docs/layout/dynamic-font-scaling.md +++ b/docs/layout/dynamic-font-scaling.md @@ -1,31 +1,31 @@ -# Dynamic Font Scaling +# ダイナミックフォントスケーリング -Dynamic Font Scaling is a feature that allows users to choose the size of the text displayed on the screen. This helps users who need larger text for better readability, and it also accommodates users who can read smaller text. +ダイナミックフォントスケーリングは、ユーザーが画面上に表示されるテキストのサイズを選択できる機能です。これは、読みやすさのために大きなテキストが必要なユーザーを支援し、小さなテキストを読むことができるユーザーにも対応します。 -## Try It Out +## 試してみる :::tip -Be sure to try this on an Android, iOS, or iPadOS device. +Android、iOS、または iPadOS デバイスで試してください。 -If you are testing on Chrome for Android, make sure ["Accessibility Page Zoom"](#chrome-for-android) is enabled. +Android の Chrome でテストしている場合は、["Accessibility Page Zoom"](#chrome-for-android)が有効になっていることを確認してください。 ::: -Follow the [Changing the Font Size on a Device](#changing-the-font-size-on-a-device) guide to set your preferred font size, and watch the text in the demo below grow or shrink according to your preferences. +[デバイスでのフォントサイズの変更](#changing-the-font-size-on-a-device)ガイドに従って、好みのフォントサイズを設定し、以下のデモのテキストが設定に応じて拡大または縮小するのを確認してください。 import DynamicFontScaling from '@site/static/usage/v8/layout/dynamic-font-scaling/index.md'; -## Enabling Dynamic Font Scaling in Ionic +## Ionic でダイナミックフォントスケーリングを有効にする :::info -This feature is currently opt-in on iOS. However, it will be enabled by default starting in Ionic 8 at which point the following CSS will no longer be necessary. +この機能は現在、iOS ではオプトインです。ただし、Ionic 8 からデフォルトで有効になり、以下の CSS は不要になります。 ::: -Dynamic Font Scaling is already enabled by default on Android. Developers can enable it on iOS using the following steps: +ダイナミックフォントスケーリングは、Android ではデフォルトで既に有効になっています。開発者は、iOS で以下の手順を使用して有効にできます: -1. Ensure that the [typography.css](/docs/layout/global-stylesheets#typographycss) file is imported. -2. Add the following CSS to a global stylesheet: +1. [typography.css](/docs/layout/global-stylesheets#typographycss)ファイルがインポートされていることを確認します。 +2. グローバルスタイルシートに以下の CSS を追加します: ```css html { @@ -34,7 +34,7 @@ html { ``` :::note -Under the hood, Ionic sets the following CSS on iOS devices to enable Dynamic Font Scaling: +内部では、Ionic は iOS デバイスでダイナミックフォントスケーリングを有効にするために以下の CSS を設定します: ```css html { @@ -44,21 +44,21 @@ html { ::: -## Using Dynamic Font Scaling +## ダイナミックフォントスケーリングの使用 -### Enabling in an Application +### アプリケーションで有効にする -Dynamic Font Scaling is enabled by default as long as the [typography.css](/docs/layout/global-stylesheets#typographycss) file is imported. Importing this file will define the `--ion-dynamic-font` variable which will activate Dynamic Font Scaling. While not recommended, developers can opt-out of Dynamic Font Scaling by setting this variable to `initial` in their application code. +[typography.css](/docs/layout/global-stylesheets#typographycss)ファイルがインポートされている限り、ダイナミックフォントスケーリングはデフォルトで有効になっています。このファイルをインポートすると、`--ion-dynamic-font`変数が定義され、ダイナミックフォントスケーリングがアクティブになります。推奨されませんが、開発者はアプリケーションコードでこの変数を`initial`に設定することで、ダイナミックフォントスケーリングをオプトアウトできます。 -### Integrating Custom Components +### カスタムコンポーネントの統合 -Developers can configure their custom components to take advantage of Dynamic Font Scaling by converting any `font-size` declarations that use `px` units to use [rem units](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units#lengths) instead. An easy way to convert from `px` to `rem` is to divide the pixel font size by the default browser font size, which is typically `16px`. For example, if a component has a font size of `14px`, then this could be converted to `rem` by doing `14px / 16px = 0.875rem`. Also note that any Ionic components that have had their font sizes overridden should also be updated to use `rem` units. +開発者は、カスタムコンポーネントを設定して、`px`単位を使用する`font-size`宣言を[rem 単位](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units#lengths)を使用するように変換することで、ダイナミックフォントスケーリングを活用できます。`px`から`rem`に変換する簡単な方法は、ピクセルフォントサイズをデフォルトのブラウザフォントサイズ(通常は`16px`)で割ることです。たとえば、コンポーネントのフォントサイズが`14px`の場合、`14px / 16px = 0.875rem`として`rem`に変換できます。また、フォントサイズがオーバーライドされた Ionic コンポーネントも、`rem`単位を使用するように更新する必要があることに注意してください。 -One thing to keep in mind is that the dimensions of your components may need to change to accommodate the larger font sizes. For example, `width` and `height` properties may need to change to `min-width` and `min-height`, respectively. Developers should audit their applications for any CSS properties that use [length values](https://developer.mozilla.org/en-US/docs/Web/CSS/length) and make any applicable conversions from `px` to `rem`. We also recommend having long text wrap to the next line instead of truncating to keep large text readable. +考慮すべき点の 1 つは、コンポーネントの寸法が大きなフォントサイズに対応するために変更する必要がある場合があることです。たとえば、`width`と`height`プロパティをそれぞれ`min-width`と`min-height`に変更する必要がある場合があります。開発者は、[length 値](https://developer.mozilla.org/en-US/docs/Web/CSS/length)を使用する CSS プロパティについてアプリケーションを監査し、`px`から`rem`への適切な変換を行う必要があります。また、大きなテキストを読みやすく保つために、長いテキストを切り詰めるのではなく、次の行に折り返すことをお勧めします。 -### Custom Font Family +### カスタムフォントファミリー -We recommend using the default fonts in Ionic as they are designed to look good at any size and ensure consistency with other mobile apps. However, developers can use a custom font family with Dynamic Font Scaling via CSS: +Ionic のデフォルトフォントは、あらゆるサイズで見栄えが良く、他のモバイルアプリとの一貫性を確保するように設計されているため、使用することをお勧めします。ただし、開発者は CSS を使用してダイナミックフォントスケーリングでカスタムフォントファミリーを使用できます: ```css html { @@ -67,13 +67,13 @@ html { } ``` -### `em` units versus `rem` units +### `em`単位と`rem`単位 -Developers have two options for relative font sizes: [`em` and `rem`](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units#ems_and_rems). +開発者は、相対フォントサイズに 2 つのオプションがあります:[`em`と`rem`](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units#ems_and_rems)。 -`em` units set the font size of an element relative to the font size of its parent. +`em`単位は、要素のフォントサイズを親のフォントサイズを基準に設定します。 -In the following example, the computed font size of `.child` is `40px` because it is a child of `.parent` (`2em * 20px = 40px`). +次の例では、`.child`の計算されたフォントサイズは`40px`です。これは`.parent`の子であるためです(`2em * 20px = 40px`)。 ```css .parent { @@ -85,7 +85,7 @@ In the following example, the computed font size of `.child` is `40px` because i } ``` -However, the `em` unit has a compounding effect which can cause issues. In the following example, the second `.child` element has a computed font size of `80px` since the font sizes compound. +ただし、`em`単位には複合効果があり、問題を引き起こす可能性があります。次の例では、2 番目の`.child`要素の計算されたフォントサイズは`80px`です。フォントサイズが複合されるためです。 ```html
@@ -105,9 +105,9 @@ However, the `em` unit has a compounding effect which can cause issues. In the f
-Due to this compounding effect, we strongly recommend using `rem` units instead of `em` units when working with Dynamic Font Scaling. `rem` units set the font size of an element relative to the font size of the root element, which is typically ``. The default font size of the root element is typically `16px`. +この複合効果により、ダイナミックフォントスケーリングで作業する際は、`em`単位の代わりに`rem`単位を使用することを強くお勧めします。`rem`単位は、要素のフォントサイズをルート要素(通常は``)のフォントサイズを基準に設定します。ルート要素のデフォルトフォントサイズは通常`16px`です。 -In the following example, the computed font size of `.child` is `32px` because the font size is being computed relative to `html`, not `.parent`. +次の例では、`.child`の計算されたフォントサイズは`32px`です。フォントサイズが`.parent`ではなく`html`を基準に計算されるためです。 ```css .parent { @@ -119,27 +119,27 @@ In the following example, the computed font size of `.child` is `32px` because t } ``` -## How Dynamic Font Scaling works in Ionic +## Ionic でのダイナミックフォントスケーリングの仕組み -Ionic components that define font sizes and participate in Dynamic Font Scaling typically use [rem units](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units#lengths). This sizes the text in each component relative to the font size of the root element, which is usually the `html` element. This means that as the root element's font size changes, the text in all Ionic components scale in a consistent manner. This avoids the need to manually override each component's font size. Some elements inside of these components, such as icons, use `em` units instead so the elements are sized relative to the text, though the text itself is sized using `rem` units. +フォントサイズを定義し、ダイナミックフォントスケーリングに参加する Ionic コンポーネントは、通常[rem 単位](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units#lengths)を使用します。これにより、各コンポーネント内のテキストがルート要素(通常は`html`要素)のフォントサイズを基準にサイズ設定されます。これは、ルート要素のフォントサイズが変更されると、すべての Ionic コンポーネント内のテキストが一貫した方法でスケールすることを意味します。これにより、各コンポーネントのフォントサイズを手動でオーバーライドする必要がなくなります。これらのコンポーネント内の一部の要素(アイコンなど)は、要素をテキストを基準にサイズ設定するために`em`単位を使用しますが、テキスト自体は`rem`単位を使用してサイズ設定されます。 ### iOS -Dynamic Font Scaling in Ionic builds on top of an iOS feature called [Dynamic Type](https://developer.apple.com/documentation/uikit/uifont/scaling_fonts_automatically#overview). To do this, Ionic sets the [font](https://developer.mozilla.org/en-US/docs/Web/CSS/font) of the root element to an Apple-defined text style. For consistency, Ionic uses the [body](https://developer.apple.com/documentation/uikit/uifont/textstyle/1616682-body) text style. +Ionic のダイナミックフォントスケーリングは、[Dynamic Type](https://developer.apple.com/documentation/uikit/uifont/scaling_fonts_automatically#overview)と呼ばれる iOS 機能の上に構築されています。これを行うために、Ionic はルート要素の[font](https://developer.mozilla.org/en-US/docs/Web/CSS/font)を Apple 定義のテキストスタイルに設定します。一貫性のために、Ionic は[body](https://developer.apple.com/documentation/uikit/uifont/textstyle/1616682-body)テキストスタイルを使用します。 -Using the Apple-defined text style enables Dynamic Type, allowing all text in Ionic components to scale according to the system-level preference. Note that these Apple-defined fonts only work on Apple devices. As a result, these fonts will not work on Android devices even if your app is using `ios` mode. +Apple 定義のテキストスタイルを使用すると、Dynamic Type が有効になり、Ionic コンポーネント内のすべてのテキストがシステムレベルの設定に従ってスケールします。これらの Apple 定義フォントは Apple デバイスでのみ機能することに注意してください。その結果、アプリが`ios`モードを使用している場合でも、これらのフォントは Android デバイスでは機能しません。 -Ionic follows [Apple's Human Interface Guidelines for Typography](https://developer.apple.com/design/human-interface-guidelines/typography) when an app is in `ios` mode. As a result, important content is prioritized when the text size changes. This means a few things: +Ionic は、アプリが`ios`モードの場合、[Apple の Human Interface Guidelines for Typography](https://developer.apple.com/design/human-interface-guidelines/typography)に従います。その結果、テキストサイズが変更されると、重要なコンテンツが優先されます。これは、いくつかのことを意味します: -1. Content in an `ion-header` or an `ion-footer` will have maximum font sizes to prioritize content in `ion-content` which is deemed more important than content in the `ion-header` and `ion-footer`. -2. Components such as `ion-badge` and `ion-back-button` will have minimum font sizes so they remain readable. -3. Text in components such as `ion-tab-bar` and `ion-picker` do not participate in Dynamic Font Scaling according to Apple's Human Interface Guidelines. +1. `ion-header`または`ion-footer`内のコンテンツには最大フォントサイズが設定され、`ion-header`と`ion-footer`内のコンテンツよりも重要と見なされる`ion-content`内のコンテンツが優先されます。 +2. `ion-badge`や`ion-back-button`などのコンポーネントには最小フォントサイズが設定され、読みやすさが保たれます。 +3. `ion-tab-bar`や`ion-picker`などのコンポーネント内のテキストは、Apple の Human Interface Guidelines に従ってダイナミックフォントスケーリングに参加しません。 ### Android Web View -The Android Web View's font scaling mechanism is always enabled in web content and will automatically scale font sizes defined using the `px` unit. This means that any maximum or minimum font sizes specified using `px` will still be scaled even if the final font size does not align with the maximum or minimum font sizes specified. +Android Web View のフォントスケーリングメカニズムは、Web コンテンツで常に有効になっており、`px`単位で定義されたフォントサイズを自動的にスケールします。これは、`px`を使用して指定された最大または最小フォントサイズは、最終的なフォントサイズが指定された最大または最小フォントサイズと一致しない場合でも、スケールされることを意味します。 -In the following example we are using the [min()](https://developer.mozilla.org/en-US/docs/Web/CSS/min) function to indicate that the font size of `.foo` should be no larger than `14px`. +次の例では、[min()](https://developer.mozilla.org/en-US/docs/Web/CSS/min)関数を使用して、`.foo`のフォントサイズが`14px`を超えないように指定しています。 ```css .foo { @@ -147,78 +147,78 @@ In the following example we are using the [min()](https://developer.mozilla.org/ } ``` -If the root element's default font size is `16px`, and the system-level font scale is `1.5` (i.e text sizes should be increased by 50%), then `1rem` will evaluate to `24px` because `16 * 1.5 = 24`. +ルート要素のデフォルトフォントサイズが`16px`で、システムレベルのフォントスケールが`1.5`(つまり、テキストサイズを 50%増やす)の場合、`1rem`は`16 * 1.5 = 24`であるため、`24px`と評価されます。 -This is larger than our defined maximum of `14px`, so one might assume that the evaluated font size of `.foo` is `14px`. However, since the Android Web View scales any font sizes defined using the `px` unit, this means the `14px` used in our `min()` function will also be scaled by 1.5. +これは定義された最大値`14px`より大きいため、`.foo`の評価されたフォントサイズは`14px`であると想定されるかもしれません。ただし、Android Web View は`px`単位で定義されたフォントサイズをスケールするため、`min()`関数で使用される`14px`も 1.5 倍にスケールされます。 -As a result, this means that the maximum computed font size is actually `21px` since `14 * 1.5 = 21` and therefore the overall computed font size of `.foo` is `21px`. +その結果、最大計算フォントサイズは実際には`14 * 1.5 = 21`であるため`21px`となり、したがって`.foo`の全体的な計算フォントサイズは`21px`です。 ### Chrome for Android -The Chrome Web Browser on Android behaves differently than the Android Web View. By default, Chrome for Android does not respect the system-level font scale setting. However, the Chromium team is working on a new feature to allow for this. When enabled, this feature will change the `zoom` level of the `html` element which will cause the layout to increase in size in addition to the text. +Android の Chrome Web Browser は、Android Web View とは異なる動作をします。デフォルトでは、Chrome for Android はシステムレベルのフォントスケール設定を尊重しません。ただし、Chromium チームはこれを可能にする新機能に取り組んでいます。有効にすると、この機能は`html`要素の`zoom`レベルを変更し、テキストに加えてレイアウトのサイズも増加させます。 -Developers can test this behavior by enabling the experimental "Accessibility Page Zoom" feature in `chrome://flags`. +開発者は、`chrome://flags`で実験的な「Accessibility Page Zoom」機能を有効にすることで、この動作をテストできます。 -See https://bugs.chromium.org/p/chromium/issues/detail?id=645717 for more information. +詳細については、https://bugs.chromium.org/p/chromium/issues/detail?id=645717を参照してください。 -### Using Modes on Different Platforms +### 異なるプラットフォームでのモードの使用 -Each platform has slightly different font scaling behaviors, and the `ios` and `md` modes have been implemented to take advantage of the scaling behaviors on their respective platforms. +各プラットフォームには、わずかに異なるフォントスケーリング動作があり、`ios`と`md`モードは、それぞれのプラットフォームでのスケーリング動作を活用するように実装されています。 -For example, `ios` mode makes use of maximum and minimum font sizes to follow [Apple's Human Interface Guidelines for Typography](https://developer.apple.com/design/human-interface-guidelines/typography). `md` mode does not implement this same behavior because Material Design does not have that same guidance. This means that using `md` mode on an iOS device may allow for very large font sizes in headers and footers. +たとえば、`ios`モードは、[Apple の Human Interface Guidelines for Typography](https://developer.apple.com/design/human-interface-guidelines/typography)に従うために最大および最小フォントサイズを利用します。`md`モードは、Material Design には同じガイダンスがないため、この同じ動作を実装していません。これは、iOS デバイスで`md`モードを使用すると、ヘッダーとフッターで非常に大きなフォントサイズが許可される可能性があることを意味します。 -As a result, we strongly recommend using `ios` mode on iOS devices and `md` mode on Android devices when using Dynamic Font Scaling. +その結果、ダイナミックフォントスケーリングを使用する場合は、iOS デバイスで`ios`モードを使用し、Android デバイスで`md`モードを使用することを強くお勧めします。 -## Changing the Font Size on a Device +## デバイスでのフォントサイズの変更 -Font scaling preferences are configured on a per-device basis by the user. This allows the user to scale the font for all applications that support this behavior. This guide shows how to enable font scaling for each platform. +フォントスケーリングの設定は、ユーザーがデバイスごとに設定します。これにより、ユーザーはこの動作をサポートするすべてのアプリケーションでフォントをスケールできます。このガイドでは、各プラットフォームでフォントスケーリングを有効にする方法を示します。 ### iOS -Font scaling on iOS can be configured in the Settings app. +iOS でのフォントスケーリングは、設定アプリで設定できます。 -See [Apple Support](https://support.apple.com/en-us/102453) for more information. +詳細については、[Apple Support](https://support.apple.com/en-us/102453)を参照してください。 ### Android -Where users access the font scaling configuration varies across devices, but it is typically found in the "Accessibility" page in the Settings app. +ユーザーがフォントスケーリング設定にアクセスする場所はデバイスによって異なりますが、通常は設定アプリの「アクセシビリティ」ページにあります。 :::info -The Chrome Web Browser on Android has some limitations with respecting system-level font scales. See [Chrome for Android](#chrome-for-android) for more information. +Android の Chrome Web Browser には、システムレベルのフォントスケールを尊重する際にいくつかの制限があります。詳細については、[Chrome for Android](#chrome-for-android)を参照してください。 ::: -## Troubleshooting +## トラブルシューティング -### Dynamic Font Scaling is not working +### ダイナミックフォントスケーリングが機能しない -There are a number of reasons why Dynamic Font Scaling may not have any effect on an app. The following list, while not exhaustive, provides some things to check to debug why Dynamic Font Scaling is not working. +ダイナミックフォントスケーリングがアプリに影響を与えない理由はいくつかあります。以下のリストは網羅的ではありませんが、ダイナミックフォントスケーリングが機能しない理由をデバッグするために確認すべきいくつかのことを提供します。 -1. Verify that your version of Ionic supports Dynamic Font Scaling. Dynamic Font Scaling was added starting in Ionic v7.5. -2. Verify that the [typography.css](/docs/layout/global-stylesheets#typographycss) file has been imported. This file is required for Dynamic Font Scaling to work. -3. Verify that your code does not override the root element's default font size. Manually setting a font size on the root element will prevent Dynamic Font Scaling from working as intended. -4. Verify that your code does not override font sizes on Ionic components. Ionic components that set `font-size` rules will use `rem` units. However, if your app overrides that to use `px`, then that custom rule will need to be converted to use `rem`. See [Integrating Custom Components](#integrating-custom-components) for more information. -5. Verify "Accessibility Page Zoom" is enabled if using Chrome for Android. See [Chrome for Android](#chrome-for-android) for more information. +1. Ionic のバージョンがダイナミックフォントスケーリングをサポートしていることを確認してください。ダイナミックフォントスケーリングは、Ionic v7.5 から追加されました。 +2. [typography.css](/docs/layout/global-stylesheets#typographycss)ファイルがインポートされていることを確認してください。このファイルは、ダイナミックフォントスケーリングが機能するために必要です。 +3. コードがルート要素のデフォルトフォントサイズをオーバーライドしていないことを確認してください。ルート要素にフォントサイズを手動で設定すると、ダイナミックフォントスケーリングが意図したとおりに機能しなくなります。 +4. コードが Ionic コンポーネントのフォントサイズをオーバーライドしていないことを確認してください。`font-size`ルールを設定する Ionic コンポーネントは`rem`単位を使用します。ただし、アプリがそれを`px`を使用するようにオーバーライドしている場合、そのカスタムルールを`rem`を使用するように変換する必要があります。詳細については、[カスタムコンポーネントの統合](#integrating-custom-components)を参照してください。 +5. Chrome for Android を使用している場合は、「Accessibility Page Zoom」が有効になっていることを確認してください。詳細については、[Chrome for Android](#chrome-for-android)を参照してください。 -### Maximum and minimum font sizes are not being respected on Android +### Android で最大および最小フォントサイズが尊重されない -The Android Web View scales any font sizes defined using the `px` unit by the system-level font scale preference. This means that actual font sizes may be larger or smaller than the font sizes defined in [min()](https://developer.mozilla.org/en-US/docs/Web/CSS/min), [max()](https://developer.mozilla.org/en-US/docs/Web/CSS/max), or [clamp()](https://developer.mozilla.org/en-US/docs/Web/CSS/clamp). +Android Web View は、システムレベルのフォントスケール設定によって`px`単位で定義されたフォントサイズをスケールします。これは、実際のフォントサイズが[min()](https://developer.mozilla.org/en-US/docs/Web/CSS/min)、[max()](https://developer.mozilla.org/en-US/docs/Web/CSS/max)、または[clamp()](https://developer.mozilla.org/en-US/docs/Web/CSS/clamp)で定義されたフォントサイズより大きいか小さい可能性があることを意味します。 -See [how font scaling works on Android](#android) for more information. +詳細については、[Android でのフォントスケーリングの仕組み](#android)を参照してください。 -### Font sizes are larger/smaller even with Dynamic Font Scaling disabled +### ダイナミックフォントスケーリングが無効でもフォントサイズが大きい/小さい -Ionic components define font sizes using [rem units](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units#lengths) even when Dynamic Font Scaling is disabled. This sizes the text in each component relative to the font size of the root element, which is usually the `html` element. As a result, if the font size of `html` changes, the computed font size of all Ionic components will change too. +Ionic コンポーネントは、ダイナミックフォントスケーリングが無効になっている場合でも、[rem 単位](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units#lengths)を使用してフォントサイズを定義します。これにより、各コンポーネント内のテキストがルート要素(通常は`html`要素)のフォントサイズを基準にサイズ設定されます。その結果、`html`のフォントサイズが変更されると、すべての Ionic コンポーネントの計算されたフォントサイズも変更されます。 -### Scaled Ionic iOS component font sizes do not exactly match native iOS equivalents +### スケールされた Ionic iOS コンポーネントのフォントサイズがネイティブ iOS の同等物と完全に一致しない -Certain native iOS components such as the Action Sheet make use of private font scales that Ionic does not have access to. While we try to stay as close as possible to the native behavior, text in some components may render slightly larger or smaller than their native counterparts. +Action Sheet などの特定のネイティブ iOS コンポーネントは、Ionic がアクセスできないプライベートフォントスケールを使用します。ネイティブの動作にできるだけ近づけようとしていますが、一部のコンポーネントのテキストは、ネイティブの対応物よりわずかに大きくまたは小さくレンダリングされる場合があります。 -### The text size in my Ionic app on iOS changed when enabling Dynamic Font Scaling +### iOS で Ionic アプリのテキストサイズがダイナミックフォントスケーリングを有効にしたときに変更された -The root element's default font size is typically `16px`. However, Dynamic Font Scaling on iOS devices make use of the ["Body" text style](https://developer.apple.com/design/human-interface-guidelines/typography#Specifications) which has a default font size of `17px`. Since the text in Ionic components is scaled relative to the root element's font size, some text may get larger or smaller when Dynamic Font Scaling is enabled, even if the system-level text scale did not change. +ルート要素のデフォルトフォントサイズは通常`16px`です。ただし、iOS デバイスでのダイナミックフォントスケーリングは、デフォルトフォントサイズが`17px`の["Body"テキストスタイル](https://developer.apple.com/design/human-interface-guidelines/typography#Specifications)を利用します。Ionic コンポーネント内のテキストはルート要素のフォントサイズを基準にスケールされるため、システムレベルのテキストスケールが変更されていなくても、ダイナミックフォントスケーリングを有効にすると一部のテキストが大きくなったり小さくなったりする場合があります。 :::info -iOS provides a "Callout" text style which has a default font size of `16px`. However, this font style is currently not exposed to web content. See [the supported text styles in WebKit](https://webkit.org/blog/3709/using-the-system-font-in-web-content/) for more information. +iOS は、デフォルトフォントサイズが`16px`の"Callout"テキストスタイルを提供します。ただし、このフォントスタイルは現在、Web コンテンツに公開されていません。詳細については、[WebKit でサポートされているテキストスタイル](https://webkit.org/blog/3709/using-the-system-font-in-web-content/)を参照してください。 ::: # Dynamic Font Scaling diff --git a/docs/layout/global-stylesheets.md b/docs/layout/global-stylesheets.md index 36bf78d7193..63a379f91bc 100644 --- a/docs/layout/global-stylesheets.md +++ b/docs/layout/global-stylesheets.md @@ -6,7 +6,7 @@ title: グローバルスタイルシート グローバルスタイルシート: Styled CSS Component Options for Ionic Apps diff --git a/docs/layout/grid.md b/docs/layout/grid.md new file mode 100644 index 00000000000..cf3ca2f004b --- /dev/null +++ b/docs/layout/grid.md @@ -0,0 +1,512 @@ +--- +title: レスポンシブグリッド +--- + + + レスポンシブグリッドシステムとスクリーンサイズに応じたカルムレイアウト + + + +グリッドは、カスタムレイアウトを構築するための強力なモバイルファーストのフレックスボックスシステムです。グリッドは、[grid](../api/grid.md), [row(s)](../api/row.md), [column(s)](../api/col.md) という三つの単位で構成されています。列はその行を埋めるように拡張され、追加の列に合うようにサイズが変更されます。これは、画面サイズに応じて異なるブレイクポイントを持つ 12 列のレイアウトに基づいています。カラムの数は CSS を使ってカスタマイズすることができます。 + +## 仕組み + +```html + + + +
1 of 3
+
+ +
2 of 3
+
+ +
3 of 3
+
+
+
+``` + +- グリッドは、すべての行と列のためのコンテナとして機能します。グリッドはコンテナの幅いっぱいに表示されます。 + しかし、`fixed`属性を追加すると、スクリーンサイズごとの幅を指定することができます。 +- 行は、列を適切に並べるための水平方向のグループです。 +- コンテンツは列の中に配置されるべきで、列のみが行の直接の子となることができます。 +- `size-{breakpoint}` 属性は、1 行あたりデフォルトの 12 列のうち、使用する列の数を指定します。 + つまり、`size="4"` を指定すると、グリッドの 1/3、つまり 12 列のうち 4 列を占有することができます。 +- size に値を指定しないカラムは、自動的に同じ幅になります。例えば、`size-sm`を 4 つ指定すると、スモールブレイクポイント以上の幅は、それぞれ自動的に 25%になります。 +- カラムの幅はパーセンテージで設定されるため、常に流動的で、親要素からの相対的な大きさになります。 +- カラムは個々のカラムの間にパディングを持ちますが、パディングはグリッドとカラムから削除することができます。 + しかし、グリッドに `ion-no-padding` クラスを追加することで、グリッドとカラムからパディングを取り除くことができます。グリッドに適用できるその他のスタイルについては、[CSS ユーティリティ](css-utilities.md) を参照してください。 +- グリッドの階層は、レスポンシブ・ブレークポイントごとに、すべてのブレークポイント(特小)、小、中、大、特大の 5 段階あります。 +- グリッドの階層は最小幅を基準にしており、その階層とそれより大きな階層に適用されます。 + (例: `size-sm="4"` は、小型、中型、大型、特大のデバイスに適用されます)。 +- グリッドは CSS 変数で簡単にカスタマイズすることができます。グリッドのカスタマイズ](#customizing-the-grid)を参照してください。 + +### ライブでの実装例 + +Angular の場合は [こちら](https://stackblitz.com/edit/ionic-ng-basic-grid) 、React の場合は [こちら](https://stackblitz.com/edit/ionic-react-basic-grid) で、ライブでの実装例を見ることができます。 + +## グリッドの大きさ + +デフォルトでは、グリッドは 100%の幅を占めます。画面サイズに応じた幅を設定するには、 `fixed` 属性を追加します。各ブレークポイントにおけるグリッドの幅は、CSS 変数 `--ion-grid-width-{breakpoint}` で定義される。詳しくは、[グリッドのカスタマイズ](#customizing-the-grid) を参照してください。 + +| Name | Value | Description | +| ---- | ------ | ------------------------------------------------- | +| xs | 100% | Don't set the grid width for xs screens | +| sm | 540px | Set grid width to 540px when (min-width: 576px) | +| md | 720px | Set grid width to 720px when (min-width: 768px) | +| lg | 960px | Set grid width to 960px when (min-width: 992px) | +| xl | 1140px | Set grid width to 1140px when (min-width: 1200px) | + +### ライブでの実装例 + +Angular の場合は [こちら](https://stackblitz.com/edit/ionic-ng-fixed-width-grid) 、React の場合は [こちら](https://stackblitz.com/edit/ionic-react-fixed-width-grid) で、ライブの例を見ることができます。 + +## グリッドの属性 + +グリッドは、デフォルトでは画面の幅いっぱいに表示されます。これは、以下の属性を使って変更できます。 + +| Property | Description | +| -------- | ------------------------------------------------- | +| fixed | Set a max width based on the current screen size. | + +## デフォルトのブレークポイント + +デフォルトのブレークポイントは、以下の表で定義されています。現時点では、ブレイクポイントをカスタマイズすることはできません。カスタマイズできない理由については、 [Variables in Media Queries](../theming/advanced.md#variables-in-media-queries) を参照してください。 + +| Name | Value | Width Prefix | Offset Prefix | Push Prefix | Pull Prefix | Description | +| ---- | ------ | ------------ | ------------- | ----------- | ----------- | ------------------------------------ | +| xs | 0 | `size-` | `offset-` | `push-` | `pull-` | Set columns when (min-width: 0) | +| sm | 576px | `size-sm-` | `offset-sm-` | `push-sm-` | `pull-sm-` | Set columns when (min-width: 576px) | +| md | 768px | `size-md-` | `offset-md-` | `push-md-` | `pull-md-` | Set columns when (min-width: 768px) | +| lg | 992px | `size-lg-` | `offset-lg-` | `push-lg-` | `pull-lg-` | Set columns when (min-width: 992px) | +| xl | 1200px | `size-xl-` | `offset-xl-` | `push-xl-` | `pull-xl-` | Set columns when (min-width: 1200px) | + +## オートレイアウトカラム + +### 均等な幅 + +デフォルトでは、すべてのデバイスと画面サイズにおいて、カラムは行の中で同じ幅を占めます。 + +```html + + + +
1 of 2
+
+ +
2 of 2
+
+
+ + +
1 of 3
+
+ +
2 of 3
+
+ +
3 of 3
+
+
+
+``` + +### 1 列の幅を設定する + +1 つのカラムの幅を設定すると、他のカラムは自動的にその幅にリサイズされます。これは、あらかじめ定義されたグリッド属性を使って行うことができます。以下の例では、中央のカラムの幅に関係なく、他のカラムがリサイズされます。 + +```html + + + +
1 of 3
+
+ +
2 of 3 (wider)
+
+ +
3 of 3
+
+
+ + +
1 of 3
+
+ +
2 of 3 (wider)
+
+ +
3 of 3
+
+
+
+``` + +#### ライブでの実装例 + +Angular では [こちら](https://stackblitz.com/edit/ionic-ng-set-width-col) 、React では [こちら](https://stackblitz.com/edit/ionic-react-set-width-col) で、実例を見ることができます。 + +### 可変幅 + +`size-{breakpoint}` プロパティを `"auto"` に設定することで、カラムはそのコンテンツの自然な幅に基づいてサイズを変更することができます。これは、ピクセルでカラムの幅を設定する場合に非常に便利です。可変幅のカラムの隣のカラムは、行を埋めるようにリサイズされます。 + +```html + + + +
1 of 3
+
+ +
Variable width content
+
+ +
3 of 3
+
+
+ + +
1 of 4
+
+ +
2 of 4
+
+ +
+ +
+
+ +
4 of 4
+
+
+
+``` + +#### ライブでの実装例 + +Angular では [こちら](https://stackblitz.com/edit/ionic-ng-var-width-col) 、React では [こちら](https://stackblitz.com/edit/ionic-react-var-width-col) で、実例を見ることができます。 + +## レスポンシブ属性 + +### すべてのブレークポイント + +すべてのデバイスとスクリーンに対してカラムの幅をカスタマイズするには、`size` プロパティを設定します。このプロパティの値は、利用可能なカラムのうち、このカラムが占めるべきカラムの数を決定します。 + +```html + + + +
1 of 4
+
+ +
2 of 4
+
+ +
3 of 4
+
+ +
4 of 4
+
+
+
+``` + +### 積み上げから水平へ + +width 属性と breakpoint 属性の組み合わせで、超小型画面では積み上げ型、小型画面では水平型になるようなグリッドを作成することができます。 + +```html + + + +
1 of 4
+
+ +
2 of 4
+
+ +
3 of 4
+
+ +
4 of 4
+
+
+
+``` + +#### ライブでの実装例 + +Angular では [こちら](https://stackblitz.com/edit/ionic-ng-stacked-horizontal-grid) 、React では [こちら](https://stackblitz.com/edit/ionic-react-stacked-horizontal-grid) で実例を見ることができます。 + +##並び替え + +### カラムのオフセット + +offset` プロパティを追加することで、カラムを右に移動させることができます。このプロパティは、カラムの左側のマージンを指定したカラム数だけ増加させる。例えば、以下のグリッドでは、最後のカラムは 3 カラム分オフセットされ、3 カラムを占めることになります。 + +```html + + + +
1 of 2
+
+ +
2 of 2
+
+
+
+``` + +また、スクリーンのブレークポイントに基づいてオフセットを追加することもできます。以下は、`md`スクリーン以上では最後のカラムが 3 カラム分オフセットされるグリッドの例です。 + +```html + + + +
1 of 3
+
+ +
2 of 3
+
+ +
3 of 3
+
+
+
+``` + +#### ライブでの実装例 + +Angular では [こちら](https://stackblitz.com/edit/ionic-ng-offset-grid-cols) 、React では [こちら](https://stackblitz.com/edit/ionic-react-offset-grid-cols) で、実例を見ることができます。 + +### プッシュとプル + +`push` と `pull` というプロパティを追加することで、カラムの並び替えを行うことができます。これらのプロパティは、カラムの `left` と `right` を指定したカラム数だけ調整し、カラムの並び替えを簡単に行うことができます。例えば、以下のグリッドでは、`1 of 2`と記述されたカラムが実際には最後のカラムとなり、`2 of 2`が最初のカラムとなります。 + +```html + + + +
1 of 2
+
+ +
2 of 2
+
+
+
+``` + +また、画面のブレークポイントに基づいて Push と Pull を追加することができます。以下の例では、`3 of 3`のカラムの記述があるカラムは、実際には`md`画面以上の最初のカラムになります。 + +```html + + + +
1 of 3
+
+ +
2 of 3
+
+ +
3 of 3
+
+
+
+``` + +#### ライブでの実装例 + +Angular では [こちら](https://stackblitz.com/edit/ionic-ng-grid-push-pull) 、React では [こちら](https://stackblitz.com/edit/ionic-react-grid-push-pull) で実例を見ることができます。 + +## アライメント + +### 垂直方向のアラインメント + +行に異なるクラスを追加することで、すべての列を行の内側に垂直に整列させることができます。利用可能なクラスの一覧は、[css utilities](css-utilities.md#flex-container-properties) を参照してください。 + +```html + + + +
1 of 4
+
+ +
2 of 4
+
+ +
3 of 4
+
+ +
4 of 4 # # #
+
+
+ + + +
1 of 4
+
+ +
2 of 4
+
+ +
3 of 4
+
+ +
4 of 4 # # #
+
+
+ + + +
1 of 4
+
+ +
2 of 4
+
+ +
3 of 4
+
+ +
4 of 4 # # #
+
+
+
+``` + +カラムはまた、カラムに直接 alignment クラスを追加することによって、他のカラムと異なるように自分自身を配置することができます。利用可能なクラスの一覧は、[css utilities](css-utilities.md#flex-item-properties) を参照してください。 + +```html + + + +
1 of 4
+
+ +
2 of 4
+
+ +
3 of 4
+
+ +
4 of 4 # # #
+
+
+
+``` + +#### ライブでの実装例 + +Angular では [こちら](https://stackblitz.com/edit/ionic-ng-grid-vertical-align) 、React では [こちら](https://stackblitz.com/edit/ionic-react-grid-vertical-align) で、実例を見ることができます。 + +### 水平方向の整列 + +行に異なるクラスを追加することで、すべての列を行の内側に水平に揃えることができます。利用可能なクラスの一覧は、[css ユーティリティ](css-utilities.md#flex-container-properties) を参照してください。 + +```html + + + +
1 of 2
+
+ +
2 of 2
+
+
+ + + +
1 of 2
+
+ +
2 of 2
+
+
+ + + +
1 of 2
+
+ +
2 of 2
+
+
+ + + +
1 of 2
+
+ +
2 of 2
+
+
+ + + +
1 of 2
+
+ +
2 of 2
+
+
+
+``` + +#### ライブでの実装例 + +Angular では [こちら](https://stackblitz.com/edit/ionic-ng-grid-horizontal-align) 、React では [こちら](https://stackblitz.com/edit/ionic-react-grid-horizontal-align) で実例を見ることができます。 + +## グリッドのカスタマイズ + +組み込みの CSS 変数を使用すると、定義済みのグリッド属性をカスタマイズすることができます。パディングの値やカラムの数などを変更できます。 + +### 列の数 + +グリッドのカラム数は、CSS 変数 `--ion-grid-columns` で変更することができます。デフォルトでは 12 列ですが、これを任意の正の整数に変更し、個々の列の幅を計算するために使用することができます。 + +```css +--ion-grid-columns: 12; +``` + +### グリッドの Padding + +グリッドコンテナの Padding は、CSS 変数 `--ion-grid-padding` を使ってすべてのブレークポイントに対して設定することができます。個々のブレイクポイントを上書きするには、CSS 変数 `--ion-grid-padding-{breakpoint}` を使用します。 + +```css +--ion-grid-padding: 5px; + +--ion-grid-padding-xs: 5px; +--ion-grid-padding-sm: 5px; +--ion-grid-padding-md: 5px; +--ion-grid-padding-lg: 5px; +--ion-grid-padding-xl: 5px; +``` + +### Grid width + +固定グリッドの幅の値を画面サイズに応じてカスタマイズするには、各ブレークポイントごとに `--ion-grid-width-{breakpoint}` の値をオーバーライドします。 + +```css +--ion-grid-width-xs: 100%; +--ion-grid-width-sm: 540px; +--ion-grid-width-md: 720px; +--ion-grid-width-lg: 960px; +--ion-grid-width-xl: 1140px; +``` + +### Column Padding + +列の padding は `--ion-grid-column-padding` CSS 変数で全てのブレークポイントに対して設定することができます。個々のブレークポイントを上書きするには、CSS 変数 `--ion-grid-column-padding-{breakpoint}` を使用します。 + +```css +--ion-grid-column-padding: 5px; + +--ion-grid-column-padding-xs: 5px; +--ion-grid-column-padding-sm: 5px; +--ion-grid-column-padding-md: 5px; +--ion-grid-column-padding-lg: 5px; +--ion-grid-column-padding-xl: 5px; +``` diff --git a/docs/layout/structure.md b/docs/layout/structure.md index 16c3e0c313b..84d45e5e613 100644 --- a/docs/layout/structure.md +++ b/docs/layout/structure.md @@ -9,7 +9,7 @@ import DocsCards from '@components/global/DocsCards'; レイアウトの構成 | Structures for Content Layout on Ionic Apps diff --git a/docs/react/add-to-existing.md b/docs/react/add-to-existing.md new file mode 100644 index 00000000000..eee23e0f10c --- /dev/null +++ b/docs/react/add-to-existing.md @@ -0,0 +1,370 @@ +--- +title: Add to Existing React Project +sidebar_label: Add to Existing +--- + +import DocsCard from '@components/global/DocsCard'; +import DocsCards from '@components/global/DocsCards'; + + + Add Ionic React to Existing Project: Integration Guide + + + +This guide covers how to add Ionic React to an existing React project. If you're looking to start a new project from scratch, check out the [Ionic React Quickstart](/docs/react/quickstart.md) guide. For an overview of how Ionic React works with React, including version support and tooling, check out the [Ionic React Overview](/docs/react/overview.md). + +:::tip + +This guide uses TypeScript examples. If you're using JavaScript, the setup process is the same, but you'll use `.jsx` file extensions instead of `.tsx`. + +::: + +## Setup + +:::info + +This guide follows the structure of a React app created with Vite. If you started your React app using a different tool (such as Create React App), your file structure and setup may differ. + +::: + +Follow these steps to add Ionic React to your existing React project: + +#### 1. Install the Package + +```bash +npm install @ionic/react +``` + +#### 2. Configure Ionic React + +Update `src/App.tsx` to include `setupIonicReact` and import the required Ionic Framework stylesheets: + +```tsx title="src/App.tsx" +// ...existing imports... + +import { setupIonicReact } from '@ionic/react'; + +/* Core CSS required for Ionic components to work properly */ +import '@ionic/react/css/core.css'; + +/* Basic CSS for apps built with Ionic */ +import '@ionic/react/css/normalize.css'; +import '@ionic/react/css/structure.css'; +import '@ionic/react/css/typography.css'; + +setupIonicReact(); + +// ...existing app function and export... +``` + +`setupIonicReact` is a function that sets up the Ionic React components to work with your app. It is required to be called before using any of the Ionic React components. + +:::info + +While `core.css` is required, `normalize.css`, `structure.css`, and `typography.css` are recommended but not required. They normalize cross-browser differences, ensure proper scrolling behavior, and provide consistent typography and form styling. Without them, you may need to handle these concerns yourself. For more details, refer to [Global Stylesheets](/docs/layout/global-stylesheets.md). + +::: + +## Using Individual Components + +After completing the setup above, you can start using Ionic components in your existing React app. Here's an example of how to use them: + +Update `src/App.tsx` to the following: + +```tsx title="src/App.tsx" +import { IonButton, IonDatetime, setupIonicReact } from '@ionic/react'; +import './App.css'; + +/* Core CSS required for Ionic components to work properly */ +import '@ionic/react/css/core.css'; + +/* Basic CSS for apps built with Ionic */ +import '@ionic/react/css/normalize.css'; +import '@ionic/react/css/structure.css'; +import '@ionic/react/css/typography.css'; + +setupIonicReact(); + +const App: React.FC = () => ( + <> + Button + + +); + +export default App; +``` + +Visit the [components](/docs/components.md) page for all of the available Ionic components. + +:::tip + +If your existing React app imports a global stylesheet (such as `index.css`) in `src/main.tsx`, you may want to remove it or update any styles that conflict with Ionic Framework components. Ionic Framework includes its own CSS reset and normalization, which may conflict with existing global styles. + +::: + +## Using Ionic Pages + +If you want to use Ionic pages with full navigation and page transitions, follow these additional setup steps. + +#### 1. Add Additional Ionic Framework Stylesheets + +Update the imported stylesheets in `src/App.tsx`: + +```tsx title="src/App.tsx" +/* Core CSS required for Ionic components to work properly */ +import '@ionic/react/css/core.css'; + +/* Basic CSS for apps built with Ionic */ +import '@ionic/react/css/normalize.css'; +import '@ionic/react/css/structure.css'; +import '@ionic/react/css/typography.css'; + +/* Optional CSS utils that can be commented out */ +import '@ionic/react/css/padding.css'; +import '@ionic/react/css/float-elements.css'; +import '@ionic/react/css/text-alignment.css'; +import '@ionic/react/css/text-transformation.css'; +import '@ionic/react/css/flex-utils.css'; +import '@ionic/react/css/display.css'; +``` + +These stylesheets set up the overall page structure and provide [CSS utilities](/docs/layout/css-utilities.md) for faster development. Some stylesheets are optional. For details on which stylesheets are required, check out [Global Stylesheets](/docs/layout/global-stylesheets.md). + +#### 2. Set up Theming + +Create a `src/theme/variables.css` file with the following content: + +```css title="src/theme/variables.css" +/* For information on how to create your own theme, please refer to: +https://ionicframework.com/docs/theming/ */ +``` + +Then, import the file and the dark palette stylesheet in `src/App.tsx`: + +```tsx title="src/App.tsx" +// ...existing imports... + +// ...existing stylesheets... + +/** + * Ionic Dark Mode + * ----------------------------------------------------- + * For more info, please refer to: + * https://ionicframework.com/docs/theming/dark-mode + */ + +/* @import '@ionic/react/css/palettes/dark.always.css'; */ +/* @import '@ionic/react/css/palettes/dark.class.css'; */ +import '@ionic/react/css/palettes/dark.system.css'; + +/* Theme variables */ +import './theme/variables.css'; + +setupIonicReact(); + +// ...existing app function and export... +``` + +The `variables.css` file can be used to create custom Ionic Framework themes. The `dark.system.css` import enables [dark mode support](/docs/theming/dark-mode.md) for your Ionic app when the system is set to prefer a dark appearance. You can customize the theming behavior by uncommenting different dark palette imports or adding custom CSS variables to `theme/variables.css`. + +#### 3. Update the App Component + +Update `src/App.tsx` to the following: + +```tsx title="src/App.tsx" +import { IonApp, IonRouterOutlet, setupIonicReact } from '@ionic/react'; +import { IonReactRouter } from '@ionic/react-router'; + +/* Core CSS required for Ionic components to work properly */ +import '@ionic/react/css/core.css'; + +/* Basic CSS for apps built with Ionic */ +import '@ionic/react/css/normalize.css'; +import '@ionic/react/css/structure.css'; +import '@ionic/react/css/typography.css'; + +/* Optional CSS utils that can be commented out */ +import '@ionic/react/css/padding.css'; +import '@ionic/react/css/float-elements.css'; +import '@ionic/react/css/text-alignment.css'; +import '@ionic/react/css/text-transformation.css'; +import '@ionic/react/css/flex-utils.css'; +import '@ionic/react/css/display.css'; + +/** + * Ionic Dark Mode + * ----------------------------------------------------- + * For more info, please refer to: + * https://ionicframework.com/docs/theming/dark-mode + */ + +/* @import '@ionic/react/css/palettes/dark.always.css'; */ +/* @import '@ionic/react/css/palettes/dark.class.css'; */ +import '@ionic/react/css/palettes/dark.system.css'; + +/* Theme variables */ +import './theme/variables.css'; + +setupIonicReact(); + +const App = () => { + return ( + + + {/* Routes will be added here */} + + + ); +}; + +export default App; +``` + +#### 4. Create a Home Page + +Create a new file at `src/pages/Home.tsx` with the following: + +```tsx title="src/pages/Home.tsx" +import { IonContent, IonHeader, IonPage, IonTitle, IonToolbar } from '@ionic/react'; + +import './Home.css'; + +const Home = () => { + return ( + + + + Home + + + + + + + Home + + + +
+ Ready to create an app? +

+ Start with Ionic{' '} + + UI Components + +

+
+
+
+ ); +}; + +export default Home; +``` + +Then, create `src/pages/Home.css`: + +```css title="src/pages/Home.css" +#container { + text-align: center; + + position: absolute; + left: 0; + right: 0; + top: 50%; + transform: translateY(-50%); +} + +#container strong { + font-size: 20px; + line-height: 26px; +} + +#container p { + font-size: 16px; + line-height: 22px; + + color: #8c8c8c; + + margin: 0; +} + +#container a { + text-decoration: none; +} +``` + +#### 5. Set up Routing + +:::important + +Ionic React Router currently only supports React Router v5. You must install the following specific versions of the router packages to set up routing with Ionic React. + +::: + +Install the router packages: + +```bash +npm install @ionic/react-router react-router@5 react-router-dom@5 +npm install @types/react-router-dom --save-dev +``` + +Then, update `src/App.tsx` to add the routes for the Home page: + +```tsx title="src/App.tsx" +import { Redirect, Route } from 'react-router-dom'; +import { IonApp, IonRouterOutlet, setupIonicReact } from '@ionic/react'; +import { IonReactRouter } from '@ionic/react-router'; +import Home from './pages/Home'; + +// ...existing Ionic Framework stylesheet imports... + +setupIonicReact(); + +const App: React.FC = () => ( + + + + + + + + + + + + +); + +export default App; +``` + +You're all set! Your Ionic React app is now configured with full Ionic page support. Run `npm run dev` to start your development server and view your app. + +## Next Steps + +Now that you have Ionic React integrated into your project, check out: + + + + +

Discover how to handle routing and navigation in Ionic React apps using the React Router.

+
+ + +

Explore Ionic's rich library of UI components for building beautiful apps.

+
+ + +

Learn how to customize the look and feel of your app with Ionic's powerful theming system.

+
+ + +

Explore how to access native device features and deploy your app to iOS, Android, and the web with Capacitor.

+
+ +
diff --git a/docs/react/adding-ionic-react-to-an-existing-react-project.md b/docs/react/adding-ionic-react-to-an-existing-react-project.md index 20bf7b3fcb7..7718b91147e 100644 --- a/docs/react/adding-ionic-react-to-an-existing-react-project.md +++ b/docs/react/adding-ionic-react-to-an-existing-react-project.md @@ -1,146 +1,6 @@ -# Adding To An Existing React App +--- +title: Add to Existing React Project +sidebar_label: Add to Existing +--- -This post has been forked from [Ely Lucas' blog post](https://dev.to/ionic/adding-ionic-react-to-an-existing-react-project-4kib) and updated to the latest version of Ionic. - -### Using Individual Ionic Components - -Ionic React has around 100 components that you can begin using in your app immediately to help make it more mobile-friendly. - -To get started with using components install the `@ionic/react` package: - -```bash -npm i @ionic/react -``` - -Import the stylesheets from Ionic in your main app file: - -```tsx title="App.tsx" -import '@ionic/react/css/core.css'; -``` - -Add the `setupIonicReact` function to your app: - -```tsx title="App.tsx" -import { setupIonicReact } from '@ionic/react'; - -setupIonicReact(); - -const App = () => { - return ( - ... - ); -} - -export default App; -``` - -:::note - -`setupIonicReact` is a function that will set up the Ionic React components to work with your app. It is required to be called before using any of the Ionic React components. - -::: - -You can import any of the components and begin to use them right away. Here we are importing the `IonButton` and `IonDatetime` components and using them anywhere in our app: - -```tsx -import React from 'react'; -import { IonButton, IonDatetime } from '@ionic/react'; - -const MyComponent = () => { - return ( - <> - - Start - - ); -}; -``` - -### Using Ionic Pages - -If you want to convert part of your app and give it the whole Ionic experience, there are a few additional steps to take to get this setup. - -First, import some additional CSS files that help set up the overall structure of the page and some utility helpers: - -```js -/* Basic CSS for apps built with Ionic */ -import '@ionic/react/css/normalize.css'; -import '@ionic/react/css/structure.css'; -import '@ionic/react/css/typography.css'; - -/* Optional CSS utils that can be commented out */ -import '@ionic/react/css/padding.css'; -import '@ionic/react/css/float-elements.css'; -import '@ionic/react/css/text-alignment.css'; -import '@ionic/react/css/text-transformation.css'; -import '@ionic/react/css/flex-utils.css'; -import '@ionic/react/css/display.css'; -``` - -If you are using another CSS framework (like Bootstrap), you might want to isolate the Ionic pages away from them. This will help to ensure there aren't any CSS conflicts between the libraries. - -Next, install the `@ionic/react-router` library: - -```bash -npm i @ionic/react-router -``` - -The Ionic React Router library is a small wrapper around the popular React Router library and helps provide the functionality we need for native-like page transitions. The Ionic React Router library is compatible with v5 of React Router. - -The main Ionic page will need a couple of base components. First, use a `IonApp` component (from `@ionic/react`) as the root component, and then use `IonReactRouter` (from `@ionic/react-router`). - -`IonApp` sets up our main container, with the necessary styling needed for our structural components. `IonReactRouter` is a small wrapper for React Routers `BrowserRouter` and should be used in its place. - -Then, wrap all your routes in an `IonRouterOutlet`, which is what manages our Ionic pages. - -```tsx -import { IonApp, IonRouterOutlet } from '@ionic/react'; -import { IonReactRouter } from '@ionic/react-router'; - -... - - - - - - - - - -``` - -Now you can setup Ionic pages like so: - -```tsx - - - - My Page - - - - - Start - - -``` - -:::note - -`IonPage` is important to have as the base component for your "Ionic" pages. `IonPage` is the element Ionic performs page transitions on. - -::: - -For more information on routing and navigation in Ionic React, see [here](/docs/react/navigation). - -### Customize the Theme - -To customize the look and feel of the components, Ionic has CSS variables you can [override](https://ionicframework.com/docs/theming/colors#modifying-colors) to provide a theme for your components. Set these in your main CSS file. - -For more info on theming your Ionic app, see the guide [here](/docs/theming/themes). - -### Wrapping up - -Adding Ionic React to an existing React project is fairly simple and can be done in just a few minutes. - -The great thing about using individual components from Ionic React is that you only import the component you need. This makes Ionic React ideal for adding it to existing projects that need to look and work great on mobile devices. +This page has moved. Go to [Add to Existing](/docs/react/add-to-existing). diff --git a/docs/react/quickstart.md b/docs/react/quickstart.md index d0242135d51..49fdaec1777 100644 --- a/docs/react/quickstart.md +++ b/docs/react/quickstart.md @@ -4,41 +4,41 @@ sidebar_label: Quickstart --- - Ionic React Quickstart Using Ionic CLI: React Basics + Ionic CLIを使用したIonic Reactクイックスタート: Reactの基本 import DocsCard from '@components/global/DocsCard'; import DocsCards from '@components/global/DocsCards'; -Welcome! This guide will walk you through the basics of Ionic React development. You'll learn how to set up your development environment, generate a simple project, explore the project structure, and understand how Ionic components work. This is perfect for getting familiar with Ionic React before building your first real app. +ようこそ!このガイドでは、Ionic React 開発の基本を説明します。開発環境のセットアップ、シンプルなプロジェクトの生成、プロジェクト構造の探索、Ionic コンポーネントの動作方法を学びます。最初の実際のアプリを構築する前に Ionic React に慣れるのに最適です。 -If you're looking for a high-level overview of what Ionic React is and how it fits into the React ecosystem, see the [Ionic React Overview](overview). +Ionic React とは何か、React エコシステムにどのように適合するかの高レベルの概要をお探しの場合は、[Ionic React の概要](overview)を参照してください。 -## Prerequisites +## 前提条件 -Before you begin, make sure you have Node.js and npm installed on your machine. -You can check by running: +始める前に、マシンに Node.js と npm がインストールされていることを確認してください。 +次を実行して確認できます: ```shell node -v npm -v ``` -If you don't have Node.js and npm, [download Node.js here](https://nodejs.org/en/download) (which includes npm). +Node.js と npm がない場合は、[こちらから Node.js をダウンロード](https://nodejs.org/en/download)してください(npm が含まれています)。 -## Create a Project with the Ionic CLI +## Ionic CLI でプロジェクトを作成 -First, install the latest [Ionic CLI](../cli): +まず、最新の[Ionic CLI](../cli)をインストールします: ```shell npm install -g @ionic/cli ``` -Then, run the following commands to create and run a new project: +次に、次のコマンドを実行して新しいプロジェクトを作成し、実行します: ```shell ionic start myApp blank --type react @@ -47,36 +47,37 @@ cd myApp ionic serve ``` -After running `ionic serve`, your project will open in the browser. +`ionic serve`を実行すると、プロジェクトがブラウザで開きます。 ![Screenshot of the Ionic React Home page](/img/guides/quickstart/home-page.png 'Ionic React Home Component') ## Explore the Project Structure -Your new app's `src` directory will look like this: +Your new app's directory will look like this: ```shell -├── App.tsx -├── components -│   ├── ExploreContainer.css -│   └── ExploreContainer.tsx -├── main.tsx -└── pages -    ├── Home.css -    └── Home.tsx +└── src/ + ├── App.tsx + ├── components + │ ├── ExploreContainer.css + │ └── ExploreContainer.tsx + ├── main.tsx + └── pages + ├── Home.css + └── Home.tsx ``` :::info -All file paths in the examples below are relative to the `src/` directory. +以下の例のすべてのファイルパスは、プロジェクトのルートディレクトリを基準にしています。 ::: -Let's walk through these files to understand the app's structure. +アプリの構造を理解するために、これらのファイルを見ていきましょう。 ## View the App Component The root of your app is defined in `App.tsx`: -```tsx +```tsx title="src/App.tsx" import { Redirect, Route } from 'react-router-dom'; import { IonApp, IonRouterOutlet, setupIonicReact } from '@ionic/react'; import { IonReactRouter } from '@ionic/react-router'; @@ -104,13 +105,13 @@ const App: React.FC = () => ( export default App; ``` -This sets up the root of your application, using Ionic's `IonApp` and `IonReactRouter` components. The `IonRouterOutlet` is where your pages will be displayed. +これにより、Ionic の`IonApp`と`IonReactRouter`コンポーネントを使用してアプリケーションのルートが設定されます。`IonRouterOutlet`は、ページが表示される場所です。 ## View Routes Routes are defined within the `IonRouterOutlet` in `App.tsx`: -```tsx +```tsx title="src/App.tsx" @@ -121,13 +122,13 @@ Routes are defined within the `IonRouterOutlet` in `App.tsx`: ``` -When you visit the root URL (`/`), the `Home` component will be loaded. +ルート URL(`/`)にアクセスすると、`Home`コンポーネントが読み込まれます。 ## View the Home Page -The Home page component, defined in `pages/Home.tsx`, imports the Ionic components and defines the page template: +The Home page component, defined in `Home.tsx`, imports the Ionic components and defines the page template: -```tsx +```tsx title="src/pages/Home.tsx" import { IonContent, IonHeader, IonPage, IonTitle, IonToolbar } from '@ionic/react'; import ExploreContainer from '../components/ExploreContainer'; import './Home.css'; @@ -155,17 +156,17 @@ const Home: React.FC = () => { export default Home; ``` -This creates a page with a header and scrollable content area. The `IonPage` component provides the basic page structure and must be used on every page. The second header shows a [collapsible large title](/docs/api/title#collapsible-large-titles) that displays when at the top of the content, then condenses to show the smaller title in the first header when scrolling down. +これにより、ヘッダーとスクロール可能なコンテンツ領域を持つページが作成されます。`IonPage`コンポーネントは基本的なページ構造を提供し、すべてのページで使用する必要があります。2 番目のヘッダーは、コンテンツの上部にあるときに表示される[折りたたみ可能な大きなタイトル](/docs/api/title.md#collapsible-large-titles)を示し、スクロールダウンすると最初のヘッダーの小さなタイトルを表示するために縮小されます。 -:::tip Learn More -For detailed information about Ionic layout components, see the [Header](/docs/api/header), [Toolbar](/docs/api/toolbar), [Title](/docs/api/title), and [Content](/docs/api/content) documentation. +:::tip 詳細情報 +Ionic レイアウトコンポーネントの詳細については、[Header](/docs/api/header.md)、[Toolbar](/docs/api/toolbar.md)、[Title](/docs/api/title.md)、[Content](/docs/api/content.md)のドキュメントを参照してください。 ::: -## Add an Ionic Component +## Ionic コンポーネントを追加 -You can enhance your Home page with more Ionic UI components. For example, import and add a [Button](/docs/api/button) at the end of the `IonContent` in `pages/Home.tsx`: +より多くの Ionic UI コンポーネントで Home ページを強化できます。たとえば、`Home.tsx`の`IonContent`の最後に[Button](/docs/api/button.md)をインポートして追加します: -```tsx +```tsx title="src/pages/Home.tsx" import { IonButton, IonContent, IonHeader, IonPage, IonTitle, IonToolbar } from '@ionic/react'; // ...existing imports... @@ -191,9 +192,9 @@ export default Home; ## Add a New Page -Create a new page at `pages/New.tsx`: +Create a new page at `New.tsx`: -```tsx +```tsx title="src/pages/New.tsx" import { IonBackButton, IonButtons, IonContent, IonHeader, IonPage, IonTitle, IonToolbar } from '@ionic/react'; const New: React.FC = () => { @@ -221,23 +222,23 @@ const New: React.FC = () => { export default New; ``` -This creates a page with a [Back Button](/docs/api/back-button) in the [Toolbar](/docs/api/toolbar). The back button will automatically handle navigation back to the previous page, or to `/` if there is no history. +これにより、[Toolbar](/docs/api/toolbar.md)に[Back Button](/docs/api/back-button.md)を持つページが作成されます。戻るボタンは、前のページへのナビゲーション、または履歴がない場合は`/`へのナビゲーションを自動的に処理します。 -:::warning Important -When creating your own pages, always use `IonPage` as the root component. This is essential for proper transitions between pages, base CSS styling that Ionic components depend on, and consistent layout behavior across your app. +:::warning +独自のページを作成する際は、常に`IonPage`をルートコンポーネントとして使用してください。これは、ページ間の適切な遷移、Ionic コンポーネントが依存する基本 CSS スタイリング、アプリ全体での一貫したレイアウト動作に不可欠です。 ::: ## Navigate to the New Page To navigate to the new page, create a route for it by first importing it at the top of `App.tsx` after the `Home` import: -```tsx +```tsx title="src/App.tsx" import New from './pages/New'; ``` Then, add its route in `IonRouterOutlet`: -```tsx +```tsx title="src/App.tsx" @@ -251,45 +252,45 @@ Then, add its route in `IonRouterOutlet`: ``` -Once that is done, update the button in `pages/Home.tsx`: +Once that is done, update the button in `Home.tsx`: -```tsx +```tsx title="src/pages/Home.tsx" Navigate ``` :::info -Navigating can also be performed programmatically using React Router's `history` prop. See the [React Navigation documentation](/docs/react/navigation#navigating-using-history) for more information. +React Router の`history`プロップを使用して、プログラム的にナビゲーションを実行することもできます。詳細については、[React Navigation ドキュメント](/docs/react/navigation.md#navigating-using-history)を参照してください。 ::: -## Add Icons to the New Page +## 新しいページにアイコンを追加 -Ionic React comes with [Ionicons](https://ionic.io/ionicons/) pre-installed. You can use any icon by setting the `icon` property of the `IonIcon` component. +Ionic React には[Ionicons](https://ionic.io/ionicons/)がプリインストールされています。`IonIcon`コンポーネントの`icon`プロパティを設定することで、任意のアイコンを使用できます。 -Update the imports in `pages/New.tsx` to import `IonIcon` and the `heart` and `logoIonic` icons: +`New.tsx`のインポートを更新して、`IonIcon`と`heart`および`logoIonic`アイコンをインポートします: -```tsx +```tsx title="src/pages/New.tsx" import { IonBackButton, IonButtons, IonContent, IonHeader, IonIcon, IonPage, IonTitle, IonToolbar } from '@ionic/react'; import { heart, logoIonic } from 'ionicons/icons'; ``` -Then, include them inside of the `IonContent`: +次に、それらを`IonContent`内に含めます: -```tsx +```tsx title="src/pages/New.tsx" ``` -Note that we are passing the imported SVG reference, **not** the icon name as a string. +インポートされた SVG 参照を渡していることに注意してください。文字列としてのアイコン名**ではありません**。 -For more information, see the [Icon documentation](/docs/api/icon) and the [Ionicons documentation](https://ionic.io/ionicons/). +詳細については、[Icon ドキュメント](/docs/api/icon.md)と[Ionicons ドキュメント](https://ionic.io/ionicons/)を参照してください。 -## Call Component Methods +## コンポーネントメソッドを呼び出す -Let's add a button that can scroll the content area to the bottom. +コンテンツ領域を下部にスクロールできるボタンを追加しましょう。 -Update `pages/New.tsx` to add a `ref` on `IonContent` and a button and some items after the existing icons: +Update `New.tsx` to add a `ref` on `IonContent` and a button and some items after the existing icons: -```tsx +```tsx title="src/pages/New.tsx" @@ -307,7 +308,7 @@ Update `pages/New.tsx` to add a `ref` on `IonContent` and a button and some item Then, add the imports for the additional components and define the `scrollToBottom` function: -```tsx +```tsx title="src/pages/New.tsx" import { useRef } from 'react'; import { IonButton, IonBackButton, IonButtons, IonContent, IonHeader, IonIcon, IonItem, IonLabel, IonPage, IonTitle, IonToolbar } from '@ionic/react'; import { heart, logoIonic } from 'ionicons/icons'; @@ -332,13 +333,13 @@ To call methods on Ionic components: 1. Create a `ref` for the component 2. Call the method directly on `ref.current` -This pattern is necessary because React refs store the component instance in the `.current` property. +このパターンは、React refs がコンポーネントインスタンスを`.current`プロパティに保存するために必要です。 -You can find available methods for each component in the [Methods](/docs/api/content#methods) section of their API documentation. +各コンポーネントの利用可能なメソッドは、API ドキュメントの[Methods](/docs/api/content.md#methods)セクションで見つけることができます。 -## Run on a Device +## デバイスで実行 -Ionic's components work everywhere: on iOS, Android, and PWAs. To deploy to mobile, use [Capacitor](https://capacitorjs.com): +Ionic のコンポーネントは、iOS、Android、PWA のどこでも動作します。モバイルにデプロイするには、[Capacitor](https://capacitorjs.com)を使用します: ```shell ionic build @@ -346,43 +347,45 @@ ionic cap add ios ionic cap add android ``` -Open the native projects in their IDEs: +ネイティブプロジェクトを IDE で開きます: ```shell ionic cap open ios ionic cap open android ``` -See [Capacitor's Getting Started guide](https://capacitorjs.com/docs/getting-started/with-ionic) for more. +詳細については、[Capacitor の Getting Started ガイド](https://capacitorjs.com/docs/getting-started/with-ionic)を参照してください。 -## Explore More +## さらに探索 -This guide covered the basics of creating an Ionic React app, adding navigation, and introducing Capacitor for native builds. To dive deeper, check out: +このガイドでは、Ionic React アプリの作成、ナビゲーションの追加、ネイティブビルド用の Capacitor の導入の基本をカバーしました。さらに深く掘り下げるには、以下を確認してください: - -

Build a real Photo Gallery app with Ionic React and native device features.

+ +

Ionic Reactとネイティブデバイス機能を使用して実際のPhoto Galleryアプリを構築します。

- -

Learn more about React's core concepts, tools, and best practices from the official React documentation.

+ +

公式Reactドキュメントから、Reactのコアコンセプト、ツール、ベストプラクティスについて詳しく学びます。

- -

Discover how to handle routing and navigation in Ionic React apps using the React Router.

+ +

React Routerを使用してIonic Reactアプリでルーティングとナビゲーションを処理する方法を発見します。

- -

Explore Ionic's rich library of UI components for building beautiful apps.

+ +

美しいアプリを構築するためのIonicの豊富なUIコンポーネントライブラリを探索します。

- -

Learn how to customize the look and feel of your app with Ionic's powerful theming system.

+ +

Ionicの強力なテーマ設定システムを使用してアプリの外観と操作性をカスタマイズする方法を学びます。

- -

Explore how to access native device features and deploy your app to iOS, Android, and the web with Capacitor.

+ +

+ Capacitorを使用してネイティブデバイス機能にアクセスし、アプリをiOS、Android、Webにデプロイする方法を探索します。 +

diff --git a/docs/react/your-first-app.md b/docs/react/your-first-app.md index 003077cc632..da309778604 100644 --- a/docs/react/your-first-app.md +++ b/docs/react/your-first-app.md @@ -4,10 +4,10 @@ sidebar_label: はじめてのアプリ --- - React Apps | Build Your First Ionic Framework React Application + Build Your First Ionic Mobile App with React | Ionic Capacitor Camera @@ -30,11 +30,11 @@ We'll create a Photo Gallery app that offers the ability to take photos with you Highlights include: -- One React-based codebase that runs on the web, iOS, and Android using Ionic Framework [UI components](https://ionicframework.com/docs/components). +- One React-based codebase that runs on the web, iOS, and Android using Ionic Framework [UI components](../components.md). - Deployed as a native iOS and Android mobile app using [Capacitor](https://capacitorjs.com), Ionic's official native app runtime. -- Photo Gallery functionality powered by the Capacitor [Camera](https://capacitorjs.com/docs/apis/camera), [Filesystem](https://capacitorjs.com/docs/apis/filesystem), and [Preferences](https://capacitorjs.com/docs/apis/preferences) APIs. +- Photo Gallery functionality powered by the Capacitor [Camera](../native/camera.md), [Filesystem](../native/filesystem.md), and [Preferences](../native/preferences.md) APIs. -Find the complete app code referenced in this guide [on GitHub](https://github.com/ionic-team/photo-gallery-capacitor-react). +Find the [complete app code](https://github.com/ionic-team/tutorial-photo-gallery-react) referenced in this guide on GitHub. ## Download Required Tools @@ -43,9 +43,8 @@ Download and install these right away to ensure an optimal Ionic development exp - **Node.js** for interacting with the Ionic ecosystem. [Download the LTS version here](https://nodejs.org/en/). - **A code editor** for... writing code! We are fans of [Visual Studio Code](https://code.visualstudio.com/). - **Command-line interface/terminal (CLI)**: - - **Windows** users: for the best Ionic experience, we recommend the built-in command line (cmd) or the Powershell - CLI, running in Administrator mode. - - **Mac/Linux** users, virtually any terminal will work. + - **Windows** users: for the best Ionic experience, we recommend the built-in command line (cmd) or the Powershell CLI, running in Administrator mode. + - **Mac/Linux** users: virtually any terminal will work. ## Install Ionic Tooling @@ -67,10 +66,10 @@ Consider setting up npm to operate globally without elevated permissions. See [R ## Create an App -Next, create an Ionic React app that uses the “Tabs” starter template and adds Capacitor for native functionality: +Next, create an Ionic React app that uses the "Tabs" starter template and adds Capacitor for native functionality: ```shell -ionic start photo-gallery tabs --type=react --capacitor +ionic start photo-gallery tabs --type=react ``` This starter project comes complete with three pre-built pages and best practices for Ionic development. With common building blocks already in place, we can add more features easily! @@ -89,7 +88,7 @@ npm install @capacitor/camera @capacitor/preferences @capacitor/filesystem ### PWA Elements -Some Capacitor plugins, including the Camera API, provide the web-based functionality and UI via the Ionic [PWA Elements library](https://github.com/ionic-team/pwa-elements). +Some Capacitor plugins, including the [Camera API](../native/camera.md), provide the web-based functionality and UI via the Ionic [PWA Elements library](https://github.com/ionic-team/pwa-elements). It's a separate dependency, so install it next: @@ -97,22 +96,32 @@ It's a separate dependency, so install it next: npm install @ionic/pwa-elements ``` -After installation, open up the project in your code editor of choice. - Next, import `@ionic/pwa-elements` by editing `src/main.tsx`. ```tsx +import React from 'react'; +import { createRoot } from 'react-dom/client'; +import App from './App'; +// CHANGE: Add the following import import { defineCustomElements } from '@ionic/pwa-elements/loader'; -// Call the element loader before the render call +// CHANGE: Call the element loader before the render call defineCustomElements(window); + +const container = document.getElementById('root'); +const root = createRoot(container!); +root.render( + + + +); ``` That’s it! Now for the fun part - let’s see the app in action. ## Run the App -Run this command in your shell: +Run this command next: ```shell ionic serve @@ -120,85 +129,171 @@ ionic serve And voilà! Your Ionic app is now running in a web browser. Most of your app can be built and tested right in the browser, greatly increasing development and testing speed. -## Photo Gallery!!! +## Photo Gallery -There are three tabs. Click on the Tab2 tab. It’s a blank canvas, aka the perfect spot to transform into a Photo Gallery. The Ionic CLI features Live Reload, so when you make changes and save them, the app is updated immediately! +There are three tabs. Click on the "Tab2" tab. It’s a blank canvas, aka the perfect spot to transform into a Photo Gallery. The Ionic CLI features Live Reload, so when you make changes and save them, the app is updated immediately! ![Animated GIF showing the live reload feature in an Ionic app, with changes in code immediately updating the app in a web browser.](/img/guides/react/first-app/live-reload.gif 'Live Reload Feature in Ionic App') Open `/src/pages/Tab2.tsx`. We see: +```tsx +import { IonContent, IonHeader, IonPage, IonTitle, IonToolbar } from '@ionic/react'; +import ExploreContainer from '../components/ExploreContainer'; +import './Tab2.css'; + +const Tab2: React.FC = () => { + return ( + + + + Tab 2 + + + + + + Tab 2 + + + + + + ); +}; + +export default Tab2; +``` + +`IonHeader` represents the top navigation and toolbar, with "Tab 2" as the title (there are two of them due to iOS [Collapsible Large Title](../api/title.md#collapsible-large-titles) support). Let’s rename both `IonTitle` elements to: + ```tsx - Tab 2 + {/* CHANGE: Update title */} + Photo Gallery - + + + {/* CHANGE: Update title */} + Photo Gallery + + + + {/* ...existing code... */} ``` -`IonHeader` represents the top navigation and toolbar, with "Tab 2" as the title. Let’s rename it: +We put the visual aspects of our app into ``. In this case, it’s where we’ll add a button that opens the device’s camera as well as displays the image captured by the camera. Start by adding a [floating action button](../api/fab.md) (FAB) to the bottom of the page and set the camera image as the icon. ```tsx -Photo Gallery +// CHANGE: Add the following import +import { camera } from 'ionicons/icons'; +// CHANGE: Update the following import +import { IonContent, IonHeader, IonPage, IonTitle, IonToolbar, IonFab, IonFabButton, IonIcon } from '@ionic/react'; +// CHANGE: Remove or comment out `ExploreContainer` +// import ExploreContainer from '../components/ExploreContainer'; +import './Tab2.css'; + +const Tab2: React.FC = () => { + return ( + + + + Photo Gallery + + + + + + Photo Gallery + + + + {/* CHANGE: Add the floating action button */} + + + + + + + {/* CHANGE: Remove or comment out `ExploreContainer` */} + {/* */} + + + ); +}; + +export default Tab2; ``` -We put the visual aspects of our app into ``. In this case, it’s where we’ll add a button that opens the device’s camera as well as displays the image captured by the camera. Start by adding a [floating action button](https://ionicframework.com/docs/api/fab) (FAB). First, update the imports at the top of the page to include the Camera icon as well as some of the Ionic components we'll use shortly: +Next, open `src/App.tsx`. Change the label to "Photos" and the `ellipse` icon to `images` for the middle tab button. ```tsx -import { camera, trash, close } from 'ionicons/icons'; +import { Redirect, Route } from 'react-router-dom'; import { - IonContent, - IonHeader, - IonPage, - IonTitle, - IonToolbar, - IonFab, - IonFabButton, + IonApp, IonIcon, - IonGrid, - IonRow, - IonCol, - IonImg, - IonActionSheet, + IonLabel, + IonRouterOutlet, + IonTabBar, + IonTabButton, + IonTabs, + setupIonicReact, } from '@ionic/react'; -``` - -Then, add the FAB to the bottom of the page. Use the camera image as the icon, and call the `takePhoto()` function when this button is clicked (to be implemented soon): - -```tsx - - - takePhoto()}> - - - - -``` - -We’ll be creating the `takePhoto` method and the logic to use the Camera and other native features in a moment. - -Next, open `src/App.tsx`, remove the `ellipse` icon from the import and import the `images` icon instead: - -```tsx +import { IonReactRouter } from '@ionic/react-router'; +// CHANGE: Update the following import import { images, square, triangle } from 'ionicons/icons'; +import Tab1 from './pages/Tab1'; +import Tab2 from './pages/Tab2'; +import Tab3 from './pages/Tab3'; + +/* ...existing Ionic styles... */ + +const App: React.FC = () => ( + + + + + + + + + + + + + + + + + + + + + + {/* CHANGE: Update icon */} + + + + + + + +); + +export default App; ``` -Within the tab bar (``), change the label to “Photos” and the `ellipse` icon to `images` for the middle tab button: - -```tsx - - - Photos - -``` - -:::note -In Ionic React, icons are imported individually from `ionicons/icons` and set to the icon prop. -::: - That’s just the start of all the cool things we can do with Ionic. Up next, implement camera taking functionality on the web, then build it for iOS and Android. diff --git a/docs/react/your-first-app/2-taking-photos.md b/docs/react/your-first-app/2-taking-photos.md index 016767f35f8..b1f3e1627ed 100644 --- a/docs/react/your-first-app/2-taking-photos.md +++ b/docs/react/your-first-app/2-taking-photos.md @@ -4,41 +4,30 @@ sidebar_label: カメラ撮影 --- - Take Photos From The Camera on React Apps - Ionic Documentation + Take Photos with Camera API for iOS, Android & Web with React | Ionic Capacitor Camera -Now for the fun part - adding the ability to take photos with the device’s camera using the Capacitor [Camera API](https://capacitorjs.com/docs/apis/camera). We’ll begin with building it for the web, then make some small tweaks to make it work on mobile (iOS and Android). +Now for the fun part - adding the ability to take photos with the device’s camera using the Capacitor [Camera API](../../native/camera.md). We’ll begin with building it for the web, then make some small tweaks to make it work on mobile (iOS and Android). -To do so, we will create our own custom React hook that will manage the photos for the gallery. +## Photo Gallery Hook -:::note -If you are not familiar with React Hooks, [Introducing React Hooks](https://react.dev/reference/react/hooks) from the official React docs is a good resource to start with. -::: +We will create a [custom React hook](https://react.dev/learn/reusing-logic-with-custom-hooks#extracting-your-own-custom-hook-from-a-component) to manage the photos for the gallery. Create a new file at `src/hooks/usePhotoGallery.ts` and open it up. -A custom hook is just a function that uses other React hooks. And that's what we will be doing! We will start by importing the various hooks and utilities we will be using from React core, the Ionic React Hooks project, and Capacitor: +Next, define a new method, `usePhotoGallery()`, that will contain the core logic to take a device photo and save it to the filesystem. Let’s start by opening the device camera. -```tsx -import { useState, useEffect } from 'react'; -import { isPlatform } from '@ionic/react'; - -import { Camera, CameraResultType, CameraSource, Photo } from '@capacitor/camera'; -import { Filesystem, Directory } from '@capacitor/filesystem'; -import { Preferences } from '@capacitor/preferences'; -import { Capacitor } from '@capacitor/core'; -``` - -Next, create a function named usePhotoGallery: +```ts +import { Camera, CameraResultType, CameraSource } from '@capacitor/camera'; -```tsx export function usePhotoGallery() { - const takePhoto = async () => { - const photo = await Camera.getPhoto({ + const addNewToGallery = async () => { + // Take a photo + const capturedPhoto = await Camera.getPhoto({ resultType: CameraResultType.Uri, source: CameraSource.Camera, quality: 100, @@ -46,101 +35,236 @@ export function usePhotoGallery() { }; return { - takePhoto, + addNewToGallery, }; } ``` -Our `usePhotoGallery` hook exposes a method called takePhoto, which in turn calls into Capacitor's getPhoto method. - -Notice the magic here: there's no platform-specific code (web, iOS, or Android)! The Capacitor Camera plugin abstracts that away for us, leaving just one method call - `getPhoto()` - that will open up the device's camera and allow us to take photos. +Notice the magic here: there's no platform-specific code (web, iOS, or Android)! The Capacitor Camera plugin abstracts that away for us, leaving just one method call - `Camera.getPhoto()` - that will open up the device's camera and allow us to take photos. -The last step we need to take is to use the new hook from the Tab2 page. Go back to Tab2.tsx and import the hook: +Next, in `Tab2.tsx`, import the `usePhotoGallery()` method and destructure it to call its `addNewToGallery()` method. ```tsx +import { camera } from 'ionicons/icons'; +import { IonContent, IonHeader, IonPage, IonTitle, IonToolbar, IonFab, IonFabButton, IonIcon } from '@ionic/react'; +// CHANGE: Add `usePhotoGallery` import import { usePhotoGallery } from '../hooks/usePhotoGallery'; -``` - -And right before the return statement in the functional component, get access to the `takePhoto` method by using the hook: +import './Tab2.css'; -```tsx const Tab2: React.FC = () => { - const { takePhoto } = usePhotoGallery(); + // CHANGE: Destructure `addNewToGallery()` from `usePhotoGallery()` + const { addNewToGallery } = usePhotoGallery(); + + return ( + + + + Photo Gallery + + + + + + Photo Gallery + + + + + {/* CHANGE: Add a click event listener to the floating action button */} + addNewToGallery()}> + + + + + + ); +}; - // snip - rest of code +export default Tab2; ``` -Save the file, and if you’re not already, restart the development server in your browser by running `ionic serve`. On the Photo Gallery tab, click the Camera button. If your computer has a webcam of any sort, a modal window appears. Take a selfie! +If it's not running already, restart the development server in your browser by running `ionic serve`. On the Photo Gallery tab, click the Camera button. If your computer has a webcam of any sort, a modal window appears. Take a selfie! ![A photo gallery app displaying a webcam selfie.](/img/guides/first-app-cap-ng/camera-web.png 'Webcam Selfie in Photo Gallery') _(Your selfie is probably much better than mine)_ -After taking a photo, it disappears. We still need to display it within our app and save it for future access. +After taking a photo, it disappears right away. We need to display it within our app and save it for future access. ## Displaying Photos -First we will create a new type to define our Photo, which will hold specific metadata. Add the following UserPhoto interface to the `usePhotoGallery.ts` file, somewhere outside of the main function: +To define the data structure for our photo metadata, create a new interface named `UserPhoto`. Add this interface at the very bottom of the `usePhotoGallery.ts` file, immediately after the `usePhotoGallery()` method definition. -```tsx +```ts +export function usePhotoGallery() { + // ...existing code... +} + +// CHANGE: Add the `UserPhoto` interface export interface UserPhoto { filepath: string; webviewPath?: string; } ``` -Back at the top of the function (right after the call to `usePhotoGallery`, we will define a state variable to store the array of each photo captured with the Camera. +Above the `addNewToGallery()` method, define an array of `UserPhoto`, which will contain a reference to each photo captured with the Camera. Make it a state variable using React's [useState hook](https://react.dev/reference/react/useState). -```tsx -const [photos, setPhotos] = useState([]); -``` +```ts +// CHANGE: Add import +import { useState } from 'react'; +import { Camera, CameraResultType, CameraSource } from '@capacitor/camera'; -When the camera is done taking a picture, the resulting Photo returned from Capacitor will be stored in the `photo` variable. We want to create a new photo object and add it to the photos state array. We make sure we don't accidentally mutate the current photos array by making a new array, and then call `setPhotos` to store the array into state. Update the `takePhoto` method and add this code after the getPhoto call: +export function usePhotoGallery() { + // CHANGE: Add the `photos` array + const [photos, setPhotos] = useState([]); -```tsx -const fileName = Date.now() + '.jpeg'; -const newPhotos = [ - { - filepath: fileName, - webviewPath: photo.webPath, - }, - ...photos, -]; -setPhotos(newPhotos); + // ...existing code... +} ``` -Next, let's expose the photos array from our hook. Update the return statement to include the photos: +Over in the `addNewToGallery()` method, add the newly captured photo to the beginning of the `photos` array. Then, update the `usePhotoGallery()` return statement with the `photos` array. -```tsx -return { - photos, - takePhoto, -}; +```ts +export function usePhotoGallery() { + const [photos, setPhotos] = useState([]); + + // CHANGE: Update `addNewToGallery()` method + const addNewToGallery = async () => { + // Take a photo + const capturedPhoto = await Camera.getPhoto({ + resultType: CameraResultType.Uri, + source: CameraSource.Camera, + quality: 100, + }); + + // CHANGE: Create the `fileName` with current timestamp + const fileName = Date.now() + '.jpeg'; + // CHANGE: Create `savedImageFile` matching `UserPhoto` interface + const savedImageFile = [ + { + filepath: fileName, + webviewPath: capturedPhoto.webPath, + }, + ...photos, + ]; + + // CHANGE: Update the `photos` array with the new photo + setPhotos(savedImageFile); + }; + + return { + addNewToGallery, + // CHANGE: Update return statement to include `photos` array + photos, + }; +} ``` -And back in the Tab2 component, get access to the photos: +`usePhotoGallery.ts` should now look like this: -```tsx -const { photos, takePhoto } = usePhotoGallery(); +```ts +import { useState } from 'react'; +import { Camera, CameraResultType, CameraSource } from '@capacitor/camera'; + +export function usePhotoGallery() { + const [photos, setPhotos] = useState([]); + + const addNewToGallery = async () => { + // Take a photo + const capturedPhoto = await Camera.getPhoto({ + resultType: CameraResultType.Uri, + source: CameraSource.Camera, + quality: 100, + }); + + const fileName = Date.now() + '.jpeg'; + const savedImageFile = [ + { + filepath: fileName, + webviewPath: capturedPhoto.webPath, + }, + ...photos, + ]; + + setPhotos(savedImageFile); + }; + + return { + addNewToGallery, + photos, + }; +} + +export interface UserPhoto { + filepath: string; + webviewPath?: string; +} ``` -With the photo(s) stored into the main array we can display the images on the screen. Add a [Grid component](https://ionicframework.com/docs/api/grid) so that each photo will display nicely as photos are added to the gallery, and loop through each photo in the Photos array, adding an Image component (``) for each. Point the `src` (source) to the photo’s path: +Next, switch to `Tab2.tsx` to display the images. We'll add a [Grid component](../../api/grid.md) to ensure the photos display neatly as they're added to the gallery. Inside the grid, loop through each photo in the `UserPhoto`'s `photos` array. For each item, add an [Image component](../../api/img.md) and set its `src` property to the photo's path. ```tsx - - - - {photos.map((photo, index) => ( - - - - ))} - - - - +import { camera } from 'ionicons/icons'; +// CHANGE: Update import +import { + IonContent, + IonHeader, + IonPage, + IonTitle, + IonToolbar, + IonFab, + IonFabButton, + IonIcon, + IonGrid, + IonRow, + IonCol, + IonImg, +} from '@ionic/react'; +import { usePhotoGallery } from '../hooks/usePhotoGallery'; + +const Tab2: React.FC = () => { + // CHANGE: Add `photos` array to destructure from `usePhotoGallery()` + const { photos, addNewToGallery } = usePhotoGallery(); + + return ( + + + + Photo Gallery + + + + + + Photo Gallery + + + + {/* CHANGE: Add a grid component to display the photos */} + + + {/* CHANGE: Create a new column and image component for each photo */} + {photos.map((photo) => ( + + + + ))} + + + + + addNewToGallery()}> + + + + + + ); +}; + +export default Tab2; ``` -Save all files. Within the web browser, click the Camera button and take another photo. This time, the photo is displayed in the Photo Gallery! +Within the web browser, click the camera button and take another photo. This time, the photo is displayed in the Photo Gallery! Up next, we’ll add support for saving the photos to the filesystem, so they can be retrieved and displayed in our app at a later time. diff --git a/docs/react/your-first-app/3-saving-photos.md b/docs/react/your-first-app/3-saving-photos.md index 529055138e6..03623e4e05f 100644 --- a/docs/react/your-first-app/3-saving-photos.md +++ b/docs/react/your-first-app/3-saving-photos.md @@ -1,25 +1,121 @@ --- +title: Saving Photos to the Filesystem sidebar_label: 写真の保存 --- -# Saving Photos to the Filesystem + + Saving Photos to the Filesystem with React | Ionic Capacitor Camera + + -We’re now able to take multiple photos and display them in a photo gallery on the second tab of our app. These photos, however, are not currently being stored permanently, so when the app is closed, they will be lost. +We’re now able to take multiple photos and display them in a photo gallery on the second tab of our app. These photos, however, are not currently being stored permanently, so when the app is closed, they will be deleted. ## Filesystem API -Fortunately, saving them to the filesystem only takes a few steps. Begin by opening the `usePhotoGallery` hook (`src/hooks/usePhotoGallery.ts`), and get access to the `writeFile` method from the `Filesystem` class: +Fortunately, saving them to the filesystem only takes a few steps. Begin by creating a new class method, `savePicture()`, in the `usePhotoGallery()` method in `usePhotoGallery.ts`. -:::note -We will use the `writeFile` method initially, but we will use the others coming up shortly, so we'll go ahead and import them now. -::: +```ts +import { useState } from 'react'; +import { Camera, CameraResultType, CameraSource } from '@capacitor/camera'; +// CHANGE: Add import +import type { Photo } from '@capacitor/camera'; -Next, create a couple of new functions in `usePhotoGallery`: +export function usePhotoGallery() { + // ...existing code... + + // CHANGE: Add the `savePicture()` method + const savePicture = async (photo: Photo, fileName: string): Promise => { + return { + filepath: 'soon...', + webviewPath: 'soon...', + }; + }; + + return { + addNewToGallery, + photos, + }; +} + +export interface UserPhoto { + filepath: string; + webviewPath?: string; +} +``` + +We can use this new method immediately in `addNewToGallery()`. + +```ts +import { useState } from 'react'; +import { Camera, CameraResultType, CameraSource } from '@capacitor/camera'; +import type { Photo } from '@capacitor/camera'; -```tsx export function usePhotoGallery() { + const [photos, setPhotos] = useState([]); + + const addNewToGallery = async () => { + // Take a photo + const capturedPhoto = await Camera.getPhoto({ + resultType: CameraResultType.Uri, + source: CameraSource.Camera, + quality: 100, + }); + + const fileName = Date.now() + '.jpeg'; + // CHANGE: Add `savedImageFile` + // Save the picture and add it to photo collection + const savedImageFile = await savePicture(capturedPhoto, fileName); + + // CHANGE: Update state with new photo + const newPhotos = [savedImageFile, ...photos]; + setPhotos(newPhotos); + }; + const savePicture = async (photo: Photo, fileName: string): Promise => { - const base64Data = await base64FromPath(photo.webPath!); + return { + filepath: 'soon...', + webviewPath: 'soon...', + }; + }; + + return { + addNewToGallery, + photos, + }; +} + +export interface UserPhoto { + filepath: string; + webviewPath?: string; +} +``` + +We'll use the Capacitor [Filesystem API](../../native/filesystem.md) to save the photo. First, convert the photo to base64 format. + +Then, pass the data to the Filesystem's `writeFile` method. Recall that we display photos by setting the image's source path (`src`) to the `webviewPath` property. So, set the `webviewPath` and return the new `Photo` object. + +For now, create a new helper method, `convertBlobToBase64()`, to implement the necessary logic for running on the web. + +```ts +import { useState } from 'react'; +import { Camera, CameraResultType, CameraSource } from '@capacitor/camera'; +import type { Photo } from '@capacitor/camera'; +// CHANGE: Add import +import { Filesystem, Directory } from '@capacitor/filesystem'; + +export function usePhotoGallery() { + // ...existing code... + + // CHANGE: Update the `savePicture()` method + const savePicture = async (photo: Photo, fileName: string): Promise => { + // Fetch the photo, read as a blob, then convert to base64 format + const response = await fetch(photo.webPath!); + const blob = await response.blob(); + const base64Data = (await convertBlobToBase64(blob)) as string; + const savedFile = await Filesystem.writeFile({ path: fileName, data: base64Data, @@ -33,49 +129,101 @@ export function usePhotoGallery() { webviewPath: photo.webPath, }; }; -} -export async function base64FromPath(path: string): Promise { - const response = await fetch(path); - const blob = await response.blob(); - return new Promise((resolve, reject) => { - const reader = new FileReader(); - reader.onerror = reject; - reader.onload = () => { - if (typeof reader.result === 'string') { + // CHANGE: Add `convertBlobToBase64()` method + const convertBlobToBase64 = (blob: Blob) => { + return new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.onerror = reject; + reader.onload = () => { resolve(reader.result); - } else { - reject('method did not return a string'); - } - }; - reader.readAsDataURL(blob); - }); + }; + reader.readAsDataURL(blob); + }); + }; + + return { + addNewToGallery, + photos, + }; +} + +export interface UserPhoto { + filepath: string; + webviewPath?: string; } ``` -:::note -The base64FromPath method is a helper util that downloads a file from the supplied path and returns a base64 representation of that file. -::: +`usePhotoGallery.ts` should now look like this: + +```ts +import { useState } from 'react'; +import { Camera, CameraResultType, CameraSource } from '@capacitor/camera'; +import type { Photo } from '@capacitor/camera'; +import { Filesystem, Directory } from '@capacitor/filesystem'; -We pass in the `photo` object, which represents the newly captured device photo, as well as the fileName, which will provide a path for the file to be stored to. +export function usePhotoGallery() { + const [photos, setPhotos] = useState([]); + + const addNewToGallery = async () => { + // Take a photo + const capturedPhoto = await Camera.getPhoto({ + resultType: CameraResultType.Uri, + source: CameraSource.Camera, + quality: 100, + }); + + const fileName = Date.now() + '.jpeg'; + // Save the picture and add it to photo collection + const savedImageFile = await savePicture(capturedPhoto, fileName); + + const newPhotos = [savedImageFile, ...photos]; + setPhotos(newPhotos); + }; + + const savePicture = async (photo: Photo, fileName: string): Promise => { + // Fetch the photo, read as a blob, then convert to base64 format + const response = await fetch(photo.webPath!); + const blob = await response.blob(); + const base64Data = (await convertBlobToBase64(blob)) as string; + + const savedFile = await Filesystem.writeFile({ + path: fileName, + data: base64Data, + directory: Directory.Data, + }); -Next we use the Capacitor [Filesystem API](https://capacitorjs.com/docs/apis/filesystem) to save the photo to the filesystem. We start by converting the photo to base64 format, then feed the data to the Filesystem’s `writeFile` function. + // Use webPath to display the new image instead of base64 since it's + // already loaded into memory + return { + filepath: fileName, + webviewPath: photo.webPath, + }; + }; -Last, call `savePicture` and pass in the photo object and filename directly underneath the call to `setPhotos` in the `takePhoto` method. Here is the full method: + const convertBlobToBase64 = (blob: Blob) => { + return new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.onerror = reject; + reader.onload = () => { + resolve(reader.result); + }; + reader.readAsDataURL(blob); + }); + }; -```tsx -const takePhoto = async () => { - const photo = await Camera.getPhoto({ - resultType: CameraResultType.Uri, - source: CameraSource.Camera, - quality: 100, - }); + return { + addNewToGallery, + photos, + }; +} - const fileName = Date.now() + '.jpeg'; - const savedFileImage = await savePicture(photo, fileName); - const newPhotos = [savedFileImage, ...photos]; - setPhotos(newPhotos); -}; +export interface UserPhoto { + filepath: string; + webviewPath?: string; +} ``` -There we go! Each time a new photo is taken, it’s now automatically saved to the filesystem. +Obtaining the camera photo as base64 format on the web appears to be a bit trickier than on mobile. In reality, we’re just using built-in web APIs: [fetch()](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) as a neat way to read the file into blob format, then FileReader’s [readAsDataURL()](https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsDataURL) to convert the photo blob to base64. + +There we go! Each time a new photo is taken, it’s now automatically saved to the filesystem. Next up, we'll load and display our saved images. diff --git a/docs/react/your-first-app/4-loading-photos.md b/docs/react/your-first-app/4-loading-photos.md index 9a7119a5f7a..4f7bb35ccc1 100644 --- a/docs/react/your-first-app/4-loading-photos.md +++ b/docs/react/your-first-app/4-loading-photos.md @@ -4,7 +4,7 @@ sidebar_label: 写真の読み込み --- - Loading Photos from the Filesystem Using A Key-Value Store + Loading Photos from the Filesystem with React | Ionic Capacitor Camera ([]); + // CHANGE: Add a key for photo storage + const PHOTO_STORAGE = 'photos'; + + // ...existing code... +} ``` -Then, use the `Storage` class to get access to the get and set methods for reading and writing to device storage: +Next, at the end of the `addNewToGallery()` method, add a call to the `Preferences.set()` method to save the `photos` array. By adding it here, the `photos` array is stored each time a new photo is taken. This way, it doesn’t matter when the app user closes or switches to a different app - all photo data is saved. -At the end of the `takePhoto` function, add a call to `Preferences.set()` to save the Photos array. By adding it here, the Photos array is stored each time a new photo is taken. This way, it doesn’t matter when the app user closes or switches to a different app - all photo data is saved. +```ts +import { useState } from 'react'; +import { Camera, CameraResultType, CameraSource } from '@capacitor/camera'; +import type { Photo } from '@capacitor/camera'; +import { Filesystem, Directory } from '@capacitor/filesystem'; +// CHANGE: Add import +import { Preferences } from '@capacitor/preferences'; -```tsx -Preferences.set({ key: PHOTO_STORAGE, value: JSON.stringify(newPhotos) }); -``` +export function usePhotoGallery() { + // ...existing code... + + const addNewToGallery = async () => { + // ...existing code... + + // CHANGE: Add method to cache all photo data for future retrieval + Preferences.set({ key: PHOTO_STORAGE, value: JSON.stringify(newPhotos) }); + }; + + // ...existing code... -With the photo array data saved, we will create a method that will retrieve the data when the hook loads. We will do so by using React's `useEffect` hook. Insert this above the `takePhoto` declaration. Here is the code, and we will break it down: - -```tsx -useEffect(() => { - const loadSaved = async () => { - const { value } = await Preferences.get({ key: PHOTO_STORAGE }); - const photosInPreferences = (value ? JSON.parse(value) : []) as UserPhoto[]; - - for (let photo of photosInPreferences) { - const file = await Filesystem.readFile({ - path: photo.filepath, - directory: Directory.Data, - }); - // Web platform only: Load the photo as base64 data - photo.webviewPath = `data:image/jpeg;base64,${file.data}`; - } - setPhotos(photosInPreferences); + return { + addNewToGallery, + photos, }; - loadSaved(); -}, []); +} +``` + +With the photo array data saved, create a new method in the `usePhotoGallery()` called `loadSaved()` that can retrieve the photo data. We use the same key to retrieve the `photos` array in JSON format, then parse it into an array. + +```ts +// CHANGE: Update import +import { useState, useEffect } from 'react'; +import { Camera, CameraResultType, CameraSource } from '@capacitor/camera'; +import type { Photo } from '@capacitor/camera'; +import { Filesystem, Directory } from '@capacitor/filesystem'; +import { Preferences } from '@capacitor/preferences'; + +export function usePhotoGallery() { + const [photos, setPhotos] = useState([]); + + const PHOTO_STORAGE = 'photos'; + + // CHANGE: Add useEffect hook + useEffect(() => { + // CHANGE: Add `loadSaved()` method + const loadSaved = async () => { + const { value: photoList } = await Preferences.get({ key: PHOTO_STORAGE }); + const photosInPreferences = (photoList ? JSON.parse(photoList) : []) as UserPhoto[]; + }; + + loadSaved(); + }, []); + + // ...existing code... +} ``` -This seems a bit scary at first, so let's walk through it, first by looking at the second parameter we pass into the hook: the dependency array `[]`. +The second parameter, the empty dependency array (`[]`), is what tells React to only run the function once. Normally, [useEffect hooks](https://react.dev/reference/react/useEffect) run after every render, but passing an empty array prevents it from running again because none of the dependencies, the values the hook relies on, will ever change. + +On mobile (coming up next!), we can directly set the source of an image tag - `` - to each photo file on the `Filesystem`, displaying them automatically. On the web, however, we must read each image from the `Filesystem` into base64 format, using a new `base64` property on the `Photo` object. This is because the `Filesystem` API uses [IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API) under the hood. Add the following code to complete the `loadSaved()` method. + +```ts +export function usePhotoGallery() { + const [photos, setPhotos] = useState([]); + + const PHOTO_STORAGE = 'photos'; -The useEffect hook, by default, gets called each time a component renders, unless, we pass in a dependency array. In that case, it will only run when a dependency gets updated. In our case we only want it to be called once. By passing in an empty array, which will not be changed, we can prevent the hook from being called multiple times. + useEffect(() => { + // CHANGE: Update `loadSaved()` method + const loadSaved = async () => { + const { value: photoList } = await Preferences.get({ key: PHOTO_STORAGE }); + const photosInPreferences = (photoList ? JSON.parse(photoList) : []) as UserPhoto[]; + + // CHANGE: Display the photo by reading into base64 format + for (const photo of photosInPreferences) { + const readFile = await Filesystem.readFile({ + path: photo.filepath, + directory: Directory.Data, + }); + photo.webviewPath = `data:image/jpeg;base64,${readFile.data}`; + } + + setPhotos(photosInPreferences); + }; + + loadSaved(); + }, []); + + // ...existing code... +} +``` + +`usePhotoGallery.ts` should now look like this: + +```ts +import { useState, useEffect } from 'react'; +import { Camera, CameraResultType, CameraSource } from '@capacitor/camera'; +import type { Photo } from '@capacitor/camera'; +import { Filesystem, Directory } from '@capacitor/filesystem'; +import { Preferences } from '@capacitor/preferences'; + +export function usePhotoGallery() { + const [photos, setPhotos] = useState([]); + + const PHOTO_STORAGE = 'photos'; + + useEffect(() => { + const loadSaved = async () => { + const { value: photoList } = await Preferences.get({ key: PHOTO_STORAGE }); + const photosInPreferences = (photoList ? JSON.parse(photoList) : []) as UserPhoto[]; + + for (const photo of photosInPreferences) { + const readFile = await Filesystem.readFile({ + path: photo.filepath, + directory: Directory.Data, + }); + photo.webviewPath = `data:image/jpeg;base64,${readFile.data}`; + } + + setPhotos(photosInPreferences); + }; + + loadSaved(); + }, []); + + const addNewToGallery = async () => { + // Take a photo + const capturedPhoto = await Camera.getPhoto({ + resultType: CameraResultType.Uri, + source: CameraSource.Camera, + quality: 100, + }); + + const fileName = Date.now() + '.jpeg'; + // Save the picture and add it to photo collection + const savedImageFile = await savePicture(capturedPhoto, fileName); + + const newPhotos = [savedImageFile, ...photos]; + setPhotos(newPhotos); + + Preferences.set({ key: PHOTO_STORAGE, value: JSON.stringify(newPhotos) }); + }; + + const savePicture = async (photo: Photo, fileName: string): Promise => { + // Fetch the photo, read as a blob, then convert to base64 format + const response = await fetch(photo.webPath!); + const blob = await response.blob(); + const base64Data = (await convertBlobToBase64(blob)) as string; + + const savedFile = await Filesystem.writeFile({ + path: fileName, + data: base64Data, + directory: Directory.Data, + }); + + // Use webPath to display the new image instead of base64 since it's + // already loaded into memory + return { + filepath: fileName, + webviewPath: photo.webPath, + }; + }; + + const convertBlobToBase64 = (blob: Blob) => { + return new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.onerror = reject; + reader.onload = () => { + resolve(reader.result); + }; + reader.readAsDataURL(blob); + }); + }; + + return { + addNewToGallery, + photos, + }; +} + +export interface UserPhoto { + filepath: string; + webviewPath?: string; +} +``` -The first parameter to `useEffect` is the function that will be called by the effect. We pass in an anonymous arrow function, and inside of it we define another asynchronous method and then immediately call this. We have to call the async function from within the hook as the hook callback can't be asynchronous itself. +:::note +If you're seeing broken image links or missing photos after following these steps, you may need to open your browser's dev tools and clear both [localStorage](https://developer.chrome.com/docs/devtools/storage/localstorage) and [IndexedDB](https://developer.chrome.com/docs/devtools/storage/indexeddb). -On mobile (coming up next!), we can directly set the source of an image tag - `` - to each photo file on the Filesystem, displaying them automatically. On the web, however, we must read each image from the Filesystem into base64 format, because the Filesystem API stores them in base64 within [IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API) under the hood. +In localStorage, look for domain `http://localhost:8100` and key `CapacitorStorage.photos`. In IndexedDB, find a store called "FileStorage". Your photos will have a key like `/DATA/123456789012.jpeg`. +::: That’s it! We’ve built a complete Photo Gallery feature in our Ionic app that works on the web. Next up, we’ll transform it into a mobile app for iOS and Android! diff --git a/docs/react/your-first-app/5-adding-mobile.md b/docs/react/your-first-app/5-adding-mobile.md index be49116856e..c000645ec3a 100644 --- a/docs/react/your-first-app/5-adding-mobile.md +++ b/docs/react/your-first-app/5-adding-mobile.md @@ -1,38 +1,71 @@ --- -sidebar_label: Adding Mobile +title: Adding Mobile +sidebar_label: モバイルデバイス機能の追加 --- -# モバイルデバイス機能の追加 + + Adding Mobile Support with React | Ionic Capacitor Camera + + Our photo gallery app won’t be complete until it runs on iOS, Android, and the web - all using one codebase. All it takes is some small logic changes to support mobile platforms, installing some native tooling, then running the app on a device. Let’s go! +## Import Platform API + Let’s start with making some small code changes - then our app will “just work” when we deploy it to a device. +Import the Ionic [Platform API](../platform.md) into `usePhotoGallery.ts`, which is used to retrieve information about the current device. In this case, it’s useful for selecting which code to execute based on the platform the app is running on (web or mobile). + +Add `isPlatform` to the imports at the top of the file to use the `isPlatform` method. `Capacitor` is also imported to help with file paths on mobile devices. + +```ts +import { useState, useEffect } from 'react'; +import { Camera, CameraResultType, CameraSource, Photo } from '@capacitor/camera'; +import { Filesystem, Directory } from '@capacitor/filesystem'; +import { Preferences } from '@capacitor/preferences'; +// CHANGE: Add import +import { isPlatform } from '@ionic/react'; +import { Capacitor } from '@capacitor/core'; + +// ...existing code... +``` + ## Platform-specific Logic -First, we’ll update the photo saving functionality to support mobile. In the `savePicture` function, check which platform the app is running on. If it’s “hybrid” (Capacitor or Cordova, the two native runtimes), then read the photo file into base64 format using the `readFile` method. Also, return the complete file path to the photo using the Filesystem API. When setting the `webviewPath`, use the special `Capacitor.convertFileSrc` method ([details here](https://ionicframework.com/docs/core-concepts/webview#file-protocol)). Otherwise, use the same logic as before when running the app on the web. +First, we’ll update the photo saving functionality to support mobile. In the `savePicture()` method, check which platform the app is running on. If it’s “hybrid” (Capacitor, the native runtime), then read the photo file into base64 format using the `Filesystem.readFile()` method. Otherwise, use the same logic as before when running the app on the web. + +Update `savePicture()` to look like the following: -```tsx +```ts +// CHANGE: Update the `savePicture()` method const savePicture = async (photo: Photo, fileName: string): Promise => { let base64Data: string | Blob; - // "hybrid" will detect Cordova or Capacitor; + // CHANGE: Add platform check + // "hybrid" will detect mobile - iOS or Android if (isPlatform('hybrid')) { - const file = await Filesystem.readFile({ + const readFile = await Filesystem.readFile({ path: photo.path!, }); - base64Data = file.data; + base64Data = readFile.data; } else { - base64Data = await base64FromPath(photo.webPath!); + // Fetch the photo, read as a blob, then convert to base64 format + const response = await fetch(photo.webPath!); + const blob = await response.blob(); + base64Data = (await convertBlobToBase64(blob)) as string; } + const savedFile = await Filesystem.writeFile({ path: fileName, data: base64Data, directory: Directory.Data, }); + // CHANGE: Add platform check if (isPlatform('hybrid')) { // Display the new image by rewriting the 'file://' path to HTTP - // Details: https://ionicframework.com/docs/building/webview#file-protocol return { filepath: savedFile.uri, webviewPath: Capacitor.convertFileSrc(savedFile.uri), @@ -48,26 +81,146 @@ const savePicture = async (photo: Photo, fileName: string): Promise = }; ``` -Next, add a new bit of logic in the `loadSaved` function. On mobile, we can directly point to each photo file on the Filesystem and display them automatically. On the web, however, we must read each image from the Filesystem into base64 format. This is because the Filesystem API uses [IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API) under the hood. Update the `loadSaved` function inside of `useEffect` to: +Next, add a new bit of logic in the `loadSaved()` method. On mobile, we can directly point to each photo file on the Filesystem and display them automatically. On the web, however, we must read each image from the Filesystem into base64 format. This is because the Filesystem API uses [IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API) under the hood. Update the `loadSaved()` method: -```tsx +```ts +// CHANGE: Update `loadSaved` method const loadSaved = async () => { - const { value } = await Preferences.get({ key: PHOTO_STORAGE }); + const { value: photoList } = await Preferences.get({ key: PHOTO_STORAGE }); + const photosInPreferences = (photoList ? JSON.parse(photoList) : []) as UserPhoto[]; - const photosInPreferences = (value ? JSON.parse(value) : []) as UserPhoto[]; + // CHANGE: Add platform check // If running on the web... if (!isPlatform('hybrid')) { - for (let photo of photosInPreferences) { - const file = await Filesystem.readFile({ + for (const photo of photosInPreferences) { + const readFile = await Filesystem.readFile({ path: photo.filepath, directory: Directory.Data, }); - // Web platform only: Load the photo as base64 data - photo.webviewPath = `data:image/jpeg;base64,${file.data}`; + photo.webviewPath = `data:image/jpeg;base64,${readFile.data}`; } } + setPhotos(photosInPreferences); }; ``` -Our Photo Gallery now consists of one codebase that runs on the web, Android, and iOS. Next up, the part you’ve been waiting for - deploying the app to a device. +Our Photo Gallery now consists of one codebase that runs on the web, Android, and iOS. + +`usePhotoGallery.ts` should now look like this: + +```ts +import { useState, useEffect } from 'react'; +import { Camera, CameraResultType, CameraSource } from '@capacitor/camera'; +import type { Photo } from '@capacitor/camera'; +import { Filesystem, Directory } from '@capacitor/filesystem'; +import { Preferences } from '@capacitor/preferences'; +import { isPlatform } from '@ionic/react'; +import { Capacitor } from '@capacitor/core'; + +export function usePhotoGallery() { + const [photos, setPhotos] = useState([]); + + const PHOTO_STORAGE = 'photos'; + + useEffect(() => { + const loadSaved = async () => { + const { value: photoList } = await Preferences.get({ key: PHOTO_STORAGE }); + const photosInPreferences = (photoList ? JSON.parse(photoList) : []) as UserPhoto[]; + + // If running on the web... + if (!isPlatform('hybrid')) { + for (const photo of photosInPreferences) { + const readFile = await Filesystem.readFile({ + path: photo.filepath, + directory: Directory.Data, + }); + photo.webviewPath = `data:image/jpeg;base64,${readFile.data}`; + } + } + + setPhotos(photosInPreferences); + }; + + loadSaved(); + }, []); + + const addNewToGallery = async () => { + // Take a photo + const capturedPhoto = await Camera.getPhoto({ + resultType: CameraResultType.Uri, + source: CameraSource.Camera, + quality: 100, + }); + + const fileName = Date.now() + '.jpeg'; + // Save the picture and add it to photo collection + const savedImageFile = await savePicture(capturedPhoto, fileName); + + const newPhotos = [savedImageFile, ...photos]; + setPhotos(newPhotos); + + Preferences.set({ key: PHOTO_STORAGE, value: JSON.stringify(newPhotos) }); + }; + + const savePicture = async (photo: Photo, fileName: string): Promise => { + let base64Data: string | Blob; + // "hybrid" will detect mobile - iOS or Android + if (isPlatform('hybrid')) { + const readFile = await Filesystem.readFile({ + path: photo.path!, + }); + base64Data = readFile.data; + } else { + // Fetch the photo, read as a blob, then convert to base64 format + const response = await fetch(photo.webPath!); + const blob = await response.blob(); + base64Data = (await convertBlobToBase64(blob)) as string; + } + + const savedFile = await Filesystem.writeFile({ + path: fileName, + data: base64Data, + directory: Directory.Data, + }); + + if (isPlatform('hybrid')) { + // Display the new image by rewriting the 'file://' path to HTTP + return { + filepath: savedFile.uri, + webviewPath: Capacitor.convertFileSrc(savedFile.uri), + }; + } else { + // Use webPath to display the new image instead of base64 since it's + // already loaded into memory + return { + filepath: fileName, + webviewPath: photo.webPath, + }; + } + }; + + const convertBlobToBase64 = (blob: Blob) => { + return new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.onerror = reject; + reader.onload = () => { + resolve(reader.result); + }; + reader.readAsDataURL(blob); + }); + }; + + return { + addNewToGallery, + photos, + }; +} + +export interface UserPhoto { + filepath: string; + webviewPath?: string; +} +``` + +Next up, the part you’ve been waiting for - deploying the app to a device. diff --git a/docs/react/your-first-app/6-deploying-mobile.md b/docs/react/your-first-app/6-deploying-mobile.md index 64089e7621e..79372fd84e2 100644 --- a/docs/react/your-first-app/6-deploying-mobile.md +++ b/docs/react/your-first-app/6-deploying-mobile.md @@ -1,10 +1,17 @@ --- +title: Deploying to iOS and Android sidebar_label: モバイルへのデプロイ --- -# Deploying to iOS and Android + + Adding Mobile Support with React | Ionic Capacitor Camera + + -Since we added Capacitor to our project when it was first created, there’s only a handful of steps remaining until the Photo Gallery app is on our device! Remember, you can find the complete source code for this app [here](https://github.com/ionic-team/photo-gallery-capacitor-react). +Since we added Capacitor to our project when it was first created, there’s only a handful of steps remaining until the Photo Gallery app is on our device! ## Capacitor Setup @@ -19,8 +26,8 @@ ionic build Next, create both the iOS and Android projects: ```shell -$ ionic cap add ios -$ ionic cap add android +ionic cap add ios +ionic cap add android ``` Both android and ios folders at the root of the project are created. These are entirely standalone native projects that should be considered part of your Ionic app (i.e., check them into source control, edit them using their native tooling, etc.). @@ -37,13 +44,13 @@ Note: After making updates to the native portion of the code (such as adding a n ionic cap sync ``` -## iOS +## iOS Deployment -:::note +:::important To build an iOS app, you’ll need a Mac computer. ::: -Capacitor iOS apps are configured and managed through Xcode (Apple’s iOS/Mac IDE), with dependencies managed by CocoaPods. Before running this app on an iOS device, there's a couple of steps to complete. +Capacitor iOS apps are configured and managed through Xcode (Apple’s iOS/Mac IDE), with dependencies managed by [CocoaPods](https://cocoapods.org/). Before running this app on an iOS device, there's a couple of steps to complete. First, run the Capacitor `open` command, which opens the native iOS project in Xcode: @@ -51,7 +58,7 @@ First, run the Capacitor `open` command, which opens the native iOS project in X ionic cap open ios ``` -In order for some native plugins to work, user permissions must be configured. In our photo gallery app, this includes the Camera plugin: iOS displays a modal dialog automatically after the first time that `Camera.getPhoto()` is called, prompting the user to allow the app to use the Camera. The permission that drives this is labeled “Privacy - Camera Usage.” To set it, the `Info.plist` file must be modified ([more details here](https://capacitorjs.com/docs/ios/configuration)). To access it, click "Info," then expand "Custom iOS Target Properties." +In order for some native plugins to work, user permissions must be configured. In our photo gallery app, this includes the Camera plugin: iOS displays a modal dialog automatically after the first time that `Camera.getPhoto()` is called, prompting the user to allow the app to use the Camera. The permission that drives this is labeled "Privacy - Camera Usage." To set it, the `Info.plist` file must be modified ([more details here](https://capacitorjs.com/docs/ios/configuration)). To access it, click "Info," then expand "Custom iOS Target Properties." ![The Info.plist file in Xcode showing the NSCameraUsageDescription key added for camera access.](/img/guides/first-app-cap-ng/xcode-info-plist.png 'Xcode Info.plist Configuration') @@ -73,7 +80,7 @@ Upon tapping the Camera button on the Photo Gallery tab, the permission prompt w ![Two iPhones side by side, one showing the camera permission prompt and the other displaying a photo taken with the app.](/img/guides/first-app-cap-ng/ios-permissions-photo.png 'iOS Camera Permission Prompt and Photo Result') -## Android +## Android Deployment Capacitor Android apps are configured and managed through Android Studio. Before running this app on an Android device, there's a couple of steps to complete. diff --git a/docs/react/your-first-app/7-live-reload.md b/docs/react/your-first-app/7-live-reload.md index 58e12773151..9406fb57a7f 100644 --- a/docs/react/your-first-app/7-live-reload.md +++ b/docs/react/your-first-app/7-live-reload.md @@ -1,120 +1,205 @@ --- +title: Rapid App Development with Live Reload sidebar_label: ライブリロード --- -# Rapid App Development with Live Reload + + Rapid App Development with Live Reload with React | Ionic Capacitor Camera + + So far, we’ve seen how easy it is to develop a cross-platform app that works everywhere. The development experience is pretty quick, but what if I told you there was a way to go faster? -We can use the Ionic CLI’s [Live Reload functionality](https://ionicframework.com/docs/cli/livereload) to boost our productivity when building Ionic apps. When active, Live Reload will reload the browser and/or WebView when changes in the app are detected. +We can use the Ionic CLI’s [Live Reload functionality](../../cli/livereload.md) to boost our productivity when building Ionic apps. When active, Live Reload will reload the browser and/or WebView when changes in the app are detected. ## Live Reload Remember `ionic serve`? That was Live Reload working in the browser, allowing us to iterate quickly. -We can also use it when developing on iOS and Android devices. This is particularly useful when writing code that interacts with native plugins. Since we need to run native plugin code on a device in order to verify that it works, having a way to quickly write code, build and deploy it, then test it is crucial to keeping up our development speed. +We can also use it when developing on iOS and Android devices. This is particularly useful when writing code that interacts with native plugins - we must run it on a device to verify that it works. Therefore, being able to quickly write, build, test, and deploy code is crucial to keeping up our development speed. Let’s use Live Reload to implement photo deletion, the missing piece of our Photo Gallery feature. Select your platform of choice (iOS or Android) and connect a device to your computer. Next, run either command in a terminal, based on your chosen platform: ```shell -$ ionic cap run ios -l --external +ionic cap run ios -l --external -$ ionic cap run android -l --external +ionic cap run android -l --external ``` The Live Reload server will start up, and the native IDE of choice will open if not opened already. Within the IDE, click the Play button to launch the app onto your device. ## Deleting Photos -With Live Reload running and the app is open on your device, let’s implement photo deletion functionality. Open `Tab2.tsx` then import `useState` from React and `UserPhoto` from the `usePhotoGallery` hook: - -```tsx -import React, { useState } from 'react'; -import { usePhotoGallery, UserPhoto } from '../hooks/usePhotoGallery'; -// other imports -``` - -Next, reference the `deletePhoto` function, which we'll create soon: - -```tsx -const { photos, takePhoto, deletePhoto } = usePhotoGallery(); +With Live Reload running and the app open on your device, let’s implement photo deletion functionality. + +In `usePhotoGallery.ts`, add the `deletePhoto()` method. The selected photo is removed from the `photos` array first. Then, we delete the actual photo file itself using the Filesystem API. + +```ts +import { useState, useEffect } from 'react'; +import { Camera, CameraResultType, CameraSource } from '@capacitor/camera'; +import type { Photo } from '@capacitor/camera'; +import { Filesystem, Directory } from '@capacitor/filesystem'; +import { Preferences } from '@capacitor/preferences'; +import { isPlatform } from '@ionic/react'; +import { Capacitor } from '@capacitor/core'; + +export function usePhotoGallery() { + // ...existing code... + + // CHANGE: Add `deletePhoto()` method + const deletePhoto = async (photo: UserPhoto) => { + // Remove this photo from the Photos reference data array + const newPhotos = photos.filter((p) => p.filepath !== photo.filepath); + + // Update photos array cache by overwriting the existing photo array + Preferences.set({ key: PHOTO_STORAGE, value: JSON.stringify(newPhotos) }); + + // Delete photo file from filesystem + const filename = photo.filepath.slice(photo.filepath.lastIndexOf('/') + 1); + await Filesystem.deleteFile({ + path: filename, + directory: Directory.Data, + }); + + setPhotos(newPhotos); + }; + + return { + photos, + addNewToGallery, + // CHANGE: Add `deletePhoto()` to the return statement + deletePhoto, + }; +} + +export interface UserPhoto { + filepath: string; + webviewPath?: string; +} ``` -Next, add a state value to store information about the photo to delete: +Next, in `Tab2.tsx`, implement the `IonActionSheet` component. We're adding two options: "Delete", which calls `usePhotoGallery.deletePhoto()`, and "Cancel". The cancel button will automatically close the action sheet when assigned the "cancel" role. ```tsx -const [photoToDelete, setPhotoToDelete] = useState(); -``` - -When a user clicks on an image, we will show the action sheet by changing the state value to the photo. Update the `` element to: - -```tsx - setPhotoToDelete(photo)} src={photo.webviewPath} /> -``` - -Next, add an [IonActionSheet](https://ionicframework.com/docs/api/action-sheet) dialog with the option to either delete the selected photo or cancel (close) the dialog. We will set the isOpen property based on if photoToDelete has a value or not. - -In the JSX, put the following component before the closing `` tag. +// CHANGE: Add import +import { useState } from 'react'; +// CHANGE: Update import +import { camera, trash, close } from 'ionicons/icons'; +// CHANGE: Update import +import { + IonContent, + IonHeader, + IonPage, + IonTitle, + IonToolbar, + IonFab, + IonFabButton, + IonIcon, + IonGrid, + IonRow, + IonCol, + IonImg, + IonActionSheet, +} from '@ionic/react'; +// CHANGE: Add import +import type { UserPhoto } from '../hooks/usePhotoGallery'; +import { usePhotoGallery } from '../hooks/usePhotoGallery'; +import './Tab2.css'; + +const Tab2: React.FC = () => { + // CHANGE: Add `deletePhoto()` method + const { photos, addNewToGallery, deletePhoto } = usePhotoGallery(); + // CHANGE: Add state for the photo to delete + const [photoToDelete, setPhotoToDelete] = useState(); + + return ( + + + + Photo Gallery + + + + + + Photo Gallery + + + + + + {photos.map((photo) => ( + + + + ))} + + + + + addNewToGallery()}> + + + + + {/* CHANGE: Add action sheet for deleting photos */} + { + if (photoToDelete) { + deletePhoto(photoToDelete); + setPhotoToDelete(undefined); + } + }, + }, + { + text: 'Cancel', + icon: close, + role: 'cancel', + handler: () => { + // Nothing to do, action sheet is automatically closed + }, + }, + ]} + onDidDismiss={() => setPhotoToDelete(undefined)} + > + + + ); +}; -```tsx - { - if (photoToDelete) { - deletePhoto(photoToDelete); - setPhotoToDelete(undefined); - } - }, - }, - { - text: 'Cancel', - icon: close, - role: 'cancel', - }, - ]} - onDidDismiss={() => setPhotoToDelete(undefined)} -/> +export default Tab2; ``` -Above, we added two options: `Delete` that calls `deletePhoto` function (to be added next) and `Cancel`, which when given the role of “cancel” will automatically close the action sheet. It's also important to set the onDidDismiss function and set our photoToDelete back to undefined when the modal goes away. That way, when another image is clicked, the action sheet notices the change in the value of photoToDelete. - -Next, we need to implement the deletePhoto method that will come from the `usePhotoGallery` hook. Open the file and paste in the following function in the hook: +Add a click handler to the `` element. When the app user taps on a photo in our gallery, we’ll display an [Action Sheet](../../api/action-sheet.md) dialog with the option to either delete the selected photo or cancel (close) the dialog. ```tsx -const deletePhoto = async (photo: UserPhoto) => { - // Remove this photo from the Photos reference data array - const newPhotos = photos.filter((p) => p.filepath !== photo.filepath); - - // Update photos array cache by overwriting the existing photo array - Preferences.set({ key: PHOTO_STORAGE, value: JSON.stringify(newPhotos) }); - - // delete photo file from filesystem - const filename = photo.filepath.substr(photo.filepath.lastIndexOf('/') + 1); - await Filesystem.deleteFile({ - path: filename, - directory: Directory.Data, - }); - setPhotos(newPhotos); -}; + + + {photos.map((photo) => ( + + {/* CHANGE: Add a click event listener to each image. */} + setPhotoToDelete(photo)} /> + + ))} + + ``` -The selected photo is removed from the Photos array first. Then, we use the Capacitor Preferences API to update the cached version of the Photos array. Finally, we delete the actual photo file itself using the Filesystem API. - -Make sure to return the `deletePhoto` function so it is as a part of the hook API that we expose: +Remember that removing the photo from the `photos` array triggers the `setPhotos` method for us automatically. -```tsx -return { - photos, - takePhoto, - deletePhoto, -}; -``` +Tap on a photo again and choose the “Delete” option. The photo is deleted! Implemented much faster using Live Reload. 💪 -Save this file, then tap on a photo again and choose the “Delete” option. This time, the photo is deleted! Implemented much faster using Live Reload. 💪 +:::note +Remember, you can find the complete source code for this app [here](https://github.com/ionic-team/tutorial-photo-gallery-react). +::: In the final portion of this tutorial, we’ll walk you through the basics of the Appflow product used to build and deploy your application to users' devices. diff --git a/docs/react/your-first-app/8-distribute.md b/docs/react/your-first-app/8-distribute.md index 398f572b64b..204b065650f 100644 --- a/docs/react/your-first-app/8-distribute.md +++ b/docs/react/your-first-app/8-distribute.md @@ -1,8 +1,15 @@ --- +title: Build and Distribute your App sidebar_label: Distribute --- -# Build and Deploy your App + + Build and Deploy your App with React | Ionic Capacitor Camera + + Now that you have built your first app, you are going to want to get it distributed so everyone can start using it. The mechanics of building and deploying your application can be quite cumbersome. That is where [Appflow](https://ionic.io/docs/appflow/) comes into play. Appflow allows you to effectively generate web and native builds, push out live app updates, publish your app to the app stores, and automate the whole process. The entire Quickstart guide can be found [here](https://ionic.io/docs/appflow/quickstart). @@ -63,7 +70,7 @@ To dive into more details on the steps to deploy a live update, as well as addit Next up is a native binary for your app build and deploy process. This is done via the [Ionic Package](https://ionic.io/docs/appflow/package/intro) service. First things first, you will need to create a [Package build](https://ionic.io/docs/appflow/package/builds). This can be done by clicking the `Start build` icon from the `Commits` tab or by clicking the `New build` button in the top right from the `Build > Builds` tab. Then you will select the proper commit for your build and fill in all of the several required fields and any optional fields that you want to specify. After filling in all of the information and the build begins, you can check out it's progress and review the logs if you encounter any errors. -Given a successful Package build, and iOS binary (`.ipa` or IPA) or and Android binary (`.apk` or APK) file becomes available to you. The file can subsequently be downloaded so you can install it on a device by clicking the file name in the `Artifacts` section in the right of the build detail page or clicking the `Download IPA/APK` icon on the build in the `Build > Builds` tab. +Given a successful Package build, an iOS binary (`.ipa` or IPA) or/and an Android binary (`.apk` or APK) file becomes available to you. The file can subsequently be downloaded so you can install it on a device by clicking the file name in the `Artifacts` section in the right of the build detail page or clicking the `Download IPA/APK` icon on the build in the `Build > Builds` tab. Further information regarding building native binaries can be found inside of the [Build a Native Binary](https://ionic.io/docs/appflow/quickstart/package) section inside the Appflow docs. @@ -93,8 +100,8 @@ For access to the ability to create a Native Configuration, you will need to be ## What’s Next? -Congratulations! You developed a complete cross-platform Photo Gallery app that runs on the web, iOS, and Android. Not only that, you have also then built the app and deployed it to you users devices! +Congratulations! You developed a complete cross-platform Photo Gallery app that runs on the web, iOS, and Android. Not only that, you have also then built the app and deployed it to your users' devices! -There are many paths to follow from here. Try adding another [Ionic UI component](https://ionicframework.com/docs/components) to the app, or more [native functionality](https://capacitorjs.com/docs/apis). The sky’s the limit. Once you have added another feature run the build and deploy process again through Appflow to get it out to your users. +There are many paths to follow from here. Try adding another [Ionic UI component](../../components.md) to the app, or more [native functionality](https://capacitorjs.com/docs/apis). The sky’s the limit. Once you have added another feature, run the build and deploy process again through Appflow to get it out to your users. Happy app building! 💙 diff --git a/docs/techniques/security.md b/docs/techniques/security.md index 03268c4363a..30400ccc04f 100644 --- a/docs/techniques/security.md +++ b/docs/techniques/security.md @@ -3,27 +3,27 @@ title: Security --- - Security for Angular, React, and Vue Apps - Ionic Framework + Angular、React、Vueアプリのセキュリティ - Ionic Framework import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; -## Sanitizing User Input +## ユーザー入力のサニタイズ -For components such as `ion-alert` developers can allow for custom or user-provided content. This content can be plain text or HTML and should be considered untrusted. As with any untrusted input, it is important to sanitize it before doing anything else with it. In particular, using things like `innerHTML` without sanitization provides an attack vector for bad actors to input malicious content and potentially launch a [Cross Site Scripting attack (XSS)](https://en.wikipedia.org/wiki/Cross-site_scripting). +`ion-alert`などのコンポーネントでは、開発者はカスタムまたはユーザー提供のコンテンツを許可できます。このコンテンツはプレーンテキストまたは HTML であり、信頼できないものとして扱う必要があります。信頼できない入力と同様に、それを使用する前にサニタイズすることが重要です。特に、サニタイズせずに`innerHTML`のようなものを使用すると、悪意のある行為者が悪意のあるコンテンツを入力し、[クロスサイトスクリプティング攻撃(XSS)](https://en.wikipedia.org/wiki/Cross-site_scripting)を実行する攻撃ベクトルを提供する可能性があります。 -Ionic comes built in with a basic sanitization implementation for the components it provides. However, it is not a comprehensive solution. It is up to the developer to make sure all data that is passed is sanitized. Different frameworks have different solutions for sanitizing user input, so developers should familiarize themselves with what their specific framework offers. +Ionic には、提供するコンポーネント用の基本的なサニタイズ実装が組み込まれています。ただし、これは包括的なソリューションではありません。渡されるすべてのデータがサニタイズされていることを確認するのは開発者の責任です。異なるフレームワークには、ユーザー入力をサニタイズするための異なるソリューションがあるため、開発者は特定のフレームワークが提供する機能に精通する必要があります。 -For developers who are not using a framework, or for developers whose framework does not provide the sanitization methods they need, we recommend using [sanitize-html](https://www.npmjs.com/package/sanitize-html). This package provides a simple HTML sanitizer that allows the developer to specify the exact tags and attributes that they want to allow in their application. +フレームワークを使用していない開発者、またはフレームワークが必要なサニタイズメソッドを提供していない開発者には、[sanitize-html](https://www.npmjs.com/package/sanitize-html)の使用を推奨します。このパッケージは、開発者がアプリケーションで許可する正確なタグと属性を指定できるシンプルな HTML サニタイザーを提供します。 ### Angular -Angular comes built in with the `DomSanitizer` class. This helps prevent XSS issues by ensuring that values are safe to be used in the DOM. By default, Angular will mark any values it deems unsafe. For example, the following link would be marked as unsafe by Angular because it would attempt to execute some JavaScript. +Angular には`DomSanitizer`クラスが組み込まれています。これは、値が DOM で安全に使用できることを保証することで、XSS の問題を防ぐのに役立ちます。デフォルトでは、Angular は安全でないと判断した値をマークします。たとえば、以下のリンクは、JavaScript を実行しようとするため、Angular によって安全でないとマークされます。 ```tsx public myUrl: string = 'javascript:alert("oh no!")'; @@ -33,61 +33,61 @@ public myUrl: string = 'javascript:alert("oh no!")'; Click Me! ``` -To learn more about the built-in protections that Angular provides, see the [Angular Security Guide](https://angular.io/guide/security). +Angular が提供する組み込みの保護機能の詳細については、[Angular Security Guide](https://angular.io/guide/security)を参照してください。 ### React -React DOM escapes values embedded in JSX before rendering them by converting them to strings. For example, the following would be safe as `name` is converted to a string before being rendered: +React DOM は、JSX に埋め込まれた値を文字列に変換してからレンダリングする前にエスケープします。たとえば、以下の例では、`name`がレンダリングされる前に文字列に変換されるため、安全です: ```jsx const name = values.name; const element =

Hello, {name}!

; ``` -However, this does not stop someone from injecting JavaScript into places such as the `href` attribute of an anchor element. The following is unsafe and can potentially allow an XSS attack to occur: +ただし、これは誰かがアンカー要素の`href`属性などの場所に JavaScript を注入することを防ぐものではありません。以下は安全ではなく、XSS 攻撃が発生する可能性があります: ```jsx const userInput = 'javascript:alert("Oh no!")'; const element = Click Me!; ``` -If the developer needs to achieve more comprehensive sanitization, they can use the [sanitize-html](https://www.npmjs.com/package/sanitize-html) package. +開発者がより包括的なサニタイズを実現する必要がある場合は、[sanitize-html](https://www.npmjs.com/package/sanitize-html)パッケージを使用できます。 ### Vue -Vue does not provide any type of sanitizing methods built in. It is recommended that developers use a package such as [sanitize-html](https://www.npmjs.com/package/sanitize-html). +Vue は組み込みのサニタイズメソッドを提供していません。開発者は[sanitize-html](https://www.npmjs.com/package/sanitize-html)などのパッケージを使用することを推奨します。 -To learn more about the security recommendations for binding to directives such as `v-html`, see the [Vue Syntax Guide](https://vuejs.org/v2/guide/syntax.html#Raw-HTML). +`v-html`などのディレクティブにバインドする際のセキュリティ推奨事項の詳細については、[Vue Syntax Guide](https://vuejs.org/v2/guide/syntax.html#Raw-HTML)を参照してください。 -## Enabling Custom HTML Parsing via `innerHTML` +## `innerHTML`を介したカスタム HTML 解析の有効化 -`ion-alert`, `ion-infinite-scroll-content`, `ion-loading`, `ion-refresher-content`, and `ion-toast` can accept custom HTML as strings for certain properties. These strings are added to the DOM using `innerHTML` and must be properly sanitized by the developer. This behavior is disabled by default which means values passed to the affected components will always be interpreted as plaintext. Developers can enable this custom HTML behavior by setting `innerHTMLTemplatesEnabled: true` in the [IonicConfig](../developing/config#ionicconfig). +`ion-alert`、`ion-infinite-scroll-content`、`ion-loading`、`ion-refresher-content`、`ion-toast`は、特定のプロパティに対して文字列としてカスタム HTML を受け入れることができます。これらの文字列は`innerHTML`を使用して DOM に追加され、開発者が適切にサニタイズする必要があります。この動作はデフォルトで無効になっているため、影響を受けるコンポーネントに渡される値は常にプレーンテキストとして解釈されます。開発者は、[IonicConfig](../developing/config#ionicconfig)で`innerHTMLTemplatesEnabled: true`を設定することで、このカスタム HTML 動作を有効にできます。 -## Ejecting from the built-in sanitizer +## 組み込みサニタイザーからの除外 -For developers who wish to add complex HTML to components such as `ion-toast`, they will need to eject from the sanitizer that is built into Ionic Framework. Developers can either disable the sanitizer across their entire app or bypass it on a case-by-case basis. +`ion-toast`などのコンポーネントに複雑な HTML を追加したい開発者は、Ionic Framework に組み込まれているサニタイザーから除外する必要があります。開発者は、アプリ全体でサニタイザーを無効にするか、ケースバイケースでバイパスすることができます。 :::note -Bypassing sanitization functionality can make your application vulnerable to XSS attacks. Please exercise extreme caution when disabling the sanitizer. +サニタイズ機能をバイパスすると、アプリケーションがXSS 攻撃に対して脆弱になる可能性があります。サニタイザーを無効にする際は、十分に注意してください。 ::: -### Disabling the sanitizer via config +### 設定によるサニタイザーの無効化 -Ionic Framework provides an application config option called `sanitizerEnabled` that is set to `true` by default. Set this value to `false` to globally disable Ionic Framework's built in sanitizer. Please note that this does not disable any sanitizing functionality provided by other frameworks such as Angular. +Ionic Framework は、デフォルトで`true`に設定されている`sanitizerEnabled`というアプリケーション設定オプションを提供します。この値を`false`に設定すると、Ionic Framework の組み込みサニタイザーをグローバルに無効にできます。これは、Angular などの他のフレームワークが提供するサニタイズ機能を無効にしないことに注意してください。 -### Bypassing the sanitizer on a case-by-case basis +### ケースバイケースでサニタイザーをバイパス -Developers can also choose to eject from the sanitizer in certain scenarios. Ionic Framework provides the `IonicSafeString` class that allows developers to do just that. +開発者は、特定のシナリオでサニタイザーから除外することも選択できます。Ionic Framework は、開発者がこれを行うことを可能にする`IonicSafeString`クラスを提供します。 :::note -In order to bypass the sanitizer and use unsanitized custom HTML in the relevant Ionic components, `innerHTMLTemplatesEnabled` must be set to `true` in the Ionic config. +サニタイザーをバイパスして、関連する Ionic コンポーネントでサニタイズされていないカスタム HTML を使用するには、Ionic 設定で`innerHTMLTemplatesEnabled`を`true`に設定する必要があります。 -`IonicSafeString` should not be used if `innerHTMLTemplatesEnabled` is set to `false`. +`innerHTMLTemplatesEnabled`が`false`に設定されている場合、`IonicSafeString`を使用しないでください。 -See [Enabling Custom HTML Parsing](#enabling-custom-html-parsing-via-innerhtml) for more information. +詳細については、[カスタム HTML 解析の有効化](#enabling-custom-html-parsing-via-innerhtml)を参照してください。 ::: -#### Usage +#### 使用方法 ````mdx-code-block { ```` -## Content Security Policies (CSP) +## コンテンツセキュリティポリシー(CSP) -A [Content Security Policy (CSP)](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) is a security mechanism that helps protect web applications against certain types of attacks, such as cross-site scripting (XSS) and data injection. It is implemented through an HTTP header that instructs the browser on which sources of content, such as scripts, stylesheets, and images, are allowed to be loaded and executed on a web page. +[コンテンツセキュリティポリシー(CSP)](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP)は、クロスサイトスクリプティング(XSS)やデータインジェクションなどの特定のタイプの攻撃から Web アプリケーションを保護するのに役立つセキュリティメカニズムです。これは、スクリプト、スタイルシート、画像などのコンテンツのソースを、Web ページで読み込みおよび実行できるようにするかどうかをブラウザに指示する HTTP ヘッダーを通じて実装されます。 -The main purpose of a CSP is to mitigate the risks associated with code injection attacks. By defining a policy, web developers can specify from which domains or sources the browser should allow the loading and execution of various types of content. This effectively limits the potential damage that can be caused by malicious scripts or unauthorized content. +CSP の主な目的は、コードインジェクション攻撃に関連するリスクを軽減することです。ポリシーを定義することで、Web 開発者は、ブラウザがさまざまなタイプのコンテンツの読み込みと実行を許可するドメインまたはソースを指定できます。これにより、悪意のあるスクリプトや不正なコンテンツによって引き起こされる可能性のある損害を効果的に制限できます。 -### Enabling CSPs +### CSP の有効化 -Developers can assign a CSP to their application by setting a meta tag with the policy details and the expected nonce value on script and style tags. +開発者は、ポリシーの詳細とスクリプトおよびスタイルタグの期待される nonce 値を含む meta タグを設定することで、アプリケーションに CSP を割り当てることができます。 ```html ``` -### Ionic and CSP +### Ionic と CSP -Ionic Framework provides a function to help developers set the nonce value used when constructing the web component stylesheets. This function should be called before any Ionic components are loaded. This is required to pass the nonce value to the web components so that they can be used in a CSP environment. +Ionic Framework は、Web コンポーネントのスタイルシートを構築する際に使用される nonce 値を設定するのに役立つ関数を提供します。この関数は、Ionic コンポーネントが読み込まれる前に呼び出す必要があります。これは、nonce 値を Web コンポーネントに渡して、CSP 環境で使用できるようにするために必要です。 ```ts import { setNonce } from '@ionic/core/loader'; @@ -211,23 +211,23 @@ setNonce('randomNonceGoesHere'); :::tip -In Angular this can be called in the `main.ts` file, before the application is bootstrapped. +Angular では、これはアプリケーションがブートストラップされる前に`main.ts`ファイルで呼び出すことができます。 ::: -For more information on how to use CSPs with Stencil web components, see the [Stencil documentation](https://stenciljs.com/docs/csp-nonce). +Stencil Web コンポーネントで CSP を使用する方法の詳細については、[Stencil documentation](https://stenciljs.com/docs/csp-nonce)を参照してください。 ### Angular -Starting in Angular 16, Angular provides two options for setting the nonce value. +Angular 16 以降、Angular は nonce 値を設定するための 2 つのオプションを提供します。 -1. Set the `ngCspNonce` attribute on the root application element as ``. Use this approach if you have access to server-side templating that can add the nonce both to the header and the `index.html` when constructing the response. -2. Provide the nonce using the [`CSP_NONCE`](https://angular.io/api/core/CSP_NONCE) injection token. Use this approach if you have access to the nonce at runtime and you want to be able to cache the `index.html`. +1. ルートアプリケーション要素に`ngCspNonce`属性を``として設定します。レスポンスを構築する際に、ヘッダーと`index.html`の両方に nonce を追加できるサーバーサイドテンプレートにアクセスできる場合は、このアプローチを使用します。 +2. [`CSP_NONCE`](https://angular.io/api/core/CSP_NONCE)インジェクショントークンを使用して nonce を提供します。実行時に nonce にアクセスでき、`index.html`をキャッシュできるようにしたい場合は、このアプローチを使用します。 :::tip -If providing the `CSP_NONCE` injection token, set the provider in your `AppModule` for module projects or within the `bootstrapApplication` for standalone projects. +`CSP_NONCE`インジェクショントークンを提供する場合、モジュールプロジェクトの場合は`AppModule`にプロバイダーを設定し、スタンドアロンプロジェクトの場合は`bootstrapApplication`内に設定します。 ::: -For more information on how to use CSPs with Angular, see the [Angular documentation](https://angular.io/guide/security#content-security-policy). +Angular で CSP を使用する方法の詳細については、[Angular documentation](https://angular.io/guide/security#content-security-policy)を参照してください。 diff --git a/docs/theming/advanced.md b/docs/theming/advanced.md index 6aca26f34c2..393a98d5674 100644 --- a/docs/theming/advanced.md +++ b/docs/theming/advanced.md @@ -6,10 +6,10 @@ sidebar_label: 高度なカスタマイズ import CodeColor from '@components/page/theming/CodeColor'; - 高度なカスタマイズ: Quickly Customize App Colors using CSS | Ionic + 高度なカスタマイズ: CSSを使用してアプリの色をすばやくカスタマイズ | Ionic @@ -52,35 +52,35 @@ iOS 15 と macOS の Safari は自動的に適切なテーマカラーを決定 テーマセクションのアプリケーション変数とステップ変数は、アプリケーションの色を変更するのに便利ですが、しばしば、複数のコンポーネントで使用される変数が必要になることがあります。以下の変数は、コンポーネント間で共有され、グローバルなパディング設定などを変更することができます。 -### Application Variables - -| Name | Description | -| --------------------------- | ---------------------------------------------------------------------------------------------------- | -| `--ion-font-family` | Font family of the app | -| `--ion-statusbar-padding` | Statusbar padding top of the app | -| `--ion-safe-area-top` | Adjust the safe area inset top of the app | -| `--ion-safe-area-right` | Adjust the safe area inset right of the app | -| `--ion-safe-area-bottom` | Adjust the safe area inset bottom of the app | -| `--ion-safe-area-left` | Adjust the safe area inset left of the app | -| `--ion-margin` | Adjust the margin of the [Margin attributes](../layout/css-utilities.md#element-margin) | -| `--ion-padding` | Adjust the padding of the [Padding attributes](../layout/css-utilities.md#element-padding) | -| `--ion-placeholder-opacity` | Adjust the opacity of the placeholders used in the input, textarea, searchbar, and select components | - -### Grid Variables - -| Name | Description | -| ------------------------------ | ---------------------------------------------- | -| `--ion-grid-columns` | Number of columns in the grid | -| `--ion-grid-padding-xs` | Padding of the grid for xs breakpoints | -| `--ion-grid-padding-sm` | Padding of the grid for sm breakpoints | -| `--ion-grid-padding-md` | Padding of the grid for md breakpoints | -| `--ion-grid-padding-lg` | Padding of the grid for lg breakpoints | -| `--ion-grid-padding-xl` | Padding of the grid for xl breakpoints | -| `--ion-grid-column-padding-xs` | Padding of the grid columns for xs breakpoints | -| `--ion-grid-column-padding-sm` | Padding of the grid columns for sm breakpoints | -| `--ion-grid-column-padding-md` | Padding of the grid columns for md breakpoints | -| `--ion-grid-column-padding-lg` | Padding of the grid columns for lg breakpoints | -| `--ion-grid-column-padding-xl` | Padding of the grid columns for xl breakpoints | +### アプリケーション変数 + +| Name | 説明 | +| --------------------------- | --------------------------------------------------------------------------------------------- | +| `--ion-font-family` | アプリのフォントファミリー | +| `--ion-statusbar-padding` | アプリのステータスバーの上部パディング | +| `--ion-safe-area-top` | アプリのセーフエリアインセット上部を調整 | +| `--ion-safe-area-right` | アプリのセーフエリアインセット右側を調整 | +| `--ion-safe-area-bottom` | アプリのセーフエリアインセット下部を調整 | +| `--ion-safe-area-left` | アプリのセーフエリアインセット左側を調整 | +| `--ion-margin` | [Margin 属性](../layout/css-utilities.md#element-margin)のマージンを調整 | +| `--ion-padding` | [Padding 属性](../layout/css-utilities.md#element-padding)のパディングを調整 | +| `--ion-placeholder-opacity` | input、textarea、searchbar、select コンポーネントで使用されるプレースホルダーの不透明度を調整 | + +### グリッド変数 + +| Name | 説明 | +| ------------------------------ | ------------------------------------------- | +| `--ion-grid-columns` | グリッドの列数 | +| `--ion-grid-padding-xs` | xs ブレークポイントのグリッドのパディング | +| `--ion-grid-padding-sm` | sm ブレークポイントのグリッドのパディング | +| `--ion-grid-padding-md` | md ブレークポイントのグリッドのパディング | +| `--ion-grid-padding-lg` | lg ブレークポイントのグリッドのパディング | +| `--ion-grid-padding-xl` | xl ブレークポイントのグリッドのパディング | +| `--ion-grid-column-padding-xs` | xs ブレークポイントのグリッド列のパディング | +| `--ion-grid-column-padding-sm` | sm ブレークポイントのグリッド列のパディング | +| `--ion-grid-column-padding-md` | md ブレークポイントのグリッド列のパディング | +| `--ion-grid-column-padding-lg` | lg ブレークポイントのグリッド列のパディング | +| `--ion-grid-column-padding-xl` | xl ブレークポイントのグリッド列のパディング | ## 既知の変数の制限 @@ -163,9 +163,9 @@ $text-darker: darken($text, 15); $text-lighter: lighten($text, 15); ``` -After running through the Sass compiler, the colors will have the following values: +Sass コンパイラを実行した後、色は次の値になります: -| Variable | Value | +| Variable | 値 | | ------------------- | ---------------------------------------------- | | `$background` | #0054e9 | | `$background-shade` | #004acd | @@ -178,23 +178,23 @@ After running through the Sass compiler, the colors will have the following valu これは通常は問題にはなりませんが、アプリケーションに動的なテーマカラーの設定が必要な場合は問題になります。Ionic では、これが[各色にバリエーションがある](colors.md#layered-colors)理由であり、テーマ設定に[stepped colors](themes.md#stepped-colors)が必要な理由でもあります。 -There are drafts and issues discussing [color modification proposals](https://github.com/w3c/csswg-drafts/issues/3187) that would make this possible. +これを可能にする[色の変更提案](https://github.com/w3c/csswg-drafts/issues/3187)について議論しているドラフトとイシューがあります。 -## Safe Area Padding +## セーフエリアパディング -The safe area of a display is the section that is not covered by the device's notch, status bar, or other elements that are part of the device's UI and not the app's. The dimensions of the safe area are different across devices and orientations (portrait or landscape). +ディスプレイのセーフエリアは、デバイスのノッチ、ステータスバー、またはデバイスの UI の一部でありアプリの一部ではないその他の要素によって覆われていないセクションです。セーフエリアの寸法は、デバイスや向き(縦向きまたは横向き)によって異なります。 -For example, below are screenshots of an iPhone 14 Pro Max. The red section is the safe area, and the white sections are places where the app's content would be covered up. +たとえば、以下は iPhone 14 Pro Max のスクリーンショットです。赤いセクションがセーフエリアで、白いセクションはアプリのコンテンツが覆われる場所です。 | Portrait | Landscape | | ------------------------------------------------------------------------------ | -------------------------------------------------------------------------------- | | | | -To accommodate this, Ionic automatically adds padding to certain components. For example, the first `ion-toolbar` component placed in an `ion-modal` will receive padding according to the top edge of the device's safe area. This avoids the device's notch covering up the header text. +これに対応するため、Ionic は特定のコンポーネントに自動的にパディングを追加します。たとえば、`ion-modal`内に配置された最初の`ion-toolbar`コンポーネントは、デバイスのセーフエリアの上端に応じてパディングを受け取ります。これにより、デバイスのノッチがヘッダーテキストを覆うことを防ぎます。 -This padding can be manually adjusted through CSS using the `--ion-safe-area-(dir)` variables described in [Application Variables](#application-variables). Values can be set for the whole application, or on a per component basis. For example: +このパディングは、[アプリケーション変数](#application-variables)で説明されている`--ion-safe-area-(dir)`変数を使用して CSS で手動で調整できます。値はアプリケーション全体、またはコンポーネントごとに設定できます。例: ```css html { diff --git a/docs/theming/basics.md b/docs/theming/basics.md index cac6f1a4b55..cfdcb522ea9 100644 --- a/docs/theming/basics.md +++ b/docs/theming/basics.md @@ -9,7 +9,7 @@ import ColorAccordion from '@components/page/theming/ColorAccordion'; テーマ | Ionic Apps: Color and Theming Basics Definition @@ -23,7 +23,7 @@ Ionic には 9 つのデフォルトカラーがあり、多くのコンポー -## Platform Standards +## プラットフォーム標準 Ionic コンポーネントは、アプリが動作しているプラットフォームに応じて、見た目や動作を調整します。私たちはこれを **Adaptive Styling** と呼んでいます。これにより、開発者は複数のプラットフォームで同じコードベースを使用しながら、特定のプラットフォームで「ネイティブ」な外観のアプリを構築することができます。 diff --git a/docs/theming/colors.md b/docs/theming/colors.md index ae33c93be46..7dd13657f38 100644 --- a/docs/theming/colors.md +++ b/docs/theming/colors.md @@ -7,10 +7,10 @@ import NewColorGenerator from '@components/page/theming/NewColorGenerator'; import CodeColor from '@components/page/theming/CodeColor'; - Ionic CSS Color Component: Style or Change Default App Colors + Ionic CSS Colorコンポーネント: デフォルトアプリの色をスタイル設定または変更 @@ -37,7 +37,7 @@ Ionic には、多くのコンポーネントの配色を変更するために -## Modifying Colors +## 色の変更 配色を変更するときは、その色についてリストされているすべてのバリエーションを変更する必要があります。例えば、`secondary color` を に変更する時、以下の CSS プロパティが必要です。 @@ -107,7 +107,7 @@ div { CSS 変数の設定方法と使い方についての詳しい情報は [CSS Variables documentation](css-variables.md) をご覧ください。 -## New Color Creator +## 新しい色の作成 名前と値を変更して以下で新しい色を作成し、以下のコードをコピーしてプロジェクトに貼り付けることで、その配色を Ionic プロジェクトで利用できます。 diff --git a/docs/theming/css-shadow-parts.md b/docs/theming/css-shadow-parts.md index 0ac693f1fb3..a9a9d6f7855 100644 --- a/docs/theming/css-shadow-parts.md +++ b/docs/theming/css-shadow-parts.md @@ -3,10 +3,10 @@ title: CSS Shadow Parts --- - CSS Shadow Parts - Style CSS Properties Inside of A Shadow Tree + CSS Shadow Parts - シャドウツリー内のCSSプロパティをスタイル設定 @@ -41,7 +41,7 @@ ion-select .select-placeholder { } ``` -So how do we solve this? [CSS Shadow Parts](#shadow-parts-explained)! +では、どうすれば解決できるでしょうか?[CSS Shadow Parts](#shadow-parts-explained)です! ## Shadow Parts の説明 @@ -65,7 +65,7 @@ Shadow Parts は、開発者がシャドウツリーの外側から、シャド これらの Parts が公開されたことで、要素は [::part](#how-part-works) を使って直接スタイルを設定することができるようになりました。 -### How ::part works +### ::part の動作方法 `::part()` 擬似要素により、開発者はPart属性で公開されているシャドウツリー内の要素を選択することができます。 diff --git a/docs/theming/css-variables.md b/docs/theming/css-variables.md index 2a0392451fd..5cc824312f6 100644 --- a/docs/theming/css-variables.md +++ b/docs/theming/css-variables.md @@ -3,10 +3,10 @@ title: CSS変数 --- - CSS Variables | CSS Custom Properties for Variables & Components + CSS変数 | 変数とコンポーネント用のCSSカスタムプロパティ @@ -16,7 +16,7 @@ Ionic のコンポーネントは、アプリケーションを簡単にカス ### グローバル変数 -CSS 変数は、アプリケーションの `:root` セレクタでグローバルに設定できます。They can also be applied only for a specific mode. Ionic が提供するグローバル変数の詳細については、[Ionic 変数](#ionic-variables)を参照してください。 +CSS 変数は、アプリケーションの `:root` セレクタでグローバルに設定できます。特定のモードにのみ適用することもできます。Ionic が提供するグローバル変数の詳細については、[Ionic 変数](#ionic-variables)を参照してください。 Ionic CLI を使用して Angular、React、または Vue プロジェクトを開始すると Ionic のデフォルト変数を上書きすることができる `src/theme/variables.scss` が作成されます。 diff --git a/docs/theming/dark-mode.md b/docs/theming/dark-mode.md index b2cc7fd5d52..07b03fcf9da 100644 --- a/docs/theming/dark-mode.md +++ b/docs/theming/dark-mode.md @@ -8,16 +8,16 @@ import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; - ダークモード to Change Color Schemes and CSS Properties + ダークモード: カラースキームとCSSプロパティを変更 Ionic では、ダークな配色をサポートするなど、アプリのパレットを簡単に変更できます。ダークモードは、アプリのすべてのビューをダークパレットに変更する表示設定です。iOS と Android でシステム全体でサポートされているため、開発者にとってアプリに追加することが非常に望ましいです。 -## Enabling Dark Palette +## ダークパレットを有効にする アプリでダークパレットを有効にする方法は 3 つあります: **always** ダークパレットを有効にする方法、**system** OS の設定に基づく方法、**class** CSS のクラスを使用する方法です。 @@ -172,8 +172,8 @@ import ClassDarkMode from '@site/static/usage/v8/theming/class-dark-mode/index.m -:::caution Important -The `.ion-palette-dark` class **must** be added to the `html` element in order to work with the imported dark palette. +:::caution 重要 +インポートされたダークパレットを機能させるには、`.ion-palette-dark`クラスを`html`要素に追加する**必要があります**。 ::: ## システム UI コンポーネントを調整する @@ -203,7 +203,7 @@ color-scheme: light dark; ::: :::note -For developers looking to customize the theme color under the status bar in Safari on iOS 15 or the toolbar in Safari on macOS, see [`theme-color` Meta](./advanced.md#theme-color-meta). +iOS 15 の Safari のステータスバーの下または macOS の Safari のツールバーのテーマカラーをカスタマイズしたい開発者は、[`theme-color` Meta](./advanced.md#theme-color-meta)を参照してください。 ::: ## Ionic Dark Palette @@ -216,55 +216,55 @@ Ionic には推奨のダークパレットがあり、3 種類の方法で有効 -The **always** dark palette behaves in the following ways: +**always**ダークパレットは、以下のように動作します: -1. Sets the [Ionic colors](colors.md) for all [modes](platform-styles.md#ionic-modes) to complement a dark palette in the `:root` selector. The [`:root`](https://developer.mozilla.org/en-US/docs/Web/CSS/:root) selector is identical to the selector `html`, except that its [specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity) is higher. -2. Setting variables for the dark palette on `ios` devices using the `:root.ios` selector. -3. Setting variables for the dark palette on `md` devices using the `:root.md` selector. +1. `:root`セレクタで、すべての[modes](platform-styles.md#ionic-modes)の[Ionic colors](colors.md)をダークパレットに補完するように設定します。[`:root`](https://developer.mozilla.org/en-US/docs/Web/CSS/:root)セレクタは、[specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity)が高いことを除いて、セレクタ`html`と同一です。 +2. `:root.ios`セレクタを使用して、`ios`デバイスでダークパレットの変数を設定します。 +3. `:root.md`セレクタを使用して、`md`デバイスでダークパレットの変数を設定します。 :::caution -It is important to pay attention to the specificity if you want to override any of the Ionic dark palette variables. For example, because the `--ion-item-background` variable is set for each mode, it cannot be overridden in the `:root` selector. A higher specificity selector, such as `:root.ios`, is required. +Ionic ダークパレット変数のいずれかをオーバーライドする場合は、specificity に注意することが重要です。たとえば、`--ion-item-background`変数は各モードで設定されているため、`:root`セレクタでオーバーライドできません。`:root.ios`などのより高い specificity セレクタが必要です。 ::: :::info -The contents of Ionic's dark palette can be [viewed on GitHub](https://github.com/ionic-team/ionic-framework/blob/main/core/src/css/palettes/dark.scss). The CSS used to apply the **always** dark palette can be found in the [repository](https://github.com/ionic-team/ionic-framework/blob/main/core/src/css/palettes/dark.always.scss). +Ionic のダークパレットの内容は[GitHub で確認できます](https://github.com/ionic-team/ionic-framework/blob/main/core/src/css/palettes/dark.scss)。**always**ダークパレットを適用するために使用される CSS は、[リポジトリ](https://github.com/ionic-team/ionic-framework/blob/main/core/src/css/palettes/dark.always.scss)で見つけることができます。 ::: -The **system** dark palette behaves in the following ways: +**system**ダークパレットは、以下のように動作します: -1. Sets the [Ionic colors](colors.md) for all [modes](platform-styles.md#ionic-modes) to complement a dark palette in the `:root` selector. The [`:root`](https://developer.mozilla.org/en-US/docs/Web/CSS/:root) selector is identical to the selector `html`, except that its [specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity) is higher. -2. Setting variables for the dark palette on `ios` devices using the `:root.ios` selector. -3. Setting variables for the dark palette on `md` devices using the `:root.md` selector. -4. Only applies these variables when the [CSS media query for `prefers-color-scheme`](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme) is `dark`. +1. `:root`セレクタで、すべての[modes](platform-styles.md#ionic-modes)の[Ionic colors](colors.md)をダークパレットに補完するように設定します。[`:root`](https://developer.mozilla.org/en-US/docs/Web/CSS/:root)セレクタは、[specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity)が高いことを除いて、セレクタ`html`と同一です。 +2. `:root.ios`セレクタを使用して、`ios`デバイスでダークパレットの変数を設定します。 +3. `:root.md`セレクタを使用して、`md`デバイスでダークパレットの変数を設定します。 +4. [CSS media query for `prefers-color-scheme`](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme)が`dark`の場合にのみ、これらの変数を適用します。 :::caution -It is important to pay attention to the specificity if you want to override any of the Ionic dark palette variables. For example, because the `--ion-item-background` variable is set for each mode, it cannot be overridden in the `:root` selector. A higher specificity selector, such as `:root.ios`, is required. +Ionic ダークパレット変数のいずれかをオーバーライドする場合は、specificity に注意することが重要です。たとえば、`--ion-item-background`変数は各モードで設定されているため、`:root`セレクタでオーバーライドできません。`:root.ios`などのより高い specificity セレクタが必要です。 ::: :::info -The contents of Ionic's dark palette can be [viewed on GitHub](https://github.com/ionic-team/ionic-framework/blob/main/core/src/css/palettes/dark.scss). The CSS used to apply the **system** dark palette can be found in the [repository](https://github.com/ionic-team/ionic-framework/blob/main/core/src/css/palettes/dark.system.scsss). +Ionic のダークパレットの内容は[GitHub で確認できます](https://github.com/ionic-team/ionic-framework/blob/main/core/src/css/palettes/dark.scss)。**system**ダークパレットを適用するために使用される CSS は、[リポジトリ](https://github.com/ionic-team/ionic-framework/blob/main/core/src/css/palettes/dark.system.scsss)で見つけることができます。 ::: -The **class** dark palette behaves in the following ways: +**class**ダークパレットは、以下のように動作します: -1. Sets the [Ionic colors](colors.md) for all [modes](platform-styles.md#ionic-modes) to complement a dark palette in the `.ion-palette-dark` selector. The `.ion-palette-dark` class must be added to the `html` element in an app. -2. Setting variables for the dark palette on `ios` devices using the `.ion-palette-dark.ios` selector. -3. Setting variables for the dark palette on `md` devices using the `.ion-palette-dark.md` selector. +1. `.ion-palette-dark`セレクタで、すべての[modes](platform-styles.md#ionic-modes)の[Ionic colors](colors.md)をダークパレットに補完するように設定します。`.ion-palette-dark`クラスは、アプリの`html`要素に追加する必要があります。 +2. `.ion-palette-dark.ios`セレクタを使用して、`ios`デバイスでダークパレットの変数を設定します。 +3. `.ion-palette-dark.md`セレクタを使用して、`md`デバイスでダークパレットの変数を設定します。 :::caution -It is important to pay attention to the specificity if you want to override any of the Ionic dark palette variables. For example, because the `--ion-item-background` variable is set for each mode, it cannot be overridden in the `.ion-palette-dark` selector. A higher specificity selector, such as `.ion-palette-dark.ios`, is required. +Ionic ダークパレット変数のいずれかをオーバーライドする場合は、specificity に注意することが重要です。たとえば、`--ion-item-background`変数は各モードで設定されているため、`.ion-palette-dark`セレクタでオーバーライドできません。`.ion-palette-dark.ios`などのより高い specificity セレクタが必要です。 ::: :::info -The contents of Ionic's dark palette can be [viewed on GitHub](https://github.com/ionic-team/ionic-framework/blob/main/core/src/css/palettes/dark.scss). The CSS used to apply the **class** dark palette can be found in the [repository](https://github.com/ionic-team/ionic-framework/blob/main/core/src/css/palettes/dark.class.scss). +Ionic のダークパレットの内容は[GitHub で確認できます](https://github.com/ionic-team/ionic-framework/blob/main/core/src/css/palettes/dark.scss)。**class**ダークパレットを適用するために使用される CSS は、[リポジトリ](https://github.com/ionic-team/ionic-framework/blob/main/core/src/css/palettes/dark.class.scss)で見つけることができます。 ::: diff --git a/docs/theming/high-contrast-mode.md b/docs/theming/high-contrast-mode.md index 148f7c72157..bae02d14dcc 100644 --- a/docs/theming/high-contrast-mode.md +++ b/docs/theming/high-contrast-mode.md @@ -6,26 +6,26 @@ import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; - High Contrast Mode to Increase Color Contrast + ハイコントラストモード: 色のコントラストを向上 -Ionic offers palettes with increased contrast for users with low vision. These palettes work by amplifying the contrast between foreground content, such as text, and background content, such as UI components. Ionic provides both light and dark variants for achieving high contrast. +Ionic は、視力の低いユーザー向けにコントラストを向上させたパレットを提供します。これらのパレットは、テキストなどの前景コンテンツと UI コンポーネントなどの背景コンテンツ間のコントラストを増幅することで機能します。Ionic は、ハイコントラストを実現するためにライトとダークの両方のバリアントを提供します。 -## Overview +## 概要 -The default palette in Ionic provides [Ionic colors](./colors.md) that meet [Level AA color contrast](https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum.html) as defined by Web Content Accessibility Guidelines (WCAG) when used with the appropriate contrast color. The [Ionic colors](./colors.md) in the high contrast palette have been updated to meet [Level AAA color contrast](https://www.w3.org/WAI/WCAG21/Understanding/contrast-enhanced.html) when used with the appropriate contrast color. Notably, improvements have been made to the contrast of UI components, including border, text, and background colors. However, it's important to note that within the high contrast palette, priority is given to text legibility. This means that if adjusting the contrast of a UI component against the page background would significantly compromise the contrast between the component's text and its background, the contrast of the UI component background will remain unchanged. +Ionic のデフォルトパレットは、適切なコントラストカラーと組み合わせて使用すると、Web Content Accessibility Guidelines(WCAG)で定義されている[Level AA 色コントラスト](https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum.html)を満たす[Ionic colors](./colors.md)を提供します。ハイコントラストパレットの[Ionic colors](./colors.md)は、適切なコントラストカラーと組み合わせて使用すると、[Level AAA 色コントラスト](https://www.w3.org/WAI/WCAG21/Understanding/contrast-enhanced.html)を満たすように更新されています。特に、ボーダー、テキスト、背景色を含む UI コンポーネントのコントラストが改善されています。ただし、ハイコントラストパレット内では、テキストの可読性が優先されることに注意することが重要です。これは、ページの背景に対する UI コンポーネントのコントラストを調整すると、コンポーネントのテキストとその背景間のコントラストが大幅に損なわれる場合、UI コンポーネントの背景のコントラストは変更されないままになることを意味します。 -## Enabling High Contrast Theme +## ハイコントラストテーマを有効にする -There are three provided ways to enable the high contrast palette in an app: **always**, based on **system** settings, or by using a CSS **class**. +アプリでハイコントラストパレットを有効にする方法は 3 つあります:**always**、**system**設定に基づく方法、または CSS**class**を使用する方法です。 ### Always -The high contrast palette can be enabled by importing the following stylesheet in the appropriate files. This approach will enable the high contrast palette regardless of the system settings for contrast preference. +ハイコントラストパレットは、適切なファイルに以下のスタイルシートをインポートすることで有効にできます。このアプローチは、コントラスト設定のシステム設定に関係なく、ハイコントラストパレットを有効にします。 @@ -64,9 +64,9 @@ import '@ionic/vue/css/palettes/high-contrast.always.css'; // Light palette -The high contrast dark palette can be applied by importing `high-contrast-dark.always.css` instead of `high-contrast.always.css`. +ハイコントラストダークパレットは、`high-contrast.always.css`の代わりに`high-contrast-dark.always.css`をインポートすることで適用できます。 -The following example will always display the high contrast light palette, regardless of the user's preference for high contrast or dark mode. +以下の例は、ユーザーのハイコントラストまたはダークモードの設定に関係なく、常にハイコントラストライトパレットを表示します。 import AlwaysHighContrastMode from '@site/static/usage/v8/theming/always-high-contrast-mode/index.md'; @@ -74,9 +74,9 @@ import AlwaysHighContrastMode from '@site/static/usage/v8/theming/always-high-co ### System -The system approach to enabling high contrast mode involves checking the system settings for the user's preferred contrast. This is the default when starting a new Ionic Framework app. Importing the following stylesheets in the appropriate file will automatically retrieve the user's preference from the system settings and apply the high contrast palette when high contrast is preferred. +ハイコントラストモードを有効にするシステムアプローチでは、ユーザーの好みのコントラストをシステム設定で確認します。これは、新しい Ionic Framework アプリを起動するときのデフォルトです。適切なファイルに以下のスタイルシートをインポートすると、システム設定からユーザーの好みを自動的に取得し、ハイコントラストが優先される場合にハイコントラストパレットを適用します。 -The following example shows how to include both the high contrast light palette as well as the high contrast dark palette. The system's dark mode preference will be checked to show either the light or dark variant of the high contrast palette. +以下の例は、ハイコントラストライトパレットとハイコントラストダークパレットの両方を含める方法を示しています。システムのダークモード設定が確認され、ハイコントラストパレットのライトまたはダークバリアントが表示されます。 @@ -115,12 +115,12 @@ import '@ionic/vue/css/palettes/high-contrast-dark.system.css'; -This approach activates the high contrast palette when the [CSS media query for `prefers-contrast`](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-contrast) is `more`. The `prefers-contrast` media query is supported by [all modern browsers](https://caniuse.com/?search=prefers-contrast). If support for an older browser is required, we recommend using the [CSS class](#css-class) approach. +このアプローチは、[CSS media query for `prefers-contrast`](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-contrast)が`more`の場合にハイコントラストパレットをアクティブにします。`prefers-contrast`メディアクエリは[すべてのモダンブラウザ](https://caniuse.com/?search=prefers-contrast)でサポートされています。古いブラウザのサポートが必要な場合は、[CSS class](#css-class)アプローチを使用することをお勧めします。 -The following example uses the system settings to decide when to show high contrast mode. +以下の例は、ハイコントラストモードを表示するタイミングを決定するためにシステム設定を使用しています。 :::info -Not sure how to change the system settings? Here's how to enable high contrast mode on [Windows 11](https://support.microsoft.com/en-us/windows/turn-high-contrast-mode-on-or-off-in-windows-909e9d89-a0f9-a3a9-b993-7a6dcee85025) and on [macOS](https://support.apple.com/guide/mac-help/change-display-settings-for-accessibility-unac089/mac). +システム設定の変更方法がわからないですか?[Windows 11](https://support.microsoft.com/en-us/windows/turn-high-contrast-mode-on-or-off-in-windows-909e9d89-a0f9-a3a9-b993-7a6dcee85025)と[macOS](https://support.apple.com/guide/mac-help/change-display-settings-for-accessibility-unac089/mac)でハイコントラストモードを有効にする方法はこちらです。 ::: import SystemHighContrastMode from '@site/static/usage/v8/theming/system-high-contrast-mode/index.md'; @@ -128,13 +128,13 @@ import SystemHighContrastMode from '@site/static/usage/v8/theming/system-high-co :::caution -The high contrast light palette must be imported after [core.css](../layout/global-stylesheets.md#corecss), and the -high contrast dark palette must be imported after `dark.system.css`. Otherwise, the standard contrast palette will take priority. +ハイコントラストライトパレットは[core.css](../layout/global-stylesheets.md#corecss)の後にインポートする必要があり、 +ハイコントラストダークパレットは`dark.system.css`の後にインポートする必要があります。そうしないと、標準のコントラストパレットが優先されます。 ::: ### CSS Class -While the previous approaches are excellent for enabling the high contrast palette through file imports alone, there are scenarios where you may need more control over where it is applied. In cases where you need to apply the high contrast palette conditionally, such as through a toggle, or if you want to extend the functionality based on system settings, we provide a high contrast palette class file. This file applies the high contrast palette when a specific class is added to an app. Importing the following stylesheets into the appropriate file will provide the necessary styles for using the high contrast palette with the class: +以前のアプローチは、ファイルのインポートだけでハイコントラストパレットを有効にするのに優れていますが、適用場所をより制御する必要があるシナリオもあります。トグルなどを通じてハイコントラストパレットを条件付きで適用する必要がある場合、またはシステム設定に基づいて機能を拡張したい場合、ハイコントラストパレットクラスファイルを提供します。このファイルは、特定のクラスがアプリに追加されたときにハイコントラストパレットを適用します。適切なファイルに以下のスタイルシートをインポートすると、クラスでハイコントラストパレットを使用するために必要なスタイルが提供されます: @@ -173,12 +173,12 @@ import '@ionic/vue/css/palettes/high-contrast-dark.class.css'; -This approach activates the high contrast palette when the `.ion-palette-high-contrast` class is set on the `html` element. This class must be applied by the developer. This can be combined with the [`.ion-palette-dark` class](./dark-mode.md#css-class) to conditionally apply the high contrast dark palette. +このアプローチは、`.ion-palette-high-contrast`クラスが`html`要素に設定されている場合にハイコントラストパレットをアクティブにします。このクラスは開発者が適用する必要があります。これは[`.ion-palette-dark`クラス](./dark-mode.md#css-class)と組み合わせて、条件付きでハイコントラストダークパレットを適用できます。 -The following example combines site settings, system settings, and the toggle to decide when to show high contrast mode. The site's palette takes precedence over system settings. If your system settings differ from the site's palette when the demo loads, it will use the site's palette. +以下の例は、サイト設定、システム設定、トグルを組み合わせて、ハイコントラストモードを表示するタイミングを決定しています。サイトのパレットはシステム設定よりも優先されます。デモのロード時にシステム設定がサイトのパレットと異なる場合、サイトのパレットが使用されます。 :::info -Not sure how to change the system settings? Here's how to enable high contrast mode on [Windows 11](https://support.microsoft.com/en-us/windows/turn-high-contrast-mode-on-or-off-in-windows-909e9d89-a0f9-a3a9-b993-7a6dcee85025) and on [macOS](https://support.apple.com/guide/mac-help/change-display-settings-for-accessibility-unac089/mac). +システム設定の変更方法がわからないですか?[Windows 11](https://support.microsoft.com/en-us/windows/turn-high-contrast-mode-on-or-off-in-windows-909e9d89-a0f9-a3a9-b993-7a6dcee85025)と[macOS](https://support.apple.com/guide/mac-help/change-display-settings-for-accessibility-unac089/mac)でハイコントラストモードを有効にする方法はこちらです。 ::: import ClassHighContrastMode from '@site/static/usage/v8/theming/class-high-contrast-mode/index.md'; @@ -186,59 +186,59 @@ import ClassHighContrastMode from '@site/static/usage/v8/theming/class-high-cont :::caution -The high contrast light palette must be imported after [core.css](../layout/global-stylesheets.md#corecss), -and the high contrast dark palette must be imported after `dark.class.css`. Otherwise, the standard contrast palette will take -priority. +ハイコントラストライトパレットは[core.css](../layout/global-stylesheets.md#corecss)の後にインポートする必要があり、 +ハイコントラストダークパレットは`dark.class.css`の後にインポートする必要があります。 +そうしないと、標準のコントラストパレットが優先されます。 ::: :::caution -The `.ion-palette-high-contrast` class **must** be added to the `html` element in order to work with the imported high contrast palette. +インポートされたハイコントラストパレットを機能させるには、`.ion-palette-high-contrast`クラスを`html`要素に追加する**必要があります**。 ::: -## Customizing Ionic High Contrast Theme +## Ionic ハイコントラストテーマのカスタマイズ -Ionic has a recommended high contrast palette that can be enabled in three different ways: [always](#always), based on [system](#system) settings, or by using a [CSS class](#css-class). Each of these methods involves importing the high contrast palette file with the corresponding name. +Ionic には、3 つの異なる方法で有効にできる推奨のハイコントラストパレットがあります:[always](#always)、[system](#system)設定に基づく方法、または[CSS class](#css-class)を使用する方法です。これらの各方法には、対応する名前のハイコントラストパレットファイルをインポートすることが含まれます。 -The theme variables are set by importing the relevant high contrast palette file and do not need to be copied into an app. For more information on the variables being changed, including additional variables for further customization, refer to the [Themes](themes.md) section. +テーマ変数は、関連するハイコントラストパレットファイルをインポートすることで設定され、アプリにコピーする必要はありません。変更される変数、さらなるカスタマイズのための追加変数を含む詳細については、[Themes](themes.md)セクションを参照してください。 -The following provides details on how to customize the high contrast palette depending on how it was applied in an application. +以下は、アプリケーションで適用された方法に応じてハイコントラストパレットをカスタマイズする方法の詳細を提供します。 -The **always** high contrast palette can be accessed by importing `high-contrast.always.css` for the light variant and `high-contrast-dark.always.css` for the dark variant. +**always**ハイコントラストパレットは、ライトバリアントには`high-contrast.always.css`を、ダークバリアントには`high-contrast-dark.always.css`をインポートすることでアクセスできます。 -The **always** high contrast palette behaves in the following ways: +**always**ハイコントラストパレットは、以下のように動作します: -1. Sets the [Ionic colors](colors.md) for all [modes](platform-styles.md#ionic-modes) to complement a high contrast palette in the `:root` selector. The [`:root`](https://developer.mozilla.org/en-US/docs/Web/CSS/:root) selector is identical to the selector `html`, except that its [specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity) is higher. -2. Setting variables for the high contrast palette on `ios` devices using the `:root.ios` selector. -3. Setting variables for the high contrast palette on `md` devices using the `:root.md` selector. +1. `:root`セレクタで、すべての[modes](platform-styles.md#ionic-modes)の[Ionic colors](colors.md)をハイコントラストパレットに補完するように設定します。[`:root`](https://developer.mozilla.org/en-US/docs/Web/CSS/:root)セレクタは、[specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity)が高いことを除いて、セレクタ`html`と同一です。 +2. `:root.ios`セレクタを使用して、`ios`デバイスでハイコントラストパレットの変数を設定します。 +3. `:root.md`セレクタを使用して、`md`デバイスでハイコントラストパレットの変数を設定します。 -The **system** high contrast palette can be accessed by importing `high-contrast.system.css` for the light variant and `high-contrast-dark.system.css` for the dark variant. +**system**ハイコントラストパレットは、ライトバリアントには`high-contrast.system.css`を、ダークバリアントには`high-contrast-dark.system.css`をインポートすることでアクセスできます。 -The **system** high contrast palette behaves in the following ways: +**system**ハイコントラストパレットは、以下のように動作します: -1. Sets the [Ionic colors](colors.md) for all [modes](platform-styles.md#ionic-modes) to complement a high contrast palette in the `:root` selector. The [`:root`](https://developer.mozilla.org/en-US/docs/Web/CSS/:root) selector is identical to the selector `html`, except that its [specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity) is higher. -2. Setting variables for the high contrast palette on `ios` devices using the `:root.ios` selector. -3. Setting variables for the high contrast palette on `md` devices using the `:root.md` selector. -4. Only applies these variables when the [CSS media query for `prefers-contrast`](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-contrast) is `more`. +1. `:root`セレクタで、すべての[modes](platform-styles.md#ionic-modes)の[Ionic colors](colors.md)をハイコントラストパレットに補完するように設定します。[`:root`](https://developer.mozilla.org/en-US/docs/Web/CSS/:root)セレクタは、[specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity)が高いことを除いて、セレクタ`html`と同一です。 +2. `:root.ios`セレクタを使用して、`ios`デバイスでハイコントラストパレットの変数を設定します。 +3. `:root.md`セレクタを使用して、`md`デバイスでハイコントラストパレットの変数を設定します。 +4. [CSS media query for `prefers-contrast`](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-contrast)が`more`の場合にのみ、これらの変数を適用します。 -The **class** high contrast palette can be accessed by importing `high-contrast.class.css` for the light variant and `high-contrast-dark.class.css` for the dark variant. +**class**ハイコントラストパレットは、ライトバリアントには`high-contrast.class.css`を、ダークバリアントには`high-contrast-dark.class.css`をインポートすることでアクセスできます。 -The **class** high contrast palette behaves in the following ways: +**class**ハイコントラストパレットは、以下のように動作します: -1. Sets the [Ionic colors](colors.md) for all [modes](platform-styles.md#ionic-modes) to complement a high contrast palette in the `.ion-palette-high-contrast` selector. The `.ion-palette-high-contrast` class must be added to the `html` element in an app. -2. Setting variables for the high contrast palette on `ios` devices using the `.ion-palette-high-contrast.ios` selector. -3. Setting variables for the high contrast palette on `md` devices using the `.ion-palette-high-contrast.md` selector. +1. `.ion-palette-high-contrast`セレクタで、すべての[modes](platform-styles.md#ionic-modes)の[Ionic colors](colors.md)をハイコントラストパレットに補完するように設定します。`.ion-palette-high-contrast`クラスは、アプリの`html`要素に追加する必要があります。 +2. `.ion-palette-high-contrast.ios`セレクタを使用して、`ios`デバイスでハイコントラストパレットの変数を設定します。 +3. `.ion-palette-high-contrast.md`セレクタを使用して、`md`デバイスでハイコントラストパレットの変数を設定します。 diff --git a/docs/theming/platform-styles.md b/docs/theming/platform-styles.md index 2f3be9a87de..4ed0f680e05 100644 --- a/docs/theming/platform-styles.md +++ b/docs/theming/platform-styles.md @@ -3,10 +3,10 @@ title: プラットフォームの外観 --- - Ionic Platform Styles | Platform-Specific Styles for Ionic Apps + Ionicプラットフォームスタイル | Ionicアプリのプラットフォーム固有スタイル diff --git a/docs/theming/themes.md b/docs/theming/themes.md index e2044977914..6bea9d6407c 100644 --- a/docs/theming/themes.md +++ b/docs/theming/themes.md @@ -6,10 +6,10 @@ import CodeColor from '@components/page/theming/CodeColor'; import SteppedColorGenerator from '@components/page/theming/SteppedColorGenerator'; - Ionicアプリのテーマ | Change Default App Background Themes & Colors + Ionicアプリのテーマ | デフォルトアプリの背景テーマと色を変更 @@ -21,34 +21,34 @@ Ionic は、アプリケーション全体のデフォルトテーマを変更 背景とテキストの色変数は、RGB である必要があります: rgb format. なぜ `rgb` プロパティも必要であるかは [The Alpha Problem](advanced.md#the-alpha-problem) をご覧ください。 -| Name | Description | -| ------------------------------------------ | ---------------------------------------------------- | -| `--ion-background-color` | Background color of the entire app | -| `--ion-background-color-rgb` | Background color of the entire app, rgb format | -| `--ion-text-color` | Text color of the entire app | -| `--ion-text-color-rgb` | Text color of the entire app, rgb format | -| `--ion-backdrop-color` | Color of the Backdrop component | -| `--ion-backdrop-opacity` | Opacity of the Backdrop component | -| `--ion-overlay-background-color` | Background color of the overlays | -| `--ion-border-color` | Border color | -| `--ion-box-shadow-color` | Box shadow color | -| `--ion-tab-bar-background` | Background of the Tab Bar | -| `--ion-tab-bar-background-focused` | Background of the focused Tab Bar | -| `--ion-tab-bar-border-color` | Border color of the Tab Bar | -| `--ion-tab-bar-color` | Color of the Tab Bar | -| `--ion-tab-bar-color-selected` | Color of the selected Tab Button | -| `--ion-toolbar-background` | Background of the Toolbar | -| `--ion-toolbar-border-color` | Border color of the Toolbar | -| `--ion-toolbar-color` | Color of the components in the Toolbar | -| `--ion-toolbar-segment-color` | Color of the Segment Buttons in the Toolbar | -| `--ion-toolbar-segment-color-checked` | Color of the checked Segment Buttons in the Toolbar | -| `--ion-toolbar-segment-background` | Background of the Segment Buttons in the Toolbar | -| `--ion-toolbar-segment-background-checked` | Background of the Segment Buttons in the Toolbar | -| `--ion-toolbar-segment-indicator-color` | Color of the Segment Button indicator in the Toolbar | -| `--ion-item-background` | Background of the Item | -| `--ion-item-border-color` | Border color of the Item | -| `--ion-item-color` | Color of the components in the Item | -| `--ion-placeholder-color` | Color of the placeholder in Inputs | +| Name | 説明 | +| ------------------------------------------ | ------------------------------------------------- | +| `--ion-background-color` | アプリ全体の背景色 | +| `--ion-background-color-rgb` | アプリ全体の背景色、rgb 形式 | +| `--ion-text-color` | アプリ全体のテキスト色 | +| `--ion-text-color-rgb` | アプリ全体のテキスト色、rgb 形式 | +| `--ion-backdrop-color` | Backdrop コンポーネントの色 | +| `--ion-backdrop-opacity` | Backdrop コンポーネントの不透明度 | +| `--ion-overlay-background-color` | オーバーレイの背景色 | +| `--ion-border-color` | ボーダーの色 | +| `--ion-box-shadow-color` | ボックスシャドウの色 | +| `--ion-tab-bar-background` | Tab Bar の背景 | +| `--ion-tab-bar-background-focused` | フォーカスされた Tab Bar の背景 | +| `--ion-tab-bar-border-color` | Tab Bar のボーダー色 | +| `--ion-tab-bar-color` | Tab Bar の色 | +| `--ion-tab-bar-color-selected` | 選択された Tab Button の色 | +| `--ion-toolbar-background` | Toolbar の背景 | +| `--ion-toolbar-border-color` | Toolbar のボーダー色 | +| `--ion-toolbar-color` | Toolbar 内のコンポーネントの色 | +| `--ion-toolbar-segment-color` | Toolbar 内の Segment Buttons の色 | +| `--ion-toolbar-segment-color-checked` | Toolbar 内のチェックされた Segment Buttons の色 | +| `--ion-toolbar-segment-background` | Toolbar 内の Segment Buttons の背景 | +| `--ion-toolbar-segment-background-checked` | Toolbar 内のチェックされた Segment Buttons の背景 | +| `--ion-toolbar-segment-indicator-color` | Toolbar 内の Segment Button インジケーターの色 | +| `--ion-item-background` | Item の背景 | +| `--ion-item-border-color` | Item のボーダー色 | +| `--ion-item-color` | Item 内のコンポーネントの色 | +| `--ion-placeholder-color` | Input 内のプレースホルダーの色 | ### ステップカラー @@ -62,7 +62,7 @@ Ionic では、テキストカラーと背景カラーを別々に更新でき デフォルトでは、Ionic の段階的なテキストカラーは、デフォルトのテキストカラー値#000000 から始まり、背景カラー値#ffffff と増加するパーセンテージで混合します。Ionic の背景の段階的な色は、デフォルトの背景色値 #ffffff から始まり、増加する割合でテキスト色値 #000000 と混ざります。ステップカラーの完全なリストは、以下のジェネレータに示されています。 -## Stepped Color Generator +## ステップカラージェネレータ アプリのカスタム背景色とテキスト色のテーマを作成します。以下の背景色またはテキスト色の 16 進数値を更新し、生成されたコードを Ionic プロジェクトに直接コピー&ペーストしてください。 diff --git a/docs/utilities/animations.md b/docs/utilities/animations.md index 9c9515d00b3..4915b274dae 100644 --- a/docs/utilities/animations.md +++ b/docs/utilities/animations.md @@ -7,20 +7,20 @@ import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; - Animations: Web Animations API to Build and Run on Ionic Apps + アニメーション: IonicアプリでWeb Animations APIを使用してアニメーションを構築・実行 -## Overview +## 概要 -Ionic Animations is a tool that enables developers to create complex animations in a platform-agnostic manner, without requiring a specific framework or an Ionic app. +Ionic Animations は、特定のフレームワークや Ionic アプリを必要とせず、プラットフォームに依存しない方法で複雑なアニメーションを作成できるツールです。 -Creating efficient animations can be challenging, as developers are limited by the available libraries and hardware resources of the device. Moreover, many animation libraries use a JavaScript-driven approach, which can reduce the scalability of animations and use up CPU time. +効率的なアニメーションの作成は困難な場合があります。開発者は利用可能なライブラリとデバイスのハードウェアリソースに制限されるためです。さらに、多くのアニメーションライブラリは JavaScript 駆動のアプローチを使用しており、アニメーションのスケーラビリティを低下させ、CPU 時間を消費する可能性があります。 -Ionic Animations, on the other hand, uses the [Web Animations API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API), which offloads all the computation and running of animations to the browser. This approach allows the browser to optimize the animations and ensure their smooth execution. In cases where Web Animations are not supported, Ionic Animations will fall back to [CSS Animations](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Animations/Using_CSS_animations), which should have a negligible difference in performance. +一方、Ionic Animations は[Web Animations API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API)を使用しており、アニメーションの計算と実行をすべてブラウザにオフロードします。このアプローチにより、ブラウザはアニメーションを最適化し、スムーズな実行を保証できます。Web Animations がサポートされていない場合、Ionic Animations は[CSS Animations](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Animations/Using_CSS_animations)にフォールバックしますが、パフォーマンスの差は無視できる程度です。 ## Installation @@ -39,7 +39,7 @@ Ionic Animations, on the other hand, uses the [Web Animations API](https://devel }> -Developers using Ionic Core and JavaScript should install the latest version of `@ionic/core`. +Ionic CoreとJavaScriptを使用する開発者は、最新バージョンの`@ionic/core`をインストールする必要があります。 ```javascript import { createAnimation } from 'https://cdn.jsdelivr.net/npm/@ionic/core@latest/dist/esm/index.mjs'; @@ -56,7 +56,7 @@ const animation = createAnimation() -Developers using Ionic Core and TypeScript should install the latest version of `@ionic/core`. +Ionic CoreとTypeScriptを使用する開発者は、最新バージョンの`@ionic/core`をインストールする必要があります。 ```tsx import { createAnimation, Animation } from '@ionic/core'; @@ -72,7 +72,7 @@ const animation: Animation = createAnimation('') -Developers using Angular should install the latest version of `@ionic/angular`. Animations can be created via the `AnimationController` dependency injection. +Angularを使用する開発者は、最新バージョンの`@ionic/angular`をインストールする必要があります。アニメーションは`AnimationController`の依存性注入を介して作成できます。 ```tsx @@ -91,7 +91,7 @@ constructor(private animationCtrl: AnimationController) { -Developers using Angular should install the latest version of `@ionic/angular`. Animations can be created via the `AnimationController` dependency injection. +Angularを使用する開発者は、最新バージョンの`@ionic/angular`をインストールする必要があります。アニメーションは`AnimationController`の依存性注入を介して作成できます。 ```tsx @@ -110,7 +110,7 @@ constructor(private animationCtrl: AnimationController) { -Developers using React should install the latest version of `@ionic/react`. React wrappers are in beta. Please report any issues on GitHub! +Reactを使用する開発者は、最新バージョンの`@ionic/react`をインストールする必要があります。Reactラッパーはベータ版です。問題があればGitHubで報告してください! ```tsx @@ -133,7 +133,7 @@ import { CreateAnimation, Animation } from '@ionic/react'; -Developers using Ionic Vue should install the latest version of `@ionic/vue`. +Ionic Vueを使用する開発者は、最新バージョンの`@ionic/vue`をインストールする必要があります。 ```javascript import { createAnimation } from '@ionic/vue'; @@ -156,110 +156,110 @@ const animation = createAnimation() ```` -## Basic Animations +## 基本的なアニメーション -In the example below, an animation that changes the opacity on the `ion-card` element and moves it from left to right along the X axis has been created. This animation will run an infinite number of times, and each iteration of the animation will last 1500ms. +以下の例では、`ion-card`要素の不透明度を変更し、X 軸に沿って左から右に移動するアニメーションが作成されています。このアニメーションは無限に実行され、各反復は 1500ms 続きます。 -By default, all Ionic Animations are paused until the `play` method is called. +デフォルトでは、すべての Ionic Animations は`play`メソッドが呼び出されるまで一時停止しています。 import Basic from '@site/static/usage/v8/animations/basic/index.md'; -## Keyframe Animations +## キーフレームアニメーション -Ionic Animations allows you to control the intermediate steps in an animation using keyframes. Any valid CSS property can be used here, and you can even use CSS Variables as values. +Ionic Animations では、キーフレームを使用してアニメーションの中間ステップを制御できます。ここでは任意の有効な CSS プロパティを使用でき、値として CSS 変数も使用できます。 -Hyphenated CSS properties should be written using camel case when writing keyframes. For example, `border-radius` should be written as `borderRadius`. This also applies to the `fromTo()`, `from(),` and `to()` methods. +キーフレームを記述する際、ハイフン付きの CSS プロパティはキャメルケースで記述する必要があります。たとえば、`border-radius`は`borderRadius`として記述する必要があります。これは`fromTo()`、`from()`、`to()`メソッドにも適用されます。 import Keyframes from '@site/static/usage/v8/animations/keyframes/index.md'; -In the example above, the card element will transition from its initial width, to a width defined by the `--width` variable, and then transition on to the final width. +上記の例では、カード要素は初期幅から`--width`変数で定義された幅に遷移し、その後最終的な幅に遷移します。 -Each keyframe object contains an `offset` property. `offset` is a value between 0 and 1 that defines the keyframe step. Offset values must go in ascending order and cannot repeat. +各キーフレームオブジェクトには`offset`プロパティが含まれています。`offset`は、キーフレームステップを定義する 0 から 1 の間の値です。オフセット値は昇順でなければならず、繰り返すことはできません。 -## Grouped Animations +## グループ化されたアニメーション -Multiple elements can be animated at the same time and controlled via a single parent animation object. Child animations inherit properties such as duration, easing, and iterations unless otherwise specified. A parent animation's `onFinish` callback will not be called until all child animations have completed. +複数の要素を同時にアニメーション化し、単一の親アニメーションオブジェクトで制御できます。子アニメーションは、特に指定がない限り、duration、easing、iterations などのプロパティを継承します。親アニメーションの`onFinish`コールバックは、すべての子アニメーションが完了するまで呼び出されません。 -This example shows 3 child animations controlled by a single parent animation. Animations `cardA` and `cardB` inherit the parent animation's duration of 2000ms, but animation `cardC` has a duration of 5000ms since it was explicitly set. +この例では、単一の親アニメーションによって制御される 3 つの子アニメーションを示しています。アニメーション`cardA`と`cardB`は親アニメーションの 2000ms の duration を継承しますが、アニメーション`cardC`は明示的に設定されているため、duration は 5000ms です。 import Group from '@site/static/usage/v8/animations/group/index.md'; -## Before and After Hooks +## Before/After フック -Ionic Animations provides hooks that let you alter an element before an animation runs and after an animation completes. These hooks can be used to perform DOM reads and writes as well as add or remove classes and inline styles. +Ionic Animations は、アニメーションが実行される前とアニメーションが完了した後に要素を変更できるフックを提供します。これらのフックは、DOM の読み取りと書き込み、クラスやインラインスタイルの追加や削除に使用できます。 -This example sets an inline filter which inverts the background color of the card by `75%` prior to the animation starting. Once the animation finishes, the box shadow on the element is set to `rgba(255, 0, 50, 0.4) 0px 4px 16px 6px`, a red glow, and the inline filter is cleared. The animation must be stopped in order to remove the box shadow and play it with the filter again. +この例では、アニメーション開始前にカードの背景色を`75%`反転させるインラインフィルターを設定しています。アニメーションが終了すると、要素のボックスシャドウが`rgba(255, 0, 50, 0.4) 0px 4px 16px 6px`(赤いグロー)に設定され、インラインフィルターがクリアされます。ボックスシャドウを削除してフィルターを再度適用するには、アニメーションを停止する必要があります。 -See [Methods](#methods) for a complete list of hooks. +フックの完全なリストについては、[Methods](#methods)を参照してください。 import BeforeAndAfterHooks from '@site/static/usage/v8/animations/before-and-after-hooks/index.md'; -## Chained Animations +## チェーンされたアニメーション -Animations can be chained to run one after the other. The `play` method returns a Promise that resolves when the animation has completed. +アニメーションは連鎖させて、次々に実行できます。`play`メソッドは、アニメーションが完了したときに解決される Promise を返します。 import Chain from '@site/static/usage/v8/animations/chain/index.md'; -## Gesture Animations +## ジェスチャーアニメーション -Ionic Animations gives developers the ability to create powerful gesture-based animations by integrating seamlessly with [Ionic Gestures](gestures.md). +Ionic Animations は、[Ionic Gestures](gestures.md)とシームレスに統合することで、強力なジェスチャーベースのアニメーションを作成する機能を開発者に提供します。 -In the following example we are creating a track along which we can drag the card element. Our `animation` object will take care of moving the card element either left or right, and our `gesture` object will instruct the `animation` object which direction to move in. +以下の例では、カード要素をドラッグできるトラックを作成しています。`animation`オブジェクトはカード要素を左右に移動する処理を行い、`gesture`オブジェクトは`animation`オブジェクトに移動方向を指示します。 import Gesture from '@site/static/usage/v8/animations/gesture/index.md'; -## Preference-Based Animations +## ユーザー設定ベースのアニメーション -Developers can also tailor their animations to user preferences such as `prefers-reduced-motion` and `prefers-color-scheme` using CSS Variables. +開発者は、CSS 変数を使用して、`prefers-reduced-motion`や`prefers-color-scheme`などのユーザー設定に合わせてアニメーションを調整することもできます。 -This method works in all supported browsers when creating animations for the first time. Most browsers are also capable of dynamically updating keyframe animations as the CSS Variables change. +この方法は、初めてアニメーションを作成する際に、サポートされているすべてのブラウザで機能します。ほとんどのブラウザは、CSS 変数が変更されるとキーフレームアニメーションを動的に更新することもできます。 -Safari does not currently support dynamically updating keyframe animations. For developers who need this kind of support in Safari, they can use [MediaQueryList.addListener()](https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList/addListener). +Safari は現在、キーフレームアニメーションの動的更新をサポートしていません。Safari でこのようなサポートが必要な開発者は、[MediaQueryList.addListener()](https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList/addListener)を使用できます。 import PreferenceBased from '@site/static/usage/v8/animations/preference-based/index.md'; -## Overriding Ionic Component Animations +## Ionic コンポーネントアニメーションのオーバーライド -Certain Ionic components allow developers to provide custom animations. All animations are provided as either properties on the component or are set via a global config. +特定の Ionic コンポーネントでは、開発者がカスタムアニメーションを提供できます。すべてのアニメーションは、コンポーネントのプロパティとして提供されるか、グローバル設定を介して設定されます。 -### Modals +### モーダル import ModalOverride from '@site/static/usage/v8/animations/modal-override/index.md'; -## Performance Considerations +## パフォーマンスの考慮事項 -CSS and Web Animations are usually handled on the compositor thread. This is different than the main thread where layout, painting, styling, and your JavaScript is executed. It is recommended that you prefer using properties that can be handled on the compositor thread for optimal animation performance. +CSS と Web Animations は、通常、コンポジタースレッドで処理されます。これは、レイアウト、ペイント、スタイリング、JavaScript が実行されるメインスレッドとは異なります。最適なアニメーションパフォーマンスを得るには、コンポジタースレッドで処理できるプロパティを使用することをお勧めします。 -Animating properties such as `height` and `width` cause additional layouts and paints which can cause jank and degrade animation performance. On the other hand, animating properties such as `transform` and `opacity` are highly optimizable by the browser and typically do not cause much jank. +`height`や`width`などのプロパティをアニメーション化すると、追加のレイアウトとペイントが発生し、ジャンクを引き起こし、アニメーションパフォーマンスを低下させる可能性があります。一方、`transform`や`opacity`などのプロパティをアニメーション化すると、ブラウザによって高度に最適化され、通常はジャンクをほとんど引き起こしません。 -For information on which CSS properties cause layouts or paints to occur, see [CSS Triggers](https://csstriggers.com/). +どの CSS プロパティがレイアウトやペイントを引き起こすかについては、[CSS Triggers](https://csstriggers.com/)を参照してください。 -## Debugging +## デバッグ -For debugging animations in Chrome, there is a great blog post about inspecting animations using the Chrome DevTools: https://developers.google.com/web/tools/chrome-devtools/inspect-styles/animations. +Chrome でアニメーションをデバッグするには、Chrome DevTools を使用してアニメーションを検査する優れたブログ投稿があります:https://developers.google.com/web/tools/chrome-devtools/inspect-styles/animations。 -It is also recommended to assign unique identifiers to your animations. These identifiers will show up in the Animations inspector in Chrome and should make it easier to debug: +アニメーションに一意の識別子を割り当てることも推奨されます。これらの識別子は Chrome の Animations インスペクターに表示され、デバッグが容易になります: ```javascript /** - * The animation for the .square element should - * show "my-animation-identifier" in Chrome DevTools. + * .square要素のアニメーションは、 + * Chrome DevToolsで"my-animation-identifier"を表示する必要があります。 */ const animation = createAnimation('my-animation-identifier') .addElement(document.querySelector('.square')) @@ -269,9 +269,9 @@ const animation = createAnimation('my-animation-identifier') ## API -This section provides a list of all the methods and properties available on the `Animation` class. +このセクションでは、`Animation`クラスで利用可能なすべてのメソッドとプロパティのリストを提供します。 -### Interfaces +### インターフェース #### AnimationDirection @@ -293,7 +293,7 @@ type AnimationBuilder = (baseEl: any, opts?: any) => Animation; :::note -`opts` are additional options that are specific to the custom animation. For example, the sheet modal enter animation includes information for the current breakpoint. +`opts`は、カスタムアニメーションに固有の追加オプションです。たとえば、シートモーダルのエンターアニメーションには、現在のブレークポイントの情報が含まれます。 ::: @@ -321,47 +321,47 @@ interface AnimationPlayOptions { } ``` -### Properties - -| Name | Description | -| ------------------------------ | ------------------------------------------------- | -| `childAnimations: Animation[]` | All child animations of a given parent animation. | -| `elements: HTMLElement[]` | All elements attached to an animation. | -| `parentAnimation?: Animation` | The parent animation of a given animation object. | - -### Methods - -| Name | Description | -| -------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `addAnimation(animationToAdd: Animation \| Animation[]): Animation` | Group one or more animations together to be controlled by a parent animation. | -| `addElement(el: Element \| Element[] \| Node \| Node[] \| NodeList): Animation` | Add one or more elements to the animation. | -| `afterAddClass(className: string \| string[]): Animation` | Add a class or array of classes to be added to all elements in an animation after the animation ends. | -| `afterAddRead(readFn: (): void): Animation` | Add a function that performs a DOM read to be run after the animation ends. | -| `afterAddWrite(writeFn: (): void): Animation` | Add a function that performs a DOM write to be run after the animation ends. | -| `afterClearStyles(propertyNames: string[]): Animation` | Add an array of property names to be cleared from the inline styles on all elements in an animation after the animation ends. | -| `afterRemoveClass(className: string \| string[]): Animation` | Add a class or an array of classes to be removed from all elements in an animation after the animation ends. | -| `afterStyles(styles: { [property: string]: any }): Animation` | Add an object of styles to be applied to all elements in an animation after the animation ends. | -| `beforeAddClass(className: string \| string[]): Animation` | Add a class or array of classes to be added to all elements in an animation before the animation starts. | -| `beforeAddRead(readFn: (): void): Animation` | Add a function that performs a DOM read to be run before the animation starts. | -| `beforeAddWrite(writeFn: (): void): Animation` | Add a function that performs a DOM write to be run before the animation starts. | -| `beforeClearStyles(propertyNames: string[]): Animation` | Add an array of property names to be cleared from the inline styles on all elements in an animation before the animation starts. | -| `beforeRemoveClass(className: string \| string[]): Animation` | Add a class or an array of classes to be removed from all elements in an animation before the animation starts. | -| `beforeStyles(styles: { [property: string]: any }): Animation` | Add an object of styles to be applied to all elements in an animation before the animation starts. | -| `direction(direction?: AnimationDirection): Animation` | Set the direction the animation should play in. | -| `delay(delay?: number): Animation` | Set the delay for the start of the animation in milliseconds. | -| `destroy(clearStyleSheets?: boolean): Animation` | Destroy the animation and clear all elements, child animations, and keyframes. | -| `duration(duration?: number): Animation` | Set the duration of the animation in milliseconds. | -| `easing(easing?: string): Animation` | Set the easing of the animation in milliseconds. See [Easing Effects](https://developer.mozilla.org/en-US/docs/Web/API/EffectTiming/easing#Value) for a list of accepted easing values. | -| `from(property: string, value: any): Animation` | Set the start styles of the animation. | -| `fromTo(property: string, fromValue: any, toValue: any): Animation` | Set the start and end styles of the animation. | -| `fill(fill?: AnimationFill): Animation` | Set how the animation applies styles to its elements before and after the animation's execution. | -| `iterations(iterations: number): Animation` | Set the number of times the animation cycle should be played before stopping. | -| `keyframes(keyframes: any[]): Animation` | Set the keyframes for an animation. | -| `onFinish(callback: (didComplete: boolean, animation: Animation): void, opts?: AnimationCallbackOptions): Animation` | Add a callback to be run upon the animation ending. | -| `pause(): Animation` | Pause the animation. | -| `play(opts?: AnimationPlayOptions): Promise` | Play the animation. | -| `progressEnd(playTo?: 0 \| 1, step: number, dur?: number): Animation` | Stop seeking through an animation. | -| `progressStart(forceLinearEasing?: boolean, step?: number): Animation` | Begin seeking through an animation. | -| `progressStep(step: number): Animation` | Seek through an animation. | -| `stop(): Animation` | Stop the animation and reset all elements to their initial state. | -| `to(property: string, value: any): Animation` | Set the end styles of the animation. | +### プロパティ + +| Name | 説明 | +| ------------------------------ | -------------------------------------------------------- | +| `childAnimations: Animation[]` | 指定された親アニメーションのすべての子アニメーション。 | +| `elements: HTMLElement[]` | アニメーションにアタッチされたすべての要素。 | +| `parentAnimation?: Animation` | 指定されたアニメーションオブジェクトの親アニメーション。 | + +### メソッド + +| Name | 説明 | +| -------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| `addAnimation(animationToAdd: Animation \| Animation[]): Animation` | 1 つ以上のアニメーションをグループ化して、親アニメーションによって制御します。 | +| `addElement(el: Element \| Element[] \| Node \| Node[] \| NodeList): Animation` | アニメーションに 1 つ以上の要素を追加します。 | +| `afterAddClass(className: string \| string[]): Animation` | アニメーション終了後に、アニメーション内のすべての要素に追加するクラスまたはクラスの配列を追加します。 | +| `afterAddRead(readFn: (): void): Animation` | アニメーション終了後に実行される DOM 読み取りを実行する関数を追加します。 | +| `afterAddWrite(writeFn: (): void): Animation` | アニメーション終了後に実行される DOM 書き込みを実行する関数を追加します。 | +| `afterClearStyles(propertyNames: string[]): Animation` | アニメーション終了後に、アニメーション内のすべての要素のインラインスタイルからクリアするプロパティ名の配列を追加します。 | +| `afterRemoveClass(className: string \| string[]): Animation` | アニメーション終了後に、アニメーション内のすべての要素から削除するクラスまたはクラスの配列を追加します。 | +| `afterStyles(styles: { [property: string]: any }): Animation` | アニメーション終了後に、アニメーション内のすべての要素に適用するスタイルのオブジェクトを追加します。 | +| `beforeAddClass(className: string \| string[]): Animation` | アニメーション開始前に、アニメーション内のすべての要素に追加するクラスまたはクラスの配列を追加します。 | +| `beforeAddRead(readFn: (): void): Animation` | アニメーション開始前に実行される DOM 読み取りを実行する関数を追加します。 | +| `beforeAddWrite(writeFn: (): void): Animation` | アニメーション開始前に実行される DOM 書き込みを実行する関数を追加します。 | +| `beforeClearStyles(propertyNames: string[]): Animation` | アニメーション開始前に、アニメーション内のすべての要素のインラインスタイルからクリアするプロパティ名の配列を追加します。 | +| `beforeRemoveClass(className: string \| string[]): Animation` | アニメーション開始前に、アニメーション内のすべての要素から削除するクラスまたはクラスの配列を追加します。 | +| `beforeStyles(styles: { [property: string]: any }): Animation` | アニメーション開始前に、アニメーション内のすべての要素に適用するスタイルのオブジェクトを追加します。 | +| `direction(direction?: AnimationDirection): Animation` | アニメーションの再生方向を設定します。 | +| `delay(delay?: number): Animation` | アニメーション開始の遅延をミリ秒で設定します。 | +| `destroy(clearStyleSheets?: boolean): Animation` | アニメーションを破棄し、すべての要素、子アニメーション、キーフレームをクリアします。 | +| `duration(duration?: number): Animation` | アニメーションの継続時間をミリ秒で設定します。 | +| `easing(easing?: string): Animation` | アニメーションのイージングを設定します。受け入れられるイージング値のリストについては、[Easing Effects](https://developer.mozilla.org/en-US/docs/Web/API/EffectTiming/easing#Value)を参照してください。 | +| `from(property: string, value: any): Animation` | アニメーションの開始スタイルを設定します。 | +| `fromTo(property: string, fromValue: any, toValue: any): Animation` | アニメーションの開始スタイルと終了スタイルを設定します。 | +| `fill(fill?: AnimationFill): Animation` | アニメーションの実行前後で、アニメーションが要素にスタイルを適用する方法を設定します。 | +| `iterations(iterations: number): Animation` | アニメーションサイクルが停止する前に再生される回数を設定します。 | +| `keyframes(keyframes: any[]): Animation` | アニメーションのキーフレームを設定します。 | +| `onFinish(callback: (didComplete: boolean, animation: Animation): void, opts?: AnimationCallbackOptions): Animation` | アニメーション終了時に実行されるコールバックを追加します。 | +| `pause(): Animation` | アニメーションを一時停止します。 | +| `play(opts?: AnimationPlayOptions): Promise` | アニメーションを再生します。 | +| `progressEnd(playTo?: 0 \| 1, step: number, dur?: number): Animation` | アニメーションのシークを停止します。 | +| `progressStart(forceLinearEasing?: boolean, step?: number): Animation` | アニメーションのシークを開始します。 | +| `progressStep(step: number): Animation` | アニメーションをシークします。 | +| `stop(): Animation` | アニメーションを停止し、すべての要素を初期状態にリセットします。 | +| `to(property: string, value: any): Animation` | アニメーションの終了スタイルを設定します。 | diff --git a/docs/utilities/gestures.md b/docs/utilities/gestures.md index fe83e847804..04ee6696238 100644 --- a/docs/utilities/gestures.md +++ b/docs/utilities/gestures.md @@ -7,18 +7,18 @@ import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; - Gestures | Ionic App Utility for Custom Gestures and Interactions + ジェスチャー | カスタムジェスチャーとインタラクション用のIonicアプリユーティリティ -## Overview +## 概要 -Ionic Gestures is a utility that allows developers to build custom gestures and interactions for their application in a platform agnostic manner. Developers do not need to be using a particular framework such as React or Angular, nor do they even need to be building an Ionic app! As long as developers have access to v5.0 or greater of Ionic Framework, they will have access to all of Ionic Gestures. +Ionic Gestures は、開発者がプラットフォームに依存しない方法でアプリケーションのカスタムジェスチャーとインタラクションを構築できるユーティリティです。開発者は、React や Angular などの特定のフレームワークを使用する必要はなく、Ionic アプリを構築する必要もありません!開発者が Ionic Framework v5.0 以降にアクセスできる限り、Ionic Gestures のすべてにアクセスできます。 -Building complex gestures can be time consuming. Other libraries that provide custom gestures are often times too heavy handed and end up capturing mouse or touch events and not letting them propagate. This can result in other elements no longer being scrollable or clickable. +複雑なジェスチャーの構築には時間がかかる場合があります。カスタムジェスチャーを提供する他のライブラリは、しばしば過度に重く、マウスやタッチイベントをキャプチャして伝播させないため、他の要素がスクロール可能またはクリック可能でなくなる可能性があります。 ## Installation @@ -36,7 +36,7 @@ Building complex gestures can be time consuming. Other libraries that provide cu }> -Developers using Ionic Core and JavaScript should install the latest version of `@ionic/core`. +Ionic CoreとJavaScriptを使用する開発者は、最新バージョンの`@ionic/core`をインストールする必要があります。 ```javascript import { createGesture } from 'https://cdn.jsdelivr.net/npm/@ionic/core@latest/dist/esm/index.mjs'; @@ -54,7 +54,7 @@ const gesture = createGesture({ -Developers using Ionic Core and TypeScript should install the latest version of `@ionic/core`. +Ionic CoreとTypeScriptを使用する開発者は、最新バージョンの`@ionic/core`をインストールする必要があります。 ```tsx import { createGesture, Gesture } from '@ionic/core'; @@ -71,10 +71,10 @@ const gesture: Gesture = createGesture({ -Developers using Angular should install the latest version of `@ionic/angular`. Gestures can be created via the `GestureController` dependency injection. +Angularを使用する開発者は、最新バージョンの`@ionic/angular`をインストールする必要があります。ジェスチャーは`GestureController`の依存性注入を介して作成できます。 -By default, gesture callbacks do not run inside of NgZone. Developers can either set the `runInsideAngularZone` parameter to `true` when creating a gesture, -or they can wrap their callbacks in an `NgZone.run()` call. +デフォルトでは、ジェスチャーのコールバックはNgZone内で実行されません。 +開発者は、ジェスチャーを作成する際に`runInsideAngularZone`パラメータを`true`に設定するか、コールバックを`NgZone.run()`呼び出しでラップできます。 ```tsx import { Gesture, GestureController } from '@ionic/angular'; @@ -95,10 +95,10 @@ constructor(private gestureCtrl: GestureController) { -Developers using Angular should install the latest version of `@ionic/angular`. Gestures can be created via the `GestureController` dependency injection. +Angularを使用する開発者は、最新バージョンの`@ionic/angular`をインストールする必要があります。ジェスチャーは`GestureController`の依存性注入を介して作成できます。 -By default, gesture callbacks do not run inside of NgZone. Developers can either set the `runInsideAngularZone` parameter to `true` when creating a gesture, -or they can wrap their callbacks in an `NgZone.run()` call. +デフォルトでは、ジェスチャーのコールバックはNgZone内で実行されません。 +開発者は、ジェスチャーを作成する際に`runInsideAngularZone`パラメータを`true`に設定するか、コールバックを`NgZone.run()`呼び出しでラップできます。 ```tsx import { Gesture, GestureController } from '@ionic/angular/standalone'; @@ -119,7 +119,7 @@ constructor(private gestureCtrl: GestureController) { -Developers using React should install the latest version of `@ionic/react`. Full React wrappers are coming soon! +Reactを使用する開発者は、最新バージョンの`@ionic/react`をインストールする必要があります。完全なReactラッパーは近日公開予定です! ```tsx import { createGesture, Gesture } from '@ionic/react'; @@ -136,7 +136,7 @@ const gesture: Gesture = createGesture({ -Developers using Ionic Vue should install the latest version of `@ionic/vue`. +Ionic Vueを使用する開発者は、最新バージョンの`@ionic/vue`をインストールする必要があります。 ```javascript import { createGesture } from '@ionic/vue'; @@ -160,78 +160,78 @@ const gesture = createGesture({ ```` -## Basic Gestures +## 基本的なジェスチャー import Basic from '@site/static/usage/v8/gestures/basic/index.md'; -In this example, our app listens for gestures on the `ion-content` element. When a gesture movement has started, the `onStart` function is called and a class is added to our `ion-card` to add a colored box shadow. When a gesture movement was detected, the `onMove` function is called and our app prints the current gesture information within the `ion-card`. Finally, when a gesture movement has ended, the `onEnd` function is called and the custom class is removed from our `ion-card`. +この例では、アプリは`ion-content`要素でジェスチャーをリッスンします。ジェスチャーの移動が開始されると、`onStart`関数が呼び出され、`ion-card`にクラスが追加されて色付きのボックスシャドウが追加されます。ジェスチャーの移動が検出されると、`onMove`関数が呼び出され、アプリは`ion-card`内に現在のジェスチャー情報を出力します。最後に、ジェスチャーの移動が終了すると、`onEnd`関数が呼び出され、カスタムクラスが`ion-card`から削除されます。 -## Double Click Gesture +## ダブルクリックジェスチャー import DoubleClick from '@site/static/usage/v8/gestures/double-click/index.md'; -In the example below, we want to be able to detect double clicks on an element. By setting our `threshold` to `0`, we can ensure our gesture object can detect clicks. Additionally, we define a click threshold so that only 2 clicks that occur in quick succession count as a double click. +以下の例では、要素のダブルクリックを検出できるようにします。`threshold`を`0`に設定することで、ジェスチャーオブジェクトがクリックを検出できるようにします。さらに、連続して発生する 2 つのクリックのみがダブルクリックとしてカウントされるように、クリックの閾値を定義します。 -## Gesture Animations +## ジェスチャーアニメーション -See our guide on implementing gesture animations: [Gesture Animations with Ionic Animations](animations.md#gesture-animations) +ジェスチャーアニメーションの実装ガイドについては、[Ionic Animations を使用したジェスチャーアニメーション](animations.md#gesture-animations)を参照してください。 -## Types +## 型 -| Name | Value | +| Name | 値 | | ----------------- | -------------------------------------------- | | `GestureCallback` | `(detail: GestureDetail) => boolean \| void` | -## Interfaces +## インターフェース ### GestureConfig -| Property | Type | Default | Description | -| --------------- | ------------------------------------------ | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| el | `Node` | `undefined` | The element to listen on for gestures. | -| disableScroll | `boolean \| undefined` | `false` | If true, scrolling will be disabled on `el` while the gesture is enabled. | -| direction | `'x' \| 'y' \| undefined` | `'x'` | Limit gesture detection to movements along a certain axis. | -| gestureName | `string` | `undefined` | The name of the gesture to create. | -| gesturePriority | `number \| undefined` | `0` | Gestures with higher priorities will override gestures with lower priorities. Useful for ensuring the multiple gestures do not collide with one another. | -| passive | `boolean \| undefined` | `true` | If true, this will indicate that the gesture will never call `preventDefault()`. This can be used to improve scrolling performance. See [Passive Listeners](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Improving_scrolling_performance_with_passive_listeners) for more information. | -| maxAngle | `number \| undefined` | `40` | The maximum angle to allow when detecting a gesture. | -| threshold | `number \| undefined` | `10` | Defines how much a pointer must move before the gesture starts. | -| blurOnStart | `boolean \| undefined` | `undefined` | If true, the gesture will blur any active selectable element such as an input or a textarea before firing the `onStart` callback. | -| canStart | `GestureCallback \| undefined` | `undefined` | A callback that returns true if a gesture is allowed to start. | -| onWillStart | `(detail: GestureDetail) => Promise` | `undefined` | A callback that fires when a gesture is about to start. This is fired after `canStart` but before `onStart`. | -| onStart | `GestureCallback \| undefined` | `undefined` | A callback that fires when a gesture has started. | -| onMove | `GestureCallback \| undefined` | `undefined` | A callback that fires when a gesture movement was detected. | -| onEnd | `GestureCallback \| undefined` | `undefined` | A callback that fires when a gesture has ended. This is usually when a pointer has been released. | -| notCaptured | `GestureCallback \| undefined` | `undefined` | A callback that fires when a gesture has not been captured. This usually happens when there is a conflicting gesture with a higher priority. | +| Property | 型 | デフォルト | 説明 | +| --------------- | ------------------------------------------ | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| el | `Node` | `undefined` | ジェスチャーをリッスンする要素。 | +| disableScroll | `boolean \| undefined` | `false` | true の場合、ジェスチャーが有効な間、`el`でのスクロールが無効になります。 | +| direction | `'x' \| 'y' \| undefined` | `'x'` | 特定の軸に沿った移動にジェスチャー検出を制限します。 | +| gestureName | `string` | `undefined` | 作成するジェスチャーの名前。 | +| gesturePriority | `number \| undefined` | `0` | 優先度の高いジェスチャーは、優先度の低いジェスチャーをオーバーライドします。複数のジェスチャーが衝突しないようにするのに役立ちます。 | +| passive | `boolean \| undefined` | `true` | true の場合、ジェスチャーが`preventDefault()`を呼び出すことはないことを示します。これはスクロールパフォーマンスを向上させるために使用できます。詳細については、[Passive Listeners](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Improving_scrolling_performance_with_passive_listeners)を参照してください。 | +| maxAngle | `number \| undefined` | `40` | ジェスチャーを検出する際に許可する最大角度。 | +| threshold | `number \| undefined` | `10` | ジェスチャーが開始する前にポインターが移動する必要がある量を定義します。 | +| blurOnStart | `boolean \| undefined` | `undefined` | true の場合、ジェスチャーは`onStart`コールバックを発火する前に、input や textarea などのアクティブな選択可能な要素をぼかします。 | +| canStart | `GestureCallback \| undefined` | `undefined` | ジェスチャーが開始を許可されている場合に true を返すコールバック。 | +| onWillStart | `(detail: GestureDetail) => Promise` | `undefined` | ジェスチャーが開始されようとしているときに発火するコールバック。これは`canStart`の後、`onStart`の前に発火します。 | +| onStart | `GestureCallback \| undefined` | `undefined` | ジェスチャーが開始されたときに発火するコールバック。 | +| onMove | `GestureCallback \| undefined` | `undefined` | ジェスチャーの移動が検出されたときに発火するコールバック。 | +| onEnd | `GestureCallback \| undefined` | `undefined` | ジェスチャーが終了したときに発火するコールバック。通常、ポインターが解放されたときです。 | +| notCaptured | `GestureCallback \| undefined` | `undefined` | ジェスチャーがキャプチャされなかったときに発火するコールバック。通常、優先度の高い競合するジェスチャーがある場合に発生します。 | ### GestureDetail -| Property | Type | Description | -| -------------- | ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------- | -| type | `string` | The type of gesture that was detected. | -| startX | `number` | The starting x coordinate of the gesture. | -| startY | `number` | The starting y coordinate of the gesture. | -| startTimeStamp | `number` | The timestamp at which the gesture was started. | -| currentX | `number` | The current x coordinate of the gesture. | -| currentY | `number` | The current y coordinate of the gesture. | -| velocityX | `number` | How fast the gesture is currently moving on the x axis. | -| velocityY | `number` | How fast the gesture is currently moving on the y axis. | -| deltaX | `number` | How much the gesture has moved on the x axis since it started. | -| deltaY | `number` | How much the gesture has moved on the y axis since it started. | -| timeStamp | `number` | The current timestamp of the gesture. | -| event | `UIEvent` | The native event dispatched by the browser. See [UIEvent](https://developer.mozilla.org/en-US/docs/Web/API/UIEvent) for more information. | -| data | `any \| undefined` | Any data specified by the user. This can be set and read in any of the callbacks. | - -## Methods +| Property | 型 | 説明 | +| -------------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| type | `string` | 検出されたジェスチャーのタイプ。 | +| startX | `number` | ジェスチャーの開始 x 座標。 | +| startY | `number` | ジェスチャーの開始 y 座標。 | +| startTimeStamp | `number` | ジェスチャーが開始されたタイムスタンプ。 | +| currentX | `number` | ジェスチャーの現在の x 座標。 | +| currentY | `number` | ジェスチャーの現在の y 座標。 | +| velocityX | `number` | ジェスチャーが現在 x 軸上で移動している速度。 | +| velocityY | `number` | ジェスチャーが現在 y 軸上で移動している速度。 | +| deltaX | `number` | ジェスチャーが開始されてから x 軸上で移動した量。 | +| deltaY | `number` | ジェスチャーが開始されてから y 軸上で移動した量。 | +| timeStamp | `number` | ジェスチャーの現在のタイムスタンプ。 | +| event | `UIEvent` | ブラウザによってディスパッチされたネイティブイベント。詳細については、[UIEvent](https://developer.mozilla.org/en-US/docs/Web/API/UIEvent)を参照してください。 | +| data | `any \| undefined` | ユーザーによって指定された任意のデータ。これは任意のコールバックで設定および読み取ることができます。 | + +## メソッド #### `enable(enable: boolean = true) => void` -Enable or disable the gesture. +ジェスチャーを有効または無効にします。 #### `destroy() => void` -Destroy the gesture instance and stop listening on the target element. +ジェスチャーインスタンスを破棄し、ターゲット要素でのリッスンを停止します。 diff --git a/docs/vue/add-to-existing.md b/docs/vue/add-to-existing.md new file mode 100644 index 00000000000..f4e88f1fc3f --- /dev/null +++ b/docs/vue/add-to-existing.md @@ -0,0 +1,349 @@ +--- +title: Add to Existing Vue Project +sidebar_label: Add to Existing +--- + +import DocsCard from '@components/global/DocsCard'; +import DocsCards from '@components/global/DocsCards'; + + + Add Ionic Vue to Existing Project: Integration Guide + + + +This guide covers how to add Ionic Vue to an existing Vue project. If you're looking to start a new project from scratch, check out the [Ionic Vue Quickstart](/docs/vue/quickstart.md) guide. For an overview of how Ionic Vue works with Vue, including version support and tooling, check out the [Ionic Vue Overview](/docs/vue/overview.md). + +:::tip + +This guide uses JavaScript examples. If you're using TypeScript, the setup process is the same, but you'll use `.ts` file extensions instead of `.js`. + +::: + +## Setup + +:::info + +This guide follows the structure of a Vue app created with `create-vue` (which uses Vite). If you started your Vue app using a different tool (such as Vue CLI), your file structure and setup may differ. + +::: + +Follow these steps to add Ionic Vue to your existing Vue project: + +#### 1. Install the Packages + +```bash +npm install @ionic/vue @ionic/vue-router vue-router +``` + +#### 2. Configure Ionic Vue + +Update `src/main.js` to include `IonicVue` and import the required Ionic Framework stylesheets: + +```javascript title="src/main.js" +import { createApp } from 'vue'; +import { IonicVue } from '@ionic/vue'; + +import App from './App.vue'; + +/* Core CSS required for Ionic components to work properly */ +import '@ionic/vue/css/core.css'; + +/* Basic CSS for apps built with Ionic */ +import '@ionic/vue/css/normalize.css'; +import '@ionic/vue/css/structure.css'; +import '@ionic/vue/css/typography.css'; + +createApp(App).use(IonicVue).mount('#app'); +``` + +:::info + +While `core.css` is required, `normalize.css`, `structure.css`, and `typography.css` are recommended but not required. They normalize cross-browser differences, ensure proper scrolling behavior, and provide consistent typography and form styling. Without them, you may need to handle these concerns yourself. For more details, refer to [Global Stylesheets](/docs/layout/global-stylesheets.md). + +::: + +## Using Individual Components + +After completing the setup above, you can start using Ionic components in your existing Vue app. Here's an example of how to use them: + +Update `src/App.vue` to the following: + +```vue title="src/App.vue" + + + +``` + +Visit the [components](/docs/components.md) page for all of the available Ionic components. + +## Using Ionic Pages + +If you want to use Ionic pages with full navigation and page transitions, follow these additional setup steps. + +#### 1. Add Additional Ionic Framework Stylesheets + +Update the imported stylesheets in `src/main.js`: + +```javascript title="src/main.js" +/* Core CSS required for Ionic components to work properly */ +import '@ionic/vue/css/core.css'; + +/* Basic CSS for apps built with Ionic */ +import '@ionic/vue/css/normalize.css'; +import '@ionic/vue/css/structure.css'; +import '@ionic/vue/css/typography.css'; + +/* Optional CSS utils that can be commented out */ +import '@ionic/vue/css/padding.css'; +import '@ionic/vue/css/float-elements.css'; +import '@ionic/vue/css/text-alignment.css'; +import '@ionic/vue/css/text-transformation.css'; +import '@ionic/vue/css/flex-utils.css'; +import '@ionic/vue/css/display.css'; +``` + +These stylesheets set up the overall page structure and provide [CSS utilities](/docs/layout/css-utilities.md) for faster development. Some stylesheets are optional. For details on which stylesheets are required, check out [Global Stylesheets](/docs/layout/global-stylesheets.md). + +#### 2. Set up Theming + +Create a `src/theme/variables.css` file with the following content: + +```css title="src/theme/variables.css" +/* For information on how to create your own theme, please refer to: +https://ionicframework.com/docs/theming/ */ +``` + +Then, import the file and the dark palette stylesheet in `src/main.js`: + +```javascript title="src/main.js" +import { createApp } from 'vue'; +import App from './App.vue'; + +import { IonicVue } from '@ionic/vue'; + +/* Core CSS required for Ionic components to work properly */ +import '@ionic/vue/css/core.css'; + +/* Basic CSS for apps built with Ionic */ +import '@ionic/vue/css/normalize.css'; +import '@ionic/vue/css/structure.css'; +import '@ionic/vue/css/typography.css'; + +/* Optional CSS utils that can be commented out */ +import '@ionic/vue/css/padding.css'; +import '@ionic/vue/css/float-elements.css'; +import '@ionic/vue/css/text-alignment.css'; +import '@ionic/vue/css/text-transformation.css'; +import '@ionic/vue/css/flex-utils.css'; +import '@ionic/vue/css/display.css'; + +/** + * Ionic Dark Mode + * ----------------------------------------------------- + * For more info, please refer to: + * https://ionicframework.com/docs/theming/dark-mode + */ + +/* @import '@ionic/vue/css/palettes/dark.always.css'; */ +/* @import '@ionic/vue/css/palettes/dark.class.css'; */ +import '@ionic/vue/css/palettes/dark.system.css'; + +/* Theme variables */ +import './theme/variables.css'; + +createApp(App).use(IonicVue).mount('#app'); +``` + +The `variables.css` file can be used to create custom Ionic Framework themes. The `dark.system.css` import enables [dark mode support](/docs/theming/dark-mode.md) for your Ionic app when the system is set to prefer a dark appearance. You can customize the theming behavior by uncommenting different dark palette imports or adding custom CSS variables to `theme/variables.css`. + +#### 3. Update the App Component + +Update `src/App.vue` to the following: + +```vue title="src/App.vue" + + + +``` + +#### 4. Create a Home Page + +Create a new file at `src/views/HomePage.vue` with the following: + +```vue title="src/views/HomePage.vue" + + + + + +``` + +#### 5. Set up Routing + +Add a file at `src/router/index.js` defining the routes: + +```javascript title="src/router/index.js" +import { createRouter, createWebHistory } from '@ionic/vue-router'; +import HomePage from '../views/HomePage.vue'; + +const routes = [ + { + path: '/', + redirect: '/home', + }, + { + path: '/home', + name: 'Home', + component: HomePage, + }, +]; + +const router = createRouter({ + history: createWebHistory(import.meta.env.BASE_URL), + routes, +}); + +export default router; +``` + +Update `src/main.js` to include the router: + +```javascript title="src/main.js" +import { createApp } from 'vue'; +import App from './App.vue'; +import router from './router'; + +import { IonicVue } from '@ionic/vue'; + +/* Core CSS required for Ionic components to work properly */ +import '@ionic/vue/css/core.css'; + +/* Basic CSS for apps built with Ionic */ +import '@ionic/vue/css/normalize.css'; +import '@ionic/vue/css/structure.css'; +import '@ionic/vue/css/typography.css'; + +/* Optional CSS utils that can be commented out */ +import '@ionic/vue/css/padding.css'; +import '@ionic/vue/css/float-elements.css'; +import '@ionic/vue/css/text-alignment.css'; +import '@ionic/vue/css/text-transformation.css'; +import '@ionic/vue/css/flex-utils.css'; +import '@ionic/vue/css/display.css'; + +/** + * Ionic Dark Mode + * ----------------------------------------------------- + * For more info, please refer to: + * https://ionicframework.com/docs/theming/dark-mode + */ + +/* @import '@ionic/vue/css/palettes/dark.always.css'; */ +/* @import '@ionic/vue/css/palettes/dark.class.css'; */ +import '@ionic/vue/css/palettes/dark.system.css'; + +/* Theme variables */ +import './theme/variables.css'; + +const app = createApp(App).use(IonicVue).use(router); + +router.isReady().then(() => { + app.mount('#app'); +}); +``` + +You're all set! Your Ionic Vue app is now configured with full Ionic page support. Run `npm run dev` to start your development server and view your app. + +## Next Steps + +Now that you have Ionic Vue integrated into your project, check out: + + + + +

Discover how to handle routing and navigation in Ionic Vue apps using the Vue Router.

+
+ + +

Explore Ionic's rich library of UI components for building beautiful apps.

+
+ + +

Learn how to customize the look and feel of your app with Ionic's powerful theming system.

+
+ + +

Explore how to access native device features and deploy your app to iOS, Android, and the web with Capacitor.

+
+ +
diff --git a/docs/vue/build-options.md b/docs/vue/build-options.md index 5a43eaf6fb7..8d27698cfd8 100644 --- a/docs/vue/build-options.md +++ b/docs/vue/build-options.md @@ -28,7 +28,7 @@ Also note that locally registered components are not available in subcomponents. Let's take a look at how local component registration works: -```html +```vue ``` @@ -70,7 +70,7 @@ app.component('ion-page', IonPage); **MyComponent.vue** -```html +```vue ``` diff --git a/docs/vue/lifecycle.md b/docs/vue/lifecycle.md index b69f6b9fd07..1a27c80f15d 100644 --- a/docs/vue/lifecycle.md +++ b/docs/vue/lifecycle.md @@ -21,7 +21,7 @@ Ionic Framework はアプリで使えるいくつかのライフサイクルメ ライフサイクルは、Vue のライフサイクルメソッドと同じように、Vue コンポーネントのルートで関数として定義されます: -```tsx +```vue ``` @@ -364,7 +364,7 @@ const routes: Array = [ まず、 `Tabs` コンポーネントをみていきましょう: -```html +```vue ``` @@ -494,7 +494,7 @@ The example below shows how the Spotify app reuses the same album component to s The `IonPage` component wraps each view in an Ionic Vue app and allows page transitions and stack navigation to work properly. Each view that is navigated to using the router must include an `IonPage` component. -```html +```vue ``` @@ -550,7 +550,7 @@ const routes: Array = [ コンポーネントでの使用方法を見てみましょう。 -```html +```vue ``` diff --git a/docs/vue/overview.md b/docs/vue/overview.md index 7bed131055a..31b2cc19316 100644 --- a/docs/vue/overview.md +++ b/docs/vue/overview.md @@ -4,31 +4,31 @@ sidebar_label: 概要 --- - Ionic Vue Overview | Vue.js Framework Documentation + Ionic Vueの概要 | Vue.jsフレームワークドキュメント import DocsCard from '@components/global/DocsCard'; import DocsCards from '@components/global/DocsCards'; -`@ionic/vue` brings the full power of the Ionic Framework to Vue developers. It offers seamless integration with the Vue ecosystem, so you can build high-quality cross-platform apps using familiar Vue tools, components, and best practices. You also get access to Ionic's extensive UI library and native capabilities. +`@ionic/vue`は、Ionic Framework の全機能を Vue 開発者にもたらします。Vue エコシステムとのシームレスな統合を提供するため、使い慣れた Vue ツール、コンポーネント、ベストプラクティスを使用して高品質なクロスプラットフォームアプリを構築できます。また、Ionic の豊富な UI ライブラリとネイティブ機能にもアクセスできます。 ## Vue バージョンサポート -Ionic Vue v8 supports Vue 3.x. For detailed information on supported versions and our support policy, see the [Ionic Vue Support Policy](/docs/reference/support#ionic-vue). +Ionic Vue v8 は Vue 3.x をサポートしています。サポートされているバージョンとサポートポリシーの詳細については、[Ionic Vue サポートポリシー](/docs/reference/support#ionic-vue)を参照してください。 ## Vue ツール -Ionic Vue projects use the same tooling as standard Vue CLI projects, so you can take advantage of the full Vue CLI feature set for building, testing, and deploying your apps. Starter projects come with useful features enabled by default, such as Vue Router for navigation and TypeScript support for type safety and improved developer experience. +Ionic Vue プロジェクトは、標準の Vue CLI プロジェクトと同じツールを使用するため、アプリのビルド、テスト、デプロイに Vue CLI の全機能セットを活用できます。スタータープロジェクトには、ナビゲーション用の Vue Router や、型安全性と開発者体験の向上のための TypeScript サポートなど、デフォルトで有効になっている便利な機能が含まれています。 -## Native Tooling +## ネイティブツール -[Capacitor](https://capacitorjs.com) is the official cross-platform runtime for Ionic Vue, enabling your apps to run natively on iOS, Android, and the web with a single codebase. +[Capacitor](https://capacitorjs.com)は、Ionic Vue の公式クロスプラットフォームランタイムで、単一のコードベースで iOS、Android、Web 上でネイティブにアプリを実行できます。 -While you can use many [Cordova](https://cordova.apache.org/) plugins with Ionic Vue, Capacitor is the recommended and fully supported solution. The [Ionic CLI](../cli.md) does not provide official Cordova integration for Ionic Vue projects. For more information on using Cordova plugins with Capacitor, see the [Capacitor documentation](https://capacitorjs.com/docs/cordova). +Ionic Vue で多くの[Cordova](https://cordova.apache.org/)プラグインを使用できますが、Capacitor が推奨され、完全にサポートされているソリューションです。[Ionic CLI](../cli.md)は、Ionic Vue プロジェクトの公式 Cordova 統合を提供していません。Capacitor で Cordova プラグインを使用する方法の詳細については、[Capacitor ドキュメント](https://capacitorjs.com/docs/cordova)を参照してください。 ## インストール @@ -40,32 +40,34 @@ $ cd myApp $ ionic serve █ ``` -## Resources +## リソース - -

Quickly set up your first Ionic Vue app and learn the basics of the framework and CLI.

+ +

最初のIonic Vueアプリを迅速にセットアップし、フレームワークとCLIの基本を学びます。

- -

Learn more about Vue's core concepts, tools, and best practices from the official Vue documentation.

+ +

公式Vueドキュメントから、Vueのコアコンセプト、ツール、ベストプラクティスについて詳しく学びます。

- -

Discover how to handle routing and navigation in Ionic Vue apps using the Vue Router.

+ +

Vue Routerを使用してIonic Vueアプリでルーティングとナビゲーションを処理する方法を発見します。

- -

Explore Ionic's rich library of UI components for building beautiful apps.

+ +

美しいアプリを構築するためのIonicの豊富なUIコンポーネントライブラリを探索します。

- -

Learn how to customize the look and feel of your app with Ionic's powerful theming system.

+ +

Ionicの強力なテーマ設定システムを使用してアプリの外観と操作性をカスタマイズする方法を学びます。

- -

Explore how to access native device features and deploy your app to iOS, Android, and the web with Capacitor.

+ +

+ Capacitorを使用してネイティブデバイス機能にアクセスし、アプリをiOS、Android、Webにデプロイする方法を探索します。 +

diff --git a/docs/vue/performance.md b/docs/vue/performance.md index c767f2aa8bc..b3206fd76e2 100644 --- a/docs/vue/performance.md +++ b/docs/vue/performance.md @@ -11,7 +11,7 @@ When using `v-for` with Ionic components, we recommend using Vue's `key` attribu By using `key` you can provide a stable identity for each loop element so Vue can track insertions and deletions within the iterator. Below is an example of how to use `key`: -```html +```vue ``` diff --git a/docs/vue/quickstart.md b/docs/vue/quickstart.md index 7bc6c1206a0..1ca383830e9 100644 --- a/docs/vue/quickstart.md +++ b/docs/vue/quickstart.md @@ -53,19 +53,20 @@ After running `ionic serve`, your project will open in the browser. ## Explore the Project Structure -Your new app's `src` directory will look like this: +Your new app's directory will look like this: ```shell -├── App.vue -├── main.ts -├── router -│   └── index.ts -└── views -    └── HomePage.vue +└── src/ + ├── App.vue + ├── main.ts + ├── router + │   └── index.ts + └── views +    └── HomePage.vue ``` :::info -All file paths in the examples below are relative to the `src/` directory. +All file paths in the examples below are relative to the project root directory. ::: Let's walk through these files to understand the app's structure. @@ -74,7 +75,7 @@ Let's walk through these files to understand the app's structure. The root of your app is defined in `App.vue`: -```tsx +```vue title="src/App.vue"
`要素のように動作します。 | +| `.ion-display-table-row` | `display: table-row` | 要素は HTML の`