From f497f8cd8fa3c29d00352b03db7b8caa1335a84d Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Tue, 2 May 2023 11:57:36 +0200 Subject: [PATCH] Better default avatar if none is set (#19804) Closes #19681 --- js/apps/account-ui/public/avatar.svg | 33 ------ .../keycloak-masthead/src/DefaultAvatar.tsx | 109 ++++++++++++++++++ js/libs/keycloak-masthead/src/Masthead.tsx | 9 +- js/libs/keycloak-masthead/src/svg.d.ts | 4 + js/package-lock.json | 6 +- 5 files changed, 122 insertions(+), 39 deletions(-) delete mode 100644 js/apps/account-ui/public/avatar.svg create mode 100644 js/libs/keycloak-masthead/src/DefaultAvatar.tsx create mode 100644 js/libs/keycloak-masthead/src/svg.d.ts diff --git a/js/apps/account-ui/public/avatar.svg b/js/apps/account-ui/public/avatar.svg deleted file mode 100644 index 11c80b85ff..0000000000 --- a/js/apps/account-ui/public/avatar.svg +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/js/libs/keycloak-masthead/src/DefaultAvatar.tsx b/js/libs/keycloak-masthead/src/DefaultAvatar.tsx new file mode 100644 index 0000000000..6e7f8e906d --- /dev/null +++ b/js/libs/keycloak-masthead/src/DefaultAvatar.tsx @@ -0,0 +1,109 @@ +import styles from "@patternfly/react-styles/css/components/Avatar/avatar"; +import { css } from "@patternfly/react-styles"; + +type DefaultAvatarProps = { + className?: string; + border?: "light" | "dark"; + size?: "sm" | "md" | "lg" | "xl"; +}; + +export const DefaultAvatar = ({ + className = "", + border, + size = "md", +}: DefaultAvatarProps) => ( + + + + + + + + + + + + + + + + + + + + + + +); diff --git a/js/libs/keycloak-masthead/src/Masthead.tsx b/js/libs/keycloak-masthead/src/Masthead.tsx index 72313c6cb2..b686106f94 100644 --- a/js/libs/keycloak-masthead/src/Masthead.tsx +++ b/js/libs/keycloak-masthead/src/Masthead.tsx @@ -16,6 +16,7 @@ import { ReactNode } from "react"; import { KeycloakDropdown } from "./KeycloakDropdown"; import { useTranslation } from "./translation/useTranslation"; import { loggedInUserName } from "./util"; +import { DefaultAvatar } from "./DefaultAvatar"; type BrandLogo = BrandProps & { onClick?: () => void; @@ -109,9 +110,11 @@ const KeycloakMasthead = ({ /> - + {picture || avatar?.src ? ( + + ) : ( + + )} } /> diff --git a/js/libs/keycloak-masthead/src/svg.d.ts b/js/libs/keycloak-masthead/src/svg.d.ts new file mode 100644 index 0000000000..3a982e1598 --- /dev/null +++ b/js/libs/keycloak-masthead/src/svg.d.ts @@ -0,0 +1,4 @@ +declare module "*.svg" { + const content: React.FC>; + export default content; +} diff --git a/js/package-lock.json b/js/package-lock.json index 0910ede86f..afb1044031 100644 --- a/js/package-lock.json +++ b/js/package-lock.json @@ -211,9 +211,9 @@ "dev": true }, "node_modules/@babel/code-frame": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.18.6.tgz", - "integrity": "sha512-TDCmlK5eOvH+eH7cdAFlNXeVJqWIQ7gW9tY1GJIpUtFb6CmjVyq2VM3u71bOyR8CRihcCgMUYoDNyLXao3+70Q==", + "version": "7.21.4", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.21.4.tgz", + "integrity": "sha512-LYvhNKfwWSPpocw8GI7gpK2nq3HSDuEPC/uSYaALSJu9xjsalaaYFOq0Pwt5KmVqwEbZlDu81aLXwBOmD/Fv9g==", "dev": true, "dependencies": { "@babel/highlight": "^7.18.6"