@betterinternship/components 3.4.1 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -38
- package/dist/brand-logos.d.ts +4 -0
- package/dist/brand-logos.js +13 -0
- package/dist/brand-logos.js.map +1 -0
- package/dist/components/accordion.js.map +1 -1
- package/dist/components/animated-count.js.map +1 -1
- package/dist/components/animated-shiny-text.js.map +1 -1
- package/dist/components/app-header.js.map +1 -1
- package/dist/components/autocomplete.d.ts +1 -2
- package/dist/components/autocomplete.js +75 -64
- package/dist/components/autocomplete.js.map +1 -1
- package/dist/components/avatar.js.map +1 -1
- package/dist/components/badge.js.map +1 -1
- package/dist/components/banner.js.map +1 -1
- package/dist/components/button.js.map +1 -1
- package/dist/components/calendar.js.map +1 -1
- package/dist/components/card.js.map +1 -1
- package/dist/components/carousel.js.map +1 -1
- package/dist/components/checkbox-field.d.ts +18 -0
- package/dist/components/checkbox-field.js +25 -0
- package/dist/components/checkbox-field.js.map +1 -0
- package/dist/components/checkbox-group.d.ts +33 -0
- package/dist/components/checkbox-group.js +43 -0
- package/dist/components/checkbox-group.js.map +1 -0
- package/dist/components/checkbox.d.ts +1 -1
- package/dist/components/checkbox.js +6 -2
- package/dist/components/checkbox.js.map +1 -1
- package/dist/components/chip-select.d.ts +11 -2
- package/dist/components/chip-select.js +9 -4
- package/dist/components/chip-select.js.map +1 -1
- package/dist/components/collapsible.js.map +1 -1
- package/dist/components/context-menu.js.map +1 -1
- package/dist/components/{form-date-picker.d.ts → date-picker.d.ts} +11 -8
- package/dist/components/date-picker.js +57 -0
- package/dist/components/date-picker.js.map +1 -0
- package/dist/components/dialog.js.map +1 -1
- package/dist/components/divider.js.map +1 -1
- package/dist/components/dot-matrix.js.map +1 -1
- package/dist/components/dropdown-menu.js.map +1 -1
- package/dist/components/dropdown.js +7 -2
- package/dist/components/dropdown.js.map +1 -1
- package/dist/components/error.js.map +1 -1
- package/dist/components/fab.js.map +1 -1
- package/dist/components/file-upload.js.map +1 -1
- package/dist/components/filter-chip.js.map +1 -1
- package/dist/components/form-field.d.ts +60 -5
- package/dist/components/form-field.js +55 -5
- package/dist/components/form-field.js.map +1 -1
- package/dist/components/hover-card.js.map +1 -1
- package/dist/components/input-otp.js.map +1 -1
- package/dist/components/input.js +3 -1
- package/dist/components/input.js.map +1 -1
- package/dist/components/label.js.map +1 -1
- package/dist/components/loader.js.map +1 -1
- package/dist/components/magnetic-button.js.map +1 -1
- package/dist/components/messages.js.map +1 -1
- package/dist/components/mobile-sheet-portal.js.map +1 -1
- package/dist/components/{form-month-picker.d.ts → month-picker.d.ts} +6 -6
- package/dist/components/month-picker.js +57 -0
- package/dist/components/month-picker.js.map +1 -0
- package/dist/components/option-list.js.map +1 -1
- package/dist/components/page-header.js.map +1 -1
- package/dist/components/paginator.js.map +1 -1
- package/dist/components/popover.js.map +1 -1
- package/dist/components/progress.js.map +1 -1
- package/dist/components/radio-group.d.ts +11 -1
- package/dist/components/radio-group.js +17 -4
- package/dist/components/radio-group.js.map +1 -1
- package/dist/components/select.js +38 -2
- package/dist/components/select.js.map +1 -1
- package/dist/components/sheet.d.ts +1 -1
- package/dist/components/sheet.js.map +1 -1
- package/dist/components/skeleton.js.map +1 -1
- package/dist/components/slider.js.map +1 -1
- package/dist/components/sonner-toast.js +133 -133
- package/dist/components/sonner-toast.js.map +1 -1
- package/dist/components/stepper.js.map +1 -1
- package/dist/components/switch.d.ts +1 -1
- package/dist/components/switch.js +4 -1
- package/dist/components/switch.js.map +1 -1
- package/dist/components/table.js +5 -5
- package/dist/components/table.js.map +1 -1
- package/dist/components/tabs.js.map +1 -1
- package/dist/components/textarea.d.ts +1 -1
- package/dist/components/textarea.js +3 -1
- package/dist/components/textarea.js.map +1 -1
- package/dist/components/time-input.d.ts +9 -0
- package/dist/components/time-input.js +65 -0
- package/dist/components/time-input.js.map +1 -0
- package/dist/components/timeline.js.map +1 -1
- package/dist/components/toggle.js.map +1 -1
- package/dist/components/tooltip.js.map +1 -1
- package/dist/hooks/use-detect-click-outside.js.map +1 -1
- package/dist/hooks/use-field-focus.d.ts +1 -1
- package/dist/hooks/use-field-focus.js +1 -1
- package/dist/hooks/use-field-focus.js.map +1 -1
- package/dist/hooks/use-mobile-sheet-viewport.js.map +1 -1
- package/dist/hooks/use-mobile.js.map +1 -1
- package/dist/hooks/use-resource-table.js.map +1 -1
- package/dist/hooks/useMQJob.js.map +1 -1
- package/dist/index.d.ts +9 -12
- package/dist/index.js +8 -11
- package/dist/index.js.map +1 -1
- package/dist/lib/interaction-styles.js.map +1 -1
- package/dist/logos/base/betterinternship.svg.js +4 -0
- package/dist/logos/base/betterinternship.svg.js.map +1 -0
- package/dist/logos/black_fill/betterinternship_black.svg.js +4 -0
- package/dist/logos/black_fill/betterinternship_black.svg.js.map +1 -0
- package/dist/logos/circle/betterinternship_circle.svg.js +4 -0
- package/dist/logos/circle/betterinternship_circle.svg.js.map +1 -0
- package/dist/logos/white_fill/betterinternship_white.svg.js +4 -0
- package/dist/logos/white_fill/betterinternship_white.svg.js.map +1 -0
- package/dist/node_modules/tailwind-merge/dist/bundle-mjs.js +54 -2
- package/dist/node_modules/tailwind-merge/dist/bundle-mjs.js.map +1 -1
- package/dist/utils.js +11 -1
- package/dist/utils.js.map +1 -1
- package/package.json +317 -330
- package/theme.css +414 -414
- package/theme.legacy.css +84 -84
- package/dist/components/form-checkbox-group.d.ts +0 -31
- package/dist/components/form-checkbox-group.js +0 -30
- package/dist/components/form-checkbox-group.js.map +0 -1
- package/dist/components/form-checkbox.d.ts +0 -15
- package/dist/components/form-checkbox.js +0 -15
- package/dist/components/form-checkbox.js.map +0 -1
- package/dist/components/form-date-picker.js +0 -56
- package/dist/components/form-date-picker.js.map +0 -1
- package/dist/components/form-input.d.ts +0 -11
- package/dist/components/form-input.js +0 -13
- package/dist/components/form-input.js.map +0 -1
- package/dist/components/form-month-picker.js +0 -56
- package/dist/components/form-month-picker.js.map +0 -1
- package/dist/components/form-radio.d.ts +0 -15
- package/dist/components/form-radio.js +0 -20
- package/dist/components/form-radio.js.map +0 -1
- package/dist/components/form-textarea.d.ts +0 -11
- package/dist/components/form-textarea.js +0 -12
- package/dist/components/form-textarea.js.map +0 -1
- package/dist/components/form.d.ts +0 -24
- package/dist/components/form.js +0 -71
- package/dist/components/form.js.map +0 -1
- package/dist/components/time-input-native.d.ts +0 -14
- package/dist/components/time-input-native.js +0 -62
- package/dist/components/time-input-native.js.map +0 -1
- package/dist/node_modules/react-hook-form/dist/index.esm.js +0 -706
- package/dist/node_modules/react-hook-form/dist/index.esm.js.map +0 -1
package/dist/components/form.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx } from 'react/jsx-runtime';
|
|
3
|
-
import * as React from 'react';
|
|
4
|
-
import { Slot } from '@radix-ui/react-slot';
|
|
5
|
-
import { useFormContext, FormProvider, Controller } from '../node_modules/react-hook-form/dist/index.esm.js';
|
|
6
|
-
import { cn } from '../utils.js';
|
|
7
|
-
import { Label } from './label.js';
|
|
8
|
-
|
|
9
|
-
const Form = FormProvider;
|
|
10
|
-
const FormFieldContext = React.createContext({});
|
|
11
|
-
const FormField = ({ ...props }) => {
|
|
12
|
-
return (jsx(FormFieldContext.Provider, { value: { name: props.name }, children: jsx(Controller, { ...props }) }));
|
|
13
|
-
};
|
|
14
|
-
const useFormField = () => {
|
|
15
|
-
const fieldContext = React.useContext(FormFieldContext);
|
|
16
|
-
const itemContext = React.useContext(FormItemContext);
|
|
17
|
-
const { getFieldState, formState } = useFormContext();
|
|
18
|
-
const fieldState = getFieldState(fieldContext.name, formState);
|
|
19
|
-
if (!fieldContext) {
|
|
20
|
-
throw new Error("useFormField should be used within <FormField>");
|
|
21
|
-
}
|
|
22
|
-
const { id } = itemContext;
|
|
23
|
-
return {
|
|
24
|
-
id,
|
|
25
|
-
name: fieldContext.name,
|
|
26
|
-
formItemId: `${id}-form-item`,
|
|
27
|
-
formDescriptionId: `${id}-form-item-description`,
|
|
28
|
-
formMessageId: `${id}-form-item-message`,
|
|
29
|
-
...fieldState,
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
const FormItemContext = React.createContext({});
|
|
33
|
-
const FormItem = React.forwardRef(({ className, ...props }, ref) => {
|
|
34
|
-
const id = React.useId();
|
|
35
|
-
return (jsx(FormItemContext.Provider, { value: { id }, children: jsx("div", { ref: ref, className: cn("space-y-field-label-gap", className), ...props }) }));
|
|
36
|
-
});
|
|
37
|
-
FormItem.displayName = "FormItem";
|
|
38
|
-
const FormLabel = React.forwardRef(({ className, required = false, children, ...props }, ref) => {
|
|
39
|
-
const { error, formItemId } = useFormField();
|
|
40
|
-
return (jsx(Label, { label: children, required: required, className: "mb-0", labelProps: {
|
|
41
|
-
ref,
|
|
42
|
-
htmlFor: formItemId,
|
|
43
|
-
...props,
|
|
44
|
-
className: cn(error && 'text-destructive', className),
|
|
45
|
-
} }));
|
|
46
|
-
});
|
|
47
|
-
FormLabel.displayName = "FormLabel";
|
|
48
|
-
const FormControl = React.forwardRef(({ ...props }, ref) => {
|
|
49
|
-
const { error, formItemId, formDescriptionId, formMessageId } = useFormField();
|
|
50
|
-
return (jsx(Slot, { ref: ref, id: formItemId, "aria-describedby": !error
|
|
51
|
-
? `${formDescriptionId}`
|
|
52
|
-
: `${formDescriptionId} ${formMessageId}`, "aria-invalid": !!error, ...props }));
|
|
53
|
-
});
|
|
54
|
-
FormControl.displayName = "FormControl";
|
|
55
|
-
const FormDescription = React.forwardRef(({ className, ...props }, ref) => {
|
|
56
|
-
const { formDescriptionId } = useFormField();
|
|
57
|
-
return (jsx("p", { ref: ref, id: formDescriptionId, className: cn("text-sm leading-normal text-muted-foreground", className), ...props }));
|
|
58
|
-
});
|
|
59
|
-
FormDescription.displayName = "FormDescription";
|
|
60
|
-
const FormMessage = React.forwardRef(({ className, children, ...props }, ref) => {
|
|
61
|
-
const { error, formMessageId } = useFormField();
|
|
62
|
-
const body = error ? String(error?.message) : children;
|
|
63
|
-
if (!body) {
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
return (jsx("p", { ref: ref, id: formMessageId, className: cn("text-sm leading-normal font-medium text-destructive", className), ...props, children: body }));
|
|
67
|
-
});
|
|
68
|
-
FormMessage.displayName = "FormMessage";
|
|
69
|
-
|
|
70
|
-
export { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, useFormField };
|
|
71
|
-
//# sourceMappingURL=form.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"form.js","sources":["../../src/components/form.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { Slot } from \"@radix-ui/react-slot\";\nimport {\n Controller,\n ControllerProps,\n FieldPath,\n FieldValues,\n FormProvider,\n useFormContext,\n} from \"react-hook-form\";\n\nimport { cn } from \"@/utils\";\nimport { Label } from './label';\n\nconst Form = FormProvider;\n\ntype FormFieldContextValue<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n> = {\n name: TName;\n};\n\nconst FormFieldContext = React.createContext<FormFieldContextValue>(\n {} as FormFieldContextValue,\n);\n\nconst FormField = <\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n>({\n ...props\n}: ControllerProps<TFieldValues, TName>) => {\n return (\n <FormFieldContext.Provider value={{ name: props.name }}>\n <Controller {...props} />\n </FormFieldContext.Provider>\n );\n};\n\nconst useFormField = () => {\n const fieldContext = React.useContext(FormFieldContext);\n const itemContext = React.useContext(FormItemContext);\n const { getFieldState, formState } = useFormContext();\n\n const fieldState = getFieldState(fieldContext.name, formState);\n\n if (!fieldContext) {\n throw new Error(\"useFormField should be used within <FormField>\");\n }\n\n const { id } = itemContext;\n\n return {\n id,\n name: fieldContext.name,\n formItemId: `${id}-form-item`,\n formDescriptionId: `${id}-form-item-description`,\n formMessageId: `${id}-form-item-message`,\n ...fieldState,\n };\n};\n\ntype FormItemContextValue = {\n id: string;\n};\n\nconst FormItemContext = React.createContext<FormItemContextValue>(\n {} as FormItemContextValue,\n);\n\nconst FormItem = React.forwardRef<\n HTMLDivElement,\n React.HTMLAttributes<HTMLDivElement>\n>(({ className, ...props }, ref) => {\n const id = React.useId();\n\n return (\n <FormItemContext.Provider value={{ id }}>\n <div ref={ref} className={cn(\"space-y-field-label-gap\", className)} {...props} />\n </FormItemContext.Provider>\n );\n});\nFormItem.displayName = \"FormItem\";\n\nconst FormLabel = React.forwardRef<\n HTMLLabelElement,\n React.ComponentPropsWithoutRef<'label'> & { required?: boolean }\n>(({ className, required = false, children, ...props }, ref) => {\n const { error, formItemId } = useFormField();\n\n return (\n <Label\n label={children}\n required={required}\n className=\"mb-0\"\n labelProps={{\n ref,\n htmlFor: formItemId,\n ...props,\n className: cn(error && 'text-destructive', className),\n }}\n />\n );\n});\nFormLabel.displayName = \"FormLabel\";\n\nconst FormControl = React.forwardRef<\n React.ElementRef<typeof Slot>,\n React.ComponentPropsWithoutRef<typeof Slot>\n>(({ ...props }, ref) => {\n const { error, formItemId, formDescriptionId, formMessageId } =\n useFormField();\n\n return (\n <Slot\n ref={ref}\n id={formItemId}\n aria-describedby={\n !error\n ? `${formDescriptionId}`\n : `${formDescriptionId} ${formMessageId}`\n }\n aria-invalid={!!error}\n {...props}\n />\n );\n});\nFormControl.displayName = \"FormControl\";\n\nconst FormDescription = React.forwardRef<\n HTMLParagraphElement,\n React.HTMLAttributes<HTMLParagraphElement>\n>(({ className, ...props }, ref) => {\n const { formDescriptionId } = useFormField();\n\n return (\n <p\n ref={ref}\n id={formDescriptionId}\n className={cn(\"text-sm leading-normal text-muted-foreground\", className)}\n {...props}\n />\n );\n});\nFormDescription.displayName = \"FormDescription\";\n\nconst FormMessage = React.forwardRef<\n HTMLParagraphElement,\n React.HTMLAttributes<HTMLParagraphElement>\n>(({ className, children, ...props }, ref) => {\n const { error, formMessageId } = useFormField();\n const body = error ? String(error?.message) : children;\n\n if (!body) {\n return null;\n }\n\n return (\n <p\n ref={ref}\n id={formMessageId}\n className={cn(\"text-sm leading-normal font-medium text-destructive\", className)}\n {...props}\n >\n {body}\n </p>\n );\n});\nFormMessage.displayName = \"FormMessage\";\n\nexport {\n useFormField,\n Form,\n FormItem,\n FormLabel,\n FormControl,\n FormDescription,\n FormMessage,\n FormField,\n};\n"],"names":[],"mappings":";;;;;;;;AAgBA;AASA;AAIA;;AAWA;AAEA;;;;;;AAQI;;AAGF;;;;;;;AAQE;;AAEJ;AAMA;AAIA;AAIE;AAEA;AAKF;AACA;AAEA;;AAME;;AAOM;AACA;;AAED;AAGP;AACA;AAEA;AAIE;AAGA;;AAOQ;AAMV;AACA;AAEA;AAIE;;AAUF;AACA;AAEA;;AAKE;;AAGE;;;AAaJ;AACA;;"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
export type TimeInputNativeProps = {
|
|
3
|
-
label: string;
|
|
4
|
-
/** "HH:MM" */
|
|
5
|
-
value?: string;
|
|
6
|
-
onChange?: (v?: string) => void;
|
|
7
|
-
required?: boolean;
|
|
8
|
-
helper?: string;
|
|
9
|
-
className?: string;
|
|
10
|
-
tooltip?: string;
|
|
11
|
-
tooltipId?: string;
|
|
12
|
-
labelAddon?: React.ReactNode;
|
|
13
|
-
} & Omit<React.InputHTMLAttributes<HTMLInputElement>, 'onChange'>;
|
|
14
|
-
export declare function TimeInputNative({ label, value, onChange, required, helper, className, tooltip, tooltipId, labelAddon, ...props }: TimeInputNativeProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
-
import * as React from 'react';
|
|
4
|
-
import { Input } from './input.js';
|
|
5
|
-
import { FormField } from './form-field.js';
|
|
6
|
-
import { Clock } from 'lucide-react';
|
|
7
|
-
import { Popover, PopoverAnchor, PopoverTrigger, PopoverContent } from './popover.js';
|
|
8
|
-
import { useFieldFocus, FieldChromeContext, fieldFocusOutlineClassName, fieldInteractionClassName } from '../hooks/use-field-focus.js';
|
|
9
|
-
import { cn } from '../utils.js';
|
|
10
|
-
|
|
11
|
-
function TimeInputNative({ label, value, onChange, required = true, helper, className, tooltip, tooltipId, labelAddon, ...props }) {
|
|
12
|
-
const [open, setOpen] = React.useState(false);
|
|
13
|
-
const formatTime = (time) => {
|
|
14
|
-
if (!time)
|
|
15
|
-
return '';
|
|
16
|
-
const [hour, minute] = time.split(':');
|
|
17
|
-
return `${String(Number(hour) % 12 || 12).padStart(2, '0')}:${minute} ${Number(hour) >= 12 ? 'PM' : 'AM'}`;
|
|
18
|
-
};
|
|
19
|
-
const [draft, setDraft] = React.useState(() => formatTime(value));
|
|
20
|
-
React.useEffect(() => { setDraft(formatTime(value)); }, [value]);
|
|
21
|
-
const disabled = props.disabled;
|
|
22
|
-
const { keyboardFocus, focusProps } = useFieldFocus();
|
|
23
|
-
const updatePart = (part, next) => {
|
|
24
|
-
const [hour = '09', minute = '00'] = (value || '09:00').split(':');
|
|
25
|
-
const currentHour = Number(hour);
|
|
26
|
-
const nextHour = part === 'hour'
|
|
27
|
-
? Number(next) % 12 + (currentHour >= 12 ? 12 : 0)
|
|
28
|
-
: part === 'period' ? currentHour % 12 + (next === 'PM' ? 12 : 0) : currentHour;
|
|
29
|
-
onChange?.(`${String(nextHour).padStart(2, '0')}:${part === 'minute' ? next : minute}`);
|
|
30
|
-
};
|
|
31
|
-
return (jsxs(FormField, { label: label, required: required, tooltip: tooltip, tooltipId: tooltipId, labelAddon: labelAddon, className: className, children: [jsxs(Popover, { open: open, onOpenChange: setOpen, children: [jsx(PopoverAnchor, { asChild: true, children: jsx("div", { ...focusProps, className: cn('relative', !disabled && fieldInteractionClassName, !disabled && keyboardFocus && fieldFocusOutlineClassName), children: jsxs(FieldChromeContext, { value: true, children: [jsx(Input, { ...props, type: "text", placeholder: props.placeholder ?? 'HH:MM AM/PM', value: draft, onChange: (event) => {
|
|
32
|
-
const next = event.target.value;
|
|
33
|
-
// Permit incomplete time segments while typing, but no arbitrary text.
|
|
34
|
-
if (!/^\d{0,2}(:[0-5]?\d?)?(\s?[AaPp]?[Mm]?)?$/.test(next))
|
|
35
|
-
return;
|
|
36
|
-
const parts = next.match(/^(\d{1,2})/);
|
|
37
|
-
if (parts && Number(parts[1]) > 23)
|
|
38
|
-
return;
|
|
39
|
-
setDraft(next);
|
|
40
|
-
if (!next.trim()) {
|
|
41
|
-
onChange?.(undefined);
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
const match = next.trim().match(/^(\d{1,2}):(\d{2})\s*(AM|PM)?$/i);
|
|
45
|
-
if (!match)
|
|
46
|
-
return;
|
|
47
|
-
let hour = Number(match[1]);
|
|
48
|
-
const minute = Number(match[2]);
|
|
49
|
-
if (minute > 59 || hour > 23 || (match[3] && (hour < 1 || hour > 12)))
|
|
50
|
-
return;
|
|
51
|
-
if (match[3])
|
|
52
|
-
hour = hour % 12 + (match[3].toUpperCase() === 'PM' ? 12 : 0);
|
|
53
|
-
onChange?.(`${String(hour).padStart(2, '0')}:${match[2]}`);
|
|
54
|
-
}, onBlur: (event) => {
|
|
55
|
-
setDraft(formatTime(value));
|
|
56
|
-
props.onBlur?.(event);
|
|
57
|
-
}, onClick: (event) => { props.onClick?.(event); if (!event.defaultPrevented && !disabled && !props.readOnly)
|
|
58
|
-
setOpen(true); }, className: "pr-11" }), jsx(PopoverTrigger, { asChild: true, children: jsx("button", { type: "button", disabled: disabled || props.readOnly, "aria-label": `Choose ${label.toLowerCase()}`, className: "absolute inset-y-0 right-0 z-20 flex w-11 items-center justify-center rounded-control-lg text-muted-foreground hover:text-foreground disabled:opacity-50", children: jsx(Clock, { className: "size-4", "aria-hidden": "true" }) }) })] }) }) }), jsx(PopoverContent, { align: "start", sideOffset: 6, className: "w-72", "aria-label": `Choose ${label.toLowerCase()}`, onOpenAutoFocus: event => event.preventDefault(), children: jsxs("div", { className: "grid grid-cols-3 gap-2", children: [jsx("div", { children: jsx("select", { "aria-label": "Hour", className: "h-form-control rounded-control-lg border border-input bg-background px-field-padding-x text-base text-foreground", value: String(Number(value?.split(':')[0] ?? 9) % 12 || 12).padStart(2, '0'), onChange: event => updatePart('hour', event.target.value), children: Array.from({ length: 12 }, (_, hour) => { const text = String(hour + 1).padStart(2, '0'); return jsx("option", { value: text, children: text }, text); }) }) }), jsx("div", { children: jsx("select", { "aria-label": "Minute", className: "h-form-control rounded-control-lg border border-input bg-background px-field-padding-x text-base text-foreground", value: value?.split(':')[1] ?? '00', onChange: event => updatePart('minute', event.target.value), children: Array.from({ length: 60 }, (_, minute) => { const text = String(minute).padStart(2, '0'); return jsx("option", { value: text, children: text }, text); }) }) }), jsx("div", { children: jsxs("select", { "aria-label": "AM or PM", className: "h-form-control rounded-control-lg border border-input bg-background px-field-padding-x text-base text-foreground", value: Number(value?.split(':')[0] ?? 9) >= 12 ? 'PM' : 'AM', onChange: event => updatePart('period', event.target.value), children: [jsx("option", { value: "AM", children: "AM" }), jsx("option", { value: "PM", children: "PM" })] }) })] }) })] }), helper && jsx("p", { className: "mt-1 text-sm text-muted-foreground", children: helper })] }));
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export { TimeInputNative };
|
|
62
|
-
//# sourceMappingURL=time-input-native.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"time-input-native.js","sources":["../../src/components/time-input-native.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\n\nimport { Input } from '@/components/input';\nimport { FormField } from './form-field';\nimport { Clock } from 'lucide-react';\nimport { Popover, PopoverAnchor, PopoverContent, PopoverTrigger } from './popover';\nimport { FieldChromeContext, fieldInteractionClassName, fieldFocusOutlineClassName, useFieldFocus } from '@/hooks/use-field-focus';\nimport { cn } from '@/utils';\n\nexport type TimeInputNativeProps = {\n label: string;\n /** \"HH:MM\" */\n value?: string;\n onChange?: (v?: string) => void;\n required?: boolean;\n helper?: string;\n className?: string;\n tooltip?: string;\n tooltipId?: string;\n labelAddon?: React.ReactNode;\n} & Omit<React.InputHTMLAttributes<HTMLInputElement>, 'onChange'>;\n\nexport function TimeInputNative({\n label,\n value,\n onChange,\n required = true,\n helper,\n className,\n tooltip,\n tooltipId,\n labelAddon,\n ...props\n}: TimeInputNativeProps) {\n const [open, setOpen] = React.useState(false);\n const formatTime = (time?: string) => {\n if (!time) return '';\n const [hour, minute] = time.split(':');\n return `${String(Number(hour) % 12 || 12).padStart(2, '0')}:${minute} ${Number(hour) >= 12 ? 'PM' : 'AM'}`;\n };\n const [draft, setDraft] = React.useState(() => formatTime(value));\n React.useEffect(() => { setDraft(formatTime(value)); }, [value]);\n const disabled = props.disabled;\n const { keyboardFocus, focusProps } = useFieldFocus();\n const updatePart = (part: 'hour' | 'minute' | 'period', next: string) => {\n const [hour = '09', minute = '00'] = (value || '09:00').split(':');\n const currentHour = Number(hour);\n const nextHour = part === 'hour'\n ? Number(next) % 12 + (currentHour >= 12 ? 12 : 0)\n : part === 'period' ? currentHour % 12 + (next === 'PM' ? 12 : 0) : currentHour;\n onChange?.(`${String(nextHour).padStart(2, '0')}:${part === 'minute' ? next : minute}`);\n };\n return (\n <FormField\n label={label}\n required={required}\n tooltip={tooltip}\n tooltipId={tooltipId}\n labelAddon={labelAddon}\n className={className}\n >\n <Popover open={open} onOpenChange={setOpen}>\n <PopoverAnchor asChild>\n <div {...focusProps} className={cn('relative', !disabled && fieldInteractionClassName, !disabled && keyboardFocus && fieldFocusOutlineClassName)}>\n <FieldChromeContext value={true}>\n <Input\n {...props}\n type=\"text\"\n placeholder={props.placeholder ?? 'HH:MM AM/PM'}\n value={draft}\n onChange={(event) => {\n const next = event.target.value;\n // Permit incomplete time segments while typing, but no arbitrary text.\n if (!/^\\d{0,2}(:[0-5]?\\d?)?(\\s?[AaPp]?[Mm]?)?$/.test(next)) return;\n const parts = next.match(/^(\\d{1,2})/);\n if (parts && Number(parts[1]) > 23) return;\n setDraft(next);\n if (!next.trim()) { onChange?.(undefined); return; }\n const match = next.trim().match(/^(\\d{1,2}):(\\d{2})\\s*(AM|PM)?$/i);\n if (!match) return;\n let hour = Number(match[1]);\n const minute = Number(match[2]);\n if (minute > 59 || hour > 23 || (match[3] && (hour < 1 || hour > 12))) return;\n if (match[3]) hour = hour % 12 + (match[3].toUpperCase() === 'PM' ? 12 : 0);\n onChange?.(`${String(hour).padStart(2, '0')}:${match[2]}`);\n }}\n onBlur={(event) => {\n setDraft(formatTime(value));\n props.onBlur?.(event);\n }}\n onClick={(event) => { props.onClick?.(event); if (!event.defaultPrevented && !disabled && !props.readOnly) setOpen(true); }}\n className=\"pr-11\"\n />\n <PopoverTrigger asChild>\n <button type=\"button\" disabled={disabled || props.readOnly} aria-label={`Choose ${label.toLowerCase()}`} className=\"absolute inset-y-0 right-0 z-20 flex w-11 items-center justify-center rounded-control-lg text-muted-foreground hover:text-foreground disabled:opacity-50\"><Clock className=\"size-4\" aria-hidden=\"true\" /></button>\n </PopoverTrigger>\n </FieldChromeContext>\n </div>\n </PopoverAnchor>\n <PopoverContent align=\"start\" sideOffset={6} className=\"w-72\" aria-label={`Choose ${label.toLowerCase()}`} onOpenAutoFocus={event => event.preventDefault()}>\n <div className=\"grid grid-cols-3 gap-2\">\n <div>\n <select aria-label=\"Hour\" className=\"h-form-control rounded-control-lg border border-input bg-background px-field-padding-x text-base text-foreground\" value={String(Number(value?.split(':')[0] ?? 9) % 12 || 12).padStart(2, '0')} onChange={event => updatePart('hour', event.target.value)}>\n {Array.from({ length: 12 }, (_, hour) => { const text = String(hour + 1).padStart(2, '0'); return <option key={text} value={text}>{text}</option>; })}\n </select>\n </div>\n <div>\n <select aria-label=\"Minute\" className=\"h-form-control rounded-control-lg border border-input bg-background px-field-padding-x text-base text-foreground\" value={value?.split(':')[1] ?? '00'} onChange={event => updatePart('minute', event.target.value)}>\n {Array.from({ length: 60 }, (_, minute) => { const text = String(minute).padStart(2, '0'); return <option key={text} value={text}>{text}</option>; })}\n </select>\n </div>\n <div>\n <select aria-label=\"AM or PM\" className=\"h-form-control rounded-control-lg border border-input bg-background px-field-padding-x text-base text-foreground\" value={Number(value?.split(':')[0] ?? 9) >= 12 ? 'PM' : 'AM'} onChange={event => updatePart('period', event.target.value)}>\n <option value=\"AM\">AM</option><option value=\"PM\">PM</option>\n </select>\n </div>\n </div>\n </PopoverContent>\n </Popover>\n {helper && <p className=\"mt-1 text-sm text-muted-foreground\">{helper}</p>}\n </FormField>\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;AAwBM;AAYJ;AACA;AACE;AAAW;AACX;AACA;AACF;AACA;;AAEA;;AAEA;;AAEE;AACA;;AAEE;AACF;AACF;;AAoBQ;;AAEA;;;;;;AAIA;AAAoB;;;;AAEpB;;;;;;;;;AAMF;AAEE;AACA;AACF;AAC2G;AAgCnH;;"}
|