Skip to content

Commit

Permalink
feat(cms-core): Added SectionsView
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksandarDev committed Dec 27, 2023
1 parent 8dd531b commit 3eed0f4
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 11 deletions.
21 changes: 11 additions & 10 deletions web/apps/uier/app/(rest)/(marketing)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { ExoticComponent, memo } from 'react';
import { Heading1 } from '@signalco/cms-feature-marketing/Heading';
import { Footer1 } from '@signalco/cms-feature-marketing/Footer';
import { SectionsView } from '@signalco/cms-core/SectionsView';
import { type SectionData } from '@signalco/cms-core/SectionData';
import { KnownPages } from '../../../src/knownPages';

const data: SectionData[] = [
{
component: 'Heading1',
header: 'uier',
ctas: [
{ label: 'Get Started', href: KnownPages.App },
]
},
{
component: 'Footer1',
features: [
{
header: 'Product',
Expand Down Expand Up @@ -43,20 +47,17 @@ const data: SectionData[] = [
}
];

const sections = [
Heading1,
Footer1
];
const sectionComponents: { [key: string]: ExoticComponent<SectionData> } = {
'Heading1': memo(Heading1),
'Footer1': memo(Footer1)
};

export default function LandingPage() {
return (
<main>
{sections.map((Section, index) => {
const sectionData = data[index];
return (
<Section key={index} {...sectionData} />
);
})}
<SectionsView
sectionsData={data}
componentsRegistry={sectionComponents} />
</main>
);
}
4 changes: 3 additions & 1 deletion web/packages/cms-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
},
"devDependencies": {
"@signalco/eslint-config-signalco": "workspace:*",
"@signalco/ui-primitives": "workspace:*",
"@signalco/ui-icons": "workspace:*",
"@signalco/tailwindcss-config-signalco": "workspace:*",
"@signalco/tsconfig": "workspace:*",
"@types/react": "18.2.45",
Expand All @@ -20,4 +22,4 @@
"react-dom": "18.2.0",
"typescript": "5.3.3"
}
}
}
1 change: 1 addition & 0 deletions web/packages/cms-core/src/SectionData/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ReactNode } from 'react';

export type SectionData = {
component?: string;
tagline?: string;
header?: string;
description?: string;
Expand Down
38 changes: 38 additions & 0 deletions web/packages/cms-core/src/SectionsView/SectionsEditor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { ExoticComponent } from 'react';
import { Typography } from '@signalco/ui-primitives/Typography';
import { IconButton } from '@signalco/ui-primitives/IconButton';
import { MoreHorizontal } from '@signalco/ui-icons';
import { SectionData } from '../SectionData';

export function SectionsEditor({ sectionsData, componentsRegistry }: { sectionsData: SectionData[]; componentsRegistry: { [key: string]: ExoticComponent<SectionData>; }; }) {
const handleSectionEdit = (sectionData: SectionData) => {
console.log('Edit', sectionData);
};

return (
<div>
{sectionsData.map((sectionData, index) => {
const Section = sectionData.component ? componentsRegistry[sectionData.component] : null;
if (!Section) {
return null;
}

return (
<div className="group relative" key={index}>
<div className="pointer-events-none absolute inset-0 rounded-md border opacity-0 transition-opacity group-hover:opacity-100" />
<IconButton
onClick={() => handleSectionEdit(sectionData)}
variant="soft"
className="absolute left-0 top-0 rounded-r-none rounded-bl-none opacity-0 transition-opacity group-hover:opacity-100">
<MoreHorizontal />
</IconButton>
<Typography level="body2" className="absolute left-12 top-2 text-center opacity-0 transition-opacity group-hover:opacity-100">
{sectionData.component}
</Typography>
<Section {...sectionData} />
</div>
);
})}
</div>
);
}
30 changes: 30 additions & 0 deletions web/packages/cms-core/src/SectionsView/SectionsView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { ExoticComponent } from 'react';
import { SectionData } from '../SectionData';

export type CmsComponentRegistry = {
[key: string]: ExoticComponent<SectionData>;
};

export type CmsSectionsViewProps = {
sectionsData: SectionData[];
componentsRegistry: CmsComponentRegistry;
};

export function SectionsView({ sectionsData, componentsRegistry }: CmsSectionsViewProps) {
return (
<div>
{sectionsData.map((sectionData, index) => {
const Section = sectionData.component ? componentsRegistry[sectionData.component] : null;
if (!Section) {
return null;
}

return (
<Section key={index} {...sectionData} />
);
})}
</div>
);
}


2 changes: 2 additions & 0 deletions web/packages/cms-core/src/SectionsView/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './SectionsView';
export * from './SectionsEditor';
6 changes: 6 additions & 0 deletions web/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3eed0f4

Please sign in to comment.