Skip to content

Commit

Permalink
feat: add support to stylesheet interface in JS/TS version
Browse files Browse the repository at this point in the history
  • Loading branch information
omariosouto committed Aug 1, 2022
1 parent e62803a commit 65310d7
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 3 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
It's a set of common utility strategies to work with responsive styles with CSS in JS and Flutter

## Summary

- [Dart/Flutter](#dartflutter)
- [JavaScript/React](#javascriptreact)
- [Dart/Flutter](#dartflutter-🐦)
- [JavaScript/React](#javascriptreact-⚛)
- [Docs](#docs)

## Dart/Flutter 🐦
Expand Down Expand Up @@ -101,6 +100,7 @@ yarn add @skynexui/responsive_stylesheet
| [GridItem](./lib/grid-item//grid_item.md) || 🚧 |
| parseStylesheet | 🚧 ||
| BreakpointsProvider | 🚧 | 🚧 |
| StyleSheet | 🚧 ||

> ✅ Ready, 🚧 WIP, ❌ Not in roadmap by now, 🗺️ Inside roadmap
Expand Down
9 changes: 9 additions & 0 deletions lib/parse-stylesheet/parse-stylesheet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { breakpoints } from "@lib/breakpoints/breakpoints";

function parseStyleSheetRule(property: any, value: any) {
if (property.includes("crossAxisAlignment")) {
// crossAxisAlignment?: alignItems;
return { alignItems: value };
}
if (property.includes("crossAxisAlignment")) {
// mainAxisAlignment?: justifyContent;
return { crossAxisAlignment: value };
}

if (property.includes("Vertical")) {
const propertyBase = property.replace("Vertical", "");
return {
Expand Down
6 changes: 6 additions & 0 deletions lib/stylesheet/properties/box-model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ResponsiveProperty } from "../responsive-property";

export type height = ResponsiveProperty<string | number> | string;
export type width = ResponsiveProperty<string | number> | string;
export type background = ResponsiveProperty<string> | string;
export type color = ResponsiveProperty<string> | string;
20 changes: 20 additions & 0 deletions lib/stylesheet/properties/flexbox.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ResponsiveProperty } from "../responsive-property";

export type flexDirection = ResponsiveProperty<"row" | "column"> | string;

export type flex = ResponsiveProperty<number | string> | string | number;

export type alignItems =
| ResponsiveProperty<"stretch" | "flex-start" | "flex-end" | "center">
| string;

export type justifyContent =
| ResponsiveProperty<
| "center"
| "flex-start"
| "flex-end"
| "spaceBetween"
| "spaceAround"
| "spaceEvenly"
>
| string;
3 changes: 3 additions & 0 deletions lib/stylesheet/responsive-property.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Breakpoints } from "@lib/breakpoints/breakpoints";

export type ResponsiveProperty<Type> = Partial<Record<Breakpoints, Type>>;
30 changes: 30 additions & 0 deletions lib/stylesheet/stylesheet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { background, color, height, width } from "./properties/box-model";
import {
alignItems,
flex,
flexDirection,
justifyContent,
} from "./properties/flexbox";
import { ResponsiveProperty } from "./responsive-property";

export interface StyleSheet {
// [box-model]
height?: height;
width?: width;
color?: color;
backgroundColor?: background;

// [flexbox]
flex?: flex;
alignItems?: alignItems;
crossAxisAlignment?: alignItems;
justifyContent?: justifyContent;
mainAxisAlignment?: justifyContent;
flexDirection?: flexDirection;

// Extras
hover?: StyleSheet;
focus?: StyleSheet;
modeDark?: StyleSheet;
[key: string]: ResponsiveProperty<string | any> | string | any;
}

1 comment on commit 65310d7

@vercel
Copy link

@vercel vercel bot commented on 65310d7 Aug 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.