|
| 1 | +import * as React from "react"; |
| 2 | +import AlignVerticalTopIcon from "@mui/icons-material/AlignVerticalTop"; |
| 3 | +import AlignVerticalCenterIcon from "@mui/icons-material/AlignVerticalCenter"; |
| 4 | +import AlignVerticalBottomIcon from "@mui/icons-material/AlignVerticalBottom"; |
| 5 | +import Stack from "@mui/material/Stack"; |
| 6 | +import ToggleButton from "@mui/material/ToggleButton"; |
| 7 | +import ToggleButtonGroup from "@mui/material/ToggleButtonGroup"; |
| 8 | +import { TextAlignmentProps } from "cdm/StyleModel"; |
| 9 | +import { COLUMN_ALIGNMENT_OPTIONS, StyleVariables } from "helpers/Constants"; |
| 10 | +import { t } from "lang/helpers"; |
| 11 | + |
| 12 | +export default function TextAlignmentYSelector(props: TextAlignmentProps) { |
| 13 | + const { modal, columnId, currentAlignment } = props; |
| 14 | + const { view } = modal; |
| 15 | + const [alignment, setAlignment] = React.useState(currentAlignment); |
| 16 | + |
| 17 | + const handleAlignment = async ( |
| 18 | + event: React.MouseEvent<HTMLElement>, |
| 19 | + newAlignment: string | null |
| 20 | + ) => { |
| 21 | + if (newAlignment !== null) { |
| 22 | + // Persist changes |
| 23 | + await view.diskConfig.updateColumnConfig(columnId, { |
| 24 | + content_vertical_alignment: newAlignment, |
| 25 | + }); |
| 26 | + modal.enableReset = true; |
| 27 | + setAlignment(newAlignment); |
| 28 | + } |
| 29 | + }; |
| 30 | + |
| 31 | + return ( |
| 32 | + <Stack direction="row" spacing={4}> |
| 33 | + <ToggleButtonGroup |
| 34 | + value={alignment} |
| 35 | + exclusive |
| 36 | + onChange={handleAlignment} |
| 37 | + aria-label={t( |
| 38 | + "column_settings_modal_text_alignment_vertical_select_title" |
| 39 | + )} |
| 40 | + > |
| 41 | + <ToggleButton |
| 42 | + value={COLUMN_ALIGNMENT_OPTIONS.TOP} |
| 43 | + aria-label={t( |
| 44 | + "column_settings_modal_text_alignment_vertical_select_top" |
| 45 | + )} |
| 46 | + sx={{ |
| 47 | + color: StyleVariables.TEXT_NORMAL, |
| 48 | + "&.Mui-selected, &.Mui-selected:hover": { |
| 49 | + color: StyleVariables.TEXT_ACCENT, |
| 50 | + }, |
| 51 | + }} |
| 52 | + > |
| 53 | + <AlignVerticalTopIcon /> |
| 54 | + </ToggleButton> |
| 55 | + <ToggleButton |
| 56 | + value={COLUMN_ALIGNMENT_OPTIONS.MIDDLE} |
| 57 | + aria-label={t( |
| 58 | + "column_settings_modal_text_alignment_vertical_select_middle" |
| 59 | + )} |
| 60 | + sx={{ |
| 61 | + color: StyleVariables.TEXT_NORMAL, |
| 62 | + "&.Mui-selected, &.Mui-selected:hover": { |
| 63 | + color: StyleVariables.TEXT_ACCENT, |
| 64 | + }, |
| 65 | + }} |
| 66 | + > |
| 67 | + <AlignVerticalCenterIcon /> |
| 68 | + </ToggleButton> |
| 69 | + <ToggleButton |
| 70 | + value={COLUMN_ALIGNMENT_OPTIONS.BOTTOM} |
| 71 | + aria-label={t( |
| 72 | + "column_settings_modal_text_alignment_vertical_select_bottom" |
| 73 | + )} |
| 74 | + sx={{ |
| 75 | + color: StyleVariables.TEXT_NORMAL, |
| 76 | + "&.Mui-selected, &.Mui-selected:hover": { |
| 77 | + color: StyleVariables.TEXT_ACCENT, |
| 78 | + }, |
| 79 | + }} |
| 80 | + > |
| 81 | + <AlignVerticalBottomIcon /> |
| 82 | + </ToggleButton> |
| 83 | + </ToggleButtonGroup> |
| 84 | + </Stack> |
| 85 | + ); |
| 86 | +} |
0 commit comments