|
| 1 | +'use client' |
| 2 | + |
| 3 | +import React, { useState } from 'react' |
| 4 | +import { Fab, useTheme, alpha, Tooltip } from '@mui/material' |
| 5 | +import { Security as SecurityIcon } from '@mui/icons-material' |
| 6 | +import { styled } from '@mui/material/styles' |
| 7 | +import { PasswordGenerator } from './PasswordGenerator' |
| 8 | + |
| 9 | +const GlassFloatingButton = styled(Fab)(({ theme }) => ({ |
| 10 | + position: 'fixed', |
| 11 | + bottom: '30px', |
| 12 | + right: '30px', |
| 13 | + width: '64px', |
| 14 | + height: '64px', |
| 15 | + backdropFilter: 'blur(20px)', |
| 16 | + border: '1px solid', |
| 17 | + zIndex: 1000, |
| 18 | + animation: 'breathingButton 6s infinite ease-in-out', |
| 19 | + |
| 20 | + '@keyframes breathingButton': { |
| 21 | + '0%': { |
| 22 | + transform: 'scale(0.95)', |
| 23 | + backgroundColor: theme.palette.mode === 'dark' |
| 24 | + ? alpha(theme.palette.primary.main, 0.4) |
| 25 | + : alpha(theme.palette.primary.main, 0.35), |
| 26 | + borderColor: theme.palette.mode === 'dark' |
| 27 | + ? alpha(theme.palette.primary.main, 0.6) |
| 28 | + : alpha(theme.palette.primary.main, 0.7), |
| 29 | + boxShadow: `0 8px 32px ${alpha(theme.palette.primary.main, 0.3)}`, |
| 30 | + color: theme.palette.primary.main |
| 31 | + }, |
| 32 | + '50%': { |
| 33 | + transform: 'scale(1.15)', |
| 34 | + backgroundColor: theme.palette.mode === 'dark' |
| 35 | + ? alpha(theme.palette.primary.main, 0.5) |
| 36 | + : alpha(theme.palette.primary.main, 0.45), |
| 37 | + borderColor: theme.palette.mode === 'dark' |
| 38 | + ? alpha(theme.palette.primary.main, 0.7) |
| 39 | + : alpha(theme.palette.primary.main, 0.8), |
| 40 | + boxShadow: `0 20px 56px ${alpha(theme.palette.primary.main, 0.6)}`, |
| 41 | + color: theme.palette.primary.main |
| 42 | + }, |
| 43 | + '100%': { |
| 44 | + transform: 'scale(0.95)', |
| 45 | + backgroundColor: theme.palette.mode === 'dark' |
| 46 | + ? alpha(theme.palette.primary.main, 0.4) |
| 47 | + : alpha(theme.palette.primary.main, 0.35), |
| 48 | + borderColor: theme.palette.mode === 'dark' |
| 49 | + ? alpha(theme.palette.primary.main, 0.6) |
| 50 | + : alpha(theme.palette.primary.main, 0.7), |
| 51 | + boxShadow: `0 8px 32px ${alpha(theme.palette.primary.main, 0.3)}`, |
| 52 | + color: theme.palette.primary.main |
| 53 | + } |
| 54 | + }, |
| 55 | + |
| 56 | + '&:hover': { |
| 57 | + animation: 'none', |
| 58 | + backgroundColor: |
| 59 | + theme.palette.mode === 'dark' |
| 60 | + ? alpha(theme.palette.primary.main, 0.5) |
| 61 | + : alpha(theme.palette.primary.main, 0.45), |
| 62 | + borderColor: |
| 63 | + theme.palette.mode === 'dark' |
| 64 | + ? alpha(theme.palette.primary.main, 0.7) |
| 65 | + : alpha(theme.palette.primary.main, 0.8), |
| 66 | + boxShadow: `0 16px 48px ${alpha(theme.palette.primary.main, 0.4)}`, |
| 67 | + transform: 'translateY(-2px) scale(1.1)', |
| 68 | + color: theme.palette.primary.main |
| 69 | + }, |
| 70 | + |
| 71 | + '&:active': { |
| 72 | + transform: 'translateY(0px) scale(1.0)' |
| 73 | + }, |
| 74 | + |
| 75 | + '& .MuiSvgIcon-root': { |
| 76 | + fontSize: '28px', |
| 77 | + filter: 'drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1))', |
| 78 | + transition: 'inherit' |
| 79 | + }, |
| 80 | + |
| 81 | + '@media (max-width: 600px)': { |
| 82 | + width: '56px', |
| 83 | + height: '56px', |
| 84 | + bottom: '20px', |
| 85 | + right: '20px', |
| 86 | + '& .MuiSvgIcon-root': { |
| 87 | + fontSize: '24px' |
| 88 | + } |
| 89 | + } |
| 90 | +})) |
| 91 | + |
| 92 | + |
| 93 | +export const FloatingPasswordButton: React.FC = () => { |
| 94 | + const theme = useTheme() |
| 95 | + const [isGeneratorOpen, setIsGeneratorOpen] = useState(false) |
| 96 | + |
| 97 | + const handleClick = () => { |
| 98 | + setIsGeneratorOpen(true) |
| 99 | + } |
| 100 | + |
| 101 | + const handleClose = () => { |
| 102 | + setIsGeneratorOpen(false) |
| 103 | + } |
| 104 | + |
| 105 | + return ( |
| 106 | + <> |
| 107 | + <Tooltip title="Generate 2FA Code" placement="left" arrow> |
| 108 | + <GlassFloatingButton |
| 109 | + onClick={handleClick} |
| 110 | + aria-label="Generate 2FA code" |
| 111 | + > |
| 112 | + <SecurityIcon /> |
| 113 | + </GlassFloatingButton> |
| 114 | + </Tooltip> |
| 115 | + |
| 116 | + <PasswordGenerator open={isGeneratorOpen} onClose={handleClose} /> |
| 117 | + </> |
| 118 | + ) |
| 119 | +} |
0 commit comments