@wordpress/global-styles-ui
Version:
Global Styles UI components for WordPress.
1 lines • 1.63 kB
Source Map (JSON)
{"version":3,"file":"provider.mjs","names":[],"sources":["../src/provider.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\nimport { useMemo } from '@wordpress/element';\nimport type { GlobalStylesConfig } from '@wordpress/global-styles-engine';\nimport { mergeGlobalStyles } from '@wordpress/global-styles-engine';\nimport { GlobalStylesContext } from './context';\n\ninterface GlobalStylesProviderProps {\n\tchildren: ReactNode;\n\tvalue: GlobalStylesConfig;\n\tbaseValue: GlobalStylesConfig;\n\tonChange: ( newValue: GlobalStylesConfig ) => void;\n\tfontLibraryEnabled?: boolean;\n}\n\nexport function GlobalStylesProvider( {\n\tchildren,\n\tvalue,\n\tbaseValue,\n\tonChange,\n\tfontLibraryEnabled,\n}: GlobalStylesProviderProps ) {\n\t// Compute merged with memoization since merging can be expensive\n\tconst merged = useMemo( () => {\n\t\treturn mergeGlobalStyles( baseValue, value );\n\t}, [ baseValue, value ] );\n\n\tconst contextValue = useMemo(\n\t\t() => ( {\n\t\t\tuser: value,\n\t\t\tbase: baseValue,\n\t\t\tmerged,\n\t\t\tonChange,\n\t\t\tfontLibraryEnabled,\n\t\t} ),\n\t\t[ value, baseValue, merged, onChange, fontLibraryEnabled ]\n\t);\n\n\treturn (\n\t\t<GlobalStylesContext.Provider value={ contextValue }>\n\t\t\t{ children }\n\t\t</GlobalStylesContext.Provider>\n\t);\n}\n"],"mappings":";;;;;AAcA,SAAgB,qBAAsB,EACrC,UACA,OACA,WACA,UACA,sBAC8B;CAE9B,MAAM,SAAS,cAAe;EAC7B,OAAO,kBAAmB,WAAW,KAAM;CAC5C,GAAG,CAAE,WAAW,KAAM,CAAE;CAExB,MAAM,eAAe,eACZ;EACP,MAAM;EACN,MAAM;EACN;EACA;EACA;CACD,IACA;EAAE;EAAO;EAAW;EAAQ;EAAU;CAAmB,CAC1D;CAEA,OACC,oBAAC,oBAAoB,UAArB;EAA8B,OAAQ;EACnC;CAC2B,CAAA;AAEhC"}