Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@solid-primitives/props
Advanced tools
Library of primitives focused around component props.
combineProps
- Reactively merges multiple props objects together while smartly combining some of Solid's JSX/DOM attributes.createProps
- Provides controllable props signals like knobs/controls for simple component testing.npm install @solid-primitives/props
# or
yarn add @solid-primitives/props
combineProps
A helper that reactively merges multiple props objects together while smartly combining some of Solid's JSX/HTML attributes.
Event handlers (onClick, onclick, onMouseMove, onSomething), and refs (props.ref) are chained.
class
, className
, classList
and style
are combined.
For all other props, the last prop object overrides all previous ones. Similarly to Solid's mergeProps.
import { combineProps } from "@solid-primitives/props";
const MyButton: Component<ButtonProps> = props => {
// primitives of a lot of headless ui libraries will provide props to spread
const { buttonProps } = createButton();
// they can be combined with user's props easily
const combined = combineProps(props, buttonProps);
return <button {...combined} />;
};
// component consumer can provide button props
// they will be combined with those provided by createButton() primitive
<MyButton style={{ margin: "24px" }} />;
Every function/tuple property with on___
name get's chained. That could potentially include properties that are not actually event-listeners – such as only
or once
. Hence you should remove them from the props (with splitProps).
Chained functions will always return void
. If you want to get the returned value from a callback, you have to split those props and handle them yourself.
Warning: The types for event-listeners often won't correctly represent the values. Chaining is meant only for DOM Events spreading to an element.
const combined = combineProps(
{
onClick: e => {},
onclick: e => {}
},
{
onClick: [(n, e) => {}, 123]
}
);
// combined.onClick() will call all 3 of the functions above
combineProps
works, see the TESTSA couple of lower-lever helpers that power combineProps
:
stringStyleToObject
const styles = stringStyleToObject("margin: 24px; border: 1px solid #121212");
styles; // { margin: "24px", border: "1px solid #121212" }
combineStyle
const styles = combineStyle("margin: 24px; border: 1px solid #121212", {
margin: "2rem",
padding: "16px"
});
styles; // { margin: "2rem", border: "1px solid #121212", padding: "16px" }
https://codesandbox.io/s/combineprops-demo-ytw247?file=/index.tsx
createProps
Primitive that provides controllable props signals like knobs/controls for simple component testing
You can either create a single prop:
// Second argument can be initialValue for boolean, number, string:
const [string, setString, stringField] = createControlledProp("stringValue", "test");
// Arrays or enums can be provided in an options object:
const [language, setLanguage, languageField] = createControlledProp(
"language",
{ initialValue: "en", options: ["de", "en", "fr", "it"] as const }
// If you want your array to be able to influence the setter/getter types, use `as const`.
);
enum Currency {
AUD,
GBP,
EUR,
USD,
CHF,
JPY,
CNY
}
const [currency, setCurrency, currencyField] = createControlledProp("currency", {
initialValue: Currency.USD,
options: Currency
});
return { languageField(); };
or multiple props in one call:
enum Test { One, Two, Three };
const languages = ['de', 'en', 'fr', 'it'] as const;
const [props, fields] = createControlledProps({
boolean: true,
number: 42,
string: 'text',
array: { initialValue: 'en', options: languages },
enum: { initialValue: Test.Three, options: Test }
});
props == {
boolean: Accessor<boolean>,
setBoolean: Setter<boolean>,
number: Accessor<number>,
setNumber: Setter<number>,
string: Accessor<string>,
setString: Setter<string>,
array: Accessor<string>,
setArray: Setter<string>,
enum: Accessor<Test>,
setEnum: Setter<Test>
};
fields == JSX.Element[];
TODO
0.0.100
Initial release
1.0.2
Release initial version with CJS support.
2.0.0 - PR#127
Renamed createProps
to createControlledProps
, createProp
to createControlledProp
etc. (for all of the primitives focused on testing)
Added combineProps
primitive
2.1.0
Add support for tuple event handlers and de-dupeing to combineProps
.
2.1.1
Support for Solid 1.4
FAQs
Library of primitives focused around component props.
The npm package @solid-primitives/props receives a total of 36,242 weekly downloads. As such, @solid-primitives/props popularity was classified as popular.
We found that @solid-primitives/props demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.