-
Notifications
You must be signed in to change notification settings - Fork 69
/
Declaration.tsx
41 lines (36 loc) · 1.31 KB
/
Declaration.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
import React from 'react';
import PropTypes from 'prop-types';
import { colorCSSDeclaration, containsCSSVariable } from './utils';
export default function CSSDeclaration({ declaration, handleMouseEnter, handleMouseLeave }: DeclarationData) {
const [attribute, value, importantFlag] = declaration.split(/:|!/);
if (containsCSSVariable(value)) {
return (
<code style={{ fontSize: '14px' }} key={declaration} className="mb-0 text-muted">
<span>{attribute}: </span>
<span
onMouseEnter={(e: React.MouseEvent) => handleMouseEnter(e, declaration)}
onMouseLeave={() => handleMouseLeave()}
style={{ cursor: 'pointer', textDecoration: 'underline dotted' }}
>
{colorCSSDeclaration(value.trim())}
</span>
{importantFlag && <span> !important;</span>}
</code>
);
}
return (
<code style={{ fontSize: '14px' }} key={declaration} className="mb-0 text-muted">
{colorCSSDeclaration(declaration)}
</code>
);
}
interface DeclarationData {
declaration: string,
handleMouseEnter: (e: React.MouseEvent, declaration: string) => void,
handleMouseLeave: () => void,
}
CSSDeclaration.propTypes = {
declaration: PropTypes.string.isRequired,
handleMouseEnter: PropTypes.func.isRequired,
handleMouseLeave: PropTypes.func.isRequired,
};