-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathExampleOutput.tsx
More file actions
58 lines (54 loc) · 1.62 KB
/
ExampleOutput.tsx
File metadata and controls
58 lines (54 loc) · 1.62 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 {cloneElement, createElement, isValidElement} from 'react';
import {style} from '@react-spectrum/s2/style' with {type: 'macro'};
interface ExampleOutputProps {
component?: any,
props?: Record<string, any>,
align?: 'start' | 'center' | 'end',
orientation?: 'horizontal' | 'vertical'
}
export function ExampleOutput({component, props = {}, align = 'center', orientation = 'horizontal'}: ExampleOutputProps) {
return (
<div
role="group"
aria-label="Rendered component"
className={style({
display: 'flex',
flexDirection: {
orientation: {
horizontal: 'column',
vertical: 'row'
}
},
justifyContent: {
align: {
center: 'center',
start: 'start',
end: 'end'
}
},
alignItems: 'center',
width: 'full',
overflow: 'auto',
gridArea: 'example',
borderRadius: 'lg',
font: 'ui',
padding: {
default: 12,
lg: 24
},
boxSizing: 'border-box'
})({align, orientation})}
style={{background: getBackgroundColor(props.staticColor || (props.isOverBackground ? 'white' : undefined))}}>
{isValidElement(component) ? cloneElement(component, props) : createElement(component, props)}
</div>
);
}
function getBackgroundColor(staticColor: 'black' | 'white' | undefined) {
if (staticColor === 'black') {
return 'linear-gradient(to right,#ddd6fe,#fbcfe8)';
} else if (staticColor === 'white') {
return 'linear-gradient(to right,#0f172a,#334155)';
}
return undefined;
}