From fe14e64f7423df8f12d881c7347d51c5d0469aff Mon Sep 17 00:00:00 2001 From: sunduckcow <83990793+sunduckcow@users.noreply.github.com> Date: Wed, 27 Sep 2023 14:01:24 +0300 Subject: [PATCH] feat: added right adornments for settings items (#110) * feat: added right adornments for settings items * fix: fixed tags styles in AsideHeader stories --------- Co-authored-by: sunduckcow --- .../__stories__/AsideHeaderShowcase.scss | 7 ++++ src/components/Settings/Settings.scss | 8 ++++ src/components/Settings/Settings.tsx | 42 +++++++++++++++---- .../Settings/__stories__/SettingsDemo.tsx | 4 ++ 4 files changed, 54 insertions(+), 7 deletions(-) diff --git a/src/components/AsideHeader/__stories__/AsideHeaderShowcase.scss b/src/components/AsideHeader/__stories__/AsideHeaderShowcase.scss index e06cbb6..0b470cd 100644 --- a/src/components/AsideHeader/__stories__/AsideHeaderShowcase.scss +++ b/src/components/AsideHeader/__stories__/AsideHeaderShowcase.scss @@ -78,3 +78,10 @@ body { padding: 20px; } } + +.composite-bar-showcase__tag { + color: var(--g-color-text-positive); + font-size: 12px; + font-weight: 500; + letter-spacing: 0.3px; +} diff --git a/src/components/Settings/Settings.scss b/src/components/Settings/Settings.scss index c01879c..ed830a3 100644 --- a/src/components/Settings/Settings.scss +++ b/src/components/Settings/Settings.scss @@ -195,6 +195,14 @@ $block: '.#{variables.$ns}settings'; padding-right: 20px; color: var(--g-color-text-secondary); } + + &-right-adornment_hidden { + opacity: 0; + transition: opacity 0.2s; + } + &:hover &-right-adornment_hidden { + opacity: 1; + } } &__found { diff --git a/src/components/Settings/Settings.tsx b/src/components/Settings/Settings.tsx index 15ee759..dc9c25a 100644 --- a/src/components/Settings/Settings.tsx +++ b/src/components/Settings/Settings.tsx @@ -2,7 +2,7 @@ import React from 'react'; import {block} from '../utils/cn'; import identity from 'lodash/identity'; -import {IconProps, Loader} from '@gravity-ui/uikit'; +import {Flex, IconProps, Loader} from '@gravity-ui/uikit'; import {SettingsSearch} from './SettingsSearch/SettingsSearch'; import {SettingsMenu, SettingsMenuInstance} from './SettingsMenu/SettingsMenu'; import {SettingsMenuMobile} from './SettingsMenuMobile/SettingsMenuMobile'; @@ -29,6 +29,8 @@ export interface SettingsProps { loading?: boolean; view?: 'normal' | 'mobile'; onClose?: () => void; + renderRightAdornment?: (item: Pick) => React.ReactNode; + showRightAdornmentOnHover?: boolean; } export interface SettingsGroupProps { @@ -62,11 +64,20 @@ export interface SettingsItemProps { description?: string; } +export interface SettingsContextType + extends Pick {} + +const SettingsContext = React.createContext({}); + +export const useSettingsContext = () => React.useContext(SettingsContext); + export function Settings({ loading, renderLoading, children, view = 'normal', + renderRightAdornment, + showRightAdornmentOnHover = true, ...props }: SettingsProps) { if (loading) { @@ -82,9 +93,11 @@ export function Settings({ } return ( - - {children} - + + + {children} + + ); } @@ -284,12 +297,27 @@ Settings.Item = function SettingsItem({ mode, description, }: SettingsItemProps) { + const {renderRightAdornment, showRightAdornmentOnHover} = useSettingsContext(); + const titleNode = ( + {renderTitleComponent(title)} + ); return (
{children}
diff --git a/src/components/Settings/__stories__/SettingsDemo.tsx b/src/components/Settings/__stories__/SettingsDemo.tsx index a4ee972..b245e50 100644 --- a/src/components/Settings/__stories__/SettingsDemo.tsx +++ b/src/components/Settings/__stories__/SettingsDemo.tsx @@ -67,6 +67,10 @@ export const SettingsComponent = React.memo( console.log({page}); }} onClose={onClose} + renderRightAdornment={({title}) => ( + + )} + showRightAdornmentOnHover={true} // true by default >