UNPKG

@spaced-out/ui-design-system

Version:
38 lines (32 loc) 719 B
// @flow strict import * as React from 'react'; type V = { key: string, label: string, arbitrary?: boolean, multiarbitrary?: boolean, ... }; type Group<V> = { options: Array<V>, groupTitle?: React.Node, ... }; export const getFirstOption = (options: Array<V>): V | null => { // pick the first option from the options if (options.length > 0) { return options[0]; } return null; }; export const getFirstOptionFromGroup = ( groupTitleOptions: Array<Group<V>>, ): V | null => { if (groupTitleOptions.length > 0) { const firstGroup = groupTitleOptions[0]; if (firstGroup.options && firstGroup.options.length > 0) { return firstGroup.options[0]; } } return null; };