Skip to content

Commit abe7702

Browse files
author
Shawn
authored
Merge pull request #17 from input-output-hk/fix-file-upload-onremove
fix: on remove triggering file upload click and label changes
2 parents 725dda0 + e3a1375 commit abe7702

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

src/design-system/file-upload/file-upload.component.tsx

+17-13
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,35 @@ import * as cx from './file-upload.css';
1313
import type { OmitClassName } from '../../types';
1414

1515
type Props = OmitClassName<'input'> & {
16-
label: { text: string; highlight: boolean }[];
16+
label: string | React.ReactNode;
1717
supportedFormats: string;
1818
files?: string[];
1919
removeButtonLabel: string;
20+
key?: string;
2021
onRemove?: (file: string, index: number) => void;
2122
};
2223

2324
export const FileUpload = ({
24-
label: labelText,
25+
label,
2526
supportedFormats,
2627
id = crypto.randomUUID(),
2728
accept,
2829
files = [],
2930
removeButtonLabel,
31+
key = 'file-upload',
3032
onRemove,
3133
...props
3234
}: Readonly<Props>): JSX.Element => (
3335
<label htmlFor={id} className={cx.root} id={`${id}-label`}>
34-
<input type="file" id={id} accept={accept} required hidden {...props} />
36+
<input
37+
type="file"
38+
id={id}
39+
accept={accept}
40+
required
41+
hidden
42+
key={key}
43+
{...props}
44+
/>
3545
<Flex
3646
className={cx.iconBox}
3747
mr="$24"
@@ -43,15 +53,7 @@ export const FileUpload = ({
4353
<Box w="$fill">
4454
<Box>
4555
<Box mb="$8">
46-
{labelText.map(({ text, highlight }) => (
47-
<Text.Body.Normal
48-
weight="$medium"
49-
color={highlight ? 'highlight' : 'primary'}
50-
key={text}
51-
>
52-
{text}{' '}
53-
</Text.Body.Normal>
54-
))}
56+
<Text.Body.Normal weight="$medium">{label}</Text.Body.Normal>
5557
</Box>
5658
<Text.Body.Small color="secondary" weight="$medium">
5759
{supportedFormats}
@@ -70,8 +72,10 @@ export const FileUpload = ({
7072
</Flex>
7173
<button
7274
className={cx.removeButtonBox}
73-
onClick={(): void => {
75+
onClick={(event): void => {
7476
if (onRemove) {
77+
event.preventDefault();
78+
event.stopPropagation();
7579
onRemove(file, index);
7680
}
7781
}}

src/design-system/file-upload/file-upload.css.ts

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export const checkIconBox = style([
4848
h: '$24',
4949
fontSize: '$25',
5050
color: '$data_green',
51+
lineHeight: '$0',
5152
}),
5253
]);
5354

src/design-system/file-upload/file-upload.stories.tsx

+1-7
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ export default {
1818
decorators: [page({ title: 'File Upload', subtitle })],
1919
} as Meta;
2020

21-
const label = [
22-
{ text: 'Drag & drop or', highlight: false },
23-
{ text: 'choose file', highlight: true },
24-
{ text: 'to upload', highlight: false },
25-
];
26-
2721
const supportedFormats = 'Supported formats: JSON';
2822

2923
const removeButtonLabel = 'Remove';
@@ -33,7 +27,7 @@ const RenderFileUpload = ({
3327
files,
3428
}: Readonly<{ id?: string; files?: string[] }>): JSX.Element => (
3529
<FileUpload
36-
label={label}
30+
label="Drag & drop or choose file to upload"
3731
supportedFormats={supportedFormats}
3832
removeButtonLabel={removeButtonLabel}
3933
id={id}

src/design-tokens/typography.data.ts

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const fontSizes = {
1717
} as const;
1818

1919
export const lineHeights = {
20+
$0: '0',
2021
$16: '16px',
2122
$17: '17px',
2223
$24: '24px',

0 commit comments

Comments
 (0)