MCPcopy
hub / github.com/shadcn-ui/ui / mergeProps

Function mergeProps

packages/react/src/use-render/index.ts:84–135  ·  view source on GitHub ↗
(
  ...sources: Array<
    React.ComponentPropsWithRef<TElement> | Record<string, unknown> | undefined
  >
)

Source from the content-addressed store, hash-verified

82}
83
84function mergeProps<TElement extends React.ElementType>(
85 ...sources: Array<
86 React.ComponentPropsWithRef<TElement> | Record<string, unknown> | undefined
87 >
88) {
89 const result: Record<string, unknown> = {}
90
91 for (const source of sources) {
92 if (!source) {
93 continue
94 }
95
96 const sourceProps = source as Record<string, unknown>
97
98 for (const key of Object.keys(sourceProps)) {
99 const value = sourceProps[key]
100
101 if (value === undefined) {
102 continue
103 }
104
105 const current = result[key]
106
107 if (key === "className") {
108 result[key] = [current, value].filter(Boolean).join(" ")
109 } else if (key === "style") {
110 result[key] = {
111 ...(current as React.CSSProperties | undefined),
112 ...(value as React.CSSProperties | undefined),
113 }
114 } else if (key === "ref") {
115 result[key] = composeRefs(
116 current as React.Ref<unknown> | undefined,
117 value as React.Ref<unknown> | undefined
118 )
119 } else if (
120 isEventHandler(key) &&
121 typeof current === "function" &&
122 typeof value === "function"
123 ) {
124 result[key] = composeEventHandlers(
125 value as EventHandler,
126 current as EventHandler
127 )
128 } else {
129 result[key] = value
130 }
131 }
132 }
133
134 return result as React.ComponentPropsWithRef<TElement>
135}
136
137function getStateAttributes<TState extends RenderState>(
138 state: TState,

Callers 15

MessageScrollerButtonFunction · 0.90
useRenderFunction · 0.85
BreadcrumbLinkFunction · 0.85
ButtonGroupTextFunction · 0.85
MarkerFunction · 0.85
BubbleContentFunction · 0.85
AttachmentTriggerFunction · 0.85
ItemFunction · 0.85
SidebarGroupLabelFunction · 0.85
SidebarGroupActionFunction · 0.85
SidebarMenuButtonFunction · 0.85
SidebarMenuActionFunction · 0.85

Calls 3

composeRefsFunction · 0.85
isEventHandlerFunction · 0.85
composeEventHandlersFunction · 0.85

Tested by

no test coverage detected