mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-17 23:26:02 +00:00
modals rewritten
This commit is contained in:
1 parent
d42c3e9d5f
commit
196bed1a47
6 files changed
+151
-32
No files matched your search
Binary file not shown.
+44
@@ -0,0 +1,44 @@
|
||||
@import "scss/_breakpoint.scss";
|
||||
@import "scss/breakpoints.scss";
|
||||
@import "scss/colours.scss";
|
||||
|
||||
.fy-modal-layer {
|
||||
// position: absolute;
|
||||
position: fixed;
|
||||
background: rgba(#000, 0.5);
|
||||
top: 0;
|
||||
left: 0;
|
||||
height: 100vh;
|
||||
width: 100vw;
|
||||
z-index: 2000;
|
||||
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
.fy-modal-body {
|
||||
width: 100%;
|
||||
height: fit-content;
|
||||
background-color: $panel;
|
||||
border-color: lighten($panel, 8%) !important;
|
||||
border: 1px solid;
|
||||
border-radius: 0.5rem;
|
||||
box-shadow: 0px 9px 33px 1px rgba(19, 19, 27, 0.8);
|
||||
-webkit-box-shadow: 0px 9px 33px 1px rgba(19, 19, 27, 0.8);
|
||||
-moz-box-shadow: 0px 9px 33px 1px rgba(19, 19, 27, 0.8);
|
||||
|
||||
padding: 1rem;
|
||||
|
||||
max-width: 1140px;
|
||||
|
||||
@include breakpoint($under1200) {
|
||||
max-width: 800px;
|
||||
}
|
||||
|
||||
@include breakpoint($under992) {
|
||||
max-width: 100%;
|
||||
height: 100%;
|
||||
border-radius: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
import React from "react";
|
||||
import { a, easings, useTransition } from "@react-spring/web";
|
||||
import "./ModalLayer.scss";
|
||||
|
||||
interface Props {
|
||||
content?: React.ElementType | null;
|
||||
contentProps?: any;
|
||||
handleClose: () => void;
|
||||
killModal: boolean;
|
||||
modalOpen: boolean;
|
||||
onModalCloseEnd: (x: any) => void;
|
||||
}
|
||||
|
||||
export default function ModalLayer({
|
||||
content: Content,
|
||||
contentProps,
|
||||
handleClose,
|
||||
modalOpen,
|
||||
onModalCloseEnd,
|
||||
}: Props) {
|
||||
const tintTransition = useTransition(modalOpen, {
|
||||
config: {
|
||||
easing: modalOpen ? easings.easeOutQuad : easings.easeInQuad,
|
||||
duration: 175,
|
||||
},
|
||||
from: { opacity: 0 },
|
||||
enter: { opacity: 1 },
|
||||
leave: { opacity: 0 },
|
||||
onRest: onModalCloseEnd,
|
||||
});
|
||||
|
||||
return tintTransition(
|
||||
(tinter, shade) =>
|
||||
shade && (
|
||||
<a.div {...{ className: "fy-modal-layer", style: { ...tinter } }}>
|
||||
<div {...{ className: "fy-modal-body" }}>
|
||||
{Content && <Content {...{ ...contentProps, handleClose }} />}
|
||||
</div>
|
||||
</a.div>
|
||||
)
|
||||
);
|
||||
}
|
||||
+48
-23
@@ -1,40 +1,65 @@
|
||||
import React, { useState } from "react";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { ModalContext } from "context";
|
||||
import { Modal } from "components/common";
|
||||
|
||||
interface Props {
|
||||
import ModalLayer from "./ModalLayer";
|
||||
|
||||
interface ModalProviderProps {
|
||||
children?: any;
|
||||
}
|
||||
|
||||
interface ModalConfig {
|
||||
export interface ModalConfig {
|
||||
component: React.ElementType;
|
||||
props?: any;
|
||||
}
|
||||
|
||||
export default function ModalProvider({ children }: Props) {
|
||||
// how this works
|
||||
//
|
||||
// When modalState is set via open(), modalOpen is set to true to via useEffect
|
||||
// this is to separate modal rendering (modalOpen) from its state (modalState) to achieve smooth transitions.
|
||||
//
|
||||
// When close() is run, modalOpen is set to false triggering a ModalLayer transition,
|
||||
// and killModal is set to true to indicate an exiting transition.
|
||||
// When the transition is complete onModalCloseEnd() runs, and because killModal is true
|
||||
// modalState will be cleared, ensuring the state is cleared only when the modal is no longer rendered.
|
||||
|
||||
export default function ModalProvider({ children }: ModalProviderProps) {
|
||||
const [modalState, modalStateSet] = useState<ModalConfig | null>(null);
|
||||
const [modalOpen, modalOpenSet] = useState(false);
|
||||
const [killModal, killModalSet] = useState(false);
|
||||
const open = (cfg: ModalConfig) => modalStateSet(cfg);
|
||||
const close = () => modalStateSet(null);
|
||||
const close = () => {
|
||||
modalOpenSet(false);
|
||||
killModalSet(true);
|
||||
};
|
||||
const onModalCloseEnd = () => {
|
||||
if (killModal && modalState) {
|
||||
killModalSet(false);
|
||||
modalStateSet(null);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!killModal && modalState && !modalOpen) {
|
||||
modalOpenSet(true);
|
||||
}
|
||||
}, [killModal, modalOpen, modalState]);
|
||||
|
||||
return (
|
||||
<ModalContext.Provider {...{ value: { close, open, modalState } }}>
|
||||
<ModalContext.Provider
|
||||
{...{ value: { close, open, modalOpen, modalState } }}
|
||||
>
|
||||
{children}
|
||||
{
|
||||
<Modal
|
||||
{...{
|
||||
large: true,
|
||||
className: "fy-core-modal",
|
||||
content: modalState?.component,
|
||||
contentProps: modalState?.props,
|
||||
handleClose: close,
|
||||
noHeader: true,
|
||||
omitBody: true,
|
||||
show: !!modalState?.component,
|
||||
showButtons: false,
|
||||
mobileFullscreen: true,
|
||||
}}
|
||||
/>
|
||||
}
|
||||
<ModalLayer
|
||||
{...{
|
||||
content: modalState?.component,
|
||||
contentProps: modalState?.props,
|
||||
handleClose: close,
|
||||
killModal,
|
||||
modalOpen,
|
||||
modalState,
|
||||
onModalCloseEnd,
|
||||
}}
|
||||
/>
|
||||
</ModalContext.Provider>
|
||||
);
|
||||
}
|
||||
@@ -1,20 +1,26 @@
|
||||
import { createContext } from 'react';
|
||||
import { createContext } from "react";
|
||||
|
||||
export enum ModalView {
|
||||
Closed,
|
||||
Signup,
|
||||
Login
|
||||
Login,
|
||||
}
|
||||
|
||||
interface ModalConfig {
|
||||
component: React.ElementType,
|
||||
props?: any
|
||||
component: React.ElementType;
|
||||
props?: any;
|
||||
}
|
||||
|
||||
interface AccountModalContext { close: () => void, modalState: ModalConfig | null, open: (comp: any) => void }
|
||||
interface AccountModalContext {
|
||||
close: () => void;
|
||||
modalOpen: boolean;
|
||||
modalState: ModalConfig | null;
|
||||
open: (comp: any) => void;
|
||||
}
|
||||
|
||||
export default createContext<AccountModalContext>({
|
||||
close: () => {},
|
||||
open: () => {},
|
||||
modalState: null,
|
||||
});
|
||||
close: () => {},
|
||||
open: () => {},
|
||||
modalOpen: false,
|
||||
modalState: null,
|
||||
});
|
||||
@@ -1,3 +1,5 @@
|
||||
$under1280: max-width 1280px;
|
||||
$over1200: min-width 1200px;
|
||||
$under1200: max-width 1200px;
|
||||
$under992: max-width 992px;
|
||||
$over992: min-width 992px;
|
||||
Reference in new issue
Block a user