forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOfficialTemplate.tsx
More file actions
43 lines (39 loc) · 1.01 KB
/
OfficialTemplate.tsx
File metadata and controls
43 lines (39 loc) · 1.01 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
import React, { useCallback } from 'react';
import { Template } from '../../types/index';
import getIcon from '../../templates/icons';
import { ENTER } from '../../utils/keycodes';
import { Button, IconContainer, Title } from './elements';
interface IOfficialTemplateProps {
template: Template;
selectTemplate: (t: Template) => void;
small: boolean;
}
export const OfficialTemplate = ({
template,
selectTemplate,
small,
}: IOfficialTemplateProps) => {
const Icon = getIcon(template.name);
const select = useCallback(() => {
selectTemplate(template);
}, [selectTemplate, template]);
return (
<Button
onClick={select}
color={template.color}
onKeyDown={e => {
if (e.keyCode === ENTER) {
select();
}
}}
tabIndex={0}
>
<IconContainer>
<Icon width={small ? 24 : 32} height={small ? 24 : 32} />
</IconContainer>
<div style={{ width: '100%' }}>
<Title>{template.niceName}</Title>
</div>
</Button>
);
};