forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Highlighter.tsx
94 lines (93 loc) · 2.5 KB
/
Highlighter.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import * as React from 'react';
import ButtonBase, { ButtonBaseProps } from '@mui/material/ButtonBase';
export default function Highlighter({
disableBorder = false,
selected = false,
selectedBg = 'white',
sx,
...props
}: {
disableBorder?: boolean;
selectedBg?: 'white' | 'comfort';
selected?: boolean;
} & ButtonBaseProps) {
const lightSelectedBg = {
white: '#fff',
comfort: 'grey.50',
};
const ref = React.useRef<null | HTMLButtonElement>(null);
return (
<ButtonBase
ref={ref}
{...props}
onClick={(event) => {
if (ref.current) {
ref.current.scrollIntoView({ block: 'nearest' });
}
if (props.onClick) {
props.onClick(event);
}
}}
onFocusVisible={(event) => {
if (ref.current) {
ref.current.scrollIntoView({ block: 'nearest' });
}
if (props.onFocusVisible) {
props.onFocusVisible(event);
}
}}
sx={[
(theme) => ({
justifyContent: 'flex-start',
textAlign: 'left',
alignItems: 'center',
borderRadius: 1,
height: '100%',
border: '1px solid transparent',
transitionProperty: 'all',
transitionDuration: '150ms',
color: 'primary.300',
...((!disableBorder || selected) && {
borderColor: 'grey.200',
}),
...(selected && {
bgcolor: lightSelectedBg[selectedBg],
borderColor: 'grey.200',
color: 'primary.500',
}),
...(!selected && {
'&:hover, &:focus': {
bgcolor: 'grey.100',
'@media (hover: none)': {
bgcolor: 'transparent',
},
},
}),
...theme.applyDarkStyles({
color: 'primary.800',
...((!disableBorder || selected) && {
borderColor: 'primaryDark.500',
}),
...(selected && {
bgcolor: 'primaryDark.700',
borderColor: 'primaryDark.300',
color: 'primary.300',
}),
...(!selected && {
'&:hover, &:focus': {
bgcolor: 'primaryDark.800',
'@media (hover: none)': {
bgcolor: 'transparent',
},
},
}),
}),
'&.Mui-disabled': {
opacity: 0.4,
},
}),
...(Array.isArray(sx) ? sx : [sx]),
]}
/>
);
}