@razorpay/blade 7.2.2 → 8.0.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/CHANGELOG.md CHANGED
@@ -1,5 +1,87 @@
1
1
  # @razorpay/blade
2
2
 
3
+ ## 8.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - 9917a5cd: feat(Dropdown): Controlled Dropdown and Button Trigger
8
+
9
+ - Adds API to seamlessly build controlled dropdown
10
+ - Add DropdownButton component to trigger dropdown using Button
11
+ - Removes `isDefaultSelected` from `ActionListItem` _(see migration guide below)_
12
+
13
+ > **Warning**
14
+ >
15
+ > **Breaking change** for consumers who -
16
+ >
17
+ > - Use `isDefaultSelected` on `ActionListItem` component
18
+ > - Use `onChange` on `SelectInput` (under some scenarios. Check migration guide below)
19
+ >
20
+ > Rest of the consumers can safely upgrade without any migration
21
+
22
+ ### Migration Guide
23
+
24
+ #### `isDefaultSelected` Migration
25
+
26
+ We have removed `isDefaultSelected` from `<ActionListItem />` component. [Check out API decision](https://github.com/razorpay/blade/blob/master/packages/blade/src/components/Dropdown/_decisions/controlled-dropdown.md) for reasoning
27
+
28
+ If you were using it as a workaround for controlled selection,
29
+
30
+ - We now have a first class controlled selection support with `value` and `onChange` prop on `SelectInput`.
31
+
32
+ Checkout CodeSandbox Example for new API - https://codesandbox.io/s/blade-controlled-select-vxg30b
33
+
34
+ If you were using `isDefaultSelected` for default selections, you can now use `defaultValue` on SelectInput
35
+
36
+ - Remove `isDefaultSelected` and use `defaultValue` on SelectInput. You can pass array of values to `defaultValue` in case of multiselect
37
+ ```diff
38
+ <Dropdown>
39
+ <SelectInput
40
+ label="Select City"
41
+ + defaultValue="mumbai"
42
+ />
43
+ <DropdownOverlay>
44
+ <ActionListItem
45
+ title="Mumbai"
46
+ value="mumbai"
47
+ - isDefaultSelected
48
+ />
49
+ <ActionListItem title="Bangalore" value="bangalore" />
50
+ </DropdownOverlay>
51
+ </Dropdown>
52
+ ```
53
+
54
+ #### `onChange` on SelectInput Migration
55
+
56
+ As a part of [bug fix](https://github.com/razorpay/blade/issues/1102), `onChange` will now **NOT** be called on initial render
57
+ like it previously did. This will only require migration if you were earlier relying on `onChange` to set initial value.
58
+
59
+ If you were relying on `onChange` to set initial value, you can now move those values to your `useState`'s initial value.
60
+
61
+ ```tsx
62
+ const Example = (): JSX.Element => {
63
+ const [cities, setCities] = React.useState();
64
+ return (
65
+ <>
66
+ <Dropdown>
67
+ <SelectInput label="Cities" onChange={({values}) => setCities(values) } />
68
+ <DropdownOverlay>
69
+ <ActionListItem title="Mumbai" value="mumbai" />
70
+ <ActionListItem title="Pune" value="pune" />
71
+ </DropdownOverlay>
72
+ </Dropdown>
73
+ <Text>{cities}</Text>
74
+ {/*
75
+ In earlier versions, value of `cities` would've been `['']`
76
+ (because onChange would've been called initially to set array with empty string value)
77
+
78
+ Now it will output undefined (anything you pass in your useState) as the onChange wouldn't be called on initial render
79
+ */}
80
+ <>
81
+ )
82
+ }
83
+ ```
84
+
3
85
  ## 7.2.2
4
86
 
5
87
  ### Patch Changes
@@ -1437,6 +1437,10 @@ declare type ActionListItemProps = {
1437
1437
  * Link to open when item is clicked.
1438
1438
  */
1439
1439
  href?: string;
1440
+ /**
1441
+ * HTML target of the link
1442
+ */
1443
+ target?: string;
1440
1444
  /**
1441
1445
  * Item that goes on left-side of item.
1442
1446
  *
@@ -1451,12 +1455,14 @@ declare type ActionListItemProps = {
1451
1455
  * Valid elements - `<ActionListItemText />`, `<ActionListItemIcon />`
1452
1456
  */
1453
1457
  trailing?: React__default.ReactNode;
1454
- /**
1455
- * If item is selected on page load
1456
- */
1457
- isDefaultSelected?: boolean;
1458
1458
  isDisabled?: boolean;
1459
1459
  intent?: Extract<Feedback, 'negative'>;
1460
+ /**
1461
+ * Can be used in combination of `onClick` to highlight item as selected in Button Triggers.
1462
+ *
1463
+ * When trigger is SelectInput, Use `value` prop on SelectInput instead to make dropdown controlled.
1464
+ */
1465
+ isSelected?: boolean;
1460
1466
  /**
1461
1467
  * Internally passed from ActionList. No need to pass it explicitly
1462
1468
  *
@@ -2896,9 +2902,10 @@ declare const CheckboxGroup: ({ children, label, helpText, isDisabled, necessity
2896
2902
 
2897
2903
  declare type DropdownProps = {
2898
2904
  selectionType?: 'single' | 'multiple';
2905
+ onDismiss?: () => void;
2899
2906
  children: React__default.ReactNode[];
2900
2907
  } & StyledPropsBlade;
2901
- declare const Dropdown: ({ children, selectionType, ...styledProps }: DropdownProps) => JSX.Element;
2908
+ declare const Dropdown: ({ children, selectionType, onDismiss, ...styledProps }: DropdownProps) => JSX.Element;
2902
2909
 
2903
2910
  declare type DropdownOverlayProps = {
2904
2911
  children: React__default.ReactNode;
@@ -3792,7 +3799,7 @@ declare type TextInputProps = Pick<BaseInputProps, 'label' | 'labelPosition' | '
3792
3799
  */
3793
3800
  type?: Type;
3794
3801
  } & StyledPropsBlade;
3795
- declare const TextInput: React__default.ForwardRefExoticComponent<Pick<BaseInputProps, "name" | "testID" | "placeholder" | "label" | "value" | "onFocus" | "onBlur" | "onChange" | "onSubmit" | "autoFocus" | "defaultValue" | "prefix" | "autoCapitalize" | "isDisabled" | "labelPosition" | "helpText" | "errorText" | "successText" | "necessityIndicator" | "suffix" | "validationState" | "isRequired" | "maxCharacters" | "keyboardReturnKeyType" | "autoCompleteSuggestionType"> & {
3802
+ declare const TextInput: React__default.ForwardRefExoticComponent<Pick<BaseInputProps, "name" | "testID" | "placeholder" | "label" | "value" | "onFocus" | "onBlur" | "onChange" | "onSubmit" | "autoFocus" | "defaultValue" | "prefix" | "autoCapitalize" | "isDisabled" | "labelPosition" | "validationState" | "helpText" | "errorText" | "necessityIndicator" | "successText" | "isRequired" | "suffix" | "maxCharacters" | "keyboardReturnKeyType" | "autoCompleteSuggestionType"> & {
3796
3803
  /**
3797
3804
  * Decides whether to render a clear icon button
3798
3805
  */
@@ -3878,7 +3885,7 @@ declare type PasswordInputExtraProps = {
3878
3885
  autoCompleteSuggestionType?: Extract<BaseInputProps['autoCompleteSuggestionType'], 'none' | 'password' | 'newPassword'>;
3879
3886
  };
3880
3887
  declare type PasswordInputProps = Pick<BaseInputProps, 'label' | 'labelPosition' | 'maxCharacters' | 'validationState' | 'errorText' | 'successText' | 'helpText' | 'isDisabled' | 'defaultValue' | 'placeholder' | 'isRequired' | 'value' | 'onChange' | 'onBlur' | 'onSubmit' | 'onFocus' | 'name' | 'autoFocus' | 'keyboardReturnKeyType' | 'autoCompleteSuggestionType' | 'testID'> & PasswordInputExtraProps & StyledPropsBlade;
3881
- declare const PasswordInput: React__default.ForwardRefExoticComponent<Pick<BaseInputProps, "name" | "testID" | "placeholder" | "label" | "value" | "onFocus" | "onBlur" | "onChange" | "onSubmit" | "autoFocus" | "defaultValue" | "isDisabled" | "labelPosition" | "helpText" | "errorText" | "successText" | "validationState" | "isRequired" | "maxCharacters" | "keyboardReturnKeyType" | "autoCompleteSuggestionType"> & PasswordInputExtraProps & Partial<Omit<MakeObjectResponsive<{
3888
+ declare const PasswordInput: React__default.ForwardRefExoticComponent<Pick<BaseInputProps, "name" | "testID" | "placeholder" | "label" | "value" | "onFocus" | "onBlur" | "onChange" | "onSubmit" | "autoFocus" | "defaultValue" | "isDisabled" | "labelPosition" | "validationState" | "helpText" | "errorText" | "successText" | "isRequired" | "maxCharacters" | "keyboardReturnKeyType" | "autoCompleteSuggestionType"> & PasswordInputExtraProps & Partial<Omit<MakeObjectResponsive<{
3882
3889
  margin: SpacingValueType | ArrayOfMaxLength4<SpacingValueType>;
3883
3890
  marginX: SpacingValueType;
3884
3891
  marginY: SpacingValueType;
@@ -3912,7 +3919,7 @@ declare type TextAreaProps = Pick<BaseInputProps, 'label' | 'labelPosition' | 'n
3912
3919
  */
3913
3920
  onClearButtonClick?: () => void;
3914
3921
  } & StyledPropsBlade;
3915
- declare const TextArea: React__default.ForwardRefExoticComponent<Pick<BaseInputProps, "name" | "testID" | "placeholder" | "label" | "value" | "onFocus" | "onBlur" | "onChange" | "onSubmit" | "autoFocus" | "defaultValue" | "numberOfLines" | "isDisabled" | "labelPosition" | "helpText" | "errorText" | "successText" | "necessityIndicator" | "validationState" | "isRequired" | "maxCharacters"> & {
3922
+ declare const TextArea: React__default.ForwardRefExoticComponent<Pick<BaseInputProps, "name" | "testID" | "placeholder" | "label" | "value" | "onFocus" | "onBlur" | "onChange" | "onSubmit" | "autoFocus" | "defaultValue" | "numberOfLines" | "isDisabled" | "labelPosition" | "validationState" | "helpText" | "errorText" | "necessityIndicator" | "successText" | "isRequired" | "maxCharacters"> & {
3916
3923
  /**
3917
3924
  * Decides whether to render a clear icon button
3918
3925
  */
@@ -4005,6 +4012,16 @@ declare const OTPInput: ({ autoFocus, errorText, helpText, isDisabled, keyboardR
4005
4012
 
4006
4013
  declare type SelectInputProps = Pick<BaseInputProps, 'label' | 'labelPosition' | 'necessityIndicator' | 'validationState' | 'helpText' | 'errorText' | 'successText' | 'name' | 'isDisabled' | 'isRequired' | 'prefix' | 'suffix' | 'autoFocus' | 'onClick' | 'onFocus' | 'onBlur' | 'placeholder' | 'testID'> & {
4007
4014
  icon?: IconComponent$1;
4015
+ /**
4016
+ * Controlled value of the Select. Use it in combination of `onChange`.
4017
+ *
4018
+ * Check out [Controlled Dropdown Documentation](https://blade.razorpay.com/?path=/story/components-dropdown-with-select--controlled-dropdown&globals=measureEnabled:false) for example.
4019
+ */
4020
+ value?: string | string[];
4021
+ /**
4022
+ * Used to set the default value of SelectInput when it's uncontrolled. Use `value` instead for controlled SelectInput
4023
+ */
4024
+ defaultValue?: string | string[];
4008
4025
  onChange?: ({ name, values }: {
4009
4026
  name?: string;
4010
4027
  values: string[];
@@ -4037,8 +4054,18 @@ declare type SelectInputProps = Pick<BaseInputProps, 'label' | 'labelPosition' |
4037
4054
  *
4038
4055
  * Checkout {@link https://blade.razorpay.com/?path=/docs/components-dropdown-with-select--with-single-select SelectInput Documentation}.
4039
4056
  */
4040
- declare const SelectInput: React__default.ForwardRefExoticComponent<Pick<BaseInputProps, "name" | "testID" | "placeholder" | "label" | "onFocus" | "onBlur" | "onClick" | "autoFocus" | "prefix" | "isDisabled" | "labelPosition" | "helpText" | "errorText" | "successText" | "necessityIndicator" | "suffix" | "validationState" | "isRequired"> & {
4057
+ declare const SelectInput: React__default.ForwardRefExoticComponent<Pick<BaseInputProps, "name" | "testID" | "placeholder" | "label" | "onFocus" | "onBlur" | "onClick" | "autoFocus" | "prefix" | "isDisabled" | "labelPosition" | "validationState" | "helpText" | "errorText" | "necessityIndicator" | "successText" | "isRequired" | "suffix"> & {
4041
4058
  icon?: IconComponent$1 | undefined;
4059
+ /**
4060
+ * Controlled value of the Select. Use it in combination of `onChange`.
4061
+ *
4062
+ * Check out [Controlled Dropdown Documentation](https://blade.razorpay.com/?path=/story/components-dropdown-with-select--controlled-dropdown&globals=measureEnabled:false) for example.
4063
+ */
4064
+ value?: string | string[] | undefined;
4065
+ /**
4066
+ * Used to set the default value of SelectInput when it's uncontrolled. Use `value` instead for controlled SelectInput
4067
+ */
4068
+ defaultValue?: string | string[] | undefined;
4042
4069
  onChange?: (({ name, values }: {
4043
4070
  name?: string | undefined;
4044
4071
  values: string[];
@@ -1437,6 +1437,10 @@ declare type ActionListItemProps = {
1437
1437
  * Link to open when item is clicked.
1438
1438
  */
1439
1439
  href?: string;
1440
+ /**
1441
+ * HTML target of the link
1442
+ */
1443
+ target?: string;
1440
1444
  /**
1441
1445
  * Item that goes on left-side of item.
1442
1446
  *
@@ -1451,12 +1455,14 @@ declare type ActionListItemProps = {
1451
1455
  * Valid elements - `<ActionListItemText />`, `<ActionListItemIcon />`
1452
1456
  */
1453
1457
  trailing?: React__default.ReactNode;
1454
- /**
1455
- * If item is selected on page load
1456
- */
1457
- isDefaultSelected?: boolean;
1458
1458
  isDisabled?: boolean;
1459
1459
  intent?: Extract<Feedback, 'negative'>;
1460
+ /**
1461
+ * Can be used in combination of `onClick` to highlight item as selected in Button Triggers.
1462
+ *
1463
+ * When trigger is SelectInput, Use `value` prop on SelectInput instead to make dropdown controlled.
1464
+ */
1465
+ isSelected?: boolean;
1460
1466
  /**
1461
1467
  * Internally passed from ActionList. No need to pass it explicitly
1462
1468
  *
@@ -2898,9 +2904,10 @@ declare const CheckboxGroup: ({ children, label, helpText, isDisabled, necessity
2898
2904
 
2899
2905
  declare type DropdownProps = {
2900
2906
  selectionType?: 'single' | 'multiple';
2907
+ onDismiss?: () => void;
2901
2908
  children: React__default.ReactNode[];
2902
2909
  } & StyledPropsBlade;
2903
- declare const Dropdown: ({ children, selectionType, ...styledProps }: DropdownProps) => JSX.Element;
2910
+ declare const Dropdown: ({ children, selectionType, onDismiss, ...styledProps }: DropdownProps) => JSX.Element;
2904
2911
 
2905
2912
  declare type DropdownOverlayProps = {
2906
2913
  children: React__default.ReactNode;
@@ -3795,7 +3802,7 @@ declare type TextInputProps = Pick<BaseInputProps, 'label' | 'labelPosition' | '
3795
3802
  */
3796
3803
  type?: Type;
3797
3804
  } & StyledPropsBlade;
3798
- declare const TextInput: React__default.ForwardRefExoticComponent<Pick<BaseInputProps, "testID" | "name" | "placeholder" | "label" | "value" | "onBlur" | "onFocus" | "defaultValue" | "prefix" | "autoCapitalize" | "onChange" | "onSubmit" | "isDisabled" | "autoFocus" | "labelPosition" | "helpText" | "errorText" | "successText" | "necessityIndicator" | "suffix" | "validationState" | "isRequired" | "maxCharacters" | "keyboardReturnKeyType" | "autoCompleteSuggestionType"> & {
3805
+ declare const TextInput: React__default.ForwardRefExoticComponent<Pick<BaseInputProps, "testID" | "name" | "placeholder" | "label" | "value" | "onBlur" | "onFocus" | "defaultValue" | "prefix" | "autoCapitalize" | "onChange" | "onSubmit" | "isDisabled" | "autoFocus" | "labelPosition" | "validationState" | "helpText" | "errorText" | "necessityIndicator" | "successText" | "isRequired" | "suffix" | "maxCharacters" | "keyboardReturnKeyType" | "autoCompleteSuggestionType"> & {
3799
3806
  /**
3800
3807
  * Decides whether to render a clear icon button
3801
3808
  */
@@ -3881,7 +3888,7 @@ declare type PasswordInputExtraProps = {
3881
3888
  autoCompleteSuggestionType?: Extract<BaseInputProps['autoCompleteSuggestionType'], 'none' | 'password' | 'newPassword'>;
3882
3889
  };
3883
3890
  declare type PasswordInputProps = Pick<BaseInputProps, 'label' | 'labelPosition' | 'maxCharacters' | 'validationState' | 'errorText' | 'successText' | 'helpText' | 'isDisabled' | 'defaultValue' | 'placeholder' | 'isRequired' | 'value' | 'onChange' | 'onBlur' | 'onSubmit' | 'onFocus' | 'name' | 'autoFocus' | 'keyboardReturnKeyType' | 'autoCompleteSuggestionType' | 'testID'> & PasswordInputExtraProps & StyledPropsBlade;
3884
- declare const PasswordInput: React__default.ForwardRefExoticComponent<Pick<BaseInputProps, "testID" | "name" | "placeholder" | "label" | "value" | "onBlur" | "onFocus" | "defaultValue" | "onChange" | "onSubmit" | "isDisabled" | "autoFocus" | "labelPosition" | "helpText" | "errorText" | "successText" | "validationState" | "isRequired" | "maxCharacters" | "keyboardReturnKeyType" | "autoCompleteSuggestionType"> & PasswordInputExtraProps & Partial<Omit<MakeObjectResponsive<{
3891
+ declare const PasswordInput: React__default.ForwardRefExoticComponent<Pick<BaseInputProps, "testID" | "name" | "placeholder" | "label" | "value" | "onBlur" | "onFocus" | "defaultValue" | "onChange" | "onSubmit" | "isDisabled" | "autoFocus" | "labelPosition" | "validationState" | "helpText" | "errorText" | "successText" | "isRequired" | "maxCharacters" | "keyboardReturnKeyType" | "autoCompleteSuggestionType"> & PasswordInputExtraProps & Partial<Omit<MakeObjectResponsive<{
3885
3892
  margin: SpacingValueType | ArrayOfMaxLength4<SpacingValueType>;
3886
3893
  marginX: SpacingValueType;
3887
3894
  marginY: SpacingValueType;
@@ -3915,7 +3922,7 @@ declare type TextAreaProps = Pick<BaseInputProps, 'label' | 'labelPosition' | 'n
3915
3922
  */
3916
3923
  onClearButtonClick?: () => void;
3917
3924
  } & StyledPropsBlade;
3918
- declare const TextArea: React__default.ForwardRefExoticComponent<Pick<BaseInputProps, "testID" | "name" | "placeholder" | "label" | "value" | "onBlur" | "onFocus" | "numberOfLines" | "defaultValue" | "onChange" | "onSubmit" | "isDisabled" | "autoFocus" | "labelPosition" | "helpText" | "errorText" | "successText" | "necessityIndicator" | "validationState" | "isRequired" | "maxCharacters"> & {
3925
+ declare const TextArea: React__default.ForwardRefExoticComponent<Pick<BaseInputProps, "testID" | "name" | "placeholder" | "label" | "value" | "onBlur" | "onFocus" | "numberOfLines" | "defaultValue" | "onChange" | "onSubmit" | "isDisabled" | "autoFocus" | "labelPosition" | "validationState" | "helpText" | "errorText" | "necessityIndicator" | "successText" | "isRequired" | "maxCharacters"> & {
3919
3926
  /**
3920
3927
  * Decides whether to render a clear icon button
3921
3928
  */
@@ -4008,6 +4015,16 @@ declare const OTPInput: ({ autoFocus, errorText, helpText, isDisabled, keyboardR
4008
4015
 
4009
4016
  declare type SelectInputProps = Pick<BaseInputProps, 'label' | 'labelPosition' | 'necessityIndicator' | 'validationState' | 'helpText' | 'errorText' | 'successText' | 'name' | 'isDisabled' | 'isRequired' | 'prefix' | 'suffix' | 'autoFocus' | 'onClick' | 'onFocus' | 'onBlur' | 'placeholder' | 'testID'> & {
4010
4017
  icon?: IconComponent$1;
4018
+ /**
4019
+ * Controlled value of the Select. Use it in combination of `onChange`.
4020
+ *
4021
+ * Check out [Controlled Dropdown Documentation](https://blade.razorpay.com/?path=/story/components-dropdown-with-select--controlled-dropdown&globals=measureEnabled:false) for example.
4022
+ */
4023
+ value?: string | string[];
4024
+ /**
4025
+ * Used to set the default value of SelectInput when it's uncontrolled. Use `value` instead for controlled SelectInput
4026
+ */
4027
+ defaultValue?: string | string[];
4011
4028
  onChange?: ({ name, values }: {
4012
4029
  name?: string;
4013
4030
  values: string[];
@@ -4040,8 +4057,18 @@ declare type SelectInputProps = Pick<BaseInputProps, 'label' | 'labelPosition' |
4040
4057
  *
4041
4058
  * Checkout {@link https://blade.razorpay.com/?path=/docs/components-dropdown-with-select--with-single-select SelectInput Documentation}.
4042
4059
  */
4043
- declare const SelectInput: React__default.ForwardRefExoticComponent<Pick<BaseInputProps, "testID" | "name" | "placeholder" | "label" | "onBlur" | "onFocus" | "onClick" | "prefix" | "isDisabled" | "autoFocus" | "labelPosition" | "helpText" | "errorText" | "successText" | "necessityIndicator" | "suffix" | "validationState" | "isRequired"> & {
4060
+ declare const SelectInput: React__default.ForwardRefExoticComponent<Pick<BaseInputProps, "testID" | "name" | "placeholder" | "label" | "onBlur" | "onFocus" | "onClick" | "prefix" | "isDisabled" | "autoFocus" | "labelPosition" | "validationState" | "helpText" | "errorText" | "necessityIndicator" | "successText" | "isRequired" | "suffix"> & {
4044
4061
  icon?: IconComponent$1 | undefined;
4062
+ /**
4063
+ * Controlled value of the Select. Use it in combination of `onChange`.
4064
+ *
4065
+ * Check out [Controlled Dropdown Documentation](https://blade.razorpay.com/?path=/story/components-dropdown-with-select--controlled-dropdown&globals=measureEnabled:false) for example.
4066
+ */
4067
+ value?: string | string[] | undefined;
4068
+ /**
4069
+ * Used to set the default value of SelectInput when it's uncontrolled. Use `value` instead for controlled SelectInput
4070
+ */
4071
+ defaultValue?: string | string[] | undefined;
4045
4072
  onChange?: (({ name, values }: {
4046
4073
  name?: string | undefined;
4047
4074
  values: string[];