@northlight/ui 2.2.0 → 2.4.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.
@@ -1,8 +1,8 @@
1
1
  import { AccordionProps, AccordionButtonProps, AccordionPanelProps, AccordionItemProps, AvatarProps as AvatarProps$1, AlertProps as AlertProps$1, AspectRatioProps, StackProps, BadgeProps, ButtonProps as ButtonProps$1, CheckboxProps as CheckboxProps$1, StackDirection, IconButtonProps as IconButtonProps$1, InputProps, FlexProps, BoxProps, TagProps as TagProps$1, IconProps as IconProps$1, SystemStyleObject, HeadingProps as HeadingProps$1, TextProps, FormLabelProps as FormLabelProps$1, Heading, Text, ModalProps as ModalProps$1, NumberInputProps as NumberInputProps$1, PinInputProps as PinInputProps$1, RadioProps as RadioProps$1, RadioGroupProps as RadioGroupProps$1, SpinnerProps as SpinnerProps$1, SwitchProps as SwitchProps$1, TabsProps as TabsProps$1, TabPanelProps as TabPanelProps$1, TextareaProps as TextareaProps$1, UseToastOptions as UseToastOptions$1, FadeProps as FadeProps$1, ScaleFadeProps as ScaleFadeProps$1, SlideProps as SlideProps$1, SlideFadeProps as SlideFadeProps$1, CollapseProps as CollapseProps$1, TabListProps, TabProps, LinkProps, GridProps, GridItemProps, EditableProps as EditableProps$1 } from '@chakra-ui/react';
2
2
  export { AbsoluteCenter, AccordionButtonProps, AccordionIcon, AccordionIconProps, AccordionItemProps, AccordionPanelProps, AccordionProps, AlertDescription, AlertDialog, AlertDialogBody, AlertDialogCloseButton, AlertDialogContent, AlertDialogFooter, AlertDialogHeader, AlertDialogOverlay, AlertIcon, AlertTitle, AspectRatioProps, BadgeProps, Box, BoxProps, BreadcrumbItem as Breadcrumb, BreadcrumbLink, BreadcrumbSeparator, Breadcrumb as Breadcrumbs, ButtonGroup, Card, CardBody, CardFooter, CardHeader, Center, Modal as ChakraModal, CheckboxGroup, Circle, CircularProgress, CircularProgressLabel, CloseButton, Code, Container, Divider, Drawer, DrawerBody, DrawerCloseButton, DrawerContent, DrawerFooter, DrawerHeader, DrawerOverlay, Editable, EditableInput, EditablePreview, Flex, FormControl, FormErrorMessage, FormHelperText, Grid, GridItem, HStack, Heading, Hide, Highlight, Image, Input, InputAddon, InputGroup, InputLeftAddon, InputLeftElement, InputRightAddon, InputRightElement, Kbd, Link, LinkOverlay, List, ListIcon, ListItem, Menu, MenuButton, MenuCommand, MenuDivider, MenuGroup, MenuIcon, MenuItem, MenuItemOption, MenuList, MenuOptionGroup, ModalBody, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, NumberDecrementStepper, NumberIncrementStepper, OrderedList, PinInputField, Popover, PopoverAnchor, PopoverArrow, PopoverBody, PopoverCloseButton, PopoverContent, PopoverFooter, PopoverHeader, PopoverTrigger, Portal, RangeSlider, RangeSliderFilledTrack, RangeSliderMark, RangeSliderThumb, RangeSliderTrack, Show, SimpleGrid, Skeleton, SkeletonCircle, SkeletonText, Slider, SliderFilledTrack, SliderMark, SliderThumb, SliderTrack, Spacer, Stack, StackDivider, Stat, StatArrow, StatGroup, StatHelpText, StatLabel, StatNumber, TabIndicator as StepIndicator, TabPanels as StepPanels, Tab, TabIndicator, TabList, TabPanels, Table, TableCaption, TableContainer, TagCloseButton, TagLabel, TagLeftIcon, TagRightIcon, Tbody, Td, Text, Tfoot, Th, Thead, Tooltip, Tr, UnorderedList, VStack, VisuallyHidden, VisuallyHiddenInput, Wrap, WrapItem, useBoolean, useBreakpoint, useBreakpointValue, useClipboard, useControllableProp, useControllableState, useDisclosure, useEditable, useEditableControls, useEditableState, useInterval, useMediaQuery, useMergeRefs, useNumberInput, useOutsideClick, usePrefersReducedMotion, useRadio, useRadioGroup, useTab, useTabs, useTheme, useToken } from '@chakra-ui/react';
3
3
  import * as React$1 from 'react';
4
- import React__default, { ChangeEvent, ComponentType, InputHTMLAttributes, ReactNode, ReactElement } from 'react';
5
- import { RegisterOptions, FieldValues, UseFormReturn as UseFormReturn$1, SetValueConfig, ControllerRenderProps, UseFormProps, FieldError, Merge, FieldErrorsImpl } from 'react-hook-form';
4
+ import React__default, { ChangeEvent, ComponentType, InputHTMLAttributes, ReactNode, ReactElement, RefObject } from 'react';
5
+ import { RegisterOptions, FieldValues, UseFormReturn as UseFormReturn$1, SetValueConfig, FieldPath, Control, ControllerRenderProps, UseFormProps, FieldError, Merge, FieldErrorsImpl } from 'react-hook-form';
6
6
  export { useController, useFieldArray, useForm, useFormContext, useFormState, useWatch } from 'react-hook-form';
7
7
  import { CheckboxGroupState } from '@react-stately/checkbox';
8
8
  import { RadioGroupState } from '@react-stately/radio';
@@ -2143,8 +2143,8 @@ type UseFormReturn<T extends FieldValues> = UseFormReturn$1<T>;
2143
2143
  type Maybe<T> = T | undefined;
2144
2144
  type CustomSubmitHandler<TFieldValues extends FieldValues> = (data: TFieldValues, event: UseFormReturn<TFieldValues>) => any | Promise<any>;
2145
2145
  type SetValueOptionsType = Maybe<SetValueConfig>;
2146
- interface FieldProps {
2147
- name: string;
2146
+ interface FieldProps<FormValues extends FieldValues = FieldValues, FieldName extends FieldPath<FormValues> = FieldPath<FormValues>> {
2147
+ name: FieldName;
2148
2148
  /** Label displayed as text beside or under/over
2149
2149
  * (depending on direction prop) over children. Recommended for accesibility */
2150
2150
  label?: string;
@@ -2161,7 +2161,12 @@ interface FieldProps {
2161
2161
  * for more information view https://react-hook-form.com/api/useform/register/ docs. (Whatever you put into the validate object will be put as the second options arguments on the react hook form register method)
2162
2162
  * */
2163
2163
  validate?: RegisterOptions;
2164
- children: (field: ControllerRenderProps<FieldValues, string>, methods: UseFormReturn<FieldValues>) => JSX.Element | JSX.Element;
2164
+ /**
2165
+ * The value is taken from the formContext by default,
2166
+ * but may be manually specified to ensure field type inference.
2167
+ * */
2168
+ control?: Control<FormValues>;
2169
+ children: (field: ControllerRenderProps<FormValues, FieldName>, methods: UseFormReturn<FormValues>) => JSX.Element;
2165
2170
  }
2166
2171
  interface FormProps<FormValues extends FieldValues> {
2167
2172
  /** This should contain an object with the name of the fields and their default values. */
@@ -2468,7 +2473,6 @@ type SelectFieldProps<T> = Omit<SelectProps<T>, 'onChange'> & InputFieldProps &
2468
2473
  * <Select
2469
2474
  * options={[{ label: 'Option 1', value: '1' }, { label: 'Option 2', value: '2' }]}
2470
2475
  * onChange={(value, action) => console.log('Selected:', value)}
2471
- * isClearable={ true }
2472
2476
  * />
2473
2477
  * ?)
2474
2478
  *
@@ -3227,8 +3231,42 @@ declare const Form: <FormValues extends FieldValues>(props: FormProps<FormValues
3227
3231
  * }
3228
3232
  * ?)
3229
3233
  *
3234
+ * @example (Example)
3235
+ * ## Type-safety
3236
+ * There are multiple ways to provide types for
3237
+ * the field callback values. To ensure that each
3238
+ * component within the field receives the correct
3239
+ * value, it's essential to make the field aware
3240
+ * of the form state values. When the Field component
3241
+ * does not receive any types, the "value" callback
3242
+ * argument will have the type of "any".
3243
+ * <br /><br />
3244
+ * ### Passing down the control prop (Recommended)
3245
+ * (?
3246
+ * <Form initialValues={{username: 'Alex'}}>
3247
+ * {
3248
+ * ({ control }) => {
3249
+ * <Box p="2">
3250
+ * <Field name="username" label="Input name" control={ control }>
3251
+ * {({value, onChange}) => ( // "value" has type of "string"
3252
+ * <Input value={value} onChange={onChange} />
3253
+ * )}
3254
+ * </Field>
3255
+ * </Box>
3256
+ * }
3257
+ * }
3258
+ * </Form>
3259
+ * ?)
3260
+ * <br /><br />
3261
+ * ### Specifying generic arguments
3262
+ * You can also specify generic arguments on the Field
3263
+ * component to ensure that "value" has a valid type.
3264
+ * The passed generic type combined with the valid
3265
+ * "name" property ensures that "value" has the expected
3266
+ * type received from the generic type:
3267
+ * `<Field<MyFormBody> name="username">...</Field>`
3230
3268
  */
3231
- declare function Field({ name, label, children, direction, isRequired, noLabelConnection, validate, }: FieldProps): JSX.Element;
3269
+ declare function Field<FormValues extends FieldValues = FieldValues, FieldName extends FieldPath<FormValues> = FieldPath<FormValues>>({ name, label, children, direction, isRequired, noLabelConnection, validate, control: passedControl, }: FieldProps<FormValues, FieldName>): JSX.Element;
3232
3270
 
3233
3271
  declare const useSetValueRefreshed: () => (name: any, value: any, options: SetValueOptionsType) => void;
3234
3272
 
@@ -3469,6 +3507,14 @@ declare const useDebounce: <T>(value: T, delay: number) => T;
3469
3507
 
3470
3508
  declare const useLoadingMessage: (prefix?: string, delay?: number) => string;
3471
3509
 
3510
+ interface Message {
3511
+ content: string;
3512
+ role: string;
3513
+ type?: string;
3514
+ data?: string;
3515
+ }
3516
+ declare const useScrollToBottom: (scrollView: RefObject<HTMLDivElement>, messages: Message[]) => void;
3517
+
3472
3518
  declare const useArrowFocus: (columns: number) => {
3473
3519
  defaultArrows: (e: any) => void;
3474
3520
  focusPrevious: ({ repeat, wrap, }?: {
@@ -3501,4 +3547,4 @@ declare const useSelectCallbacks: <T extends BasicOption>({ onChange, onAdd, onR
3501
3547
  declare const theme: Record<string, any>;
3502
3548
  declare const tottTheme: Record<string, any>;
3503
3549
 
3504
- export { Accordion, AccordionButton, AccordionItem, AccordionPanel, Alert, AlertProps, AlertVariants, AspectRatio, AsyncError, AsyncErrorProps, Avatar, AvatarBadgeProps, AvatarGroup, AvatarGroupProps, AvatarProps, Badge, BasicOption, Blinker, BlinkerProps, BlockVariant, BlockVariantColorTuple, Blockquote, BodyType, Button, ButtonProps, ButtonVariants, Capitalized, Carousel, Checkbox, CheckboxField, CheckboxFieldProps, CheckboxProps, CheckboxVariants, ChildrenType, Clickable, ClickableProps, ClipboardInput, ClipboardInputProps, Collapse, CollapseProps, Color, ColorButtonProps, ColorGrade, ColorPicker, ColorPickerField, ColorPickerFieldProps, ColorPickerProps, ColorShades, ColorsExpandButtonProps, ConfirmDeleteModalProps, CurrentTheme, CustomContainerPropsType, CustomElementType, CustomFlipButtonProps, CustomFlipButtonPropsType, CustomTheme, DatePicker, DatePickerField, DatePickerFieldProps, DatePickerProps, DateRange, DateRangePicker, DateRangePickerField, DateRangePickerFieldProps, DateRangePickerProps, DragAndDrop, DragHandle, DragHandleProps, DragItem, DragItemProps, Draggable, DraggableProps, DropZone, DropZoneProps, Droppable, DroppableProps, DurationType, EditableControlsProps, EditableProps, EditableSizes, EditableText, Fade, FadeProps, FastGrid, FastGridProps, FastList, FastListProps, Field, FieldErrorType, FieldProps, FileEditorModalProps, FileFormat, FileIconButtonProps, FileItemProps, FilePicker, FilePickerField, FilePickerFieldProps, FilePickerProps, FileWithSizeAndType, FileWithSrcNameType, FileWithType, FlipButton, FlipButtonGroup, FlipButtonGroupField, FlipButtonGroupFieldProps, FlipButtonGroupProps, FlipButtonProps, Form, FormBody, FormLabel, FormLabelProps, FormProps, FormattedNumberInput, FormattedNumberInputProps, H1, H2, H3, H4, H5, H6, HeadingProps, HeadingType, Icon, IconButton, IconButtonProps, IconProps, InputFieldProps, Label, LabelProps, LabelSizes, LabelType, Lead, ListenersType, MaskedTextInput, MaskedTextInputProps, MediatoolThemeProvider, MediatoolThemeProviderProps, Modal, ModalBooleans, ModalProps, ModalSizes, MultiFileList, MultiFileListProps, MultiFilePicker, MultiFilePickerField, MultiFilePickerFieldProps, MultiFilePickerProps, MultiFileUploader, MultiFileUploaderProps, MultiItemType, MultiSort, MultiSortProps, NotificationIconButton, NotificationIconButtonProps, NumberInput, NumberInputField, NumberInputFieldProps, NumberInputProps, NumberInputSizeProps, NumberInputStepperProps, OffsetType, Option, OrganizationLogo, OrganizationLogoProps, OverflowGroup, OverflowGroupProps, OverflowIndicatorProps, P, PProps, PaneDivider, PaneItem, PinInput, PinInputProps, PinSize, PinSizeTuple, PinVariant, ProgressBar, Radio, RadioFieldGroupProps, RadioFieldProps, RadioGroup, RadioGroupField, RadioGroupProps, RadioProps, ScaleFade, ScaleFadeProps, SearchBar, SearchBarField, SearchBarFieldProps, SearchBarOptionType, SearchBarProps, Select, SelectActionMeta, SelectField, SelectFieldProps, SelectProps, SetValueOptionsType, Slide, SlideFade, SlideFadeProps, SlideProps, Small, Sortable, SortableContainer, SortableContainerProps, SortableItem, SortableItemProps, SortableList, SortableListProps, Spinner, SpinnerProps, SplitPane, SplitPaneProps, StatusBlock, StatusBlockProps, StatusPin, StatusPinProps, Step, StepList, StepListProps, StepPanel, StepPanelProps, StepProps, StepStack, Steps, StepsProps, StylizedType, Switch, SwitchField, SwitchFieldProps, SwitchProps, TabPanel, TabPanelProps, Tabs, TabsProps, Tag, TagGroup, TagGroupProps, TagProps, TextField, TextFieldProps, TextInputFormatter, TextSizeProps, Textarea, TextareaField, TextareaFieldProps, TextareaProps, Tiny, Toast, ToastProps, Toolbox, ToolboxContent, ToolboxContentProps, ToolboxFooter, ToolboxFooterProps, ToolboxHeader, ToolboxHeaderProps, ToolboxProps, TransitionDirection, UseFormReturn, UseSelectCallbacksProps, UseToastOptions, addAlpha, advancedParseFloat, createDebounceFunctionInstance, getChildrenWithProps, getContrastColor, getFieldError, getInitials, getShades, highlight, luminosity, ring, statusIconMap, theme, tottTheme, trimFormValues, useArrowFocus, useCurrentTheme, useDebounce, useLoadingMessage, useOverflowGroup, useSelectCallbacks, useSetValueRefreshed, useToast };
3550
+ export { Accordion, AccordionButton, AccordionItem, AccordionPanel, Alert, AlertProps, AlertVariants, AspectRatio, AsyncError, AsyncErrorProps, Avatar, AvatarBadgeProps, AvatarGroup, AvatarGroupProps, AvatarProps, Badge, BasicOption, Blinker, BlinkerProps, BlockVariant, BlockVariantColorTuple, Blockquote, BodyType, Button, ButtonProps, ButtonVariants, Capitalized, Carousel, Checkbox, CheckboxField, CheckboxFieldProps, CheckboxProps, CheckboxVariants, ChildrenType, Clickable, ClickableProps, ClipboardInput, ClipboardInputProps, Collapse, CollapseProps, Color, ColorButtonProps, ColorGrade, ColorPicker, ColorPickerField, ColorPickerFieldProps, ColorPickerProps, ColorShades, ColorsExpandButtonProps, ConfirmDeleteModalProps, CurrentTheme, CustomContainerPropsType, CustomElementType, CustomFlipButtonProps, CustomFlipButtonPropsType, CustomTheme, DatePicker, DatePickerField, DatePickerFieldProps, DatePickerProps, DateRange, DateRangePicker, DateRangePickerField, DateRangePickerFieldProps, DateRangePickerProps, DragAndDrop, DragHandle, DragHandleProps, DragItem, DragItemProps, Draggable, DraggableProps, DropZone, DropZoneProps, Droppable, DroppableProps, DurationType, EditableControlsProps, EditableProps, EditableSizes, EditableText, Fade, FadeProps, FastGrid, FastGridProps, FastList, FastListProps, Field, FieldErrorType, FieldProps, FileEditorModalProps, FileFormat, FileIconButtonProps, FileItemProps, FilePicker, FilePickerField, FilePickerFieldProps, FilePickerProps, FileWithSizeAndType, FileWithSrcNameType, FileWithType, FlipButton, FlipButtonGroup, FlipButtonGroupField, FlipButtonGroupFieldProps, FlipButtonGroupProps, FlipButtonProps, Form, FormBody, FormLabel, FormLabelProps, FormProps, FormattedNumberInput, FormattedNumberInputProps, H1, H2, H3, H4, H5, H6, HeadingProps, HeadingType, Icon, IconButton, IconButtonProps, IconProps, InputFieldProps, Label, LabelProps, LabelSizes, LabelType, Lead, ListenersType, MaskedTextInput, MaskedTextInputProps, MediatoolThemeProvider, MediatoolThemeProviderProps, Message, Modal, ModalBooleans, ModalProps, ModalSizes, MultiFileList, MultiFileListProps, MultiFilePicker, MultiFilePickerField, MultiFilePickerFieldProps, MultiFilePickerProps, MultiFileUploader, MultiFileUploaderProps, MultiItemType, MultiSort, MultiSortProps, NotificationIconButton, NotificationIconButtonProps, NumberInput, NumberInputField, NumberInputFieldProps, NumberInputProps, NumberInputSizeProps, NumberInputStepperProps, OffsetType, Option, OrganizationLogo, OrganizationLogoProps, OverflowGroup, OverflowGroupProps, OverflowIndicatorProps, P, PProps, PaneDivider, PaneItem, PinInput, PinInputProps, PinSize, PinSizeTuple, PinVariant, ProgressBar, Radio, RadioFieldGroupProps, RadioFieldProps, RadioGroup, RadioGroupField, RadioGroupProps, RadioProps, ScaleFade, ScaleFadeProps, SearchBar, SearchBarField, SearchBarFieldProps, SearchBarOptionType, SearchBarProps, Select, SelectActionMeta, SelectField, SelectFieldProps, SelectProps, SetValueOptionsType, Slide, SlideFade, SlideFadeProps, SlideProps, Small, Sortable, SortableContainer, SortableContainerProps, SortableItem, SortableItemProps, SortableList, SortableListProps, Spinner, SpinnerProps, SplitPane, SplitPaneProps, StatusBlock, StatusBlockProps, StatusPin, StatusPinProps, Step, StepList, StepListProps, StepPanel, StepPanelProps, StepProps, StepStack, Steps, StepsProps, StylizedType, Switch, SwitchField, SwitchFieldProps, SwitchProps, TabPanel, TabPanelProps, Tabs, TabsProps, Tag, TagGroup, TagGroupProps, TagProps, TextField, TextFieldProps, TextInputFormatter, TextSizeProps, Textarea, TextareaField, TextareaFieldProps, TextareaProps, Tiny, Toast, ToastProps, Toolbox, ToolboxContent, ToolboxContentProps, ToolboxFooter, ToolboxFooterProps, ToolboxHeader, ToolboxHeaderProps, ToolboxProps, TransitionDirection, UseFormReturn, UseSelectCallbacksProps, UseToastOptions, addAlpha, advancedParseFloat, createDebounceFunctionInstance, getChildrenWithProps, getContrastColor, getFieldError, getInitials, getShades, highlight, luminosity, ring, statusIconMap, theme, tottTheme, trimFormValues, useArrowFocus, useCurrentTheme, useDebounce, useLoadingMessage, useOverflowGroup, useScrollToBottom, useSelectCallbacks, useSetValueRefreshed, useToast };
@@ -1505,6 +1505,32 @@
1505
1505
  return `${prefix}${dots}`;
1506
1506
  };
1507
1507
 
1508
+ const smoothScrollToBottom = (div) => {
1509
+ const totalSteps = 50;
1510
+ let currentStep = 0;
1511
+ const targetScrollTop = div.scrollHeight - div.clientHeight;
1512
+ const originalScrollTop = div.scrollTop;
1513
+ const scrollInterval = setInterval(() => {
1514
+ if (currentStep >= totalSteps) {
1515
+ clearInterval(scrollInterval);
1516
+ } else {
1517
+ currentStep += 1;
1518
+ const scrollProgress = currentStep / totalSteps;
1519
+ const easing = 1 - (1 - scrollProgress) * (1 - scrollProgress);
1520
+ div.scrollTop = originalScrollTop + (targetScrollTop - originalScrollTop) * easing;
1521
+ }
1522
+ }, 20);
1523
+ };
1524
+
1525
+ const useScrollToBottom = (scrollView, messages) => {
1526
+ React.useEffect(() => {
1527
+ const div = scrollView.current;
1528
+ if (div) {
1529
+ smoothScrollToBottom(div);
1530
+ }
1531
+ }, [messages]);
1532
+ };
1533
+
1508
1534
  const useArrowFocus = (columns) => {
1509
1535
  const {
1510
1536
  focusNext: next,
@@ -1607,13 +1633,12 @@
1607
1633
  direction = "column",
1608
1634
  isRequired = false,
1609
1635
  noLabelConnection = false,
1610
- validate
1636
+ validate,
1637
+ control: passedControl
1611
1638
  }) {
1612
1639
  const methods = reactHookForm.useFormContext();
1613
- const {
1614
- control,
1615
- formState: { errors }
1616
- } = methods;
1640
+ const { formState: { errors } } = methods;
1641
+ const control = passedControl != null ? passedControl : methods.control;
1617
1642
  const fieldError = getFieldError(name, errors);
1618
1643
  return /* @__PURE__ */ React.createElement(react.FormControl, { isInvalid: !!fieldError, isRequired }, /* @__PURE__ */ React.createElement(
1619
1644
  react.Stack,
@@ -10862,8 +10887,10 @@
10862
10887
  variant: "danger",
10863
10888
  size: "sm",
10864
10889
  fontSize: "xs",
10865
- hidden: value === "" || !isClearable,
10866
- onClick: onChange,
10890
+ hidden: value === void 0 || !isClearable,
10891
+ onClick: () => {
10892
+ onChange(void 0);
10893
+ },
10867
10894
  icon: /* @__PURE__ */ React.createElement(Icon$1, { as: icons.XCloseSolid })
10868
10895
  }
10869
10896
  ))
@@ -12848,6 +12875,7 @@
12848
12875
  exports.useDebounce = useDebounce;
12849
12876
  exports.useLoadingMessage = useLoadingMessage;
12850
12877
  exports.useOverflowGroup = useOverflowGroup;
12878
+ exports.useScrollToBottom = useScrollToBottom;
12851
12879
  exports.useSelectCallbacks = useSelectCallbacks;
12852
12880
  exports.useSetValueRefreshed = useSetValueRefreshed;
12853
12881
  exports.useToast = useToast;