import { DEFAULT_SETTINGS_SPEC } from '../../specs/constants' ; import { SettingsSpec } from '../../specs/settings' ; import { isDefined } from '../../utils/common' ; import { GlobalChartState } from '../chart_state' ; import { createCustomCachedSelector } from '../create_selector' ; import { getChartIdSelector } from './get_chart_id' ; import { getSettingsSpecSelector } from './get_settings_specs' ; internal export const getSpecs = ( state ) => state . specs ; internal export type A11ySettings = { label ? : string ; labelId ? : string ; labelHeadingLevel : SettingsSpec [ 'ariaLabelHeadingLevel' ] ; description ? : string ; descriptionId ? : string ; defaultSummaryId ? : string ; tableCaption ? : string ; } ; internal export const DEFAULT_A11Y_SETTINGS = { labelHeadingLevel : DEFAULT_SETTINGS_SPEC . ariaLabelHeadingLevel , } ; internal export const getA11ySettingsSelector = createCustomCachedSelector ( [ getSettingsSpecSelector , getChartIdSelector ] , ( { ariaDescription , ariaDescribedBy , ariaLabel , ariaLabelledBy , ariaUseDefaultSummary , ariaLabelHeadingLevel , ariaTableCaption , } , chartId ) => { const defaultSummaryId = ariaUseDefaultSummary ? `${ chartId }--defaultSummary` : undefined ; const describeBy = [ ariaDescribedBy ?? ( ariaDescription && `${ chartId }--desc` ) , defaultSummaryId ] . filter ( isDefined ) ; return { label : ariaLabelledBy ? undefined : ariaLabel , labelId : ariaLabelledBy ?? ( ariaLabel && `${ chartId }--label` ) , labelHeadingLevel : isValidHeadingLevel ( ariaLabelHeadingLevel ) ? ariaLabelHeadingLevel : DEFAULT_A11Y_SETTINGS . labelHeadingLevel , description : ariaDescribedBy ? undefined : ariaDescription , descriptionId : describeBy . length > 0 ? describeBy . join ( ' ' ) : undefined , defaultSummaryId , tableCaption : ariaTableCaption , } ; } ) ; function isValidHeadingLevel ( ariaLabelHeadingLevel ) { return [ 'h1' , 'h2' , 'h3' , 'h4' , 'h5' , 'h6' , 'p' ] . includes ( ariaLabelHeadingLevel ) ; }