Skip to content

Commit 2db2f76

Browse files
committed
add symbols to gravity selector for cropped images
1 parent a23c459 commit 2db2f76

File tree

11 files changed

+67
-15
lines changed

11 files changed

+67
-15
lines changed

client/components/editor/Image.tsx

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@ import ReactCrop, {Crop} from 'react-image-crop';
33
import DropDownMenu from '../../common/DropDownMenu';
44
import FileDetails from '../../admin/FileDetails';
55
import ClearCropIcon from '../../icons/clear-crop.svg';
6+
import GravityCenterIcon from '../../icons/gravity-center.svg';
7+
import GravityNorthIcon from '../../icons/gravity-north.svg';
8+
import GravityNorthEastIcon from '../../icons/gravity-north-east.svg';
9+
import GravityEastIcon from '../../icons/gravity-east.svg';
10+
import GravitySouthEastIcon from '../../icons/gravity-south-east.svg';
11+
import GravitySouthIcon from '../../icons/gravity-south.svg';
12+
import GravitySouthWestIcon from '../../icons/gravity-south-west.svg';
13+
import GravityWestIcon from '../../icons/gravity-west.svg';
14+
import GravityNorthWestIcon from '../../icons/gravity-north-west.svg';
15+
16+
17+
interface GravityOption {
18+
label: string,
19+
icon: JSX.Element,
20+
}
621

722

823
export default function Image(props) {
@@ -18,10 +33,16 @@ export default function Image(props) {
1833
const [crop, setCrop] = useState<Crop>(null);
1934
const [gravity, setGravity] = useState<string>(gravityField.value);
2035
const ref = useRef(null);
21-
const gravityOptions = {
22-
'': gettext("Center"), 'n': gettext("North"), 'ne': gettext("Northeast"),
23-
'e': gettext("East"), 'se': gettext("Southeast"), 's': gettext("South"),
24-
'sw': gettext("Southwest"), 'w': gettext("West"), 'nw': gettext("Northwest"),
36+
const gravityOptions: Record<string, GravityOption> = {
37+
'': {label: gettext("Center"), icon: <GravityCenterIcon/>},
38+
'n': {label: gettext("North"), icon: <GravityNorthIcon/>},
39+
'ne': {label: gettext("Northeast"), icon: <GravityNorthEastIcon/>},
40+
'e': {label: gettext("East"), icon: <GravityEastIcon/>},
41+
'se': {label: gettext("Southeast"), icon: <GravitySouthEastIcon/>},
42+
's': {label: gettext("South"), icon: <GravitySouthIcon/>},
43+
'sw': {label: gettext("Southwest"), icon: <GravitySouthWestIcon/>},
44+
'w': {label: gettext("West"), icon: <GravityWestIcon/>},
45+
'nw': {label: gettext("Northwest"), icon: <GravityNorthWestIcon/>},
2546
};
2647

2748
useEffect(() => {
@@ -60,22 +81,20 @@ export default function Image(props) {
6081
}
6182
}
6283

63-
function getItemProps(value: string) {
64-
return {
65-
role: 'option',
66-
'aria-selected': gravity === value,
67-
onClick: () => {
68-
setGravity(value);
69-
gravityField.value = value;
70-
},
71-
};
84+
function setGravityOption(value) {
85+
setGravity(value);
86+
gravityField.value = value;
7287
}
7388

7489
const controlButtons = [
7590
<Fragment key="clear-crop">
7691
<button type="button" onClick={() => handleChange(null)}><ClearCropIcon/>{gettext("Clear selection")}</button>
77-
<DropDownMenu className="with-caret" wrapperElement="div" label={gettext("Gravity") + ": " + gravityOptions[gravity]} tooltip={gettext("Align image before cropping")}>
78-
{Object.entries(gravityOptions).map(([value, label]) => (<li {...getItemProps(value)}>{label}</li>))}
92+
<DropDownMenu className="with-caret" wrapperElement="div" label={<Fragment>{gettext("Gravity")}: {gravityOptions[gravity].label}</Fragment>} tooltip={gettext("Align image before cropping")}>
93+
{Object.entries(gravityOptions).map(([value, record]) => (
94+
<li key={value} value={value} role="option" aria-selected={gravity === value} onClick={() => setGravityOption(value)}>
95+
{record.icon}{record.label}
96+
</li>
97+
))}
7998
</DropDownMenu>
8099
</Fragment>
81100
];

client/icons/gravity-center.svg

Lines changed: 3 additions & 0 deletions
Loading

client/icons/gravity-east.svg

Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading

client/icons/gravity-north.svg

Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading

client/icons/gravity-south.svg

Lines changed: 3 additions & 0 deletions
Loading

client/icons/gravity-west.svg

Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)