-
-
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.
- Loading branch information
1 parent
9df24a7
commit 6f3fbf8
Showing
90 changed files
with
2,248 additions
and
1,937 deletions.
There are no files selected for viewing
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,19 @@ | ||
import { CodeBlock, dracula } from 'react-code-blocks' | ||
import Usage from './Details/Usage' | ||
|
||
export default function CodeSample({ code }: any) { | ||
return ( | ||
<Usage title="Syntex"> | ||
<CodeBlock | ||
customStyle={{ | ||
padding: "0 0.1rem" | ||
}} | ||
theme={dracula} | ||
text={code} | ||
language="jsx" | ||
wrapLongLines | ||
showLineNumbers={false} | ||
/> | ||
</Usage> | ||
) | ||
} |
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 |
---|---|---|
@@ -1,32 +1,31 @@ | ||
import { Button } from '@/components/ui/button' | ||
import { examleSandboxLinks, exampleMarkDownPrefixUrl } from '@/lib/utils'; | ||
import { MoveUpRightIcon } from 'lucide-react' | ||
|
||
export default function RedirectToExample({ hook }: any) { | ||
const githubUrl = 'https://github.com/PunitSoniME/react-helper-hooks/blob/main' | ||
const hookCodeUrl = `${githubUrl}/src`; | ||
const exampleCodeUrl = `${githubUrl}/example/src/hooks`; | ||
|
||
const codeSandboxLink = examleSandboxLinks[hook]; | ||
export default function RedirectToExample({ hook }: any) { | ||
|
||
return ( | ||
<> | ||
<Button size="sm" className='mt-2' | ||
onClick={() => { | ||
window.open(`${exampleMarkDownPrefixUrl}/${hook}.md`, '_blank'); | ||
window.open(`${hookCodeUrl}/${hook}/index.tsx`, '_blank'); | ||
}} | ||
> | ||
Example Code | ||
<MoveUpRightIcon className='ml-2' size={14} /> | ||
</Button> | ||
|
||
{ | ||
codeSandboxLink ? <Button size="sm" variant="secondary" className='ml-2 mt-2' | ||
onClick={() => { | ||
window.open(codeSandboxLink, '_blank'); | ||
}} | ||
> | ||
Example Playground | ||
<MoveUpRightIcon className='ml-2' size={14} /> | ||
</Button> : "" | ||
} | ||
<Button size="sm" variant="secondary" className='ml-2 mt-2' | ||
onClick={() => { | ||
window.open(`${exampleCodeUrl}/${hook}/index.tsx`, '_blank'); | ||
}} | ||
> | ||
Source code of hook | ||
<MoveUpRightIcon className='ml-2' size={14} /> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react' | ||
|
||
export default function Usage({ title, children }: any) { | ||
return ( | ||
<div className='mt-4 border rounded-md bg-slate-50'> | ||
<p className='text-lg p-4 font-semibold tracking-wider text-slate-800'> | ||
{title || "Usage"} | ||
</p> | ||
|
||
{children} | ||
</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,27 @@ | ||
import React, { lazy, Suspense } from 'react' | ||
|
||
const Title = lazy(() => import('@/common/Details/Title')); | ||
const Lead = lazy(() => import('@/common/Lead')); | ||
const CodeSample = lazy(() => import('@/common/CodeSample')); | ||
|
||
export default function Documentation({ hook, info, usage, children }: any) { | ||
return ( | ||
<> | ||
<Suspense fallback={<></>}> | ||
<Title>{hook}</Title> | ||
</Suspense> | ||
|
||
<Suspense fallback={<>Loading Code Block</>}> | ||
<Lead className='text-md'> | ||
{info} | ||
</Lead> | ||
</Suspense> | ||
|
||
<Suspense fallback={<></>}> | ||
<CodeSample code={usage} /> | ||
</Suspense> | ||
|
||
{children} | ||
</> | ||
) | ||
} |
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 was deleted.
Oops, something went wrong.
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,72 @@ | ||
import { lazy, Suspense } from 'react'; | ||
import { useArray } from '../../../..'; | ||
import { packageName } from '@/lib/utils'; | ||
import { Button } from '@/components/ui/button'; | ||
|
||
const Block = lazy(() => import('@/common/Details/Block')); | ||
const Documentation = lazy(() => import('@/common/Documentation')); | ||
|
||
const hook = 'useArray'; | ||
const info = 'Useful to use methods of array like push, update, remove, filter, update, clear etc...'; | ||
|
||
const usage: string = `import { ${hook} } from '${packageName}'; | ||
export default function Component() { | ||
/* | ||
@params - Array - The datasource as an array | ||
@returns | ||
array - Array - Data on which operation to perform | ||
set - function - Re-initialize the array with new data | ||
push - function - Insert an element in array | ||
remove - function - Remove an element from array | ||
filter - function - Filter out the data from array ( This will mutate the source ) | ||
update - function - Update any element of array | ||
clear - function - Clear whole array | ||
*/ | ||
const { array, set, push, remove, filter, update, clear } = ${hook}([DATA]); | ||
}` | ||
|
||
const api = [ | ||
{ execute: 'array', type: 'array', description: 'Data on which operation to perform' }, | ||
{ execute: 'set', type: 'function', description: 'Re-initialize the array with new data' }, | ||
{ execute: 'push', type: 'function', description: 'Insert an element in array' }, | ||
{ execute: 'remove', type: 'function', description: 'Remove an element from array' }, | ||
{ execute: 'filter', type: 'function', description: 'Filter out the data from array ( This will mutate the source )' }, | ||
{ execute: 'update', type: 'function', description: 'Update any element of array' }, | ||
{ execute: 'clear', type: 'function', description: 'Clear whole array' } | ||
]; | ||
|
||
export default function ArrayComponent() { | ||
|
||
const { array, set, push, remove, filter, update, clear } = useArray([1, 2, 3, 4, 5, 6]) | ||
|
||
return ( | ||
<Suspense fallback={<></>}> | ||
|
||
<Documentation | ||
hook={hook} | ||
info={info} | ||
usage={usage} | ||
> | ||
<Block title='Example'> | ||
|
||
<div>{array.join(", ")}</div> | ||
|
||
<div className="flex flex-row flex-wrap gap-3 mt-2"> | ||
<Button size="sm" onClick={() => push(((Math.random() + 1) * 10).toFixed(0))}>Add random number</Button> | ||
<Button size="sm" onClick={() => update(1, 9)}>Update 2nd element to 9</Button> | ||
<Button size="sm" onClick={() => remove(1)}>Remove Second Element</Button> | ||
<Button size="sm" onClick={() => filter(f => f < 3)}>Keep numbers less than 3</Button> | ||
<Button size="sm" onClick={() => set([1, 2])}>Set 1 to 2</Button> | ||
<Button size="sm" onClick={clear}>Clear</Button> | ||
</div> | ||
</Block> | ||
|
||
|
||
</Documentation> | ||
|
||
</Suspense> | ||
) | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.