1.5.7 • Published 3 years ago

react-layout-library v1.5.7

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

version size license

TOC

React Layout Library by @bacebu4

React Layout Library is used for the unified system of laying out React Components by adding to them specified props such as mt (stands for margin-top) and ml in px units.

The props are being added by applying Higher Order Components (HOC) to your components.

Besides that the library provides HOC for creating unified style for shadows and FlexBox component for easy layouts.

NOTE: You can use those HOC's separately from each other.

Usage

Check example/src/* for more in-depth usage.

First, install the dependencies

npm i -D styled-components
npm i -D react-layout-library

Use withLayoutStyles to add mt and ml props to your styled component.

Use createShadowStyles to create custom HOC with custom box-shadow properties applied.

// StyledButton.tsx

import styled from "styled-components";
import { withLayoutStyles, createShadowStyles } from "react-layout-library";

const withShadowStyles = createShadowStyles({
	x: 2,
	y: 3,
	b: 10,
	s: 12,
	color: "#0001A",
});

const StyledButtonLayout = styled.button`
	padding: 12px 16px;
`;

export const StyledButton = withShadowStyles(
	withLayoutStyles(StyledButtonLayout)
);
// App.tsx

import { StyledButton } from "./StyledButton";
import { FlexBox } from "react-layout-library";

<FlexBox jc="center" ai="center" height="100vh">
	<StyledButton>Sample button</StyledButton>

	<StyledButton mt={3} ml={1} mb={6} mr={4}>
		Sample button with margins
	</StyledButton>
</FlexBox>;

Usage with Function Components

// FunctionComponentButton.tsx

import { withLayoutStyles } from "react-layout-library";

const FunctionComponentButtonLayout: React.FC<{ className?: string }> = ({
	className,
}) => {
	return (
		<button className={className} type="button">
			hey
		</button>
	);
};

export const FunctionComponentButton = withLayoutStyles(
	FunctionComponentButtonLayout
);
// App.tsx

import { FunctionComponentButton } from "./StyledButton";

<FunctionComponentButton>
	Sample button
</FunctionComponentButton>

<FunctionComponentButton mt={32} ml={16} mb={16} mr={4}>
	Sample button with margins
</FunctionComponentButton>

withShadowStyles, createShadowStyles

  • withShadowStyles is the HOC which gives you the default nice looking soft shade.
  • createShadowStyles is the function for creating your own HOC's (note: passing down the empty object into the function gives you the same shadow values as using withShadowStyles)

createShadowStyles(options) API

options object required { x: number; y: number; b: number; s: number; color: string }

NameDefaultDescription
x2offset-x. Specifies the horizontal distance
y3offset-y. Specifies the vertical distance
b17blur-radius. The larger this value, the bigger the blur, so the shadow becomes bigger and lighter. Negative values are not allowed.
s2spread-radius. Positive values will cause the shadow to expand and grow bigger, negative values will cause the shadow to shrink.
color'rgba(114, 114, 114, 0.15)'The basic string that you would usually write in CSS. See color values for possible keywords and notations.

<FlexBox> API

NameTypeDescription
direction"column"If not specified then "row"
jc"space-around" | "space-between" | "space-evenly" | "stretch" | "center" | "end" | "flex-end" | "flex-start"justify-content
ai"center" | "end" | "flex-end" | "flex-start" | "self-end" | "self-start" | "start" | "baseline" | "normal" | "stretch"align-items
mtnumbermargin-top
mbnumbermargin-bottom
mlnumbermargin-left
mrnumbermargin-right
ptnumberpadding-top
pbnumberpadding-bottom
plnumberpadding-left
prnumberpadding-right
marginstringmargin
paddingstringpadding
wstringwidth
hstringheight

Development (src, lib and the build process)

NOTE: The source code for the component is in src. A transpiled CommonJS version (generated with Babel) is available in lib for use with node.js, browserify and webpack.

To build, watch and serve the examples (which will also watch the component source), run npm run dev.

License

MIT Licensed Copyright (c) 2021 Vasilii Krasikov

1.5.7

3 years ago

1.5.6

3 years ago

1.5.5

3 years ago

1.5.4

3 years ago

1.5.3

3 years ago

1.5.2

3 years ago

1.5.1

3 years ago

1.5.0

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.3.3

3 years ago

1.3.2

3 years ago

1.4.0

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago