-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #174 from sima-land/170-modifier-media-modal
Шаг 4 #170 Внести доработки в компоненты на основе изменений в гайдах
- Loading branch information
Showing
11 changed files
with
212 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
src/common/components/media-modal/__stories__/test-images-broken.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
import React, { Fragment, useState } from 'react'; | ||
import { Modal } from '@sima-land/ui-nucleons/modal'; | ||
import { | ||
MediaLayout, | ||
MediaHeader, | ||
MediaMain, | ||
MediaAside, | ||
MediaFooter, | ||
HeaderLayout, | ||
Preset, | ||
MediaContent, | ||
MediaView, | ||
Thumbnails, | ||
Thumbnail, | ||
ProductBrief, | ||
} from '..'; | ||
import { Tabs } from '@sima-land/ui-nucleons/tabs'; | ||
import { mixed } from '../__mocks__'; | ||
import { Layout } from '@sima-land/ui-nucleons/layout'; | ||
import { Button } from '@sima-land/ui-nucleons/button'; | ||
import { Stepper } from '@sima-land/ui-nucleons/stepper'; | ||
import { MediaData } from '../types'; | ||
|
||
export default { | ||
title: 'common/MediaLayout', | ||
parameters: { | ||
layout: 'fullscreen', | ||
}, | ||
}; | ||
|
||
export function TestImagesBroken() { | ||
const [targetIndex, setTargetIndex] = useState(0); | ||
const [broken, setBroken] = useState(false); | ||
|
||
const processSrc = (src: string | undefined) => (broken ? 'http://non-existed-site.com/' : src); | ||
|
||
const processMedia = (media: MediaData): MediaData => ({ | ||
...media, | ||
data: { | ||
...media.data, | ||
...(media.type === '360' && { photos: media.data.photos.map(processSrc) }), | ||
...(media.type === 'image' && { src: processSrc(media.data.src) }), | ||
...(media.type === 'video' && { thumbnail: processSrc(media.data.thumbnail) }), | ||
} as any, | ||
}); | ||
|
||
return ( | ||
<Modal size='fullscreen' footerStub={false} withScrollDisable> | ||
<Modal.Header | ||
onClose={() => void 0} | ||
buttons={{ | ||
endSecondary: { | ||
text: broken ? 'Починить' : 'Сломать', | ||
onClick: () => setBroken(a => !a), | ||
}, | ||
}} | ||
/> | ||
<Modal.Body> | ||
<MediaLayout> | ||
<MediaHeader> | ||
<HeaderLayout> | ||
<HeaderLayout.Tabs> | ||
<Tabs {...Preset.headerTabs()}> | ||
<Tabs.Item name='Фото' /> | ||
<Tabs.Item name='Видео' selected /> | ||
<Tabs.Item name='360' /> | ||
<Tabs.Item name='Фото покупателей' /> | ||
</Tabs> | ||
</HeaderLayout.Tabs> | ||
</HeaderLayout> | ||
</MediaHeader> | ||
|
||
<MediaMain> | ||
<MediaContent targetIndex={targetIndex} onChangeTargetIndex={setTargetIndex}> | ||
{mixed.map(processMedia).map((item, index) => ( | ||
<MediaView key={index} media={item} /> | ||
))} | ||
</MediaContent> | ||
</MediaMain> | ||
|
||
<MediaAside> | ||
<Thumbnails targetIndex={targetIndex}> | ||
{mixed.map(processMedia).map((item, index) => ( | ||
<Fragment key={index}> | ||
{item.type === '360' && ( | ||
<Thumbnail | ||
type='icon-360' | ||
checked={targetIndex === index} | ||
onClick={() => setTargetIndex(index)} | ||
/> | ||
)} | ||
{item.type === 'video' && ( | ||
<Thumbnail | ||
type='preview-video' | ||
src={item.data.thumbnail} | ||
checked={targetIndex === index} | ||
onClick={() => setTargetIndex(index)} | ||
/> | ||
)} | ||
{item.type === 'image' && ( | ||
<Thumbnail | ||
type='preview-image' | ||
src={item.data.src} | ||
checked={targetIndex === index} | ||
onClick={() => setTargetIndex(index)} | ||
/> | ||
)} | ||
</Fragment> | ||
))} | ||
</Thumbnails> | ||
</MediaAside> | ||
|
||
<MediaFooter> | ||
<Layout disabledOn={['xs', 's', 'm', 'l', 'xl']}> | ||
<ProductBrief | ||
href='https://sima-land.ru' | ||
imageSrc={processSrc('https://loremflickr.com/240/320')} | ||
title='Игровая приставка Sony PlayStation 5 Digital 3,5 ГГц модифицированная' | ||
price={60235} | ||
currency='₽' | ||
footer={ | ||
<> | ||
<Button size='s'>В корзину</Button> | ||
<Stepper size='s' defaultValue={1} /> | ||
</> | ||
} | ||
/> | ||
</Layout> | ||
</MediaFooter> | ||
</MediaLayout> | ||
</Modal.Body> | ||
</Modal> | ||
); | ||
} | ||
|
||
TestImagesBroken.storyName = 'Тест: ошибка загрузки картинок'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,4 +27,9 @@ | |
height: 100%; | ||
object-fit: contain; | ||
} | ||
.image svg { | ||
display: block; | ||
width: 100%; | ||
height: 100%; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,11 @@ | |
height: 100%; | ||
object-fit: contain; | ||
} | ||
> svg { | ||
display: block; | ||
width: 100%; | ||
height: 100%; | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useIsomorphicLayoutEffect } from '@sima-land/ui-nucleons/hooks'; | ||
import { ReactEventHandler, useCallback, useState } from 'react'; | ||
|
||
/** | ||
* Хук состояния ошибки загрузки изображения. | ||
* @param src Ссылка на картинку. | ||
* @param onError Обработчик ошибки. | ||
* @return Управление состоянием. | ||
*/ | ||
export function useImageStub(src?: string, onError?: ReactEventHandler<HTMLImageElement>) { | ||
const [failed, setFailed] = useState(false); | ||
|
||
useIsomorphicLayoutEffect(() => { | ||
setFailed(false); | ||
}, [src]); | ||
|
||
const handleError = useCallback<ReactEventHandler<HTMLImageElement>>( | ||
event => { | ||
setFailed(true); | ||
onError?.(event); | ||
}, | ||
[onError], | ||
); | ||
|
||
return { failed, setFailed, handleError }; | ||
} |