2021-03-23 17:54:30 +03:00
|
|
|
import * as React from "react";
|
2021-03-07 23:53:54 +03:00
|
|
|
import * as Strings from "~/common/strings";
|
2021-03-23 17:54:30 +03:00
|
|
|
|
|
|
|
import { css } from "@emotion/react";
|
|
|
|
|
2021-06-09 01:53:30 +03:00
|
|
|
import { useFont, useFontControls } from "~/components/core/FontFrame/hooks";
|
|
|
|
import { Controls } from "~/components/core/FontFrame/Settings/index";
|
|
|
|
import {
|
|
|
|
FixedControls,
|
|
|
|
MobileFixedControls,
|
|
|
|
} from "~/components/core/FontFrame/Settings/FixedControls";
|
|
|
|
import FontView from "~/components/core/FontFrame/Views/index";
|
2021-03-23 17:54:30 +03:00
|
|
|
|
2021-03-24 20:55:12 +03:00
|
|
|
const GET_STYLES_CONTAINER = (theme) => css`
|
2021-03-23 17:54:30 +03:00
|
|
|
position: relative;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
2021-07-07 22:58:14 +03:00
|
|
|
background-color: ${theme.fontPreviewDarkMode ? theme.system.black : theme.system.white};
|
2021-03-24 20:55:12 +03:00
|
|
|
padding-top: 14px;
|
2021-03-23 17:54:30 +03:00
|
|
|
`;
|
2021-03-30 17:21:54 +03:00
|
|
|
|
2021-03-26 21:30:02 +03:00
|
|
|
const STYLES_MOBILE_HIDDEN = (theme) => css`
|
|
|
|
@media (max-width: ${theme.sizes.mobile}px) {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_MOBILE_ONLY = (theme) => css`
|
|
|
|
@media (min-width: ${theme.sizes.mobile}px) {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
`;
|
2021-03-23 17:54:30 +03:00
|
|
|
|
2021-03-30 17:21:54 +03:00
|
|
|
const STYLES_FONT_LOADER = (theme) => css`
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
position: absolute;
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
color: ${theme.fontPreviewDarkMode ? "#fff" : "#000"};
|
|
|
|
background-color: ${theme.fontPreviewDarkMode ? "rgba(0,0,0,0.5)" : "rgba(255,255,255,0.8)"};
|
|
|
|
`;
|
|
|
|
const FontLoader = () => (
|
|
|
|
<div css={STYLES_FONT_LOADER}>
|
|
|
|
<p>loading...</p>
|
|
|
|
</div>
|
|
|
|
);
|
2021-03-07 23:53:54 +03:00
|
|
|
export default function FontFrame({ cid, fallback, ...props }) {
|
|
|
|
const url = Strings.getURLfromCID(cid);
|
|
|
|
const { isFontLoading, error, fontName } = useFont({ cid }, [cid, url]);
|
2021-04-08 22:00:09 +03:00
|
|
|
|
2021-03-24 20:55:12 +03:00
|
|
|
const [
|
|
|
|
currentState,
|
|
|
|
{
|
2021-03-24 22:04:51 +03:00
|
|
|
updateView,
|
2021-03-24 20:55:12 +03:00
|
|
|
setLightMode,
|
|
|
|
setDarkMode,
|
|
|
|
toggleSettings,
|
|
|
|
updateFontSize,
|
|
|
|
updateLineHeight,
|
|
|
|
updateTracking,
|
|
|
|
updateColumn,
|
|
|
|
updateTextAlign,
|
|
|
|
updateVerticalAlign,
|
2021-03-30 17:21:54 +03:00
|
|
|
updateCustomView,
|
2021-03-26 21:30:02 +03:00
|
|
|
resetLayout,
|
|
|
|
getRandomLayout,
|
2021-03-24 20:55:12 +03:00
|
|
|
},
|
|
|
|
] = useFontControls();
|
2021-03-23 17:54:30 +03:00
|
|
|
|
2021-04-08 22:00:09 +03:00
|
|
|
if (error) {
|
|
|
|
return fallback;
|
|
|
|
}
|
|
|
|
|
2021-03-23 17:54:30 +03:00
|
|
|
return (
|
2021-03-24 20:55:12 +03:00
|
|
|
<div css={GET_STYLES_CONTAINER} style={{ fontFamily: fontName }} {...props}>
|
2021-03-26 21:30:02 +03:00
|
|
|
<div css={STYLES_MOBILE_HIDDEN}>
|
|
|
|
<FixedControls
|
|
|
|
onDarkMode={setDarkMode}
|
|
|
|
onLightMode={setLightMode}
|
|
|
|
onToggleSettings={toggleSettings}
|
|
|
|
isDarkMode={currentState.context.darkmode}
|
|
|
|
isSettingsVisible={currentState.context.showSettings}
|
|
|
|
/>
|
|
|
|
</div>
|
2021-05-27 11:20:34 +03:00
|
|
|
<div style={{ position: "relative", flexGrow: 1, overflowY: "auto" }}>
|
2021-03-30 17:21:54 +03:00
|
|
|
{isFontLoading && <FontLoader />}
|
|
|
|
<FontView
|
|
|
|
view={currentState.view}
|
2021-03-31 22:00:12 +03:00
|
|
|
content={{
|
|
|
|
paragraph: currentState.context.paragraph,
|
|
|
|
sentence: currentState.context.sentence,
|
|
|
|
custom: currentState.context.customViewContent,
|
|
|
|
}}
|
2021-03-30 17:21:54 +03:00
|
|
|
customView={currentState.customView}
|
|
|
|
settings={currentState.context.settings}
|
|
|
|
updateCustomView={updateCustomView}
|
|
|
|
/>
|
2021-03-24 20:55:12 +03:00
|
|
|
</div>
|
2021-03-26 21:30:02 +03:00
|
|
|
<div css={STYLES_MOBILE_HIDDEN}>
|
|
|
|
{currentState.context.showSettings && (
|
|
|
|
<Controls
|
|
|
|
view={currentState.view}
|
2021-04-01 17:05:51 +03:00
|
|
|
customView={currentState.customView}
|
2021-03-26 21:30:02 +03:00
|
|
|
defaultOptions={currentState.defaultOptions}
|
|
|
|
resetLayout={resetLayout}
|
|
|
|
updateView={updateView}
|
|
|
|
settings={currentState.context.settings}
|
|
|
|
updateFontSize={updateFontSize}
|
|
|
|
updateLineHeight={updateLineHeight}
|
|
|
|
updateTracking={updateTracking}
|
|
|
|
updateColumn={updateColumn}
|
|
|
|
updateTextAlign={updateTextAlign}
|
|
|
|
updateVerticalAlign={updateVerticalAlign}
|
|
|
|
getRandomLayout={getRandomLayout}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
<div css={STYLES_MOBILE_ONLY}>
|
|
|
|
<MobileFixedControls
|
2021-03-24 22:04:51 +03:00
|
|
|
view={currentState.view}
|
2021-03-26 21:30:02 +03:00
|
|
|
defaultOptions={currentState.defaultOptions}
|
2021-03-24 22:04:51 +03:00
|
|
|
updateView={updateView}
|
2021-03-26 21:30:02 +03:00
|
|
|
onDarkMode={setDarkMode}
|
|
|
|
onLightMode={setLightMode}
|
2021-03-24 22:04:51 +03:00
|
|
|
/>
|
2021-03-26 21:30:02 +03:00
|
|
|
</div>
|
2021-03-23 17:54:30 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|