import React from 'react' import { Check, ChevronDown, ChevronRight, Minus } from 'lucide-react' import { useTranslation } from '../../i18n' import { fs } from '../shared/DialogShell' import { SettingRows, SETTINGS_BUTTON } from '../Settings/settingsKit' import { useScopeSelection } from './useScopeSelection' interface Props { selected: string[] onChange: (scopes: string[]) => void } /** The square of a checkbox in the accent look: ticked, partly ticked (mixed) or empty. */ function CheckBox({ checked, mixed = false }: { checked: boolean; mixed?: boolean }) { const on = checked || mixed return ( ) } /** * The scopes an OAuth client may ask for, grouped like the consent page: one row * per group with a fold-out list of its scopes. Every tick is a button with * role="checkbox", so it reads as one and answers to Space and Enter. */ export default function ScopeGroupPicker({ selected, onChange }: Props): React.ReactElement { const { t } = useTranslation() const { scopesByGroup, allSelected, open, groupState, toggleOpen, toggleAll, toggleGroup, toggleScope } = useScopeSelection(selected, onChange) return (
{Object.entries(scopesByGroup).map(([group, groupScopes]) => { const state = groupState(groupScopes) const { allSelected: allGroupSelected, someSelected: someGroupSelected, mixed } = state return (
{open[group] && (
{groupScopes.map(({ scope, label, description }) => { const on = selected.includes(scope) return ( ) })}
)}
) })}
) }