Skip to content

Commit 64a2829

Browse files
anaisbergSimonClo
authored andcommitted
♻️ extract add column button component
1 parent 3e2c81b commit 64a2829

File tree

2 files changed

+48
-48
lines changed

2 files changed

+48
-48
lines changed

src/frontend/apps/impress/src/features/docs/doc-editor/components/custom-blocks/DatabaseBlock.tsx

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
/* eslint-disable react-hooks/rules-of-hooks */
22
import { insertOrUpdateBlock } from '@blocknote/core';
33
import { createReactBlockSpec } from '@blocknote/react';
4-
import { Button, Input } from '@openfun/cunningham-react';
4+
import { Button } from '@openfun/cunningham-react';
55
import { ColDef } from 'ag-grid-community';
66
import { AgGridReact } from 'ag-grid-react';
77
import { TFunction } from 'i18next';
88
import React, { useRef, useState } from 'react';
99

10-
import { Box, DropButton, Icon, Text } from '@/components';
10+
import { Box, Icon } from '@/components';
1111

1212
import { DocsBlockNoteEditor } from '../../types';
1313
import { DatabaseSourceSelector } from '../DatabaseSourceSelector';
1414
import { DatabaseTableDisplay } from '../DatabaseTableDisplay';
1515

16+
import { AddButtonComponent } from './DatabaseBlock/AddColumnButton';
17+
1618
export const DatabaseBlock = createReactBlockSpec(
1719
{
1820
type: 'database',
@@ -40,52 +42,6 @@ export const DatabaseBlock = createReactBlockSpec(
4042
{ make: 'Toyota', model: 'Corolla', price: 29600, electric: false },
4143
];
4244

43-
const AddButtonComponent = ({
44-
isOpen,
45-
setIsOpen,
46-
}: {
47-
isOpen: boolean;
48-
setIsOpen: (open: boolean) => void;
49-
}) => {
50-
const onOpenChange = (isOpen: boolean) => {
51-
setIsOpen(isOpen);
52-
};
53-
54-
return (
55-
<DropButton
56-
isOpen={isOpen}
57-
onOpenChange={onOpenChange}
58-
label="add column"
59-
button={
60-
<Box style={{ padding: '0.25rem', gap: '16px' }} color="tertiary">
61-
<span className="material-icons">add</span>
62-
</Box>
63-
}
64-
>
65-
<Box style={{ padding: '10px', gap: '10px' }}>
66-
<Text
67-
$variation="600"
68-
$size="s"
69-
$weight="bold"
70-
$theme="greyscale"
71-
>
72-
Ajouter une colonne
73-
</Text>
74-
<Input label="Column label"></Input>
75-
<Button
76-
size="small"
77-
onClick={() => {
78-
setIsOpen(false);
79-
}}
80-
style={{ alignSelf: 'end', width: 'fit-content' }}
81-
>
82-
Valider
83-
</Button>
84-
</Box>
85-
</DropButton>
86-
);
87-
};
88-
8945
// Column Definitions: Defines the columns to be displayed.
9046
const colDefs: ColDef[] = [
9147
{ field: 'make', sort: 'desc' },
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { Button, Input } from '@openfun/cunningham-react';
2+
3+
import { Box, DropButton, Text } from '@/components';
4+
5+
export const AddButtonComponent = ({
6+
isOpen,
7+
setIsOpen,
8+
}: {
9+
isOpen: boolean;
10+
setIsOpen: (open: boolean) => void;
11+
}) => {
12+
const onOpenChange = (isOpen: boolean) => {
13+
setIsOpen(isOpen);
14+
};
15+
16+
return (
17+
<DropButton
18+
isOpen={isOpen}
19+
onOpenChange={onOpenChange}
20+
label="add column"
21+
button={
22+
<Box style={{ padding: '0.25rem', gap: '16px' }} color="tertiary">
23+
<span className="material-icons">add</span>
24+
</Box>
25+
}
26+
>
27+
<Box style={{ padding: '10px', gap: '10px' }}>
28+
<Text $variation="600" $size="s" $weight="bold" $theme="greyscale">
29+
Ajouter une colonne
30+
</Text>
31+
<Input label="Column label"></Input>
32+
<Button
33+
size="small"
34+
onClick={() => {
35+
setIsOpen(false);
36+
}}
37+
style={{ alignSelf: 'end', width: 'fit-content' }}
38+
>
39+
Valider
40+
</Button>
41+
</Box>
42+
</DropButton>
43+
);
44+
};

0 commit comments

Comments
 (0)