Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
satr committed Sep 23, 2024
1 parent 504dee1 commit 7e6e44f
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 24 deletions.
116 changes: 92 additions & 24 deletions src/components/git-tags/git-tag-links.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,97 @@
import { Typography } from '@equinor/eds-core-react';
import type { FunctionComponent } from 'react';

import { List, Tooltip, Typography } from '@equinor/eds-core-react';
import { type FunctionComponent, useState } from 'react';
import { linkToGitHubTag } from '../../utils/string';
import { ScrimPopup } from '../scrim-popup';

import './style.css';

const Tag: FunctionComponent<{
repository: string;
tag: string;
tagTitle: string;
}> = ({ repository, tag, tagTitle }) => (
<Typography
token={{ textDecoration: 'none' }}
{...(repository && {
link: true,
href: linkToGitHubTag(repository, tag),
rel: 'noopener noreferrer',
target: '_blank',
})}
>
<div className="tags">{tagTitle}</div>
</Typography>
);

const ShortenedTag: FunctionComponent<{ repository: string; tag: string }> = ({
repository,
tag,
}) => {
const tagTitle =
tag?.length > 25 ? `${tag.substring(0, 8)}...${tag.slice(-12)}` : tag;
return tag && tagTitle != tag ? (
<Tooltip placement="top" title={tag}>
<div>
<Tag tag={tag} tagTitle={tagTitle} repository={repository} />
</div>
</Tooltip>
) : (
<Tag tag={tag} tagTitle={tagTitle} repository={repository} />
);
};

const TagList: FunctionComponent<{ repository: string; tags: string[] }> = ({
repository,
tags,
}) => (
<List>
{tags.map((tag) => (
<List.Item key={tag}>
<ShortenedTag tag={tag} repository={repository} />
</List.Item>
))}
</List>
);

export const GitTagLinks: FunctionComponent<{
gitTags: string;
repository?: string;
}> = ({ gitTags, repository }) => (
<>
{gitTags
.split(/[ ,]+/)
.map((tag) => tag.trim())
.map((tag, i, arr) => (
<Typography
key={i}
token={{ textDecoration: 'none' }}
{...(repository && {
link: true,
href: linkToGitHubTag(repository, tag),
rel: 'noopener noreferrer',
target: '_blank',
})}
>
{`${tag}${arr.length - 1 !== i ? ', ' : ''}`}
</Typography>
))}
</>
);
}> = ({ gitTags, repository }) => {
const [visibleScrim, setVisibleScrim] = useState(false);
const gitTagList = gitTags?.split(/[ ,]+/) || [];
return (
<>
{!gitTagList.length ? (
<></>
) : gitTagList.length == 1 ? (
<ShortenedTag tag={gitTagList[0]} repository={repository} />
) : gitTags.length < 20 ? (
gitTagList
.map((tag) => tag.trim())
.map((tag) => (
<ShortenedTag key={tag} tag={tag} repository={repository} />
))
) : (
<>
<Typography
link
onClick={() => setVisibleScrim(!visibleScrim)}
token={{ textDecoration: 'none' }}
>
Multiple tags
</Typography>
<ScrimPopup
title={'Tags'}
open={!!visibleScrim}
onClose={() => setVisibleScrim(false)}
isDismissable
>
<div className="multiple-tags-content">
<TagList tags={gitTagList} repository={repository} />
</div>
</ScrimPopup>
</>
)}
</>
);
};
11 changes: 11 additions & 0 deletions src/components/git-tags/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.multiple-tags-content {
padding: var(--eds_spacing_medium);
padding-top: 0;
overflow: auto;
}

.tags {
font-size: 0.850rem;
line-height: 1.333em;
font-weight: 500;
}

0 comments on commit 7e6e44f

Please sign in to comment.