mirror of
https://github.com/DOI-DO/j40-cejst-2.git
synced 2025-02-22 17:44:20 -08:00
Add USWDS expand to demographics side panel
This commit is contained in:
parent
96f6536b24
commit
504181d809
12 changed files with 121 additions and 59 deletions
|
@ -1,7 +1,7 @@
|
|||
@use '../../styles/design-system.scss' as *;
|
||||
|
||||
.demographicsContainer{
|
||||
@include u-padding(2);
|
||||
padding: 1.2rem 1rem 0 1.2rem;
|
||||
|
||||
.demographicItem {
|
||||
display: flex;
|
||||
|
@ -13,18 +13,6 @@
|
|||
}
|
||||
}
|
||||
.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;
|
||||
@include u-margin(1.5);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
import React, {useState} from 'react';
|
||||
import {Accordion} from '@trussworks/react-uswds';
|
||||
|
||||
import * as styles from './Demographics.module.scss';
|
||||
import {useFlags} from '../../contexts/FlagContext';
|
||||
|
||||
type IDemographicsData = {
|
||||
racial: [string, number][],
|
||||
|
@ -54,68 +52,46 @@ interface IJ40AccordionItem {
|
|||
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`}
|
||||
id={`${id}-expand-control`}
|
||||
type="button"
|
||||
className="usa-accordion__button usa-banner__button"
|
||||
aria-expanded={isExpanded}
|
||||
aria-controls={`${id}-expand-content`}
|
||||
onClick={() => setIsExpanded(!isExpanded)}
|
||||
tabIndex={0}
|
||||
>
|
||||
{isExpanded ? 'hide' : 'show'}
|
||||
<span className="usa-banner__button-text">{isExpanded ? `hide` : 'show'}</span>
|
||||
</button>
|
||||
{ isExpanded ? <span>▲</span> : <span>▼</span>}
|
||||
{' )'}
|
||||
</h6>
|
||||
|
||||
<section
|
||||
id={`${id}-panel`}
|
||||
aria-labelledby={`${id}-header`}
|
||||
<div
|
||||
id={`${id}-expand-content`}
|
||||
className="usa-banner__content usa-accordion__content"
|
||||
aria-labelledby={`${id}-expand-control`}
|
||||
hidden={!isExpanded}
|
||||
>{children}</section>
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const Demographics = () => {
|
||||
const flags = useFlags();
|
||||
|
||||
const demographicSections = [
|
||||
{
|
||||
title: `Racial Ethnographic`,
|
||||
content: demographicItemGen(demographicsData.racial),
|
||||
expanded: false,
|
||||
id: '123',
|
||||
headingLevel: 'h4',
|
||||
},
|
||||
{
|
||||
title: `Age`,
|
||||
content: demographicItemGen(demographicsData.age),
|
||||
expanded: false,
|
||||
id: 'abc',
|
||||
headingLevel: 'h4',
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<div className={styles.demographicsContainer}>
|
||||
<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}/>
|
||||
}
|
||||
<>
|
||||
<J40AccordionItem id={'race'} title={`Racial Ethnographic`}>
|
||||
{demographicItemGen(demographicsData.racial)}
|
||||
</J40AccordionItem>
|
||||
<J40AccordionItem id={'age'} title={`Age`}>
|
||||
{demographicItemGen(demographicsData.age)}
|
||||
</J40AccordionItem>
|
||||
</>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
@use '../../styles/design-system.scss' as *;
|
||||
|
||||
.tractDemographicsContainer{
|
||||
|
||||
}
|
12
client/src/components/TractDemographics/TractDemographics.module.scss.d.ts
vendored
Normal file
12
client/src/components/TractDemographics/TractDemographics.module.scss.d.ts
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
declare namespace TractDemographicsNamespace {
|
||||
export interface ITractDemographicsScss {
|
||||
tractDemographicsContainer: string;
|
||||
}
|
||||
}
|
||||
|
||||
declare const TractDemographicsScssModule: TractDemographicsNamespace.ITractDemographicsScss & {
|
||||
/** WARNING: Only available when "css-loader" is used without "style-loader" or "mini-css-extract-plugin" */
|
||||
locals: TractDemographicsNamespace.ITractDemographicsScss;
|
||||
};
|
||||
|
||||
export = TractDemographicsScssModule;
|
|
@ -0,0 +1,15 @@
|
|||
import React from 'react';
|
||||
import { render } from '@testing-library/react';
|
||||
import {LocalizedComponent} from '../../test/testHelpers';
|
||||
import TractDemographics from './TractDemographics';
|
||||
|
||||
describe('rendering of TractDemographics Component', () => {
|
||||
const {asFragment} = render(
|
||||
<LocalizedComponent>
|
||||
<TractDemographics />
|
||||
</LocalizedComponent>,
|
||||
);
|
||||
it('checks if component renders', () => {
|
||||
expect(asFragment()).toMatchSnapshot();
|
||||
});
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
import React from 'react';
|
||||
|
||||
import * as styles from './TractDemographics.module.scss';
|
||||
|
||||
export interface ITractDemographicsProps {}
|
||||
|
||||
const TractDemographics = ({}: ITractDemographicsProps) => {
|
||||
return (
|
||||
<div className={styles.tractDemographicsContainer}>
|
||||
Hello 👋, I am a TractDemographics component.
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default TractDemographics;
|
2
client/src/components/TractDemographics/index.ts
Normal file
2
client/src/components/TractDemographics/index.ts
Normal file
|
@ -0,0 +1,2 @@
|
|||
import TractDemographics from './TractDemographics';
|
||||
export default TractDemographics;
|
5
client/src/components/TractInfo/TractInfo.module.scss
Normal file
5
client/src/components/TractInfo/TractInfo.module.scss
Normal file
|
@ -0,0 +1,5 @@
|
|||
@use '../../styles/design-system.scss' as *;
|
||||
|
||||
.tractInfoContainer{
|
||||
|
||||
}
|
12
client/src/components/TractInfo/TractInfo.module.scss.d.ts
vendored
Normal file
12
client/src/components/TractInfo/TractInfo.module.scss.d.ts
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
declare namespace TractInfoNamespace {
|
||||
export interface ITractInfoScss {
|
||||
tractInfoContainer: string;
|
||||
}
|
||||
}
|
||||
|
||||
declare const TractInfoScssModule: TractInfoNamespace.ITractInfoScss & {
|
||||
/** WARNING: Only available when "css-loader" is used without "style-loader" or "mini-css-extract-plugin" */
|
||||
locals: TractInfoNamespace.ITractInfoScss;
|
||||
};
|
||||
|
||||
export = TractInfoScssModule;
|
15
client/src/components/TractInfo/TractInfo.test.tsx
Normal file
15
client/src/components/TractInfo/TractInfo.test.tsx
Normal file
|
@ -0,0 +1,15 @@
|
|||
import React from 'react';
|
||||
import { render } from '@testing-library/react';
|
||||
import {LocalizedComponent} from '../../test/testHelpers';
|
||||
import TractInfo from './TractInfo';
|
||||
|
||||
describe('rendering of TractInfo Component', () => {
|
||||
const {asFragment} = render(
|
||||
<LocalizedComponent>
|
||||
<TractInfo />
|
||||
</LocalizedComponent>,
|
||||
);
|
||||
it('checks if component renders', () => {
|
||||
expect(asFragment()).toMatchSnapshot();
|
||||
});
|
||||
});
|
15
client/src/components/TractInfo/TractInfo.tsx
Normal file
15
client/src/components/TractInfo/TractInfo.tsx
Normal file
|
@ -0,0 +1,15 @@
|
|||
import React from 'react';
|
||||
|
||||
import * as styles from './TractInfo.module.scss';
|
||||
|
||||
export interface ITractInfoProps {}
|
||||
|
||||
const TractInfo = ({}: ITractInfoProps) => {
|
||||
return (
|
||||
<div className={styles.tractInfoContainer}>
|
||||
Hello 👋, I am a TractInfo component.
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default TractInfo;
|
2
client/src/components/TractInfo/index.ts
Normal file
2
client/src/components/TractInfo/index.ts
Normal file
|
@ -0,0 +1,2 @@
|
|||
import TractInfo from './TractInfo';
|
||||
export default TractInfo;
|
Loading…
Add table
Reference in a new issue