ui: mobile sexiness

This commit is contained in:
cha0s 2020-07-14 06:01:01 -05:00
parent d08a396412
commit 8cece3100f
9 changed files with 86 additions and 9 deletions

View File

@ -1,6 +1,8 @@
.app { .app {
width: 100vw; width: 100vw;
height: 100vh; height: 100vh;
overflow: hidden;
position: relative;
} }
.panes { .panes {

View File

@ -6,7 +6,9 @@ import ChatMessages from './chat--messages';
export default function ChatCenter() { export default function ChatCenter() {
return ( return (
<div className="center flexed"> <div
className="center flexed"
>
<ChatMessages /> <ChatMessages />
</div> </div>
); );

View File

@ -1,3 +1,11 @@
@import '~/client/scss/breakpoints.scss';
.center { .center {
background-color: #212121;
flex-grow: 1; flex-grow: 1;
width: 100%;
z-index: 100;
@include breakpoint(tablet) {
width: auto;
}
} }

View File

@ -7,10 +7,10 @@ import useBreakpoints from './hooks/useBreakpoints';
import Bar from './bar'; import Bar from './bar';
export default function ChatLeft() { export default function ChatLeft() {
const {desktop} = useBreakpoints(); const {desktop, tablet} = useBreakpoints();
const [isOpen, setIsOpen] = useState(false); const [isOpen, setIsOpen] = useState(false);
const toggleOpen = () => setIsOpen(!isOpen); const toggleOpen = () => setIsOpen(!isOpen);
const showsAsOpen = isOpen || desktop; const showsAsOpen = isOpen || desktop || !tablet;
const buttons = [ const buttons = [
{ {
icon: '📜', icon: '📜',

View File

@ -1,6 +1,12 @@
@import '~/client/scss/breakpoints.scss';
.left { .left {
background-color: #373737; background-color: #373737;
transform: translateX(-100%);
transition: 0.2s width; transition: 0.2s width;
@include breakpoint(tablet) {
transform: none;
}
} }
.left.open { .left.open {

View File

@ -7,10 +7,10 @@ import useBreakpoints from './hooks/useBreakpoints';
import Bar from './bar'; import Bar from './bar';
export default function ChatRight() { export default function ChatRight() {
const {desktop} = useBreakpoints(); const {desktop, tablet} = useBreakpoints();
const [isOpen, setIsOpen] = useState(false); const [isOpen, setIsOpen] = useState(false);
const toggleOpen = () => setIsOpen(!isOpen); const toggleOpen = () => setIsOpen(!isOpen);
const showsAsOpen = isOpen || desktop; const showsAsOpen = isOpen || desktop || !tablet;
const buttons = [ const buttons = [
{ {
icon: '🙃', icon: '🙃',

View File

@ -1,6 +1,13 @@
@import '~/client/scss/breakpoints.scss';
.right { .right {
background-color: #373737; background-color: #373737;
right: 0;
transform: translateX(100%);
transition: 0.2s width; transition: 0.2s width;
@include breakpoint(tablet) {
transform: none;
}
} }
.right .bar--vertical { .right .bar--vertical {

View File

@ -1,14 +1,59 @@
import './chat.scss'; import './chat.scss';
import React from 'react'; import React, {useRef} from 'react';
import useBreakpoints from './hooks/useBreakpoints';
import ChatCenter from './chat--center'; import ChatCenter from './chat--center';
import ChatLeft from './chat--left'; import ChatLeft from './chat--left';
import ChatRight from './chat--right'; import ChatRight from './chat--right';
export default function Chat() { export default function Chat() {
const ref = useRef(null);
const {tablet} = useBreakpoints();
let origin;
const onPointerEvents = {
onPointerDown: (event) => {
if (ref.current) {
origin = {
left: parseInt(ref.current.style.left, 10),
point: event.clientX,
};
}
},
onPointerMove: (event) => {
if (origin) {
ref.current.classList.add('moving');
const offset = event.clientX - origin.point + origin.left;
const max = Math.min(window.innerWidth - 32, (2 + 16) * 16);
ref.current.style.left = `${Math.max(-max, Math.min(max, offset))}px`;
}
},
onPointerUp: () => {
const left = parseInt(ref.current.style.left, 10);
const max = Math.min(window.innerWidth - 32, (2 + 16) * 16);
if (left >= max / 2) {
ref.current.style.left = `${max}px`;
}
else if (left <= -max / 2) {
ref.current.style.left = `${-max}px`;
}
else {
ref.current.style.left = 0;
}
origin = undefined;
ref.current.classList.remove('moving');
},
};
if (tablet && ref.current) {
ref.current.style.left = 0;
}
return ( return (
<div className="chat"> <div
className="chat"
// eslint-disable-next-line react/jsx-props-no-spreading
{...(tablet ? {} : onPointerEvents)}
ref={ref}
>
<ChatLeft /> <ChatLeft />
<ChatCenter /> <ChatCenter />
<ChatRight /> <ChatRight />

View File

@ -3,15 +3,22 @@
.chat { .chat {
display: flex; display: flex;
height: 100%; height: 100%;
position: absolute;
width: 100%; width: 100%;
&:not(.moving) {
transition: 0.2s left;
}
} }
.flexed { .flexed {
display: none; position: absolute;
height: 100%; height: 100%;
width: 4em; width: 4em;
overflow: hidden; overflow: hidden;
&:not(.center) {
max-width: calc(100% - 2em);
}
@include breakpoint(tablet) { @include breakpoint(tablet) {
display: block; position: static;
} }
} }