Skip to content

Commit

Permalink
feat: dynamically generate utility classes
Browse files Browse the repository at this point in the history
  • Loading branch information
ilkyazarabaci committed Oct 8, 2023
1 parent f2c42fd commit 39dd043
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 10 deletions.
12 changes: 6 additions & 6 deletions packages/react/src/atoms/Color/Color.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import React from "react";
import Spacing from "../../foundation/Spacing";

interface ColorProps {
hexCode: string,
width: string,
height: string
width?: keyof typeof Spacing,
height?: keyof typeof Spacing
}

const Color: React.FC<ColorProps> = ({ hexCode, width, height }) => {
return <div style={{
const Color: React.FC<ColorProps> = ({ hexCode, width = Spacing.sm, height = Spacing.sm }) => {
const className = `dse-width-${width} dse-height-${height}`;
return <div className={className} style={{
backgroundColor: hexCode,
width,
height
}}>

</div>
Expand Down
33 changes: 33 additions & 0 deletions packages/react/src/foundation/Spacing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const spaces: {
none: "none";
xxxs: "xxxs";
xxs: "xxs";
xs: "xs";
sm: "sm";
md: "md";
lg: "lg";
xl: "xl";
xxl: "xxl";
xxxl: "xxxl";
} = {
none: "none",
xxxs: "xxxs",
// 4px
xxs: "xxs",
// 8px
xs: "xs",
// 12px
sm: "sm",
// 16px
md: "md",
// 24px
lg: "lg",
// 32px
xl: "xl",
// 48px
xxl: "xxl",
// 72px
xxxl: "xxxl",
};

export default Object.freeze(spaces);
3 changes: 2 additions & 1 deletion packages/react/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// import Button from "./atoms/Button";
import Color from "./atoms/Color";
import Spacing from "./foundation/Spacing";

export { Color };
export { Color, Spacing };
11 changes: 11 additions & 0 deletions packages/scss/src/atoms/Utilities.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@import "foundation/all";

@each $size, $value in $spacing {
.dse-width-#{$size} {
width: $value;
}

.dse-height-#{$size} {
height: $value;
}
}
6 changes: 3 additions & 3 deletions playgrounds/react/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import React from "react";
import ReactDOM from "react-dom/client";

// import Button from '@ds.e/react';
import Color from '@ds.e/react';

import { Color } from '@ds.e/react';
// import '@ds.e/scss/lib/Button.css';
import '@ds.e/scss/lib/Utilities.css';

const root = ReactDOM.createRoot(
document.getElementById('root') as HTMLElement
)

root.render(
<React.StrictMode>
<Color hexCode='#000' width="1rem" height="1rem"/>
<Color hexCode='#000' />
{/* <Button label="React Playground"/> */}
</React.StrictMode>,
)

0 comments on commit 39dd043

Please sign in to comment.