|
1 | 1 | import * as React from 'react'; |
2 | 2 |
|
3 | 3 | import {Archive, ArrowRotateLeft, CircleCheck, Funnel, TrashBin} from '@gravity-ui/icons'; |
4 | | -import {Button, DropdownMenu, Flex, Icon, Link} from '@gravity-ui/uikit'; |
| 4 | +import {Disclosure, DropdownMenu, Flex, Icon, Link} from '@gravity-ui/uikit'; |
5 | 5 |
|
6 | 6 | import {NotificationAction} from '../../Notification/NotificationAction'; |
7 | 7 | import {NotificationSwipeAction} from '../../Notification/NotificationSwipeAction'; |
@@ -89,54 +89,25 @@ export const notificationBottomActions: JSX.Element = ( |
89 | 89 | </React.Fragment> |
90 | 90 | ); |
91 | 91 |
|
92 | | -export const LongNotificationContent = (props: { |
93 | | - rootRef?: React.RefObject<HTMLDivElement>; |
94 | | - wrapperRef?: React.RefObject<HTMLDivElement>; |
95 | | -}) => { |
96 | | - const {rootRef} = props; |
97 | | - const [expanded, setExpanded] = React.useState(false); |
98 | | - const prevExpandedRef = React.useRef(false); |
| 92 | +export const LongNotificationContent = (props: {wrapperRef?: React.RefObject<HTMLDivElement>}) => { |
| 93 | + const {wrapperRef} = props; |
99 | 94 |
|
100 | | - React.useLayoutEffect(() => { |
101 | | - if (prevExpandedRef.current && !expanded) { |
| 95 | + const handleUpdate = (expanded: boolean) => { |
| 96 | + if (!expanded) { |
102 | 97 | requestAnimationFrame(() => { |
103 | | - rootRef?.current?.scrollIntoView({block: 'nearest', behavior: 'smooth'}); |
| 98 | + wrapperRef?.current?.scrollIntoView({block: 'nearest', behavior: 'smooth'}); |
104 | 99 | }); |
105 | 100 | } |
106 | | - |
107 | | - prevExpandedRef.current = expanded; |
108 | | - }, [expanded, rootRef]); |
109 | | - |
110 | | - const handleExpand = (event: React.MouseEvent<HTMLButtonElement>) => { |
111 | | - event.preventDefault(); |
112 | | - setExpanded(true); |
113 | | - }; |
114 | | - |
115 | | - const handleCollapse = (event: React.MouseEvent<HTMLButtonElement>) => { |
116 | | - event.preventDefault(); |
117 | | - setExpanded(false); |
118 | 101 | }; |
119 | 102 |
|
120 | | - if (expanded) { |
121 | | - return ( |
| 103 | + return ( |
| 104 | + <Disclosure summary="Collapsed content" onUpdate={handleUpdate}> |
122 | 105 | <Flex direction="column" gap={1}> |
123 | 106 | {Array.from({length: 20}, (_, index) => ( |
124 | 107 | <i key={index}>{'Long expanded content. '}</i> |
125 | 108 | ))} |
126 | | - <Button view="flat-secondary" onClick={handleCollapse}> |
127 | | - Collapse |
128 | | - </Button> |
129 | 109 | </Flex> |
130 | | - ); |
131 | | - } |
132 | | - |
133 | | - return ( |
134 | | - <Flex direction="column" gap={1}> |
135 | | - <span>Collapsed content</span> |
136 | | - <Button view="flat-secondary" onClick={handleExpand}> |
137 | | - Expand |
138 | | - </Button> |
139 | | - </Flex> |
| 110 | + </Disclosure> |
140 | 111 | ); |
141 | 112 | }; |
142 | 113 |
|
@@ -209,7 +180,6 @@ export const mockNotifications: NotificationProps[] = [ |
209 | 180 | content: (contentProps) => <LongNotificationContent {...contentProps} />, |
210 | 181 | formattedDate: '29 seconds ago', |
211 | 182 | swipeActions: notificationsMockSwipeActions, |
212 | | - href: 'https://ya.ru', |
213 | 183 | }, |
214 | 184 | { |
215 | 185 | id: 'yandex', |
|
0 commit comments