@razorpay/blade 6.4.0 → 6.5.1

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.
@@ -19,6 +19,7 @@ declare const MetaConstants: {
19
19
  readonly ActionListSection: "action-list-section";
20
20
  readonly Alert: "alert";
21
21
  readonly Badge: "badge";
22
+ readonly Box: "box";
22
23
  readonly Button: "button";
23
24
  readonly Checkbox: "checkbox";
24
25
  readonly CheckboxGroup: "checkbox-group";
@@ -47,18 +48,73 @@ declare const MetaConstants: {
47
48
  };
48
49
 
49
50
  type Breakpoints = Readonly<{
50
- /** max width: 320px */
51
+ /**
52
+ * `base` is used for responsive styling following a **mobile first** approach. It starts from 0px till the next existing token
53
+ *
54
+ * Think of this as styles without any media query.
55
+ *
56
+ * ### Example
57
+ *
58
+ * This code will set margin as `spacing.2` on "m" size screens and above. And as `spacing.1` on less than "m" size screens
59
+ * ```jsx
60
+ * <Box margin={{ base: 'spacing.1', m: 'spacing.2' }} />
61
+ * ```
62
+ *
63
+ * This roughly translates into -
64
+ *
65
+ * ```
66
+ * .Box {
67
+ * margin: 'spacing.1';
68
+ * }
69
+ *
70
+ * @media screen and (min-width: 768px) {
71
+ * .Box {
72
+ * margin: 'spacing.2';
73
+ * }
74
+ * }
75
+ * ```
76
+ */
77
+ base: number;
78
+ /**
79
+ * `@media screen and (min-width: 320px)`
80
+ *
81
+ * Small Mobiles
82
+ */
51
83
  xs: number;
52
- /** min width: 321px and max width: 480px */
84
+ /**
85
+ * `@media screen and (min-width: 480px)`
86
+ *
87
+ * Mobiles and Small Tablets
88
+ */
53
89
  s: number;
54
- /** min width: 481px and max width: 768px */
90
+ /**
91
+ * `@media screen and (min-width: 768px)`
92
+ *
93
+ * Medium and Large Tablets.
94
+ *
95
+ * Dimensions with `m` and above can be treated as desktop in mobile-first approach (with min-width).
96
+ * Hence this breakpoint can be used for desktop styling.
97
+ *
98
+ * E.g. next example will keep flexDirection `row` on mobiles and `column` on large tablets, desktop, and larger screens
99
+ *
100
+ * ```jsx
101
+ * <Box display="flex" flexDirection={{ base: 'row', m: 'column' }} />
102
+ * ```
103
+ *
104
+ */
55
105
  m: number;
56
- /** min width: 769 and max width: 1024px */
106
+ /**
107
+ * `@media screen and (min-width: 1024px)`
108
+ *
109
+ * Desktop
110
+ */
57
111
  l: number;
58
- /** min width: 1025 and max width: 1200px */
112
+ /**
113
+ * `@media screen and (min-width: 1200px)`
114
+ *
115
+ * HD Desktop
116
+ */
59
117
  xl: number;
60
- /** min width: 1201px */
61
- max: number;
62
118
  }>;
63
119
 
64
120
  /* eslint-disable @typescript-eslint/no-explicit-any */
@@ -102,6 +158,11 @@ type ColorSchemeNamesInput = ColorSchemeNames | 'system';
102
158
 
103
159
  declare const getColorScheme: (colorScheme?: ColorSchemeNamesInput) => ColorSchemeNames;
104
160
 
161
+ declare const getMediaQuery: ({ min, max }: {
162
+ min: number;
163
+ max?: number | undefined;
164
+ }) => string;
165
+
105
166
  declare type PlatformTypes = 'browser' | 'node' | 'react-native' | 'unknown';
106
167
  declare const getPlatformType: () => PlatformTypes;
107
168
 
@@ -482,4 +543,4 @@ declare const castNativeType: <T>(value: T) => Extract<T, {
482
543
  __brand__?: "platform-all" | "platform-native" | undefined;
483
544
  }>;
484
545
 
485
- export { AccessibilityKeys, AccessibilityMap, AccessibilityProps, AriaAttributes, AriaRoles, DeepPartial, MakeSize, MetaConstants, Platform, PlatformTypes, UseColorScheme, WithComponentId, castNativeType, castWebType, getColorScheme, getComponentId, getOS, getPlatformType, isAndroid, isPartialMatchObjectKeys, isReactNative, isValidAllowedChildren, makeAccessible, makeBezier, makeBorderSize, makeMotionTime, makeSize, makeSpace, makeTypographySize, metaAttribute, setupMatchMediaMock, testID, toTitleCase, useBreakpoint, useColorScheme, usePrevious };
546
+ export { AccessibilityKeys, AccessibilityMap, AccessibilityProps, AriaAttributes, AriaRoles, DeepPartial, MakeSize, MetaConstants, Platform, PlatformTypes, UseColorScheme, WithComponentId, castNativeType, castWebType, getColorScheme, getComponentId, getMediaQuery, getOS, getPlatformType, isAndroid, isPartialMatchObjectKeys, isReactNative, isValidAllowedChildren, makeAccessible, makeBezier, makeBorderSize, makeMotionTime, makeSize, makeSpace, makeTypographySize, metaAttribute, setupMatchMediaMock, testID, toTitleCase, useBreakpoint, useColorScheme, usePrevious };
@@ -20,6 +20,7 @@ declare const MetaConstants: {
20
20
  readonly ActionListSection: "action-list-section";
21
21
  readonly Alert: "alert";
22
22
  readonly Badge: "badge";
23
+ readonly Box: "box";
23
24
  readonly Button: "button";
24
25
  readonly Checkbox: "checkbox";
25
26
  readonly CheckboxGroup: "checkbox-group";
@@ -48,18 +49,73 @@ declare const MetaConstants: {
48
49
  };
49
50
 
50
51
  type Breakpoints = Readonly<{
51
- /** max width: 320px */
52
+ /**
53
+ * `base` is used for responsive styling following a **mobile first** approach. It starts from 0px till the next existing token
54
+ *
55
+ * Think of this as styles without any media query.
56
+ *
57
+ * ### Example
58
+ *
59
+ * This code will set margin as `spacing.2` on "m" size screens and above. And as `spacing.1` on less than "m" size screens
60
+ * ```jsx
61
+ * <Box margin={{ base: 'spacing.1', m: 'spacing.2' }} />
62
+ * ```
63
+ *
64
+ * This roughly translates into -
65
+ *
66
+ * ```
67
+ * .Box {
68
+ * margin: 'spacing.1';
69
+ * }
70
+ *
71
+ * @media screen and (min-width: 768px) {
72
+ * .Box {
73
+ * margin: 'spacing.2';
74
+ * }
75
+ * }
76
+ * ```
77
+ */
78
+ base: number;
79
+ /**
80
+ * `@media screen and (min-width: 320px)`
81
+ *
82
+ * Small Mobiles
83
+ */
52
84
  xs: number;
53
- /** min width: 321px and max width: 480px */
85
+ /**
86
+ * `@media screen and (min-width: 480px)`
87
+ *
88
+ * Mobiles and Small Tablets
89
+ */
54
90
  s: number;
55
- /** min width: 481px and max width: 768px */
91
+ /**
92
+ * `@media screen and (min-width: 768px)`
93
+ *
94
+ * Medium and Large Tablets.
95
+ *
96
+ * Dimensions with `m` and above can be treated as desktop in mobile-first approach (with min-width).
97
+ * Hence this breakpoint can be used for desktop styling.
98
+ *
99
+ * E.g. next example will keep flexDirection `row` on mobiles and `column` on large tablets, desktop, and larger screens
100
+ *
101
+ * ```jsx
102
+ * <Box display="flex" flexDirection={{ base: 'row', m: 'column' }} />
103
+ * ```
104
+ *
105
+ */
56
106
  m: number;
57
- /** min width: 769 and max width: 1024px */
107
+ /**
108
+ * `@media screen and (min-width: 1024px)`
109
+ *
110
+ * Desktop
111
+ */
58
112
  l: number;
59
- /** min width: 1025 and max width: 1200px */
113
+ /**
114
+ * `@media screen and (min-width: 1200px)`
115
+ *
116
+ * HD Desktop
117
+ */
60
118
  xl: number;
61
- /** min width: 1201px */
62
- max: number;
63
119
  }>;
64
120
 
65
121
  /* eslint-disable @typescript-eslint/no-explicit-any */
@@ -103,6 +159,11 @@ type ColorSchemeNamesInput = ColorSchemeNames | 'system';
103
159
 
104
160
  declare const getColorScheme: (colorScheme?: ColorSchemeNamesInput) => ColorSchemeNames;
105
161
 
162
+ declare const getMediaQuery: ({ min, max }: {
163
+ min: number;
164
+ max?: number | undefined;
165
+ }) => string;
166
+
106
167
  declare type PlatformTypes = 'browser' | 'node' | 'react-native' | 'unknown';
107
168
  declare const getPlatformType: () => PlatformTypes;
108
169
 
@@ -481,4 +542,4 @@ declare const castNativeType: <T>(value: T) => Extract<T, {
481
542
  __brand__?: "platform-native" | "platform-all" | undefined;
482
543
  }>;
483
544
 
484
- export { AccessibilityKeys, AccessibilityMap, AccessibilityProps, AriaAttributes, AriaRoles, DeepPartial, MakeSize, MetaConstants, Platform, PlatformTypes, UseColorScheme, WithComponentId, castNativeType, castWebType, getColorScheme, getComponentId, getOS, getPlatformType, isAndroid, isPartialMatchObjectKeys, isReactNative, isValidAllowedChildren, makeAccessible, makeBezier, makeBorderSize, makeMotionTime, makeSize, makeSpace, makeTypographySize, metaAttribute, setupMatchMediaMock, testID, toTitleCase, useBreakpoint, useColorScheme, usePrevious };
545
+ export { AccessibilityKeys, AccessibilityMap, AccessibilityProps, AriaAttributes, AriaRoles, DeepPartial, MakeSize, MetaConstants, Platform, PlatformTypes, UseColorScheme, WithComponentId, castNativeType, castWebType, getColorScheme, getComponentId, getMediaQuery, getOS, getPlatformType, isAndroid, isPartialMatchObjectKeys, isReactNative, isValidAllowedChildren, makeAccessible, makeBezier, makeBorderSize, makeMotionTime, makeSize, makeSpace, makeTypographySize, metaAttribute, setupMatchMediaMock, testID, toTitleCase, useBreakpoint, useColorScheme, usePrevious };
@@ -2791,7 +2791,7 @@ var cloneDeep_1 = cloneDeep;
2791
2791
 
2792
2792
  var metaAttribute=function metaAttribute(_ref){var testID=_ref.testID;return _extends({},testID?{testID:testID}:{});};
2793
2793
 
2794
- var MetaConstants={ActionList:'action-list',ActionListFooter:'action-list-footer',ActionListHeader:'action-list-header',ActionListItem:'action-list-item',ActionListSection:'action-list-section',Alert:'alert',Badge:'badge',Button:'button',Checkbox:'checkbox',CheckboxGroup:'checkbox-group',Code:'code',Component:'blade-component',Counter:'counter',DropdownOverlay:'dropdown-overlay',Icon:'icon',IconButton:'icon-button',Indicator:'indicator',Link:'link',List:'list',ListItem:'list-item',OTPInput:'otp-input',ProgressBar:'progress-bar',Radio:'radio',RadioGroup:'radio-group',SkipNav:'skipnav',Spinner:'spinner',SelectInput:'select-input',Card:'card',CardBody:'card-body',CardHeader:'card-header',CardFooter:'card-footer',VisuallyHidden:'visually-hidden'};
2794
+ var MetaConstants={ActionList:'action-list',ActionListFooter:'action-list-footer',ActionListHeader:'action-list-header',ActionListItem:'action-list-item',ActionListSection:'action-list-section',Alert:'alert',Badge:'badge',Box:'box',Button:'button',Checkbox:'checkbox',CheckboxGroup:'checkbox-group',Code:'code',Component:'blade-component',Counter:'counter',DropdownOverlay:'dropdown-overlay',Icon:'icon',IconButton:'icon-button',Indicator:'indicator',Link:'link',List:'list',ListItem:'list-item',OTPInput:'otp-input',ProgressBar:'progress-bar',Radio:'radio',RadioGroup:'radio-group',SkipNav:'skipnav',Spinner:'spinner',SelectInput:'select-input',Card:'card',CardBody:'card-body',CardHeader:'card-header',CardFooter:'card-footer',VisuallyHidden:'visually-hidden'};
2795
2795
 
2796
2796
  var getColorScheme=function getColorScheme(){var colorScheme=arguments.length>0&&arguments[0]!==undefined?arguments[0]:'light';if(colorScheme==='light'||colorScheme==='dark'){return colorScheme;}if(colorScheme==='system'){var _Appearance$getColorS;return (_Appearance$getColorS=Appearance.getColorScheme())!=null?_Appearance$getColorS:'light';}return 'light';};
2797
2797
 
@@ -3177,6 +3177,8 @@ function get(object, path, defaultValue) {
3177
3177
 
3178
3178
  var get_1 = get;
3179
3179
 
3180
+ var getMediaQuery=function getMediaQuery(_ref){var min=_ref.min,max=_ref.max;return "screen and (min-width: "+min+"px)"+(max?" and (max-width: "+max+"px)":'');};
3181
+
3180
3182
  var getPlatformType=function getPlatformType(){if(typeof navigator!=='undefined'&&navigator.product==='ReactNative'){return 'react-native';}if(typeof document!=='undefined'){return 'browser';}if(typeof process!=='undefined'){return 'node';}return 'unknown';};
3181
3183
 
3182
3184
  var baseKeys = _baseKeys,
@@ -4537,7 +4539,7 @@ var testID=function testID(defaultKey){return {testID:defaultKey};};
4537
4539
 
4538
4540
  var toTitleCase=function toTitleCase(inputString){return inputString.toLowerCase().split(' ').map(function(word){return word.charAt(0).toUpperCase()+word.slice(1);}).join(' ');};
4539
4541
 
4540
- var deviceType={desktop:'desktop',mobile:'mobile'};var useBreakpoint=function useBreakpoint(_ref){var _window;var breakpoints=_ref.breakpoints;var supportsMatchMedia=typeof document!=='undefined'&&typeof window!=='undefined'&&typeof((_window=window)==null?void 0:_window.matchMedia)==='function';var breakpointsTokenAndQueryCollection=useMemo(function(){return supportsMatchMedia?Object.entries(breakpoints).map(function(_ref2,index,breakpointsArray){var _ref3=_slicedToArray(_ref2,2),token=_ref3[0],screenSize=_ref3[1];var mediaQuery='';if(token==='max'){mediaQuery="screen and (min-width: "+screenSize+"px)";}else if(breakpointsArray[index-1]){mediaQuery="screen and (min-width: "+(breakpointsArray[index-1][1]+1)+"px) and (max-width: "+screenSize+"px)";}else {mediaQuery="screen and (max-width: "+screenSize+"px)";}return {token:token,screenSize:screenSize,mediaQuery:mediaQuery};}):[];},[breakpoints,supportsMatchMedia]);var getMatchedDeviceType=useCallback(function(matchedBreakpoint){var matchedDeviceType=deviceType.mobile;var platform=getPlatformType();if(platform==='react-native'){matchedDeviceType=deviceType.mobile;}else if(platform==='browser'){if(matchedBreakpoint&&['xs','s','m'].includes(matchedBreakpoint)){matchedDeviceType=deviceType.mobile;}else {matchedDeviceType=deviceType.desktop;}}else if(platform==='node'){matchedDeviceType=deviceType.desktop;}return matchedDeviceType;},[]);var getMatchedBreakpoint=useCallback(function(event){var _breakpointsTokenAndQ,_breakpointsTokenAndQ2;var matchedBreakpoint=(_breakpointsTokenAndQ=(_breakpointsTokenAndQ2=breakpointsTokenAndQueryCollection.find(function(_ref4){var _ref4$mediaQuery=_ref4.mediaQuery,mediaQuery=_ref4$mediaQuery===void 0?'':_ref4$mediaQuery;if((event==null?void 0:event.media)===mediaQuery){return true;}if(window.matchMedia(mediaQuery).matches){return true;}return false;}))==null?void 0:_breakpointsTokenAndQ2.token)!=null?_breakpointsTokenAndQ:undefined;return matchedBreakpoint;},[breakpointsTokenAndQueryCollection]);var _useState=useState(function(){var matchedBreakpoint=getMatchedBreakpoint();var matchedDeviceType=getMatchedDeviceType(matchedBreakpoint);return {matchedBreakpoint:matchedBreakpoint,matchedDeviceType:matchedDeviceType};}),_useState2=_slicedToArray(_useState,2),breakpointAndDevice=_useState2[0],setBreakpointAndDevice=_useState2[1];useEffect(function(){if(!supportsMatchMedia){return undefined;}var handleMediaQueryChange=function handleMediaQueryChange(event){setBreakpointAndDevice(function(){var matchedBreakpoint=getMatchedBreakpoint(event);var matchedDeviceType=getMatchedDeviceType(matchedBreakpoint);return {matchedBreakpoint:matchedBreakpoint,matchedDeviceType:matchedDeviceType};});};var mediaQueryInstances=breakpointsTokenAndQueryCollection.map(function(_ref5){var _ref5$mediaQuery=_ref5.mediaQuery,mediaQuery=_ref5$mediaQuery===void 0?'':_ref5$mediaQuery;var mediaQueryInstance=window.matchMedia(mediaQuery);if(mediaQueryInstance.addEventListener){mediaQueryInstance.addEventListener('change',handleMediaQueryChange);}else {mediaQueryInstance.addListener(handleMediaQueryChange);}return mediaQueryInstance;});return function(){mediaQueryInstances.forEach(function(mediaQueryInstance){if(mediaQueryInstance.removeEventListener){mediaQueryInstance.removeEventListener('change',handleMediaQueryChange);}else {mediaQueryInstance.removeListener(handleMediaQueryChange);}});};},[breakpointsTokenAndQueryCollection,getMatchedBreakpoint,getMatchedDeviceType,supportsMatchMedia]);return breakpointAndDevice;};
4542
+ var deviceType={desktop:'desktop',mobile:'mobile'};var useBreakpoint=function useBreakpoint(_ref){var _window;var breakpoints=_ref.breakpoints;var supportsMatchMedia=typeof document!=='undefined'&&typeof window!=='undefined'&&typeof((_window=window)==null?void 0:_window.matchMedia)==='function';var breakpointsTokenAndQueryCollection=useMemo(function(){return supportsMatchMedia?Object.entries(breakpoints).map(function(_ref2,index,breakpointsArray){var _breakpointsArray;var _ref3=_slicedToArray(_ref2,2),token=_ref3[0],screenSize=_ref3[1];var min=screenSize;var maxValue=(_breakpointsArray=breakpointsArray[index+1])==null?void 0:_breakpointsArray[1];var mediaQuery=getMediaQuery({min:min,max:maxValue?maxValue-1:undefined});return {token:token,screenSize:screenSize,mediaQuery:mediaQuery};}):[];},[breakpoints,supportsMatchMedia]);var getMatchedDeviceType=useCallback(function(matchedBreakpoint){var matchedDeviceType=deviceType.mobile;var platform=getPlatformType();if(platform==='react-native'){matchedDeviceType=deviceType.mobile;}else if(platform==='browser'){if(matchedBreakpoint&&['base','xs','s'].includes(matchedBreakpoint)){matchedDeviceType=deviceType.mobile;}else {matchedDeviceType=deviceType.desktop;}}else if(platform==='node'){matchedDeviceType=deviceType.desktop;}return matchedDeviceType;},[]);var getMatchedBreakpoint=useCallback(function(event){var _breakpointsTokenAndQ,_breakpointsTokenAndQ2;var matchedBreakpoint=(_breakpointsTokenAndQ=(_breakpointsTokenAndQ2=breakpointsTokenAndQueryCollection.find(function(_ref4){var _ref4$mediaQuery=_ref4.mediaQuery,mediaQuery=_ref4$mediaQuery===void 0?'':_ref4$mediaQuery;if((event==null?void 0:event.media)===mediaQuery){return true;}if(window.matchMedia(mediaQuery).matches){return true;}return false;}))==null?void 0:_breakpointsTokenAndQ2.token)!=null?_breakpointsTokenAndQ:undefined;return matchedBreakpoint;},[breakpointsTokenAndQueryCollection]);var _useState=useState(function(){var matchedBreakpoint=getMatchedBreakpoint();var matchedDeviceType=getMatchedDeviceType(matchedBreakpoint);return {matchedBreakpoint:matchedBreakpoint,matchedDeviceType:matchedDeviceType};}),_useState2=_slicedToArray(_useState,2),breakpointAndDevice=_useState2[0],setBreakpointAndDevice=_useState2[1];useEffect(function(){if(!supportsMatchMedia){return undefined;}var handleMediaQueryChange=function handleMediaQueryChange(event){setBreakpointAndDevice(function(){var matchedBreakpoint=getMatchedBreakpoint(event);var matchedDeviceType=getMatchedDeviceType(matchedBreakpoint);return {matchedBreakpoint:matchedBreakpoint,matchedDeviceType:matchedDeviceType};});};var mediaQueryInstances=breakpointsTokenAndQueryCollection.map(function(_ref5){var _ref5$mediaQuery=_ref5.mediaQuery,mediaQuery=_ref5$mediaQuery===void 0?'':_ref5$mediaQuery;var mediaQueryInstance=window.matchMedia(mediaQuery);if(mediaQueryInstance.addEventListener){mediaQueryInstance.addEventListener('change',handleMediaQueryChange);}else {mediaQueryInstance.addListener(handleMediaQueryChange);}return mediaQueryInstance;});return function(){mediaQueryInstances.forEach(function(mediaQueryInstance){if(mediaQueryInstance.removeEventListener){mediaQueryInstance.removeEventListener('change',handleMediaQueryChange);}else {mediaQueryInstance.removeListener(handleMediaQueryChange);}});};},[breakpointsTokenAndQueryCollection,getMatchedBreakpoint,getMatchedDeviceType,supportsMatchMedia]);return breakpointAndDevice;};
4541
4543
 
4542
4544
  var fontFamily={text:'Lato',code:Platform$1.OS==='ios'?'Courier':'monospace'};
4543
4545
 
@@ -4559,5 +4561,5 @@ var Platform;(function(_Platform){})(Platform||(Platform={}));
4559
4561
 
4560
4562
  var castWebType=function castWebType(value){return value;};var castNativeType=function castNativeType(value){return value;};
4561
4563
 
4562
- export { MetaConstants, Platform, castNativeType, castWebType, cloneDeep_1 as cloneDeep, getColorScheme, getComponentId, get_1 as getIn, getOS, getPlatformType, isAndroid, isEmpty_1 as isEmpty, isEqual_1 as isEqual, isPartialMatchObjectKeys, isReactNative, isValidAllowedChildren, makeAccessible, makeBezier, makeBorderSize, makeMotionTime, makeSize, makeSpace, makeTypographySize, merge_1 as merge, metaAttribute, setupMatchMediaMock, testID, toTitleCase, useBreakpoint, useColorScheme, usePrevious };
4564
+ export { MetaConstants, Platform, castNativeType, castWebType, cloneDeep_1 as cloneDeep, getColorScheme, getComponentId, get_1 as getIn, getMediaQuery, getOS, getPlatformType, isAndroid, isEmpty_1 as isEmpty, isEqual_1 as isEqual, isPartialMatchObjectKeys, isReactNative, isValidAllowedChildren, makeAccessible, makeBezier, makeBorderSize, makeMotionTime, makeSize, makeSpace, makeTypographySize, merge_1 as merge, metaAttribute, setupMatchMediaMock, testID, toTitleCase, useBreakpoint, useColorScheme, usePrevious };
4563
4565
  //# sourceMappingURL=index.native.js.map