Updated packages

Added icon aspect ratio option
This commit is contained in:
Jordan Roher 2023-07-16 10:28:42 -07:00
parent 486bb2a9d2
commit d616c66677
8 changed files with 406 additions and 363 deletions

670
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,7 @@
"repository": { "repository": {
"url": "https://github.com/notclickable-jordan/starbase-80" "url": "https://github.com/notclickable-jordan/starbase-80"
}, },
"version": "1.0.1", "version": "1.1.5",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
@ -13,20 +13,20 @@
"start": "npm run build && vite preview" "start": "npm run build && vite preview"
}, },
"dependencies": { "dependencies": {
"@types/react-dom": "^18.0.11", "@types/react-dom": "^18.2.7",
"@types/react-helmet": "^6.1.6", "@types/react-helmet": "^6.1.6",
"@types/react": "^18.0.28", "@types/react": "^18.2.15",
"@vitejs/plugin-react": "^3.1.0", "@vitejs/plugin-react": "^4.0.3",
"autoprefixer": "^10.4.14", "autoprefixer": "^10.4.14",
"js-yaml": "^4.1.0", "js-yaml": "^4.1.0",
"postcss": "^8.4.23", "postcss": "^8.4.26",
"prettier": "^2.8.7", "prettier": "^3.0.0",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"react-helmet": "^6.1.0", "react-helmet": "^6.1.0",
"react": "^18.2.0", "react": "^18.2.0",
"tailwindcss": "^3.3.1", "tailwindcss": "^3.3.3",
"typescript": "^4.9.3", "typescript": "^5.1.6",
"vite": "^4.2.0" "vite": "^4.4.4"
}, },
"prettier": { "prettier": {
"arrowParens": "avoid", "arrowParens": "avoid",

View File

@ -129,6 +129,7 @@ Can have as many categories as you like.
- **iconBG**: optional, hex code or [Tailwind color](https://tailwindcss.com/docs/background-color) (do not prefix with `bg-`). Background color for icons. - **iconBG**: optional, hex code or [Tailwind color](https://tailwindcss.com/docs/background-color) (do not prefix with `bg-`). Background color for icons.
- **iconColor**: optional, hex code or [Tailwind color](https://tailwindcss.com/docs/background-color) (do not prefix with `bg-`). Only used as the fill color for Material Design icons. - **iconColor**: optional, hex code or [Tailwind color](https://tailwindcss.com/docs/background-color) (do not prefix with `bg-`). Only used as the fill color for Material Design icons.
- **iconBubble**: optional, defaults to `true`, when `false` the bubble and shadow are removed from the icon - **iconBubble**: optional, defaults to `true`, when `false` the bubble and shadow are removed from the icon
- **iconAspect**: optional, defaults to `"square"`, can set to `"width"` or `"height"` to constrain the icon to the width or height of the icon, respectively
## Template ## Template
@ -145,7 +146,8 @@ Can have as many categories as you like.
"icon": "mdi-cloud", "icon": "mdi-cloud",
"iconBG": "#fff", "iconBG": "#fff",
"iconColor": "#000", "iconColor": "#000",
"iconBubble": false "iconBubble": false,
"iconAspect": "width"
} }
] ]
} }

View File

@ -4,20 +4,21 @@ import { NEWWINDOW } from "../variables";
interface IProps { interface IProps {
uri: string; uri: string;
title?: string; title?: string;
className?: string;
children?: React.ReactNode; children?: React.ReactNode;
} }
export const Anchor: React.FunctionComponent<IProps> = ({ uri, children, title }) => { export const Anchor: React.FunctionComponent<IProps> = ({ uri, children, title, className }) => {
if (NEWWINDOW) { if (NEWWINDOW) {
return ( return (
<a href={uri} target="_blank" rel="noreffer" title={title}> <a href={uri} target="_blank" rel="noreffer" title={title} className={className}>
{children} {children}
</a> </a>
); );
} }
return ( return (
<a href={uri} title={title}> <a href={uri} title={title} className={className}>
{children} {children}
</a> </a>
); );

View File

@ -1,5 +1,6 @@
import React from "react"; import React from "react";
import { is } from "../shared/is"; import { is } from "../shared/is";
import { IconAspect } from "../shared/types";
import { Anchor } from "./anchor"; import { Anchor } from "./anchor";
const iconColors = [ const iconColors = [
@ -30,10 +31,20 @@ interface IProps {
iconColor?: string; iconColor?: string;
iconBG?: string; iconBG?: string;
iconBubble?: boolean; iconBubble?: boolean;
iconAspect?: IconAspect;
uri?: string; uri?: string;
} }
export const Icon: React.FunctionComponent<IProps> = ({ name, uri, icon, index, iconBG, iconBubble, iconColor }) => { export const Icon: React.FunctionComponent<IProps> = ({
name,
uri,
icon,
index,
iconBG,
iconBubble,
iconColor,
iconAspect,
}) => {
if (is.null(icon)) { if (is.null(icon)) {
if (!is.null(uri)) { if (!is.null(uri)) {
return ( return (
@ -48,13 +59,27 @@ export const Icon: React.FunctionComponent<IProps> = ({ name, uri, icon, index,
if (!is.null(uri)) { if (!is.null(uri)) {
return ( return (
<Anchor uri={uri as string} title={name}> <Anchor uri={uri as string} title={name} className="flex">
<IconBase icon={icon as string} iconBG={iconBG} iconColor={iconColor} iconBubble={iconBubble} /> <IconBase
icon={icon as string}
iconBG={iconBG}
iconColor={iconColor}
iconBubble={iconBubble}
iconAspect={iconAspect}
/>
</Anchor> </Anchor>
); );
} }
return <IconBase icon={icon as string} iconBG={iconBG} iconColor={iconColor} iconBubble={iconBubble} />; return (
<IconBase
icon={icon as string}
iconBG={iconBG}
iconColor={iconColor}
iconBubble={iconBubble}
iconAspect={iconAspect}
/>
);
}; };
interface IIconBlankProps { interface IIconBlankProps {
@ -82,9 +107,16 @@ interface IIconBaseProps {
iconColor?: string; iconColor?: string;
iconBG?: string; iconBG?: string;
iconBubble?: boolean; iconBubble?: boolean;
iconAspect?: IconAspect;
} }
const IconBase: React.FunctionComponent<IIconBaseProps> = ({ icon, iconBG, iconBubble, iconColor }) => { const IconBase: React.FunctionComponent<IIconBaseProps> = ({
icon,
iconBG,
iconBubble,
iconColor,
iconAspect = "square",
}) => {
let iconType: IconType = IconType.uri; let iconType: IconType = IconType.uri;
if (icon.startsWith("http") || icon.startsWith("/")) { if (icon.startsWith("http") || icon.startsWith("/")) {
@ -96,7 +128,23 @@ const IconBase: React.FunctionComponent<IIconBaseProps> = ({ icon, iconBG, iconB
} }
// Everyone starts the same size // Everyone starts the same size
let iconClassName = "block w-16 h-16 overflow-hidden bg-contain"; let iconClassName = "block overflow-hidden bg-contain";
let iconWidthHeightClassName = "";
switch (iconAspect) {
case "width":
iconWidthHeightClassName = "w-16";
break;
case "height":
iconWidthHeightClassName = "h-16";
break;
case "square":
default:
iconWidthHeightClassName = "w-16 h-16";
break;
}
iconClassName += " " + iconWidthHeightClassName;
if (is.null(iconBubble) || iconBubble !== false) { if (is.null(iconBubble) || iconBubble !== false) {
iconClassName += " rounded-2xl border border-black/5 shadow-sm"; iconClassName += " rounded-2xl border border-black/5 shadow-sm";
@ -161,7 +209,7 @@ const IconBase: React.FunctionComponent<IIconBaseProps> = ({ icon, iconBG, iconB
return ( return (
<div className={iconClassName} style={{ ...iconStyle }}> <div className={iconClassName} style={{ ...iconStyle }}>
<div <div
className={`block w-16 h-16 ${mdiIconColorFull} overflow-hidden`} className={`block ${iconWidthHeightClassName} ${mdiIconColorFull} overflow-hidden`}
style={{ style={{
...mdiIconStyle, ...mdiIconStyle,
mask: `url(https://cdn.jsdelivr.net/npm/@mdi/svg@latest/svg/${icon}.svg) no-repeat center / contain`, mask: `url(https://cdn.jsdelivr.net/npm/@mdi/svg@latest/svg/${icon}.svg) no-repeat center / contain`,

View File

@ -24,7 +24,7 @@ interface IServiceProps {
} }
const Service: React.FunctionComponent<IServiceProps> = ({ service, index }) => { const Service: React.FunctionComponent<IServiceProps> = ({ service, index }) => {
const { name, uri, description, icon, iconBG, iconBubble, iconColor } = service; const { name, uri, description, icon, iconBG, iconBubble, iconColor, iconAspect } = service;
return ( return (
<li className="p-4 flex gap-4"> <li className="p-4 flex gap-4">
@ -38,6 +38,7 @@ const Service: React.FunctionComponent<IServiceProps> = ({ service, index }) =>
iconColor={iconColor} iconColor={iconColor}
iconBG={iconBG} iconBG={iconBG}
iconBubble={iconBubble} iconBubble={iconBubble}
iconAspect={iconAspect}
/> />
</span> </span>
)} )}

View File

@ -13,4 +13,7 @@ export interface IService {
iconColor?: string; iconColor?: string;
iconBG?: string; iconBG?: string;
iconBubble?: boolean; iconBubble?: boolean;
iconAspect?: IconAspect;
} }
export type IconAspect = "square" | "width" | "height";

View File

@ -1 +1 @@
1.1.4 1.1.5