Created
April 5, 2025 20:18
-
-
Save acquitelol/cb9d893d6718f01d6c32f091023b9b3d to your computer and use it in GitHub Desktop.
An extremely minimal StyleSheet module for use in React-style projects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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