Skip to content

Commit e0fd3b1

Browse files
natemoo-reandrewshie-sentry
authored andcommitted
ref(storybook): category sidebar icons (#83525)
Tiny improvement for our component library sidebar! Files in the tree now have icons based on their parent folder. The component icon (currently using "grid") should probably be something else, but we can circle back to that IMO. <img width="1184" alt="stories-sidebar" src="https://github.com/user-attachments/assets/c4bfcbcd-d3e9-40af-bc24-5b08c00c79c8" />
1 parent 7635fce commit e0fd3b1

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

static/app/views/stories/storyTree.tsx

+32-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@ import styled from '@emotion/styled';
33
import * as qs from 'query-string';
44

55
import Link from 'sentry/components/links/link';
6-
import {IconChevron, IconFile} from 'sentry/icons';
6+
import {
7+
IconChevron,
8+
IconCircle,
9+
IconCode,
10+
IconExpand,
11+
IconFile,
12+
IconGrid,
13+
IconNumber,
14+
} from 'sentry/icons';
15+
import type {SVGIconProps} from 'sentry/icons/svgIcon';
716
import {space} from 'sentry/styles/space';
817
import {useLocation} from 'sentry/utils/useLocation';
918

@@ -120,22 +129,42 @@ function Folder(props: {node: StoryTreeNode}) {
120129
function File(props: {node: StoryTreeNode}) {
121130
const location = useLocation();
122131
const query = qs.stringify({...location.query, name: props.node.path});
132+
const category = props.node.path.split('/').at(1) ?? 'default';
123133

124134
return (
125135
<li>
126136
<FolderLink
127137
to={`/stories/?${query}`}
128138
active={location.query.name === props.node.path}
129139
>
130-
{/* @TODO (JonasBadalic): Do file type icons make sense here? */}
131-
<IconFile size="xs" />
140+
<StoryIcon category={category} />
132141
{/* @TODO (JonasBadalic): Do we need to show the file extension? */}
133142
{normalizeFilename(props.node.name)}
134143
</FolderLink>
135144
</li>
136145
);
137146
}
138147

148+
function StoryIcon(props: {
149+
category: 'components' | 'icons' | 'styles' | 'utils' | 'views' | string | {};
150+
}) {
151+
const iconProps: SVGIconProps = {size: 'xs'};
152+
switch (props.category) {
153+
case 'components':
154+
return <IconGrid {...iconProps} />;
155+
case 'icons':
156+
return <IconExpand {...iconProps} />;
157+
case 'styles':
158+
return <IconCircle {...iconProps} />;
159+
case 'utils':
160+
return <IconCode {...iconProps} />;
161+
case 'views':
162+
return <IconNumber {...iconProps} />;
163+
default:
164+
return <IconFile {...iconProps} />;
165+
}
166+
}
167+
139168
const StoryList = styled('ul')`
140169
list-style-type: none;
141170
padding-left: 10px;

0 commit comments

Comments
 (0)