11import React , { useState } from 'react' ;
22
3- import { Foldable , HTML , ToggleArrow , YFMWrapper } from '../../components' ;
4- import Link from '../../components/Link/Link' ;
53import { Col , Row } from '../../grid' ;
64import { QuestionsProps } from '../../models' ;
75import { Content } from '../../sub-blocks' ;
86import { block } from '../../utils' ;
97
8+ import { QuestionBlockItem } from './QuestionBlockItem/QuestionBlockItem' ;
9+ import { FaqMicrodataValues } from './models' ;
10+
1011import './Questions.scss' ;
1112
1213const b = block ( 'QuestionsBlock' ) ;
1314
14- const FaqMicrodataValues = {
15- PageType : 'https://schema.org/FAQPage' ,
16- QuestionType : 'https://schema.org/Question' ,
17- QuestionProp : 'mainEntity' ,
18- QuestionNameProp : 'name' ,
19- QuestionTextProp : 'text' ,
20- AnswerType : 'https://schema.org/Answer' ,
21- AnswerProp : 'acceptedAnswer' ,
22- AnswerTextProp : 'text' ,
23- } as const ;
24-
2515const QuestionsBlock = ( props : QuestionsProps ) => {
2616 const { title, text, additionalInfo, links, buttons, items} = props ;
2717 const [ opened , setOpened ] = useState < number [ ] > ( [ 0 ] ) ;
@@ -30,7 +20,7 @@ const QuestionsBlock = (props: QuestionsProps) => {
3020 let newState ;
3121
3222 if ( opened . includes ( index ) ) {
33- newState = opened . filter ( ( intemIndex : number ) => intemIndex !== index ) ;
23+ newState = opened . filter ( ( itemIndex : number ) => itemIndex !== index ) ;
3424 } else {
3525 newState = [ ...opened , index ] ;
3626 }
@@ -53,54 +43,22 @@ const QuestionsBlock = (props: QuestionsProps) => {
5343 />
5444 </ div >
5545 </ Col >
56- < Col sizes = { { all : 12 , md : 8 } } >
46+ < Col sizes = { { all : 12 , md : 8 } } role = { 'list' } >
5747 { items . map (
5848 ( { title : itemTitle , text : itemText , link, listStyle = 'dash' } , index ) => {
5949 const isOpened = opened . includes ( index ) ;
50+ const onClick = ( ) => toggleItem ( index ) ;
6051
6152 return (
62- < div
53+ < QuestionBlockItem
6354 key = { itemTitle }
64- className = { b ( 'item' ) }
65- itemScope
66- itemProp = { FaqMicrodataValues . QuestionProp }
67- itemType = { FaqMicrodataValues . QuestionType }
68- >
69- < h3
70- className = { b ( 'item-title' ) }
71- onClick = { ( ) => toggleItem ( index ) }
72- >
73- < HTML itemProp = { FaqMicrodataValues . QuestionNameProp } >
74- { itemTitle }
75- </ HTML >
76- < ToggleArrow
77- open = { isOpened }
78- size = { 16 }
79- type = { 'vertical' }
80- iconType = "navigation"
81- className = { b ( 'arrow' ) }
82- />
83- </ h3 >
84- < Foldable isOpened = { isOpened } >
85- < div
86- className = { b ( 'text' ) }
87- itemScope
88- itemProp = { FaqMicrodataValues . AnswerProp }
89- itemType = { FaqMicrodataValues . AnswerType }
90- >
91- < YFMWrapper
92- content = { itemText }
93- modifiers = { {
94- constructor : true ,
95- constructorListStyle : true ,
96- constructorListStyleDash : listStyle === 'dash' ,
97- } }
98- itemProp = { FaqMicrodataValues . QuestionTextProp }
99- />
100- { link && < Link { ...link } className = { b ( 'link' ) } /> }
101- </ div >
102- </ Foldable >
103- </ div >
55+ title = { itemTitle }
56+ text = { itemText }
57+ link = { link }
58+ listStyle = { listStyle }
59+ isOpened = { isOpened }
60+ onClick = { onClick }
61+ />
10462 ) ;
10563 } ,
10664 ) }
0 commit comments