Skip to content

Commit

Permalink
feat: update impact component spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
benfurber committed Jan 8, 2025
1 parent 38cb7d0 commit 8dbd9f8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 16 deletions.
14 changes: 7 additions & 7 deletions src/pages/User/impact/ImpactField.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { impactQuestions } from 'src/pages/UserSettings/content/impactQuestions'
import { numberWithCommas } from 'src/utils/helpers'
import { Box, Text } from 'theme-ui'
import { Flex, Text } from 'theme-ui'

import { ImpactIcon } from './ImpactIcon'

Expand All @@ -17,10 +17,11 @@ export const ImpactField = ({ field }: Props) => {
if (!impactQuestion || !isVisible) return null

const sx = {
alignItems: 'center',
backgroundColor: 'background',
borderRadius: 1,
gap: 1,
padding: 1,
mt: 2,
}

const prefix = impactQuestion?.prefix || ''
Expand All @@ -29,10 +30,9 @@ export const ImpactField = ({ field }: Props) => {
const text = `${prefix} ${numberWithCommas(value)} ${suffix} ${label}`

return (
<Box sx={sx}>
<Text variant="label">
<ImpactIcon id={id} /> {text}
</Text>
</Box>
<Flex sx={sx}>
<ImpactIcon id={id} />
<Text variant="label">{text}</Text>
</Flex>
)
}
10 changes: 6 additions & 4 deletions src/pages/User/impact/ImpactItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { sortImpactYearDisplayFields } from 'src/pages/UserSettings/utils'
import { Box, Heading } from 'theme-ui'
import { Box, Flex, Heading } from 'theme-ui'

import { ImpactField } from './ImpactField'
import { ImpactMissing } from './ImpactMissing'
Expand Down Expand Up @@ -35,9 +35,11 @@ export const ImpactItem = ({ fields, user, year }: Props) => {
{year}
</Heading>
{visibleFields && visibleFields.length > 0 ? (
visibleFields.map((field, index) => {
return <ImpactField field={field} key={index} />
})
<Flex sx={{ flexDirection: 'column', gap: 2 }}>
{visibleFields.map((field, index) => {
return <ImpactField field={field} key={index} />
})}
</Flex>
) : (
<ImpactMissing
fields={fields}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const ImpactQuestionField = ({ field, formId }: Props) => {
name={`${field.id}.value`}
sx={{ background: 'white' }}
type="number"
formatOnBlur
/>
</Box>

Expand Down
1 change: 1 addition & 0 deletions src/pages/UserSettings/content/fields/ImpactYear.field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const ImpactYearField = (props: Props) => {
type="submit"
onClick={handleSubmit}
form={formId}
sx={{ alignSelf: 'start' }}
>
{buttons.impact.save}
</Button>
Expand Down
18 changes: 13 additions & 5 deletions src/pages/UserSettings/content/sections/ImpactYear.section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { observer } from 'mobx-react'
import { useCommonStores } from 'src/common/hooks/useCommonStores'
import { UserContactError } from 'src/pages/User/contact'
import { form } from 'src/pages/UserSettings/labels'
import { Box, Heading } from 'theme-ui'
import { Flex, Heading, Text } from 'theme-ui'

import {
sortImpactYearDisplayFields,
Expand All @@ -17,6 +17,7 @@ import { ImpactYearDisplayField } from '../fields/ImpactYearDisplay.field'

import type { IImpactYear, IImpactYearFieldList } from 'oa-shared'
import type { SubmitResults } from 'src/pages/User/contact/UserContactError'
import type { ThemeUIStyleObject } from 'theme-ui'

interface Props {
year: IImpactYear
Expand All @@ -37,9 +38,11 @@ export const ImpactYearSection = observer(({ year }: Props) => {
const sx = {
backgroundColor: 'background',
borderRadius: 2,
gap: 1,
marginBottom: 2,
padding: 2,
}
flexDirection: 'column',
} as ThemeUIStyleObject

useEffect(() => {
const fetchImpact = () => {
Expand Down Expand Up @@ -86,11 +89,16 @@ export const ImpactYearSection = observer(({ year }: Props) => {
}

return (
<Box sx={sx} id={`year_${year}`}>
<Flex sx={sx} id={`year_${year}`}>
<UserContactError submitResults={submitResults} />

<Heading as="h3" variant="small" ref={impactDivRef}>
{year}
</Heading>
<UserContactError submitResults={submitResults} />
<Text as="h4" variant="quiet" sx={{ marginBottom: 2 }}>
All fields optional
</Text>

<Form
id={formId}
initialValues={impact ? transformImpactData(impact) : undefined}
Expand All @@ -113,6 +121,6 @@ export const ImpactYearSection = observer(({ year }: Props) => {
)
}}
/>
</Box>
</Flex>
)
})

0 comments on commit 8dbd9f8

Please sign in to comment.