Sha256: 0977849afc5ecace81b637a0547f6f238f6e920335d832932f3231ca52027cef

Contents?: true

Size: 1.86 KB

Versions: 64

Compression:

Stored size: 1.86 KB

Contents

/*eslint-disable react/no-multi-comp, flowtype/space-before-type-colon */

import React, { forwardRef } from 'react'
import Body from '../pb_body/_body'
import classnames from 'classnames'
import { buildAriaProps, buildCss, buildDataProps } from '../utilities/props'
import { globalProps, GlobalProps } from '../utilities/globalProps'

type RadioProps = {
  aria?: {[key: string]: string},
  alignment?: string,
  checked?: boolean,
  children?: Node,
  className?: string,
  dark?: boolean,
  data?: {[key: string]: string},
  error?: boolean,
  id?: string,
  label: string,
  name: string,
  value: string,
  text: string,
  onChange: (event: React.FormEvent<HTMLInputElement> | null)=>void,
} & GlobalProps

const Radio = ({
  aria = {},
  alignment,
  children,
  className,
  dark = false,
  data = {},
  error = false,
  id,
  label,
  name = 'radio_name',
  text = 'Radio Text',
  value = 'radio_text',
  onChange = () => { void 0 },
  ...props
}: RadioProps, ref: any) => {
  const ariaProps = buildAriaProps(aria)
  const dataProps = buildDataProps(data)
  const classes = classnames(
    buildCss('pb_radio_kit', alignment ),
    dark ? 'dark': null, error ? 'error': null,
    globalProps(props),
    className)

  const displayRadio = (props: RadioProps & any) => {
    if (children)
      return (children)
    else
    return (
    <input
        id={id}
        name={name}
        onChange={onChange}
        ref={ref}
        text={text}
        type="radio"
        value={value}
        {...props}
    />
  )}

  return (
    <label
        {...ariaProps}
        {...dataProps}
        className={classes}
        htmlFor={id}
    >
    <>{displayRadio(props)}</>
    <span className="pb_radio_button" />
    <Body
        dark={dark}
        status={error ? 'negative' : null}
        text={label}
        variant={null}
      />
    </label>
  )
}

export default forwardRef(Radio)

Version data entries

64 entries across 64 versions & 1 rubygems

Version Path
playbook_ui-11.13.0.pre.alpha.fileupload1 app/pb_kits/playbook/pb_radio/_radio.tsx
playbook_ui-11.12.0 app/pb_kits/playbook/pb_radio/_radio.tsx
playbook_ui-11.11.0.pre.alpha.paginate2 app/pb_kits/playbook/pb_radio/_radio.tsx
playbook_ui-11.11.0.pre.alpha.dialog2 app/pb_kits/playbook/pb_radio/_radio.tsx
playbook_ui-11.11.0.pre.alpha.paginate1 app/pb_kits/playbook/pb_radio/_radio.tsx
playbook_ui-11.11.0.pre.alpha.renderer1 app/pb_kits/playbook/pb_radio/_radio.tsx
playbook_ui-11.11.0.pre.alpha.dialog1 app/pb_kits/playbook/pb_radio/_radio.tsx
playbook_ui-11.11.0 app/pb_kits/playbook/pb_radio/_radio.tsx
playbook_ui-11.10.0.pre.alpha.pre.bold1 app/pb_kits/playbook/pb_radio/_radio.tsx
playbook_ui-11.10.0.pre.alpha.pagination1 app/pb_kits/playbook/pb_radio/_radio.tsx
playbook_ui-11.10.0 app/pb_kits/playbook/pb_radio/_radio.tsx
playbook_ui-11.9.0 app/pb_kits/playbook/pb_radio/_radio.tsx
playbook_ui-11.9.0.pre.alpha.fileupload1 app/pb_kits/playbook/pb_radio/_radio.tsx
playbook_ui-11.8.1 app/pb_kits/playbook/pb_radio/_radio.tsx
playbook_ui-11.8.0 app/pb_kits/playbook/pb_radio/_radio.tsx
playbook_ui-11.7.0.pre.alpha.table1 app/pb_kits/playbook/pb_radio/_radio.tsx
playbook_ui-11.7.0 app/pb_kits/playbook/pb_radio/_radio.tsx
playbook_ui-11.6.0.pre.alpha.fontawesome app/pb_kits/playbook/pb_radio/_radio.tsx
playbook_ui-11.5.0.pre.alpha.fontawesome app/pb_kits/playbook/pb_radio/_radio.tsx
playbook_ui-11.7.0.pre.alpha.pre.guagechart1 app/pb_kits/playbook/pb_radio/_radio.tsx