From 8681e6104b85b7a620d08f4d4c26f84393b95ed3 Mon Sep 17 00:00:00 2001 From: Andrew Noblet Date: Tue, 5 Mar 2024 11:59:23 -0500 Subject: [PATCH 1/3] feat: add custom buttons to the navigation bar --- .../ui-react/src/components/Header/Header.tsx | 15 ++++++++ .../ui-react/src/containers/Layout/Layout.tsx | 36 +++++++++++++++++-- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/packages/ui-react/src/components/Header/Header.tsx b/packages/ui-react/src/components/Header/Header.tsx index 3aedb2575..4a8ef537a 100644 --- a/packages/ui-react/src/components/Header/Header.tsx +++ b/packages/ui-react/src/components/Header/Header.tsx @@ -66,6 +66,15 @@ type Props = { selectProfile: ({ avatarUrl, id }: { avatarUrl: string; id: string }) => void; isSelectingProfile: boolean; }; + + rightSideItems?: CustomMenuItem[]; +}; + +type CustomMenuItem = { + label: string; + url: string; + position?: 'before' | 'right' | 'after'; + key: string; }; const Header: React.FC = ({ @@ -97,6 +106,7 @@ const Header: React.FC = ({ siteName, profilesData: { currentProfile, profiles, profilesEnabled, selectProfile, isSelectingProfile } = {}, navItems = [], + rightSideItems, }) => { const { t } = useTranslation('menu'); const [logoLoaded, setLogoLoaded] = useState(false); @@ -236,6 +246,11 @@ const Header: React.FC = ({ )} +
+ {rightSideItems?.map((item) => ( +
{renderSearch()} {renderLanguageDropdown()} diff --git a/packages/ui-react/src/containers/Layout/Layout.tsx b/packages/ui-react/src/containers/Layout/Layout.tsx index f4bba8739..b609c9c8d 100644 --- a/packages/ui-react/src/containers/Layout/Layout.tsx +++ b/packages/ui-react/src/containers/Layout/Layout.tsx @@ -41,6 +41,23 @@ const Layout = () => { const isLoggedIn = !!useAccountStore(({ user }) => user); const favoritesEnabled = !!config.features?.favoritesList; const { menu, assets, siteName, description, features, styling, custom } = config; + + const customItems = useMemo(() => { + if (!custom) return []; + + return Object.keys(custom) + .filter((key) => key.startsWith('navItem')) + .map((key) => { + const item = JSON.parse(custom[key] as string); + item.key = Math.random().toString(); + return item; + }); + }, [custom]); + + const beforeItems = customItems.filter((item) => item.position === 'before'); + const rightItems = customItems.filter((item) => item.position === 'right'); + const afterItems = customItems.filter((item) => !['before', 'right'].includes(item.position)); + const metaDescription = description || t('default_description'); const { footerText: configFooterText } = styling || {}; const footerText = configFooterText || unicodeToChar(env.APP_FOOTER_TEXT); @@ -199,8 +216,12 @@ const Layout = () => { selectProfile: ({ avatarUrl, id }) => selectProfile.mutate({ id, avatarUrl }), isSelectingProfile: selectProfile.isLoading, }} - navItems={navItems} - /> + > +
From 4d4fdf6e6340ee34db395922526384a001032ecc Mon Sep 17 00:00:00 2001 From: Andrew Noblet Date: Tue, 5 Mar 2024 23:53:16 -0500 Subject: [PATCH 2/3] feat: add custom buttons to the video details section --- .../ui-react/src/components/Button/Button.tsx | 1 + .../src/components/CTAButton/CTAButton.tsx | 23 +++++++++++++ .../components/VideoDetails/VideoDetails.tsx | 6 ++++ .../VideoDetailsInline/VideoDetailsInline.tsx | 6 +++- .../components/VideoLayout/VideoLayout.tsx | 17 +++++++++- .../ui-react/src/hooks/useCustomCTAButtons.ts | 32 +++++++++++++++++++ 6 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 packages/ui-react/src/components/CTAButton/CTAButton.tsx create mode 100644 packages/ui-react/src/hooks/useCustomCTAButtons.ts diff --git a/packages/ui-react/src/components/Button/Button.tsx b/packages/ui-react/src/components/Button/Button.tsx index 0961aacc0..1792ada34 100644 --- a/packages/ui-react/src/components/Button/Button.tsx +++ b/packages/ui-react/src/components/Button/Button.tsx @@ -30,6 +30,7 @@ type Props = { id?: string; as?: 'button' | 'a'; activeClassname?: string; + target?: string; } & React.AriaAttributes; const Button: React.FC = ({ diff --git a/packages/ui-react/src/components/CTAButton/CTAButton.tsx b/packages/ui-react/src/components/CTAButton/CTAButton.tsx new file mode 100644 index 000000000..d99ce1f11 --- /dev/null +++ b/packages/ui-react/src/components/CTAButton/CTAButton.tsx @@ -0,0 +1,23 @@ +import React from 'react'; + +import useBreakpoint, { Breakpoint } from '../../hooks/useBreakpoint'; +import Button from '../Button/Button'; + +type Props = { + label: string; + url: string; +}; + +export type CTAItem = { + label: string; + url: string; + description?: string; +}; + +const CTAButton = ({ label, url }: Props) => { + const breakpoint = useBreakpoint(); + + return