Sha256: f105540e25b040586f4a3c45a6a547edcec4d0861e9a973705f414ed76ee1a86

Contents?: true

Size: 1.46 KB

Versions: 208

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 = 'sm',
  value,
  ...props
}: Props) => {
  const ariaProps = buildAriaProps(aria)
  const dataProps = buildDataProps(data)
  const css = classnames(
    buildCss('pb_toggle_kit',
      size,
      {
        on: checked,
        off: !checked,
      }
    ))

  return (
    <div
        {...ariaProps}
        {...dataProps}
        className={classnames(css, globalProps(props), className)}
        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

208 entries across 208 versions & 1 rubygems

Version Path
playbook_ui-10.23.0.pre.cachetest app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-10.21.0.pre.alpha.lightbox.2 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-10.21.0.pre.alpha.lightbox app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-10.21.0.pre.alpha.rg1 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-10.21.0.pre.alpha.jg1 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-10.21.0.pre.alpha.na1 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-10.21.0.pre.alpha.jd1 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-10.20.0 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-10.19.0 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-10.19.0.pre.lightbox app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-10.18.2 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-10.19.0.pre.popover.alpha1 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-10.18.1 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-10.18.0 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-10.17.0 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-10.16.0 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-10.15.1 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-10.15.1.pre.alpha.rubocop.deps app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-10.15.0 app/pb_kits/playbook/pb_toggle/_toggle.jsx
playbook_ui-10.14.1.pre.alpha2 app/pb_kits/playbook/pb_toggle/_toggle.jsx