@bloomreach/react-banana-ui 1.6.0 → 1.7.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.
Files changed (27) hide show
  1. package/dist/bloomreach-react-banana-ui.es.js +3628 -3131
  2. package/dist/bloomreach-react-banana-ui.es.js.map +1 -1
  3. package/dist/bloomreach-react-banana-ui.umd.js +17 -17
  4. package/dist/bloomreach-react-banana-ui.umd.js.map +1 -1
  5. package/dist/components/inputs/base-input/base-input.d.ts +6 -2
  6. package/dist/components/inputs/internal.d.ts +1 -0
  7. package/dist/components/inputs/select/index.d.ts +2 -0
  8. package/dist/components/inputs/select/select.d.ts +37 -0
  9. package/dist/components/inputs/select/select.types.d.ts +66 -0
  10. package/dist/components/inputs/select-field/index.d.ts +1 -0
  11. package/dist/components/inputs/select-field/select-field.d.ts +34 -0
  12. package/dist/components/inputs/select-field/select-field.qa.stories.d.ts +15 -0
  13. package/dist/components/inputs/select-field/select-field.stories.d.ts +20 -0
  14. package/dist/components/inputs/select-field/select-field.types.d.ts +38 -0
  15. package/dist/components/inputs/select-option/index.d.ts +2 -0
  16. package/dist/components/inputs/select-option/select-option.d.ts +4 -0
  17. package/dist/components/inputs/select-option/select-option.types.d.ts +30 -0
  18. package/dist/components/internal.d.ts +1 -0
  19. package/dist/components/lists/internal.d.ts +2 -0
  20. package/dist/components/lists/listbox/index.d.ts +2 -0
  21. package/dist/components/lists/listbox/listbox.d.ts +26 -0
  22. package/dist/components/lists/listbox/listbox.types.d.ts +16 -0
  23. package/dist/components/lists/listbox-item/index.d.ts +2 -0
  24. package/dist/components/lists/listbox-item/listbox-item.d.ts +27 -0
  25. package/dist/components/lists/listbox-item/listbox-item.types.d.ts +28 -0
  26. package/dist/style.css +1 -1
  27. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import React, { ChangeEventHandler, FocusEventHandler, InputHTMLAttributes, ReactNode } from 'react';
1
+ import React, { ChangeEventHandler, FocusEventHandler, ForwardedRef, InputHTMLAttributes, ReactNode } from 'react';
2
2
  import './base-input.scss';
3
3
  export interface BaseInputProps {
4
4
  /**
@@ -37,6 +37,10 @@ export interface BaseInputProps {
37
37
  * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea#Attributes
38
38
  */
39
39
  inputProps?: InputHTMLAttributes<HTMLInputElement | HTMLTextAreaElement>;
40
+ /**
41
+ * The ref to the `input` or `textarea` element.
42
+ */
43
+ inputRef?: ForwardedRef<HTMLInputElement> | ForwardedRef<HTMLTextAreaElement>;
40
44
  /**
41
45
  * Icon or any element displayed at the end of the `input` or `textarea`.
42
46
  */
@@ -101,5 +105,5 @@ export interface BaseInputProps {
101
105
  * The base input component to enter and edit text.
102
106
  * Should be used only by other components and not exposed to the end users.
103
107
  */
104
- declare const BaseInput: React.ForwardRefExoticComponent<BaseInputProps & React.RefAttributes<HTMLInputElement | HTMLTextAreaElement>>;
108
+ declare const BaseInput: React.ForwardRefExoticComponent<BaseInputProps & React.RefAttributes<HTMLDivElement>>;
105
109
  export default BaseInput;
@@ -1,4 +1,5 @@
1
1
  export * from './base-field';
2
2
  export * from './base-input';
3
3
  export * from './field-label';
4
+ export * from './select';
4
5
  export * from './toggle';
@@ -0,0 +1,2 @@
1
+ export { default as Select } from './select';
2
+ export type { SelectProps } from './select.types';
@@ -0,0 +1,37 @@
1
+ import { SelectComponentType } from './select.types';
2
+ import './select.scss';
3
+ /**
4
+ * @internal
5
+ *
6
+ * The `Select` component is meant to optimize user interaction and experience.
7
+ * It is a customizable dropdown list that allows users to choose one or more options from a list.
8
+ * Its primary function is to enhance and simplify data input, minimizing user effort
9
+ * in navigation while avoiding incorrect entries.
10
+ *
11
+ * ### Usage
12
+ *
13
+ * ```tsx
14
+ * import { Select, SelectOption } from '@bloomreach/react-banana-ui';
15
+ * import React from 'react';
16
+ *
17
+ * export default function MyCustomSingleSelect() {
18
+ * return (
19
+ * <Select
20
+ * label="List of fruits"
21
+ * placeholder="Select a fruit"
22
+ * onChange={(event, value) => console.log(value)}
23
+ * >
24
+ * <SelectOption value="apple">Apple</SelectOption>
25
+ * <SelectOption value="banana">Banana</SelectOption>
26
+ * <SelectOption value="orange">Orange</SelectOption>
27
+ * <SelectOption value="grapes">Grapes</SelectOption>
28
+ * <SelectOption value="strawberries">Strawberries</SelectOption>
29
+ * <SelectOption value="blueberries">Blueberries</SelectOption>
30
+ * <SelectOption value="pineapple">Pineapple</SelectOption>
31
+ * </Select>
32
+ * );
33
+ * }
34
+ * ```
35
+ */
36
+ declare const _default: SelectComponentType;
37
+ export default _default;
@@ -0,0 +1,66 @@
1
+ import { ForwardedRef, ReactElement, ReactNode } from 'react';
2
+ export type SelectValue<Value, Multiple> = Multiple extends true ? Value[] : Value | null;
3
+ export interface SelectProps<OptionValue extends NonNullable<unknown>, Multiple extends boolean> {
4
+ /**
5
+ * The content of the component.
6
+ */
7
+ children?: ReactNode;
8
+ /**
9
+ * Custom class name for the container of the component.
10
+ */
11
+ className?: string;
12
+ /**
13
+ * The default selected value. Use when the component is not controlled.
14
+ * The value must be an array when `multiple` is `true`.
15
+ */
16
+ defaultValue?: SelectValue<OptionValue, Multiple>;
17
+ /**
18
+ * If true, the select is disabled.
19
+ */
20
+ disabled?: boolean;
21
+ /**
22
+ * Display an icon at the beginning of the select field.
23
+ */
24
+ icon?: ReactNode;
25
+ /**
26
+ * The `id` of the select element.
27
+ */
28
+ id?: string;
29
+ /**
30
+ * If `true`, selecting multiple values is allowed.
31
+ * This affects the type of the `value`, `defaultValue`, and `onChange` props.
32
+ */
33
+ multiple?: Multiple;
34
+ /**
35
+ * Name of the element. For example used by the server to identify the fields in form submits.
36
+ */
37
+ name?: string;
38
+ /**
39
+ * Callback fired when an option is selected.
40
+ */
41
+ onChange?: (event: React.MouseEvent<Element, MouseEvent> | React.KeyboardEvent<Element> | React.FocusEvent<Element, Element> | null, value: SelectValue<OptionValue, Multiple>) => void;
42
+ /**
43
+ * Text to show when there is no selected value.
44
+ */
45
+ placeholder?: string;
46
+ /**
47
+ * If `true`, the `select` element is readonly.
48
+ */
49
+ readOnly?: boolean;
50
+ /**
51
+ * If `true`, the `Select` cannot be empty when submitting form.
52
+ */
53
+ required?: boolean;
54
+ /**
55
+ * The selected value.
56
+ * Set to `null` in case of single select and `[]` in case of multiple select to clear the selection.
57
+ * If the value is an object it must have reference equality with the option in order to be selected.
58
+ */
59
+ value?: SelectValue<OptionValue, Multiple>;
60
+ }
61
+ export interface SelectComponentType {
62
+ <OptionValue extends NonNullable<unknown>, Multiple extends boolean = false>(props: SelectProps<OptionValue, Multiple> & {
63
+ ref?: ForwardedRef<HTMLElement>;
64
+ }): ReactElement | null;
65
+ displayName?: string | undefined;
66
+ }
@@ -0,0 +1 @@
1
+ export { default as SelectField } from './select-field';
@@ -0,0 +1,34 @@
1
+ import { SelectFieldComponentType } from './select-field.types';
2
+ /**
3
+ * The `SelectField` component is meant to optimize user interaction and experience.
4
+ * It is a customizable dropdown list that allows users to choose one or more options from a list.
5
+ * Its primary function is to enhance and simplify data input, minimizing user effort
6
+ * in navigation while avoiding incorrect entries.
7
+ *
8
+ * ### Usage
9
+ *
10
+ * ```tsx
11
+ * import { SelectField, SelectOption } from '@bloomreach/react-banana-ui';
12
+ * import React from 'react';
13
+ *
14
+ * export default function MyCustomSingleSelectField() {
15
+ * return (
16
+ * <SelectField
17
+ * label="List of fruits"
18
+ * placeholder="Select a fruit"
19
+ * onChange={(event, value) => console.log(value)}
20
+ * >
21
+ * <SelectOption value="apple">Apple</SelectOption>
22
+ * <SelectOption value="banana">Banana</SelectOption>
23
+ * <SelectOption value="orange">Orange</SelectOption>
24
+ * <SelectOption value="grapes">Grapes</SelectOption>
25
+ * <SelectOption value="strawberries">Strawberries</SelectOption>
26
+ * <SelectOption value="blueberries">Blueberries</SelectOption>
27
+ * <SelectOption value="pineapple">Pineapple</SelectOption>
28
+ * </SelectField>
29
+ * );
30
+ * }
31
+ * ```
32
+ */
33
+ declare const _default: SelectFieldComponentType;
34
+ export default _default;
@@ -0,0 +1,15 @@
1
+ import { Meta } from '@storybook/react';
2
+ import { type Story } from './select-field.stories';
3
+ import { SelectField } from '.';
4
+ declare const meta: Meta<typeof SelectField>;
5
+ export default meta;
6
+ export declare const Basic: Story;
7
+ export declare const DifferentStates: Story;
8
+ export declare const FullWidth: Story;
9
+ export declare const Single: Story;
10
+ export declare const ControlledSingleSelect: Story;
11
+ export declare const Multiple: Story<string, true>;
12
+ export declare const ControlledMultipleSelect: Story<string, true>;
13
+ export declare const OptionWithLabel: Story;
14
+ export declare const NoneOption: Story;
15
+ export declare const DisabledOptions: Story;
@@ -0,0 +1,20 @@
1
+ import { Meta, StoryObj } from '@storybook/react';
2
+ import SelectField from './select-field';
3
+ declare const meta: Meta<typeof SelectField>;
4
+ export default meta;
5
+ export type Story<ValueType extends NonNullable<unknown> = string, Multiple extends boolean = false> = StoryObj<typeof SelectField<ValueType, Multiple>>;
6
+ export declare const Basic: Story;
7
+ export declare const WithLabel: Story;
8
+ export declare const WithTooltip: Story;
9
+ export declare const WithHelperText: Story;
10
+ export declare const CompleteField: Story;
11
+ export declare const FullWidth: Story;
12
+ export declare const ControlledSingleSelect: Story;
13
+ export declare const Multiple: Story<string, true>;
14
+ export declare const ControlledMultipleSelect: Story<string, true>;
15
+ export declare const WithIconInTheField: Story;
16
+ export declare const FieldsInColumn: Story;
17
+ export declare const FieldsInRow: Story;
18
+ export declare const OptionWithLabel: Story;
19
+ export declare const NoneOption: Story;
20
+ export declare const DisabledOptions: Story;
@@ -0,0 +1,38 @@
1
+ import { ForwardedRef, ReactElement, ReactNode } from 'react';
2
+ import { SelectProps } from '../../internal';
3
+ export interface SelectFieldProps<OptionValue extends NonNullable<unknown>, Multiple extends boolean> extends SelectProps<OptionValue, Multiple> {
4
+ /**
5
+ * The options of the select. Use the `SelectOption` component to define the options.
6
+ */
7
+ children: React.ReactNode;
8
+ /**
9
+ * Custom class name for the container of the component.
10
+ */
11
+ className?: string;
12
+ /**
13
+ * If `true`, the ``field` will indicate an error and set the `aria-invalid` attribute for `input`.
14
+ */
15
+ error?: boolean;
16
+ /**
17
+ * If `true`, the field will take up the full width of its container.
18
+ */
19
+ fullWidth?: boolean;
20
+ /**
21
+ * The helper text content.
22
+ */
23
+ helperText?: ReactNode;
24
+ /**
25
+ * The label content.
26
+ */
27
+ label?: ReactNode;
28
+ /**
29
+ * Tooltip to display when the field has label.
30
+ */
31
+ tooltip?: ReactNode;
32
+ }
33
+ export interface SelectFieldComponentType {
34
+ <OptionValue extends NonNullable<unknown>, Multiple extends boolean = false>(props: SelectFieldProps<OptionValue, Multiple> & {
35
+ ref?: ForwardedRef<HTMLElement>;
36
+ }): ReactElement | null;
37
+ displayName?: string;
38
+ }
@@ -0,0 +1,2 @@
1
+ export { default as SelectOption } from './select-option';
2
+ export type { SelectOptionProps } from './select-option.types';
@@ -0,0 +1,4 @@
1
+ import { SelectOptionComponentType } from './select-option.types';
2
+ import './select-option.scss';
3
+ declare const _default: SelectOptionComponentType;
4
+ export default _default;
@@ -0,0 +1,30 @@
1
+ import { ForwardedRef, ReactElement, ReactNode } from 'react';
2
+ export interface SelectOptionProps<OptionValue> {
3
+ /**
4
+ * Custom class name for the container of the component.
5
+ */
6
+ className?: string;
7
+ /**
8
+ * The content of the component.
9
+ */
10
+ children?: ReactNode;
11
+ /**
12
+ * If `true`, the option will be disabled.
13
+ */
14
+ disabled?: boolean;
15
+ /**
16
+ * The value of the option.
17
+ * If the value is an object it must have reference equality with the select in order to be selected.
18
+ */
19
+ value: OptionValue;
20
+ /**
21
+ * A text representation of the option's content. Used for keyboard text navigation matching.
22
+ */
23
+ label?: string;
24
+ }
25
+ export interface SelectOptionComponentType {
26
+ <OptionValue>(props: SelectOptionProps<OptionValue> & {
27
+ ref?: ForwardedRef<HTMLElement>;
28
+ }): ReactElement | null;
29
+ displayName?: string;
30
+ }
@@ -1 +1,2 @@
1
1
  export * from './inputs/internal';
2
+ export * from './lists/internal';
@@ -0,0 +1,2 @@
1
+ export * from './listbox-item';
2
+ export * from './listbox';
@@ -0,0 +1,2 @@
1
+ export { default as Listbox } from './listbox';
2
+ export type { ListboxProps } from './listbox.types';
@@ -0,0 +1,26 @@
1
+ /// <reference types="react" />
2
+ import { ListboxProps } from './listbox.types';
3
+ import './listbox.scss';
4
+ /**
5
+ * @internal
6
+ * The `Listbox` component is used to display a list of items aligned with design system styles.
7
+ * Use the `ListboxItem` component to define the items of the list.
8
+ *
9
+ * ### Usage
10
+ *
11
+ * ```tsx
12
+ * import { Listbox, ListboxItem } from '@bloomreach/react-banana-ui';
13
+ *
14
+ * export default function MyMenu() {
15
+ * return (
16
+ * <Listbox>
17
+ * <ListboxItem>Item 1</ListboxItem>
18
+ * <ListboxItem>Item 2</ListboxItem>
19
+ * <ListboxItem>Item 3</ListboxItem>
20
+ * </Listbox>
21
+ * );
22
+ * }
23
+ * ```
24
+ */
25
+ declare const Listbox: import("react").ForwardRefExoticComponent<ListboxProps & import("react").RefAttributes<HTMLUListElement>>;
26
+ export default Listbox;
@@ -0,0 +1,16 @@
1
+ import { HTMLAttributes, ReactNode } from 'react';
2
+ export interface ListboxProps {
3
+ /**
4
+ * Custom class name for the container of the component.
5
+ */
6
+ className?: string;
7
+ /**
8
+ * The content of the component.
9
+ */
10
+ children: ReactNode;
11
+ /**
12
+ * The role of the list box.
13
+ * @default 'listbox'
14
+ */
15
+ role?: HTMLAttributes<Element>['role'];
16
+ }
@@ -0,0 +1,2 @@
1
+ export { default as ListboxItem } from './listbox-item';
2
+ export type { ListboxItemProps } from './listbox-item.types';
@@ -0,0 +1,27 @@
1
+ /// <reference types="react" />
2
+ import { ListboxItemProps } from './listbox-item.types';
3
+ import './listbox-item.scss';
4
+ /**
5
+ * @internal
6
+ * The `ListboxItem` component is used to define the items of the `Listbox` component.
7
+ * It mostly should be used as internal component to bring defined styles to the list items in menu
8
+ * or select components.
9
+ *
10
+ * ### Usage
11
+ *
12
+ * ```tsx
13
+ * import { Listbox, ListboxItem } from '@bloomreach/react-banana-ui';
14
+ *
15
+ * export default function MyMenu() {
16
+ * return (
17
+ * <Listbox>
18
+ * <ListboxItem>Item 1</ListboxItem>
19
+ * <ListboxItem>Item 2</ListboxItem>
20
+ * <ListboxItem>Item 3</ListboxItem>
21
+ * </Listbox>
22
+ * );
23
+ * }
24
+ * ```
25
+ */
26
+ declare const ListboxItem: import("react").ForwardRefExoticComponent<ListboxItemProps & import("react").RefAttributes<HTMLLIElement>>;
27
+ export default ListboxItem;
@@ -0,0 +1,28 @@
1
+ import { HTMLAttributes, ReactNode } from 'react';
2
+ export interface ListboxItemProps {
3
+ /**
4
+ * Custom class name for the container of the component.
5
+ */
6
+ className?: string;
7
+ /**
8
+ * The content of the component.
9
+ */
10
+ children?: ReactNode;
11
+ /**
12
+ * If `true`, the item will be disabled.
13
+ */
14
+ disabled?: boolean;
15
+ /**
16
+ * If `true`, the item will be highlighted.
17
+ */
18
+ highlighted?: boolean;
19
+ /**
20
+ * If `true`, the item will be selected.
21
+ */
22
+ selected?: boolean;
23
+ /**
24
+ * The role of the list box item.
25
+ * @default 'option'
26
+ */
27
+ role?: HTMLAttributes<Element>['role'];
28
+ }