Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(3165): add label and select generic components #3820

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions app/components/generic/Label.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use client';

import classNames from 'classnames';
import React from 'react';

export default function Label({
children,
htmlFor,
className = '',
required = false,
}: {
children: React.ReactNode;
htmlFor: string;
className?: string;
required?: boolean;
}) {
return (
<label
htmlFor={htmlFor}
className={classNames('block text-sm font-medium leading-6 text-gray-900 mb--1', className)}
>
{children}
{required && <span className="text-red-500">*</span>}
</label>
);
}
58 changes: 58 additions & 0 deletions app/components/generic/select/FormMultiSelect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
'use client';

import { MultiSelect, ComboboxData } from '@mantine/core';
import classnames from 'classnames';
import _kebabCase from 'lodash-es/kebabCase';
import { FocusEventHandler } from 'react';
import Label from '../Label';

export interface FormMultiSelectProps {
id?: string;
name: string;
label?: string;
data: ComboboxData;
onChange: (value: string[]) => void;
onBlur?: FocusEventHandler<HTMLInputElement> | undefined;
value: string[];
disabled?: boolean;
classNames?: {
wrapper?: string;
label?: string;
input?: string;
};
}

export default function FormMultiSelect({
id,
name,
label,
classNames,
data,
onChange,
onBlur,
value,
disabled = false,
}: FormMultiSelectProps) {
if (!id) id = _kebabCase(name);

return (
<div className={classNames?.wrapper}>
{label && (
<Label htmlFor={id} className={classNames?.label}>
{label}
</Label>
)}

<MultiSelect
placeholder="select..."
data={data}
onChange={onChange}
onBlur={onBlur}
value={value}
searchable
disabled={disabled}
classNames={{ input: classnames('text-md', classNames?.input) }}
/>
</div>
);
}
60 changes: 60 additions & 0 deletions app/components/generic/select/FormSingleSelect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
'use client';

import { Select, ComboboxData, ComboboxItem } from '@mantine/core';
import classnames from 'classnames';
import _kebabCase from 'lodash-es/kebabCase';
import { FocusEventHandler } from 'react';
import Label from '../Label';

export interface FormSingleSelectProps {
id?: string;
name: string;
label?: string;
data: ComboboxData;
onChange: (value: string, option: ComboboxItem) => void;
onBlur?: FocusEventHandler<HTMLInputElement> | undefined;
value: string;
disabled?: boolean;
classNames?: {
wrapper?: string;
label?: string;
input?: string;
};
}

export default function FormSingleSelect({
id,
name,
label,
classNames,
data,
onChange,
onBlur,
value,
disabled = false,
}: FormSingleSelectProps) {
if (!id) id = _kebabCase(name);

return (
<div className={classNames?.wrapper}>
{label && (
<Label htmlFor={id} className={classNames?.label}>
{label}
</Label>
)}

<Select
placeholder="select..."
data={data}
onChange={(val, option) => {
if (val) onChange(val, option);
}}
onBlur={onBlur}
value={value}
searchable
disabled={disabled}
classNames={{ input: classnames('text-md', classNames?.input) }}
/>
</div>
);
}
105 changes: 105 additions & 0 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading