Sha256: 583b0e5923a4c8eb24a53439d42efe3c0ffe47bee37ba23fc760d1263c4cbf59

Contents?: true

Size: 1.8 KB

Versions: 86

Compression:

Stored size: 1.8 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 },
  disabled?: boolean,
  htmlOptions?: {[key: string]: string | number | boolean | (() => void)},
  id?: string,
  name?: string,
  onChange?: InputCallback<HTMLInputElement>,
  size?: "sm" | "md",
  value?: string,
} & GlobalProps

const Toggle = ({
  aria = {},
  checked = false,
  children,
  className,
  data = {},
  disabled = false,
  id,
  htmlOptions = {},
  name,
  onChange = (): void => {
  // Function body here
  },
  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}
              disabled={disabled}
              name={name}
              onChange={onChange}
              type="checkbox"
              value={value}
          />
        }
        <div className="pb_toggle_control" />
      </label>
    </div>
  )
}

export default Toggle

Version data entries

86 entries across 86 versions & 1 rubygems

Version Path
playbook_ui-13.34.1.pre.alpha.play1447addrequiredicons3455 app/pb_kits/playbook/pb_toggle/_toggle.tsx
playbook_ui-13.34.1.pre.alpha.play1447addrequiredicons3451 app/pb_kits/playbook/pb_toggle/_toggle.tsx
playbook_ui-13.34.1.pre.alpha.PLAY14043436 app/pb_kits/playbook/pb_toggle/_toggle.tsx
playbook_ui-13.34.1.pre.alpha.pbntr258paginationkitforreact3413 app/pb_kits/playbook/pb_toggle/_toggle.tsx
playbook_ui-13.34.1.pre.alpha.pbntr258paginationkitforreact3411 app/pb_kits/playbook/pb_toggle/_toggle.tsx
playbook_ui-13.34.1.pre.alpha.pbntr258paginationkitforreact3409 app/pb_kits/playbook/pb_toggle/_toggle.tsx
playbook_ui-13.34.1.pre.alpha.pbntr258paginationkitforreact3404 app/pb_kits/playbook/pb_toggle/_toggle.tsx
playbook_ui-13.34.1.pre.alpha.powerfontsexternal3403 app/pb_kits/playbook/pb_toggle/_toggle.tsx
playbook_ui-14.0.0 app/pb_kits/playbook/pb_toggle/_toggle.tsx
playbook_ui-13.34.1.pre.alpha.play1407statvaluekitinconsistencies3388 app/pb_kits/playbook/pb_toggle/_toggle.tsx
playbook_ui-13.34.1.pre.alpha.PLAY14703378 app/pb_kits/playbook/pb_toggle/_toggle.tsx
playbook_ui-13.34.0.pre.alpha.PLAY14143373 app/pb_kits/playbook/pb_toggle/_toggle.tsx
playbook_ui-13.34.0.pre.alpha.PLAY14143372 app/pb_kits/playbook/pb_toggle/_toggle.tsx
playbook_ui-13.34.1 app/pb_kits/playbook/pb_toggle/_toggle.tsx
playbook_ui-13.34.0.pre.alpha.PBNTR358responsiveadvancedtablereact3370 app/pb_kits/playbook/pb_toggle/_toggle.tsx
playbook_ui-13.34.0.pre.alpha.PBNTR358responsiveadvancedtablereact3369 app/pb_kits/playbook/pb_toggle/_toggle.tsx
playbook_ui-13.34.0.pre.alpha.PBNTR358responsiveadvancedtablereact3368 app/pb_kits/playbook/pb_toggle/_toggle.tsx
playbook_ui-13.34.0.pre.alpha.PBNTR358responsiveadvancedtablereact3366 app/pb_kits/playbook/pb_toggle/_toggle.tsx
playbook_ui-13.34.0.pre.alpha.PLAY14143358 app/pb_kits/playbook/pb_toggle/_toggle.tsx
playbook_ui-13.34.0.pre.alpha.PLAY14143357 app/pb_kits/playbook/pb_toggle/_toggle.tsx