![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Lightweight CSS-In-JS library for UI packages. Battle tested on Emoji-Picker-React.
When creating a third-party package, you have different concerns than when creating an application. Most existing solutions come to solve the problem of shipping styles with your application, but they are not suitable for third-party packages.
There is no existing standard that makes consuming third party packages with their styles as easy as importing packages that are defined locally in your application. The process always involves some manual work or extra configuration, and no solution works out of the box with all bundlers or environment.
FlairUp aims to solve this by allowing package-authors to ship their styles with their package, and automatically apply the styles with them, both during SSR and in the browser.
npm install flairup
The main issue that FlairUp is trying to tackle is the challenge of bringing your own styles as a third-party dependency. There is no standard way for configuring your styling that will work in all environments and with all bundlers.
It will either break on some bundlers, or will require the user to import the styles manually, which is not ideal.
FlairUp is a one-time-runtime library, meaning that it will only run once, when the package is imported. While usually, it is not recommended to have styles computed at runtime, this is the only way we can assure the library is working in all environments.
The way FlairUp works is by adding a <style>
tag to the DOM, and injecting the styles into it.
To reduce bloat and improve performance, FlairUp will only add a single class per CSS property, meaning that if a certain style exists in multiple places, it will only be added as one class to the stylesheet, and be reused in all places consuming it. This is a much more efficient way, allowing us not to worry about de-duplication of stylis.
Defining your style has two parts:
createSheet
function. This function adds the style tag to the DOM, and returns a stylesheet object with a create
function.create
function.
In the create function you can define your styles as a javascript object, and get back a Set containing the class names of the styles you defined.import { createSheet, cx } from 'flairup';
const sheet = createSheet('MyComponent');
const styles = sheet.create({
button: {
color: 'red',
':hover': {
color: 'blue',
},
},
});
const Button = () => <button className={cx(styles.button)}>Hover Me</button>;
const styles = sheet.create({
button: {
'.': 'my-button', // or ["my-button", "button-main"]
color: 'red',
},
});
Unlike regular CSS properties, CSS variables are as a single class per scope.
const styles = sheet.create({
button: {
'--': {
'--color': 'red',
'--hover-color': 'blue',
},
},
});
const styles = sheet.create({
button: {
color: 'red',
'@media (max-width: 600px)': {
color: 'blue',
},
},
});
const styles = sheet.create({
button: {
color: 'red',
':hover': {
color: 'blue',
},
'::before': {
content: '🎩',
},
},
});
const styles = sheet.create({
'.theme-dark': {
button: {
color: 'red',
':hover': {
color: 'blue',
},
},
},
button: {
color: 'green',
},
});
Supports all the following selectors:
>
~
+
*
&.class
(Adds the class directly to the selector without a space)const styles = sheet.create({
button: {
'.lower_level_class': {
color: 'red',
},
},
paragraph: {
'*': {
color: 'blue',
},
},
});
While the library supports SSR, we need to do a little bit of work in our component to make it work. All we need to do is render a style tag inside our component and put the styles inside it.
Create the following component:
export function SSRStyles() {
if (stylesheet.isApplied()) {
return null;
}
return (
<style
suppressHydrationWarning
dangerouslySetInnerHTML={{ __html: stylesheet.getStyle() }}
/>
);
}
And place it anywhere inside your component, like this:
export default function MyComponentMain({ children }: Props) {
return (
<div>
<SSRStyles /> // <-- Here
<ChildComponent>{children}</ChildComponent>
</div>
);
}
FAQs
🎩 Lightweight CSS-in-JS solution for npm packages
The npm package flairup receives a total of 220,353 weekly downloads. As such, flairup popularity was classified as popular.
We found that flairup demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.