Skip to content

Commit 622fdaa

Browse files
authored
feat(view): added hook for opening files gallery (#742)
`useFilesGallery` hook expects `@gravity-ui/uikit` version 7.10.0 or higher to be installed in the project
1 parent 1ba2b41 commit 622fdaa

21 files changed

+337
-36
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import transform from '@diplodoc/transform';
2+
import type {StoryObj} from '@storybook/react';
3+
4+
import {ViewWithGallery} from './ViewWithGallery';
5+
import {galleryMarkup} from './markup';
6+
7+
export const Story: StoryObj<typeof ViewWithGallery> = {
8+
args: {
9+
html: transform(galleryMarkup).result.html,
10+
},
11+
};
12+
Story.storyName = 'View gallery';
13+
14+
export default {
15+
title: 'View / Gallery',
16+
component: ViewWithGallery,
17+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.view-with-gallery {
2+
img {
3+
cursor: pointer;
4+
}
5+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import type {FC} from 'react';
2+
3+
import {GalleryProvider} from '@gravity-ui/components';
4+
5+
import {YfmStaticView, type YfmStaticViewProps, useFilesGallery} from 'src/view';
6+
7+
import './ViewWithGallery.scss';
8+
9+
export type ViewWithGalleryProps = YfmStaticViewProps;
10+
11+
const ViewWithGalleryContent: FC<ViewWithGalleryProps> = (props) => {
12+
const {openFilesGallery} = useFilesGallery();
13+
14+
return (
15+
// eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions
16+
<div className="view-with-gallery" onClick={openFilesGallery}>
17+
<YfmStaticView {...props} />
18+
</div>
19+
);
20+
};
21+
22+
export const ViewWithGallery: FC<ViewWithGalleryProps> = (props) => {
23+
return (
24+
<GalleryProvider>
25+
<ViewWithGalleryContent {...props} />
26+
</GalleryProvider>
27+
);
28+
};

demo/stories/view/gallery/markup.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export const galleryMarkup = `
2+
## Images
3+
4+
![Minion](https://octodex.github.com/images/minion.png)
5+
![Stormtroopocat](https://octodex.github.com/images/stormtroopocat.jpg "The Stormtroopocat")
6+
7+
![Dojocat](https://octodex.github.com/images/dojocat.jpg "The Dojocat")
8+
9+
![Video](http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4)
10+
`.trim();
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import transform from '@diplodoc/transform';
2+
import type {StoryObj} from '@storybook/react';
3+
4+
import {YfmStaticView} from 'src/view';
5+
6+
import {markup} from '../../../defaults/content';
7+
8+
export const Story: StoryObj<typeof YfmStaticView> = {
9+
args: {
10+
html: transform(markup).result.html,
11+
},
12+
};
13+
Story.storyName = 'Static view';
14+
15+
export default {
16+
title: 'View / YfmStaticView',
17+
component: YfmStaticView,
18+
};

package-lock.json

Lines changed: 94 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,13 @@
228228
"@diplodoc/quote-link-extension": "0.1.3",
229229
"@diplodoc/tabs-extension": "^3.5.1",
230230
"@diplodoc/transform": "^4.57.2",
231+
"@gravity-ui/components": "4.2.2",
231232
"@gravity-ui/eslint-config": "3.3.0",
232233
"@gravity-ui/gulp-utils": "1.0.3",
233234
"@gravity-ui/prettier-config": "1.1.0",
234235
"@gravity-ui/stylelint-config": "4.0.1",
235236
"@gravity-ui/tsconfig": "1.0.0",
236-
"@gravity-ui/uikit": "7.1.1",
237+
"@gravity-ui/uikit": "7.10.0",
237238
"@playwright/experimental-ct-react": "1.49.0",
238239
"@playwright/test": "1.49.0",
239240
"@storybook/addon-docs": "8.4.1",
@@ -310,6 +311,9 @@
310311
},
311312
"lowlight": {
312313
"optional": true
314+
},
315+
"@gravity-ui/components": {
316+
"optional": true
313317
}
314318
},
315319
"peerDependencies": {
@@ -322,6 +326,7 @@
322326
"@diplodoc/quote-link-extension": "^0.1.3",
323327
"@diplodoc/tabs-extension": "^3.5.1",
324328
"@diplodoc/transform": "^4.43.0",
329+
"@gravity-ui/components": "^4.2.2",
325330
"@gravity-ui/uikit": "^7.1.0",
326331
"highlight.js": "^11.8.0",
327332
"katex": "^0.16.9",

src/view/hooks/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './useYfmShowElemWithId';
2+
export * from './useFilesGallery';

0 commit comments

Comments
 (0)