forked from cerc-io/snowballtools-base
[component lib] input forward ref react-hook-form (#30)
This commit is contained in:
commit
f8908c1c06
@ -1,11 +1,18 @@
|
||||
import { ReactNode, useMemo } from 'react';
|
||||
import { ComponentPropsWithoutRef } from 'react';
|
||||
import { InputTheme, inputTheme } from './Input.theme';
|
||||
import {
|
||||
forwardRef,
|
||||
ReactNode,
|
||||
useMemo,
|
||||
ComponentPropsWithoutRef,
|
||||
} from 'react';
|
||||
import { FieldValues, UseFormRegister } from 'react-hook-form';
|
||||
|
||||
import { WarningIcon } from 'components/shared/CustomIcon';
|
||||
import { cloneIcon } from 'utils/cloneIcon';
|
||||
import { cn } from 'utils/classnames';
|
||||
|
||||
export interface InputProps
|
||||
import { InputTheme, inputTheme } from './Input.theme';
|
||||
|
||||
export interface InputProps<T extends FieldValues = FieldValues>
|
||||
extends InputTheme,
|
||||
Omit<ComponentPropsWithoutRef<'input'>, 'size'> {
|
||||
label?: string;
|
||||
@ -13,20 +20,28 @@ export interface InputProps
|
||||
leftIcon?: ReactNode;
|
||||
rightIcon?: ReactNode;
|
||||
helperText?: string;
|
||||
|
||||
// react-hook-form optional register
|
||||
register?: ReturnType<UseFormRegister<T>>;
|
||||
}
|
||||
|
||||
export const Input = ({
|
||||
const Input = forwardRef<HTMLInputElement, InputProps>(
|
||||
(
|
||||
{
|
||||
className,
|
||||
label,
|
||||
description,
|
||||
leftIcon,
|
||||
rightIcon,
|
||||
helperText,
|
||||
register,
|
||||
size,
|
||||
state,
|
||||
appearance,
|
||||
...props
|
||||
}: InputProps) => {
|
||||
},
|
||||
ref,
|
||||
) => {
|
||||
const styleProps = useMemo(
|
||||
() => ({
|
||||
size: size || 'md',
|
||||
@ -92,14 +107,21 @@ export const Input = ({
|
||||
<div className={containerCls({ class: className })}>
|
||||
{leftIcon && renderLeftIcon}
|
||||
<input
|
||||
{...(register ? register : {})}
|
||||
className={cn(inputCls(), {
|
||||
'pl-10': leftIcon,
|
||||
})}
|
||||
{...props}
|
||||
ref={ref}
|
||||
/>
|
||||
{rightIcon && renderRightIcon}
|
||||
</div>
|
||||
{renderHelperText}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
Input.displayName = 'Input';
|
||||
|
||||
export { Input };
|
||||
|
51
packages/frontend/src/components/shared/Table/Table.tsx
Normal file
51
packages/frontend/src/components/shared/Table/Table.tsx
Normal file
@ -0,0 +1,51 @@
|
||||
import React from 'react';
|
||||
|
||||
const Header: React.FC<{ children: React.ReactNode }> = ({ children }) => (
|
||||
<thead className="text-left">{children}</thead>
|
||||
);
|
||||
const Body: React.FC<{ children: React.ReactNode }> = ({ children }) => (
|
||||
<tbody className="text-left">{children}</tbody>
|
||||
);
|
||||
const Row: React.FC<{ children: React.ReactNode }> = ({ children }) => (
|
||||
<tr className="text-left">{children}</tr>
|
||||
);
|
||||
const ColumnHeaderCell: React.FC<{ children: React.ReactNode }> = ({
|
||||
children,
|
||||
}) => (
|
||||
<th className="px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
{children}
|
||||
</th>
|
||||
);
|
||||
const RowHeaderCell: React.FC<{ children: React.ReactNode }> = ({
|
||||
children,
|
||||
}) => (
|
||||
<th
|
||||
scope="row"
|
||||
className="px-6 py-4 font-medium text-gray-900 whitespace-nowrap"
|
||||
>
|
||||
{children}
|
||||
</th>
|
||||
);
|
||||
const Cell: React.FC<{ children: React.ReactNode }> = ({ children }) => (
|
||||
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
||||
{children}
|
||||
</td>
|
||||
);
|
||||
|
||||
const Table: React.FC<{ children: React.ReactNode }> & {
|
||||
Header: typeof Header;
|
||||
Body: typeof Body;
|
||||
Row: typeof Row;
|
||||
ColumnHeaderCell: typeof ColumnHeaderCell;
|
||||
RowHeaderCell: typeof RowHeaderCell;
|
||||
Cell: typeof Cell;
|
||||
} = ({ children }) => <table className="min-w-full">{children}</table>;
|
||||
|
||||
Table.Header = Header;
|
||||
Table.Body = Body;
|
||||
Table.Row = Row;
|
||||
Table.ColumnHeaderCell = ColumnHeaderCell;
|
||||
Table.RowHeaderCell = RowHeaderCell;
|
||||
Table.Cell = Cell;
|
||||
|
||||
export { Table };
|
1
packages/frontend/src/components/shared/Table/index.ts
Normal file
1
packages/frontend/src/components/shared/Table/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './Table';
|
@ -1,12 +1,13 @@
|
||||
import toast from 'react-hot-toast';
|
||||
import { useNavigate, useParams, useSearchParams } from 'react-router-dom';
|
||||
import {
|
||||
Typography,
|
||||
Alert,
|
||||
Button,
|
||||
} from '@snowballtools/material-tailwind-react-fork';
|
||||
|
||||
import { useGQLClient } from '../../../../../../../context/GQLClientContext';
|
||||
import { Heading } from 'components/shared/Heading';
|
||||
import { Table } from 'components/shared/Table';
|
||||
|
||||
const Config = () => {
|
||||
const { id, orgSlug } = useParams();
|
||||
@ -38,37 +39,44 @@ const Config = () => {
|
||||
}
|
||||
};
|
||||
|
||||
// TODO: Figure out DNS Provider if possible and update appropriatly
|
||||
return (
|
||||
<div className="flex flex-col gap-6 w-full">
|
||||
<div>
|
||||
<Typography variant="h5">Configure DNS</Typography>
|
||||
<Typography variant="small">
|
||||
<Heading className="text-sky-950 text-lg font-medium leading-normal">
|
||||
Setup domain name
|
||||
</Heading>
|
||||
<p className="text-blue-gray-500">
|
||||
Add the following records to your domain.
|
||||
<a href="https://www.namecheap.com/" target="_blank" rel="noreferrer">
|
||||
<span className="underline">Go to NameCheap</span> ^
|
||||
<span className="underline">Go to NameCheap</span>
|
||||
</a>
|
||||
</Typography>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<table className="rounded-lg w-3/4 text-blue-gray-600">
|
||||
<tbody>
|
||||
<tr className="border-b-2 border-gray-300">
|
||||
<th className="text-left p-2">Type</th>
|
||||
<th className="text-left p-2">Name</th>
|
||||
<th className="text-left p-2">Value</th>
|
||||
</tr>
|
||||
<tr className="border-b-2 border-gray-300">
|
||||
<td className="text-left p-2">A</td>
|
||||
<td className="text-left p-2">@</td>
|
||||
<td className="text-left p-2">56.49.19.21</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td className="text-left p-2">CNAME</td>
|
||||
<td className="text-left p-2">www</td>
|
||||
<td className="text-left p-2">cname.snowballtools.xyz</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<Table>
|
||||
<Table.Header>
|
||||
<Table.Row>
|
||||
<Table.ColumnHeaderCell>Type</Table.ColumnHeaderCell>
|
||||
<Table.ColumnHeaderCell>Host</Table.ColumnHeaderCell>
|
||||
<Table.ColumnHeaderCell>Value</Table.ColumnHeaderCell>
|
||||
</Table.Row>
|
||||
</Table.Header>
|
||||
|
||||
<Table.Body>
|
||||
<Table.Row>
|
||||
<Table.RowHeaderCell>A</Table.RowHeaderCell>
|
||||
<Table.Cell>@</Table.Cell>
|
||||
<Table.Cell>56.49.19.21</Table.Cell>
|
||||
</Table.Row>
|
||||
|
||||
<Table.Row>
|
||||
<Table.RowHeaderCell>CNAME</Table.RowHeaderCell>
|
||||
<Table.Cell>www</Table.Cell>
|
||||
<Table.Cell>cname.snowballtools.xyz</Table.Cell>
|
||||
</Table.Row>
|
||||
</Table.Body>
|
||||
</Table>
|
||||
|
||||
<Alert color="blue">
|
||||
<i>^</i>It can take up to 48 hours for these updates to reflect
|
||||
|
48
packages/frontend/src/stories/Components/Table.stories.tsx
Normal file
48
packages/frontend/src/stories/Components/Table.stories.tsx
Normal file
@ -0,0 +1,48 @@
|
||||
import { StoryObj, Meta } from '@storybook/react';
|
||||
|
||||
import { Table } from 'components/shared/Table';
|
||||
|
||||
const meta: Meta<typeof Table> = {
|
||||
title: 'Components/Table',
|
||||
component: Table,
|
||||
tags: ['autodocs'],
|
||||
};
|
||||
|
||||
export default meta;
|
||||
|
||||
type Story = StoryObj<typeof Table>;
|
||||
|
||||
export const Default: Story = {
|
||||
render: ({}) => (
|
||||
<Table>
|
||||
<Table.Header>
|
||||
<Table.Row>
|
||||
<Table.ColumnHeaderCell>Full name</Table.ColumnHeaderCell>
|
||||
<Table.ColumnHeaderCell>Email</Table.ColumnHeaderCell>
|
||||
<Table.ColumnHeaderCell>Group</Table.ColumnHeaderCell>
|
||||
</Table.Row>
|
||||
</Table.Header>
|
||||
|
||||
<Table.Body>
|
||||
<Table.Row>
|
||||
<Table.RowHeaderCell>Danilo Sousa</Table.RowHeaderCell>
|
||||
<Table.Cell>danilo@example.com</Table.Cell>
|
||||
<Table.Cell>Developer</Table.Cell>
|
||||
</Table.Row>
|
||||
|
||||
<Table.Row>
|
||||
<Table.RowHeaderCell>Zahra Ambessa</Table.RowHeaderCell>
|
||||
<Table.Cell>zahra@example.com</Table.Cell>
|
||||
<Table.Cell>Admin</Table.Cell>
|
||||
</Table.Row>
|
||||
|
||||
<Table.Row>
|
||||
<Table.RowHeaderCell>Jasper Eriksson</Table.RowHeaderCell>
|
||||
<Table.Cell>jasper@example.com</Table.Cell>
|
||||
<Table.Cell>Developer</Table.Cell>
|
||||
</Table.Row>
|
||||
</Table.Body>
|
||||
</Table>
|
||||
),
|
||||
args: {},
|
||||
};
|
Loading…
Reference in New Issue
Block a user