Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
@polymorphic-factory/solid
Advanced tools
Create polymorphic SolidJS components with a customizable styled
function.
A polymorphic component is a component that can be rendered with a different element.
Known drawbacks for the type definitions:
Event handlers are not typed correctly when using the
as
prop.This is a deliberate decision to keep the usage as simple as possible.
npm install @polymorphic-factory/solid
or
yarn add @polymorphic-factory/solid
or
pnpm install @polymorphic-factory/solid
Import the polymorphic factory and create your element factory.
import { polymorphicFactory } from '@polymorphic-factory/solid'
const poly = polymorphicFactory()
styled
functionYou can override the default implementation by passing styled
function in the options.
import { Dynamic } from 'solid-js/web'
const poly = polymorphicFactory({
styled: (component, options) => (props) => {
const [local, others] = splitProps(props, ['as'])
const component = local.as || originalComponent
return (
<Dynamic
component={component}
data-custom-styled
data-options={JSON.stringify(options)}
{...others}
/>
)
},
})
const WithOptions = poly('div', { hello: 'world' })
const App = () => {
return (
<>
<poly.div hello="world" />
{/* renders <div data-custom-styled hello="world" /> */}
<WithOptions />
{/* renders <div data-custom-styled data-options="{ \"hello\": \"world\" }" /> */}
</>
)
}
Use the element factory to create elements inline.
Every JSX element is supported div
, main
, aside
, etc.
<>
<poly.div />
<poly.main>
<poly.section>
<poly.div as="p">This is rendered as a p element</poly.div>
</poly.section>
</poly.main>
</>
Use the factory to wrap custom components.
const OriginalComponent = (props) => <div data-original="true" {...props}></div>
const MyComponent = poly(OriginalComponent)
const App = () => <MyComponent />
// render <div data-original="true" />
It still supports the as
prop, which would replace the OriginalComponent
.
<MyComponent as="div" />
// renders <div />
import type { HTMLPolymorphicComponents, HTMLPolymorphicProps } from '@polymorphic-factory/solid'
type PolymorphicDiv = HTMLPolymorphicComponents['div']
type DivProps = HTMLPolymorphicProps<'div'>
MIT © Tim Kolberger
FAQs
@polymorphic-factory/solid
The npm package @polymorphic-factory/solid receives a total of 23 weekly downloads. As such, @polymorphic-factory/solid popularity was classified as not popular.
We found that @polymorphic-factory/solid demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.