-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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 #23446 from storybookjs/release/7.2
Features: For 7.2
- Loading branch information
Showing
321 changed files
with
7,547 additions
and
4,564 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
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
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 |
---|---|---|
@@ -1,50 +1,42 @@ | ||
import React, { useState } from 'react'; | ||
import { addons, types, useChannel } from '@storybook/manager-api'; | ||
import React from 'react'; | ||
import { addons, types, useAddonState, useChannel } from '@storybook/manager-api'; | ||
import { STORY_CHANGED } from '@storybook/core-events'; | ||
import { Badge, Spaced } from '@storybook/components'; | ||
import ActionLogger from './containers/ActionLogger'; | ||
import { ADDON_ID, CLEAR_ID, EVENT_ID, PANEL_ID, PARAM_KEY } from './constants'; | ||
|
||
function Title({ count }: { count: { current: number } }) { | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
const [_, setRerender] = useState(false); | ||
function Title() { | ||
const [{ count }, setCount] = useAddonState(ADDON_ID, { count: 0 }); | ||
|
||
// Reactivity hack - force re-render on STORY_CHANGED, EVENT_ID and CLEAR_ID events | ||
useChannel({ | ||
[EVENT_ID]: () => { | ||
setRerender((r) => !r); | ||
setCount((c) => ({ ...c, count: c.count + 1 })); | ||
}, | ||
[STORY_CHANGED]: () => { | ||
setRerender((r) => !r); | ||
setCount((c) => ({ ...c, count: 0 })); | ||
}, | ||
[CLEAR_ID]: () => { | ||
setRerender((r) => !r); | ||
setCount((c) => ({ ...c, count: 0 })); | ||
}, | ||
}); | ||
|
||
const suffix = count.current === 0 ? '' : ` (${count.current})`; | ||
return <>Actions{suffix}</>; | ||
const suffix = count === 0 ? '' : <Badge status="neutral">{count}</Badge>; | ||
|
||
return ( | ||
<div> | ||
<Spaced col={1}> | ||
<span style={{ display: 'inline-block', verticalAlign: 'middle' }}>Actions</span> | ||
{suffix} | ||
</Spaced> | ||
</div> | ||
); | ||
} | ||
|
||
addons.register(ADDON_ID, (api) => { | ||
const countRef = { current: 0 }; | ||
|
||
api.on(STORY_CHANGED, (id) => { | ||
countRef.current = 0; | ||
}); | ||
|
||
api.on(EVENT_ID, () => { | ||
countRef.current += 1; | ||
}); | ||
|
||
api.on(CLEAR_ID, () => { | ||
countRef.current = 0; | ||
}); | ||
|
||
addons.add(PANEL_ID, { | ||
title: <Title count={countRef} />, | ||
id: 'actions', | ||
title: Title, | ||
type: types.PANEL, | ||
render: ({ active, key }) => <ActionLogger key={key} api={api} active={!!active} />, | ||
render: ({ active }) => <ActionLogger api={api} active={!!active} />, | ||
paramKey: PARAM_KEY, | ||
}); | ||
}); |
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
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
Oops, something went wrong.