Skip to content

Commit

Permalink
Merge pull request #7 from Gimnath-Perera/feat/dummy-data-generation
Browse files Browse the repository at this point in the history
feat: row count change handled
  • Loading branch information
gimnathperera committed Aug 28, 2023
2 parents dc69f30 + 7e52ab1 commit f94a184
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
10 changes: 9 additions & 1 deletion app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,26 @@ interface Person {

const Home: FC = () => {
const [code, setCode] = useState<string>(DEFAULT_INTERFACE);
const [selectedKeys, setSelectedKeys] = useState(new Set(['10']));

const handleOnGenerate = (): void => {
console.log('*********', code);
};

const handleOnRowCountChange = (newRowCount: any): void => {
setSelectedKeys(newRowCount);
};
const handleOnCodeChange = (newCode: string): void => {
setCode(newCode);
};

return (
<section className='h-full'>
<Header onGenerate={handleOnGenerate} />
<Header
onGenerate={handleOnGenerate}
selectedKeys={selectedKeys}
onRowCountChange={handleOnRowCountChange}
/>
<div className='flex justify-center gap-6 h-[calc(100vh-12rem)]'>
<CodeEditor onCodeChange={handleOnCodeChange} initialCode={code} />
<Result />
Expand Down
40 changes: 32 additions & 8 deletions components/header/index.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,51 @@
import React, { FC } from 'react';
import { Dropdown, DropdownTrigger, DropdownMenu, DropdownItem, Button } from '@nextui-org/react';
import {
Dropdown,
DropdownTrigger,
DropdownMenu,
DropdownItem,
Button,
Selection,
} from '@nextui-org/react';

type Props = {
onGenerate: () => void;
onRowCountChange: (rowCount: Selection) => void;
selectedKeys: any;
};

const Header: FC<Props> = ({ onGenerate }) => {
const Header: FC<Props> = ({ onGenerate, onRowCountChange, selectedKeys }) => {
const selectedValue = React.useMemo(
() => Array.from(selectedKeys).join(', ').replaceAll('_', ' '),
[selectedKeys],
);

return (
<div className='pb-6 text-center flex items-center justify-between'>
<h1 className='tracking-tight inline font-semibold text-[2.3rem] lg:text-3xl'>
Generate Fake Data
</h1>
<div className='flex items-center gap-4'>
<Dropdown backdrop='blur'>
<Dropdown>
<DropdownTrigger>
<Button variant='bordered'>#锔忊儯 Scale [Number of rows]</Button>
<Button variant='bordered' className='capitalize'>
{`#锔忊儯 Scale [${selectedValue} of rows]`}
</Button>
</DropdownTrigger>
<DropdownMenu variant='faded' aria-label='Static Actions'>
<DropdownItem key='new'>10</DropdownItem>
<DropdownItem key='copy'>50</DropdownItem>
<DropdownItem key='edit'>100</DropdownItem>
<DropdownMenu
aria-label='Single selection example'
variant='flat'
disallowEmptySelection
selectionMode='single'
selectedKeys={selectedKeys}
onSelectionChange={onRowCountChange}
>
<DropdownItem key='10'>10</DropdownItem>
<DropdownItem key='50'>50</DropdownItem>
<DropdownItem key='100'>100</DropdownItem>
</DropdownMenu>
</Dropdown>

<Button color='primary' variant='shadow' onClick={onGenerate}>
馃獎 Generate
</Button>
Expand Down

0 comments on commit f94a184

Please sign in to comment.