Sha256: 3d28cd5f074c39a3e5426e34be9734ed1109ac3af0c7efedc3a7cdc0b3f6c421

Contents?: true

Size: 1.46 KB

Versions: 6

Compression:

Stored size: 1.46 KB

Contents

// @flow

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

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

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

type Props = {
  aria?: object,
  checked?: Boolean,
  children?: React.Node,
  className?: String,
  data?: object,
  id?: String,
  name?: String,
  onChange?: InputCallback<HTMLInputElement>,
  size?: "sm" | "md",
  value?: String,
}

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

  return (
    <div
        {...ariaProps}
        {...dataProps}
        className={classnames(css, globalProps(props))}
        id={id}
    >
      <label className="pb_toggle_wrapper">
        <If condition={children}>
          {children}
          <Else />
          <input
              {...props}
              defaultChecked={checked}
              name={name}
              onChange={onChange}
              type="checkbox"
              value={value}
          />
        </If>
        <div className="pb_toggle_control" />
      </label>
    </div>
  )
}

export default Toggle

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
playbook_ui-6.1.0.pre.alpha5 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-6.1.0.pre.alpha4 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-6.1.0.pre.alpha3 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-6.1.0.pre.alpha2 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-6.1.0.pre.alpha1 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-6.1.0 app/pb_kits/playbook/pb_toggle/_toggle.jsx