|
|
|
@ -7,11 +7,13 @@ import Typography from '../../../ui/typography'; |
|
|
|
|
import { |
|
|
|
|
COLORS, |
|
|
|
|
TYPOGRAPHY, |
|
|
|
|
TEXT_ALIGN, |
|
|
|
|
} from '../../../../helpers/constants/design-system'; |
|
|
|
|
import { useI18nContext } from '../../../../hooks/useI18nContext'; |
|
|
|
|
|
|
|
|
|
const snapIdPrefixes = ['npm:', 'local:']; |
|
|
|
|
|
|
|
|
|
const SnapsAuthorshipPill = ({ snapId, className }) => { |
|
|
|
|
const SnapsAuthorshipPill = ({ snapId, version, className }) => { |
|
|
|
|
// @todo Use getSnapPrefix from snaps-skunkworks when possible
|
|
|
|
|
const snapPrefix = snapIdPrefixes.find((prefix) => snapId.startsWith(prefix)); |
|
|
|
|
const packageName = snapId.replace(snapPrefix, ''); |
|
|
|
@ -20,6 +22,7 @@ const SnapsAuthorshipPill = ({ snapId, className }) => { |
|
|
|
|
? `https://www.npmjs.com/package/${packageName}` |
|
|
|
|
: packageName; |
|
|
|
|
const icon = isNPM ? 'fab fa-npm fa-lg' : 'fas fa-code'; |
|
|
|
|
const t = useI18nContext(); |
|
|
|
|
return ( |
|
|
|
|
<a |
|
|
|
|
href={url} |
|
|
|
@ -33,6 +36,26 @@ const SnapsAuthorshipPill = ({ snapId, className }) => { |
|
|
|
|
<i className={`${icon} snaps-authorship-icon`} /> |
|
|
|
|
</Box> |
|
|
|
|
} |
|
|
|
|
rightIcon={ |
|
|
|
|
version && ( |
|
|
|
|
<Box |
|
|
|
|
className="snaps-authorship-version" |
|
|
|
|
backgroundColor={COLORS.PRIMARY_DEFAULT} |
|
|
|
|
paddingLeft={2} |
|
|
|
|
paddingRight={2} |
|
|
|
|
> |
|
|
|
|
<Typography |
|
|
|
|
color={COLORS.PRIMARY_INVERSE} |
|
|
|
|
variant={TYPOGRAPHY.H7} |
|
|
|
|
align={TEXT_ALIGN.CENTER} |
|
|
|
|
tag="span" |
|
|
|
|
className="version" |
|
|
|
|
> |
|
|
|
|
{t('shorthandVersion', [version])} |
|
|
|
|
</Typography> |
|
|
|
|
</Box> |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
backgroundColor={COLORS.BACKGROUND_DEFAULT} |
|
|
|
|
> |
|
|
|
|
<Typography |
|
|
|
@ -53,6 +76,10 @@ SnapsAuthorshipPill.propTypes = { |
|
|
|
|
* The id of the snap |
|
|
|
|
*/ |
|
|
|
|
snapId: PropTypes.string, |
|
|
|
|
/** |
|
|
|
|
* The version of the snap |
|
|
|
|
*/ |
|
|
|
|
version: PropTypes.string, |
|
|
|
|
/** |
|
|
|
|
* The className of the SnapsAuthorshipPill |
|
|
|
|
*/ |
|
|
|
|