Sha256: e6678cd3e0e377ff3922e7aaf16be325b38e1a4e4d0b0176d236fb64cdabe13e

Contents?: true

Size: 1.86 KB

Versions: 375

Compression:

Stored size: 1.86 KB

Contents

/* eslint-disable react/jsx-no-target-blank */
/* eslint-disable react/no-multi-comp */

import React from 'react'
import classnames from 'classnames'

import { buildAriaProps, buildCss, buildDataProps, buildHtmlProps } from '../utilities/props'
import { globalProps, GlobalProps } from '../utilities/globalProps'

import Badge from '../pb_badge/_badge'

type HashtagProps = {
  aria?: {[key: string]: string},
  className?: string,
  dark?: boolean,
  data?: string,
  htmlOptions?: {[key: string]: string | number | boolean | (() => void)},
  id?: string,
  newWindow?: boolean,
  rel?: string,
  target?: string,
  text?: string,
  type: "default" | "home" | "project" | "appointment",
  url?: string,
} & GlobalProps

const typeMap = {
  home: 'H#',
  project: 'P#',
  appointment: 'A#',
  default: '#',
}

const Hashtag = (props: HashtagProps) => {
  const {
    aria = {},
    className,
    dark = false,
    data = {},
    htmlOptions = {},
    id,
    newWindow,
    rel,
    target,
    text,
    type = 'default',
    url,
  } = props

  const ariaProps = buildAriaProps(aria)
  const dataProps = buildDataProps(data)
  const htmlProps = buildHtmlProps(htmlOptions)
  const classes = classnames(buildCss('pb_hashtag_kit'), globalProps(props), className)

  const getTargetAttribute = () => {
    if (target && url) {
      return target
    } else if (newWindow) {
      return '_blank'
    } else {
      return '_self'
    }

    return null
  }

  return (
    <span
        {...ariaProps}
        {...dataProps}
        {...htmlProps}
        className={classes}
        id={id}
    >
      <a
          href={url}
          rel={(newWindow ? "noreferrer" : rel)}
          target={getTargetAttribute()}
      >
        <Badge
            dark={dark}
            text={typeMap[type] + text}
            variant="primary"
        />
      </a>
    </span>
  )
}

export default Hashtag

Version data entries

375 entries across 375 versions & 1 rubygems

Version Path
playbook_ui-14.3.1.pre.alpha.PBNTR515typeaheadmarginbottomredux3746 app/pb_kits/playbook/pb_hashtag/_hashtag.tsx
playbook_ui-14.4.0.pre.rc.4 app/pb_kits/playbook/pb_hashtag/_hashtag.tsx
playbook_ui-14.3.1.pre.alpha.dhhuynh2patch13743 app/pb_kits/playbook/pb_hashtag/_hashtag.tsx
playbook_ui-14.3.1.pre.alpha.PLAY14973742 app/pb_kits/playbook/pb_hashtag/_hashtag.tsx
playbook_ui-14.4.0.pre.rc.3 app/pb_kits/playbook/pb_hashtag/_hashtag.tsx
playbook_ui-14.4.0.pre.rc.2 app/pb_kits/playbook/pb_hashtag/_hashtag.tsx
playbook_ui-14.3.1 app/pb_kits/playbook/pb_hashtag/_hashtag.tsx
playbook_ui-14.4.0.pre.rc.1 app/pb_kits/playbook/pb_hashtag/_hashtag.tsx
playbook_ui-14.3.0.pre.alpha.revert3654PBNTR479removeextraspacingfromradiochildren3734 app/pb_kits/playbook/pb_hashtag/_hashtag.tsx
playbook_ui-14.4.0.pre.rc.0 app/pb_kits/playbook/pb_hashtag/_hashtag.tsx
playbook_ui-14.3.0 app/pb_kits/playbook/pb_hashtag/_hashtag.tsx
playbook_ui-14.3.0.pre.rc.12 app/pb_kits/playbook/pb_hashtag/_hashtag.tsx
playbook_ui-14.3.0.pre.rc.11 app/pb_kits/playbook/pb_hashtag/_hashtag.tsx
playbook_ui-14.3.0.pre.rc.10 app/pb_kits/playbook/pb_hashtag/_hashtag.tsx
playbook_ui-14.3.0.pre.rc.9 app/pb_kits/playbook/pb_hashtag/_hashtag.tsx