Add the shape lock button for mobile (#1054)

This commit is contained in:
Sanghyeon Lee 2020-03-24 19:51:49 +09:00 committed by GitHub
parent e38045ccad
commit 104e48b6cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 15 deletions

View File

@ -190,7 +190,7 @@ export class App extends React.Component<any, AppState> {
language={getLanguage()} language={getLanguage()}
onRoomCreate={this.createRoom} onRoomCreate={this.createRoom}
onRoomDestroy={this.destroyRoom} onRoomDestroy={this.destroyRoom}
onToggleLock={this.toggleLock} onLockToggle={this.toggleLock}
/> />
<main> <main>
<canvas <canvas

View File

@ -33,7 +33,7 @@ interface LayerUIProps {
setElements: (elements: readonly ExcalidrawElement[]) => void; setElements: (elements: readonly ExcalidrawElement[]) => void;
onRoomCreate: () => void; onRoomCreate: () => void;
onRoomDestroy: () => void; onRoomDestroy: () => void;
onToggleLock: () => void; onLockToggle: () => void;
} }
export const LayerUI = React.memo( export const LayerUI = React.memo(
@ -47,7 +47,7 @@ export const LayerUI = React.memo(
setElements, setElements,
onRoomCreate, onRoomCreate,
onRoomDestroy, onRoomDestroy,
onToggleLock, onLockToggle,
}: LayerUIProps) => { }: LayerUIProps) => {
const isMobile = useIsMobile(); const isMobile = useIsMobile();
@ -101,6 +101,7 @@ export const LayerUI = React.memo(
setAppState={setAppState} setAppState={setAppState}
onRoomCreate={onRoomCreate} onRoomCreate={onRoomCreate}
onRoomDestroy={onRoomDestroy} onRoomDestroy={onRoomDestroy}
onLockToggle={onLockToggle}
/> />
) : ( ) : (
<> <>
@ -159,9 +160,8 @@ export const LayerUI = React.memo(
</Island> </Island>
<LockIcon <LockIcon
checked={appState.elementLocked} checked={appState.elementLocked}
onChange={onToggleLock} onChange={onLockToggle}
title={t("toolBar.lock")} title={t("toolBar.lock")}
isButton={isMobile}
/> />
</Stack.Row> </Stack.Row>
</Stack.Col> </Stack.Col>

View File

@ -12,7 +12,6 @@ type LockIconProps = {
checked: boolean; checked: boolean;
onChange?(): void; onChange?(): void;
size?: LockIconSize; size?: LockIconSize;
isButton?: boolean;
}; };
const DEFAULT_SIZE: LockIconSize = "m"; const DEFAULT_SIZE: LockIconSize = "m";
@ -46,9 +45,7 @@ export function LockIcon(props: LockIconProps) {
return ( return (
<label <label
className={`ToolIcon ToolIcon__lock ${ className={`ToolIcon ToolIcon__lock ToolIcon_type_floating ${sizeCn}`}
props.isButton ? "ToolIcon_type_button" : "ToolIcon_type_floating"
} ${sizeCn}`}
title={`${props.title} ${getShortcutKey("Q")}`} title={`${props.title} ${getShortcutKey("Q")}`}
> >
<input <input

View File

@ -14,6 +14,7 @@ import { SelectedShapeActions, ShapesSwitcher } from "./Actions";
import { Section } from "./Section"; import { Section } from "./Section";
import { RoomDialog } from "./RoomDialog"; import { RoomDialog } from "./RoomDialog";
import { SCROLLBAR_WIDTH, SCROLLBAR_MARGIN } from "../scene/scrollbars"; import { SCROLLBAR_WIDTH, SCROLLBAR_MARGIN } from "../scene/scrollbars";
import { LockIcon } from "./LockIcon";
type MobileMenuProps = { type MobileMenuProps = {
appState: AppState; appState: AppState;
@ -24,6 +25,7 @@ type MobileMenuProps = {
setElements: any; setElements: any;
onRoomCreate: () => void; onRoomCreate: () => void;
onRoomDestroy: () => void; onRoomDestroy: () => void;
onLockToggle: () => void;
}; };
export function MobileMenu({ export function MobileMenu({
@ -35,6 +37,7 @@ export function MobileMenu({
setAppState, setAppState,
onRoomCreate, onRoomCreate,
onRoomDestroy, onRoomDestroy,
onLockToggle,
}: MobileMenuProps) { }: MobileMenuProps) {
return ( return (
<> <>
@ -54,6 +57,11 @@ export function MobileMenu({
/> />
</Stack.Row> </Stack.Row>
</Island> </Island>
<LockIcon
checked={appState.elementLocked}
onChange={onLockToggle}
title={t("toolBar.lock")}
/>
</Stack.Row> </Stack.Row>
</Stack.Col> </Stack.Col>
)} )}

View File

@ -106,12 +106,6 @@
} }
.ToolIcon.ToolIcon__lock { .ToolIcon.ToolIcon__lock {
&.ToolIcon_type_button {
border-radius: 4px;
svg {
position: static;
}
}
&.ToolIcon_type_floating { &.ToolIcon_type_floating {
margin-left: 0.1rem; margin-left: 0.1rem;
} }
@ -126,3 +120,32 @@
font-family: var(--ui-font); font-family: var(--ui-font);
user-select: none; 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;
}
}
}