@bloomreach/react-banana-ui 1.11.0 → 1.13.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/dist/bloomreach-react-banana-ui.es.js +5148 -4198
- package/dist/bloomreach-react-banana-ui.es.js.map +1 -1
- package/dist/bloomreach-react-banana-ui.umd.js +18 -14
- package/dist/bloomreach-react-banana-ui.umd.js.map +1 -1
- package/dist/components/foundations/icon/icon.stories.d.ts +1 -0
- package/dist/components/inputs/autocomplete/autocomplete.d.ts +23 -0
- package/dist/components/inputs/autocomplete/autocomplete.qa.stories.d.ts +19 -0
- package/dist/components/inputs/autocomplete/autocomplete.stories.d.ts +26 -0
- package/dist/components/inputs/autocomplete/autocomplete.types.d.ts +114 -0
- package/dist/components/inputs/autocomplete/index.d.ts +2 -0
- package/dist/components/inputs/base-input/base-input.types.d.ts +7 -11
- package/dist/components/inputs/index.d.ts +5 -1
- package/dist/components/inputs/radio/index.d.ts +2 -0
- package/dist/components/inputs/radio/radio.d.ts +27 -0
- package/dist/components/inputs/radio/radio.qa.stories.d.ts +9 -0
- package/dist/components/inputs/radio/radio.stories.d.ts +10 -0
- package/dist/components/inputs/radio/radio.types.d.ts +47 -0
- package/dist/components/inputs/radio-field/index.d.ts +2 -0
- package/dist/components/inputs/radio-field/radio-field.d.ts +28 -0
- package/dist/components/inputs/radio-field/radio-field.qa.stories.d.ts +8 -0
- package/dist/components/inputs/radio-field/radio-field.stories.d.ts +11 -0
- package/dist/components/inputs/radio-field/radio-field.types.d.ts +12 -0
- package/dist/components/inputs/radio-group/index.d.ts +2 -0
- package/dist/components/inputs/radio-group/radio-group-context.d.ts +34 -0
- package/dist/components/inputs/radio-group/radio-group.d.ts +41 -0
- package/dist/components/inputs/radio-group/radio-group.qa.stories.d.ts +10 -0
- package/dist/components/inputs/radio-group/radio-group.stories.d.ts +14 -0
- package/dist/components/inputs/radio-group/radio-group.types.d.ts +57 -0
- package/dist/components/inputs/select-option/select-option.d.ts +0 -1
- package/dist/components/lists/internal.d.ts +2 -0
- package/dist/components/lists/listbox-group/index.d.ts +2 -0
- package/dist/components/lists/listbox-group/listbox-group.d.ts +33 -0
- package/dist/components/lists/listbox-group/listbox-group.types.d.ts +11 -0
- package/dist/components/lists/listbox-group-label/index.d.ts +2 -0
- package/dist/components/lists/listbox-group-label/listbox-group-label.d.ts +33 -0
- package/dist/components/lists/listbox-group-label/listbox-group-label.types.d.ts +11 -0
- package/dist/style.css +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { AutocompleteComponentType } from './autocomplete.types';
|
|
2
|
+
import './autocomplete.scss';
|
|
3
|
+
/**
|
|
4
|
+
* Autocomplete allows a user to search for value(s) to select from a list.
|
|
5
|
+
*
|
|
6
|
+
* ### Usage
|
|
7
|
+
*
|
|
8
|
+
* ```tsx
|
|
9
|
+
* import { Autocomplete } from '@bloomreach/react-banana-ui';
|
|
10
|
+
*
|
|
11
|
+
* export default function MyAutocomplete() {
|
|
12
|
+
* return (
|
|
13
|
+
* <Autocomplete
|
|
14
|
+
* options={['Banana', 'Apple', 'Orange', 'Pineapple', 'Strawberry', 'Grape', 'Watermelon']}
|
|
15
|
+
* placeholder="Select a fruit"
|
|
16
|
+
* onChange={(_, newValue) => console.log(newValue)}
|
|
17
|
+
* />
|
|
18
|
+
* );
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
declare const _default: AutocompleteComponentType;
|
|
23
|
+
export default _default;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Meta } from '@storybook/react';
|
|
2
|
+
import { ControlledMultipleValue as ControlledMultipleValueStory, ControlledSingleValue as ControlledSingleValueStory, CustomOptionLabel as CustomOptionLabelStory, HideSelectedOptions as HideSelectedOptionsStory, Multiple as MultipleStory, type Story } from './autocomplete.stories';
|
|
3
|
+
import Autocomplete from './autocomplete';
|
|
4
|
+
declare const meta: Meta<typeof Autocomplete>;
|
|
5
|
+
export default meta;
|
|
6
|
+
export declare const Basic: Story;
|
|
7
|
+
export declare const DifferentStates: Story;
|
|
8
|
+
export declare const Single: Story;
|
|
9
|
+
export declare const ControlledSingleValue: typeof ControlledSingleValueStory;
|
|
10
|
+
export declare const Multiple: typeof MultipleStory;
|
|
11
|
+
export declare const ControlledMultipleValue: typeof ControlledMultipleValueStory;
|
|
12
|
+
export declare const HideSelectedOptions: typeof HideSelectedOptionsStory;
|
|
13
|
+
export declare const GroupedOptions: Story<{
|
|
14
|
+
group: string;
|
|
15
|
+
label: string;
|
|
16
|
+
}>;
|
|
17
|
+
export declare const DisabledOptions: Story;
|
|
18
|
+
export declare const CustomOptionLabel: typeof CustomOptionLabelStory;
|
|
19
|
+
export declare const Loading: Story;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import Autocomplete from './autocomplete';
|
|
3
|
+
declare const meta: Meta<typeof Autocomplete>;
|
|
4
|
+
export default meta;
|
|
5
|
+
export type Story<Value extends NonNullable<unknown> = string, Multiple extends boolean = false> = StoryObj<typeof Autocomplete<Value, Multiple>>;
|
|
6
|
+
declare const fruits: string[];
|
|
7
|
+
export declare const Basic: Story;
|
|
8
|
+
export declare const DefaultValue: Story;
|
|
9
|
+
export declare const ControlledSingleValue: Story;
|
|
10
|
+
export declare const Multiple: Story<typeof fruits[0], true>;
|
|
11
|
+
export declare const DefaultValueMultiple: Story<typeof fruits[0], true>;
|
|
12
|
+
export declare const ControlledMultipleValue: Story<typeof fruits[0], true>;
|
|
13
|
+
export declare const HideSelectedOptions: Story<string, true>;
|
|
14
|
+
export declare const GroupedOptions: Story<{
|
|
15
|
+
label: string;
|
|
16
|
+
firstLetter: string;
|
|
17
|
+
}>;
|
|
18
|
+
export declare const DisabledOptions: Story<{
|
|
19
|
+
label: string;
|
|
20
|
+
id: number;
|
|
21
|
+
}>;
|
|
22
|
+
export declare const CustomOptionLabel: Story<{
|
|
23
|
+
fruitName: string;
|
|
24
|
+
}>;
|
|
25
|
+
export declare const NoOptionsText: Story<string>;
|
|
26
|
+
export declare const Loading: Story;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { AutocompleteGroupedOption as MuiBaseAutocompleteGroupedOption } from '@mui/base';
|
|
2
|
+
import { ForwardedRef, ReactElement, ReactNode, SyntheticEvent } from 'react';
|
|
3
|
+
export type AutocompleteValue<Value, Multiple> = Multiple extends true ? Value[] : Value | null;
|
|
4
|
+
export interface AutocompleteProps<AutocompleteOption extends NonNullable<unknown>, Multiple extends boolean> {
|
|
5
|
+
/**
|
|
6
|
+
* Custom class name for the container of the component.
|
|
7
|
+
*/
|
|
8
|
+
className?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Clear the selected value when clicking the clear icon.
|
|
11
|
+
* @default false
|
|
12
|
+
*/
|
|
13
|
+
clearable?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* If `true`, the popup closes after a selection is made.
|
|
16
|
+
* It is `false` by default when `multiple` is `true`.
|
|
17
|
+
*/
|
|
18
|
+
closeOnSelect?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* The default selected value. Use when the component is not controlled.
|
|
21
|
+
* The value must be an array when `multiple` is `true`.
|
|
22
|
+
*/
|
|
23
|
+
defaultValue?: AutocompleteValue<AutocompleteOption, Multiple>;
|
|
24
|
+
/**
|
|
25
|
+
* If `true`, the component is disabled.
|
|
26
|
+
* @default false
|
|
27
|
+
*/
|
|
28
|
+
disabled?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Used to determine if an option is disabled.
|
|
31
|
+
*/
|
|
32
|
+
getOptionDisabled?: (option: AutocompleteOption) => boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Used to determine the string value for a given option.
|
|
35
|
+
* @default (option) => option
|
|
36
|
+
*/
|
|
37
|
+
getOptionLabel?: (option: AutocompleteOption) => string;
|
|
38
|
+
/**
|
|
39
|
+
* If provided, the options will be grouped under the returned string.
|
|
40
|
+
* The groupBy value is also used as the text for group headings
|
|
41
|
+
*/
|
|
42
|
+
groupBy?: (option: AutocompleteOption) => string;
|
|
43
|
+
/**
|
|
44
|
+
* If `true`, the selected options are not displayed.
|
|
45
|
+
* @default false
|
|
46
|
+
*/
|
|
47
|
+
hideSelectedOptions?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* If `true`, the component is in a loading state.
|
|
50
|
+
* @default false
|
|
51
|
+
*/
|
|
52
|
+
loading?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* The text to display when the component is in a loading state.
|
|
55
|
+
* @default "Loading..."
|
|
56
|
+
*/
|
|
57
|
+
loadingText?: string;
|
|
58
|
+
/**
|
|
59
|
+
* If `true`, the component allows multiple selections.
|
|
60
|
+
* @default false
|
|
61
|
+
*/
|
|
62
|
+
multiple?: Multiple;
|
|
63
|
+
/**
|
|
64
|
+
* Text to display when there are no options.
|
|
65
|
+
* @default "No options"
|
|
66
|
+
*/
|
|
67
|
+
noOptionsText?: string;
|
|
68
|
+
/**
|
|
69
|
+
* Callback fired when the value changes.
|
|
70
|
+
*/
|
|
71
|
+
onChange?: (event: SyntheticEvent, value: AutocompleteValue<AutocompleteOption, Multiple>) => void;
|
|
72
|
+
/**
|
|
73
|
+
* Callback fired when the popup closes.
|
|
74
|
+
*/
|
|
75
|
+
onClose?: () => void;
|
|
76
|
+
/**
|
|
77
|
+
* Callback fired when the popup opens.
|
|
78
|
+
*/
|
|
79
|
+
onOpen?: () => void;
|
|
80
|
+
/**
|
|
81
|
+
* Array ot options to display.
|
|
82
|
+
*/
|
|
83
|
+
options: AutocompleteOption[];
|
|
84
|
+
/**
|
|
85
|
+
* The input placeholder.
|
|
86
|
+
*/
|
|
87
|
+
placeholder?: string;
|
|
88
|
+
/**
|
|
89
|
+
* If `true`, the autocomplete is readonly.
|
|
90
|
+
*/
|
|
91
|
+
readOnly?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* If `true`, the autocomplete is required.
|
|
94
|
+
* @default false
|
|
95
|
+
*/
|
|
96
|
+
required?: boolean;
|
|
97
|
+
/**
|
|
98
|
+
* The selected value.
|
|
99
|
+
* Set to `null` in case of single select and `[]` in case of multiple select to clear the selection.
|
|
100
|
+
* If the value is an object it must have reference equality with the option in order to be selected.
|
|
101
|
+
*/
|
|
102
|
+
value?: AutocompleteValue<AutocompleteOption, Multiple>;
|
|
103
|
+
}
|
|
104
|
+
export interface AutocompleteGroupedOption<AutocompleteOption extends NonNullable<unknown>> extends MuiBaseAutocompleteGroupedOption<AutocompleteOption> {
|
|
105
|
+
}
|
|
106
|
+
export interface AutocompleteRenderGroupParams extends AutocompleteGroupedOption<object> {
|
|
107
|
+
children: ReactNode;
|
|
108
|
+
}
|
|
109
|
+
export interface AutocompleteComponentType {
|
|
110
|
+
<AutocompleteOption extends NonNullable<unknown>, Multiple extends boolean = false>(props: AutocompleteProps<AutocompleteOption, Multiple> & {
|
|
111
|
+
ref?: ForwardedRef<HTMLElement>;
|
|
112
|
+
}): ReactElement | null;
|
|
113
|
+
displayName?: string | undefined;
|
|
114
|
+
}
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import { ChangeEventHandler, FocusEventHandler, ForwardedRef, InputHTMLAttributes, ReactNode } from 'react';
|
|
1
|
+
import { ChangeEventHandler, FocusEventHandler, ForwardedRef, InputHTMLAttributes, ReactNode, Ref, RefCallback } from 'react';
|
|
2
2
|
export interface BaseInputProps {
|
|
3
|
-
/**
|
|
4
|
-
* Automatically adjusts textarea height to match the length of the content within.
|
|
5
|
-
* When `multiline` is `false`, this prop is ignored.
|
|
6
|
-
*/
|
|
7
|
-
autoSize?: boolean;
|
|
8
3
|
/**
|
|
9
4
|
* Custom class name for the container of this component.
|
|
10
5
|
*/
|
|
@@ -39,7 +34,7 @@ export interface BaseInputProps {
|
|
|
39
34
|
/**
|
|
40
35
|
* The ref to the `input` or `textarea` element.
|
|
41
36
|
*/
|
|
42
|
-
inputRef?: ForwardedRef<HTMLInputElement> |
|
|
37
|
+
inputRef?: ForwardedRef<HTMLInputElement | HTMLTextAreaElement> | Ref<HTMLInputElement | HTMLTextAreaElement>;
|
|
43
38
|
/**
|
|
44
39
|
* Icon or any element displayed at the end of the `input` or `textarea`.
|
|
45
40
|
*/
|
|
@@ -54,10 +49,6 @@ export interface BaseInputProps {
|
|
|
54
49
|
* Works only when `multiline` is `true`.
|
|
55
50
|
*/
|
|
56
51
|
minRows?: number;
|
|
57
|
-
/**
|
|
58
|
-
* If `true`, a `textarea` element is rendered.
|
|
59
|
-
*/
|
|
60
|
-
multiline?: boolean;
|
|
61
52
|
/**
|
|
62
53
|
* The `name` attribute of the `input` or `textarea` element.
|
|
63
54
|
*/
|
|
@@ -90,6 +81,11 @@ export interface BaseInputProps {
|
|
|
90
81
|
* If `true`, the `input` or `textarea` will be required.
|
|
91
82
|
*/
|
|
92
83
|
required?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Custom render function for the `input` or `textarea` element.
|
|
86
|
+
* Use this to render a custom `input` or `textarea` element.
|
|
87
|
+
*/
|
|
88
|
+
renderInput?: (props: InputHTMLAttributes<HTMLInputElement | HTMLTextAreaElement>, ref: RefCallback<HTMLInputElement | HTMLTextAreaElement> | null) => JSX.Element;
|
|
93
89
|
/**
|
|
94
90
|
* Icon or any element displayed at the start of the `input` or `textarea`.
|
|
95
91
|
*/
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './autocomplete';
|
|
2
2
|
export * from './checkbox-field';
|
|
3
|
+
export * from './checkbox';
|
|
3
4
|
export * from './input-field';
|
|
5
|
+
export * from './radio';
|
|
6
|
+
export * from './radio-field';
|
|
7
|
+
export * from './radio-group';
|
|
4
8
|
export * from './select-field';
|
|
5
9
|
export * from './select-option';
|
|
6
10
|
export * from './text-field';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { RadioProps } from './radio.types';
|
|
3
|
+
import './radio.scss';
|
|
4
|
+
/**
|
|
5
|
+
* Radio buttons are used to pick an option when only one option can be chosen.
|
|
6
|
+
* A single radio button can be used representing a singular option,
|
|
7
|
+
* for the purpose of selecting an element between a group of options.
|
|
8
|
+
*
|
|
9
|
+
* ### Usage
|
|
10
|
+
*
|
|
11
|
+
* ```tsx
|
|
12
|
+
* import { useState } from 'react';
|
|
13
|
+
* import { Radio } from '@bloomreach/react-banana-ui';
|
|
14
|
+
*
|
|
15
|
+
* export default function MyRadioComponent() {
|
|
16
|
+
* const [checked, setChecked] = useState(false);
|
|
17
|
+
* return (
|
|
18
|
+
* <Radio
|
|
19
|
+
* checked={checked}
|
|
20
|
+
* onChange={(event) => setChecked(event.target.checked)}
|
|
21
|
+
* />
|
|
22
|
+
* );
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
declare const Radio: import("react").ForwardRefExoticComponent<RadioProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
27
|
+
export default Radio;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Meta } from '@storybook/react';
|
|
2
|
+
import { type Story } from './radio.stories';
|
|
3
|
+
declare const meta: Meta;
|
|
4
|
+
export default meta;
|
|
5
|
+
export declare const SelectedUncontrolled: Story;
|
|
6
|
+
export declare const SelectedControlled: Story;
|
|
7
|
+
export declare const Unselected: Story;
|
|
8
|
+
export declare const RadiosWithSameName: Story;
|
|
9
|
+
export declare const CombinedStories: Story;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import Radio from './radio';
|
|
3
|
+
declare const meta: Meta<typeof Radio>;
|
|
4
|
+
export default meta;
|
|
5
|
+
export type Story = StoryObj<typeof Radio>;
|
|
6
|
+
export declare const Basic: Story;
|
|
7
|
+
export declare const Controlled: Story;
|
|
8
|
+
export declare const Disabled: Story;
|
|
9
|
+
export declare const ReadOnly: Story;
|
|
10
|
+
export declare const RadiosWithSameNameAttribute: Story;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface RadioProps {
|
|
3
|
+
/**
|
|
4
|
+
* If `true`, the radio button is checked.
|
|
5
|
+
*/
|
|
6
|
+
checked?: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Custom class name for the container of the component.
|
|
9
|
+
*/
|
|
10
|
+
className?: string;
|
|
11
|
+
/**
|
|
12
|
+
* The state of the radio button when it is initially rendered. Use when you do not need to control its state.
|
|
13
|
+
* @default false
|
|
14
|
+
*/
|
|
15
|
+
defaultChecked?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* When `true`, prevents the user from interacting with the radio.
|
|
18
|
+
* @default false
|
|
19
|
+
*/
|
|
20
|
+
disabled?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* The props applied to the input element.
|
|
23
|
+
*/
|
|
24
|
+
inputProps?: React.InputHTMLAttributes<HTMLInputElement>;
|
|
25
|
+
/**
|
|
26
|
+
* The name of the input element.
|
|
27
|
+
*/
|
|
28
|
+
name?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Callback fired when the radio button is clicked
|
|
31
|
+
*/
|
|
32
|
+
onChange?: React.ChangeEventHandler<HTMLInputElement>;
|
|
33
|
+
/**
|
|
34
|
+
* If `true`, the component is read only and prevent user to change state.
|
|
35
|
+
* @default false
|
|
36
|
+
*/
|
|
37
|
+
readOnly?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* If `true`, the radio element is required.
|
|
40
|
+
* @default false
|
|
41
|
+
*/
|
|
42
|
+
required?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* The value of the radio element.
|
|
45
|
+
*/
|
|
46
|
+
value?: string;
|
|
47
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { RadioFieldProps } from './radio-field.types';
|
|
3
|
+
/**
|
|
4
|
+
* Radio fields are used to pick an option when only one option can be chosen.
|
|
5
|
+
* A single Radio field can be used representing a singular option,
|
|
6
|
+
* for the purpose of selecting an element between a group of options.
|
|
7
|
+
*
|
|
8
|
+
* ### Usage
|
|
9
|
+
*
|
|
10
|
+
* ```tsx
|
|
11
|
+
* import { useState } from 'react';
|
|
12
|
+
* import { RadioField } from '@bloomreach/react-banana-ui';
|
|
13
|
+
*
|
|
14
|
+
* export default function MyRadioFieldComponent() {
|
|
15
|
+
* const [checked, setChecked] = useState(false);
|
|
16
|
+
*
|
|
17
|
+
* return (
|
|
18
|
+
* <RadioField
|
|
19
|
+
* checked={checked}
|
|
20
|
+
* label="Radio button field with a label"
|
|
21
|
+
* onChange={(event) => setChecked(event.target.checked)}
|
|
22
|
+
* />
|
|
23
|
+
* );
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
declare const RadioField: import("react").ForwardRefExoticComponent<RadioFieldProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
28
|
+
export default RadioField;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Meta } from '@storybook/react';
|
|
2
|
+
import { type Story } from './radio-field.stories';
|
|
3
|
+
declare const meta: Meta;
|
|
4
|
+
export default meta;
|
|
5
|
+
export declare const WithLabelAndTooltip: Story;
|
|
6
|
+
export declare const Uncontrolled: Story;
|
|
7
|
+
export declare const Controlled: Story;
|
|
8
|
+
export declare const RadioFieldsWithSameNameAttribute: Story;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import RadioField from './radio-field';
|
|
3
|
+
declare const meta: Meta<typeof RadioField>;
|
|
4
|
+
export default meta;
|
|
5
|
+
export type Story = StoryObj<typeof RadioField>;
|
|
6
|
+
export declare const Basic: Story;
|
|
7
|
+
export declare const WithLabelAndTooltip: Story;
|
|
8
|
+
export declare const Controlled: Story;
|
|
9
|
+
export declare const Disabled: Story;
|
|
10
|
+
export declare const ReadOnly: Story;
|
|
11
|
+
export declare const RadioFieldsWithSameNameAttribute: Story;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import type { RadioProps } from '../radio';
|
|
3
|
+
export interface RadioFieldProps extends RadioProps {
|
|
4
|
+
/**
|
|
5
|
+
* The label to display with the radio field.
|
|
6
|
+
*/
|
|
7
|
+
label?: ReactNode;
|
|
8
|
+
/**
|
|
9
|
+
* Tooltip to display when the field has info icon.
|
|
10
|
+
*/
|
|
11
|
+
tooltip?: ReactNode;
|
|
12
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export type RadioGroupContextType = {
|
|
3
|
+
/**
|
|
4
|
+
* If `true`, all the radio buttons within the group will be disabled, preventing user interaction.
|
|
5
|
+
* @default false
|
|
6
|
+
*/
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* The common name for all radio buttons within the group.
|
|
10
|
+
* This is used to group the radio buttons together semantically in the DOM.
|
|
11
|
+
*/
|
|
12
|
+
name?: string;
|
|
13
|
+
/**
|
|
14
|
+
* This is a callback function that is fired when the state of any radio button within the group is changed.
|
|
15
|
+
* The event object of the radio button that triggered the change is passed as an argument.
|
|
16
|
+
*/
|
|
17
|
+
onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
|
|
18
|
+
/**
|
|
19
|
+
* If `true`, all the radio buttons within the group will be read-only,
|
|
20
|
+
* preventing the user from changing the value but allowing them to interact with the component.
|
|
21
|
+
* @default false
|
|
22
|
+
*/
|
|
23
|
+
readOnly?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* If `true`, the user must select one of the radio buttons within the group before submitting a form.
|
|
26
|
+
* @default false
|
|
27
|
+
*/
|
|
28
|
+
required?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* The current value of the radio group. This is usually the value of the selected radio button within the group.
|
|
31
|
+
*/
|
|
32
|
+
value: string | null;
|
|
33
|
+
};
|
|
34
|
+
export declare const RadioGroupContext: React.Context<RadioGroupContextType | undefined>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { RadioGroupProps } from './radio-group.types';
|
|
3
|
+
import './radio-group.scss';
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* RadioGroup is a component that groups Radio components together,
|
|
7
|
+
* ensuring that only one Radio within the group can be selected at a time.
|
|
8
|
+
* It is used when there is a list of two or more options that are mutually
|
|
9
|
+
* exclusive and the user must select exactly one choice
|
|
10
|
+
*
|
|
11
|
+
* ### Usage
|
|
12
|
+
*
|
|
13
|
+
* ```tsx
|
|
14
|
+
* import { RadioGroup } from '@bloomreach/react-banana-ui';
|
|
15
|
+
*
|
|
16
|
+
* export default function MyRadioFieldGroupComponent() {
|
|
17
|
+
* return (
|
|
18
|
+
* <RadioGroup label="Pick your favourite fruit">
|
|
19
|
+
* <RadioField label="Mango" value="mango" />
|
|
20
|
+
* <RadioField label="Banana" value="banana" />
|
|
21
|
+
* <RadioField label="Orange" value="orange" />
|
|
22
|
+
* </RadioGroup>
|
|
23
|
+
* ```
|
|
24
|
+
*OR
|
|
25
|
+
*
|
|
26
|
+
* ### Usage
|
|
27
|
+
*
|
|
28
|
+
* ```tsx
|
|
29
|
+
* import { RadioGroup } from '@bloomreach/react-banana-ui';
|
|
30
|
+
*
|
|
31
|
+
* export default function MyRadioGroupComponent() {
|
|
32
|
+
* return (
|
|
33
|
+
* <RadioGroup label="Radio Group" name="Radio group name">
|
|
34
|
+
* <Radio value="option1" />
|
|
35
|
+
* <Radio value="option2" />
|
|
36
|
+
* <Radio value="option3" />
|
|
37
|
+
* </RadioGroup>
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
declare const RadioGroup: React.ForwardRefExoticComponent<RadioGroupProps & React.RefAttributes<HTMLInputElement>>;
|
|
41
|
+
export default RadioGroup;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Args, Meta } from '@storybook/react';
|
|
2
|
+
import { type Story } from './radio-group.stories';
|
|
3
|
+
import { RadioGroupProps } from './radio-group.types';
|
|
4
|
+
type StoryArgs = Args & RadioGroupProps;
|
|
5
|
+
declare const meta: Meta<StoryArgs>;
|
|
6
|
+
export default meta;
|
|
7
|
+
export declare const Uncontrolled: Story;
|
|
8
|
+
export declare const Controlled: Story;
|
|
9
|
+
export declare const MixedDisabledAndReadOnlyState: Story;
|
|
10
|
+
export declare const CombinedStories: Story;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import RadioGroup from './radio-group';
|
|
3
|
+
declare const meta: Meta<typeof RadioGroup>;
|
|
4
|
+
export default meta;
|
|
5
|
+
export type Story = StoryObj<typeof RadioGroup>;
|
|
6
|
+
export declare const UncontrolledWithRadioFields: Story;
|
|
7
|
+
export declare const ControlledWithRadioFields: Story;
|
|
8
|
+
export declare const UncontrolledWithRadios: Story;
|
|
9
|
+
export declare const ControlledWithRadios: Story;
|
|
10
|
+
export declare const MixedWithRadioFieldsAndRadios: Story;
|
|
11
|
+
export declare const AllDisabled: Story;
|
|
12
|
+
export declare const AllReadOnly: Story;
|
|
13
|
+
export declare const MixedDisabledAndReadOnly: Story;
|
|
14
|
+
export declare const SingleRadioFieldInGroup: Story;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import React, { ReactElement } from 'react';
|
|
2
|
+
export interface RadioGroupProps {
|
|
3
|
+
/**
|
|
4
|
+
* The child elements of the component. These are usually `Radio` or 'RadioField' components.
|
|
5
|
+
*/
|
|
6
|
+
children: ReactElement | ReactElement[];
|
|
7
|
+
/**
|
|
8
|
+
* Custom class name for the container of the component. This can be used to apply custom styles.
|
|
9
|
+
*/
|
|
10
|
+
className?: string;
|
|
11
|
+
/**
|
|
12
|
+
* The default value of the selected radio field in an uncontrolled component.
|
|
13
|
+
* This is the value that the radio group starts with.
|
|
14
|
+
*/
|
|
15
|
+
defaultValue?: string;
|
|
16
|
+
/**
|
|
17
|
+
* If `true`, all the radio buttons within the group will be disabled, preventing user interaction.
|
|
18
|
+
* @default false
|
|
19
|
+
*/
|
|
20
|
+
disabled?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* The label for the radio group. This is usually displayed above the radio buttons.
|
|
23
|
+
*/
|
|
24
|
+
label?: string;
|
|
25
|
+
/**
|
|
26
|
+
* The common name for all radio buttons within the group.
|
|
27
|
+
* This is used to group the radio buttons together semantically in the DOM.
|
|
28
|
+
* If not provided, a unique name will be generated for the group.
|
|
29
|
+
*/
|
|
30
|
+
name?: string;
|
|
31
|
+
/**
|
|
32
|
+
* This is a callback function that is fired when the state of any radio button within the group is changed.
|
|
33
|
+
* The change event object of the radio button that triggered the change is passed as an argument.
|
|
34
|
+
*/
|
|
35
|
+
onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
|
|
36
|
+
/**
|
|
37
|
+
* The component orientation of the radio buttons within the group.
|
|
38
|
+
* @default 'vertical'
|
|
39
|
+
*/
|
|
40
|
+
orientation?: 'horizontal' | 'vertical';
|
|
41
|
+
/**
|
|
42
|
+
* If `true`, all the radio buttons within the group will be read-only,
|
|
43
|
+
* preventing the user from changing the value but allowing them to interact with the component.
|
|
44
|
+
* @default false
|
|
45
|
+
*/
|
|
46
|
+
readOnly?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* If `true`, the user must select one of the radio buttons within the group.
|
|
49
|
+
* @default false
|
|
50
|
+
*/
|
|
51
|
+
required?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* The value of the selected radio field in a controlled component.
|
|
54
|
+
* This is the value that the radio group starts with.
|
|
55
|
+
*/
|
|
56
|
+
value?: string;
|
|
57
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { ListboxGroupProps } from './listbox-group.types';
|
|
3
|
+
import './listbox-group.scss';
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
* The `ListboxGroup` component is used to display a list of grouped items aligned with design system styles.
|
|
7
|
+
* Use the `ListboxItem` component to define the items of the list and `ListboxGroupLabel` to define the group label.
|
|
8
|
+
*
|
|
9
|
+
* ### Usage
|
|
10
|
+
*
|
|
11
|
+
* import { Listbox, ListboxItem, ListboxGroup, ListboxGroupLabel } from '@bloomreach/react-banana-ui';
|
|
12
|
+
*
|
|
13
|
+
* export default function MyList() {
|
|
14
|
+
* return (
|
|
15
|
+
* <Listbox>
|
|
16
|
+
* <ListboxGroup>
|
|
17
|
+
* <ListboxGroupLabel>Group one</ListboxGroupLabel>
|
|
18
|
+
* <ListboxItem>Item 1</ListboxItem>
|
|
19
|
+
* <ListboxItem>Item 2</ListboxItem>
|
|
20
|
+
* <ListboxItem>Item 3</ListboxItem>
|
|
21
|
+
* </ListboxGroup>
|
|
22
|
+
* <ListboxGroup>
|
|
23
|
+
* <ListboxGroupLabel>Group two</ListboxGroupLabel>
|
|
24
|
+
* <ListboxItem>Item 1</ListboxItem>
|
|
25
|
+
* <ListboxItem>Item 2</ListboxItem>
|
|
26
|
+
* <ListboxItem>Item 3</ListboxItem>
|
|
27
|
+
* </ListboxGroup>
|
|
28
|
+
* </Listbox>
|
|
29
|
+
* );
|
|
30
|
+
* }
|
|
31
|
+
*/
|
|
32
|
+
declare const ListboxGroup: import("react").ForwardRefExoticComponent<ListboxGroupProps & import("react").RefAttributes<HTMLUListElement>>;
|
|
33
|
+
export default ListboxGroup;
|