Skip to content

Commit 93e420a

Browse files
authored
Implement containers (#20)
1 parent a080593 commit 93e420a

6 files changed

Lines changed: 78 additions & 21 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@jpbarela/arachnae",
3-
"version": "0.3.1",
3+
"version": "0.4.0",
44
"description": "A simple React component library",
55
"main": "dist/index.js",
66
"files": [

src/Form/index.jsx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import { useForm } from "react-hook-form";
44
import { createUseStyles } from "react-jss";
55
import { useButtonStyles } from "../index";
66
import type { ButtonStyleProps } from "../index";
7-
import { Row, useLayoutStyles } from "../Layout";
8-
import type { LayoutProps } from "../Layout";
7+
import { Row, useContainerStyles, useLayoutStyles } from "../Layout";
8+
import type { ContainerProps, LayoutProps } from "../Layout";
99

1010
type FormProps<T> = {
1111
children: React.Node,
12+
container?: ContainerProps,
1213
onSubmit: (T) => void,
1314
};
1415

@@ -33,10 +34,6 @@ type SelectInputType = {
3334
required?: boolean,
3435
};
3536

36-
type InputLayoutProps = {
37-
width: string,
38-
};
39-
4037
type SubmitProps = {
4138
name: string,
4239
disabled?: boolean,
@@ -56,12 +53,22 @@ type FormContextValue = {
5653

5754
const FormContext = React.createContext(({}: FormContextValue));
5855

59-
export function Form<T>({ children, onSubmit }: FormProps<T>): React.Node {
56+
export function Form<T>({
57+
children,
58+
container,
59+
onSubmit,
60+
}: FormProps<T>): React.Node {
61+
const containerClasses = useContainerStyles(container || {});
6062
const { errors, handleSubmit, register } = useForm();
6163

6264
return (
6365
<FormContext.Provider value={{ errors, handleSubmit, register }}>
64-
<form onSubmit={handleSubmit(onSubmit)}>{children}</form>
66+
<form
67+
onSubmit={handleSubmit(onSubmit)}
68+
className={containerClasses.container}
69+
>
70+
{children}
71+
</form>
6572
</FormContext.Provider>
6673
);
6774
}
@@ -152,7 +159,7 @@ export function SelectInput({
152159
required,
153160
testID,
154161
width,
155-
}: SelectInputType & InputLayoutProps): React.Node {
162+
}: SelectInputType & LayoutProps): React.Node {
156163
const { register, errors } = React.useContext(FormContext);
157164
const classes = useInputStyles();
158165
const layoutClasses = useLayoutStyles({ width });

src/Layout/__snapshots__/index.test.jsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
exports[`Row renders 1`] = `
44
<div>
55
<div
6-
class="row-0-2-1 row-d0-0-2-2 layout-0-2-3 layout-d0-0-2-4"
6+
class="row-0-2-1 row-d0-0-2-2 container-0-2-3 container-d0-0-2-4"
77
>
88
I'm a row
99
</div>

src/Layout/index.js

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@ import { createUseStyles } from "react-jss";
44

55
type FlexAlignType = "center" | "space-between" | "start";
66

7+
export type ContainerProps = {
8+
backgroundColor?: string,
9+
border?: string,
10+
borderBottom?: string,
11+
borderLeft?: string,
12+
borderRight?: string,
13+
boderTop?: string,
14+
height?: string,
15+
padding?: string,
16+
paddingBottom?: string,
17+
paddingLeft?: string,
18+
paddingRight?: string,
19+
paddingTop?: string,
20+
width?: string,
21+
};
22+
723
export type LayoutProps = {
824
height?: string,
925
width?: string,
@@ -12,26 +28,24 @@ export type LayoutProps = {
1228
type RowType = {
1329
justifyContent: FlexAlignType,
1430
alignItems: FlexAlignType,
15-
backgroundColor?: string,
31+
container?: ContainerProps,
1632
children?: React.Node,
1733
className?: string,
1834
};
1935

2036
export function Row({
2137
alignItems,
2238
justifyContent,
23-
backgroundColor,
39+
container,
2440
children,
2541
className,
26-
height,
27-
width,
2842
}: RowType & LayoutProps): React.Node {
29-
const classes = useRowStyles({ alignItems, backgroundColor, justifyContent });
30-
const layoutClasses = useLayoutStyles({ height, width });
43+
const classes = useRowStyles({ alignItems, justifyContent });
44+
const containerClasses = useContainerStyles(container || {});
3145

3246
return (
3347
<div
34-
className={[classes.row, layoutClasses.layout, className]
48+
className={[classes.row, containerClasses.container, className]
3549
.join(" ")
3650
.trim()}
3751
>
@@ -52,8 +66,6 @@ const useRowStyles = createUseStyles({
5266
alignItems: ({ alignItems }: { alignItems: FlexAlignType }) => alignItems,
5367
justifyContent: ({ justifyContent }: { justifyContent: FlexAlignType }) =>
5468
justifyContent,
55-
backgroundColor: ({ backgroundColor }: { backgroundColor: string }) =>
56-
backgroundColor,
5769
},
5870
});
5971

@@ -65,3 +77,25 @@ export const useLayoutStyles: (LayoutProps) => {
6577
width: ({ width }) => width,
6678
},
6779
});
80+
81+
export const useContainerStyles: (
82+
container: ContainerProps
83+
) => {
84+
container: string,
85+
} = createUseStyles({
86+
container: {
87+
backgroundColor: (container) => container.backgroundColor,
88+
border: (container) => container.border,
89+
borderBottom: (container) => container.borderBottom,
90+
borderLeft: (container) => container.borderLeft,
91+
borderRight: (container) => container.borderRight,
92+
borderTop: (container) => container.borderTop,
93+
height: (container) => container.height,
94+
padding: (container) => container.padding,
95+
paddingBottom: (container) => container.paddingBottom,
96+
paddingLeft: (container) => container.paddingLeft,
97+
paddingRight: (container) => container.paddingRight,
98+
paddingTop: (container) => container.paddingTop,
99+
width: (container) => container.width,
100+
},
101+
});

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ export {
99
SubmitInput,
1010
TextInput,
1111
} from "./Form";
12-
export { Row } from "./Layout";
12+
export { Row, useContainerStyles } from "./Layout";
13+
export type { ContainerProps } from "./Layout";
1314
export { Page } from "./Page";
1415
export * as Poylfills from "./Polyfills";
1516
export {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Meta, Story } from "@storybook/addon-docs/blocks";
2+
import { action } from "@storybook/addon-actions";
3+
import { Row } from "../../src/Layout";
4+
5+
<Meta title="Layout / Containers" />
6+
7+
# Containers
8+
9+
Arachnae provides a common way to define containers or large blocks of screen real estate. Arachnae provides the
10+
`useContainerStyles` and `ContainerProps` type to control large `<div>`s that represent grouped components.
11+
12+
The following components implement containers:
13+
14+
- Form
15+
- Row

0 commit comments

Comments
 (0)