0.4.0 • Published 3 years ago

@primitives/radio v0.4.0

Weekly downloads
22
License
MIT
Repository
github
Last release
3 years ago

Radio brings the equivalent of an <input type="radio" /> to Native land.

Handling changes

Context passes down a groupValue and a groupName together with a setGroupValue action to all its consumers. Both the value and the state are set by a useState hook within the consumer’s side, while groupName is a hardcoded string that marks the group name. And this is how the checked state is defined, since React Native does not offer a built-in solution similar to the radio input on Web.

Basic usage

import React, { useState } from 'react'
import { RadioGroup, RadioContext, RadioInput } from '@primitives/radio'
import PresentationComponent from './somewhere'

const RadioWrapper = ({
  groupName,
  isVisible = false,
  isDisabled = false
}) => {
  const [ groupValue, setGroupValue ] = useState('')

  return <RadioGroup
    groupName={groupName}
    groupValue={groupValue}
    onChange={setGroupValue}
  >
    <RadioInput
      value={value}
      isVisible={isVisible}
      isDisabled={isDisabled}
    />
    <RadioContext.Consumer>
      {({groupValue}) => (
        <PresentationComponent
          groupValue={groupValue}
        />
      )}
    </RadioContext.Consumer>
  </RadioGroup>
}
0.4.0

3 years ago

0.3.1

3 years ago

0.3.0

4 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago