@radix-ui/react-slot 0.1.1 → 0.1.2-rc.4

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.
@@ -1 +1 @@
1
- {"mappings":"A;AAOA,0BAAoB,SAAQ,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC;IAC3D,QAAQ,CAAC,EAAE,MAAM,SAAS,CAAC;CAC5B;AAED,OAAA,MAAM,mFAyBJ,CAAC;AA+BH,OAAA,MAAM;cAAuC,MAAM,SAAS;iBAE3D,CAAC;AAqCF,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"}
1
+ {"mappings":"A;AAOA,0BAAoB,SAAQ,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC;IAC3D,QAAQ,CAAC,EAAE,MAAM,SAAS,CAAC;CAC5B;AAED,OAAA,MAAM,mFAwBJ,CAAC;AA+BH,OAAA,MAAM;cAAuC,MAAM,SAAS;iBAE3D,CAAC;AAqCF,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
- var e,r,t,n=require("@radix-ui/react-compose-refs").composeRefs,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),o=(t=require("@babel/runtime/helpers/extends"))&&t.__esModule?t.default:t;const s=/*#__PURE__*/l.forwardRef(((e,r)=>{const{children:t,...n}=e,s=l.Children.toArray(t);return s.some(i)?/*#__PURE__*/l.createElement(l.Fragment,null,s.map((e=>i(e)?/*#__PURE__*/l.createElement(c,o({},n,{ref:r}),e.props.children):e))):/*#__PURE__*/l.createElement(c,o({},n,{ref:r}),t)}));exports.Slot=s,s.displayName="Slot";const c=/*#__PURE__*/l.forwardRef(((e,r)=>{const{children:t,...o}=e;/*#__PURE__*/return l.isValidElement(t)?/*#__PURE__*/l.cloneElement(t,{...u(o,t.props),ref:n(r,t.ref)}):l.Children.count(t)>1?l.Children.only(null):null}));c.displayName="SlotClone";const a=({children:e})=>/*#__PURE__*/l.createElement(l.Fragment,null,e);function i(e){/*#__PURE__*/return l.isValidElement(e)&&e.type===a}function u(e,r){const t={...r};for(const n in r){const l=e[n],o=r[n];/^on[A-Z]/.test(n)?t[n]=(...e)=>{null==o||o(...e),null==l||l(...e)}:"style"===n?t[n]={...l,...o}:"className"===n&&(t[n]=[l,o].filter(Boolean).join(" "))}return{...e,...t}}exports.Slottable=a;const d=s;exports.Root=d;
1
+ var e,r,n,t=require("@radix-ui/react-compose-refs").composeRefs,l=(e={},r=require("react"),Object.keys(r).forEach((function(n){"default"!==n&&"__esModule"!==n&&Object.defineProperty(e,n,{enumerable:!0,get:function(){return r[n]}})})),e),o=(n=require("@babel/runtime/helpers/extends"))&&n.__esModule?n.default:n;const s=/*#__PURE__*/l.forwardRef(((e,r)=>{const{children:n,...t}=e;return l.Children.toArray(n).some(i)?/*#__PURE__*/l.createElement(l.Fragment,null,l.Children.map(n,(e=>i(e)?/*#__PURE__*/l.createElement(c,o({},t,{ref:r}),e.props.children):e))):/*#__PURE__*/l.createElement(c,o({},t,{ref:r}),n)}));exports.Slot=s,s.displayName="Slot";const c=/*#__PURE__*/l.forwardRef(((e,r)=>{const{children:n,...o}=e;/*#__PURE__*/return l.isValidElement(n)?/*#__PURE__*/l.cloneElement(n,{...u(o,n.props),ref:t(r,n.ref)}):l.Children.count(n)>1?l.Children.only(null):null}));c.displayName="SlotClone";const a=({children:e})=>/*#__PURE__*/l.createElement(l.Fragment,null,e);function i(e){/*#__PURE__*/return l.isValidElement(e)&&e.type===a}function u(e,r){const n={...r};for(const t in r){const l=e[t],o=r[t];/^on[A-Z]/.test(t)?n[t]=(...e)=>{null==o||o(...e),null==l||l(...e)}:"style"===t?n[t]={...l,...o}:"className"===t&&(n[t]=[l,o].filter(Boolean).join(" "))}return{...e,...n}}exports.Slottable=a;const d=s;exports.Root=d;
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":"IAYgCA,EAAMC,EAZNC,2DAYAF,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,ECUzC,MAAMU,eAAOC,EAAMC,YAAmC,CAACC,EAAOC,KAC5D,MAAMC,SAAEA,KAAaC,GAAcH,EAC7BI,EAAaN,EAAMO,SAASC,QAAQJ,GAE1C,OAAIE,EAAWG,KAAKC,gBAEhBC,EAAAC,cAAAD,EAAAE,SAAA,KACGP,EAAWQ,KAAKC,GACRL,EAAYK,gBACjBJ,EAAAC,cAACI,EAADC,EAAA,GAAeZ,EAAf,CAA0Ba,IAAKf,IAC5BY,EAAMb,MAAME,UAGfW,kBAQRJ,EAAAC,cAACI,EAADC,EAAA,GAAeZ,EAAf,CAA0Ba,IAAKf,IAC5BC,qBAKPL,EAAKoB,YAAc,OAUnB,MAAMC,eAAYpB,EAAMC,YAAgC,CAACC,EAAOC,KAC9D,MAAMC,SAAEA,KAAaC,GAAcH,eAEnC,OAAIF,EAAMqB,eAAejB,gBAChBJ,EAAMsB,aAAalB,EAAU,IAC/BmB,EAAWlB,EAAWD,EAASF,OAClCgB,IAAKM,EAAYrB,EAAeC,EAAiBc,OAI9ClB,EAAMO,SAASkB,MAAMrB,GAAY,EAAIJ,EAAMO,SAASmB,KAAK,MAAQ,QAG1EN,EAAUD,YAAc,YAMxB,MAAMQ,EAAY,EAAGvB,SAAAA,kBACZO,EAAAC,cAAAD,EAAAE,SAAA,KAAGT,GAOZ,SAASM,EAAYK,gBACnB,OAAOf,EAAMqB,eAAeN,IAAUA,EAAMa,OAASD,EAGvD,SAASJ,EAAWlB,EAAqBwB,GAEvC,MAAMC,EAAgB,IAAKD,GAE3B,IAAK,MAAME,KAAYF,EAAY,CACjC,MAAMG,EAAgB3B,EAAU0B,GAC1BE,EAAiBJ,EAAWE,GAEhB,WAAWG,KAAKH,GAGhCD,EAAcC,GAAY,IAAII,KAC5BF,MAAAA,GAAAA,KAAoBE,GACpBH,MAAAA,GAAAA,KAAmBG,IAID,UAAbJ,EACPD,EAAcC,GAAY,IAAKC,KAAkBC,GAC3B,cAAbF,IACTD,EAAcC,GAAY,CAACC,EAAeC,GAAgBG,OAAOC,SAASC,KAAK,MAInF,MAAO,IAAKjC,KAAcyB,uBAG5B,MAAMS,EAAOxC","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 { composeRefs } from '@radix-ui/react-compose-refs';\n\n/* -------------------------------------------------------------------------------------------------\n * Slot\n * -----------------------------------------------------------------------------------------------*/\n\ninterface SlotProps extends React.HTMLAttributes<HTMLElement> {\n children?: React.ReactNode;\n}\n\nconst Slot = React.forwardRef<HTMLElement, SlotProps>((props, forwardedRef) => {\n const { children, ...slotProps } = props;\n const childArray = React.Children.toArray(children);\n\n if (childArray.some(isSlottable)) {\n return (\n <>\n {childArray.map((child) => {\n return isSlottable(child) ? (\n <SlotClone {...slotProps} ref={forwardedRef}>\n {child.props.children}\n </SlotClone>\n ) : (\n child\n );\n })}\n </>\n );\n }\n\n return (\n <SlotClone {...slotProps} ref={forwardedRef}>\n {children}\n </SlotClone>\n );\n});\n\nSlot.displayName = 'Slot';\n\n/* -------------------------------------------------------------------------------------------------\n * SlotClone\n * -----------------------------------------------------------------------------------------------*/\n\ninterface SlotCloneProps {\n children: React.ReactNode;\n}\n\nconst SlotClone = React.forwardRef<any, SlotCloneProps>((props, forwardedRef) => {\n const { children, ...slotProps } = props;\n\n if (React.isValidElement(children)) {\n return React.cloneElement(children, {\n ...mergeProps(slotProps, children.props),\n ref: composeRefs(forwardedRef, (children as any).ref),\n });\n }\n\n return React.Children.count(children) > 1 ? React.Children.only(null) : null;\n});\n\nSlotClone.displayName = 'SlotClone';\n\n/* -------------------------------------------------------------------------------------------------\n * Slottable\n * -----------------------------------------------------------------------------------------------*/\n\nconst Slottable = ({ children }: { children: React.ReactNode }) => {\n return <>{children}</>;\n};\n\n/* ---------------------------------------------------------------------------------------------- */\n\ntype AnyProps = Record<string, any>;\n\nfunction isSlottable(child: React.ReactNode): child is React.ReactElement {\n return React.isValidElement(child) && child.type === Slottable;\n}\n\nfunction mergeProps(slotProps: AnyProps, childProps: AnyProps) {\n // all child props should override\n const overrideProps = { ...childProps };\n\n for (const propName in childProps) {\n const slotPropValue = slotProps[propName];\n const childPropValue = childProps[propName];\n\n const isHandler = /^on[A-Z]/.test(propName);\n // if it's a handler, modify the override by composing the base handler\n if (isHandler) {\n overrideProps[propName] = (...args: unknown[]) => {\n childPropValue?.(...args);\n slotPropValue?.(...args);\n };\n }\n // if it's `style`, we merge them\n else if (propName === 'style') {\n overrideProps[propName] = { ...slotPropValue, ...childPropValue };\n } else if (propName === 'className') {\n overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(' ');\n }\n }\n\n return { ...slotProps, ...overrideProps };\n}\n\nconst Root = Slot;\n\nexport {\n Slot,\n Slottable,\n //\n Root,\n};\nexport type { SlotProps };\n"],"names":["dest","source","a","Object","keys","forEach","key","defineProperty","enumerable","get","__esModule","default","Slot","React","forwardRef","props","forwardedRef","children","slotProps","childArray","Children","toArray","some","isSlottable","_react","createElement","Fragment","map","child","$bd3c7a2329cce5affa12c89d44fd473$var$SlotClone","_babelRuntimeHelpersExtends","ref","displayName","SlotClone","isValidElement","cloneElement","mergeProps","composeRefs","count","only","Slottable","type","childProps","overrideProps","propName","slotPropValue","childPropValue","test","args","filter","Boolean","join","Root"],"version":3,"file":"index.js.map"}
1
+ {"mappings":"IAYgCA,EAAMC,EAZNC,2DAYAF,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,ECUzC,MAAMU,eAAOC,EAAMC,YAAmC,CAACC,EAAOC,KAC5D,MAAMC,SAAEA,KAAaC,GAAcH,EAEnC,OAAIF,EAAMM,SAASC,QAAQH,GAAUI,KAAKC,gBAEtCC,EAAAC,cAAAD,EAAAE,SAAA,KACGZ,EAAMM,SAASO,IAAIT,GAAWU,GACtBL,EAAYK,gBACjBJ,EAAAC,cAACI,EAADC,EAAA,GAAeX,EAAf,CAA0BY,IAAKd,IAC5BW,EAAMZ,MAAME,UAGfU,kBAQRJ,EAAAC,cAACI,EAADC,EAAA,GAAeX,EAAf,CAA0BY,IAAKd,IAC5BC,qBAKPL,EAAKmB,YAAc,OAUnB,MAAMC,eAAYnB,EAAMC,YAAgC,CAACC,EAAOC,KAC9D,MAAMC,SAAEA,KAAaC,GAAcH,eAEnC,OAAIF,EAAMoB,eAAehB,gBAChBJ,EAAMqB,aAAajB,EAAU,IAC/BkB,EAAWjB,EAAWD,EAASF,OAClCe,IAAKM,EAAYpB,EAAeC,EAAiBa,OAI9CjB,EAAMM,SAASkB,MAAMpB,GAAY,EAAIJ,EAAMM,SAASmB,KAAK,MAAQ,QAG1EN,EAAUD,YAAc,YAMxB,MAAMQ,EAAY,EAAGtB,SAAAA,kBACZM,EAAAC,cAAAD,EAAAE,SAAA,KAAGR,GAOZ,SAASK,EAAYK,gBACnB,OAAOd,EAAMoB,eAAeN,IAAUA,EAAMa,OAASD,EAGvD,SAASJ,EAAWjB,EAAqBuB,GAEvC,MAAMC,EAAgB,IAAKD,GAE3B,IAAK,MAAME,KAAYF,EAAY,CACjC,MAAMG,EAAgB1B,EAAUyB,GAC1BE,EAAiBJ,EAAWE,GAEhB,WAAWG,KAAKH,GAGhCD,EAAcC,GAAY,IAAII,KAC5BF,MAAAA,GAAAA,KAAoBE,GACpBH,MAAAA,GAAAA,KAAmBG,IAID,UAAbJ,EACPD,EAAcC,GAAY,IAAKC,KAAkBC,GAC3B,cAAbF,IACTD,EAAcC,GAAY,CAACC,EAAeC,GAAgBG,OAAOC,SAASC,KAAK,MAInF,MAAO,IAAKhC,KAAcwB,uBAG5B,MAAMS,EAAOvC","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 { composeRefs } from '@radix-ui/react-compose-refs';\n\n/* -------------------------------------------------------------------------------------------------\n * Slot\n * -----------------------------------------------------------------------------------------------*/\n\ninterface SlotProps extends React.HTMLAttributes<HTMLElement> {\n children?: React.ReactNode;\n}\n\nconst Slot = React.forwardRef<HTMLElement, SlotProps>((props, forwardedRef) => {\n const { children, ...slotProps } = props;\n\n if (React.Children.toArray(children).some(isSlottable)) {\n return (\n <>\n {React.Children.map(children, (child) => {\n return isSlottable(child) ? (\n <SlotClone {...slotProps} ref={forwardedRef}>\n {child.props.children}\n </SlotClone>\n ) : (\n child\n );\n })}\n </>\n );\n }\n\n return (\n <SlotClone {...slotProps} ref={forwardedRef}>\n {children}\n </SlotClone>\n );\n});\n\nSlot.displayName = 'Slot';\n\n/* -------------------------------------------------------------------------------------------------\n * SlotClone\n * -----------------------------------------------------------------------------------------------*/\n\ninterface SlotCloneProps {\n children: React.ReactNode;\n}\n\nconst SlotClone = React.forwardRef<any, SlotCloneProps>((props, forwardedRef) => {\n const { children, ...slotProps } = props;\n\n if (React.isValidElement(children)) {\n return React.cloneElement(children, {\n ...mergeProps(slotProps, children.props),\n ref: composeRefs(forwardedRef, (children as any).ref),\n });\n }\n\n return React.Children.count(children) > 1 ? React.Children.only(null) : null;\n});\n\nSlotClone.displayName = 'SlotClone';\n\n/* -------------------------------------------------------------------------------------------------\n * Slottable\n * -----------------------------------------------------------------------------------------------*/\n\nconst Slottable = ({ children }: { children: React.ReactNode }) => {\n return <>{children}</>;\n};\n\n/* ---------------------------------------------------------------------------------------------- */\n\ntype AnyProps = Record<string, any>;\n\nfunction isSlottable(child: React.ReactNode): child is React.ReactElement {\n return React.isValidElement(child) && child.type === Slottable;\n}\n\nfunction mergeProps(slotProps: AnyProps, childProps: AnyProps) {\n // all child props should override\n const overrideProps = { ...childProps };\n\n for (const propName in childProps) {\n const slotPropValue = slotProps[propName];\n const childPropValue = childProps[propName];\n\n const isHandler = /^on[A-Z]/.test(propName);\n // if it's a handler, modify the override by composing the base handler\n if (isHandler) {\n overrideProps[propName] = (...args: unknown[]) => {\n childPropValue?.(...args);\n slotPropValue?.(...args);\n };\n }\n // if it's `style`, we merge them\n else if (propName === 'style') {\n overrideProps[propName] = { ...slotPropValue, ...childPropValue };\n } else if (propName === 'className') {\n overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(' ');\n }\n }\n\n return { ...slotProps, ...overrideProps };\n}\n\nconst Root = Slot;\n\nexport {\n Slot,\n Slottable,\n //\n Root,\n};\nexport type { SlotProps };\n"],"names":["dest","source","a","Object","keys","forEach","key","defineProperty","enumerable","get","__esModule","default","Slot","React","forwardRef","props","forwardedRef","children","slotProps","Children","toArray","some","isSlottable","_react","createElement","Fragment","map","child","$bd3c7a2329cce5affa12c89d44fd473$var$SlotClone","_babelRuntimeHelpersExtends","ref","displayName","SlotClone","isValidElement","cloneElement","mergeProps","composeRefs","count","only","Slottable","type","childProps","overrideProps","propName","slotPropValue","childPropValue","test","args","filter","Boolean","join","Root"],"version":3,"file":"index.js.map"}
@@ -1,2 +1,2 @@
1
- import{composeRefs as e}from"@radix-ui/react-compose-refs";import*as t from"react";import r from"@babel/runtime/helpers/esm/extends";export const Slot=/*#__PURE__*/t.forwardRef(((e,o)=>{const{children:a,...s}=e,c=t.Children.toArray(a);return c.some(l)?/*#__PURE__*/t.createElement(t.Fragment,null,c.map((e=>l(e)?/*#__PURE__*/t.createElement(n,r({},s,{ref:o}),e.props.children):e))):/*#__PURE__*/t.createElement(n,r({},s,{ref:o}),a)}));Slot.displayName="Slot";const n=/*#__PURE__*/t.forwardRef(((r,n)=>{const{children:l,...a}=r;/*#__PURE__*/return t.isValidElement(l)?/*#__PURE__*/t.cloneElement(l,{...o(a,l.props),ref:e(n,l.ref)}):t.Children.count(l)>1?t.Children.only(null):null}));n.displayName="SlotClone";export const Slottable=({children:e})=>/*#__PURE__*/t.createElement(t.Fragment,null,e);function l(e){/*#__PURE__*/return t.isValidElement(e)&&e.type===Slottable}function o(e,t){const r={...t};for(const n in t){const l=e[n],o=t[n];/^on[A-Z]/.test(n)?r[n]=(...e)=>{null==o||o(...e),null==l||l(...e)}:"style"===n?r[n]={...l,...o}:"className"===n&&(r[n]=[l,o].filter(Boolean).join(" "))}return{...e,...r}}export const Root=Slot;
1
+ import{composeRefs as e}from"@radix-ui/react-compose-refs";import*as t from"react";import r from"@babel/runtime/helpers/esm/extends";export const Slot=/*#__PURE__*/t.forwardRef(((e,o)=>{const{children:a,...s}=e;return t.Children.toArray(a).some(l)?/*#__PURE__*/t.createElement(t.Fragment,null,t.Children.map(a,(e=>l(e)?/*#__PURE__*/t.createElement(n,r({},s,{ref:o}),e.props.children):e))):/*#__PURE__*/t.createElement(n,r({},s,{ref:o}),a)}));Slot.displayName="Slot";const n=/*#__PURE__*/t.forwardRef(((r,n)=>{const{children:l,...a}=r;/*#__PURE__*/return t.isValidElement(l)?/*#__PURE__*/t.cloneElement(l,{...o(a,l.props),ref:e(n,l.ref)}):t.Children.count(l)>1?t.Children.only(null):null}));n.displayName="SlotClone";export const Slottable=({children:e})=>/*#__PURE__*/t.createElement(t.Fragment,null,e);function l(e){/*#__PURE__*/return t.isValidElement(e)&&e.type===Slottable}function o(e,t){const r={...t};for(const n in t){const l=e[n],o=t[n];/^on[A-Z]/.test(n)?r[n]=(...e)=>{null==o||o(...e),null==l||l(...e)}:"style"===n?r[n]={...l,...o}:"className"===n&&(r[n]=[l,o].filter(Boolean).join(" "))}return{...e,...r}}export const Root=Slot;
2
2
  //# sourceMappingURL=index.module.js.map
@@ -1 +1 @@
1
- {"mappings":"4IAWA,MAAMA,kBAAOC,EAAMC,YAAmC,CAACC,EAAOC,KAC5D,MAAMC,SAAEA,KAAaC,GAAcH,EAC7BI,EAAaN,EAAMO,SAASC,QAAQJ,GAE1C,OAAIE,EAAWG,KAAKC,gBAEhBC,EAAAC,cAAAD,EAAAE,SAAA,KACGP,EAAWQ,KAAKC,GACRL,EAAYK,gBACjBJ,EAAAC,cAACI,EAADC,EAAA,GAAeZ,EAAf,CAA0Ba,IAAKf,IAC5BY,EAAMb,MAAME,UAGfW,kBAQRJ,EAAAC,cAACI,EAADC,EAAA,GAAeZ,EAAf,CAA0Ba,IAAKf,IAC5BC,MAKPL,KAAKoB,YAAc,OAUnB,MAAMC,eAAYpB,EAAMC,YAAgC,CAACC,EAAOC,KAC9D,MAAMC,SAAEA,KAAaC,GAAcH,eAEnC,OAAIF,EAAMqB,eAAejB,gBAChBJ,EAAMsB,aAAalB,EAAU,IAC/BmB,EAAWlB,EAAWD,EAASF,OAClCgB,IAAKM,EAAYrB,EAAeC,EAAiBc,OAI9ClB,EAAMO,SAASkB,MAAMrB,GAAY,EAAIJ,EAAMO,SAASmB,KAAK,MAAQ,QAG1EN,EAAUD,YAAc,mBAMxB,MAAMQ,UAAY,EAAGvB,SAAAA,kBACZO,EAAAC,cAAAD,EAAAE,SAAA,KAAGT,GAOZ,SAASM,EAAYK,gBACnB,OAAOf,EAAMqB,eAAeN,IAAUA,EAAMa,OAASD,UAGvD,SAASJ,EAAWlB,EAAqBwB,GAEvC,MAAMC,EAAgB,IAAKD,GAE3B,IAAK,MAAME,KAAYF,EAAY,CACjC,MAAMG,EAAgB3B,EAAU0B,GAC1BE,EAAiBJ,EAAWE,GAEhB,WAAWG,KAAKH,GAGhCD,EAAcC,GAAY,IAAII,KAC5BF,MAAAA,GAAAA,KAAoBE,GACpBH,MAAAA,GAAAA,KAAmBG,IAID,UAAbJ,EACPD,EAAcC,GAAY,IAAKC,KAAkBC,GAC3B,cAAbF,IACTD,EAAcC,GAAY,CAACC,EAAeC,GAAgBG,OAAOC,SAASC,KAAK,MAInF,MAAO,IAAKjC,KAAcyB,UAG5B,MAAMS,KAAOxC","sources":["./packages/react/slot/src/Slot.tsx"],"sourcesContent":["import * as React from 'react';\nimport { composeRefs } from '@radix-ui/react-compose-refs';\n\n/* -------------------------------------------------------------------------------------------------\n * Slot\n * -----------------------------------------------------------------------------------------------*/\n\ninterface SlotProps extends React.HTMLAttributes<HTMLElement> {\n children?: React.ReactNode;\n}\n\nconst Slot = React.forwardRef<HTMLElement, SlotProps>((props, forwardedRef) => {\n const { children, ...slotProps } = props;\n const childArray = React.Children.toArray(children);\n\n if (childArray.some(isSlottable)) {\n return (\n <>\n {childArray.map((child) => {\n return isSlottable(child) ? (\n <SlotClone {...slotProps} ref={forwardedRef}>\n {child.props.children}\n </SlotClone>\n ) : (\n child\n );\n })}\n </>\n );\n }\n\n return (\n <SlotClone {...slotProps} ref={forwardedRef}>\n {children}\n </SlotClone>\n );\n});\n\nSlot.displayName = 'Slot';\n\n/* -------------------------------------------------------------------------------------------------\n * SlotClone\n * -----------------------------------------------------------------------------------------------*/\n\ninterface SlotCloneProps {\n children: React.ReactNode;\n}\n\nconst SlotClone = React.forwardRef<any, SlotCloneProps>((props, forwardedRef) => {\n const { children, ...slotProps } = props;\n\n if (React.isValidElement(children)) {\n return React.cloneElement(children, {\n ...mergeProps(slotProps, children.props),\n ref: composeRefs(forwardedRef, (children as any).ref),\n });\n }\n\n return React.Children.count(children) > 1 ? React.Children.only(null) : null;\n});\n\nSlotClone.displayName = 'SlotClone';\n\n/* -------------------------------------------------------------------------------------------------\n * Slottable\n * -----------------------------------------------------------------------------------------------*/\n\nconst Slottable = ({ children }: { children: React.ReactNode }) => {\n return <>{children}</>;\n};\n\n/* ---------------------------------------------------------------------------------------------- */\n\ntype AnyProps = Record<string, any>;\n\nfunction isSlottable(child: React.ReactNode): child is React.ReactElement {\n return React.isValidElement(child) && child.type === Slottable;\n}\n\nfunction mergeProps(slotProps: AnyProps, childProps: AnyProps) {\n // all child props should override\n const overrideProps = { ...childProps };\n\n for (const propName in childProps) {\n const slotPropValue = slotProps[propName];\n const childPropValue = childProps[propName];\n\n const isHandler = /^on[A-Z]/.test(propName);\n // if it's a handler, modify the override by composing the base handler\n if (isHandler) {\n overrideProps[propName] = (...args: unknown[]) => {\n childPropValue?.(...args);\n slotPropValue?.(...args);\n };\n }\n // if it's `style`, we merge them\n else if (propName === 'style') {\n overrideProps[propName] = { ...slotPropValue, ...childPropValue };\n } else if (propName === 'className') {\n overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(' ');\n }\n }\n\n return { ...slotProps, ...overrideProps };\n}\n\nconst Root = Slot;\n\nexport {\n Slot,\n Slottable,\n //\n Root,\n};\nexport type { SlotProps };\n"],"names":["Slot","React","forwardRef","props","forwardedRef","children","slotProps","childArray","Children","toArray","some","isSlottable","_react","createElement","Fragment","map","child","$d34e8c328cb3dd19ab7a2f6eafa6ad$var$SlotClone","_babelRuntimeHelpersEsmExtends","ref","displayName","SlotClone","isValidElement","cloneElement","mergeProps","composeRefs","count","only","Slottable","type","childProps","overrideProps","propName","slotPropValue","childPropValue","test","args","filter","Boolean","join","Root"],"version":3,"file":"index.module.js.map"}
1
+ {"mappings":"4IAWA,MAAMA,kBAAOC,EAAMC,YAAmC,CAACC,EAAOC,KAC5D,MAAMC,SAAEA,KAAaC,GAAcH,EAEnC,OAAIF,EAAMM,SAASC,QAAQH,GAAUI,KAAKC,gBAEtCC,EAAAC,cAAAD,EAAAE,SAAA,KACGZ,EAAMM,SAASO,IAAIT,GAAWU,GACtBL,EAAYK,gBACjBJ,EAAAC,cAACI,EAADC,EAAA,GAAeX,EAAf,CAA0BY,IAAKd,IAC5BW,EAAMZ,MAAME,UAGfU,kBAQRJ,EAAAC,cAACI,EAADC,EAAA,GAAeX,EAAf,CAA0BY,IAAKd,IAC5BC,MAKPL,KAAKmB,YAAc,OAUnB,MAAMC,eAAYnB,EAAMC,YAAgC,CAACC,EAAOC,KAC9D,MAAMC,SAAEA,KAAaC,GAAcH,eAEnC,OAAIF,EAAMoB,eAAehB,gBAChBJ,EAAMqB,aAAajB,EAAU,IAC/BkB,EAAWjB,EAAWD,EAASF,OAClCe,IAAKM,EAAYpB,EAAeC,EAAiBa,OAI9CjB,EAAMM,SAASkB,MAAMpB,GAAY,EAAIJ,EAAMM,SAASmB,KAAK,MAAQ,QAG1EN,EAAUD,YAAc,mBAMxB,MAAMQ,UAAY,EAAGtB,SAAAA,kBACZM,EAAAC,cAAAD,EAAAE,SAAA,KAAGR,GAOZ,SAASK,EAAYK,gBACnB,OAAOd,EAAMoB,eAAeN,IAAUA,EAAMa,OAASD,UAGvD,SAASJ,EAAWjB,EAAqBuB,GAEvC,MAAMC,EAAgB,IAAKD,GAE3B,IAAK,MAAME,KAAYF,EAAY,CACjC,MAAMG,EAAgB1B,EAAUyB,GAC1BE,EAAiBJ,EAAWE,GAEhB,WAAWG,KAAKH,GAGhCD,EAAcC,GAAY,IAAII,KAC5BF,MAAAA,GAAAA,KAAoBE,GACpBH,MAAAA,GAAAA,KAAmBG,IAID,UAAbJ,EACPD,EAAcC,GAAY,IAAKC,KAAkBC,GAC3B,cAAbF,IACTD,EAAcC,GAAY,CAACC,EAAeC,GAAgBG,OAAOC,SAASC,KAAK,MAInF,MAAO,IAAKhC,KAAcwB,UAG5B,MAAMS,KAAOvC","sources":["./packages/react/slot/src/Slot.tsx"],"sourcesContent":["import * as React from 'react';\nimport { composeRefs } from '@radix-ui/react-compose-refs';\n\n/* -------------------------------------------------------------------------------------------------\n * Slot\n * -----------------------------------------------------------------------------------------------*/\n\ninterface SlotProps extends React.HTMLAttributes<HTMLElement> {\n children?: React.ReactNode;\n}\n\nconst Slot = React.forwardRef<HTMLElement, SlotProps>((props, forwardedRef) => {\n const { children, ...slotProps } = props;\n\n if (React.Children.toArray(children).some(isSlottable)) {\n return (\n <>\n {React.Children.map(children, (child) => {\n return isSlottable(child) ? (\n <SlotClone {...slotProps} ref={forwardedRef}>\n {child.props.children}\n </SlotClone>\n ) : (\n child\n );\n })}\n </>\n );\n }\n\n return (\n <SlotClone {...slotProps} ref={forwardedRef}>\n {children}\n </SlotClone>\n );\n});\n\nSlot.displayName = 'Slot';\n\n/* -------------------------------------------------------------------------------------------------\n * SlotClone\n * -----------------------------------------------------------------------------------------------*/\n\ninterface SlotCloneProps {\n children: React.ReactNode;\n}\n\nconst SlotClone = React.forwardRef<any, SlotCloneProps>((props, forwardedRef) => {\n const { children, ...slotProps } = props;\n\n if (React.isValidElement(children)) {\n return React.cloneElement(children, {\n ...mergeProps(slotProps, children.props),\n ref: composeRefs(forwardedRef, (children as any).ref),\n });\n }\n\n return React.Children.count(children) > 1 ? React.Children.only(null) : null;\n});\n\nSlotClone.displayName = 'SlotClone';\n\n/* -------------------------------------------------------------------------------------------------\n * Slottable\n * -----------------------------------------------------------------------------------------------*/\n\nconst Slottable = ({ children }: { children: React.ReactNode }) => {\n return <>{children}</>;\n};\n\n/* ---------------------------------------------------------------------------------------------- */\n\ntype AnyProps = Record<string, any>;\n\nfunction isSlottable(child: React.ReactNode): child is React.ReactElement {\n return React.isValidElement(child) && child.type === Slottable;\n}\n\nfunction mergeProps(slotProps: AnyProps, childProps: AnyProps) {\n // all child props should override\n const overrideProps = { ...childProps };\n\n for (const propName in childProps) {\n const slotPropValue = slotProps[propName];\n const childPropValue = childProps[propName];\n\n const isHandler = /^on[A-Z]/.test(propName);\n // if it's a handler, modify the override by composing the base handler\n if (isHandler) {\n overrideProps[propName] = (...args: unknown[]) => {\n childPropValue?.(...args);\n slotPropValue?.(...args);\n };\n }\n // if it's `style`, we merge them\n else if (propName === 'style') {\n overrideProps[propName] = { ...slotPropValue, ...childPropValue };\n } else if (propName === 'className') {\n overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(' ');\n }\n }\n\n return { ...slotProps, ...overrideProps };\n}\n\nconst Root = Slot;\n\nexport {\n Slot,\n Slottable,\n //\n Root,\n};\nexport type { SlotProps };\n"],"names":["Slot","React","forwardRef","props","forwardedRef","children","slotProps","Children","toArray","some","isSlottable","_react","createElement","Fragment","map","child","$d34e8c328cb3dd19ab7a2f6eafa6ad$var$SlotClone","_babelRuntimeHelpersEsmExtends","ref","displayName","SlotClone","isValidElement","cloneElement","mergeProps","composeRefs","count","only","Slottable","type","childProps","overrideProps","propName","slotPropValue","childPropValue","test","args","filter","Boolean","join","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.1.1",
3
+ "version": "0.1.2-rc.4",
4
4
  "license": "MIT",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",
@@ -29,5 +29,6 @@
29
29
  },
30
30
  "bugs": {
31
31
  "url": "https://github.com/radix-ui/primitives/issues"
32
- }
32
+ },
33
+ "stableVersion": "0.1.1"
33
34
  }