From c09145da0f138d398e079ed09c9fb75287941cc9 Mon Sep 17 00:00:00 2001 From: Marcus Eide Date: Fri, 25 Sep 2020 10:23:17 +0200 Subject: [PATCH] Refactor tooltip placements --- .../src/components/FeatureFlagsItem.tsx | 18 +++--- .../src/components/OAuthProviderSettings.tsx | 1 + .../src/components/OIDCProviderSettings.tsx | 1 + .../src/components/PinButton.tsx | 35 ++++++----- .../src/components/ProviderSettingsItem.tsx | 60 +++++++++---------- .../src/components/ThemeToggle.tsx | 34 ++++++++--- 6 files changed, 81 insertions(+), 68 deletions(-) diff --git a/plugins/user-settings/src/components/FeatureFlagsItem.tsx b/plugins/user-settings/src/components/FeatureFlagsItem.tsx index 7f7f990e48..92065f2ed6 100644 --- a/plugins/user-settings/src/components/FeatureFlagsItem.tsx +++ b/plugins/user-settings/src/components/FeatureFlagsItem.tsx @@ -38,16 +38,16 @@ export const FlagItem = ({ flag, enabled, toggleHandler }: Props) => ( secondary={`Registered in ${flag.pluginId} plugin`} /> - toggleHandler(flag.name)} - > - + + toggleHandler(flag.name)} + > - - + + ); diff --git a/plugins/user-settings/src/components/OAuthProviderSettings.tsx b/plugins/user-settings/src/components/OAuthProviderSettings.tsx index 2ecc5536ea..669dd89822 100644 --- a/plugins/user-settings/src/components/OAuthProviderSettings.tsx +++ b/plugins/user-settings/src/components/OAuthProviderSettings.tsx @@ -71,6 +71,7 @@ export const OAuthProviderSettings: FC = ({ return ( = ({ return ( { SidebarPinStateContext, ); - const PinIcon = () => ( - - {isPinned ? : } - - ); + const PinIcon = () => + isPinned ? : ; return ( @@ -48,16 +41,22 @@ export const SidebarPinButton = () => { secondary="Prevent the sidebar from collapsing" /> - { - toggleSidebarPinState(); - }} + - - + { + toggleSidebarPinState(); + }} + > + + + ); diff --git a/plugins/user-settings/src/components/ProviderSettingsItem.tsx b/plugins/user-settings/src/components/ProviderSettingsItem.tsx index 018e6a1326..0fb3d3e97d 100644 --- a/plugins/user-settings/src/components/ProviderSettingsItem.tsx +++ b/plugins/user-settings/src/components/ProviderSettingsItem.tsx @@ -35,51 +35,47 @@ import { type OAuthProviderSidebarProps = { title: string; + description: string; icon: IconComponent; apiRef: ApiRef; }; export const ProviderSettingsItem: FC = ({ title, + description, icon: Icon, - apiRef, -}) => { - const api = useApi(apiRef); - const [signedIn, setSignedIn] = useState(false); - - useEffect(() => { - let didCancel = false; - - const subscription = api - .sessionState$() - .subscribe((sessionState: SessionState) => { - if (!didCancel) { - setSignedIn(sessionState === SessionState.SignedIn); - } - }); - - return () => { - didCancel = true; - subscription.unsubscribe(); - }; - }, [api]); - - return ( - - - - - - + signedIn, + api, + signInHandler, +}: Props) => ( + + + + + + {description} + + } + secondaryTypographyProps={{ noWrap: true, style: { width: '80%' } }} + /> + + (signedIn ? api.signOut() : api.signIn())} + onChange={() => (signedIn ? api.logout() : signInHandler())} > - - + + ); diff --git a/plugins/user-settings/src/components/ThemeToggle.tsx b/plugins/user-settings/src/components/ThemeToggle.tsx index 9acfc3407f..166d0454c5 100644 --- a/plugins/user-settings/src/components/ThemeToggle.tsx +++ b/plugins/user-settings/src/components/ThemeToggle.tsx @@ -47,21 +47,34 @@ export const SidebarThemeToggle = () => { } }; + // ToggleButtonGroup uses React.children.map instead of context + // so wrapping with Tooltip breaks ToggleButton functionality. + const TooltipToggleButton = ({ + children, + title, + value, + ...props + }: { + children: JSX.Element; + title: string; + value: string; + }) => ( + + + {children} + + + ); + const ThemeIcon = ({ theme }: { theme: AppTheme }) => { const themeIcon = themeIds.find(t => t.id === theme.id)?.icon; - const icon = themeIcon ? ( + return themeIcon ? ( cloneElement(themeIcon, { color: themeId === theme.id ? 'primary' : undefined, }) ) : ( ); - - return ( - - {icon} - - ); }; return ( @@ -75,9 +88,12 @@ export const SidebarThemeToggle = () => { onChange={handleSetTheme} > {themeIds.map(theme => ( - + - + ))}