apps/ui: add element wrapper
This commit is contained in:
parent
0424d8da50
commit
386acf4b03
@ -1,6 +1,6 @@
|
||||
import * as apiIUS from '@/api/ius/query';
|
||||
import type { Request } from '@/api/ius/types';
|
||||
import { Background, Button, Content, Input } from 'ui';
|
||||
import { Background, Button, Content, Input, Title, Wrapper } from 'ui';
|
||||
|
||||
type Props = {
|
||||
params: { slug: string };
|
||||
@ -18,15 +18,16 @@ export default async function Page(props: Props) {
|
||||
<Background>
|
||||
<div className="grid auto-rows-auto grid-cols-2 gap-2 ">
|
||||
{Object.keys(metaData).map((name) => (
|
||||
<Input
|
||||
key={name}
|
||||
id={name}
|
||||
title={metaData[name].label}
|
||||
type="text"
|
||||
required={metaData[name].required}
|
||||
defaultValue={data[name]}
|
||||
disabled={metaData[name].disabled}
|
||||
/>
|
||||
<Wrapper key={name}>
|
||||
<Title htmlFor={name} title={metaData[name].label} />
|
||||
<Input
|
||||
id={name}
|
||||
type="text"
|
||||
required={metaData[name].required}
|
||||
defaultValue={data[name]}
|
||||
disabled={metaData[name].disabled}
|
||||
/>
|
||||
</Wrapper>
|
||||
))}
|
||||
</div>
|
||||
<div className="grid grid-cols-3 gap-5 pt-3">
|
||||
|
||||
33
packages/ui/element.tsx
Normal file
33
packages/ui/element.tsx
Normal file
@ -0,0 +1,33 @@
|
||||
import { cn } from './utils';
|
||||
import type { VariantProps } from 'class-variance-authority';
|
||||
import { cva } from 'class-variance-authority';
|
||||
import type { PropsWithChildren } from 'react';
|
||||
import { forwardRef } from 'react';
|
||||
|
||||
const wrapperVariants = cva('flex flex-col');
|
||||
|
||||
export type DivProps = React.HTMLAttributes<HTMLDivElement> &
|
||||
VariantProps<typeof wrapperVariants> &
|
||||
PropsWithChildren;
|
||||
|
||||
export const Wrapper = forwardRef<HTMLDivElement, DivProps>(
|
||||
({ children, className, ...props }, ref) => (
|
||||
<div {...props} className={cn(wrapperVariants({ className }))} ref={ref}>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
);
|
||||
|
||||
const titleVariants = cva(
|
||||
'mb-1 block overflow-hidden overflow-ellipsis whitespace-nowrap text-sm font-medium text-black text-opacity-90'
|
||||
);
|
||||
|
||||
export type LabelProps = React.LabelHTMLAttributes<HTMLLabelElement>;
|
||||
|
||||
export const Title = forwardRef<HTMLLabelElement, LabelProps>(
|
||||
({ className, htmlFor, title, ...props }, ref) => (
|
||||
<label {...props} htmlFor={htmlFor} className={cn(titleVariants({ className }))} ref={ref}>
|
||||
{title}
|
||||
</label>
|
||||
)
|
||||
);
|
||||
@ -1,5 +1,6 @@
|
||||
export * from './background';
|
||||
export * from './button';
|
||||
export * from './content';
|
||||
export * from './header'
|
||||
export * from './input'
|
||||
export * from './element';
|
||||
export * from './header';
|
||||
export * from './input';
|
||||
|
||||
@ -11,19 +11,11 @@ export type InputProps = React.InputHTMLAttributes<HTMLInputElement> &
|
||||
VariantProps<typeof variants>;
|
||||
|
||||
export const Input = forwardRef<HTMLInputElement, InputProps>(({ className, ...props }, ref) => (
|
||||
<div className="flex flex-col">
|
||||
<label
|
||||
htmlFor={props.id}
|
||||
className="mb-1 block overflow-hidden overflow-ellipsis whitespace-nowrap text-sm font-medium text-black text-opacity-90"
|
||||
>
|
||||
{props.title}
|
||||
</label>
|
||||
<input
|
||||
ref={ref}
|
||||
type={props.type}
|
||||
id={props.id}
|
||||
className={cn(variants({ className }))}
|
||||
{...props}
|
||||
/>
|
||||
</div>
|
||||
<input
|
||||
ref={ref}
|
||||
type={props.type}
|
||||
id={props.id}
|
||||
className={cn(variants({ className }))}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user