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.23.0.pre.alpha.PLAY1284investigation2657 app/pb_kits/playbook/pb_toggle/_toggle.tsx
playbook_ui-13.24.0 app/pb_kits/playbook/pb_toggle/_toggle.tsx
playbook_ui-13.22.0.pre.alpha.pbntr254barchartnegativenumber2640 app/pb_kits/playbook/pb_toggle/_toggle.tsx
playbook_ui-13.22.0.pre.alpha.PLAY1297updatetextstyles2636 app/pb_kits/playbook/pb_toggle/_toggle.tsx
playbook_ui-13.22.0.pre.alpha.playbookgemspecrailsversion2608 app/pb_kits/playbook/pb_toggle/_toggle.tsx
playbook_ui-13.23.0 app/pb_kits/playbook/pb_toggle/_toggle.tsx