Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x | import l10n from "shared/lib/lang/l10n";
import React, { useMemo } from "react";
import { UnitType } from "shared/lib/entities/entitiesTypes";
import styled from "styled-components";
import { Button } from "ui/buttons/Button";
import { DropdownButton } from "ui/buttons/DropdownButton";
import { CheckIcon, BlankIcon } from "ui/icons/Icons";
import { MenuItem } from "ui/menu/Menu";
import { StyledButton } from "ui/buttons/style";
interface UnitSelectLabelButtonProps<T extends UnitType = UnitType> {
value?: T;
allowedValues?: readonly T[];
onChange?: (newValue: T) => void;
}
const Units = styled.div`
display: inline-flex;
pointer-events: all;
margin: -6px 3px;
${StyledButton} {
opacity: 0.5;
padding: 1px;
min-width: 0;
height: 18px;
&:hover {
opacity: 1;
}
}
`;
export const UnitSelectLabelButton = <T extends UnitType>({
value,
allowedValues,
onChange,
}: UnitSelectLabelButtonProps<T>) => {
const unitTypeNames: Record<UnitType, string> = useMemo(
() => ({
tiles: l10n("FIELD_TILES"),
pixels: l10n("FIELD_PIXELS"),
time: l10n("FIELD_SECONDS"),
frames: l10n("FIELD_FRAMES"),
"8px": "8px",
"16px": "16px",
}),
[],
);
const unitTypeButtonNames: Record<UnitType, string> = useMemo(
() => ({
tiles: l10n("FIELD_TILES").toLocaleLowerCase(),
pixels: l10n("FIELD_PIXELS_SHORT").toLocaleLowerCase(),
time: l10n("FIELD_SECONDS").toLocaleLowerCase(),
frames: l10n("FIELD_FRAMES").toLocaleLowerCase(),
"8px": "8px",
"16px": "16px",
}),
[],
);
const currentValue = value && unitTypeButtonNames[value];
return (
<Units>
{allowedValues ? (
<DropdownButton
label={currentValue}
showArrow={false}
size="small"
variant="transparent"
type="button"
>
{allowedValues.map((item) => (
<MenuItem
key={item}
onClick={() => onChange?.(item)}
icon={value === item ? <CheckIcon /> : <BlankIcon />}
>
{unitTypeNames[item]}
</MenuItem>
))}
</DropdownButton>
) : (
<Button size="small" variant="transparent" type="button" tabIndex={-1}>
{currentValue}
</Button>
)}
</Units>
);
};
|