🚀 release v3.0.0

This commit is contained in:
Amruth Pillai
2022-03-06 22:48:29 +01:00
parent 00505a9e5d
commit 9c1380f401
373 changed files with 12050 additions and 15783 deletions

View File

@ -0,0 +1,50 @@
.container {
@apply h-screen w-[95vw] md:w-[70vw] lg:w-[50vw] xl:w-[30vw] 2xl:w-[28vw];
@apply bg-neutral-50 text-neutral-900 dark:bg-neutral-900 dark:text-neutral-50;
@apply relative flex border-l-2 border-neutral-50/10;
nav {
@apply absolute inset-y-0 right-0;
@apply w-12 py-4 md:w-16 md:px-2;
@apply bg-neutral-100 shadow dark:bg-neutral-800;
@apply flex flex-col items-center justify-between;
hr {
@apply mt-2;
}
> div {
@apply grid gap-2;
}
.sections svg {
@apply opacity-75 transition-opacity hover:opacity-100;
}
}
main {
@apply overflow-y-scroll p-4;
@apply absolute inset-y-0 right-12 left-0 md:right-16;
> section {
@apply grid gap-4;
@apply pt-5 pb-7 first:pt-0;
@apply border-b border-neutral-900/10 last:border-b-0 dark:border-neutral-50/10;
hr {
@apply my-2;
}
}
-ms-overflow-style: none;
&::-webkit-scrollbar {
display: none;
}
}
.footer {
@apply flex flex-col items-center justify-center gap-3 py-4;
@apply text-center text-xs leading-normal opacity-40;
}
}

View File

@ -0,0 +1,86 @@
import { Divider, IconButton, SwipeableDrawer, Tooltip, useMediaQuery, useTheme } from '@mui/material';
import { capitalize } from 'lodash';
import { useTranslation } from 'next-i18next';
import Avatar from '@/components/shared/Avatar';
import Footer from '@/components/shared/Footer';
import { right } from '@/config/sections';
import { setSidebarState } from '@/store/build/buildSlice';
import { useAppDispatch, useAppSelector } from '@/store/hooks';
import styles from './RightSidebar.module.scss';
const RightSidebar = () => {
const theme = useTheme();
const { t } = useTranslation();
const dispatch = useAppDispatch();
const isDesktop = useMediaQuery(theme.breakpoints.up('lg'));
const { open } = useAppSelector((state) => state.build.sidebar.right);
const handleOpen = () => dispatch(setSidebarState({ sidebar: 'right', state: { open: true } }));
const handleClose = () => dispatch(setSidebarState({ sidebar: 'right', state: { open: false } }));
const handleClick = (id: string) => {
const section = document.querySelector(`#${id}`);
if (section) {
section.scrollIntoView({ behavior: 'smooth', block: 'start' });
}
};
return (
<SwipeableDrawer
open={open}
anchor="right"
onOpen={handleOpen}
onClose={handleClose}
PaperProps={{ className: '!shadow-lg' }}
variant={isDesktop ? 'persistent' : 'temporary'}
>
<div className={styles.container}>
<nav>
<div>
<Avatar size={40} />
<Divider />
</div>
<div className={styles.sections}>
{right.map(({ id, icon }) => (
<Tooltip
key={id}
arrow
placement="right"
title={t<string>(`builder.rightSidebar.sections.${id}.heading`, { defaultValue: capitalize(id) })}
>
<IconButton onClick={() => handleClick(id)}>{icon}</IconButton>
</Tooltip>
))}
</div>
<div />
</nav>
<main>
{right.map(({ id, component }) => (
<section key={id} id={id}>
{component}
</section>
))}
<footer className={styles.footer}>
<Footer />
<div>v{process.env.appVersion}</div>
</footer>
</main>
</div>
</SwipeableDrawer>
);
};
export default RightSidebar;

View File

@ -0,0 +1,49 @@
import Editor from '@monaco-editor/react';
import { useTheme } from '@mui/material';
import { CustomCSS as CustomCSSType } from '@reactive-resume/schema';
import clsx from 'clsx';
import get from 'lodash/get';
import { useTranslation } from 'next-i18next';
import React from 'react';
import Heading from '@/components/shared/Heading';
import { useAppDispatch, useAppSelector } from '@/store/hooks';
import { setResumeState } from '@/store/resume/resumeSlice';
const CustomCSS = () => {
const theme = useTheme();
const { t } = useTranslation();
const dispatch = useAppDispatch();
const customCSS: CustomCSSType = useAppSelector((state) => get(state.resume, 'metadata.css', {}));
const handleChange = (value: string | undefined) => {
dispatch(setResumeState({ path: 'metadata.css.value', value }));
};
return (
<>
<Heading path="metadata.css" name={t('builder.rightSidebar.sections.css.heading')} isHideable />
<Editor
height="200px"
language="css"
value={customCSS.value}
onChange={handleChange}
className={clsx({ 'opacity-50': !customCSS.visible })}
theme={theme.palette.mode === 'dark' ? 'vs-dark' : 'light'}
options={{
minimap: { enabled: false },
overviewRulerLanes: 0,
scrollBeyondLastColumn: 5,
overviewRulerBorder: false,
scrollBeyondLastLine: true,
}}
/>
</>
);
};
export default CustomCSS;

View File

@ -0,0 +1,81 @@
import { PictureAsPdf, Schema } from '@mui/icons-material';
import { List, ListItem, ListItemButton, ListItemText } from '@mui/material';
import get from 'lodash/get';
import pick from 'lodash/pick';
import { useTranslation } from 'next-i18next';
import { useMutation } from 'react-query';
import Heading from '@/components/shared/Heading';
import { ServerError } from '@/services/axios';
import { printResumeAsPdf, PrintResumeAsPdfParams } from '@/services/printer';
import { useAppSelector } from '@/store/hooks';
const Export = () => {
const { t } = useTranslation();
const resume = useAppSelector((state) => state.resume);
const { mutateAsync, isLoading } = useMutation<string, ServerError, PrintResumeAsPdfParams>(printResumeAsPdf);
const pdfListItemText = {
normal: {
primary: t('builder.rightSidebar.sections.export.pdf.normal.primary'),
secondary: t('builder.rightSidebar.sections.export.pdf.normal.secondary'),
},
loading: {
primary: t('builder.rightSidebar.sections.export.pdf.loading.primary'),
secondary: t('builder.rightSidebar.sections.export.pdf.loading.secondary'),
},
};
const handleExportJSON = async () => {
const { nanoid } = await import('nanoid');
const download = (await import('downloadjs')).default;
const redactedResume = pick(resume, ['basics', 'sections', 'metadata', 'public']);
const jsonString = JSON.stringify(redactedResume, null, 4);
const filename = `RxResume_JSONExport_${nanoid()}.json`;
download(jsonString, filename, 'application/json');
};
const handleExportPDF = async () => {
const download = (await import('downloadjs')).default;
const slug = get(resume, 'slug');
const username = get(resume, 'user.username');
const url = await mutateAsync({ username, slug });
download(url);
};
return (
<>
<Heading path="metadata.export" name={t('builder.rightSidebar.sections.export.heading')} />
<List sx={{ padding: 0 }}>
<ListItem sx={{ padding: 0 }}>
<ListItemButton className="gap-6" onClick={handleExportJSON}>
<Schema />
<ListItemText
primary={t('builder.rightSidebar.sections.export.json.primary')}
secondary={t('builder.rightSidebar.sections.export.json.secondary')}
/>
</ListItemButton>
</ListItem>
<ListItem sx={{ padding: 0 }}>
<ListItemButton className="gap-6" onClick={handleExportPDF} disabled={isLoading}>
<PictureAsPdf />
<ListItemText {...(isLoading ? pdfListItemText.loading : pdfListItemText.normal)} />
</ListItemButton>
</ListItem>
</List>
</>
);
};
export default Export;

View File

@ -0,0 +1,43 @@
.page {
@apply relative border pl-4 pb-4 dark:border-neutral-100/10;
@apply rounded bg-neutral-100 dark:bg-neutral-800;
.delete {
@apply opacity-50 hover:opacity-75;
@apply rotate-0 hover:rotate-90;
@apply transition-[opacity,transform];
}
.container {
@apply grid grid-cols-2 gap-2;
}
.heading {
@apply relative z-10 my-3;
@apply text-xs font-semibold;
}
}
.column {
@apply relative w-full px-4;
.heading {
@apply relative z-10 my-3;
@apply text-xs font-semibold;
}
.base {
@apply absolute inset-0 w-4/5;
@apply rounded bg-neutral-200 dark:bg-neutral-700;
}
}
.section {
@apply relative my-3 w-full px-4 py-2;
@apply cursor-move break-all rounded text-xs capitalize;
@apply bg-neutral-800/90 text-neutral-50 dark:bg-neutral-50/90 dark:text-neutral-800;
&.disabled {
@apply opacity-60;
}
}

View File

@ -0,0 +1,143 @@
import { Add, Close, Restore } from '@mui/icons-material';
import { Button, IconButton, Tooltip } from '@mui/material';
import clsx from 'clsx';
import cloneDeep from 'lodash/cloneDeep';
import get from 'lodash/get';
import { useTranslation } from 'next-i18next';
import { DragDropContext, Draggable, DraggableLocation, Droppable, DropResult } from 'react-beautiful-dnd';
import Heading from '@/components/shared/Heading';
import { useAppDispatch, useAppSelector } from '@/store/hooks';
import { addPage, deletePage, setResumeState } from '@/store/resume/resumeSlice';
import styles from './Layout.module.scss';
const getIndices = (location: DraggableLocation) => ({
page: +location.droppableId.split('.')[0],
column: +location.droppableId.split('.')[1],
section: +location.index,
});
const Layout = () => {
const { t } = useTranslation();
const dispatch = useAppDispatch();
const layout = useAppSelector((state) => state.resume.metadata.layout);
const resumeSections = useAppSelector((state) => state.resume.sections);
const onDragEnd = (dropResult: DropResult) => {
const { source: srcLoc, destination: destLoc } = dropResult;
if (!destLoc) return;
const newLayout = cloneDeep(layout);
const srcIndex = getIndices(srcLoc);
const destIndex = getIndices(destLoc);
const section = layout[srcIndex.page][srcIndex.column][srcIndex.section];
// Remove item at source
newLayout[srcIndex.page][srcIndex.column].splice(srcIndex.section, 1);
// Insert item at destination
newLayout[destIndex.page][destIndex.column].splice(destIndex.section, 0, section);
dispatch(setResumeState({ path: 'metadata.layout', value: newLayout }));
};
const handleAddPage = () => dispatch(addPage());
const handleDeletePage = (page: number) => dispatch(deletePage({ page }));
const handleResetLayout = () => {
for (let i = layout.length - 1; i > 0; i--) {
handleDeletePage(i);
}
};
return (
<>
<Heading
path="metadata.layout"
name={t('builder.rightSidebar.sections.layout.heading')}
action={
<Tooltip title={t<string>('builder.rightSidebar.sections.layout.tooltip.reset-layout')}>
<IconButton onClick={handleResetLayout}>
<Restore />
</IconButton>
</Tooltip>
}
/>
<DragDropContext onDragEnd={onDragEnd}>
{/* Pages */}
{layout.map((columns, pageIndex) => (
<div key={pageIndex} className={styles.page}>
<div className="flex items-center justify-between pr-3">
<p className={styles.heading}>
{t('builder.common.glossary.page')} {pageIndex + 1}
</p>
<div className={clsx(styles.delete, { hidden: pageIndex === 0 })}>
<Tooltip
title={t<string>('builder.common.actions.delete', { token: t('builder.common.glossary.page') })}
>
<IconButton size="small" onClick={() => handleDeletePage(pageIndex)}>
<Close fontSize="small" />
</IconButton>
</Tooltip>
</div>
</div>
<div className={styles.container}>
{/* Sections */}
{columns.map((sections, columnIndex) => {
const index = `${pageIndex}.${columnIndex}`;
return (
<Droppable key={index} droppableId={index}>
{(provided) => (
<div ref={provided.innerRef} className={styles.column} {...provided.droppableProps}>
<p className={styles.heading}>{columnIndex ? 'Sidebar' : 'Main'}</p>
<div className={styles.base} />
{/* Sections */}
{sections.map((sectionId, sectionIndex) => (
<Draggable key={sectionId} draggableId={sectionId} index={sectionIndex}>
{(provided) => (
<div ref={provided.innerRef} {...provided.draggableProps} {...provided.dragHandleProps}>
<div
className={clsx(styles.section, {
[styles.disabled]: !get(resumeSections, `${sectionId}.visible`, true),
})}
>
{get(resumeSections, `${sectionId}.name`)}
</div>
</div>
)}
</Draggable>
))}
{provided.placeholder}
</div>
)}
</Droppable>
);
})}
</div>
</div>
))}
<div className="flex items-center justify-end">
<Button variant="outlined" startIcon={<Add />} onClick={handleAddPage}>
{t('builder.common.actions.add', { token: t('builder.common.glossary.page') })}
</Button>
</div>
</DragDropContext>
</>
);
};
export default Layout;

View File

@ -0,0 +1,20 @@
.container {
@apply grid gap-4;
.section {
@apply grid gap-2 rounded p-6;
@apply bg-neutral-100 dark:bg-neutral-800;
h2 {
@apply inline-flex items-center gap-2 text-base font-medium;
}
p {
@apply mb-3 text-xs leading-loose;
}
}
a {
@apply hover:no-underline;
}
}

View File

@ -0,0 +1,56 @@
import { BugReport, Coffee, GitHub, Link, Savings } from '@mui/icons-material';
import { Button } from '@mui/material';
import { useTranslation } from 'next-i18next';
import Heading from '@/components/shared/Heading';
import { DONATION_URL, GITHUB_ISSUES_URL, GITHUB_URL } from '@/constants/index';
import styles from './Links.module.scss';
const Links = () => {
const { t } = useTranslation();
return (
<>
<Heading path="metadata.links" name={t('builder.rightSidebar.sections.links.heading')} />
<div className={styles.container}>
<div className={styles.section}>
<h2>
<Savings fontSize="small" />
{t('builder.rightSidebar.sections.links.donate.heading')}
</h2>
<p>{t('builder.rightSidebar.sections.links.donate.body')}</p>
<a href={DONATION_URL} target="_blank" rel="noreferrer">
<Button startIcon={<Coffee />}>{t('builder.rightSidebar.sections.links.donate.button')}</Button>
</a>
</div>
<div className={styles.section}>
<h2>
<BugReport fontSize="small" />
{t('builder.rightSidebar.sections.links.bugs-features.heading')}
</h2>
<p>{t('builder.rightSidebar.sections.links.bugs-features.body')}</p>
<a href={GITHUB_ISSUES_URL} target="_blank" rel="noreferrer">
<Button startIcon={<GitHub />}>{t('builder.rightSidebar.sections.links.bugs-features.button')}</Button>
</a>
</div>
<div>
<a href={GITHUB_URL} target="_blank" rel="noreferrer">
<Button variant="text" startIcon={<Link />}>
{t('builder.rightSidebar.sections.links.github')}
</Button>
</a>
</div>
</div>
</>
);
};
export default Links;

View File

@ -0,0 +1,199 @@
import { Anchor, DeleteForever, Palette } from '@mui/icons-material';
import {
Autocomplete,
List,
ListItem,
ListItemButton,
ListItemIcon,
ListItemText,
ListSubheader,
Switch,
TextField,
} from '@mui/material';
import { DateConfig, Resume } from '@reactive-resume/schema';
import dayjs from 'dayjs';
import get from 'lodash/get';
import { useTranslation } from 'next-i18next';
import { useMemo } from 'react';
import { useMutation } from 'react-query';
import Heading from '@/components/shared/Heading';
import ThemeSwitch from '@/components/shared/ThemeSwitch';
import { Language, languageMap, languages } from '@/config/languages';
import { ServerError } from '@/services/axios';
import queryClient from '@/services/react-query';
import { loadSampleData, LoadSampleDataParams, resetResume, ResetResumeParams } from '@/services/resume';
import { setTheme, togglePageBreakLine, togglePageOrientation } from '@/store/build/buildSlice';
import { useAppDispatch, useAppSelector } from '@/store/hooks';
import { setResumeState } from '@/store/resume/resumeSlice';
import { dateFormatOptions } from '@/utils/date';
const Settings = () => {
const { t } = useTranslation();
const dispatch = useAppDispatch();
const resume = useAppSelector((state) => state.resume);
const theme = useAppSelector((state) => state.build.theme);
const breakLine = useAppSelector((state) => state.build.page.breakLine);
const orientation = useAppSelector((state) => state.build.page.orientation);
const id: number = useMemo(() => get(resume, 'id'), [resume]);
const slug: string = useMemo(() => get(resume, 'slug'), [resume]);
const username: string = useMemo(() => get(resume, 'user.username'), [resume]);
const language: string = useMemo(() => get(resume, 'metadata.language'), [resume]);
const dateConfig: DateConfig = useMemo(() => get(resume, 'metadata.date'), [resume]);
const isDarkMode = useMemo(() => theme === 'dark', [theme]);
const exampleString = useMemo(() => `Eg. ${dayjs().format(dateConfig.format)}`, [dateConfig.format]);
const themeString = useMemo(() => (isDarkMode ? 'Matte Black Everything' : 'As bright as your future'), [isDarkMode]);
const { mutateAsync: loadSampleDataMutation } = useMutation<Resume, ServerError, LoadSampleDataParams>(
loadSampleData
);
const { mutateAsync: resetResumeMutation } = useMutation<Resume, ServerError, ResetResumeParams>(resetResume);
const handleSetTheme = (value: boolean) => dispatch(setTheme({ theme: value ? 'dark' : 'light' }));
const handleChangeDateFormat = (value: string | null) =>
dispatch(setResumeState({ path: 'metadata.date.format', value }));
const handleChangeLanguage = (value: Language | null) =>
dispatch(setResumeState({ path: 'metadata.language', value: value?.code }));
const handleLoadSampleData = async () => {
await loadSampleDataMutation({ id });
queryClient.invalidateQueries(`resume/${username}/${slug}`);
};
const handleResetResume = async () => {
await resetResumeMutation({ id });
queryClient.invalidateQueries(`resume/${username}/${slug}`);
};
return (
<>
<Heading path="metadata.settings" name={t('builder.rightSidebar.sections.settings.heading')} />
<List sx={{ padding: 0 }}>
{/* Global Settings */}
<>
<ListSubheader className="rounded">
{t('builder.rightSidebar.sections.settings.global.heading')}
</ListSubheader>
<ListItem>
<ListItemIcon>
<Palette />
</ListItemIcon>
<ListItemText
primary={t('builder.rightSidebar.sections.settings.global.theme.primary')}
secondary={themeString}
/>
<ThemeSwitch checked={isDarkMode} onChange={(_, value: boolean) => handleSetTheme(value)} />
</ListItem>
<ListItem className="flex-col">
<ListItemText
className="w-full"
primary={t('builder.rightSidebar.sections.settings.global.date.primary')}
secondary={t('builder.rightSidebar.sections.settings.global.date.secondary')}
/>
<Autocomplete<string, false, boolean, false>
disableClearable
className="my-2 w-full"
options={dateFormatOptions}
value={dateConfig.format}
onChange={(_, value) => handleChangeDateFormat(value)}
renderInput={(params) => <TextField {...params} helperText={exampleString} />}
/>
</ListItem>
<ListItem className="flex-col">
<ListItemText
className="w-full"
primary={t('builder.rightSidebar.sections.settings.global.language.primary')}
secondary={t('builder.rightSidebar.sections.settings.global.language.secondary')}
/>
<Autocomplete<Language, false, boolean, false>
disableClearable
className="my-2 w-full"
options={languages}
value={languageMap[language]}
getOptionLabel={(language) => {
if (language.localName) {
return `${language.name} (${language.localName})`;
}
return language.name;
}}
isOptionEqualToValue={(a, b) => a.code === b.code}
onChange={(_, value) => handleChangeLanguage(value)}
renderInput={(params) => <TextField {...params} />}
/>
</ListItem>
</>
{/* Page Settings */}
<>
<ListSubheader className="rounded">{t('builder.rightSidebar.sections.settings.page.heading')}</ListSubheader>
<ListItem>
<ListItemText
primary={t('builder.rightSidebar.sections.settings.page.orientation.primary')}
secondary={t('builder.rightSidebar.sections.settings.page.orientation.secondary')}
/>
<Switch
color="secondary"
checked={orientation === 'horizontal'}
onChange={() => dispatch(togglePageOrientation())}
/>
</ListItem>
<ListItem>
<ListItemText
primary={t('builder.rightSidebar.sections.settings.page.break-line.primary')}
secondary={t('builder.rightSidebar.sections.settings.page.break-line.secondary')}
/>
<Switch color="secondary" checked={breakLine} onChange={() => dispatch(togglePageBreakLine())} />
</ListItem>
</>
{/* Resume Settings */}
<>
<ListSubheader className="rounded">
{t('builder.rightSidebar.sections.settings.resume.heading')}
</ListSubheader>
<ListItem>
<ListItemButton onClick={handleLoadSampleData}>
<ListItemIcon>
<Anchor />
</ListItemIcon>
<ListItemText
primary={t('builder.rightSidebar.sections.settings.resume.sample.primary')}
secondary={t('builder.rightSidebar.sections.settings.resume.sample.secondary')}
/>
</ListItemButton>
</ListItem>
<ListItem>
<ListItemButton onClick={handleResetResume}>
<ListItemIcon>
<DeleteForever />
</ListItemIcon>
<ListItemText
primary={t('builder.rightSidebar.sections.settings.resume.reset.primary')}
secondary={t('builder.rightSidebar.sections.settings.resume.reset.secondary')}
/>
</ListItemButton>
</ListItem>
</>
</List>
</>
);
};
export default Settings;

View File

@ -0,0 +1,78 @@
import { CopyAll } from '@mui/icons-material';
import { Checkbox, FormControlLabel, IconButton, List, ListItem, ListItemText, Switch, TextField } from '@mui/material';
import get from 'lodash/get';
import { useTranslation } from 'next-i18next';
import { useMemo, useState } from 'react';
import toast from 'react-hot-toast';
import Heading from '@/components/shared/Heading';
import { useAppDispatch, useAppSelector } from '@/store/hooks';
import { setResumeState } from '@/store/resume/resumeSlice';
import getResumeUrl from '@/utils/getResumeUrl';
const Sharing = () => {
const { t } = useTranslation();
const dispatch = useAppDispatch();
const [showShortUrl, setShowShortUrl] = useState(false);
const resume = useAppSelector((state) => state.resume);
const isPublic = useMemo(() => get(resume, 'public'), [resume]);
const url = useMemo(() => getResumeUrl(resume, { withHost: true }), [resume]);
const shortUrl = useMemo(() => getResumeUrl(resume, { withHost: true, shortUrl: true }), [resume]);
const handleSetVisibility = (value: boolean) => dispatch(setResumeState({ path: 'public', value }));
const handleCopyToClipboard = async () => {
const text = showShortUrl ? shortUrl : url;
await navigator.clipboard.writeText(text);
toast.success(t('common.toast.success.resume-link-copied'));
};
return (
<>
<Heading path="metadata.sharing" name={t('builder.rightSidebar.sections.sharing.heading')} />
<List sx={{ padding: 0 }}>
<ListItem className="flex flex-col" sx={{ padding: 0 }}>
<div className="flex w-full items-center justify-between">
<ListItemText
primary={t('builder.rightSidebar.sections.sharing.visibility.title')}
secondary={t('builder.rightSidebar.sections.sharing.visibility.subtitle')}
/>
<Switch color="secondary" checked={isPublic} onChange={(_, value) => handleSetVisibility(value)} />
</div>
<div className="mt-2 w-full">
<TextField
disabled
fullWidth
value={showShortUrl ? shortUrl : url}
InputProps={{
endAdornment: (
<IconButton onClick={handleCopyToClipboard}>
<CopyAll />
</IconButton>
),
}}
/>
</div>
<div className="mt-1 flex w-full">
<FormControlLabel
label={t<string>('builder.rightSidebar.sections.sharing.short-url.label')}
control={
<Checkbox className="mr-1" checked={showShortUrl} onChange={(_, value) => setShowShortUrl(value)} />
}
/>
</div>
</ListItem>
</List>
</>
);
};
export default Sharing;

View File

@ -0,0 +1,22 @@
.container {
@apply grid grid-cols-2 gap-4;
}
.template {
@apply grid text-center;
.preview {
aspect-ratio: 1 / 1.4142;
@apply relative grid rounded;
@apply border-2 border-transparent;
&.selected {
@apply border-black dark:border-white;
}
}
.label {
@apply mt-1 text-xs font-medium;
}
}

View File

@ -0,0 +1,46 @@
import { ButtonBase } from '@mui/material';
import clsx from 'clsx';
import get from 'lodash/get';
import Image from 'next/image';
import { useTranslation } from 'next-i18next';
import Heading from '@/components/shared/Heading';
import { useAppDispatch, useAppSelector } from '@/store/hooks';
import { setResumeState } from '@/store/resume/resumeSlice';
import templateMap, { TemplateMeta } from '@/templates/templateMap';
import styles from './Templates.module.scss';
const Templates = () => {
const { t } = useTranslation();
const dispatch = useAppDispatch();
const currentTemplate: string = useAppSelector((state) => get(state.resume, 'metadata.template'));
const handleChange = (template: TemplateMeta) => {
dispatch(setResumeState({ path: 'metadata.template', value: template.id }));
};
return (
<>
<Heading path="metadata.templates" name={t('builder.rightSidebar.sections.templates.heading')} />
<div className={styles.container}>
{Object.values(templateMap).map((template) => (
<div key={template.id} className={styles.template}>
<div className={clsx(styles.preview, { [styles.selected]: template.id === currentTemplate })}>
<ButtonBase onClick={() => handleChange(template)}>
<Image src={template.preview} alt={template.name} className="rounded-sm" layout="fill" />
</ButtonBase>
</div>
<p className={styles.label}>{template.name}</p>
</div>
))}
</div>
</>
);
};
export default Templates;

View File

@ -0,0 +1,8 @@
.container {
@apply grid sm:grid-cols-2 gap-4;
}
.colorOptions {
@apply col-span-2 mb-4;
@apply grid grid-cols-8 gap-y-2 justify-items-center;
}

View File

@ -0,0 +1,57 @@
import { Theme } from '@reactive-resume/schema';
import get from 'lodash/get';
import { useTranslation } from 'next-i18next';
import ColorAvatar from '@/components/shared/ColorAvatar';
import ColorPicker from '@/components/shared/ColorPicker';
import Heading from '@/components/shared/Heading';
import { colorOptions } from '@/config/colors';
import { useAppDispatch, useAppSelector } from '@/store/hooks';
import { setResumeState } from '@/store/resume/resumeSlice';
import styles from './Theme.module.scss';
const Theme = () => {
const { t } = useTranslation();
const dispatch = useAppDispatch();
const { background, text, primary } = useAppSelector<Theme>((state) => get(state.resume, 'metadata.theme'));
const handleChange = (property: string, color: string) => {
dispatch(setResumeState({ path: `metadata.theme.${property}`, value: color }));
};
return (
<>
<Heading path="metadata.theme" name={t('builder.rightSidebar.sections.theme.heading')} />
<div className={styles.container}>
<div className={styles.colorOptions}>
{colorOptions.map((color) => (
<ColorAvatar key={color} color={color} onClick={(color) => handleChange('primary', color)} />
))}
</div>
<ColorPicker
label={t('builder.rightSidebar.sections.theme.form.primary.label')}
color={primary}
className="col-span-2"
onChange={(color) => handleChange('primary', color)}
/>
<ColorPicker
label={t('builder.rightSidebar.sections.theme.form.background.label')}
color={background}
onChange={(color) => handleChange('background', color)}
/>
<ColorPicker
label={t('builder.rightSidebar.sections.theme.form.text.label')}
color={text}
onChange={(color) => handleChange('text', color)}
/>
</div>
</>
);
};
export default Theme;

View File

@ -0,0 +1,11 @@
.container {
@apply grid gap-4 xl:grid-cols-2;
}
.subheading {
@apply mt-2 font-medium;
}
.slider {
@apply px-6;
}

View File

@ -0,0 +1,106 @@
import { Autocomplete, Skeleton, Slider, TextField } from '@mui/material';
import { Font, TypeCategory, TypeProperty, Typography as TypographyType } from '@reactive-resume/schema';
import get from 'lodash/get';
import isEmpty from 'lodash/isEmpty';
import { useTranslation } from 'next-i18next';
import { useQuery } from 'react-query';
import Heading from '@/components/shared/Heading';
import { FONTS_QUERY } from '@/constants/index';
import { fetchFonts } from '@/services/fonts';
import { useAppDispatch, useAppSelector } from '@/store/hooks';
import { setResumeState } from '@/store/resume/resumeSlice';
import styles from './Typography.module.scss';
const TypographySkeleton: React.FC = () => (
<>
<Skeleton variant="text" />
<div className={styles.container}>
<Skeleton variant="rectangular" height={60} />
<Skeleton variant="rectangular" height={60} />
</div>
</>
);
type WidgetProps = {
label: string;
category: TypeCategory;
};
const Widgets: React.FC<WidgetProps> = ({ label, category }) => {
const { t } = useTranslation();
const dispatch = useAppDispatch();
const { family, size } = useAppSelector<TypographyType>((state) => get(state.resume, 'metadata.typography'));
const { data: fonts } = useQuery(FONTS_QUERY, fetchFonts, {
select: (fonts) => fonts.sort((a, b) => a.category.localeCompare(b.category)),
});
const handleChange = (property: TypeProperty, value: number | number[] | Font | null) => {
if (!value) return;
dispatch(
setResumeState({
path: `metadata.typography.${property}.${category}`,
value: property === 'family' ? (value as Font).family : value,
})
);
};
if (!fonts || isEmpty(fonts)) return <TypographySkeleton />;
return (
<>
<h5 className={styles.subheading}>{label}</h5>
<div className={styles.container}>
<div className={styles.slider}>
<Slider
min={12}
max={36}
step={1}
marks={[
{ value: 12, label: '12px' },
{ value: 24, label: t('builder.rightSidebar.sections.typography.form.font-size.label') },
{ value: 36, label: '36px' },
]}
valueLabelDisplay="auto"
value={size[category]}
onChange={(_, size: number | number[]) => handleChange('size', size)}
/>
</div>
<Autocomplete<Font, false, boolean, false>
options={fonts}
disableClearable={true}
groupBy={(font) => font.category}
getOptionLabel={(font) => font.family}
isOptionEqualToValue={(a, b) => a.family === b.family}
value={fonts.find((font) => font.family === family[category])}
onChange={(_, font: Font | null) => handleChange('family', font)}
renderInput={(params) => (
<TextField {...params} label={t('builder.rightSidebar.sections.typography.form.font-family.label')} />
)}
/>
</div>
</>
);
};
const Typography = () => {
const { t } = useTranslation();
return (
<>
<Heading path="metadata.typography" name={t('builder.rightSidebar.sections.typography.heading')} />
<Widgets label={t('builder.rightSidebar.sections.typography.widgets.headings.label')} category="heading" />
<Widgets label={t('builder.rightSidebar.sections.typography.widgets.body.label')} category="body" />
</>
);
};
export default Typography;