Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import PropTypes from 'prop-types';
/** Internal Dependencies */
import restrictNumber from 'utils/restrictNumber';
import ColorInput from 'components/common/ColorInput';
import { StyledSliderInput } from 'components/tools/tools.styled';
import { StyledSpacedOptionFields } from './AnnotationOptions.styled';
import Slider from '../Slider';

Expand All @@ -30,6 +31,10 @@ const StrokeFields = ({ annotation, updateAnnotation }) => {

return (
<StyledSpacedOptionFields>
<StyledSliderInput
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the difference between this and the next Slider call?

Copy link
Contributor Author

@HimonRana HimonRana Sep 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an Input that shows the width makes it easier to write strokeWidth if the slider is to hard to slide and find a specific width. Also you dont know exactly what width you have unless you hover over so that helps too(specially in mobile mode).
image

value={strokeWidth}
onChange={({ target: { value } }) => changeStrokeWidth(value)}
/>
<Slider
annotation="px"
onChange={changeStrokeWidth}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const AnnotationOptions = ({
annotation,
updateAnnotation,
hideFillOption,
hideStrokeField,
hidePositionField,
className,
...rest
Expand All @@ -54,17 +55,19 @@ const AnnotationOptions = ({
},
...(!useCloudimage
? [
{ titleKey: 'stroke', name: POPPABLE_OPTIONS.STROKE, Icon: Stroke },
...(hideStrokeField ? [{ titleKey: 'stroke', name: POPPABLE_OPTIONS.STROKE, Icon: Stroke }] : []),
{ titleKey: 'shadow', name: POPPABLE_OPTIONS.SHADOW, Icon: Shadow },
]
: []),
!hidePositionField
? {
titleKey: 'position',
name: POPPABLE_OPTIONS.POSITION,
Icon: Position,
}
: undefined,
...(!hidePositionField
? [
{
titleKey: 'position',
name: POPPABLE_OPTIONS.POSITION,
Icon: Position,
},
]
: []),
],
[morePoppableOptionsPrepended],
);
Expand All @@ -89,7 +92,11 @@ const AnnotationOptions = ({

const changeAnnotationFill = useCallback(
(newFill) => {
updateAnnotation({ fill: newFill });
if (!hideStrokeField) {
updateAnnotation({ stroke: newFill });
} else {
updateAnnotation({ fill: newFill });
}
},
[updateAnnotation],
);
Expand All @@ -115,7 +122,13 @@ const AnnotationOptions = ({
className={`FIE_annotations-options${className ? ` ${className}` : ''}`}
isPhoneScreen={isPhoneScreen}
>
{!hideFillOption && (
{ !hideStrokeField && (
<StrokeFields
annotation={annotation}
updateAnnotation={updateAnnotation}
/>
)}
{ !hideFillOption && (
<ColorInput
color={annotation.fill}
onChange={changeAnnotationFill}
Expand Down Expand Up @@ -173,6 +186,7 @@ AnnotationOptions.defaultProps = {
moreOptionsPopupComponentsObj: {},
morePoppableOptionsAppended: [],
hideFillOption: false,
hideStrokeField: false,
hidePositionField: false,
className: undefined,
};
Expand All @@ -182,6 +196,7 @@ AnnotationOptions.propTypes = {
updateAnnotation: PropTypes.func.isRequired,
children: PropTypes.node,
hideFillOption: PropTypes.bool,
hideStrokeField: PropTypes.bool,
morePoppableOptionsPrepended: PropTypes.arrayOf(PropTypes.instanceOf(Object)),
morePoppableOptionsAppended: PropTypes.arrayOf(PropTypes.instanceOf(Object)),
moreOptionsPopupComponentsObj: PropTypes.instanceOf(Object),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ import { StyledPickerTrigger } from './ColorInput.styled';

const pinnedColorsKey = 'FIE_pinnedColors';

const presetPinnedColors = [
'#000000',
'#ff0000',
'#00ff00',
'#0000ff',
'#ffff00',
'#ffffff',
];

// colorFor is used to save the latest color for a specific purpose (e.g. fill/shadow/stroke)
const ColorInput = ({ onChange, color, colorFor }) => {
const {
Expand All @@ -23,27 +32,27 @@ const ColorInput = ({ onChange, color, colorFor }) => {
const [currentColor, setCurrentColor] = useState(
() => latestColor || color || annotationsCommon.fill,
);
const [pinnedColors, setPinnedColors] = useState(
window?.localStorage
? JSON.parse(localStorage.getItem(pinnedColorsKey) || '[]')
: [],
);
const [pinnedColors, setPinnedColors] = useState(() => {
if (window?.localStorage) {
const savedColors = localStorage.getItem(pinnedColorsKey);
return savedColors ? JSON.parse(savedColors) : presetPinnedColors;
}
return presetPinnedColors;
});
const initialColor = useRef(currentColor);

const changePinnedColors = (newPinnedColors) => {
if (!window?.localStorage) {
return;
}
const localStoragePinnedColors =
window.localStorage.getItem(pinnedColorsKey);
if (JSON.stringify(newPinnedColors) !== localStoragePinnedColors) {
const maxOfSavedColors = 9;
const pinnedColorsToSave = newPinnedColors.slice(-maxOfSavedColors);
window.localStorage.setItem(
pinnedColorsKey,
JSON.stringify(pinnedColorsToSave),
);
setPinnedColors(pinnedColorsToSave);
if (!window?.localStorage) return;

const localStoragePinnedColors = localStorage.getItem(pinnedColorsKey);
const currentPinnedColors = localStoragePinnedColors
? JSON.parse(localStoragePinnedColors)
: presetPinnedColors;


if (JSON.stringify(newPinnedColors) !== JSON.stringify(currentPinnedColors)) {
localStorage.setItem(pinnedColorsKey, JSON.stringify(newPinnedColors));
setPinnedColors(newPinnedColors);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ const ColorPickerWrap = styled.div`
.SfxColorPicker-select {
width: 100px;
}
.SfxInput-root {
width: 190px !important;
}
}

.SfxColorPicker-icon {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const EllipseOptions = ({ t }) => {
className="FIE_ellipse-tool-options"
annotation={ellipse}
updateAnnotation={saveEllipse}
hideStrokeField
t={t}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const ImageControls = ({ image, saveImage, children, t }) => (
updateAnnotation={saveImage}
t={t}
hideFillOption
hideStrokeField
>
{children}
</AnnotationOptions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const PolygonOptions = ({ t }) => {
updateAnnotation={savePolygon}
t={t}
hidePositionField
hideStrokeField
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const RectOptions = ({ t }) => {
morePoppableOptionsPrepended={RECT_POPPABLE_OPTIONS}
annotation={rect}
updateAnnotation={saveRect}
hideStrokeField
t={t}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ const TextControls = ({ text, saveText, children }) => {
moreOptionsPopupComponentsObj={
!useCloudimage ? textOptionsPopupComponents : {}
}
hideStrokeField
t={t}
>
{Array.isArray(fonts) && fonts.length > 1 && (
Expand Down