Unverified Commit 95acd8b4 authored by PapatMayuri's avatar PapatMayuri Committed by GitHub

updated with-ionic-typescript example to utilize the App Router. (#73418)

This PR updates the with-ionic-typescript example for using the App
Router.
Here are the changes that have been made:

- I renamed the `pages` folder and moved it to the `app` folder.
- Added the `layout.tsx` file as part of the App Router.
- Updated the `package.json` file.

CC: @samcx

---------
Co-authored-by: 's avatarSam Ko <sam@vercel.com>
parent 0c780098
const path = require("path");
const CopyPlugin = require("copy-webpack-plugin");
/** @type {import('next').NextConfig} */
module.exports = {
webpack: (config) => {
config.plugins.push(
new CopyPlugin({
patterns: [
{
from: path.join(
__dirname,
"node_modules/ionicons/dist/ionicons/svg",
),
to: path.join(__dirname, "public/svg"),
},
],
}),
);
return config;
},
};
import Image from "next/image";
export default function Home() {
return (
<ion-grid>
<ion-row>
{new Array(8).fill("").map((k, i) => (
<ion-col key={i} size="3">
<ion-card>
<Image
src="/cat.jpg"
alt="Picture of the author"
width={500}
height={500}
/>
<ion-card-header>
<ion-card-subtitle>Destination</ion-card-subtitle>
<ion-card-title>Madison, WI</ion-card-title>
</ion-card-header>
<ion-card-content>
<ion-icon name="pin" slot="start"></ion-icon>
Keep close to Nature's heart... and break clear away, once in
awhile, and climb a mountain or spend a week in the woods. Wash
your spirit clean.
</ion-card-content>
</ion-card>
</ion-col>
))}
</ion-row>
</ion-grid>
);
}
<svg width="283" height="64" viewBox="0 0 283 64" fill="none"
xmlns="http://www.w3.org/2000/svg">
<path d="M141.04 16c-11.04 0-19 7.2-19 18s8.96 18 20 18c6.67 0 12.55-2.64 16.19-7.09l-7.65-4.42c-2.02 2.21-5.09 3.5-8.54 3.5-4.79 0-8.86-2.5-10.37-6.5h28.02c.22-1.12.35-2.28.35-3.5 0-10.79-7.96-17.99-19-17.99zm-9.46 14.5c1.25-3.99 4.67-6.5 9.45-6.5 4.79 0 8.21 2.51 9.45 6.5h-18.9zM248.72 16c-11.04 0-19 7.2-19 18s8.96 18 20 18c6.67 0 12.55-2.64 16.19-7.09l-7.65-4.42c-2.02 2.21-5.09 3.5-8.54 3.5-4.79 0-8.86-2.5-10.37-6.5h28.02c.22-1.12.35-2.28.35-3.5 0-10.79-7.96-17.99-19-17.99zm-9.45 14.5c1.25-3.99 4.67-6.5 9.45-6.5 4.79 0 8.21 2.51 9.45 6.5h-18.9zM200.24 34c0 6 3.92 10 10 10 4.12 0 7.21-1.87 8.8-4.92l7.68 4.43c-3.18 5.3-9.14 8.49-16.48 8.49-11.05 0-19-7.2-19-18s7.96-18 19-18c7.34 0 13.29 3.19 16.48 8.49l-7.68 4.43c-1.59-3.05-4.68-4.92-8.8-4.92-6.07 0-10 4-10 10zm82.48-29v46h-9V5h9zM36.95 0L73.9 64H0L36.95 0zm92.38 5l-27.71 48L73.91 5H84.3l17.32 30 17.32-30h10.39zm58.91 12v9.69c-1-.29-2.06-.49-3.2-.49-5.81 0-10 4-10 10V51h-9V17h9v9.2c0-5.08 5.91-9.2 13.2-9.2z" fill="#000"/>
</svg>
\ No newline at end of file
...@@ -3,8 +3,12 @@ ...@@ -3,8 +3,12 @@
# dependencies # dependencies
/node_modules /node_modules
/.pnp /.pnp
.pnp.js .pnp.*
.yarn/install-state.gz .yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/versions
# testing # testing
/coverage /coverage
...@@ -24,6 +28,7 @@ ...@@ -24,6 +28,7 @@
npm-debug.log* npm-debug.log*
yarn-debug.log* yarn-debug.log*
yarn-error.log* yarn-error.log*
.pnpm-debug.log*
# local env files # local env files
.env*.local .env*.local
......
# Ionic with TypeScript Example # Ionic with TypeScript Example
Example app using Next.js with [Ionic](https://ionicframework.com/) and [TypeScript](https://www.typescriptlang.org/). You can learn more about Ionic in the [documentation](https://ionicframework.com/docs). Example app using Next.js with [Ionic](https://ionicframework.com/). You can learn more about Ionic in the [documentation](https://ionicframework.com/docs).
## Deploy your own ## Deploy your own
Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example) or preview live with [StackBlitz](https://stackblitz.com/github/vercel/next.js/tree/canary/examples/with-ionic-typescript) Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example) or preview live with [StackBlitz](https://stackblitz.com/github/vercel/next.js/tree/canary/examples/with-ionic)
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/vercel/next.js/tree/canary/examples/with-ionic-typescript&project-name=with-ionic-typescript&repository-name=with-ionic-typescript) [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/vercel/next.js/tree/canary/examples/with-ionic&project-name=with-ionic&repository-name=with-ionic)
## How to use ## How to use
Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init), [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/), or [pnpm](https://pnpm.io) to bootstrap the example: Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init), [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/), or [pnpm](https://pnpm.io) to bootstrap the example:
```bash ```bash
npx create-next-app --example with-ionic-typescript with-ionic-typescript-app npx create-next-app --example with-ionic with-ionic-app
``` ```
```bash ```bash
yarn create next-app --example with-ionic-typescript with-ionic-typescript-app yarn create next-app --example with-ionic with-ionic-app
``` ```
```bash ```bash
pnpm create next-app --example with-ionic-typescript with-ionic-typescript-app pnpm create next-app --example with-ionic with-ionic-app
``` ```
Deploy it to the cloud with [Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)). Deploy it to the cloud with [Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).
import Image from "next/image";
type CardProps = {
imageSrc: string;
title: string;
subtitle: string;
content: string;
};
export default function Card({
imageSrc,
title,
subtitle,
content,
}: CardProps) {
return (
<ion-card>
<Image
src={imageSrc}
alt={`Image of ${title}`}
width={320}
height={320}
priority={true}
/>
<ion-card-header>
<ion-card-subtitle>{subtitle}</ion-card-subtitle>
<ion-card-title>{title}</ion-card-title>
</ion-card-header>
<ion-card-content>
<ion-icon name="pin" slot="start"></ion-icon>
{content}
</ion-card-content>
</ion-card>
);
}
"use client";
import React, { useEffect } from "react"; import React, { useEffect } from "react";
import { defineCustomElements as ionDefineCustomElements } from "@ionic/core/loader"; import { defineCustomElements as ionDefineCustomElements } from "@ionic/core/loader";
/* Core CSS required for Ionic components to work properly */ export default function IonicLayout({
import "@ionic/core/css/core.css"; children,
}: {
/* Basic CSS for apps built with Ionic */ children: React.ReactNode;
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";
function MyApp({ Component, pageProps }) {
useEffect(() => { useEffect(() => {
ionDefineCustomElements(window); ionDefineCustomElements(window);
}); }, []);
return ( return (
<ion-app> <ion-app>
<ion-header translucent> <ion-header translucent>
...@@ -28,10 +19,7 @@ function MyApp({ Component, pageProps }) { ...@@ -28,10 +19,7 @@ function MyApp({ Component, pageProps }) {
<ion-title>Next.js with Ionic</ion-title> <ion-title>Next.js with Ionic</ion-title>
</ion-toolbar> </ion-toolbar>
</ion-header> </ion-header>
<ion-content fullscreen>{children}</ion-content>
<ion-content fullscreen>
<Component {...pageProps} />
</ion-content>
<ion-footer> <ion-footer>
<ion-toolbar> <ion-toolbar>
<ion-title>Footer</ion-title> <ion-title>Footer</ion-title>
...@@ -40,5 +28,3 @@ function MyApp({ Component, pageProps }) { ...@@ -40,5 +28,3 @@ function MyApp({ Component, pageProps }) {
</ion-app> </ion-app>
); );
} }
export default MyApp;
import "@ionic/core/css/core.css";
import "@ionic/core/css/normalize.css";
import "@ionic/core/css/structure.css";
import "@ionic/core/css/typography.css";
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";
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body>{children}</body>
</html>
);
}
import IonicLayout from "@/_components/IonicLayout";
import CardComponent from "@/_components/Card";
export default function Home() {
const destinations = new Array(8).fill({
imageSrc: "/img/cat.jpg",
title: "Madison, WI",
subtitle: "Destination",
content:
"Keep close to Nature's heart... and break clear away, once in awhile, and climb a mountain or spend a week in the woods. Wash your spirit clean.",
});
return (
<IonicLayout>
<ion-grid>
<ion-row>
{destinations.map((destination, i) => (
<ion-col key={i} size="3">
<CardComponent
imageSrc={destination.imageSrc}
title={destination.title}
subtitle={destination.subtitle}
content={destination.content}
/>
</ion-col>
))}
</ion-row>
</ion-grid>
</IonicLayout>
);
}
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
/* config options here */
};
export default nextConfig;
...@@ -6,16 +6,15 @@ ...@@ -6,16 +6,15 @@
"start": "next start" "start": "next start"
}, },
"dependencies": { "dependencies": {
"@ionic/core": "^5.4.1", "@ionic/core": "^8.4.1",
"ionicons": "^5.2.3", "ionicons": "^7.4.0",
"next": "latest", "next": "latest",
"react": "^18.2.0", "react": "^19.0.0",
"react-dom": "^18.2.0" "react-dom": "^19.0.0"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^14.14.6", "@types/node": "^22.10.1",
"@types/react": "^16.9.55", "@types/react": "^19.0.1",
"copy-webpack-plugin": "6.2.1", "typescript": "^5.7.2"
"typescript": "^4.0.5"
} }
} }
<svg xmlns="http://www.w3.org/2000/svg" class="ionicon" viewBox="0 0 512 512"><path d="M336 96a80 80 0 10-96 78.39v283.17a32.09 32.09 0 002.49 12.38l10.07 24a3.92 3.92 0 006.88 0l10.07-24a32.09 32.09 0 002.49-12.38V174.39A80.13 80.13 0 00336 96zm-56 0a24 24 0 1124-24 24 24 0 01-24 24z"/></svg>
\ No newline at end of file
{ {
"compilerOptions": { "compilerOptions": {
"target": "es5", "target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"], "lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true, "allowJs": true,
"skipLibCheck": true, "skipLibCheck": true,
"strict": false, "strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true, "noEmit": true,
"esModuleInterop": true, "esModuleInterop": true,
"module": "esnext", "module": "esnext",
"moduleResolution": "node", "moduleResolution": "bundler",
"resolveJsonModule": true, "resolveJsonModule": true,
"isolatedModules": true, "isolatedModules": true,
"jsx": "preserve" "jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./*"]
}
}, },
"include": ["next-env.d.ts", "ionic.d.ts", "**/*.ts", "**/*.tsx"], "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"] "exclude": ["node_modules"]
} }
...@@ -120,7 +120,7 @@ ...@@ -120,7 +120,7 @@
"with-http2": true, "with-http2": true,
"with-i18n-next-intl": true, "with-i18n-next-intl": true,
"with-i18n-rosetta": true, "with-i18n-rosetta": true,
"with-ionic-typescript": true, "with-ionic": true,
"with-iron-session": true, "with-iron-session": true,
"with-jest": true, "with-jest": true,
"with-jest-babel": true, "with-jest-babel": true,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment