diff --git a/scripts/picto-builder.ts b/scripts/picto-builder.ts index db7e1f9b7..1c421539b 100644 --- a/scripts/picto-builder.ts +++ b/scripts/picto-builder.ts @@ -126,9 +126,9 @@ async function generateComponent(svgPath: string, outputDir: string): Promise {{& svgContent }} , @@ -167,7 +167,7 @@ async function generateTypes(outputDir: string): Promise { const iconNames = files.map(f => pascalCaseName(path.basename(f, ".tsx"))); const filePath = path.join(outputDir, "index.d.ts"); - const header = `import { IconWrapper } from './utils/IconWrapper';\n\ntype SvgIconComponent = typeof IconWrapper;\n\n`; + const header = `import { PictoWrapper } from './utils/PictoWrapper';\n\ntype SvgIconComponent = typeof PictoWrapper;\n\n`; const lines = iconNames.map(name => `export const ${name}: SvgIconComponent;`); const content = `${header}${lines.join("\n")}\n`; diff --git a/src/Tile.tsx b/src/Tile.tsx index 6cee46e21..b43091b47 100644 --- a/src/Tile.tsx +++ b/src/Tile.tsx @@ -21,17 +21,6 @@ export type TileProps = { desc?: ReactNode; detail?: ReactNode; start?: ReactNode; - imageUrl?: string; - imageAlt?: string; - /** - * @deprecated imageWidth has no effect - */ - imageWidth?: string | number; - /** - * @deprecated imageHeight has no effect - */ - imageHeight?: string | number; - imageSvg?: boolean; grey?: boolean; /** make the whole tile clickable */ enlargeLinkOrButton?: boolean; @@ -60,7 +49,8 @@ export type TileProps = { noBackground?: boolean; disabled?: boolean; style?: CSSProperties; -} & (TileProps.WithLink | TileProps.WithButton | TileProps.Unclickable); +} & (TileProps.WithImage | TileProps.WithPicto) & + (TileProps.WithLink | TileProps.WithButton | TileProps.Unclickable); export namespace TileProps { export type Unclickable = { @@ -78,6 +68,30 @@ export namespace TileProps { linkProps?: never; buttonProps: ComponentProps<"button">; }; + + export type WithImage = { + imageUrl?: string; + imageAlt?: string; + /** + * @deprecated imageWidth has no effect + */ + imageWidth?: string | number; + /** + * @deprecated imageHeight has no effect + */ + imageHeight?: string | number; + imageSvg?: boolean; + pictogram?: never; + }; + + export type WithPicto = { + imageUrl?: never; + imageAlt?: never; + imageWidth?: never; + imageHeight?: never; + imageSvg?: never; + pictogram: ReactNode; + }; } /** @see */ @@ -99,6 +113,7 @@ export const Tile = memo( imageWidth, imageHeight, imageSvg = false, + pictogram, orientation = "vertical", small = false, noBorder = false, @@ -189,33 +204,37 @@ export const Tile = memo( - {imageUrl !== undefined && imageUrl.length > 0 && ( + {((imageUrl !== undefined && imageUrl.length > 0) || pictogram !== undefined) && (
- {imageSvg ? ( + {imageSvg || pictogram !== undefined ? (
- - {( - [ - "artwork-decorative", - "artwork-minor", - "artwork-major" - ] as const - ).map(label => ( - - ))} - + {pictogram !== undefined ? ( + pictogram + ) : ( + + {( + [ + "artwork-decorative", + "artwork-minor", + "artwork-major" + ] as const + ).map(label => ( + + ))} + + )}
) : (
diff --git a/src/picto/Accessibility.tsx b/src/picto/Accessibility.tsx index c043d8f95..e83213bd3 100644 --- a/src/picto/Accessibility.tsx +++ b/src/picto/Accessibility.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/Archive.tsx b/src/picto/Archive.tsx index 9fdfb58a6..1ca09c41c 100644 --- a/src/picto/Archive.tsx +++ b/src/picto/Archive.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/Art.tsx b/src/picto/Art.tsx index 7c6e8d1fd..ebee628dc 100644 --- a/src/picto/Art.tsx +++ b/src/picto/Art.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/Backpack.tsx b/src/picto/Backpack.tsx index edc7f2768..89ea8b949 100644 --- a/src/picto/Backpack.tsx +++ b/src/picto/Backpack.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/Book.tsx b/src/picto/Book.tsx index 3dc26fda6..5090ff3b3 100644 --- a/src/picto/Book.tsx +++ b/src/picto/Book.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/Calendar.tsx b/src/picto/Calendar.tsx index fcb86f610..4eb58b0ea 100644 --- a/src/picto/Calendar.tsx +++ b/src/picto/Calendar.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/Catalog.tsx b/src/picto/Catalog.tsx index 120c0241b..db36dc53c 100644 --- a/src/picto/Catalog.tsx +++ b/src/picto/Catalog.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/CityHall.tsx b/src/picto/CityHall.tsx index 366c0ce9b..e017406a5 100644 --- a/src/picto/CityHall.tsx +++ b/src/picto/CityHall.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/Coding.tsx b/src/picto/Coding.tsx index d504eea2c..b416c7637 100644 --- a/src/picto/Coding.tsx +++ b/src/picto/Coding.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/Companie.tsx b/src/picto/Companie.tsx index 1dfb2e058..aa0cc2f4c 100644 --- a/src/picto/Companie.tsx +++ b/src/picto/Companie.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/Conclusion.tsx b/src/picto/Conclusion.tsx index ed67390d1..9de9a667b 100644 --- a/src/picto/Conclusion.tsx +++ b/src/picto/Conclusion.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/ConnectionLost.tsx b/src/picto/ConnectionLost.tsx index 1e4c1fc82..b99e3321b 100644 --- a/src/picto/ConnectionLost.tsx +++ b/src/picto/ConnectionLost.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/Contract.tsx b/src/picto/Contract.tsx index 397234532..cd816f560 100644 --- a/src/picto/Contract.tsx +++ b/src/picto/Contract.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/DataVisualization.tsx b/src/picto/DataVisualization.tsx index bf9eec057..85974ca4b 100644 --- a/src/picto/DataVisualization.tsx +++ b/src/picto/DataVisualization.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/DocumentAdd.tsx b/src/picto/DocumentAdd.tsx index 89b7ccb33..24b7e9558 100644 --- a/src/picto/DocumentAdd.tsx +++ b/src/picto/DocumentAdd.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/DocumentSearch.tsx b/src/picto/DocumentSearch.tsx index fa24ea6d4..3fd75e3e1 100644 --- a/src/picto/DocumentSearch.tsx +++ b/src/picto/DocumentSearch.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/DrivingLicense.tsx b/src/picto/DrivingLicense.tsx index 5e1bd294d..7d179b66c 100644 --- a/src/picto/DrivingLicense.tsx +++ b/src/picto/DrivingLicense.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/DrivingLicenseNew.tsx b/src/picto/DrivingLicenseNew.tsx index cb3efb1b5..be7ea2393 100644 --- a/src/picto/DrivingLicenseNew.tsx +++ b/src/picto/DrivingLicenseNew.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/EyeOff.tsx b/src/picto/EyeOff.tsx index 212d2ee23..063c67b84 100644 --- a/src/picto/EyeOff.tsx +++ b/src/picto/EyeOff.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/Firefighter.tsx b/src/picto/Firefighter.tsx index 07b387f97..311db757f 100644 --- a/src/picto/Firefighter.tsx +++ b/src/picto/Firefighter.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/FlowList.tsx b/src/picto/FlowList.tsx index 3e45f64a7..d8550f4e6 100644 --- a/src/picto/FlowList.tsx +++ b/src/picto/FlowList.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/Food.tsx b/src/picto/Food.tsx index 6c20008d9..1387e5042 100644 --- a/src/picto/Food.tsx +++ b/src/picto/Food.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/Grocery.tsx b/src/picto/Grocery.tsx index a9162a657..e74122d06 100644 --- a/src/picto/Grocery.tsx +++ b/src/picto/Grocery.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/Hospital.tsx b/src/picto/Hospital.tsx index b3f3d42fc..02bed1d8e 100644 --- a/src/picto/Hospital.tsx +++ b/src/picto/Hospital.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/InProgress.tsx b/src/picto/InProgress.tsx index 85c3c3b3b..d3af50325 100644 --- a/src/picto/InProgress.tsx +++ b/src/picto/InProgress.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/Innovation.tsx b/src/picto/Innovation.tsx index 755b0cb8a..641ea18b7 100644 --- a/src/picto/Innovation.tsx +++ b/src/picto/Innovation.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/Leaf.tsx b/src/picto/Leaf.tsx index b06d153e0..23b4c51ee 100644 --- a/src/picto/Leaf.tsx +++ b/src/picto/Leaf.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/LocationFrance.tsx b/src/picto/LocationFrance.tsx index 5e8b8fc55..079dc9c4f 100644 --- a/src/picto/LocationFrance.tsx +++ b/src/picto/LocationFrance.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/MainSend.tsx b/src/picto/MainSend.tsx index ad4502e87..d69e668a4 100644 --- a/src/picto/MainSend.tsx +++ b/src/picto/MainSend.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/Map.tsx b/src/picto/Map.tsx index 44808c0d3..700f43243 100644 --- a/src/picto/Map.tsx +++ b/src/picto/Map.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/MedicalResearch.tsx b/src/picto/MedicalResearch.tsx index cb0ed0c4c..e1b11ce68 100644 --- a/src/picto/MedicalResearch.tsx +++ b/src/picto/MedicalResearch.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/Mountain.tsx b/src/picto/Mountain.tsx index 90c277675..73fd0b6f6 100644 --- a/src/picto/Mountain.tsx +++ b/src/picto/Mountain.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/NationalIdentityCard.tsx b/src/picto/NationalIdentityCard.tsx index 625ee7ad5..61ab4e024 100644 --- a/src/picto/NationalIdentityCard.tsx +++ b/src/picto/NationalIdentityCard.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/NuclearPlant.tsx b/src/picto/NuclearPlant.tsx index d8aa46182..46cc5ab82 100644 --- a/src/picto/NuclearPlant.tsx +++ b/src/picto/NuclearPlant.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/Passport.tsx b/src/picto/Passport.tsx index 62bdf0736..437ebd3b3 100644 --- a/src/picto/Passport.tsx +++ b/src/picto/Passport.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/Police.tsx b/src/picto/Police.tsx index e6bffe00e..0500c55c0 100644 --- a/src/picto/Police.tsx +++ b/src/picto/Police.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/PressCard.tsx b/src/picto/PressCard.tsx index 85c206004..a63396439 100644 --- a/src/picto/PressCard.tsx +++ b/src/picto/PressCard.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/Search.tsx b/src/picto/Search.tsx index abd05176f..2956a6f93 100644 --- a/src/picto/Search.tsx +++ b/src/picto/Search.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/SelfTraining.tsx b/src/picto/SelfTraining.tsx index e7e9592b2..7be37bffc 100644 --- a/src/picto/SelfTraining.tsx +++ b/src/picto/SelfTraining.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/TaxStamp.tsx b/src/picto/TaxStamp.tsx index f67b856fd..6dbbe412f 100644 --- a/src/picto/TaxStamp.tsx +++ b/src/picto/TaxStamp.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/TechnicalError.tsx b/src/picto/TechnicalError.tsx index e9ab4d26e..5f3a121d6 100644 --- a/src/picto/TechnicalError.tsx +++ b/src/picto/TechnicalError.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/TravelBack.tsx b/src/picto/TravelBack.tsx index 1ce5dc15b..61096cd2b 100644 --- a/src/picto/TravelBack.tsx +++ b/src/picto/TravelBack.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/Vaccine.tsx b/src/picto/Vaccine.tsx index 0b5e50d39..86969b1e6 100644 --- a/src/picto/Vaccine.tsx +++ b/src/picto/Vaccine.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/VideoGames.tsx b/src/picto/VideoGames.tsx index 7e34ae713..4badd6e8f 100644 --- a/src/picto/VideoGames.tsx +++ b/src/picto/VideoGames.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> diff --git a/src/picto/Wheelchair.tsx b/src/picto/Wheelchair.tsx index e8813fa31..e1e8684ae 100644 --- a/src/picto/Wheelchair.tsx +++ b/src/picto/Wheelchair.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { createIcon } from "./utils/IconWrapper"; +import { createPicto } from "./utils/PictoWrapper"; -export default createIcon( +export default createPicto( <> , "fontSize">; - -const getSize = (size: IconSize) => { - switch (size) { - case "small": - return "1.25em"; - case "medium": - return "1.5em"; - case "large": - return "2.5em"; - case "inherit": - return "inherit"; - default: - return size; - } -}; - -const getColor = (color?: IconColor) => { - if (!color) { - return undefined; - } - return `fr-artwork--${color}`; -}; - -export const IconWrapper: React.FC = memo( - ({ children, color, fontSize = "medium", className, ...props }) => ( - - ) -); - -export function createIcon(SvgPath: JSX.Element, displayName: string) { - const IconComponent: React.FC = props => ( - {SvgPath} - ); - - IconComponent.displayName = displayName; - return IconComponent; -} diff --git a/src/picto/utils/PictoWrapper.tsx b/src/picto/utils/PictoWrapper.tsx new file mode 100644 index 000000000..f17180e85 --- /dev/null +++ b/src/picto/utils/PictoWrapper.tsx @@ -0,0 +1,82 @@ +import React, { memo } from "react"; +import { cx } from "../../tools/cx"; + +export type PictoProps = { + fontSize?: PictoProps.Size; + color?: PictoProps.Color; +} & Omit, "fontSize">; + +export namespace PictoProps { + export type Size = "small" | "medium" | "large" | "inherit" | (string & {}); + const colors = [ + "red-marianne", + "green-tilleul-verveine", + "green-bourgeon", + "green-emeraude", + "green-menthe", + "green-archipel", + "blue-ecume", + "blue-cumulus", + "purple-glycine", + "pink-macaron", + "pink-tuile", + "yellow-tournesol", + "yellow-moutarde", + "orange-terre-battue", + "brown-cafe-creme", + "brown-caramel", + "brown-opera", + "beige-gris-galet" + ] as const; + export type Color = typeof colors[number]; +} + +const getSize = (size: PictoProps.Size) => { + switch (size) { + case "small": + return "1.25em"; + case "medium": + return "1.5em"; + case "large": + return "2.5em"; + case "inherit": + return "inherit"; + default: + return size; + } +}; + +const getColor = (color?: PictoProps.Color) => { + if (!color) { + return undefined; + } + return `fr-artwork--${color}`; +}; + +export const PictoWrapper: React.FC = memo( + ({ children, color, fontSize = "medium", className, ...props }) => ( + + ) +); + +export function createPicto(SvgPath: JSX.Element, displayName: string) { + const IconComponent: React.FC = props => ( + {SvgPath} + ); + + IconComponent.displayName = displayName; + return IconComponent; +} diff --git a/stories/Tile.stories.tsx b/stories/Tile.stories.tsx index fa6c550de..382d2f21c 100644 --- a/stories/Tile.stories.tsx +++ b/stories/Tile.stories.tsx @@ -9,6 +9,7 @@ import { getStoryFactory } from "./getStory"; import { sectionName } from "./sectionName"; import picto from "./assets/city-hall.svg"; +import CityHall from "../dist/picto/CityHall"; const { meta, getStory } = getStoryFactory({ sectionName, @@ -119,6 +120,10 @@ const { meta, getStory } = getStoryFactory({ }, "type": "boolean" }, + "pictogram": { + "description": + "Instead of using an image with `imageUrl` and `imageSvg`, you can use [native DSFR pictogram components](/?path=/docs/🖼%EF%B8%8F-pictograms--page) or any other SVG component." + }, "grey": { "description": "Set to true if the background should be grey. Not applicable if noBackground is set true.", @@ -201,7 +206,8 @@ const defaultProps: TileProps = { "noIcon": false, "noBackground": false, "grey": false, - "disabled": false + "disabled": false, + "pictogram": undefined }; export const Default = getStory({ ...defaultProps }); @@ -265,6 +271,19 @@ export const TileWithoutImage = getStory( { "description": "Tuile sans picto" } ); +export const TileWithNativePictogram = getStory( + { + ...defaultProps, + imageUrl: undefined, + imageSvg: undefined, + imageAlt: undefined, + imageWidth: undefined, + imageHeight: undefined, + pictogram: + }, + { "description": "Tuile avec Pictogramme natif DSFR" } +); + export const TileMDVertical = getStory( { ...defaultProps }, { "description": "Tuile MD Verticale" } diff --git a/test/integration/vite/src/Home.tsx b/test/integration/vite/src/Home.tsx index 5670da0d3..aadd201cb 100644 --- a/test/integration/vite/src/Home.tsx +++ b/test/integration/vite/src/Home.tsx @@ -9,9 +9,11 @@ import { fr } from "@codegouvfr/react-dsfr"; import { useIsDark } from "@codegouvfr/react-dsfr/useIsDark"; import { useState } from "react"; import { Table } from "@codegouvfr/react-dsfr/Table"; +import { Tile } from "@codegouvfr/react-dsfr/Tile"; import { Accordion } from "@codegouvfr/react-dsfr/Accordion"; -import { Book, Money, Police, Sun } from '@codegouvfr/react-dsfr/picto'; +import { Book, Money, Police, Sun, LocationFrance } from '@codegouvfr/react-dsfr/picto'; +import CityHall from './assets/city-hall.svg'; export function Home() { const { isDark, setIsDark } = useIsDark(); @@ -31,12 +33,12 @@ export function Home() {