import React from 'react' import { Link } from 'gatsby' import shortid from 'shortid' import slugify from 'slugify' import styles from './Tags.module.css' declare type TagsProps = { items: string[] max?: number showMore?: boolean className?: string noLinks?: boolean } const Tag = ({ tag, noLinks }: { tag: string; noLinks?: boolean }) => { // TODO: we should slugify all tags upon publish, so only // slug-style tags should be allowed. const cleanTag = slugify(tag).toLowerCase() return noLinks ? ( {cleanTag} ) : ( {cleanTag} ) } const Tags: React.FC = ({ items, max, showMore, className, noLinks }) => { max = max || items.length const remainder = items.length - max const tags = items.slice(0, max) const shouldShowMore = showMore && remainder > 0 const classes = className ? `${styles.tags} ${className}` : styles.tags return (
{tags && tags.map((tag) => ( ))} {shouldShowMore && ( {`+ ${items.length - max} more`} )}
) } export default Tags