|
| 1 | +/* |
| 2 | + * Copyright 2026 LY Corporation |
| 3 | + * |
| 4 | + * LY Corporation licenses this file to you under the Apache License, |
| 5 | + * version 2.0 (the "License"); you may not use this file except in compliance |
| 6 | + * with the License. You may obtain a copy of the License at: |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | + * License for the specific language governing permissions and limitations |
| 14 | + * under the License. |
| 15 | + */ |
| 16 | +import { ReactNode } from 'react'; |
| 17 | +import { Box, Flex, HStack, Input, Spacer, useColorModeValue } from '@chakra-ui/react'; |
| 18 | + |
| 19 | +interface EditorActionBarProps { |
| 20 | + commitSummary: string; |
| 21 | + onCommitSummaryChange: (value: string) => void; |
| 22 | + commitPlaceholder: string; |
| 23 | + // Constrains the bar to the form width (the K8s aggregator form uses "3xl"). Defaults to the full |
| 24 | + // width of the content area (used by the full-width YAML resource editor). |
| 25 | + maxW?: string; |
| 26 | + // Action buttons (Cancel/Save/Preview/Create), rendered right-aligned. |
| 27 | + children: ReactNode; |
| 28 | +} |
| 29 | + |
| 30 | +// A sticky footer that pins the commit-summary input and action buttons to the bottom of the viewport |
| 31 | +// while editing, so Save/Create stays reachable without scrolling past a tall editor or form. It relies |
| 32 | +// on the page (body) being the scroll container, matching the rest of the app. |
| 33 | +export const EditorActionBar = ({ |
| 34 | + commitSummary, |
| 35 | + onCommitSummaryChange, |
| 36 | + commitPlaceholder, |
| 37 | + maxW, |
| 38 | + children, |
| 39 | +}: EditorActionBarProps) => { |
| 40 | + // Match the default Chakra body background (the app uses the stock theme, no extendTheme) so the bar |
| 41 | + // opaquely covers any editor/form content it overlaps in both color modes. |
| 42 | + const bg = useColorModeValue('white', 'gray.800'); |
| 43 | + const borderColor = useColorModeValue('gray.200', 'gray.700'); |
| 44 | + return ( |
| 45 | + <Box |
| 46 | + position="sticky" |
| 47 | + bottom={0} |
| 48 | + zIndex={1} |
| 49 | + mt={4} |
| 50 | + py={3} |
| 51 | + bg={bg} |
| 52 | + borderTopWidth="1px" |
| 53 | + borderColor={borderColor} |
| 54 | + maxW={maxW} |
| 55 | + > |
| 56 | + <Flex align="center" gap={3}> |
| 57 | + {/* The descriptive placeholder ("Update cluster: ...") stands in for a visible label so the bar |
| 58 | + stays a single row; aria-label keeps it accessible. */} |
| 59 | + <Input |
| 60 | + aria-label="Commit summary" |
| 61 | + maxW="md" |
| 62 | + value={commitSummary} |
| 63 | + onChange={(e) => onCommitSummaryChange(e.target.value)} |
| 64 | + placeholder={commitPlaceholder} |
| 65 | + /> |
| 66 | + <Spacer /> |
| 67 | + <HStack spacing={3} flexShrink={0}> |
| 68 | + {children} |
| 69 | + </HStack> |
| 70 | + </Flex> |
| 71 | + </Box> |
| 72 | + ); |
| 73 | +}; |
0 commit comments