forked from openedx/frontend-app-authoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlockCardButton.tsx
More file actions
82 lines (77 loc) · 1.93 KB
/
BlockCardButton.tsx
File metadata and controls
82 lines (77 loc) · 1.93 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import React from 'react';
import {
Button,
Chip,
Collapsible,
Icon,
Stack,
} from '@openedx/paragon';
import { getItemIcon } from '../block-type-utils';
export type BlockTemplate = {
displayName: string;
boilerplateName: string;
};
export interface BlockCardButtonProps {
name: string;
blockType: string;
onClick: () => void;
disabled?: boolean;
templates?: BlockTemplate[];
onClickTemplate?: (boilerplateName: string) => void;
actionIcon?: React.ReactElement;
}
/**
* Renders a Card button with icon, name and templates of a block type
*/
export const BlockCardButton = ({
name,
blockType,
onClick,
templates,
disabled = false,
onClickTemplate,
actionIcon,
}: BlockCardButtonProps) => {
const titleComponent = (
<Stack direction="horizontal" gap={3}>
<span className={`icon-with-border icon-with-border-${blockType} p-2 rounded`}>
<Icon size="lg" src={getItemIcon(blockType)} />
</span>
<span className="text-primary-700">
{name}
</span>
</Stack>
);
if (templates?.length) {
return (
<div data-testid={`${blockType}-collapsible`}>
<Collapsible
styling="card-lg"
className="mx-n2 font-weight-bold shadow-sm pl-1 rounded"
title={titleComponent}
>
<Stack direction="horizontal" className="d-flex flex-wrap" gap={2}>
{templates.map((template) => (
<Chip onClick={() => onClickTemplate?.(template.boilerplateName)} key={template.boilerplateName}>
{template.displayName}
</Chip>
))}
</Stack>
</Collapsible>
</div>
);
}
return (
<Button
variant="tertiary"
className="mx-n2 shadow-sm border justify-content-between pl-4 font-weight-bold"
onClick={onClick}
disabled={disabled}
>
{titleComponent}
<div className="mr-1">
{actionIcon}
</div>
</Button>
);
};