mirror of
https://github.com/DOI-DO/j40-cejst-2.git
synced 2025-02-23 01:54:18 -08:00
Add custom Accordion component to match designs
This commit is contained in:
parent
4a2bc42e27
commit
f7d2e27a97
3 changed files with 74 additions and 5 deletions
|
@ -6,10 +6,25 @@
|
||||||
.demographicItem {
|
.demographicItem {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
|
|
||||||
span {
|
span {
|
||||||
font-size: .8rem;
|
font-size: .8rem;
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.customDemographicHeading {
|
||||||
|
@include u-margin(1);
|
||||||
|
}
|
||||||
|
.customDemographicItemToggle {
|
||||||
|
//remove styling of button
|
||||||
|
border: none;
|
||||||
|
background-color: white;
|
||||||
|
|
||||||
|
//emulate a link
|
||||||
|
cursor:pointer;
|
||||||
|
color:blue;
|
||||||
|
text-decoration:underline;
|
||||||
|
|
||||||
|
min-width: 45px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@ declare namespace DemographicsNamespace {
|
||||||
export interface IDemographicsScss {
|
export interface IDemographicsScss {
|
||||||
demographicsContainer: string;
|
demographicsContainer: string;
|
||||||
demographicItem: string;
|
demographicItem: string;
|
||||||
|
customDemographicItemToggle: string;
|
||||||
|
customDemographicHeading: string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
import React from 'react';
|
import React, {useState} from 'react';
|
||||||
import {Accordion} from '@trussworks/react-uswds';
|
import {Accordion} from '@trussworks/react-uswds';
|
||||||
|
|
||||||
import * as styles from './Demographics.module.scss';
|
import * as styles from './Demographics.module.scss';
|
||||||
|
import {useFlags} from '../../contexts/FlagContext';
|
||||||
// export interface IDemographicsProps {}
|
|
||||||
|
|
||||||
type IDemographicsData = {
|
type IDemographicsData = {
|
||||||
racial: [string, number][],
|
racial: [string, number][],
|
||||||
age: [string, number][]
|
age: [string, number][]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Temporary while backend is developed
|
// Mock backend data
|
||||||
const demographicsData:IDemographicsData = {
|
const demographicsData:IDemographicsData = {
|
||||||
racial: [
|
racial: [
|
||||||
['White', 61.4],
|
['White', 61.4],
|
||||||
|
@ -30,6 +29,10 @@ const demographicsData:IDemographicsData = {
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Generate the demographic item based the input
|
||||||
|
* TODO: Update after actual data is created
|
||||||
|
*/
|
||||||
const demographicItemGen = (demographicData: any[]) => {
|
const demographicItemGen = (demographicData: any[]) => {
|
||||||
return demographicData.map((el, index) => {
|
return demographicData.map((el, index) => {
|
||||||
return (
|
return (
|
||||||
|
@ -41,7 +44,45 @@ const demographicItemGen = (demographicData: any[]) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
interface IJ40AccordionItem {
|
||||||
|
id: string,
|
||||||
|
title: string,
|
||||||
|
children: React.ElementType
|
||||||
|
}
|
||||||
|
|
||||||
|
const J40AccordionItem = ({id, title, children}:IJ40AccordionItem) => {
|
||||||
|
const [isExpanded, setIsExpanded] = useState(false);
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<h6 className={styles.customDemographicHeading}>
|
||||||
|
{title}
|
||||||
|
{' ( '}
|
||||||
|
<button
|
||||||
|
className={styles.customDemographicItemToggle}
|
||||||
|
id={`${id}-header`}
|
||||||
|
aria-controls={`${id}-panel`}
|
||||||
|
aria-expanded={isExpanded}
|
||||||
|
onClick={() => setIsExpanded(!isExpanded)}
|
||||||
|
tabIndex={0}
|
||||||
|
>
|
||||||
|
{isExpanded ? 'hide' : 'show'}
|
||||||
|
</button>
|
||||||
|
{ isExpanded ? <span>▲</span> : <span>▼</span>}
|
||||||
|
{' )'}
|
||||||
|
</h6>
|
||||||
|
|
||||||
|
<section
|
||||||
|
id={`${id}-panel`}
|
||||||
|
aria-labelledby={`${id}-header`}
|
||||||
|
hidden={!isExpanded}
|
||||||
|
>{children}</section>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const Demographics = () => {
|
const Demographics = () => {
|
||||||
|
const flags = useFlags();
|
||||||
|
|
||||||
const demographicSections = [
|
const demographicSections = [
|
||||||
{
|
{
|
||||||
title: `Racial Ethnographic`,
|
title: `Racial Ethnographic`,
|
||||||
|
@ -62,7 +103,18 @@ const Demographics = () => {
|
||||||
return (
|
return (
|
||||||
<div className={styles.demographicsContainer}>
|
<div className={styles.demographicsContainer}>
|
||||||
<div>Tract demographics</div>
|
<div>Tract demographics</div>
|
||||||
|
{'cdc' in flags ? (
|
||||||
|
<>
|
||||||
|
<J40AccordionItem id={'race'} title={`Racial Ethnographic`}>
|
||||||
|
{demographicItemGen(demographicsData.racial)}
|
||||||
|
</J40AccordionItem>
|
||||||
|
<J40AccordionItem id={'age'} title={`Age`}>
|
||||||
|
{demographicItemGen(demographicsData.age)}
|
||||||
|
</J40AccordionItem>
|
||||||
|
</>
|
||||||
|
) :
|
||||||
<Accordion items={demographicSections} multiselectable={true}/>
|
<Accordion items={demographicSections} multiselectable={true}/>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue