mirror of
https://github.com/DOI-DO/j40-cejst-2.git
synced 2025-10-23 02:03:52 -07: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 *;
|
@use '../../styles/design-system.scss' as *;
|
||||||
|
|
||||||
.demographicsContainer{
|
.demographicsContainer{
|
||||||
@include u-padding(2);
|
padding: 1.2rem 1rem 0 1.2rem;
|
||||||
|
|
||||||
.demographicItem {
|
.demographicItem {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
@ -13,18 +13,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.customDemographicHeading {
|
.customDemographicHeading {
|
||||||
@include u-margin(1);
|
@include u-margin(1.5);
|
||||||
}
|
|
||||||
.customDemographicItemToggle {
|
|
||||||
//remove styling of button
|
|
||||||
border: none;
|
|
||||||
background-color: white;
|
|
||||||
|
|
||||||
//emulate a link
|
|
||||||
cursor:pointer;
|
|
||||||
color:blue;
|
|
||||||
text-decoration:underline;
|
|
||||||
|
|
||||||
min-width: 45px;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
import React, {useState} from 'react';
|
import React, {useState} from 'react';
|
||||||
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';
|
|
||||||
|
|
||||||
type IDemographicsData = {
|
type IDemographicsData = {
|
||||||
racial: [string, number][],
|
racial: [string, number][],
|
||||||
|
@ -54,57 +52,38 @@ interface IJ40AccordionItem {
|
||||||
const J40AccordionItem = ({id, title, children}:IJ40AccordionItem) => {
|
const J40AccordionItem = ({id, title, children}:IJ40AccordionItem) => {
|
||||||
const [isExpanded, setIsExpanded] = useState(false);
|
const [isExpanded, setIsExpanded] = useState(false);
|
||||||
return (
|
return (
|
||||||
|
|
||||||
<>
|
<>
|
||||||
<h6 className={styles.customDemographicHeading}>
|
<h6 className={styles.customDemographicHeading}>
|
||||||
{title}
|
{title}
|
||||||
{' ( '}
|
|
||||||
<button
|
<button
|
||||||
className={styles.customDemographicItemToggle}
|
id={`${id}-expand-control`}
|
||||||
id={`${id}-header`}
|
type="button"
|
||||||
aria-controls={`${id}-panel`}
|
className="usa-accordion__button usa-banner__button"
|
||||||
aria-expanded={isExpanded}
|
aria-expanded={isExpanded}
|
||||||
|
aria-controls={`${id}-expand-content`}
|
||||||
onClick={() => setIsExpanded(!isExpanded)}
|
onClick={() => setIsExpanded(!isExpanded)}
|
||||||
tabIndex={0}
|
|
||||||
>
|
>
|
||||||
{isExpanded ? 'hide' : 'show'}
|
<span className="usa-banner__button-text">{isExpanded ? `hide` : 'show'}</span>
|
||||||
</button>
|
</button>
|
||||||
{ isExpanded ? <span>▲</span> : <span>▼</span>}
|
|
||||||
{' )'}
|
|
||||||
</h6>
|
</h6>
|
||||||
|
|
||||||
<section
|
<div
|
||||||
id={`${id}-panel`}
|
id={`${id}-expand-content`}
|
||||||
aria-labelledby={`${id}-header`}
|
className="usa-banner__content usa-accordion__content"
|
||||||
|
aria-labelledby={`${id}-expand-control`}
|
||||||
hidden={!isExpanded}
|
hidden={!isExpanded}
|
||||||
>{children}</section>
|
>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const Demographics = () => {
|
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 (
|
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`}>
|
<J40AccordionItem id={'race'} title={`Racial Ethnographic`}>
|
||||||
{demographicItemGen(demographicsData.racial)}
|
{demographicItemGen(demographicsData.racial)}
|
||||||
|
@ -113,9 +92,6 @@ const Demographics = () => {
|
||||||
{demographicItemGen(demographicsData.age)}
|
{demographicItemGen(demographicsData.age)}
|
||||||
</J40AccordionItem>
|
</J40AccordionItem>
|
||||||
</>
|
</>
|
||||||
) :
|
|
||||||
<Accordion items={demographicSections} multiselectable={true}/>
|
|
||||||
}
|
|
||||||
</div>
|
</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
Add a link
Reference in a new issue