Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add box stories & enchance box #21

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Contributing

First of all, Thank you very much for taking interest on this repository. Your good intention to contribute is very appreciated.

This is a monorepo for the project masjid-network. It contains code for both Frontend and Backend. you can find the code on each respective folder.

When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change.

### Frontend

For frontend, we use the `frontend` folder. Here is the step to contribute for the first timers:

- cd into `frontend` folder
- Type `npm install` into your terminal (make sure you have node and npm installed)
- after installing dependencies, you can start the project in development mode with `npm run dev`
22 changes: 21 additions & 1 deletion frontend/design-system/components/box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@ import isPropValid from '@emotion/is-prop-valid'
import { spacing } from '../units'
import { theme as defaultTheme } from '../theme'
import { isObjectEmpty } from '../../utils/isObjectEmpty'
import { Theme } from '@emotion/react'

const defaultProps = {
paddingX: 1,
paddingY: 1,
marginX: 1,
marginY: 1,
width: 'auto',
display: 'block',
theme: defaultTheme,
}

interface BoxProps extends React.CSSProperties {
paddingX?: number;
paddingY?: number;
marginX?: number;
marginY?: number;
theme: Theme;
}

const StyledBox = ({
paddingX,
Expand All @@ -14,7 +33,7 @@ const StyledBox = ({
display,
theme,
...props
}) => {
}: BoxProps = defaultProps) => {
if (isObjectEmpty(theme)) {
theme = defaultTheme;
}
Expand Down Expand Up @@ -47,6 +66,7 @@ const StyledBox = ({
}

return {
...props,
padding,
paddingTop,
paddingRight,
Expand Down
37 changes: 37 additions & 0 deletions frontend/emotion.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import '@emotion/react'

declare module '@emotion/react' {
export interface Theme {
palette: {
common: {
black: string,
white: string,
},
primary: {
main: string,
light: string,
contrastText: string,
},
error: {
main: string,
light: string,
contrastText: string,
},
grey: {
100: string,
200: string,
300: string,
400: string,
},
},
shadows: {
0: string,
1: string,
2: string,
},
typography: {
fontFamily: string,
customFontPath: string,
};
}
}
44 changes: 44 additions & 0 deletions frontend/stories/Box.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React from 'react';
import { ComponentStory, ComponentMeta } from '@storybook/react';

import { Box } from '../design-system/components/box';

export default {
title: 'masjid-network/Box',
component: Box,
argTypes: {
padding: {
control: 'select',
options: ['small', 'medium', 'large']
},
margin: {
control: 'select',
options: ['small', 'medium', 'large']
},
},
} as ComponentMeta<typeof Box>;

const Template: ComponentStory<typeof Box> = (args) => (
<div>
<Box {...args} />
</div>
);

export const Default = Template.bind({});
Default.args = {
children: 'Box',
};

export const WithPadding = Template.bind({});
WithPadding.args = {
children: 'Box',
padding: 'small',
border: '1px solid red',
};

export const WithMargin = Template.bind({});
WithMargin.args = {
children: 'Box',
margin: 'small',
border: '1px solid red',
};
2 changes: 1 addition & 1 deletion frontend/utils/isObjectEmpty.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const isObjectEmpty = (obj: Record<string, unknown>): boolean => {
export const isObjectEmpty = <T = Record<string, unknown>>(obj: T): boolean => {

return Object.keys(obj).length === 0;
};