-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1dcba36
commit d98cbca
Showing
7 changed files
with
179 additions
and
1 deletion.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
packages/dm-core-plugins/blueprints/stack/StackPluginConfig.json
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,72 @@ | ||
{ | ||
"name": "StackPluginConfig", | ||
"type": "dmss://system/SIMOS/Blueprint", | ||
"attributes": [ | ||
{ | ||
"name": "type", | ||
"type": "CORE:BlueprintAttribute", | ||
"attributeType": "string" | ||
}, | ||
{ | ||
"name": "items", | ||
"type": "CORE:BlueprintAttribute", | ||
"attributeType": "CORE:ViewConfig", | ||
"dimensions": "*" | ||
}, | ||
{ | ||
"name": "direction", | ||
"type": "CORE:BlueprintAttribute", | ||
"description": "horizontal or vertical", | ||
"attributeType": "string", | ||
"optional": true, | ||
"default": "horizontal" | ||
}, | ||
{ | ||
"name": "verticalPlacement", | ||
"type": "CORE:BlueprintAttribute", | ||
"description": "left, center, right or spaceItems", | ||
"attributeType": "string", | ||
"optional": true, | ||
"default": "left" | ||
}, | ||
{ | ||
"name": "horizontalPlacement", | ||
"type": "CORE:BlueprintAttribute", | ||
"description": "top, center or bottom", | ||
"attributeType": "string", | ||
"optional": true, | ||
"default": "top" | ||
}, | ||
{ | ||
"name": "spacing", | ||
"type": "CORE:BlueprintAttribute", | ||
"description": "REM value. Default is 2 = 32px", | ||
"attributeType": "number", | ||
"optional": true, | ||
"default": 2 | ||
}, | ||
{ | ||
"name": "maxWidth", | ||
"type": "CORE:BlueprintAttribute", | ||
"description": "Set max-width of wrapper if you want to use less than 100% width.", | ||
"attributeType": "string", | ||
"optional": true | ||
}, | ||
{ | ||
"name": "wrapItems", | ||
"type": "CORE:BlueprintAttribute", | ||
"description": "When using vertical direction, make items wrap under eachother when width is getting too small to fit all items", | ||
"attributeType": "boolean", | ||
"optional": true, | ||
"default": false | ||
}, | ||
{ | ||
"name": "classNames", | ||
"type": "CORE:BlueprintAttribute", | ||
"description": "Add tailwind classNames to wrapper", | ||
"attributeType": "string", | ||
"dimensions": "*", | ||
"optional": true | ||
} | ||
] | ||
} |
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,25 @@ | ||
{ | ||
"name": "stack", | ||
"type": "CORE:Package", | ||
"isRoot": false, | ||
"_meta_": { | ||
"type": "CORE:Meta", | ||
"version": "0.0.1", | ||
"dependencies": [ | ||
{ | ||
"type": "CORE:Dependency", | ||
"alias": "CORE", | ||
"address": "system/SIMOS", | ||
"version": "0.0.1", | ||
"protocol": "dmss" | ||
}, | ||
{ | ||
"type": "CORE:Dependency", | ||
"alias": "PLUGINS", | ||
"address": "system/Plugins", | ||
"version": "0.0.1", | ||
"protocol": "dmss" | ||
} | ||
] | ||
} | ||
} |
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,50 @@ | ||
import { IUIPlugin, Stack, ViewCreator } from '@development-framework/dm-core' | ||
import { | ||
DirectionTypes, | ||
StackProps, | ||
} from '@development-framework/dm-core/dist/components/common/Stack/types' | ||
import { StackPluginConfig, defaultConfig } from './types' | ||
|
||
export const StackPlugin = (props: IUIPlugin) => { | ||
const { idReference } = props | ||
const config: StackPluginConfig = { ...defaultConfig, ...props.config } | ||
|
||
// map plugin language to stack props/css language | ||
const configMap: { [name: string]: string } = { | ||
horizontal: 'column', | ||
vertical: 'row', | ||
verticalPlacement: | ||
config.direction === 'horizontal' ? 'alignItems' : 'justifyContent', | ||
horizontalPlacement: | ||
config.direction === 'horizontal' ? 'justifyContent' : 'alignItems', | ||
left: 'flex-start', | ||
center: 'center', | ||
right: 'flex-end', | ||
top: 'flex-start', | ||
bottom: 'flex-end', | ||
spaceItems: 'space-between', | ||
} | ||
|
||
const stackProps: StackProps = { | ||
direction: configMap[config.direction] as DirectionTypes, | ||
[configMap.verticalPlacement]: configMap[config.verticalPlacement], | ||
[configMap.horizontalPlacement]: configMap[config.horizontalPlacement], | ||
className: config.classNames?.join(' '), | ||
spacing: config.spacing !== undefined ? config.spacing : 1.5, | ||
wrap: config.wrap ? 'wrap' : 'no-wrap', | ||
} | ||
|
||
return ( | ||
<Stack {...stackProps}> | ||
{config.items?.map((item, index) => ( | ||
<ViewCreator | ||
key={`${item.recipe}_${index}`} | ||
idReference={idReference} | ||
viewConfig={item} | ||
onSubmit={props.onSubmit} | ||
onChange={props.onChange} | ||
/> | ||
))} | ||
</Stack> | ||
) | ||
} |
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,23 @@ | ||
import { TViewConfig } from '@development-framework/dm-core' | ||
|
||
export type StackPluginConfig = { | ||
items: TViewConfig[] | ||
direction: 'horizontal' | 'vertical' | ||
verticalPlacement: 'left' | 'center' | 'right' | 'spaceItems' | ||
horizontalPlacement: 'top' | 'center' | 'bottom' | ||
spacing: number | ||
maxWidth: string | ||
wrap: boolean | ||
classNames: string[] | ||
} | ||
|
||
export const defaultConfig: StackPluginConfig = { | ||
items: [], | ||
direction: 'horizontal', | ||
verticalPlacement: 'left', | ||
horizontalPlacement: 'top', | ||
spacing: 2, | ||
maxWidth: '100%', | ||
wrap: false, | ||
classNames: [], | ||
} |
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