Skip to content

fix: on remove triggering file upload click and label changes #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions src/design-system/file-upload/file-upload.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,35 @@ import * as cx from './file-upload.css';
import type { OmitClassName } from '../../types';

type Props = OmitClassName<'input'> & {
label: { text: string; highlight: boolean }[];
label: string | React.ReactNode;
supportedFormats: string;
files?: string[];
removeButtonLabel: string;
key?: string;
onRemove?: (file: string, index: number) => void;
};

export const FileUpload = ({
label: labelText,
label,
supportedFormats,
id = crypto.randomUUID(),
accept,
files = [],
removeButtonLabel,
key = 'file-upload',
onRemove,
...props
}: Readonly<Props>): JSX.Element => (
<label htmlFor={id} className={cx.root} id={`${id}-label`}>
<input type="file" id={id} accept={accept} required hidden {...props} />
<input
type="file"
id={id}
accept={accept}
required
hidden
key={key}
{...props}
/>
<Flex
className={cx.iconBox}
mr="$24"
Expand All @@ -43,15 +53,7 @@ export const FileUpload = ({
<Box w="$fill">
<Box>
<Box mb="$8">
{labelText.map(({ text, highlight }) => (
<Text.Body.Normal
weight="$medium"
color={highlight ? 'highlight' : 'primary'}
key={text}
>
{text}{' '}
</Text.Body.Normal>
))}
<Text.Body.Normal weight="$medium">{label}</Text.Body.Normal>
</Box>
<Text.Body.Small color="secondary" weight="$medium">
{supportedFormats}
Expand All @@ -70,8 +72,10 @@ export const FileUpload = ({
</Flex>
<button
className={cx.removeButtonBox}
onClick={(): void => {
onClick={(event): void => {
if (onRemove) {
event.preventDefault();
event.stopPropagation();
onRemove(file, index);
}
}}
Expand Down
1 change: 1 addition & 0 deletions src/design-system/file-upload/file-upload.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const checkIconBox = style([
h: '$24',
fontSize: '$25',
color: '$data_green',
lineHeight: '$0',
}),
]);

Expand Down
8 changes: 1 addition & 7 deletions src/design-system/file-upload/file-upload.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ export default {
decorators: [page({ title: 'File Upload', subtitle })],
} as Meta;

const label = [
{ text: 'Drag & drop or', highlight: false },
{ text: 'choose file', highlight: true },
{ text: 'to upload', highlight: false },
];

const supportedFormats = 'Supported formats: JSON';

const removeButtonLabel = 'Remove';
Expand All @@ -33,7 +27,7 @@ const RenderFileUpload = ({
files,
}: Readonly<{ id?: string; files?: string[] }>): JSX.Element => (
<FileUpload
label={label}
label="Drag & drop or choose file to upload"
supportedFormats={supportedFormats}
removeButtonLabel={removeButtonLabel}
id={id}
Expand Down
1 change: 1 addition & 0 deletions src/design-tokens/typography.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const fontSizes = {
} as const;

export const lineHeights = {
$0: '0',
$16: '16px',
$17: '17px',
$24: '24px',
Expand Down