import React from 'react'; import PropTypes from 'prop-types'; import classnames from 'classnames'; import Chip from '../../../ui/chip'; import Box from '../../../ui/box'; 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, version, className }) => { // @todo Use getSnapPrefix from snaps-skunkworks when possible const snapPrefix = snapIdPrefixes.find((prefix) => snapId.startsWith(prefix)); const packageName = snapId.replace(snapPrefix, ''); const isNPM = snapPrefix === 'npm:'; const url = isNPM ? `https://www.npmjs.com/package/${packageName}` : packageName; const icon = isNPM ? 'fab fa-npm fa-lg' : 'fas fa-code'; const t = useI18nContext(); return ( } rightIcon={ version && ( {t('shorthandVersion', [version])} ) } backgroundColor={COLORS.BACKGROUND_DEFAULT} > {packageName} ); }; SnapsAuthorshipPill.propTypes = { /** * The id of the snap */ snapId: PropTypes.string, /** * The version of the snap */ version: PropTypes.string, /** * The className of the SnapsAuthorshipPill */ className: PropTypes.string, }; export default SnapsAuthorshipPill;