forked from badges/shields
-
Notifications
You must be signed in to change notification settings - Fork 1
/
snippet.js
46 lines (39 loc) · 1010 Bytes
/
snippet.js
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
import React from 'react'
import PropTypes from 'prop-types'
import ClickToSelect from '@mapbox/react-click-to-select'
import styled, { css } from 'styled-components'
const CodeContainer = styled.span`
position: relative;
vertical-align: middle;
display: inline-block;
${({ truncate }) =>
truncate &&
css`
max-width: 40%;
overflow: hidden;
text-overflow: ellipsis;
`};
`
export const StyledCode = styled.code`
line-height: 1.2em;
padding: 0.1em 0.3em;
border-radius: 4px;
background: #eef;
font-family: Lekton;
font-size: ${({ fontSize }) => fontSize};
white-space: nowrap;
`
export function Snippet({ snippet, truncate = false, fontSize }) {
return (
<CodeContainer truncate={truncate}>
<ClickToSelect>
<StyledCode fontSize={fontSize}>{snippet}</StyledCode>
</ClickToSelect>
</CodeContainer>
)
}
Snippet.propTypes = {
snippet: PropTypes.string.isRequired,
truncate: PropTypes.bool,
fontSize: PropTypes.string,
}