Skip to content

Commit fbb44f7

Browse files
committed
use boxed row
1 parent b541363 commit fbb44f7

11 files changed

Lines changed: 43 additions & 85 deletions
1.24 MB
Loading

src/__screenshot_tests__/__fixtures__/file-upload-2.svg

Lines changed: 0 additions & 37 deletions
This file was deleted.
11.7 KB
Loading

src/__screenshot_tests__/__fixtures__/file-upload-3.svg

Lines changed: 0 additions & 5 deletions
This file was deleted.
84.4 KB
Loading
996 Bytes
Loading
Loading
Loading

src/__screenshot_tests__/file-upload-screenshot-test.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ test('FileUpload - upload multiple files and remove', async () => {
6464
// Upload first file
6565
const fileInput = await screen.findByLabelText('Drag or upload your file');
6666
const firstFixturePath = prepareFile(path.join(__dirname, '__fixtures__', 'file-upload-1.txt'));
67-
const secondFixturePath = prepareFile(path.join(__dirname, '__fixtures__', 'file-upload-2.svg'));
67+
const secondFixturePath = prepareFile(path.join(__dirname, '__fixtures__', 'file-upload-2.png'));
6868
await fileInput.uploadFile(firstFixturePath);
6969
await screen.findByText('file-upload-1.txt');
7070

@@ -73,7 +73,7 @@ test('FileUpload - upload multiple files and remove', async () => {
7373

7474
// Upload second file
7575
await fileInput.uploadFile(secondFixturePath);
76-
await screen.findByText('file-upload-2.svg');
76+
await screen.findByText('file-upload-2.png');
7777
await screen.findAllByRole('button', {name: /^Eliminar archivo/});
7878

7979
const imageWithTwoFiles = await fileUploader.screenshot();
@@ -82,7 +82,7 @@ test('FileUpload - upload multiple files and remove', async () => {
8282
// Remove one file
8383
const removeButtons = await screen.findAllByRole('button', {name: /^Eliminar archivo/});
8484
await removeButtons[0].click();
85-
await screen.findByText('file-upload-2.svg');
85+
await screen.findByText('file-upload-2.png');
8686
await expect(screen.findByText('file-upload-1.txt')).rejects.toThrow();
8787

8888
const imageAfterRemoval = await fileUploader.screenshot();
@@ -97,14 +97,13 @@ test('FileUpload - custom gallery', async () => {
9797

9898
const fileUploader = await screen.findByTestId('FileUpload');
9999
const fileInput = await screen.findByLabelText('Gallery');
100-
const firstFixturePath = prepareFile(path.join(__dirname, '__fixtures__', 'file-upload-2.svg'));
101-
const secondFixturePath = prepareFile(path.join(__dirname, '__fixtures__', 'file-upload-3.svg'));
100+
const firstFixturePath = prepareFile(path.join(__dirname, '__fixtures__', 'file-upload-2.png'));
101+
const secondFixturePath = prepareFile(path.join(__dirname, '__fixtures__', 'file-upload-3.png'));
102102

103103
await fileInput.uploadFile(firstFixturePath);
104-
await screen.findByLabelText('Remove file-upload-2.svg');
105-
104+
await screen.findByLabelText('Remove file-upload-2.png');
106105
await fileInput.uploadFile(secondFixturePath);
107-
await screen.findByLabelText('Remove file-upload-3.svg');
106+
await screen.findByLabelText('Remove file-upload-3.png');
108107

109108
const image = await fileUploader.screenshot();
110109
expect(image).toMatchImageSnapshot();

src/file-upload.tsx

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ import {Text1, Text2, Text3} from './text';
66
import Inline from './inline';
77
import IconWarningRegular from './generated/mistica-icons/icon-warning-regular';
88
import {vars as skinVars} from './skins/skin-contract.css';
9-
import {Boxed} from './boxed';
109
import Box from './box';
1110
import {useInnerText, useTheme} from './hooks';
1211
import * as textTokens from './text-tokens';
13-
import {IconButton} from './icon-button';
1412
import Image from './image';
1513
import IconCloseRegular from './generated/mistica-icons/icon-close-regular';
1614
import IconFilePdfRegular from './generated/mistica-icons/icon-file-pdf-regular';
@@ -32,6 +30,7 @@ import IconClipRegular from './generated/mistica-icons/icon-clip-regular';
3230
import * as styles from './file-upload.css';
3331
import {useThemeVariant} from './theme-variant-context';
3432
import {getPrefixedDataAttributes} from './utils/dom';
33+
import {BoxedRow, BoxedRowList} from './list';
3534

3635
import type {DataAttributes, IconProps} from './utils/types';
3736
import type {ExclusifyUnion} from './utils/utility-types';
@@ -349,40 +348,28 @@ const useFileUpload = ({
349348
type FileItemProps = {
350349
file: File;
351350
onRemove: (file: File) => void;
352-
formatSize?: (sizeInBytes: number) => string;
353351
removeLabel?: string;
354352
};
355353

356354
export const FileItem = ({file, onRemove, removeLabel}: FileItemProps): JSX.Element => {
357355
const {i18n, t, texts} = useTheme();
358356

359357
return (
360-
<Boxed>
361-
<Box paddingX={8} paddingY={16}>
362-
<Inline space="between" alignItems="center">
363-
<Inline space={8} alignItems="center">
364-
<FileIcon file={file} />
365-
<Text2 regular>{file.name}</Text2>
366-
</Inline>
367-
<Inline space={16} alignItems="center">
368-
<Text2 regular color={skinVars.colors.textSecondary}>
369-
{formatSize(file.size, i18n.locale)}
370-
</Text2>
371-
<IconButton
372-
Icon={IconCloseRegular}
373-
type="neutral"
374-
small
375-
onPress={() => onRemove(file)}
376-
aria-label={
377-
removeLabel ??
378-
texts.fileUploadRemoveFile ??
379-
t(textTokens.fileUploadRemoveFile, file.name)
380-
}
381-
/>
382-
</Inline>
383-
</Inline>
384-
</Box>
385-
</Boxed>
358+
<BoxedRow
359+
title={file.name}
360+
asset={<FileIcon file={file} />}
361+
detail={formatSize(file.size, i18n.locale)}
362+
iconButton={{
363+
type: 'neutral',
364+
Icon: IconCloseRegular,
365+
small: true,
366+
onPress: () => onRemove(file),
367+
'aria-label':
368+
removeLabel ??
369+
texts.fileUploadRemoveFile ??
370+
t(textTokens.fileUploadRemoveFile, file.name),
371+
}}
372+
/>
386373
);
387374
};
388375

@@ -610,15 +597,13 @@ const FileUpload = (props: Props): JSX.Element => {
610597
? renderFiles({files, removeFile})
611598
: files &&
612599
files.length > 0 && (
613-
<Stack
614-
space={8}
615-
role="list"
600+
<BoxedRowList
616601
aria-label={texts.fileUploadListLabel ?? t(textTokens.fileUploadListLabel)}
617602
>
618603
{Array.from(files).map((file, index) => (
619604
<FileItem key={index} file={file} onRemove={removeFile} />
620605
))}
621-
</Stack>
606+
</BoxedRowList>
622607
)}
623608
</Stack>
624609
);

0 commit comments

Comments
 (0)