-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathCommand.tsx
More file actions
58 lines (50 loc) · 1.26 KB
/
Command.tsx
File metadata and controls
58 lines (50 loc) · 1.26 KB
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
'use client';
import {CopyButton} from './CopyButton';
import React from 'react';
import {style} from '@react-spectrum/s2/style' with {type: 'macro'};
const container = style({
backgroundColor: 'layer-1',
marginY: 20,
borderRadius: 'xl',
display: 'flex',
flexDirection: 'column'
});
const codeWrap = style({
padding: 16
});
const codeContainer = style({
display: 'flex',
alignItems: 'center',
gap: 12,
padding: 4
});
const preStyle = style({
font: {default: 'code-xs', lg: 'code-sm'},
overflowX: 'auto',
paddingY: 8,
paddingX: 0,
margin: 0,
whiteSpace: 'pre',
flex: 1,
minWidth: 0
});
export interface CommandProps {
/** The command to display. */
command: string,
/** Optional label preceding the code block. */
label?: string
}
export function Command({command, label}: CommandProps) {
return (
<div className={container} data-example-switcher>
<div className={codeWrap}>
{label && <div className={style({font: 'body-sm', marginBottom: 8, color: 'body'})}>{label}</div>}
<div className={codeContainer}>
<pre className={preStyle}>{command}</pre>
<CopyButton ariaLabel="Copy command" tooltip="Copy command" text={command} />
</div>
</div>
</div>
);
}
export default Command;