Skip to content

Commit

Permalink
Merge pull request #46 from VKCOM/o.shcherbakov/modal/QA-15689
Browse files Browse the repository at this point in the history
feat(ui): add modal component & upgrade vkui to v7
  • Loading branch information
DaniilSmirnov authored Dec 12, 2024
2 parents 2c91f88 + cd5b315 commit 24c4564
Show file tree
Hide file tree
Showing 19 changed files with 107 additions and 49 deletions.
2 changes: 1 addition & 1 deletion ui/.stylelintrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"overrides": [
{
"files": [
"src/components/views/settings-page/settings-page.module.css",
"src/components/lib/tabs-panel/tabs-panel.module.css",
"src/components/views/control-page/control-page.module.css",
"src/components/lib/marked-slider-range/marked-slider-range.module.css"
],
Expand Down
2 changes: 1 addition & 1 deletion ui/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ export default tseslint.config(
'no-await-in-loop': 'error',
'no-shadow': 'off',
'no-continue': 'off',
'i18next/no-literal-string': ['error', { words: { exclude: ['%', 'Stub'] } }],
'i18next/no-literal-string': ['error', { words: { exclude: ['%', 'Stub', 'OK'] } }],
},
},
{
Expand Down
33 changes: 13 additions & 20 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@tanstack/react-table": "^8.20.5",
"@tanstack/react-virtual": "^3.10.8",
"@vkontakte/icons": "^2.148.0",
"@vkontakte/vkui": "^6.7.2",
"@vkontakte/vkui": "^7.0.0",
"axios": "^1.7.7",
"classnames": "^2.5.1",
"date-fns": "^4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const App = () => {
const { theme } = useTheme()

return (
<ConfigProvider appearance={theme === 'system' ? undefined : theme} platform='vkcom'>
<ConfigProvider colorScheme={theme === 'system' ? undefined : theme} platform='vkcom'>
<AdaptivityProvider>
<AppRoot>
<RouterProvider router={appRouter} />
Expand Down
4 changes: 2 additions & 2 deletions ui/src/components/app/providers/theme-provider/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import type { AppearanceType } from '@vkontakte/vkui'
import type { ColorSchemeType } from '@vkontakte/vkui'

export type Theme = AppearanceType | 'system'
export type Theme = ColorSchemeType | 'system'
2 changes: 1 addition & 1 deletion ui/src/components/lib/error-fallback/error-fallback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export const ErrorFallback = ({ error, resetErrorBoundary }: FallbackProps) => {
return (
<Gradient className={styles.gradient} mode='tint'>
<Placeholder
header={t('Something went wrong')}
icon={<Icon24ErrorCircleFillRed height={56} width={56} />}
title={t('Something went wrong')}
action={
<Button appearance='accent-invariable' mode='outline' size='m' onClick={resetErrorBoundary}>
{t('Retry')}
Expand Down
1 change: 1 addition & 0 deletions ui/src/components/lib/modal/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Modal } from './modal'
7 changes: 7 additions & 0 deletions ui/src/components/lib/modal/modal.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.modal {
width: fit-content;
}

.modalActions {
width: 100%;
}
53 changes: 53 additions & 0 deletions ui/src/components/lib/modal/modal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { useTranslation } from 'react-i18next'
import { Icon20ErrorCircleFillYellow } from '@vkontakte/icons'
import { Button, ButtonGroup, ModalCard, ModalRoot } from '@vkontakte/vkui'

import { ConditionalRender } from '@/components/lib/conditional-render'

import styles from './modal.module.css'

type ModalProps = {
isOpen: boolean
title: string
description?: string
isCancelShown?: boolean
onOk?: () => void
onClose: () => void
}

export const Modal = ({ isOpen, title, description, onOk, onClose, isCancelShown = true }: ModalProps) => {
const { t } = useTranslation()

const onOkClick = () => {
onOk?.()
onClose()
}

return (
<ModalRoot activeModal={isOpen ? 'modal-card' : null} usePortal onClose={onClose}>
<ModalCard
className={styles.modal}
description={description}
dismissButtonMode='inside'
icon={<Icon20ErrorCircleFillYellow height={56} width={56} />}
id='modal-card'
open={isOpen}
size={900}
title={title}
actions={
<ButtonGroup align='right' className={styles.modalActions}>
<Button mode={isCancelShown ? 'secondary' : 'primary'} size='l' onClick={onOkClick}>
OK
</Button>
<ConditionalRender conditions={[isCancelShown]}>
<Button mode='primary' size='l' onClick={onClose}>
{t('Cancel')}
</Button>
</ConditionalRender>
</ButtonGroup>
}
onClose={onClose}
/>
</ModalRoot>
)
}
2 changes: 1 addition & 1 deletion ui/src/components/lib/statistic-card/statistic-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const StatisticCard = ({
</ConditionalRender>
<Spacing />
<ConditionalRender conditions={[value !== undefined]}>
<Counter mode='secondary' size='s'>
<Counter appearance='neutral' mode='primary' size='s'>
{value}
</Counter>
</ConditionalRender>
Expand Down
10 changes: 10 additions & 0 deletions ui/src/components/lib/tabs-panel/tabs-panel.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.tabsPanel {
:global(._in_sa4kt_20) {
justify-content: flex-start;
}

:global(.vkuiInternalPanelHeader__before) {
flex-grow: 0;
padding: 5px;
}
}
5 changes: 4 additions & 1 deletion ui/src/components/lib/tabs-panel/tabs-panel.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { useLocation, useNavigate } from 'react-router'
import cn from 'classnames'
import { useTranslation } from 'react-i18next'
import { Group, PanelHeader, Tabs, TabsItem } from '@vkontakte/vkui'

import { ConditionalRender } from '@/components/lib/conditional-render'

import styles from './tabs-panel.module.css'

import type { TabsContent } from './types'

type CommonTabsPanelProps<T> = {
Expand Down Expand Up @@ -39,7 +42,7 @@ export const TabsPanel = <T extends boolean = false>({

return (
<>
<PanelHeader className={className}>
<PanelHeader className={cn(styles.tabsPanel, className)}>
<Tabs>
{content.map((tab) => (
<TabsItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ export const DeviceControlCard = ({
</Flex>
<Flex align='center'>
<ConditionalRender conditions={[!!helpTooltipText]}>
<Tooltip appearance='accent' placement='left' text={helpTooltipText}>
<Tooltip appearance='accent' description={helpTooltipText} placement='left'>
<Button appearance='neutral' before={<Icon20HelpOutline />} mode='tertiary' />
</Tooltip>
</ConditionalRender>
<Tooltip
appearance='accent'
description={afterTooltipText}
shown={!!afterTooltipText && isAfterButtonTooltipShown}
text={afterTooltipText}
onShownChange={setIsAfterButtonTooltipShown}
>
{after}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export const DeviceScreen = observer(() => {
/>
))}
<ConditionalRender conditions={[!!deviceScreenStore?.isScreenLoading]}>
<Spinner className={styles.spinner} size='large' />
<Spinner className={styles.spinner} size='xl' />
</ConditionalRender>
</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions ui/src/components/ui/header/header.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button, Tappable, useAppearance } from '@vkontakte/vkui'
import { Button, Tappable, useColorScheme } from '@vkontakte/vkui'
import { useTranslation } from 'react-i18next'
import { Link } from 'react-router'
import cn from 'classnames'
Expand All @@ -21,7 +21,7 @@ import styles from './header.module.css'

export const Header = () => {
const { t } = useTranslation()
const appearance = useAppearance()
const colorScheme = useColorScheme()
const { data: authDocs } = useGetAuthDocs()
const { data: authContact } = useGetAuthContact()

Expand All @@ -30,7 +30,7 @@ export const Header = () => {
<div className={styles.leftSide}>
<Link className={styles.logoLink} to={getMainRoute()}>
<Tappable activeMode='opacity' focusVisibleMode='outside' hoverMode='opacity' onClick={() => {}}>
<DeviceHubIcon className={cn({ [styles.logo]: appearance === 'dark' })} />
<DeviceHubIcon className={cn({ [styles.logo]: colorScheme === 'dark' })} />
</Tappable>
</Link>
<Link className={styles.navLink} to={getDevicesRoute()}>
Expand Down
8 changes: 4 additions & 4 deletions ui/src/components/views/devices-page/devices-page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { View, Panel, Group, CustomScrollView, Header, Flex } from '@vkontakte/vkui'
import { useTranslation } from 'react-i18next'
import { useMemo } from 'react'
import { observer } from 'mobx-react-lite'
import { useTranslation } from 'react-i18next'
import { View, Panel, Group, CustomScrollView, Header, Flex } from '@vkontakte/vkui'

import { DeviceTable } from '@/components/ui/device-table'
import { SearchDevice } from '@/components/ui/search-device'
Expand All @@ -27,12 +27,12 @@ export const DevicesPage = observer(() => {
<View activePanel='main'>
<Panel className={styles.devicesPage} id='main'>
<DeviceStatistics />
<Group header={<Header mode='secondary'>{t('Devices')}</Header>}>
<Group header={<Header size='s'>{t('Devices')}</Header>}>
<Flex align='center'>
<SearchDevice />
<TableColumnVisibility />
</Flex>
<CustomScrollView enableHorizontalScroll={true} windowResize={true}>
<CustomScrollView enableHorizontalScroll={true}>
<DeviceTable
data={displayData}
isError={devicesQueryResult.isError}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,3 @@
margin-top: 25px;
padding: 0 10px;
}

:global(._PanelHeader__in_1h7ym_20) {
justify-content: flex-start;
}

:global(._PanelHeader--vkcom_1h7ym_193 ._PanelHeader__before_1h7ym_43) {
flex-grow: 0;
padding: 5px;
}
2 changes: 1 addition & 1 deletion ui/src/styles/variables/global.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
:root {
/* z-index */
--header-z-index: 150;
--header-z-index: 99;
--screen-input-z-index: 10;

/* Colors */
Expand Down

0 comments on commit 24c4564

Please sign in to comment.