Sha256: 7f8c2ea0b91ae12059637664cca2e11e6b38628e57bc2d2aa2e61885167bf04e

Contents?: true

Size: 1.35 KB

Versions: 44

Compression:

Stored size: 1.35 KB

Contents

// @flow

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

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

import { spacing } from '../utilities/spacing.js'

type Props = {
  aria: object,
  checked: boolean,
  data: object,
  onChange: InputCallback<HTMLInputElement>,
  onCheck: InputCallback<HTMLInputElement>,
  onUncheck: InputCallback<HTMLInputElement>,
  size: "sm" | "md",
}

const Toggle = ({
  aria = {},
  checked = false,
  data = {},
  onChange = noop,
  onCheck = noop,
  onUncheck = noop,
  size = 'md',
  ...props
}: Props) => {
  const ariaProps = buildAriaProps(aria)
  const dataProps = buildDataProps(data)
  const handleChange = (event) => {
    onChange(event)
    event.target.checked ? onCheck(event) : onUncheck(event)
  }

  const css = buildCss({
    'pb_toggle_kit': true,
    [size]: true,
    on: checked,
    off: !checked,
  })

  return (
    <div
        {...ariaProps}
        {...dataProps}
        className={classnames(css, spacing(props))}
    >
      <label className="pb_toggle_wrapper">
        <input
            {...props}
            checked={checked}
            onChange={handleChange}
            type="checkbox"
        />

        <div className="pb_toggle_control" />
      </label>
    </div>
  )
}

export default Toggle

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
playbook_ui-5.2.0.pre.alpha8 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-5.2.0.pre.alpha7 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-5.3.0.pre.alpha1 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-5.4.0 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-5.2.0.pre.alpha6 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-5.2.0.pre.alpha5 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-5.3.0 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-5.2.0.pre.alpha4 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-5.2.0.pre.alpha3 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-5.2.0.pre.alpha2 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-5.2.0 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-5.1.0 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-5.0.3 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-5.0.2 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-5.0.1.pre.beta app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-5.1.0.pre.alpha4 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-5.1.0.pre.alpha2 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-5.1.0.pre.alpha1 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-5.0.1 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-5.0.1.pre.alpha1 app/pb_kits/playbook/pb_toggle/_toggle.jsx