-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #180 from wix-incubator/tyv/order_with_layout
order with layout option
- Loading branch information
Showing
22 changed files
with
3,560 additions
and
11,976 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
import React from 'react'; | ||
import {createBoard} from '@wixc3/react-board'; | ||
|
||
import { | ||
AutoFields, | ||
AutoView, | ||
ComponentsRepo, | ||
CoreSchemaMetaSchema, | ||
createUISchema, | ||
RepositoryProvider, | ||
UISchema, | ||
getHints, | ||
orderToTemplateAreas | ||
} from '../../'; | ||
|
||
const baseRepo = new ComponentsRepo('BaseRepo') | ||
.register('object', { | ||
name: 'MyObject', | ||
component: AutoFields | ||
}) | ||
.register('string', { | ||
name: 'MyStringComponent', | ||
component: props => <span>{props.data}</span> | ||
}) | ||
.register('number', { | ||
name: 'MyNumberComponent', | ||
component: props => <span>{props.data}</span> | ||
}) | ||
.register('boolean', { | ||
name: 'MyBooleanComponent', | ||
component: props => <span>{props.data ? 'online' : 'offline'}</span> | ||
}); | ||
|
||
const repo = baseRepo | ||
.clone('LayoutRepo') | ||
.addWrapper( | ||
(item, props) => { | ||
const {order} = getHints(props.uiSchema, props.pointer); | ||
return ( | ||
<> | ||
<style> | ||
{` | ||
.root { | ||
box-sizing: border-box; | ||
width: 100%; | ||
display: grid; | ||
border: 1px solid red; | ||
grid-template-columns: auto; | ||
grid-template-rows: 1fr; | ||
gap: 1rem; | ||
align-items: stretch; | ||
} | ||
.child { | ||
padding: 5px; | ||
border: 1px solid gray; | ||
border-radius: 5px; | ||
} | ||
`} | ||
</style> | ||
<div | ||
className="root" | ||
style={{gridTemplateAreas: orderToTemplateAreas(order)}} | ||
> | ||
{item} | ||
</div> | ||
</> | ||
); | ||
}, | ||
{include: ['MyObject']} | ||
) | ||
.addWrapper( | ||
(item, props) => ( | ||
<div | ||
style={{gridArea: props.field}} | ||
className="child" | ||
> | ||
{props.field} | ||
: | ||
{item} | ||
</div> | ||
), | ||
{exclude: ['MyObject']} | ||
); | ||
|
||
export const userUISchema: UISchema = createUISchema( | ||
{}, | ||
{ | ||
'': { | ||
order: [ | ||
['age', '.', '.'], | ||
['age', 'active', 'login'] | ||
] | ||
} | ||
} | ||
); | ||
|
||
export const data = { | ||
login: 'johondoe', | ||
age: 21, | ||
active: true | ||
}; | ||
|
||
const schema: CoreSchemaMetaSchema = { | ||
type: 'object', | ||
properties: { | ||
login: { | ||
type: 'string' | ||
}, | ||
age: { | ||
type: 'number' | ||
}, | ||
active: { | ||
type: 'boolean' | ||
} | ||
} | ||
}; | ||
|
||
export default createBoard({ | ||
name: 'layout', | ||
Board: () => ( | ||
<RepositoryProvider components={repo}> | ||
<AutoView | ||
schema={schema as CoreSchemaMetaSchema} | ||
data={data} | ||
uiSchema={userUISchema} | ||
/> | ||
</RepositoryProvider> | ||
), | ||
environmentProps: { | ||
canvasWidth: 264, | ||
canvasHeight: 157 | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import {orderToTemplateAreas} from '../src'; | ||
|
||
describe('Converting order into grid-template-areas', () => { | ||
it('should convert array of strings', async () => { | ||
expect(orderToTemplateAreas(['a', 'b', 'c'])).toEqual('"a"\n"b"\n"c"'); | ||
}); | ||
it('should fill gaps', async () => { | ||
expect(orderToTemplateAreas([['a', 'b', 'b'], 'c', 'd'])).toEqual( | ||
'"a b b"\n"c c c"\n"d d d"' | ||
); | ||
}); | ||
it('should respect empty cell and fill to right with empty cell', async () => { | ||
expect( | ||
orderToTemplateAreas([ | ||
['a', 'b', 'b'], | ||
['c', 'c', '.'], | ||
['.', 'd'] | ||
]) | ||
).toEqual('"a b b"\n"c c ."\n". d ."'); | ||
}); | ||
it('should respect fields areas on a few rows', async () => { | ||
expect( | ||
orderToTemplateAreas([['a', 'b', 'b'], ['c', 'b', 'b'], 'd']) | ||
).toEqual('"a b b"\n"c b b"\n"d d d"'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.