Skip to content

Commit

Permalink
feat: add title and subtitle to data sets if set in display options
Browse files Browse the repository at this point in the history
  • Loading branch information
flaminic committed Oct 14, 2024
1 parent 3a3274b commit 005f130
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as DOMPurify from 'dompurify'
import PropTypes from 'prop-types'
import React from 'react'
import styles from './section.module.css'

export const SectionDescription = ({ children }) => {
export const SanitizedText = ({ children, className }) => {
if (!children) {
return null
}
Expand All @@ -12,13 +11,11 @@ export const SectionDescription = ({ children }) => {
})

return (
<div
className={styles.sectionDescription}
dangerouslySetInnerHTML={{ __html: html }}
></div>
<p className={className} dangerouslySetInnerHTML={{ __html: html }}></p>
)
}

SectionDescription.propTypes = {
SanitizedText.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
}
56 changes: 38 additions & 18 deletions src/data-workspace/section-form/section-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import PropTypes from 'prop-types'
import React from 'react'
import { useSectionFilter } from '../../shared/index.js'
import { getDisplayOptions } from './displayOptions.js'
import { SanitizedText } from './sanitized-text.js'
import { SectionFormSection } from './section.js'
import styles from './section.module.css'

Expand All @@ -15,28 +16,47 @@ export const SectionForm = ({ dataSet, globalFilterText }) => {

const displayOptions = getDisplayOptions(dataSet)

if (dataSet.renderAsTabs) {
return (
<TabbedSectionForm
globalFilterText={globalFilterText}
sections={dataSet.sections}
dataSetId={dataSet.id}
direction={displayOptions?.tabsDirection}
/>
)
}

return (
<>
{filteredSections.map((s) => (
<SectionFormSection
section={s}
dataSetId={dataSet.id}
key={s.id}
<div
className={cx(styles.sectionsCustomerText, {
[styles.textLeft]:
displayOptions.customText?.align === 'left',
[styles.textCenter]:
displayOptions.customText?.align === 'center',
[styles.textRight]:
displayOptions.customText?.align === 'right',
})}
>
{displayOptions.customText?.header && (
<SanitizedText className={styles.sectionsTitle}>
{displayOptions.customText?.header}
</SanitizedText>
)}
{displayOptions.customText?.subheader && (
<SanitizedText className={styles.sectionsSubtitle}>
{displayOptions.customText?.subheader}
</SanitizedText>
)}
</div>
{dataSet.renderAsTabs ? (
<TabbedSectionForm
globalFilterText={globalFilterText}
collapsible
sections={dataSet.sections}
dataSetId={dataSet.id}
direction={displayOptions?.tabsDirection}
/>
))}
) : (
filteredSections.map((s) => (
<SectionFormSection
section={s}
dataSetId={dataSet.id}
key={s.id}
globalFilterText={globalFilterText}
collapsible
/>
))
)}
</>
)
}
Expand Down
10 changes: 7 additions & 3 deletions src/data-workspace/section-form/section.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { PivotedCategoryComboTableBody } from '../category-combo-table-body-pivo
import { getFieldId } from '../get-field-id.js'
import { IndicatorsTableBody } from '../indicators-table-body/indicators-table-body.js'
import { getDisplayOptions } from './displayOptions.js'
import { SectionDescription } from './section-description.js'
import { SanitizedText } from './sanitized-text.js'
import styles from './section.module.css'

export function SectionFormSection({
Expand Down Expand Up @@ -97,7 +97,9 @@ export function SectionFormSection({

return (
<div>
<SectionDescription>{beforeSectionText}</SectionDescription>
<SanitizedText className={styles.sectionDescription}>
{beforeSectionText}
</SanitizedText>
<Table className={styles.table} suppressZebraStriping>
<TableHead>
<TableRowHead>
Expand Down Expand Up @@ -189,7 +191,9 @@ export function SectionFormSection({
/>
)}
</Table>
<SectionDescription>{afterSectionText}</SectionDescription>
<SanitizedText className={styles.sectionDescription}>
{afterSectionText}
</SanitizedText>
</div>
)
}
Expand Down
21 changes: 21 additions & 0 deletions src/data-workspace/section-form/section.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,30 @@
outline: 3px solid var(--theme-focus);
}

.sectionsTitle {
margin: 4px;
font-size: 2em;
}
.sectionsSubtitle{
margin: 2px;
font-size: 1.5em;
}
.sectionsCustomerText{
width: 100%;
padding: 16px;
}
.sectionTab {
margin-bottom: 8px;
}
.textLeft{
text-align: left;
}
.textCenter{
text-align: center;
}
.textRight{
text-align: right;
}

.verticalSectionTabWrapper .sectionTab div {
flex-direction: column;
Expand Down

0 comments on commit 005f130

Please sign in to comment.