Skip to content

Commit 83797ac

Browse files
committed
Dedup FTV HelpTip trigger, drop the non-working wrap-fix style
The two branches of the FTV sentence (scored vs not-enough-data) each rendered an identical HelpTip trigger; hoisted it to one ftvHelpTipTrigger element and reused it, and split the ternary into two ftvPassCount checks. Also dropped WRAPPING_HOVER_BTN_STYLE — it didn't actually fix wrapping in practice, so the "the 4 recent statewide elections" trigger now just uses the plain shared HOVER_BTN_STYLE like the others.
1 parent 53cfa59 commit 83797ac

1 file changed

Lines changed: 16 additions & 25 deletions

File tree

app/src/app/components/EvalPanel/PartisanSection.tsx

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,6 @@ const METRIC_CUTOFF = {
3939

4040
const MAX_ALPHA = 0.6;
4141

42-
// Overrides the browser default button style (inline-block, nowrap) so a
43-
// multi-word trigger like "the 4 recent statewide elections" wraps with the
44-
// surrounding paragraph instead of staying on one line.
45-
const WRAPPING_HOVER_BTN_STYLE: React.CSSProperties = {
46-
...HOVER_BTN_STYLE,
47-
display: 'inline',
48-
whiteSpace: 'normal',
49-
};
50-
5142
// Highlights a Disproportionality cell in either table above/below while the "4 recent
5243
// statewide elections" trigger is hovered, so the reader can see exactly which rows the
5344
// FTV verdict sentence is talking about.
@@ -129,6 +120,16 @@ export const PartisanSection: React.FC<PartisanSectionProps> = ({evaluation}) =>
129120
const isFtvHighlighted = (key: string) =>
130121
(ftvHover && !!ftvKeySet?.has(key)) || (ftvPassHover && !!ftvPassingKeys?.has(key));
131122

123+
// Shared between both branches of the FTV sentence below (scored and
124+
// not-enough-data) so the HelpTip trigger isn't duplicated.
125+
const ftvHelpTipTrigger = (
126+
<HelpTip tip="freedomToVoteTest" openDelay={HELP_TIP_FAST_DELAY}>
127+
<button type="button" style={HOVER_BTN_STYLE}>
128+
Freedom-To-Vote test
129+
</button>
130+
</HelpTip>
131+
);
132+
132133
const avgSeatSkew =
133134
n > 0 && evaluation.disproportionality && numDistricts !== null
134135
? elections.reduce((sum, key) => {
@@ -315,29 +316,19 @@ export const PartisanSection: React.FC<PartisanSectionProps> = ({evaluation}) =>
315316
<Text size="2" mb="3" as="p">
316317
The following scores can all be found in the political science literature, but are
317318
not necessarily endorsed by leading scholars at this time.{' '}
318-
{ftvPassCount === null ? (
319+
{ftvPassCount === null && (
319320
<>
320321
Not enough recent Presidential and Senate election data is available to score
321-
this plan against the{' '}
322-
<HelpTip tip="freedomToVoteTest" openDelay={HELP_TIP_FAST_DELAY}>
323-
<button type="button" style={HOVER_BTN_STYLE}>
324-
Freedom-To-Vote test
325-
</button>
326-
</HelpTip>
327-
.
322+
this plan against the {ftvHelpTipTrigger}.
328323
</>
329-
) : (
324+
)}
325+
{ftvPassCount !== null && (
330326
<>
331327
This plan <strong>{ftvOverallPass ? 'passes' : 'does not pass'}</strong> the{' '}
332-
<HelpTip tip="freedomToVoteTest" openDelay={HELP_TIP_FAST_DELAY}>
333-
<button type="button" style={HOVER_BTN_STYLE}>
334-
Freedom-To-Vote test
335-
</button>
336-
</HelpTip>
337-
: among{' '}
328+
{ftvHelpTipTrigger}: among{' '}
338329
<button
339330
type="button"
340-
style={WRAPPING_HOVER_BTN_STYLE}
331+
style={HOVER_BTN_STYLE}
341332
onMouseEnter={() => setFtvHover(true)}
342333
onMouseLeave={() => setFtvHover(false)}
343334
onFocus={() => setFtvHover(true)}

0 commit comments

Comments
 (0)