From f7d2e27a976907bacd75559710858844fbdaca77 Mon Sep 17 00:00:00 2001 From: Vim USDS Date: Tue, 26 Jul 2022 20:38:34 -0700 Subject: [PATCH] Add custom Accordion component to match designs --- .../Demographics/Demographics.module.scss | 17 +++++- .../Demographics.module.scss.d.ts | 2 + .../components/Demographics/Demographics.tsx | 60 +++++++++++++++++-- 3 files changed, 74 insertions(+), 5 deletions(-) diff --git a/client/src/components/Demographics/Demographics.module.scss b/client/src/components/Demographics/Demographics.module.scss index 4e79c5e1..6ac6ad4f 100644 --- a/client/src/components/Demographics/Demographics.module.scss +++ b/client/src/components/Demographics/Demographics.module.scss @@ -6,10 +6,25 @@ .demographicItem { display: flex; justify-content: space-between; - + span { font-size: .8rem; 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; + } } diff --git a/client/src/components/Demographics/Demographics.module.scss.d.ts b/client/src/components/Demographics/Demographics.module.scss.d.ts index f8ea8552..b29cdfa4 100644 --- a/client/src/components/Demographics/Demographics.module.scss.d.ts +++ b/client/src/components/Demographics/Demographics.module.scss.d.ts @@ -2,6 +2,8 @@ declare namespace DemographicsNamespace { export interface IDemographicsScss { demographicsContainer: string; demographicItem: string; + customDemographicItemToggle: string; + customDemographicHeading: string; } } diff --git a/client/src/components/Demographics/Demographics.tsx b/client/src/components/Demographics/Demographics.tsx index 1c7e9b95..c98042f6 100644 --- a/client/src/components/Demographics/Demographics.tsx +++ b/client/src/components/Demographics/Demographics.tsx @@ -1,16 +1,15 @@ -import React from 'react'; +import React, {useState} from 'react'; import {Accordion} from '@trussworks/react-uswds'; import * as styles from './Demographics.module.scss'; - -// export interface IDemographicsProps {} +import {useFlags} from '../../contexts/FlagContext'; type IDemographicsData = { racial: [string, number][], age: [string, number][] } -// Temporary while backend is developed +// Mock backend data const demographicsData:IDemographicsData = { racial: [ ['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[]) => { return demographicData.map((el, index) => { 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 ( + <> +
+ {title} + {' ( '} + + { isExpanded ? : } + {' )'} +
+ + + + ); +}; + const Demographics = () => { + const flags = useFlags(); + const demographicSections = [ { title: `Racial Ethnographic`, @@ -62,7 +103,18 @@ const Demographics = () => { return (
Tract demographics
+ {'cdc' in flags ? ( + <> + + {demographicItemGen(demographicsData.racial)} + + + {demographicItemGen(demographicsData.age)} + + + ) : + }
); };