@razorpay/blade 9.4.1 → 9.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.
- package/build/components/index.d.ts +19 -14
- package/build/components/{index.web.js → index.development.web.js} +215 -127
- package/build/components/index.development.web.js.map +1 -0
- package/build/components/index.native.d.ts +17 -12
- package/build/components/index.native.js +36 -36
- package/build/components/index.native.js.map +1 -1
- package/build/components/index.production.web.js +29819 -0
- package/build/components/index.production.web.js.map +1 -0
- package/build/css/bankingThemeDarkDesktop.css +1 -1
- package/build/css/bankingThemeDarkMobile.css +1 -1
- package/build/css/bankingThemeLightDesktop.css +1 -1
- package/build/css/bankingThemeLightMobile.css +1 -1
- package/build/css/paymentThemeDarkDesktop.css +1 -1
- package/build/css/paymentThemeDarkMobile.css +1 -1
- package/build/css/paymentThemeLightDesktop.css +1 -1
- package/build/css/paymentThemeLightMobile.css +1 -1
- package/build/tokens/{index.web.js → index.development.web.js} +21 -14
- package/build/tokens/index.development.web.js.map +1 -0
- package/build/tokens/index.native.js +2 -2
- package/build/tokens/index.native.js.map +1 -1
- package/build/tokens/index.production.web.js +8407 -0
- package/build/tokens/index.production.web.js.map +1 -0
- package/build/utils/index.d.ts +9 -5
- package/build/utils/{index.web.js → index.development.web.js} +12 -8
- package/build/utils/index.development.web.js.map +1 -0
- package/build/utils/index.native.d.ts +9 -5
- package/build/utils/index.native.js +2 -2
- package/build/utils/index.native.js.map +1 -1
- package/build/utils/index.production.web.js +322 -0
- package/build/utils/index.production.web.js.map +1 -0
- package/package.json +19 -11
- package/build/components/index.web.js.map +0 -1
- package/build/tokens/index.web.js.map +0 -1
- package/build/utils/index.web.js.map +0 -1
package/build/utils/index.d.ts
CHANGED
|
@@ -369,11 +369,15 @@ declare const ThemeContext = createContext<ThemeContext>({
|
|
|
369
369
|
|
|
370
370
|
declare const useTheme = (): ThemeContext => {
|
|
371
371
|
const themeContext = useContext<ThemeContext>(ThemeContext);
|
|
372
|
-
if (
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
372
|
+
if (__DEV__) {
|
|
373
|
+
if (!themeContext.theme) {
|
|
374
|
+
throw new Error(`[@razorpay/blade:BladeProvider]: BladeProvider is missing theme`);
|
|
375
|
+
}
|
|
376
|
+
if (themeContext === undefined) {
|
|
377
|
+
throw new Error(
|
|
378
|
+
`[@razorpay/blade:BladeProvider]: useTheme must be used within BladeProvider`,
|
|
379
|
+
);
|
|
380
|
+
}
|
|
377
381
|
}
|
|
378
382
|
return themeContext;
|
|
379
383
|
};
|
|
@@ -199,8 +199,10 @@ var useColorScheme = function useColorScheme() {
|
|
|
199
199
|
setColorSchemeState = _useState2[1];
|
|
200
200
|
|
|
201
201
|
var setColorScheme = useCallback(function setThemeMode(colorScheme) {
|
|
202
|
-
|
|
203
|
-
|
|
202
|
+
{
|
|
203
|
+
if (!colorSchemeNamesInput.includes(colorScheme)) {
|
|
204
|
+
throw new Error("[useColorScheme]: Expected color scheme to be one of [".concat(colorSchemeNamesInput.toString(), "] but received ").concat(colorScheme));
|
|
205
|
+
}
|
|
204
206
|
}
|
|
205
207
|
|
|
206
208
|
setColorSchemeState(getColorScheme(colorScheme));
|
|
@@ -327,16 +329,18 @@ var ThemeContext = /*#__PURE__*/createContext({
|
|
|
327
329
|
var useTheme = function useTheme() {
|
|
328
330
|
var themeContext = useContext(ThemeContext);
|
|
329
331
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
332
|
+
{
|
|
333
|
+
if (!themeContext.theme) {
|
|
334
|
+
throw new Error("[@razorpay/blade:BladeProvider]: BladeProvider is missing theme");
|
|
335
|
+
}
|
|
333
336
|
|
|
334
|
-
|
|
335
|
-
|
|
337
|
+
if (themeContext === undefined) {
|
|
338
|
+
throw new Error("[@razorpay/blade:BladeProvider]: useTheme must be used within BladeProvider");
|
|
339
|
+
}
|
|
336
340
|
}
|
|
337
341
|
|
|
338
342
|
return themeContext;
|
|
339
343
|
};
|
|
340
344
|
|
|
341
345
|
export { Platform, ThemeContext, castNativeType, castWebType, getColorScheme, getMediaQuery, getOS, getPlatformType, isAndroid, isReactNative, makeBorderSize, makeMotionTime, makeSize, makeSpace, makeTypographySize, toTitleCase, useBreakpoint, useColorScheme, usePrevious, useTheme };
|
|
342
|
-
//# sourceMappingURL=index.web.js.map
|
|
346
|
+
//# sourceMappingURL=index.development.web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.development.web.js","sources":["../../src/utils/getColorScheme/getColorScheme.web.ts","../../src/utils/getMediaQuery/getMediaQuery.ts","../../src/utils/getPlatformType/getPlatformType.ts","../../src/utils/useBreakpoint/useBreakpoint.ts","../../src/tokens/theme/theme.ts","../../src/utils/useColorScheme/useColorScheme.ts","../../src/utils/platform/isReactNative.ts","../../src/utils/platform/getOS.web.ts","../../src/utils/platform/platform.ts","../../src/utils/platform/castUtils.ts","../../src/utils/makeBorderSize/makeBorderSize.ts","../../src/utils/makeMotionTime/makeMotionTime.web.ts","../../src/utils/makeSpace/makeSpace.ts","../../src/utils/makeTypographySize/makeTypographySize.web.ts","../../src/utils/makeSize/makeSize.ts","../../src/utils/toTitleCase/toTitleCase.ts","../../src/utils/usePrevious/usePrevious.ts","../../src/components/BladeProvider/useTheme.ts"],"sourcesContent":["import type { ColorSchemeNames, ColorSchemeNamesInput } from '~tokens/theme';\n\nexport const getColorScheme = (colorScheme: ColorSchemeNamesInput = 'light'): ColorSchemeNames => {\n // @TODO: create a useMediaQuery hook with an event listener which will subscribe to changes and move all this logic there\n const colorSchemeMediaQueryMap = {\n light: '(prefers-color-scheme: light)',\n dark: '(prefers-color-scheme: dark)',\n system: 'default',\n };\n const supportsMatchMedia =\n typeof window !== 'undefined' && typeof window.matchMedia === 'function';\n\n if (colorScheme === 'light' || colorScheme === 'dark') {\n return colorScheme;\n }\n\n if (\n colorScheme === 'system' &&\n supportsMatchMedia &&\n window.matchMedia(colorSchemeMediaQueryMap.dark).matches\n ) {\n return 'dark';\n }\n\n return 'light';\n};\n","export const getMediaQuery = ({ min, max }: { min: number; max?: number }): string => {\n return `screen and (min-width: ${min}px)${max ? ` and (max-width: ${max}px)` : ''}`;\n};\n","export type PlatformTypes = 'browser' | 'node' | 'react-native' | 'unknown';\n\nexport const getPlatformType = (): PlatformTypes => {\n if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {\n return 'react-native';\n }\n\n if (typeof document !== 'undefined') {\n return 'browser';\n }\n\n if (typeof process !== 'undefined') {\n return 'node';\n }\n\n return 'unknown';\n};\n","/* eslint-disable @typescript-eslint/restrict-plus-operands */\nimport { useEffect, useState, useCallback, useMemo } from 'react';\nimport { getPlatformType } from '../getPlatformType';\nimport { getMediaQuery } from '../getMediaQuery';\nimport type { Breakpoints } from '~tokens/global';\n\nconst deviceType = {\n desktop: 'desktop',\n mobile: 'mobile',\n} as const;\n\ntype DeviceType = keyof typeof deviceType;\ntype Breakpoint = keyof Breakpoints | undefined;\n\ntype BreakpointAndDevice = {\n matchedBreakpoint: Breakpoint;\n matchedDeviceType: DeviceType;\n};\n\nexport const useBreakpoint = ({\n breakpoints,\n}: {\n breakpoints: Breakpoints;\n}): BreakpointAndDevice => {\n const supportsMatchMedia =\n typeof document !== 'undefined' &&\n typeof window !== 'undefined' &&\n typeof window?.matchMedia === 'function';\n\n const breakpointsTokenAndQueryCollection = useMemo(\n () =>\n (supportsMatchMedia\n ? Object.entries(breakpoints).map(([token, screenSize], index, breakpointsArray) => {\n const min = screenSize;\n const maxValue = breakpointsArray[index + 1]?.[1];\n const mediaQuery = getMediaQuery({ min, max: maxValue ? maxValue - 1 : undefined });\n return { token, screenSize, mediaQuery };\n })\n : []) as {\n token: keyof Breakpoints;\n screenSize: number;\n mediaQuery: string;\n }[],\n [breakpoints, supportsMatchMedia],\n );\n\n const getMatchedDeviceType = useCallback((matchedBreakpoint: Breakpoint): DeviceType => {\n let matchedDeviceType: DeviceType = deviceType.mobile;\n const platform = getPlatformType();\n if (platform === 'react-native') {\n matchedDeviceType = deviceType.mobile;\n } else if (platform === 'browser') {\n if (matchedBreakpoint && ['base', 'xs', 's'].includes(matchedBreakpoint)) {\n // tablet is also categorised as mobile\n matchedDeviceType = deviceType.mobile;\n } else {\n matchedDeviceType = deviceType.desktop;\n }\n } else if (platform === 'node') {\n //@TODO: Check for useragent for node\n matchedDeviceType = deviceType.desktop;\n }\n return matchedDeviceType;\n }, []);\n\n const getMatchedBreakpoint = useCallback(\n (event?: MediaQueryListEvent): Breakpoint => {\n const matchedBreakpoint =\n breakpointsTokenAndQueryCollection.find(({ mediaQuery = '' }) => {\n // this will run whenever mediaQuery change event is triggered\n if (event?.media === mediaQuery) {\n return true;\n }\n // this will run when the state is initialised for the first time and hence the event object will be empty so we'll fallback to browser's window object\n if (window.matchMedia(mediaQuery).matches) {\n return true;\n }\n return false;\n })?.token ?? undefined;\n\n return matchedBreakpoint;\n },\n [breakpointsTokenAndQueryCollection],\n );\n\n const [breakpointAndDevice, setBreakpointAndDevice] = useState(() => {\n const matchedBreakpoint = getMatchedBreakpoint();\n const matchedDeviceType = getMatchedDeviceType(matchedBreakpoint);\n return {\n matchedBreakpoint,\n matchedDeviceType,\n };\n });\n\n useEffect(() => {\n if (!supportsMatchMedia) {\n return undefined;\n }\n\n const handleMediaQueryChange = (event: MediaQueryListEvent): void => {\n setBreakpointAndDevice(() => {\n const matchedBreakpoint = getMatchedBreakpoint(event);\n const matchedDeviceType = getMatchedDeviceType(matchedBreakpoint);\n\n return { matchedBreakpoint, matchedDeviceType };\n });\n };\n\n const mediaQueryInstances = breakpointsTokenAndQueryCollection.map(({ mediaQuery = '' }) => {\n const mediaQueryInstance = window.matchMedia(mediaQuery);\n /**\n * the mediaquery event listener is available on mediaQuery instances and not `window`\n * we iterate over all the breakpoints we have, register each instance and store them as `mediaQueryInstances` so we can later unregister all of them.\n */\n if (mediaQueryInstance.addEventListener) {\n mediaQueryInstance.addEventListener('change', handleMediaQueryChange);\n } else {\n // In older browsers MediaQueryList do not yet inherit from EventTarget, So using addListener as fallback - https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList/addListener\n mediaQueryInstance.addListener(handleMediaQueryChange);\n }\n return mediaQueryInstance;\n });\n\n return (): void => {\n mediaQueryInstances.forEach((mediaQueryInstance) => {\n if (mediaQueryInstance.removeEventListener) {\n mediaQueryInstance.removeEventListener('change', handleMediaQueryChange);\n } else {\n // In older browsers MediaQueryList do not yet inherit from EventTarget, So using removeListener as fallback - https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList/removeListener\n mediaQueryInstance.removeListener(handleMediaQueryChange);\n }\n });\n };\n }, [\n breakpointsTokenAndQueryCollection,\n getMatchedBreakpoint,\n getMatchedDeviceType,\n supportsMatchMedia,\n ]);\n\n // @TODO: handle SSR scenarios\n return breakpointAndDevice;\n};\n","import type { StringWithAutocomplete } from '~utils/types';\nimport type {\n Border,\n Breakpoints,\n Motion,\n Spacing,\n TypographyWithPlatforms,\n ElevationWithColorModes,\n} from '~tokens/global';\n\nexport type ColorSchemeNames = 'dark' | 'light';\nexport type ColorSchemeNamesInput = ColorSchemeNames | 'system';\n\nexport type ColorSchemeModes = 'onDark' | 'onLight';\n\nexport type TextTypes = 'muted' | 'normal' | 'placeholder' | 'subdued' | 'subtle';\n\nexport type ColorContrastTypes = 'low' | 'high';\n\nexport type Feedback = 'information' | 'negative' | 'neutral' | 'notice' | 'positive';\n\nexport type ColorContrast = {\n [K in ColorContrastTypes as `${Extract<K, string>}Contrast`]: string;\n};\n\n// @TODO: this shall rather be Surface = 'level1' | 'level2' | 'level3' to keep in sync with color tokens\nexport type SurfaceLevels = 1 | 2 | 3;\n\nexport type ActionStates = {\n default: string;\n hover: string;\n focus: string;\n active: string;\n disabled: string;\n};\n\nexport type LinkActionStates = ActionStates & {\n visited: string;\n};\n\nexport type ActionStatesWithContrast = {\n default: ColorContrast;\n hover: ColorContrast;\n focus: ColorContrast;\n active: ColorContrast;\n disabled: ColorContrast;\n};\n\nexport type LinkActionStatesWithContrast = ActionStatesWithContrast & {\n visited: ColorContrast;\n};\n\nexport type ActionVariants = {\n primary: ActionStates;\n secondary: ActionStates;\n tertiary: ActionStates;\n link: LinkActionStates;\n};\n\nexport type ActionVariantsWithContrast = {\n primary: ActionStatesWithContrast;\n secondary: ActionStatesWithContrast;\n tertiary: ActionStatesWithContrast;\n link: ActionStatesWithContrast;\n};\n\n// export type ActionProperties = {\n// background: ActionVariants;\n// border: ActionVariants;\n// text: ActionVariants;\n// icon: ActionVariants;\n// };\n\nexport type FeedbackActions = {\n background: Pick<ActionVariantsWithContrast, 'primary'>;\n border: Pick<ActionVariantsWithContrast, 'primary'>;\n text: Pick<ActionVariantsWithContrast, 'link' | 'primary'>;\n icon: Pick<ActionVariantsWithContrast, 'link' | 'primary'>;\n};\n\nexport type Colors = {\n brand: {\n primary: Record<300 | 400 | 500 | 600 | 700 | 800, string>;\n secondary: Record<500, string>;\n gray: Record<200 | 300 | 400 | 500 | 600 | 700 | 'a50' | 'a100', ColorContrast>;\n };\n feedback: {\n background: Record<Feedback, ColorContrast>;\n border: Record<Feedback, ColorContrast>;\n text: Record<Feedback, ColorContrast>;\n icon: Record<Feedback, ColorContrast>;\n positive: {\n action: FeedbackActions;\n };\n negative: {\n action: FeedbackActions;\n };\n information: {\n action: FeedbackActions;\n };\n notice: {\n action: FeedbackActions;\n };\n neutral: {\n action: FeedbackActions;\n };\n };\n surface: {\n background: Record<'level1' | 'level2' | 'level3', ColorContrast>;\n border: Record<'normal' | 'subtle', ColorContrast>;\n text: Record<TextTypes, ColorContrast>;\n action: {\n icon: ActionStatesWithContrast;\n };\n };\n overlay: Record<'background', string>;\n action: {\n background: Omit<ActionVariants, 'link'>;\n border: Omit<ActionVariants, 'link'>;\n text: ActionVariants;\n icon: ActionVariants;\n };\n badge: {\n background: {\n blue: ColorContrast;\n };\n border: {\n blue: ColorContrast;\n };\n text: {\n blue: ColorContrast;\n };\n icon: {\n blue: ColorContrast;\n };\n };\n};\n\nexport type ColorsWithModes = Record<ColorSchemeModes, Colors>;\n\nexport type ThemeTokens = {\n name: 'paymentTheme' | 'bankingTheme' | StringWithAutocomplete; // Can be used to watch over state changes between theme without watching over entire theme object\n border: Border;\n breakpoints: Breakpoints;\n colors: ColorsWithModes;\n motion: Motion;\n elevation: ElevationWithColorModes;\n spacing: Spacing;\n typography: TypographyWithPlatforms;\n};\n\nexport type SpacingValues = `${Spacing[keyof Spacing]}px`;\nexport type BorderWidthValues = `${Border['width'][keyof Border['width']]}px`;\nexport type BorderRadiusValues =\n | `${Border['radius'][Exclude<keyof Border['radius'], 'round'>]}px`\n | `${Border['radius'][Extract<keyof Border['radius'], 'round'>]}`;\n\nexport const colorSchemeNamesInput: ColorSchemeNamesInput[] = ['light', 'dark', 'system'];\n","import { useState, useCallback } from 'react';\nimport { getColorScheme } from '../getColorScheme';\nimport { colorSchemeNamesInput } from '~tokens/theme/theme';\nimport type { ColorSchemeNames, ColorSchemeNamesInput } from '~tokens/theme';\n\nexport type UseColorScheme = {\n colorScheme: ColorSchemeNames;\n setColorScheme: (colorScheme: ColorSchemeNamesInput) => void;\n};\n\nexport const useColorScheme = (\n initialColorScheme: ColorSchemeNamesInput = 'light',\n): UseColorScheme => {\n // if colorScheme defined use that else fallback to 'light'\n const [colorSchemeState, setColorSchemeState] = useState<ColorSchemeNames>(() =>\n getColorScheme(initialColorScheme),\n );\n\n const setColorScheme = useCallback(function setThemeMode(colorScheme: ColorSchemeNamesInput) {\n if (__DEV__) {\n if (!colorSchemeNamesInput.includes(colorScheme)) {\n throw new Error(\n `[useColorScheme]: Expected color scheme to be one of [${colorSchemeNamesInput.toString()}] but received ${colorScheme}`,\n );\n }\n }\n setColorSchemeState(getColorScheme(colorScheme));\n }, []);\n\n return {\n colorScheme: colorSchemeState,\n setColorScheme,\n };\n};\n","/* eslint-disable @typescript-eslint/no-namespace */\nimport { getPlatformType } from '../getPlatformType';\n\nconst isReactNative = (): boolean => {\n return getPlatformType() === 'react-native';\n};\n\nexport { isReactNative };\n","import type { Platform } from 'react-native';\n\nexport const getOS = (): typeof Platform.OS => {\n return 'web';\n};\n\nexport const isAndroid = (): boolean => false;\n","/* eslint-disable @typescript-eslint/no-namespace */\nimport type { Brand, NativeOrWebBrand } from './types';\n\nnamespace Platform {\n export type Name = 'web';\n /**\n * Right now, the module resolution is set to resolve `.web` files,\n *\n * Thus Platform.Select<> type will return the `web` type\n */\n export type Select<Options extends { web: unknown; native: unknown }> = Brand<\n Options[Name],\n 'platform-web'\n >;\n\n export type CastNative<T extends NativeOrWebBrand | undefined> = Extract<\n T,\n { __brand__?: 'platform-native' | 'platform-all' }\n >;\n\n export type CastWeb<T extends NativeOrWebBrand | undefined> = Extract<\n T,\n { __brand__?: 'platform-web' | 'platform-all' }\n >;\n}\n\nexport { Platform };\n","import type { Platform } from '.';\n\n/**\n * @description\n *\n * Casts a Platform.Select<> type to web type\n *\n * @example\n *\n * ```ts\n * type Example = Platform.Select<{ web: string; native: number }>;\n *\n * const extractedWebType = castWebType('' as Example);\n * // ^ string\n * ```\n */\nconst castWebType = <T>(value: T): Platform.CastWeb<T> => {\n return value as Platform.CastWeb<typeof value>;\n};\n\n/**\n * @description\n *\n * Casts a Platform.Select<> type to native type\n *\n * @example\n *\n * ```ts\n * type Example = Platform.Select<{ web: string; native: number }>;\n *\n * const extractedNativeType = castNativeType('' as Example);\n * // ^ number\n * ```\n */\nconst castNativeType = <T>(value: T): Platform.CastNative<T> => {\n return value as Platform.CastNative<typeof value>;\n};\n\nexport { castWebType, castNativeType };\n","export function makeBorderSize<T extends number>(size: T): `${T}px`;\nexport function makeBorderSize<T extends string>(size: T): T;\nexport function makeBorderSize<T extends number | string>(size: T): `${T}px` | T {\n if (typeof size === 'number') {\n return `${size}px`;\n }\n return size;\n}\n","import type { MakeMotionTime } from './types';\nimport type { Platform } from '~utils';\n\nexport const makeMotionTime = <T extends number>(time: T): Platform.CastWeb<MakeMotionTime<T>> => {\n return `${time}ms`;\n};\n","export const makeSpace = <T extends number>(size: T): `${T}px` => {\n return `${size}px`;\n};\n","export const makeTypographySize = (size: number): `${number}rem` => {\n const remValue = size / 16;\n return `${remValue}rem`;\n};\n","export type MakeSize<T extends number> = `${T}px`;\n\nexport const makeSize = <T extends number>(size: T): `${T}px` => {\n return `${size}px`;\n};\n","/**\n * @deprecated This utility will be deprecated in subsequent version.\n */\nexport const toTitleCase = (inputString: string): string =>\n inputString\n .toLowerCase()\n .split(' ')\n .map((word) => word.charAt(0).toUpperCase() + word.slice(1))\n .join(' ');\n","import type { MutableRefObject } from 'react';\nimport { useEffect, useRef } from 'react';\n\n/**\n * a type-safe version of the `usePrevious` hook described here:\n * @see {@link https://reactjs.org/docs/hooks-faq.html#how-to-get-the-previous-props-or-state}\n * @deprecated This utility will be deprecated in subsequent version.\n */\nexport function usePrevious<T>(value: T): MutableRefObject<T | undefined>['current'] {\n const ref = useRef<T>();\n\n useEffect(() => {\n ref.current = value;\n }, [value]);\n\n return ref.current;\n}\n","import { useContext, createContext } from 'react';\nimport type { UseColorScheme } from '../../utils/useColorScheme';\nimport type { Theme } from './';\nimport type { TypographyPlatforms } from '~tokens/global';\n\nexport type ThemeContext = UseColorScheme & {\n theme: Theme;\n platform: TypographyPlatforms;\n};\n\nexport const ThemeContext = createContext<ThemeContext>({\n // @ts-expect-error set null\n theme: null,\n colorScheme: 'light',\n platform: 'onDesktop',\n setColorScheme: () => null,\n});\n\nconst useTheme = (): ThemeContext => {\n const themeContext = useContext<ThemeContext>(ThemeContext);\n if (__DEV__) {\n if (!themeContext.theme) {\n throw new Error(`[@razorpay/blade:BladeProvider]: BladeProvider is missing theme`);\n }\n if (themeContext === undefined) {\n throw new Error(\n `[@razorpay/blade:BladeProvider]: useTheme must be used within BladeProvider`,\n );\n }\n }\n return themeContext;\n};\n\nexport default useTheme;\n"],"names":["getColorScheme","colorScheme","colorSchemeMediaQueryMap","light","dark","system","supportsMatchMedia","window","matchMedia","matches","getMediaQuery","min","max","getPlatformType","navigator","product","document","process","deviceType","desktop","mobile","useBreakpoint","breakpoints","breakpointsTokenAndQueryCollection","useMemo","Object","entries","map","index","breakpointsArray","token","screenSize","maxValue","mediaQuery","undefined","getMatchedDeviceType","useCallback","matchedBreakpoint","matchedDeviceType","platform","includes","getMatchedBreakpoint","event","find","media","useState","breakpointAndDevice","setBreakpointAndDevice","useEffect","handleMediaQueryChange","mediaQueryInstances","mediaQueryInstance","addEventListener","addListener","forEach","removeEventListener","removeListener","colorSchemeNamesInput","useColorScheme","initialColorScheme","colorSchemeState","setColorSchemeState","setColorScheme","setThemeMode","Error","toString","isReactNative","getOS","isAndroid","Platform","castWebType","value","castNativeType","makeBorderSize","size","makeMotionTime","time","makeSpace","makeTypographySize","remValue","makeSize","toTitleCase","inputString","toLowerCase","split","word","charAt","toUpperCase","slice","join","usePrevious","ref","useRef","current","ThemeContext","createContext","theme","useTheme","themeContext","useContext"],"mappings":";;;IAEaA,cAAc,GAAG,SAAjBA,cAAiB,GAAoE;AAAA,MAAnEC,WAAmE,uEAA9B,OAA8B;AAChG;AACA,MAAMC,wBAAwB,GAAG;AAC/BC,IAAAA,KAAK,EAAE,+BADwB;AAE/BC,IAAAA,IAAI,EAAE,8BAFyB;AAG/BC,IAAAA,MAAM,EAAE;AAHuB,GAAjC;AAKA,MAAMC,kBAAkB,GACtB,OAAOC,MAAP,KAAkB,WAAlB,IAAiC,OAAOA,MAAM,CAACC,UAAd,KAA6B,UADhE;;AAGA,MAAIP,WAAW,KAAK,OAAhB,IAA2BA,WAAW,KAAK,MAA/C,EAAuD;AACrD,WAAOA,WAAP;AACD;;AAED,MACEA,WAAW,KAAK,QAAhB,IACAK,kBADA,IAEAC,MAAM,CAACC,UAAP,CAAkBN,wBAAwB,CAACE,IAA3C,EAAiDK,OAHnD,EAIE;AACA,WAAO,MAAP;AACD;;AAED,SAAO,OAAP;AACD;;ICzBYC,aAAa,GAAG,SAAhBA,aAAgB,OAAyD;AAAA,MAAtDC,GAAsD,QAAtDA,GAAsD;AAAA,MAAjDC,GAA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B,EAAyC;AAC/D,mBAAUA,IAAV;AACD;;ACJD;AACA;AACA;IACaO,WAAW,GAAG,SAAdA,WAAc,CAACC,WAAD;AAAA,SACzBA,WAAW,CACRC,WADH,GAEGC,KAFH,CAES,GAFT,EAGGzD,GAHH,CAGO,UAAC0D,IAAD;AAAA,WAAUA,IAAI,CAACC,MAAL,CAAY,CAAZ,EAAeC,WAAf,KAA+BF,IAAI,CAACG,KAAL,CAAW,CAAX,CAAzC;AAAA,GAHP,EAIGC,IAJH,CAIQ,GAJR,CADyB;AAAA;;ACA3B;AACA;AACA;AACA;AACA;;AACO,SAASC,WAAT,CAAwBnB,KAAxB,EAA8E;AACnF,MAAMoB,GAAG,GAAGC,MAAM,EAAlB;AAEA5C,EAAAA,SAAS,CAAC,YAAM;AACd2C,IAAAA,GAAG,CAACE,OAAJ,GAActB,KAAd;AACD,GAFQ,EAEN,CAACA,KAAD,CAFM,CAAT;AAIA,SAAOoB,GAAG,CAACE,OAAX;AACD;;ICNYC,YAAY,gBAAGC,aAAa,CAAe;AACtD;AACAC,EAAAA,KAAK,EAAE,IAF+C;AAGtD/F,EAAAA,WAAW,EAAE,OAHyC;AAItDsC,EAAAA,QAAQ,EAAE,WAJ4C;AAKtDuB,EAAAA,cAAc,EAAE;AAAA,WAAM,IAAN;AAAA;AALsC,CAAf;;IAQnCmC,QAAQ,GAAG,SAAXA,QAAW,GAAoB;AACnC,MAAMC,YAAY,GAAGC,UAAU,CAAeL,YAAf,CAA/B;;AACA,EAAa;AACX,QAAI,CAACI,YAAY,CAACF,KAAlB,EAAyB;AACvB,YAAM,IAAIhC,KAAJ,mEAAN;AACD;;AACD,QAAIkC,YAAY,KAAKhE,SAArB,EAAgC;AAC9B,YAAM,IAAI8B,KAAJ,+EAAN;AAGD;AACF;;AACD,SAAOkC,YAAP;AACD;;;;"}
|
|
@@ -369,11 +369,15 @@ declare const ThemeContext = createContext<ThemeContext>({
|
|
|
369
369
|
|
|
370
370
|
declare const useTheme = (): ThemeContext => {
|
|
371
371
|
const themeContext = useContext<ThemeContext>(ThemeContext);
|
|
372
|
-
if (
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
372
|
+
if (__DEV__) {
|
|
373
|
+
if (!themeContext.theme) {
|
|
374
|
+
throw new Error(`[@razorpay/blade:BladeProvider]: BladeProvider is missing theme`);
|
|
375
|
+
}
|
|
376
|
+
if (themeContext === undefined) {
|
|
377
|
+
throw new Error(
|
|
378
|
+
`[@razorpay/blade:BladeProvider]: useTheme must be used within BladeProvider`,
|
|
379
|
+
);
|
|
380
|
+
}
|
|
377
381
|
}
|
|
378
382
|
return themeContext;
|
|
379
383
|
};
|
|
@@ -12,7 +12,7 @@ var deviceType={desktop:'desktop',mobile:'mobile'};var useBreakpoint=function us
|
|
|
12
12
|
|
|
13
13
|
var colorSchemeNamesInput=['light','dark','system'];
|
|
14
14
|
|
|
15
|
-
var useColorScheme=function useColorScheme(){var initialColorScheme=arguments.length>0&&arguments[0]!==undefined?arguments[0]:'light';var _useState=useState(function(){return getColorScheme(initialColorScheme);}),_useState2=_slicedToArray(_useState,2),colorSchemeState=_useState2[0],setColorSchemeState=_useState2[1];var setColorScheme=useCallback(function setThemeMode(colorScheme){if(!colorSchemeNamesInput.includes(colorScheme)){throw new Error("[useColorScheme]: Expected color scheme to be one of ["+colorSchemeNamesInput.toString()+"] but received "+colorScheme);}setColorSchemeState(getColorScheme(colorScheme));},[]);return {colorScheme:colorSchemeState,setColorScheme:setColorScheme};};
|
|
15
|
+
var useColorScheme=function useColorScheme(){var initialColorScheme=arguments.length>0&&arguments[0]!==undefined?arguments[0]:'light';var _useState=useState(function(){return getColorScheme(initialColorScheme);}),_useState2=_slicedToArray(_useState,2),colorSchemeState=_useState2[0],setColorSchemeState=_useState2[1];var setColorScheme=useCallback(function setThemeMode(colorScheme){if(__DEV__){if(!colorSchemeNamesInput.includes(colorScheme)){throw new Error("[useColorScheme]: Expected color scheme to be one of ["+colorSchemeNamesInput.toString()+"] but received "+colorScheme);}}setColorSchemeState(getColorScheme(colorScheme));},[]);return {colorScheme:colorSchemeState,setColorScheme:setColorScheme};};
|
|
16
16
|
|
|
17
17
|
var isReactNative=function isReactNative(){return getPlatformType()==='react-native';};
|
|
18
18
|
|
|
@@ -36,7 +36,7 @@ var toTitleCase=function toTitleCase(inputString){return inputString.toLowerCase
|
|
|
36
36
|
|
|
37
37
|
function usePrevious(value){var ref=useRef();useEffect(function(){ref.current=value;},[value]);return ref.current;}
|
|
38
38
|
|
|
39
|
-
var ThemeContext=createContext({theme:null,colorScheme:'light',platform:'onDesktop',setColorScheme:function setColorScheme(){return null;}});var useTheme=function useTheme(){var themeContext=useContext(ThemeContext);if(!themeContext.theme){throw new Error("[@razorpay/blade:BladeProvider]: BladeProvider is missing theme");}if(themeContext===undefined){throw new Error("[@razorpay/blade:BladeProvider]: useTheme must be used within BladeProvider");}return themeContext;};
|
|
39
|
+
var ThemeContext=createContext({theme:null,colorScheme:'light',platform:'onDesktop',setColorScheme:function setColorScheme(){return null;}});var useTheme=function useTheme(){var themeContext=useContext(ThemeContext);if(__DEV__){if(!themeContext.theme){throw new Error("[@razorpay/blade:BladeProvider]: BladeProvider is missing theme");}if(themeContext===undefined){throw new Error("[@razorpay/blade:BladeProvider]: useTheme must be used within BladeProvider");}}return themeContext;};
|
|
40
40
|
|
|
41
41
|
export { Platform, ThemeContext, castNativeType, castWebType, getColorScheme, getMediaQuery, getOS, getPlatformType, isAndroid, isReactNative, makeBorderSize, makeMotionTime, makeSize, makeSpace, makeTypographySize, toTitleCase, useBreakpoint, useColorScheme, usePrevious, useTheme };
|
|
42
42
|
//# sourceMappingURL=index.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.native.js","sources":["../../src/utils/getColorScheme/getColorScheme.native.ts","../../src/utils/getMediaQuery/getMediaQuery.ts","../../src/utils/getPlatformType/getPlatformType.ts","../../src/utils/useBreakpoint/useBreakpoint.ts","../../src/tokens/theme/theme.ts","../../src/utils/useColorScheme/useColorScheme.ts","../../src/utils/platform/isReactNative.ts","../../src/utils/platform/getOS.native.ts","../../src/utils/platform/platform.native.ts","../../src/utils/platform/castUtils.ts","../../src/utils/makeBorderSize/makeBorderSize.ts","../../src/utils/makeMotionTime/makeMotionTime.native.ts","../../src/utils/makeSpace/makeSpace.ts","../../src/utils/makeTypographySize/makeTypographySize.native.ts","../../src/utils/makeSize/makeSize.ts","../../src/utils/toTitleCase/toTitleCase.ts","../../src/utils/usePrevious/usePrevious.ts","../../src/components/BladeProvider/useTheme.ts"],"sourcesContent":["import { Appearance } from 'react-native';\nimport type { ColorSchemeNames, ColorSchemeNamesInput } from '~tokens/theme';\n\nexport const getColorScheme = (colorScheme: ColorSchemeNamesInput = 'light'): ColorSchemeNames => {\n // @TODO: convert this to hook as Appearance API also adds an eventListener which subscribes to the colorscheme changes on the device\n if (colorScheme === 'light' || colorScheme === 'dark') {\n return colorScheme;\n }\n\n if (colorScheme === 'system') {\n return Appearance.getColorScheme() ?? 'light';\n }\n\n return 'light';\n};\n","export const getMediaQuery = ({ min, max }: { min: number; max?: number }): string => {\n return `screen and (min-width: ${min}px)${max ? ` and (max-width: ${max}px)` : ''}`;\n};\n","export type PlatformTypes = 'browser' | 'node' | 'react-native' | 'unknown';\n\nexport const getPlatformType = (): PlatformTypes => {\n if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {\n return 'react-native';\n }\n\n if (typeof document !== 'undefined') {\n return 'browser';\n }\n\n if (typeof process !== 'undefined') {\n return 'node';\n }\n\n return 'unknown';\n};\n","/* eslint-disable @typescript-eslint/restrict-plus-operands */\nimport { useEffect, useState, useCallback, useMemo } from 'react';\nimport { getPlatformType } from '../getPlatformType';\nimport { getMediaQuery } from '../getMediaQuery';\nimport type { Breakpoints } from '~tokens/global';\n\nconst deviceType = {\n desktop: 'desktop',\n mobile: 'mobile',\n} as const;\n\ntype DeviceType = keyof typeof deviceType;\ntype Breakpoint = keyof Breakpoints | undefined;\n\ntype BreakpointAndDevice = {\n matchedBreakpoint: Breakpoint;\n matchedDeviceType: DeviceType;\n};\n\nexport const useBreakpoint = ({\n breakpoints,\n}: {\n breakpoints: Breakpoints;\n}): BreakpointAndDevice => {\n const supportsMatchMedia =\n typeof document !== 'undefined' &&\n typeof window !== 'undefined' &&\n typeof window?.matchMedia === 'function';\n\n const breakpointsTokenAndQueryCollection = useMemo(\n () =>\n (supportsMatchMedia\n ? Object.entries(breakpoints).map(([token, screenSize], index, breakpointsArray) => {\n const min = screenSize;\n const maxValue = breakpointsArray[index + 1]?.[1];\n const mediaQuery = getMediaQuery({ min, max: maxValue ? maxValue - 1 : undefined });\n return { token, screenSize, mediaQuery };\n })\n : []) as {\n token: keyof Breakpoints;\n screenSize: number;\n mediaQuery: string;\n }[],\n [breakpoints, supportsMatchMedia],\n );\n\n const getMatchedDeviceType = useCallback((matchedBreakpoint: Breakpoint): DeviceType => {\n let matchedDeviceType: DeviceType = deviceType.mobile;\n const platform = getPlatformType();\n if (platform === 'react-native') {\n matchedDeviceType = deviceType.mobile;\n } else if (platform === 'browser') {\n if (matchedBreakpoint && ['base', 'xs', 's'].includes(matchedBreakpoint)) {\n // tablet is also categorised as mobile\n matchedDeviceType = deviceType.mobile;\n } else {\n matchedDeviceType = deviceType.desktop;\n }\n } else if (platform === 'node') {\n //@TODO: Check for useragent for node\n matchedDeviceType = deviceType.desktop;\n }\n return matchedDeviceType;\n }, []);\n\n const getMatchedBreakpoint = useCallback(\n (event?: MediaQueryListEvent): Breakpoint => {\n const matchedBreakpoint =\n breakpointsTokenAndQueryCollection.find(({ mediaQuery = '' }) => {\n // this will run whenever mediaQuery change event is triggered\n if (event?.media === mediaQuery) {\n return true;\n }\n // this will run when the state is initialised for the first time and hence the event object will be empty so we'll fallback to browser's window object\n if (window.matchMedia(mediaQuery).matches) {\n return true;\n }\n return false;\n })?.token ?? undefined;\n\n return matchedBreakpoint;\n },\n [breakpointsTokenAndQueryCollection],\n );\n\n const [breakpointAndDevice, setBreakpointAndDevice] = useState(() => {\n const matchedBreakpoint = getMatchedBreakpoint();\n const matchedDeviceType = getMatchedDeviceType(matchedBreakpoint);\n return {\n matchedBreakpoint,\n matchedDeviceType,\n };\n });\n\n useEffect(() => {\n if (!supportsMatchMedia) {\n return undefined;\n }\n\n const handleMediaQueryChange = (event: MediaQueryListEvent): void => {\n setBreakpointAndDevice(() => {\n const matchedBreakpoint = getMatchedBreakpoint(event);\n const matchedDeviceType = getMatchedDeviceType(matchedBreakpoint);\n\n return { matchedBreakpoint, matchedDeviceType };\n });\n };\n\n const mediaQueryInstances = breakpointsTokenAndQueryCollection.map(({ mediaQuery = '' }) => {\n const mediaQueryInstance = window.matchMedia(mediaQuery);\n /**\n * the mediaquery event listener is available on mediaQuery instances and not `window`\n * we iterate over all the breakpoints we have, register each instance and store them as `mediaQueryInstances` so we can later unregister all of them.\n */\n if (mediaQueryInstance.addEventListener) {\n mediaQueryInstance.addEventListener('change', handleMediaQueryChange);\n } else {\n // In older browsers MediaQueryList do not yet inherit from EventTarget, So using addListener as fallback - https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList/addListener\n mediaQueryInstance.addListener(handleMediaQueryChange);\n }\n return mediaQueryInstance;\n });\n\n return (): void => {\n mediaQueryInstances.forEach((mediaQueryInstance) => {\n if (mediaQueryInstance.removeEventListener) {\n mediaQueryInstance.removeEventListener('change', handleMediaQueryChange);\n } else {\n // In older browsers MediaQueryList do not yet inherit from EventTarget, So using removeListener as fallback - https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList/removeListener\n mediaQueryInstance.removeListener(handleMediaQueryChange);\n }\n });\n };\n }, [\n breakpointsTokenAndQueryCollection,\n getMatchedBreakpoint,\n getMatchedDeviceType,\n supportsMatchMedia,\n ]);\n\n // @TODO: handle SSR scenarios\n return breakpointAndDevice;\n};\n","import type { StringWithAutocomplete } from '~utils/types';\nimport type {\n Border,\n Breakpoints,\n Motion,\n Spacing,\n TypographyWithPlatforms,\n ElevationWithColorModes,\n} from '~tokens/global';\n\nexport type ColorSchemeNames = 'dark' | 'light';\nexport type ColorSchemeNamesInput = ColorSchemeNames | 'system';\n\nexport type ColorSchemeModes = 'onDark' | 'onLight';\n\nexport type TextTypes = 'muted' | 'normal' | 'placeholder' | 'subdued' | 'subtle';\n\nexport type ColorContrastTypes = 'low' | 'high';\n\nexport type Feedback = 'information' | 'negative' | 'neutral' | 'notice' | 'positive';\n\nexport type ColorContrast = {\n [K in ColorContrastTypes as `${Extract<K, string>}Contrast`]: string;\n};\n\n// @TODO: this shall rather be Surface = 'level1' | 'level2' | 'level3' to keep in sync with color tokens\nexport type SurfaceLevels = 1 | 2 | 3;\n\nexport type ActionStates = {\n default: string;\n hover: string;\n focus: string;\n active: string;\n disabled: string;\n};\n\nexport type LinkActionStates = ActionStates & {\n visited: string;\n};\n\nexport type ActionStatesWithContrast = {\n default: ColorContrast;\n hover: ColorContrast;\n focus: ColorContrast;\n active: ColorContrast;\n disabled: ColorContrast;\n};\n\nexport type LinkActionStatesWithContrast = ActionStatesWithContrast & {\n visited: ColorContrast;\n};\n\nexport type ActionVariants = {\n primary: ActionStates;\n secondary: ActionStates;\n tertiary: ActionStates;\n link: LinkActionStates;\n};\n\nexport type ActionVariantsWithContrast = {\n primary: ActionStatesWithContrast;\n secondary: ActionStatesWithContrast;\n tertiary: ActionStatesWithContrast;\n link: ActionStatesWithContrast;\n};\n\n// export type ActionProperties = {\n// background: ActionVariants;\n// border: ActionVariants;\n// text: ActionVariants;\n// icon: ActionVariants;\n// };\n\nexport type FeedbackActions = {\n background: Pick<ActionVariantsWithContrast, 'primary'>;\n border: Pick<ActionVariantsWithContrast, 'primary'>;\n text: Pick<ActionVariantsWithContrast, 'link' | 'primary'>;\n icon: Pick<ActionVariantsWithContrast, 'link' | 'primary'>;\n};\n\nexport type Colors = {\n brand: {\n primary: Record<300 | 400 | 500 | 600 | 700 | 800, string>;\n secondary: Record<500, string>;\n gray: Record<200 | 300 | 400 | 500 | 600 | 700 | 'a50' | 'a100', ColorContrast>;\n };\n feedback: {\n background: Record<Feedback, ColorContrast>;\n border: Record<Feedback, ColorContrast>;\n text: Record<Feedback, ColorContrast>;\n icon: Record<Feedback, ColorContrast>;\n positive: {\n action: FeedbackActions;\n };\n negative: {\n action: FeedbackActions;\n };\n information: {\n action: FeedbackActions;\n };\n notice: {\n action: FeedbackActions;\n };\n neutral: {\n action: FeedbackActions;\n };\n };\n surface: {\n background: Record<'level1' | 'level2' | 'level3', ColorContrast>;\n border: Record<'normal' | 'subtle', ColorContrast>;\n text: Record<TextTypes, ColorContrast>;\n action: {\n icon: ActionStatesWithContrast;\n };\n };\n overlay: Record<'background', string>;\n action: {\n background: Omit<ActionVariants, 'link'>;\n border: Omit<ActionVariants, 'link'>;\n text: ActionVariants;\n icon: ActionVariants;\n };\n badge: {\n background: {\n blue: ColorContrast;\n };\n border: {\n blue: ColorContrast;\n };\n text: {\n blue: ColorContrast;\n };\n icon: {\n blue: ColorContrast;\n };\n };\n};\n\nexport type ColorsWithModes = Record<ColorSchemeModes, Colors>;\n\nexport type ThemeTokens = {\n name: 'paymentTheme' | 'bankingTheme' | StringWithAutocomplete; // Can be used to watch over state changes between theme without watching over entire theme object\n border: Border;\n breakpoints: Breakpoints;\n colors: ColorsWithModes;\n motion: Motion;\n elevation: ElevationWithColorModes;\n spacing: Spacing;\n typography: TypographyWithPlatforms;\n};\n\nexport type SpacingValues = `${Spacing[keyof Spacing]}px`;\nexport type BorderWidthValues = `${Border['width'][keyof Border['width']]}px`;\nexport type BorderRadiusValues =\n | `${Border['radius'][Exclude<keyof Border['radius'], 'round'>]}px`\n | `${Border['radius'][Extract<keyof Border['radius'], 'round'>]}`;\n\nexport const colorSchemeNamesInput: ColorSchemeNamesInput[] = ['light', 'dark', 'system'];\n","import { useState, useCallback } from 'react';\nimport { getColorScheme } from '../getColorScheme';\nimport { colorSchemeNamesInput } from '~tokens/theme/theme';\nimport type { ColorSchemeNames, ColorSchemeNamesInput } from '~tokens/theme';\n\nexport type UseColorScheme = {\n colorScheme: ColorSchemeNames;\n setColorScheme: (colorScheme: ColorSchemeNamesInput) => void;\n};\n\nexport const useColorScheme = (\n initialColorScheme: ColorSchemeNamesInput = 'light',\n): UseColorScheme => {\n // if colorScheme defined use that else fallback to 'light'\n const [colorSchemeState, setColorSchemeState] = useState<ColorSchemeNames>(() =>\n getColorScheme(initialColorScheme),\n );\n\n const setColorScheme = useCallback(function setThemeMode(colorScheme: ColorSchemeNamesInput) {\n if (!colorSchemeNamesInput.includes(colorScheme)) {\n throw new Error(\n `[useColorScheme]: Expected color scheme to be one of [${colorSchemeNamesInput.toString()}] but received ${colorScheme}`,\n );\n }\n setColorSchemeState(getColorScheme(colorScheme));\n }, []);\n\n return {\n colorScheme: colorSchemeState,\n setColorScheme,\n };\n};\n","/* eslint-disable @typescript-eslint/no-namespace */\nimport { getPlatformType } from '../getPlatformType';\n\nconst isReactNative = (): boolean => {\n return getPlatformType() === 'react-native';\n};\n\nexport { isReactNative };\n","import { Platform } from 'react-native';\n\nexport const getOS = (): typeof Platform.OS => {\n return Platform.OS;\n};\n\nexport const isAndroid = (): boolean => getOS() === 'android';\n","/* eslint-disable @typescript-eslint/no-namespace */\nimport type { Brand, NativeOrWebBrand } from './types';\n\nnamespace Platform {\n export type Name = 'native';\n /**\n * Right now, the module resolution is set to resolve `.native` files,\n *\n * Thus Platform.Select<> type will return the `native` type\n */\n export type Select<Options extends { web: unknown; native: unknown }> = Brand<\n Options[Name],\n 'platform-native'\n >;\n\n export type CastNative<T extends NativeOrWebBrand | undefined> = Extract<\n T,\n { __brand__?: 'platform-native' | 'platform-all' }\n >;\n\n export type CastWeb<T extends NativeOrWebBrand | undefined> = Extract<\n T,\n { __brand__?: 'platform-web' | 'platform-all' }\n >;\n}\n\nexport { Platform };\n","import type { Platform } from '.';\n\n/**\n * @description\n *\n * Casts a Platform.Select<> type to web type\n *\n * @example\n *\n * ```ts\n * type Example = Platform.Select<{ web: string; native: number }>;\n *\n * const extractedWebType = castWebType('' as Example);\n * // ^ string\n * ```\n */\nconst castWebType = <T>(value: T): Platform.CastWeb<T> => {\n return value as Platform.CastWeb<typeof value>;\n};\n\n/**\n * @description\n *\n * Casts a Platform.Select<> type to native type\n *\n * @example\n *\n * ```ts\n * type Example = Platform.Select<{ web: string; native: number }>;\n *\n * const extractedNativeType = castNativeType('' as Example);\n * // ^ number\n * ```\n */\nconst castNativeType = <T>(value: T): Platform.CastNative<T> => {\n return value as Platform.CastNative<typeof value>;\n};\n\nexport { castWebType, castNativeType };\n","export function makeBorderSize<T extends number>(size: T): `${T}px`;\nexport function makeBorderSize<T extends string>(size: T): T;\nexport function makeBorderSize<T extends number | string>(size: T): `${T}px` | T {\n if (typeof size === 'number') {\n return `${size}px`;\n }\n return size;\n}\n","import type { MakeMotionTime } from './types';\nimport type { Platform } from '~utils';\n\nexport const makeMotionTime = <T extends number>(\n time: T,\n): Platform.CastNative<MakeMotionTime<T>> => {\n return time;\n};\n","export const makeSpace = <T extends number>(size: T): `${T}px` => {\n return `${size}px`;\n};\n","export const makeTypographySize = <T extends number>(size: T): `${T}px` => {\n return `${size}px`;\n};\n","export type MakeSize<T extends number> = `${T}px`;\n\nexport const makeSize = <T extends number>(size: T): `${T}px` => {\n return `${size}px`;\n};\n","/**\n * @deprecated This utility will be deprecated in subsequent version.\n */\nexport const toTitleCase = (inputString: string): string =>\n inputString\n .toLowerCase()\n .split(' ')\n .map((word) => word.charAt(0).toUpperCase() + word.slice(1))\n .join(' ');\n","import type { MutableRefObject } from 'react';\nimport { useEffect, useRef } from 'react';\n\n/**\n * a type-safe version of the `usePrevious` hook described here:\n * @see {@link https://reactjs.org/docs/hooks-faq.html#how-to-get-the-previous-props-or-state}\n * @deprecated This utility will be deprecated in subsequent version.\n */\nexport function usePrevious<T>(value: T): MutableRefObject<T | undefined>['current'] {\n const ref = useRef<T>();\n\n useEffect(() => {\n ref.current = value;\n }, [value]);\n\n return ref.current;\n}\n","import { useContext, createContext } from 'react';\nimport type { UseColorScheme } from '../../utils/useColorScheme';\nimport type { Theme } from './';\nimport type { TypographyPlatforms } from '~tokens/global';\n\nexport type ThemeContext = UseColorScheme & {\n theme: Theme;\n platform: TypographyPlatforms;\n};\n\nexport const ThemeContext = createContext<ThemeContext>({\n // @ts-expect-error set null\n theme: null,\n colorScheme: 'light',\n platform: 'onDesktop',\n setColorScheme: () => null,\n});\n\nconst useTheme = (): ThemeContext => {\n const themeContext = useContext<ThemeContext>(ThemeContext);\n if (!themeContext.theme) {\n throw new Error(`[@razorpay/blade:BladeProvider]: BladeProvider is missing theme`);\n }\n if (themeContext === undefined) {\n throw new Error(`[@razorpay/blade:BladeProvider]: useTheme must be used within BladeProvider`);\n }\n return themeContext;\n};\n\nexport default useTheme;\n"],"names":["getColorScheme","colorScheme","Appearance","getMediaQuery","min","max","getPlatformType","navigator","product","document","process","deviceType","desktop","mobile","useBreakpoint","breakpoints","supportsMatchMedia","window","matchMedia","breakpointsTokenAndQueryCollection","useMemo","Object","entries","map","index","breakpointsArray","token","screenSize","maxValue","mediaQuery","undefined","getMatchedDeviceType","useCallback","matchedBreakpoint","matchedDeviceType","platform","includes","getMatchedBreakpoint","event","find","media","matches","useState","breakpointAndDevice","setBreakpointAndDevice","useEffect","handleMediaQueryChange","mediaQueryInstances","mediaQueryInstance","addEventListener","addListener","forEach","removeEventListener","removeListener","colorSchemeNamesInput","useColorScheme","initialColorScheme","colorSchemeState","setColorSchemeState","setColorScheme","setThemeMode","Error","toString","isReactNative","getOS","Platform","OS","isAndroid","castWebType","value","castNativeType","makeBorderSize","size","makeMotionTime","time","makeSpace","makeTypographySize","makeSize","toTitleCase","inputString","toLowerCase","split","word","charAt","toUpperCase","slice","join","usePrevious","ref","useRef","current","ThemeContext","createContext","theme","useTheme","themeContext","useContext"],"mappings":";;;;AAGaA,IAAAA,cAAc,CAAG,SAAjBA,cAAiB,EAAoE,KAAnEC,WAAmE,2DAA9B,OAA8B,CAEhG,GAAIA,WAAW,GAAK,OAAhB,EAA2B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GC,MAAM,EAAlB,CAEA5C,SAAS,CAAC,UAAM,CACd2C,GAAG,CAACE,OAAJ,CAAcrB,KAAd,CACD,CAFQ,CAEN,CAACA,KAAD,CAFM,CAAT,CAIA,OAAOmB,GAAG,CAACE,OAAX,CACD;;ACNYC,IAAAA,YAAY,CAAGC,aAAa,CAAe,CAEtDC,KAAK,CAAE,IAF+C,CAGtD5F,WAAW,CAAE,OAHyC,CAItDkC,QAAQ,CAAE,WAJ4C,CAKtDwB,cAAc,CAAE,qCAAA,EALsC,CAAf,EAQnCmC,IAAAA,QAAQ,CAAG,SAAXA,QAAW,EAAoB,CACnC,IAAMC,YAAY,CAAGC,UAAU,CAAeL,YAAf,CAA/B,CACA,GAAI,CAACI,YAAY,CAACF,KAAlB,CAAyB,CACvB,UAAUhC,KAAJ,mEAAN,CACD,CACD,GAAIkC,YAAY,GAAKjE,SAArB,CAAgC,CAC9B,UAAU+B,KAAJ,+EAAN,CACD,CACD,OAAOkC,YAAP,CACD;;;;"}
|
|
1
|
+
{"version":3,"file":"index.native.js","sources":["../../src/utils/getColorScheme/getColorScheme.native.ts","../../src/utils/getMediaQuery/getMediaQuery.ts","../../src/utils/getPlatformType/getPlatformType.ts","../../src/utils/useBreakpoint/useBreakpoint.ts","../../src/tokens/theme/theme.ts","../../src/utils/useColorScheme/useColorScheme.ts","../../src/utils/platform/isReactNative.ts","../../src/utils/platform/getOS.native.ts","../../src/utils/platform/platform.native.ts","../../src/utils/platform/castUtils.ts","../../src/utils/makeBorderSize/makeBorderSize.ts","../../src/utils/makeMotionTime/makeMotionTime.native.ts","../../src/utils/makeSpace/makeSpace.ts","../../src/utils/makeTypographySize/makeTypographySize.native.ts","../../src/utils/makeSize/makeSize.ts","../../src/utils/toTitleCase/toTitleCase.ts","../../src/utils/usePrevious/usePrevious.ts","../../src/components/BladeProvider/useTheme.ts"],"sourcesContent":["import { Appearance } from 'react-native';\nimport type { ColorSchemeNames, ColorSchemeNamesInput } from '~tokens/theme';\n\nexport const getColorScheme = (colorScheme: ColorSchemeNamesInput = 'light'): ColorSchemeNames => {\n // @TODO: convert this to hook as Appearance API also adds an eventListener which subscribes to the colorscheme changes on the device\n if (colorScheme === 'light' || colorScheme === 'dark') {\n return colorScheme;\n }\n\n if (colorScheme === 'system') {\n return Appearance.getColorScheme() ?? 'light';\n }\n\n return 'light';\n};\n","export const getMediaQuery = ({ min, max }: { min: number; max?: number }): string => {\n return `screen and (min-width: ${min}px)${max ? ` and (max-width: ${max}px)` : ''}`;\n};\n","export type PlatformTypes = 'browser' | 'node' | 'react-native' | 'unknown';\n\nexport const getPlatformType = (): PlatformTypes => {\n if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {\n return 'react-native';\n }\n\n if (typeof document !== 'undefined') {\n return 'browser';\n }\n\n if (typeof process !== 'undefined') {\n return 'node';\n }\n\n return 'unknown';\n};\n","/* eslint-disable @typescript-eslint/restrict-plus-operands */\nimport { useEffect, useState, useCallback, useMemo } from 'react';\nimport { getPlatformType } from '../getPlatformType';\nimport { getMediaQuery } from '../getMediaQuery';\nimport type { Breakpoints } from '~tokens/global';\n\nconst deviceType = {\n desktop: 'desktop',\n mobile: 'mobile',\n} as const;\n\ntype DeviceType = keyof typeof deviceType;\ntype Breakpoint = keyof Breakpoints | undefined;\n\ntype BreakpointAndDevice = {\n matchedBreakpoint: Breakpoint;\n matchedDeviceType: DeviceType;\n};\n\nexport const useBreakpoint = ({\n breakpoints,\n}: {\n breakpoints: Breakpoints;\n}): BreakpointAndDevice => {\n const supportsMatchMedia =\n typeof document !== 'undefined' &&\n typeof window !== 'undefined' &&\n typeof window?.matchMedia === 'function';\n\n const breakpointsTokenAndQueryCollection = useMemo(\n () =>\n (supportsMatchMedia\n ? Object.entries(breakpoints).map(([token, screenSize], index, breakpointsArray) => {\n const min = screenSize;\n const maxValue = breakpointsArray[index + 1]?.[1];\n const mediaQuery = getMediaQuery({ min, max: maxValue ? maxValue - 1 : undefined });\n return { token, screenSize, mediaQuery };\n })\n : []) as {\n token: keyof Breakpoints;\n screenSize: number;\n mediaQuery: string;\n }[],\n [breakpoints, supportsMatchMedia],\n );\n\n const getMatchedDeviceType = useCallback((matchedBreakpoint: Breakpoint): DeviceType => {\n let matchedDeviceType: DeviceType = deviceType.mobile;\n const platform = getPlatformType();\n if (platform === 'react-native') {\n matchedDeviceType = deviceType.mobile;\n } else if (platform === 'browser') {\n if (matchedBreakpoint && ['base', 'xs', 's'].includes(matchedBreakpoint)) {\n // tablet is also categorised as mobile\n matchedDeviceType = deviceType.mobile;\n } else {\n matchedDeviceType = deviceType.desktop;\n }\n } else if (platform === 'node') {\n //@TODO: Check for useragent for node\n matchedDeviceType = deviceType.desktop;\n }\n return matchedDeviceType;\n }, []);\n\n const getMatchedBreakpoint = useCallback(\n (event?: MediaQueryListEvent): Breakpoint => {\n const matchedBreakpoint =\n breakpointsTokenAndQueryCollection.find(({ mediaQuery = '' }) => {\n // this will run whenever mediaQuery change event is triggered\n if (event?.media === mediaQuery) {\n return true;\n }\n // this will run when the state is initialised for the first time and hence the event object will be empty so we'll fallback to browser's window object\n if (window.matchMedia(mediaQuery).matches) {\n return true;\n }\n return false;\n })?.token ?? undefined;\n\n return matchedBreakpoint;\n },\n [breakpointsTokenAndQueryCollection],\n );\n\n const [breakpointAndDevice, setBreakpointAndDevice] = useState(() => {\n const matchedBreakpoint = getMatchedBreakpoint();\n const matchedDeviceType = getMatchedDeviceType(matchedBreakpoint);\n return {\n matchedBreakpoint,\n matchedDeviceType,\n };\n });\n\n useEffect(() => {\n if (!supportsMatchMedia) {\n return undefined;\n }\n\n const handleMediaQueryChange = (event: MediaQueryListEvent): void => {\n setBreakpointAndDevice(() => {\n const matchedBreakpoint = getMatchedBreakpoint(event);\n const matchedDeviceType = getMatchedDeviceType(matchedBreakpoint);\n\n return { matchedBreakpoint, matchedDeviceType };\n });\n };\n\n const mediaQueryInstances = breakpointsTokenAndQueryCollection.map(({ mediaQuery = '' }) => {\n const mediaQueryInstance = window.matchMedia(mediaQuery);\n /**\n * the mediaquery event listener is available on mediaQuery instances and not `window`\n * we iterate over all the breakpoints we have, register each instance and store them as `mediaQueryInstances` so we can later unregister all of them.\n */\n if (mediaQueryInstance.addEventListener) {\n mediaQueryInstance.addEventListener('change', handleMediaQueryChange);\n } else {\n // In older browsers MediaQueryList do not yet inherit from EventTarget, So using addListener as fallback - https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList/addListener\n mediaQueryInstance.addListener(handleMediaQueryChange);\n }\n return mediaQueryInstance;\n });\n\n return (): void => {\n mediaQueryInstances.forEach((mediaQueryInstance) => {\n if (mediaQueryInstance.removeEventListener) {\n mediaQueryInstance.removeEventListener('change', handleMediaQueryChange);\n } else {\n // In older browsers MediaQueryList do not yet inherit from EventTarget, So using removeListener as fallback - https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList/removeListener\n mediaQueryInstance.removeListener(handleMediaQueryChange);\n }\n });\n };\n }, [\n breakpointsTokenAndQueryCollection,\n getMatchedBreakpoint,\n getMatchedDeviceType,\n supportsMatchMedia,\n ]);\n\n // @TODO: handle SSR scenarios\n return breakpointAndDevice;\n};\n","import type { StringWithAutocomplete } from '~utils/types';\nimport type {\n Border,\n Breakpoints,\n Motion,\n Spacing,\n TypographyWithPlatforms,\n ElevationWithColorModes,\n} from '~tokens/global';\n\nexport type ColorSchemeNames = 'dark' | 'light';\nexport type ColorSchemeNamesInput = ColorSchemeNames | 'system';\n\nexport type ColorSchemeModes = 'onDark' | 'onLight';\n\nexport type TextTypes = 'muted' | 'normal' | 'placeholder' | 'subdued' | 'subtle';\n\nexport type ColorContrastTypes = 'low' | 'high';\n\nexport type Feedback = 'information' | 'negative' | 'neutral' | 'notice' | 'positive';\n\nexport type ColorContrast = {\n [K in ColorContrastTypes as `${Extract<K, string>}Contrast`]: string;\n};\n\n// @TODO: this shall rather be Surface = 'level1' | 'level2' | 'level3' to keep in sync with color tokens\nexport type SurfaceLevels = 1 | 2 | 3;\n\nexport type ActionStates = {\n default: string;\n hover: string;\n focus: string;\n active: string;\n disabled: string;\n};\n\nexport type LinkActionStates = ActionStates & {\n visited: string;\n};\n\nexport type ActionStatesWithContrast = {\n default: ColorContrast;\n hover: ColorContrast;\n focus: ColorContrast;\n active: ColorContrast;\n disabled: ColorContrast;\n};\n\nexport type LinkActionStatesWithContrast = ActionStatesWithContrast & {\n visited: ColorContrast;\n};\n\nexport type ActionVariants = {\n primary: ActionStates;\n secondary: ActionStates;\n tertiary: ActionStates;\n link: LinkActionStates;\n};\n\nexport type ActionVariantsWithContrast = {\n primary: ActionStatesWithContrast;\n secondary: ActionStatesWithContrast;\n tertiary: ActionStatesWithContrast;\n link: ActionStatesWithContrast;\n};\n\n// export type ActionProperties = {\n// background: ActionVariants;\n// border: ActionVariants;\n// text: ActionVariants;\n// icon: ActionVariants;\n// };\n\nexport type FeedbackActions = {\n background: Pick<ActionVariantsWithContrast, 'primary'>;\n border: Pick<ActionVariantsWithContrast, 'primary'>;\n text: Pick<ActionVariantsWithContrast, 'link' | 'primary'>;\n icon: Pick<ActionVariantsWithContrast, 'link' | 'primary'>;\n};\n\nexport type Colors = {\n brand: {\n primary: Record<300 | 400 | 500 | 600 | 700 | 800, string>;\n secondary: Record<500, string>;\n gray: Record<200 | 300 | 400 | 500 | 600 | 700 | 'a50' | 'a100', ColorContrast>;\n };\n feedback: {\n background: Record<Feedback, ColorContrast>;\n border: Record<Feedback, ColorContrast>;\n text: Record<Feedback, ColorContrast>;\n icon: Record<Feedback, ColorContrast>;\n positive: {\n action: FeedbackActions;\n };\n negative: {\n action: FeedbackActions;\n };\n information: {\n action: FeedbackActions;\n };\n notice: {\n action: FeedbackActions;\n };\n neutral: {\n action: FeedbackActions;\n };\n };\n surface: {\n background: Record<'level1' | 'level2' | 'level3', ColorContrast>;\n border: Record<'normal' | 'subtle', ColorContrast>;\n text: Record<TextTypes, ColorContrast>;\n action: {\n icon: ActionStatesWithContrast;\n };\n };\n overlay: Record<'background', string>;\n action: {\n background: Omit<ActionVariants, 'link'>;\n border: Omit<ActionVariants, 'link'>;\n text: ActionVariants;\n icon: ActionVariants;\n };\n badge: {\n background: {\n blue: ColorContrast;\n };\n border: {\n blue: ColorContrast;\n };\n text: {\n blue: ColorContrast;\n };\n icon: {\n blue: ColorContrast;\n };\n };\n};\n\nexport type ColorsWithModes = Record<ColorSchemeModes, Colors>;\n\nexport type ThemeTokens = {\n name: 'paymentTheme' | 'bankingTheme' | StringWithAutocomplete; // Can be used to watch over state changes between theme without watching over entire theme object\n border: Border;\n breakpoints: Breakpoints;\n colors: ColorsWithModes;\n motion: Motion;\n elevation: ElevationWithColorModes;\n spacing: Spacing;\n typography: TypographyWithPlatforms;\n};\n\nexport type SpacingValues = `${Spacing[keyof Spacing]}px`;\nexport type BorderWidthValues = `${Border['width'][keyof Border['width']]}px`;\nexport type BorderRadiusValues =\n | `${Border['radius'][Exclude<keyof Border['radius'], 'round'>]}px`\n | `${Border['radius'][Extract<keyof Border['radius'], 'round'>]}`;\n\nexport const colorSchemeNamesInput: ColorSchemeNamesInput[] = ['light', 'dark', 'system'];\n","import { useState, useCallback } from 'react';\nimport { getColorScheme } from '../getColorScheme';\nimport { colorSchemeNamesInput } from '~tokens/theme/theme';\nimport type { ColorSchemeNames, ColorSchemeNamesInput } from '~tokens/theme';\n\nexport type UseColorScheme = {\n colorScheme: ColorSchemeNames;\n setColorScheme: (colorScheme: ColorSchemeNamesInput) => void;\n};\n\nexport const useColorScheme = (\n initialColorScheme: ColorSchemeNamesInput = 'light',\n): UseColorScheme => {\n // if colorScheme defined use that else fallback to 'light'\n const [colorSchemeState, setColorSchemeState] = useState<ColorSchemeNames>(() =>\n getColorScheme(initialColorScheme),\n );\n\n const setColorScheme = useCallback(function setThemeMode(colorScheme: ColorSchemeNamesInput) {\n if (__DEV__) {\n if (!colorSchemeNamesInput.includes(colorScheme)) {\n throw new Error(\n `[useColorScheme]: Expected color scheme to be one of [${colorSchemeNamesInput.toString()}] but received ${colorScheme}`,\n );\n }\n }\n setColorSchemeState(getColorScheme(colorScheme));\n }, []);\n\n return {\n colorScheme: colorSchemeState,\n setColorScheme,\n };\n};\n","/* eslint-disable @typescript-eslint/no-namespace */\nimport { getPlatformType } from '../getPlatformType';\n\nconst isReactNative = (): boolean => {\n return getPlatformType() === 'react-native';\n};\n\nexport { isReactNative };\n","import { Platform } from 'react-native';\n\nexport const getOS = (): typeof Platform.OS => {\n return Platform.OS;\n};\n\nexport const isAndroid = (): boolean => getOS() === 'android';\n","/* eslint-disable @typescript-eslint/no-namespace */\nimport type { Brand, NativeOrWebBrand } from './types';\n\nnamespace Platform {\n export type Name = 'native';\n /**\n * Right now, the module resolution is set to resolve `.native` files,\n *\n * Thus Platform.Select<> type will return the `native` type\n */\n export type Select<Options extends { web: unknown; native: unknown }> = Brand<\n Options[Name],\n 'platform-native'\n >;\n\n export type CastNative<T extends NativeOrWebBrand | undefined> = Extract<\n T,\n { __brand__?: 'platform-native' | 'platform-all' }\n >;\n\n export type CastWeb<T extends NativeOrWebBrand | undefined> = Extract<\n T,\n { __brand__?: 'platform-web' | 'platform-all' }\n >;\n}\n\nexport { Platform };\n","import type { Platform } from '.';\n\n/**\n * @description\n *\n * Casts a Platform.Select<> type to web type\n *\n * @example\n *\n * ```ts\n * type Example = Platform.Select<{ web: string; native: number }>;\n *\n * const extractedWebType = castWebType('' as Example);\n * // ^ string\n * ```\n */\nconst castWebType = <T>(value: T): Platform.CastWeb<T> => {\n return value as Platform.CastWeb<typeof value>;\n};\n\n/**\n * @description\n *\n * Casts a Platform.Select<> type to native type\n *\n * @example\n *\n * ```ts\n * type Example = Platform.Select<{ web: string; native: number }>;\n *\n * const extractedNativeType = castNativeType('' as Example);\n * // ^ number\n * ```\n */\nconst castNativeType = <T>(value: T): Platform.CastNative<T> => {\n return value as Platform.CastNative<typeof value>;\n};\n\nexport { castWebType, castNativeType };\n","export function makeBorderSize<T extends number>(size: T): `${T}px`;\nexport function makeBorderSize<T extends string>(size: T): T;\nexport function makeBorderSize<T extends number | string>(size: T): `${T}px` | T {\n if (typeof size === 'number') {\n return `${size}px`;\n }\n return size;\n}\n","import type { MakeMotionTime } from './types';\nimport type { Platform } from '~utils';\n\nexport const makeMotionTime = <T extends number>(\n time: T,\n): Platform.CastNative<MakeMotionTime<T>> => {\n return time;\n};\n","export const makeSpace = <T extends number>(size: T): `${T}px` => {\n return `${size}px`;\n};\n","export const makeTypographySize = <T extends number>(size: T): `${T}px` => {\n return `${size}px`;\n};\n","export type MakeSize<T extends number> = `${T}px`;\n\nexport const makeSize = <T extends number>(size: T): `${T}px` => {\n return `${size}px`;\n};\n","/**\n * @deprecated This utility will be deprecated in subsequent version.\n */\nexport const toTitleCase = (inputString: string): string =>\n inputString\n .toLowerCase()\n .split(' ')\n .map((word) => word.charAt(0).toUpperCase() + word.slice(1))\n .join(' ');\n","import type { MutableRefObject } from 'react';\nimport { useEffect, useRef } from 'react';\n\n/**\n * a type-safe version of the `usePrevious` hook described here:\n * @see {@link https://reactjs.org/docs/hooks-faq.html#how-to-get-the-previous-props-or-state}\n * @deprecated This utility will be deprecated in subsequent version.\n */\nexport function usePrevious<T>(value: T): MutableRefObject<T | undefined>['current'] {\n const ref = useRef<T>();\n\n useEffect(() => {\n ref.current = value;\n }, [value]);\n\n return ref.current;\n}\n","import { useContext, createContext } from 'react';\nimport type { UseColorScheme } from '../../utils/useColorScheme';\nimport type { Theme } from './';\nimport type { TypographyPlatforms } from '~tokens/global';\n\nexport type ThemeContext = UseColorScheme & {\n theme: Theme;\n platform: TypographyPlatforms;\n};\n\nexport const ThemeContext = createContext<ThemeContext>({\n // @ts-expect-error set null\n theme: null,\n colorScheme: 'light',\n platform: 'onDesktop',\n setColorScheme: () => null,\n});\n\nconst useTheme = (): ThemeContext => {\n const themeContext = useContext<ThemeContext>(ThemeContext);\n if (__DEV__) {\n if (!themeContext.theme) {\n throw new Error(`[@razorpay/blade:BladeProvider]: BladeProvider is missing theme`);\n }\n if (themeContext === undefined) {\n throw new Error(\n `[@razorpay/blade:BladeProvider]: useTheme must be used within BladeProvider`,\n );\n }\n }\n return themeContext;\n};\n\nexport default useTheme;\n"],"names":["getColorScheme","colorScheme","Appearance","getMediaQuery","min","max","getPlatformType","navigator","product","document","process","deviceType","desktop","mobile","useBreakpoint","breakpoints","supportsMatchMedia","window","matchMedia","breakpointsTokenAndQueryCollection","useMemo","Object","entries","map","index","breakpointsArray","token","screenSize","maxValue","mediaQuery","undefined","getMatchedDeviceType","useCallback","matchedBreakpoint","matchedDeviceType","platform","includes","getMatchedBreakpoint","event","find","media","matches","useState","breakpointAndDevice","setBreakpointAndDevice","useEffect","handleMediaQueryChange","mediaQueryInstances","mediaQueryInstance","addEventListener","addListener","forEach","removeEventListener","removeListener","colorSchemeNamesInput","useColorScheme","initialColorScheme","colorSchemeState","setColorSchemeState","setColorScheme","setThemeMode","__DEV__","Error","toString","isReactNative","getOS","Platform","OS","isAndroid","castWebType","value","castNativeType","makeBorderSize","size","makeMotionTime","time","makeSpace","makeTypographySize","makeSize","toTitleCase","inputString","toLowerCase","split","word","charAt","toUpperCase","slice","join","usePrevious","ref","useRef","current","ThemeContext","createContext","theme","useTheme","themeContext","useContext"],"mappings":";;;;AAGaA,IAAAA,cAAc,CAAG,SAAjBA,cAAiB,EAAoE,KAAnEC,WAAmE,2DAA9B,OAA8B,CAEhG,GAAIA,WAAW,GAAK,OAAhB,EAA2BA,WAAW,GAAK,MAA/C,CAAuD,CACrD,OAAOA,WAAP,CACD,CAED,GAAIA,WAAW,GAAK,QAApB,CAA8B,2BAC5B,8BAAOC,UAAU,CAACF,cAAX,EAAP,8BAAsC,OAAtC,CACD,CAED,OAAO,OAAP,CACD;;ACdYG,IAAAA,aAAa,CAAG,SAAhBA,aAAgB,MAAyD,KAAtDC,GAAsD,MAAtDA,GAAsD,CAAjDC,GAAiD,MAAjDA,GAAiD,CACpF,iCAAiCD,GAAjC,QAA0CC,GAAG,qBAAuBA,GAAvB,OAAkC,EAA/E,EACD;;ACAYC,IAAAA,eAAe,CAAG,S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G,SAAXA,QAAW,EAAoB,CACnC,IAAMC,YAAY,CAAGC,UAAU,CAAeL,YAAf,CAA/B,CACA,GAAI/B,OAAJ,CAAa,CACX,GAAI,CAACmC,YAAY,CAACF,KAAlB,CAAyB,CACvB,UAAUhC,KAAJ,mEAAN,CACD,CACD,GAAIkC,YAAY,GAAKlE,SAArB,CAAgC,CAC9B,UAAUgC,KAAJ,+EAAN,CAGD,CACF,CACD,OAAOkC,YAAP,CACD;;;;"}
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
2
|
+
import { useMemo, useCallback, useState, useEffect, useRef, createContext, useContext } from 'react';
|
|
3
|
+
|
|
4
|
+
var getColorScheme = function getColorScheme() {
|
|
5
|
+
var colorScheme = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'light';
|
|
6
|
+
// @TODO: create a useMediaQuery hook with an event listener which will subscribe to changes and move all this logic there
|
|
7
|
+
var colorSchemeMediaQueryMap = {
|
|
8
|
+
light: '(prefers-color-scheme: light)',
|
|
9
|
+
dark: '(prefers-color-scheme: dark)',
|
|
10
|
+
system: 'default'
|
|
11
|
+
};
|
|
12
|
+
var supportsMatchMedia = typeof window !== 'undefined' && typeof window.matchMedia === 'function';
|
|
13
|
+
|
|
14
|
+
if (colorScheme === 'light' || colorScheme === 'dark') {
|
|
15
|
+
return colorScheme;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (colorScheme === 'system' && supportsMatchMedia && window.matchMedia(colorSchemeMediaQueryMap.dark).matches) {
|
|
19
|
+
return 'dark';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return 'light';
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
var getMediaQuery = function getMediaQuery(_ref) {
|
|
26
|
+
var min = _ref.min,
|
|
27
|
+
max = _ref.max;
|
|
28
|
+
return "screen and (min-width: ".concat(min, "px)").concat(max ? " and (max-width: ".concat(max, "px)") : '');
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
var getPlatformType = function getPlatformType() {
|
|
32
|
+
if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
|
|
33
|
+
return 'react-native';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (typeof document !== 'undefined') {
|
|
37
|
+
return 'browser';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (typeof process !== 'undefined') {
|
|
41
|
+
return 'node';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return 'unknown';
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
var deviceType = {
|
|
48
|
+
desktop: 'desktop',
|
|
49
|
+
mobile: 'mobile'
|
|
50
|
+
};
|
|
51
|
+
var useBreakpoint = function useBreakpoint(_ref) {
|
|
52
|
+
var _window;
|
|
53
|
+
|
|
54
|
+
var breakpoints = _ref.breakpoints;
|
|
55
|
+
var supportsMatchMedia = typeof document !== 'undefined' && typeof window !== 'undefined' && typeof ((_window = window) === null || _window === void 0 ? void 0 : _window.matchMedia) === 'function';
|
|
56
|
+
var breakpointsTokenAndQueryCollection = useMemo(function () {
|
|
57
|
+
return supportsMatchMedia ? Object.entries(breakpoints).map(function (_ref2, index, breakpointsArray) {
|
|
58
|
+
var _breakpointsArray;
|
|
59
|
+
|
|
60
|
+
var _ref3 = _slicedToArray(_ref2, 2),
|
|
61
|
+
token = _ref3[0],
|
|
62
|
+
screenSize = _ref3[1];
|
|
63
|
+
|
|
64
|
+
var min = screenSize;
|
|
65
|
+
var maxValue = (_breakpointsArray = breakpointsArray[index + 1]) === null || _breakpointsArray === void 0 ? void 0 : _breakpointsArray[1];
|
|
66
|
+
var mediaQuery = getMediaQuery({
|
|
67
|
+
min: min,
|
|
68
|
+
max: maxValue ? maxValue - 1 : undefined
|
|
69
|
+
});
|
|
70
|
+
return {
|
|
71
|
+
token: token,
|
|
72
|
+
screenSize: screenSize,
|
|
73
|
+
mediaQuery: mediaQuery
|
|
74
|
+
};
|
|
75
|
+
}) : [];
|
|
76
|
+
}, [breakpoints, supportsMatchMedia]);
|
|
77
|
+
var getMatchedDeviceType = useCallback(function (matchedBreakpoint) {
|
|
78
|
+
var matchedDeviceType = deviceType.mobile;
|
|
79
|
+
var platform = getPlatformType();
|
|
80
|
+
|
|
81
|
+
if (platform === 'react-native') {
|
|
82
|
+
matchedDeviceType = deviceType.mobile;
|
|
83
|
+
} else if (platform === 'browser') {
|
|
84
|
+
if (matchedBreakpoint && ['base', 'xs', 's'].includes(matchedBreakpoint)) {
|
|
85
|
+
// tablet is also categorised as mobile
|
|
86
|
+
matchedDeviceType = deviceType.mobile;
|
|
87
|
+
} else {
|
|
88
|
+
matchedDeviceType = deviceType.desktop;
|
|
89
|
+
}
|
|
90
|
+
} else if (platform === 'node') {
|
|
91
|
+
//@TODO: Check for useragent for node
|
|
92
|
+
matchedDeviceType = deviceType.desktop;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return matchedDeviceType;
|
|
96
|
+
}, []);
|
|
97
|
+
var getMatchedBreakpoint = useCallback(function (event) {
|
|
98
|
+
var _breakpointsTokenAndQ, _breakpointsTokenAndQ2;
|
|
99
|
+
|
|
100
|
+
var matchedBreakpoint = (_breakpointsTokenAndQ = (_breakpointsTokenAndQ2 = breakpointsTokenAndQueryCollection.find(function (_ref4) {
|
|
101
|
+
var _ref4$mediaQuery = _ref4.mediaQuery,
|
|
102
|
+
mediaQuery = _ref4$mediaQuery === void 0 ? '' : _ref4$mediaQuery;
|
|
103
|
+
|
|
104
|
+
// this will run whenever mediaQuery change event is triggered
|
|
105
|
+
if ((event === null || event === void 0 ? void 0 : event.media) === mediaQuery) {
|
|
106
|
+
return true;
|
|
107
|
+
} // this will run when the state is initialised for the first time and hence the event object will be empty so we'll fallback to browser's window object
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
// this will run when the state is initialised for the first time and hence the event object will be empty so we'll fallback to browser's window object
|
|
111
|
+
if (window.matchMedia(mediaQuery).matches) {
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return false;
|
|
116
|
+
})) === null || _breakpointsTokenAndQ2 === void 0 ? void 0 : _breakpointsTokenAndQ2.token) !== null && _breakpointsTokenAndQ !== void 0 ? _breakpointsTokenAndQ : undefined;
|
|
117
|
+
return matchedBreakpoint;
|
|
118
|
+
}, [breakpointsTokenAndQueryCollection]);
|
|
119
|
+
|
|
120
|
+
var _useState = useState(function () {
|
|
121
|
+
var matchedBreakpoint = getMatchedBreakpoint();
|
|
122
|
+
var matchedDeviceType = getMatchedDeviceType(matchedBreakpoint);
|
|
123
|
+
return {
|
|
124
|
+
matchedBreakpoint: matchedBreakpoint,
|
|
125
|
+
matchedDeviceType: matchedDeviceType
|
|
126
|
+
};
|
|
127
|
+
}),
|
|
128
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
129
|
+
breakpointAndDevice = _useState2[0],
|
|
130
|
+
setBreakpointAndDevice = _useState2[1];
|
|
131
|
+
|
|
132
|
+
useEffect(function () {
|
|
133
|
+
if (!supportsMatchMedia) {
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
var handleMediaQueryChange = function handleMediaQueryChange(event) {
|
|
138
|
+
setBreakpointAndDevice(function () {
|
|
139
|
+
var matchedBreakpoint = getMatchedBreakpoint(event);
|
|
140
|
+
var matchedDeviceType = getMatchedDeviceType(matchedBreakpoint);
|
|
141
|
+
return {
|
|
142
|
+
matchedBreakpoint: matchedBreakpoint,
|
|
143
|
+
matchedDeviceType: matchedDeviceType
|
|
144
|
+
};
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
var mediaQueryInstances = breakpointsTokenAndQueryCollection.map(function (_ref5) {
|
|
149
|
+
var _ref5$mediaQuery = _ref5.mediaQuery,
|
|
150
|
+
mediaQuery = _ref5$mediaQuery === void 0 ? '' : _ref5$mediaQuery;
|
|
151
|
+
var mediaQueryInstance = window.matchMedia(mediaQuery);
|
|
152
|
+
/**
|
|
153
|
+
* the mediaquery event listener is available on mediaQuery instances and not `window`
|
|
154
|
+
* we iterate over all the breakpoints we have, register each instance and store them as `mediaQueryInstances` so we can later unregister all of them.
|
|
155
|
+
*/
|
|
156
|
+
|
|
157
|
+
if (mediaQueryInstance.addEventListener) {
|
|
158
|
+
mediaQueryInstance.addEventListener('change', handleMediaQueryChange);
|
|
159
|
+
} else {
|
|
160
|
+
// In older browsers MediaQueryList do not yet inherit from EventTarget, So using addListener as fallback - https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList/addListener
|
|
161
|
+
mediaQueryInstance.addListener(handleMediaQueryChange);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return mediaQueryInstance;
|
|
165
|
+
});
|
|
166
|
+
return function () {
|
|
167
|
+
mediaQueryInstances.forEach(function (mediaQueryInstance) {
|
|
168
|
+
if (mediaQueryInstance.removeEventListener) {
|
|
169
|
+
mediaQueryInstance.removeEventListener('change', handleMediaQueryChange);
|
|
170
|
+
} else {
|
|
171
|
+
// In older browsers MediaQueryList do not yet inherit from EventTarget, So using removeListener as fallback - https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList/removeListener
|
|
172
|
+
mediaQueryInstance.removeListener(handleMediaQueryChange);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
}, [breakpointsTokenAndQueryCollection, getMatchedBreakpoint, getMatchedDeviceType, supportsMatchMedia]); // @TODO: handle SSR scenarios
|
|
177
|
+
|
|
178
|
+
return breakpointAndDevice;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
var useColorScheme = function useColorScheme() {
|
|
182
|
+
var initialColorScheme = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'light';
|
|
183
|
+
|
|
184
|
+
// if colorScheme defined use that else fallback to 'light'
|
|
185
|
+
var _useState = useState(function () {
|
|
186
|
+
return getColorScheme(initialColorScheme);
|
|
187
|
+
}),
|
|
188
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
189
|
+
colorSchemeState = _useState2[0],
|
|
190
|
+
setColorSchemeState = _useState2[1];
|
|
191
|
+
|
|
192
|
+
var setColorScheme = useCallback(function setThemeMode(colorScheme) {
|
|
193
|
+
|
|
194
|
+
setColorSchemeState(getColorScheme(colorScheme));
|
|
195
|
+
}, []);
|
|
196
|
+
return {
|
|
197
|
+
colorScheme: colorSchemeState,
|
|
198
|
+
setColorScheme: setColorScheme
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
/* eslint-disable @typescript-eslint/no-namespace */
|
|
203
|
+
|
|
204
|
+
var isReactNative = function isReactNative() {
|
|
205
|
+
return getPlatformType() === 'react-native';
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
var getOS = function getOS() {
|
|
209
|
+
return 'web';
|
|
210
|
+
};
|
|
211
|
+
var isAndroid = function isAndroid() {
|
|
212
|
+
return false;
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
/* eslint-disable @typescript-eslint/no-namespace */
|
|
216
|
+
var Platform;
|
|
217
|
+
|
|
218
|
+
(function (_Platform) {})(Platform || (Platform = {}));
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* @description
|
|
222
|
+
*
|
|
223
|
+
* Casts a Platform.Select<> type to web type
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
*
|
|
227
|
+
* ```ts
|
|
228
|
+
* type Example = Platform.Select<{ web: string; native: number }>;
|
|
229
|
+
*
|
|
230
|
+
* const extractedWebType = castWebType('' as Example);
|
|
231
|
+
* // ^ string
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
var castWebType = function castWebType(value) {
|
|
235
|
+
return value;
|
|
236
|
+
};
|
|
237
|
+
/**
|
|
238
|
+
* @description
|
|
239
|
+
*
|
|
240
|
+
* Casts a Platform.Select<> type to native type
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
*
|
|
244
|
+
* ```ts
|
|
245
|
+
* type Example = Platform.Select<{ web: string; native: number }>;
|
|
246
|
+
*
|
|
247
|
+
* const extractedNativeType = castNativeType('' as Example);
|
|
248
|
+
* // ^ number
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
var castNativeType = function castNativeType(value) {
|
|
254
|
+
return value;
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
function makeBorderSize(size) {
|
|
258
|
+
if (typeof size === 'number') {
|
|
259
|
+
return "".concat(size, "px");
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return size;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
var makeMotionTime = function makeMotionTime(time) {
|
|
266
|
+
return "".concat(time, "ms");
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
var makeSpace = function makeSpace(size) {
|
|
270
|
+
return "".concat(size, "px");
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
var makeTypographySize = function makeTypographySize(size) {
|
|
274
|
+
var remValue = size / 16;
|
|
275
|
+
return "".concat(remValue, "rem");
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
var makeSize = function makeSize(size) {
|
|
279
|
+
return "".concat(size, "px");
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* @deprecated This utility will be deprecated in subsequent version.
|
|
284
|
+
*/
|
|
285
|
+
var toTitleCase = function toTitleCase(inputString) {
|
|
286
|
+
return inputString.toLowerCase().split(' ').map(function (word) {
|
|
287
|
+
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
288
|
+
}).join(' ');
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* a type-safe version of the `usePrevious` hook described here:
|
|
293
|
+
* @see {@link https://reactjs.org/docs/hooks-faq.html#how-to-get-the-previous-props-or-state}
|
|
294
|
+
* @deprecated This utility will be deprecated in subsequent version.
|
|
295
|
+
*/
|
|
296
|
+
|
|
297
|
+
function usePrevious(value) {
|
|
298
|
+
var ref = useRef();
|
|
299
|
+
useEffect(function () {
|
|
300
|
+
ref.current = value;
|
|
301
|
+
}, [value]);
|
|
302
|
+
return ref.current;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
var ThemeContext = /*#__PURE__*/createContext({
|
|
306
|
+
// @ts-expect-error set null
|
|
307
|
+
theme: null,
|
|
308
|
+
colorScheme: 'light',
|
|
309
|
+
platform: 'onDesktop',
|
|
310
|
+
setColorScheme: function setColorScheme() {
|
|
311
|
+
return null;
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
var useTheme = function useTheme() {
|
|
316
|
+
var themeContext = useContext(ThemeContext);
|
|
317
|
+
|
|
318
|
+
return themeContext;
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
export { Platform, ThemeContext, castNativeType, castWebType, getColorScheme, getMediaQuery, getOS, getPlatformType, isAndroid, isReactNative, makeBorderSize, makeMotionTime, makeSize, makeSpace, makeTypographySize, toTitleCase, useBreakpoint, useColorScheme, usePrevious, useTheme };
|
|
322
|
+
//# sourceMappingURL=index.production.web.js.map
|