Skip to content

Commit

Permalink
Add the shape lock button for mobile (excalidraw#1054)
Browse files Browse the repository at this point in the history
  • Loading branch information
yongdamsh authored Mar 24, 2020
1 parent e38045c commit 104e48b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export class App extends React.Component<any, AppState> {
language={getLanguage()}
onRoomCreate={this.createRoom}
onRoomDestroy={this.destroyRoom}
onToggleLock={this.toggleLock}
onLockToggle={this.toggleLock}
/>
<main>
<canvas
Expand Down
8 changes: 4 additions & 4 deletions src/components/LayerUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interface LayerUIProps {
setElements: (elements: readonly ExcalidrawElement[]) => void;
onRoomCreate: () => void;
onRoomDestroy: () => void;
onToggleLock: () => void;
onLockToggle: () => void;
}

export const LayerUI = React.memo(
Expand All @@ -47,7 +47,7 @@ export const LayerUI = React.memo(
setElements,
onRoomCreate,
onRoomDestroy,
onToggleLock,
onLockToggle,
}: LayerUIProps) => {
const isMobile = useIsMobile();

Expand Down Expand Up @@ -101,6 +101,7 @@ export const LayerUI = React.memo(
setAppState={setAppState}
onRoomCreate={onRoomCreate}
onRoomDestroy={onRoomDestroy}
onLockToggle={onLockToggle}
/>
) : (
<>
Expand Down Expand Up @@ -159,9 +160,8 @@ export const LayerUI = React.memo(
</Island>
<LockIcon
checked={appState.elementLocked}
onChange={onToggleLock}
onChange={onLockToggle}
title={t("toolBar.lock")}
isButton={isMobile}
/>
</Stack.Row>
</Stack.Col>
Expand Down
5 changes: 1 addition & 4 deletions src/components/LockIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ type LockIconProps = {
checked: boolean;
onChange?(): void;
size?: LockIconSize;
isButton?: boolean;
};

const DEFAULT_SIZE: LockIconSize = "m";
Expand Down Expand Up @@ -46,9 +45,7 @@ export function LockIcon(props: LockIconProps) {

return (
<label
className={`ToolIcon ToolIcon__lock ${
props.isButton ? "ToolIcon_type_button" : "ToolIcon_type_floating"
} ${sizeCn}`}
className={`ToolIcon ToolIcon__lock ToolIcon_type_floating ${sizeCn}`}
title={`${props.title} ${getShortcutKey("Q")}`}
>
<input
Expand Down
8 changes: 8 additions & 0 deletions src/components/MobileMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { SelectedShapeActions, ShapesSwitcher } from "./Actions";
import { Section } from "./Section";
import { RoomDialog } from "./RoomDialog";
import { SCROLLBAR_WIDTH, SCROLLBAR_MARGIN } from "../scene/scrollbars";
import { LockIcon } from "./LockIcon";

type MobileMenuProps = {
appState: AppState;
Expand All @@ -24,6 +25,7 @@ type MobileMenuProps = {
setElements: any;
onRoomCreate: () => void;
onRoomDestroy: () => void;
onLockToggle: () => void;
};

export function MobileMenu({
Expand All @@ -35,6 +37,7 @@ export function MobileMenu({
setAppState,
onRoomCreate,
onRoomDestroy,
onLockToggle,
}: MobileMenuProps) {
return (
<>
Expand All @@ -54,6 +57,11 @@ export function MobileMenu({
/>
</Stack.Row>
</Island>
<LockIcon
checked={appState.elementLocked}
onChange={onLockToggle}
title={t("toolBar.lock")}
/>
</Stack.Row>
</Stack.Col>
)}
Expand Down
35 changes: 29 additions & 6 deletions src/components/ToolIcon.scss
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,6 @@
}

.ToolIcon.ToolIcon__lock {
&.ToolIcon_type_button {
border-radius: 4px;
svg {
position: static;
}
}
&.ToolIcon_type_floating {
margin-left: 0.1rem;
}
Expand All @@ -126,3 +120,32 @@
font-family: var(--ui-font);
user-select: none;
}

@media (max-width: 360px) {
.ToolIcon.ToolIcon__lock {
display: inline-block;
position: absolute;
top: 60px;
right: -8px;

margin-left: 0;
border-radius: 20px 0 0 20px;

background-color: var(--button-gray-1);
&:hover {
background-color: var(--button-gray-1);
}
&:active {
background-color: var(--button-gray-2);
}

.ToolIcon__icon {
width: 2.5rem;
height: 2.5rem;
border-radius: inherit;
}
svg {
position: static;
}
}
}

0 comments on commit 104e48b

Please sign in to comment.