{"version":3,"file":"RadioButtonList.cjs","sources":["../../../../../src/components/Forms/RadioButtonList/RadioButtonList.tsx"],"sourcesContent":["import { css, cx } from '@emotion/css';\nimport { uniqueId } from 'lodash';\n\nimport { GrafanaTheme2, SelectableValue } from '@grafana/data';\n\nimport { useStyles2 } from '../../../themes/ThemeContext';\n\nimport { RadioButtonDot } from './RadioButtonDot';\n\nexport interface RadioButtonListProps<T> {\n  /** A name of a radio group. Used to group multiple radio inputs into a single group */\n  name: string;\n  id?: string;\n  /** An array of available options */\n  options: Array<SelectableValue<T>>;\n  value?: T;\n  onChange?: (value: T) => void;\n  /** Disables all elements in the list */\n  disabled?: boolean;\n  /** Disables subset of elements in the list. Compares values using the === operator */\n  disabledOptions?: T[];\n  className?: string;\n}\n\n/**\n * RadioButtonList is used to select a single value from multiple mutually exclusive options usually in a vertical manner.\n *\n * https://developers.grafana.com/ui/latest/index.html?path=/docs/inputs-radiobuttonlist--docs\n */\nexport function RadioButtonList<T extends string | number | readonly string[]>({\n  name,\n  id,\n  options,\n  value,\n  onChange,\n  className,\n  disabled,\n  disabledOptions = [],\n}: RadioButtonListProps<T>) {\n  const styles = useStyles2(getStyles);\n  const internalId = id ?? uniqueId('radiogroup-list-');\n\n  return (\n    <div id={id} className={cx(styles.container, className)} role=\"radiogroup\">\n      {options.map((option, index) => {\n        const itemId = `${internalId}-${index}`;\n\n        const isChecked = value && value === option.value;\n        const isDisabled = disabled || disabledOptions.some((optionValue) => optionValue === option.value);\n\n        const handleChange = () => onChange && option.value && onChange(option.value);\n\n        return (\n          <RadioButtonDot<T>\n            key={index}\n            id={itemId}\n            name={name}\n            label={option.label}\n            description={option.description}\n            checked={isChecked}\n            value={option.value}\n            disabled={isDisabled}\n            onChange={handleChange}\n          />\n        );\n      })}\n    </div>\n  );\n}\n\nconst getStyles = (theme: GrafanaTheme2) => ({\n  container: css({\n    display: 'grid',\n    gap: theme.spacing(1),\n  }),\n});\n"],"names":["useStyles2","uniqueId","jsx","cx","RadioButton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