Skip to content

Commit

Permalink
feat: stack plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
awesthouse committed Feb 7, 2024
1 parent 1dcba36 commit d98cbca
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 1 deletion.
72 changes: 72 additions & 0 deletions packages/dm-core-plugins/blueprints/stack/StackPluginConfig.json
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
}
]
}
25 changes: 25 additions & 0 deletions packages/dm-core-plugins/blueprints/stack/package.json
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"
}
]
}
}
7 changes: 7 additions & 0 deletions packages/dm-core-plugins/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ export default ({
}))
),
},
'@development-framework/dm-core-plugins/stack': {
component: lazy(() =>
import('./stack/StackPlugin').then((module) => ({
default: module.StackPlugin,
}))
),
},
'@development-framework/dm-core-plugins/data_grid': {
component: lazy(() =>
import('./data-grid/DataGridPlugin').then((module) => ({
Expand Down
50 changes: 50 additions & 0 deletions packages/dm-core-plugins/src/stack/StackPlugin.tsx
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>
)
}
23 changes: 23 additions & 0 deletions packages/dm-core-plugins/src/stack/types.ts
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: [],
}
2 changes: 1 addition & 1 deletion packages/dm-core/src/components/common/Stack/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export interface StackProps extends React.ComponentPropsWithoutRef<'div'> {
| 'max-content'
grow?: number
shrink?: number
direction?: 'row' | 'column' | 'row-reverse' | 'column-reverse'
direction?: DirectionTypes
wrap?: 'initial' | 'no-wrap' | 'wrap' | 'wrap-reverse'
order?: number
className?: string
Expand Down
1 change: 1 addition & 0 deletions packages/dm-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ export type TViewConfig = {
eds_icon?: string
roles?: string[]
showRefreshButton?: boolean
recipe?: string
}

export type TReferenceViewConfig = TViewConfig & {
Expand Down

0 comments on commit d98cbca

Please sign in to comment.