UNPKG

@mantine/core

Version:

React components library focused on usability, accessibility and developer experience

1 lines 1.51 kB
{"version":3,"file":"use-props.cjs","names":["useMantineTheme","filterProps"],"sources":["../../../../src/core/MantineProvider/use-props/use-props.ts"],"sourcesContent":["import { filterProps } from '../../utils';\nimport { useMantineTheme } from '../MantineThemeProvider';\n\nexport function useProps<T extends Record<string, any>, U extends Partial<T> | null = {}>(\n component: string | (string | undefined)[],\n defaultProps: U,\n props: T\n): T &\n (U extends null | undefined\n ? {}\n : {\n [Key in Extract<keyof T, keyof U>]-?: U[Key] | NonNullable<T[Key]>;\n }) {\n const theme = useMantineTheme();\n const names = (Array.isArray(component) ? component : [component]).filter(Boolean) as string[];\n\n let contextProps: Record<string, any> = {};\n for (const name of names) {\n const payload = theme.components[name]?.defaultProps;\n const resolved = typeof payload === 'function' ? payload(theme) : payload;\n if (resolved) {\n contextProps = { ...contextProps, ...resolved };\n }\n }\n\n return { ...defaultProps, ...contextProps, ...filterProps(props) } as any;\n}\n"],"mappings":";;;;AAGA,SAAgB,SACd,WACA,cACA,OAMO;CACP,MAAM,QAAQA,6BAAAA,gBAAgB;CAC9B,MAAM,SAAS,MAAM,QAAQ,SAAS,IAAI,YAAY,CAAC,SAAS,GAAG,OAAO,OAAO;CAEjF,IAAI,eAAoC,CAAC;CACzC,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,UAAU,MAAM,WAAW,OAAO;EACxC,MAAM,WAAW,OAAO,YAAY,aAAa,QAAQ,KAAK,IAAI;EAClE,IAAI,UACF,eAAe;GAAE,GAAG;GAAc,GAAG;EAAS;CAElD;CAEA,OAAO;EAAE,GAAG;EAAc,GAAG;EAAc,GAAGC,qBAAAA,YAAY,KAAK;CAAE;AACnE"}