@radix-ui/react-slot 0.0.6 → 0.0.10

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/dist/index.d.ts CHANGED
@@ -2,10 +2,10 @@ import * as React from "react";
2
2
  type SlotProps = {
3
3
  children: React.ReactNode;
4
4
  };
5
- export const Slot: React.ForwardRefExoticComponent<SlotProps & React.RefAttributes<never>>;
5
+ export const Slot: React.ForwardRefExoticComponent<SlotProps & React.RefAttributes<HTMLElement>>;
6
6
  export const Slottable: ({ children }: {
7
7
  children: React.ReactNode;
8
8
  }) => React.ReactElement<any, string | ((props: any) => React.ReactElement<any, any> | null) | (new (props: any) => React.Component<any, any, any>)>;
9
- export const Root: React.ForwardRefExoticComponent<SlotProps & React.RefAttributes<never>>;
9
+ export const Root: React.ForwardRefExoticComponent<SlotProps & React.RefAttributes<HTMLElement>>;
10
10
 
11
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"mappings":"A;AAQA,iBAAiB;IAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;CAAE,CAAC;AAE/C,OAAA,MAAM,6EA2BJ,CAAC;AA4BH,OAAA,MAAM;cAAuC,MAAM,SAAS;oJAE3D,CAAC;AAwBF,OAAA,MAAM,6EAAW,CAAC","sources":["./packages/react/slot/src/packages/react/slot/src/Slot.tsx","./packages/react/slot/src/packages/react/slot/src/index.ts"],"sourcesContent":[null,null],"names":[],"version":3,"file":"index.d.ts.map"}
1
+ {"mappings":"A;AAQA,iBAAiB;IAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;CAAE,CAAC;AAE/C,OAAA,MAAM,mFA2BJ,CAAC;AA4BH,OAAA,MAAM;cAAuC,MAAM,SAAS;oJAE3D,CAAC;AAwBF,OAAA,MAAM,mFAAW,CAAC","sources":["./packages/react/slot/src/packages/react/slot/src/Slot.tsx","./packages/react/slot/src/packages/react/slot/src/index.ts"],"sourcesContent":[null,null],"names":[],"version":3,"file":"index.d.ts.map"}
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- function e(e,r,t){Object.defineProperty(e,r,{get:t,enumerable:!0})}var r,t=require("@radix-ui/react-compose-refs").composeRefs,n=require("@radix-ui/primitive").composeEventHandlers,o=require("react"),l=o.forwardRef,i=o.Children,c=o.createElement,s=o.Fragment,u=o.isValidElement,a=o.cloneElement,p=(r=require("@babel/runtime/helpers/extends"))&&r.__esModule?r.default:r,d={};const f=l(((e,r)=>{const{children:t,...n}=e;return 1===i.count(t)?c(m,p({},n,{ref:r}),t):c(s,null,i.map(t,(e=>u(e)&&e.type===b?c(m,p({},n,{ref:r}),e.props.children):e)))}));exports.Slot=f,f.displayName="Slot";const m=l(((e,r)=>{const{children:n,...o}=e,l=i.only(n);return u(l)?a(l,{...h(o,l.props),ref:t(r,l.ref)}):null}));m.displayName="SlotClone";const b=({children:e})=>e;function h(e,r){const t={...r};for(const o in r){const l=e[o],i=r[o];/^on[A-Z]/.test(o)&&(t[o]=n(i,l))}return{...e,...t}}exports.Slottable=b;const x=f;exports.Root=x,e(d,"Root",(function(){return x})),e(d,"Slottable",(function(){return b})),e(d,"Slot",(function(){return f}));
1
+ var e,r,t,n=require("@radix-ui/react-compose-refs").composeRefs,o=require("@radix-ui/primitive").composeEventHandlers,l=(e={},r=require("react"),Object.keys(r).forEach((function(t){"default"!==t&&"__esModule"!==t&&Object.defineProperty(e,t,{enumerable:!0,get:function(){return r[t]}})})),e),i=(t=require("@babel/runtime/helpers/extends"))&&t.__esModule?t.default:t;const s=/*#__PURE__*/l.forwardRef(((e,r)=>{const{children:t,...n}=e;return 1===l.Children.count(t)?/*#__PURE__*/l.createElement(c,i({},n,{ref:r}),t):/*#__PURE__*/l.createElement(l.Fragment,null,l.Children.map(t,(e=>/*#__PURE__*/l.isValidElement(e)&&e.type===a?/*#__PURE__*/l.createElement(c,i({},n,{ref:r}),e.props.children):e)))}));exports.Slot=s,s.displayName="Slot";const c=/*#__PURE__*/l.forwardRef(((e,r)=>{const{children:t,...o}=e,i=l.Children.only(t);/*#__PURE__*/return l.isValidElement(i)?/*#__PURE__*/l.cloneElement(i,{...d(o,i.props),ref:n(r,i.ref)}):null}));c.displayName="SlotClone";const a=({children:e})=>e;function d(e,r){const t={...r};for(const n in r){const l=e[n],i=r[n];/^on[A-Z]/.test(n)&&(t[n]=o(i,l))}return{...e,...t}}exports.Slottable=a;const u=s;exports.Root=u;
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":"AAmBA,SAAAA,EAAwBC,EAAGC,EAAGC,GAC5BC,OAAOC,eAAeJ,EAAGC,EAAAA,CAAII,IAAKH,EAAGI,YAAY,QATnBC,mOAAAA,8CAClBA,EAAEC,WAAaD,EAAEE,QAAUF,aCFnCG,EAAAA,GAA0C,CAACC,EAAOC,oBAC9CC,KAAaC,GAAcH,SAGf,IAFdI,EAA6BC,MAAMH,KAIpCI,EAAAA,EAAAA,GAAcH,EAAAA,CAAWI,IAAKN,IAC5BC,cAOaM,IAAIN,GAAWO,KACJA,IAAUA,EAAMC,OAASC,IAE7CL,EAAAA,EAAAA,GAAcH,EAAAA,CAAWI,IAAKN,IAC5BQ,EAAMT,MAAME,UAKZO,uBAMfV,EAAKa,YAAc,aAQbN,EAAAA,GAAkD,CAACN,EAAOC,oBACtDC,KAAaC,GAAcH,EAC7BS,EAAAA,EAAuBI,KAAKX,YAENO,GAAAA,EACLA,EAAAA,IACdK,EAAWX,EAAWM,EAAMT,OAC/BO,IAAKQ,EAAYd,EAAeQ,EAAcF,OAEhD,QAGND,EAAUM,YAAc,kBAMlBD,EAAY,EAAGT,SAAAA,KACZA,EAOT,SAAAY,EAAoBX,EAAqBa,SAEjCC,EAAAA,IAAqBD,aAGhBE,KAAYF,EAAAA,OACfG,EAAgBhB,EAAUe,GAC1BE,EAAiBJ,EAAWE,GAC5BG,WAAuBC,KAAKJ,KAGhCD,EAAcC,GAAYK,EAAqBH,EAAgBD,cAIvDhB,KAAcc,6BAGtBO,EAAOzB","sources":["./node_modules/@parcel/scope-hoisting/lib/helpers.js","./packages/react/slot/src/Slot.tsx"],"sourcesContent":["var $parcel$global =\n typeof globalThis !== 'undefined'\n ? globalThis\n : typeof self !== 'undefined'\n ? self\n : typeof window !== 'undefined'\n ? window\n : typeof global !== 'undefined'\n ? global\n : {};\n\nfunction $parcel$interopDefault(a) {\n return a && a.__esModule ? a.default : a;\n}\n\nfunction $parcel$defineInteropFlag(a) {\n Object.defineProperty(a, '__esModule', {value: true});\n}\n\nfunction $parcel$export(e, n, v) {\n Object.defineProperty(e, n, {get: v, enumerable: true});\n}\n\nfunction $parcel$exportWildcard(dest, source) {\n Object.keys(source).forEach(function(key) {\n if (key === 'default' || key === '__esModule') {\n return;\n }\n\n Object.defineProperty(dest, key, {\n enumerable: true,\n get: function get() {\n return source[key];\n },\n });\n });\n\n return dest;\n}\n\nfunction $parcel$missingModule(name) {\n var err = new Error(\"Cannot find module '\" + name + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n}\n","import * as React from 'react';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { composeRefs } from '@radix-ui/react-compose-refs';\n\n/* -------------------------------------------------------------------------------------------------\n * Slot\n * -----------------------------------------------------------------------------------------------*/\n\ntype SlotProps = { children: React.ReactNode };\n\nconst Slot = React.forwardRef<never, SlotProps>((props, forwardedRef) => {\n const { children, ...slotProps } = props;\n const childLength = React.Children.count(children);\n\n if (childLength === 1) {\n return (\n <SlotClone {...slotProps} ref={forwardedRef}>\n {children}\n </SlotClone>\n );\n }\n\n return (\n <>\n {React.Children.map(children, (child) => {\n if (React.isValidElement(child) && child.type === Slottable) {\n return (\n <SlotClone {...slotProps} ref={forwardedRef}>\n {child.props.children}\n </SlotClone>\n );\n }\n\n return child;\n })}\n </>\n );\n});\n\nSlot.displayName = 'Slot';\n\n/* -------------------------------------------------------------------------------------------------\n * SlotClone\n * -----------------------------------------------------------------------------------------------*/\n\ntype SlotCloneProps = { children: React.ReactNode };\n\nconst SlotClone = React.forwardRef<any, SlotCloneProps>((props, forwardedRef) => {\n const { children, ...slotProps } = props;\n const child = React.Children.only(children);\n\n return React.isValidElement(child)\n ? React.cloneElement(child, {\n ...mergeProps(slotProps, child.props),\n ref: composeRefs(forwardedRef, (child as any).ref),\n })\n : null;\n});\n\nSlotClone.displayName = 'SlotClone';\n\n/* -------------------------------------------------------------------------------------------------\n * Slottable\n * -----------------------------------------------------------------------------------------------*/\n\nconst Slottable = ({ children }: { children: React.ReactNode }) => {\n return children as React.ReactElement;\n};\n\n/* ---------------------------------------------------------------------------------------------- */\n\ntype AnyProps = Record<string, any>;\n\nfunction mergeProps(slotProps: AnyProps, childProps: AnyProps) {\n // all child props should override\n const overrideProps = { ...childProps };\n\n // if it's a handler, modify the override by composing the base handler\n for (const propName in childProps) {\n const slotPropValue = slotProps[propName];\n const childPropValue = childProps[propName];\n const isHandler = /^on[A-Z]/.test(propName);\n\n if (isHandler) {\n overrideProps[propName] = composeEventHandlers(childPropValue, slotPropValue);\n }\n }\n\n return { ...slotProps, ...overrideProps };\n}\n\nconst Root = Slot;\n\nexport {\n Slot,\n Slottable,\n //\n Root,\n};\n"],"names":["$parcel$export","e","n","v","Object","defineProperty","get","enumerable","a","__esModule","default","Slot","props","forwardedRef","children","slotProps","childLength","count","$745f03260359d8803670e70afd4cf6aa$var$SlotClone","ref","map","child","type","Slottable","displayName","only","$745f03260359d8803670e70afd4cf6aa$var$mergeProps","composeRefs","childProps","overrideProps","propName","slotPropValue","childPropValue","isHandler","test","composeEventHandlers","Root"],"version":3,"file":"index.js.map"}
1
+ {"mappings":"IAYgCA,EAAMC,EAZNC,iHAYAF,KAAMC,mBACpCE,OAAOC,KAAKH,GAAQI,SAAQ,SAASC,GACvB,YAARA,GAA6B,eAARA,GAIzBH,OAAOI,eAAeP,EAAMM,EAAK,CAC/BE,YAAY,EACZC,IAAK,WACH,OAAOR,EAAOK,SAKbN,MA1BuBE,8CAClBA,EAAEQ,WAAaR,EAAES,QAAUT,ECSzC,MAAMU,eAAOC,EAAMC,YAAmC,CAACC,EAAOC,KAC5D,MAAMC,SAAEA,KAAaC,GAAcH,EAGnC,OAAoB,IAFAF,EAAMM,SAASC,MAAMH,gBAIrCI,EAAAC,cAACC,EAADC,EAAA,GAAeN,EAAf,CAA0BO,IAAKT,IAC5BC,gBAMLI,EAAAC,cAAAD,EAAAK,SAAA,KACGb,EAAMM,SAASQ,IAAIV,GAAWW,gBACzBf,EAAMgB,eAAeD,IAAUA,EAAME,OAASC,eAE9CV,EAAAC,cAACC,EAADC,EAAA,GAAeN,EAAf,CAA0BO,IAAKT,IAC5BY,EAAMb,MAAME,UAKZW,uBAMfhB,EAAKoB,YAAc,OAQnB,MAAMC,eAAYpB,EAAMC,YAAgC,CAACC,EAAOC,KAC9D,MAAMC,SAAEA,KAAaC,GAAcH,EAC7Ba,EAAQf,EAAMM,SAASe,KAAKjB,gBAElC,OAAOJ,EAAMgB,eAAeD,gBACxBf,EAAMsB,aAAaP,EAAO,IACrBQ,EAAWlB,EAAWU,EAAMb,OAC/BU,IAAKY,EAAYrB,EAAeY,EAAcH,OAEhD,QAGNQ,EAAUD,YAAc,YAMxB,MAAMD,EAAY,EAAGd,SAAAA,KACZA,EAOT,SAASmB,EAAWlB,EAAqBoB,GAEvC,MAAMC,EAAgB,IAAKD,GAG3B,IAAK,MAAME,KAAYF,EAAY,CACjC,MAAMG,EAAgBvB,EAAUsB,GAC1BE,EAAiBJ,EAAWE,GAChB,WAAWG,KAAKH,KAGhCD,EAAcC,GAAYI,EAAqBF,EAAgBD,IAInE,MAAO,IAAKvB,KAAcqB,uBAG5B,MAAMM,EAAOjC","sources":["./node_modules/@parcel/scope-hoisting/lib/helpers.js","./packages/react/slot/src/Slot.tsx"],"sourcesContent":["function $parcel$interopDefault(a) {\n return a && a.__esModule ? a.default : a;\n}\n\nfunction $parcel$defineInteropFlag(a) {\n Object.defineProperty(a, '__esModule', {value: true});\n}\n\nfunction $parcel$reexport(e, n, v) {\n Object.defineProperty(e, n, {get: v, enumerable: true});\n}\n\nfunction $parcel$exportWildcard(dest, source) {\n Object.keys(source).forEach(function(key) {\n if (key === 'default' || key === '__esModule') {\n return;\n }\n\n Object.defineProperty(dest, key, {\n enumerable: true,\n get: function get() {\n return source[key];\n },\n });\n });\n\n return dest;\n}\n\nfunction $parcel$missingModule(name) {\n var err = new Error(\"Cannot find module '\" + name + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n}\n\nvar $parcel$global =\n typeof globalThis !== 'undefined'\n ? globalThis\n : typeof self !== 'undefined'\n ? self\n : typeof window !== 'undefined'\n ? window\n : typeof global !== 'undefined'\n ? global\n : {};\n","import * as React from 'react';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { composeRefs } from '@radix-ui/react-compose-refs';\n\n/* -------------------------------------------------------------------------------------------------\n * Slot\n * -----------------------------------------------------------------------------------------------*/\n\ntype SlotProps = { children: React.ReactNode };\n\nconst Slot = React.forwardRef<HTMLElement, SlotProps>((props, forwardedRef) => {\n const { children, ...slotProps } = props;\n const childLength = React.Children.count(children);\n\n if (childLength === 1) {\n return (\n <SlotClone {...slotProps} ref={forwardedRef}>\n {children}\n </SlotClone>\n );\n }\n\n return (\n <>\n {React.Children.map(children, (child) => {\n if (React.isValidElement(child) && child.type === Slottable) {\n return (\n <SlotClone {...slotProps} ref={forwardedRef}>\n {child.props.children}\n </SlotClone>\n );\n }\n\n return child;\n })}\n </>\n );\n});\n\nSlot.displayName = 'Slot';\n\n/* -------------------------------------------------------------------------------------------------\n * SlotClone\n * -----------------------------------------------------------------------------------------------*/\n\ntype SlotCloneProps = { children: React.ReactNode };\n\nconst SlotClone = React.forwardRef<any, SlotCloneProps>((props, forwardedRef) => {\n const { children, ...slotProps } = props;\n const child = React.Children.only(children);\n\n return React.isValidElement(child)\n ? React.cloneElement(child, {\n ...mergeProps(slotProps, child.props),\n ref: composeRefs(forwardedRef, (child as any).ref),\n })\n : null;\n});\n\nSlotClone.displayName = 'SlotClone';\n\n/* -------------------------------------------------------------------------------------------------\n * Slottable\n * -----------------------------------------------------------------------------------------------*/\n\nconst Slottable = ({ children }: { children: React.ReactNode }) => {\n return children as React.ReactElement;\n};\n\n/* ---------------------------------------------------------------------------------------------- */\n\ntype AnyProps = Record<string, any>;\n\nfunction mergeProps(slotProps: AnyProps, childProps: AnyProps) {\n // all child props should override\n const overrideProps = { ...childProps };\n\n // if it's a handler, modify the override by composing the base handler\n for (const propName in childProps) {\n const slotPropValue = slotProps[propName];\n const childPropValue = childProps[propName];\n const isHandler = /^on[A-Z]/.test(propName);\n\n if (isHandler) {\n overrideProps[propName] = composeEventHandlers(childPropValue, slotPropValue);\n }\n }\n\n return { ...slotProps, ...overrideProps };\n}\n\nconst Root = Slot;\n\nexport {\n Slot,\n Slottable,\n //\n Root,\n};\n"],"names":["dest","source","a","Object","keys","forEach","key","defineProperty","enumerable","get","__esModule","default","Slot","React","forwardRef","props","forwardedRef","children","slotProps","Children","count","_react","createElement","$bd3c7a2329cce5affa12c89d44fd473$var$SlotClone","_babelRuntimeHelpersExtends","ref","Fragment","map","child","isValidElement","type","Slottable","displayName","SlotClone","only","cloneElement","mergeProps","composeRefs","childProps","overrideProps","propName","slotPropValue","childPropValue","test","composeEventHandlers","Root"],"version":3,"file":"index.js.map"}
@@ -1,2 +1,2 @@
1
- function t(t,o,e){Object.defineProperty(t,o,{get:e,enumerable:!0})}import{composeRefs as o}from"@radix-ui/react-compose-refs";import{composeEventHandlers as e}from"@radix-ui/primitive";import{forwardRef as r,Children as n,createElement as l,Fragment as i,isValidElement as c,cloneElement as p}from"react";import s from"@babel/runtime/helpers/esm/extends";var u={};export const Slot=r(((t,o)=>{const{children:e,...r}=t;return 1===n.count(e)?l(a,s({},r,{ref:o}),e):l(i,null,n.map(e,(t=>c(t)&&t.type===Slottable?l(a,s({},r,{ref:o}),t.props.children):t)))}));Slot.displayName="Slot";const a=r(((t,e)=>{const{children:r,...l}=t,i=n.only(r);return c(i)?p(i,{...f(l,i.props),ref:o(e,i.ref)}):null}));a.displayName="SlotClone";export const Slottable=({children:t})=>t;function f(t,o){const r={...o};for(const n in o){const l=t[n],i=o[n];/^on[A-Z]/.test(n)&&(r[n]=e(i,l))}return{...t,...r}}export const Root=Slot;t(u,"Root",(function(){return Root})),t(u,"Slottable",(function(){return Slottable})),t(u,"Slot",(function(){return Slot}));
1
+ import{composeRefs as e}from"@radix-ui/react-compose-refs";import{composeEventHandlers as t}from"@radix-ui/primitive";import*as r from"react";import o from"@babel/runtime/helpers/esm/extends";export const Slot=/*#__PURE__*/r.forwardRef(((e,t)=>{const{children:l,...i}=e;return 1===r.Children.count(l)?/*#__PURE__*/r.createElement(n,o({},i,{ref:t}),l):/*#__PURE__*/r.createElement(r.Fragment,null,r.Children.map(l,(e=>/*#__PURE__*/r.isValidElement(e)&&e.type===Slottable?/*#__PURE__*/r.createElement(n,o({},i,{ref:t}),e.props.children):e)))}));Slot.displayName="Slot";const n=/*#__PURE__*/r.forwardRef(((t,o)=>{const{children:n,...i}=t,c=r.Children.only(n);/*#__PURE__*/return r.isValidElement(c)?/*#__PURE__*/r.cloneElement(c,{...l(i,c.props),ref:e(o,c.ref)}):null}));n.displayName="SlotClone";export const Slottable=({children:e})=>e;function l(e,r){const o={...r};for(const n in r){const l=e[n],i=r[n];/^on[A-Z]/.test(n)&&(o[n]=t(i,l))}return{...e,...o}}export const Root=Slot;
2
2
  //# sourceMappingURL=index.module.js.map
@@ -1 +1 @@
1
- {"mappings":"AAmBA,SAAAA,EAAwBC,EAAGC,EAAGC,GAC5BC,OAAOC,eAAeJ,EAAGC,EAAAA,CAAII,IAAKH,EAAGI,YAAY,0TCV7CC,KAAAA,GAA0C,CAACC,EAAOC,oBAC9CC,KAAaC,GAAcH,SAGf,IAFdI,EAA6BC,MAAMH,KAIpCI,EAAAA,EAAAA,GAAcH,EAAAA,CAAWI,IAAKN,IAC5BC,cAOaM,IAAIN,GAAWO,KACJA,IAAUA,EAAMC,OAASC,YAE7CL,EAAAA,EAAAA,GAAcH,EAAAA,CAAWI,IAAKN,IAC5BQ,EAAMT,MAAME,UAKZO,QAMfV,KAAKa,YAAc,aAQbN,EAAAA,GAAkD,CAACN,EAAOC,oBACtDC,KAAaC,GAAcH,EAC7BS,EAAAA,EAAuBI,KAAKX,YAENO,GAAAA,EACLA,EAAAA,IACdK,EAAWX,EAAWM,EAAMT,OAC/BO,IAAKQ,EAAYd,EAAeQ,EAAcF,OAEhD,QAGND,EAAUM,YAAc,yBAMlBD,UAAY,EAAGT,SAAAA,KACZA,EAOT,SAAAY,EAAoBX,EAAqBa,SAEjCC,EAAAA,IAAqBD,aAGhBE,KAAYF,EAAAA,OACfG,EAAgBhB,EAAUe,GAC1BE,EAAiBJ,EAAWE,GAC5BG,WAAuBC,KAAKJ,KAGhCD,EAAcC,GAAYK,EAAqBH,EAAgBD,cAIvDhB,KAAcc,gBAGtBO,KAAOzB","sources":["./node_modules/@parcel/scope-hoisting/lib/helpers.js","./packages/react/slot/src/Slot.tsx"],"sourcesContent":["var $parcel$global =\n typeof globalThis !== 'undefined'\n ? globalThis\n : typeof self !== 'undefined'\n ? self\n : typeof window !== 'undefined'\n ? window\n : typeof global !== 'undefined'\n ? global\n : {};\n\nfunction $parcel$interopDefault(a) {\n return a && a.__esModule ? a.default : a;\n}\n\nfunction $parcel$defineInteropFlag(a) {\n Object.defineProperty(a, '__esModule', {value: true});\n}\n\nfunction $parcel$export(e, n, v) {\n Object.defineProperty(e, n, {get: v, enumerable: true});\n}\n\nfunction $parcel$exportWildcard(dest, source) {\n Object.keys(source).forEach(function(key) {\n if (key === 'default' || key === '__esModule') {\n return;\n }\n\n Object.defineProperty(dest, key, {\n enumerable: true,\n get: function get() {\n return source[key];\n },\n });\n });\n\n return dest;\n}\n\nfunction $parcel$missingModule(name) {\n var err = new Error(\"Cannot find module '\" + name + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n}\n","import * as React from 'react';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { composeRefs } from '@radix-ui/react-compose-refs';\n\n/* -------------------------------------------------------------------------------------------------\n * Slot\n * -----------------------------------------------------------------------------------------------*/\n\ntype SlotProps = { children: React.ReactNode };\n\nconst Slot = React.forwardRef<never, SlotProps>((props, forwardedRef) => {\n const { children, ...slotProps } = props;\n const childLength = React.Children.count(children);\n\n if (childLength === 1) {\n return (\n <SlotClone {...slotProps} ref={forwardedRef}>\n {children}\n </SlotClone>\n );\n }\n\n return (\n <>\n {React.Children.map(children, (child) => {\n if (React.isValidElement(child) && child.type === Slottable) {\n return (\n <SlotClone {...slotProps} ref={forwardedRef}>\n {child.props.children}\n </SlotClone>\n );\n }\n\n return child;\n })}\n </>\n );\n});\n\nSlot.displayName = 'Slot';\n\n/* -------------------------------------------------------------------------------------------------\n * SlotClone\n * -----------------------------------------------------------------------------------------------*/\n\ntype SlotCloneProps = { children: React.ReactNode };\n\nconst SlotClone = React.forwardRef<any, SlotCloneProps>((props, forwardedRef) => {\n const { children, ...slotProps } = props;\n const child = React.Children.only(children);\n\n return React.isValidElement(child)\n ? React.cloneElement(child, {\n ...mergeProps(slotProps, child.props),\n ref: composeRefs(forwardedRef, (child as any).ref),\n })\n : null;\n});\n\nSlotClone.displayName = 'SlotClone';\n\n/* -------------------------------------------------------------------------------------------------\n * Slottable\n * -----------------------------------------------------------------------------------------------*/\n\nconst Slottable = ({ children }: { children: React.ReactNode }) => {\n return children as React.ReactElement;\n};\n\n/* ---------------------------------------------------------------------------------------------- */\n\ntype AnyProps = Record<string, any>;\n\nfunction mergeProps(slotProps: AnyProps, childProps: AnyProps) {\n // all child props should override\n const overrideProps = { ...childProps };\n\n // if it's a handler, modify the override by composing the base handler\n for (const propName in childProps) {\n const slotPropValue = slotProps[propName];\n const childPropValue = childProps[propName];\n const isHandler = /^on[A-Z]/.test(propName);\n\n if (isHandler) {\n overrideProps[propName] = composeEventHandlers(childPropValue, slotPropValue);\n }\n }\n\n return { ...slotProps, ...overrideProps };\n}\n\nconst Root = Slot;\n\nexport {\n Slot,\n Slottable,\n //\n Root,\n};\n"],"names":["$parcel$export","e","n","v","Object","defineProperty","get","enumerable","Slot","props","forwardedRef","children","slotProps","childLength","count","$de6a1431c6870217be1f53fae243cc20$var$SlotClone","ref","map","child","type","Slottable","displayName","only","$de6a1431c6870217be1f53fae243cc20$var$mergeProps","composeRefs","childProps","overrideProps","propName","slotPropValue","childPropValue","isHandler","test","composeEventHandlers","Root"],"version":3,"file":"index.module.js.map"}
1
+ {"mappings":"uMAUA,MAAMA,kBAAOC,EAAMC,YAAmC,CAACC,EAAOC,KAC5D,MAAMC,SAAEA,KAAaC,GAAcH,EAGnC,OAAoB,IAFAF,EAAMM,SAASC,MAAMH,gBAIrCI,EAAAC,cAACC,EAADC,EAAA,GAAeN,EAAf,CAA0BO,IAAKT,IAC5BC,gBAMLI,EAAAC,cAAAD,EAAAK,SAAA,KACGb,EAAMM,SAASQ,IAAIV,GAAWW,gBACzBf,EAAMgB,eAAeD,IAAUA,EAAME,OAASC,uBAE9CV,EAAAC,cAACC,EAADC,EAAA,GAAeN,EAAf,CAA0BO,IAAKT,IAC5BY,EAAMb,MAAME,UAKZW,QAMfhB,KAAKoB,YAAc,OAQnB,MAAMC,eAAYpB,EAAMC,YAAgC,CAACC,EAAOC,KAC9D,MAAMC,SAAEA,KAAaC,GAAcH,EAC7Ba,EAAQf,EAAMM,SAASe,KAAKjB,gBAElC,OAAOJ,EAAMgB,eAAeD,gBACxBf,EAAMsB,aAAaP,EAAO,IACrBQ,EAAWlB,EAAWU,EAAMb,OAC/BU,IAAKY,EAAYrB,EAAeY,EAAcH,OAEhD,QAGNQ,EAAUD,YAAc,mBAMxB,MAAMD,UAAY,EAAGd,SAAAA,KACZA,EAOT,SAASmB,EAAWlB,EAAqBoB,GAEvC,MAAMC,EAAgB,IAAKD,GAG3B,IAAK,MAAME,KAAYF,EAAY,CACjC,MAAMG,EAAgBvB,EAAUsB,GAC1BE,EAAiBJ,EAAWE,GAChB,WAAWG,KAAKH,KAGhCD,EAAcC,GAAYI,EAAqBF,EAAgBD,IAInE,MAAO,IAAKvB,KAAcqB,UAG5B,MAAMM,KAAOjC","sources":["./packages/react/slot/src/Slot.tsx"],"sourcesContent":["import * as React from 'react';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { composeRefs } from '@radix-ui/react-compose-refs';\n\n/* -------------------------------------------------------------------------------------------------\n * Slot\n * -----------------------------------------------------------------------------------------------*/\n\ntype SlotProps = { children: React.ReactNode };\n\nconst Slot = React.forwardRef<HTMLElement, SlotProps>((props, forwardedRef) => {\n const { children, ...slotProps } = props;\n const childLength = React.Children.count(children);\n\n if (childLength === 1) {\n return (\n <SlotClone {...slotProps} ref={forwardedRef}>\n {children}\n </SlotClone>\n );\n }\n\n return (\n <>\n {React.Children.map(children, (child) => {\n if (React.isValidElement(child) && child.type === Slottable) {\n return (\n <SlotClone {...slotProps} ref={forwardedRef}>\n {child.props.children}\n </SlotClone>\n );\n }\n\n return child;\n })}\n </>\n );\n});\n\nSlot.displayName = 'Slot';\n\n/* -------------------------------------------------------------------------------------------------\n * SlotClone\n * -----------------------------------------------------------------------------------------------*/\n\ntype SlotCloneProps = { children: React.ReactNode };\n\nconst SlotClone = React.forwardRef<any, SlotCloneProps>((props, forwardedRef) => {\n const { children, ...slotProps } = props;\n const child = React.Children.only(children);\n\n return React.isValidElement(child)\n ? React.cloneElement(child, {\n ...mergeProps(slotProps, child.props),\n ref: composeRefs(forwardedRef, (child as any).ref),\n })\n : null;\n});\n\nSlotClone.displayName = 'SlotClone';\n\n/* -------------------------------------------------------------------------------------------------\n * Slottable\n * -----------------------------------------------------------------------------------------------*/\n\nconst Slottable = ({ children }: { children: React.ReactNode }) => {\n return children as React.ReactElement;\n};\n\n/* ---------------------------------------------------------------------------------------------- */\n\ntype AnyProps = Record<string, any>;\n\nfunction mergeProps(slotProps: AnyProps, childProps: AnyProps) {\n // all child props should override\n const overrideProps = { ...childProps };\n\n // if it's a handler, modify the override by composing the base handler\n for (const propName in childProps) {\n const slotPropValue = slotProps[propName];\n const childPropValue = childProps[propName];\n const isHandler = /^on[A-Z]/.test(propName);\n\n if (isHandler) {\n overrideProps[propName] = composeEventHandlers(childPropValue, slotPropValue);\n }\n }\n\n return { ...slotProps, ...overrideProps };\n}\n\nconst Root = Slot;\n\nexport {\n Slot,\n Slottable,\n //\n Root,\n};\n"],"names":["Slot","React","forwardRef","props","forwardedRef","children","slotProps","Children","count","_react","createElement","$d34e8c328cb3dd19ab7a2f6eafa6ad$var$SlotClone","_babelRuntimeHelpersEsmExtends","ref","Fragment","map","child","isValidElement","type","Slottable","displayName","SlotClone","only","cloneElement","mergeProps","composeRefs","childProps","overrideProps","propName","slotPropValue","childPropValue","test","composeEventHandlers","Root"],"version":3,"file":"index.module.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radix-ui/react-slot",
3
- "version": "0.0.6",
3
+ "version": "0.0.10",
4
4
  "license": "MIT",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",
@@ -18,8 +18,8 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@babel/runtime": "^7.13.10",
21
- "@radix-ui/primitive": "0.0.2",
22
- "@radix-ui/react-compose-refs": "0.0.2"
21
+ "@radix-ui/primitive": "0.0.5",
22
+ "@radix-ui/react-compose-refs": "0.0.5"
23
23
  },
24
24
  "peerDependencies": {
25
25
  "react": "^16.8 || ^17.0"