Skip to content

Commit

Permalink
♻️ Ajoute des types TS aux différents composants
Browse files Browse the repository at this point in the history
En particulier, ça permettre d'améliorer la complétion !
  • Loading branch information
ushu committed Nov 19, 2024
1 parent 9b74892 commit 2dfd6e6
Show file tree
Hide file tree
Showing 36 changed files with 280 additions and 213 deletions.
15 changes: 13 additions & 2 deletions src/components/card.astro
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
---
import { Tick } from "@components/ui/icons";
import SquareRoundedCheck from "@components/ui/icons/square-rounded-check.astro";
import Link from "@components/ui/link.astro";
export type CardInfo = {
name: string;
popular: boolean;
features: string[];
button: {
text: string;
link: string;
};
};
type Props = {
card: CardInfo;
}
const { card } = Astro.props;
---

<div>
Expand Down
3 changes: 3 additions & 0 deletions src/components/container.astro
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
---
type Props = {
class?: string;
}
const { class: className } = Astro.props;
---

Expand Down
1 change: 0 additions & 1 deletion src/components/features.astro
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ const features = [
},
];
---

<div class="mt-16 md:mt-0">
<h2 class="text-3xl sm:text-4xl lg:text-5xl font-bold lg:tracking-tight">
Missions de l'institut
Expand Down
34 changes: 21 additions & 13 deletions src/components/item.astro
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
---
import { Icon } from "astro-icon";
const { color = "white", icon = "circle-filled" } = Astro.props;
let textColor;
let backgroundColor;
if (color == "white") {
textColor = "text-white";
backgroundColor = "bg-black";
} else {
textColor = `text-${color}-600`;
backgroundColor = `bg-${color}-100`;
const supportedStyles = {
white: {
textColor: "text-white",
backgroundColor: "bg-black",
},
sky: {
textColor: "text-sky-600",
backgroundColor: "bg-sky-100",
},
purple: {
textColor: "text-purple-600",
backgroundColor: "bg-purple-100",
},
}
type SupportedStyle = keyof typeof supportedStyles;
type Props = {
color?: SupportedStyle;
icon: string;
};
const { color = "white", icon = "circle-filled" } = Astro.props;
// Tailwind tree shaker
("bg-sky-100 bg-purple-100 bg-red-100 bg-black");
("text-sky-600 text-purple-600 text-red-600 text-black");
const {textColor, backgroundColor } = supportedStyles[color]
---

<span class="relative">
Expand Down
5 changes: 4 additions & 1 deletion src/components/itn-list-item.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
---
import Topic from "/src/components/itn-topic.astro";
import Topic, { type ItnTopicType } from "./itn-topic.astro";
type Props = {
name: ItnTopicType;
};
const { name } = Astro.props;
---

Expand Down
25 changes: 13 additions & 12 deletions src/components/itn-topic.astro
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,28 @@ import { Icon } from "astro-icon";
const icons = {
"Ingénierie Numérique": {
name: "abacus",
iconColor: "sky-600",
backgroundColor: "sky-100",
iconColor: "text-sky-600",
backgroundColor: "bg-sky-100",
},
"Industries Culturelles et Créatives": {
name: "tabler:palette",
iconColor: "purple-600",
backgroundColor: "purple-100",
iconColor: "text-purple-600",
backgroundColor: "bg-purple-100",
},
"Santé Numérique": {
name: "tabler:vaccine",
iconColor: "red-600",
backgroundColor: "red-100",
iconColor: "text-red-600",
backgroundColor: "bg-red-100",
},
};
export type ItnTopicType = keyof typeof icons;
type Props = {
name: ItnTopicType;
};
const { name } = Astro.props;
const icon = icons[name];
`bg-sky-100 text-sky-600
bg-purple-100 text-purple-600
bg-red-100 bg-red-600`;
const icon = icons[name];
---

<span
Expand All @@ -34,10 +35,10 @@ bg-red-100 bg-red-600`;
title={name}>
<span style="position: relative; top:0.0625em;">
<span
class={`bg-${icon.backgroundColor} top-1 mt-0 w-5 h-5 rounded inline-flex items-center justify-center`}>
class={`${icon.backgroundColor} top-1 mt-0 w-5 h-5 rounded inline-flex items-center justify-center`}>
<Icon
name={icon.name}
class={`text-${icon.iconColor} inline-block w-4 h-4`}
class={`${icon.iconColor} inline-block w-4 h-4`}
/>
</span>
</span>
Expand Down
41 changes: 25 additions & 16 deletions src/components/list-item.astro
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
---
import { Icon } from "astro-icon";
const { color = "white", icon = "circle-filled" } = Astro.props;
let textColor;
let backgroundColor;
const supportedStyles = {
white: {
textColor: "text-white",
backgroundColor: "bg-bkack",
},
black: {
textColor: "text-black",
backgroundColor: "bg-white",
},
sky: {
textColor: "text-sky-600",
backgroundColor: "bg-sky-100",
},
purple: {
textColor: "text-purple-600",
backgroundColor: "bg-purple-100",
},
};
type SupportedStyle = keyof typeof supportedStyles;
if (color == "white") {
textColor = "text-white";
backgroundColor = "bg-black";
} else if (color == "black") {
textColor = "text-black";
backgroundColor = "bg-white";
} else {
textColor = `text-${color}-600`;
backgroundColor = `bg-${color}-100`;
}
type Props = {
color?: SupportedStyle;
icon?: string;
};
const { color = "white", icon = "circle-filled" } = Astro.props;
// Tailwind tree shaker
("bg-sky-100 bg-purple-100 bg-red-100 bg-black bg-white");
("text-sky-600 text-purple-600 text-red-600 text-white text-black");
const { textColor, backgroundColor} = supportedStyles[color];
---

<li class="relative">
Expand Down
6 changes: 5 additions & 1 deletion src/components/mareva-list-item.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
---
import Topic from "/src/components/mareva-topic-alt.astro";
import Topic, { type MarevaTopicType } from "./mareva-topic-alt.astro";
type Props = {
name: MarevaTopicType
};
const { name } = Astro.props;
---

Expand Down
13 changes: 5 additions & 8 deletions src/components/mareva-topic-alt.astro
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,14 @@ const icons = {
background: "purple-200",
},
};
export type MarevaTopicType = keyof typeof icons;
type Props = {
name: MarevaTopicType
};
const { name } = Astro.props;
const icon = icons[name];
`bg-slate-800 text-slate-200
bg-orange-200 text-orange-500
bg-slate-200 text-slate-800
text-green-200
bg-purple-200 text-purple-500
bg-rose-200 text-rose-500
bg-blue-200 text-blue-500`;
const icon = icons[name];
---

<span
Expand Down
3 changes: 3 additions & 0 deletions src/components/mareva-topic.astro
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const icons = {
Apprentissage: "brain",
};
type Props = {
name: keyof typeof icons;
};
const { name } = Astro.props;
---

Expand Down
23 changes: 13 additions & 10 deletions src/components/movie-project.astro
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
---
import { Image } from "@astrojs/image/components";
import { Picture } from "@astrojs/image/components";
import Link from "@components/ui/card-link.astro";
import { Icon } from "astro-icon";
let { title, author, description, image, url, tags } = Astro.props;
tags = tags.split(",").map((tag) => tag.trim());
const icons = {
Photogrammétrie: "stereo-glasses",
Expand All @@ -20,10 +15,18 @@ const icons = {
Innovation: "bulb",
};
// import crossingTheLandscape from "assets/crossing-the-landscape.png";
type Props = {
title: string;
author: string;
description: string;
image: ImageMetadata;
url: string;
tags: string | string[];
};
const { title, author, description, image, url, tags: tagListOrString } = Astro.props;
// const url =
// "https://projet-ingenierie.minesparis.psl.eu/portfolio/capture-volumetrique-et-danse-collaboration-avec-lartiste-celeste-rogosin/";
const tagList = Array.isArray(tagListOrString) ? tagListOrString : tagListOrString.split(",");
const tags = tagList.map((tag) => tag.trim());
---

<div
Expand All @@ -32,8 +35,8 @@ const icons = {
src={image}
class="hidden md:inline-block rounded-l-md m-0"
alt="Crossing the Landscape"
width="196"
height="196"
width={196}
height={196}
loading="eager"
format="avif"
/>
Expand Down
13 changes: 9 additions & 4 deletions src/components/named-tag.astro
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
---
import { Icon } from "astro-icon";
const { type } = Astro.props;
const style = {
const AvailableStyles = {
"Ingénierie Numérique": {
iconName: "abacus",
iconColor: "text-sky-600",
Expand All @@ -28,8 +26,15 @@ const style = {
backgroundColor: "bg-slate-100",
textColor: "text-slate-900",
},
}[type]
}
type TagType = keyof typeof AvailableStyles;
type Props = {
type: TagType;
};
const { type } = Astro.props;
const style = AvailableStyles[type];
---

<span class={`py-1 px-1 rounded relative ${style.backgroundColor} ${style.iconColor}`}>
Expand Down
6 changes: 3 additions & 3 deletions src/components/navbar/dropdown.astro
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
import { Dropdown, DropdownItems } from "astro-navbar";
import { Dropdown as AstroDropdown, DropdownItems } from "astro-navbar";
const { title, lastItem, children } = Astro.props;
---

<li class="relative">
<Dropdown class="group">
<AstroDropdown class="group">
<button
class="flex items-center gap-1 w-full lg:w-auto lg:px-3 py-2 text-gray-600 hover:text-gray-900">
<span>{title}</span>
Expand Down Expand Up @@ -43,5 +43,5 @@ const { title, lastItem, children } = Astro.props;
</div>
</div>
</DropdownItems>
</Dropdown>
</AstroDropdown>
</li>
10 changes: 7 additions & 3 deletions src/components/navbar/navbar.astro
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
---
import Container from "@components/container.astro";
import Link from "@components/ui/link.astro";
import ITNLogo from "@components/itn-logo.astro";
import Dropdown from "./dropdown.astro";
import { Astronav, MenuItems, MenuIcon } from "astro-navbar";
import { Icon } from "astro-icon";
import Social from "@components/social.astro";
const menuitems = [
type MenuItem = {
title: string;
path: string;
children?: MenuItem[];
};
const menuitems: MenuItem[] = [
// {
// title: "Features",
// path: "#",
Expand Down
Loading

0 comments on commit 2dfd6e6

Please sign in to comment.