UNPKG

@scrolia/react-native

Version:
1 lines 1.5 kB
{"version":3,"file":"props.mjs","names":["options: GetComponentPropsOptions<P>","result: P"],"sources":["../../src/functions/props.ts"],"sourcesContent":["import type { Plugin } from \"#/@types/options\";\n\nimport { tryPlugin } from \"#/functions/plugin\";\n\n/** The name of the component. */\ntype GetComponentPropsName =\n | \"container\"\n | \"contentX\"\n | \"contentY\"\n | \"listX\"\n | \"listY\"\n | \"trackX\"\n | \"trackY\"\n | \"thumbX\"\n | \"thumbY\";\n\n/** The options for `getComponentProps` function. */\ntype GetComponentPropsOptions<P> = {\n name: GetComponentPropsName;\n props: P;\n plugins: Plugin[];\n};\n\n/** The function to get component props with plugins. */\nconst getComponentProps = <P extends object>(\n options: GetComponentPropsOptions<P>,\n): P => {\n const { name, props, plugins } = options;\n\n let result: P = props;\n\n for (const plugin of plugins) {\n if (!plugin.props?.[name]) continue;\n\n result = {\n ...result,\n ...tryPlugin(plugin, plugin.props[name] as any, result as any),\n };\n }\n\n return result;\n};\n\nexport type { GetComponentPropsName, GetComponentPropsOptions };\nexport { getComponentProps };\n"],"mappings":";;;AAwBA,MAAM,oBAAoB,CACtBA,YACI;CACJ,MAAM,EAAE,MAAM,OAAO,SAAS,GAAG;CAEjC,IAAIC,SAAY;AAEhB,MAAK,MAAM,UAAU,SAAS;AAC1B,MAAI,CAAC,OAAO,QAAQ,MAAO;EAE3B,SAAS;GACL,GAAG;GACH,GAAG,UAAU,QAAQ,OAAO,MAAM,OAAc,OAAc;EACjE;CACJ;AAED,QAAO;AACV"}