UNPKG

@kinvolk/headlamp-plugin

Version:

The needed infrastructure for building Headlamp plugins.

96 lines (95 loc) 4.56 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; /* * Copyright 2025 The Kubernetes Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { Icon } from '@iconify/react'; import { alpha, Box, Button, useTheme } from '@mui/material'; import { Trans } from 'react-i18next'; import { useDispatch } from 'react-redux'; import { setDetailDrawerEnabled } from '../../../redux/drawerModeSlice'; import { useTypedSelector } from '../../../redux/hooks'; function OverlayPreview({ variant }) { const theme = useTheme(); const size = '150px'; return (_jsxs(Box, { sx: { width: size, height: size, border: '1px solid', borderColor: theme.palette.divider, position: 'relative', borderRadius: theme.shape.borderRadius + 'px', overflow: 'hidden', }, children: [_jsx(Box, { sx: { position: 'absolute', top: 0, left: 0, width: '100%', height: '10%', borderBottom: '1px solid', borderColor: theme.palette.divider, } }), _jsx(Box, { sx: { position: 'absolute', width: '20%', height: '90%', top: '10%', left: 0, borderRight: '1px solid', borderColor: theme.palette.divider, } }), variant === 'overlay' && (_jsx(Box, { sx: { position: 'absolute', background: theme.palette.background.muted, width: '50%', height: '90%', top: '10%', left: '50%', border: '1px solid', borderColor: theme.palette.divider, display: 'flex', alignItems: 'center', justifyContent: 'center', borderRadius: theme.shape.borderRadius + 'px', }, children: _jsx(Box, { sx: { position: 'absolute', top: 0, right: 0, padding: '3px' }, children: _jsx(Icon, { icon: "mdi:close" }) }) })), variant === 'full-page' && (_jsx(Box, { sx: { position: 'absolute', background: theme.palette.background.muted, width: '80%', height: '90%', top: '10%', left: '20%', display: 'flex', alignItems: 'center', justifyContent: 'center', }, children: _jsx(Box, { sx: { position: 'absolute', top: 0, left: 0, padding: '3px', }, children: _jsx(Icon, { icon: "mdi:chevron-left" }) }) }))] })); } const OptionButton = ({ children, active, onClick, }) => (_jsx(Button, { "aria-pressed": active, onClick: onClick, sx: theme => ({ display: 'flex', flexDirection: 'column', color: 'unset', textTransform: 'none', gap: 1, border: '2px solid', borderColor: active ? alpha(theme.palette.action.active, theme.palette.action.activatedOpacity) : 'transparent', }), children: children })); export default function DrawerModeSettings() { const dispatch = useDispatch(); const isDrawerEnabled = useTypedSelector(state => state?.drawerMode?.isDetailDrawerEnabled); return (_jsxs(Box, { sx: { display: 'flex' }, children: [_jsxs(OptionButton, { active: isDrawerEnabled, onClick: () => dispatch(setDetailDrawerEnabled(true)), children: [_jsx(OverlayPreview, { variant: "overlay" }), _jsx(Trans, { children: "Window" })] }), _jsxs(OptionButton, { active: !isDrawerEnabled, onClick: () => dispatch(setDetailDrawerEnabled(false)), children: [_jsx(OverlayPreview, { variant: "full-page" }), _jsx(Trans, { children: "Full page" })] })] })); }