Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@leafygreen-ui/polymorphic

Package Overview
Dependencies
Maintainers
5
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@leafygreen-ui/polymorphic - npm Package Compare versions

Comparing version 0.1.0-next.0 to 0.1.0-next.1

dist/InferredPolymorphic.d.ts

6

CHANGELOG.md
# @leafygreen-ui/polymorphic
## 0.1.0-next.1
### Minor Changes
- Updates package export names
## 0.1.0-next.0

@@ -4,0 +10,0 @@

2

dist/esm/index.js

@@ -1,2 +0,2 @@

import r from"react";function n(){return n=Object.assign||function(r){for(var n=1;n<arguments.length;n++){var e=arguments[n];for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&(r[t]=e[t])}return r},n.apply(this,arguments)}function e(r,n){if(null==r)return{};var e,t,o=function(r,n){if(null==r)return{};var e,t,o={},a=Object.keys(r);for(t=0;t<a.length;t++)e=a[t],n.indexOf(e)>=0||(o[e]=r[e]);return o}(r,n);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(r);for(t=0;t<a.length;t++)e=a[t],n.indexOf(e)>=0||Object.prototype.propertyIsEnumerable.call(r,e)&&(o[e]=r[e])}return o}var t=function(n){return r.useRef(null)};function o(r){return r||"div"}function a(r){return{Component:o(r),ref:t()}}var l=["as","children"],u=function(t,a){var u=t.as,f=t.children,i=e(t,l),c=o(u);return r.createElement(c,n({},i,{ref:a}),f)},f=r.forwardRef(u);f.displayName="Polymorph";var i=function(n,e){if(1===n.length){var t=n;return t.displayName=null!=e?e:n.displayName,t}var o=r.forwardRef(n);return o.displayName=null!=e?e:n.displayName,o};function c(r,n){return r=function(r,n){return r||"string"==typeof(null==n?void 0:n.href)&&(r="a"),r}(r,n),a(r)}export{u as BasePolymorph,f as Polymorph,i as Polymorphic,c as useImplicitPolymorphic,a as usePolymorphic,o as usePolymorphicComponent,t as usePolymorphicRef};
import r from"react";function n(){return n=Object.assign||function(r){for(var n=1;n<arguments.length;n++){var e=arguments[n];for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&(r[t]=e[t])}return r},n.apply(this,arguments)}function e(r,n){if(null==r)return{};var e,t,o=function(r,n){if(null==r)return{};var e,t,o={},a=Object.keys(r);for(t=0;t<a.length;t++)e=a[t],n.indexOf(e)>=0||(o[e]=r[e]);return o}(r,n);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(r);for(t=0;t<a.length;t++)e=a[t],n.indexOf(e)>=0||Object.prototype.propertyIsEnumerable.call(r,e)&&(o[e]=r[e])}return o}var t=function(n){return r.useRef(null)};function o(r){return r||"div"}function a(r){return{Component:o(r),ref:t()}}var l=["as","children"],u=function(t,a){var u=t.as,f=t.children,i=e(t,l),c=o(u);return r.createElement(c,n({},i,{ref:a}),f)},f=r.forwardRef(u);f.displayName="Polymorph";var i=function(n,e){if(1===n.length){var t=n;return t.displayName=null!=e?e:n.displayName,t}var o=r.forwardRef(n);return o.displayName=null!=e?e:n.displayName,o};function c(r,n){return r=function(r,n){return r||"string"==typeof(null==n?void 0:n.href)&&(r="a"),r}(r,n),a(r)}export{u as BasePolymorph,f as Polymorph,i as Polymorphic,c as useInferredPolymorphic,a as usePolymorphic,o as usePolymorphicComponent,t as usePolymorphicRef};
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

export { ExamplePolymorphic, ExamplePolymorphicWithRef, AdvancedPolymorphic, AdvancedPolymorphicWithRef, ExampleImplicit, RestrictedExample, } from './Example';
export { ExamplePolymorphic, ExamplePolymorphicWithRef, AdvancedPolymorphic, AdvancedPolymorphicWithRef, ExampleInferred, RestrictedExample, } from './Example';
//# sourceMappingURL=index.d.ts.map

@@ -5,4 +5,4 @@ export { Polymorph, BasePolymorph } from './Polymorph';

export type { PolymorphicAs, PolymorphicProps, PolymorphicPropsWithRef, PolymorphicRef, PolymorphicComponentType, } from './Polymorphic.types';
export { useImplicitPolymorphic } from './ImplicitPolymorphic';
export type { ImplicitPolymorphicProps } from './ImplicitPolymorphic';
export { useInferredPolymorphic } from './InferredPolymorphic';
export type { InferredPolymorphicProps } from './InferredPolymorphic';
//# sourceMappingURL=index.d.ts.map

@@ -1,2 +0,2 @@

!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self)["@leafygreen-ui/polymorphic"]={},e.React)}(this,(function(e,r){"use strict";function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=t(r);function o(){return o=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},o.apply(this,arguments)}function l(e,r){if(null==e)return{};var t,n,o=function(e,r){if(null==e)return{};var t,n,o={},l=Object.keys(e);for(n=0;n<l.length;n++)t=l[n],r.indexOf(t)>=0||(o[t]=e[t]);return o}(e,r);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(n=0;n<l.length;n++)t=l[n],r.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(o[t]=e[t])}return o}var u=function(e){return n.default.useRef(null)};function i(e){return e||"div"}function f(e){return{Component:i(e),ref:u()}}var a=["as","children"],c=function(e,r){var t=e.as,u=e.children,f=l(e,a),c=i(t);return n.default.createElement(c,o({},f,{ref:r}),u)},p=n.default.forwardRef(c);p.displayName="Polymorph";e.BasePolymorph=c,e.Polymorph=p,e.Polymorphic=function(e,r){if(1===e.length){var t=e;return t.displayName=null!=r?r:e.displayName,t}var o=n.default.forwardRef(e);return o.displayName=null!=r?r:e.displayName,o},e.useImplicitPolymorphic=function(e,r){return e=function(e,r){return e||"string"==typeof(null==r?void 0:r.href)&&(e="a"),e}(e,r),f(e)},e.usePolymorphic=f,e.usePolymorphicComponent=i,e.usePolymorphicRef=u,Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self)["@leafygreen-ui/polymorphic"]={},e.React)}(this,(function(e,r){"use strict";function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var t=n(r);function o(){return o=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])}return e},o.apply(this,arguments)}function l(e,r){if(null==e)return{};var n,t,o=function(e,r){if(null==e)return{};var n,t,o={},l=Object.keys(e);for(t=0;t<l.length;t++)n=l[t],r.indexOf(n)>=0||(o[n]=e[n]);return o}(e,r);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(t=0;t<l.length;t++)n=l[t],r.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}var u=function(e){return t.default.useRef(null)};function f(e){return e||"div"}function i(e){return{Component:f(e),ref:u()}}var a=["as","children"],c=function(e,r){var n=e.as,u=e.children,i=l(e,a),c=f(n);return t.default.createElement(c,o({},i,{ref:r}),u)},p=t.default.forwardRef(c);p.displayName="Polymorph";e.BasePolymorph=c,e.Polymorph=p,e.Polymorphic=function(e,r){if(1===e.length){var n=e;return n.displayName=null!=r?r:e.displayName,n}var o=t.default.forwardRef(e);return o.displayName=null!=r?r:e.displayName,o},e.useInferredPolymorphic=function(e,r){return e=function(e,r){return e||"string"==typeof(null==r?void 0:r.href)&&(e="a"),e}(e,r),i(e)},e.usePolymorphic=i,e.usePolymorphicComponent=f,e.usePolymorphicRef=u,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=index.js.map
{
"name": "@leafygreen-ui/polymorphic",
"version": "0.1.0-next.0",
"version": "0.1.0-next.1",
"description": "LeafyGreen UI Kit Polymorphic",

@@ -32,6 +32,4 @@ "main": "./dist/index.js",

"devDependencies": {
"@emotion/styled": "11.10.5",
"@leafygreen-ui/box": "3.1.1",
"@leafygreen-ui/emotion": "4.0.3"
"@emotion/styled": "11.10.5"
}
}

@@ -65,12 +65,13 @@ # Polymorphic

### Implicit `as` prop
### Inferred `as` prop
Components extended using the `Polymorphic` factory function can be made to imply the `as` prop value based on the `href` passed in.
Ensure the custom props are wrapped in `ImplicitPolymorphicProps`, and use the `useImplicitPolymorphic` hook. Make sure to pass both `as` and `rest` (or an object that contains `href`) into the hook.
Components extended using the `Polymorphic` factory function can be made to infer the `as` prop value based on the `href` passed in.
Ensure the custom props are wrapped in `InferredPolymorphicProps`, and use the `useInferredPolymorphic` hook.
Make sure to pass both `as` and a `rest` object (that may contain `href`) into the hook.
```tsx
export const MyImplicitComponent = Polymorphic<
ImplicitPolymorphicProps<MyProps>
export const MyInferredComponent = Polymorphic<
InferredPolymorphicProps<MyProps>
>(({ as, ...rest }) => {
const { Component, ref } = useImplicitPolymorphic(as, rest);
const { Component, ref } = useInferredPolymorphic(as, rest);
return (

@@ -85,3 +86,3 @@ <Component ref={ref} {...rest}>

<MyImplicitComponent href="mongodb.design" />; // renders as <a>
<MyInferredComponent href="mongodb.design" />; // renders as <a>
```

@@ -88,0 +89,0 @@

@@ -1,2 +0,1 @@

// Uncomment these to debug tsdoc generation
export {

@@ -7,4 +6,4 @@ ExamplePolymorphic,

AdvancedPolymorphicWithRef,
ExampleImplicit,
ExampleInferred,
RestrictedExample,
} from './Example';
} from './Polymorphic.example';

@@ -18,4 +18,4 @@ export { Polymorph, BasePolymorph } from './Polymorph';

export { useImplicitPolymorphic } from './ImplicitPolymorphic';
export { useInferredPolymorphic } from './InferredPolymorphic';
export type { ImplicitPolymorphicProps } from './ImplicitPolymorphic';
export type { InferredPolymorphicProps } from './InferredPolymorphic';

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc