@material-ui/icons APIs
- Close
- ExpandMore
- Add
- ExpandLess
- ArrowDropDown
- GitHub
- Check
- ArrowUpward
- ArrowDownward
- MoreVert
- Launch
- Info
- ChevronRight
- Edit
- Clear
- HelpOutline
- Delete
- Search
- Visibility
- VisibilityOff
- Settings
- ExitToApp
- Error
- InfoOutlined
- ArrowDropUp
- Brightness3
- CheckCircle
- KeyboardArrowRight
- KeyboardArrowDown
- KeyboardArrowUp
- Schedule
- ImageRounded
- Refresh
- KeyboardArrowLeft
- ArrowForward
- WarningRounded
- CloudDownload
- FullscreenExit
- Notifications
- ChevronLeft
- VolumeUp
- ArrowBack
- Work
- Person
- Favorite
- SearchOutlined
- AccountCircle
- Send
- Warning
- FirstPage
- LastPage
- Brightness5
- Telegram
- AccountBalanceWallet
- NotificationsNone
- AddCircle
- SwapHoriz
- AccessTime
- DoneOutlined
- ChevronRightRounded
- List
- ViewModule
- ThumbDownOutlined
- ThumbUpOutlined
- Forum
- CallMade
- PlayCircleOutline
- Cancel
- CancelRounded
- ArrowForwardIos
- LiveHelp
- AllInbox
- Face
- People
- SettingsPower
- NavigateNext
- NavigateBefore
- Save
- LayersClear
- Collections
- ThumbDown
- ThumbUp
- ZoomIn
- ZoomOut
- Fullscreen
- BarChart
- Image
- CenterFocusWeak
- VolumeDown
- Copyright
- DirectionsBoatRounded
- Create
- DeleteOutline
- DeleteOutlineOutlined
- CloudUploadOutlined
- PlayArrow
- Stop
- Done
- Undo
- FileCopy
- Menu
- Home
- Accessibility
- NotificationsActive
- Today
- Gavel
- AddAPhoto
- Dashboard
- Devices
- Event
- FitnessCenter
- Remove
- PinDrop
- Toc
- Group
- MenuBook
- NotListedLocation
- LocationOff
- Alarm
- BrightnessMedium
- Cloud
- ListAlt
- Pets
- GetApp
- ControlPoint
- FiberManualRecordRounded
- Flag
- FileCopyOutlined
- ExitToAppOutlined
- OpenInNew
- CheckCircleOutlined
- CancelOutlined
- PauseCircleOutline
- RemoveCircleOutline
- PlayCircleOutlineOutlined
- ArrowDownwardOutlined
- Brightness7
- OpenInNewSharp
- FilterCenterFocusSharp
- Web
- CheckRounded
- DeleteRounded
- FileCopyRounded
- MoreVertRounded
- SendRounded
- Cached
- CalendarToday
- FlashOn
- PictureAsPdf
- GridOn
- ArrowBackRounded
- PersonAddRounded
- KeyboardArrowUpRounded
- KeyboardArrowDownRounded
- KeyboardArrowLeftRounded
- KeyboardArrowRightRounded
- IndeterminateCheckBoxRounded
- FilterList
- Subject
- ExitToAppRounded
- CachedRounded
- FaceRounded
- Language
- SvgIconComponent
- MoreHoriz
- YouTube
- RestorePage
- NoteAdd
- ArrowBackIos
- Equalizer
- ImportExportRounded
- CloudDownloadRounded
- HelpOutlineRounded
- Star
- Business
- HouseOutlined
- ArrowRight
- ErrorOutline
- Lock
- FavoriteBorder
- MeetingRoom
- Mic
- MicOff
- Videocam
- VideocamOff
- VolumeOff
- ScreenShare
- Receipt
- Title
- ViewComfy
- ViewCompact
- FiberManualRecord
- RadioButtonUnchecked
Other Related APIs
- react#useState
- react#useRef
- react-redux#useSelector
- @material-ui/core#Button
- @material-ui/core#Typography
- @material-ui/core#Dialog
- @material-ui/core#DialogTitle
- @material-ui/core#DialogContent
- @material-ui/core#DialogActions
- @material-ui/core#Hidden
- @material-ui/core#ListItemText
- @material-ui/core#ListItemIcon
- @material-ui/core#Theme
- @material-ui/core#Grid
- @material-ui/core#MenuItem
- @material-ui/core#withStyles
- @material-ui/core#createStyles
- @material-ui/core#WithStyles
- @material-ui/icons#ArrowDropDown
- @material-ui/icons#CloudDownload
@material-ui/icons#Image TypeScript Examples
The following examples show how to use
@material-ui/icons#Image.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.tsx From prism-frontend with MIT License | 4 votes |
function Download({ classes }: DownloadProps) {
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
const [open, setOpen] = useState(false);
const selectedMap = useSelector(mapSelector);
const previewRef = useRef<HTMLCanvasElement>(null);
const { t } = useSafeTranslation();
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
setAnchorEl(event.currentTarget);
};
const handleClose = () => {
setAnchorEl(null);
};
const openModal = () => {
if (selectedMap) {
const activeLayers = selectedMap.getCanvas();
const canvas = previewRef.current;
if (canvas) {
canvas.setAttribute('width', activeLayers.width.toString());
canvas.setAttribute('height', activeLayers.height.toString());
const context = canvas.getContext('2d');
if (context) {
context.drawImage(activeLayers, 0, 0);
}
}
setOpen(true);
}
handleClose();
};
const download = (format: string) => {
const ext = format === 'pdf' ? 'png' : format;
const canvas = previewRef.current;
if (canvas) {
const file = canvas.toDataURL(`image/${ext}`);
if (format === 'pdf') {
// eslint-disable-next-line new-cap
const pdf = new jsPDF({
orientation: 'landscape',
});
const imgProps = pdf.getImageProperties(file);
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width;
pdf.addImage(file, 'PNG', 0, 0, pdfWidth, pdfHeight);
pdf.save('map.pdf');
} else {
const link = document.createElement('a');
link.setAttribute('href', file);
link.setAttribute('download', `map.${ext}`);
link.click();
}
setOpen(false);
handleClose();
}
};
return (
<Grid item>
<Button variant="contained" color="primary" onClick={handleClick}>
<CloudDownload fontSize="small" />
<Hidden smDown>
<Typography className={classes.label} variant="body2">
{t('Export')}
</Typography>
</Hidden>
<ArrowDropDown fontSize="small" />
</Button>
<ExportMenu
id="export-menu"
anchorEl={anchorEl}
keepMounted
open={Boolean(anchorEl)}
onClose={handleClose}
>
<ExportMenuItem onClick={openModal}>
<ListItemIcon>
<Image fontSize="small" style={{ color: 'white' }} />
</ListItemIcon>
<ListItemText primary={t('IMAGE')} />
</ExportMenuItem>
</ExportMenu>
<Dialog
maxWidth="xl"
open={open}
keepMounted
onClose={() => setOpen(false)}
aria-labelledby="dialog-preview"
>
<DialogTitle className={classes.title} id="dialog-preview">
{t('Map Preview')}
</DialogTitle>
<DialogContent>
<canvas ref={previewRef} />
</DialogContent>
<DialogActions>
<Button onClick={() => setOpen(false)} color="primary">
{t('Cancel')}
</Button>
<Button
variant="contained"
onClick={() => download('png')}
color="primary"
>
{t('Download PNG')}
</Button>
<Button
variant="contained"
onClick={() => download('jpeg')}
color="primary"
>
{t('Download JPEG')}
</Button>
<Button
variant="contained"
onClick={() => download('pdf')}
color="primary"
>
{t('Download PDF')}
</Button>
</DialogActions>
</Dialog>
</Grid>
);
}