Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions code/core/src/manager/components/sidebar/FileList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ export const FileListLi = styled('li')(({ theme }) => ({
},
}));

export const FileListItem = styled('div')(({ theme }) => ({
export const FileListItem = styled('div')({
display: 'flex',
flexDirection: 'column',
position: 'relative',
}));
});

export const FileListItemContentWrapper = styled.div<{
selected: boolean;
Expand Down Expand Up @@ -141,8 +141,7 @@ export const FileListExport = styled('ul')(({ theme }) => ({
}));

export const FileListItemExport = styled('li')<{ error: boolean }>(({ theme, error }) => ({
padding: '8px 16px 8px 16px',
marginLeft: '30px',
padding: '8px 16px 8px 58px',
display: 'flex',
gap: '8px',
alignItems: 'center',
Expand Down Expand Up @@ -188,10 +187,14 @@ export const FileListItemExportNameContent = styled('span')(({ theme }) => ({
whiteSpace: 'nowrap',
textOverflow: 'ellipsis',
overflow: 'hidden',
maxWidth: 'calc(100% - 160px)',
display: 'inline-block',
color: theme.base === 'dark' ? theme.color.lightest : theme.color.darkest,
}));

export const FileListItemExportNameContentWithExport = styled(FileListItemExportNameContent)({
maxWidth: 'calc(100% - 120px)',
});

export const DefaultExport = styled('span')(({ theme }) => ({
display: 'inline-block',
padding: `1px ${theme.appBorderRadius}px`,
Expand Down
45 changes: 27 additions & 18 deletions code/core/src/manager/components/sidebar/FileSearchList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import type {
FileComponentSearchResponsePayload,
} from 'storybook/internal/core-events';

import { ChevronDownIcon, ChevronRightIcon, ComponentIcon } from '@storybook/icons';
import {
BookmarkHollowIcon,
ChevronSmallDownIcon,
ChevronSmallRightIcon,
ComponentIcon,
} from '@storybook/icons';

import type { VirtualItem } from '@tanstack/react-virtual';
import { useVirtualizer } from '@tanstack/react-virtual';
Expand All @@ -24,6 +29,7 @@ import {
FileListItemExport,
FileListItemExportName,
FileListItemExportNameContent,
FileListItemExportNameContentWithExport,
FileListItemLabel,
FileListItemPath,
FileListLi,
Expand All @@ -40,16 +46,14 @@ export interface NewStoryPayload extends CreateNewStoryRequestPayload {
selectedItemId: string | number;
}

const ChevronRightIconStyled = styled(ChevronRightIcon)(({ theme }) => ({
display: 'none',
alignSelf: 'center',
const TreeExpandIconStyled = styled(ChevronSmallRightIcon)(({ theme }) => ({
color: theme.color.mediumdark,
marginTop: 2,
}));

const ChevronDownIconStyled = styled(ChevronDownIcon)(({ theme }) => ({
display: 'none',
alignSelf: 'center',
const TreeCollapseIconStyled = styled(ChevronSmallDownIcon)(({ theme }) => ({
color: theme.color.mediumdark,
marginTop: 2,
}));

interface FileSearchListProps {
Expand Down Expand Up @@ -189,6 +193,11 @@ export const FileSearchList = memo(function FileSearchList({
searchResult.exportedComponents?.length === 0
}
>
{itemSelected ? (
<TreeCollapseIconStyled size={14} />
) : (
<TreeExpandIconStyled size={14} />
)}
Comment on lines +196 to +200

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Chevrons now appear for all items, even when they have no exports and can't be expanded. This could confuse users since the chevron suggests expandability.

Suggested change
{itemSelected ? (
<TreeCollapseIconStyled size={14} />
) : (
<TreeExpandIconStyled size={14} />
)}
{(searchResult.exportedComponents && searchResult.exportedComponents.length > 0) && (
itemSelected ? (
<TreeCollapseIconStyled size={14} />
) : (
<TreeExpandIconStyled size={14} />
)
)}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is valid. If consistency with the sidebar is what you were after, then items without children shouldn't have a chevron. It seems in the original version the chevron was doing double-duty as an expand indicator as well as a "continue" or "next" icon. That was honestly confusing because you couldn't tell whether clicking a row would generate a story or expand to reveal children. We should fix that. Maybe keep the larger chevron on the right as an indicator for leaf nodes (i.e. this will generate a story). I'd also be fine with some other indicator. Would be even better to get some sort of confirmation screen before actually generating the story. @MichaelArestad WDYT?

<FileListIconWrapper error={itemError}>
<ComponentIcon />
</FileListIconWrapper>
Expand All @@ -198,7 +207,6 @@ export const FileSearchList = memo(function FileSearchList({
</FileListItemLabel>
<FileListItemPath>{searchResult.filepath}</FileListItemPath>
</FileListItemContent>
{itemSelected ? <ChevronDownIconStyled /> : <ChevronRightIconStyled />}
</FileListItemContentWrapper>
{/* @ts-expect-error (non strict) */}
{searchResult?.exportedComponents?.length > 1 && itemSelected && (
Expand Down Expand Up @@ -249,19 +257,20 @@ export const FileSearchList = memo(function FileSearchList({
}}
>
<FileListItemExportName>
<ComponentIcon />
<BookmarkHollowIcon />
{component.default ? (
<>
<FileListItemExportNameContent>
<FileListItemExportNameContentWithExport>
{searchResult.filepath.split('/').at(-1)?.split('.')?.at(0)}
</FileListItemExportNameContent>
</FileListItemExportNameContentWithExport>
<DefaultExport>Default export</DefaultExport>
</>
) : (
component.name
<FileListItemExportNameContent>
{component.name}
</FileListItemExportNameContent>
)}
</FileListItemExportName>
<ChevronRightIconStyled />
</FileListItemExport>
);
})}
Expand Down Expand Up @@ -340,15 +349,15 @@ export const FileSearchList = memo(function FileSearchList({
<WithTooltip
{...itemProps}
style={{ width: '100%' }}
trigger="hover"
hasChrome={false}
closeOnOutsideClick={true}
delayHide={100}
delayShow={200}
placement="top-start"
tooltip={
<TooltipNote
// @ts-expect-error (non strict)
note={
noExports
? "We can't evaluate exports for this file. You can't create a story for it automatically"
: null
"We can't evaluate exports for this file. Automatic story creation is disabled."
}
/>
}
Expand Down
Loading