Skip to content

Commit

Permalink
feat: adds support for dark mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ghoshnirmalya committed Dec 29, 2020
1 parent de7ca00 commit 74b6c16
Show file tree
Hide file tree
Showing 17 changed files with 110 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
addTemplateSectionData,
removeTemplateSectionData,
updateTemplateSectionData,
updateTemplateSectionMeta,
} from "slices/site";

interface IProps {
Expand All @@ -24,7 +25,7 @@ interface IProps {
const NavbarSectionEditorTextPanel: FC<IProps> = ({ positionOfSection }) => {
const dispatch = useDispatch();
const currentPageId = useSelector(getCurrentPageData());
const { data } = useSelector(
const { data, meta } = useSelector(
getSectionData(currentPageId, positionOfSection)
);

Expand All @@ -45,6 +46,17 @@ const NavbarSectionEditorTextPanel: FC<IProps> = ({ positionOfSection }) => {
);
};

const handleMetaChange = (itemType: string, value: string) => {
dispatch(
updateTemplateSectionMeta({
currentPageId,
positionOfSection,
itemType,
value,
})
);
};

const handleDataDeletion = (itemPosition: number) => {
dispatch(
removeTemplateSectionData({
Expand All @@ -71,6 +83,17 @@ const NavbarSectionEditorTextPanel: FC<IProps> = ({ positionOfSection }) => {

return (
<VStack spacing={4} align="stretch">
<FormControl>
<FormLabel>Name of the site</FormLabel>
<Input
size="sm"
rounded="lg"
value={meta.siteName}
onChange={(e: ChangeEvent<HTMLInputElement>) =>
handleMetaChange("siteName", e.currentTarget.value)
}
/>
</FormControl>
{data.links.map((link: any, index: number) => {
return (
<HStack spacing={4} key={index} alignItems="flex-end">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,7 @@ const RightSidebar: FC = () => {
const bgColor = useColorModeValue("brand.100", "brand.900");

return (
<Box
h="calc(100vh - 50px)"
w="500px"
bg={bgColor}
borderLeftWidth={1}
overflowY="auto"
>
<Box w="500px" bg={bgColor} borderLeftWidth={1} overflowY="hidden">
<HStack
spacing={4}
align="center"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,31 +86,31 @@ const RightSidebarTabs: FC = () => {
</Tab>
<Tab>
<HStack spacing={1}>
<Icon as={MdChromeReaderMode} />
<Text>Templates</Text>
<Icon as={MdCollections} />
<Text>Pages</Text>
</HStack>
</Tab>
<Tab>
<HStack spacing={1}>
<Icon as={MdCollections} />
<Text>Pages</Text>
<Icon as={MdChromeReaderMode} />
<Text>Templates</Text>
</HStack>
</Tab>
</TabList>
<TabPanels>
<TabPanels height="calc(100vh - 50px - 42px - 65px)" overflowY="scroll">
<TabPanel>
<Box>
<LazyRightSidebarSectionsTab />
</Box>
</TabPanel>
<TabPanel>
<Box>
<LazyRightSidebarTemplatesTab />
<LazyRightSidebarPagesTab />
</Box>
</TabPanel>
<TabPanel>
<Box>
<LazyRightSidebarPagesTab />
<LazyRightSidebarTemplatesTab />
</Box>
</TabPanel>
</TabPanels>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import scrollPreviewSectionIntoView from "lib/scroll-preview-section-into-view";
import React, { FC } from "react";
import { MdAdd } from "react-icons/md";
import { useDispatch, useSelector } from "react-redux";
import { getCurrentPageData } from "selectors/site";
import { getCurrentPageData, getSiteData } from "selectors/site";
import { addTemplateSection } from "slices/site";

interface IProps {
Expand All @@ -27,6 +27,7 @@ const AddNewSection: FC<IProps> = ({ positionOfSection }) => {
const dispatch = useDispatch();
const { onOpen, onClose, isOpen } = useDisclosure();
const currentPageId = useSelector(getCurrentPageData());
const { theme } = useSelector(getSiteData());

const handleNewSectionAddition = (sectionType: string) => {
switch (sectionType) {
Expand All @@ -37,7 +38,7 @@ const AddNewSection: FC<IProps> = ({ positionOfSection }) => {
addTemplateSection({
currentPageId,
positionOfSection,
sectionContent: navbarSectionData,
sectionContent: navbarSectionData(theme.mode),
})
);

Expand All @@ -50,7 +51,7 @@ const AddNewSection: FC<IProps> = ({ positionOfSection }) => {
addTemplateSection({
currentPageId,
positionOfSection,
sectionContent: heroSectionData,
sectionContent: heroSectionData(theme.mode),
})
);

Expand All @@ -63,7 +64,7 @@ const AddNewSection: FC<IProps> = ({ positionOfSection }) => {
addTemplateSection({
currentPageId,
positionOfSection,
sectionContent: featuresSectionData,
sectionContent: featuresSectionData(theme.mode),
})
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { Box, Img, Text, useColorModeValue, VStack } from "@chakra-ui/react";
import {
Alert,
AlertIcon,
Box,
Img,
Text,
useColorModeValue,
VStack,
} from "@chakra-ui/react";
import rainbowTemplateData from "data/templates/rainbow";
import unoTemplateData from "data/templates/uno";
import React, { FC } from "react";
Expand Down Expand Up @@ -73,7 +81,15 @@ const RightSidebarTemplatesTab: FC = () => {
});
};

return <VStack spacing={4}>{templateNode()}</VStack>;
return (
<VStack spacing={4}>
<Alert status="warning" rounded="lg">
<AlertIcon />
All changes done here are permanent. Please proceed with caution.
</Alert>
{templateNode()}
</VStack>
);
};

export default RightSidebarTemplatesTab;
4 changes: 2 additions & 2 deletions packages/builder/components/views/sections/navbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ const NavbarSectionView: FC<IProps> = ({ positionOfSection, pageId }) => {
const renderLayout = () => {
switch (meta.layout) {
case "one":
return <NavbarLayouts.One theme={theme} data={data} />;
return <NavbarLayouts.One theme={theme} data={data} meta={meta} />;

case "two":
return <NavbarLayouts.Two theme={theme} data={data} />;
return <NavbarLayouts.Two theme={theme} data={data} meta={meta} />;

default:
break;
Expand Down
8 changes: 4 additions & 4 deletions packages/builder/data/sections/features.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Image2, Image3, Image4 } from "@writy/sections";

const featuresSectionData = {
const featuresSectionData = (mode: "light" | "dark") => ({
meta: {
type: "features",
layout: "one",
heading: "We've developed and shipped over 500 products",
},
theme: {
backgroundColor: "#ffffff",
textColor: "#000000",
backgroundColor: mode === "dark" ? "#000000" : "#f2f2f2",
textColor: mode === "dark" ? "#ffffff" : "#000000",
},
data: {
cards: [
Expand All @@ -32,6 +32,6 @@ const featuresSectionData = {
},
],
},
};
});

export default featuresSectionData;
8 changes: 4 additions & 4 deletions packages/builder/data/sections/footer.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const footerSectionData = {
const footerSectionData = (mode: "light" | "dark") => ({
meta: {
type: "footer",
layout: "one",
},
theme: {
backgroundColor: "#f2f2f2",
linkColor: "#000000",
backgroundColor: mode === "dark" ? "#000000" : "#f2f2f2",
linkColor: mode === "dark" ? "#ffffff" : "#000000",
},
data: {
links: [
Expand All @@ -23,6 +23,6 @@ const footerSectionData = {
},
],
},
};
});

export default footerSectionData;
12 changes: 6 additions & 6 deletions packages/builder/data/sections/hero.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Image1 } from "@writy/sections";

const heroSectionData = {
const heroSectionData = (mode: "light" | "dark") => ({
meta: {
type: "hero",
layout: "one",
Expand All @@ -10,10 +10,10 @@ const heroSectionData = {
image: Image1,
},
theme: {
backgroundColor: "#ffffff",
textColor: "#000000",
buttonBackgroundColor: "#000000",
buttonTextColor: "#ffffff",
backgroundColor: mode === "dark" ? "#000000" : "#f2f2f2",
textColor: mode === "dark" ? "#ffffff" : "#000000",
buttonBackgroundColor: mode === "dark" ? "#ffffff" : "#000000",
buttonTextColor: mode === "dark" ? "#000000" : "#ffffff",
},
data: {
buttons: [
Expand All @@ -27,6 +27,6 @@ const heroSectionData = {
},
],
},
};
});

export default heroSectionData;
9 changes: 5 additions & 4 deletions packages/builder/data/sections/navbar.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const navbarSectionData = {
const navbarSectionData = (mode: "light" | "dark") => ({
meta: {
type: "navbar",
layout: "one",
siteName: "Writy",
},
theme: {
backgroundColor: "#f2f2f2",
linkColor: "#000000",
backgroundColor: mode === "dark" ? "#000000" : "#f2f2f2",
linkColor: mode === "dark" ? "#ffffff" : "#000000",
},
data: {
links: [
Expand All @@ -23,6 +24,6 @@ const navbarSectionData = {
},
],
},
};
});

export default navbarSectionData;
7 changes: 6 additions & 1 deletion packages/builder/data/site/dark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const darkModeSiteData = {
meta: {
type: "navbar",
layout: "one",
siteName: "Writy",
},
theme: {
backgroundColor: "#000000",
Expand Down Expand Up @@ -141,6 +142,7 @@ const darkModeSiteData = {
meta: {
type: "navbar",
layout: "one",
siteName: "Writy",
},
theme: {
backgroundColor: "#000000",
Expand Down Expand Up @@ -266,6 +268,7 @@ const darkModeSiteData = {
meta: {
type: "navbar",
layout: "one",
siteName: "Writy",
},
theme: {
backgroundColor: "#000000",
Expand Down Expand Up @@ -379,7 +382,9 @@ const darkModeSiteData = {
},
},
],
theme: {},
theme: {
mode: "dark",
},
};

export default darkModeSiteData;
7 changes: 6 additions & 1 deletion packages/builder/data/site/light.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const lightModeSiteData = {
meta: {
type: "navbar",
layout: "one",
siteName: "Writy",
},
theme: {
backgroundColor: "#f2f2f2",
Expand Down Expand Up @@ -141,6 +142,7 @@ const lightModeSiteData = {
meta: {
type: "navbar",
layout: "one",
siteName: "Writy",
},
theme: {
backgroundColor: "#f2f2f2",
Expand Down Expand Up @@ -266,6 +268,7 @@ const lightModeSiteData = {
meta: {
type: "navbar",
layout: "one",
siteName: "Writy",
},
theme: {
backgroundColor: "#f2f2f2",
Expand Down Expand Up @@ -379,7 +382,9 @@ const lightModeSiteData = {
},
},
],
theme: {},
theme: {
mode: "light",
},
};

export default lightModeSiteData;
1 change: 1 addition & 0 deletions packages/builder/data/templates/rainbow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const rainbow = {
meta: {
type: "navbar",
layout: "two",
siteName: "Writy",
},
theme: {
backgroundColor: "#f2f2f2",
Expand Down
1 change: 1 addition & 0 deletions packages/builder/data/templates/uno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const uno = {
meta: {
type: "navbar",
layout: "one",
siteName: "Writy",
},
theme: {
backgroundColor: "#ffffff",
Expand Down

0 comments on commit 74b6c16

Please sign in to comment.