Sha256: 5d50cc5802c0d4b64eb9a98738dd0a64adfd5140721acb8d21360fc98ff7a741

Contents?: true

Size: 1.67 KB

Versions: 10

Compression:

Stored size: 1.67 KB

Contents

import React from 'react'
import classnames from 'classnames'
import type { InputCallback } from '../types'

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

import { GlobalProps, globalProps } from '../utilities/globalProps'

type Props = {
  aria?: { [key: string]: string },
  checked?: boolean,
  children?: React.ReactNode | React.ReactNode[],
  className?: string,
  data?: { [key: string]: string },
  htmlOptions?: {[key: string]: string | number | boolean | Function},
  id?: string,
  name?: string,
  onChange?: InputCallback<HTMLInputElement>,
  size?: "sm" | "md",
  value?: string,
} & GlobalProps

const Toggle = ({
  aria = {},
  checked = false,
  children,
  className,
  data = {},
  id,
  htmlOptions = {},
  name,
  onChange = () => { },
  size = 'sm',
  value,
  ...props
}: Props) => {
  const ariaProps = buildAriaProps(aria)
  const dataProps = buildDataProps(data)
  const htmlProps = buildHtmlProps(htmlOptions)
  const css = classnames(
    buildCss('pb_toggle_kit',
      size,
      {
        on: checked,
        off: !checked,
      }
    ))

  return (
    <div
      {...ariaProps}
      {...dataProps}
      {...htmlProps}
      className={classnames(css, globalProps(props), className)}
      id={id}
    >
      <label className="pb_toggle_wrapper">
        {children && children}

        {!children &&
          <input
            {...props}
            defaultChecked={checked}
            name={name}
            onChange={onChange}
            type="checkbox"
            value={value}
          />
        }
        <div className="pb_toggle_control" />
      </label>
    </div>
  )
}

export default Toggle

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
playbook_ui-13.14.0.pre.alpha.PLAY1109bugdisplaypropblocksfontcolor1784 app/pb_kits/playbook/pb_toggle/_toggle.tsx
playbook_ui-13.14.0.pre.alpha.play1106filter1751 app/pb_kits/playbook/pb_toggle/_toggle.tsx
playbook_ui-13.14.0.pre.alpha.play1106filter1748 app/pb_kits/playbook/pb_toggle/_toggle.tsx
playbook_ui-13.14.0 app/pb_kits/playbook/pb_toggle/_toggle.tsx
playbook_ui-13.13.0.pre.alpha.PLAY1097linterenhancedelement1728 app/pb_kits/playbook/pb_toggle/_toggle.tsx
playbook_ui-13.13.0.pre.alpha.play10221678 app/pb_kits/playbook/pb_toggle/_toggle.tsx
playbook_ui-13.13.0.pre.alpha.PLAY1090csstokens1675 app/pb_kits/playbook/pb_toggle/_toggle.tsx
playbook_ui-13.13.0.pre.alpha.play900startratingasinput1657 app/pb_kits/playbook/pb_toggle/_toggle.tsx
playbook_ui-13.13.0 app/pb_kits/playbook/pb_toggle/_toggle.tsx
playbook_ui-13.12.0.pre.alpha.play10281596 app/pb_kits/playbook/pb_toggle/_toggle.tsx