Skip to content
This repository has been archived by the owner on Aug 6, 2024. It is now read-only.

feat: Box component added #644

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/design-system/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
"@testing-library/react": "12.1.2",
"@testing-library/react-hooks": "^7.0.2",
"@testing-library/user-event": "13.5.0",
"@types/loadable__component": "^5.13.4",
"@types/jest": "^27.4.1",
"@types/loadable__component": "^5.13.4",
"@types/react": "^17.0.2",
"@types/react-datepicker": "^4.10.0",
"@types/react-router-dom": "^5.3.3",
Expand Down Expand Up @@ -93,8 +93,8 @@
"storybook": "^7.0.24",
"storybook-zeplin": "^2.0.1",
"styled-components": "^5.3.6",
"tsconfig-paths-webpack-plugin": "^3.5.2",
"ts-jest": "27.0.0",
"tsconfig-paths-webpack-plugin": "^3.5.2",
"typescript": "4.9.5",
"webpack": "^5.88.1"
},
Expand Down Expand Up @@ -132,6 +132,8 @@
"@react-aria/textfield": "^3.8.1",
"@react-stately/radio": "^3.6.2",
"@react-stately/toggle": "^3.4.4",
"@xstyled/styled-components": "^3.8.0",
Copy link

Choose a reason for hiding this comment

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

There are some doubts about using another CSS-in-JS library. This will inflate the bundle, it is also not very clear what to use in the end for styles. Do you plan to switch to this library?

Copy link
Contributor Author

@albinAppsmith albinAppsmith Oct 4, 2023

Choose a reason for hiding this comment

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

xstyled is more of like an addon to styled-components or emotion. It is not a standalone package. I can check the bundle size variation after this. And this will be removed in future when we get a clear picture on how to make these components using just CSS.

"csstype": "^3.1.2",
"date-fns": "^2.29.3",
"loglevel": "^1.8.1",
"rc-select": "^14.4.3",
Expand Down
14 changes: 4 additions & 10 deletions packages/design-system/plop-templates/stories.tsx.hbs
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import React from "react";
import { ComponentMeta, ComponentStory } from "@storybook/react";
import { Meta } from "@storybook/react";

import { {{capitalize name}} } from "./{{capitalize name}}";

export default {
title: "Design System/{{capitalize name}}",
component: {{capitalize name}},
} as ComponentMeta<typeof {{capitalize name}}>;
} as Meta<typeof {{capitalize name}}>;

// eslint-disable-next-line react/function-component-definition
const Template: ComponentStory<typeof {{capitalize name}}> = (args) => {
return <{{capitalize name}} {...args} />;
};
const Story = StoryObj<typeof {{capitalize name}}>;

export const {{capitalize name}}Story = Template.bind({});
{{capitalize name}}Story.storyName = "{{capitalize name}}";
{{capitalize name}}Story.args = {
//add arguments here
};
export const {{capitalize name}}Story: Story = {};
30 changes: 30 additions & 0 deletions packages/design-system/src/Box/Box.constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { CLASS_NAME_PREFIX } from "__config__/constants";

export const BoxClassName = `${CLASS_NAME_PREFIX}-box`;
export const PropsToBeCssPrefixPrepended = [
"m",
"margin",
"mt",
"marginTop",
"mr",
"marginRight",
"mb",
"marginBottom",
"ml",
"marginLeft",
"mx",
"my",
"p",
"padding",
"pt",
"paddingTop",
"pr",
"paddingRight",
"pb",
"paddingBottom",
"pl",
"paddingLeft",
"px",
"py",
"gap",
];
36 changes: 36 additions & 0 deletions packages/design-system/src/Box/Box.styles.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import styled from "styled-components";
import {
compose,
backgrounds,
borders,
effects,
interactivity,
layout,
sizing,
space,
transforms,
flexboxes,
flexboxGrids,
grids,
} from "@xstyled/system";
import { width, height } from "__config__/utils";

const customSystem = compose(
backgrounds,
borders,
effects,
interactivity,
layout,
sizing,
space,
transforms,
width,
height,
flexboxes,
flexboxGrids,
grids,
);

export const StyledBox = styled.div`
${customSystem}
`;
29 changes: 29 additions & 0 deletions packages/design-system/src/Box/Box.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from "react";
import clsx from "classnames";

import { BoxProps } from "./Box.types";
import { BoxClassName, PropsToBeCssPrefixPrepended } from "./Box.constants";
import { StyledBox } from "./Box.styles";
import { CSS_VARIABLE_PREFIX } from "__config__/constants";

function Box({ children, className, ...rest }: BoxProps) {
const transformedRest = Object.entries(rest).reduce((acc, [key, value]) => {
const newValue = PropsToBeCssPrefixPrepended.includes(key)
? `var(${CSS_VARIABLE_PREFIX}${value})`
: value;

return {
...acc,
[key]: newValue,
};
}, {} as BoxProps);
return (
<StyledBox className={clsx(BoxClassName, className)} {...transformedRest}>
{children}
</StyledBox>
);
}

Box.displayName = "Box";

export { Box };
71 changes: 71 additions & 0 deletions packages/design-system/src/Box/Box.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import React from "react";
import {
BackgroundsProps as BackgroundProps,
BordersProps as BorderProps,
EffectsProps,
ITheme,
InteractivityProps,
LayoutProps,
Size,
SizingProps,
SystemProp,
Theme,
TransformsProps,
FlexboxesProps,
FlexboxGridsProps,
GridsProps,
} from "@xstyled/styled-components";
import * as CSS from "csstype";

import { Spaces } from "__config__/types";

interface WidthProps<T extends ITheme = Theme> {
width?: SystemProp<Size<T> | CSS.Property.Width, T>;
}

interface HeightProps<T extends ITheme = Theme> {
height?: SystemProp<Size<T> | CSS.Property.Height, T>;
}

type SpaceProps = {
m?: Spaces;
margin?: Spaces;
mt?: Spaces;
marginTop?: Spaces;
mr?: Spaces;
marginRight?: Spaces;
mb?: Spaces;
marginBottom?: Spaces;
ml?: Spaces;
marginLeft?: Spaces;
mx?: Spaces;
my?: Spaces;
p?: Spaces;
padding?: Spaces;
pt?: Spaces;
paddingTop?: Spaces;
pr?: Spaces;
paddingRight?: Spaces;
pb?: Spaces;
paddingBottom?: Spaces;
pl?: Spaces;
paddingLeft?: Spaces;
px?: Spaces;
py?: Spaces;
gap?: Spaces;
};

export type BoxProps = WidthProps &
HeightProps &
SpaceProps &
LayoutProps &
SizingProps &
BackgroundProps &
BorderProps &
InteractivityProps &
EffectsProps &
TransformsProps &
FlexboxesProps &
FlexboxGridsProps &
Omit<GridsProps, "gap"> &
React.HTMLAttributes<HTMLDivElement>;
2 changes: 2 additions & 0 deletions packages/design-system/src/Box/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./Box";
export * from "./Box.types";
1 change: 1 addition & 0 deletions packages/design-system/src/__config__/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
* @see https://en.bem.info/methodology/css/
*/
export const CLASS_NAME_PREFIX = "ads-v2";
export const CSS_VARIABLE_PREFIX = "--ads-v2-";
17 changes: 17 additions & 0 deletions packages/design-system/src/__config__/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,20 @@
export type Sizes = "xs" | "sm" | "md" | "lg" | "xl" | "xxl" | "xxxl" | "xxxxl";

export type Kind = "success" | "error" | "warning" | "info" | undefined;

export type Spaces =
| "spaces-0"
| "spaces-1"
| "spaces-2"
| "spaces-3"
| "spaces-4"
| "spaces-5"
| "spaces-6"
| "spaces-7"
| "spaces-8"
| "spaces-9"
| "spaces-10"
| "spaces-11"
| "spaces-12"
| "spaces-13"
| "spaces-14";
11 changes: 11 additions & 0 deletions packages/design-system/src/__config__/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { style } from "@xstyled/styled-components";

export const width = style({
prop: ["width", "w"],
css: "width",
});

export const height = style({
prop: ["height", "h"],
css: "height",
});
34 changes: 32 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7092,6 +7092,36 @@
"@webassemblyjs/wast-parser" "1.9.0"
"@xtuc/long" "4.2.2"

"@xstyled/core@^3.8.0":
version "3.8.0"
resolved "https://registry.yarnpkg.com/@xstyled/core/-/core-3.8.0.tgz#9f33314976e0ae1ae3cc8ce74b1cc70253085c0b"
integrity sha512-DkRtg1841+xJBW4azIEW6bQGPudnRYGDusXhTTT7W0xhMrSEvIyv02Ivhh6KkHtTYmmUalGJ+dRPHyOqrVpMUA==
dependencies:
"@xstyled/system" "^3.8.0"
"@xstyled/util" "^3.7.0"

"@xstyled/styled-components@^3.8.0":
version "3.8.0"
resolved "https://registry.yarnpkg.com/@xstyled/styled-components/-/styled-components-3.8.0.tgz#dc6cce97b74cec79b3fda4a6a186a7fddd5b5eab"
integrity sha512-TCOByj56DxdF2CM71sdEZSu4cA4s74/+C6n6etY21b0HxqU8Pm1KpMwhCZY0kV3Zb/y2VQsBAhWj5Nspv69Msg==
dependencies:
"@xstyled/core" "^3.8.0"
"@xstyled/system" "^3.8.0"
"@xstyled/util" "^3.7.0"

"@xstyled/system@^3.8.0":
version "3.8.0"
resolved "https://registry.yarnpkg.com/@xstyled/system/-/system-3.8.0.tgz#0d5959eab770f668561ff9ff7b5866a0f5ac0967"
integrity sha512-XDYihj8UHtA64lcKklUYu/ZN3SCB7ciqb6JBl6uFmaMIr8lgre8chJONqAyIX0s6MLjvcQdseSf0a7X2hTntOw==
dependencies:
"@xstyled/util" "^3.7.0"
csstype "^3.1.1"

"@xstyled/util@^3.7.0":
version "3.7.0"
resolved "https://registry.yarnpkg.com/@xstyled/util/-/util-3.7.0.tgz#513c045dda0847d43b39612b6d36cc38b507e82d"
integrity sha512-rYtXRcNh+pgRxGnciP0Mas21mpyOzcCTVy7w9uIByQk3EytwBQjDiN6wCasXibkw49Urfti5efsklRbCl5QZww==

"@xtuc/ieee754@^1.2.0":
version "1.2.0"
resolved "https://registry.npmjs.org/@xtuc/ieee754/-/ieee754-1.2.0.tgz"
Expand Down Expand Up @@ -9546,9 +9576,9 @@ cssstyle@^2.3.0:
dependencies:
cssom "~0.3.6"

csstype@^3.0.2, csstype@^3.1.0:
csstype@^3.0.2, csstype@^3.1.0, csstype@^3.1.1, csstype@^3.1.2:
version "3.1.2"
resolved "https://registry.npmjs.org/csstype/-/csstype-3.1.2.tgz"
resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.1.2.tgz#1d4bf9d572f11c14031f0436e1c10bc1f571f50b"
integrity sha512-I7K1Uu0MBPzaFKg4nI5Q7Vs2t+3gWWW648spaF+Rg7pI9ds18Ugn+lvg4SHczUdKlHI5LWBXyqfS8+DufyBsgQ==

csv-generate@^3.4.3:
Expand Down
Loading