Skip to content
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

[material-ui][Button] Add demo for file upload #38786

Merged
merged 15 commits into from
Sep 4, 2023
30 changes: 30 additions & 0 deletions docs/data/material/components/buttons/InputFileUpload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as React from 'react';
import { styled } from '@mui/material/styles';
import Button from '@mui/material/Button';
import CloudUploadIcon from '@mui/icons-material/CloudUpload';

const VisuallyHiddenInput = styled('input')`
clip: rect(0 0 0 0);
clip-path: inset(50%);
height: 1px;
overflow: hidden;
position: absolute;
bottom: 0;
left: 0;
white-space: nowrap;
width: 1px;
`;

export default function InputFileUpload() {
return (
<Button
component="label"
variant="contained"
startIcon={<CloudUploadIcon />}
href="#file-upload"
>
Upload a file
<VisuallyHiddenInput type="file" />
</Button>
);
}
30 changes: 30 additions & 0 deletions docs/data/material/components/buttons/InputFileUpload.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as React from 'react';
import { styled } from '@mui/material/styles';
import Button from '@mui/material/Button';
import CloudUploadIcon from '@mui/icons-material/CloudUpload';

const VisuallyHiddenInput = styled('input')`
clip: rect(0 0 0 0);
clip-path: inset(50%);
height: 1px;
overflow: hidden;
position: absolute;
bottom: 0;
left: 0;
white-space: nowrap;
width: 1px;
`;
Comment on lines +6 to +16
Copy link
Member

@oliviertassinari oliviertassinari Sep 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know, the standard is for all the demos should use the JavaScript object syntax in Base UI, Joy UI,
Material UI. I imagine it's because 1. the source are written this way, so easier for developers to move between source and demos, and 2. it's more typesafe.

Can we update these?


export default function InputFileUpload() {
return (
<Button
component="label"
variant="contained"
startIcon={<CloudUploadIcon />}
href="#file-upload"
Copy link
Member

@oliviertassinari oliviertassinari Sep 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

>
Upload a file
<VisuallyHiddenInput type="file" />
</Button>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Button
component="label"
variant="contained"
startIcon={<CloudUploadIcon />}
href="#file-upload"
>
Upload a file
<VisuallyHiddenInput type="file" />
</Button>
6 changes: 6 additions & 0 deletions docs/data/material/components/buttons/buttons.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ Use `color` prop to apply theme color palette to component.

{{"demo": "IconButtonColors.js"}}

## File upload

To create a file upload button, turn the button into a label using `component="label"` and then create a visually-hidden input with type `file`.

{{"demo": "InputFileUpload.js"}}

## Customization

Here are some examples of customizing the component.
Expand Down