-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from apptension/feature/element
feat: add element
- Loading branch information
Showing
22 changed files
with
203 additions
and
23 deletions.
There are no files selected for viewing
2 changes: 0 additions & 2 deletions
2
lib/default/forms/92daef9d-18d8-4716-9146-8b840cbe7cd1/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import '../../../../../src/styles/globals.css'; | ||
|
||
export default function () { | ||
return <button class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">Button</button>; | ||
} |
2 changes: 0 additions & 2 deletions
2
lib/default/forms/formLayouts/586b4ad0-9949-4000-b6bf-202db8fea36f/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import '../../../../../src/styles/globals.css'; | ||
|
||
export default function () { | ||
return <button class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">Button</button>; | ||
} |
2 changes: 0 additions & 2 deletions
2
lib/default/lists/4494f6cd-d586-4685-8647-1e7d5c713669/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import '../../../../../src/styles/globals.css'; | ||
|
||
export default function () { | ||
return <button class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">Button</button>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { useState } from 'react'; | ||
import clsx from 'clsx'; | ||
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'; | ||
import { dracula } from 'react-syntax-highlighter/dist/cjs/styles/prism'; | ||
|
||
import { ELEMENT_BOX_MODE } from './elementBox.const'; | ||
|
||
export function ElementBoxComponent({ author, description, Component, source }) { | ||
const [mode, setMode] = useState(ELEMENT_BOX_MODE.PREVIEW); | ||
const handlePreview = () => setMode(ELEMENT_BOX_MODE.PREVIEW); | ||
const handleSource = () => setMode(ELEMENT_BOX_MODE.SOURCE); | ||
return ( | ||
<div className="bg-blue-100 p-4 rounded"> | ||
<div className="flex justify-between"> | ||
<p>{description}</p> | ||
<p>by {author}</p> | ||
</div> | ||
<div className="flex justify-center"> | ||
<button | ||
onClick={handlePreview} | ||
className={clsx( | ||
{ | ||
'border-blue-500 text-gray-900': mode === ELEMENT_BOX_MODE.PREVIEW, | ||
'border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700': | ||
mode !== ELEMENT_BOX_MODE.PREVIEW, | ||
}, | ||
'inline-flex items-center px-1 pt-1 border-b-2 text-m font-medium' | ||
)} | ||
> | ||
Preview | ||
</button> | ||
<button | ||
onClick={handleSource} | ||
className={clsx( | ||
{ | ||
'border-blue-500 text-gray-900': mode === ELEMENT_BOX_MODE.SOURCE, | ||
'border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700': | ||
mode !== ELEMENT_BOX_MODE.SOURCE, | ||
}, | ||
'inline-flex items-center px-1 pt-1 border-b-2 text-m font-medium' | ||
)} | ||
> | ||
Source | ||
</button> | ||
</div> | ||
<div className="bg-white"> | ||
{mode === ELEMENT_BOX_MODE.PREVIEW && ( | ||
<div className="h-32 flex justify-center items-center">{Component.default()}</div> | ||
)} | ||
{mode === ELEMENT_BOX_MODE.SOURCE && ( | ||
<SyntaxHighlighter showLineNumbers language="javascript" style={dracula}> | ||
{source} | ||
</SyntaxHighlighter> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const ELEMENT_BOX_MODE = { | ||
PREVIEW: 'PREVIEW', | ||
SOURCE: 'SOURCE', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { ElementBoxComponent as ElementBox } from './elementBox.component'; |
14 changes: 14 additions & 0 deletions
14
src/components/element/elementList/elementList.component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { useElement } from '../../../modules/element'; | ||
import { ElementBox } from '../elementBox'; | ||
|
||
export function ElementListComponent() { | ||
const { elements } = useElement(); | ||
|
||
return ( | ||
<div className="mt-10 max-w-7xl mx-auto"> | ||
{elements.map((data) => ( | ||
<ElementBox key={data.id} {...data} /> | ||
))} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { ElementListComponent as ElementList } from './elementList.component'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
export function FooterComponent() { | ||
return ( | ||
<footer className="w-full h-16 flex justify-center items-center bg-blue-500 mt-8"> | ||
<p className="text-white">Made with ❤️ by Apptension / NY</p> | ||
<p className="text-white">Made with ❤️ by Apptension</p> | ||
</footer> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
export function HomeHeroComponent() { | ||
return ( | ||
<div className="bg-blue-500 h-96 w-full flex justify-center items-center"> | ||
<p className="text-white text-7xl">Something about the project</p> | ||
<p className="text-white text-7xl">Community-Driven Tailwind UI Kit</p> | ||
</div> | ||
); | ||
} |
2 changes: 1 addition & 1 deletion
2
src/components/home/homeResults/homeCategory/homeCategory.component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 18 additions & 5 deletions
23
src/components/home/homeResults/homeResult/homeResult.component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,21 @@ | ||
export function HomeResultComponent({ type, count }) { | ||
import clsx from 'clsx'; | ||
import Link from 'next/link'; | ||
import { ROUTES } from '../../../../utils/routes'; | ||
|
||
export function HomeResultComponent({ url, count, label }) { | ||
return ( | ||
<div className="bg-blue-500 text-white relative rounded h-60 flex justify-center items-center"> | ||
{type} | ||
<div className="absolute bottom-2 right-2">{count}</div> | ||
</div> | ||
<Link href={ROUTES.element(url)}> | ||
<a | ||
className={clsx({ | ||
'cursor-not-allowed opacity-80 pointer-events-none': count === 0, | ||
'cursor-pointer': count > 0, | ||
})} | ||
> | ||
<div className="bg-blue-500 text-white relative rounded h-60 flex justify-center items-center"> | ||
{label} | ||
<div className="absolute bottom-2 right-2">{count}</div> | ||
</div> | ||
</a> | ||
</Link> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { useContext, useMemo } from 'react'; | ||
// import { readFileSync } from 'fs-extra'; | ||
import { ElementContext } from './element.provider'; | ||
import data from '../../../elements.json'; | ||
|
||
export const useElement = () => { | ||
return useContext(ElementContext); | ||
}; | ||
|
||
export const useElementProvider = ({ category, type, sources }) => { | ||
const elements = useMemo( | ||
() => | ||
(data?.[category]?.[type] || []).map((item) => ({ | ||
...item, | ||
Component: require(`../../../lib/${item.category}/${item.type}/${item.id}/index.js`), | ||
source: sources.find((s) => s.id === item.id)?.source, | ||
})), | ||
[category, type, sources] | ||
); | ||
console.log(elements); | ||
return { elements }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { createContext } from 'react'; | ||
import { useElementProvider } from './element.hook'; | ||
|
||
export const ElementContext = createContext({}); | ||
|
||
export const ElementProvider = ({ children, category, type, sources }) => { | ||
const values = useElementProvider({ category, type, sources }); | ||
return <ElementContext.Provider value={values}>{children}</ElementContext.Provider>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { ElementProvider } from './element.provider'; | ||
export { useElement } from './element.hook'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { useRouter } from 'next/router'; | ||
import data from '../../../../elements.json'; | ||
import path from 'path'; | ||
import { readFileSync } from 'fs-extra'; | ||
import { ElementList } from '../../../components/element/elementList'; | ||
import { Layout } from '../../../components/layout'; | ||
import { ElementProvider } from '../../../modules/element'; | ||
|
||
export default function ElementType({ sources }) { | ||
const router = useRouter(); | ||
const { category, type } = router.query; | ||
return ( | ||
<Layout> | ||
<ElementProvider category={category} type={type} sources={sources}> | ||
<ElementList /> | ||
</ElementProvider> | ||
</Layout> | ||
); | ||
} | ||
|
||
export async function getServerSideProps({ params }) { | ||
const { category, type } = params; | ||
const arr = data[category][type]; | ||
const sources = arr.map((e) => ({ | ||
id: e.id, | ||
source: readFileSync( | ||
path.resolve(__dirname, `../../../../../lib/${e.category}/${e.type}/${e.id}/index.js`), | ||
'utf-8' | ||
), | ||
})); | ||
|
||
return { | ||
props: { sources }, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export const ROUTES = { | ||
home: '/', | ||
board: '/board', | ||
element: (url) => `/element/${url}`, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51f70df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: