Skip to content

Commit

Permalink
[material-ui][Button] Add demo for file upload (mui#38786)
Browse files Browse the repository at this point in the history
  • Loading branch information
anle9650 authored and xcode-it committed Sep 11, 2023
1 parent 1c7bf5d commit 871f86d
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
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;
`;

export default function InputFileUpload() {
return (
<Button
component="label"
variant="contained"
startIcon={<CloudUploadIcon />}
href="#file-upload"
>
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

0 comments on commit 871f86d

Please sign in to comment.