
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
@jongold/st
Advanced tools
styling for functional UIs
import Style from '@jongold/st';
import { add, always, compose as c, evolve } from 'ramda';
import chroma from 'chroma';
import { Touchable, View } from 'react-primitives'; // or react-native etc
// define some abstract style transformations
// bumpFontSize :: CSS -> CSS
const bumpFontSize = evolve({
fontSize: add(4),
});
// darkenText :: CSS -> CSS
const darkenText = evolve({
color: c => chroma(a).darken(),
});
// brandify :: CSS -> CSS
const brandify = evolve({
fontFamily: always('Circular Air Pro'),
});
// and some primitive styles
const boxShadow = {
boxShadow: '0 2px 3px rgba(0,0,0,.25)',
};
// encapsulate a style that varies on props
const GenericButtonStyle = Style(props => ({
fontSize: 16,
fontWeight: 'bold',
fontFamily: 'SF UI Display'
backgroundColor: props.primary ? 'green' : 'blue',
color: 'white',
}));
// and maybe another transform
// that relies on more props
const outlineify = style => Style(props => ({
...style,
border: props.outline ? '1px solid currentColor' : 'none',
color: props.outline ? style.backgroundColor : style.color,
backgroundColor: props.outline ? 'transparent' : style.backgroundColor,
}));
// compose some of those transformations
const MyButtonStyle = GenericButtonStyle.map(
c(bumpFontSize, darkenText, brandify)
).concat(boxShadow).chain(outlineify);
// associative, so could be written as
const MyButtonStyle = GenericButtonStyle
.map(bumpFontSize)
.map(darkenText)
.map(brandify)
.concat(boxShadow)
.chain(outlineify);
// Notice that we have passed in any props yet
// so neither GenericButtonStyle nor MyButton
// are complete.
// Let's use it in context. I'm using Flow +
// react-primitives but neither are necessary
type P = {
children: string,
primary: bool,
outline: bool,
onPress: () => void,
}
const MyButton = (props: P) =>
<Touchable onPress={props.onPress}>
<View style={MyButtonStyle.resolve(props)}>
{ props.children }
</View>
</Touchable>
<MyButton primary={true} />
// => rendered View has style:
// {
// fontSize: 20,
// fontWeight: 'bold',
// fontFamily: 'Circular Air Pro',
// backgroundColor: 'darkGreen',
// color: 'white',
// boxShadow: '0 2px 3px rgba(0,0,0,.25)',
// }
<MyButton primary={false} outline={true} />
// => rendered View has style:
// {
// fontSize: 20,
// fontWeight: 'bold',
// fontFamily: 'Circular Air Pro',
// color: 'darkBlue',
// backgroundColor: 'transparent',
// border: '1px solid darkBlue',
// boxShadow: '0 2px 3px rgba(0,0,0,.25)',
// }
St implements FantasyLand 1, FantasyLand 2,
FantasyLand 3 compatible Semigroup, Monoid, Functor, Apply, Applicative, Chain, ChainRec and Monad.
Hindley-Milner type signatures are used to document functions. Signatures starting with a . refer to "static" functions, whereas signatures starting with a # refer to functions on the prototype.
A list of types used within the signatures:
Style :: => (Props -> CSS) -> Style CSSStyle(props => ({
backgroundColor: props.color,
fontSize: 16,
});
// Style({ backgroundColor: __color__, fontSize: 16 })
.of :: a -> Style aStyle.of({
backgroundColor: 'red',
fontSize: 16,
});
// Style({ backgroundColor: 'red', fontSize: 16, });
#concat :: Style a ~> Style a ~> Style aStyle.of({ fontWeight: 'bold', fontSize: 14 }).concat({ fontSize: 16, backgroundColor: 'red' })
// Style({ fontWeight: 'bold', fontSize: 16, backgroundColor: 'red' }))
.empty :: () -> Style _Style.empty()
// Style({})
#map :: Style a ~> (a -> b) -> Style bStyle.of({
backgroundColor: 'red',
fontSize: 14
}).map(style => ({
...style,
fontSize: 16
});
// Style({ backgroundColor: 'red, fontSize: 16 }))
Style.of({
backgroundColor: 'red',
fontSize: 14
}).map(evolve({
fontSize: x => x * 2
});
// { backgroundColor: 'red, fontSize: 24 })
#chain :: Style a ~> Style a -> Style awip
#ap :: Style (a -> b) ~> Style a -> Style bStyle.of(style => ({
...style,
fontSize: style.fontSize * 2,
}).ap({ color: 'red', fontSize: 14 })
//
#resolve :: Style a ~> Props -> CSSconst st = Style(props => ({
backgroundColor: props.primary ? 'green' : 'gray',
fontSize: 16,
})).map(evolve({ fontSize: add(2) }))
st.resolve({ title: 'sign up', primary: true })
// { backgroundColor: 'red', fontSize: 18 }
e.g., in a render function
const Button = props =>
<button style={st.resolve(props)}>
{ props.children }
</button>
// <button style="background-color: 'red', font-size: 18">sign up</button>
Made with love and monads by (emoji key):
Jon Gold 📖 💡 👀 | James Baxley 💻 |
|---|
FAQs
Functional styling
We found that @jongold/st 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.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.