| 1 |
import { CSSProperties } from "react"; |
| 2 |
|
| 3 |
import { CellKey } from "../attributes"; |
| 4 |
import { |
| 5 |
ElementAlignment, |
| 6 |
elementAlignmentToJustifyContent, |
| 7 |
} from "../alignment"; |
| 8 |
|
| 9 |
/** Shared bits for the element blocks' edit components. */ |
| 10 |
|
| 11 |
export function alignmentWrapperStyle(align: ElementAlignment): CSSProperties { |
| 12 |
return { |
| 13 |
display: "flex", |
| 14 |
justifyContent: elementAlignmentToJustifyContent(align), |
| 15 |
textAlign: align, |
| 16 |
}; |
| 17 |
} |
| 18 |
|
| 19 |
// Placeholder coords for reused controls whose store path is inactive in |
| 20 |
// the native editor (the passed updateAttrs/updateStyles override always |
| 21 |
// wins). |
| 22 |
export const NO_COORDS = "0,0" as CellKey; |
| 23 |
|
| 24 |
import { BlockControls } from "@wordpress/block-editor"; |
| 25 |
import { ToolbarWithDropdown } from "@tableberg/components"; |
| 26 |
import { __ } from "@wordpress/i18n"; |
| 27 |
|
| 28 |
export function ElementAlignmentToolbar({ |
| 29 |
align, |
| 30 |
onChange, |
| 31 |
}: { |
| 32 |
align: ElementAlignment; |
| 33 |
onChange: (align: ElementAlignment) => void; |
| 34 |
}) { |
| 35 |
return ( |
| 36 |
<BlockControls> |
| 37 |
<ToolbarWithDropdown |
| 38 |
title={__("Align element", "tableberg")} |
| 39 |
value={align} |
| 40 |
onChange={(newAlign?: string) => { |
| 41 |
if ( |
| 42 |
newAlign === "left" || |
| 43 |
newAlign === "center" || |
| 44 |
newAlign === "right" |
| 45 |
) { |
| 46 |
onChange(newAlign); |
| 47 |
} |
| 48 |
}} |
| 49 |
controlset="alignment" |
| 50 |
/> |
| 51 |
</BlockControls> |
| 52 |
); |
| 53 |
} |
| 54 |
|