Skip to content

Instantly share code, notes, and snippets.

@acquitelol
Created April 5, 2025 20:18
Show Gist options
  • Select an option

  • Save acquitelol/cb9d893d6718f01d6c32f091023b9b3d to your computer and use it in GitHub Desktop.

Select an option

Save acquitelol/cb9d893d6718f01d6c32f091023b9b3d to your computer and use it in GitHub Desktop.
An extremely minimal StyleSheet module for use in React-style projects
type StyleSheet = Record<string, React.CSSProperties>;
export const mergeStyles = (...styles: React.CSSProperties[]) => styles.reduce((pre, cur) => ({ ...pre, ...cur }), {});
export const createStyleSheet = <T extends StyleSheet>(sheet: T) => ({
styles: sheet,
merge: (callback: (sheet: T) => React.CSSProperties[]) => mergeStyles(...callback(sheet))
});
export const commonStyles = createStyleSheet({
flex: {
display: 'flex'
},
align: {
alignItems: 'center'
},
justify: {
justifyContent: 'center'
},
row: {
flexDirection: 'row'
},
column: {
flexDirection: 'column'
},
wrap: {
flexWrap: 'wrap'
},
textCenter: {
textAlign: 'center'
}
});
export default { mergeStyles, createStyleSheet, commonStyles };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment