@radix-ui/react-slot 0.0.11 → 0.1.0

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
@@ -1,7 +1,7 @@
1
1
  import * as React from "react";
2
- type SlotProps = {
3
- children: React.ReactNode;
4
- };
2
+ export interface SlotProps {
3
+ children?: React.ReactNode;
4
+ }
5
5
  export const Slot: React.ForwardRefExoticComponent<SlotProps & React.RefAttributes<HTMLElement>>;
6
6
  export const Slottable: ({ children }: {
7
7
  children: React.ReactNode;
@@ -1 +1 @@
1
- {"mappings":"A;AAOA,iBAAiB;IAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;CAAE,CAAC;AAE/C,OAAA,MAAM,mFA2BJ,CAAC;AA4BH,OAAA,MAAM;cAAuC,MAAM,SAAS;oJAE3D,CAAC;AAwCF,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;IACE,QAAQ,CAAC,EAAE,MAAM,SAAS,CAAC;CAC5B;AAED,OAAA,MAAM,mFA2BJ,CAAC;AA8BH,OAAA,MAAM;cAAuC,MAAM,SAAS;oJAE3D,CAAC;AA0CF,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,t,n,r=require("@radix-ui/react-compose-refs").composeRefs,l=(e={},t=require("react"),Object.keys(t).forEach((function(n){"default"!==n&&"__esModule"!==n&&Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[n]}})})),e),o=(n=require("@babel/runtime/helpers/extends"))&&n.__esModule?n.default:n;const c=/*#__PURE__*/l.forwardRef(((e,t)=>{const{children:n,...r}=e;return 1===l.Children.count(n)?/*#__PURE__*/l.createElement(s,o({},r,{ref:t}),n):/*#__PURE__*/l.createElement(l.Fragment,null,l.Children.map(n,(e=>/*#__PURE__*/l.isValidElement(e)&&e.type===i?/*#__PURE__*/l.createElement(s,o({},r,{ref:t}),e.props.children):e)))}));exports.Slot=c,c.displayName="Slot";const s=/*#__PURE__*/l.forwardRef(((e,t)=>{const{children:n,...o}=e,c=l.Children.only(n);/*#__PURE__*/return l.isValidElement(c)?/*#__PURE__*/l.cloneElement(c,{...u(o,c.props),ref:r(t,c.ref)}):null}));s.displayName="SlotClone";const i=({children:e})=>e;function u(e,t){const n={...t};for(const r in t){const l=e[r],o=t[r];/^on[A-Z]/.test(r)?n[r]=a(o,l):"style"===r&&(n[r]={...l,...o})}return{...e,...n}}function a(e,t){return function(...n){null==e||e(...n);n[0]instanceof Event&&n[0].defaultPrevented||null==t||t(...n)}}exports.Slottable=i;const d=c;exports.Root=d;
1
+ var e,n,t,r=require("@radix-ui/react-compose-refs").composeRefs,l=(e={},n=require("react"),Object.keys(n).forEach((function(t){"default"!==t&&"__esModule"!==t&&Object.defineProperty(e,t,{enumerable:!0,get:function(){return n[t]}})})),e),o=(t=require("@babel/runtime/helpers/extends"))&&t.__esModule?t.default:t;const c=/*#__PURE__*/l.forwardRef(((e,n)=>{const{children:t,...r}=e;return 1===l.Children.count(t)?/*#__PURE__*/l.createElement(s,o({},r,{ref:n}),t):/*#__PURE__*/l.createElement(l.Fragment,null,l.Children.map(t,(e=>/*#__PURE__*/l.isValidElement(e)&&e.type===i?/*#__PURE__*/l.createElement(s,o({},r,{ref:n}),e.props.children):e)))}));exports.Slot=c,c.displayName="Slot";const s=/*#__PURE__*/l.forwardRef(((e,n)=>{const{children:t,...o}=e,c=l.Children.only(t);/*#__PURE__*/return l.isValidElement(c)?/*#__PURE__*/l.cloneElement(c,{...a(o,c.props),ref:r(n,c.ref)}):null}));s.displayName="SlotClone";const i=({children:e})=>e;function a(e,n){const t={...n};for(const r in n){const l=e[r],o=n[r];/^on[A-Z]/.test(r)?t[r]=u(o,l):"style"===r?t[r]={...l,...o}:"className"===r&&(t[r]=[l,o].filter(Boolean).join(" "))}return{...e,...t}}function u(e,n){return function(...t){null==e||e(...t);t[0]instanceof Event&&t[0].defaultPrevented||null==n||n(...t)}}exports.Slottable=i;const f=c;exports.Root=f;
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,ECQzC,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,GAE3B,IAAK,MAAME,KAAYF,EAAY,CACjC,MAAMG,EAAgBvB,EAAUsB,GAC1BE,EAAiBJ,EAAWE,GAEhB,WAAWG,KAAKH,GAGhCD,EAAcC,GAAYI,EAAgBF,EAAgBD,GAGtC,UAAbD,IACPD,EAAcC,GAAY,IAAKC,KAAkBC,IAIrD,MAAO,IAAKxB,KAAcqB,GAK5B,SAASK,EAAgBC,EAA6BC,GACpD,OAAO,YAAwBC,GAC7BF,MAAAA,GAAAA,KAAkBE,GACcA,EAAK,aAAcC,OAASD,EAAK,GAAGE,kBAElEH,MAAAA,GAAAA,KAAiBC,wBAKvB,MAAMG,EAAOtC","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\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 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] = composeHandlers(childPropValue, slotPropValue);\n }\n // if it's `style`, we merge them\n else if (propName === 'style') {\n overrideProps[propName] = { ...slotPropValue, ...childPropValue };\n }\n }\n\n return { ...slotProps, ...overrideProps };\n}\n\ntype EventHandler = (...args: unknown[]) => unknown;\n\nfunction composeHandlers(childHandler?: EventHandler, slotHandler?: EventHandler) {\n return function handleEvent(...args) {\n childHandler?.(...args);\n const isDefaultPreventedEvent = args[0] instanceof Event && args[0].defaultPrevented;\n if (!isDefaultPreventedEvent) {\n slotHandler?.(...args);\n }\n } as EventHandler;\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","composeHandlers","childHandler","slotHandler","args","Event","defaultPrevented","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,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,OAUnB,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,GAE3B,IAAK,MAAME,KAAYF,EAAY,CACjC,MAAMG,EAAgBvB,EAAUsB,GAC1BE,EAAiBJ,EAAWE,GAEhB,WAAWG,KAAKH,GAGhCD,EAAcC,GAAYI,EAAgBF,EAAgBD,GAGtC,UAAbD,EACPD,EAAcC,GAAY,IAAKC,KAAkBC,GAC3B,cAAbF,IACTD,EAAcC,GAAY,CAACC,EAAeC,GAAgBG,OAAOC,SAASC,KAAK,MAInF,MAAO,IAAK7B,KAAcqB,GAK5B,SAASK,EAAgBI,EAA6BC,GACpD,OAAO,YAAwBC,GAC7BF,MAAAA,GAAAA,KAAkBE,GACcA,EAAK,aAAcC,OAASD,EAAK,GAAGE,kBAElEH,MAAAA,GAAAA,KAAiBC,wBAKvB,MAAMG,EAAOzC","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 {\n children?: React.ReactNode;\n}\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\ninterface SlotCloneProps {\n children: React.ReactNode;\n}\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 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] = composeHandlers(childPropValue, slotPropValue);\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\ntype EventHandler = (...args: unknown[]) => unknown;\n\nfunction composeHandlers(childHandler?: EventHandler, slotHandler?: EventHandler) {\n return function handleEvent(...args) {\n childHandler?.(...args);\n const isDefaultPreventedEvent = args[0] instanceof Event && args[0].defaultPrevented;\n if (!isDefaultPreventedEvent) {\n slotHandler?.(...args);\n }\n } as EventHandler;\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","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","composeHandlers","filter","Boolean","join","childHandler","slotHandler","args","Event","defaultPrevented","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 n from"@babel/runtime/helpers/esm/extends";export const Slot=/*#__PURE__*/t.forwardRef(((e,o)=>{const{children:l,...c}=e;return 1===t.Children.count(l)?/*#__PURE__*/t.createElement(r,n({},c,{ref:o}),l):/*#__PURE__*/t.createElement(t.Fragment,null,t.Children.map(l,(e=>/*#__PURE__*/t.isValidElement(e)&&e.type===Slottable?/*#__PURE__*/t.createElement(r,n({},c,{ref:o}),e.props.children):e)))}));Slot.displayName="Slot";const r=/*#__PURE__*/t.forwardRef(((n,r)=>{const{children:l,...c}=n,i=t.Children.only(l);/*#__PURE__*/return t.isValidElement(i)?/*#__PURE__*/t.cloneElement(i,{...o(c,i.props),ref:e(r,i.ref)}):null}));r.displayName="SlotClone";export const Slottable=({children:e})=>e;function o(e,t){const n={...t};for(const r in t){const o=e[r],c=t[r];/^on[A-Z]/.test(r)?n[r]=l(c,o):"style"===r&&(n[r]={...o,...c})}return{...e,...n}}function l(e,t){return function(...n){null==e||e(...n);n[0]instanceof Event&&n[0].defaultPrevented||null==t||t(...n)}}export const Root=Slot;
1
+ import{composeRefs as e}from"@radix-ui/react-compose-refs";import*as t from"react";import n from"@babel/runtime/helpers/esm/extends";export const Slot=/*#__PURE__*/t.forwardRef(((e,o)=>{const{children:l,...c}=e;return 1===t.Children.count(l)?/*#__PURE__*/t.createElement(r,n({},c,{ref:o}),l):/*#__PURE__*/t.createElement(t.Fragment,null,t.Children.map(l,(e=>/*#__PURE__*/t.isValidElement(e)&&e.type===Slottable?/*#__PURE__*/t.createElement(r,n({},c,{ref:o}),e.props.children):e)))}));Slot.displayName="Slot";const r=/*#__PURE__*/t.forwardRef(((n,r)=>{const{children:l,...c}=n,i=t.Children.only(l);/*#__PURE__*/return t.isValidElement(i)?/*#__PURE__*/t.cloneElement(i,{...o(c,i.props),ref:e(r,i.ref)}):null}));r.displayName="SlotClone";export const Slottable=({children:e})=>e;function o(e,t){const n={...t};for(const r in t){const o=e[r],c=t[r];/^on[A-Z]/.test(r)?n[r]=l(c,o):"style"===r?n[r]={...o,...c}:"className"===r&&(n[r]=[o,c].filter(Boolean).join(" "))}return{...e,...n}}function l(e,t){return function(...n){null==e||e(...n);n[0]instanceof Event&&n[0].defaultPrevented||null==t||t(...n)}}export const Root=Slot;
2
2
  //# sourceMappingURL=index.module.js.map
@@ -1 +1 @@
1
- {"mappings":"4IASA,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,GAE3B,IAAK,MAAME,KAAYF,EAAY,CACjC,MAAMG,EAAgBvB,EAAUsB,GAC1BE,EAAiBJ,EAAWE,GAEhB,WAAWG,KAAKH,GAGhCD,EAAcC,GAAYI,EAAgBF,EAAgBD,GAGtC,UAAbD,IACPD,EAAcC,GAAY,IAAKC,KAAkBC,IAIrD,MAAO,IAAKxB,KAAcqB,GAK5B,SAASK,EAAgBC,EAA6BC,GACpD,OAAO,YAAwBC,GAC7BF,MAAAA,GAAAA,KAAkBE,GACcA,EAAK,aAAcC,OAASD,EAAK,GAAGE,kBAElEH,MAAAA,GAAAA,KAAiBC,WAKvB,MAAMG,KAAOtC","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\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 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] = composeHandlers(childPropValue, slotPropValue);\n }\n // if it's `style`, we merge them\n else if (propName === 'style') {\n overrideProps[propName] = { ...slotPropValue, ...childPropValue };\n }\n }\n\n return { ...slotProps, ...overrideProps };\n}\n\ntype EventHandler = (...args: unknown[]) => unknown;\n\nfunction composeHandlers(childHandler?: EventHandler, slotHandler?: EventHandler) {\n return function handleEvent(...args) {\n childHandler?.(...args);\n const isDefaultPreventedEvent = args[0] instanceof Event && args[0].defaultPrevented;\n if (!isDefaultPreventedEvent) {\n slotHandler?.(...args);\n }\n } as EventHandler;\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","composeHandlers","childHandler","slotHandler","args","Event","defaultPrevented","Root"],"version":3,"file":"index.module.js.map"}
1
+ {"mappings":"4IAWA,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,OAUnB,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,GAE3B,IAAK,MAAME,KAAYF,EAAY,CACjC,MAAMG,EAAgBvB,EAAUsB,GAC1BE,EAAiBJ,EAAWE,GAEhB,WAAWG,KAAKH,GAGhCD,EAAcC,GAAYI,EAAgBF,EAAgBD,GAGtC,UAAbD,EACPD,EAAcC,GAAY,IAAKC,KAAkBC,GAC3B,cAAbF,IACTD,EAAcC,GAAY,CAACC,EAAeC,GAAgBG,OAAOC,SAASC,KAAK,MAInF,MAAO,IAAK7B,KAAcqB,GAK5B,SAASK,EAAgBI,EAA6BC,GACpD,OAAO,YAAwBC,GAC7BF,MAAAA,GAAAA,KAAkBE,GACcA,EAAK,aAAcC,OAASD,EAAK,GAAGE,kBAElEH,MAAAA,GAAAA,KAAiBC,WAKvB,MAAMG,KAAOzC","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 {\n children?: React.ReactNode;\n}\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\ninterface SlotCloneProps {\n children: React.ReactNode;\n}\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 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] = composeHandlers(childPropValue, slotPropValue);\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\ntype EventHandler = (...args: unknown[]) => unknown;\n\nfunction composeHandlers(childHandler?: EventHandler, slotHandler?: EventHandler) {\n return function handleEvent(...args) {\n childHandler?.(...args);\n const isDefaultPreventedEvent = args[0] instanceof Event && args[0].defaultPrevented;\n if (!isDefaultPreventedEvent) {\n slotHandler?.(...args);\n }\n } as EventHandler;\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","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","composeHandlers","filter","Boolean","join","childHandler","slotHandler","args","Event","defaultPrevented","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.11",
3
+ "version": "0.1.0",
4
4
  "license": "MIT",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",
@@ -13,12 +13,11 @@
13
13
  "sideEffects": false,
14
14
  "scripts": {
15
15
  "clean": "rm -rf dist",
16
- "prepublish": "yarn clean",
17
16
  "version": "yarn version"
18
17
  },
19
18
  "dependencies": {
20
19
  "@babel/runtime": "^7.13.10",
21
- "@radix-ui/react-compose-refs": "0.0.5"
20
+ "@radix-ui/react-compose-refs": "0.1.0"
22
21
  },
23
22
  "peerDependencies": {
24
23
  "react": "^16.8 || ^17.0"