Skip to content
Snippets Groups Projects
Commit 752d5fc3 authored by Chris Beer's avatar Chris Beer
Browse files

Pull search hit styling up

parent 06ae0792
No related branches found
No related tags found
2 merge requests!19Draft: Merge video support into mui5,!18Only nudge over badge content for the WindowListButton; it needs special...
...@@ -67,14 +67,13 @@ describe('SearchHit', () => { ...@@ -67,14 +67,13 @@ describe('SearchHit', () => {
it('renders the annotationLabel if present', () => { it('renders the annotationLabel if present', () => {
render(<Subject annotationLabel="The Anno Label" />); render(<Subject annotationLabel="The Anno Label" />);
expect(screen.getAllByRole('heading', { level: 6 })).toHaveLength(2); expect(screen.getByRole('heading', { level: 4, name: 'The Anno Label' })).toBeInTheDocument();
expect(screen.getByRole('heading', { level: 6, name: 'The Anno Label' })).toHaveClass('MuiTypography-subtitle2');
}); });
it('does not render the typography if no annotation label is present', () => { it('does not render the typography if no annotation label is present', () => {
render(<Subject />); render(<Subject />);
expect(screen.getByRole('heading', { level: 6 })).toBeInTheDocument(); expect(screen.getByRole('heading', { level: 4 })).toBeInTheDocument();
}); });
}); });
......
...@@ -95,8 +95,8 @@ describe('SearchResults', () => { ...@@ -95,8 +95,8 @@ describe('SearchResults', () => {
searchHits: [], searchHits: [],
}); });
expect(screen.getByRole('heading', { level: 6, name: 'The Anno Label' })).toBeInTheDocument(); expect(screen.getByRole('heading', { level: 4, name: 'The Anno Label' })).toBeInTheDocument();
expect(screen.getByRole('heading', { level: 6, name: 'Annother Anno Label' })).toBeInTheDocument(); expect(screen.getByRole('heading', { level: 4, name: 'Annother Anno Label' })).toBeInTheDocument();
}); });
}); });
......
...@@ -5,10 +5,45 @@ import ListItem from '@mui/material/ListItem'; ...@@ -5,10 +5,45 @@ import ListItem from '@mui/material/ListItem';
import ListItemText from '@mui/material/ListItemText'; import ListItemText from '@mui/material/ListItemText';
import Typography from '@mui/material/Typography'; import Typography from '@mui/material/Typography';
import Chip from '@mui/material/Chip'; import Chip from '@mui/material/Chip';
import { styled } from '@mui/material/styles';
import SanitizedHtml from '../containers/SanitizedHtml'; import SanitizedHtml from '../containers/SanitizedHtml';
import TruncatedHit from '../lib/TruncatedHit'; import TruncatedHit from '../lib/TruncatedHit';
import { ScrollTo } from './ScrollTo'; import { ScrollTo } from './ScrollTo';
const Root = styled(ListItem, { name: 'SearchHit', slot: 'root' })(({ ownerState, theme }) => ({
'&.Mui-focused': {
'&:hover': {
...(ownerState.windowSelected && {
backgroundColor: 'inherit',
}),
},
...(ownerState.windowSelected && {
backgroundColor: 'inherit',
}),
},
paddingRight: theme.spacing(1),
}));
const CanvasLabel = styled('h4', { name: 'SearchHit', slot: 'canvasLabel' })(({ theme }) => ({
display: 'inline',
marginBottom: theme.spacing(1.5),
}));
const Counter = styled(Chip, { name: 'SearchHit', slot: 'counter' })(({ ownerState, theme }) => ({
// eslint-disable-next-line no-nested-ternary
backgroundColor: theme.palette.hitCounter.default,
...(ownerState.windowSelected && {
backgroundColor: theme.palette.highlights.primary,
}),
...(ownerState.adjacent && !ownerState.windowSelected && {
backgroundColor: theme.palette.highlights.secondary,
}),
height: 30,
marginRight: theme.spacing(1),
typography: 'subtitle2',
verticalAlign: 'inherit',
}));
/** */ /** */
export class SearchHit extends Component { export class SearchHit extends Component {
/** */ /** */
...@@ -93,6 +128,25 @@ export class SearchHit extends Component { ...@@ -93,6 +128,25 @@ export class SearchHit extends Component {
const truncatedHit = focused ? hit : hit && new TruncatedHit(hit, annotation); const truncatedHit = focused ? hit : hit && new TruncatedHit(hit, annotation);
const truncated = hit && (truncatedHit.before !== hit.before || truncatedHit.after !== hit.after); const truncated = hit && (truncatedHit.before !== hit.before || truncatedHit.after !== hit.after);
const canvasLabelHtmlId = `${companionWindowId}-${index}`; const canvasLabelHtmlId = `${companionWindowId}-${index}`;
const ownerState = {
adjacent, focused, selected, windowSelected,
};
const header = (
<>
<Counter
component="span"
ownerState={ownerState}
label={index + 1}
/>
<CanvasLabel id={canvasLabelHtmlId}>
{canvasLabel}
{annotationLabel && (
<Typography component="span" sx={{ display: 'block', marginTop: 1 }}>{annotationLabel}</Typography>
)}
</CanvasLabel>
</>
);
return ( return (
<ScrollTo <ScrollTo
...@@ -100,48 +154,21 @@ export class SearchHit extends Component { ...@@ -100,48 +154,21 @@ export class SearchHit extends Component {
offsetTop={96} // offset for the height of the form above offsetTop={96} // offset for the height of the form above
scrollTo={windowSelected && !focused} scrollTo={windowSelected && !focused}
> >
<ListItem <Root
ownerState={ownerState}
className={windowSelected ? 'windowSelected' : ''} className={windowSelected ? 'windowSelected' : ''}
sx={{
'&.Mui-focused': {
'&:hover': {
...(windowSelected && {
backgroundColor: 'inherit',
}),
},
...(windowSelected && {
backgroundColor: 'inherit',
}),
},
paddingRight: 1,
}}
divider divider
button={!selected} button={!selected}
component="li" component="li"
onClick={this.handleClick} onClick={this.handleClick}
selected={selected} selected={selected}
> >
<ListItemText primaryTypographyProps={{ variant: 'body1' }}> <ListItemText
<Typography variant="subtitle2" sx={{ marginBottom: 1.5 }}> primary={header}
<Chip primaryTypographyProps={{ component: 'div', sx: { marginBottom: 1 }, variant: 'subtitle2' }}
component="span" secondaryTypographyProps={{ variant: 'body1' }}
label={index + 1} secondary={(
sx={{ <>
// eslint-disable-next-line no-nested-ternary
backgroundColor: windowSelected ? 'highlights.primary' : adjacent ? 'highlights.secondary' : 'hitCounter.default',
height: 30,
marginRight: 1,
typography: 'subtitle2',
verticalAlign: 'inherit',
}}
/>
<span id={canvasLabelHtmlId}>
{canvasLabel}
</span>
</Typography>
{annotationLabel && (
<Typography variant="subtitle2">{annotationLabel}</Typography>
)}
{hit && ( {hit && (
<> <>
<SanitizedHtml ruleSet="iiif" htmlString={truncatedHit.before} /> <SanitizedHtml ruleSet="iiif" htmlString={truncatedHit.before} />
...@@ -173,8 +200,10 @@ export class SearchHit extends Component { ...@@ -173,8 +200,10 @@ export class SearchHit extends Component {
</> </>
)} )}
{!hit && annotation && <SanitizedHtml ruleSet="iiif" htmlString={annotation.chars} />} {!hit && annotation && <SanitizedHtml ruleSet="iiif" htmlString={annotation.chars} />}
</ListItemText> </>
</ListItem> )}
/>
</Root>
</ScrollTo> </ScrollTo>
); );
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment