Skip to content

Commit

Permalink
feat: add vertices example
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianCraig committed Feb 25, 2020
1 parent 324c7e9 commit ff2b1a9
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "constraint-layout",
"name": "react-constraint",
"version": "0.1.0",
"private": true,
"dependencies": {
Expand Down
6 changes: 3 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import "./App.css";
import { simpleBlock } from "./constraints/example";
import { createLayoutComponent } from "./constraints/generator";
import { vertices } from "./examples/vertices";

const codeStyle: React.CSSProperties = {
width: "50vw",
Expand All @@ -21,13 +21,13 @@ const viewStyle: React.CSSProperties = {
left: "50%"
};

const Comp = createLayoutComponent(simpleBlock);
const Comp = createLayoutComponent(vertices);

const App: React.FC = () => {
return (
<>
<div style={codeStyle} contentEditable>
{JSON.stringify(simpleBlock, null, 2)}
{JSON.stringify(vertices, null, 2)}
</div>
<div style={viewStyle}>
<Comp width={400} height={400} Block={<p>Hola</p>} />
Expand Down
2 changes: 1 addition & 1 deletion src/constraints/example.ts → src/examples/simple.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LayoutDefinition } from "./definition";
import { LayoutDefinition } from "../constraints/definition";

export const simpleBlock: LayoutDefinition = {
Block: {
Expand Down
60 changes: 60 additions & 0 deletions src/examples/vertices.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { LayoutDefinition } from "../constraints/definition";

export const vertices: LayoutDefinition = {
Center: {
constraints: [
{
component: "parent",
fromSide: "top",
toSide: "top",
distance: 64
},
{
component: "parent",
fromSide: "right",
toSide: "right",
distance: -64
},
{
component: "parent",
fromSide: "bottom",
toSide: "bottom",
distance: -64
},
{
component: "parent",
fromSide: "left",
toSide: "left",
distance: 64
}
]
},
BottomLeft: {
constraints: [
{
component: "Center",
fromSide: "top",
toSide: "bottom",
distance: -32
},
{
component: "Center",
fromSide: "right",
toSide: "left",
distance: 32
},
{
component: "Center",
fromSide: "bottom",
toSide: "bottom",
distance: 32
},
{
component: "Center",
fromSide: "left",
toSide: "left",
distance: -32
}
]
}
};

0 comments on commit ff2b1a9

Please sign in to comment.