Skip to content

Commit 9f54cc6

Browse files
authored
feat(Stories): add props to reset story index on close (#333)
1 parent 5ca714a commit 9f54cc6

2 files changed

Lines changed: 17 additions & 11 deletions

File tree

src/components/Stories/README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ Component for displaying stories. It looks like a carousel in a modal with given
44

55
### PropTypes
66

7-
| Property | Type | Required | Default | Description |
8-
| :------------------ | :-------------- | :------- | :------ | :----------------------------------------------- |
9-
| open | `Boolean` || | Visibility flag |
10-
| items | `StoriesItem[]` || | List of stories to display |
11-
| initialStoryIndex | `Number` | | 0 | Index of the first story to be displayed |
12-
| onClose | `Function` | | | Action on close |
13-
| onPreviousClick | `Function` | | | Action when switching to previous story |
14-
| onNextClick | `Function` | | | Action when switching to next story |
15-
| disableOutsideClick | `Boolean` | | true | If `true`, do not close stories on click outside |
16-
| className | `string` | | | Stories modal class |
7+
| Property | Type | Required | Default | Description |
8+
| :--------------------- | :-------------- | :------- | :------ | :------------------------------------------------ |
9+
| open | `Boolean` || | Visibility flag |
10+
| items | `StoriesItem[]` || | List of stories to display |
11+
| initialStoryIndex | `Number` | | 0 | Index of the first story to be displayed |
12+
| resetStoryIndexOnClose | `Boolean` | | false | If `true`, reset story index to initialStoryIndex |
13+
| onClose | `Function` | | | Action on close |
14+
| onPreviousClick | `Function` | | | Action when switching to previous story |
15+
| onNextClick | `Function` | | | Action when switching to next story |
16+
| disableOutsideClick | `Boolean` | | true | If `true`, do not close stories on click outside |
17+
| className | `string` | | | Stories modal class |
1718

1819
### StoriesItem object
1920

src/components/Stories/Stories.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface StoriesProps {
2626
disableOutsideClick?: boolean;
2727
className?: string;
2828
syncInTabsKey?: string;
29+
resetStoryIndexOnClose?: boolean;
2930
}
3031

3132
export function Stories({
@@ -38,14 +39,18 @@ export function Stories({
3839
disableOutsideClick = true,
3940
className,
4041
syncInTabsKey,
42+
resetStoryIndexOnClose,
4143
}: StoriesProps) {
4244
const [storyIndex, setStoryIndex] = React.useState(initialStoryIndex);
4345

4446
const handleClose = React.useCallback<NonNullable<StoriesProps['onClose']>>(
4547
(event, reason) => {
48+
if (resetStoryIndexOnClose) {
49+
setStoryIndex(initialStoryIndex);
50+
}
4651
onClose?.(event, reason);
4752
},
48-
[onClose],
53+
[onClose, setStoryIndex, initialStoryIndex, resetStoryIndexOnClose],
4954
);
5055

5156
const {callback: closeWithLS} = useSyncWithLS<NonNullable<StoriesProps['onClose']>>({

0 commit comments

Comments
 (0)