diff --git a/packages/vkui/src/components/AppRoot/AppRoot.tsx b/packages/vkui/src/components/AppRoot/AppRoot.tsx index 7ba821f43ae..807f0525a32 100644 --- a/packages/vkui/src/components/AppRoot/AppRoot.tsx +++ b/packages/vkui/src/components/AppRoot/AppRoot.tsx @@ -28,6 +28,25 @@ const vkuiSizeXClassNames = { [SizeType.REGULAR]: 'vkui--sizeX-regular', }; +const vkuiLayoutClassNames = { + card: 'vkui--layout-card', + plain: 'vkui--layout-plain', +}; + +function containerClassNames(layout: AppRootProps['layout'], sizeX: SizeType | 'none'): string[] { + const classNames: string[] = []; + + if (layout) { + classNames.push(vkuiLayoutClassNames[layout]); + } + + if (sizeX !== SizeType.COMPACT) { + classNames.push(vkuiSizeXClassNames[sizeX]); + } + + return classNames; +} + const INSET_CUSTOM_PROPERTY_PREFIX = `--vkui_internal--safe_area_inset_`; // Используйте classList, но будьте осторожны @@ -45,6 +64,7 @@ export interface AppRootProps extends React.HTMLAttributes { portalRoot?: HTMLElement | React.RefObject | null; /** Disable portal for components */ disablePortal?: boolean; + layout?: 'card' | 'plain'; } /** @@ -58,6 +78,7 @@ export const AppRoot = ({ disablePortal, className, safeAreaInsets, + layout, ...props }: AppRootProps) => { const isKeyboardInputActive = useKeyboardInputTracker(); @@ -160,18 +181,20 @@ export const AppRoot = ({ if (mode === 'partial') { return noop; } - const className = sizeX !== SizeType.COMPACT ? vkuiSizeXClassNames[sizeX] : null; + + const classNames = containerClassNames(layout, sizeX); + const container = mode === 'embedded' ? rootRef.current?.parentElement : document!.body; - if (className === null || !container) { + if (!classNames.length || !container) { return noop; } - container.classList.add(className); + container.classList.add(...classNames); return () => { - container.classList.remove(className); + container.classList.remove(...classNames); }; - }, [sizeX]); + }, [sizeX, layout]); useIsomorphicLayoutEffect(() => { if (mode !== 'full' || appearance === undefined) { @@ -196,6 +219,7 @@ export const AppRoot = ({ keyboardInput: isKeyboardInputActive, mode, disablePortal, + layout, }} > diff --git a/packages/vkui/src/components/AppRoot/AppRootContext.ts b/packages/vkui/src/components/AppRoot/AppRootContext.ts index 5ff48a36f72..32d4d9ecf38 100644 --- a/packages/vkui/src/components/AppRoot/AppRootContext.ts +++ b/packages/vkui/src/components/AppRoot/AppRootContext.ts @@ -7,6 +7,7 @@ export interface AppRootContextInterface { mode?: 'partial' | 'embedded' | 'full'; keyboardInput?: boolean; disablePortal?: boolean; + layout?: 'card' | 'plain'; } export const AppRootContext = React.createContext({ diff --git a/packages/vkui/src/styles/common.css b/packages/vkui/src/styles/common.css index e1bc81513b5..5f726a9d3ab 100644 --- a/packages/vkui/src/styles/common.css +++ b/packages/vkui/src/styles/common.css @@ -34,3 +34,11 @@ background: var(--vkui--color_background); } } + +.vkui--layout-card { + background: var(--vkui--color_background); +} + +.vkui--layout-plain { + background: var(--vkui--color_background_content); +}