Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
ui-component-library / src / forms / __unused / RadioGroup / deps / unselectInputsList.tsx
Size: Mime:
import { isSelectedInput } from './isSelectedInput'

// unselectInputsListFor
// unselectInputsListExcept
function unselectInputsList(input, inputsList) {
  // console.log('unselectInputsList', inputsList, input)

  // filter + set
  //
  // compare an input
  //  if (it isn't the one that just changed)
  //  -> unselect it
  const unSelectOtherInputs = selectedInput => {
    // console.log('unSelectOtherInputs', selectedInput)
    const isDiffIdentifier = selectedInput.identifier !== input.identifier
    // console.log({ isDiffIdentifier })
    if (isDiffIdentifier) {
      // console.warn('UNSELECTING')
      // selectedInput.isSelected = false

      if (selectedInput.unselect) {
        // console.log('selecting input')
        selectedInput.unselect()
      } else {
        throw new TypeError('use the action')
      }
      // selectedInput.isSelected = !selectedInput.isSelected
    }
  }

  // if some are selected, unselect the others
  if (inputsList.some(isSelectedInput)) {
    // @todo may need slice?
    // console.warn('OTHERS_ARE_SELECTED')
    //
    const selectedList = inputsList.filter(isSelectedInput)
    selectedList.forEach(unSelectOtherInputs)
  }
}
unselectInputsList.isRadioUnSelect = true

export { unselectInputsList }
export default unselectInputsList