diff --git a/cspell-wordlist.txt b/cspell-wordlist.txt index 13a8a710581..bf433d7615a 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..e574460a89e --- /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, see [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/intro/cdn.md b/docs/intro/cdn.md index a90c4a6b250..adf8a7ceda7 100644 --- a/docs/intro/cdn.md +++ b/docs/intro/cdn.md @@ -1,156 +1,122 @@ --- -title: Ionic Packages +title: Ionic Packages & CDN sidebar_label: Packages & CDN --- - Ionic Framework Packages: CDN, Angular, Vue, and React + Ionic Framework Packages: CDN, Angular, Vue, React, and JavaScript -Ionic provides different packages that can be used to quickly get started using Ionic Framework or Ionicons in a test environment, Angular, any other framework, or none at all. +import DocsCard from '@components/global/DocsCard'; +import DocsCards from '@components/global/DocsCards'; -## Ionic Framework CDN - -Ionic Framework can be included from a CDN for quick testing in a [Plunker](https://plnkr.co/), [Codepen](https://codepen.io), or any other online code editor! - -It's recommended to use [jsdelivr](https://www.jsdelivr.com/) to access the Framework from a CDN. To get the latest version, add the following inside the `` element in an HTML file, or where external assets are included in the online code editor: - -```html - - - -``` +Ionic Framework offers npm packages for Angular, React, Vue, and JavaScript, plus CDN links for quick prototyping. Choose your framework below to get started, or use the CDN to test Ionic Framework components in the browser. -With this it's possible to use all of the Ionic Framework core components without having to install a framework. The CSS bundle will include all of the Ionic [Global Stylesheets](../layout/global-stylesheets). +## Ionic Angular -:::note -This does not install Angular or any other frameworks. This allows use of the Ionic Framework core components without a framework. -::: +Start a new Ionic Angular app or add Ionic to your existing Angular project. -## Ionic + Angular + -When using Ionic Framework in an Angular project, install the latest `@ionic/angular` package from [npm](../reference/glossary.md#npm). This comes with all of the Ionic Framework components and Angular specific services and features. + +

Create a new Ionic Angular app using the Ionic CLI.

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

Add Ionic Angular to an existing Angular project.

+
-Each time there is a new Ionic Framework release, this [version](../reference/versioning.md) will need to be updated to get the latest features and fixes. The version can be [updated using npm](../developing/tips.md#updating-dependencies), as well. +
-For adding Ionic to an already existing Angular project, use the Angular CLI's `ng add` feature. +## Ionic React -```shell -ng add @ionic/angular -``` +Start a new Ionic React app or add Ionic to your existing React project. -This will add the necessary imports to the `@ionic/angular` package as well as add the styles needed. + -## Ionic + React + +

Create a new Ionic React app using the Ionic CLI.

+
-To add Ionic Framework to an already existing React project, install the `@ionic/react` and `@ionic/react-router` package. + +

Add Ionic React to an existing React project.

+
-```shell -$ npm install @ionic/react -$ npm install @ionic/react-router -``` +
-### CSS +## Ionic Vue -To include the necessary CSS in a React project, add the following to the root App component. +Start a new Ionic Vue app or add Ionic to your existing Vue project. -```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'; + +

Create a new Ionic Vue app using the Ionic CLI.

+
-/* 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'; -``` + +

Add Ionic Vue to an existing Vue project.

+
-## Ionic + Vue +
-To add Ionic Framework to an existing Vue project, install the `@ionic/vue` and `@ionic/vue-router` packages. +## Ionic JavaScript -```shell -npm install @ionic/vue @ionic/vue-router -``` - -After that, you will need to install the `IonicVue` plugin in your Vue app. +Start a new Ionic JavaScript app. -**main.js** + -```javascript -import { IonicVue } from '@ionic/vue'; + +

Create a new Ionic JavaScript app using Vite.

+
-import App from './App.vue'; -import router from './router'; +
-const app = createApp(App).use(IonicVue).use(router); - -router.isReady().then(() => { - app.mount('#app'); -}); -``` - -Be sure to mount your app once `router.isReady()` has resolved. - -### Routing - -When setting up routing in your Vue app, you will need to import your dependencies from `@ionic/vue-router` instead of `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 - -To include the necessary CSS in a Vue project, add the following to your `main.js` file. +## Ionic Framework CDN -```javascript -/* Core CSS required for Ionic components to work properly */ -import '@ionic/vue/css/core.css'; +Ionic Framework can be included from a CDN for quick testing in a [StackBlitz](https://stackblitz.com/), [Plunker](https://plnkr.co/), [Codepen](https://codepen.io), or any other online code editor! -/* 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'; +It's recommended to use [jsdelivr](https://www.jsdelivr.com/) to access the Framework from a CDN. To get the latest version, add the following inside the `` element in an HTML file, or where external assets are included in the online code editor: -/* 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 + + + ``` -From here, you can learn about how to develop with Ionic Framework in our [Ionic Vue Quickstart Guide](https://ionicframework.com/docs/vue/quickstart). +With this it's possible to use all of the Ionic Framework core components without having to install a framework. The CSS bundle will include all of the Ionic [Global Stylesheets](/docs/layout/global-stylesheets.md). ## Ionicons CDN @@ -161,6 +127,4 @@ Ionicons is packaged by default with the Ionic Framework, so no installation is ``` -:::note -See [Ionicons usage](https://ionic.io/ionicons/usage) for more information on using Ionicons. -::: +For more information on using Ionicons, visit the [Ionicons documentation](https://ionic.io/ionicons/usage). diff --git a/docs/react/add-to-existing.md b/docs/react/add-to-existing.md new file mode 100644 index 00000000000..929bed987fb --- /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, see [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 deleted file mode 100644 index 20bf7b3fcb7..00000000000 --- a/docs/react/adding-ionic-react-to-an-existing-react-project.md +++ /dev/null @@ -1,146 +0,0 @@ -# Adding To An Existing React App - -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. diff --git a/docs/vue/add-to-existing.md b/docs/vue/add-to-existing.md new file mode 100644 index 00000000000..0277e6a5740 --- /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, see [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/docusaurus.config.js b/docusaurus.config.js index e7b90b1c434..3288ffc7371 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -19,7 +19,7 @@ const VERSIONS_JSON = require('./versions.json'); * Note that the urls specified in this file should * NOT have a trailing slash otherwise users will * briefly get a 404 Page Not Found error before - * the docuementation website loads. + * the documentation website loads. */ const ARCHIVED_VERSIONS_JSON = require('./versionsArchived.json'); @@ -325,7 +325,7 @@ module.exports = { theme: { plain: {}, styles: [] }, // Prism provides a [default list of languages](https://github.com/FormidableLabs/prism-react-renderer/blob/e1c83a468b05df7f452b3ad7e4ae5ab874574d4e/packages/generate-prism-languages/index.ts#L9-L26). // A list of [additional languages](https://prismjs.com/#supported-languages) that are supported can be found at their website. - additionalLanguages: ['shell-session', 'http', 'diff'], + additionalLanguages: ['shell-session', 'http', 'diff', 'json'], }, algolia: { appId: 'O9QSL985BS', diff --git a/sidebars.js b/sidebars.js index a04b7796f10..d8cacb17545 100644 --- a/sidebars.js +++ b/sidebars.js @@ -83,6 +83,7 @@ module.exports = { 'angular/your-first-app/distribute', ], }, + 'angular/add-to-existing', 'angular/build-options', 'angular/lifecycle', 'angular/navigation', @@ -123,7 +124,7 @@ module.exports = { 'react/your-first-app/distribute', ], }, - 'react/adding-ionic-react-to-an-existing-react-project', + 'react/add-to-existing', 'react/lifecycle', 'react/navigation', 'react/virtual-scroll', @@ -173,6 +174,7 @@ module.exports = { 'vue/your-first-app/distribute', ], }, + 'vue/add-to-existing', 'vue/build-options', 'vue/lifecycle', 'vue/navigation', diff --git a/src/components/global/DocsCard/index.tsx b/src/components/global/DocsCard/index.tsx index a8991dd4799..0ca705cd4c0 100644 --- a/src/components/global/DocsCard/index.tsx +++ b/src/components/global/DocsCard/index.tsx @@ -34,14 +34,16 @@ function DocsCard(props: Props): JSX.Element { )} {props.ionicon && } {props.iconset && ( -
- {props.iconset.split(',').map((icon, index) => ( - +
+ {props.iconset.split(',').map((icon, index, array) => ( + + + {index < array.length - 1 && ( +
+ + +
+ )} +
))}
)} diff --git a/src/components/global/DocsCard/styles.module.scss b/src/components/global/DocsCard/styles.module.scss index 8b3955f0fe9..a57e862b16c 100644 --- a/src/components/global/DocsCard/styles.module.scss +++ b/src/components/global/DocsCard/styles.module.scss @@ -116,20 +116,19 @@ docs-card[disabled]::after { .Card-icon-row { position: relative; + display: flex; + gap: 8px; } - .Card-iconset__container { - position: relative; - } - - .Card-iconset__container .Card-icon { - position: absolute; - opacity: 0; - transition: 0.8s opacity; - } - - .Card-iconset__container .Card-icon--active { - opacity: 1; + .Card-plus-icon { + display: flex; + align-items: center; + justify-content: center; + width: 24px; + height: 48px; + color: var(--docs-card-border-c); + font-size: 22px; + font-weight: 600; } .Card-ionicon { diff --git a/src/components/global/DocsCards/cards.css b/src/components/global/DocsCards/cards.css index eadaa0350b0..760d7c90465 100644 --- a/src/components/global/DocsCards/cards.css +++ b/src/components/global/DocsCards/cards.css @@ -2,7 +2,17 @@ docs-cards { display: grid; font-size: 12px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); - grid-gap: 1.35rem; + gap: 1.35rem; +} + +/* + * This prevents a single card from stretching the full width by + * forcing a 2-column grid layout (a single card will only take up + * 1 column instead of stretching across both). This is used on the + * Packages & CDN page by the JavaScript section. + */ +docs-cards:has(docs-card:only-child) { + grid-template-columns: 1fr 1fr; } docs-cards > docs-card { diff --git a/vercel.json b/vercel.json index 5ab15d8df22..8c7509aaf63 100644 --- a/vercel.json +++ b/vercel.json @@ -94,7 +94,15 @@ "destination": "/docs/vue/your-first-app/deploying-mobile" }, { "source": "/docs/vue/your-first-app/7-live-reload", "destination": "/docs/vue/your-first-app/live-reload" }, - { "source": "/docs/react/testing", "destination": "/docs/react/testing/introduction" } + { "source": "/docs/react/testing", "destination": "/docs/react/testing/introduction" }, + { + "source": "/docs/react/adding-ionic-react-to-an-existing-react-project", + "destination": "/docs/react/add-to-existing" + }, + { + "source": "/docs/:version(v7)/react/adding-ionic-react-to-an-existing-react-project", + "destination": "/docs/:version/react/add-to-existing" + } ], "rewrites": [ { "source": "/docs", "destination": "/" }, diff --git a/versioned_docs/version-v7/react/add-to-existing.md b/versioned_docs/version-v7/react/add-to-existing.md new file mode 100644 index 00000000000..929bed987fb --- /dev/null +++ b/versioned_docs/version-v7/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, see [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/versioned_docs/version-v7/react/adding-ionic-react-to-an-existing-react-project.md b/versioned_docs/version-v7/react/adding-ionic-react-to-an-existing-react-project.md deleted file mode 100644 index 20bf7b3fcb7..00000000000 --- a/versioned_docs/version-v7/react/adding-ionic-react-to-an-existing-react-project.md +++ /dev/null @@ -1,146 +0,0 @@ -# Adding To An Existing React App - -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. diff --git a/versioned_sidebars/version-v7-sidebars.json b/versioned_sidebars/version-v7-sidebars.json index 3495cf3d822..0e3dc75dd63 100644 --- a/versioned_sidebars/version-v7-sidebars.json +++ b/versioned_sidebars/version-v7-sidebars.json @@ -127,7 +127,7 @@ "react/your-first-app/distribute" ] }, - "react/adding-ionic-react-to-an-existing-react-project", + "react/add-to-existing", "react/lifecycle", "react/navigation", "react/virtual-scroll",