Skip to content

Commit

Permalink
Add count of selected filters
Browse files Browse the repository at this point in the history
  • Loading branch information
shilman committed Jun 17, 2024
1 parent 7b69bae commit b8af895
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
49 changes: 37 additions & 12 deletions code/ui/manager/src/components/sidebar/TagsFilter.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
import React, { useState, useEffect } from 'react';
import { IconButton, WithTooltip } from '@storybook/components';
import { Badge, IconButton, WithTooltip } from '@storybook/components';
import { FilterIcon } from '@storybook/icons';
import type { API } from '@storybook/manager-api';
import { styled } from '@storybook/theming';
import type { Tag, API_IndexHash } from '@storybook/types';
import { TagsFilterPanel } from './TagsFilterPanel';

const TAGS_FILTER = 'tags-filter';

const Wrapper = styled.div({
position: 'relative',
});

const Count = styled(Badge)(({ theme }) => ({
position: 'absolute',
top: 0,
right: 0,
transform: 'translate(50%, -50%)',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
padding: 3,
height: 15,
minWidth: 15,
lineHeight: '15px',
fontSize: theme.typography.size.s1 - 1,
background: theme.color.secondary,
color: theme.color.lightest,
}));

export interface TagsFilterProps {
api: API;
index: API_IndexHash;
Expand Down Expand Up @@ -66,17 +88,20 @@ export const TagsFilter = ({
/>
)}
>
<IconButton
key="tags"
title="Tag filters"
active={tagsActive}
onClick={(event) => {
event.preventDefault();
setExpanded(!expanded);
}}
>
<FilterIcon />
</IconButton>
<Wrapper>
<IconButton
key="tags"
title="Tag filters"
active={tagsActive}
onClick={(event) => {
event.preventDefault();
setExpanded(!expanded);
}}
>
<FilterIcon />
</IconButton>
{selectedTags.length > 0 && <Count>{selectedTags.length}</Count>}
</Wrapper>
</WithTooltip>
);
};
2 changes: 2 additions & 0 deletions code/ui/manager/src/components/sidebar/TagsFilterPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, { useState } from 'react';
import { transparentize } from 'polished';
import { styled } from '@storybook/theming';
import { CollapseIcon } from './components/CollapseIcon';
import type { Tag } from '@storybook/types';

const BUILT_IN_TAGS = new Set([
'dev',
Expand Down Expand Up @@ -88,6 +89,7 @@ const TagsList = ({ tags, selectedTags, toggleTag }: TagsListProps) => {
};

const Wrapper = styled.div({
padding: 10,
label: {
display: 'flex',
},
Expand Down

0 comments on commit b8af895

Please sign in to comment.