From 7920c9df3cd8519d6049aec49558e33c830762b5 Mon Sep 17 00:00:00 2001 From: Filip Witosz Date: Thu, 11 Feb 2021 16:48:06 +0100 Subject: [PATCH] Allows for native titles to replace Reqore popovers. --- package.json | 2 +- src/components/Sidebar/index.tsx | 3 +++ src/components/Sidebar/item.tsx | 26 +++++++++++++++++++++++++ src/stories/Sidebar/Sidebar.stories.tsx | 6 ++++++ 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 28fe14ba..49f9984b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@qoretechnologies/reqore", - "version": "0.2.6", + "version": "0.2.7", "description": "ReQore is a UI library of components for Qorus connected apps", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/components/Sidebar/index.tsx b/src/components/Sidebar/index.tsx index 609d2565..8564ff0c 100644 --- a/src/components/Sidebar/index.tsx +++ b/src/components/Sidebar/index.tsx @@ -50,6 +50,7 @@ export interface IQorusSidebarProps { path: string; wrapperStyle?: React.CSSProperties; onBookmarksChange?: (bookmarks: string[]) => void; + useNativeTitle?: boolean; } const StyledSidebar = styled.div<{ expanded?: boolean; theme: IReqoreTheme }>` @@ -312,6 +313,7 @@ const ReqoreSidebar: React.FC = ({ collapseLabel, wrapperStyle, onBookmarksChange, + useNativeTitle, }) => { const [_isCollapsed, setIsCollapsed] = useState( isCollapsed || false @@ -389,6 +391,7 @@ const ReqoreSidebar: React.FC = ({ onUnfavoriteClick={handleUnfavoriteClick} sectionName={sectionId} hasFavorites={!!onBookmarksChange} + useNativeTitle={useNativeTitle} /> ))} diff --git a/src/components/Sidebar/item.tsx b/src/components/Sidebar/item.tsx index ac95d7ae..af38723b 100644 --- a/src/components/Sidebar/item.tsx +++ b/src/components/Sidebar/item.tsx @@ -27,6 +27,7 @@ export interface SidebarItemProps { currentPath: string; sectionName: string; hasFavorites: boolean; + useNativeTitle?: boolean; } export interface ISidebarTooltipProps { @@ -37,6 +38,7 @@ export interface ISidebarTooltipProps { isSubcategory: boolean; isSubitem: boolean; onClick: any; + useNativeTitle?: boolean; } const SidebarItemTooltip: Function = ({ @@ -47,9 +49,28 @@ const SidebarItemTooltip: Function = ({ isSubitem, isSubcategory, onClick, + useNativeTitle, }: ISidebarTooltipProps) => { const Element = itemData.as || 'div'; + if (useNativeTitle) { + return ( + //@ts-ignore + + {children} + + ); + } + return ( //@ts-ignore { const handleFavoriteClick = (event) => { event.persist(); @@ -122,6 +144,7 @@ const SidebarItem: Function = ({ itemData={itemData} isActive={isActive} isSubitem={subItem} + useNativeTitle={useNativeTitle} onClick={ onSectionToggle ? () => { @@ -172,6 +195,7 @@ const SidebarItemWrapper: Function = ({ onUnfavoriteClick, hasFavorites, sectionName, + useNativeTitle, }: SidebarItemProps) => { const theme: IReqoreTheme = useContext(ThemeContext); @@ -222,6 +246,7 @@ const SidebarItemWrapper: Function = ({ onUnfavoriteClick={onUnfavoriteClick} sectionName={sectionName} hasFavorites={hasFavorites} + useNativeTitle={useNativeTitle} /> {expandedSection === itemData.name && map(itemData.submenu, (subItemData: any, key: number) => ( @@ -236,6 +261,7 @@ const SidebarItemWrapper: Function = ({ onUnfavoriteClick={onUnfavoriteClick} sectionName={sectionName} hasFavorites={hasFavorites} + useNativeTitle={useNativeTitle} /> ))} diff --git a/src/stories/Sidebar/Sidebar.stories.tsx b/src/stories/Sidebar/Sidebar.stories.tsx index 8b29ead3..f405f581 100644 --- a/src/stories/Sidebar/Sidebar.stories.tsx +++ b/src/stories/Sidebar/Sidebar.stories.tsx @@ -94,3 +94,9 @@ WithCustomColors.args = { }, path: '/item-3/item-2', } as IReqoreUIProviderProps & IQorusSidebarProps; + +export const WithNativeTitles = Template.bind({}); + +WithNativeTitles.args = { + useNativeTitle: true, +} as IReqoreUIProviderProps & IQorusSidebarProps;